Skip to content

Commit 2fbd345

Browse files
authored
More multiphase overset improvements (#1182)
* proper use of refRatio * remove pressure initialization from sloshing tank * correct approach on first timestep * removing unused function declarations
1 parent 3e9194c commit 2fbd345

File tree

4 files changed

+33
-81
lines changed

4 files changed

+33
-81
lines changed

amr-wind/incflo.H

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ public:
143143
amrex::Real scaling_factor,
144144
bool incremental);
145145

146-
void UpdateGradP(
147-
amrex::Vector<amrex::MultiFab const*> density,
148-
amrex::Real time,
149-
amrex::Real scaling_factor);
150-
151146
//! Initialize Physics instances as well as PDEs (include turbulence models)
152147
void init_physics_and_pde();
153148

@@ -204,7 +199,6 @@ private:
204199
//
205200
///////////////////////////////////////////////////////////////////////////
206201

207-
void set_background_pressure();
208202
void ReadParameters();
209203
void InitialProjection();
210204
void InitialIterations();

amr-wind/overset/OversetOps.cpp

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ void OversetOps::initialize(CFDSim& sim)
3030

3131
pp.query("verbose", m_verbose);
3232

33-
m_vof_exists = (*m_sim_ptr).repo().field_exists("vof");
33+
m_vof_exists = m_sim_ptr->repo().field_exists("vof");
3434
if (m_vof_exists) {
35-
m_mphase = &(*m_sim_ptr).physics_manager().get<MultiPhase>();
35+
m_mphase = &m_sim_ptr->physics_manager().get<MultiPhase>();
3636

3737
// Check combination of pressure options
3838
if (m_mphase->perturb_pressure() &&
@@ -51,7 +51,7 @@ void OversetOps::initialize(CFDSim& sim)
5151
}
5252
}
5353
if (m_replace_gradp_postsolve) {
54-
m_gp_copy = &(*m_sim_ptr).repo().declare_field("gp_copy", 3);
54+
m_gp_copy = &m_sim_ptr->repo().declare_field("gp_copy", 3);
5555
}
5656

5757
parameter_output();
@@ -60,6 +60,14 @@ void OversetOps::initialize(CFDSim& sim)
6060
void OversetOps::pre_advance_work()
6161
{
6262
if (!(m_vof_exists && m_use_hydrostatic_gradp)) {
63+
if (m_mphase != nullptr) {
64+
// Avoid modifying pressure upon initialization, assume pressure = 0
65+
if (m_mphase->perturb_pressure() &&
66+
m_sim_ptr->time().current_time() > 0.0) {
67+
// Modify to be consistent with internal source terms
68+
form_perturb_pressure();
69+
}
70+
}
6371
// Update pressure gradient using updated overset pressure field
6472
update_gradp();
6573
}
@@ -71,20 +79,15 @@ void OversetOps::pre_advance_work()
7179
// Use hydrostatic pressure gradient
7280
set_hydrostatic_gradp();
7381
} else {
74-
if (m_mphase->perturb_pressure()) {
75-
// Modify to be consistent with internal source terms
76-
form_perturb_pressure();
77-
}
7882
// Update pressure gradient using sharpened pressure field
7983
update_gradp();
8084
}
8185
}
8286

8387
// If pressure gradient will be replaced, store current pressure gradient
8488
if (m_replace_gradp_postsolve) {
85-
const auto& gp = (*m_sim_ptr).repo().get_field("gp");
86-
for (int lev = 0; lev < (*m_sim_ptr).repo().num_active_levels();
87-
++lev) {
89+
const auto& gp = m_sim_ptr->repo().get_field("gp");
90+
for (int lev = 0; lev < m_sim_ptr->repo().num_active_levels(); ++lev) {
8891
amrex::MultiFab::Copy(
8992
(*m_gp_copy)(lev), gp(lev), 0, 0, gp(lev).nComp(),
9093
(m_gp_copy)->num_grow());
@@ -97,30 +100,30 @@ void OversetOps::update_gradp()
97100
BL_PROFILE("amr-wind::OversetOps::update_gradp");
98101

99102
// Get relevant fields
100-
auto& grad_p = (*m_sim_ptr).repo().get_field("gp");
101-
auto& pressure = (*m_sim_ptr).repo().get_field("p");
102-
auto& velocity = (*m_sim_ptr).repo().get_field("velocity");
103+
auto& grad_p = m_sim_ptr->repo().get_field("gp");
104+
auto& pressure = m_sim_ptr->repo().get_field("p");
105+
auto& velocity = m_sim_ptr->repo().get_field("velocity");
103106

104107
// Set up projection object
105108
std::unique_ptr<Hydro::NodalProjector> nodal_projector;
106109
// Boundary conditions from field, periodicity
107110
auto bclo = nodal_projection::get_projection_bc(
108111
amrex::Orientation::low, pressure,
109-
(*m_sim_ptr).mesh().Geom(0).isPeriodic());
112+
m_sim_ptr->mesh().Geom(0).isPeriodic());
110113
auto bchi = nodal_projection::get_projection_bc(
111114
amrex::Orientation::high, pressure,
112-
(*m_sim_ptr).mesh().Geom(0).isPeriodic());
115+
m_sim_ptr->mesh().Geom(0).isPeriodic());
113116
// Velocity multifab is needed for proper initialization, but only the size
114117
// matters for the purpose of calculating gradp, the values do not matter
115-
int finest_level = (*m_sim_ptr).mesh().finestLevel();
118+
int finest_level = m_sim_ptr->mesh().finestLevel();
116119
Vector<MultiFab*> vel;
117120
for (int lev = 0; lev <= finest_level; ++lev) {
118121
vel.push_back(&(velocity(lev)));
119122
}
120123
amr_wind::MLMGOptions options("nodal_proj");
121124
// Create nodal projector with unity scaling factor for simplicity
122125
nodal_projector = std::make_unique<Hydro::NodalProjector>(
123-
vel, 1.0, (*m_sim_ptr).mesh().Geom(0, finest_level), options.lpinfo());
126+
vel, 1.0, m_sim_ptr->mesh().Geom(0, finest_level), options.lpinfo());
124127
// Set MLMG and NodalProjector options
125128
options(*nodal_projector);
126129
nodal_projector->setDomainBC(bclo, bchi);
@@ -203,9 +206,9 @@ void OversetOps::parameter_output() const
203206

204207
void OversetOps::sharpen_nalu_data()
205208
{
206-
const auto& repo = (*m_sim_ptr).repo();
209+
const auto& repo = m_sim_ptr->repo();
207210
const auto nlevels = repo.num_active_levels();
208-
const auto geom = (*m_sim_ptr).mesh().Geom();
211+
const auto geom = m_sim_ptr->mesh().Geom();
209212

210213
// Get blanking for cells
211214
const auto& iblank_cell = repo.get_int_field("iblank_cell");
@@ -333,7 +336,7 @@ void OversetOps::sharpen_nalu_data()
333336
for (int lev = nlevels - 1; lev > 0; --lev) {
334337
amrex::average_down_faces(
335338
GetArrOfConstPtrs(fluxes[lev]), fluxes[lev - 1],
336-
repo.mesh().refRatio(lev), geom[lev - 1]);
339+
repo.mesh().refRatio(lev - 1), geom[lev - 1]);
337340
}
338341

339342
// Get pseudo dt (dtau)
@@ -382,7 +385,7 @@ void OversetOps::sharpen_nalu_data()
382385
}
383386

384387
// Fillpatch for pressure to make sure pressure stencil has all points
385-
p.fillpatch((*m_sim_ptr).time().current_time());
388+
p.fillpatch(m_sim_ptr->time().current_time());
386389

387390
// Purely for debugging via visualization, should be removed later
388391
// Currently set up to overwrite the levelset field (not used as time
@@ -395,19 +398,19 @@ void OversetOps::sharpen_nalu_data()
395398

396399
void OversetOps::form_perturb_pressure()
397400
{
398-
auto& pressure = (*m_sim_ptr).repo().get_field("p");
399-
const auto& p0 = (*m_sim_ptr).repo().get_field("reference_pressure");
400-
for (int lev = 0; lev < (*m_sim_ptr).repo().num_active_levels(); lev++) {
401+
auto& pressure = m_sim_ptr->repo().get_field("p");
402+
const auto& p0 = m_sim_ptr->repo().get_field("reference_pressure");
403+
for (int lev = 0; lev < m_sim_ptr->repo().num_active_levels(); lev++) {
401404
amrex::MultiFab::Subtract(
402405
pressure(lev), p0(lev), 0, 0, 1, pressure.num_grow()[0]);
403406
}
404407
}
405408

406409
void OversetOps::set_hydrostatic_gradp()
407410
{
408-
const auto& repo = (*m_sim_ptr).repo();
411+
const auto& repo = m_sim_ptr->repo();
409412
const auto nlevels = repo.num_active_levels();
410-
const auto geom = (*m_sim_ptr).mesh().Geom();
413+
const auto geom = m_sim_ptr->mesh().Geom();
411414

412415
// Get blanking for cells
413416
const auto& iblank_cell = repo.get_int_field("iblank_cell");
@@ -417,7 +420,7 @@ void OversetOps::set_hydrostatic_gradp()
417420
auto& rho = repo.get_field("density");
418421
auto& gp = repo.get_field("gp");
419422
if (m_mphase->perturb_pressure()) {
420-
rho0 = &((*m_sim_ptr).repo().get_field("reference_density"));
423+
rho0 = &(m_sim_ptr->repo().get_field("reference_density"));
421424
} else {
422425
// Point to existing field, won't be used
423426
rho0 = &rho;
@@ -433,11 +436,11 @@ void OversetOps::set_hydrostatic_gradp()
433436

434437
void OversetOps::replace_masked_gradp()
435438
{
436-
const auto& repo = (*m_sim_ptr).repo();
439+
const auto& repo = m_sim_ptr->repo();
437440
const auto nlevels = repo.num_active_levels();
438441

439442
// Get timestep
440-
const amrex::Real dt = (*m_sim_ptr).time().delta_t();
443+
const amrex::Real dt = m_sim_ptr->time().delta_t();
441444

442445
// Get blanking for cells
443446
const auto& iblank_cell = repo.get_int_field("iblank_cell");

amr-wind/physics/multiphase/SloshingTank.H

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public:
3535
private:
3636
Field& m_velocity;
3737
Field& m_levelset;
38-
Field& m_pressure;
3938

4039
//! Initial free surface amplitude magnitude
4140
amrex::Real m_amplitude{0.1};
@@ -45,14 +44,6 @@ private:
4544

4645
//! Initial zero-level free-surface water depth
4746
amrex::Real m_waterlevel{0.0};
48-
49-
//! Stuff to get from MultiPhase physics
50-
amrex::Real m_rho1{std::numeric_limits<amrex::Real>::quiet_NaN()};
51-
amrex::Real m_rho2{std::numeric_limits<amrex::Real>::quiet_NaN()};
52-
amrex::Vector<amrex::Real> m_gravity{
53-
std::numeric_limits<amrex::Real>::quiet_NaN(),
54-
std::numeric_limits<amrex::Real>::quiet_NaN(),
55-
std::numeric_limits<amrex::Real>::quiet_NaN()};
5647
};
5748

5849
} // namespace amr_wind

amr-wind/physics/multiphase/SloshingTank.cpp

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "amr-wind/physics/multiphase/SloshingTank.H"
2-
#include "amr-wind/physics/multiphase/MultiPhase.H"
32
#include "amr-wind/CFDSim.H"
43
#include "AMReX_ParmParse.H"
54
#include "amr-wind/fvm/gradient.H"
@@ -10,30 +9,22 @@ namespace amr_wind {
109
SloshingTank::SloshingTank(CFDSim& sim)
1110
: m_velocity(sim.repo().get_field("velocity"))
1211
, m_levelset(sim.repo().get_field("levelset"))
13-
, m_pressure(sim.repo().get_field("p"))
1412
{
1513
amrex::ParmParse pp(identifier());
1614
pp.query("amplitude", m_amplitude);
1715
pp.query("peak_enhance", m_kappa);
1816
pp.query("water_level", m_waterlevel);
19-
20-
const auto& mphase = sim.physics_manager().get<MultiPhase>();
21-
m_rho1 = mphase.rho1();
22-
m_rho2 = mphase.rho2();
23-
m_gravity = mphase.gravity();
2417
}
2518

2619
/** Initialize the velocity and levelset fields at the beginning of the
27-
* simulation. Initializing pressure has little effect for pure AMR-Wind
28-
* simulations, but it improves initialization in the overset solver.
20+
* simulation.
2921
*/
3022
void SloshingTank::initialize_fields(int level, const amrex::Geometry& geom)
3123
{
3224
auto& velocity = m_velocity(level);
3325
velocity.setVal(0.0);
3426

3527
auto& levelset = m_levelset(level);
36-
auto& pressure = m_pressure(level);
3728
const auto& dx = geom.CellSizeArray();
3829
const auto& problo = geom.ProbLoArray();
3930
const auto& probhi = geom.ProbHiArray();
@@ -42,14 +33,10 @@ void SloshingTank::initialize_fields(int level, const amrex::Geometry& geom)
4233
const amrex::Real water_level = m_waterlevel;
4334
const amrex::Real Lx = probhi[0] - problo[0];
4435
const amrex::Real Ly = probhi[1] - problo[1];
45-
const amrex::Real rho1 = m_rho1;
46-
const amrex::Real rho2 = m_rho2;
47-
const amrex::Real grav_z = m_gravity[2];
4836

4937
for (amrex::MFIter mfi(levelset); mfi.isValid(); ++mfi) {
5038
const auto& vbx = mfi.validbox();
5139
auto phi = levelset.array(mfi);
52-
auto p = pressure.array(mfi);
5340

5441
amrex::ParallelFor(
5542
vbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
@@ -63,29 +50,6 @@ void SloshingTank::initialize_fields(int level, const amrex::Geometry& geom)
6350
std::pow(y - problo[1] - 0.5 * Ly, 2)));
6451
phi(i, j, k) = z0 - z;
6552
});
66-
amrex::Box const& nbx = mfi.grownnodaltilebox();
67-
amrex::ParallelFor(
68-
nbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
69-
// For pressure nodes, no offset
70-
const amrex::Real x = problo[0] + i * dx[0];
71-
const amrex::Real y = problo[1] + j * dx[1];
72-
const amrex::Real z = problo[2] + k * dx[2];
73-
const amrex::Real z0 =
74-
water_level +
75-
Amp * std::exp(
76-
-kappa * (std::pow(x - problo[0] - 0.5 * Lx, 2) +
77-
std::pow(y - problo[1] - 0.5 * Ly, 2)));
78-
// Integrated (top-down in z) phase heights to pressure node
79-
const amrex::Real ih_g =
80-
amrex::max(0.0, amrex::min(probhi[2] - z0, probhi[2] - z));
81-
const amrex::Real ih_l =
82-
amrex::max(0.0, amrex::min(z0 - z, z0 - problo[2]));
83-
// Integrated rho at pressure node
84-
const amrex::Real irho = rho1 * ih_l + rho2 * ih_g;
85-
86-
// Add term to reference pressure
87-
p(i, j, k) = -irho * grav_z;
88-
});
8953
}
9054
}
9155

0 commit comments

Comments
 (0)