mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Updated GeometricField creation from io and mesh via dictionary
This commit is contained in:
@ -28,8 +28,151 @@ License
|
|||||||
#include "globalMeshData.H"
|
#include "globalMeshData.H"
|
||||||
#include "cyclicPolyPatch.H"
|
#include "cyclicPolyPatch.H"
|
||||||
|
|
||||||
|
template<class Type, template<class> class PatchField, class GeoMesh>
|
||||||
|
void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
|
||||||
|
readField
|
||||||
|
(
|
||||||
|
const DimensionedField<Type, GeoMesh>& field,
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this->setSize(bmesh_.size());
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
Info<< "GeometricField<Type, PatchField, GeoMesh>::"
|
||||||
|
"GeometricBoundaryField::readField"
|
||||||
|
"("
|
||||||
|
"const DimensionedField<Type, GeoMesh>&, "
|
||||||
|
"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<Type>::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<Type>::New
|
||||||
|
(
|
||||||
|
emptyPolyPatch::typeName,
|
||||||
|
bmesh_[patchi],
|
||||||
|
field
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool found = dict.found(bmesh_[patchi].name());
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
this->set
|
||||||
|
(
|
||||||
|
patchi,
|
||||||
|
PatchField<Type>::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<Type, PatchField, GeoMesh>::"
|
||||||
|
"GeometricBoundaryField::readField"
|
||||||
|
"("
|
||||||
|
"const DimensionedField<Type, GeoMesh>&, "
|
||||||
|
"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<Type, PatchField, GeoMesh>::"
|
||||||
|
"GeometricBoundaryField::readField"
|
||||||
|
"("
|
||||||
|
"const DimensionedField<Type, GeoMesh>&, "
|
||||||
|
"const dictionary&"
|
||||||
|
")",
|
||||||
|
dict
|
||||||
|
) << "Cannot find patchField entry for "
|
||||||
|
<< bmesh_[patchi].name() << exit(FatalIOError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type, template<class> class PatchField, class GeoMesh>
|
||||||
|
Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
|
||||||
|
GeometricBoundaryField
|
||||||
|
(
|
||||||
|
const BoundaryMesh& bmesh
|
||||||
|
)
|
||||||
|
:
|
||||||
|
FieldField<PatchField, Type>(bmesh.size()),
|
||||||
|
bmesh_(bmesh)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class Type, template<class> class PatchField, class GeoMesh>
|
template<class Type, template<class> class PatchField, class GeoMesh>
|
||||||
Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
|
Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
|
||||||
GeometricBoundaryField
|
GeometricBoundaryField
|
||||||
@ -260,130 +403,7 @@ GeometricBoundaryField
|
|||||||
FieldField<PatchField, Type>(bmesh.size()),
|
FieldField<PatchField, Type>(bmesh.size()),
|
||||||
bmesh_(bmesh)
|
bmesh_(bmesh)
|
||||||
{
|
{
|
||||||
if (debug)
|
readField(field, dict);
|
||||||
{
|
|
||||||
Info<< "GeometricField<Type, PatchField, GeoMesh>::"
|
|
||||||
"GeometricBoundaryField::"
|
|
||||||
"GeometricBoundaryField"
|
|
||||||
"("
|
|
||||||
"const BoundaryMesh&, "
|
|
||||||
"const DimensionedField<Type, GeoMesh>&, "
|
|
||||||
"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<Type>::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<Type>::New
|
|
||||||
(
|
|
||||||
emptyPolyPatch::typeName,
|
|
||||||
bmesh_[patchi],
|
|
||||||
field
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool found = dict.found(bmesh_[patchi].name());
|
|
||||||
|
|
||||||
if (found)
|
|
||||||
{
|
|
||||||
this->set
|
|
||||||
(
|
|
||||||
patchi,
|
|
||||||
PatchField<Type>::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<Type, PatchField, GeoMesh>::"
|
|
||||||
"GeometricBoundaryField::"
|
|
||||||
"GeometricBoundaryField"
|
|
||||||
"("
|
|
||||||
"const BoundaryMesh&, "
|
|
||||||
"const DimensionedField<Type, GeoMesh>&, "
|
|
||||||
"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<Type, PatchField, GeoMesh>::"
|
|
||||||
"GeometricBoundaryField::"
|
|
||||||
"GeometricBoundaryField"
|
|
||||||
"("
|
|
||||||
"const BoundaryMesh&, "
|
|
||||||
"const DimensionedField<Type, GeoMesh>&, "
|
|
||||||
"const dictionary&"
|
|
||||||
")",
|
|
||||||
dict
|
|
||||||
) << "Cannot find patchField entry for "
|
|
||||||
<< bmesh_[patchi].name() << exit(FatalIOError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -47,57 +47,33 @@ if ((gf1).mesh() != (gf2).mesh()) \
|
|||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type, template<class> class PatchField, class GeoMesh>
|
template<class Type, template<class> class PatchField, class GeoMesh>
|
||||||
Foam::tmp
|
void Foam::GeometricField<Type, PatchField, GeoMesh>::readFields
|
||||||
<
|
|
||||||
typename Foam::GeometricField<Type, PatchField, GeoMesh>::
|
|
||||||
GeometricBoundaryField
|
|
||||||
>
|
|
||||||
Foam::GeometricField<Type, PatchField, GeoMesh>::readField
|
|
||||||
(
|
(
|
||||||
const dictionary& fieldDict
|
const dictionary& dict
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DimensionedField<Type, GeoMesh>::readField(fieldDict, "internalField");
|
DimensionedField<Type, GeoMesh>::readField(dict, "internalField");
|
||||||
|
|
||||||
tmp<GeometricBoundaryField> tboundaryField
|
boundaryField_.readField(*this, dict.subDict("boundaryField"));
|
||||||
(
|
|
||||||
new GeometricBoundaryField
|
|
||||||
(
|
|
||||||
this->mesh().boundary(),
|
|
||||||
*this,
|
|
||||||
fieldDict.subDict("boundaryField")
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (fieldDict.found("referenceLevel"))
|
if (dict.found("referenceLevel"))
|
||||||
{
|
{
|
||||||
Type fieldAverage(pTraits<Type>(fieldDict.lookup("referenceLevel")));
|
Type fieldAverage(pTraits<Type>(dict.lookup("referenceLevel")));
|
||||||
|
|
||||||
Field<Type>::operator+=(fieldAverage);
|
Field<Type>::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 Type, template<class> class PatchField, class GeoMesh>
|
template<class Type, template<class> class PatchField, class GeoMesh>
|
||||||
Foam::tmp
|
void Foam::GeometricField<Type, PatchField, GeoMesh>::readFields()
|
||||||
<
|
|
||||||
typename Foam::GeometricField<Type, PatchField, GeoMesh>::
|
|
||||||
GeometricBoundaryField
|
|
||||||
>
|
|
||||||
Foam::GeometricField<Type, PatchField, GeoMesh>::readField(Istream& is)
|
|
||||||
{
|
{
|
||||||
return readField
|
const IOdictionary dict
|
||||||
(
|
|
||||||
IOdictionary
|
|
||||||
(
|
(
|
||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
@ -108,9 +84,12 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::readField(Istream& is)
|
|||||||
IOobject::NO_WRITE,
|
IOobject::NO_WRITE,
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
is
|
this->readStream(typeName)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this->close();
|
||||||
|
|
||||||
|
readFields(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -132,8 +111,7 @@ bool Foam::GeometricField<Type, PatchField, GeoMesh>::readIfPresent()
|
|||||||
}
|
}
|
||||||
else if (this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk())
|
else if (this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk())
|
||||||
{
|
{
|
||||||
boundaryField_.transfer(readField(this->readStream(typeName))());
|
readFields();
|
||||||
this->close();
|
|
||||||
|
|
||||||
// Check compatibility between field and mesh
|
// Check compatibility between field and mesh
|
||||||
if (this->size() != GeoMesh::size(this->mesh()))
|
if (this->size() != GeoMesh::size(this->mesh()))
|
||||||
@ -360,9 +338,9 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
|
|||||||
timeIndex_(this->time().timeIndex()),
|
timeIndex_(this->time().timeIndex()),
|
||||||
field0Ptr_(NULL),
|
field0Ptr_(NULL),
|
||||||
fieldPrevIterPtr_(NULL),
|
fieldPrevIterPtr_(NULL),
|
||||||
boundaryField_(*this, readField(this->readStream(typeName)))
|
boundaryField_(mesh.boundary())
|
||||||
{
|
{
|
||||||
this->close();
|
readFields();
|
||||||
|
|
||||||
// Check compatibility between field and mesh
|
// Check compatibility between field and mesh
|
||||||
|
|
||||||
@ -401,8 +379,10 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
|
|||||||
timeIndex_(this->time().timeIndex()),
|
timeIndex_(this->time().timeIndex()),
|
||||||
field0Ptr_(NULL),
|
field0Ptr_(NULL),
|
||||||
fieldPrevIterPtr_(NULL),
|
fieldPrevIterPtr_(NULL),
|
||||||
boundaryField_(*this, readField(dict))
|
boundaryField_(mesh.boundary())
|
||||||
{
|
{
|
||||||
|
readFields(dict);
|
||||||
|
|
||||||
// Check compatibility between field and mesh
|
// Check compatibility between field and mesh
|
||||||
|
|
||||||
if (this->size() != GeoMesh::size(this->mesh()))
|
if (this->size() != GeoMesh::size(this->mesh()))
|
||||||
|
|||||||
@ -117,6 +117,9 @@ public:
|
|||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from a BoundaryMesh
|
||||||
|
GeometricBoundaryField(const BoundaryMesh&);
|
||||||
|
|
||||||
//- Construct from a BoundaryMesh,
|
//- Construct from a BoundaryMesh,
|
||||||
// reference to the internal field
|
// reference to the internal field
|
||||||
// and a patch type
|
// and a patch type
|
||||||
@ -177,6 +180,13 @@ public:
|
|||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
|
|
||||||
|
//- Read the boundary field
|
||||||
|
void readField
|
||||||
|
(
|
||||||
|
const DimensionedField<Type, GeoMesh>& field,
|
||||||
|
const dictionary& dict
|
||||||
|
);
|
||||||
|
|
||||||
//- Update the boundary condition coefficients
|
//- Update the boundary condition coefficients
|
||||||
void updateCoeffs();
|
void updateCoeffs();
|
||||||
|
|
||||||
@ -247,10 +257,10 @@ private:
|
|||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Read the field from the dictionary
|
//- Read the field from the dictionary
|
||||||
tmp<GeometricBoundaryField> readField(const dictionary&);
|
void readFields(const dictionary&);
|
||||||
|
|
||||||
//- Read the field from the given stream
|
//- Read the field - create the field dictionary on-the-fly
|
||||||
tmp<GeometricBoundaryField> readField(Istream& is);
|
void readFields();
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user