Skip to content

Commit

Permalink
adding lte support
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigfried Haering committed Jul 2, 2024
1 parent f412352 commit a931a34
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/calorically_perfect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class CaloricallyPerfectThermoChem : public ThermoChemModelBase {
double hsolve_rtol_;
double hsolve_atol_;

// streamwise-stabilization
bool sw_stab_;
double re_offset_;
double re_factor_;
Expand Down
2 changes: 1 addition & 1 deletion src/loMach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void LoMachSolver::initialize() {
thermo_ =
new CaloricallyPerfectThermoChem(pmesh_, &loMach_opts_, temporal_coeff_, (meshData_->getGridScale()), tpsP_);
} else if (loMach_opts_.thermo_solver == "lte-thermo-chem") {
thermo_ = new LteThermoChem(pmesh_, &loMach_opts_, temporal_coeff_, tpsP_);
thermo_ = new LteThermoChem(pmesh_, &loMach_opts_, temporal_coeff_, (meshData_->getGridScale()), tpsP_);
} else if (loMach_opts_.thermo_solver == "reacting-flow") {
thermo_ = new ReactingFlow(pmesh_, &loMach_opts_, temporal_coeff_, tpsP_);
} else {
Expand Down
89 changes: 87 additions & 2 deletions src/lte_thermo_chem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ static double sigmaTorchStartUp(const Vector &pos) {
static FunctionCoefficient sigma_start_up(sigmaTorchStartUp);

LteThermoChem::LteThermoChem(mfem::ParMesh *pmesh, LoMachOptions *loMach_opts, temporalSchemeCoefficients &time_coeff,
TPS::Tps *tps)
: tpsP_(tps), pmesh_(pmesh), time_coeff_(time_coeff) {
ParGridFunction *gridScale, TPS::Tps *tps)
: tpsP_(tps), pmesh_(pmesh), dim_(pmesh->Dimension()), time_coeff_(time_coeff) {
rank0_ = (pmesh_->GetMyRank() == 0);
order_ = loMach_opts->order;
gridScale_gf_ = gridScale;

tps->getInput("loMach/axisymmetric", axisym_, false);

Expand Down Expand Up @@ -166,6 +167,10 @@ LteThermoChem::LteThermoChem(mfem::ParMesh *pmesh, LoMachOptions *loMach_opts, t
tps->getInput("loMach/ltethermo/linear-solver-rtol", rtol_, 1e-12);
tps->getInput("loMach/ltethermo/linear-solver-max-iter", max_iter_, 1000);
tps->getInput("loMach/ltethermo/linear-solver-verbosity", pl_solve_, 0);

tps->getInput("loMach/ltethermo/streamwise-stabilization", sw_stab_, false);
tps->getInput("loMach/ltethermo/Reh_offset", re_offset_, 1.0);
tps->getInput("loMach/ltethermo/Reh_factor", re_factor_, 0.1);
}

LteThermoChem::~LteThermoChem() {
Expand All @@ -192,6 +197,7 @@ LteThermoChem::~LteThermoChem() {
delete M_rho_Cp_form_;
delete Ms_form_;
delete At_form_;
delete D_form_;
delete rho_Cp_u_coeff_;
delete un_next_coeff_;
delete kap_gradT_coeff_;
Expand All @@ -208,6 +214,8 @@ LteThermoChem::~LteThermoChem() {
// allocated in initializeSelf
delete sfes_;
delete sfec_;
delete vfes_;
delete vfec_;
}

void LteThermoChem::initializeSelf() {
Expand All @@ -219,6 +227,9 @@ void LteThermoChem::initializeSelf() {
sfec_ = new H1_FECollection(order_);
sfes_ = new ParFiniteElementSpace(pmesh_, sfec_);

vfec_ = new H1_FECollection(order_, dim_);
vfes_ = new ParFiniteElementSpace(pmesh_, vfec_, dim_);

// Check if fully periodic mesh
if (!(pmesh_->bdr_attributes.Size() == 0)) {
temp_ess_attr_.SetSize(pmesh_->bdr_attributes.Max());
Expand All @@ -230,6 +241,7 @@ void LteThermoChem::initializeSelf() {
if (rank0_) grvy_printf(ginfo, "LteThermoChem paces constructed...\n");

int sfes_truevsize = sfes_->GetTrueVSize();
int vfes_truevsize = vfes_->GetTrueVSize();

Qt_.SetSize(sfes_truevsize);
Qt_ = 0.0;
Expand Down Expand Up @@ -317,8 +329,16 @@ void LteThermoChem::initializeSelf() {
radiation_sink_.SetSize(sfes_truevsize);
radiation_sink_ = 0.0;

vel_gf_.SetSpace(vfes_);
tmpR1_gf_.SetSpace(vfes_);
tmpR0_gf_.SetSpace(sfes_);

swDiff_.SetSize(sfes_truevsize);
tmpR0_.SetSize(sfes_truevsize);
tmpR0a_.SetSize(sfes_truevsize);
tmpR0b_.SetSize(sfes_truevsize);
tmpR0c_.SetSize(sfes_truevsize);
tmpR1_.SetSize(vfes_truevsize);

R0PM0_gf_.SetSpace(sfes_);

Expand Down Expand Up @@ -628,6 +648,24 @@ void LteThermoChem::initializeOperators() {
M_rho_form_->Assemble();
M_rho_form_->FormSystemMatrix(empty, M_rho_);

// Divergence operator
D_form_ = new ParMixedBilinearForm(vfes_, sfes_);
VectorDivergenceIntegrator *vd_mblfi;
// if (axisym_) {
// vd_mblfi = new VectorDivergenceIntegrator(radius_coeff);
// } else {
vd_mblfi = new VectorDivergenceIntegrator();
// }
if (numerical_integ_) {
vd_mblfi->SetIntRule(&ir_nli);
}
D_form_->AddDomainIntegrator(vd_mblfi);
if (partial_assembly_) {
D_form_->SetAssemblyLevel(AssemblyLevel::PARTIAL);
}
D_form_->Assemble();
D_form_->FormRectangularSystemMatrix(empty, empty, D_op_);

// helmholtz
Ht_form_ = new ParBilinearForm(sfes_);
MassIntegrator *hmt_blfi;
Expand Down Expand Up @@ -905,6 +943,12 @@ void LteThermoChem::step() {
tmpR0_ = dtP_;
Ms_->AddMult(tmpR0_, resT_);

// Add streamwise stability to rhs
if (sw_stab_) {
streamwiseDiffusion(Tn_, swDiff_);
resT_.Add(1.0, swDiff_);
}

// Joule heating (and radiation sink)
jh_form_->Update();
jh_form_->Assemble();
Expand Down Expand Up @@ -1231,3 +1275,44 @@ void LteThermoChem::computeQt() {
Qt_.Neg();
Qt_gf_.SetFromTrueDofs(Qt_);
}

void LteThermoChem::streamwiseDiffusion(Vector &phi, Vector &swDiff) {
// compute streamwise gradient of input field
tmpR0_gf_.SetFromTrueDofs(phi);
(flow_interface_->velocity)->GetTrueDofs(tmpR0a_);
vel_gf_.SetFromTrueDofs(tmpR0a_);
streamwiseGrad(dim_, tmpR0_gf_, vel_gf_, tmpR1_gf_);

// divergence of sw-grad
tmpR1_gf_.GetTrueDofs(tmpR1_);
D_op_->Mult(tmpR1_, swDiff);

gridScale_gf_->GetTrueDofs(tmpR0b_);
(turbModel_interface_->eddy_viscosity)->GetTrueDofs(tmpR0c_);

const double *rho = rn_.HostRead();
const double *vel = tmpR0a_.HostRead();
const double *del = tmpR0b_.HostRead();
const double *mu = visc_.HostRead();
const double *muT = tmpR0c_.HostRead();
double *data = swDiff.HostReadWrite();

int Sdof = rn_.Size();
for (int dof = 0; dof < Sdof; dof++) {
double Umag = 0.0;
for (int i = 0; i < dim_; i++) Umag += vel[i] * vel[i];
Umag = std::sqrt(Umag);

// element Re
double Re = Umag * del[dof] * rho[dof] / (mu[dof] + muT[dof]);

// SUPG weight
double Csupg = 0.5 * (tanh(re_factor_ * Re - re_offset_) + 1.0);

// streamwise diffusion coeff
double CswDiff = Csupg * Umag * del[dof] * rho[dof];

// scaled streamwise Laplacian
data[dof] *= CswDiff;
}
}
26 changes: 24 additions & 2 deletions src/lte_thermo_chem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class LteThermoChem final : public ThermoChemModelBase {

// Mesh and discretization scheme info
ParMesh *pmesh_ = nullptr;
int dim_;
int order_;
IntegrationRules gll_rules_;
const temporalSchemeCoefficients &time_coeff_;
Expand All @@ -95,6 +96,11 @@ class LteThermoChem final : public ThermoChemModelBase {
int max_iter_; /**< Maximum number of linear solver iterations */
double rtol_ = 1e-12; /**< Linear solver relative tolerance */

// streamwise-stabilization
bool sw_stab_;
double re_offset_;
double re_factor_;

// Boundary condition info
Array<int> temp_ess_attr_; /**< List of patches with Dirichlet BC on temperature */
Array<int> Qt_ess_attr_; /**< List of patches with Dirichlet BC on Q (thermal divergence) */
Expand Down Expand Up @@ -131,6 +137,10 @@ class LteThermoChem final : public ThermoChemModelBase {
// Scalar \f$H^1\f$ finite element space.
ParFiniteElementSpace *sfes_ = nullptr;

// Vector fe collection and space
FiniteElementCollection *vfec_ = nullptr;
ParFiniteElementSpace *vfes_ = nullptr;

// Fields
ParGridFunction Tnm1_gf_, Tnm2_gf_;
ParGridFunction Tn_gf_, Tn_next_gf_, Text_gf_, resT_gf_;
Expand All @@ -148,6 +158,11 @@ class LteThermoChem final : public ThermoChemModelBase {
ParGridFunction R0PM0_gf_;
ParGridFunction Qt_gf_;

ParGridFunction tmpR0_gf_;
ParGridFunction tmpR1_gf_;
ParGridFunction vel_gf_;
ParGridFunction *gridScale_gf_ = nullptr;

// ParGridFunction *buffer_tInlet_ = nullptr;
GridFunctionCoefficient *temperature_bc_field_ = nullptr;

Expand Down Expand Up @@ -195,6 +210,8 @@ class LteThermoChem final : public ThermoChemModelBase {
ParBilinearForm *LQ_form_ = nullptr;
ParLinearForm *LQ_bdry_ = nullptr;

ParMixedBilinearForm *D_form_ = nullptr;

OperatorHandle At_;
OperatorHandle Ht_;
OperatorHandle Ms_;
Expand All @@ -203,6 +220,7 @@ class LteThermoChem final : public ThermoChemModelBase {
OperatorHandle M_rho_Cp_;
OperatorHandle M_rho_;
OperatorHandle A_rho_;
OperatorHandle D_op_;

mfem::Solver *MsInvPC_ = nullptr;
mfem::CGSolver *MsInv_ = nullptr;
Expand All @@ -218,7 +236,9 @@ class LteThermoChem final : public ThermoChemModelBase {
Vector NTn_, NTnm1_, NTnm2_;
Vector Text_;
Vector resT_;
Vector tmpR0_, tmpR0b_;
Vector tmpR0_, tmpR0a_, tmpR0b_, tmpR0c_;
Vector tmpR1_;
Vector swDiff_;

Vector Qt_;
Vector rn_, rnm1_, rnm2_, rnm3_;
Expand All @@ -241,7 +261,8 @@ class LteThermoChem final : public ThermoChemModelBase {
ParGridFunction Tn_filtered_gf_;

public:
LteThermoChem(mfem::ParMesh *pmesh, LoMachOptions *loMach_opts, temporalSchemeCoefficients &timeCoeff, TPS::Tps *tps);
LteThermoChem(mfem::ParMesh *pmesh, LoMachOptions *loMach_opts, temporalSchemeCoefficients &timeCoeff,
ParGridFunction *gridScale, TPS::Tps *tps);
virtual ~LteThermoChem();

// Functions overriden from base class
Expand All @@ -261,6 +282,7 @@ class LteThermoChem final : public ThermoChemModelBase {
void computeExplicitTempConvectionOP();
void computeQt();
void updateHistory();
void streamwiseDiffusion(Vector &phi, Vector &swDiff);

/// Return a pointer to the current temperature ParGridFunction.
ParGridFunction *GetCurrentTemperature() { return &Tn_gf_; }
Expand Down
5 changes: 1 addition & 4 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,9 +1166,6 @@ bool copyFile(const char *SRC, const char *DEST) {
}

void streamwiseGrad(int dim, ParGridFunction &phi, ParGridFunction &u, ParGridFunction &swGrad) {
// need to make this general...
// int dim_ = 3;

/*
std::cout << "maxInd minusInd plusInd" << endl;
std::cout << 0 << " " << ((0-1) % dim_ + dim_) % dim_ << " " << (0 + 1) % dim_ << endl;
Expand Down Expand Up @@ -1241,7 +1238,7 @@ void streamwiseGrad(int dim, ParGridFunction &phi, ParGridFunction &u, ParGridFu
if (dim == 3) M(d, 2) = unitT2[d];
}

// streamwise diffusion coeff
// streamwise coeff
DenseMatrix swM(dim, dim);
swM = 0.0;
swM(0, 0) = 1.0;
Expand Down

0 comments on commit a931a34

Please sign in to comment.