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

compressible bc with face-based uvw #284

Merged
merged 6 commits into from
Jun 25, 2024
Merged
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
24 changes: 14 additions & 10 deletions src/BCintegrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
#include "outletBC.hpp"
#include "wallBC.hpp"

BCintegrator::BCintegrator(MPI_Groups *_groupsMPI, ParMesh *_mesh, ParFiniteElementSpace *_vfes,
IntegrationRules *_intRules, RiemannSolver *rsolver_, double &_dt, GasMixture *_mixture,
GasMixture *d_mixture, Fluxes *_fluxClass, ParGridFunction *_Up, ParGridFunction *_gradUp,
const boundaryFaceIntegrationData &boundary_face_data, const int _dim,
const int _num_equation, double &_max_char_speed, RunConfiguration &_runFile,
BCintegrator::BCintegrator(bool _mpiRoot, MPI_Groups *_groupsMPI, ParMesh *_mesh, ParFiniteElementSpace *_vfes,
IntegrationRules *_intRules, RiemannSolver *rsolver_, double &_dt, double *_time,
GasMixture *_mixture, GasMixture *d_mixture, Fluxes *_fluxClass, ParGridFunction *_Up,
ParGridFunction *_gradUp, const boundaryFaceIntegrationData &boundary_face_data,
const int _dim, const int _num_equation, double &_max_char_speed, RunConfiguration &_runFile,
Array<int> &local_attr, const int &_maxIntPoints, const int &_maxDofs,
ParGridFunction *distance)
: groupsMPI(_groupsMPI),
Expand All @@ -65,6 +65,10 @@ BCintegrator::BCintegrator(MPI_Groups *_groupsMPI, ParMesh *_mesh, ParFiniteElem
outletBCmap.clear();
wallBCmap.clear();

mpiRoot = _mpiRoot;
time = *_time;
pTime = _time;

// Init inlet BCs
for (size_t in = 0; in < config.GetInletPatchType()->size(); in++) {
std::pair<int, InletType> patchANDtype = (*config.GetInletPatchType())[in];
Expand Down Expand Up @@ -222,17 +226,17 @@ void BCintegrator::initBCs() {
}

void BCintegrator::computeBdrFlux(const int attr, Vector &normal, Vector &stateIn, DenseMatrix &gradState,
Vector transip, double delta, double distance, Vector &bdrFlux) {
Vector transip, double delta, double time, double distance, Vector &bdrFlux) {
std::unordered_map<int, BoundaryCondition *>::const_iterator ibc = inletBCmap.find(attr);
std::unordered_map<int, BoundaryCondition *>::const_iterator obc = outletBCmap.find(attr);
std::unordered_map<int, BoundaryCondition *>::const_iterator wbc = wallBCmap.find(attr);

if (ibc != inletBCmap.end())
ibc->second->computeBdrFlux(normal, stateIn, gradState, transip, delta, distance, bdrFlux);
ibc->second->computeBdrFlux(normal, stateIn, gradState, transip, delta, time, distance, bdrFlux);
if (obc != outletBCmap.end())
obc->second->computeBdrFlux(normal, stateIn, gradState, transip, delta, distance, bdrFlux);
obc->second->computeBdrFlux(normal, stateIn, gradState, transip, delta, time, distance, bdrFlux);
if (wbc != wallBCmap.end())
wbc->second->computeBdrFlux(normal, stateIn, gradState, transip, delta, distance, bdrFlux);
wbc->second->computeBdrFlux(normal, stateIn, gradState, transip, delta, time, distance, bdrFlux);

// BCmap[attr]->computeBdrFlux(normal, stateIn, gradState, radius, bdrFlux);
}
Expand Down Expand Up @@ -417,7 +421,7 @@ void BCintegrator::AssembleFaceVector(const FiniteElement &el1, const FiniteElem
radius = transip[0];
}

computeBdrFlux(Tr.Attribute, nor, funval1, iGradUp, transip, delta, d1, fluxN);
computeBdrFlux(Tr.Attribute, nor, funval1, iGradUp, transip, delta, *pTime, d1, fluxN);
fluxN *= ip.weight;

if (config.isAxisymmetric()) {
Expand Down
17 changes: 11 additions & 6 deletions src/BCintegrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,21 @@ class BCintegrator : public NonlinearFormIntegrator {
std::unordered_map<int, BoundaryCondition *> outletBCmap;
std::unordered_map<int, BoundaryCondition *> wallBCmap;

bool mpiRoot;
double time;
double *pTime;

// void calcMeanState();
void computeBdrFlux(const int attr, Vector &normal, Vector &stateIn, DenseMatrix &gradState, Vector transip,
double delta, double distance, Vector &bdrFlux);
double delta, double time, double distance, Vector &bdrFlux);

public:
BCintegrator(MPI_Groups *_groupsMPI, ParMesh *_mesh, ParFiniteElementSpace *_vfes, IntegrationRules *_intRules,
RiemannSolver *rsolver_, double &_dt, GasMixture *mixture, GasMixture *d_mixture, Fluxes *_fluxClass,
ParGridFunction *_Up, ParGridFunction *_gradUp, const boundaryFaceIntegrationData &boundary_face_data,
const int _dim, const int _num_equation, double &_max_char_speed, RunConfiguration &_runFile,
Array<int> &local_bdr_attr, const int &_maxIntPoints, const int &_maxDofs, ParGridFunction *distance_);
BCintegrator(bool _mpiRoot, MPI_Groups *_groupsMPI, ParMesh *_mesh, ParFiniteElementSpace *_vfes,
IntegrationRules *_intRules, RiemannSolver *rsolver_, double &_dt, double *_time, GasMixture *mixture,
GasMixture *d_mixture, Fluxes *_fluxClass, ParGridFunction *_Up, ParGridFunction *_gradUp,
const boundaryFaceIntegrationData &boundary_face_data, const int _dim, const int _num_equation,
double &_max_char_speed, RunConfiguration &_runFile, Array<int> &local_bdr_attr,
const int &_maxIntPoints, const int &_maxDofs, ParGridFunction *distance_);
~BCintegrator();

virtual void AssembleFaceVector(const FiniteElement &el1, const FiniteElement &el2, FaceElementTransformations &Tr,
Expand Down
2 changes: 1 addition & 1 deletion src/BoundaryCondition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class BoundaryCondition {
virtual ~BoundaryCondition();

virtual void computeBdrFlux(Vector &normal, Vector &stateIn, DenseMatrix &gradState, Vector transip, double delta,
double distance, Vector &bdrFlux) = 0;
double time, double distance, Vector &bdrFlux) = 0;

/** \brief Set the boundary state used in the gradient evaluation
*
Expand Down
43 changes: 30 additions & 13 deletions src/M2ulPhyS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,14 @@ void M2ulPhyS::initVariables() {
Array<int> local_attr;
getAttributesInPartition(local_attr);

double *pTime;
pTime = &time;

bcIntegrator = NULL;
if (local_attr.Size() > 0) {
bcIntegrator = new BCintegrator(groupsMPI, mesh, vfes, intRules, rsolver, dt, mixture, d_mixture, d_fluxClass, Up,
gradUp, gpu_precomputed_data_.boundary_face_data, dim, num_equation, max_char_speed,
config, local_attr, maxIntPoints, maxDofs, distance_);
bcIntegrator = new BCintegrator(rank0_, groupsMPI, mesh, vfes, intRules, rsolver, dt, pTime, mixture, d_mixture,
d_fluxClass, Up, gradUp, gpu_precomputed_data_.boundary_face_data, dim,
num_equation, max_char_speed, config, local_attr, maxIntPoints, maxDofs, distance_);
}

// A->SetAssemblyLevel(AssemblyLevel::PARTIAL);
Expand Down Expand Up @@ -2783,19 +2786,19 @@ void M2ulPhyS::parseViscosityOptions() {
tpsP->getInput("viscosityMultiplierFunction/isEnabled", config.linViscData.isEnabled, false);
if (config.linViscData.isEnabled) {
auto normal = config.linViscData.normal.HostWrite();
tpsP->getRequiredVecElem("viscosityMultiplierFunction/norm", normal[0], 0);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/norm", normal[1], 1);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/norm", normal[2], 2);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/normal", normal[0], 0);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/normal", normal[1], 1);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/normal", normal[2], 2);

auto point0 = config.linViscData.point0.HostWrite();
tpsP->getRequiredVecElem("viscosityMultiplierFunction/p0", point0[0], 0);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/p0", point0[1], 1);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/p0", point0[2], 2);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/point", point0[0], 0);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/point", point0[1], 1);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/point", point0[2], 2);

auto pointInit = config.linViscData.pointInit.HostWrite();
tpsP->getRequiredVecElem("viscosityMultiplierFunction/pInit", pointInit[0], 0);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/pInit", pointInit[1], 1);
tpsP->getRequiredVecElem("viscosityMultiplierFunction/pInit", pointInit[2], 2);
// auto pointInit = config.linViscData.pointInit.HostWrite();
// tpsP->getRequiredVecElem("viscosityMultiplierFunction/pInit", pointInit[0], 0);
// tpsP->getRequiredVecElem("viscosityMultiplierFunction/pInit", pointInit[1], 1);
// tpsP->getRequiredVecElem("viscosityMultiplierFunction/pInit", pointInit[2], 2);

tpsP->getRequiredInput("viscosityMultiplierFunction/width", config.linViscData.width);
tpsP->getRequiredInput("viscosityMultiplierFunction/viscosityRatio", config.linViscData.viscRatio);
Expand Down Expand Up @@ -3563,6 +3566,9 @@ void M2ulPhyS::parseBCInputs() {
// Inlet Bcs
std::map<std::string, InletType> inletMapping;
inletMapping["subsonic"] = SUB_DENS_VEL;
inletMapping["subsonicFaceBasedX"] = SUB_DENS_VEL_FACE_X;
inletMapping["subsonicFaceBasedY"] = SUB_DENS_VEL_FACE_Y;
inletMapping["subsonicFaceBasedZ"] = SUB_DENS_VEL_FACE_Z;
inletMapping["nonreflecting"] = SUB_DENS_VEL_NR;
inletMapping["nonreflectingConstEntropy"] = SUB_VEL_CONST_ENT;

Expand All @@ -3582,6 +3588,17 @@ void M2ulPhyS::parseBCInputs() {
config.inletBC.Append(density);
config.inletBC.Append(uvw, 3);
}

// NOTE: if there is a need, make face-based general by specifying tangent, leave
// as either tan = x, y, or z for now as fixing requires changing BC interface
// across the board
// FaceBased requires an additional tangent definition cooresponding to the w-component in uvw
// if (type == "subsonicFaceBased") {
// Array<double> tangent2;
// tpsP->getRequiredVec((basepath + "/w-tangent").c_str(), tangent2, 3);
// config.inletBC.Append(tangent2, 3);
//}

// For multi-component gas, require (numActiveSpecies)-more inputs.
if ((config.workFluid != DRY_AIR) && (config.numSpecies > 1)) {
grvy_printf(GRVY_INFO, "\nInlet mass fraction of background species will not be used. \n");
Expand Down
16 changes: 8 additions & 8 deletions src/M2ulPhyS2Boltzmann.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ void M2ulPhyS::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 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
}
2 changes: 1 addition & 1 deletion src/chemistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ MFEM_HOST_DEVICE Chemistry::~Chemistry() {
}
}

MFEM_HOST_DEVICE void Chemistry::setRates(const double * data, int size) {
MFEM_HOST_DEVICE void Chemistry::setRates(const double *data, int size) {
for (int r = 0; r < numReactions_; r++) {
if (reactions_[r]->reactionModel == GRIDFUNCTION_RXN) {
GridFunctionReaction *rx = (GridFunctionReaction *)(reactions_[r]);
Expand Down
2 changes: 1 addition & 1 deletion src/chemistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Chemistry {

// Set the grid function rates for GRIDFUNCTION_RXN reaction types
void setGridFunctionRates(mfem::GridFunction &f);
MFEM_HOST_DEVICE void setRates(const double * data, int size);
MFEM_HOST_DEVICE void setRates(const double *data, int size);

// return Vector of reaction rate coefficients, with the size of numReaction_.
// WARNING(marc) I have removed "virtual" qualifier here assuming these functions will not
Expand Down
16 changes: 11 additions & 5 deletions src/dataStructures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,17 @@ enum SpeciesPrimitiveType { MASS_FRACTION, MOLE_FRACTION, NUMBER_DENSITY, NUM_SP
enum boundaryCategory { INLET, OUTLET, WALL, NUM_BC_CATEGORIES };

enum InletType {
UNI_DENS_VEL, // uniform inlet with density and vel specified
INTERPOLATE, // from an external data file
SUB_DENS_VEL, // Subsonic inlet specified by the density and velocity components
SUB_DENS_VEL_NR, // Non-reflecting subsonic inlet specified by the density and velocity components
SUB_VEL_CONST_ENT // Subsonic non-reflecting. Specified vel, keeps entropy constant
UNI_DENS_VEL, // uniform inlet with density and vel specified
INTERPOLATE, // from an external data file
SUB_DENS_VEL, // Subsonic inlet specified by the density and velocity components
SUB_DENS_VEL_FACE_X, // Subsonic inlet specified by the density and velocity component relative to the inlet face
// with u = normal, w = global x
SUB_DENS_VEL_FACE_Y, // Subsonic inlet specified by the density and velocity component relative to the inlet face
// with u = normal, w = global y
SUB_DENS_VEL_FACE_Z, // Subsonic inlet specified by the density and velocity component relative to the inlet face
// with u = normal, w = global z
SUB_DENS_VEL_NR, // Non-reflecting subsonic inlet specified by the density and velocity components
SUB_VEL_CONST_ENT // Subsonic non-reflecting. Specified vel, keeps entropy constant
};

enum OutletType {
Expand Down
4 changes: 2 additions & 2 deletions src/gpu_constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ __global__ void freeDeviceRadiation(Radiation *radiation) {
//---------------------------------------------------
// And finally device setters
//---------------------------------------------------
__global__ void deviceSetGridFunctionReactionData(const double * data, int size, GridFunctionReaction * reaction) {
__global__ void deviceSetGridFunctionReactionData(const double *data, int size, GridFunctionReaction *reaction) {
reaction->setData(data, size);
}

__global__ void deviceSetChemistryReactionData(const double * data, int size, Chemistry * chem) {
__global__ void deviceSetChemistryReactionData(const double *data, int size, Chemistry *chem) {
chem->setRates(data, size);
}

Expand Down
4 changes: 2 additions & 2 deletions src/gpu_constructor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ __global__ void freeDeviceChemistry(Chemistry *chem);
__global__ void freeDeviceRadiation(Radiation *radiation);

//! Set the data to a GridFunctionReaction
__global__ void deviceSetGridFunctionReactionData(const double * data, int size, GridFunctionReaction * reaction);
__global__ void deviceSetChemistryReactionData(const double * data, int size, Chemistry * chem);
__global__ void deviceSetGridFunctionReactionData(const double *data, int size, GridFunctionReaction *reaction);
__global__ void deviceSetChemistryReactionData(const double *data, int size, Chemistry *chem);

#endif // cuda or hip
} // namespace gpu
Expand Down
Loading
Loading