Skip to content

Commit e36a075

Browse files
nileshsawantnileshsawantmarchdf
authored
Simplify inflow BC and tweak the tests (#143)
Co-authored-by: nileshsawant <nileshsawant@github.com> Co-authored-by: Marc T. Henry de Frahan <marc.henrydefrahan@nrel.gov>
1 parent ebba107 commit e36a075

File tree

10 files changed

+75
-90
lines changed

10 files changed

+75
-90
lines changed

Docs/sphinx/InputFiles.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ Here is an example input file::
4848
lbm.save_streaming = 0
4949

5050
lbm.velocity_bc_type = "channel"
51-
velocity_bc_channel.u_ref = 0.1
51+
velocity_bc_channel.initial_density = 1.0
52+
velocity_bc_channel.Mach_ref = 0.01
53+
velocity_bc_channel.initial_temperature = 0.03
5254

5355
lbm.ic_type = "constant"
5456
ic_constant.density = 1.0

Source/BC.H

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ struct BCFill
194194
const amrex::IntVect& iv,
195195
const int q,
196196
const amrex::IntVect& ev,
197-
const int idir,
198-
const int ndir,
197+
const int /*idir*/,
198+
const int /*ndir*/,
199+
const amrex::Real& rho_bc,
199200
const amrex::RealVect& vel_bc,
200201
const amrex::Real& RT,
201-
amrex::Array4<amrex::Real> const& data,
202-
amrex::Real& rho_bc_out) const
202+
amrex::Array4<amrex::Real> const& data) const
203203
{
204204
// Prepare the ghost cell layer of f_ for
205205
// streaming due to a prescribed velocity. This
@@ -213,33 +213,8 @@ struct BCFill
213213
// In this case, a value for u, v, and w must be
214214
// specified, either hard coded or set by a
215215
// user-specified function
216-
amrex::Real rho_out = 0.0;
217-
amrex::Real rho_tan = 0.0;
218-
219-
const amrex::IntVect ivn(iv + ev);
220-
221-
// Build the 3-part rho calculation at the
222-
// (iv+ev) fluid cell
223-
for (int qq = 0; qq < constants::N_MICRO_STATES; qq++) {
224-
225-
const auto& evn_out = m_evs[qq];
226-
const int bounce_qq = m_bounce_dirs[qq];
227-
const auto& evn_in = m_evs[bounce_qq];
228-
229-
if (evn_in[idir] == -ndir) {
230-
rho_out += 2.0 * data(ivn + evn_out, bounce_qq);
231-
} else if (evn_in[idir] == 0) {
232-
rho_tan += 1.0 * data(ivn + evn_out, bounce_qq);
233-
}
234-
}
235-
236-
const amrex::Real rho_bc =
237-
(rho_out + rho_tan) / (1.0 - ndir * vel_bc[idir]);
238-
239216
data(iv, q) = set_equilibrium_value(
240217
rho_bc, vel_bc, RT, m_mesh_speed, m_weights[q], ev);
241-
242-
rho_bc_out = rho_bc;
243218
}
244219

245220
AMREX_GPU_DEVICE
@@ -423,41 +398,41 @@ struct BCFill
423398
temperature(1.0 / 3.0);
424399
amrex::Real gamma(5.0 / 3.0);
425400

426-
amrex::Real rho_bcout(1.0);
401+
amrex::Real rho_bc(0.0);
427402

428403
m_vel_bc_op(
429-
iv, idir, normal_dir, time, geom, vel_bc,
430-
specific_gas_constant, temperature, gamma);
404+
iv, idir, normal_dir, time, geom, rho_bc,
405+
vel_bc, specific_gas_constant, temperature,
406+
gamma);
431407

432408
if (m_is_energy_lattice) {
433-
rho_bcout = 1.0;
434-
435409
velocity_bc_g(
436-
iv, q, ev, idir, normal_dir, rho_bcout,
410+
iv, q, ev, idir, normal_dir, rho_bc,
437411
vel_bc, specific_gas_constant,
438412
temperature, gamma, data);
439413
} else {
440414
velocity_bc_f(
441-
iv, q, ev, idir, normal_dir, vel_bc,
415+
iv, q, ev, idir, normal_dir, rho_bc,
416+
vel_bc,
442417
specific_gas_constant * temperature,
443-
data, rho_bcout);
418+
data);
444419
}
445420

446421
} else if (m_bc_type[bc_idx] == PRESSURE) {
447422

448-
const amrex::Real rho_bc = 1.0;
449-
450423
amrex::RealVect vel_bc(
451424
AMREX_D_DECL(0.0, 0.0, 0.0));
452425
amrex::Real specific_gas_constant(1.0),
453426
temperature(1.0 / 3.0);
454427
amrex::Real gamma(5.0 / 3.0);
455428

456429
amrex::Real rho_bcout(1.0);
430+
amrex::Real rho_bc(1.0);
457431

458432
m_vel_bc_op(
459-
iv, idir, normal_dir, time, geom, vel_bc,
460-
specific_gas_constant, temperature, gamma);
433+
iv, idir, normal_dir, time, geom, rho_bc,
434+
vel_bc, specific_gas_constant, temperature,
435+
gamma);
461436

462437
if (m_is_energy_lattice) {
463438

Source/VelocityBC.H

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct NoOp
2222
const int /*ndir*/,
2323
const amrex::Real /*time*/,
2424
amrex::GeometryData const& /*geom*/,
25+
amrex::Real& /*rho*/,
2526
amrex::RealVect& /*vel*/,
2627
amrex::Real& /*R*/,
2728
amrex::Real& /*T*/,
@@ -45,6 +46,7 @@ struct Constant
4546
int dir{1};
4647
amrex::Real u0{0.0};
4748

49+
amrex::Real initial_density = 1.0;
4850
amrex::Real initial_temperature = 1.0 / 3.0;
4951
amrex::Real adiabatic_exponent = 5.0 / 3.0;
5052
const amrex::Real R_u = constants::AIR_MOLAR_MASS;
@@ -53,7 +55,7 @@ struct Constant
5355
std::sqrt(adiabatic_exponent * (R_u / m_bar) * initial_temperature);
5456

5557
int model_type = 1;
56-
amrex::Real Mach_0{0.005};
58+
amrex::Real Mach_ref{0.005};
5759

5860
AMREX_GPU_DEVICE
5961
void operator()(
@@ -62,11 +64,13 @@ struct Constant
6264
const int /*ndir*/,
6365
const amrex::Real /*time*/,
6466
amrex::GeometryData const& /*geom*/,
67+
amrex::Real& rho,
6568
amrex::RealVect& vel,
6669
amrex::Real& R,
6770
amrex::Real& T,
6871
amrex::Real& gamma) const
6972
{
73+
rho = initial_density;
7074
vel[dir] = u0;
7175
R = (R_u / m_bar);
7276
T = initial_temperature;
@@ -89,6 +93,7 @@ struct Channel
8993
{
9094
amrex::Real u_ref{1.0};
9195

96+
amrex::Real initial_density = 1.0;
9297
amrex::Real initial_temperature = 1.0 / 3.0;
9398
amrex::Real adiabatic_exponent = 5.0 / 3.0;
9499
const amrex::Real R_u = constants::AIR_MOLAR_MASS;
@@ -106,11 +111,13 @@ struct Channel
106111
const int /*ndir*/,
107112
const amrex::Real /*time*/,
108113
amrex::GeometryData const& geom,
114+
amrex::Real& rho,
109115
amrex::RealVect& vel,
110116
amrex::Real& R,
111117
amrex::Real& T,
112118
amrex::Real& gamma) const
113119
{
120+
rho = initial_density;
114121
const int* domhi = geom.Domain().hiVect();
115122
const amrex::Real c1 = iv[1] * (domhi[1] - iv[1]);
116123
const amrex::Real c2 =
@@ -139,6 +146,7 @@ struct Parabolic
139146
int tangential_dir{1};
140147
amrex::Real um{1.0};
141148

149+
amrex::Real initial_density = 1.0;
142150
amrex::Real initial_temperature = 1.0 / 3.0;
143151
amrex::Real adiabatic_exponent = 5.0 / 3.0;
144152

@@ -148,7 +156,7 @@ struct Parabolic
148156
std::sqrt(adiabatic_exponent * (R_u / m_bar) * initial_temperature);
149157

150158
int model_type = 1;
151-
amrex::Real mach_m{0.05};
159+
amrex::Real Mach_ref{0.05};
152160

153161
AMREX_GPU_DEVICE
154162
void operator()(
@@ -157,11 +165,13 @@ struct Parabolic
157165
const int /*ndir*/,
158166
const amrex::Real /*time*/,
159167
amrex::GeometryData const& geom,
168+
amrex::Real& rho,
160169
amrex::RealVect& vel,
161170
amrex::Real& R,
162171
amrex::Real& T,
163172
amrex::Real& gamma) const
164173
{
174+
rho = initial_density;
165175
const amrex::Real* prob_lo = geom.ProbLo();
166176
const amrex::Real* prob_hi = geom.ProbHi();
167177
const amrex::Real* dx = geom.CellSize();

Source/VelocityBC.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ Constant::Constant()
77
{
88
amrex::ParmParse pp("velocity_bc_constant");
99
pp.query("dir", m_op.dir);
10-
pp.query("u0", m_op.u0);
1110

1211
m_op.model_type = 1;
13-
pp.query("Mach_0", m_op.Mach_0);
12+
pp.query("Mach_ref", m_op.Mach_ref);
13+
pp.query("initial_density", m_op.initial_density);
1414
pp.query("initial_temperature", m_op.initial_temperature);
1515
pp.query("adiabatic_exponent", m_op.adiabatic_exponent);
1616
pp.query("mean_molecular_mass", m_op.m_bar);
1717
m_op.speed_of_sound_ref = std::sqrt(
1818
m_op.adiabatic_exponent * (m_op.R_u / m_op.m_bar) *
1919
m_op.initial_temperature);
20-
m_op.u0 = m_op.Mach_0 * m_op.speed_of_sound_ref;
20+
m_op.u0 = m_op.Mach_ref * m_op.speed_of_sound_ref;
2121
}
2222

2323
Channel::Channel()
2424
{
2525
amrex::ParmParse pp("velocity_bc_channel");
26-
pp.query("u_ref", m_op.u_ref);
2726

2827
m_op.model_type = 1;
2928
pp.query("Mach_ref", m_op.Mach_ref);
29+
pp.query("initial_density", m_op.initial_density);
3030
pp.query("initial_temperature", m_op.initial_temperature);
3131
pp.query("adiabatic_exponent", m_op.adiabatic_exponent);
3232
pp.query("mean_molecular_mass", m_op.m_bar);
@@ -41,17 +41,17 @@ Parabolic::Parabolic()
4141
amrex::ParmParse pp("velocity_bc_parabolic");
4242
pp.query("normal_dir", m_op.normal_dir);
4343
pp.query("tangential_dir", m_op.tangential_dir);
44-
pp.query("um", m_op.um);
4544

4645
m_op.model_type = 1;
47-
pp.query("Mach_m", m_op.mach_m);
46+
pp.query("Mach_ref", m_op.Mach_ref);
47+
pp.query("initial_density", m_op.initial_density);
4848
pp.query("initial_temperature", m_op.initial_temperature);
4949
pp.query("adiabatic_exponent", m_op.adiabatic_exponent);
5050
pp.query("mean_molecular_mass", m_op.m_bar);
5151
m_op.speed_of_sound_ref = std::sqrt(
5252
m_op.adiabatic_exponent * (m_op.R_u / m_op.m_bar) *
5353
m_op.initial_temperature);
54-
m_op.um = m_op.mach_m * m_op.speed_of_sound_ref;
54+
m_op.um = m_op.Mach_ref * m_op.speed_of_sound_ref;
5555
}
5656

5757
} // namespace lbm::bc

Tests/test_files/channel_cylinder/channel_cylinder.inp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
11
max_step = 1000
22

3-
# geometry parameters
43
geometry.prob_lo = 0.0 0.0 0.0
5-
geometry.prob_hi = 96.0 16.0 16.0
6-
geometry.is_periodic = 0 0 0
4+
geometry.prob_hi = 128.0 32.0 4.0
5+
geometry.is_periodic = 0 0 1
76

8-
# timestepping
9-
amr.n_cell = 96 16 16
7+
amr.n_cell = 128 32 4
108
amr.max_level = 0
11-
amr.max_grid_size = 8
12-
amr.plot_int = 10
13-
amr.chk_int = 10
9+
amr.max_grid_size = 4
10+
amr.plot_int = 100
11+
amr.chk_int = 1000
1412

15-
lbm.bc_lo = 2 1 1
16-
lbm.bc_hi = 3 1 1
13+
lbm.bc_lo = 2 1 0
14+
lbm.bc_hi = 5 1 0
1715
lbm.dx_outer = 0.5
1816
lbm.dt_outer = 0.5
19-
#lbm.reynolds = 10.23
20-
lbm.nu = 0.01733333333333333
21-
lbm.save_streaming = 1
17+
lbm.nu = 0.0050
18+
lbm.save_streaming = 0
2219

2320
lbm.velocity_bc_type = "channel"
24-
velocity_bc_channel.u_ref = 0.1
21+
velocity_bc_channel.initial_density = 1.0
22+
velocity_bc_channel.Mach_ref = 0.01
23+
velocity_bc_channel.initial_temperature = 0.03
2524

2625
lbm.ic_type = "constant"
2726
ic_constant.density = 1.0
28-
ic_constant.velocity = 0.0 0.0 0.0
27+
ic_constant.initial_temperature = 0.03
28+
ic_constant.mach_components = 0.0 0.0 0.0
2929

30-
#eb2.geom_type = "all_regular"
3130
eb2.geom_type = "cylinder"
3231
eb2.cylinder_radius = 2.0
3332
eb2.cylinder_center = 32.0 8.0 8.0
3433
eb2.cylinder_has_fluid_inside = 0
3534
eb2.cylinder_height = 256.0
3635
eb2.cylinder_direction = 1
3736

38-
# eb2.geom_type = "sphere"
39-
# eb2.sphere_radius = 2.0
40-
# eb2.sphere_center = 32.0 8.0 8.0
41-
# eb2.sphere_has_fluid_inside = 0
42-
4337
amrex.fpe_trap_invalid = 1
4438
amrex.fpe_trap_zero = 1
4539
amrex.fpe_trap_overflow = 1
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1-
max_step = 1000
1+
max_step = 10000
22

33
geometry.prob_lo = 0.0 0.0 0.0
4-
geometry.prob_hi = 1.0 1.0 1.0
5-
geometry.is_periodic = 0 0 0
4+
geometry.prob_hi = 128.0 32.0 4.0
5+
geometry.is_periodic = 0 0 1
66

7-
amr.n_cell = 32 32 32
7+
amr.n_cell = 128 32 4
88
amr.max_level = 0
9-
amr.max_grid_size = 16
10-
amr.plot_int = 10
11-
amr.chk_int = 10
9+
amr.max_grid_size = 4
10+
amr.plot_int = 100
11+
amr.chk_int = 1000
1212

13-
lbm.bc_lo = 2 1 1
14-
lbm.bc_hi = 5 1 1
13+
lbm.bc_lo = 2 1 0
14+
lbm.bc_hi = 5 1 0
1515
lbm.dx_outer = 0.5
1616
lbm.dt_outer = 0.5
17-
#lbm.reynolds = 10.23
18-
lbm.nu = 0.20
17+
lbm.nu = 0.0050
1918
lbm.save_streaming = 0
2019

2120
lbm.velocity_bc_type = "channel"
22-
velocity_bc_channel.Mach_ref = 0.001
21+
velocity_bc_channel.initial_density = 1.0
22+
velocity_bc_channel.Mach_ref = 0.01
23+
velocity_bc_channel.initial_temperature = 0.03
2324

2425
lbm.ic_type = "constant"
2526
ic_constant.density = 1.0
26-
ic_constant.mach_components = 0.002 0.0 0.0
27+
ic_constant.initial_temperature = 0.03
28+
ic_constant.mach_components = 0.0 0.0 0.0
2729

2830
eb2.geom_type="all_regular"
2931

3032
amrex.fpe_trap_invalid = 1
3133
amrex.fpe_trap_zero = 1
32-
amrex.fpe_trap_overflow = 1
34+
amrex.fpe_trap_overflow = 1
35+
amrex.the_arena_is_managed = 0
36+
amrex.abort_on_out_of_gpu_memory = 1

Tests/test_files/pine_box/pine_box.inp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ lbm.save_streaming = 1
2222

2323
lbm.velocity_bc_type = "constant"
2424
velocity_bc_constant.dir = 2
25-
velocity_bc_constant.u0 = 0.002
25+
ic_constant.mach_components = 0.002 0.0 0.0
2626

2727
lbm.ic_type = "constant"
2828
ic_constant.density = 1.0

Tests/test_files/single_cylinder/single_cylinder.inp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ lbm.save_streaming = 0
2323
lbm.compute_forces = 1
2424

2525
lbm.velocity_bc_type = "parabolic"
26-
velocity_bc_parabolic.um = 0.015
26+
velocity_bc_parabolic.Mach_ref = 0.015
2727
velocity_bc_parabolic.normal_dir = 0
2828
velocity_bc_parabolic.tangential_dir = 1
2929

0 commit comments

Comments
 (0)