STYLE: use patch type instead of cloning list of the same

This commit is contained in:
Mark Olesen
2024-01-11 12:33:43 +01:00
parent a4cbb33373
commit f485093d37
7 changed files with 99 additions and 211 deletions

View File

@ -97,7 +97,7 @@ Foam::eddyViscosity<BasicTurbulenceModel>::R() const
if if
( (
!fvPatchField<symmTensor>::patchConstructorTablePtr_ !fvPatchField<symmTensor>::patchConstructorTablePtr_
->found(patchFieldTypes[i]) ->contains(patchFieldTypes[i])
) )
{ {
patchFieldTypes[i] = fvPatchFieldBase::calculatedType(); patchFieldTypes[i] = fvPatchFieldBase::calculatedType();

View File

@ -159,7 +159,7 @@ Foam::fvMeshSubset::interpolate
( (
vf.boundaryField()[basePatchId], vf.boundaryField()[basePatchId],
subPatch, subPatch,
result(), result.internalField(),
mapper mapper
) )
); );
@ -526,7 +526,7 @@ Foam::fvMeshSubset::interpolate
( (
vf.boundaryField()[patchMap[patchi]], vf.boundaryField()[patchMap[patchi]],
subPatch, subPatch,
result(), result.internalField(),
directPointPatchFieldMapper(directAddressing) directPointPatchFieldMapper(directAddressing)
) )
); );

View File

@ -30,38 +30,18 @@ License
#include "directFvPatchFieldMapper.H" #include "directFvPatchFieldMapper.H"
#include "Time.H" #include "Time.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh>> singleCellFvMesh::interpolate Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::singleCellFvMesh::interpolate
( (
const GeometricField<Type, fvPatchField, volMesh>& vf const GeometricField<Type, fvPatchField, volMesh>& vf
) const ) const
{ {
// 1. Create the complete field with dummy patch fields // 1. Create the complete field with dummy patch fields
PtrList<fvPatchField<Type>> patchFields(vf.boundaryField().size());
forAll(patchFields, patchi) tmp<GeometricField<Type, fvPatchField, volMesh>> tresult
{
patchFields.set
(
patchi,
fvPatchField<Type>::New
(
fvPatchFieldBase::calculatedType(),
boundary()[patchi],
fvPatchField<Type>::Internal::null()
)
);
}
// Create the complete field from the pieces
tmp<GeometricField<Type, fvPatchField, volMesh>> tresF
( (
new GeometricField<Type, fvPatchField, volMesh> new GeometricField<Type, fvPatchField, volMesh>
( (
@ -74,19 +54,18 @@ tmp<GeometricField<Type, fvPatchField, volMesh>> singleCellFvMesh::interpolate
IOobject::NO_WRITE IOobject::NO_WRITE
), ),
*this, *this,
Type(gAverage(vf.primitiveField())),
vf.dimensions(), vf.dimensions(),
Field<Type>(1, gAverage(vf)), fvPatchFieldBase::calculatedType()
patchFields
) )
); );
GeometricField<Type, fvPatchField, volMesh>& resF = tresF.ref(); auto& result = tresult.ref();
// 2. Change the fvPatchFields to the correct type using a mapper // 2. Change the fvPatchFields to the correct type using a mapper
// constructor (with reference to the now correct internal field) // constructor (with reference to the now correct internal field)
typename GeometricField<Type, fvPatchField, volMesh>:: auto& bf = result.boundaryFieldRef();
Boundary& bf = resF.boundaryFieldRef();
if (agglomerate()) if (agglomerate())
{ {
@ -117,7 +96,7 @@ tmp<GeometricField<Type, fvPatchField, volMesh>> singleCellFvMesh::interpolate
( (
vf.boundaryField()[patchi], vf.boundaryField()[patchi],
boundary()[patchi], boundary()[patchi],
resF(), result.internalField(),
agglomPatchFieldMapper(coarseToFine, coarseWeights) agglomPatchFieldMapper(coarseToFine, coarseWeights)
) )
); );
@ -136,19 +115,15 @@ tmp<GeometricField<Type, fvPatchField, volMesh>> singleCellFvMesh::interpolate
( (
vf.boundaryField()[patchi], vf.boundaryField()[patchi],
boundary()[patchi], boundary()[patchi],
resF(), result.internalField(),
directFvPatchFieldMapper(map) directFvPatchFieldMapper(map)
) )
); );
} }
} }
return tresF; return tresult;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -94,13 +94,17 @@ createZeroBoundaryPtr
// on symmetry patches (not a good practice either way) // on symmetry patches (not a good practice either way)
const fvBoundaryMesh& bm = mesh.boundary(); const fvBoundaryMesh& bm = mesh.boundary();
wordList actualPatchTypes(bm.size(), word::null); wordList actualPatchTypes(bm.size(), word::null);
forAll(actualPatchTypes, pI) forAll(actualPatchTypes, patchi)
{ {
auto patchTypeCstrIter = if
fvPatchField<Type>::patchConstructorTablePtr_->cfind(bm[pI].type()); (
if (patchTypeCstrIter.good()) fvPatchField<Type>::patchConstructorTablePtr_->contains
(
bm[patchi].type()
)
)
{ {
actualPatchTypes[pI] = bm[pI].type(); actualPatchTypes[patchi] = bm[patchi].type();
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -37,25 +37,16 @@ Foam::dimFieldDecomposer::decomposeField
const DimensionedField<Type, volMesh>& field const DimensionedField<Type, volMesh>& field
) const ) const
{ {
// Create and map the internal field values
Field<Type> mappedField(field, cellAddressing_);
// Create the field for the processor // Create the field for the processor
return
tmp<DimensionedField<Type, volMesh>>::New return DimensionedField<Type, volMesh>::New
(
IOobject
( (
field.name(), field.name(),
procMesh_.thisDb().time().timeName(), IOobject::NO_REGISTER,
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
procMesh_, procMesh_,
field.dimensions(), field.dimensions(),
std::move(mappedField) // Internal field - mapped values
Field<Type>(field.field(), cellAddressing_)
); );
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -44,25 +44,16 @@ Foam::fvFieldDecomposer::decomposeField
const DimensionedField<Type, volMesh>& field const DimensionedField<Type, volMesh>& field
) const ) const
{ {
// Create and map the internal field values
Field<Type> mappedField(field, cellAddressing_);
// Create the field for the processor // Create the field for the processor
return
tmp<DimensionedField<Type, volMesh>>::New return DimensionedField<Type, volMesh>::New
(
IOobject
( (
field.name(), field.name(),
procMesh_.thisDb().time().timeName(), IOobject::NO_REGISTER,
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
procMesh_, procMesh_,
field.dimensions(), field.dimensions(),
std::move(mappedField) // Internal field - mapped values
Field<Type>(field.field(), cellAddressing_)
); );
} }
@ -75,52 +66,26 @@ Foam::fvFieldDecomposer::decomposeField
const bool allowUnknownPatchFields const bool allowUnknownPatchFields
) const ) const
{ {
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
// 1. Create the complete field with dummy patch fields
PtrList<fvPatchField<Type>> patchFields(boundaryAddressing_.size());
forAll(boundaryAddressing_, patchi)
{
patchFields.set
(
patchi,
fvPatchField<Type>::New
(
fvPatchFieldBase::calculatedType(),
procMesh_.boundary()[patchi],
fvPatchField<Type>::Internal::null()
)
);
}
// Create the field for the processor // Create the field for the processor
tmp<VolFieldType> tresF // - with dummy patch fields
( auto tresult = GeometricField<Type, fvPatchField, volMesh>::New
new VolFieldType
(
IOobject
( (
field.name(), field.name(),
procMesh_.thisDb().time().timeName(), IOobject::NO_REGISTER,
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procMesh_, procMesh_,
field.dimensions(), field.dimensions(),
// Internal field - mapped values
Field<Type>(field.primitiveField(), cellAddressing_), Field<Type>(field.primitiveField(), cellAddressing_),
patchFields fvPatchFieldBase::calculatedType()
)
); );
VolFieldType& resF = tresF.ref(); auto& result = tresult.ref();
resF.oriented() = field().oriented(); result.oriented() = field.oriented();
// 2. Change the fvPatchFields to the correct type using a mapper // 2. Change the fvPatchFields to the correct type using a mapper
// constructor (with reference to the now correct internal field) // constructor (with reference to the now correct internal field)
auto& bf = resF.boundaryFieldRef(); auto& bf = result.boundaryFieldRef();
forAll(bf, patchi) forAll(bf, patchi)
{ {
@ -133,7 +98,7 @@ Foam::fvFieldDecomposer::decomposeField
( (
field.boundaryField()[boundaryAddressing_[patchi]], field.boundaryField()[boundaryAddressing_[patchi]],
procMesh_.boundary()[patchi], procMesh_.boundary()[patchi],
resF(), result.internalField(),
patchFieldDecomposerPtrs_[patchi] patchFieldDecomposerPtrs_[patchi]
) )
); );
@ -146,7 +111,7 @@ Foam::fvFieldDecomposer::decomposeField
new processorCyclicFvPatchField<Type> new processorCyclicFvPatchField<Type>
( (
procMesh_.boundary()[patchi], procMesh_.boundary()[patchi],
resF(), result.internalField(),
Field<Type> Field<Type>
( (
field.primitiveField(), field.primitiveField(),
@ -163,7 +128,7 @@ Foam::fvFieldDecomposer::decomposeField
new processorFvPatchField<Type> new processorFvPatchField<Type>
( (
procMesh_.boundary()[patchi], procMesh_.boundary()[patchi],
resF(), result.internalField(),
Field<Type> Field<Type>
( (
field.primitiveField(), field.primitiveField(),
@ -180,7 +145,7 @@ Foam::fvFieldDecomposer::decomposeField
new emptyFvPatchField<Type> new emptyFvPatchField<Type>
( (
procMesh_.boundary()[patchi], procMesh_.boundary()[patchi],
resF() result.internalField()
) )
); );
} }
@ -192,7 +157,7 @@ Foam::fvFieldDecomposer::decomposeField
} }
// Create the field for the processor // Create the field for the processor
return tresF; return tresult;
} }
@ -203,27 +168,15 @@ Foam::fvFieldDecomposer::decomposeField
const GeometricField<Type, fvsPatchField, surfaceMesh>& field const GeometricField<Type, fvsPatchField, surfaceMesh>& field
) const ) const
{ {
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
labelList mapAddr labelList mapAddr
( (
labelList::subList labelList::subList(faceAddressing_, procMesh_.nInternalFaces())
(
faceAddressing_,
procMesh_.nInternalFaces()
)
); );
forAll(mapAddr, i) forAll(mapAddr, i)
{ {
mapAddr[i] -= 1; mapAddr[i] -= 1;
} }
// Create and map the internal field values
Field<Type> internalField
(
field.primitiveField(),
mapAddr
);
// Problem with addressing when a processor patch picks up both internal // Problem with addressing when a processor patch picks up both internal
// faces and faces from cyclic boundaries. This is a bit of a hack, but // faces and faces from cyclic boundaries. This is a bit of a hack, but
@ -232,66 +185,40 @@ Foam::fvFieldDecomposer::decomposeField
// (i.e. using slices) // (i.e. using slices)
Field<Type> allFaceField(field.mesh().nFaces()); Field<Type> allFaceField(field.mesh().nFaces());
forAll(field.primitiveField(), i)
{ {
allFaceField[i] = field.primitiveField()[i]; SubList<Type>(allFaceField, field.primitiveField().size()) =
} field.primitiveField();
forAll(field.boundaryField(), patchi) forAll(field.boundaryField(), patchi)
{ {
const Field<Type>& p = field.boundaryField()[patchi]; const Field<Type>& pfld = field.boundaryField()[patchi];
const label patchStart = field.mesh().boundaryMesh()[patchi].start(); const label start = field.mesh().boundaryMesh()[patchi].start();
forAll(p, i) SubList<Type>(allFaceField, pfld.size(), start) = pfld;
{
allFaceField[patchStart + i] = p[i];
} }
} }
// 1. Create the complete field with dummy patch fields // 1. Create the complete field with dummy patch fields
PtrList<fvsPatchField<Type>> patchFields(boundaryAddressing_.size());
forAll(boundaryAddressing_, patchi) auto tresult = GeometricField<Type, fvsPatchField, surfaceMesh>::New
{
patchFields.set
(
patchi,
fvsPatchField<Type>::New
(
fvsPatchFieldBase::calculatedType(),
procMesh_.boundary()[patchi],
fvsPatchField<Type>::Internal::null()
)
);
}
tmp<SurfaceFieldType> tresF
(
new SurfaceFieldType
(
IOobject
( (
field.name(), field.name(),
procMesh_.thisDb().time().timeName(), IOobject::NO_REGISTER,
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procMesh_, procMesh_,
field.dimensions(), field.dimensions(),
// Internal field - mapped values
Field<Type>(field.primitiveField(), mapAddr), Field<Type>(field.primitiveField(), mapAddr),
patchFields fvsPatchFieldBase::calculatedType()
)
); );
SurfaceFieldType& resF = tresF.ref(); auto& result = tresult.ref();
resF.oriented() = field().oriented(); result.oriented() = field.oriented();
// 2. Change the fvsPatchFields to the correct type using a mapper // 2. Change the fvsPatchFields to the correct type using a mapper
// constructor (with reference to the now correct internal field) // constructor (with reference to the now correct internal field)
auto& bf = resF.boundaryFieldRef(); auto& bf = result.boundaryFieldRef();
forAll(boundaryAddressing_, patchi) forAll(boundaryAddressing_, patchi)
{ {
@ -304,7 +231,7 @@ Foam::fvFieldDecomposer::decomposeField
( (
field.boundaryField()[boundaryAddressing_[patchi]], field.boundaryField()[boundaryAddressing_[patchi]],
procMesh_.boundary()[patchi], procMesh_.boundary()[patchi],
resF(), result.internalField(),
patchFieldDecomposerPtrs_[patchi] patchFieldDecomposerPtrs_[patchi]
) )
); );
@ -317,7 +244,7 @@ Foam::fvFieldDecomposer::decomposeField
new processorCyclicFvsPatchField<Type> new processorCyclicFvsPatchField<Type>
( (
procMesh_.boundary()[patchi], procMesh_.boundary()[patchi],
resF(), result.internalField(),
Field<Type> Field<Type>
( (
allFaceField, allFaceField,
@ -326,7 +253,7 @@ Foam::fvFieldDecomposer::decomposeField
) )
); );
if (resF.is_oriented()) if (result.is_oriented())
{ {
bf[patchi] *= faceSign_[patchi]; bf[patchi] *= faceSign_[patchi];
} }
@ -339,7 +266,7 @@ Foam::fvFieldDecomposer::decomposeField
new processorFvsPatchField<Type> new processorFvsPatchField<Type>
( (
procMesh_.boundary()[patchi], procMesh_.boundary()[patchi],
resF(), result.internalField(),
Field<Type> Field<Type>
( (
allFaceField, allFaceField,
@ -348,7 +275,7 @@ Foam::fvFieldDecomposer::decomposeField
) )
); );
if (resF.is_oriented()) if (result.is_oriented())
{ {
bf[patchi] *= faceSign_[patchi]; bf[patchi] *= faceSign_[patchi];
} }
@ -361,7 +288,7 @@ Foam::fvFieldDecomposer::decomposeField
} }
// Create the field for the processor // Create the field for the processor
return tresF; return tresult;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -38,9 +38,6 @@ Foam::pointFieldDecomposer::decomposeField
const GeometricField<Type, pointPatchField, pointMesh>& field const GeometricField<Type, pointPatchField, pointMesh>& field
) const ) const
{ {
// Create and map the internal field values
Field<Type> internalField(field.primitiveField(), pointAddressing_);
// Create a list of pointers for the patchFields // Create a list of pointers for the patchFields
PtrList<pointPatchField<Type>> patchFields(boundaryAddressing_.size()); PtrList<pointPatchField<Type>> patchFields(boundaryAddressing_.size());
@ -76,21 +73,15 @@ Foam::pointFieldDecomposer::decomposeField
} }
// Create the field for the processor // Create the field for the processor
return return GeometricField<Type, pointPatchField, pointMesh>::New
tmp<GeometricField<Type, pointPatchField, pointMesh>>::New
(
IOobject
( (
field.name(), field.name(),
procMesh_.thisDb().time().timeName(), IOobject::NO_REGISTER,
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
procMesh_, procMesh_,
field.dimensions(), field.dimensions(),
internalField, // Internal field - mapped values
Field<Type>(field.primitiveField(), pointAddressing_),
// Boundary field
patchFields patchFields
); );
} }