Skip to content

Commit

Permalink
check whether mechanism exist before Cantera read it, to make error m…
Browse files Browse the repository at this point in the history
…ore readable when mechanism file not exist
  • Loading branch information
of committed May 18, 2023
1 parent eadf316 commit 98d6876
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
32 changes: 21 additions & 11 deletions src/dfCanteraMixture/CanteraMixture.C
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,30 @@ Foam::CanteraMixture::CanteraMixture
IOobject::NO_WRITE
)
),
CanteraMechanismFile_(CanteraTorchProperties_.lookup("CanteraMechanismFile")),
CanteraSolution_(Cantera::newSolution(CanteraMechanismFile_, "")),
CanteraGas_(CanteraSolution_->thermo()),
CanteraMechanismFile_(fileName(CanteraTorchProperties_.lookup("CanteraMechanismFile")).expand()),
transportModelName_(CanteraTorchProperties_.lookup("transportModel")),
CanteraTransport_(newTransportMgr(transportModelName_, CanteraGas_.get())),
Y_(nSpecies()),
Tref_(mesh.objectRegistry::lookupObject<volScalarField>("T")),
pref_(mesh.objectRegistry::lookupObject<volScalarField>("p")),
yTemp_(nSpecies()),
HaTemp_(nSpecies()),
CpTemp_(nSpecies()),
CvTemp_(nSpecies()),
muTemp_(nSpecies())
pref_(mesh.objectRegistry::lookupObject<volScalarField>("p"))
{
if(!isFile(CanteraMechanismFile_))
{
FatalErrorInFunction
<<"Chemical mechanism "
<<CanteraMechanismFile_
<<" doesn't exist!\n"
<<exit(FatalError);
}

CanteraSolution_=Cantera::newSolution(CanteraMechanismFile_, "");
CanteraGas_=CanteraSolution_->thermo();
CanteraTransport_=newTransportMgr(transportModelName_, CanteraGas_.get());

Y_.resize(nSpecies());
yTemp_.resize(nSpecies());
HaTemp_.resize(nSpecies());
CpTemp_.resize(nSpecies());
CvTemp_.resize(nSpecies());
muTemp_.resize(nSpecies());
forAll(Y_, i)
{
species_.append(CanteraGas_->speciesName(i));
Expand Down
6 changes: 3 additions & 3 deletions src/dfCanteraMixture/CanteraMixture.H
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class CanteraMixture
// Private Data

IOdictionary CanteraTorchProperties_;
const word CanteraMechanismFile_;
const string CanteraMechanismFile_;
std::shared_ptr<Cantera::Solution> CanteraSolution_;
std::shared_ptr<Cantera::ThermoPhase> CanteraGas_;
word transportModelName_;
std::shared_ptr<Cantera::Transport> CanteraTransport_;
Cantera::Transport* CanteraTransport_;
hashedWordList species_;
PtrList<volScalarField> Y_;
const volScalarField& Tref_;
Expand Down Expand Up @@ -227,7 +227,7 @@ public:

std::shared_ptr<Cantera::Solution> CanteraSolution() {return CanteraSolution_;}

std::shared_ptr<Cantera::Transport> CanteraTransport() {return CanteraTransport_;}
Cantera::Transport* CanteraTransport() {return CanteraTransport_;}

const word& transportModelName() {return transportModelName_;}

Expand Down

0 comments on commit 98d6876

Please sign in to comment.