24 amrex::Array4<amrex::Real const>
const& volfrac,
27 amrex::Real& mz)
noexcept
30 volfrac(i - 1, j - 1, k - 1) + volfrac(i - 1, j - 1, k + 1) +
31 volfrac(i - 1, j + 1, k - 1) + volfrac(i - 1, j + 1, k + 1) +
32 2.0 * (volfrac(i - 1, j - 1, k) + volfrac(i - 1, j + 1, k) +
33 volfrac(i - 1, j, k - 1) + volfrac(i - 1, j, k + 1)) +
34 4.0 * volfrac(i - 1, j, k);
36 volfrac(i + 1, j - 1, k - 1) + volfrac(i + 1, j - 1, k + 1) +
37 volfrac(i + 1, j + 1, k - 1) + volfrac(i + 1, j + 1, k + 1) +
38 2.0 * (volfrac(i + 1, j - 1, k) + volfrac(i + 1, j + 1, k) +
39 volfrac(i + 1, j, k - 1) + volfrac(i + 1, j, k + 1)) +
40 4.0 * volfrac(i + 1, j, k);
43 mm1 = volfrac(i - 1, j - 1, k - 1) + volfrac(i - 1, j - 1, k + 1) +
44 volfrac(i + 1, j - 1, k - 1) + volfrac(i + 1, j - 1, k + 1) +
45 2.0 * (volfrac(i - 1, j - 1, k) + volfrac(i + 1, j - 1, k) +
46 volfrac(i, j - 1, k - 1) + volfrac(i, j - 1, k + 1)) +
47 4.0 * volfrac(i, j - 1, k);
48 mm2 = volfrac(i - 1, j + 1, k - 1) + volfrac(i - 1, j + 1, k + 1) +
49 volfrac(i + 1, j + 1, k - 1) + volfrac(i + 1, j + 1, k + 1) +
50 2.0 * (volfrac(i - 1, j + 1, k) + volfrac(i + 1, j + 1, k) +
51 volfrac(i, j + 1, k - 1) + volfrac(i, j + 1, k + 1)) +
52 4.0 * volfrac(i, j + 1, k);
55 mm1 = volfrac(i - 1, j - 1, k - 1) + volfrac(i - 1, j + 1, k - 1) +
56 volfrac(i + 1, j - 1, k - 1) + volfrac(i + 1, j + 1, k - 1) +
57 2.0 * (volfrac(i - 1, j, k - 1) + volfrac(i + 1, j, k - 1) +
58 volfrac(i, j - 1, k - 1) + volfrac(i, j + 1, k - 1)) +
59 4.0 * volfrac(i, j, k - 1);
60 mm2 = volfrac(i - 1, j - 1, k + 1) + volfrac(i - 1, j + 1, k + 1) +
61 volfrac(i + 1, j - 1, k + 1) + volfrac(i + 1, j + 1, k + 1) +
62 2.0 * (volfrac(i - 1, j, k + 1) + volfrac(i + 1, j, k + 1) +
63 volfrac(i, j - 1, k + 1) + volfrac(i, j + 1, k + 1)) +
64 4.0 * volfrac(i, j, k + 1);
76 amrex::Array4<amrex::Real const>
const& volfrac,
79 amrex::Real& mz)
noexcept
82 const int im1 = ibdy == -1 ? i : i - 1;
83 const int jm1 = jbdy == -1 ? j : j - 1;
84 const int km1 = kbdy == -1 ? k : k - 1;
85 const int ip1 = ibdy == +1 ? i : i + 1;
86 const int jp1 = jbdy == +1 ? j : j + 1;
87 const int kp1 = kbdy == +1 ? k : k + 1;
89 amrex::Real mm1 = volfrac(im1, jm1, km1) + volfrac(im1, jm1, kp1) +
90 volfrac(im1, jp1, km1) + volfrac(im1, jp1, kp1) +
91 2.0 * (volfrac(im1, jm1, k) + volfrac(im1, jp1, k) +
92 volfrac(im1, j, km1) + volfrac(im1, j, kp1)) +
93 4.0 * volfrac(im1, j, k);
94 amrex::Real mm2 = volfrac(ip1, jm1, km1) + volfrac(ip1, jm1, kp1) +
95 volfrac(ip1, jp1, km1) + volfrac(ip1, jp1, kp1) +
96 2.0 * (volfrac(ip1, jm1, k) + volfrac(ip1, jp1, k) +
97 volfrac(ip1, j, km1) + volfrac(ip1, j, kp1)) +
98 4.0 * volfrac(ip1, j, k);
101 mm1 = volfrac(im1, jm1, km1) + volfrac(im1, jm1, kp1) +
102 volfrac(ip1, jm1, km1) + volfrac(ip1, jm1, kp1) +
103 2.0 * (volfrac(im1, jm1, k) + volfrac(ip1, jm1, k) +
104 volfrac(i, jm1, km1) + volfrac(i, jm1, kp1)) +
105 4.0 * volfrac(i, jm1, k);
106 mm2 = volfrac(im1, jp1, km1) + volfrac(im1, jp1, kp1) +
107 volfrac(ip1, jp1, km1) + volfrac(ip1, jp1, kp1) +
108 2.0 * (volfrac(im1, jp1, k) + volfrac(ip1, jp1, k) +
109 volfrac(i, jp1, km1) + volfrac(i, jp1, kp1)) +
110 4.0 * volfrac(i, jp1, k);
113 mm1 = volfrac(im1, jm1, km1) + volfrac(im1, jp1, km1) +
114 volfrac(ip1, jm1, km1) + volfrac(ip1, jp1, km1) +
115 2.0 * (volfrac(im1, j, km1) + volfrac(ip1, j, km1) +
116 volfrac(i, jm1, km1) + volfrac(i, jp1, km1)) +
117 4.0 * volfrac(i, j, km1);
118 mm2 = volfrac(im1, jm1, kp1) + volfrac(im1, jp1, kp1) +
119 volfrac(ip1, jm1, kp1) + volfrac(ip1, jp1, kp1) +
120 2.0 * (volfrac(im1, j, kp1) + volfrac(ip1, j, kp1) +
121 volfrac(i, jm1, kp1) + volfrac(i, jp1, kp1)) +
122 4.0 * volfrac(i, j, kp1);
130 amrex::Array4<amrex::Real const>
const& volfrac,
133 amrex::Real& mz)
noexcept
135 amrex::Array2D<amrex::Real, 0, AMREX_SPACEDIM + 1, 0, AMREX_SPACEDIM> m;
138 amrex::Real m1 = volfrac(i - 1, j, k - 1) + volfrac(i - 1, j, k + 1) +
139 volfrac(i - 1, j - 1, k) + volfrac(i - 1, j + 1, k) +
140 volfrac(i - 1, j, k);
141 amrex::Real m2 = volfrac(i + 1, j, k - 1) + volfrac(i + 1, j, k + 1) +
142 volfrac(i + 1, j - 1, k) + volfrac(i + 1, j + 1, k) +
143 volfrac(i + 1, j, k);
145 m(0, 0) = (m1 > m2) ? 1.0 : -1.0;
147 m1 = volfrac(i - 1, j - 1, k) + volfrac(i + 1, j - 1, k) +
148 volfrac(i, j - 1, k);
149 m2 = volfrac(i - 1, j + 1, k) + volfrac(i + 1, j + 1, k) +
150 volfrac(i, j + 1, k);
151 m(0, 1) = 0.5 * (m1 - m2);
153 m1 = volfrac(i - 1, j, k - 1) + volfrac(i + 1, j, k - 1) +
154 volfrac(i, j, k - 1);
155 m2 = volfrac(i - 1, j, k + 1) + volfrac(i + 1, j, k + 1) +
156 volfrac(i, j, k + 1);
157 m(0, 2) = 0.5 * (m1 - m2);
162 m1 = volfrac(i - 1, j - 1, k) + volfrac(i - 1, j + 1, k) +
163 volfrac(i - 1, j, k);
164 m2 = volfrac(i + 1, j - 1, k) + volfrac(i + 1, j + 1, k) +
165 volfrac(i + 1, j, k);
166 m(1, 0) = 0.5 * (m1 - m2);
168 m1 = volfrac(i, j - 1, k - 1) + volfrac(i, j - 1, k + 1) +
169 volfrac(i + 1, j - 1, k) + volfrac(i - 1, j - 1, k) +
170 volfrac(i, j - 1, k);
171 m2 = volfrac(i, j + 1, k - 1) + volfrac(i, j + 1, k + 1) +
172 volfrac(i + 1, j + 1, k) + volfrac(i - 1, j + 1, k) +
173 volfrac(i, j + 1, k);
175 m(1, 1) = (m1 > m2) ? 1.0 : -1.0;
177 m1 = volfrac(i, j - 1, k - 1) + volfrac(i, j, k - 1) +
178 volfrac(i, j + 1, k - 1);
179 m2 = volfrac(i, j - 1, k + 1) + volfrac(i, j, k + 1) +
180 volfrac(i, j + 1, k + 1);
181 m(1, 2) = 0.5 * (m1 - m2);
186 m1 = volfrac(i - 1, j, k - 1) + volfrac(i - 1, j, k + 1) +
187 volfrac(i - 1, j, k);
188 m2 = volfrac(i + 1, j, k - 1) + volfrac(i + 1, j, k + 1) +
189 volfrac(i + 1, j, k);
190 m(2, 0) = 0.5 * (m1 - m2);
192 m1 = volfrac(i, j - 1, k - 1) + volfrac(i, j - 1, k + 1) +
193 volfrac(i, j - 1, k);
194 m2 = volfrac(i, j + 1, k - 1) + volfrac(i, j + 1, k + 1) +
195 volfrac(i, j + 1, k);
196 m(2, 1) = 0.5 * (m1 - m2);
198 m1 = volfrac(i - 1, j, k - 1) + volfrac(i + 1, j, k - 1) +
199 volfrac(i, j - 1, k - 1) + volfrac(i, j + 1, k - 1) +
200 volfrac(i, j, k - 1);
201 m2 = volfrac(i - 1, j, k + 1) + volfrac(i + 1, j, k + 1) +
202 volfrac(i, j - 1, k + 1) + volfrac(i, j + 1, k + 1) +
203 volfrac(i, j, k + 1);
205 m(2, 2) = (m1 > m2) ? 1.0 : -1.0;
208 amrex::Real t0, t1, t2;
210 t0 = std::abs(m(0, 0)) + std::abs(m(0, 1)) + std::abs(m(0, 2));
211 m(0, 0) = m(0, 0) / t0;
212 m(0, 1) = m(0, 1) / t0;
213 m(0, 2) = m(0, 2) / t0;
215 t0 = std::abs(m(1, 0)) + std::abs(m(1, 1)) + std::abs(m(1, 2));
216 m(1, 0) = m(1, 0) / t0;
217 m(1, 1) = m(1, 1) / t0;
218 m(1, 2) = m(1, 2) / t0;
220 t0 = std::abs(m(2, 0)) + std::abs(m(2, 1)) + std::abs(m(2, 2));
221 m(2, 0) = m(2, 0) / t0;
222 m(2, 1) = m(2, 1) / t0;
223 m(2, 2) = m(2, 2) / t0;
226 t0 = std::abs(m(0, 0));
227 t1 = std::abs(m(1, 1));
228 t2 = std::abs(m(2, 2));
242 i, j, k, volfrac, m(3, 0), m(3, 1), m(3, 2));
244 constexpr amrex::Real tiny = 1e-20;
245 t0 = std::abs(m(3, 0)) + std::abs(m(3, 1)) + std::abs(m(3, 2)) + tiny;
246 m(3, 0) = m(3, 0) / t0;
247 m(3, 1) = m(3, 1) / t0;
248 m(3, 2) = m(3, 2) / t0;
251 t0 = std::abs(m(3, 0));
252 t1 = std::abs(m(3, 1));
253 t2 = std::abs(m(3, 2));
261 if (std::abs(m(cn, cn)) > t0 && t0 > 0.0) {
276 const amrex::Real b1,
277 const amrex::Real b2,
278 const amrex::Real b3,
279 const amrex::Real volF)
noexcept
281 using namespace amrex;
283 amrex::Real const_tiny = std::numeric_limits<amrex::Real>::epsilon();
289 amrex::Real m1 = amrex::min(b1, b2);
290 amrex::Real m3 = amrex::max(b1, b2);
298 }
else if (m2 > m3) {
304 amrex::Real m12 = m1 + m2;
305 amrex::Real pr = amrex::max<amrex::Real>(6. * m1 * m2 * m3, const_tiny);
306 amrex::Real V1 = m1 * m1 * m1 / pr;
307 amrex::Real V2 = V1 + 0.5 * (m2 - m1) / m3;
312 V3 = (m3 * m3 * (3.0 * m12 - m3) + m1 * m1 * (m1 - 3.0 * m3) +
313 m2 * m2 * (m2 - 3.0 * m3)) /
320 amrex::Real ch = amrex::min<amrex::Real>(volF, 1.0 - volF);
322 amrex::Real alpha, p, q, p12, teta, cs;
324 alpha = std::cbrt(pr * ch);
325 }
else if (ch < V2) {
326 alpha = 0.50 * (m1 + std::sqrt(m1 * m1 + 8.0 * m2 * m3 * (ch - V1)));
327 }
else if (ch < V3) {
329 q = 1.5 * m1 * m2 * (m12 - 2.0 * m3 * ch);
331 teta = std::acos(q / (p * p12 + 1e-20)) / 3.0;
333 alpha = p12 * (std::sqrt(3.0 * (1.0 - cs * cs)) - cs) + m12;
334 }
else if (m12 < m3) {
335 alpha = m3 * ch + 0.5 * mm;
337 p = m1 * (m2 + m3) + m2 * m3 - 0.25;
338 q = 1.5 * m1 * m2 * m3 * (0.5 - ch);
340 teta = std::acos(q / (p * p12 + 1e-20)) / 3.0;
342 alpha = p12 * (std::sqrt(3.0 * (1.0 - cs * cs)) - cs) + 0.5;
360AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
cut_volume(
361 const amrex::Real m1,
362 const amrex::Real m2,
363 const amrex::Real m3,
364 const amrex::Real alpha,
365 const amrex::Real r0,
366 const amrex::Real dr0)
noexcept
369 const amrex::Real const_tiny = std::numeric_limits<amrex::Real>::epsilon();
373 al = alpha - m1 * r0;
376 al = al + amrex::max<amrex::Real>(0.0, -m1 * dr0) +
377 amrex::max<amrex::Real>(0.0, -m2) + amrex::max<amrex::Real>(0.0, -m3);
381 amrex::Real tmp = std::abs(m1) * dr0 + std::abs(m2) + std::abs(m3);
382 amrex::Real n1 = std::abs(m1) / tmp;
383 amrex::Real n2 = std::abs(m2) / tmp;
384 amrex::Real n3 = std::abs(m3) / tmp;
385 al = amrex::max<amrex::Real>(
386 0.0, amrex::min<amrex::Real>(
389 amrex::min<amrex::Real>(al, 1.0 - al);
392 amrex::Real b1 = amrex::min(n1 * dr0, n2);
393 amrex::Real b3 = amrex::max(n1 * dr0, n2);
400 }
else if (b2 > b3) {
406 amrex::Real b12 = b1 + b2;
410 amrex::Real vm1 = b1;
411 amrex::Real vm3 = b3;
412 amrex::Real vm2 = b2;
413 amrex::Real vm12 = b12;
419 v = a * a * a / (6.0 * vm1 * vm2 * vm3);
420 }
else if (a < vm2) {
421 v = a * (a - vm1) / (2.0 * vm2 * vm3) +
422 vm1 * vm1 / (6.0 * vm2 * vm3 + const_tiny);
423 }
else if (a < amrex::min(vm12, vm3)) {
424 v = (a * a * (3.0 * vm12 - a) + vm1 * vm1 * (vm1 - 3.0 * a) +
425 vm2 * vm2 * (vm2 - 3.0 * a)) /
426 (6.0 * vm1 * vm2 * vm3);
427 }
else if (vm3 < vm12) {
428 v = (a * a * (3.0 - 2.0 * a) + vm1 * vm1 * (vm1 - 3.0 * a) +
429 vm2 * vm2 * (vm2 - 3.0 * a) + vm3 * vm3 * (vm3 - 3.0 * a)) /
430 (6.0 * vm1 * vm2 * vm3);
432 v = (a - 0.5 * vm12) / vm3;