33 template<
class ThermoType>
40 log_(this->lookupOrDefault(
"log",
false)),
41 loadBalancing_(this->lookupOrDefault(
"loadBalancing",
false)),
44 this->
found(
"jacobian")
45 ? jacobianTypeNames_.read(this->lookup(
"jacobian"))
49 specieThermos_(mixture_.specieThermos()),
50 reactions_(mixture_.species(), specieThermos_, this->
mesh(), *
this),
64 mechRed_(*mechRedPtr_),
66 tabulation_(*tabulationPtr_)
78 "RR." + Yvf_[fieldi].
name(),
90 Info<<
"chemistryModel: Number of species = " << nSpecie_
91 <<
" and reactions = " << nReaction() <<
endl;
120 cpuSolveFile_ = logFile(
"cpu_solve.out");
127 template<
class ThermoType>
134 template<
class ThermoType>
147 Y_[sToc_[i]] =
max(YTp[i], 0);
154 Y_[i] =
max(YTp[i], 0);
158 const scalar
T = YTp[nSpecie_];
159 const scalar
p = YTp[nSpecie_ + 1];
163 for (
label i=0; i<Y_.size(); i++)
165 rhoM += Y_[i]/specieThermos_[i].rho(p, T);
170 for (
label i=0; i<Y_.size(); i ++)
172 c_[i] = rhoM/specieThermos_[i].W()*Y_[i];
179 if (!mechRed_.reactionDisabled(ri))
181 reactions_[ri].dNdtByV
196 for (
label i=0; i<nSpecie_; i++)
198 const scalar WiByrhoM = specieThermos_[sToc(i)].W()/rhoM;
199 scalar& dYidt = dYTpdt[i];
207 for (
label i=0; i<Y_.size(); i++)
209 CpM += Y_[i]*specieThermos_[i].Cp(p, T);
213 scalar& dTdt = dYTpdt[nSpecie_];
214 for (
label i=0; i<nSpecie_; i++)
216 dTdt -= dYTpdt[i]*specieThermos_[sToc(i)].Ha(p, T);
221 scalar&
dpdt = dYTpdt[nSpecie_ + 1];
226 template<
class ThermoType>
240 Y_[sToc_[i]] =
max(YTp[i], 0);
247 Y_[i] =
max(YTp[i], 0);
251 const scalar
T = YTp[nSpecie_];
252 const scalar
p = YTp[nSpecie_ + 1];
256 for (
label i=0; i<Y_.size(); i++)
258 v[i] = 1/specieThermos_[i].rho(p, T);
261 for (
label i=0; i<Y_.size(); i++)
268 for (
label i=0; i<Y_.size(); i ++)
270 c_[i] = rhoM/specieThermos_[i].W()*Y_[i];
275 for (
label i=0; i<nSpecie_; i++)
277 const scalar rhoMByWi = rhoM/specieThermos_[sToc(i)].W();
278 switch (jacobianType_)
280 case jacobianType::fast:
282 dcdY(i, i) = rhoMByWi;
285 case jacobianType::exact:
286 for (
label j=0; j<nSpecie_; j++)
289 rhoMByWi*((i == j) - rhoM*v[sToc(j)]*Y_[sToc(i)]);
297 for (
label i=0; i<Y_.size(); i++)
299 alphavM += Y_[i]*rhoM*v[i]*specieThermos_[i].alphav(p, T);
305 for (
label i=0; i<nSpecie_ + 2; i++)
307 for (
label j=0; j<nSpecie_ + 2; j++)
309 ddNdtByVdcTp[i][j] = 0;
314 if (!mechRed_.reactionDisabled(ri))
316 reactions_[ri].ddNdtByVdcTp
335 for (
label i=0; i<nSpecie_; i++)
337 const scalar WiByrhoM = specieThermos_[sToc(i)].W()/rhoM;
338 scalar& dYidt = dYTpdt[i];
341 for (
label j=0; j<nSpecie_; j++)
343 scalar ddNidtByVdYj = 0;
344 switch (jacobianType_)
346 case jacobianType::fast:
348 const scalar ddNidtByVdcj = ddNdtByVdcTp(i, j);
349 ddNidtByVdYj = ddNidtByVdcj*dcdY(j, j);
352 case jacobianType::exact:
355 const scalar ddNidtByVdck = ddNdtByVdcTp(i,
k);
356 ddNidtByVdYj += ddNidtByVdck*dcdY(
k, j);
361 scalar& ddYidtdYj = J(i, j);
362 ddYidtdYj = WiByrhoM*ddNidtByVdYj + rhoM*v[sToc(j)]*dYidt;
365 scalar ddNidtByVdT = ddNdtByVdcTp(i, nSpecie_);
366 for (
label j=0; j<nSpecie_; j++)
368 const scalar ddNidtByVdcj = ddNdtByVdcTp(i, j);
369 ddNidtByVdT -= ddNidtByVdcj*c_[sToc(j)]*alphavM;
372 scalar& ddYidtdT = J(i, nSpecie_);
373 ddYidtdT = WiByrhoM*ddNidtByVdT + alphavM*dYidt;
375 scalar& ddYidtdp = J(i, nSpecie_ + 1);
383 scalar CpM = 0, dCpMdT = 0;
384 for (
label i=0; i<Y_.size(); i++)
386 Cp[i] = specieThermos_[i].Cp(p, T);
388 dCpMdT += Y_[i]*specieThermos_[i].dCpdT(p, T);
393 scalar& dTdt = dYTpdt[nSpecie_];
394 for (
label i=0; i<nSpecie_; i++)
396 Ha[sToc(i)] = specieThermos_[sToc(i)].Ha(p, T);
397 dTdt -= dYTpdt[i]*Ha[sToc(i)];
402 scalar&
dpdt = dYTpdt[nSpecie_ + 1];
406 for (
label i=0; i<nSpecie_; i++)
408 scalar& ddTdtdYi = J(nSpecie_, i);
410 for (
label j=0; j<nSpecie_; j++)
412 const scalar ddYjdtdYi = J(j, i);
413 ddTdtdYi -= ddYjdtdYi*Ha[sToc(j)];
415 ddTdtdYi -= Cp[sToc(i)]*dTdt;
420 scalar& ddTdtdT = J(nSpecie_, nSpecie_);
422 for (
label i=0; i<nSpecie_; i++)
424 const scalar dYidt = dYTpdt[i];
425 const scalar ddYidtdT = J(i, nSpecie_);
426 ddTdtdT -= dYidt*Cp[sToc(i)] + ddYidtdT*Ha[sToc(i)];
428 ddTdtdT -= dTdt*dCpMdT;
432 scalar& ddTdtdp = J(nSpecie_, nSpecie_ + 1);
436 for (
label i=0; i<nSpecie_ + 2; i++)
438 scalar& ddpdtdYiTp = J(nSpecie_ + 1, i);
444 template<
class ThermoType>
455 extrapolatedCalculatedFvPatchScalarField::typeName
466 if (this->chemistry_)
468 reactionEvaluationScope scope(*
this);
472 const scalar rhoi = rho[celli];
473 const scalar Ti = T[celli];
474 const scalar
pi = p[celli];
476 for (
label i=0; i<nSpecie_; i++)
478 c_[i] = rhoi*Yvf_[i][celli]/specieThermos_[i].W();
498 scalar sumW = 0, sumWRateByCTot = 0;
502 scalar omegaf, omegar;
503 R.
omega(pi, Ti, c_, celli, omegaf, omegar);
508 wf += R.
rhs()[
s].stoichCoeff*omegaf;
511 sumWRateByCTot +=
sqr(wf);
516 wr += R.
lhs()[
s].stoichCoeff*omegar;
519 sumWRateByCTot +=
sqr(wr);
523 sumWRateByCTot == 0 ? vGreat : sumW/sumWRateByCTot*
sum(c_);
527 ttc.
ref().correctBoundaryConditions();
533 template<
class ThermoType>
547 if (this->chemistry_)
549 reactionEvaluationScope scope(*
this);
557 const scalar hi = specieThermos_[i].Hf();
558 Qdot[celli] -= hi*RR_[i][celli];
567 template<
class ThermoType>
593 reactionEvaluationScope scope(*
this);
595 scalar omegaf, omegar;
599 const scalar rhoi = rho[celli];
600 const scalar Ti = T[celli];
601 const scalar
pi = p[celli];
603 for (
label i=0; i<nSpecie_; i++)
605 const scalar Yi = Yvf_[i][celli];
606 c_[i] = rhoi*Yi/specieThermos_[i].W();
610 const scalar omegaI = R.
omega(pi, Ti, c_, celli, omegaf, omegar);
614 if (si == R.
lhs()[
s].index)
616 RR[celli] -= R.
lhs()[
s].stoichCoeff*omegaI;
622 if (si == R.
rhs()[
s].index)
624 RR[celli] += R.
rhs()[
s].stoichCoeff*omegaI;
628 RR[celli] *= specieThermos_[si].W();
635 template<
class ThermoType>
638 if (!this->chemistry_)
651 reactionEvaluationScope scope(*
this);
655 const scalar rhoi = rho[celli];
656 const scalar Ti = T[celli];
657 const scalar
pi = p[celli];
659 for (
label i=0; i<nSpecie_; i++)
661 const scalar Yi = Yvf_[i][celli];
662 c_[i] = rhoi*Yi/specieThermos_[i].W();
669 if (!mechRed_.reactionDisabled(ri))
671 reactions_[ri].dNdtByV
685 for (
label i=0; i<mechRed_.nActiveSpecies(); i++)
687 RR_[sToc(i)][celli] = dNdtByV[i]*specieThermos_[sToc(i)].W();
693 template<
class ThermoType>
694 template<
class DeltaTType>
697 const DeltaTType& deltaT
711 scalar totalSolveCpuTime_ = 0;
715 scalar deltaTMin = great;
717 if (!this->chemistry_)
730 reactionEvaluationScope scope(*
this);
738 chemistryCpuTime.
reset();
742 const scalar
rho = rhovf[celli];
743 const scalar
rho0 = rho0vf[celli];
745 scalar
p = p0vf[celli];
746 scalar
T = T0vf[celli];
748 for (
label i=0; i<nSpecie_; i++)
750 Y_[i] = Y0[i] = Yvf_[i].oldTime()[celli];
753 for (
label i=0; i<nSpecie_; i++)
755 phiq[i] = Yvf_[i].oldTime()[celli];
759 phiq[
nSpecie() + 2] = deltaT[celli];
762 scalar timeLeft = deltaT[celli];
770 if (tabulation_.retrieve(phiq, Rphiq))
789 for (
label i=0; i<nSpecie_; i++)
791 c_[i] = rho0*Y_[i]/specieThermos_[i].W();
795 mechRed_.reduceMechanism(p, T, c_, cTos_, sToc_, celli);
799 for (
label i=0; i<nSpecie_; i++)
801 sY_[i] = Y_[sToc(i)];
812 while (timeLeft > small)
814 scalar dt = timeLeft;
828 for (
label i=0; i<mechRed_.nActiveSpecies(); i++)
830 Y_[sToc_[i]] = sY_[i];
835 solve(p, T, Y_, celli, dt, deltaTChem_[celli]);
847 if (tabulation_.tabulates())
853 Rphiq[Rphiq.
size()-3] =
T;
854 Rphiq[Rphiq.
size()-2] =
p;
855 Rphiq[Rphiq.
size()-1] = deltaT[celli];
861 mechRed_.nActiveSpecies(),
872 setNSpecie(mechRed_.nSpecie());
875 deltaTMin =
min(deltaTChem_[celli], deltaTMin);
876 deltaTChem_[celli] =
min(deltaTChem_[celli], deltaTChemMax_);
880 for (
label i=0; i<nSpecie_; i++)
882 RR_[i][celli] = (Y_[i]*rho - Y0[i]*
rho0)/deltaT[celli];
894 << this->time().userTimeValue()
895 <<
" " << totalSolveCpuTime_ <<
endl;
899 tabulation_.update();
901 if (reduction_ && Pstream::parRun())
905 Pstream::listCombineScatter(active);
920 template<
class ThermoType>
935 template<
class ThermoType>
941 return this->solve<scalarField>(deltaT);
virtual tmp< volScalarField::Internal > calculateRR(const label reactionI, const label speciei) const
Return reaction rate of the speciei in reactionI.
void setInactive(label speciei) const
Set speciei inactive.
#define forAll(list, i)
Loop across all elements in list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
virtual void derivatives(const scalar t, const scalarField &YTp, const label li, scalarField &dYTpdt) const
Calculate the derivatives in dydx.
virtual void cpuTimeIncrement(const label celli)
Dummy cpuTimeIncrement function.
fluidReactionThermo & thermo
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
scalar omega(const scalar p, const scalar T, const scalarField &c, const label li, scalar &omegaf, scalar &omegar) const
Net reaction rate.
virtual tmp< volScalarField > tc() const
Return the chemical time scale.
bool headerOk()
Read header (uses typeGlobalFile to find file) and check.
bool active(label speciei) const
Return true for active species.
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(rho0+psi *p, rhoMin);# 1 "/home/ubuntu/OpenFOAM-10/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H" 1{ alphav=max(min((rho - rholSat)/(rhovSat - rholSat), scalar(1)), scalar(0));alphal=1.0 - alphav;Info<< "max-min alphav: "<< max(alphav).value()<< " "<< min(alphav).value()<< endl;psiModel-> correct()
basicSpecieMixture & composition
T & ref() const
Return non-const reference or generate a fatal error.
Templated form of IOobject providing type information for file reading and header type checking...
dimensionedSymmTensor sqr(const dimensionedVector &dv)
To & refCast(From &r)
Reference type cast template function.
void size(const label)
Override size to be inconsistent with allocated storage.
virtual ~chemistryModel()
Destructor.
Ostream & endl(Ostream &os)
Add newline and flush stream.
tmp< volScalarField > trho
Base-class for multi-component fluid thermodynamic properties.
label k
Boltzmann constant.
const List< specieCoeffs > & lhs() const
Return the components of the left hand side.
Specialisation of basicMixture for a mixture consisting of a number for molecular species...
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
scalarList Y0(nSpecie, 0.0)
const dimensionSet dimTime
const dimensionedScalar RR
Universal gas constant: default SI units: [J/kmol/K].
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
virtual void jacobian(const scalar t, const scalarField &YTp, const label li, scalarField &dYTpdt, scalarSquareMatrix &J) const
Calculate the Jacobian of the system.
Foam::multiComponentMixture.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
chemistryModel(const fluidReactionThermo &thermo)
Construct from thermo.
volScalarField scalarField(fieldObject, mesh)
const Mesh & mesh() const
Return mesh.
const dimensionSet dimEnergy
const dimensionSet dimMass
word name(const complex &)
Return a string representation of a complex.
virtual void calculate()
Calculates the reaction rates.
void setSize(const label)
Reset size of List.
Extends base chemistry model by adding a thermo package, and ODE functions. Introduces chemistry equa...
const List< specieCoeffs > & rhs() const
Return the components of the right hand side.
#define R(A, B, C, D, E, F, K, M)
virtual const volScalarField & T() const =0
Temperature [K].
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
scalar Cp(const scalar p, const scalar T) const
const dimensionSet dimVolume
virtual void reset()
Dummy reset function.
scalar Ha(const scalar p, const scalar T) const
void setActive(label speciei) const
Set speciei active.
An abstract class for methods of chemical mechanism reduction.
virtual tmp< volScalarField > Qdot() const
Return the heat release rate [kg/m/s^3].
Starts timing CPU usage and return elapsed time from start.
A class for managing temporary objects.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Extends base chemistry model adding an ODESystem and the reduction maps needed for tabulation...
SquareMatrix< scalar > scalarSquareMatrix