Go to the documentation of this file.
35 #undef defineExpressionMethod
36 #define defineExpressionMethod(Type, Member) \
38 inline const Type& exprResult::singleValue::get<Type>() const \
44 inline const Type& exprResult::singleValue::set(const Type& val) \
58 #undef defineExpressionMethod
67 inline bool Foam::expressions::exprResult::deleteChecked()
69 const bool ok = isType<Type>();
71 if (ok && fieldPtr_ !=
nullptr)
73 delete static_cast<Field<Type>*
>(fieldPtr_);
83 inline bool Foam::expressions::exprResult::readChecked
86 const dictionary&
dict,
91 const bool ok = isType<Type>();
99 const Type val(
dict.get<Type>(key));
102 fieldPtr_ =
new Field<Type>(size_, val);
109 fieldPtr_ =
new Field<Type>(key,
dict, size_);
112 isUniform_ = uniform;
120 bool Foam::expressions::exprResult::getUniformChecked
135 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
143 if (limits.mag() > SMALL)
146 <<
"Different min/max values: " << limits
147 <<
" Using the average " << avg <<
nl;
151 result.setResult(avg, size);
158 bool Foam::expressions::exprResult::plusEqChecked
163 const bool ok = isType<Type>();
167 *
static_cast<Field<Type>*
>(fieldPtr_)
168 += *
static_cast<const Field<Type>*
>(
b.fieldPtr_);
176 bool Foam::expressions::exprResult::multiplyEqChecked
181 const bool ok = isType<Type>();
185 *
static_cast<Field<Type>*
>(fieldPtr_) *=
b;
239 return (!valType_.empty() && fieldPtr_ !=
nullptr);
251 const bool wantPointData
254 return isPointData_ == wantPointData;
274 if (!isUniform_ || !isType<Type>())
279 return single_.get<Type>();
291 return bool(objectPtr_);
310 target().setResultImpl(val, wantPointData);
323 target().setResultImpl(val, wantPointData);
328 void Foam::expressions::exprResult::setResultImpl
339 isPointData_ = wantPointData;
350 void Foam::expressions::exprResult::setResultImpl
361 isPointData_ = wantPointData;
374 target().setObjectResultImpl(obj.ptr());
379 void Foam::expressions::exprResult::setObjectResultImpl(
T* ptr)
384 isPointData_ =
false;
389 valType_ = ptr->typeName;
390 objectPtr_.reset(ptr);
402 target().setResultImpl(fldPtr, wantPointData);
407 void Foam::expressions::exprResult::setResultImpl
416 isPointData_ = wantPointData;
418 if (fldPtr !=
nullptr)
420 size_ = fldPtr->size();
434 target().setResultImpl(val, size);
439 void Foam::expressions::exprResult::setResultImpl
449 isPointData_ =
false;
463 target().setSingleValueImpl(val);
468 bool Foam::expressions::exprResult::writeSingleValueChecked(
Ostream& os)
const
475 if (this->size() <= 0)
479 os << single_.get<Type>();
484 os << pTraits<Type>::zero;
489 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
499 bool Foam::expressions::exprResult::writeValueFieldChecked(Ostream& os)
const
506 if (this->size() <= 0)
510 const Type& val = single_.get<Type>();
511 os.writeEntry(
"value", val);
516 const Field<Type>
fld;
517 fld.writeEntry(
"value", os);
522 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
526 os.writeEntry(
"value",
fld.first());
530 fld.writeEntry(
"value", os);
539 bool Foam::expressions::exprResult::writeEntryChecked
550 if (this->size() <= 0)
552 if (isUniform_ && is_contiguous<Type>::value)
554 const Type& val = single_.get<Type>();
558 os.writeKeyword(keyword);
566 const Field<Type>
fld;
567 fld.writeEntry(keyword, os);
572 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
574 if (isUniform_ && is_contiguous<Type>::value)
578 os.writeKeyword(keyword);
585 fld.writeEntry(keyword, os);
594 bool Foam::expressions::exprResult::setAverageValueChecked(
const bool parRun)
601 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
605 isUniform_ = (limits.mag() <= SMALL);
607 const Type avg = limits.centre();
616 bool Foam::expressions::exprResult::duplicateFieldChecked(
const void* ptr)
625 deleteChecked<Type>();
628 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(ptr);
631 fieldPtr_ =
new Field<Type>(
fld);
638 void Foam::expressions::exprResult::setSingleValueImpl(
const Type& val)
645 isPointData_ =
false;
650 valType_ = pTraits<Type>::typeName;
651 fieldPtr_ =
new Field<Type>(size_, val);
665 <<
" is different from the stored result type "
666 << valType_ <<
nl <<
nl
670 if (fieldPtr_ ==
nullptr)
673 <<
"Cannot create tmp from nullptr." <<
nl
674 <<
"This error message should never appear!!" <<
nl
707 <<
" is different from the stored result type "
708 << valType_ <<
nl <<
nl
712 if (fieldPtr_ ==
nullptr)
715 <<
"Cannot return reference from nullptr." <<
nl
716 <<
"This error message should never appear!!" <<
nl
720 return *
static_cast<const Field<Type>*
>(fieldPtr_);
728 return const_cast<Field<Type>&
>(this->cref<Type>());
736 return const_cast<Field<Type>&
>(this->cref<Type>());
750 <<
" is different from the stored result type "
751 << valType_ <<
nl <<
nl
755 Type* ptr =
dynamic_cast<Type*
>(objectPtr_.get());
772 objectPtr_.release();
780 template<
template<
class>
class BinaryOp,
class Type>
783 const BinaryOp<Type>& bop,
791 <<
" is different from the stored result type "
792 << valType_ <<
nl <<
nl
796 Type result = initial;
800 for (
const Type& val :
fld)
802 result = bop(result, val);
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
bool isObject() const
True if the object pointer is being used.
A class for handling words, derived from Foam::string.
label size() const
The field or object size.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Type getReduced(const BinaryOp< Type > &bop, const Type &initial=pTraits< Type >::zero)
Get a reduced result.
A class for managing temporary objects.
static constexpr const zero Zero
Global zero (0)
bool isPointData(const bool wantPointData=true) const
Type gAverage(const FieldField< Field, Type > &f)
const word & valueType() const
Basic type for the field or single value.
tmp< Field< Type > > getResult(bool cacheCopy=false)
const Type & value() const
Return const reference to value.
bool isBool() const
True if valueType is a bool.
void setObjectResult(autoPtr< Type > &&obj)
Set result object.
A polymorphic field/result from evaluating an expression.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Generic templated field type.
#define defineExpressionMethod(Type, Member)
#define DebugInFunction
Report an information message using Foam::Info.
Field< Type > & ref()
Return non-const reference to the field.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void setSingleValue(const Type &val)
Set single-value uniform result.
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
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))
tmp< Type > getObjectResult(bool cacheCopy=false)
bool hasValue() const
Has a value?
bool isUniform() const
True if single, uniform value.
Generic dimensioned Type class.
const Field< Type > & cref() const
Return const reference to the field.
bool isType() const
True if valueType corresponds to the given Type.
Vector< scalar > vector
A scalar version of the templated Vector.
Field< Type > & getRef() const
Return non-const reference to the field, casting away constness.
errorManipArg< error, int > exit(error &err, const int errNo=1)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
exprResult()
Default construct.
Traits class for primitives.
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
void setResult(Field< Type > *, bool wantPointData=false)
Set result field, taking ownership of the pointer.
#define WarningInFunction
Report a warning using Foam::Warning.
Tensor< scalar > tensor
Tensor of scalars, i.e. Tensor<scalar>.
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)