From f61228ae382965a6734b438dd9bbf1084a0a9e0a Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 15 Oct 2021 17:59:45 +0200 Subject: [PATCH] STYLE: changes for implicit handling, region coupling - avoid deprecated autoPtr check - bundle bool values in fvPatchField for compacter allocation - change useImplicit to a set method taking an argument instead of allowing direct access. --- .../include/createCoupledRegions.H | 12 +++--- ...eratureRadCoupledMixedFvPatchScalarField.C | 5 ++- .../fvPatchFields/fvPatchField/fvPatchField.C | 40 ++++++++++--------- .../fvPatchFields/fvPatchField/fvPatchField.H | 32 ++++++++------- .../basic/heThermo/heThermo.C | 4 +- 5 files changed, 51 insertions(+), 42 deletions(-) diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/include/createCoupledRegions.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/include/createCoupledRegions.H index 2d62b08dd4..6175adc5e6 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/include/createCoupledRegions.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/include/createCoupledRegions.H @@ -9,7 +9,7 @@ forAll(fluidRegions, i) const rhoThermo& thermo = refCast(thermoFluid[i]); const auto& bpsi = thermo.T().boundaryField(); - forAll (bpsi, patchI) + forAll(bpsi, patchI) { if (bpsi[patchI].useImplicit()) { @@ -23,7 +23,7 @@ forAll(solidRegions, i) solidThermo& thermo = thermos[i]; const auto& bpsi = thermo.T().boundaryField(); - forAll (bpsi, patchI) + forAll(bpsi, patchI) { if (bpsi[patchI].useImplicit()) { @@ -37,7 +37,7 @@ forAll(fluidRegions, i) const rhoThermo& thermo = refCast(thermoFluid[i]); if (coupled) { - Info << "Create fvMatrixAssembly." << endl; + Info<< "Create fvMatrixAssembly." << endl; fvMatrixAssemblyPtr.reset ( new fvMatrix @@ -50,12 +50,12 @@ forAll(fluidRegions, i) } } -forAll(solidRegions, i) +if (coupled && !fvMatrixAssemblyPtr) { - if (coupled && fvMatrixAssemblyPtr.empty()) + forAll(solidRegions, i) { solidThermo& thermo = thermos[i]; - Info << "Create fvMatrixAssembly." << endl; + Info<< "Create fvMatrixAssembly." << endl; fvMatrixAssemblyPtr.reset ( new fvMatrix diff --git a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C index 837d97748f..9f6e988966 100644 --- a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C +++ b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C @@ -151,9 +151,10 @@ turbulentTemperatureRadCoupledMixedFvPatchScalarField valueFraction() = 1.0; } - if (dict.found("useImplicit")) + bool boolVal(false); + if (dict.readIfPresent("useImplicit", boolVal)) { - useImplicit() = dict.get("useImplicit"); + this->useImplicit(boolVal); } if (dict.found("source")) { diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C index ba1ab519c3..5cb5ff130f 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,8 +46,8 @@ Foam::fvPatchField::fvPatchField internalField_(iF), updated_(false), manipulatedMatrix_(false), - patchType_(word::null), - useImplicit_(false) + useImplicit_(false), + patchType_() {} @@ -64,8 +64,8 @@ Foam::fvPatchField::fvPatchField internalField_(iF), updated_(false), manipulatedMatrix_(false), - patchType_(word::null), - useImplicit_(false) + useImplicit_(false), + patchType_() {} @@ -82,8 +82,8 @@ Foam::fvPatchField::fvPatchField internalField_(iF), updated_(false), manipulatedMatrix_(false), - patchType_(patchType), - useImplicit_(false) + useImplicit_(false), + patchType_(patchType) {} @@ -100,8 +100,8 @@ Foam::fvPatchField::fvPatchField internalField_(iF), updated_(false), manipulatedMatrix_(false), - patchType_(word::null), - useImplicit_(false) + useImplicit_(false), + patchType_() {} @@ -119,8 +119,8 @@ Foam::fvPatchField::fvPatchField internalField_(iF), updated_(false), manipulatedMatrix_(false), - patchType_(dict.getOrDefault("patchType", word::null)), - useImplicit_(dict.getOrDefault("useImplicit", false)) + useImplicit_(dict.getOrDefault("useImplicit", false)), + patchType_(dict.getOrDefault("patchType", word::null)) { if (valueRequired) { @@ -155,8 +155,8 @@ Foam::fvPatchField::fvPatchField internalField_(iF), updated_(false), manipulatedMatrix_(false), - patchType_(ptf.patchType_), - useImplicit_(ptf.useImplicit_) + useImplicit_(ptf.useImplicit_), + patchType_(ptf.patchType_) { // For unmapped faces set to internal field value (zero-gradient) if (notNull(iF) && mapper.hasUnmapped()) @@ -178,8 +178,8 @@ Foam::fvPatchField::fvPatchField internalField_(ptf.internalField_), updated_(false), manipulatedMatrix_(false), - patchType_(ptf.patchType_), - useImplicit_(ptf.useImplicit_) + useImplicit_(ptf.useImplicit_), + patchType_(ptf.patchType_) {} @@ -195,8 +195,8 @@ Foam::fvPatchField::fvPatchField internalField_(iF), updated_(false), manipulatedMatrix_(false), - patchType_(ptf.patchType_), - useImplicit_(ptf.useImplicit_) + useImplicit_(ptf.useImplicit_), + patchType_(ptf.patchType_) {} @@ -384,7 +384,11 @@ template void Foam::fvPatchField::write(Ostream& os) const { os.writeEntry("type", type()); - os.writeEntryIfDifferent("useImplicit", false, useImplicit_); + + if (useImplicit_) + { + os.writeEntry("useImplicit", "true"); + } if (patchType_.size()) { diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H index 0532940ca5..5b0c9ca43e 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -82,7 +82,7 @@ class fvPatchField : public Field { - // Private data + // Private Data //- Reference to patch const fvPatch& patch_; @@ -91,21 +91,21 @@ class fvPatchField const DimensionedField& internalField_; //- Update index used so that updateCoeffs is called only once during - // the construction of the matrix + //- the construction of the matrix bool updated_; //- Update index used so that manipulateMatrix is called only once - // during the construction of the matrix + //- during the construction of the matrix bool manipulatedMatrix_; + //- Use implicit formulation + bool useImplicit_; + //- Optional patch type, used to allow specified boundary conditions // to be applied to constraint patches by providing the constraint // patch type as 'patchType' word patchType_; - //- Use implicit formulation - bool useImplicit_; - public: @@ -307,15 +307,18 @@ public: // Implicit Functions //- Use implicit formulation for coupled patches only - bool useImplicit() const + bool useImplicit() const noexcept { return useImplicit_; } - //- Non-const access to useImplicit - bool& useImplicit() + //- Set useImplicit on/off + // \return old value + bool useImplicit(bool on) noexcept { - return useImplicit_; + bool old(useImplicit_); + useImplicit_ = on; + return old; } @@ -393,7 +396,8 @@ public: return manipulatedMatrix_; } - // Mapping functions + + // Mapping Functions //- Map (and resize as needed) from self given a mapping object virtual void autoMap @@ -409,7 +413,7 @@ public: ); - // Evaluation functions + // Evaluation Functions //- Return patch-normal gradient virtual tmp> snGrad() const; @@ -558,7 +562,7 @@ public: void check(const fvPatchField&) const; - // Member operators + // Member Operators virtual void operator=(const UList&); diff --git a/src/thermophysicalModels/basic/heThermo/heThermo.C b/src/thermophysicalModels/basic/heThermo/heThermo.C index 2b25c54e60..1acb2b3e09 100644 --- a/src/thermophysicalModels/basic/heThermo/heThermo.C +++ b/src/thermophysicalModels/basic/heThermo/heThermo.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2017 OpenCFD Ltd. + Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -83,7 +83,7 @@ void Foam::heThermo::init patchi ); - heBf[patchi].useImplicit() = T.boundaryField()[patchi].useImplicit(); + heBf[patchi].useImplicit(T.boundaryField()[patchi].useImplicit()); } this->heBoundaryCorrection(he);