BUG: uninitialized file pointer in thermoCoupleProbes (fixes #2365)

- as a side-effect of changes to probes, the file pointers are not
  automatically creating when reading the dictionary but delayed
  until prepare(WRITE_ACTION) is called.
  This nuance was missed in thermoCoupleProbes.
This commit is contained in:
Mark Olesen
2022-02-14 20:00:27 +01:00
parent eb2b9b2823
commit ad6f17652b
3 changed files with 59 additions and 57 deletions

View File

@ -68,8 +68,7 @@ Foam::functionObjects::thermoCoupleProbes::thermoCoupleProbes
read(dict); read(dict);
} }
// Check if the property exist (resume old calculation) // Check if the property exists (resume old calculation) or is new
// or of it is new.
dictionary probeDict; dictionary probeDict;
if (getDict(typeName, probeDict)) if (getDict(typeName, probeDict))
{ {
@ -77,7 +76,7 @@ Foam::functionObjects::thermoCoupleProbes::thermoCoupleProbes
} }
else else
{ {
Ttc_ = probes::sample(thermo_.T()); Ttc_ = probes::sample(thermo_.T());
} }
// Note: can only create the solver once all samples have been found // Note: can only create the solver once all samples have been found
@ -88,10 +87,6 @@ Foam::functionObjects::thermoCoupleProbes::thermoCoupleProbes
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::thermoCoupleProbes::~thermoCoupleProbes()
{}
Foam::label Foam::functionObjects::thermoCoupleProbes::nEqns() const Foam::label Foam::functionObjects::thermoCoupleProbes::nEqns() const
{ {
return this->size(); return this->size();
@ -168,9 +163,12 @@ void Foam::functionObjects::thermoCoupleProbes::jacobian
bool Foam::functionObjects::thermoCoupleProbes::write() bool Foam::functionObjects::thermoCoupleProbes::write()
{ {
if (this->size()) if (!pointField::empty())
{ {
sampleAndWrite<scalar>(thermo_.T()); (void) prepare(ACTION_WRITE);
const auto& Tfield = thermo_.T();
writeValues(Tfield.name(), Ttc_, Tfield.time().timeOutputValue());
dictionary probeDict; dictionary probeDict;
probeDict.add("Tc", Ttc_); probeDict.add("Tc", Ttc_);
@ -184,7 +182,7 @@ bool Foam::functionObjects::thermoCoupleProbes::write()
bool Foam::functionObjects::thermoCoupleProbes::execute() bool Foam::functionObjects::thermoCoupleProbes::execute()
{ {
if (this->size()) if (!pointField::empty())
{ {
scalar dt = mesh_.time().deltaTValue(); scalar dt = mesh_.time().deltaTValue();
scalar t = mesh_.time().value(); scalar t = mesh_.time().value();

View File

@ -79,8 +79,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef functionObjects_thermoCoupleProbes_H #ifndef Foam_functionObjects_thermoCoupleProbes_H
#define functionObjects_thermoCoupleProbes_H #define Foam_functionObjects_thermoCoupleProbes_H
#include "probes.H" #include "probes.H"
#include "ODESystem.H" #include "ODESystem.H"
@ -106,7 +106,7 @@ class thermoCoupleProbes
{ {
protected: protected:
// Protected data // Protected Data
//- Thermocouple density //- Thermocouple density
scalar rho_; scalar rho_;
@ -126,7 +126,7 @@ protected:
//- Name of the incident radiation field //- Name of the incident radiation field
word radiationFieldName_; word radiationFieldName_;
//- Fluid thermo reference //- Fluid thermo reference
const fluidThermo& thermo_; const fluidThermo& thermo_;
//- ODESolver //- ODESolver
@ -136,18 +136,19 @@ protected:
scalarField Ttc_; scalarField Ttc_;
// Protected Member Functions
//- Sample and write a particular volume field
template<class Type>
void sampleAndWrite
(
const GeometricField<Type, fvPatchField, volMesh>&
);
private: private:
// Private Member Functions
//- Sample/write
template<class Type>
void writeValues
(
const word& fieldName,
const Field<Type>& values,
const scalar timeValue
);
//- No copy construct //- No copy construct
thermoCoupleProbes(const thermoCoupleProbes&) = delete; thermoCoupleProbes(const thermoCoupleProbes&) = delete;
@ -176,40 +177,40 @@ public:
//- Destructor //- Destructor
virtual ~thermoCoupleProbes(); virtual ~thermoCoupleProbes() = default;
// ODE functions (overriding abstract functions in ODE.H) // ODE functions (overriding abstract functions in ODE.H)
//- Number of ODE's to solve //- Number of ODE's to solve
virtual label nEqns() const; virtual label nEqns() const;
virtual void derivatives virtual void derivatives
( (
const scalar x, const scalar x,
const scalarField& y, const scalarField& y,
scalarField& dydx scalarField& dydx
) const; ) const;
virtual void jacobian virtual void jacobian
( (
const scalar t, const scalar t,
const scalarField& y, const scalarField& y,
scalarField& dfdt, scalarField& dfdt,
scalarSquareMatrix& dfdy scalarSquareMatrix& dfdy
) const; ) const;
// Public Member Functions // Public Member Functions
//- Sample and write
virtual bool write();
//- Execute, currently does nothing
virtual bool execute();
//- Read //- Read
virtual bool read(const dictionary&); virtual bool read(const dictionary&);
//- Execute. Evaluates the ODESolver
virtual bool execute();
//- Sample and write
virtual bool write();
}; };

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016 OpenCFD Ltd. Copyright (C) 2016-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,25 +28,28 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type> template<class Type>
void Foam::functionObjects::thermoCoupleProbes::sampleAndWrite void Foam::functionObjects::thermoCoupleProbes::writeValues
( (
const GeometricField<Type, fvPatchField, volMesh>& vField const word& fieldName,
const Field<Type>& values,
const scalar timeValue
) )
{ {
if (Pstream::master()) if (Pstream::master())
{ {
unsigned int w = IOstream::defaultPrecision() + 7; const unsigned int w = IOstream::defaultPrecision() + 7;
OFstream& probeStream = *probeFilePtrs_[vField.name()]; OFstream& os = *probeFilePtrs_[fieldName];
probeStream os << setw(w) << timeValue;
<< setw(w)
<< vField.time().timeOutputValue();
forAll(*this, probeI) forAll(*this, probei)
{ {
probeStream << ' ' << setw(w) << Ttc_[probeI]; // if (includeOutOfBounds_ || processor_[probei] != -1)
{
os << ' ' << setw(w) << values[probei];
}
} }
probeStream << endl; os << endl;
} }
} }