60bool Foam::expressions::exprResult::setAverageValueCheckedBool
72 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
73 label len =
fld.size();
78 for (
const Type val :
fld)
88 reduce(nTrue, sumOp<label>());
100 reduce(len, sumOp<label>());
113 else if (nTrue*10 >= len*9)
128bool Foam::expressions::exprResult::getUniformCheckedBool
145 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
146 label len =
fld.size();
151 for (
const Type val :
fld)
161 reduce(nTrue, sumOp<label>());
162 reduce(len, sumOp<label>());
165 const Type avg = (nTrue > len/2);
172 result.setResult<Type>(avg, size);
211 bool singleValueOnly,
217 dict.readIfPresent(
"valueType", valType_);
218 dict.readIfPresent(
"isPointValue", isPointData_);
219 dict.readIfPresent(
"noReset", noReset_);
220 dict.readIfPresent(
"isSingleValue", singleValueOnly);
233 ?
dict.getOrDefault<label>(
"fieldSize", 1)
234 :
dict.get<label>(
"fieldSize")
240 readChecked<scalar>(valueEntry, len, singleValueOnly)
241 || readChecked<vector>(valueEntry, len, singleValueOnly)
242 || readChecked<tensor>(valueEntry, len, singleValueOnly)
243 || readChecked<symmTensor>(valueEntry, len, singleValueOnly)
244 || readChecked<sphericalTensor>(valueEntry, len, singleValueOnly)
245 || readChecked<bool>(valueEntry, len, singleValueOnly)
250 if (valType_.empty())
257 <<
"Do not know how to read data type " <<
valueType()
258 << (singleValueOnly ?
" as a single value." :
".") <<
nl
264 if (valType_.empty())
283 const word resultType
285 dict.getOrDefault<
word>(
"resultType",
"exprResult")
288 if (
dict.getOrDefault(
"unsetValue",
false))
290 auto* ctorPtr = emptyConstructorTable(resultType);
299 *emptyConstructorTablePtr_
304 <<
"Creating unset result of type " << resultType <<
nl;
306 return autoPtr<exprResult>(ctorPtr());
310 auto* ctorPtr = dictionaryConstructorTable(resultType);
319 *dictionaryConstructorTablePtr_
324 <<
"Creating result of type " << resultType <<
nl;
361 if (force || !noReset_ || needsReset_)
381void Foam::expressions::exprResult::destroy()
387 deleteChecked<scalar>()
388 || deleteChecked<vector>()
389 || deleteChecked<tensor>()
390 || deleteChecked<symmTensor>()
391 || deleteChecked<sphericalTensor>()
392 || deleteChecked<bool>()
398 <<
"Unknown type " << valueType()
399 <<
" probable memory loss" <<
nl
417 if (fieldPtr_ ==
nullptr)
420 <<
"Not set. Cannot construct uniform value" <<
nl
428 getUniformChecked<scalar>(ret, size, noWarn, parRun)
429 || getUniformChecked<vector>(ret, size, noWarn, parRun)
430 || getUniformChecked<tensor>(ret, size, noWarn, parRun)
431 || getUniformChecked<symmTensor>(ret, size, noWarn, parRun)
432 || getUniformChecked<sphericalTensor>(ret, size, noWarn, parRun)
438 <<
"Cannot get uniform value for type "
449 if (fieldPtr_ ==
nullptr)
452 <<
"Not set - cannot determine if uniform" <<
nl <<
endl;
458 setAverageValueChecked<scalar>(parRun)
459 || setAverageValueChecked<vector>(parRun)
460 || setAverageValueChecked<tensor>(parRun)
461 || setAverageValueChecked<symmTensor>(parRun)
462 || setAverageValueChecked<sphericalTensor>(parRun)
463 || setAverageValueCheckedBool(parRun)
485 valType_ =
rhs.valType_;
486 isPointData_ =
rhs.isPointData_;
493 duplicateFieldChecked<scalar>(
rhs.fieldPtr_)
494 || duplicateFieldChecked<vector>(
rhs.fieldPtr_)
495 || duplicateFieldChecked<tensor>(
rhs.fieldPtr_)
496 || duplicateFieldChecked<symmTensor>(
rhs.fieldPtr_)
497 || duplicateFieldChecked<sphericalTensor>(
rhs.fieldPtr_)
498 || duplicateFieldChecked<bool>(
rhs.fieldPtr_)
520 valType_ =
rhs.valType_;
521 isPointData_ =
rhs.isPointData_;
522 noReset_ =
rhs.noReset_;
523 needsReset_ =
rhs.needsReset_;
527 fieldPtr_ =
rhs.fieldPtr_;
529 rhs.fieldPtr_ =
nullptr;
542 writeEntryChecked<scalar>(keyword,
os)
543 || writeEntryChecked<vector>(keyword,
os)
544 || writeEntryChecked<tensor>(keyword,
os)
545 || writeEntryChecked<symmTensor>(keyword,
os)
546 || writeEntryChecked<sphericalTensor>(keyword,
os)
547 || writeEntryChecked<bool>(keyword,
os)
553 <<
"Data type " <<
valueType() <<
" was not written" <<
endl;
576 os.writeEntry(
"resultType", valueType());
577 os.writeEntryIfDifferent<Switch>(
"noReset",
false, noReset_);
579 if (fieldPtr_ ==
nullptr)
581 os.writeEntry<Switch>(
"unsetValue",
true);
585 os.writeEntry(
"valueType", valueType());
587 os.writeEntryIfDifferent<Switch>(
"isPointValue",
false, isPointData_);
588 os.writeEntry<Switch>(
"isSingleValue", value_.good());
617 writeFieldChecked<scalar>(keyword,
os)
618 || writeFieldChecked<vector>(keyword,
os)
619 || writeFieldChecked<tensor>(keyword,
os)
620 || writeFieldChecked<symmTensor>(keyword,
os)
621 || writeFieldChecked<sphericalTensor>(keyword,
os)
622 || writeFieldChecked<label>(keyword,
os)
623 || writeFieldChecked<bool>(keyword,
os)
629 <<
"Data type " <<
valueType() <<
" was not written" <<
endl;
648 writeSingleValueChecked<scalar>(
os)
649 || writeSingleValueChecked<vector>(
os)
650 || writeSingleValueChecked<tensor>(
os)
651 || writeSingleValueChecked<symmTensor>(
os)
652 || writeSingleValueChecked<sphericalTensor>(
os)
653 || writeSingleValueChecked<label>(
os)
654 || writeSingleValueChecked<bool>(
os)
660 <<
"Data type " << valueType() <<
" was not written" <<
endl;
668Foam::expressions::exprResult::operator*=
676 <<
"Can not multiply. Unallocated field of type "
683 multiplyEqChecked<scalar>(
b)
684 || multiplyEqChecked<vector>(
b)
685 || multiplyEqChecked<tensor>(
b)
686 || multiplyEqChecked<symmTensor>(
b)
687 || multiplyEqChecked<sphericalTensor>(
b)
693 <<
"Can not multiply field of type "
703Foam::expressions::exprResult::operator+=
711 <<
"Can not add. Unallocated field of type "
716 if (this->size() !=
b.size())
719 <<
"Different sizes " << this->size() <<
" and " <<
b.size() <<
nl
723 if (this->valueType() !=
b.valueType())
726 <<
"Different types: "
727 << this->valueType() <<
" and " <<
b.valueType() <<
nl
733 plusEqChecked<scalar>(
b)
734 || plusEqChecked<vector>(
b)
735 || plusEqChecked<tensor>(
b)
736 || plusEqChecked<symmTensor>(
b)
737 || plusEqChecked<sphericalTensor>(
b)
743 <<
"Can not add Field-type exprResult of type "
757 expressions::exprResult& data
771 const expressions::exprResult& data
783 const expressions::exprResult&
b
793 const expressions::exprResult& a,
806 const expressions::exprResult& a,
807 const expressions::exprResult&
b
819 #undef defineExpressionMethod
820 #define defineExpressionMethod(Type) \
821 if (isType<Type>()) \
823 return static_cast<Field<Type>*>(fieldPtr_)->cdata(); \
832 #undef defineExpressionMethod
835 <<
"Unsupported type:" << valueType() <<
nl
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
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))
static const Enum< streamFormat > formatNames
Stream format names (ascii, binary).
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
A polymorphic field/result from evaluating an expression.
const word & valueType() const noexcept
Basic type for the field or single value.
void testIfSingleValue(const bool parRun=UPstream::parRun())
Test if field corresponds to a single-value and thus uniform.
void writeDict(Ostream &os, const bool subDict=true) const
Write entry as dictionary contents.
static const exprResult null
An empty result.
virtual void resetImpl()
Reset at new timestep according to the derived class type.
label size() const
The field or object size.
bool isType() const
True if valueType corresponds to the given Type.
exprResult getUniform(const label size, const bool noWarn, const bool parRun=UPstream::parRun()) const
Construct a uniform field from the current results.
void writeValue(Ostream &os) const
Write the single value, or the first value from field.
void writeEntry(const word &keyword, Ostream &os) const
Forwarding to Field::writeEntry.
virtual void operator=(const exprResult &rhs)
Copy assignment.
exprResult()
Default construct.
static autoPtr< exprResult > New(const dictionary &dict)
Return a reference to the selected value driver.
void clear()
Clear (zero) the result.
virtual ~exprResult()
Destructor.
const void * dataAddress() const
The address of the field data content.
bool reset(bool force=false)
Reset at new timestep according to type.
bool hasValue() const
Has a value?
void writeField(Ostream &os, const word &keyword="") const
Write the field, optionally as an entry.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define defineExpressionMethod(Type)
OBJstream os(runTime.globalPath()/outputName)
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
bool writeField(ensightOutput::floatBufferType &scratch, ensightFile &os, const Field< Type > &fld, const ensightCells &part, bool parallel)
Write a field of cell values as an indirect list, using the cell ids from ensightCells.
A namespace for expression-related classes/traits etc.
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
bool isType(const U &obj)
Check if typeid of the object and Type are identical.
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.
errorManipArg< error, int > exit(error &err, const int errNo=1)
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
constexpr char nl
The newline '\n' character (0x0a).
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.