32 inline bool Foam::expressions::exprResult::deleteChecked()
34 const bool ok = isType<Type>();
36 if (ok && fieldPtr_ !=
nullptr)
38 delete static_cast<Field<Type>*
>(fieldPtr_);
48 inline bool Foam::expressions::exprResult::readChecked
52 const bool singleValueOnly
55 const bool ok = isType<Type>();
63 const Type val(
e.get<Type>());
66 fieldPtr_ =
new Field<Type>(size_, val);
73 fieldPtr_ =
new Field<Type>(
e, size_);
84 bool Foam::expressions::exprResult::getUniformChecked
99 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
107 if (limits.mag() > SMALL)
110 <<
"Different min/max values: " << limits
111 <<
" Using the average " << avg <<
nl;
115 result.setResult(avg, size);
122 bool Foam::expressions::exprResult::plusEqChecked
127 const bool ok = isType<Type>();
131 *
static_cast<Field<Type>*
>(fieldPtr_)
132 += *
static_cast<const Field<Type>*
>(
b.fieldPtr_);
140 bool Foam::expressions::exprResult::multiplyEqChecked
145 const bool ok = isType<Type>();
149 *
static_cast<Field<Type>*
>(fieldPtr_) *=
b;
194 return (!valType_.empty() && fieldPtr_ !=
nullptr);
207 const bool wantPointData
210 return isPointData_ == wantPointData;
216 return value_.good();
230 if (value_.good() && isType<Type>())
232 return value_.get<Type>();
274 target().setResultImpl(val, wantPointData);
287 target().setResultImpl(val, wantPointData);
292 void Foam::expressions::exprResult::setResultImpl
303 isPointData_ = wantPointData;
314 void Foam::expressions::exprResult::setResultImpl
325 isPointData_ = wantPointData;
328 valType_ = pTraits<Type>::typeName;
329 fieldPtr_ =
new Field<Type>(std::move(
fld));
342 target().setResultImpl(fldPtr, wantPointData);
347 void Foam::expressions::exprResult::setResultImpl
356 isPointData_ = wantPointData;
358 if (fldPtr !=
nullptr)
360 size_ = fldPtr->
size();
374 target().setResultImpl(val, size);
379 void Foam::expressions::exprResult::setResultImpl
390 isPointData_ =
false;
401 target().setSingleValueImpl(val);
406 bool Foam::expressions::exprResult::writeSingleValueChecked(
Ostream&
os)
const 413 if (this->size() <= 0)
417 os << value_.get<Type>();
422 os << pTraits<Type>::zero;
427 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
437 bool Foam::expressions::exprResult::writeFieldChecked
448 if (this->size() <= 0)
452 const Type& val = value_.get<Type>();
460 os.writeEntry(keyword, val);
468 os << pTraits<Type>::zero;
472 Field<Type>().writeEntry(keyword,
os);
478 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
488 os.writeEntry(keyword,
fld.front());
492 fld.writeEntry(keyword,
os);
502 bool Foam::expressions::exprResult::writeEntryChecked
513 if (this->size() <= 0)
515 if (value_.good() && is_contiguous<Type>::value)
517 const Type& val = value_.get<Type>();
521 os.writeKeyword(keyword);
529 const Field<Type>
fld;
530 fld.writeEntry(keyword,
os);
535 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
537 if (value_.good() && is_contiguous<Type>::value)
541 os.writeKeyword(keyword);
548 fld.writeEntry(keyword,
os);
557 bool Foam::expressions::exprResult::setAverageValueChecked(
const bool parRun)
564 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
568 if (limits.mag() <= SMALL)
570 value_.set(limits.centre());
582 bool Foam::expressions::exprResult::duplicateFieldChecked(
const void* ptr)
591 deleteChecked<Type>();
594 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(ptr);
597 fieldPtr_ =
new Field<Type>(
fld);
604 void Foam::expressions::exprResult::setSingleValueImpl(
const Type& val)
611 isPointData_ =
false;
629 <<
" is different from the stored result type " 630 << valueType() <<
nl <<
nl 634 if (fieldPtr_ ==
nullptr)
637 <<
"Cannot create tmp from nullptr." <<
nl 638 <<
"This error message should never appear!!" <<
nl 642 Field<Type>* ptr =
static_cast<Field<Type>*
>(fieldPtr_);
648 return tmp<Field<Type>>
::New(*ptr);
652 tmp<Field<Type>> tresult(ptr);
671 <<
" is different from the stored result type " 672 << valueType() <<
nl <<
nl 676 if (fieldPtr_ ==
nullptr)
679 <<
"Cannot return reference from nullptr." <<
nl 680 <<
"This error message should never appear!!" <<
nl 684 return *
static_cast<const Field<Type>*
>(fieldPtr_);
692 return const_cast<Field<Type>&
>(this->cref<Type>());
700 return const_cast<Field<Type>&
>(this->cref<Type>());
704 template<
template<
class>
class BinaryOp,
class Type>
707 const BinaryOp<Type>& bop,
715 <<
" is different from the stored result type " 716 << valueType() <<
nl <<
nl 720 Type result = initial;
724 for (
const Type& val :
fld)
726 result = bop(result, val);
bool hasValue() const
Has a value?
Type getReduced(const BinaryOp< Type > &bop, const Type &initial=pTraits< Type >::zero)
Get a reduced result.
bool is_bool() const
True if valueType is a bool.
const Type & value() const noexcept
Return const reference to value.
void size(const label n)
Older name for setAddressableSize.
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1)
Field< Type > & ref()
Return non-const reference to the field.
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.
bool isUniform() const
True if single, uniform value.
A polymorphic field/result from evaluating an expression.
tmp< Field< Type > > getResult(bool cacheCopy=false)
Return tmp field of the contents, optionally keeping a copy in cache.
constexpr char nl
The newline '\n' character (0x0a)
bool isType() const
True if valueType corresponds to the given Type.
A traits class, which is primarily used for primitives and vector-space.
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.
Generic dimensioned Type class.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Field< Type > & constCast() const
Return non-const reference to the field, casting away constness.
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
const Field< Type > & cref() const
Return const reference to the field.
const dimensionedScalar e
Elementary charge.
Generic templated field type.
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()
Default construct.
const Field< Type > * getField() const
Return a read pointer to the field data if the type matches, nullptr otherwise. Can generally be cons...
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
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))
label size() const
The field or object size.
#define WarningInFunction
Report a warning using Foam::Warning.
void setSingleValue(const Type &val)
Set single-value uniform result.
Type gAverage(const FieldField< Field, Type > &f)
void setResult(Field< Type > *, bool wantPointData=false)
Set result field, taking ownership of the pointer.
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.
Type getValue() const
Return a single value when isUniform() is true, or Zero when it is non-uniform or if the type mismatc...
static constexpr const zero Zero
Global zero (0)