23 amrex::Array4<amrex::Real const>
const& volfrac,
26 amrex::Real& mz)
noexcept
29 volfrac(i - 1, j - 1, k - 1) + volfrac(i - 1, j - 1, k + 1) +
30 volfrac(i - 1, j + 1, k - 1) + volfrac(i - 1, j + 1, k + 1) +
31 2.0 * (volfrac(i - 1, j - 1, k) + volfrac(i - 1, j + 1, k) +
32 volfrac(i - 1, j, k - 1) + volfrac(i - 1, j, k + 1)) +
33 4.0 * volfrac(i - 1, j, k);
35 volfrac(i + 1, j - 1, k - 1) + volfrac(i + 1, j - 1, k + 1) +
36 volfrac(i + 1, j + 1, k - 1) + volfrac(i + 1, j + 1, k + 1) +
37 2.0 * (volfrac(i + 1, j - 1, k) + volfrac(i + 1, j + 1, k) +
38 volfrac(i + 1, j, k - 1) + volfrac(i + 1, j, k + 1)) +
39 4.0 * volfrac(i + 1, j, k);
42 mm1 = volfrac(i - 1, j - 1, k - 1) + volfrac(i - 1, j - 1, k + 1) +
43 volfrac(i + 1, j - 1, k - 1) + volfrac(i + 1, j - 1, k + 1) +
44 2.0 * (volfrac(i - 1, j - 1, k) + volfrac(i + 1, j - 1, k) +
45 volfrac(i, j - 1, k - 1) + volfrac(i, j - 1, k + 1)) +
46 4.0 * volfrac(i, j - 1, k);
47 mm2 = volfrac(i - 1, j + 1, k - 1) + volfrac(i - 1, j + 1, k + 1) +
48 volfrac(i + 1, j + 1, k - 1) + volfrac(i + 1, j + 1, k + 1) +
49 2.0 * (volfrac(i - 1, j + 1, k) + volfrac(i + 1, j + 1, k) +
50 volfrac(i, j + 1, k - 1) + volfrac(i, j + 1, k + 1)) +
51 4.0 * volfrac(i, j + 1, k);
54 mm1 = volfrac(i - 1, j - 1, k - 1) + volfrac(i - 1, j + 1, k - 1) +
55 volfrac(i + 1, j - 1, k - 1) + volfrac(i + 1, j + 1, k - 1) +
56 2.0 * (volfrac(i - 1, j, k - 1) + volfrac(i + 1, j, k - 1) +
57 volfrac(i, j - 1, k - 1) + volfrac(i, j + 1, k - 1)) +
58 4.0 * volfrac(i, j, k - 1);
59 mm2 = volfrac(i - 1, j - 1, k + 1) + volfrac(i - 1, j + 1, k + 1) +
60 volfrac(i + 1, j - 1, k + 1) + volfrac(i + 1, j + 1, k + 1) +
61 2.0 * (volfrac(i - 1, j, k + 1) + volfrac(i + 1, j, k + 1) +
62 volfrac(i, j - 1, k + 1) + volfrac(i, j + 1, k + 1)) +
63 4.0 * volfrac(i, j, k + 1);
75 amrex::Array4<amrex::Real const>
const& volfrac,
78 amrex::Real& mz)
noexcept
81 const int im1 = ibdy == -1 ? i : i - 1;
82 const int jm1 = jbdy == -1 ? j : j - 1;
83 const int km1 = kbdy == -1 ? k : k - 1;
84 const int ip1 = ibdy == +1 ? i : i + 1;
85 const int jp1 = jbdy == +1 ? j : j + 1;
86 const int kp1 = kbdy == +1 ? k : k + 1;
88 amrex::Real mm1 = volfrac(im1, jm1, km1) + volfrac(im1, jm1, kp1) +
89 volfrac(im1, jp1, km1) + volfrac(im1, jp1, kp1) +
90 2.0 * (volfrac(im1, jm1, k) + volfrac(im1, jp1, k) +
91 volfrac(im1, j, km1) + volfrac(im1, j, kp1)) +
92 4.0 * volfrac(im1, j, k);
93 amrex::Real mm2 = volfrac(ip1, jm1, km1) + volfrac(ip1, jm1, kp1) +
94 volfrac(ip1, jp1, km1) + volfrac(ip1, jp1, kp1) +
95 2.0 * (volfrac(ip1, jm1, k) + volfrac(ip1, jp1, k) +
96 volfrac(ip1, j, km1) + volfrac(ip1, j, kp1)) +
97 4.0 * volfrac(ip1, j, k);
100 mm1 = volfrac(im1, jm1, km1) + volfrac(im1, jm1, kp1) +
101 volfrac(ip1, jm1, km1) + volfrac(ip1, jm1, kp1) +
102 2.0 * (volfrac(im1, jm1, k) + volfrac(ip1, jm1, k) +
103 volfrac(i, jm1, km1) + volfrac(i, jm1, kp1)) +
104 4.0 * volfrac(i, jm1, k);
105 mm2 = volfrac(im1, jp1, km1) + volfrac(im1, jp1, kp1) +
106 volfrac(ip1, jp1, km1) + volfrac(ip1, jp1, kp1) +
107 2.0 * (volfrac(im1, jp1, k) + volfrac(ip1, jp1, k) +
108 volfrac(i, jp1, km1) + volfrac(i, jp1, kp1)) +
109 4.0 * volfrac(i, jp1, k);
112 mm1 = volfrac(im1, jm1, km1) + volfrac(im1, jp1, km1) +
113 volfrac(ip1, jm1, km1) + volfrac(ip1, jp1, km1) +
114 2.0 * (volfrac(im1, j, km1) + volfrac(ip1, j, km1) +
115 volfrac(i, jm1, km1) + volfrac(i, jp1, km1)) +
116 4.0 * volfrac(i, j, km1);
117 mm2 = volfrac(im1, jm1, kp1) + volfrac(im1, jp1, kp1) +
118 volfrac(ip1, jm1, kp1) + volfrac(ip1, jp1, kp1) +
119 2.0 * (volfrac(im1, j, kp1) + volfrac(ip1, j, kp1) +
120 volfrac(i, jm1, kp1) + volfrac(i, jp1, kp1)) +
121 4.0 * volfrac(i, j, kp1);
129 amrex::Array4<amrex::Real const>
const& volfrac,
132 amrex::Real& mz)
noexcept
134 amrex::Array2D<amrex::Real, 0, AMREX_SPACEDIM + 1, 0, AMREX_SPACEDIM> m;
137 amrex::Real m1 = volfrac(i - 1, j, k - 1) + volfrac(i - 1, j, k + 1) +
138 volfrac(i - 1, j - 1, k) + volfrac(i - 1, j + 1, k) +
139 volfrac(i - 1, j, k);
140 amrex::Real m2 = volfrac(i + 1, j, k - 1) + volfrac(i + 1, j, k + 1) +
141 volfrac(i + 1, j - 1, k) + volfrac(i + 1, j + 1, k) +
142 volfrac(i + 1, j, k);
144 m(0, 0) = (m1 > m2) ? 1.0 : -1.0;
146 m1 = volfrac(i - 1, j - 1, k) + volfrac(i + 1, j - 1, k) +
147 volfrac(i, j - 1, k);
148 m2 = volfrac(i - 1, j + 1, k) + volfrac(i + 1, j + 1, k) +
149 volfrac(i, j + 1, k);
150 m(0, 1) = 0.5 * (m1 - m2);
152 m1 = volfrac(i - 1, j, k - 1) + volfrac(i + 1, j, k - 1) +
153 volfrac(i, j, k - 1);
154 m2 = volfrac(i - 1, j, k + 1) + volfrac(i + 1, j, k + 1) +
155 volfrac(i, j, k + 1);
156 m(0, 2) = 0.5 * (m1 - m2);
161 m1 = volfrac(i - 1, j - 1, k) + volfrac(i - 1, j + 1, k) +
162 volfrac(i - 1, j, k);
163 m2 = volfrac(i + 1, j - 1, k) + volfrac(i + 1, j + 1, k) +
164 volfrac(i + 1, j, k);
165 m(1, 0) = 0.5 * (m1 - m2);
167 m1 = volfrac(i, j - 1, k - 1) + volfrac(i, j - 1, k + 1) +
168 volfrac(i + 1, j - 1, k) + volfrac(i - 1, j - 1, k) +
169 volfrac(i, j - 1, k);
170 m2 = volfrac(i, j + 1, k - 1) + volfrac(i, j + 1, k + 1) +
171 volfrac(i + 1, j + 1, k) + volfrac(i - 1, j + 1, k) +
172 volfrac(i, j + 1, k);
174 m(1, 1) = (m1 > m2) ? 1.0 : -1.0;
176 m1 = volfrac(i, j - 1, k - 1) + volfrac(i, j, k - 1) +
177 volfrac(i, j + 1, k - 1);
178 m2 = volfrac(i, j - 1, k + 1) + volfrac(i, j, k + 1) +
179 volfrac(i, j + 1, k + 1);
180 m(1, 2) = 0.5 * (m1 - m2);
185 m1 = volfrac(i - 1, j, k - 1) + volfrac(i - 1, j, k + 1) +
186 volfrac(i - 1, j, k);
187 m2 = volfrac(i + 1, j, k - 1) + volfrac(i + 1, j, k + 1) +
188 volfrac(i + 1, j, k);
189 m(2, 0) = 0.5 * (m1 - m2);
191 m1 = volfrac(i, j - 1, k - 1) + volfrac(i, j - 1, k + 1) +
192 volfrac(i, j - 1, k);
193 m2 = volfrac(i, j + 1, k - 1) + volfrac(i, j + 1, k + 1) +
194 volfrac(i, j + 1, k);
195 m(2, 1) = 0.5 * (m1 - m2);
197 m1 = volfrac(i - 1, j, k - 1) + volfrac(i + 1, j, k - 1) +
198 volfrac(i, j - 1, k - 1) + volfrac(i, j + 1, k - 1) +
199 volfrac(i, j, k - 1);
200 m2 = volfrac(i - 1, j, k + 1) + volfrac(i + 1, j, k + 1) +
201 volfrac(i, j - 1, k + 1) + volfrac(i, j + 1, k + 1) +
202 volfrac(i, j, k + 1);
204 m(2, 2) = (m1 > m2) ? 1.0 : -1.0;
207 amrex::Real t0, t1, t2;
209 t0 = std::abs(m(0, 0)) + std::abs(m(0, 1)) + std::abs(m(0, 2));
210 m(0, 0) = m(0, 0) / t0;
211 m(0, 1) = m(0, 1) / t0;
212 m(0, 2) = m(0, 2) / t0;
214 t0 = std::abs(m(1, 0)) + std::abs(m(1, 1)) + std::abs(m(1, 2));
215 m(1, 0) = m(1, 0) / t0;
216 m(1, 1) = m(1, 1) / t0;
217 m(1, 2) = m(1, 2) / t0;
219 t0 = std::abs(m(2, 0)) + std::abs(m(2, 1)) + std::abs(m(2, 2));
220 m(2, 0) = m(2, 0) / t0;
221 m(2, 1) = m(2, 1) / t0;
222 m(2, 2) = m(2, 2) / t0;
225 t0 = std::abs(m(0, 0));
226 t1 = std::abs(m(1, 1));
227 t2 = std::abs(m(2, 2));
241 i, j, k, volfrac, m(3, 0), m(3, 1), m(3, 2));
243 constexpr amrex::Real tiny = 1e-20;
244 t0 = std::abs(m(3, 0)) + std::abs(m(3, 1)) + std::abs(m(3, 2)) + tiny;
245 m(3, 0) = m(3, 0) / t0;
246 m(3, 1) = m(3, 1) / t0;
247 m(3, 2) = m(3, 2) / t0;
250 t0 = std::abs(m(3, 0));
251 t1 = std::abs(m(3, 1));
252 t2 = std::abs(m(3, 2));
260 if (std::abs(m(cn, cn)) > t0 && t0 > 0.0) {
275 const amrex::Real b1,
276 const amrex::Real b2,
277 const amrex::Real b3,
278 const amrex::Real volF)
noexcept
280 using namespace amrex;
282 amrex::Real const_tiny = std::numeric_limits<amrex::Real>::epsilon();
288 amrex::Real m1 = amrex::min(b1, b2);
289 amrex::Real m3 = amrex::max(b1, b2);
297 }
else if (m2 > m3) {
303 amrex::Real m12 = m1 + m2;
304 amrex::Real pr = amrex::max<amrex::Real>(6. * m1 * m2 * m3, const_tiny);
305 amrex::Real V1 = m1 * m1 * m1 / pr;
306 amrex::Real V2 = V1 + 0.5 * (m2 - m1) / m3;
311 V3 = (m3 * m3 * (3.0 * m12 - m3) + m1 * m1 * (m1 - 3.0 * m3) +
312 m2 * m2 * (m2 - 3.0 * m3)) /
319 amrex::Real ch = amrex::min<amrex::Real>(volF, 1.0 - volF);
321 amrex::Real alpha, p, q, p12, teta, cs;
323 alpha = std::cbrt(pr * ch);
324 }
else if (ch < V2) {
325 alpha = 0.50 * (m1 + std::sqrt(m1 * m1 + 8.0 * m2 * m3 * (ch - V1)));
326 }
else if (ch < V3) {
328 q = 1.5 * m1 * m2 * (m12 - 2.0 * m3 * ch);
330 teta = std::acos(q / (p * p12 + 1e-20)) / 3.0;
332 alpha = p12 * (std::sqrt(3.0 * (1.0 - cs * cs)) - cs) + m12;
333 }
else if (m12 < m3) {
334 alpha = m3 * ch + 0.5 * mm;
336 p = m1 * (m2 + m3) + m2 * m3 - 0.25;
337 q = 1.5 * m1 * m2 * m3 * (0.5 - ch);
339 teta = std::acos(q / (p * p12 + 1e-20)) / 3.0;
341 alpha = p12 * (std::sqrt(3.0 * (1.0 - cs * cs)) - cs) + 0.5;
359AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
cut_volume(
360 const amrex::Real m1,
361 const amrex::Real m2,
362 const amrex::Real m3,
363 const amrex::Real alpha,
364 const amrex::Real r0,
365 const amrex::Real dr0)
noexcept
368 const amrex::Real const_tiny = std::numeric_limits<amrex::Real>::epsilon();
372 al = alpha - m1 * r0;
375 al = al + amrex::max<amrex::Real>(0.0, -m1 * dr0) +
376 amrex::max<amrex::Real>(0.0, -m2) + amrex::max<amrex::Real>(0.0, -m3);
380 amrex::Real tmp = std::abs(m1) * dr0 + std::abs(m2) + std::abs(m3);
381 amrex::Real n1 = std::abs(m1) / tmp;
382 amrex::Real n2 = std::abs(m2) / tmp;
383 amrex::Real n3 = std::abs(m3) / tmp;
384 al = amrex::max<amrex::Real>(
385 0.0, amrex::min<amrex::Real>(
388 amrex::min<amrex::Real>(al, 1.0 - al);
391 amrex::Real b1 = amrex::min(n1 * dr0, n2);
392 amrex::Real b3 = amrex::max(n1 * dr0, n2);
399 }
else if (b2 > b3) {
405 amrex::Real b12 = b1 + b2;
409 amrex::Real vm1 = b1;
410 amrex::Real vm3 = b3;
411 amrex::Real vm2 = b2;
412 amrex::Real vm12 = b12;
418 v = a * a * a / (6.0 * vm1 * vm2 * vm3);
419 }
else if (a < vm2) {
420 v = a * (a - vm1) / (2.0 * vm2 * vm3) +
421 vm1 * vm1 / (6.0 * vm2 * vm3 + const_tiny);
422 }
else if (a < amrex::min(vm12, vm3)) {
423 v = (a * a * (3.0 * vm12 - a) + vm1 * vm1 * (vm1 - 3.0 * a) +
424 vm2 * vm2 * (vm2 - 3.0 * a)) /
425 (6.0 * vm1 * vm2 * vm3);
426 }
else if (vm3 < vm12) {
427 v = (a * a * (3.0 - 2.0 * a) + vm1 * vm1 * (vm1 - 3.0 * a) +
428 vm2 * vm2 * (vm2 - 3.0 * a) + vm3 * vm3 * (vm3 - 3.0 * a)) /
429 (6.0 * vm1 * vm2 * vm3);
431 v = (a - 0.5 * vm12) / vm3;