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