diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C index 20d15fbe81..c1b516e97c 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C @@ -28,8 +28,151 @@ License #include "globalMeshData.H" #include "cyclicPolyPatch.H" +template class PatchField, class GeoMesh> +void Foam::GeometricField::GeometricBoundaryField:: +readField +( + const DimensionedField& field, + const dictionary& dict +) +{ + this->setSize(bmesh_.size()); + + if (debug) + { + Info<< "GeometricField::" + "GeometricBoundaryField::readField" + "(" + "const DimensionedField&, " + "const dictionary&" + ")" + << endl; + } + + // Patch or patch-groups. (using non-wild card entries of dictionaries) + forAllConstIter(dictionary, dict, iter) + { + if (iter().isDict() && !iter().keyword().isPattern()) + { + const labelList patchIDs = bmesh_.findIndices + ( + iter().keyword(), + true + ); + + forAll(patchIDs, i) + { + label patchi = patchIDs[i]; + + this->set + ( + patchi, + PatchField::New + ( + bmesh_[patchi], + field, + iter().dict() + ) + ); + } + } + } + + // Check for wildcard patch overrides + forAll(bmesh_, patchi) + { + if (!this->set(patchi)) + { + if (bmesh_[patchi].type() == emptyPolyPatch::typeName) + { + this->set + ( + patchi, + PatchField::New + ( + emptyPolyPatch::typeName, + bmesh_[patchi], + field + ) + ); + } + else + { + bool found = dict.found(bmesh_[patchi].name()); + + if (found) + { + this->set + ( + patchi, + PatchField::New + ( + bmesh_[patchi], + field, + dict.subDict(bmesh_[patchi].name()) + ) + ); + } + } + } + } + + + // Check for any unset patches + forAll(bmesh_, patchi) + { + if (!this->set(patchi)) + { + if (bmesh_[patchi].type() == cyclicPolyPatch::typeName) + { + FatalIOErrorIn + ( + "GeometricField::" + "GeometricBoundaryField::readField" + "(" + "const DimensionedField&, " + "const dictionary&" + ")", + dict + ) << "Cannot find patchField entry for cyclic " + << bmesh_[patchi].name() << endl + << "Is your field uptodate with split cyclics?" << endl + << "Run foamUpgradeCyclics to convert mesh and fields" + << " to split cyclics." << exit(FatalIOError); + } + else + { + FatalIOErrorIn + ( + "GeometricField::" + "GeometricBoundaryField::readField" + "(" + "const DimensionedField&, " + "const dictionary&" + ")", + dict + ) << "Cannot find patchField entry for " + << bmesh_[patchi].name() << exit(FatalIOError); + } + } + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +template class PatchField, class GeoMesh> +Foam::GeometricField::GeometricBoundaryField:: +GeometricBoundaryField +( + const BoundaryMesh& bmesh +) +: + FieldField(bmesh.size()), + bmesh_(bmesh) +{} + + template class PatchField, class GeoMesh> Foam::GeometricField::GeometricBoundaryField:: GeometricBoundaryField @@ -260,130 +403,7 @@ GeometricBoundaryField FieldField(bmesh.size()), bmesh_(bmesh) { - if (debug) - { - Info<< "GeometricField::" - "GeometricBoundaryField::" - "GeometricBoundaryField" - "(" - "const BoundaryMesh&, " - "const DimensionedField&, " - "const dictionary&" - ")" - << endl; - } - - - // Patch or patch-groups. (using non-wild card entries of dictionaries) - forAllConstIter(dictionary, dict, iter) - { - if (iter().isDict() && !iter().keyword().isPattern()) - { - const labelList patchIDs = bmesh_.findIndices - ( - iter().keyword(), - true - ); - - forAll(patchIDs, i) - { - label patchi = patchIDs[i]; - this->set - ( - patchi, - PatchField::New - ( - bmesh_[patchi], - field, - iter().dict() - ) - ); - } - } - } - - // Check for wildcard patch overrides - forAll(bmesh_, patchi) - { - if (!this->set(patchi)) - { - if (bmesh_[patchi].type() == emptyPolyPatch::typeName) - { - this->set - ( - patchi, - PatchField::New - ( - emptyPolyPatch::typeName, - bmesh_[patchi], - field - ) - ); - } - else - { - bool found = dict.found(bmesh_[patchi].name()); - - if (found) - { - this->set - ( - patchi, - PatchField::New - ( - bmesh_[patchi], - field, - dict.subDict(bmesh_[patchi].name()) - ) - ); - } - } - } - } - - - // Check for any unset patches - forAll(bmesh_, patchi) - { - if (!this->set(patchi)) - { - if (bmesh_[patchi].type() == cyclicPolyPatch::typeName) - { - FatalIOErrorIn - ( - "GeometricField::" - "GeometricBoundaryField::" - "GeometricBoundaryField" - "(" - "const BoundaryMesh&, " - "const DimensionedField&, " - "const dictionary&" - ")", - dict - ) << "Cannot find patchField entry for cyclic " - << bmesh_[patchi].name() << endl - << "Is your field uptodate with split cyclics?" << endl - << "Run foamUpgradeCyclics to convert mesh and fields" - << " to split cyclics." << exit(FatalIOError); - } - else - { - FatalIOErrorIn - ( - "GeometricField::" - "GeometricBoundaryField::" - "GeometricBoundaryField" - "(" - "const BoundaryMesh&, " - "const DimensionedField&, " - "const dictionary&" - ")", - dict - ) << "Cannot find patchField entry for " - << bmesh_[patchi].name() << exit(FatalIOError); - } - } - } + readField(field, dict); } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index 8898b162f4..2b82169561 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -47,70 +47,49 @@ if ((gf1).mesh() != (gf2).mesh()) \ // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // template class PatchField, class GeoMesh> -Foam::tmp -< - typename Foam::GeometricField:: - GeometricBoundaryField -> -Foam::GeometricField::readField +void Foam::GeometricField::readFields ( - const dictionary& fieldDict + const dictionary& dict ) { - DimensionedField::readField(fieldDict, "internalField"); + DimensionedField::readField(dict, "internalField"); - tmp tboundaryField - ( - new GeometricBoundaryField - ( - this->mesh().boundary(), - *this, - fieldDict.subDict("boundaryField") - ) - ); + boundaryField_.readField(*this, dict.subDict("boundaryField")); - if (fieldDict.found("referenceLevel")) + if (dict.found("referenceLevel")) { - Type fieldAverage(pTraits(fieldDict.lookup("referenceLevel"))); + Type fieldAverage(pTraits(dict.lookup("referenceLevel"))); Field::operator+=(fieldAverage); - GeometricBoundaryField& boundaryField = tboundaryField(); - - forAll(boundaryField, patchi) + forAll(boundaryField_, patchi) { - boundaryField[patchi] == boundaryField[patchi] + fieldAverage; + boundaryField_[patchi] == boundaryField_[patchi] + fieldAverage; } } - - return tboundaryField; } template class PatchField, class GeoMesh> -Foam::tmp -< - typename Foam::GeometricField:: - GeometricBoundaryField -> -Foam::GeometricField::readField(Istream& is) +void Foam::GeometricField::readFields() { - return readField + const IOdictionary dict ( - IOdictionary + IOobject ( - IOobject - ( - this->name(), - this->time().timeName(), - this->db(), - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - is - ) + this->name(), + this->time().timeName(), + this->db(), + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + this->readStream(typeName) ); + + this->close(); + + readFields(dict); } @@ -132,8 +111,7 @@ bool Foam::GeometricField::readIfPresent() } else if (this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk()) { - boundaryField_.transfer(readField(this->readStream(typeName))()); - this->close(); + readFields(); // Check compatibility between field and mesh if (this->size() != GeoMesh::size(this->mesh())) @@ -360,9 +338,9 @@ Foam::GeometricField::GeometricField timeIndex_(this->time().timeIndex()), field0Ptr_(NULL), fieldPrevIterPtr_(NULL), - boundaryField_(*this, readField(this->readStream(typeName))) + boundaryField_(mesh.boundary()) { - this->close(); + readFields(); // Check compatibility between field and mesh @@ -401,8 +379,10 @@ Foam::GeometricField::GeometricField timeIndex_(this->time().timeIndex()), field0Ptr_(NULL), fieldPrevIterPtr_(NULL), - boundaryField_(*this, readField(dict)) + boundaryField_(mesh.boundary()) { + readFields(dict); + // Check compatibility between field and mesh if (this->size() != GeoMesh::size(this->mesh())) diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index 5aef9e0fb8..ba510d77e8 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -117,6 +117,9 @@ public: // Constructors + //- Construct from a BoundaryMesh + GeometricBoundaryField(const BoundaryMesh&); + //- Construct from a BoundaryMesh, // reference to the internal field // and a patch type @@ -177,6 +180,13 @@ public: // Member functions + //- Read the boundary field + void readField + ( + const DimensionedField& field, + const dictionary& dict + ); + //- Update the boundary condition coefficients void updateCoeffs(); @@ -247,10 +257,10 @@ private: // Private Member Functions //- Read the field from the dictionary - tmp readField(const dictionary&); + void readFields(const dictionary&); - //- Read the field from the given stream - tmp readField(Istream& is); + //- Read the field - create the field dictionary on-the-fly + void readFields(); public: