From ffc98940337246102800795186449c819e698d5d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 13 May 2024 12:31:57 +0200 Subject: [PATCH 1/2] STYLE: more consistency in writeEntry() signatures - boundary entries with writeEntry(const word&, ...) instead of writeEntry(const keyType&, ...) to match with most other writeEntry() signatures. Also, this content will not be used to supply regex matched sub-dictionaries. STYLE: more consistent patch initEvaluate()/evaluate() coding --- applications/test/dimField/Make/files | 3 - applications/test/dimField1/Make/files | 3 + .../test/{dimField => dimField1}/Make/options | 0 .../Test-dimField1.cxx} | 50 +++++++++-------- .../test/parallelOverset/Make/options | 1 + .../test/parallelOverset/laplacianDyMFoam.C | 2 + .../preProcessing/mapFieldsPar/MapVolFields.H | 47 +++++++--------- .../polyBoundaryMesh/polyBoundaryMesh.C | 2 +- .../polyBoundaryMesh/polyBoundaryMesh.H | 2 +- .../polyBoundaryMeshEntries.C | 2 +- .../polyBoundaryMeshEntries.H | 2 +- .../faMesh/faBoundaryMesh/faBoundaryMesh.C | 2 +- .../faMesh/faBoundaryMesh/faBoundaryMesh.H | 2 +- .../faBoundaryMesh/faBoundaryMeshEntries.C | 2 +- .../faBoundaryMesh/faBoundaryMeshEntries.H | 2 +- .../volPointInterpolate.C | 3 +- .../field/mapFields/mapFieldsTemplates.C | 43 ++++++-------- .../zeroGradient/zeroGradientTemplates.C | 6 +- .../cellSources/fieldToCell/fieldDictionary.H | 26 ++++----- .../cellCellStencilTemplates.C | 23 ++++---- src/overset/oversetFvMesh/oversetFvMeshBase.H | 2 +- .../oversetFvMeshBaseTemplates.C | 56 ++++++++++--------- 22 files changed, 136 insertions(+), 145 deletions(-) delete mode 100644 applications/test/dimField/Make/files create mode 100644 applications/test/dimField1/Make/files rename applications/test/{dimField => dimField1}/Make/options (100%) rename applications/test/{dimField/Test-dimField.C => dimField1/Test-dimField1.cxx} (80%) diff --git a/applications/test/dimField/Make/files b/applications/test/dimField/Make/files deleted file mode 100644 index 8289e2ec00..0000000000 --- a/applications/test/dimField/Make/files +++ /dev/null @@ -1,3 +0,0 @@ -Test-dimField.C - -EXE = $(FOAM_USER_APPBIN)/Test-dimField diff --git a/applications/test/dimField1/Make/files b/applications/test/dimField1/Make/files new file mode 100644 index 0000000000..226fc66a5d --- /dev/null +++ b/applications/test/dimField1/Make/files @@ -0,0 +1,3 @@ +Test-dimField1.cxx + +EXE = $(FOAM_USER_APPBIN)/Test-dimField1 diff --git a/applications/test/dimField/Make/options b/applications/test/dimField1/Make/options similarity index 100% rename from applications/test/dimField/Make/options rename to applications/test/dimField1/Make/options diff --git a/applications/test/dimField/Test-dimField.C b/applications/test/dimField1/Test-dimField1.cxx similarity index 80% rename from applications/test/dimField/Test-dimField.C rename to applications/test/dimField1/Test-dimField1.cxx index f711584883..9eaf98fe95 100644 --- a/applications/test/dimField/Test-dimField.C +++ b/applications/test/dimField1/Test-dimField1.cxx @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020-2022 OpenCFD Ltd. + Copyright (C) 2020-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,7 +24,7 @@ License along with OpenFOAM. If not, see . Application - Test-dimField + Test-dimField1 Description Simple tests for DimensionedField @@ -52,7 +52,12 @@ namespace Foam int main(int argc, char *argv[]) { + argList::addBoolOption("write", "write some test fields"); + #include "setRootCase.H" + + const bool doWrite = args.found("write"); + #include "createTime.H" #include "createMesh.H" @@ -60,19 +65,23 @@ int main(int argc, char *argv[]) Info<< "Tensor field\n" << endl; DimensionedField tensorfld ( - IOobject + mesh.newIOobject ( "tensor", - runTime.timeName(), - mesh, - { IOobject::READ_IF_PRESENT, IOobject::NO_REGISTER } + { IOobject::READ_IF_PRESENT, IOobject::NO_WRITE } ), mesh, dimensioned(dimless, tensor(1,2,3,4,5,6,7,8,9)) ); - Info().beginBlock("transformed") - << tensorfld.T() << nl; + if (doWrite) + { + tensorfld.write(); + } + + + Info<< nl; + Info().beginBlock("transformed") << tensorfld.T(); Info().endBlock(); { @@ -84,8 +93,8 @@ int main(int argc, char *argv[]) dimensioned(14) ); - Info().beginBlock(tfld().type()) - << tfld << nl; + Info<< nl; + Info().beginBlock(tfld().type()) << tfld; Info().endBlock(); } @@ -98,8 +107,8 @@ int main(int argc, char *argv[]) dimensioned(5) ); - Info().beginBlock(tfld().type()) - << tfld() << nl; + Info<< nl; + Info().beginBlock(tfld().type()) << tfld(); Info().endBlock(); // From dissimilar types @@ -111,8 +120,8 @@ int main(int argc, char *argv[]) dimensioned(Zero) ); - Info().beginBlock(tfld2().type()) - << tfld2() << nl; + Info<< nl; + Info().beginBlock(tfld2().type()) << tfld2(); Info().endBlock(); } } @@ -122,20 +131,13 @@ int main(int argc, char *argv[]) Info<< "uint8 field\n" << endl; DimensionedField statefld ( - IOobject - ( - "state", - runTime.timeName(), - mesh, - IOobject::NO_READ, - IOobject::NO_WRITE - ), + mesh.newIOobject("state") mesh, dimensioned(dimless, uint8_t{100}) ); - Info().beginBlock("stateField") - << statefld << nl; + Info<< nl; + Info().beginBlock("stateField") << statefld; Info().endBlock(); } #endif diff --git a/applications/test/parallelOverset/Make/options b/applications/test/parallelOverset/Make/options index b0aa2ef220..db6c073e47 100644 --- a/applications/test/parallelOverset/Make/options +++ b/applications/test/parallelOverset/Make/options @@ -7,5 +7,6 @@ EXE_INC = \ EXE_LIBS = \ -lfiniteVolume \ + -ldynamicFvMesh \ -lsampling \ -loverset diff --git a/applications/test/parallelOverset/laplacianDyMFoam.C b/applications/test/parallelOverset/laplacianDyMFoam.C index 997ef3f590..f94bbd2caf 100644 --- a/applications/test/parallelOverset/laplacianDyMFoam.C +++ b/applications/test/parallelOverset/laplacianDyMFoam.C @@ -56,6 +56,7 @@ Description #include "fvCFD.H" #include "simpleControl.H" +#include "predicates.H" #include "dynamicFvMesh.H" #include "dynamicOversetFvMesh.H" @@ -97,6 +98,7 @@ int main(int argc, char *argv[]) component(T.ref(), mesh.C(), 1); // Interpolate + halo swap T.correctBoundaryConditions(); + // T.boundaryFieldRef().evaluate_if(predicates::always{}); // Check halo swap dynamicOversetFvMesh::checkCoupledBC(T); } diff --git a/applications/utilities/preProcessing/mapFieldsPar/MapVolFields.H b/applications/utilities/preProcessing/mapFieldsPar/MapVolFields.H index f3106def5c..34b26b49ed 100644 --- a/applications/utilities/preProcessing/mapFieldsPar/MapVolFields.H +++ b/applications/utilities/preProcessing/mapFieldsPar/MapVolFields.H @@ -26,8 +26,8 @@ License \*---------------------------------------------------------------------------*/ -#ifndef MapConsistentVolFields_H -#define MapConsistentVolFields_H +#ifndef Foam_MapConsistentVolFields_H +#define Foam_MapConsistentVolFields_H #include "GeometricField.H" #include "meshToMesh.H" @@ -41,10 +41,9 @@ namespace Foam template void evaluateConstraintTypes(GeometricField& fld) { - auto& fldBf = fld.boundaryFieldRef(); + auto& bfld = fld.boundaryFieldRef(); const UPstream::commsTypes commsType = UPstream::defaultCommsType; - const label startOfRequests = UPstream::nRequests(); if ( @@ -52,37 +51,32 @@ void evaluateConstraintTypes(GeometricField& fld) || commsType == UPstream::commsTypes::nonBlocking ) { - forAll(fldBf, patchi) - { - fvPatchField& tgtField = fldBf[patchi]; + const label startOfRequests = UPstream::nRequests(); + for (auto& pfld : bfld) + { if ( - tgtField.type() == tgtField.patch().patch().type() - && polyPatch::constraintType(tgtField.patch().patch().type()) + pfld.type() == pfld.patch().patch().type() + && polyPatch::constraintType(pfld.patch().patch().type()) ) { - tgtField.initEvaluate(commsType); + pfld.initEvaluate(commsType); } } - // Wait for outstanding requests - if (commsType == UPstream::commsTypes::nonBlocking) - { - UPstream::waitRequests(startOfRequests); - } + // Wait for outstanding requests (non-blocking) + UPstream::waitRequests(startOfRequests); - forAll(fldBf, patchi) + for (auto& pfld : bfld) { - fvPatchField& tgtField = fldBf[patchi]; - if ( - tgtField.type() == tgtField.patch().patch().type() - && polyPatch::constraintType(tgtField.patch().patch().type()) + pfld.type() == pfld.patch().patch().type() + && polyPatch::constraintType(pfld.patch().patch().type()) ) { - tgtField.evaluate(commsType); + pfld.evaluate(commsType); } } } @@ -94,22 +88,21 @@ void evaluateConstraintTypes(GeometricField& fld) for (const auto& schedEval : patchSchedule) { const label patchi = schedEval.patch; - - fvPatchField& tgtField = fldBf[patchi]; + auto& pfld = bfld[patchi]; if ( - tgtField.type() == tgtField.patch().patch().type() - && polyPatch::constraintType(tgtField.patch().patch().type()) + pfld.type() == pfld.patch().patch().type() + && polyPatch::constraintType(pfld.patch().patch().type()) ) { if (schedEval.init) { - tgtField.initEvaluate(commsType); + pfld.initEvaluate(commsType); } else { - tgtField.evaluate(commsType); + pfld.evaluate(commsType); } } } diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index f7332a1900..5d096e36f6 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -1440,7 +1440,7 @@ void Foam::polyBoundaryMesh::writeEntry(Ostream& os) const void Foam::polyBoundaryMesh::writeEntry ( - const keyType& keyword, + const word& keyword, Ostream& os ) const { diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H index 93a059a06e..d21d9cf0b5 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H @@ -379,7 +379,7 @@ public: //- Write as a primitive entry with given name. //- If the keyword is empty, revert to a plain list. - void writeEntry(const keyType& keyword, Ostream& os) const; + void writeEntry(const word& keyword, Ostream& os) const; //- The writeData member function required by regIOobject virtual bool writeData(Ostream& os) const; diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.C index 7cf2f53abb..e8c4cfe61c 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.C @@ -214,7 +214,7 @@ void Foam::polyBoundaryMeshEntries::writeEntry(Ostream& os) const void Foam::polyBoundaryMeshEntries::writeEntry ( - const keyType& keyword, + const word& keyword, Ostream& os ) const { diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.H index 2fb5c6feae..e614c0929a 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.H @@ -121,7 +121,7 @@ public: //- Write as a primitive entry with given name. //- If the keyword is empty, revert to a plain list. - void writeEntry(const keyType& keyword, Ostream& os) const; + void writeEntry(const word& keyword, Ostream& os) const; //- The writeData member function required by regIOobject virtual bool writeData(Ostream& os) const; diff --git a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.C b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.C index 55ee4b2899..e770328a70 100644 --- a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.C +++ b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.C @@ -1058,7 +1058,7 @@ void Foam::faBoundaryMesh::writeEntry(Ostream& os) const void Foam::faBoundaryMesh::writeEntry ( - const keyType& keyword, + const word& keyword, Ostream& os ) const { diff --git a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.H b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.H index 9c3cc9d0e9..cad2924791 100644 --- a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.H +++ b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMesh.H @@ -299,7 +299,7 @@ public: //- Write as a primitive entry with given name. //- If the keyword is empty, revert to a plain list. - void writeEntry(const keyType& keyword, Ostream& os) const; + void writeEntry(const word& keyword, Ostream& os) const; //- The writeData member function required by regIOobject virtual bool writeData(Ostream& os) const; diff --git a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMeshEntries.C b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMeshEntries.C index 59ebacfe33..2a07f2fd99 100644 --- a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMeshEntries.C +++ b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMeshEntries.C @@ -183,7 +183,7 @@ void Foam::faBoundaryMeshEntries::writeEntry(Ostream& os) const void Foam::faBoundaryMeshEntries::writeEntry ( - const keyType& keyword, + const word& keyword, Ostream& os ) const { diff --git a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMeshEntries.H b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMeshEntries.H index c9f8571693..ccaebe01ac 100644 --- a/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMeshEntries.H +++ b/src/finiteArea/faMesh/faBoundaryMesh/faBoundaryMeshEntries.H @@ -108,7 +108,7 @@ public: //- Write as a primitive entry with given name. //- If the keyword is empty, revert to a plain list. - void writeEntry(const keyType& keyword, Ostream& os) const; + void writeEntry(const word& keyword, Ostream& os) const; //- The writeData member function required by regIOobject virtual bool writeData(Ostream& os) const; diff --git a/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolate.C b/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolate.C index 3ef984cf4d..f1b7fd0ff0 100644 --- a/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolate.C +++ b/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolate.C @@ -107,8 +107,7 @@ void Foam::volPointInterpolation::addSeparated } } - // Wait for outstanding requests - // (commsType == UPstream::commsTypes::nonBlocking) + // Wait for outstanding requests (non-blocking) UPstream::waitRequests(startOfRequests); forAll(pfbf, patchi) diff --git a/src/functionObjects/field/mapFields/mapFieldsTemplates.C b/src/functionObjects/field/mapFields/mapFieldsTemplates.C index 2350ef32c0..58bd9572dc 100644 --- a/src/functionObjects/field/mapFields/mapFieldsTemplates.C +++ b/src/functionObjects/field/mapFields/mapFieldsTemplates.C @@ -36,10 +36,9 @@ void Foam::functionObjects::mapFields::evaluateConstraintTypes GeometricField& fld ) const { - auto& fldBf = fld.boundaryFieldRef(); + auto& bfld = fld.boundaryFieldRef(); const UPstream::commsTypes commsType = UPstream::defaultCommsType; - const label startOfRequests = UPstream::nRequests(); if ( @@ -47,37 +46,32 @@ void Foam::functionObjects::mapFields::evaluateConstraintTypes || commsType == UPstream::commsTypes::nonBlocking ) { - forAll(fldBf, patchi) - { - fvPatchField& tgtField = fldBf[patchi]; + const label startOfRequests = UPstream::nRequests(); + for (auto& pfld : bfld) + { if ( - tgtField.type() == tgtField.patch().patch().type() - && polyPatch::constraintType(tgtField.patch().patch().type()) + pfld.type() == pfld.patch().patch().type() + && polyPatch::constraintType(pfld.patch().patch().type()) ) { - tgtField.initEvaluate(commsType); + pfld.initEvaluate(commsType); } } - // Wait for outstanding requests - if (commsType == UPstream::commsTypes::nonBlocking) - { - UPstream::waitRequests(startOfRequests); - } + // Wait for outstanding requests (non-blocking) + UPstream::waitRequests(startOfRequests); - forAll(fldBf, patchi) + for (auto& pfld : bfld) { - fvPatchField& tgtField = fldBf[patchi]; - if ( - tgtField.type() == tgtField.patch().patch().type() - && polyPatch::constraintType(tgtField.patch().patch().type()) + pfld.type() == pfld.patch().patch().type() + && polyPatch::constraintType(pfld.patch().patch().type()) ) { - tgtField.evaluate(commsType); + pfld.evaluate(commsType); } } } @@ -89,22 +83,21 @@ void Foam::functionObjects::mapFields::evaluateConstraintTypes for (const auto& schedEval : patchSchedule) { const label patchi = schedEval.patch; - - fvPatchField& tgtField = fldBf[patchi]; + auto& pfld = bfld[patchi]; if ( - tgtField.type() == tgtField.patch().patch().type() - && polyPatch::constraintType(tgtField.patch().patch().type()) + pfld.type() == pfld.patch().patch().type() + && polyPatch::constraintType(pfld.patch().patch().type()) ) { if (schedEval.init) { - tgtField.initEvaluate(commsType); + pfld.initEvaluate(commsType); } else { - tgtField.evaluate(commsType); + pfld.evaluate(commsType); } } } diff --git a/src/functionObjects/field/zeroGradient/zeroGradientTemplates.C b/src/functionObjects/field/zeroGradient/zeroGradientTemplates.C index 0894b199d5..0c6dcd4ecb 100644 --- a/src/functionObjects/field/zeroGradient/zeroGradientTemplates.C +++ b/src/functionObjects/field/zeroGradient/zeroGradientTemplates.C @@ -37,11 +37,9 @@ bool Foam::functionObjects::zeroGradient::accept const GeometricField& input ) { - const auto& patches = input.boundaryField(); - - forAll(patches, patchi) + for (const auto& pfld : input.boundaryField()) { - if (!polyPatch::constraintType(patches[patchi].patch().patch().type())) + if (!polyPatch::constraintType(pfld.patch().patch().type())) { return true; } diff --git a/src/meshTools/topoSet/cellSources/fieldToCell/fieldDictionary.H b/src/meshTools/topoSet/cellSources/fieldToCell/fieldDictionary.H index 999f5a8862..c04f5bfb38 100644 --- a/src/meshTools/topoSet/cellSources/fieldToCell/fieldDictionary.H +++ b/src/meshTools/topoSet/cellSources/fieldToCell/fieldDictionary.H @@ -32,11 +32,11 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef fieldDictionary_H -#define fieldDictionary_H +#ifndef Foam_fieldDictionary_H +#define Foam_fieldDictionary_H -#include "regIOobject.H" #include "dictionary.H" +#include "regIOobject.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -52,22 +52,22 @@ class fieldDictionary public regIOobject, public dictionary { - // Private Data - const word type_; + //- The specified field type + const word fieldType_; public: // Constructors - //- Construct from ioobject and overloaded typename. - fieldDictionary(const IOobject& io, const word& type) + //- Construct from IOobject and specified (overloaded) type name + fieldDictionary(const IOobject& io, const word& fieldType) : regIOobject(io), - dictionary(readStream(type)), - type_(type) + dictionary(readStream(fieldType)), + fieldType_(fieldType) { close(); } @@ -78,13 +78,13 @@ public: //- Redefine type name to be of the instantiated type virtual const word& type() const { - return type_; + return fieldType_; } - bool writeData(Ostream& os) const + //- The writeData function required by regIOobject write operation + virtual bool writeData(Ostream& os) const { - static_cast(*this).write(os, false); - + dictionary::write(os, false); return os.good(); } }; diff --git a/src/overset/cellCellStencil/cellCellStencil/cellCellStencilTemplates.C b/src/overset/cellCellStencil/cellCellStencil/cellCellStencilTemplates.C index 8023791110..f110df6463 100644 --- a/src/overset/cellCellStencil/cellCellStencil/cellCellStencilTemplates.C +++ b/src/overset/cellCellStencil/cellCellStencil/cellCellStencilTemplates.C @@ -185,29 +185,26 @@ void Foam::cellCellStencil::correctBoundaryConditions // Version of GeoField::correctBoundaryConditions that exclude evaluation // of oversetFvPatchFields - typename GeoField::Boundary& bfld = psi.boundaryFieldRef(); + auto& bfld = psi.boundaryFieldRef(); - const label nReq = Pstream::nRequests(); + const label startOfRequests = UPstream::nRequests(); - forAll(bfld, patchi) + for (auto& pfld : bfld) { - if (!isA(bfld[patchi])) + if (!isA(pfld)) { - bfld[patchi].initEvaluate(Pstream::commsTypes::nonBlocking); + pfld.initEvaluate(UPstream::commsTypes::nonBlocking); } } - // Block for any outstanding requests - if (Pstream::parRun()) - { - Pstream::waitRequests(nReq); - } + // Wait for outstanding requests (non-blocking) + UPstream::waitRequests(startOfRequests); - forAll(bfld, patchi) + for (auto& pfld : bfld) { - if (!isA(bfld[patchi])) + if (!isA(pfld)) { - bfld[patchi].evaluate(Pstream::commsTypes::nonBlocking); + pfld.evaluate(UPstream::commsTypes::nonBlocking); } } } diff --git a/src/overset/oversetFvMesh/oversetFvMeshBase.H b/src/overset/oversetFvMesh/oversetFvMeshBase.H index 4951322195..b0678b1a24 100644 --- a/src/overset/oversetFvMesh/oversetFvMeshBase.H +++ b/src/overset/oversetFvMesh/oversetFvMeshBase.H @@ -256,7 +256,7 @@ public: static void checkCoupledBC(const GeoField& fld); //- Correct boundary conditions of certain type (typeOnly = true) - // or explicitly not of the type (typeOnly = false) + //- or explicitly not of the type (typeOnly = false) template static void correctBoundaryConditions ( diff --git a/src/overset/oversetFvMesh/oversetFvMeshBaseTemplates.C b/src/overset/oversetFvMesh/oversetFvMeshBaseTemplates.C index c57a635818..471cbee742 100644 --- a/src/overset/oversetFvMesh/oversetFvMeshBaseTemplates.C +++ b/src/overset/oversetFvMesh/oversetFvMeshBaseTemplates.C @@ -80,28 +80,36 @@ void Foam::oversetFvMeshBase::correctBoundaryConditions const bool typeOnly ) { + // Alternative (C++14) + // + // bfld.evaluate_if + // ( + // [typeOnly](const auto& pfld) -> bool + // { + // return (typeOnly == bool(isA(pfld))); + // }, + // UPstream::defaultCommsType + // ); + const UPstream::commsTypes commsType = UPstream::defaultCommsType; const label startOfRequests = UPstream::nRequests(); - forAll(bfld, patchi) + for (auto& pfld : bfld) { - if (typeOnly == (isA(bfld[patchi]) != nullptr)) + if (typeOnly == bool(isA(pfld))) { - bfld[patchi].initEvaluate(commsType); + pfld.initEvaluate(commsType); } } - // Wait for outstanding requests - if (commsType == UPstream::commsTypes::nonBlocking) - { - Pstream::waitRequests(startOfRequests); - } + // Wait for outstanding requests (non-blocking) + UPstream::waitRequests(startOfRequests); - forAll(bfld, patchi) + for (auto& pfld : bfld) { - if (typeOnly == (isA(bfld[patchi]) != nullptr)) + if (typeOnly == bool(isA(pfld))) { - bfld[patchi].evaluate(commsType); + pfld.evaluate(commsType); } } } @@ -989,32 +997,30 @@ void Foam::oversetFvMeshBase::write template void Foam::oversetFvMeshBase::correctCoupledBoundaryConditions(GeoField& fld) { - typename GeoField::Boundary& bfld = fld.boundaryFieldRef(); + auto& bfld = fld.boundaryFieldRef(); const UPstream::commsTypes commsType = UPstream::defaultCommsType; + const label startOfRequests = UPstream::nRequests(); - forAll(bfld, patchi) + for (auto& pfld : bfld) { - if (bfld[patchi].coupled()) + if (pfld.coupled()) { - //Pout<< "initEval of " << bfld[patchi].patch().name() << endl; - bfld[patchi].initEvaluate(commsType); + //Pout<< "initEval of " << pfld.patch().name() << endl; + pfld.initEvaluate(commsType); } } - // Wait for outstanding requests - if (commsType == UPstream::commsTypes::nonBlocking) - { - Pstream::waitRequests(startOfRequests); - } + // Wait for outstanding requests (non-blocking) + UPstream::waitRequests(startOfRequests); - forAll(bfld, patchi) + for (auto& pfld : bfld) { - if (bfld[patchi].coupled()) + if (pfld.coupled()) { - //Pout<< "eval of " << bfld[patchi].patch().name() << endl; - bfld[patchi].evaluate(commsType); + //Pout<< "eval of " << pfld.patch().name() << endl; + pfld.evaluate(commsType); } } } From 9335b641f1d38bfa56a22c844ad64810b0bb1a8a Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 13 May 2024 12:31:57 +0200 Subject: [PATCH 2/2] ENH: GeometricBoundaryField evaluate with specified communication type - evaluate() the communication type is exposed as a parameter to allow for more tuning, but default parameter remains defaultCommsType so there is no change in behaviour for existing code - evaluate_if() supports a general selection predicate - evaluateSelected() now does initEvaluate() for all patches, waits and then calls evaluate(). This avoids potential deadlocks when multiple patches are inter-communicating. ENH: align DimensionedField reading with GeometricField treatment - use localIOdictionary to obtain the dictionary contents ENH: update GeometricField code - change GeometricField writeData() as primary output method (not operator<<) for better clarity of purpose - use unique_ptr for GeometricField demand-driven data --- .../DimensionedField/DimensionedField.H | 10 +- .../DimensionedField/DimensionedFieldIO.C | 58 +++-- .../GeometricField/GeometricBoundaryField.C | 218 +++++++++++------- .../GeometricField/GeometricBoundaryField.H | 58 +++-- .../GeometricField/GeometricField.C | 159 ++++--------- .../GeometricField/GeometricField.H | 21 +- 6 files changed, 282 insertions(+), 242 deletions(-) diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H index e7b4d21c6f..d37b651781 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H @@ -115,8 +115,12 @@ private: //- Assert that non-zero field size == mesh size void checkFieldSize() const; + //- Read from file if it is present. Checks the readOption flag void readIfPresent(const word& fieldDictEntry = "value"); + //- Read the field - create the field dictionary on-the-fly + void readField(const word& fieldDictEntry = "value"); + //- Implementation for 'New' with specified registerObject preference. // For LEGACY_REGISTER, registration is determined by // objectRegistry::is_cacheTemporaryObject(). @@ -580,8 +584,8 @@ public: bool writeData(Ostream& os, const word& fieldDictEntry) const; //- The writeData function (required by regIOobject), - //- call writeData with dictionary entry name = "value" - bool writeData(Ostream& os) const; + //- calls writeData with dictionary entry name = "value" + bool writeData(Ostream& os) const { return writeData(os, "value"); } // Member Operators @@ -613,12 +617,14 @@ public: // Ostream Operators + //- Calls DimensionedField::writeData() friend Ostream& operator<< ( Ostream& os, const DimensionedField& df ); + //- Calls DimensionedField::writeData() friend Ostream& operator<< ( Ostream& os, diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldIO.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldIO.C index 57a0da9e66..7ad8544616 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldIO.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldIO.C @@ -28,6 +28,7 @@ License #include "DimensionedField.H" #include "IOstreams.H" +#include "localIOdictionary.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -58,15 +59,49 @@ void Foam::DimensionedField::readField } +template +void Foam::DimensionedField::readField +( + const word& fieldDictEntry +) +{ + dictionary dict + ( + localIOdictionary::readContents + ( + IOobject + ( + this->name(), + this->instance(), + this->local(), + this->db(), + IOobjectOption::MUST_READ, + IOobjectOption::NO_WRITE, + IOobjectOption::NO_REGISTER + ), + typeName + ) + ); + + this->close(); + + readField(dict, fieldDictEntry); +} + + template void Foam::DimensionedField::readIfPresent ( const word& fieldDictEntry ) { - if (this->isReadRequired() || (this->isReadOptional() && this->headerOk())) + if + ( + this->isReadRequired() + || (this->isReadOptional() && this->headerOk()) + ) { - readField(dictionary(readStream(typeName)), fieldDictEntry); + readField(fieldDictEntry); } } @@ -87,7 +122,7 @@ Foam::DimensionedField::DimensionedField dimensions_(dimless), oriented_() { - readField(dictionary(readStream(typeName)), fieldDictEntry); + readField(fieldDictEntry); } @@ -134,23 +169,16 @@ bool Foam::DimensionedField::writeData } -template -bool Foam::DimensionedField::writeData(Ostream& os) const -{ - return writeData(os, "value"); -} - - // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // template Foam::Ostream& Foam::operator<< ( Ostream& os, - const DimensionedField& df + const DimensionedField& fld ) { - df.writeData(os); + fld.writeData(os); return os; } @@ -160,11 +188,11 @@ template Foam::Ostream& Foam::operator<< ( Ostream& os, - const tmp>& tdf + const tmp>& tfld ) { - tdf().writeData(os); - tdf.clear(); + tfld().writeData(os); + tfld.clear(); return os; } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C index 70d5ce2556..aff9204eef 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C @@ -91,7 +91,7 @@ bool Foam::GeometricBoundaryField::checkConsistency } } - // Wait for outstanding requests + // Wait for outstanding requests (non-blocking) UPstream::waitRequests(startOfRequests); for (auto& pfld : bfld) @@ -193,10 +193,7 @@ void Foam::GeometricBoundaryField::readField const dictionary& dict ) { - ///if (GeometricFieldclear(); @@ -363,10 +360,7 @@ Foam::GeometricBoundaryField::GeometricBoundaryField FieldField(bmesh.size()), bmesh_(bmesh) { - ///if (GeometricField::GeometricBoundaryField FieldField(bmesh.size()), bmesh_(bmesh) { - ///if (GeometricField::GeometricBoundaryField FieldField(bmesh.size()), bmesh_(bmesh) { - ///if (GeometricField::GeometricBoundaryField FieldField(btf.size()), bmesh_(btf.bmesh_) { - ///if (GeometricField::GeometricBoundaryField FieldField(btf.size()), bmesh_(btf.bmesh_) { - ///if (GeometricField::GeometricBoundaryField : FieldField(btf), bmesh_(btf.bmesh_) -{ - ///if (GeometricField class PatchField, class GeoMesh> @@ -573,10 +550,7 @@ Foam::GeometricBoundaryField::GeometricBoundaryField template class PatchField, class GeoMesh> void Foam::GeometricBoundaryField::updateCoeffs() { - ///if (GeometricField::updateCoeffs() template class PatchField, class GeoMesh> -void Foam::GeometricBoundaryField::evaluate() +void Foam::GeometricBoundaryField::evaluate +( + const UPstream::commsTypes commsType +) { - ///if (GeometricField::evaluate() else { FatalErrorInFunction - << "Unsupported communications type " - << UPstream::commsTypeNames[commsType] + << "Unsupported communications type " << int(commsType) << nl + << exit(FatalError); + } +} + + +template class PatchField, class GeoMesh> +template +void Foam::GeometricBoundaryField::evaluate_if +( + const UnaryPredicate& pred, + const UPstream::commsTypes commsType +) +{ + if + ( + commsType == UPstream::commsTypes::buffered + || commsType == UPstream::commsTypes::nonBlocking + ) + { + const label startOfRequests = UPstream::nRequests(); + + for (auto& pfld : *this) + { + if (pred(pfld)) + { + pfld.initEvaluate(commsType); + } + } + + // Wait for outstanding requests (non-blocking) + UPstream::waitRequests(startOfRequests); + + for (auto& pfld : *this) + { + if (pred(pfld)) + { + pfld.evaluate(commsType); + } + } + } + else if (commsType == UPstream::commsTypes::scheduled) + { + const lduSchedule& patchSchedule = + bmesh_.mesh().globalData().patchSchedule(); + + for (const auto& schedEval : patchSchedule) + { + const label patchi = schedEval.patch; + auto& pfld = (*this)[patchi]; + + if (pred(pfld)) + { + if (schedEval.init) + { + pfld.initEvaluate(commsType); + } + else + { + pfld.evaluate(commsType); + } + } + } + } + else + { + FatalErrorInFunction + << "Unsupported communications type " << int(commsType) << nl << exit(FatalError); } } @@ -651,58 +685,60 @@ void Foam::GeometricBoundaryField::evaluate() template class PatchField, class GeoMesh> void Foam::GeometricBoundaryField::evaluateSelected ( - const UList