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>());
126 bool Foam::expressions::exprResult::getUniformCheckedBool
143 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
144 label len =
fld.size();
149 for (
const Type val :
fld)
159 reduce(nTrue, sumOp<label>());
160 reduce(len, sumOp<label>());
163 const Type avg = (nTrue > len/2);
170 result.setResult<Type>(avg, size);
178 Foam::expressions::exprResult::singleValue::singleValue()
180 std::memset(static_cast<void*>(
this),
'\0',
sizeof(*
this));
184 Foam::expressions::exprResult::singleValue::singleValue
186 const singleValue& val
189 std::memcpy(static_cast<void*>(
this), &val,
sizeof(*
this));
193 void Foam::expressions::exprResult::singleValue::operator=
195 const singleValue& val
201 std::memcpy(static_cast<void*>(
this), &val,
sizeof(*
this));
226 this->operator=(rhs);
234 this->operator=(std::move(rhs));
246 valType_(
dict.getOrDefault<
word>(
"valueType",
"")),
247 isUniform_(
dict.getOrDefault(
"isSingleValue",
uniform)),
248 isPointData_(
dict.getOrDefault(
"isPointValue", false)),
249 noReset_(
dict.getOrDefault(
"noReset", false)),
262 const bool uniform = isUniform_;
267 ?
dict.getOrDefault<label>(
"fieldSize", 1)
268 :
dict.get<label>(
"fieldSize")
274 readChecked<scalar>(valueEntry, len,
uniform)
275 || readChecked<vector>(valueEntry, len,
uniform)
276 || readChecked<tensor>(valueEntry, len,
uniform)
277 || readChecked<symmTensor>(valueEntry, len,
uniform)
278 || readChecked<sphericalTensor>(valueEntry, len,
uniform)
279 || readChecked<bool>(valueEntry, len,
uniform)
284 if (valType_.empty())
291 <<
"Do not know how to read data type " << valType_
292 << (
uniform ?
" as a single value." :
".") <<
nl 299 <<
"No entry 'value' defined" <<
nl 311 const word resultType
313 dict.getOrDefault<
word>(
"resultType",
"exprResult")
316 if (
dict.getOrDefault(
"unsetValue",
false))
318 auto* ctorPtr = emptyConstructorTable(resultType);
327 *emptyConstructorTablePtr_
332 <<
"Creating unset result of type " << resultType <<
nl;
334 return autoPtr<exprResult>(ctorPtr());
338 auto* ctorPtr = dictionaryConstructorTable(resultType);
347 *dictionaryConstructorTablePtr_
352 <<
"Creating result of type " << resultType <<
nl;
389 if (force || !noReset_ || needsReset_)
409 void Foam::expressions::exprResult::uglyDelete()
415 deleteChecked<scalar>()
416 || deleteChecked<vector>()
417 || deleteChecked<tensor>()
418 || deleteChecked<symmTensor>()
419 || deleteChecked<sphericalTensor>()
420 || deleteChecked<bool>()
426 <<
"Unknown type " << valType_
427 <<
" probable memory loss" <<
nl 445 if (fieldPtr_ ==
nullptr)
448 <<
"Not set. Cannot construct uniform value" <<
nl 456 getUniformChecked<scalar>(ret, size, noWarn, parRun)
457 || getUniformChecked<vector>(ret, size, noWarn, parRun)
458 || getUniformChecked<tensor>(ret, size, noWarn, parRun)
459 || getUniformChecked<symmTensor>(ret, size, noWarn, parRun)
460 || getUniformChecked<sphericalTensor>(ret, size, noWarn, parRun)
466 <<
"Cannot get uniform value for type " << valType_ <<
nl 476 if (fieldPtr_ ==
nullptr)
479 <<
"Not set - cannot determine if uniform" <<
nl <<
endl;
485 setAverageValueChecked<scalar>(parRun)
486 || setAverageValueChecked<vector>(parRun)
487 || setAverageValueChecked<tensor>(parRun)
488 || setAverageValueChecked<symmTensor>(parRun)
489 || setAverageValueChecked<sphericalTensor>(parRun)
490 || setAverageValueCheckedBool(parRun)
496 <<
"Unknown type " << valType_ <<
nl <<
endl;
512 valType_ = rhs.valType_;
513 isUniform_ = rhs.isUniform_;
514 isPointData_ = rhs.isPointData_;
515 single_ = rhs.single_;
521 duplicateFieldChecked<scalar>(rhs.fieldPtr_)
522 || duplicateFieldChecked<vector>(rhs.fieldPtr_)
523 || duplicateFieldChecked<tensor>(rhs.fieldPtr_)
524 || duplicateFieldChecked<symmTensor>(rhs.fieldPtr_)
525 || duplicateFieldChecked<sphericalTensor>(rhs.fieldPtr_)
526 || duplicateFieldChecked<bool>(rhs.fieldPtr_)
532 <<
" Type " << valType_ <<
" can not be copied" <<
nl 548 valType_ = rhs.valType_;
549 isUniform_ = rhs.isUniform_;
550 isPointData_ = rhs.isPointData_;
551 noReset_ = rhs.noReset_;
552 needsReset_ = rhs.needsReset_;
555 single_ = rhs.single_;
556 fieldPtr_ = rhs.fieldPtr_;
558 rhs.fieldPtr_ =
nullptr;
571 writeEntryChecked<scalar>(keyword,
os)
572 || writeEntryChecked<vector>(keyword,
os)
573 || writeEntryChecked<tensor>(keyword,
os)
574 || writeEntryChecked<symmTensor>(keyword,
os)
575 || writeEntryChecked<sphericalTensor>(keyword,
os)
576 || writeEntryChecked<bool>(keyword,
os)
582 <<
"Unknown data type " << valType_ <<
endl;
605 os.writeEntry(
"resultType", valueType());
606 os.writeEntryIfDifferent<Switch>(
"noReset",
false, noReset_);
608 if (fieldPtr_ ==
nullptr)
610 os.writeEntry<Switch>(
"unsetValue",
true);
614 os.writeEntry(
"valueType", valType_);
616 os.writeEntryIfDifferent<Switch>(
"isPointValue",
false, isPointData_);
617 os.writeEntry<Switch>(
"isSingleValue", isUniform_);
646 writeFieldChecked<scalar>(keyword,
os)
647 || writeFieldChecked<vector>(keyword,
os)
648 || writeFieldChecked<tensor>(keyword,
os)
649 || writeFieldChecked<symmTensor>(keyword,
os)
650 || writeFieldChecked<sphericalTensor>(keyword,
os)
651 || writeFieldChecked<label>(keyword,
os)
652 || writeFieldChecked<bool>(keyword,
os)
658 <<
"Unknown data type " << valType_ <<
endl;
677 writeSingleValueChecked<scalar>(
os)
678 || writeSingleValueChecked<vector>(
os)
679 || writeSingleValueChecked<tensor>(
os)
680 || writeSingleValueChecked<symmTensor>(
os)
681 || writeSingleValueChecked<sphericalTensor>(
os)
682 || writeSingleValueChecked<label>(
os)
683 || writeSingleValueChecked<bool>(
os)
689 <<
"Unknown data type " << valType_ <<
endl;
697 Foam::expressions::exprResult::operator*=
705 <<
"Can not multiply. Unallocated field of type" << valType_ <<
nl 711 multiplyEqChecked<scalar>(
b)
712 || multiplyEqChecked<vector>(
b)
713 || multiplyEqChecked<tensor>(
b)
714 || multiplyEqChecked<symmTensor>(
b)
715 || multiplyEqChecked<sphericalTensor>(
b)
721 <<
"Can not multiply field of type " 731 Foam::expressions::exprResult::operator+=
739 <<
"Can not add. Unallocated field of type " << valType_ <<
nl 743 if (this->size() !=
b.size())
746 <<
"Different sizes " << this->size() <<
" and " <<
b.size() <<
nl 752 plusEqChecked<scalar>(
b)
753 || plusEqChecked<vector>(
b)
754 || plusEqChecked<tensor>(
b)
755 || plusEqChecked<symmTensor>(
b)
756 || plusEqChecked<sphericalTensor>(
b)
762 <<
"Can not add Field-type exprResult of type" 776 expressions::exprResult& data
790 const expressions::exprResult& data
802 const expressions::exprResult&
b 812 const expressions::exprResult& a,
816 expressions::exprResult result(a);
825 const expressions::exprResult& a,
826 const expressions::exprResult&
b 838 #undef defineExpressionMethod 839 #define defineExpressionMethod(Type) \ 840 if (isType<Type>()) \ 842 return static_cast<Field<Type>*>(fieldPtr_)->cdata(); \ 851 #undef defineExpressionMethod 854 <<
"Unsupported type" << valType_ <<
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)
Reference counter for various OpenFOAM components.
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.
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.
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 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=Pstream::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=Pstream::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)
Database for solution data, solver performance and other reduced data.
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 reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
void writeEntry(const word &keyword, Ostream &os) const
Forwarding to Field::writeEntry.
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.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...