Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terrain blanking informed by ocean waves #1369

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3dca78d
init w2a waves as intended
mbkuhn Nov 22, 2024
d253836
set up abl multiphase reg test for w2a, shows obvious flaws
mbkuhn Nov 22, 2024
e3b9a57
Merge branch 'abl_w2a_reg_test' into w2a_init
mbkuhn Nov 22, 2024
d824c95
move variable assignment outside parallelfor
mbkuhn Nov 22, 2024
cbce352
tweak time stepping settings
mbkuhn Nov 22, 2024
c9c73b2
documentation (for arguments now in reg test)
mbkuhn Nov 22, 2024
6fe11fe
docs fix
mbkuhn Nov 22, 2024
1eb1d53
get those MFIters outta here
mbkuhn Nov 22, 2024
e023a6f
changes to use ow fields in terrain drag
mbkuhn Nov 22, 2024
ca7b1ca
create modes for ocean waves
mbkuhn Nov 22, 2024
dc2870f
correct conditional
mbkuhn Nov 22, 2024
84a891e
moving toward ocean waves single-phase compatibility
mbkuhn Nov 22, 2024
32783ac
renaming update_relax_zones to be more accurate
mbkuhn Nov 22, 2024
fa60d17
init tweaks to w2a
mbkuhn Nov 22, 2024
8b4090a
introduce target vel to drag forcing
mbkuhn Nov 22, 2024
64fed5e
wave terrain showing up in forcing at beginning and end of reg test
mbkuhn Nov 23, 2024
18aaea6
Merge branch 'main' into moving_terrain_blanking
mbkuhn Nov 23, 2024
983a7b7
formatting
mbkuhn Nov 23, 2024
86ffb47
more formatting
mbkuhn Nov 23, 2024
c2a0b96
correct terrain height
mbkuhn Nov 23, 2024
3904a33
consistent case
mbkuhn Nov 23, 2024
9dc581d
add dragtempforcing to reg test
mbkuhn Nov 25, 2024
e309c39
progress on abl + w2a terrain reg test
mbkuhn Nov 25, 2024
ffd6fcb
move function to public
mbkuhn Nov 25, 2024
21a862a
address terrain roughness
mbkuhn Nov 25, 2024
9b6fc95
ignore unused
mbkuhn Nov 25, 2024
29db41b
remove unused
mbkuhn Nov 25, 2024
07e6e42
more for unused
mbkuhn Nov 25, 2024
1d1f412
better function name
mbkuhn Nov 25, 2024
a7a411d
change to warning, filling modes by default at beginning
mbkuhn Nov 25, 2024
b378762
offset for waves in reg test
mbkuhn Nov 25, 2024
b66f909
tweak warning message
mbkuhn Nov 25, 2024
2ec5297
correct conditional to get ow_velocity correct
mbkuhn Nov 25, 2024
04a91c3
Merge branch 'main' into moving_terrain_blanking
mbkuhn Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions amr-wind/equation_systems/icns/source_terms/DragForcing.H
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private:
const CFDSim& m_sim;
const amrex::AmrCore& m_mesh;
const Field& m_velocity;
const Field* m_target_vel{nullptr};
amrex::Gpu::DeviceVector<amrex::Real> m_device_vel_ht;
amrex::Gpu::DeviceVector<amrex::Real> m_device_vel_vals;
amrex::Real m_drag_coefficient{10.0};
Expand All @@ -48,6 +49,7 @@ private:
int m_sponge_south{0};
int m_sponge_north{1};
bool m_is_laminar{false};
bool m_terrain_is_waves{false};
};

} // namespace amr_wind::pde::icns
Expand Down
29 changes: 26 additions & 3 deletions amr-wind/equation_systems/icns/source_terms/DragForcing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "AMReX_Gpu.H"
#include "AMReX_Random.H"
#include "amr-wind/wind_energy/ABL.H"
#include "amr-wind/physics/TerrainDrag.H"
#include "amr-wind/utilities/linear_interpolation.H"

namespace amr_wind::pde::icns {
Expand Down Expand Up @@ -42,6 +43,13 @@ DragForcing::DragForcing(const CFDSim& sim)
} else {
m_sponge_strength = 0.0;
}
if (phy_mgr.contains("OceanWaves")) {
const auto terrain_phys =
m_sim.physics_manager().get<amr_wind::terraindrag::TerrainDrag>();
const auto target_vel_name = terrain_phys.wave_velocity_field_name();
m_target_vel = &sim.repo().get_field(target_vel_name);
m_terrain_is_waves = true;
}
}

DragForcing::~DragForcing() = default;
Expand All @@ -68,6 +76,12 @@ void DragForcing::operator()(
const auto& drag = (*m_terrain_drag)(lev).const_array(mfi);
auto* const m_terrainz0 = &this->m_sim.repo().get_field("terrainz0");
const auto& terrainz0 = (*m_terrainz0)(lev).const_array(mfi);

const bool is_waves = m_terrain_is_waves;
const auto& target_vel_arr = is_waves
? (*m_target_vel)(lev).const_array(mfi)
: amrex::Array4<amrex::Real>();

const auto& geom = m_mesh.Geom(lev);
const auto& dx = geom.CellSizeArray();
const auto& prob_lo = geom.ProbLoArray();
Expand Down Expand Up @@ -158,20 +172,29 @@ void DragForcing::operator()(
Dyz = -ustar * ustar * uy1 /
(tiny + std::sqrt(ux1 * ux1 + uy1 * uy1)) / dx[2];
}
amrex::Real target_u = 0.;
amrex::Real target_v = 0.;
amrex::Real target_w = 0.;
if (is_waves) {
target_u = target_vel_arr(i, j, k, 0);
target_v = target_vel_arr(i, j, k, 1);
target_w = target_vel_arr(i, j, k, 2);
}

const amrex::Real CdM =
std::min(Cd / (m + tiny), cd_max / scale_factor);
src_term(i, j, k, 0) -=
(CdM * m * ux1 * blank(i, j, k) + Dxz * drag(i, j, k) +
(CdM * m * (ux1 - target_u) * blank(i, j, k) + Dxz * drag(i, j, k) +
bc_forcing_x * drag(i, j, k) +
(xstart_damping + xend_damping + ystart_damping + yend_damping) *
(ux1 - sponge_density * spongeVelX));
src_term(i, j, k, 1) -=
(CdM * m * uy1 * blank(i, j, k) + Dyz * drag(i, j, k) +
(CdM * m * (uy1 - target_v) * blank(i, j, k) + Dyz * drag(i, j, k) +
bc_forcing_y * drag(i, j, k) +
(xstart_damping + xend_damping + ystart_damping + yend_damping) *
(uy1 - sponge_density * spongeVelY));
src_term(i, j, k, 2) -=
(CdM * m * uz1 * blank(i, j, k) +
(CdM * m * (uz1 - target_w) * blank(i, j, k) +
(xstart_damping + xend_damping + ystart_damping + yend_damping) *
(uz1 - sponge_density * spongeVelZ));
});
Expand Down
7 changes: 7 additions & 0 deletions amr-wind/ocean_waves/OceanWaves.H
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ protected:
private:
void relaxation_zones();

void update_target_volume_fraction();

CFDSim& m_sim;

//! Unique pointer to the ocean waves model
Expand All @@ -68,6 +70,11 @@ private:

//! Ocean waves pressure gradient
// Field& m_ow_pressure;

//! Multiphase mode forces the velocity and vof in the domain
//! When off, single-phase mode simply provides the target variables, and
//! forcing is handled in other parts of the code
bool m_multiphase_mode{true};
};

} // namespace ocean_waves
Expand Down
37 changes: 31 additions & 6 deletions amr-wind/ocean_waves/OceanWaves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ OceanWaves::OceanWaves(CFDSim& sim)
sim.repo().declare_field("ow_velocity", AMREX_SPACEDIM, 3, 1))
{
if (!sim.physics_manager().contains("MultiPhase")) {
amrex::Abort("OceanWaves requires Multiphase physics to be active");
m_multiphase_mode = false;
}
m_ow_levelset.set_default_fillpatch_bc(sim.time());
m_ow_vof.set_default_fillpatch_bc(sim.time());
Expand All @@ -32,6 +32,13 @@ void OceanWaves::pre_init_actions()
BL_PROFILE("amr-wind::ocean_waves::OceanWaves::pre_init_actions");
amrex::ParmParse pp(identifier());

if (!(m_multiphase_mode ||
m_sim.physics_manager().contains("TerrainDrag"))) {
amrex::Abort(
"OceanWaves requires MultiPhase or TerrainDrag physics to be "
"active");
}

std::string label;
pp.query("label", label);
const std::string& tname = label;
Expand All @@ -54,13 +61,18 @@ void OceanWaves::pre_init_actions()
void OceanWaves::initialize_fields(int level, const amrex::Geometry& geom)
{
BL_PROFILE("amr-wind::ocean_waves::OceanWaves::initialize_fields");
m_owm->init_waves(level, geom);
m_owm->init_waves(level, geom, m_multiphase_mode);
}

void OceanWaves::post_init_actions()
{
BL_PROFILE("amr-wind::ocean_waves::OceanWaves::post_init_actions");
relaxation_zones();
if (m_multiphase_mode) {
relaxation_zones();
} else {
m_owm->update_target_fields(true);
m_owm->update_target_volume_fraction();
}
}

void OceanWaves::post_regrid_actions()
Expand All @@ -72,25 +84,38 @@ void OceanWaves::post_regrid_actions()
void OceanWaves::pre_advance_work()
{
BL_PROFILE("amr-wind::ocean_waves::OceanWaves::pre_advance_work");
if (!m_multiphase_mode) {
m_owm->update_target_fields(true);
m_owm->update_target_volume_fraction();
}
}

void OceanWaves::post_advance_work()
{
BL_PROFILE("amr-wind::ocean_waves::OceanWaves::post_init_actions");
relaxation_zones();
if (m_multiphase_mode) {
relaxation_zones();
}
}

/** Update ocean waves relaxation zones
*
*/
void OceanWaves::relaxation_zones()
{
BL_PROFILE("amr-wind::ocean_waves::OceanWaves::update_relaxation_zones");
m_owm->update_relax_zones();
BL_PROFILE("amr-wind::ocean_waves::OceanWaves::relaxation_zones");
m_owm->update_target_fields(false);
m_owm->apply_relax_zones();
m_owm->reset_regrid_flag();
}

void OceanWaves::update_target_volume_fraction()
{
BL_PROFILE(
"amr-wind::ocean_waves::OceanWaves::update_target_volume_fraction");
m_owm->update_target_volume_fraction();
}

void OceanWaves::prepare_outputs()
{
const std::string post_dir = m_sim.io_manager().post_processing_directory();
Expand Down
21 changes: 15 additions & 6 deletions amr-wind/ocean_waves/OceanWavesModel.H
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ public:

virtual void read_inputs(const ::amr_wind::utils::MultiParser&) = 0;

virtual void init_waves(int, const amrex::Geometry&) = 0;
virtual void init_waves(int, const amrex::Geometry&, bool) = 0;

virtual void update_relax_zones() = 0;
virtual void update_target_fields(bool) = 0;

virtual void apply_relax_zones() = 0;

virtual void update_target_volume_fraction() = 0;

virtual void prepare_outputs(const std::string&) = 0;

virtual void write_outputs() = 0;
Expand Down Expand Up @@ -91,16 +93,21 @@ public:
m_out_op.read_io_options(pp);
}

void update_relax_zones() override
void update_target_fields(bool for_forcing_term) override
{
ops::UpdateRelaxZonesOp<WaveTheoryTrait>()(m_data);
ops::UpdateTargetFieldsOp<WaveTheoryTrait>()(m_data, for_forcing_term);
}

void apply_relax_zones() override
{
ops::ApplyRelaxZonesOp<WaveTheoryTrait>()(m_data);
}

void update_target_volume_fraction() override
{
ops::UpdateTargetVolumeFractionOp<WaveTheoryTrait>()(m_data);
}

void prepare_outputs(const std::string& out_dir) override
{
m_out_op.prepare_outputs(out_dir);
Expand All @@ -112,9 +119,11 @@ public:

void write_outputs() override { m_out_op.write_outputs(); }

void init_waves(int level, const amrex::Geometry& geom) override
void init_waves(
int level, const amrex::Geometry& geom, bool multiphase_mode) override
{
ops::InitDataOp<WaveTheoryTrait>()(m_data, level, geom);
ops::InitDataOp<WaveTheoryTrait>()(
m_data, level, geom, multiphase_mode);
}
};

Expand Down
5 changes: 4 additions & 1 deletion amr-wind/ocean_waves/OceanWavesOps.H
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ template <typename WaveTheoryTrait, typename = void>
struct InitDataOp;

template <typename WaveTheoryTrait, typename = void>
struct UpdateRelaxZonesOp;
struct UpdateTargetFieldsOp;

template <typename WaveTheoryTrait, typename = void>
struct ApplyRelaxZonesOp;

template <typename WaveTheoryTrait, typename = void>
struct UpdateTargetVolumeFractionOp;

template <typename WaveTheoryTrait, typename = void>
struct ProcessOutputsOp;

Expand Down
Loading