Go to the documentation of this file.
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)
61 good = (result.size() == expectedSize);
81 const label expectedSize,
87 if (hasVariable(
name) && variable(
name).isType<Type>())
91 else if (isGlobalVariable<Type>(
name))
99 const auto& var = tvar.
cref();
113 if (!var.isUniform())
116 <<
"Variable " <<
name
117 <<
" is nonuniform and does not fit the size "
118 << expectedSize <<
". Using average" <<
endl;
127 <<
"Variable (" <<
name <<
") not found." <<
nl
143 Info<<
"fvExprDriver::foundField. Name: " <<
name
144 <<
" Type: " << Type::typeName
145 <<
" registry:" << searchRegistry()
146 <<
" disk:" << searchFiles() <<
endl;
150 for (
int checki = 0; checki < 2; ++checki)
158 ioptr = exprDriver::cfindContextIOobject(
name);
160 else if (searchRegistry())
162 ioptr = this->
mesh().cfindIOobject(name);
164 if (!ioptr)
continue;
166 const Type* fldPtr =
dynamic_cast<const Type*
>(ioptr);
174 Info<<
"Found registered:";
178 Info<<
"Found context object:";
190 Info<<
"Registered:";
194 Info<<
"Context object:";
198 << Type::typeName <<
nl;
204 if (searchFiles() && getTypeOfField(
name) == Type::typeName)
231 Info<<
"fvExprDriver::isField <" << name << '>
' << endl;
234 typedef GeometricField<Type, fvPatchField, volMesh> vfieldType;
235 typedef GeometricField<Type, fvsPatchField, surfaceMesh> sfieldType;
236 typedef GeometricField<Type, pointPatchField, pointMesh> pfieldType;
241 ? this->foundField<pfieldType>(name)
244 this->foundField<vfieldType>(name)
245 || this->foundField<sfieldType>(name)
251 template<class GeomField, class Mesh>
252 Foam::tmp<GeomField> Foam::expressions::fvExprDriver::getOrReadFieldImpl
260 typedef typename GeomField::value_type Type;
262 tmp<GeomField> tfield;
266 Info<< "fvExprDriver::getOrReadField <" << name
267 << "> Type: " << GeomField::typeName << endl;
274 refPtr<expressions::exprResult> tvar;
276 if (hasVariable(name) && variable(name).isType<Type>())
278 tvar.cref(variable(name));
280 else if (isGlobalVariable<Type>(name))
282 tvar.cref(lookupGlobal(name));
287 const auto& var = tvar.cref();
288 const Type deflt(var.getValue<Type>());
292 Info<< "Getting " << name << " from variables. Default: "
298 Info<< "Creating field " << name << " of type "
299 << GeomField::typeName << nl;
302 tfield = GeomField::New
306 dimensioned<Type>(deflt),
307 // Patch is zeroGradient (volFields) or calculated (other)
308 defaultBoundaryType(GeomField::null())
310 auto& fld = tfield.ref();
314 Info<< "New field: " << name << " ownedByRegistry"
315 << fld.ownedByRegistry() << endl;
318 const Field<Type>& vals = var.cref<Type>();
322 Pout<< "sizes: " << vals.size() << ' ' << fld.size() << endl;
325 if (returnReduce((vals.size() == fld.size()), andOp<bool>()))
327 fld.primitiveFieldRef() = vals;
331 const Type avg = gAverage(vals);
337 MinMax<Type> range = gMinMax(vals);
339 if (range.mag() > SMALL)
342 << "The min/max ranges differ " << range
343 << " - using average " << avg << nl;
347 fld.primitiveFieldRef() = avg;
356 // Find context or registered field
357 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
359 const GeomField* origFldPtr = nullptr;
361 for (int checki = 0; !origFldPtr && checki < 2; ++checki)
363 // Check 0: object context (first)
364 // Check 1: regular objectRegistry
368 origFldPtr = exprDriver::cfindContextObject<GeomField>(name);
370 else if (searchRegistry())
373 meshRef.thisDb().template cfindObject<GeomField>(name);
379 // Found from context or registry
383 Info<< "Retrieve context/registered:" << name << nl;
386 const GeomField& origFld = *origFldPtr;
388 // Make a deep copy of the data to return. Avoids shadowing
389 // the original object, but most importantly the backend
390 // parser (eg, lemon) will be working with combining via plain
391 // pointers. We thus lose any of the tmp<> shallow copy semantics
392 // anyhow. Additionally, need to disable dimension checking here or
395 tfield = GeomField::New(name + "_exprDriverCopy", origFld);
401 Info<< "Getting oldTime of " << name << " has "
402 << origFld.nOldTimes() << endl;
405 if (!origFld.nOldTimes() && this->prevIterIsOldTime())
409 Info<< "No oldTime, using previous iteration" << endl;
411 tfield.ref().oldTime() = origFld.prevIter();
415 else if (searchFiles() && getTypeOfField(name) == GeomField::typeName)
419 Info<< "Reading " << name << " from disc" << endl;
424 this->readAndRegister<GeomField>(name, meshRef)
426 // oldTime automatically read
432 Info<< "field: valid()=" << Switch::name(tfield.valid()) << endl;
437 GeomField& fld = tfield.ref();
441 Info<< "Valid " << name << " found. Removing dimensions" << nl;
444 fld.dimensions().clear();
450 Info<< "Removing dimensions of oldTime of " << name
451 << " has " << fld.nOldTimes() << nl;
454 // Switch dimension checking off
455 const bool oldDimChecking = dimensionSet::checking(false);
457 // go through ALL old times
458 GeomField* fp = &(fld);
460 while (fp->nOldTimes())
462 fp = &(fp->oldTime());
463 fp->dimensions().clear();
466 // Restore old value of dimension checking
467 dimensionSet::checking(oldDimChecking);
473 << "Could not find field " << name
474 << " in registry or on file-system" << nl
483 Foam::autoPtr<T> Foam::expressions::fvExprDriver::getTopoSet
490 // Avoid possible name clashes
491 const word regName = name + "RegisteredNameFor" + T::typeName;
495 Info<< "Looking for " << T::typeName << " named " << name
496 << " or registered as " << regName << " with mesh "
497 << "Caching:" << cacheSets()
498 << " Found:" << (mesh.foundObject<T>(name))
499 << " Found registered:" << mesh.foundObject<T>(regName)
504 origin = SetOrigin::INVALID;
512 !mesh.thisDb().foundObject<T>(regName)
513 && !mesh.thisDb().foundObject<T>(name)
519 Info<< "Constructing new " << T::typeName << ' ' << name << nl;
523 Pout<< mesh.thisDb().names();
527 origin = SetOrigin::FILE;
528 setPtr.reset(new T(mesh, name, IOobject::MUST_READ));
534 Info<< "Registering a copy of " << name << " with mesh" << nl;
537 autoPtr<T> toCache(new T(mesh, regName, *setPtr));
538 toCache->store(toCache);
543 const T* ptr = mesh.thisDb().template cfindObject<T>(name);
549 Info<< "Getting existing " << name << endl;
552 origin = SetOrigin::MEMORY;
553 setPtr.reset(new T(mesh, name, *ptr));
559 Info<< "Getting existing " << regName << endl;
562 origin = SetOrigin::CACHE;
563 setPtr.reset(new T(mesh, name, mesh.lookupObject<T>(regName)));
573 bool Foam::expressions::fvExprDriver::updateSet
580 const label oldSize = setPtr->size();
582 bool updated = false;
583 const auto& mesh = dynamicCast<const polyMesh>(setPtr->db());
587 Info<< "UpdateSet: " << setPtr->name() << " Id: " << name
588 << " Origin: " << int(origin) << endl;
593 case SetOrigin::FILE:
598 mesh.time().timeName(),
599 polyMesh::meshSubDir/"sets",
605 if (header.typeHeaderOk<T>())
609 Pout<< "Rereading from "
610 << header.localFilePath(T::typeName) << endl;
612 setPtr.reset(new T(header));
619 case SetOrigin::MEMORY:
620 case SetOrigin::CACHE:
622 if (origin == SetOrigin::NEW)
625 << "State NEW shouldn't exist
"
631 const T* ptr = mesh.thisDb().template cfindObject<T>(name);
637 Info<< "Found
" << name
638 << " and rereading it
" << endl;
641 setPtr.reset(new T(mesh, name, *ptr));
646 << name << " Not
found" << endl
647 << "In registry:
" << mesh.thisDb().names() << endl
657 << T::typeName << ' ' << name << " is invalid
" << endl
666 Info<< "Origin
" << int(origin) << " not implemented
" << endl;
674 Pout<< name << " old size
" << oldSize << " new:
"
675 << setPtr->size() << endl;
682 // ************************************************************************* //
int debug
Static debugging option.
A class for handling words, derived from Foam::string.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
A class for managing temporary objects.
Type gAverage(const FieldField< Field, Type > &f)
bool foundField(const word &name) const
Test if specified field can be found in memory or disk.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const word & headerClassName() const noexcept
Return name of the class name read from header.
bool isGlobalVariable(const word &name, const bool wantPointData=false, const label expectedSize=-1) const
Test existence of a global variable.
bool valid() const noexcept
Identical to good(), or bool operator.
A polymorphic field/result from evaluating an expression.
Generic templated field type.
tmp< Field< Type > > getVariable(const word &name, const label expectSize, const bool mandatory=true) const
Retrieve local/global variable as a tmp field.
messageStream Info
Information stream (stdout output on master, null elsewhere)
reduce(hasMovingMesh, orOp< bool >())
errorManipArg< error, int > exit(error &err, const int errNo=1)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define DebugInfo
Report an information message using Foam::Info.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
#define WarningInFunction
Report a warning using Foam::Warning.
bool isField(const word &name, const bool wantPointData=false, const label expectSize=-1) const
Test for the existence of a mesh field.
A class for managing references or pointers (no reference counting)