Block-Structured AMR Software Framework
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
AMReX_COORDSYS_2D_C.H
Go to the documentation of this file.
1#ifndef AMREX_COORDSYS_2D_C_H_
2#define AMREX_COORDSYS_2D_C_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_Gpu.H>
6#include <AMReX_Array.H>
7#include <AMReX_FArrayBox.H>
8#include <cmath>
9
10namespace amrex {
11
13inline
14void
15amrex_setvol (Box const& bx, Array4<Real> const& vol,
17 GpuArray<Real,2> const& dx, const int coord) noexcept
18{
19 const auto lo = amrex::lbound(bx);
20 const auto hi = amrex::ubound(bx);
21
22 if (coord == 0) // Cartesian
23 {
24 Real dv = dx[0]*dx[1];
25 for (int j = lo.y; j <= hi.y; ++j) {
27 for (int i = lo.x; i <= hi.x; ++i) {
28 vol(i,j,0) = dv;
29 }
30 }
31 }
32 else if (coord == 1) // r-z
33 {
34 const Real pi = Real(3.1415926535897932);
35 for (int j = lo.y; j <= hi.y; ++j) {
37 for (int i = lo.x; i <= hi.x; ++i) {
38 Real ri = offset[0] + dx[0]*(i);
39 Real ro = ri + dx[0];
40 Real v = pi*dx[1]*dx[0]*(ro + ri);
41 vol(i,j,0) = std::abs(v);
42 }
43 }
44 }
45 else // r-theta
46 {
47 const Real pi = Real(3.1415926535897932);
48 for (int j = lo.y; j <= hi.y; ++j) {
49 Real ti = offset[1] + dx[1]*(j);
50 Real to = ti + dx[1];
51 Real tmp = (Real(2.)*pi)*(std::cos(ti)-std::cos(to))/Real(3.0);
53 for (int i = lo.x; i <= hi.x; ++i) {
54 Real ri = offset[0] + dx[0]*(i);
55 Real ro = ri + dx[0];
56 Real v = tmp*(ro-ri)*(ro*ro+ro*ri+ri*ri);
57 vol(i,j,0) = std::abs(v);
58 }
59 }
60 }
61}
62
64inline
65void
66amrex_setarea (Box const& bx, Array4<Real> const& area,
68 GpuArray<Real,2> const& dx, const int dir, const int coord) noexcept
69{
70 const auto lo = amrex::lbound(bx);
71 const auto hi = amrex::ubound(bx);
72
73 if (coord == 0)
74 {
75 Real a = (dir == 0) ? dx[1] : dx[0];
76 for (int j = lo.y; j <= hi.y; ++j) {
78 for (int i = lo.x; i <= hi.x; ++i) {
79 area(i,j,0) = a;
80 }
81 }
82 }
83 else if (coord == 1)
84 {
85 const Real pi = Real(3.1415926535897932);
86 if (dir == 0)
87 {
88 for (int j = lo.y; j <= hi.y; ++j) {
90 for (int i = lo.x; i <= hi.x; ++i) {
91 Real ri = offset[0] + dx[0]*(i);
92 Real a = std::abs((Real(2.)*pi)*ri*dx[1]);
93 area(i,j,0) = a;
94 }
95 }
96 }
97 else
98 {
99 for (int j = lo.y; j <= hi.y; ++j) {
101 for (int i = lo.x; i <= hi.x; ++i) {
102 Real rc = offset[0] + dx[0]*(i+Real(0.5));
103 Real a = std::abs(dx[0]*(Real(2.)*pi)*rc);
104 area(i,j,0) = a;
105 }
106 }
107 }
108 }
109 else
110 {
111 const Real pi = Real(3.1415926535897932);
112 if (dir == 0)
113 {
114 for (int j = lo.y; j <= hi.y; ++j) {
115 Real ti = offset[1] + dx[1]*(j);
116 Real to = ti + dx[1];
117 Real tmp = (Real(2.)*pi)*(std::cos(ti)-std::cos(to));
119 for (int i = lo.x; i <= hi.x; ++i) {
120 Real ri = offset[0] + dx[0]*(i);
121 Real a = std::abs(tmp*ri*ri);
122 area(i,j,0) = a;
123 }
124 }
125 }
126 else
127 {
128 for (int j = lo.y; j <= hi.y; ++j) {
129 Real ti = offset[1] + dx[1]*(j);
130 Real tmp = pi*std::sin(ti);
132 for (int i = lo.x; i <= hi.x; ++i) {
133 Real ri = offset[0] + dx[0]*(i);
134 Real ro = ri + dx[0];
135 Real a = std::abs(tmp*(ro-ri)*(ro+ri));
136 area(i,j,0) = a;
137 }
138 }
139 }
140 }
141}
142
144inline
145void
146amrex_setdloga (Box const& bx, Array4<Real> const& dloga,
148 GpuArray<Real,2> const& dx, const int dir, const int coord) noexcept
149{
150 const auto lo = amrex::lbound(bx);
151 const auto hi = amrex::ubound(bx);
152
153 if (coord == 0)
154 {
155 for (int j = lo.y; j <= hi.y; ++j) {
157 for (int i = lo.x; i <= hi.x; ++i) {
158 dloga(i,j,0) = Real(0.0);
159 }
160 }
161 }
162 else if (coord == 1)
163 {
164 if (dir == 0)
165 {
166 for (int j = lo.y; j <= hi.y; ++j) {
168 for (int i = lo.x; i <= hi.x; ++i) {
169 Real rc = offset[0] + dx[0]*(i+Real(0.5));
170 dloga(i,j,0) = Real(1.0)/rc;
171 }
172 }
173 }
174 else
175 {
176 for (int j = lo.y; j <= hi.y; ++j) {
178 for (int i = lo.x; i <= hi.x; ++i) {
179 dloga(i,j,0) = Real(0.0);
180 }
181 }
182 }
183 }
184 else
185 {
186 if (dir == 0)
187 {
188 for (int j = lo.y; j <= hi.y; ++j) {
190 for (int i = lo.x; i <= hi.x; ++i) {
191 Real rc = offset[0] + dx[0]*(i+Real(0.5));
192 dloga(i,j,0) = Real(2.0)/rc;
193 }
194 }
195 }
196 else
197 {
198 for (int j = lo.y; j <= hi.y; ++j) {
199 Real ti = offset[1] + dx[1]*(j);
200 Real to = ti + dx[1];
201 Real tmp = Real(1.0)/std::tan(Real(0.5)*(ti+to));
203 for (int i = lo.x; i <= hi.x; ++i) {
204 Real rc = offset[0] + dx[0]*(i+Real(0.5) );
205 dloga(i,j,0) = tmp/rc;
206 }
207 }
208 }
209 }
210}
211
212}
213
214#endif
#define AMREX_PRAGMA_SIMD
Definition AMReX_Extension.H:80
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1089
Definition AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE void amrex_setvol(Box const &bx, Array4< Real > const &vol, GpuArray< Real, 1 > const &offset, GpuArray< Real, 1 > const &dx, const int coord) noexcept
Definition AMReX_COORDSYS_1D_C.H:15
AMREX_GPU_HOST_DEVICE void amrex_setarea(Box const &bx, Array4< Real > const &area, GpuArray< Real, 1 > const &offset, GpuArray< Real, 1 > const &dx, const int, const int coord) noexcept
Definition AMReX_COORDSYS_1D_C.H:57
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 ubound(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:315
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 lbound(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:308
AMREX_GPU_HOST_DEVICE void amrex_setdloga(Box const &bx, Array4< Real > const &dloga, GpuArray< Real, 1 > const &offset, GpuArray< Real, 1 > const &dx, const int, const int coord) noexcept
Definition AMReX_COORDSYS_1D_C.H:96
Definition AMReX_Array4.H:61
Definition AMReX_Array.H:34