ENH: reduce some allocations in rawTopoChangerFvMesh
- cache and reuse the zero field STYLE: use templated form of objectRegistry::names<..>
This commit is contained in:
parent
630d60de3b
commit
d300fab63a
@ -65,12 +65,6 @@ Foam::rawTopoChangerFvMesh::rawTopoChangerFvMesh
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::rawTopoChangerFvMesh::~rawTopoChangerFvMesh()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::rawTopoChangerFvMesh::update()
|
||||
@ -121,30 +115,24 @@ bool Foam::rawTopoChangerFvMesh::update()
|
||||
}
|
||||
}
|
||||
|
||||
const List<objectMap>& fromFaces = topoChangeMap().facesFromFacesMap();
|
||||
|
||||
forAll(fromFaces, i)
|
||||
for (const auto& map : topoChangeMap().facesFromFacesMap())
|
||||
{
|
||||
mappedFace.set(fromFaces[i].index());
|
||||
mappedFace.set(map.index());
|
||||
}
|
||||
|
||||
const List<objectMap>& fromEdges = topoChangeMap().facesFromEdgesMap();
|
||||
|
||||
forAll(fromEdges, i)
|
||||
for (const auto& map : topoChangeMap().facesFromEdgesMap())
|
||||
{
|
||||
mappedFace.set(fromEdges[i].index());
|
||||
mappedFace.set(map.index());
|
||||
}
|
||||
|
||||
const List<objectMap>& fromPts = topoChangeMap().facesFromPointsMap();
|
||||
|
||||
forAll(fromPts, i)
|
||||
for (const auto& map : topoChangeMap().facesFromPointsMap())
|
||||
{
|
||||
mappedFace.set(fromPts[i].index());
|
||||
mappedFace.set(map.index());
|
||||
}
|
||||
|
||||
// Set unmapped faces to zero
|
||||
Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values."
|
||||
<< endl;
|
||||
Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values." << nl;
|
||||
|
||||
zeroUnmappedValues<scalar, fvPatchField, volMesh>(mappedFace);
|
||||
zeroUnmappedValues<vector, fvPatchField, volMesh>(mappedFace);
|
||||
zeroUnmappedValues<sphericalTensor, fvPatchField, volMesh>(mappedFace);
|
||||
@ -155,8 +143,8 @@ bool Foam::rawTopoChangerFvMesh::update()
|
||||
Info<< "rawTopoChangerFvMesh :"
|
||||
<< " recreating phi for unmapped boundary values." << endl;
|
||||
|
||||
const volVectorField& U = lookupObject<volVectorField>("U");
|
||||
surfaceScalarField& phi = lookupObjectRef<surfaceScalarField>("phi");
|
||||
const auto& U = lookupObject<volVectorField>("U");
|
||||
auto& phi = lookupObjectRef<surfaceScalarField>("phi");
|
||||
|
||||
setUnmappedValues
|
||||
(
|
||||
|
@ -38,8 +38,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef rawTopoChangerFvMesh_H
|
||||
#define rawTopoChangerFvMesh_H
|
||||
#ifndef Foam_rawTopoChangerFvMesh_H
|
||||
#define Foam_rawTopoChangerFvMesh_H
|
||||
|
||||
#include "topoChangerFvMesh.H"
|
||||
#include "bitSet.H"
|
||||
@ -49,8 +49,6 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class rawTopoChangerFvMesh Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -94,8 +92,9 @@ public:
|
||||
const bool doInit=true
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~rawTopoChangerFvMesh();
|
||||
virtual ~rawTopoChangerFvMesh() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2024 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -25,9 +26,6 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rawTopoChangerFvMesh.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type, template<class> class PatchField, class GeoMesh>
|
||||
@ -42,10 +40,7 @@ void Foam::rawTopoChangerFvMesh::setUnmappedValues
|
||||
|
||||
forAll(fld.boundaryField(), patchi)
|
||||
{
|
||||
PatchField<Type>& fvp = const_cast<PatchField<Type>&>
|
||||
(
|
||||
fld.boundaryField()[patchi]
|
||||
);
|
||||
auto& fvp = const_cast<PatchField<Type>&>(fld.boundaryField()[patchi]);
|
||||
|
||||
const label start = fvp.patch().start();
|
||||
forAll(fvp, i)
|
||||
@ -71,33 +66,27 @@ void Foam::rawTopoChangerFvMesh::zeroUnmappedValues
|
||||
{
|
||||
typedef GeometricField<Type, PatchField, GeoMesh> FieldType;
|
||||
|
||||
const wordList fldNames(names(FieldType::typeName));
|
||||
std::unique_ptr<FieldType> zeroFieldPtr;
|
||||
|
||||
forAll(fldNames, i)
|
||||
for (const word& fldName : names<FieldType>())
|
||||
{
|
||||
//Pout<< "Checking field " << fldNames[i] << endl;
|
||||
FieldType& fld = lookupObjectRef<FieldType>(fldName);
|
||||
//Pout<< "Checking field " << fld.name() << endl;
|
||||
|
||||
FieldType& fld = lookupObjectRef<FieldType>(fldNames[i]);
|
||||
|
||||
setUnmappedValues
|
||||
(
|
||||
fld,
|
||||
mappedFace,
|
||||
FieldType
|
||||
if (!zeroFieldPtr)
|
||||
{
|
||||
zeroFieldPtr = std::make_unique<FieldType>
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"zero",
|
||||
time().timeName(),
|
||||
*this,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE,
|
||||
IOobject::NO_REGISTER
|
||||
),
|
||||
this->newIOobject("zero"),
|
||||
*this,
|
||||
dimensioned<Type>(fld.dimensions(), Zero)
|
||||
)
|
||||
);
|
||||
Foam::zero{},
|
||||
dimless
|
||||
);
|
||||
}
|
||||
|
||||
zeroFieldPtr->dimensions().reset(fld.dimensions());
|
||||
|
||||
setUnmappedValues(fld, mappedFace, *zeroFieldPtr);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user