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)),
257 if (
dict.found(
"value"))
259 const bool uniform = isUniform_;
264 ?
dict.getOrDefault<label>(
"fieldSize", 1)
265 :
dict.get<label>(
"fieldSize")
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;
331 return autoPtr<exprResult>(ctorPtr());
335 auto* ctorPtr = dictionaryConstructorTable(resultType);
344 *dictionaryConstructorTablePtr_
349 <<
"Creating result of type " << resultType <<
nl;
386 if (force || !noReset_ || needsReset_)
406 void 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_);
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;
694 Foam::expressions::exprResult::operator*=
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 "
728 Foam::expressions::exprResult::operator+=
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"
773 expressions::exprResult& data
787 const expressions::exprResult& data
799 const expressions::exprResult&
b
809 const expressions::exprResult& a,
813 expressions::exprResult result(a);
822 const expressions::exprResult& a,
823 const expressions::exprResult&
b
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