32inline bool Foam::expressions::exprResult::deleteChecked()
36 if (ok && fieldPtr_ !=
nullptr)
38 delete static_cast<Field<Type>*
>(fieldPtr_);
48inline bool Foam::expressions::exprResult::readChecked
52 const bool singleValueOnly
63 const Type val(
e.get<Type>());
66 fieldPtr_ =
new Field<Type>(size_, val);
73 fieldPtr_ =
new Field<Type>(
e, size_);
84bool Foam::expressions::exprResult::getUniformChecked
99 const Field<Type>&
fld = *
static_cast<const Field<Type>*
>(fieldPtr_);
110 <<
"Different min/max values: " << limits
111 <<
" Using the average " << avg << nl;
115 result.setResult(avg, size);
122bool Foam::expressions::exprResult::plusEqChecked
131 *
static_cast<Field<Type>*
>(fieldPtr_)
132 += *
static_cast<const Field<Type>*
>(
b.fieldPtr_);
140bool Foam::expressions::exprResult::multiplyEqChecked
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();
232 return value_.get<Type>();
274 target().setResultImpl(val, wantPointData);
287 target().setResultImpl(val, wantPointData);
292void Foam::expressions::exprResult::setResultImpl
303 isPointData_ = wantPointData;
314void Foam::expressions::exprResult::setResultImpl
325 isPointData_ = wantPointData;
328 valType_ = pTraits<Type>::typeName;
342 target().setResultImpl(fldPtr, wantPointData);
347void Foam::expressions::exprResult::setResultImpl
356 isPointData_ = wantPointData;
358 if (fldPtr !=
nullptr)
360 size_ = fldPtr->
size();
374 target().setResultImpl(val, size);
379void Foam::expressions::exprResult::setResultImpl
390 isPointData_ =
false;
401 target().setSingleValueImpl(val);
406bool 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_);
437bool 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);
502bool Foam::expressions::exprResult::writeEntryChecked
513 if (this->size() <= 0)
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_);
541 os.writeKeyword(keyword);
548 fld.writeEntry(keyword,
os);
557bool 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());
582bool 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);
604void 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_);
704template<
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);
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))
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
void size(const label n)
Older name for setAddressableSize.
Generic dimensioned Type class.
const Type & value() const noexcept
Return const reference to value.
A polymorphic field/result from evaluating an expression.
Field< Type > & constCast() const
Return non-const reference to the field, casting away constness.
const word & valueType() const noexcept
Basic type for the field or single value.
Type getReduced(const BinaryOp< Type > &bop, const Type &initial=pTraits< Type >::zero)
Get a reduced result.
Type getValue() const
Return a single value when isUniform() is true, or Zero when it is non-uniform or if the type mismatc...
tmp< Field< Type > > getResult(bool cacheCopy=false)
Return tmp field of the contents, optionally keeping a copy in cache.
virtual expressions::exprResult & target()
Simulate virtual templated methods.
label size() const
The field or object size.
bool isType() const
True if valueType corresponds to the given Type.
Field< Type > & ref()
Return non-const reference to the field.
bool is_bool() const
True if valueType is a bool.
const Field< Type > & cref() const
Return const reference to the field.
void setSingleValue(const Type &val)
Set single-value uniform result.
const Field< Type > * getField() const
Return a read pointer to the field data if the type matches, nullptr otherwise. Can generally be cons...
void setResult(Field< Type > *, bool wantPointData=false)
Set result field, taking ownership of the pointer.
exprResult()
Default construct.
bool isUniform() const
True if single, uniform value.
bool isPointData(const bool wantPointData=true) const
True if representing point data, or test for same value as wantPointData argument.
bool hasValue() const
Has a value?
A traits class, which is primarily used for primitives and vector-space.
A class for managing temporary objects.
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
#define DebugInFunction
Report an information message using Foam::Info.
Type gAverage(const FieldField< Field, Type > &f, const label comm)
The global arithmetic average of a FieldField.
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.
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
static constexpr const zero Zero
Global zero (0).
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...
constexpr bool is_contiguous_v
The is_contiguous value of Type (after stripping of qualifiers).
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1, const label comm)
constexpr char nl
The newline '\n' character (0x0a).