fvMesh: Split construction

This provides finer control as to when the changes get constructed and
initial stitching is performed. These is needed by certain processes,
notably decomposition and reconstruction.

By default, the mesh still performs all these operations on a "normal"
read-construction. A flag has to be passed explicitly to the constructor
in order to prevent the post-construction steps.
This commit is contained in:
Will Bainbridge
2024-01-30 08:26:43 +00:00
parent f1ab9882c7
commit 716cab7618
9 changed files with 132 additions and 83 deletions

View File

@ -113,10 +113,6 @@ Foam::regionSolvers::regionSolvers(const Time& runTime)
forAll(regionSolverNames, i) forAll(regionSolverNames, i)
{ {
const word& regionName = regionSolverNames[i].first(); const word& regionName = regionSolverNames[i].first();
const word& solverName = regionSolverNames[i].second();
// Load the solver library
solver::load(solverName);
regions_.set regions_.set
( (
@ -129,9 +125,24 @@ Foam::regionSolvers::regionSolvers(const Time& runTime)
runTime.name(), runTime.name(),
runTime, runTime,
IOobject::MUST_READ IOobject::MUST_READ
) ),
false
) )
); );
}
forAll(regions_, i)
{
regions_[i].postConstruct(true, fvMesh::stitchType::geometric);
}
forAll(regionSolverNames, i)
{
const word& regionName = regionSolverNames[i].first();
const word& solverName = regionSolverNames[i].second();
// Load the solver library
solver::load(solverName);
solvers_.set(i, solver::New(solverName, regions_[i])); solvers_.set(i, solver::New(solverName, regions_[i]));

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -48,7 +48,8 @@ int main(int argc, char *argv[])
runTime.name(), runTime.name(),
runTime, runTime,
IOobject::MUST_READ IOobject::MUST_READ
) ),
false
); );
Info<< mesh.C() << endl; Info<< mesh.C() << endl;

View File

@ -477,10 +477,11 @@ void Foam::vtkPVFoam::updateFoamMesh()
dbPtr_(), dbPtr_(),
IOobject::MUST_READ IOobject::MUST_READ
), ),
false, false
fvMesh::stitchType::nonGeometric
); );
meshPtr_->postConstruct(false, fvMesh::stitchType::nonGeometric);
meshChanged_ = true; meshChanged_ = true;
} }
else else

View File

@ -13,3 +13,5 @@ Foam::fvMesh mesh
), ),
false false
); );
mesh.postConstruct(false, fvMesh::stitchType::geometric);

View File

@ -25,3 +25,5 @@ Foam::fvMesh mesh
), ),
false false
); );
mesh.postConstruct(false, fvMesh::stitchType::geometric);

View File

@ -267,17 +267,12 @@ Foam::surfaceLabelField::Boundary& Foam::fvMesh::polyFacesBfRef()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fvMesh::fvMesh Foam::fvMesh::fvMesh(const IOobject& io, const bool doPost)
(
const IOobject& io,
const bool changers,
const stitchType stitch
)
: :
polyMesh(io), polyMesh(io),
surfaceInterpolation(*this), surfaceInterpolation(*this),
boundary_(*this, boundaryMesh()), boundary_(*this, boundaryMesh()),
stitcher_(fvMeshStitcher::New(*this, changers).ptr()), stitcher_(nullptr),
topoChanger_(nullptr), topoChanger_(nullptr),
distributor_(nullptr), distributor_(nullptr),
mover_(nullptr), mover_(nullptr),
@ -307,54 +302,9 @@ Foam::fvMesh::fvMesh
Pout<< FUNCTION_NAME << "Constructing fvMesh from IOobject" << endl; Pout<< FUNCTION_NAME << "Constructing fvMesh from IOobject" << endl;
} }
// Stitch or Re-stitch if necessary if (doPost)
if (stitch != stitchType::none)
{ {
stitcher_->connect(false, stitch == stitchType::geometric, true); postConstruct(true, stitchType::geometric);
}
// Construct changers
if (changers)
{
topoChanger_.set(fvMeshTopoChanger::New(*this).ptr());
distributor_.set(fvMeshDistributor::New(*this).ptr());
mover_.set(fvMeshMover::New(*this).ptr());
// Check the existence of the cell volumes and read if present
if (fileHandler().isFile(time().timePath()/"Vc0"))
{
V0Ptr_ = new DimensionedField<scalar, volMesh>
(
IOobject
(
"Vc0",
time().name(),
*this,
IOobject::MUST_READ,
IOobject::NO_WRITE,
true
),
*this
);
}
// Check the existence of the mesh fluxes and read if present
if (fileHandler().isFile(time().timePath()/"meshPhi"))
{
phiPtr_ = new surfaceScalarField
(
IOobject
(
"meshPhi",
time().name(),
*this,
IOobject::MUST_READ,
IOobject::NO_WRITE,
true
),
*this
);
}
} }
} }
@ -572,6 +522,66 @@ Foam::fvMesh::~fvMesh()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fvMesh::postConstruct(const bool changers, const stitchType stitch)
{
// Construct the stitcher
stitcher_.set(fvMeshStitcher::New(*this, changers).ptr());
// Stitch or Re-stitch if necessary
if (stitch != stitchType::none)
{
stitcher_->connect(false, stitch == stitchType::geometric, true);
}
// Construct changers
if (changers)
{
topoChanger_.set(fvMeshTopoChanger::New(*this).ptr());
distributor_.set(fvMeshDistributor::New(*this).ptr());
mover_.set(fvMeshMover::New(*this).ptr());
// Check the existence of the cell volumes and read if present
// and set the storage of V00
if (fileHandler().isFile(time().timePath()/"Vc0"))
{
V0Ptr_ = new DimensionedField<scalar, volMesh>
(
IOobject
(
"Vc0",
time().name(),
*this,
IOobject::MUST_READ,
IOobject::NO_WRITE,
true
),
*this
);
V00();
}
// Check the existence of the mesh fluxes and read if present
if (fileHandler().isFile(time().timePath()/"meshPhi"))
{
phiPtr_ = new surfaceScalarField
(
IOobject
(
"meshPhi",
time().name(),
*this,
IOobject::MUST_READ,
IOobject::NO_WRITE,
true
),
*this
);
}
}
}
bool Foam::fvMesh::topoChanging() const bool Foam::fvMesh::topoChanging() const
{ {
return topoChanger_.valid() && topoChanger_->dynamic(); return topoChanger_.valid() && topoChanger_->dynamic();
@ -649,7 +659,7 @@ bool Foam::fvMesh::move()
void Foam::fvMesh::addFvPatches void Foam::fvMesh::addFvPatches
( (
const List<polyPatch*> & p, const List<polyPatch*>& p,
const bool validBoundary const bool validBoundary
) )
{ {
@ -748,11 +758,11 @@ Foam::fvMesh::readUpdateState Foam::fvMesh::readUpdate
if if
( (
stitcher_.valid() stitcher_.valid()
&& stitch != stitchType::none && stitcher_->stitches()
&& state != polyMesh::UNCHANGED && state != polyMesh::UNCHANGED
) )
{ {
stitcher_->disconnect(false, stitch == stitchType::geometric); stitcher_->disconnect(false, false);
} }
if (state == polyMesh::TOPO_PATCH_CHANGE) if (state == polyMesh::TOPO_PATCH_CHANGE)
@ -793,8 +803,9 @@ Foam::fvMesh::readUpdateState Foam::fvMesh::readUpdate
if if
( (
stitcher_.valid() stitcher_.valid()
&& stitch != stitchType::none && stitcher_->stitches()
&& state != polyMesh::UNCHANGED && state != polyMesh::UNCHANGED
&& stitch != stitchType::none
) )
{ {
stitcher_->connect(false, stitch == stitchType::geometric, true); stitcher_->connect(false, stitch == stitchType::geometric, true);
@ -973,6 +984,12 @@ const Foam::fvMeshStitcher& Foam::fvMesh::stitcher() const
} }
Foam::fvMeshStitcher& Foam::fvMesh::stitcher()
{
return stitcher_();
}
const Foam::fvMeshTopoChanger& Foam::fvMesh::topoChanger() const const Foam::fvMeshTopoChanger& Foam::fvMesh::topoChanger() const
{ {
return topoChanger_(); return topoChanger_();

View File

@ -327,15 +327,10 @@ public:
// Constructors // Constructors
//- Construct from IOobject //- Construct from IOobject. Optionally prevent post-construction, so
// with the option to not instantiate the mesh changers and the option // that postConstruct may be called manually for finer control of
// to prevent some or all of the stitching // construction of mesh changes and the level of stitching.
explicit fvMesh explicit fvMesh(const IOobject& io, const bool doPost = true);
(
const IOobject& io,
const bool changers = true,
const stitchType stitch = stitchType::geometric
);
//- Construct from cellShapes with boundary. //- Construct from cellShapes with boundary.
fvMesh fvMesh
@ -364,7 +359,7 @@ public:
); );
//- Construct without boundary from cells rather than owner/neighbour. //- Construct without boundary from cells rather than owner/neighbour.
// Boundary is added using addPatches() member function // Boundary is added using addFvPatches() member function
fvMesh fvMesh
( (
const IOobject& io, const IOobject& io,
@ -389,6 +384,13 @@ public:
// Helpers // Helpers
//- Complete construction of the mesh
void postConstruct
(
const bool changers,
const stitchType stitch
);
//- Add boundary patches. Constructor helper //- Add boundary patches. Constructor helper
void addFvPatches void addFvPatches
( (
@ -488,6 +490,9 @@ public:
//- Return the stitcher function class //- Return the stitcher function class
const fvMeshStitcher& stitcher() const; const fvMeshStitcher& stitcher() const;
//- Return the stitcher function class
fvMeshStitcher& stitcher();
//- Return the topo-changer function class //- Return the topo-changer function class
const fvMeshTopoChanger& topoChanger() const; const fvMeshTopoChanger& topoChanger() const;

View File

@ -245,8 +245,7 @@ bool Foam::fvMeshTopoChangers::meshToMesh::update()
time, time,
IOobject::MUST_READ IOobject::MUST_READ
), ),
false, false
fvMesh::stitchType::none
); );
mesh().swap(otherMesh); mesh().swap(otherMesh);

View File

@ -106,12 +106,17 @@ void Foam::domainDecomposition::readComplete(const bool stitch)
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
), ),
false, false
stitch
? fvMesh::stitchType::nonGeometric
: fvMesh::stitchType::none
) )
); );
completeMesh_->init
(
false,
stitch
? fvMesh::stitchType::nonGeometric
: fvMesh::stitchType::none
);
} }
@ -136,6 +141,12 @@ void Foam::domainDecomposition::readProcs()
false false
) )
); );
procMeshes_[proci].init
(
false,
fvMesh::stitchType::nonGeometric
);
} }
} }