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

Adding the radiation module #313

Merged
merged 18 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
12 changes: 12 additions & 0 deletions Exec/Make.PeleLMeX
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ ifeq ($(USE_SOOT), TRUE)
DEFINES += -DNUM_SOOT_MOMENTS=$(NUM_SOOT_MOMENTS)
endif

ifeq ($(USE_PELERAD), TRUE)
$(info ******** Radiation model is activated ********)
wjge marked this conversation as resolved.
Show resolved Hide resolved
DEFINES += -DPELELM_USE_RAD
ifeq ($(USE_HIP), TRUE)
$(info ******** Radiation module is using hip ********)
wjge marked this conversation as resolved.
Show resolved Hide resolved
DEFINES += -DPELERAD_USE_HIP
endif
endif

Bpack += $(foreach dir, $(LMdirs), $(PELELMEX_HOME)/$(dir)/Make.package)
Blocs += $(foreach dir, $(LMdirs), $(PELELMEX_HOME)/$(dir))

Expand Down Expand Up @@ -142,6 +151,9 @@ ifeq ($(USE_SOOT), TRUE)
Bpack += $(PELEMP_HOME)/Source/Soot_Models/Make.package
Blocs += $(PELEMP_HOME)/Source/Soot_Models
endif
ifeq ($(USE_PELERAD), TRUE)
Blocs += $(PELERAD_HOME)/src
endif

#---------------
# Includes
Expand Down
6 changes: 6 additions & 0 deletions Source/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ ifeq ($(USE_SOOT), TRUE)
CEXE_sources += PeleLMeX_Soot.cpp
endif

ifeq ($(USE_PELERAD), TRUE)
CEXE_sources += PeleLMeX_Rad.cpp
endif

ifeq ($(USE_PARTICLES), TRUE)
CEXE_sources += PeleLMeX_SprayParticles.cpp
endif


19 changes: 19 additions & 0 deletions Source/PeleLMeX.H
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include <AMReX_ErrorList.H>
#include <AMReX_VisMF.H>

#ifdef PELELM_USE_RAD
#include <PeleLMRad.hpp>
wjge marked this conversation as resolved.
Show resolved Hide resolved
#endif

// Forward declarations
#ifdef PELELM_USE_SPRAY
class SprayParticleContainer;
Expand Down Expand Up @@ -857,6 +861,15 @@ public:
//-----------------------------------------------------------------------------
#endif

#ifdef PELELM_USE_RAD
// Initialize the radiation module
void RadInit();

// Compute the radiation source term
void computeRadSource(
const PeleLM::TimeStamp& a_timestamp, const amrex::Real a_dt);
#endif

//-----------------------------------------------------------------------------
// EOS

Expand Down Expand Up @@ -1679,6 +1692,12 @@ public:
bool do_soot_solve;
#endif

#ifdef PELELM_USE_RAD
// Radiation parameters
std::unique_ptr<PeleRad::Radiation> rad_model;
bool do_rad_solve;
#endif

// Active controller
int m_ctrl_active{0};
int m_ctrl_useTemp{0};
Expand Down
7 changes: 7 additions & 0 deletions Source/PeleLMeX_Advance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ PeleLM::Advance(int is_initIter)
computeSootSource(AmrOldTime, m_dt);
}
#endif
#ifdef PELELM_USE_RAD
wjge marked this conversation as resolved.
Show resolved Hide resolved
if (do_rad_solve) {
BL_PROFILE_VAR("PeleLM::advance::rad", PLM_RAD);
computeRadSource(AmrOldTime, m_dt);
wjge marked this conversation as resolved.
Show resolved Hide resolved
BL_PROFILE_VAR_STOP(PLM_RAD);
}
#endif

if (m_incompressible == 0) {
floorSpecies(AmrOldTime);
Expand Down
10 changes: 10 additions & 0 deletions Source/PeleLMeX_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ PeleLM::initData()
#ifdef PELELM_USE_SPRAY
SprayInit();
#endif
#ifdef PELELM_USE_RAD
if (do_rad_solve) {
RadInit();
}
#endif

//----------------------------------------------------------------
// Set typical values
Expand Down Expand Up @@ -249,6 +254,11 @@ PeleLM::initData()
#ifdef PELELM_USE_SPRAY
SprayInit();
#endif
#ifdef PELELM_USE_RAD
if (do_rad_solve) {
RadInit();
}
#endif
#ifdef PELE_USE_EFIELD
// If restarting from a non efield simulation
if (m_restart_nonEF) {
Expand Down
25 changes: 25 additions & 0 deletions Source/PeleLMeX_Plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#ifdef PELELM_USE_SOOT
#include "SootModel.H"
#endif
#ifdef PELELM_USE_RAD
#include "PeleLMRad.hpp"
#endif

using namespace amrex;

namespace {
Expand Down Expand Up @@ -116,6 +120,10 @@ PeleLM::WritePlotFile()
ncomp += 1;
#endif

#ifdef PELELM_USE_RAD
ncomp += 3;
wjge marked this conversation as resolved.
Show resolved Hide resolved
#endif

// Derive
int deriveEntryCount = 0;
for (int ivar = 0; ivar < m_derivePlotVarCount; ivar++) {
Expand Down Expand Up @@ -177,6 +185,13 @@ PeleLM::WritePlotFile()
std::string sootname = soot_model->sootVariableName(mom);
plt_VarsName.push_back(sootname);
}
#endif
#ifdef PELELM_USE_RAD
if (do_rad_solve) {
plt_VarsName.push_back("rad.G");
plt_VarsName.push_back("rad.kappa");
plt_VarsName.push_back("rad.emis");
}
#endif
if (m_has_divu != 0) {
plt_VarsName.push_back("divu");
Expand Down Expand Up @@ -283,6 +298,16 @@ PeleLM::WritePlotFile()
mf_plt[lev], m_leveldata_new[lev]->state, FIRSTSOOT, cnt, NUMSOOTVAR,
0);
cnt += NUMSOOTVAR;
#endif
#ifdef PELELM_USE_RAD
if (do_rad_solve) {
MultiFab::Copy(mf_plt[lev], rad_model->G()[lev], 0, cnt, 1, 0);
cnt += 1;
MultiFab::Copy(mf_plt[lev], rad_model->kappa()[lev], 0, cnt, 1, 0);
cnt += 1;
MultiFab::Copy(mf_plt[lev], rad_model->emis()[lev], 0, cnt, 1, 0);
cnt += 1;
}
#endif
if (m_has_divu != 0) {
MultiFab::Copy(mf_plt[lev], m_leveldata_new[lev]->divu, 0, cnt, 1, 0);
Expand Down
88 changes: 88 additions & 0 deletions Source/PeleLMeX_Rad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include <PeleLMeX.H>
#include <PeleLMeX_Derive.H>

#include <PeleLMRad.hpp>

void
PeleLM::RadInit()
{
amrex::Print() << "Radiation model is activated "
<< "\n";
wjge marked this conversation as resolved.
Show resolved Hide resolved
PeleRad::RadComps rc;
amrex::Vector<std::string> names;
pele::physics::eos::speciesNames<pele::physics::PhysicsType::eos_type>(names);
for (int i = 0; i < NUM_SPECIES; ++i) {
if (names[i] == "CO2") {
rc.co2Indx = i;
continue;
}
if (names[i] == "H2O") {
rc.h2oIndx = i;
continue;
}
if (names[i] == "CO")
rc.coIndx = i;
}
amrex::ParmParse mlmgpp("pelerad");

#ifdef AMREX_USE_EB
amrex::Print() << "The EB support is activated in the radiation module \n";
rad_model = std::make_unique<PeleRad::Radiation>(
geom, grids, dmap, rc, mlmgpp, m_factory);
#else
rad_model =
std::make_unique<PeleRad::Radiation>(geom, grids, dmap, rc, mlmgpp);
#endif
}

void
PeleLM::computeRadSource(
const PeleLM::TimeStamp& a_timestamp, const amrex::Real a_dt)
{
int const co2Indx = rad_model->readRadIndices().co2Indx;
int const h2oIndx = rad_model->readRadIndices().h2oIndx;
int const coIndx = rad_model->readRadIndices().coIndx;

BL_PROFILE_VAR("PeleLM::advance::rad::spec", PLM_RAD_SPEC);
for (int lev = 0; lev <= finest_level; lev++) {
auto ldata_p = PeleLM::getLevelDataPtr(lev, a_timestamp);
#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for (amrex::MFIter mfi(*(m_extSource[lev]), amrex::TilingIfNotGPU());
mfi.isValid(); ++mfi) {
auto const& q_yin_co2 =
ldata_p->state.const_array(mfi, FIRSTSPEC + co2Indx);
auto const& q_yin_h2o =
ldata_p->state.const_array(mfi, FIRSTSPEC + h2oIndx);
auto const& q_yin_co =
ldata_p->state.const_array(mfi, FIRSTSPEC + coIndx);
auto const& q_Tin = ldata_p->state.const_array(mfi, TEMP);
auto const& q_Pin = ldata_p->state.const_array(mfi, RHORT);
#ifdef PELELM_USE_SOOT
auto const& q_fvin = ldata_p->state.const_array(mfi, FIRSTSOOT + 1);
rad_model->updateSpecProp(
mfi, q_yin_co2, q_yin_h2o, q_yin_co, q_Tin, q_Pin, q_fvin, lev);
#else
rad_model->updateSpecProp(
mfi, q_yin_co2, q_yin_h2o, q_yin_co, q_Tin, q_Pin, lev);
#endif
}
}
BL_PROFILE_VAR_STOP(PLM_RAD_SPEC);

BL_PROFILE_VAR("PeleLM::advance::rad::solve", PLM_RAD_SOLV);
rad_model->evaluateRad();
BL_PROFILE_VAR_STOP(PLM_RAD_SOLV);

for (int lev = 0; lev <= finest_level; lev++) {
#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for (amrex::MFIter mfi(*(m_extSource[lev]), amrex::TilingIfNotGPU());
mfi.isValid(); ++mfi) {
auto const& source_arr = m_extSource[lev]->array(mfi, RHOH);
rad_model->calcRadSource(mfi, source_arr, lev);
wjge marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
12 changes: 12 additions & 0 deletions Source/PeleLMeX_Setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#ifdef PELELM_USE_SOOT
#include "SootModel.H"
#endif

#ifdef PELELM_USE_RAD
#include <PeleLMRad.hpp>
wjge marked this conversation as resolved.
Show resolved Hide resolved
#endif

using namespace amrex;

static Box
Expand Down Expand Up @@ -588,6 +593,13 @@ PeleLM::readParameters()
}
soot_model->readSootParams();
#endif
#ifdef PELELM_USE_RAD
do_rad_solve = false;
pp.query("do_rad_solve", do_rad_solve);
if (m_verbose && do_rad_solve) {
Print() << "Simulation performed with radiation modeling \n";
}
#endif
}

void
Expand Down
Loading