40 const bool wantPointData,
41 const label expectedSize
45 <<
"Looking for global" << (wantPointData ?
" point" :
"")
46 <<
" field name:" <<
name;
51 <<
" - found (" <<
result.valueType() <<
' '
52 <<
result.isPointData() <<
')';
56 (
result.isType<Type>() &&
result.isPointData(wantPointData));
59 if (good && expectedSize >= 0)
80 const label expectedSize,
90 else if (isGlobalVariable<Type>(
name))
98 const auto& var = tvar.
cref();
100 const Field<Type>& vals = var.cref<Type>();
109 return tmp<Field<Type>>
::New(vals);
112 if (!var.isUniform())
115 <<
"Variable " <<
name
116 <<
" is nonuniform and does not fit the size "
117 << expectedSize <<
". Using average" <<
endl;
126 <<
"Variable (" <<
name <<
") not found." <<
nl
142 Info<<
"fvExprDriver::foundField. Name: " <<
name
143 <<
" Type: " << Type::typeName
144 <<
" registry:" << searchRegistry()
145 <<
" disk:" << searchFiles() <<
endl;
149 for (
int checki = 0; checki < 2; ++checki)
153 const regIOobject* ioptr =
nullptr;
159 else if (searchRegistry())
161 ioptr = this->
mesh().cfindIOobject(
name);
163 if (!ioptr)
continue;
165 const Type* fldPtr =
dynamic_cast<const Type*
>(ioptr);
173 Info<<
"Found registered:";
177 Info<<
"Found context object:";
189 Info<<
"Registered:";
193 Info<<
"Context object:";
196 << ioptr->headerClassName() <<
" != type:"
197 << Type::typeName <<
nl;
203 if (searchFiles() && getTypeOfField(
name) == Type::typeName)
230 Info<<
"fvExprDriver::isField <" <<
name <<
'>' <<
endl;
246template<
class GeomField,
class Mesh>
255 typedef typename GeomField::value_type Type;
261 Info<<
"fvExprDriver::getOrReadField <" <<
name
262 <<
"> Type: " << GeomField::typeName <<
endl;
275 else if (isGlobalVariable<Type>(
name))
282 const auto& var = tvar.
cref();
283 const Type deflt(var.getValue<Type>());
287 Info<<
"Getting " <<
name <<
" from variables. Default: "
293 Info<<
"Creating field " <<
name <<
" of type "
294 << GeomField::typeName <<
nl;
297 tfield = GeomField::New
301 dimensioned<Type>(deflt),
303 defaultBoundaryType(GeomField::null())
309 Info<<
"New field: " <<
name <<
" ownedByRegistry"
310 <<
fld.ownedByRegistry() <<
endl;
313 const Field<Type>& vals = var.cref<Type>();
317 Pout<<
"sizes: " << vals.size() <<
' ' <<
fld.size() <<
endl;
322 fld.primitiveFieldRef() = vals;
334 if (
range.mag() > SMALL)
337 <<
"The min/max ranges differ " <<
range
338 <<
" - using average " << avg <<
nl;
342 fld.primitiveFieldRef() = avg;
354 const GeomField* origFldPtr =
nullptr;
356 for (
int checki = 0; !origFldPtr && checki < 2; ++checki)
365 else if (searchRegistry())
368 meshRef.thisDb().template cfindObject<GeomField>(
name);
378 Info<<
"Retrieve context/registered:" <<
name <<
nl;
381 const GeomField& origFld = *origFldPtr;
390 tfield = GeomField::New(
name +
"_exprDriverCopy", origFld);
396 Info<<
"Getting oldTime of " <<
name <<
" has "
397 << origFld.nOldTimes() <<
endl;
400 if (!origFld.nOldTimes() && this->prevIterIsOldTime())
404 Info<<
"No oldTime, using previous iteration" <<
endl;
406 tfield.
ref().oldTime() = origFld.prevIter();
410 else if (searchFiles() && getTypeOfField(
name) == GeomField::typeName)
419 this->readAndRegister<GeomField>(
name, meshRef)
432 GeomField&
fld = tfield.
ref();
436 Info<<
"Valid " <<
name <<
" found. Removing dimensions" <<
nl;
439 fld.dimensions().clear();
445 Info<<
"Removing dimensions of oldTime of " <<
name
446 <<
" has " <<
fld.nOldTimes() <<
nl;
453 GeomField* fp = &(
fld);
455 while (fp->nOldTimes())
457 fp = &(fp->oldTime());
458 fp->dimensions().clear();
468 <<
"Could not find field " <<
name
469 <<
" in registry or on file-system" <<
nl
486 const word regName =
name +
"RegisteredNameFor" + T::typeName;
490 Info<<
"Looking for " << T::typeName <<
" named " <<
name
491 <<
" or registered as " << regName <<
" with mesh "
492 <<
"Caching:" << cacheSets()
493 <<
" Found:" << (
mesh.foundObject<
T>(
name))
494 <<
" Found registered:" <<
mesh.foundObject<
T>(regName)
499 origin = SetOrigin::INVALID;
507 !
mesh.thisDb().foundObject<
T>(regName)
514 Info<<
"Constructing new " << T::typeName <<
' ' <<
name <<
nl;
522 origin = SetOrigin::FILE;
529 Info<<
"Registering a copy of " <<
name <<
" with mesh" <<
nl;
532 autoPtr<T> toCache(
new T(
mesh, regName, *setPtr));
533 toCache->store(toCache);
538 const T* ptr =
mesh.thisDb().template cfindObject<T>(
name);
547 origin = SetOrigin::MEMORY;
554 Info<<
"Getting existing " << regName <<
endl;
557 origin = SetOrigin::CACHE;
575 const label oldSize = setPtr->size();
577 bool updated =
false;
582 Info<<
"UpdateSet: " << setPtr->name() <<
" Id: " <<
name
583 <<
" Origin: " << int(origin) <<
endl;
588 case SetOrigin::FILE:
593 mesh.time().timeName(),
600 if (header.typeHeaderOk<
T>())
604 Pout<<
"Rereading from "
605 << header.localFilePath(T::typeName) <<
endl;
607 setPtr.
reset(
new T(header));
614 case SetOrigin::MEMORY:
615 case SetOrigin::CACHE:
617 if (origin == SetOrigin::NEW)
620 <<
"State NEW shouldn't exist"
626 const T* ptr =
mesh.thisDb().template cfindObject<T>(
name);
633 <<
" and rereading it" <<
endl;
642 <<
"In registry: " <<
mesh.thisDb().names() <<
endl
652 << T::typeName <<
' ' <<
name <<
" is invalid" <<
endl
661 Info<<
"Origin " << int(origin) <<
" not implemented" <<
endl;
669 Pout<<
name <<
" old size " << oldSize <<
" new: "
670 << setPtr->size() <<
endl;
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const word & headerClassName() const noexcept
Return name of the class name read from header.
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (respects is_globalIOobject trait) and check its info. A void type suppresses trait and t...
fileName localFilePath(const word &typeName, const bool search=true) const
Redirect to fileHandler filePath, searching locally.
A min/max value pair with additional methods. In addition to conveniently storing values,...
static const char * name(bool b) noexcept
A string representation of bool as "false" / "true".
void size(const label n)
Older name for setAddressableSize.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
static bool checking() noexcept
True if dimension checking is enabled (the usual default).
Generic dimensioned Type class.
bool searchFiles() const noexcept
bool searchRegistry() const noexcept
const ObjType * cfindContextObject(const word &name) const
Find context field object of specified type.
const exprResult & result() const noexcept
Const access to expression result.
const regIOobject * cfindContextIOobject(const word &name) const
Find named context field, if it exists.
A polymorphic field/result from evaluating an expression.
virtual exprResult & variable(const word &name)
Non-const access to the named variable (sub-classes only).
bool foundField(const word &name) const
Test if specified field can be found in memory or disk.
tmp< Field< Type > > getVariable(const word &name, const label expectSize, const bool mandatory=true) const
Retrieve local/global variable as a tmp field.
tmp< GeomField > readAndRegister(const word &name, const MeshRef &meshRef)
Helper function for getOrReadField.
const exprResult & lookupGlobal(const word &name) const
Return the global variable if available or a null result.
tmp< GeomField > getOrReadFieldImpl(const word &name, const MeshRef &meshRef, const bool mandatory=true, const bool getOldTime=false)
Retrieve field from memory or disk (implementation).
virtual const fvMesh & mesh() const =0
The mesh we are attached to.
static word defaultBoundaryType(const T &)
Default boundary type is calculated.
bool isField(const word &name, const bool wantPointData=false, const label expectSize=-1) const
Test for the existence of a mesh field.
static void correctField(T &)
Apply correctBoundaryConditions (volume fields only).
autoPtr< T > getTopoSet(const fvMesh &mesh, const word &setName, SetOrigin &origin) const
Get topoSet.
virtual bool hasVariable(const word &name) const
True if named variable exists.
bool cacheSets() const
Status of cache-sets (static variable).
bool updateSet(autoPtr< T > &setPtr, const word &setName, SetOrigin origin) const
Update topoSet.
word getTypeOfField(const word &fieldName) const
Read the IOobject for fieldName and return its headerClassName.
SetOrigin
The origin of the topoSet.
bool isGlobalVariable(const word &name, const bool wantPointData=false, const label expectedSize=-1) const
Test existence of a global variable.
Mesh data needed to do the Finite Volume discretisation.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh").
A class for managing references or pointers (no reference counting).
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
bool valid() const noexcept
Identical to good(), or bool operator.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
A class for managing temporary objects.
bool valid() const noexcept
Identical to good(), or bool operator.
void reset(tmp< T > &&other) noexcept
Clear existing and transfer ownership.
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for handling debugging switches.
@ INVALID
Invalid/unknown/error type.
Type gAverage(const FieldField< Field, Type > &f, const label comm)
The global arithmetic average of a FieldField.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
GeometricField< Type, fvPatchField, volMesh > VolumeField
A volume field for a given type.
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
bool isType(const U &obj)
Check if typeid of the object and Type are identical.
GeometricField< Type, pointPatchField, pointMesh > PointField
A point field for a given type.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
GeometricField< Type, fvsPatchField, surfaceMesh > SurfaceField
A (volume) surface field for a given type.
constexpr char nl
The newline '\n' character (0x0a).
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...