00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "GeometricField.H"
00028 #include "Time.H"
00029 #include "demandDrivenData.H"
00030 #include "dictionary.H"
00031
00032
00033
00034
00035
00036 #define checkField(gf1, gf2, op) \
00037 if ((gf1).mesh() != (gf2).mesh()) \
00038 { \
00039 FatalErrorIn("checkField(gf1, gf2, op)") \
00040 << "different mesh for fields " \
00041 << (gf1).name() << " and " << (gf2).name() \
00042 << " during operatrion " << op \
00043 << abort(FatalError); \
00044 }
00045
00046
00047
00048
00049 template<class Type, template<class> class PatchField, class GeoMesh>
00050 Foam::tmp
00051 <
00052 typename Foam::GeometricField<Type, PatchField, GeoMesh>::
00053 GeometricBoundaryField
00054 >
00055 Foam::GeometricField<Type, PatchField, GeoMesh>::readField(Istream& is)
00056 {
00057 if (is.version() < 2.0)
00058 {
00059 FatalIOErrorIn
00060 (
00061 "GeometricField<Type, PatchField, GeoMesh>::readField(Istream&)",
00062 is
00063 ) << "IO versions < 2.0 are not supported."
00064 << exit(FatalIOError);
00065 }
00066
00067 dictionary fieldDict(is);
00068
00069 DimensionedField<Type, GeoMesh>::readField(fieldDict, "internalField");
00070
00071 tmp<GeometricBoundaryField> tboundaryField
00072 (
00073 new GeometricBoundaryField
00074 (
00075 this->mesh().boundary(),
00076 *this,
00077 fieldDict.subDict("boundaryField")
00078 )
00079 );
00080
00081 if (fieldDict.found("referenceLevel"))
00082 {
00083 Type fieldAverage(pTraits<Type>(fieldDict.lookup("referenceLevel")));
00084
00085 Field<Type>::operator+=(fieldAverage);
00086
00087 GeometricBoundaryField& boundaryField = tboundaryField();
00088
00089 forAll(boundaryField, patchi)
00090 {
00091 boundaryField[patchi] == boundaryField[patchi] + fieldAverage;
00092 }
00093 }
00094
00095 return tboundaryField;
00096 }
00097
00098
00099 template<class Type, template<class> class PatchField, class GeoMesh>
00100 bool Foam::GeometricField<Type, PatchField, GeoMesh>::readIfPresent()
00101 {
00102 if (this->readOpt() == IOobject::MUST_READ)
00103 {
00104 WarningIn
00105 (
00106 "GeometricField<Type, PatchField, GeoMesh>::readIfPresent()"
00107 ) << "read option IOobject::MUST_READ "
00108 << "suggests that a read constructor for field " << this->name()
00109 << " would be more appropriate." << endl;
00110 }
00111 else if (this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk())
00112 {
00113 boundaryField_.transfer(readField(this->readStream(typeName))());
00114 this->close();
00115
00116
00117 if (this->size() != GeoMesh::size(this->mesh()))
00118 {
00119 FatalIOErrorIn
00120 (
00121 "GeometricField<Type, PatchField, GeoMesh>::"
00122 "readIfPresent()",
00123 this->readStream(typeName)
00124 ) << " number of field elements = " << this->size()
00125 << " number of mesh elements = "
00126 << GeoMesh::size(this->mesh())
00127 << exit(FatalIOError);
00128 }
00129
00130 readOldTimeIfPresent();
00131
00132 return true;
00133 }
00134
00135 return false;
00136 }
00137
00138
00139 template<class Type, template<class> class PatchField, class GeoMesh>
00140 bool Foam::GeometricField<Type, PatchField, GeoMesh>::readOldTimeIfPresent()
00141 {
00142
00143 IOobject field0
00144 (
00145 this->name() + "_0",
00146 this->time().timeName(),
00147 this->db(),
00148 IOobject::READ_IF_PRESENT,
00149 IOobject::AUTO_WRITE
00150 );
00151
00152 if (field0.headerOk())
00153 {
00154 if (debug)
00155 {
00156 Info<< "Reading old time level for field"
00157 << endl << this->info() << endl;
00158 }
00159
00160 field0Ptr_ = new GeometricField<Type, PatchField, GeoMesh>
00161 (
00162 field0,
00163 this->mesh()
00164 );
00165
00166 field0Ptr_->timeIndex_ = timeIndex_ - 1;
00167
00168 if (!field0Ptr_->readOldTimeIfPresent())
00169 {
00170 field0Ptr_->oldTime();
00171 }
00172
00173 return true;
00174 }
00175
00176 return false;
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186 template<class Type, template<class> class PatchField, class GeoMesh>
00187 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00188 (
00189 const IOobject& io,
00190 const Mesh& mesh,
00191 const dimensionSet& ds,
00192 const word& patchFieldType
00193 )
00194 :
00195 DimensionedField<Type, GeoMesh>(io, mesh, ds),
00196 timeIndex_(this->time().timeIndex()),
00197 field0Ptr_(NULL),
00198 fieldPrevIterPtr_(NULL),
00199 boundaryField_(mesh.boundary(), *this, patchFieldType)
00200 {
00201 if (debug)
00202 {
00203 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00204 "creating temporary"
00205 << endl << this->info() << endl;
00206 }
00207
00208 readIfPresent();
00209 }
00210
00211
00212
00213
00214
00215
00216 template<class Type, template<class> class PatchField, class GeoMesh>
00217 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00218 (
00219 const IOobject& io,
00220 const Mesh& mesh,
00221 const dimensionSet& ds,
00222 const wordList& patchFieldTypes
00223 )
00224 :
00225 DimensionedField<Type, GeoMesh>(io, mesh, ds),
00226 timeIndex_(this->time().timeIndex()),
00227 field0Ptr_(NULL),
00228 fieldPrevIterPtr_(NULL),
00229 boundaryField_(mesh.boundary(), *this, patchFieldTypes)
00230 {
00231 if (debug)
00232 {
00233 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00234 "creating temporary"
00235 << endl << this->info() << endl;
00236 }
00237
00238 readIfPresent();
00239 }
00240
00241
00242
00243 template<class Type, template<class> class PatchField, class GeoMesh>
00244 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00245 (
00246 const IOobject& io,
00247 const Mesh& mesh,
00248 const dimensioned<Type>& dt,
00249 const word& patchFieldType
00250 )
00251 :
00252 DimensionedField<Type, GeoMesh>(io, mesh, dt),
00253 timeIndex_(this->time().timeIndex()),
00254 field0Ptr_(NULL),
00255 fieldPrevIterPtr_(NULL),
00256 boundaryField_(mesh.boundary(), *this, patchFieldType)
00257 {
00258 if (debug)
00259 {
00260 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00261 "creating temporary"
00262 << endl << this->info() << endl;
00263 }
00264
00265 boundaryField_ == dt.value();
00266
00267 readIfPresent();
00268 }
00269
00270
00271
00272 template<class Type, template<class> class PatchField, class GeoMesh>
00273 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00274 (
00275 const IOobject& io,
00276 const Mesh& mesh,
00277 const dimensioned<Type>& dt,
00278 const wordList& patchFieldTypes
00279 )
00280 :
00281 DimensionedField<Type, GeoMesh>(io, mesh, dt),
00282 timeIndex_(this->time().timeIndex()),
00283 field0Ptr_(NULL),
00284 fieldPrevIterPtr_(NULL),
00285 boundaryField_(mesh.boundary(), *this, patchFieldTypes)
00286 {
00287 if (debug)
00288 {
00289 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00290 "creating temporary"
00291 << endl << this->info() << endl;
00292 }
00293
00294 boundaryField_ == dt.value();
00295
00296 readIfPresent();
00297 }
00298
00299
00300
00301 template<class Type, template<class> class PatchField, class GeoMesh>
00302 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00303 (
00304 const IOobject& io,
00305 const Mesh& mesh,
00306 const dimensionSet& ds,
00307 const Field<Type>& iField,
00308 const PtrList<PatchField<Type> >& ptfl
00309 )
00310 :
00311 DimensionedField<Type, GeoMesh>(io, mesh, ds, iField),
00312 timeIndex_(this->time().timeIndex()),
00313 field0Ptr_(NULL),
00314 fieldPrevIterPtr_(NULL),
00315 boundaryField_(mesh.boundary(), *this, ptfl)
00316 {
00317 if (debug)
00318 {
00319 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00320 "constructing from components"
00321 << endl << this->info() << endl;
00322 }
00323
00324 readIfPresent();
00325 }
00326
00327
00328 template<class Type, template<class> class PatchField, class GeoMesh>
00329 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00330 (
00331 const IOobject& io,
00332 const Mesh& mesh
00333 )
00334 :
00335 DimensionedField<Type, GeoMesh>(io, mesh, dimless),
00336 timeIndex_(this->time().timeIndex()),
00337 field0Ptr_(NULL),
00338 fieldPrevIterPtr_(NULL),
00339 boundaryField_(*this, readField(this->readStream(typeName)))
00340 {
00341 this->close();
00342
00343
00344
00345 if (this->size() != GeoMesh::size(this->mesh()))
00346 {
00347 FatalIOErrorIn
00348 (
00349 "GeometricField<Type, PatchField, GeoMesh>::GeometricField"
00350 "(const IOobject&, const Mesh&)",
00351 this->readStream(typeName)
00352 ) << " number of field elements = " << this->size()
00353 << " number of mesh elements = " << GeoMesh::size(this->mesh())
00354 << exit(FatalIOError);
00355 }
00356
00357 readOldTimeIfPresent();
00358
00359 if (debug)
00360 {
00361 Info<< "Finishing read-construct of "
00362 "GeometricField<Type, PatchField, GeoMesh>"
00363 << endl << this->info() << endl;
00364 }
00365 }
00366
00367
00368 template<class Type, template<class> class PatchField, class GeoMesh>
00369 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00370 (
00371 const IOobject& io,
00372 const Mesh& mesh,
00373 Istream& is
00374 )
00375 :
00376 DimensionedField<Type, GeoMesh>(io, mesh, dimless),
00377 timeIndex_(this->time().timeIndex()),
00378 field0Ptr_(NULL),
00379 fieldPrevIterPtr_(NULL),
00380 boundaryField_(*this, readField(is))
00381 {
00382
00383
00384 if (this->size() != GeoMesh::size(this->mesh()))
00385 {
00386 FatalIOErrorIn
00387 (
00388 "GeometricField<Type, PatchField, GeoMesh>::GeometricField"
00389 "(const IOobject&, const Mesh&, Istream&)",
00390 is
00391 ) << " number of field elements = " << this->size()
00392 << " number of mesh elements = " << GeoMesh::size(this->mesh())
00393 << exit(FatalIOError);
00394 }
00395
00396 readOldTimeIfPresent();
00397
00398 if (debug)
00399 {
00400 Info<< "Finishing read-construct of "
00401 "GeometricField<Type, PatchField, GeoMesh>"
00402 << endl << this->info() << endl;
00403 }
00404 }
00405
00406
00407
00408 template<class Type, template<class> class PatchField, class GeoMesh>
00409 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00410 (
00411 const GeometricField<Type, PatchField, GeoMesh>& gf
00412 )
00413 :
00414 DimensionedField<Type, GeoMesh>(gf),
00415 timeIndex_(gf.timeIndex()),
00416 field0Ptr_(NULL),
00417 fieldPrevIterPtr_(NULL),
00418 boundaryField_(*this, gf.boundaryField_)
00419 {
00420 if (debug)
00421 {
00422 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00423 "constructing as copy"
00424 << endl << this->info() << endl;
00425 }
00426
00427 if (gf.field0Ptr_)
00428 {
00429 field0Ptr_ = new GeometricField<Type, PatchField, GeoMesh>
00430 (
00431 *gf.field0Ptr_
00432 );
00433 }
00434
00435 this->writeOpt() = IOobject::NO_WRITE;
00436 }
00437
00438
00439 #ifdef ConstructFromTmp
00440 template<class Type, template<class> class PatchField, class GeoMesh>
00441 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00442 (
00443 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
00444 )
00445 :
00446 DimensionedField<Type, GeoMesh>
00447 (
00448 const_cast<GeometricField<Type, PatchField, GeoMesh>&>(tgf()),
00449 tgf.isTmp()
00450 ),
00451 timeIndex_(tgf().timeIndex()),
00452 field0Ptr_(NULL),
00453 fieldPrevIterPtr_(NULL),
00454 boundaryField_(*this, tgf().boundaryField_)
00455 {
00456 if (debug)
00457 {
00458 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00459 "constructing as copy"
00460 << endl << this->info() << endl;
00461 }
00462
00463 this->writeOpt() = IOobject::NO_WRITE;
00464
00465 tgf.clear();
00466 }
00467 #endif
00468
00469
00470
00471 template<class Type, template<class> class PatchField, class GeoMesh>
00472 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00473 (
00474 const IOobject& io,
00475 const GeometricField<Type, PatchField, GeoMesh>& gf
00476 )
00477 :
00478 DimensionedField<Type, GeoMesh>(io, gf),
00479 timeIndex_(gf.timeIndex()),
00480 field0Ptr_(NULL),
00481 fieldPrevIterPtr_(NULL),
00482 boundaryField_(*this, gf.boundaryField_)
00483 {
00484 if (debug)
00485 {
00486 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00487 "constructing as copy resetting IO params"
00488 << endl << this->info() << endl;
00489 }
00490
00491 if (!readIfPresent() && gf.field0Ptr_)
00492 {
00493 field0Ptr_ = new GeometricField<Type, PatchField, GeoMesh>
00494 (
00495 io.name() + "_0",
00496 *gf.field0Ptr_
00497 );
00498 }
00499 }
00500
00501
00502
00503 template<class Type, template<class> class PatchField, class GeoMesh>
00504 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00505 (
00506 const word& newName,
00507 const GeometricField<Type, PatchField, GeoMesh>& gf
00508 )
00509 :
00510 DimensionedField<Type, GeoMesh>(newName, gf),
00511 timeIndex_(gf.timeIndex()),
00512 field0Ptr_(NULL),
00513 fieldPrevIterPtr_(NULL),
00514 boundaryField_(*this, gf.boundaryField_)
00515 {
00516 if (debug)
00517 {
00518 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00519 "constructing as copy resetting name"
00520 << endl << this->info() << endl;
00521 }
00522
00523 if (!readIfPresent() && gf.field0Ptr_)
00524 {
00525 field0Ptr_ = new GeometricField<Type, PatchField, GeoMesh>
00526 (
00527 newName + "_0",
00528 *gf.field0Ptr_
00529 );
00530 }
00531 }
00532
00533
00534
00535 #ifdef ConstructFromTmp
00536 template<class Type, template<class> class PatchField, class GeoMesh>
00537 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00538 (
00539 const word& newName,
00540 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
00541 )
00542 :
00543 DimensionedField<Type, GeoMesh>
00544 (
00545 newName,
00546 const_cast<GeometricField<Type, PatchField, GeoMesh>&>(tgf()),
00547 tgf.isTmp()
00548 ),
00549 timeIndex_(tgf().timeIndex()),
00550 field0Ptr_(NULL),
00551 fieldPrevIterPtr_(NULL),
00552 boundaryField_(*this, tgf().boundaryField_)
00553 {
00554 if (debug)
00555 {
00556 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00557 "constructing from tmp resetting name"
00558 << endl << this->info() << endl;
00559 }
00560
00561 tgf.clear();
00562 }
00563 #endif
00564
00565
00566 template<class Type, template<class> class PatchField, class GeoMesh>
00567 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00568 (
00569 const IOobject& io,
00570 const GeometricField<Type, PatchField, GeoMesh>& gf,
00571 const word& patchFieldType
00572 )
00573 :
00574 DimensionedField<Type, GeoMesh>(io, gf),
00575 timeIndex_(gf.timeIndex()),
00576 field0Ptr_(NULL),
00577 fieldPrevIterPtr_(NULL),
00578 boundaryField_(this->mesh().boundary(), *this, patchFieldType)
00579 {
00580 if (debug)
00581 {
00582 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00583 "constructing as copy resetting IO params"
00584 << endl << this->info() << endl;
00585 }
00586
00587 boundaryField_ == gf.boundaryField_;
00588
00589 if (!readIfPresent() && gf.field0Ptr_)
00590 {
00591 field0Ptr_ = new GeometricField<Type, PatchField, GeoMesh>
00592 (
00593 io.name() + "_0",
00594 *gf.field0Ptr_
00595 );
00596 }
00597 }
00598
00599
00600
00601 template<class Type, template<class> class PatchField, class GeoMesh>
00602 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
00603 (
00604 const IOobject& io,
00605 const GeometricField<Type, PatchField, GeoMesh>& gf,
00606 const wordList& patchFieldTypes
00607 )
00608 :
00609 DimensionedField<Type, GeoMesh>(io, gf),
00610 timeIndex_(gf.timeIndex()),
00611 field0Ptr_(NULL),
00612 fieldPrevIterPtr_(NULL),
00613 boundaryField_(this->mesh().boundary(), *this, patchFieldTypes)
00614 {
00615 if (debug)
00616 {
00617 Info<< "GeometricField<Type, PatchField, GeoMesh>::GeometricField : "
00618 "constructing as copy resetting IO params"
00619 << endl << this->info() << endl;
00620 }
00621
00622 boundaryField_ == gf.boundaryField_;
00623
00624 if (!readIfPresent() && gf.field0Ptr_)
00625 {
00626 field0Ptr_ = new GeometricField<Type, PatchField, GeoMesh>
00627 (
00628 io.name() + "_0",
00629 *gf.field0Ptr_
00630 );
00631 }
00632 }
00633
00634
00635
00636
00637 template<class Type, template<class> class PatchField, class GeoMesh>
00638 Foam::GeometricField<Type, PatchField, GeoMesh>::~GeometricField()
00639 {
00640 deleteDemandDrivenData(field0Ptr_);
00641 deleteDemandDrivenData(fieldPrevIterPtr_);
00642 }
00643
00644
00645
00646
00647 template<class Type, template<class> class PatchField, class GeoMesh>
00648 typename
00649 Foam::GeometricField<Type, PatchField, GeoMesh>::DimensionedInternalField&
00650 Foam::GeometricField<Type, PatchField, GeoMesh>::dimensionedInternalField()
00651 {
00652 this->setUpToDate();
00653 storeOldTimes();
00654 return *this;
00655 }
00656
00657
00658 template<class Type, template<class> class PatchField, class GeoMesh>
00659 typename
00660 Foam::GeometricField<Type, PatchField, GeoMesh>::InternalField&
00661 Foam::GeometricField<Type, PatchField, GeoMesh>::internalField()
00662 {
00663 this->setUpToDate();
00664 storeOldTimes();
00665 return *this;
00666 }
00667
00668
00669
00670 template<class Type, template<class> class PatchField, class GeoMesh>
00671 typename
00672 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField&
00673 Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryField()
00674 {
00675 this->setUpToDate();
00676 storeOldTimes();
00677 return boundaryField_;
00678 }
00679
00680
00681
00682 template<class Type, template<class> class PatchField, class GeoMesh>
00683 void Foam::GeometricField<Type, PatchField, GeoMesh>::storeOldTimes() const
00684 {
00685 if
00686 (
00687 field0Ptr_
00688 && timeIndex_ != this->time().timeIndex()
00689 && !(
00690 this->name().size() > 2
00691 && this->name()(this->name().size()-2, 2) == "_0"
00692 )
00693 )
00694 {
00695 storeOldTime();
00696 }
00697
00698
00699 timeIndex_ = this->time().timeIndex();
00700 }
00701
00702
00703 template<class Type, template<class> class PatchField, class GeoMesh>
00704 void Foam::GeometricField<Type, PatchField, GeoMesh>::storeOldTime() const
00705 {
00706 if (field0Ptr_)
00707 {
00708 field0Ptr_->storeOldTime();
00709
00710 if (debug)
00711 {
00712 Info<< "Storing old time field for field" << endl
00713 << this->info() << endl;
00714 }
00715
00716 *field0Ptr_ == *this;
00717 field0Ptr_->timeIndex_ = timeIndex_;
00718
00719 if (field0Ptr_->field0Ptr_)
00720 {
00721 field0Ptr_->writeOpt() = this->writeOpt();
00722 }
00723 }
00724 }
00725
00726
00727 template<class Type, template<class> class PatchField, class GeoMesh>
00728 Foam::label Foam::GeometricField<Type, PatchField, GeoMesh>::nOldTimes() const
00729 {
00730 if (field0Ptr_)
00731 {
00732 return field0Ptr_->nOldTimes() + 1;
00733 }
00734 else
00735 {
00736 return 0;
00737 }
00738 }
00739
00740
00741 template<class Type, template<class> class PatchField, class GeoMesh>
00742 const Foam::GeometricField<Type, PatchField, GeoMesh>&
00743 Foam::GeometricField<Type, PatchField, GeoMesh>::oldTime() const
00744 {
00745 if (!field0Ptr_)
00746 {
00747 field0Ptr_ = new GeometricField<Type, PatchField, GeoMesh>
00748 (
00749 IOobject
00750 (
00751 this->name() + "_0",
00752 this->time().timeName(),
00753 this->db()
00754 ),
00755 *this
00756 );
00757 }
00758 else
00759 {
00760 storeOldTimes();
00761 }
00762
00763 return *field0Ptr_;
00764 }
00765
00766
00767 template<class Type, template<class> class PatchField, class GeoMesh>
00768 Foam::GeometricField<Type, PatchField, GeoMesh>&
00769 Foam::GeometricField<Type, PatchField, GeoMesh>::oldTime()
00770 {
00771 static_cast<const GeometricField<Type, PatchField, GeoMesh>&>(*this)
00772 .oldTime();
00773
00774 return *field0Ptr_;
00775 }
00776
00777
00778
00779 template<class Type, template<class> class PatchField, class GeoMesh>
00780 void Foam::GeometricField<Type, PatchField, GeoMesh>::storePrevIter() const
00781 {
00782 if (!fieldPrevIterPtr_)
00783 {
00784 if (debug)
00785 {
00786 Info<< "Allocating previous iteration field" << endl
00787 << this->info() << endl;
00788 }
00789
00790 fieldPrevIterPtr_ = new GeometricField<Type, PatchField, GeoMesh>
00791 (
00792 this->name() + "PrevIter",
00793 *this
00794 );
00795 }
00796 else
00797 {
00798 *fieldPrevIterPtr_ == *this;
00799 }
00800 }
00801
00802
00803
00804 template<class Type, template<class> class PatchField, class GeoMesh>
00805 const Foam::GeometricField<Type, PatchField, GeoMesh>&
00806 Foam::GeometricField<Type, PatchField, GeoMesh>::prevIter() const
00807 {
00808 if (!fieldPrevIterPtr_)
00809 {
00810 FatalErrorIn
00811 (
00812 "GeometricField<Type, PatchField, GeoMesh>::prevIter() const"
00813 ) << "previous iteration field" << endl << this->info() << endl
00814 << " not stored."
00815 << " Use field.storePrevIter() at start of iteration."
00816 << abort(FatalError);
00817 }
00818
00819 return *fieldPrevIterPtr_;
00820 }
00821
00822
00823
00824 template<class Type, template<class> class PatchField, class GeoMesh>
00825 void Foam::GeometricField<Type, PatchField, GeoMesh>::
00826 correctBoundaryConditions()
00827 {
00828 this->setUpToDate();
00829 storeOldTimes();
00830 boundaryField_.evaluate();
00831 }
00832
00833
00834
00835 template<class Type, template<class> class PatchField, class GeoMesh>
00836 bool Foam::GeometricField<Type, PatchField, GeoMesh>::needReference() const
00837 {
00838
00839
00840
00841 bool needRef = true;
00842
00843 forAll(boundaryField_, patchi)
00844 {
00845 if (boundaryField_[patchi].fixesValue())
00846 {
00847 needRef = false;
00848 break;
00849 }
00850 }
00851
00852 reduce(needRef, andOp<bool>());
00853
00854 return needRef;
00855 }
00856
00857
00858 template<class Type, template<class> class PatchField, class GeoMesh>
00859 void Foam::GeometricField<Type, PatchField, GeoMesh>::relax(const scalar alpha)
00860 {
00861 operator==(prevIter() + alpha*(*this - prevIter()));
00862 }
00863
00864
00865 template<class Type, template<class> class PatchField, class GeoMesh>
00866 void Foam::GeometricField<Type, PatchField, GeoMesh>::relax()
00867 {
00868 scalar alpha = 0;
00869
00870 if (this->mesh().relax(this->name()))
00871 {
00872 alpha = this->mesh().relaxationFactor(this->name());
00873 }
00874
00875 if (alpha > 0)
00876 {
00877 relax(alpha);
00878 }
00879 }
00880
00881
00882
00883 template<class Type, template<class> class PatchField, class GeoMesh>
00884 bool Foam::GeometricField<Type, PatchField, GeoMesh>::
00885 writeData(Ostream& os) const
00886 {
00887 os << *this;
00888 return os.good();
00889 }
00890
00891
00892
00893
00894 template<class Type, template<class> class PatchField, class GeoMesh>
00895 Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >
00896 Foam::GeometricField<Type, PatchField, GeoMesh>::T() const
00897 {
00898 tmp<GeometricField<Type, PatchField, GeoMesh> > result
00899 (
00900 new GeometricField<Type, PatchField, GeoMesh>
00901 (
00902 IOobject
00903 (
00904 this->name() + ".T()",
00905 this->instance(),
00906 this->db()
00907 ),
00908 this->mesh(),
00909 this->dimensions()
00910 )
00911 );
00912
00913 Foam::T(result().internalField(), internalField());
00914 Foam::T(result().boundaryField(), boundaryField());
00915
00916 return result;
00917 }
00918
00919
00920 template<class Type, template<class> class PatchField, class GeoMesh>
00921 Foam::tmp
00922 <
00923 Foam::GeometricField
00924 <
00925 typename Foam::GeometricField<Type, PatchField, GeoMesh>::cmptType,
00926 PatchField,
00927 GeoMesh
00928 >
00929 >
00930 Foam::GeometricField<Type, PatchField, GeoMesh>::component
00931 (
00932 const direction d
00933 ) const
00934 {
00935 tmp<GeometricField<cmptType, PatchField, GeoMesh> > Component
00936 (
00937 new GeometricField<cmptType, PatchField, GeoMesh>
00938 (
00939 IOobject
00940 (
00941 this->name() + ".component(" + Foam::name(d) + ')',
00942 this->instance(),
00943 this->db()
00944 ),
00945 this->mesh(),
00946 this->dimensions()
00947 )
00948 );
00949
00950 Foam::component(Component().internalField(), internalField(), d);
00951 Foam::component(Component().boundaryField(), boundaryField(), d);
00952
00953 return Component;
00954 }
00955
00956
00957 template<class Type, template<class> class PatchField, class GeoMesh>
00958 void Foam::GeometricField<Type, PatchField, GeoMesh>::replace
00959 (
00960 const direction d,
00961 const GeometricField
00962 <
00963 typename GeometricField<Type, PatchField, GeoMesh>::cmptType,
00964 PatchField,
00965 GeoMesh
00966 >& gcf
00967 )
00968 {
00969 internalField().replace(d, gcf.internalField());
00970 boundaryField().replace(d, gcf.boundaryField());
00971 }
00972
00973
00974 template<class Type, template<class> class PatchField, class GeoMesh>
00975 void Foam::GeometricField<Type, PatchField, GeoMesh>::replace
00976 (
00977 const direction d,
00978 const dimensioned<cmptType>& ds
00979 )
00980 {
00981 internalField().replace(d, ds.value());
00982 boundaryField().replace(d, ds.value());
00983 }
00984
00985
00986 template<class Type, template<class> class PatchField, class GeoMesh>
00987 void Foam::GeometricField<Type, PatchField, GeoMesh>::max
00988 (
00989 const dimensioned<Type>& dt
00990 )
00991 {
00992 Foam::max(internalField(), internalField(), dt.value());
00993 Foam::max(boundaryField(), boundaryField(), dt.value());
00994 }
00995
00996
00997 template<class Type, template<class> class PatchField, class GeoMesh>
00998 void Foam::GeometricField<Type, PatchField, GeoMesh>::min
00999 (
01000 const dimensioned<Type>& dt
01001 )
01002 {
01003 Foam::min(internalField(), internalField(), dt.value());
01004 Foam::min(boundaryField(), boundaryField(), dt.value());
01005 }
01006
01007
01008 template<class Type, template<class> class PatchField, class GeoMesh>
01009 void Foam::GeometricField<Type, PatchField, GeoMesh>::negate()
01010 {
01011 internalField().negate();
01012 boundaryField().negate();
01013 }
01014
01015
01016
01017
01018 template<class Type, template<class> class PatchField, class GeoMesh>
01019 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator=
01020 (
01021 const GeometricField<Type, PatchField, GeoMesh>& gf
01022 )
01023 {
01024 if (this == &gf)
01025 {
01026 FatalErrorIn
01027 (
01028 "GeometricField<Type, PatchField, GeoMesh>::operator="
01029 "(const GeometricField<Type, PatchField, GeoMesh>&)"
01030 ) << "attempted assignment to self"
01031 << abort(FatalError);
01032 }
01033
01034 checkField(*this, gf, "=");
01035
01036
01037
01038 dimensionedInternalField() = gf.dimensionedInternalField();
01039 boundaryField() = gf.boundaryField();
01040 }
01041
01042
01043 template<class Type, template<class> class PatchField, class GeoMesh>
01044 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator=
01045 (
01046 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
01047 )
01048 {
01049 if (this == &(tgf()))
01050 {
01051 FatalErrorIn
01052 (
01053 "GeometricField<Type, PatchField, GeoMesh>::operator="
01054 "(const tmp<GeometricField<Type, PatchField, GeoMesh> >&)"
01055 ) << "attempted assignment to self"
01056 << abort(FatalError);
01057 }
01058
01059 const GeometricField<Type, PatchField, GeoMesh>& gf = tgf();
01060
01061 checkField(*this, gf, "=");
01062
01063
01064
01065 this->dimensions() = gf.dimensions();
01066
01067
01068 internalField().transfer
01069 (
01070 const_cast<Field<Type>&>(gf.internalField())
01071 );
01072
01073 boundaryField() = gf.boundaryField();
01074
01075 tgf.clear();
01076 }
01077
01078
01079 template<class Type, template<class> class PatchField, class GeoMesh>
01080 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator=
01081 (
01082 const dimensioned<Type>& dt
01083 )
01084 {
01085 dimensionedInternalField() = dt;
01086 boundaryField() = dt.value();
01087 }
01088
01089
01090 template<class Type, template<class> class PatchField, class GeoMesh>
01091 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator==
01092 (
01093 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
01094 )
01095 {
01096 const GeometricField<Type, PatchField, GeoMesh>& gf = tgf();
01097
01098 checkField(*this, gf, "==");
01099
01100
01101
01102 dimensionedInternalField() = gf.dimensionedInternalField();
01103 boundaryField() == gf.boundaryField();
01104
01105 tgf.clear();
01106 }
01107
01108
01109 template<class Type, template<class> class PatchField, class GeoMesh>
01110 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator==
01111 (
01112 const dimensioned<Type>& dt
01113 )
01114 {
01115 dimensionedInternalField() = dt;
01116 boundaryField() == dt.value();
01117 }
01118
01119
01120 #define COMPUTED_ASSIGNMENT(TYPE, op) \
01121 \
01122 template<class Type, template<class> class PatchField, class GeoMesh> \
01123 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \
01124 ( \
01125 const GeometricField<TYPE, PatchField, GeoMesh>& gf \
01126 ) \
01127 { \
01128 checkField(*this, gf, #op); \
01129 \
01130 dimensionedInternalField() op gf.dimensionedInternalField(); \
01131 boundaryField() op gf.boundaryField(); \
01132 } \
01133 \
01134 template<class Type, template<class> class PatchField, class GeoMesh> \
01135 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \
01136 ( \
01137 const tmp<GeometricField<TYPE, PatchField, GeoMesh> >& tgf \
01138 ) \
01139 { \
01140 operator op(tgf()); \
01141 tgf.clear(); \
01142 } \
01143 \
01144 template<class Type, template<class> class PatchField, class GeoMesh> \
01145 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \
01146 ( \
01147 const dimensioned<TYPE>& dt \
01148 ) \
01149 { \
01150 dimensionedInternalField() op dt; \
01151 boundaryField() op dt.value(); \
01152 }
01153
01154 COMPUTED_ASSIGNMENT(Type, +=)
01155 COMPUTED_ASSIGNMENT(Type, -=)
01156 COMPUTED_ASSIGNMENT(scalar, *=)
01157 COMPUTED_ASSIGNMENT(scalar, /=)
01158
01159 #undef COMPUTED_ASSIGNMENT
01160
01161
01162
01163
01164 template<class Type, template<class> class PatchField, class GeoMesh>
01165 Foam::Ostream& Foam::operator<<
01166 (
01167 Ostream& os,
01168 const GeometricField<Type, PatchField, GeoMesh>& gf
01169 )
01170 {
01171 gf.dimensionedInternalField().writeData(os, "internalField");
01172 os << nl;
01173 gf.boundaryField().writeEntry("boundaryField", os);
01174
01175
01176 os.check
01177 (
01178 "Ostream& operator<<(Ostream&, "
01179 "const GeometricField<Type, PatchField, GeoMesh>&)"
01180 );
01181
01182 return (os);
01183 }
01184
01185
01186 template<class Type, template<class> class PatchField, class GeoMesh>
01187 Foam::Ostream& Foam::operator<<
01188 (
01189 Ostream& os,
01190 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
01191 )
01192 {
01193 os << tgf();
01194 tgf.clear();
01195 return os;
01196 }
01197
01198
01199
01200
01201 #undef checkField
01202
01203
01204
01205 #include "GeometricBoundaryField.C"
01206 #include "GeometricFieldFunctions.C"
01207
01208