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
This commit is contained in:
Mark Olesen
2024-05-13 12:31:57 +02:00
parent 1406f9ec26
commit ffc9894033
22 changed files with 136 additions and 145 deletions

View File

@ -1,3 +0,0 @@
Test-dimField.C
EXE = $(FOAM_USER_APPBIN)/Test-dimField

View File

@ -0,0 +1,3 @@
Test-dimField1.cxx
EXE = $(FOAM_USER_APPBIN)/Test-dimField1

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020-2022 OpenCFD Ltd. Copyright (C) 2020-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -24,7 +24,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application Application
Test-dimField Test-dimField1
Description Description
Simple tests for DimensionedField Simple tests for DimensionedField
@ -52,7 +52,12 @@ namespace Foam
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
argList::addBoolOption("write", "write some test fields");
#include "setRootCase.H" #include "setRootCase.H"
const bool doWrite = args.found("write");
#include "createTime.H" #include "createTime.H"
#include "createMesh.H" #include "createMesh.H"
@ -60,19 +65,23 @@ int main(int argc, char *argv[])
Info<< "Tensor field\n" << endl; Info<< "Tensor field\n" << endl;
DimensionedField<tensor, volMesh> tensorfld DimensionedField<tensor, volMesh> tensorfld
( (
IOobject mesh.newIOobject
( (
"tensor", "tensor",
runTime.timeName(), { IOobject::READ_IF_PRESENT, IOobject::NO_WRITE }
mesh,
{ IOobject::READ_IF_PRESENT, IOobject::NO_REGISTER }
), ),
mesh, mesh,
dimensioned<tensor>(dimless, tensor(1,2,3,4,5,6,7,8,9)) dimensioned<tensor>(dimless, tensor(1,2,3,4,5,6,7,8,9))
); );
Info().beginBlock("transformed") if (doWrite)
<< tensorfld.T() << nl; {
tensorfld.write();
}
Info<< nl;
Info().beginBlock("transformed") << tensorfld.T();
Info().endBlock(); Info().endBlock();
{ {
@ -84,8 +93,8 @@ int main(int argc, char *argv[])
dimensioned<scalar>(14) dimensioned<scalar>(14)
); );
Info().beginBlock(tfld().type()) Info<< nl;
<< tfld << nl; Info().beginBlock(tfld().type()) << tfld;
Info().endBlock(); Info().endBlock();
} }
@ -98,8 +107,8 @@ int main(int argc, char *argv[])
dimensioned<scalar>(5) dimensioned<scalar>(5)
); );
Info().beginBlock(tfld().type()) Info<< nl;
<< tfld() << nl; Info().beginBlock(tfld().type()) << tfld();
Info().endBlock(); Info().endBlock();
// From dissimilar types // From dissimilar types
@ -111,8 +120,8 @@ int main(int argc, char *argv[])
dimensioned<vector>(Zero) dimensioned<vector>(Zero)
); );
Info().beginBlock(tfld2().type()) Info<< nl;
<< tfld2() << nl; Info().beginBlock(tfld2().type()) << tfld2();
Info().endBlock(); Info().endBlock();
} }
} }
@ -122,20 +131,13 @@ int main(int argc, char *argv[])
Info<< "uint8 field\n" << endl; Info<< "uint8 field\n" << endl;
DimensionedField<uint8_t, volMesh> statefld DimensionedField<uint8_t, volMesh> statefld
( (
IOobject mesh.newIOobject("state")
(
"state",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh, mesh,
dimensioned<uint8_t>(dimless, uint8_t{100}) dimensioned<uint8_t>(dimless, uint8_t{100})
); );
Info().beginBlock("stateField") Info<< nl;
<< statefld << nl; Info().beginBlock("stateField") << statefld;
Info().endBlock(); Info().endBlock();
} }
#endif #endif

View File

@ -7,5 +7,6 @@ EXE_INC = \
EXE_LIBS = \ EXE_LIBS = \
-lfiniteVolume \ -lfiniteVolume \
-ldynamicFvMesh \
-lsampling \ -lsampling \
-loverset -loverset

View File

@ -56,6 +56,7 @@ Description
#include "fvCFD.H" #include "fvCFD.H"
#include "simpleControl.H" #include "simpleControl.H"
#include "predicates.H"
#include "dynamicFvMesh.H" #include "dynamicFvMesh.H"
#include "dynamicOversetFvMesh.H" #include "dynamicOversetFvMesh.H"
@ -97,6 +98,7 @@ int main(int argc, char *argv[])
component(T.ref(), mesh.C(), 1); component(T.ref(), mesh.C(), 1);
// Interpolate + halo swap // Interpolate + halo swap
T.correctBoundaryConditions(); T.correctBoundaryConditions();
// T.boundaryFieldRef().evaluate_if(predicates::always{});
// Check halo swap // Check halo swap
dynamicOversetFvMesh::checkCoupledBC(T); dynamicOversetFvMesh::checkCoupledBC(T);
} }

View File

@ -26,8 +26,8 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef MapConsistentVolFields_H #ifndef Foam_MapConsistentVolFields_H
#define MapConsistentVolFields_H #define Foam_MapConsistentVolFields_H
#include "GeometricField.H" #include "GeometricField.H"
#include "meshToMesh.H" #include "meshToMesh.H"
@ -41,10 +41,9 @@ namespace Foam
template<class Type> template<class Type>
void evaluateConstraintTypes(GeometricField<Type, fvPatchField, volMesh>& fld) void evaluateConstraintTypes(GeometricField<Type, fvPatchField, volMesh>& fld)
{ {
auto& fldBf = fld.boundaryFieldRef(); auto& bfld = fld.boundaryFieldRef();
const UPstream::commsTypes commsType = UPstream::defaultCommsType; const UPstream::commsTypes commsType = UPstream::defaultCommsType;
const label startOfRequests = UPstream::nRequests();
if if
( (
@ -52,37 +51,32 @@ void evaluateConstraintTypes(GeometricField<Type, fvPatchField, volMesh>& fld)
|| commsType == UPstream::commsTypes::nonBlocking || commsType == UPstream::commsTypes::nonBlocking
) )
{ {
forAll(fldBf, patchi) const label startOfRequests = UPstream::nRequests();
{
fvPatchField<Type>& tgtField = fldBf[patchi];
for (auto& pfld : bfld)
{
if if
( (
tgtField.type() == tgtField.patch().patch().type() pfld.type() == pfld.patch().patch().type()
&& polyPatch::constraintType(tgtField.patch().patch().type()) && polyPatch::constraintType(pfld.patch().patch().type())
) )
{ {
tgtField.initEvaluate(commsType); pfld.initEvaluate(commsType);
} }
} }
// Wait for outstanding requests // Wait for outstanding requests (non-blocking)
if (commsType == UPstream::commsTypes::nonBlocking) UPstream::waitRequests(startOfRequests);
{
UPstream::waitRequests(startOfRequests);
}
forAll(fldBf, patchi) for (auto& pfld : bfld)
{ {
fvPatchField<Type>& tgtField = fldBf[patchi];
if if
( (
tgtField.type() == tgtField.patch().patch().type() pfld.type() == pfld.patch().patch().type()
&& polyPatch::constraintType(tgtField.patch().patch().type()) && polyPatch::constraintType(pfld.patch().patch().type())
) )
{ {
tgtField.evaluate(commsType); pfld.evaluate(commsType);
} }
} }
} }
@ -94,22 +88,21 @@ void evaluateConstraintTypes(GeometricField<Type, fvPatchField, volMesh>& fld)
for (const auto& schedEval : patchSchedule) for (const auto& schedEval : patchSchedule)
{ {
const label patchi = schedEval.patch; const label patchi = schedEval.patch;
auto& pfld = bfld[patchi];
fvPatchField<Type>& tgtField = fldBf[patchi];
if if
( (
tgtField.type() == tgtField.patch().patch().type() pfld.type() == pfld.patch().patch().type()
&& polyPatch::constraintType(tgtField.patch().patch().type()) && polyPatch::constraintType(pfld.patch().patch().type())
) )
{ {
if (schedEval.init) if (schedEval.init)
{ {
tgtField.initEvaluate(commsType); pfld.initEvaluate(commsType);
} }
else else
{ {
tgtField.evaluate(commsType); pfld.evaluate(commsType);
} }
} }
} }

View File

@ -1440,7 +1440,7 @@ void Foam::polyBoundaryMesh::writeEntry(Ostream& os) const
void Foam::polyBoundaryMesh::writeEntry void Foam::polyBoundaryMesh::writeEntry
( (
const keyType& keyword, const word& keyword,
Ostream& os Ostream& os
) const ) const
{ {

View File

@ -379,7 +379,7 @@ public:
//- Write as a primitive entry with given name. //- Write as a primitive entry with given name.
//- If the keyword is empty, revert to a plain list. //- 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 //- The writeData member function required by regIOobject
virtual bool writeData(Ostream& os) const; virtual bool writeData(Ostream& os) const;

View File

@ -214,7 +214,7 @@ void Foam::polyBoundaryMeshEntries::writeEntry(Ostream& os) const
void Foam::polyBoundaryMeshEntries::writeEntry void Foam::polyBoundaryMeshEntries::writeEntry
( (
const keyType& keyword, const word& keyword,
Ostream& os Ostream& os
) const ) const
{ {

View File

@ -121,7 +121,7 @@ public:
//- Write as a primitive entry with given name. //- Write as a primitive entry with given name.
//- If the keyword is empty, revert to a plain list. //- 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 //- The writeData member function required by regIOobject
virtual bool writeData(Ostream& os) const; virtual bool writeData(Ostream& os) const;

View File

@ -1058,7 +1058,7 @@ void Foam::faBoundaryMesh::writeEntry(Ostream& os) const
void Foam::faBoundaryMesh::writeEntry void Foam::faBoundaryMesh::writeEntry
( (
const keyType& keyword, const word& keyword,
Ostream& os Ostream& os
) const ) const
{ {

View File

@ -299,7 +299,7 @@ public:
//- Write as a primitive entry with given name. //- Write as a primitive entry with given name.
//- If the keyword is empty, revert to a plain list. //- 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 //- The writeData member function required by regIOobject
virtual bool writeData(Ostream& os) const; virtual bool writeData(Ostream& os) const;

View File

@ -183,7 +183,7 @@ void Foam::faBoundaryMeshEntries::writeEntry(Ostream& os) const
void Foam::faBoundaryMeshEntries::writeEntry void Foam::faBoundaryMeshEntries::writeEntry
( (
const keyType& keyword, const word& keyword,
Ostream& os Ostream& os
) const ) const
{ {

View File

@ -108,7 +108,7 @@ public:
//- Write as a primitive entry with given name. //- Write as a primitive entry with given name.
//- If the keyword is empty, revert to a plain list. //- 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 //- The writeData member function required by regIOobject
virtual bool writeData(Ostream& os) const; virtual bool writeData(Ostream& os) const;

View File

@ -107,8 +107,7 @@ void Foam::volPointInterpolation::addSeparated
} }
} }
// Wait for outstanding requests // Wait for outstanding requests (non-blocking)
// (commsType == UPstream::commsTypes::nonBlocking)
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
forAll(pfbf, patchi) forAll(pfbf, patchi)

View File

@ -36,10 +36,9 @@ void Foam::functionObjects::mapFields::evaluateConstraintTypes
GeometricField<Type, fvPatchField, volMesh>& fld GeometricField<Type, fvPatchField, volMesh>& fld
) const ) const
{ {
auto& fldBf = fld.boundaryFieldRef(); auto& bfld = fld.boundaryFieldRef();
const UPstream::commsTypes commsType = UPstream::defaultCommsType; const UPstream::commsTypes commsType = UPstream::defaultCommsType;
const label startOfRequests = UPstream::nRequests();
if if
( (
@ -47,37 +46,32 @@ void Foam::functionObjects::mapFields::evaluateConstraintTypes
|| commsType == UPstream::commsTypes::nonBlocking || commsType == UPstream::commsTypes::nonBlocking
) )
{ {
forAll(fldBf, patchi) const label startOfRequests = UPstream::nRequests();
{
fvPatchField<Type>& tgtField = fldBf[patchi];
for (auto& pfld : bfld)
{
if if
( (
tgtField.type() == tgtField.patch().patch().type() pfld.type() == pfld.patch().patch().type()
&& polyPatch::constraintType(tgtField.patch().patch().type()) && polyPatch::constraintType(pfld.patch().patch().type())
) )
{ {
tgtField.initEvaluate(commsType); pfld.initEvaluate(commsType);
} }
} }
// Wait for outstanding requests // Wait for outstanding requests (non-blocking)
if (commsType == UPstream::commsTypes::nonBlocking) UPstream::waitRequests(startOfRequests);
{
UPstream::waitRequests(startOfRequests);
}
forAll(fldBf, patchi) for (auto& pfld : bfld)
{ {
fvPatchField<Type>& tgtField = fldBf[patchi];
if if
( (
tgtField.type() == tgtField.patch().patch().type() pfld.type() == pfld.patch().patch().type()
&& polyPatch::constraintType(tgtField.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) for (const auto& schedEval : patchSchedule)
{ {
const label patchi = schedEval.patch; const label patchi = schedEval.patch;
auto& pfld = bfld[patchi];
fvPatchField<Type>& tgtField = fldBf[patchi];
if if
( (
tgtField.type() == tgtField.patch().patch().type() pfld.type() == pfld.patch().patch().type()
&& polyPatch::constraintType(tgtField.patch().patch().type()) && polyPatch::constraintType(pfld.patch().patch().type())
) )
{ {
if (schedEval.init) if (schedEval.init)
{ {
tgtField.initEvaluate(commsType); pfld.initEvaluate(commsType);
} }
else else
{ {
tgtField.evaluate(commsType); pfld.evaluate(commsType);
} }
} }
} }

View File

@ -37,11 +37,9 @@ bool Foam::functionObjects::zeroGradient::accept
const GeometricField<Type, fvPatchField, volMesh>& input const GeometricField<Type, fvPatchField, volMesh>& input
) )
{ {
const auto& patches = input.boundaryField(); for (const auto& pfld : input.boundaryField())
forAll(patches, patchi)
{ {
if (!polyPatch::constraintType(patches[patchi].patch().patch().type())) if (!polyPatch::constraintType(pfld.patch().patch().type()))
{ {
return true; return true;
} }

View File

@ -32,11 +32,11 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef fieldDictionary_H #ifndef Foam_fieldDictionary_H
#define fieldDictionary_H #define Foam_fieldDictionary_H
#include "regIOobject.H"
#include "dictionary.H" #include "dictionary.H"
#include "regIOobject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -52,22 +52,22 @@ class fieldDictionary
public regIOobject, public regIOobject,
public dictionary public dictionary
{ {
// Private Data // Private Data
const word type_; //- The specified field type
const word fieldType_;
public: public:
// Constructors // Constructors
//- Construct from ioobject and overloaded typename. //- Construct from IOobject and specified (overloaded) type name
fieldDictionary(const IOobject& io, const word& type) fieldDictionary(const IOobject& io, const word& fieldType)
: :
regIOobject(io), regIOobject(io),
dictionary(readStream(type)), dictionary(readStream(fieldType)),
type_(type) fieldType_(fieldType)
{ {
close(); close();
} }
@ -78,13 +78,13 @@ public:
//- Redefine type name to be of the instantiated type //- Redefine type name to be of the instantiated type
virtual const word& type() const 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<const dictionary&>(*this).write(os, false); dictionary::write(os, false);
return os.good(); return os.good();
} }
}; };

View File

@ -185,29 +185,26 @@ void Foam::cellCellStencil::correctBoundaryConditions
// Version of GeoField::correctBoundaryConditions that exclude evaluation // Version of GeoField::correctBoundaryConditions that exclude evaluation
// of oversetFvPatchFields // 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<SuppressBC>(bfld[patchi])) if (!isA<SuppressBC>(pfld))
{ {
bfld[patchi].initEvaluate(Pstream::commsTypes::nonBlocking); pfld.initEvaluate(UPstream::commsTypes::nonBlocking);
} }
} }
// Block for any outstanding requests // Wait for outstanding requests (non-blocking)
if (Pstream::parRun()) UPstream::waitRequests(startOfRequests);
{
Pstream::waitRequests(nReq);
}
forAll(bfld, patchi) for (auto& pfld : bfld)
{ {
if (!isA<SuppressBC>(bfld[patchi])) if (!isA<SuppressBC>(pfld))
{ {
bfld[patchi].evaluate(Pstream::commsTypes::nonBlocking); pfld.evaluate(UPstream::commsTypes::nonBlocking);
} }
} }
} }

View File

@ -256,7 +256,7 @@ public:
static void checkCoupledBC(const GeoField& fld); static void checkCoupledBC(const GeoField& fld);
//- Correct boundary conditions of certain type (typeOnly = true) //- 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<class GeoField, class PatchType> template<class GeoField, class PatchType>
static void correctBoundaryConditions static void correctBoundaryConditions
( (

View File

@ -80,28 +80,36 @@ void Foam::oversetFvMeshBase::correctBoundaryConditions
const bool typeOnly const bool typeOnly
) )
{ {
// Alternative (C++14)
//
// bfld.evaluate_if
// (
// [typeOnly](const auto& pfld) -> bool
// {
// return (typeOnly == bool(isA<PatchType>(pfld)));
// },
// UPstream::defaultCommsType
// );
const UPstream::commsTypes commsType = UPstream::defaultCommsType; const UPstream::commsTypes commsType = UPstream::defaultCommsType;
const label startOfRequests = UPstream::nRequests(); const label startOfRequests = UPstream::nRequests();
forAll(bfld, patchi) for (auto& pfld : bfld)
{ {
if (typeOnly == (isA<PatchType>(bfld[patchi]) != nullptr)) if (typeOnly == bool(isA<PatchType>(pfld)))
{ {
bfld[patchi].initEvaluate(commsType); pfld.initEvaluate(commsType);
} }
} }
// Wait for outstanding requests // Wait for outstanding requests (non-blocking)
if (commsType == UPstream::commsTypes::nonBlocking) UPstream::waitRequests(startOfRequests);
{
Pstream::waitRequests(startOfRequests);
}
forAll(bfld, patchi) for (auto& pfld : bfld)
{ {
if (typeOnly == (isA<PatchType>(bfld[patchi]) != nullptr)) if (typeOnly == bool(isA<PatchType>(pfld)))
{ {
bfld[patchi].evaluate(commsType); pfld.evaluate(commsType);
} }
} }
} }
@ -989,32 +997,30 @@ void Foam::oversetFvMeshBase::write
template<class GeoField> template<class GeoField>
void Foam::oversetFvMeshBase::correctCoupledBoundaryConditions(GeoField& fld) void Foam::oversetFvMeshBase::correctCoupledBoundaryConditions(GeoField& fld)
{ {
typename GeoField::Boundary& bfld = fld.boundaryFieldRef(); auto& bfld = fld.boundaryFieldRef();
const UPstream::commsTypes commsType = UPstream::defaultCommsType; const UPstream::commsTypes commsType = UPstream::defaultCommsType;
const label startOfRequests = UPstream::nRequests(); 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; //Pout<< "initEval of " << pfld.patch().name() << endl;
bfld[patchi].initEvaluate(commsType); pfld.initEvaluate(commsType);
} }
} }
// Wait for outstanding requests // Wait for outstanding requests (non-blocking)
if (commsType == UPstream::commsTypes::nonBlocking) UPstream::waitRequests(startOfRequests);
{
Pstream::waitRequests(startOfRequests);
}
forAll(bfld, patchi) for (auto& pfld : bfld)
{ {
if (bfld[patchi].coupled()) if (pfld.coupled())
{ {
//Pout<< "eval of " << bfld[patchi].patch().name() << endl; //Pout<< "eval of " << pfld.patch().name() << endl;
bfld[patchi].evaluate(commsType); pfld.evaluate(commsType);
} }
} }
} }