Skip to content

Commit

Permalink
attempt to remove duplicate code with streamwise-stab. Added Re_h gf …
Browse files Browse the repository at this point in the history
…and calcs in flow which is exported to thermo-chem, moved supg-like section to utils, changed interface for streamwiseDiffusion routines to take the gradients directly. Commented out communications portions of curl calcs as they seem to be introducing partition imprinting. Fixed small bug in channel temp ic
  • Loading branch information
Sigfried Haering committed Jul 4, 2024
1 parent ff4cdb9 commit 6abe504
Show file tree
Hide file tree
Showing 10 changed files with 361 additions and 44 deletions.
101 changes: 92 additions & 9 deletions src/calorically_perfect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,14 @@ CaloricallyPerfectThermoChem::~CaloricallyPerfectThermoChem() {
delete HtInvPC_;
delete MsInv_;
delete MsInvPC_;
delete Mv_inv_;
delete Mv_inv_pc_;
delete Ht_form_;
delete MsRho_form_;
delete Ms_form_;
delete Mv_form_;
delete At_form_;
delete G_form_;
delete D_form_;
delete rhou_coeff_;
delete rhon_next_coeff_;
Expand Down Expand Up @@ -262,6 +266,9 @@ void CaloricallyPerfectThermoChem::initializeSelf() {
tmpR0c_.SetSize(sfes_truevsize);
tmpR1_.SetSize(vfes_truevsize);

gradT_.SetSize(vfes_truevsize);
gradT_ = 0.0;

R0PM0_gf_.SetSpace(sfes_);

rhoDt.SetSpace(sfes_);
Expand Down Expand Up @@ -510,6 +517,43 @@ void CaloricallyPerfectThermoChem::initializeOperators() {
D_form_->Assemble();
D_form_->FormRectangularSystemMatrix(empty, empty, D_op_);

// Gradient
G_form_ = new ParMixedBilinearForm(sfes_, vfes_);
// auto *g_mblfi = new GradientIntegrator();
GradientIntegrator *g_mblfi;
// if (axisym_) {
// g_mblfi = new GradientIntegrator(radius_coeff);
// } else {
g_mblfi = new GradientIntegrator();
//}
if (numerical_integ_) {
g_mblfi->SetIntRule(&ir_nli);
}
G_form_->AddDomainIntegrator(g_mblfi);
if (partial_assembly_) {
G_form_->SetAssemblyLevel(AssemblyLevel::PARTIAL);
}
G_form_->Assemble();
G_form_->FormRectangularSystemMatrix(empty, empty, G_op_);

// Mass matrix for the vector (gradT)
Mv_form_ = new ParBilinearForm(vfes_);
VectorMassIntegrator *mv_blfi;
// if (axisym_) {
// mv_blfi = new VectorMassIntegrator(radius_coeff);
// } else {
mv_blfi = new VectorMassIntegrator();
//}
if (numerical_integ_) {
mv_blfi->SetIntRule(&ir_nli);
}
Mv_form_->AddDomainIntegrator(mv_blfi);
if (partial_assembly_) {
Mv_form_->SetAssemblyLevel(AssemblyLevel::PARTIAL);
}
Mv_form_->Assemble();
Mv_form_->FormSystemMatrix(temp_ess_tdof_, Mv_);

// mass matrix with rho
MsRho_form_ = new ParBilinearForm(sfes_);
auto *msrho_blfi = new MassIntegrator(*rho_coeff_);
Expand All @@ -522,6 +566,7 @@ void CaloricallyPerfectThermoChem::initializeOperators() {
MsRho_form_->FormSystemMatrix(empty, MsRho_);
if (rank0_) std::cout << "CaloricallyPerfectThermoChem MsRho operator set" << endl;

// Helmholtz
Ht_form_ = new ParBilinearForm(sfes_);
auto *hmt_blfi = new MassIntegrator(*rho_over_dt_coeff_);
auto *hdt_blfi = new DiffusionIntegrator(*thermal_diff_total_coeff_);
Expand Down Expand Up @@ -556,6 +601,27 @@ void CaloricallyPerfectThermoChem::initializeOperators() {
MsInv_->SetAbsTol(mass_inverse_atol_);
MsInv_->SetMaxIter(mass_inverse_max_iter_);

// Inverse (unweighted) mass operator (velocity space)
if (partial_assembly_) {
Vector diag_pa(vfes_->GetTrueVSize());
Mv_form_->AssembleDiagonal(diag_pa);
Mv_inv_pc_ = new OperatorJacobiSmoother(diag_pa, empty);
} else {
Mv_inv_pc_ = new HypreSmoother(*Mv_.As<HypreParMatrix>());
dynamic_cast<HypreSmoother *>(Mv_inv_pc_)->SetType(HypreSmoother::Jacobi, smoother_passes_);
dynamic_cast<HypreSmoother *>(Mv_inv_pc_)->SetSOROptions(smoother_relax_weight_, smoother_relax_omega_);
dynamic_cast<HypreSmoother *>(Mv_inv_pc_)
->SetPolyOptions(smoother_poly_order_, smoother_poly_fraction_, smoother_eig_est_);
}
Mv_inv_ = new CGSolver(vfes_->GetComm());
Mv_inv_->iterative_mode = false;
Mv_inv_->SetOperator(*Mv_);
Mv_inv_->SetPreconditioner(*Mv_inv_pc_);
Mv_inv_->SetPrintLevel(mass_inverse_pl_);
Mv_inv_->SetAbsTol(mass_inverse_atol_);
Mv_inv_->SetRelTol(mass_inverse_rtol_);
Mv_inv_->SetMaxIter(mass_inverse_max_iter_);

HtInvPC_ = new HypreSmoother(*Ht_.As<HypreParMatrix>());
dynamic_cast<HypreSmoother *>(HtInvPC_)->SetType(HypreSmoother::Jacobi, smoother_passes_);
dynamic_cast<HypreSmoother *>(HtInvPC_)->SetSOROptions(hsmoother_relax_weight_, hsmoother_relax_omega_);
Expand Down Expand Up @@ -707,7 +773,12 @@ void CaloricallyPerfectThermoChem::step() {

// Add streamwise stability to rhs
if (sw_stab_) {
streamwiseDiffusion(Tn_, swDiff_);
// compute temp gradient (only really needed for sw-stab)
G_op_->Mult(Text_, tmpR1_);
Mv_inv_->Mult(tmpR1_, gradT_);

// streamwiseDiffusion(Tn_, swDiff_);
streamwiseDiffusion(gradT_, swDiff_);
resT_.Add(1.0, swDiff_);
}

Expand Down Expand Up @@ -1068,25 +1139,35 @@ void CaloricallyPerfectThermoChem::screenValues(std::vector<double> &values) {
}
}

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

// compute streamwise gradient of input field
// tmpR0_gf_.SetFromTrueDofs(phi);
// streamwiseGrad(dim_, tmpR0_gf_, vel_gf_, tmpR1_gf_);

tmpR1_gf_.SetFromTrueDofs(gradPhi);
streamwiseGrad(dim_, 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_);
//(turbModel_interface_->eddy_viscosity)->GetTrueDofs(tmpR0c_);
(flow_interface_->Reh)->GetTrueDofs(tmpR0c_);

upwindDiff(dim_, re_factor_, re_offset_, tmpR0a_, rn_, tmpR0b_, tmpR0c_, swDiff);

/*
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();
//const double *mu = visc_.HostRead();
//const double *muT = tmpR0c_.HostRead();
const double *Reh = tmpR0c_.HostRead();
double *data = swDiff.HostReadWrite();
int Sdof = rn_.Size();
Expand All @@ -1096,7 +1177,8 @@ void CaloricallyPerfectThermoChem::streamwiseDiffusion(Vector &phi, Vector &swDi
Umag = std::sqrt(Umag);
// element Re
double Re = Umag * del[dof] * rho[dof] / (mu[dof] + muT[dof]);
//double Re = Umag * del[dof] * rho[dof] / (mu[dof] + muT[dof]);
double Re = Reh[dof];
// SUPG weight
double Csupg = 0.5 * (tanh(re_factor_ * Re - re_offset_) + 1.0);
Expand All @@ -1107,4 +1189,5 @@ void CaloricallyPerfectThermoChem::streamwiseDiffusion(Vector &phi, Vector &swDi
// scaled streamwise Laplacian
data[dof] *= CswDiff;
}
*/
}
10 changes: 9 additions & 1 deletion src/calorically_perfect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ class CaloricallyPerfectThermoChem : public ThermoChemModelBase {
// operators and solvers
ParBilinearForm *At_form_ = nullptr;
ParBilinearForm *Ms_form_ = nullptr;
ParBilinearForm *Mv_form_ = nullptr;
ParBilinearForm *MsRho_form_ = nullptr;
ParBilinearForm *Ht_form_ = nullptr;
ParBilinearForm *Mq_form_ = nullptr;
ParBilinearForm *LQ_form_ = nullptr;
ParMixedBilinearForm *D_form_ = nullptr;
ParMixedBilinearForm *G_form_ = nullptr;
ParLinearForm *LQ_bdry_ = nullptr;

OperatorHandle LQ_;
Expand All @@ -202,14 +204,18 @@ class CaloricallyPerfectThermoChem : public ThermoChemModelBase {
OperatorHandle Ms_;
OperatorHandle MsRho_;
OperatorHandle Mq_;
OperatorHandle Mv_;
OperatorHandle D_op_;
OperatorHandle G_op_;

mfem::Solver *MsInvPC_ = nullptr;
mfem::CGSolver *MsInv_ = nullptr;
mfem::Solver *MqInvPC_ = nullptr;
mfem::CGSolver *MqInv_ = nullptr;
mfem::Solver *HtInvPC_ = nullptr;
mfem::CGSolver *HtInv_ = nullptr;
mfem::Solver *Mv_inv_pc_ = nullptr;
mfem::CGSolver *Mv_inv_ = nullptr;

// Vectors
Vector Tn_, Tn_next_, Tnm1_, Tnm2_;
Expand All @@ -219,6 +225,7 @@ class CaloricallyPerfectThermoChem : public ThermoChemModelBase {
Vector tmpR0_, tmpR0a_, tmpR0b_, tmpR0c_;
Vector tmpR1_;
Vector swDiff_;
Vector gradT_;

Vector Qt_;
Vector rn_;
Expand Down Expand Up @@ -276,7 +283,8 @@ class CaloricallyPerfectThermoChem : public ThermoChemModelBase {
void computeExplicitTempConvectionOP(bool extrap);
void computeQt();
void computeQtTO();
void streamwiseDiffusion(Vector &phi, Vector &swDiff);
// void streamwiseDiffusion(Vector &phi, Vector &swDiff);
void streamwiseDiffusion(Vector &gradPhi, Vector &swDiff);

/// Return a pointer to the current temperature ParGridFunction.
ParGridFunction *GetCurrentTemperature() { return &Tn_gf_; }
Expand Down
2 changes: 1 addition & 1 deletion src/cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ double temp_channel(const Vector &coords, double t) {
double Tlo = 200.0;
double y = coords(1);
double temp;
temp = Tlo + (y + 0.5) * (Thi - Tlo);
temp = Tlo + 0.5 * (y + 0.1) * (Thi - Tlo);
return temp;
}

Expand Down
Loading

0 comments on commit 6abe504

Please sign in to comment.