Go to the documentation of this file.
39 const bool wantPointData,
40 const label expectedSize
44 <<
"Looking for global" << (wantPointData ?
" point" :
"")
45 <<
" field name:" <<
name;
50 <<
" - found (" << result.valueType() <<
' '
51 << result.isPointData() <<
')';
55 (result.isType<Type>() && result.isPointData(wantPointData));
58 if (good && expectedSize >= 0)
60 good = (result.size() == expectedSize);
80 const label expectedSize,
86 if (hasVariable(
name) && variable(
name).isType<Type>())
90 else if (isGlobalVariable<Type>(
name))
98 const auto& var = tvar.
cref();
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:" << searchInMemory()
145 <<
" disk:" << searchFiles() <<
endl;
150 if (searchInMemory())
155 if (this->
mesh().foundObject<Type>(
name))
172 Info<<
", not type:" << Type::typeName <<
nl;
177 if (searchFiles() && getTypeOfField(
name) == Type::typeName)
207 Info<<
"fvExprDriver::isField <" << name << '>
' << endl;
210 typedef GeometricField<Type, fvPatchField, volMesh> vfieldType;
211 typedef GeometricField<Type, fvsPatchField, surfaceMesh> sfieldType;
212 typedef GeometricField<Type, pointPatchField, pointMesh> pfieldType;
217 ? this->foundField<pfieldType>(name)
220 this->foundField<vfieldType>(name)
221 || this->foundField<sfieldType>(name)
227 template<class GeomField, class Mesh>
228 Foam::tmp<GeomField> Foam::expressions::fvExprDriver::getOrReadFieldImpl
236 typedef typename GeomField::value_type Type;
240 Info<< "fvExprDriver::getOrReadField <" << name
241 << "> Type: " << GeomField::typeName << endl;
244 refPtr<expressions::exprResult> tvar;
246 if (hasVariable(name) && variable(name).isType<Type>())
248 tvar.cref(variable(name));
250 else if (isGlobalVariable<Type>(name))
252 tvar.cref(lookupGlobal(name));
256 tmp<GeomField> tfield;
260 const auto& var = tvar.cref();
261 const Type deflt(var.getValue<Type>());
265 Info<< "Getting " << name << " from variables. Default: "
271 Info<< "Creating field " << name << " of type "
272 << GeomField::typeName << nl;
275 tfield = GeomField::New
279 dimensioned<Type>(deflt),
280 // Patch is zeroGradient (volFields) or calculated (other)
281 defaultBoundaryType(GeomField::null())
283 auto& fld = tfield.ref();
287 Info<< "New field: " << name << " ownedByRegistry"
288 << fld.ownedByRegistry() << endl;
291 const Field<Type>& vals = var.cref<Type>();
295 Pout<< "sizes: " << vals.size() << ' ' << fld.size() << endl;
298 if (returnReduce((vals.size() == fld.size()), andOp<bool>()))
300 fld.primitiveFieldRef() = vals;
304 const Type avg = gAverage(vals);
310 MinMax<Type> range = gMinMax(vals);
312 if (range.mag() > SMALL)
315 << "The min/max ranges differ " << range
316 << " - using average " << avg << nl;
320 fld.primitiveFieldRef() = avg;
329 const objectRegistry& obr = meshRef.thisDb();
331 const GeomField* origFldPtr;
336 && (origFldPtr = obr.cfindObject<GeomField>(name)) != nullptr
341 Info<< "Retrieve registered: " << name << nl;
344 const GeomField& origFld = *origFldPtr;
346 // Avoid shadowing the original object
347 tfield = GeomField::New(name + "_exprDriverCopy", origFld);
353 Info<< "Getting oldTime of " << name << " has "
354 << origFld.nOldTimes() << endl;
357 if (!origFld.nOldTimes() && this->prevIterIsOldTime())
361 Info<< "No oldTime, using previous iteration" << endl;
363 tfield.ref().oldTime() = origFld.prevIter();
367 else if (searchFiles() && getTypeOfField(name) == GeomField::typeName)
371 Info<< "Reading " << name << " from disc" << endl;
376 this->readAndRegister<GeomField>(name, meshRef)
378 // oldTime automatically read
384 Info<< "field: valid()=" << Switch::name(tfield.valid()) << endl;
389 GeomField& fld = tfield.ref();
393 Info<< "Valid " << name << " found. Removing dimensions" << nl;
396 fld.dimensions().clear();
402 Info<< "Removing dimensions of oldTime of " << name
403 << " has " << fld.nOldTimes() << nl;
406 // Switch dimension checking off
407 const int oldDebug = dimensionSet::debug;
408 dimensionSet::debug = 0;
410 // go through ALL old times
411 GeomField* fp = &(fld);
413 while (fp->nOldTimes())
415 fp = &(fp->oldTime());
416 fp->dimensions().clear();
419 // Restore old value of dimension checking
420 dimensionSet::debug = oldDebug;
426 << "Could not find field " << name
427 << " in registry or on file-system" << nl
436 Foam::autoPtr<T> Foam::expressions::fvExprDriver::getTopoSet
443 // Avoid possible name clashes
444 const word regName = name + "RegisteredNameFor" + T::typeName;
448 Info<< "Looking for " << T::typeName << " named " << name;
450 Info<< " or registered as " << regName << " with mesh "
451 << "Caching:" << cacheSets()
452 << " Found:" << (mesh.foundObject<T>(name))
453 << " Found registered:" << mesh.foundObject<T>(regName)
458 origin = SetOrigin::INVALID;
466 !mesh.thisDb().foundObject<T>(regName)
467 && !mesh.thisDb().foundObject<T>(name)
473 Info<< "Constructing new " << T::typeName << ' ' << name << nl;
477 Pout<< mesh.thisDb().names();
481 origin = SetOrigin::FILE;
482 setPtr.reset(new T(mesh, name, IOobject::MUST_READ));
488 Info<< "Registering a copy of " << name << " with mesh" << nl;
491 autoPtr<T> toCache(new T(mesh, regName, *setPtr));
492 toCache->store(toCache);
497 const T* ptr = mesh.thisDb().findObject<T>(name);
503 Info<< "Getting existing " << name << endl;
506 origin = SetOrigin::MEMORY;
507 setPtr.reset(new T(mesh, name, *ptr));
513 Info<< "Getting existing " << regName << endl;
516 origin = SetOrigin::CACHE;
517 setPtr.reset(new T(mesh, name, mesh.lookupObject<T>(regName)));
527 bool Foam::expressions::fvExprDriver::updateSet
534 const label oldSize = setPtr->size();
536 bool updated = false;
537 const polyMesh& mesh = dynamic_cast<const polyMesh&>(setPtr->db());
541 Info<< "UpdateSet: " << setPtr->name() << " Id: " << name
542 << " Origin: " << int(origin) << endl;
547 case SetOrigin::FILE:
552 mesh.time().timeName(),
553 polyMesh::meshSubDir/"sets",
559 if (header.typeHeaderOk<T>())
563 Pout<< "Rereading from "
564 << header.localFilePath(T::typeName) << endl;
566 setPtr.reset(new T(header));
573 case SetOrigin::MEMORY:
574 case SetOrigin::CACHE:
576 if (origin == SetOrigin::NEW)
579 << "State NEW shouldn't exist
"
585 const T* ptr = mesh.thisDb().findObject<T>(name);
591 Info<< "Found
" << name
592 << " and rereading it
" << endl;
595 setPtr.reset(new T(mesh, name, *ptr));
600 << name << " Not
found" << endl
601 << "In registry:
" << mesh.thisDb().names() << endl
611 << T::typeName << ' ' << name << " is invalid
" << endl
620 Info<< "Origin
" << int(origin) << " not implemented
" << endl;
628 Pout<< name << " old size
" << oldSize << " new:
"
629 << setPtr->size() << endl;
636 // ************************************************************************* //
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.
bool isGlobalVariable(const word &name, const bool wantPointData=false, const label expectedSize=-1) const
Test existence of a global variable.
bool valid() const noexcept
True for non-null pointer/reference.
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 (uses stdout - output is on the master only)
word name(const complex &c)
Return string representation of complex.
reduce(hasMovingMesh, orOp< bool >())
errorManipArg< error, int > exit(error &err, const int errNo=1)
const word & headerClassName() const
Return name of the class name read from header.
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.
#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)