/home/runner/work/kynema-sgf/kynema-sgf/src/equation_systems/vof/split_advection.H Source File

Kynema-SGF API: /home/runner/work/kynema-sgf/kynema-sgf/src/equation_systems/vof/split_advection.H Source File
Kynema-SGF API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
split_advection.H
Go to the documentation of this file.
1#ifndef SPLIT_ADVECTION_H
2#define SPLIT_ADVECTION_H
3
4#include <cmath>
7#include "AMReX_FArrayBox.H"
8#include "AMReX_BCRec.H"
9#include "AMReX_REAL.H"
10
11using namespace amrex::literals;
12
13namespace kynema_sgf::multiphase {
14
15AMREX_GPU_DEVICE AMREX_FORCE_INLINE void eulerian_implicit(
16 const int i,
17 const int j,
18 const int k,
19 const int dir,
20 const amrex::Real dtdx,
21 const amrex::Real velL,
22 const amrex::Real velR,
23 const amrex::Real mx,
24 const amrex::Real my,
25 const amrex::Real mz,
26 const amrex::Real alpha,
27 amrex::Array4<amrex::Real const> const& volfrac,
28 amrex::Array4<amrex::Real> const& vofL,
29 amrex::Array4<amrex::Real> const& vofR)
30{
31 amrex::Real x0, deltax;
32 amrex::Real aL = velL * dtdx;
33 amrex::Real aR = velR * dtdx;
34
35 vofL(i, j, k) = 0.0_rt;
36 vofR(i, j, k) = 0.0_rt;
37
38 if (std::abs(volfrac(i, j, k) - 1.0_rt) <= constants::VOF_TOL) {
39 if (aL < 0.0_rt) {
40 vofL(i, j, k) = 1.0_rt;
41 }
42 if (aR > 0.0_rt) {
43 vofR(i, j, k) = 1.0_rt;
44 }
45 } else if (volfrac(i, j, k) > constants::VOF_TOL) {
46 // Eulerian advection
47 x0 = 0.0_rt;
48 if (dir == 0) {
49 if (aL < 0.0_rt) {
50 deltax = -aL;
51 vofL(i, j, k) = cut_volume(mx, my, mz, alpha, x0, deltax);
52 }
53 if (aR > 0.0_rt) {
54 x0 = 1.0_rt - aR;
55 deltax = aR;
56 vofR(i, j, k) = cut_volume(mx, my, mz, alpha, x0, deltax);
57 }
58 } else if (dir == 1) {
59 if (aL < 0.0_rt) {
60 deltax = -aL;
61 vofL(i, j, k) = cut_volume(my, mz, mx, alpha, x0, deltax);
62 }
63 if (aR > 0.0_rt) {
64 x0 = 1.0_rt - aR;
65 deltax = aR;
66 vofR(i, j, k) = cut_volume(my, mz, mx, alpha, x0, deltax);
67 }
68 } else if (dir == 2) {
69 if (aL < 0.0_rt) {
70 deltax = -aL;
71 vofL(i, j, k) = cut_volume(mz, mx, my, alpha, x0, deltax);
72 }
73 if (aR > 0.0_rt) {
74 x0 = 1.0_rt - aR;
75 deltax = aR;
76 vofR(i, j, k) = cut_volume(mz, mx, my, alpha, x0, deltax);
77 }
78 }
79 }
80}
81
82AMREX_GPU_DEVICE AMREX_FORCE_INLINE void balance_eulerian_fluxes(
83 const int i,
84 const int j,
85 const int k,
86 const int dir,
87 const amrex::Real dxi,
88 const amrex::Real velL,
89 const amrex::Real velR,
90 amrex::Array4<amrex::Real> const& volfrac,
91 amrex::Array4<amrex::Real const> const& fluxF,
92 amrex::Array4<amrex::Real const> const& fluxC)
93{
94
95 if (dir == 0) {
96 volfrac(i, j, k) += ((fluxF(i, j, k) - fluxF(i + 1, j, k)) * dxi) +
97 (fluxC(i, j, k) * (velR - velL));
98 } else if (dir == 1) {
99 volfrac(i, j, k) += ((fluxF(i, j, k) - fluxF(i, j + 1, k)) * dxi) +
100 (fluxC(i, j, k) * (velR - velL));
101 } else if (dir == 2) {
102 volfrac(i, j, k) += ((fluxF(i, j, k) - fluxF(i, j, k + 1)) * dxi) +
103 (fluxC(i, j, k) * (velR - velL));
104 }
105 // Do clipping
106 volfrac(i, j, k) = amrex::max<amrex::Real>(
107 0.0_rt, amrex::min<amrex::Real>(1.0_rt, volfrac(i, j, k)));
108}
109
110AMREX_GPU_DEVICE AMREX_FORCE_INLINE void fluxes_bc_save(
111 const int i,
112 const int j,
113 const int k,
114 const int dir,
115 const amrex::Real disp,
116 amrex::Array4<amrex::Real> const& f_f,
117 amrex::Array4<amrex::Real> const& vofL,
118 amrex::Array4<amrex::Real> const& vofR,
119 amrex::Array4<amrex::Real> const& advalpha_f,
120 amrex::GpuArray<BC, AMREX_SPACEDIM * 2> BCs,
121 const int domlo,
122 const int domhi)
123{
124 auto bclo = BCs[amrex::Orientation(dir, amrex::Orientation::low)];
125 auto bchi = BCs[amrex::Orientation(dir, amrex::Orientation::high)];
126
127 if (dir == 0) {
128 // For wall BCs, do not allow flow into or out of domain
129 if (bclo == BC::no_slip_wall || bclo == BC::slip_wall ||
130 bclo == BC::wall_model || bclo == BC::symmetric_wall) {
131 if (i == domlo) {
132 vofR(domlo - 1, j, k) = 0.0_rt;
133 vofL(domlo, j, k) = 0.0_rt;
134 }
135 }
136
137 if (bchi == BC::no_slip_wall || bchi == BC::slip_wall ||
138 bchi == BC::wall_model || bchi == BC::symmetric_wall) {
139 if (i == domhi + 1) {
140 vofL(domhi + 1, j, k) = 0.0_rt;
141 vofR(domhi, j, k) = 0.0_rt;
142 }
143 }
144 // Store volume fraction of each flux and multiply by integral
145 // displacement to get the flux term
146 advalpha_f(i, j, k) = vofR(i - 1, j, k) + vofL(i, j, k);
147 f_f(i, j, k) = advalpha_f(i, j, k) * disp;
148 // Note: only one of vofR or vofL can be nonzero, due to the nature of
149 // eulerian_implicit(), so this sum is not for the sake of accumulation
150 } else if (dir == 1) {
151 if (bclo == BC::no_slip_wall || bclo == BC::slip_wall ||
152 bclo == BC::wall_model || bclo == BC::symmetric_wall) {
153 if (j == domlo) {
154 vofR(i, domlo - 1, k) = 0.0_rt;
155 vofL(i, domlo, k) = 0.0_rt;
156 }
157 }
158 if (bchi == BC::no_slip_wall || bchi == BC::slip_wall ||
159 bchi == BC::wall_model || bchi == BC::symmetric_wall) {
160 if (j == domhi + 1) {
161 vofL(i, domhi + 1, k) = 0.0_rt;
162 vofR(i, domhi, k) = 0.0_rt;
163 }
164 }
165 advalpha_f(i, j, k) = vofR(i, j - 1, k) + vofL(i, j, k);
166 f_f(i, j, k) = advalpha_f(i, j, k) * disp;
167 } else if (dir == 2) {
168 if (bclo == BC::no_slip_wall || bclo == BC::slip_wall ||
169 bclo == BC::wall_model || bclo == BC::symmetric_wall) {
170 if (k == domlo) {
171 vofR(i, j, domlo - 1) = 0.0_rt;
172 vofL(i, j, domlo) = 0.0_rt;
173 }
174 }
175 if (bchi == BC::no_slip_wall || bchi == BC::slip_wall ||
176 bchi == BC::wall_model || bchi == BC::symmetric_wall) {
177 if (k == domhi + 1) {
178 vofL(i, j, domhi + 1) = 0.0_rt;
179 vofR(i, j, domhi) = 0.0_rt;
180 }
181 }
182 advalpha_f(i, j, k) = vofR(i, j, k - 1) + vofL(i, j, k);
183 f_f(i, j, k) = advalpha_f(i, j, k) * disp;
184 }
185}
186
187AMREX_GPU_DEVICE AMREX_FORCE_INLINE void c_mask(
188 const int i,
189 const int j,
190 const int k,
191 amrex::Array4<amrex::Real> const& volfrac,
192 amrex::Array4<amrex::Real> const& volfrac_masked)
193{
194 if (volfrac(i, j, k) > 0.5_rt) {
195 volfrac_masked(i, j, k) = 1.0_rt;
196 } else {
197 volfrac_masked(i, j, k) = 0.0_rt;
198 }
199}
200
201AMREX_GPU_DEVICE AMREX_FORCE_INLINE void remove_vof_debris(
202 const int i,
203 const int j,
204 const int k,
205 amrex::Array4<amrex::Real> const& volfrac)
206{
207 amrex::Real small_vof = 1.0e-6_rt;
208 amrex::Real volFxL = volfrac(i - 1, j, k);
209 amrex::Real volFxR = volfrac(i + 1, j, k);
210 amrex::Real volFyL = volfrac(i, j - 1, k);
211 amrex::Real volFyR = volfrac(i, j + 1, k);
212 amrex::Real volFzL = volfrac(i, j, k - 1);
213 amrex::Real volFzR = volfrac(i, j, k + 1);
214
215 if (volfrac(i, j, k) > 0.0_rt && volFxL < small_vof && volFxR < small_vof &&
216 volFyL < small_vof && volFyR < small_vof && volFzL < small_vof &&
217 volFzR < small_vof) {
218 volfrac(i, j, k) = 0.0_rt;
219 }
220}
221
222} // namespace kynema_sgf::multiphase
223#endif // SPLIT_ADVECTION.H
@ slip_wall
Definition incflo_enums.H:19
@ wall_model
Definition incflo_enums.H:20
@ symmetric_wall
Definition incflo_enums.H:24
@ no_slip_wall
Definition incflo_enums.H:18
static constexpr amrex::Real VOF_TOL
Tolerance for vof determining presence of liquid.
Definition constants.H:34
Definition height_functions.H:8
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void fluxes_bc_save(const int i, const int j, const int k, const int dir, const amrex::Real disp, amrex::Array4< amrex::Real > const &f_f, amrex::Array4< amrex::Real > const &vofL, amrex::Array4< amrex::Real > const &vofR, amrex::Array4< amrex::Real > const &advalpha_f, amrex::GpuArray< BC, AMREX_SPACEDIM *2 > BCs, const int domlo, const int domhi)
Definition split_advection.H:110
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void eulerian_implicit(const int i, const int j, const int k, const int dir, const amrex::Real dtdx, const amrex::Real velL, const amrex::Real velR, const amrex::Real mx, const amrex::Real my, const amrex::Real mz, const amrex::Real alpha, amrex::Array4< amrex::Real const > const &volfrac, amrex::Array4< amrex::Real > const &vofL, amrex::Array4< amrex::Real > const &vofR)
Definition split_advection.H:15
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void remove_vof_debris(const int i, const int j, const int k, amrex::Array4< amrex::Real > const &volfrac)
Definition split_advection.H:201
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real cut_volume(const amrex::Real m1, const amrex::Real m2, const amrex::Real m3, const amrex::Real alpha, const amrex::Real r0, const amrex::Real dr0)
Definition volume_fractions.H:367
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void balance_eulerian_fluxes(const int i, const int j, const int k, const int dir, const amrex::Real dxi, const amrex::Real velL, const amrex::Real velR, amrex::Array4< amrex::Real > const &volfrac, amrex::Array4< amrex::Real const > const &fluxF, amrex::Array4< amrex::Real const > const &fluxC)
Definition split_advection.H:82
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void c_mask(const int i, const int j, const int k, amrex::Array4< amrex::Real > const &volfrac, amrex::Array4< amrex::Real > const &volfrac_masked)
Definition split_advection.H:187