Skip to content

Commit

Permalink
Merge branch 'main' into ow_current_linear
Browse files Browse the repository at this point in the history
  • Loading branch information
mbkuhn authored Jan 16, 2025
2 parents fbfd78d + 9fee431 commit 73e608f
Show file tree
Hide file tree
Showing 26 changed files with 349 additions and 68 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ if(AMR_WIND_ENABLE_OPENFAST)
target_compile_definitions(${amr_wind_lib_name} PUBLIC AMR_WIND_USE_OPENFAST)
target_include_directories(${amr_wind_lib_name} PUBLIC ${OpenFAST_INCLUDE_DIRS})
target_link_libraries(${amr_wind_lib_name} PUBLIC ${OpenFAST_LIBRARIES})

set(AMR_WIND_OPENFAST_VERSION "3" CACHE STRING "OpenFAST major version")
if((AMR_WIND_OPENFAST_VERSION STREQUAL "master") OR (AMR_WIND_OPENFAST_VERSION STREQUAL "main") OR (AMR_WIND_OPENFAST_VERSION STREQUAL "develop"))
set(AMR_WIND_OPENFAST_VERSION "4.0")
endif()
if(NOT AMR_WIND_OPENFAST_VERSION VERSION_LESS "5")
message(FATAL_ERROR "AMR_WIND_OPENFAST_VERSION must be less than 5.")
endif()
string(REPLACE "." ";" OPENFAST_VERSION_LIST ${AMR_WIND_OPENFAST_VERSION})
list(LENGTH OPENFAST_VERSION_LIST OPENFAST_VERSION_LIST_LENGTH)
if(OPENFAST_VERSION_LIST_LENGTH GREATER_EQUAL 1)
list(GET OPENFAST_VERSION_LIST 0 OPENFAST_VERSION_MAJOR)
endif()
target_compile_definitions(${amr_wind_lib_name} PUBLIC OPENFAST_VERSION_MAJOR=${OPENFAST_VERSION_MAJOR})
endif()

if(AMR_WIND_ENABLE_ASCENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ private:
//! Transport model
const transport::TransportModel& m_transport;

//! Reference temperature
std::unique_ptr<ScratchField> m_ref_theta;

int m_axis{2};

bool m_const_profile{false};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ ABLMeanBoussinesq::ABLMeanBoussinesq(const CFDSim& sim)
const auto& abl = sim.physics_manager().get<amr_wind::ABL>();
abl.register_mean_boussinesq_term(this);

m_ref_theta = m_transport.ref_theta();

// gravity in `incflo` namespace
amrex::ParmParse pp_incflo("incflo");
pp_incflo.queryarr("gravity", m_gravity);
Expand Down Expand Up @@ -96,7 +94,10 @@ void ABLMeanBoussinesq::operator()(
amrex::Array4<amrex::Real> const& beta_arr = beta_fab.array();
m_transport.beta_impl(lev, mfi, bx, beta_arr);

const auto& ref_theta = (*m_ref_theta)(lev).const_array(mfi);
amrex::FArrayBox ref_theta_fab(bx, 1, amrex::The_Async_Arena());
amrex::Array4<amrex::Real> const& ref_theta_arr = ref_theta_fab.array();
m_transport.ref_theta_impl(lev, mfi, bx, ref_theta_arr);

const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> gravity{
m_gravity[0], m_gravity[1], m_gravity[2]};

Expand All @@ -110,7 +111,7 @@ void ABLMeanBoussinesq::operator()(
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
amrex::IntVect iv(i, j, k);
const amrex::Real ht = problo[idir] + (iv[idir] + 0.5) * dx[idir];
const amrex::Real T0 = ref_theta(i, j, k);
const amrex::Real T0 = ref_theta_arr(i, j, k);
const amrex::Real temp =
amr_wind::interp::linear(theights, theights_end, tvals, ht);
const amrex::Real fac = beta_arr(i, j, k) * (temp - T0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ private:

//! Transport model
const transport::TransportModel& m_transport;

//! Reference temperature
std::unique_ptr<ScratchField> m_ref_theta;
};
} // namespace amr_wind::pde::icns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ BoussinesqBuoyancy::BoussinesqBuoyancy(const CFDSim& sim)
: m_temperature(sim.repo().get_field("temperature"))
, m_transport(sim.transport_model())
{
m_ref_theta = m_transport.ref_theta();

// gravity in `incflo` namespace
amrex::ParmParse pp_incflo("incflo");
pp_incflo.queryarr("gravity", m_gravity);
Expand All @@ -38,10 +36,12 @@ void BoussinesqBuoyancy::operator()(
amrex::FArrayBox beta_fab(bx, 1, amrex::The_Async_Arena());
amrex::Array4<amrex::Real> const& beta_arr = beta_fab.array();
m_transport.beta_impl(lev, mfi, bx, beta_arr);
const auto& ref_theta = (*m_ref_theta)(lev).const_array(mfi);
amrex::FArrayBox ref_theta_fab(bx, 1, amrex::The_Async_Arena());
amrex::Array4<amrex::Real> const& ref_theta_arr = ref_theta_fab.array();
m_transport.ref_theta_impl(lev, mfi, bx, ref_theta_arr);
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
const amrex::Real T = temp(i, j, k, 0);
const amrex::Real T0 = ref_theta(i, j, k);
const amrex::Real T0 = ref_theta_arr(i, j, k);
const amrex::Real fac = beta_arr(i, j, k) * (T0 - T);

src_term(i, j, k, 0) += gravity[0] * fac;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ private:

//! Transport model
const transport::TransportModel& m_transport;

//! Reference temperature
std::unique_ptr<ScratchField> m_ref_theta;
};

} // namespace amr_wind::pde::temperature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ DragTempForcing::DragTempForcing(const CFDSim& sim)
{
amrex::ParmParse pp("DragTempForcing");
pp.query("drag_coefficient", m_drag_coefficient);
m_ref_theta = m_transport.ref_theta();
if (pp.contains("reference_temperature")) {
amrex::Abort(
"DragTempForcing.reference_temperature has been deprecated. Please "
Expand Down Expand Up @@ -50,7 +49,9 @@ void DragTempForcing::operator()(
const auto& geom = m_mesh.Geom(lev);
const auto& dx = geom.CellSizeArray();
const amrex::Real drag_coefficient = m_drag_coefficient / dx[2];
const auto& ref_theta = (*m_ref_theta)(lev).const_array(mfi);
amrex::FArrayBox ref_theta_fab(bx, 1, amrex::The_Async_Arena());
amrex::Array4<amrex::Real> const& ref_theta_arr = ref_theta_fab.array();
m_transport.ref_theta_impl(lev, mfi, bx, ref_theta_arr);
const auto tiny = std::numeric_limits<amrex::Real>::epsilon();
const amrex::Real cd_max = 10.0;
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
Expand All @@ -60,7 +61,7 @@ void DragTempForcing::operator()(
const amrex::Real m = std::sqrt(ux1 * ux1 + uy1 * uy1 + uz1 * uz1);
const amrex::Real Cd =
std::min(drag_coefficient / (m + tiny), cd_max / dx[2]);
const amrex::Real T0 = ref_theta(i, j, k);
const amrex::Real T0 = ref_theta_arr(i, j, k);
src_term(i, j, k, 0) -=
(Cd * (temperature(i, j, k, 0) - T0) * blank(i, j, k, 0));
});
Expand Down
3 changes: 0 additions & 3 deletions amr-wind/equation_systems/tke/source_terms/KransAxell.H
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ private:

//! Transport model
const transport::TransportModel& m_transport;

//! Reference temperature
std::unique_ptr<ScratchField> m_ref_theta;
};

} // namespace amr_wind::pde::tke
Expand Down
5 changes: 3 additions & 2 deletions amr-wind/equation_systems/tke/source_terms/KransAxell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ KransAxell::KransAxell(const CFDSim& sim)
amrex::ParmParse pp_incflow("incflo");
pp_incflow.queryarr("gravity", m_gravity);
}
m_ref_theta = m_transport.ref_theta();
}

KransAxell::~KransAxell() = default;
Expand All @@ -49,7 +48,9 @@ void KransAxell::operator()(
const auto& buoy_prod_arr = (this->m_buoy_prod)(lev).array(mfi);
const auto& dissip_arr = (this->m_dissip)(lev).array(mfi);
const auto& tke_arr = m_tke(lev).array(mfi);
const auto& ref_theta_arr = (*m_ref_theta)(lev).const_array(mfi);
amrex::FArrayBox ref_theta_fab(bx, 1, amrex::The_Async_Arena());
amrex::Array4<amrex::Real> const& ref_theta_arr = ref_theta_fab.array();
m_transport.ref_theta_impl(lev, mfi, bx, ref_theta_arr);
const auto& geom = m_mesh.Geom(lev);
const auto& problo = m_mesh.Geom(lev).ProbLoArray();
const auto& probhi = m_mesh.Geom(lev).ProbHiArray();
Expand Down
65 changes: 55 additions & 10 deletions amr-wind/transport_models/ConstTransport.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define CONSTTRANSPORT_H

#include "amr-wind/transport_models/TransportModel.H"
#include "amr-wind/utilities/constants.H"
#include "AMReX_ParmParse.H"

namespace amr_wind::transport {
Expand Down Expand Up @@ -176,14 +175,26 @@ public:
const amrex::Array4<amrex::Real>& beta) const override
{

const amrex::Real beta_val = (m_constant_beta > 0.0)
? m_constant_beta
: 1.0 / m_reference_temperature;

amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
beta(i, j, k) = beta_val;
});
if (m_constant_beta > 0.0) {
const amrex::Real beta_val = m_constant_beta;
amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
beta(i, j, k) = beta_val;
});
} else if (m_repo.field_exists("reference_temperature")) {
const auto& temp0 = m_repo.get_field("reference_temperature");
const auto& temp0_arr = temp0(lev).const_array(mfi);
amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
beta(i, j, k) = 1.0 / temp0_arr(i, j, k);
});
} else {
const amrex::Real beta_val = 1.0 / m_reference_temperature;
amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
beta(i, j, k) = beta_val;
});
}

if (m_repo.field_exists("vof")) {
const auto& vof = m_repo.get_field("vof");
Expand Down Expand Up @@ -211,11 +222,45 @@ public:

auto ref_theta = m_repo.create_scratch_field(1, m_ngrow);
for (int lev = 0; lev < m_repo.num_active_levels(); ++lev) {
(*ref_theta)(lev).setVal(m_reference_temperature);
#ifdef AMREX_USE_OMP
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
#endif
for (amrex::MFIter mfi((*ref_theta)(lev)); mfi.isValid(); ++mfi) {
const auto& bx = mfi.tilebox();
const auto& ref_theta_arr = (*ref_theta)(lev).array(mfi);
ref_theta_impl(lev, mfi, bx, ref_theta_arr);
}
}
return ref_theta;
}

//! Compute the reference temperature
inline void ref_theta_impl(
const int lev,
const amrex::MFIter& mfi,
const amrex::Box& bx,
const amrex::Array4<amrex::Real>& ref_theta) const override
{
if (m_reference_temperature < 0.0) {
amrex::Abort("Reference temperature was not set");
}

if (m_repo.field_exists("reference_temperature")) {
auto& temp0 = m_repo.get_field("reference_temperature");
const auto& temp0_arr = temp0(lev).const_array(mfi);
amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
ref_theta(i, j, k) = temp0_arr(i, j, k);
});
} else {
const amrex::Real ref_theta_val = m_reference_temperature;
amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
ref_theta(i, j, k) = ref_theta_val;
});
}
}

private:
//! Reference to the field repository (for creating scratch fields)
FieldRepo& m_repo;
Expand Down
9 changes: 9 additions & 0 deletions amr-wind/transport_models/TransportModel.H
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "amr-wind/core/Factory.H"
#include "amr-wind/CFDSim.H"
#include "amr-wind/core/FieldRepo.H"
#include "amr-wind/utilities/constants.H"
#include "amr-wind/core/field_ops.H"

namespace amr_wind::transport {

Expand Down Expand Up @@ -56,6 +58,13 @@ public:
//! Reference temperature
virtual amrex::Real reference_temperature() const = 0;

//! Reference temperature
virtual void ref_theta_impl(
const int lev,
const amrex::MFIter& mfi,
const amrex::Box& bx,
const amrex::Array4<amrex::Real>& ref_theta) const = 0;

//! Reference temperature
virtual std::unique_ptr<ScratchField> ref_theta() const = 0;

Expand Down
65 changes: 57 additions & 8 deletions amr-wind/transport_models/TwoPhaseTransport.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "amr-wind/physics/multiphase/MultiPhase.H"
#include "amr-wind/transport_models/TransportModel.H"
#include "amr-wind/utilities/constants.H"
#include "AMReX_ParmParse.H"

namespace amr_wind::transport {
Expand Down Expand Up @@ -309,9 +308,27 @@ public:
const amrex::Box& bx,
const amrex::Array4<amrex::Real>& beta) const override
{
const amrex::Real beta_val = (m_constant_beta > 0.0)
? m_constant_beta
: 1.0 / m_reference_temperature;

if (m_constant_beta > 0.0) {
const amrex::Real beta_val = m_constant_beta;
amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
beta(i, j, k) = beta_val;
});
} else if (m_repo.field_exists("reference_temperature")) {
const auto& temp0 = m_repo.get_field("reference_temperature");
const auto& temp0_arr = temp0(lev).const_array(mfi);
amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
beta(i, j, k) = 1.0 / temp0_arr(i, j, k);
});
} else {
const amrex::Real beta_val = 1.0 / m_reference_temperature;
amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
beta(i, j, k) = beta_val;
});
}

if (m_ifacetype == InterfaceCapturingMethod::VOF) {
const auto& vof = m_repo.get_field("vof");
Expand All @@ -320,8 +337,6 @@ public:
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
if (vof_arr(i, j, k) > constants::TIGHT_TOL) {
beta(i, j, k) = 0.0;
} else {
beta(i, j, k) = beta_val;
}
});
} else if (m_ifacetype == InterfaceCapturingMethod::LS) {
Expand All @@ -342,7 +357,7 @@ public:
1.0 / M_PI *
std::sin(phi_arr(i, j, k) * M_PI / eps));
}
beta(i, j, k) = beta_val * (1 - smooth_heaviside);
beta(i, j, k) *= (1 - smooth_heaviside);
});
}
}
Expand All @@ -361,11 +376,45 @@ public:

auto ref_theta = m_repo.create_scratch_field(1, m_ngrow);
for (int lev = 0; lev < m_repo.num_active_levels(); ++lev) {
(*ref_theta)(lev).setVal(m_reference_temperature);
#ifdef AMREX_USE_OMP
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
#endif
for (amrex::MFIter mfi((*ref_theta)(lev)); mfi.isValid(); ++mfi) {
const auto& bx = mfi.tilebox();
const auto& ref_theta_arr = (*ref_theta)(lev).array(mfi);
ref_theta_impl(lev, mfi, bx, ref_theta_arr);
}
}
return ref_theta;
}

//! Compute the reference temperature
inline void ref_theta_impl(
const int lev,
const amrex::MFIter& mfi,
const amrex::Box& bx,
const amrex::Array4<amrex::Real>& ref_theta) const override
{
if (m_reference_temperature < 0.0) {
amrex::Abort("Reference temperature was not set");
}

if (m_repo.field_exists("reference_temperature")) {
auto& temp0 = m_repo.get_field("reference_temperature");
const auto& temp0_arr = temp0(lev).const_array(mfi);
amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
ref_theta(i, j, k) = temp0_arr(i, j, k);
});
} else {
const amrex::Real ref_theta_val = m_reference_temperature;
amrex::ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
ref_theta(i, j, k) = ref_theta_val;
});
}
}

private:
//! Reference to the CFD sim
const CFDSim& m_sim;
Expand Down
10 changes: 10 additions & 0 deletions amr-wind/utilities/constants.H
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,15 @@ is_close(const amrex::Real a, const amrex::Real b)
return amrex::Math::abs(a - b) < EPS;
}

//! Boltzmann constant (J/K)
static constexpr amrex::Real BOLTZMANN_CONSTANT = 1.380649 * 1e-23;

//! Avogadro's constant (mol^-1)
static constexpr amrex::Real AVOGADRO_CONSTANT = 6.02214076 * 1e23;

//! Universal gas constant (J/K mol)
static constexpr amrex::Real UNIVERSAL_GAS_CONSTANT =
AVOGADRO_CONSTANT * BOLTZMANN_CONSTANT;

} // namespace amr_wind::constants
#endif
Loading

0 comments on commit 73e608f

Please sign in to comment.