34 #define checkField(gf1, gf2, op) \
35 if ((gf1).mesh() != (gf2).mesh()) \
37 FatalErrorInFunction \
38 << "different mesh for fields " \
39 << (gf1).name() << " and " << (gf2).name() \
40 << " during operation " << op \
41 << abort(FatalError); \
47 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
50 const dictionary&
dict
55 boundaryField_.readField(*
this,
dict.subDict(
"boundaryField"));
57 if (
dict.found(
"referenceLevel"))
59 Type fieldAverage(pTraits<Type>(
dict.lookup(
"referenceLevel")));
65 boundaryField_[
patchi] == boundaryField_[
patchi] + fieldAverage;
71 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
85 this->readStream(typeName)
94 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
99 this->readOpt() == IOobject::MUST_READ
100 || this->readOpt() == IOobject::MUST_READ_IF_MODIFIED
104 <<
"read option IOobject::MUST_READ or MUST_READ_IF_MODIFIED"
105 <<
" suggests that a read constructor for field " << this->
name()
106 <<
" would be more appropriate." <<
endl;
108 else if (this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk())
113 if (this->size() != GeoMesh::size(this->
mesh()))
116 <<
" number of field elements = " << this->size()
117 <<
" number of mesh elements = "
118 << GeoMesh::size(this->
mesh())
122 readOldTimeIfPresent();
131 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
140 IOobject::READ_IF_PRESENT,
141 IOobject::AUTO_WRITE,
142 this->registerObject()
149 Info<<
"Reading old time level for field"
159 field0Ptr_->timeIndex_ = timeIndex_ - 1;
161 if (!field0Ptr_->readOldTimeIfPresent())
163 field0Ptr_->oldTime();
175 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
181 const word& patchFieldType
187 fieldPrevIterPtr_(NULL),
201 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
210 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
215 const dimensionSet& ds,
220 DimensionedField<Type, GeoMesh>(io,
mesh, ds, false),
223 fieldPrevIterPtr_(NULL),
224 boundaryField_(
mesh.
boundary(), *this, patchFieldTypes, actualPatchTypes)
238 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
247 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
252 const dimensioned<Type>& dt,
253 const word& patchFieldType
256 DimensionedField<Type, GeoMesh>(io,
mesh, dt, false),
259 fieldPrevIterPtr_(NULL),
273 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
278 boundaryField_ == dt.value();
284 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
289 const dimensioned<Type>& dt,
294 DimensionedField<Type, GeoMesh>(io,
mesh, dt, false),
297 fieldPrevIterPtr_(NULL),
298 boundaryField_(
mesh.
boundary(), *this, patchFieldTypes, actualPatchTypes)
303 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
308 boundaryField_ == dt.value();
314 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
319 const dimensionSet& ds,
320 const Field<Type>& iField,
321 const PtrList<PatchField<Type> >& ptfl
324 DimensionedField<Type, GeoMesh>(io,
mesh, ds, iField),
327 fieldPrevIterPtr_(NULL),
333 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
334 "constructing from components"
342 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
347 const bool readOldTime
350 DimensionedField<Type, GeoMesh>(io,
mesh,
dimless, false),
353 fieldPrevIterPtr_(NULL),
368 if (this->size() != GeoMesh::size(this->
mesh()))
371 <<
" number of field elements = " << this->size()
372 <<
" number of mesh elements = " << GeoMesh::size(this->
mesh())
378 readOldTimeIfPresent();
383 Info<<
"Finishing read-construct of "
384 "GeometricField<Type, PatchField, GeoMesh>"
390 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
395 const dictionary&
dict
398 DimensionedField<Type, GeoMesh>(io,
mesh,
dimless, false),
401 fieldPrevIterPtr_(NULL),
409 if (this->size() != GeoMesh::size(this->
mesh()))
412 <<
" number of field elements = " << this->size()
413 <<
" number of mesh elements = " << GeoMesh::size(this->
mesh())
419 Info<<
"Finishing dictionary-construct of "
420 "GeometricField<Type, PatchField, GeoMesh>"
426 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
429 const GeometricField<Type, PatchField, GeoMesh>& gf
432 DimensionedField<Type, GeoMesh>(gf),
435 fieldPrevIterPtr_(NULL),
436 boundaryField_(*this, gf.boundaryField_)
441 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
442 "constructing as copy"
448 field0Ptr_ =
new GeometricField<Type, PatchField, GeoMesh>
454 this->writeOpt() = IOobject::NO_WRITE;
458 #ifndef NoConstructFromTmp
459 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
462 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
465 DimensionedField<Type, GeoMesh>
467 const_cast<GeometricField<Type, PatchField, GeoMesh>&>(tgf()),
472 fieldPrevIterPtr_(NULL),
473 boundaryField_(*this, tgf().boundaryField_)
478 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
479 "constructing as copy"
483 this->writeOpt() = IOobject::NO_WRITE;
490 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
494 const GeometricField<Type, PatchField, GeoMesh>& gf
497 DimensionedField<Type, GeoMesh>(io, gf),
500 fieldPrevIterPtr_(NULL),
501 boundaryField_(*this, gf.boundaryField_)
506 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
507 "constructing as copy resetting IO params"
511 if (!readIfPresent() && gf.field0Ptr_)
513 field0Ptr_ =
new GeometricField<Type, PatchField, GeoMesh>
522 #ifndef NoConstructFromTmp
523 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
527 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
530 DimensionedField<Type, GeoMesh>
533 const_cast<GeometricField<Type, PatchField, GeoMesh>&>(tgf()),
538 fieldPrevIterPtr_(NULL),
539 boundaryField_(*this, tgf().boundaryField_)
544 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
545 "constructing from tmp resetting IO params"
556 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
560 const GeometricField<Type, PatchField, GeoMesh>& gf
563 DimensionedField<Type, GeoMesh>(newName, gf),
566 fieldPrevIterPtr_(NULL),
567 boundaryField_(*this, gf.boundaryField_)
572 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
573 "constructing as copy resetting name"
577 if (!readIfPresent() && gf.field0Ptr_)
579 field0Ptr_ =
new GeometricField<Type, PatchField, GeoMesh>
588 #ifndef NoConstructFromTmp
589 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
593 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
596 DimensionedField<Type, GeoMesh>
599 const_cast<GeometricField<Type, PatchField, GeoMesh>&>(tgf()),
604 fieldPrevIterPtr_(NULL),
605 boundaryField_(*this, tgf().boundaryField_)
610 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
611 "constructing from tmp resetting name"
620 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
624 const GeometricField<Type, PatchField, GeoMesh>& gf,
625 const word& patchFieldType
628 DimensionedField<Type, GeoMesh>(io, gf),
631 fieldPrevIterPtr_(NULL),
632 boundaryField_(this->
mesh().
boundary(), *this, patchFieldType)
637 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
638 "constructing as copy resetting IO params and patch type"
642 boundaryField_ == gf.boundaryField_;
644 if (!readIfPresent() && gf.field0Ptr_)
646 field0Ptr_ =
new GeometricField<Type, PatchField, GeoMesh>
655 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
659 const GeometricField<Type, PatchField, GeoMesh>& gf,
665 DimensionedField<Type, GeoMesh>(io, gf),
668 fieldPrevIterPtr_(NULL),
680 Info<<
"GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
681 "constructing as copy resetting IO params and patch types"
685 boundaryField_ == gf.boundaryField_;
687 if (!readIfPresent() && gf.field0Ptr_)
689 field0Ptr_ =
new GeometricField<Type, PatchField, GeoMesh>
700 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
710 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
721 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
732 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
739 return boundaryField_;
743 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
749 && timeIndex_ != this->time().
timeIndex()
751 this->
name().size() > 2
752 && this->
name()(this->
name().size()-2, 2) ==
"_0"
760 timeIndex_ = this->time().timeIndex();
764 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
769 field0Ptr_->storeOldTime();
773 Info<<
"Storing old time field for field" <<
endl
774 << this->info() <<
endl;
777 *field0Ptr_ == *
this;
778 field0Ptr_->timeIndex_ = timeIndex_;
780 if (field0Ptr_->field0Ptr_)
782 field0Ptr_->writeOpt() = this->writeOpt();
788 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
793 return field0Ptr_->nOldTimes() + 1;
802 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
817 this->registerObject()
831 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
842 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
845 if (!fieldPrevIterPtr_)
849 Info<<
"Allocating previous iteration field" <<
endl
850 << this->info() <<
endl;
855 this->
name() +
"PrevIter",
861 *fieldPrevIterPtr_ == *
this;
866 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
870 if (!fieldPrevIterPtr_)
873 <<
"previous iteration field" <<
endl << this->info() <<
endl
875 <<
" Use field.storePrevIter() at start of iteration."
879 return *fieldPrevIterPtr_;
883 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
889 boundaryField_.evaluate();
893 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
903 if (boundaryField_[
patchi].fixesValue())
916 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
922 <<
"Relaxing" <<
endl << this->info() <<
" by " <<
alpha <<
endl;
929 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
936 this->
mesh().data::template lookupOrDefault<bool>
953 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
961 return this->
name() +
"Final";
970 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
976 os <<
"min/max(" << this->
name() <<
") = "
983 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
994 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1004 this->
name() +
".T()",
1020 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1057 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1061 const GeometricField
1063 typename GeometricField<Type, PatchField, GeoMesh>::cmptType,
1074 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1078 const dimensioned<cmptType>& ds
1086 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1089 const dimensioned<Type>& dt
1097 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1100 const dimensioned<Type>& dt
1108 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1118 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1127 <<
"attempted assignment to self"
1140 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1143 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
1146 if (
this == &(tgf()))
1149 <<
"attempted assignment to self"
1153 const GeometricField<Type, PatchField, GeoMesh>& gf = tgf();
1159 this->dimensions() = gf.dimensions();
1164 const_cast<Field<Type>&
>(gf.internalField())
1173 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1176 const dimensioned<Type>& dt
1184 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1187 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
1190 const GeometricField<Type, PatchField, GeoMesh>& gf = tgf();
1203 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1206 const dimensioned<Type>& dt
1214 #define COMPUTED_ASSIGNMENT(TYPE, op) \
1216 template<class Type, template<class> class PatchField, class GeoMesh> \
1217 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \
1219 const GeometricField<TYPE, PatchField, GeoMesh>& gf \
1222 checkField(*this, gf, #op); \
1224 dimensionedInternalField() op gf.dimensionedInternalField(); \
1225 boundaryField() op gf.boundaryField(); \
1228 template<class Type, template<class> class PatchField, class GeoMesh> \
1229 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \
1231 const tmp<GeometricField<TYPE, PatchField, GeoMesh> >& tgf \
1234 operator op(tgf()); \
1238 template<class Type, template<class> class PatchField, class GeoMesh> \
1239 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \
1241 const dimensioned<TYPE>& dt \
1244 dimensionedInternalField() op dt; \
1245 boundaryField() op dt.value(); \
1253 #undef COMPUTED_ASSIGNMENT
1258 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1262 const GeometricField<Type, PatchField, GeoMesh>& gf
1265 gf.dimensionedInternalField().writeData(os,
"internalField");
1267 gf.boundaryField().writeEntry(
"boundaryField", os);
1272 "Ostream& operator<<(Ostream&, "
1273 "const GeometricField<Type, PatchField, GeoMesh>&)"
1280 template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
1284 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf