60bool 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>());
126bool 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);
178Foam::expressions::exprResult::singleValue::singleValue()
180 std::memset(
static_cast<void*
>(
this),
'\0',
sizeof(*
this));
184Foam::expressions::exprResult::singleValue::singleValue
186 const singleValue& val
189 std::memcpy(
static_cast<void*
>(
this), &val,
sizeof(*
this));
195 const singleValue& val
201 std::memcpy(
static_cast<void*
>(
this), &val,
sizeof(*
this));
246 valType_(
dict.getOrDefault<
word>(
"valueType",
"")),
247 isUniform_(
dict.getOrDefault(
"isSingleValue",
uniform)),
248 isPointData_(
dict.getOrDefault(
"isPointValue", false)),
249 noReset_(
dict.getOrDefault(
"noReset", false)),
259 const bool uniform = isUniform_;
272 || readChecked<vector>(
"value",
dict, len,
uniform)
273 || readChecked<tensor>(
"value",
dict, len,
uniform)
274 || readChecked<symmTensor>(
"value",
dict, len,
uniform)
275 || readChecked<sphericalTensor>(
"value",
dict, len,
uniform)
281 if (valType_.empty())
288 <<
"Do not know how to read data type " << valType_
289 << (
uniform ?
" as a single value." :
".") <<
nl
296 <<
"No entry 'value' defined" <<
nl
308 const word resultType
310 dict.getOrDefault<
word>(
"resultType",
"exprResult")
313 if (
dict.getOrDefault(
"unsetValue",
false))
315 auto* ctorPtr = emptyConstructorTable(resultType);
324 *emptyConstructorTablePtr_
329 <<
"Creating unset result of type " << resultType <<
nl;
335 auto* ctorPtr = dictionaryConstructorTable(resultType);
344 *dictionaryConstructorTablePtr_
349 <<
"Creating result of type " << resultType <<
nl;
386 if (force || !noReset_ || needsReset_)
406void Foam::expressions::exprResult::uglyDelete()
412 deleteChecked<scalar>()
413 || deleteChecked<vector>()
414 || deleteChecked<tensor>()
415 || deleteChecked<symmTensor>()
416 || deleteChecked<sphericalTensor>()
417 || deleteChecked<bool>()
423 <<
"Unknown type " << valType_
424 <<
" probable memory loss" <<
nl
442 if (fieldPtr_ ==
nullptr)
445 <<
"Not set. Cannot construct uniform value" <<
nl
453 getUniformChecked<scalar>(ret, size, noWarn, parRun)
454 || getUniformChecked<vector>(ret, size, noWarn, parRun)
455 || getUniformChecked<tensor>(ret, size, noWarn, parRun)
456 || getUniformChecked<symmTensor>(ret, size, noWarn, parRun)
457 || getUniformChecked<sphericalTensor>(ret, size, noWarn, parRun)
463 <<
"Cannot get uniform value for type " << valType_ <<
nl
473 if (fieldPtr_ ==
nullptr)
476 <<
"Not set - cannot determine if uniform" <<
nl <<
endl;
482 setAverageValueChecked<scalar>(parRun)
483 || setAverageValueChecked<vector>(parRun)
484 || setAverageValueChecked<tensor>(parRun)
485 || setAverageValueChecked<symmTensor>(parRun)
486 || setAverageValueChecked<sphericalTensor>(parRun)
487 || setAverageValueCheckedBool(parRun)
493 <<
"Unknown type " << valType_ <<
nl <<
endl;
509 valType_ = rhs.valType_;
510 isUniform_ = rhs.isUniform_;
511 isPointData_ = rhs.isPointData_;
512 single_ = rhs.single_;
518 duplicateFieldChecked<scalar>(rhs.fieldPtr_)
519 || duplicateFieldChecked<vector>(rhs.fieldPtr_)
520 || duplicateFieldChecked<tensor>(rhs.fieldPtr_)
521 || duplicateFieldChecked<symmTensor>(rhs.fieldPtr_)
522 || duplicateFieldChecked<sphericalTensor>(rhs.fieldPtr_)
523 || duplicateFieldChecked<bool>(rhs.fieldPtr_)
529 <<
" Type " << valType_ <<
" can not be copied" <<
nl
545 valType_ = rhs.valType_;
546 isUniform_ = rhs.isUniform_;
547 isPointData_ = rhs.isPointData_;
548 noReset_ = rhs.noReset_;
549 needsReset_ = rhs.needsReset_;
552 single_ = rhs.single_;
553 fieldPtr_ = rhs.fieldPtr_;
555 rhs.fieldPtr_ =
nullptr;
568 writeEntryChecked<scalar>(keyword,
os)
569 || writeEntryChecked<vector>(keyword,
os)
570 || writeEntryChecked<tensor>(keyword,
os)
571 || writeEntryChecked<symmTensor>(keyword,
os)
572 || writeEntryChecked<sphericalTensor>(keyword,
os)
573 || writeEntryChecked<bool>(keyword,
os)
579 <<
"Unknown data type " << valType_ <<
endl;
602 os.writeEntry(
"resultType", valueType());
603 os.writeEntryIfDifferent<
Switch>(
"noReset",
false, noReset_);
605 if (fieldPtr_ ==
nullptr)
607 os.writeEntry<
Switch>(
"unsetValue",
true);
611 os.writeEntry(
"valueType", valType_);
613 os.writeEntryIfDifferent<
Switch>(
"isPointValue",
false, isPointData_);
614 os.writeEntry<
Switch>(
"isSingleValue", isUniform_);
616 this->writeField(
os,
"value");
643 writeFieldChecked<scalar>(keyword,
os)
644 || writeFieldChecked<vector>(keyword,
os)
645 || writeFieldChecked<tensor>(keyword,
os)
646 || writeFieldChecked<symmTensor>(keyword,
os)
647 || writeFieldChecked<sphericalTensor>(keyword,
os)
648 || writeFieldChecked<label>(keyword,
os)
649 || writeFieldChecked<bool>(keyword,
os)
655 <<
"Unknown data type " << valType_ <<
endl;
674 writeSingleValueChecked<scalar>(
os)
675 || writeSingleValueChecked<vector>(
os)
676 || writeSingleValueChecked<tensor>(
os)
677 || writeSingleValueChecked<symmTensor>(
os)
678 || writeSingleValueChecked<sphericalTensor>(
os)
679 || writeSingleValueChecked<label>(
os)
680 || writeSingleValueChecked<bool>(
os)
686 <<
"Unknown data type " << valType_ <<
endl;
702 <<
"Can not multiply. Unallocated field of type" << valType_ <<
nl
708 multiplyEqChecked<scalar>(
b)
709 || multiplyEqChecked<vector>(
b)
710 || multiplyEqChecked<tensor>(
b)
711 || multiplyEqChecked<symmTensor>(
b)
712 || multiplyEqChecked<sphericalTensor>(
b)
718 <<
"Can not multiply field of type "
736 <<
"Can not add. Unallocated field of type " << valType_ <<
nl
740 if (this->size() !=
b.size())
743 <<
"Different sizes " << this->size() <<
" and " <<
b.size() <<
nl
749 plusEqChecked<scalar>(
b)
750 || plusEqChecked<vector>(
b)
751 || plusEqChecked<tensor>(
b)
752 || plusEqChecked<symmTensor>(
b)
753 || plusEqChecked<sphericalTensor>(
b)
759 <<
"Can not add Field-type exprResult of type"
835 #undef defineExpressionMethod
836 #define defineExpressionMethod(Type) \
837 if (isType<Type>()) \
839 return static_cast<Field<Type>*>(fieldPtr_)->cdata(); \
848 #undef defineExpressionMethod
851 <<
"Unsupported type" << valType_ <<
nl
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
static const Enum< streamFormat > formatNames
Stream format names (ascii, binary)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Database for solution data, solver performance and other reduced data.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
void reset()
Reset to defaults.
A polymorphic field/result from evaluating an expression.
exprResult getUniform(const label size, const bool noWarn, const bool parRun=Pstream::parRun()) const
Construct a uniform field from the current results.
static const exprResult null
An empty result.
virtual void resetImpl()
Reset at new timestep according to the derived class type.
void testIfSingleValue(const bool parRun=Pstream::parRun())
Test if field corresponds to a single-value and thus uniform.
void writeValue(Ostream &os) const
Write the single value, or the first value from field.
void writeEntry(const word &keyword, Ostream &os) const
Forwarding to Field::writeEntry.
virtual void operator=(const exprResult &rhs)
Copy assignment.
exprResult()
Default construct.
void clear()
Clear (zero) the result.
virtual ~exprResult()
Destructor.
const void * dataAddress() const
The address of the field data content.
void writeField(Ostream &os, const word &keyword="") const
Write the field, optionally as an entry.
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
Foam::dictionary writeDict() const
Write to dictionary.
Reference counter for various OpenFOAM components.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define defineExpressionMethod(Type)
OBJstream os(runTime.globalPath()/outputName)
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.