38 #define checkField(gf1, gf2, op) \
39 if ((gf1).mesh() != (gf2).mesh()) \
41 FatalErrorInFunction \
42 << "different mesh for fields " \
43 << (gf1).name() << " and " << (gf2).name() \
44 << " during operation " << op \
45 << abort(FatalError); \
51 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
54 const dictionary&
dict
57 Internal::readField(
dict,
"internalField");
59 boundaryField_.readField(*
this,
dict.subDict(
"boundaryField"));
63 if (
dict.readIfPresent(
"referenceLevel", refLevel))
67 forAll(boundaryField_, patchi)
69 boundaryField_[patchi] == boundaryField_[patchi] + refLevel;
75 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
78 const localIOdictionary
dict
99 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
104 this->readOpt() == IOobject::MUST_READ
105 || this->readOpt() == IOobject::MUST_READ_IF_MODIFIED
109 <<
"read option IOobject::MUST_READ or MUST_READ_IF_MODIFIED"
110 <<
" suggests that a read constructor for field " << this->
name()
111 <<
" would be more appropriate." <<
endl;
115 this->readOpt() == IOobject::READ_IF_PRESENT
116 && this->
template typeHeaderOk<GeometricField<Type, PatchField, GeoMesh>>
125 if (this->size() != GeoMesh::size(this->
mesh()))
128 <<
" number of field elements = " << this->size()
129 <<
" number of mesh elements = "
130 << GeoMesh::size(this->
mesh())
134 readOldTimeIfPresent();
143 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
152 IOobject::READ_IF_PRESENT,
153 IOobject::AUTO_WRITE,
154 this->registerObject()
159 field0.template typeHeaderOk<GeometricField<Type, PatchField, GeoMesh>>
166 <<
"Reading old time level for field" <<
nl << this->info() <<
endl;
168 field0Ptr_ =
new GeometricField<Type, PatchField, GeoMesh>
177 field0Ptr_->oriented() = this->oriented();
179 field0Ptr_->timeIndex_ = timeIndex_ - 1;
181 if (!field0Ptr_->readOldTimeIfPresent())
183 field0Ptr_->oldTime();
195 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
200 const dimensionSet& ds,
201 const word& patchFieldType
204 Internal(io,
mesh, ds, false),
207 fieldPrevIterPtr_(nullptr),
211 <<
"Creating temporary" <<
nl << this->info() <<
endl;
217 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
222 const dimensionSet& ds,
227 Internal(io,
mesh, ds, false),
230 fieldPrevIterPtr_(nullptr),
231 boundaryField_(
mesh.
boundary(), *this, patchFieldTypes, actualPatchTypes)
234 <<
"Creating temporary" <<
nl << this->info() <<
endl;
240 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
245 const dimensioned<Type>& dt,
246 const word& patchFieldType
249 Internal(io,
mesh, dt, false),
252 fieldPrevIterPtr_(nullptr),
256 <<
"Creating temporary" <<
nl << this->info() <<
endl;
258 boundaryField_ == dt.value();
264 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
269 const dimensioned<Type>& dt,
274 Internal(io,
mesh, dt, false),
277 fieldPrevIterPtr_(nullptr),
278 boundaryField_(
mesh.
boundary(), *this, patchFieldTypes, actualPatchTypes)
281 <<
"Creating temporary" <<
nl << this->info() <<
endl;
283 boundaryField_ == dt.value();
289 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
293 const Internal& diField,
294 const PtrList<PatchField<Type>>& ptfl
297 Internal(io, diField),
300 fieldPrevIterPtr_(nullptr),
304 <<
"Copy construct from components" <<
nl << this->info() <<
endl;
310 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
315 const dimensionSet& ds,
316 const Field<Type>& iField,
317 const word& patchFieldType
320 Internal(io,
mesh, ds, iField),
323 fieldPrevIterPtr_(nullptr),
327 <<
"Copy construct from internal field" <<
nl << this->info() <<
endl;
333 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
338 const dimensionSet& ds,
339 Field<Type>&& iField,
340 const word& patchFieldType
343 Internal(io,
mesh, ds, std::move(iField)),
346 fieldPrevIterPtr_(nullptr),
350 <<
"Move construct from internal field" <<
nl << this->info() <<
endl;
356 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
363 const PtrList<PatchField<Type>>& ptfl
366 Internal(io,
mesh, ds, iField),
369 fieldPrevIterPtr_(nullptr),
373 <<
"Copy construct from components" <<
nl << this->info() <<
endl;
379 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
384 const bool readOldTime
390 fieldPrevIterPtr_(nullptr),
397 if (this->size() != GeoMesh::size(this->
mesh()))
400 <<
" number of field elements = " << this->size()
401 <<
" number of mesh elements = " << GeoMesh::size(this->
mesh())
407 readOldTimeIfPresent();
411 <<
"Finishing read-construction" <<
nl << this->info() <<
endl;
415 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
426 fieldPrevIterPtr_(nullptr),
433 if (this->size() != GeoMesh::size(this->
mesh()))
436 <<
" number of field elements = " << this->size()
437 <<
" number of mesh elements = " << GeoMesh::size(this->
mesh())
442 <<
"Finishing dictionary-construct" <<
nl << this->info() <<
endl;
446 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
455 fieldPrevIterPtr_(nullptr),
456 boundaryField_(*this, gf.boundaryField_)
459 <<
"Copy construct" <<
nl << this->info() <<
endl;
469 this->writeOpt(IOobject::NO_WRITE);
473 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
479 Internal(tgf.constCast(), tgf.movable()),
482 fieldPrevIterPtr_(nullptr),
483 boundaryField_(*this, tgf().boundaryField_)
486 <<
"Constructing from tmp" <<
nl << this->info() <<
endl;
488 this->writeOpt(IOobject::NO_WRITE);
494 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
504 fieldPrevIterPtr_(nullptr),
505 boundaryField_(*this, gf.boundaryField_)
508 <<
"Copy construct, resetting IO params" <<
nl
509 << this->info() <<
endl;
511 if (!readIfPresent() && gf.field0Ptr_)
522 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
526 const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf
529 Internal(io, tgf.constCast(), tgf.movable()),
532 fieldPrevIterPtr_(nullptr),
533 boundaryField_(*this, tgf().boundaryField_)
536 <<
"Constructing from tmp resetting IO params" <<
nl
537 << this->info() <<
endl;
545 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
552 Internal(newName, gf),
555 fieldPrevIterPtr_(nullptr),
556 boundaryField_(*this, gf.boundaryField_)
559 <<
"Copy construct, resetting name" <<
nl
560 << this->info() <<
endl;
562 if (!readIfPresent() && gf.field0Ptr_)
573 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
577 const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf
580 Internal(newName, tgf.constCast(), tgf.movable()),
583 fieldPrevIterPtr_(nullptr),
584 boundaryField_(*this, tgf().boundaryField_)
587 <<
"Constructing from tmp resetting name" <<
nl
588 << this->info() <<
endl;
594 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
599 const word& patchFieldType
605 fieldPrevIterPtr_(nullptr),
606 boundaryField_(this->
mesh().
boundary(), *this, patchFieldType)
609 <<
"Copy construct, resetting IO params" <<
nl
610 << this->info() <<
endl;
612 boundaryField_ == gf.boundaryField_;
614 if (!readIfPresent() && gf.field0Ptr_)
625 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
629 const GeometricField<Type, PatchField, GeoMesh>& gf,
637 fieldPrevIterPtr_(nullptr),
647 <<
"Copy construct, resetting IO params and patch types" <<
nl
648 << this->info() <<
endl;
650 boundaryField_ == gf.boundaryField_;
652 if (!readIfPresent() && gf.field0Ptr_)
654 field0Ptr_ =
new GeometricField<Type, PatchField, GeoMesh>
663 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
667 const GeometricField<Type, PatchField, GeoMesh>& gf,
669 const word& patchFieldType
675 fieldPrevIterPtr_(nullptr),
676 boundaryField_(*this, gf.boundaryField_, patchIDs, patchFieldType)
679 <<
"Copy construct, resetting IO params and setting patchFieldType "
680 <<
"for patchIDs" <<
nl
681 << this->info() <<
endl;
683 if (!readIfPresent() && gf.field0Ptr_)
685 field0Ptr_ =
new GeometricField<Type, PatchField, GeoMesh>
694 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
698 const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf,
703 Internal(io, tgf.constCast(), tgf.movable()),
706 fieldPrevIterPtr_(nullptr),
716 <<
"Constructing from tmp resetting IO params and patch types" <<
nl
717 << this->info() <<
endl;
719 boundaryField_ == tgf().boundaryField_;
725 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
735 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
745 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
750 const bool updateAccessTime
753 if (updateAccessTime)
762 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
767 const bool updateAccessTime
770 if (updateAccessTime)
779 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
784 const bool updateAccessTime
787 if (updateAccessTime)
792 return boundaryField_;
796 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
802 && timeIndex_ != this->time().
timeIndex()
803 && !this->
name().ends_with(
"_0")
807 timeIndex_ = this->time().timeIndex();
815 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
820 field0Ptr_->storeOldTime();
823 <<
"Storing old time field for field" <<
nl << this->info() <<
endl;
825 *field0Ptr_ == *
this;
826 field0Ptr_->timeIndex_ = timeIndex_;
828 if (field0Ptr_->field0Ptr_)
830 field0Ptr_->writeOpt(this->writeOpt());
836 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
841 return field0Ptr_->nOldTimes() + 1;
848 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
863 this->registerObject()
871 <<
"created old time field " << field0Ptr_->info() <<
endl;
875 error::printStack(
Info);
888 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
899 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
902 if (!fieldPrevIterPtr_)
905 <<
"Allocating previous iteration field" <<
nl
906 << this->info() <<
endl;
910 this->
name() +
"PrevIter",
916 *fieldPrevIterPtr_ == *
this;
921 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
925 if (!fieldPrevIterPtr_)
928 <<
"previous iteration field" <<
endl << this->info() <<
endl
930 <<
" Use field.storePrevIter() at start of iteration."
934 return *fieldPrevIterPtr_;
938 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
944 boundaryField_.evaluate();
948 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
956 forAll(boundaryField_, patchi)
958 if (boundaryField_[patchi].fixesValue())
971 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
981 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
988 this->
mesh().data::template getOrDefault<bool>
1005 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1013 return this->
name() +
"Final";
1016 return this->
name();
1020 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1033 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1044 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1052 this->
name() +
".T()",
1060 Foam::T(tresult.ref().primitiveFieldRef(), primitiveField());
1061 Foam::T(tresult.ref().boundaryFieldRef(), boundaryField());
1067 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1082 auto tresult = tmp<GeometricField<cmptType, PatchField, GeoMesh>>
::New
1094 Foam::component(tresult.ref().primitiveFieldRef(), primitiveField(), d);
1095 Foam::component(tresult.ref().boundaryFieldRef(), boundaryField(), d);
1101 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1105 const GeometricField
1107 typename GeometricField<Type, PatchField, GeoMesh>::cmptType,
1114 boundaryFieldRef().replace(d, gcf.boundaryField());
1118 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1126 boundaryFieldRef().replace(d, ds.
value());
1130 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1141 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1152 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1163 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1177 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1184 this->
clip(minVal, maxVal);
1188 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1192 boundaryFieldRef().negate();
1198 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1201 const GeometricField<Type, PatchField, GeoMesh>& gf
1214 boundaryFieldRef() = gf.boundaryField();
1218 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1221 const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf
1224 const auto& gf = tgf();
1235 this->dimensions() = gf.dimensions();
1236 this->oriented() = gf.oriented();
1248 boundaryFieldRef() = gf.boundaryField();
1254 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1257 const dimensioned<Type>& dt
1261 boundaryFieldRef() = dt.
value();
1265 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1268 const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf
1271 const auto& gf = tgf();
1278 boundaryFieldRef() == gf.boundaryField();
1284 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1287 const dimensioned<Type>& dt
1291 boundaryFieldRef() == dt.
value();
1295 #define COMPUTED_ASSIGNMENT(TYPE, op) \
1297 template<class Type, template<class> class PatchField, class GeoMesh> \
1298 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \
1300 const GeometricField<TYPE, PatchField, GeoMesh>& gf \
1303 checkField(*this, gf, #op); \
1306 boundaryFieldRef() op gf.boundaryField(); \
1309 template<class Type, template<class> class PatchField, class GeoMesh> \
1310 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \
1312 const tmp<GeometricField<TYPE, PatchField, GeoMesh>>& tgf \
1315 operator op(tgf()); \
1319 template<class Type, template<class> class PatchField, class GeoMesh> \
1320 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \
1322 const dimensioned<TYPE>& dt \
1326 boundaryFieldRef() op dt.value(); \
1334 #undef COMPUTED_ASSIGNMENT
1339 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1343 const GeometricField<Type, PatchField, GeoMesh>& gf
1346 gf().writeData(
os,
"internalField");
1348 gf.boundaryField().writeEntry(
"boundaryField",
os);
1355 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1359 const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf