60 bool 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)
128 bool 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);
196 this->operator=(rhs);
204 this->operator=(std::move(rhs));
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())
271 <<
"No entry 'value' defined for data type " <<
valueType() <<
nl 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_)
381 void 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)
469 <<
"Type " << valueType() <<
" was not handled" <<
nl <<
endl;
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_)
504 <<
"Type " << valueType() <<
" could not be copied" <<
nl 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;
668 Foam::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 " 703 Foam::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,
797 expressions::exprResult result(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 bool hasValue() const
Has a value?
void writeValue(Ostream &os) const
Write the single value, or the first value from field.
defineTypeNameAndDebug(fvExprDriver, 0)
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...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A polymorphic field/result from evaluating an expression.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
static const Enum< streamFormat > formatNames
Stream format names (ascii, binary)
void clear()
Clear (zero) the result.
defineRunTimeSelectionTable(fvExprDriver, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
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 word & valueType() const noexcept
Basic type for the field or single value.
virtual ~exprResult()
Destructor.
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.
bool set(const Type &val)
Assign from type. Returns false and sets to 'none' for unsupported types.
Macros for easy insertion into run-time selection tables.
const void * dataAddress() const
The address of the field data content.
static autoPtr< exprResult > New(const dictionary &dict)
Return a reference to the selected value driver.
void writeField(Ostream &os, const word &keyword="") const
Write the field, optionally as an entry.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
A class for handling words, derived from Foam::string.
#define DebugInFunction
Report an information message using Foam::Info.
exprResult getUniform(const label size, const bool noWarn, const bool parRun=UPstream::parRun()) const
Construct a uniform field from the current results.
exprResult()
Default construct.
#define defineExpressionMethod(Type)
#define DebugInfo
Report an information message using Foam::Info.
void testIfSingleValue(const bool parRun=UPstream::parRun())
Test if field corresponds to a single-value and thus uniform.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
addToRunTimeSelectionTable(exprResult, exprResult, dictionary)
#define WarningInFunction
Report a warning using Foam::Warning.
bool reset(bool force=false)
Reset at new timestep according to type.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
virtual void operator=(const exprResult &rhs)
Copy assignment.
static const exprResult null
An empty result.
void writeEntry(const word &keyword, Ostream &os) const
Forwarding to Field::writeEntry.
void clear()
Reset to 'none'.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
void writeDict(Ostream &os, const bool subDict=true) const
Write entry as dictionary contents.
Tensor of scalars, i.e. Tensor<scalar>.
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
virtual void resetImpl()
Reset at new timestep according to the derived class type.
void reduce(T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) using linear/tree communication schedule.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...