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

View File

@ -79,8 +79,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_thermoCoupleProbes_H
#define functionObjects_thermoCoupleProbes_H
#ifndef Foam_functionObjects_thermoCoupleProbes_H
#define Foam_functionObjects_thermoCoupleProbes_H
#include "probes.H"
#include "ODESystem.H"
@ -106,7 +106,7 @@ class thermoCoupleProbes
{
protected:
// Protected data
// Protected Data
//- Thermocouple density
scalar rho_;
@ -126,7 +126,7 @@ protected:
//- Name of the incident radiation field
word radiationFieldName_;
//- Fluid thermo reference
//- Fluid thermo reference
const fluidThermo& thermo_;
//- ODESolver
@ -136,18 +136,19 @@ protected:
scalarField Ttc_;
// Protected Member Functions
//- Sample and write a particular volume field
template<class Type>
void sampleAndWrite
(
const GeometricField<Type, fvPatchField, volMesh>&
);
private:
// Private Member Functions
//- Sample/write
template<class Type>
void writeValues
(
const word& fieldName,
const Field<Type>& values,
const scalar timeValue
);
//- No copy construct
thermoCoupleProbes(const thermoCoupleProbes&) = delete;
@ -176,40 +177,40 @@ public:
//- Destructor
virtual ~thermoCoupleProbes();
virtual ~thermoCoupleProbes() = default;
// ODE functions (overriding abstract functions in ODE.H)
//- Number of ODE's to solve
virtual label nEqns() const;
//- Number of ODE's to solve
virtual label nEqns() const;
virtual void derivatives
(
const scalar x,
const scalarField& y,
scalarField& dydx
) const;
virtual void derivatives
(
const scalar x,
const scalarField& y,
scalarField& dydx
) const;
virtual void jacobian
(
const scalar t,
const scalarField& y,
scalarField& dfdt,
scalarSquareMatrix& dfdy
) const;
virtual void jacobian
(
const scalar t,
const scalarField& y,
scalarField& dfdt,
scalarSquareMatrix& dfdy
) const;
// Public Member Functions
//- Sample and write
virtual bool write();
//- Execute, currently does nothing
virtual bool execute();
//- Read
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
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,25 +28,28 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
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())
{
unsigned int w = IOstream::defaultPrecision() + 7;
OFstream& probeStream = *probeFilePtrs_[vField.name()];
const unsigned int w = IOstream::defaultPrecision() + 7;
OFstream& os = *probeFilePtrs_[fieldName];
probeStream
<< setw(w)
<< vField.time().timeOutputValue();
os << setw(w) << timeValue;
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;
}
}