Skip to content

Commit

Permalink
Merge branch 'development' into RRTMGP_Port
Browse files Browse the repository at this point in the history
  • Loading branch information
AMLattanzi authored Jan 21, 2025
2 parents ac3eb77 + 2d3ed58 commit 5be1998
Show file tree
Hide file tree
Showing 29 changed files with 1,957 additions and 561 deletions.
9 changes: 5 additions & 4 deletions CMake/BuildERFExe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ function(build_erf_lib erf_lib_name)
${SRC_DIR}/Diffusion/ERF_ComputeStrain_N.cpp
${SRC_DIR}/Diffusion/ERF_ComputeStrain_T.cpp
${SRC_DIR}/Diffusion/ERF_ComputeTurbulentViscosity.cpp
${SRC_DIR}/EB/ERF_InitEB.cpp
${SRC_DIR}/EB/ERF_EBAux.cpp
${SRC_DIR}/EB/ERF_EBBox.cpp
${SRC_DIR}/EB/ERF_EBRegular.cpp
${SRC_DIR}/EB/ERF_InitEB.cpp
${SRC_DIR}/EB/ERF_WriteEBSurface.cpp
${SRC_DIR}/EB/ERF_EB.cpp
${SRC_DIR}/EB/ERF_EBCutCell.cpp
${SRC_DIR}/EB/ERF_EBRedistribute.cpp
${SRC_DIR}/EB/ERF_EBWriteSurface.cpp
${SRC_DIR}/Initialization/ERF_InitBCs.cpp
${SRC_DIR}/Initialization/ERF_InitCustom.cpp
${SRC_DIR}/Initialization/ERF_InitFromHSE.cpp
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ add_library(${PROJECT_NAME}::erf_api ALIAS erf_srclib)

# Collect all headers and make them installable with the target
set(ERF_INCLUDES "Source/ERF.H;Source/ERF_Constants.H;Source/WindFarmParametrization/SimpleActuatorDisk/ERF_SimpleAD.H;Source/WindFarmParametrization/EWP/ERF_EWP.H;Source/WindFarmParametrization/Null/ERF_NullWindFarm.H;Source/WindFarmParametrization/ERF_WindFarm.H;Source/WindFarmParametrization/Fitch/ERF_Fitch.H;Source/BoundaryConditions/ERF_PhysBCFunct.H;Source/BoundaryConditions/ERF_MOSTAverage.H;Source/BoundaryConditions/ERF_MOSTRoughness.H;Source/BoundaryConditions/ERF_ABLMost.H;Source/BoundaryConditions/ERF_FillPatcher.H;Source/BoundaryConditions/ERF_MOSTStress.H;Source/BoundaryConditions/ERF_TimeInterpolatedData.H;Source/Utils/ERF_InitTerrain.H;Source/Utils/ERF_Interpolation.H;Source/Utils/ERF_TileNoZ.H;Source/Utils/ERF_PlaneAverage.H;Source/Utils/ERF_Interpolation_WENO.H;Source/Utils/ERF_DirectionSelector.H;Source/Utils/ERF_ParFunctions.H;Source/Utils/ERF_Wstar.H;Source/Utils/ERF_MicrophysicsUtils.H;Source/Utils/ERF_SatMethods.H;Source/Utils/ERF_Interpolation_1D.H;Source/Utils/ERF_Interpolation_UPW.H;Source/Utils/ERF_TerrainMetrics.H;Source/Utils/ERF_Interpolation_WENO_Z.H;Source/Utils/ERF_Thetav.H;Source/Utils/ERF_WaterVaporSaturation.H;Source/Utils/ERF_Utils.H;Source/Utils/ERF_Orbit.H;Source/Utils/ERF_EOS.H;Source/Utils/ERF_HSEUtils.H;Source/EB/ERF_TerrainIF.H;Source/EB/ERF_EBIF.H;Source/Particles/ERFPC.H;Source/Particles/ERF_ParticleData.H;Source/Prob/ERF_InitDensityHSEDry.H;Source/Prob/ERF_InitRayleighDamping.H;Source/Prob/ERF_InitConstantDensityHSE.H;Source/ERF_ProbCommon.H;Source/ERF_Derive.H;Source/Radiation/ERF_RRTMGP_Interface.H;Source/Radiation/ERF_RRTMGP_Utils.H;Source/Radiation/ERF_Radiation.H;Source/Radiation/ERF_OrbCosZenith.H;Source/SourceTerms/ERF_NumericalDiffusion.H;Source/SourceTerms/ERF_SrcHeaders.H;Source/SourceTerms/ERF_ForestDrag.H;Source/IO/ERF_SampleData.H;Source/IO/ERF_NCInterface.H;Source/IO/ERF_NCWpsFile.H;Source/IO/ERF_NCPlotFile.H;Source/IO/ERF_ReadBndryPlanes.H;Source/IO/ERF_WriteBndryPlanes.H;Source/PBL/ERF_MYNNStruct.H;Source/PBL/ERF_PBLModels.H;Source/PBL/ERF_PBLHeight.H;Source/TimeIntegration/ERF_TI_substep_fun.H;Source/TimeIntegration/ERF_TI_slow_headers.H;Source/TimeIntegration/ERF_TI_slow_rhs_fun.H;Source/TimeIntegration/ERF_TI_fast_headers.H;Source/TimeIntegration/ERF_TI_utils.H;Source/TimeIntegration/ERF_MRI.H;Source/TimeIntegration/ERF_TI_no_substep_fun.H;Source/LandSurfaceModel/Null/ERF_NullSurf.H;Source/LandSurfaceModel/ERF_LandSurface.H;Source/LandSurfaceModel/MM5/ERF_MM5.H;Source/LandSurfaceModel/SLM/ERF_SLM.H;Source/ERF_IndexDefines.H;Source/Advection/ERF_AdvectionSrcForMom_N.H;Source/Advection/ERF_AdvectionSrcForScalars.H;Source/Advection/ERF_AdvectionSrcForMom_T.H;Source/Advection/ERF_Advection.H;Source/MultiBlock/ERF_MultiBlockContainer.H;Source/Initialization/ERF_MetgridUtils.H;Source/Diffusion/ERF_EddyViscosity.H;Source/Diffusion/ERF_Diffusion.H;Source/Microphysics/Null/ERF_NullMoistLagrangian.H;Source/Microphysics/Null/ERF_NullMoist.H;Source/Microphysics/ERF_Microphysics.H;Source/Microphysics/ERF_LagrangianMicrophysics.H;Source/Microphysics/ERF_EulerianMicrophysics.H;Source/Microphysics/Kessler/ERF_Kessler.H;Source/Microphysics/SAM/ERF_SAM.H;Source/Microphysics/SatAdj/ERF_SatAdj.H;Source/DataStructs/ERF_InputSpongeData.H;Source/DataStructs/ERF_TurbPertStruct.H;Source/DataStructs/ERF_SpongeStruct.H;Source/DataStructs/ERF_AdvStruct.H;Source/DataStructs/ERF_DataStruct.H;Source/DataStructs/ERF_InputSoundingData.H;Source/DataStructs/ERF_DiffStruct.H;Source/DataStructs/ERF_TurbStruct.H;Source/LinearSolvers/ERF_TerrainPoisson.H;Source/LinearSolvers/ERF_FFTUtils.H")

set_target_properties(
erf_srclib PROPERTIES PUBLIC_HEADER "${ERF_INCLUDES}")

Expand Down
17 changes: 6 additions & 11 deletions Exec/DevTests/EB_Test/ERF_Prob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Problem::init_custom_pert(

const bool use_moisture = (sc.moisture_type != MoistureType::None);

AMREX_ALWAYS_ASSERT(sc.terrain_type == TerrainType::EB);

AMREX_ALWAYS_ASSERT(bx.length()[2] == khi+1);

// ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
Expand Down Expand Up @@ -169,17 +171,10 @@ Problem::init_custom_pert(
dxInv[2] = 1. / dx[2];

// Set the z-velocity from impenetrable condition
if (sc.terrain_type == TerrainType::EB) {
ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
{
z_vel_pert(i, j, k) = 0.0;
});
} else {
ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
{
z_vel_pert(i, j, k) = WFromOmega(i, j, k, 0.0, x_vel_pert, y_vel_pert, z_nd, dxInv);
});
}
ParallelFor(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
{
z_vel_pert(i, j, k) = 0.0;
});

amrex::Gpu::streamSynchronize();
}
Expand Down
3 changes: 2 additions & 1 deletion Exec/DevTests/EB_Test/inputs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ erf.plot_vars_1 = density rhotheta theta rhoadv_0 x_velocity y_velocity z_ve
# SOLVER CHOICE
erf.use_gravity = false
erf.use_coriolis = false
erf.les_type = "None"

erf.les_type = "None"
erf.molec_diff_type = "None"
Expand All @@ -67,6 +66,8 @@ erf.alpha_C = 0.0

erf.init_type = "uniform"

erf.terrain_type = EB

# PROBLEM PARAMETERS
prob.rho_0 = 1.0
prob.T_0 = 1.0
Expand Down
10 changes: 10 additions & 0 deletions Source/EB/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
target_include_directories( simplexacore PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)

target_sources( simplexacore PRIVATE
eb.cpp
eb_box.cpp
eb_terrain.cpp
eb_cut_cell.cpp
eb_aux.cpp
)
73 changes: 73 additions & 0 deletions Source/EB/ERF_EB.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef ERF_EB_H_
#define ERF_EB_H_

#include <AMReX_Geometry.H>
#include <AMReX_DistributionMapping.H>
#include <AMReX_BoxArray.H>

#include <AMReX_EB2.H>
#include <AMReX_EBFabFactory.H>

#include <ERF_EBAux.H>

class eb_ {

public:

~eb_ ();

eb_ (amrex::Geometry const& a_geom,
amrex::FArrayBox const& terrain_fab,
amrex::Gpu::DeviceVector<amrex::Real>& a_dz_stretched,
bool is_anelastic);

void make_factory ( amrex::Geometry const& a_geom,
amrex::DistributionMapping const& a_dmap,
amrex::BoxArray const& a_grids);

int nghost_basic () const { return 2; }
int nghost_volume () const { return 2; }
int nghost_full () const { return 2; }

amrex::EBFArrayBoxFactory const* get_const_factory () noexcept
{ return m_factory.get(); }

amrex::EB2::Level const* get_level () const noexcept
{ return m_eb_level; }

private:

int m_has_eb;
std::string m_type;

amrex::EBSupport m_support_level;

int m_write_eb_surface;

//! EB level constructed from building GeometryShop
amrex::EB2::Level const* m_eb_level;

std::unique_ptr<amrex::EBFArrayBoxFactory> m_factory;

eb_aux_ m_u_factory;
eb_aux_ m_v_factory;
eb_aux_ m_w_factory;

void make_box (amrex::Geometry const& a_geom);
void make_terrain (amrex::Geometry const& a_geom);

//! Construct EB levels from Geometry shop.
template<class F>
void build_level (amrex::Geometry const& a_geom,
amrex::EB2::GeometryShop<F> a_gshop)
{
int const req_lev(0);
int const max_lev(2);

amrex::EB2::Build(a_gshop, a_geom, req_lev, max_lev);
const amrex::EB2::IndexSpace& ebis = amrex::EB2::IndexSpace::top();
m_eb_level = &(ebis.getLevel(a_geom));
}

};
#endif
101 changes: 101 additions & 0 deletions Source/EB/ERF_EB.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include <AMReX_ParmParse.H>
#include <AMReX_Print.H>
#include <AMReX_WriteEBSurface.H>

#include <ERF_EBIFTerrain.H>
#include <ERF_ProbCommon.H>

#include <ERF_EB.H>

using namespace amrex;

eb_::~eb_()
{
if (m_factory) { m_factory.reset(nullptr); }
}

eb_:: eb_ ( Geometry const& a_geom, amrex::FArrayBox const& terrain_fab,
amrex::Gpu::DeviceVector<amrex::Real>& a_dz_stretched,
bool is_anelastic)
: m_has_eb(0),
m_support_level(EBSupport::full),
m_write_eb_surface(0)
{
m_type = "terrain";

int max_coarsening_level;
if (is_anelastic) {
max_coarsening_level = 100;
} else {
max_coarsening_level = 0;
}

int max_level_here = 0;

if (m_type == "terrain")
{
Print() << "\nBuilding EB geometry based on terrain.\n";

TerrainIF ebterrain(terrain_fab, a_geom, a_dz_stretched);

auto gshop = EB2::makeShop(ebterrain);

EB2::Build(gshop, a_geom, max_level_here, max_level_here+max_coarsening_level);

m_has_eb = 1;

} else if (m_type == "box") {

Print() << "\nBuilding box geometry.\n";
make_box(a_geom);
m_has_eb = 1;

} else {

EB2::AllRegularIF regular;
auto gshop = EB2::makeShop(regular);
build_level(a_geom, gshop);
}
}

void
eb_::
make_factory ( Geometry const& a_geom,
DistributionMapping const& a_dmap,
BoxArray const& a_grids)
{
Print() << "making EB factory\n";
m_factory = std::make_unique<EBFArrayBoxFactory>(*m_eb_level, a_geom, a_grids, a_dmap,
Vector<int>{nghost_basic(), nghost_volume(), nghost_full()}, m_support_level);

if (m_write_eb_surface) {
WriteEBSurface(a_grids, a_dmap, a_geom, m_factory.get());
}

{ int const idim(0);

Print() << "making EB staggered u-factory\n";
//m_u_factory.set_verbose();
m_u_factory.define(idim, a_geom, a_grids, a_dmap,
Vector<int>{nghost_basic(), nghost_volume(), nghost_full()},
m_factory.get());
}

{ int const idim(1);
Print() << "making EB staggered v-factory\n";
//m_v_factory.set_verbose();
m_v_factory.define(idim, a_geom, a_grids, a_dmap,
Vector<int>{nghost_basic(), nghost_volume(), nghost_full()},
m_factory.get());
}

{ int const idim(2);
Print() << "making EB staggered w-factory\n";
//m_w_factory.set_verbose();
m_w_factory.define(idim, a_geom, a_grids, a_dmap,
Vector<int>{nghost_basic(), nghost_volume(), nghost_full()},
m_factory.get());
}

Print() << "\nDone making EB factory.\n\n";
}
48 changes: 48 additions & 0 deletions Source/EB/ERF_EBAux.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef ERF_EB_AUX_H_
#define ERF_EB_AUX_H_

#include <AMReX_Geometry.H>
#include <AMReX_DistributionMapping.H>
#include <AMReX_BoxArray.H>

#include <AMReX_EB2.H>
#include <AMReX_EBFabFactory.H>

class eb_aux_
{
public:

eb_aux_ ();
~eb_aux_ ();

void define ( int const& a_idim,
amrex::Geometry const& a_geom,
amrex::BoxArray const& a_grids,
amrex::DistributionMapping const& a_dmap,
amrex::Vector<int> const& a_ngrow,
amrex::EBFArrayBoxFactory const* a_factory);

void set_verbose ( ) { m_verbose = 1; }

private:

int m_verbose;

// int m_defined;

amrex::FabArray<amrex::EBCellFlagFab>* m_cellflags = nullptr;

amrex::MultiFab* m_volfrac = nullptr;

// amrex::MultiCutFab* m_centroid = nullptr;
// amrex::MultiCutFab* m_bndrycent = nullptr;
// amrex::MultiCutFab* m_bndryarea = nullptr;
// amrex::MultiCutFab* m_bndrynorm = nullptr;

// amrex::Array<amrex::MultiCutFab*,AMREX_SPACEDIM> m_areafrac {{AMREX_D_DECL(nullptr, nullptr, nullptr)}};
// amrex::Array<amrex::MultiCutFab*,AMREX_SPACEDIM> m_facecent {{AMREX_D_DECL(nullptr, nullptr, nullptr)}};
// amrex::Array<amrex::MultiCutFab*,AMREX_SPACEDIM> m_edgecent {{AMREX_D_DECL(nullptr, nullptr, nullptr)}};

};

#endif
Loading

0 comments on commit 5be1998

Please sign in to comment.