Go to the documentation of this file.
44 <<
"Looking for global" << (isPointVal ?
" point" :
"")
45 <<
" field name:" <<
name;
50 <<
" - found (" << result.valueType() <<
' ' << result.isPointValue() <<
')';
53 bool good = (result.isType<Type>() && result.isPointValue(isPointVal));
56 if (good && expectedSize >= 0)
58 good = (result.size() == expectedSize);
84 bool isSingleValue =
false;
86 if (hasVariable(
name) && variable(
name).isType<Type>())
88 isSingleValue = variable(
name).isUniform();
89 tresult = variable(
name).
cref<Type>().clone();
91 else if (isGlobalVariable<Type>(
name,
false))
97 tresult = var.
cref<Type>().clone();
114 <<
"Variable " <<
name
115 <<
" is not a single value and does not fit the size "
116 << expectedSize <<
". Using average" <<
endl;
125 <<
"Variable (" <<
name <<
") not found." <<
nl
141 Info<<
"fvExprDriver::foundField. Name: " <<
name
142 <<
" Type: " << Type::typeName
143 <<
" registry:" << searchInMemory()
144 <<
" disk:" << searchFiles() <<
endl;
149 if (searchInMemory())
154 if (this->
mesh().foundObject<Type>(
name))
171 Info<<
", not type:" << Type::typeName <<
nl;
176 if (searchFiles() && getTypeOfField(
name) == Type::typeName)
206 Info<<
"fvExprDriver::isField <" << name << '>
' << endl;
209 typedef GeometricField<Type, fvPatchField, volMesh> vfieldType;
210 typedef GeometricField<Type, fvsPatchField, surfaceMesh> sfieldType;
211 typedef GeometricField<Type, pointPatchField, pointMesh> pfieldType;
216 ? this->foundField<pfieldType>(name)
219 this->foundField<vfieldType>(name)
220 || this->foundField<sfieldType>(name)
226 template<class GeomField, class Mesh>
227 Foam::tmp<GeomField> Foam::expressions::fvExprDriver::getOrReadFieldImpl
235 typedef typename GeomField::value_type Type;
239 Info<< "fvExprDriver::getOrReadField <" << name
240 << "> Type: " << GeomField::typeName << endl;
243 tmp<GeomField> tfield;
247 (hasVariable(name) && variable(name).isType<Type>())
248 || isGlobalVariable<Type>(name, false)
253 Info<< "Getting " << name << " from variables" << endl;
258 Info<< "Creating field " << name << " of type "
259 << GeomField::typeName << nl;
264 GeomField::New(name, meshRef, dimensioned<Type>(Zero))
267 GeomField& fld = tfield.ref();
271 Info<< "New field: " << name << " ownedByRegistry"
272 << fld.ownedByRegistry() << endl;
277 if (hasVariable(name) && variable(name).isType<Type>())
279 vals = variable(name).cref<Type>();
283 vals = lookupGlobal(name).cref<Type>();
288 Pout<< "sizes: " << vals.size() << ' ' << fld.size() << endl;
291 if (returnReduce((vals.size() == fld.size()), andOp<bool>()))
293 fld.primitiveFieldRef() = vals;
297 Type avg = gAverage(vals);
303 MinMax<Type> range = gMinMax(vals);
305 if (range.mag() > SMALL)
308 << "The min/max ranges differ " << range
309 << " - using average " << avg << nl;
313 fld.primitiveFieldRef() = avg;
322 const objectRegistry& obr = meshRef.thisDb();
324 if (searchInMemory() && obr.foundObject<GeomField>(name))
328 Info<< "Retrieve registered: " << name << nl;
331 const GeomField& origFld = obr.lookupObject<GeomField>(name);
333 // Avoid shadowing the original object
337 GeomField::New(name + "_exprDriverCopy", origFld)
344 Info<< "Getting oldTime of " << name << " has "
345 << origFld.nOldTimes() << endl;
348 if (!origFld.nOldTimes() && this->prevIterIsOldTime())
352 Info<< "No oldTime, using previous iteration" << endl;
354 tfield.ref().oldTime() = origFld.prevIter();
358 else if (searchFiles() && getTypeOfField(name) == GeomField::typeName)
362 Info<< "Reading " << name << " from disc" << endl;
367 this->readAndRegister<GeomField>(name, meshRef)
369 // oldTime automatically read
374 Info<< "field: valid()=" << tfield.valid() << endl;
379 GeomField& fld = tfield.ref();
383 Info<< "Valid " << name << " found. Removing dimensions" << nl;
386 fld.dimensions().clear();
392 Info<< "Removing dimensions of oldTime of " << name
393 << " has " << fld.nOldTimes() << nl;
396 // Switch dimension checking off
397 const int oldDebug = dimensionSet::debug;
398 dimensionSet::debug = 0;
400 // go through ALL old times
401 GeomField* fp = &(fld);
403 while (fp->nOldTimes())
405 fp = &(fp->oldTime());
406 fp->dimensions().clear();
409 // Restore old value of dimension checking
410 dimensionSet::debug = oldDebug;
416 << "Could not find field " << name
417 << " in registry or on file-system" << nl
426 Foam::autoPtr<T> Foam::expressions::fvExprDriver::getTopoSet
433 // Avoid possible name clashes
434 const word regName = name + "RegisteredNameFor" + T::typeName;
438 Info<< "Looking for " << T::typeName << " named " << name;
440 Info<< " or registered as " << regName << " with mesh "
441 << "Caching:" << cacheSets()
442 << " Found:" << (mesh.foundObject<T>(name))
443 << " Found registered:" << mesh.foundObject<T>(regName)
448 origin = SetOrigin::INVALID;
456 !mesh.thisDb().foundObject<T>(regName)
457 && !mesh.thisDb().foundObject<T>(name)
463 Info<< "Constructing new " << T::typeName << ' ' << name << nl;
467 Pout<< mesh.thisDb().names();
471 origin = SetOrigin::FILE;
472 setPtr.reset(new T(mesh, name, IOobject::MUST_READ));
478 Info<< "Registering a copy of " << name << " with mesh" << nl;
481 autoPtr<T> toCache(new T(mesh, regName, *setPtr));
482 toCache->store(toCache);
487 const T* ptr = mesh.thisDb().findObject<T>(name);
493 Info<< "Getting existing " << name << endl;
496 origin = SetOrigin::MEMORY;
497 setPtr.reset(new T(mesh, name, *ptr));
503 Info<< "Getting existing " << regName << endl;
506 origin = SetOrigin::CACHE;
507 setPtr.reset(new T(mesh, name, mesh.lookupObject<T>(regName)));
517 bool Foam::expressions::fvExprDriver::updateSet
524 const label oldSize = setPtr->size();
526 bool updated = false;
527 const polyMesh& mesh = dynamic_cast<const polyMesh&>(setPtr->db());
531 Info<< "UpdateSet: " << setPtr->name() << " Id: " << name
532 << " Origin: " << int(origin) << endl;
537 case SetOrigin::FILE:
542 mesh.time().timeName(),
543 polyMesh::meshSubDir/"sets",
549 if (header.typeHeaderOk<T>())
553 Pout<< "Rereading from "
554 << header.localFilePath(T::typeName) << endl;
556 setPtr.reset(new T(header));
563 case SetOrigin::MEMORY:
564 case SetOrigin::CACHE:
566 if (origin == SetOrigin::NEW)
569 << "State NEW shouldn't exist
"
575 const T* ptr = mesh.thisDb().findObject<T>(name);
581 Info<< "Found
" << name
582 << " and rereading it
" << endl;
585 setPtr.reset(new T(mesh, name, *ptr));
590 << name << " Not
found" << endl
591 << "In registry:
" << mesh.thisDb().names() << endl
601 << T::typeName << ' ' << name << " is invalid
" << endl
610 Info<< "Origin
" << int(origin) << " not implemented
" << endl;
618 Pout<< name << " old size
" << oldSize << " new:
"
619 << setPtr->size() << endl;
626 // ************************************************************************* //
int debug
Static debugging option.
tmp< Field< Type > > getVariable(const word &name, label expectSize, const bool mandatory=true) const
Retrieve local/global variable as a tmp field.
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, bool isPointVal, label expectedSize=-1) const
Test existence of a global variable.
A polymorphic field/result from evaluating an expression.
messageStream Info
Information stream (uses stdout - output is on the master only)
word name(const complex &c)
Return string representation of complex.
bool isUniform() const
True if single, uniform value.
reduce(hasMovingMesh, orOp< bool >())
const Field< Type > & cref() const
Return const reference to the field.
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.
bool isField(const word &name, bool isPointVal=false, label expectSize=-1) const
Test for the existence of a mesh field.
bool valid() const noexcept
#define WarningInFunction
Report a warning using Foam::Warning.