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

Preliminary implementation of bte coupling for low-mach #302

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion src/M2ulPhyS2Boltzmann.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "M2ulPhyS.hpp"
#include "tps2Boltzmann.hpp"

// CPU version (just for starting up)
void M2ulPhyS::push(TPS::Tps2Boltzmann &interface) {
assert(interface.IsInitialized());

Expand Down
58 changes: 58 additions & 0 deletions src/reactingFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "loMach.hpp"
#include "loMach_options.hpp"
#include "radiation.hpp"
#include "tps2Boltzmann.hpp"

using namespace mfem;
using namespace mfem::common;
Expand Down Expand Up @@ -363,6 +364,11 @@ ReactingFlow::ReactingFlow(mfem::ParMesh *pmesh, LoMachOptions *loMach_opts, tem
tpsP_->getRequiredInput((basepath + "/radius").c_str(), R);
rxnModelParamsHost.push_back(Vector({R}));

} else if (model == "bte") {
reactionModels[r - 1] = GRIDFUNCTION_RXN;
int index;
tpsP_->getRequiredInput((basepath + "/bte/index").c_str(), index);
chemistryInput_.reactionInputs[r - 1].indexInput = index;
} else {
grvy_printf(GRVY_ERROR, "\nUnknown reaction_model -> %s", model.c_str());
exit(ERROR);
Expand Down Expand Up @@ -2835,6 +2841,58 @@ double species_uniform(const Vector &coords, double t) {
return yn;
}

void ReactingFlow::push(TPS::Tps2Boltzmann &interface) {
assert(interface.IsInitialized());

const int nscalardofs(vfes_->GetNDofs());

mfem::ParGridFunction *species =
new mfem::ParGridFunction(&interface.NativeFes(TPS::Tps2Boltzmann::Index::SpeciesDensities));

double *species_data = species->HostWrite();

const double *dataRho = rn_.HostRead();
const double *dataY = Yn_.HostRead();

double state_local[gpudata::MAXEQUATIONS];
double species_local[gpudata::MAXSPECIES];

for (int i = 0; i < nscalardofs; i++) {
for (int asp = 0; asp < nActiveSpecies_; asp++)
state_local[asp] = dataRho[i]*dataY[i+asp*nscalardofs];

mixture_->computeNumberDensities(state_local, species_local);


for (int sp = 0; sp < interface.Nspecies(); sp++)
species_data[i + sp * nscalardofs] = AVOGADRONUMBER * species_local[sp];
}

interface.interpolateFromNativeFES(*species, TPS::Tps2Boltzmann::Index::SpeciesDensities);
interface.interpolateFromNativeFES(Tn_gf_, TPS::Tps2Boltzmann::Index::HeavyTemperature);
interface.interpolateFromNativeFES(Tn_gf_, TPS::Tps2Boltzmann::Index::ElectronTemperature);

interface.setTimeStep(this->dt_);
interface.setCurrentTime(this->time_);

delete species;
}

void ReactingFlow::fetch(TPS::Tps2Boltzmann &interface) {
mfem::ParFiniteElementSpace *reaction_rates_fes(&(interface.NativeFes(TPS::Tps2Boltzmann::Index::ReactionRates)));
externalReactionRates_.reset(new mfem::ParGridFunction(reaction_rates_fes));
interface.interpolateToNativeFES(*externalReactionRates_, TPS::Tps2Boltzmann::Index::ReactionRates);
#if defined(_CUDA_) || defined(_HIP_)
const double *data(externalReactionRates_->Read());
int size(externalReactionRates_->FESpace()->GetNDofs());
assert(externalReactionRates_->FESpace()->GetOrdering() == mfem::Ordering::byNODES);
gpu::deviceSetChemistryReactionData<<<1, 1>>>(data, size, chemistry_);
#else
chemistry_->setGridFunctionRates(*externalReactionRates_);
#endif
}


#if 0
void ReactingFlow::uniformInlet() {
int myRank;
Expand Down
6 changes: 6 additions & 0 deletions src/reactingFlow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
// forward-declaration for Tps support class
namespace TPS {
class Tps;
class Tps2Boltzmann;
}

#include <hdf5.h>
Expand Down Expand Up @@ -102,6 +103,8 @@ class ReactingFlow : public ThermoChemModelBase {
PerfectMixture *mixture_ = NULL;
ArgonMixtureTransport *transport_ = NULL;
Chemistry *chemistry_ = NULL;
// External reaction rates when chemistry is implemented using the BTE option
std::unique_ptr<ParGridFunction> externalReactionRates_;

std::vector<std::string> speciesNames_;
std::map<std::string, int> atomMap_;
Expand Down Expand Up @@ -415,5 +418,8 @@ class ReactingFlow : public ThermoChemModelBase {

void evalSubstepNumber();
void readTableWrapper(std::string inputPath, TableInput &result);

void push(TPS::Tps2Boltzmann &interface);
void fetch(TPS::Tps2Boltzmann &interface);
};
#endif // REACTINGFLOW_HPP_