Skip to content

Commit 79bb29a

Browse files
authored
Initialize pressure for sloshing tank, waves cases (overset purposes) (#1687)
* make pressure initialization available * tweaks to interface_band * incorporate iblank_to_mask_vof * zero velocities inside objects * make vof-dependent node mask when nodal_proj coupling not disabled * correcting arguments * getting pressure changes back in * behavior matches now with perturb pressure * formatting * remove some unnecessary changes * reinsert sync * turn off sloshing tank pressure by default
1 parent ec37004 commit 79bb29a

File tree

5 files changed

+72
-8
lines changed

5 files changed

+72
-8
lines changed

amr-wind/overset/OversetOps.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,16 @@ void OversetOps::initialize(CFDSim& sim)
5656

5757
void OversetOps::pre_advance_work()
5858
{
59-
if (m_mphase != nullptr) {
60-
// Avoid modifying pressure upon initialization, assume pressure = 0
61-
if (m_mphase->perturb_pressure() &&
62-
m_sim_ptr->time().current_time() > 0.0) {
63-
// Modify to be consistent with internal source terms
64-
form_perturb_pressure();
65-
}
66-
}
6759
// Update pressure gradient using updated overset pressure field
6860
update_gradp();
6961

7062
if (m_vof_exists) {
7163
// Reinitialize fields
7264
sharpen_nalu_data();
65+
if (m_mphase->perturb_pressure()) {
66+
// Modify to be consistent with internal source terms
67+
form_perturb_pressure();
68+
}
7369
// Update pressure gradient using sharpened pressure field
7470
update_gradp();
7571
// Calculate vof-dependent node mask

amr-wind/physics/multiphase/MultiPhase.H

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ private:
104104
// Reconstructing true pressure field at end of timestep
105105
bool m_reconstruct_true_pressure{false};
106106

107+
bool m_init_p{false};
108+
107109
// Info to create rho0
108110
amrex::Real m_water_level0{0.0};
109111
// Info to reconstruct true pressure

amr-wind/physics/multiphase/MultiPhase.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ MultiPhase::MultiPhase(CFDSim& sim)
7373
amrex::Print() << "WARNING: single-phase density has been specified "
7474
"but will not be used! (MultiPhase physics)\n";
7575
}
76+
77+
pp_multiphase.query("initialize_pressure", m_init_p);
78+
7679
// Always populate gravity
7780
pp_incflo.queryarr("gravity", m_gravity);
7881
}
@@ -131,6 +134,20 @@ void MultiPhase::post_init_actions()
131134
m_sim.mesh().Geom());
132135
}
133136
}
137+
138+
if (m_init_p && !is_wlev) {
139+
amrex::Abort(
140+
"Initialize pressure requested, but physics case does not "
141+
"specify water level.");
142+
}
143+
// Make p field if both are specified
144+
if (m_init_p && is_wlev) {
145+
// Initialize rho0 field for perturbational density, pressure
146+
auto& p = m_sim.repo().get_field("p");
147+
hydrostatic::define_p0(
148+
p, m_rho1, m_rho2, m_water_level0, m_gravity[2],
149+
m_sim.mesh().Geom());
150+
}
134151
}
135152

136153
void MultiPhase::post_regrid_actions()

amr-wind/physics/multiphase/SloshingTank.H

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

3940
//! Initial free surface amplitude magnitude
4041
amrex::Real m_amplitude{0.1};
@@ -44,6 +45,13 @@ private:
4445

4546
//! Initial zero-level free-surface water depth
4647
amrex::Real m_waterlevel{0.0};
48+
49+
bool m_init_p{false};
50+
51+
//! Stuff to get from MultiPhase physics
52+
amrex::Real m_rho1{1000.};
53+
amrex::Real m_rho2{1.};
54+
amrex::Vector<amrex::Real> m_gravity{0.0, 0.0, -9.81};
4755
};
4856

4957
} // namespace amr_wind

amr-wind/physics/multiphase/SloshingTank.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "amr-wind/physics/multiphase/SloshingTank.H"
2+
#include "amr-wind/physics/multiphase/MultiPhase.H"
23
#include "amr-wind/CFDSim.H"
34
#include "AMReX_ParmParse.H"
45
#include "amr-wind/fvm/gradient.H"
@@ -9,11 +10,19 @@ namespace amr_wind {
910
SloshingTank::SloshingTank(CFDSim& sim)
1011
: m_velocity(sim.repo().get_field("velocity"))
1112
, m_levelset(sim.repo().get_field("levelset"))
13+
, m_pressure(sim.repo().get_field("p"))
1214
{
1315
amrex::ParmParse pp(identifier());
1416
pp.query("amplitude", m_amplitude);
1517
pp.query("peak_enhance", m_kappa);
1618
pp.query("water_level", m_waterlevel);
19+
20+
pp.query("initialize_pressure", m_init_p);
21+
22+
const auto& mphase = sim.physics_manager().get<MultiPhase>();
23+
m_rho1 = mphase.rho1();
24+
m_rho2 = mphase.rho2();
25+
m_gravity = mphase.gravity();
1726
}
1827

1928
/** Initialize the velocity and levelset fields at the beginning of the
@@ -25,6 +34,7 @@ void SloshingTank::initialize_fields(int level, const amrex::Geometry& geom)
2534
velocity.setVal(0.0);
2635

2736
auto& levelset = m_levelset(level);
37+
auto& pressure = m_pressure(level);
2838
const auto& dx = geom.CellSizeArray();
2939
const auto& problo = geom.ProbLoArray();
3040
const auto& probhi = geom.ProbHiArray();
@@ -33,7 +43,12 @@ void SloshingTank::initialize_fields(int level, const amrex::Geometry& geom)
3343
const amrex::Real water_level = m_waterlevel;
3444
const amrex::Real Lx = probhi[0] - problo[0];
3545
const amrex::Real Ly = probhi[1] - problo[1];
46+
const amrex::Real rho1 = m_rho1;
47+
const amrex::Real rho2 = m_rho2;
48+
const amrex::Real grav_z = m_gravity[2];
49+
3650
const auto& phi_arrs = levelset.arrays();
51+
const auto& p = pressure.arrays();
3752

3853
amrex::ParallelFor(
3954
levelset, [=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) noexcept {
@@ -47,6 +62,32 @@ void SloshingTank::initialize_fields(int level, const amrex::Geometry& geom)
4762
std::pow(y - problo[1] - 0.5 * Ly, 2)));
4863
phi_arrs[nbx](i, j, k) = z0 - z;
4964
});
65+
66+
if (m_init_p) {
67+
amrex::ParallelFor(
68+
pressure, amrex::IntVect(0),
69+
[=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) noexcept {
70+
// For pressure nodes, no offset
71+
const amrex::Real x = problo[0] + i * dx[0];
72+
const amrex::Real y = problo[1] + j * dx[1];
73+
const amrex::Real z = problo[2] + k * dx[2];
74+
const amrex::Real z0 =
75+
water_level +
76+
Amp * std::exp(
77+
-kappa * (std::pow(x - problo[0] - 0.5 * Lx, 2) +
78+
std::pow(y - problo[1] - 0.5 * Ly, 2)));
79+
// Integrated (top-down in z) phase heights to pressure node
80+
amrex::Real ih_g =
81+
amrex::max(0.0, amrex::min(probhi[2] - z0, probhi[2] - z));
82+
amrex::Real ih_l =
83+
amrex::max(0.0, amrex::min(z0 - z, z0 - problo[2]));
84+
// Integrated rho at pressure node
85+
const amrex::Real irho = rho1 * ih_l + rho2 * ih_g;
86+
87+
// Add term to reference pressure
88+
p[nbx](i, j, k) = -irho * grav_z;
89+
});
90+
}
5091
amrex::Gpu::streamSynchronize();
5192
}
5293

0 commit comments

Comments
 (0)