40 const bool wantPointData,
41 const label expectedSize
45 <<
"Looking for global" << (wantPointData ?
" point" :
"")
46 <<
" field name:" <<
name;
59 if (good && expectedSize >= 0)
80 const label expectedSize,
86 if (hasVariable(
name) && variable(
name).isType<Type>())
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)
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:";
197 << Type::typeName <<
nl;
203 if (searchFiles() && getTypeOfField(
name) == Type::typeName)
230 Info<<
"fvExprDriver::isField <" << name << '>
' << endl; 236 ? this->foundField<PointField<Type>>(name) 239 this->foundField<VolumeField<Type>>(name) 240 || this->foundField<SurfaceField<Type>>(name) 246 template<class GeomField, class Mesh> 247 Foam::tmp<GeomField> Foam::expressions::fvExprDriver::getOrReadFieldImpl 255 typedef typename GeomField::value_type Type; 257 tmp<GeomField> tfield; 261 Info<< "fvExprDriver::getOrReadField <" << name 262 << "> Type: " << GeomField::typeName << endl; 269 refPtr<expressions::exprResult> tvar; 271 if (hasVariable(name) && variable(name).isType<Type>()) 273 tvar.cref(variable(name)); 275 else if (isGlobalVariable<Type>(name)) 277 tvar.cref(lookupGlobal(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), 302 // Patch is zeroGradient (volFields) or calculated (other) 303 defaultBoundaryType(GeomField::null()) 305 auto& fld = tfield.ref(); 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; 320 if (returnReduceAnd(vals.size() == fld.size())) 322 fld.primitiveFieldRef() = vals; 326 const Type avg = gAverage(vals); 332 MinMax<Type> range = gMinMax(vals); 334 if (range.mag() > SMALL) 337 << "The min/max ranges differ " << range 338 << " - using average " << avg << nl; 342 fld.primitiveFieldRef() = avg; 351 // Find context or registered field 352 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 354 const GeomField* origFldPtr = nullptr; 356 for (int checki = 0; !origFldPtr && checki < 2; ++checki) 358 // Check 0: object context (first) 359 // Check 1: regular objectRegistry 363 origFldPtr = exprDriver::cfindContextObject<GeomField>(name); 365 else if (searchRegistry()) 368 meshRef.thisDb().template cfindObject<GeomField>(name); 374 // Found from context or registry 378 Info<< "Retrieve context/registered:" << name << nl; 381 const GeomField& origFld = *origFldPtr; 383 // Make a deep copy of the data to return. Avoids shadowing 384 // the original object, but most importantly the backend 385 // parser (eg, lemon) will be working with combining via plain 386 // pointers. We thus lose any of the tmp<> shallow copy semantics 387 // anyhow. Additionally, need to disable dimension checking here or 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) 414 Info<< "Reading " << name << " from disc" << endl; 419 this->readAndRegister<GeomField>(name, meshRef) 421 // oldTime automatically read 427 Info<< "field: valid()=" << Switch::name(tfield.valid()) << endl; 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; 449 // Switch dimension checking off 450 const bool oldDimChecking = dimensionSet::checking(false); 452 // go through ALL old times 453 GeomField* fp = &(fld); 455 while (fp->nOldTimes()) 457 fp = &(fp->oldTime()); 458 fp->dimensions().clear(); 461 // Restore old value of dimension checking 462 dimensionSet::checking(oldDimChecking); 468 << "Could not find field " << name 469 << " in registry or on file-system" << nl 478 Foam::autoPtr<T> Foam::expressions::fvExprDriver::getTopoSet 485 // Avoid possible name clashes 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) 508 && !mesh.thisDb().foundObject<T>(name) 514 Info<< "Constructing new " << T::typeName << ' ' << name << nl; 518 Pout<< mesh.thisDb().names(); 522 origin = SetOrigin::FILE; 523 setPtr.reset(new T(mesh, name, IOobject::MUST_READ)); 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); 544 Info<< "Getting existing " << name << endl; 547 origin = SetOrigin::MEMORY; 548 setPtr.reset(new T(mesh, name, *ptr)); 554 Info<< "Getting existing " << regName << endl; 557 origin = SetOrigin::CACHE; 558 setPtr.reset(new T(mesh, name, mesh.lookupObject<T>(regName))); 568 bool Foam::expressions::fvExprDriver::updateSet 575 const label oldSize = setPtr->size(); 577 bool updated = false; 578 const auto& mesh = refCast<const polyMesh>(setPtr->db()); 582 Info<< "UpdateSet: " << setPtr->name() << " Id: " << name 583 << " Origin: " << int(origin) << endl; 588 case SetOrigin::FILE: 593 mesh.time().timeName(), 594 polyMesh::meshSubDir/"sets", 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); 632 Info<< "Found
" << name 633 << " and rereading it
" << endl; 636 setPtr.reset(new T(mesh, name, *ptr)); 641 << name << " Not
found" << 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; 677 // ************************************************************************* // errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A polymorphic field/result from evaluating an expression.
constexpr char nl
The newline '\n' character (0x0a)
bool isType() const
True if valueType corresponds to the given Type.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool isField(const word &name, const bool wantPointData=false, const label expectSize=-1) const
Test for the existence of a mesh field.
bool valid() const noexcept
Identical to good(), or bool operator.
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.
const regIOobject * cfindContextIOobject(const word &name) const
Find named context field, if it exists.
const word & valueType() const noexcept
Basic type for the field or single value.
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
A class for managing references or pointers (no reference counting)
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
A class for handling words, derived from Foam::string.
bool isGlobalVariable(const word &name, const bool wantPointData=false, const label expectedSize=-1) const
Test existence of a global variable.
const exprResult & result() const noexcept
Const access to expression result.
tmp< Field< Type > > getVariable(const word &name, const label expectSize, const bool mandatory=true) const
Retrieve local/global variable as a tmp field.
#define DebugInfo
Report an information message using Foam::Info.
int debug
Static debugging option.
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...
const word & headerClassName() const noexcept
Return name of the class name read from header.
label size() const
The field or object size.
#define WarningInFunction
Report a warning using Foam::Warning.
Type gAverage(const FieldField< Field, Type > &f)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
messageStream Info
Information stream (stdout output on master, null elsewhere)
const exprResult & lookupGlobal(const word &name) const
Return the global variable if available or a null result.
bool isPointData(const bool wantPointData=true) const
True if representing point data, or test for same value as wantPointData argument.
A class for managing temporary objects.
bool foundField(const word &name) const
Test if specified field can be found in memory or disk.