From ad6f17652bd60469425eee97d8ce944bf61e602c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 14 Feb 2022 20:00:27 +0100 Subject: [PATCH] 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. --- .../thermoCoupleProbes/thermoCoupleProbes.C | 18 ++--- .../thermoCoupleProbes/thermoCoupleProbes.H | 73 ++++++++++--------- .../thermoCoupleProbesTemplates.C | 25 ++++--- 3 files changed, 59 insertions(+), 57 deletions(-) diff --git a/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbes.C b/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbes.C index 6169402a64..860f759d7d 100644 --- a/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbes.C +++ b/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbes.C @@ -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(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(); diff --git a/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbes.H b/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbes.H index 0438f2499c..cf85be35b3 100644 --- a/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbes.H +++ b/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbes.H @@ -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 - void sampleAndWrite - ( - const GeometricField& - ); - - private: + // Private Member Functions + + //- Sample/write + template + void writeValues + ( + const word& fieldName, + const Field& 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(); }; diff --git a/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbesTemplates.C b/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbesTemplates.C index dee96c90df..1abfada4b0 100644 --- a/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbesTemplates.C +++ b/src/functionObjects/utilities/thermoCoupleProbes/thermoCoupleProbesTemplates.C @@ -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 -void Foam::functionObjects::thermoCoupleProbes::sampleAndWrite +void Foam::functionObjects::thermoCoupleProbes::writeValues ( - const GeometricField& vField + const word& fieldName, + const Field& 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; } }