mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Added film functions to map between regions using AMI functionality
This commit is contained in:
@ -190,6 +190,66 @@ bool Foam::regionModels::regionModel::read(const dictionary& dict)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::label Foam::regionModels::regionModel::nbrCoupledPatchID
|
||||||
|
(
|
||||||
|
const regionModel& nbrRegion,
|
||||||
|
const label regionPatchI
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
label nbrPatchI = -1;
|
||||||
|
|
||||||
|
// region
|
||||||
|
const fvMesh& nbrRegionMesh = nbrRegion.regionMesh();
|
||||||
|
|
||||||
|
// boundary mesh
|
||||||
|
const polyBoundaryMesh& nbrPbm = nbrRegionMesh.boundaryMesh();
|
||||||
|
|
||||||
|
const mappedPatchBase& mpb =
|
||||||
|
refCast<const mappedPatchBase>
|
||||||
|
(
|
||||||
|
regionMesh().boundaryMesh()[regionPatchI]
|
||||||
|
);
|
||||||
|
|
||||||
|
// sample patch name on the primary region
|
||||||
|
const word& primaryPatchName = mpb.samplePatch();
|
||||||
|
|
||||||
|
// find patch on nbr region that has the same sample patch name
|
||||||
|
forAll(nbrRegion.intCoupledPatchIDs(), j)
|
||||||
|
{
|
||||||
|
const label nbrRegionPatchI = nbrRegion.intCoupledPatchIDs()[j];
|
||||||
|
|
||||||
|
const mappedPatchBase& mpb =
|
||||||
|
refCast<const mappedPatchBase>(nbrPbm[nbrRegionPatchI]);
|
||||||
|
|
||||||
|
if (mpb.samplePatch() == primaryPatchName)
|
||||||
|
{
|
||||||
|
nbrPatchI = nbrRegionPatchI;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nbrPatchI == -1)
|
||||||
|
{
|
||||||
|
const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI];
|
||||||
|
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"Foam::tmp<Foam::Field<Type> > "
|
||||||
|
"Foam::regionModels::regionModel::nbrCoupledPatchID"
|
||||||
|
"("
|
||||||
|
"const regionModel& , "
|
||||||
|
"const label"
|
||||||
|
") const"
|
||||||
|
)
|
||||||
|
<< "Unable to find patch pair for local patch "
|
||||||
|
<< p.name() << " and region " << nbrRegion.name()
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nbrPatchI;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::regionModels::regionModel::regionModel(const fvMesh& mesh)
|
Foam::regionModels::regionModel::regionModel(const fvMesh& mesh)
|
||||||
|
|||||||
@ -219,6 +219,46 @@ public:
|
|||||||
|
|
||||||
// Helper
|
// Helper
|
||||||
|
|
||||||
|
//- Return the coupled patch ID paired with coupled patch
|
||||||
|
// regionPatchI
|
||||||
|
label nbrCoupledPatchID
|
||||||
|
(
|
||||||
|
const regionModel& nbrRegion,
|
||||||
|
const label regionPatchI
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Map patch field from another region model to local patch
|
||||||
|
template<class Type>
|
||||||
|
tmp<Foam::Field<Type> > mapRegionPatchField
|
||||||
|
(
|
||||||
|
const regionModel& nbrRegion,
|
||||||
|
const label regionPatchI,
|
||||||
|
const label nbrPatchI,
|
||||||
|
const Field<Type>& nbrField,
|
||||||
|
const bool flip = false
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Map patch field from another region model to local patch
|
||||||
|
template<class Type>
|
||||||
|
tmp<Field<Type> > mapRegionPatchField
|
||||||
|
(
|
||||||
|
const word& regionModelName,
|
||||||
|
const word& fieldName,
|
||||||
|
const label regionPatchI,
|
||||||
|
const bool flip = false
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Map patch internal field from another region model to local
|
||||||
|
// patch
|
||||||
|
template<class Type>
|
||||||
|
tmp<Field<Type> > mapRegionPatchInternalField
|
||||||
|
(
|
||||||
|
const word& regionModelName,
|
||||||
|
const word& fieldName,
|
||||||
|
const label regionPatchI,
|
||||||
|
const bool flip = false
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Convert a local region field to the primary region
|
//- Convert a local region field to the primary region
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void toPrimary
|
void toPrimary
|
||||||
|
|||||||
@ -23,6 +23,164 @@ License
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::tmp<Foam::Field<Type> >
|
||||||
|
Foam::regionModels::regionModel::mapRegionPatchField
|
||||||
|
(
|
||||||
|
const regionModel& nbrRegion,
|
||||||
|
const label regionPatchI,
|
||||||
|
const label nbrPatchI,
|
||||||
|
const Field<Type>& nbrField,
|
||||||
|
const bool flip
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
const fvMesh& nbrRegionMesh = nbrRegion.regionMesh();
|
||||||
|
|
||||||
|
const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI];
|
||||||
|
|
||||||
|
const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchI];
|
||||||
|
|
||||||
|
int oldTag = UPstream::msgType();
|
||||||
|
UPstream::msgType() = oldTag + 1;
|
||||||
|
|
||||||
|
AMIPatchToPatchInterpolation ami(p, nbrP, faceAreaIntersect::tmMesh, flip);
|
||||||
|
|
||||||
|
tmp<Field<Type> > tresult(ami.interpolateToSource(nbrField));
|
||||||
|
|
||||||
|
UPstream::msgType() = oldTag;
|
||||||
|
|
||||||
|
return tresult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::tmp<Foam::Field<Type> >
|
||||||
|
Foam::regionModels::regionModel::mapRegionPatchField
|
||||||
|
(
|
||||||
|
const word& regionModelName,
|
||||||
|
const word& fieldName,
|
||||||
|
const label regionPatchI,
|
||||||
|
const bool flip
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
|
||||||
|
|
||||||
|
const regionModel& nbrRegion =
|
||||||
|
this->primaryMesh_.lookupObject<regionModel>(regionModelName);
|
||||||
|
|
||||||
|
const fvMesh& nbrRegionMesh = nbrRegion.regionMesh();
|
||||||
|
|
||||||
|
const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI];
|
||||||
|
|
||||||
|
if (nbrRegionMesh.foundObject<fieldType>(fieldName))
|
||||||
|
{
|
||||||
|
const fieldType& nbrField =
|
||||||
|
nbrRegionMesh.lookupObject<fieldType>(fieldName);
|
||||||
|
|
||||||
|
const label nbrPatchI = nbrCoupledPatchID(nbrRegion, regionPatchI);
|
||||||
|
|
||||||
|
const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchI];
|
||||||
|
|
||||||
|
int oldTag = UPstream::msgType();
|
||||||
|
UPstream::msgType() = oldTag + 1;
|
||||||
|
|
||||||
|
AMIPatchToPatchInterpolation ami
|
||||||
|
(
|
||||||
|
p,
|
||||||
|
nbrP,
|
||||||
|
faceAreaIntersect::tmMesh,
|
||||||
|
flip
|
||||||
|
);
|
||||||
|
|
||||||
|
const Field<Type>& nbrFieldp = nbrField.boundaryField()[nbrPatchI];
|
||||||
|
|
||||||
|
tmp<Field<Type> > tresult(ami.interpolateToSource(nbrFieldp));
|
||||||
|
|
||||||
|
UPstream::msgType() = oldTag;
|
||||||
|
|
||||||
|
return tresult;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return
|
||||||
|
tmp<Field<Type> >
|
||||||
|
(
|
||||||
|
new Field<Type>
|
||||||
|
(
|
||||||
|
p.size(),
|
||||||
|
pTraits<Type>::zero
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::tmp<Foam::Field<Type> >
|
||||||
|
Foam::regionModels::regionModel::mapRegionPatchInternalField
|
||||||
|
(
|
||||||
|
const word& regionModelName,
|
||||||
|
const word& fieldName,
|
||||||
|
const label regionPatchI,
|
||||||
|
const bool flip
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
|
||||||
|
|
||||||
|
const regionModel& nbrRegion =
|
||||||
|
this->primaryMesh_.lookupObject<regionModel>(regionModelName);
|
||||||
|
|
||||||
|
const fvMesh& nbrRegionMesh = nbrRegion.regionMesh();
|
||||||
|
|
||||||
|
const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI];
|
||||||
|
|
||||||
|
if (nbrRegionMesh.foundObject<fieldType>(fieldName))
|
||||||
|
{
|
||||||
|
const fieldType& nbrField =
|
||||||
|
nbrRegionMesh.lookupObject<fieldType>(fieldName);
|
||||||
|
|
||||||
|
const label nbrPatchI = nbrCoupledPatchID(nbrRegion, regionPatchI);
|
||||||
|
|
||||||
|
const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchI];
|
||||||
|
|
||||||
|
int oldTag = UPstream::msgType();
|
||||||
|
UPstream::msgType() = oldTag + 1;
|
||||||
|
|
||||||
|
AMIPatchToPatchInterpolation ami
|
||||||
|
(
|
||||||
|
p,
|
||||||
|
nbrP,
|
||||||
|
faceAreaIntersect::tmMesh,
|
||||||
|
flip
|
||||||
|
);
|
||||||
|
|
||||||
|
const fvPatchField<Type>& nbrFieldp =
|
||||||
|
nbrField.boundaryField()[nbrPatchI];
|
||||||
|
|
||||||
|
tmp<Field<Type> > tresult
|
||||||
|
(
|
||||||
|
ami.interpolateToSource(nbrFieldp.patchInternalField())
|
||||||
|
);
|
||||||
|
|
||||||
|
UPstream::msgType() = oldTag;
|
||||||
|
|
||||||
|
return tresult;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return
|
||||||
|
tmp<Field<Type> >
|
||||||
|
(
|
||||||
|
new Field<Type>
|
||||||
|
(
|
||||||
|
p.size(),
|
||||||
|
pTraits<Type>::zero
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void Foam::regionModels::regionModel::toPrimary
|
void Foam::regionModels::regionModel::toPrimary
|
||||||
(
|
(
|
||||||
|
|||||||
Reference in New Issue
Block a user