diff --git a/applications/solvers/foamMultiRun/regionSolvers/regionSolvers.C b/applications/solvers/foamMultiRun/regionSolvers/regionSolvers.C index 1fc8d5a125..593c109c64 100644 --- a/applications/solvers/foamMultiRun/regionSolvers/regionSolvers.C +++ b/applications/solvers/foamMultiRun/regionSolvers/regionSolvers.C @@ -113,10 +113,6 @@ Foam::regionSolvers::regionSolvers(const Time& runTime) forAll(regionSolverNames, i) { const word& regionName = regionSolverNames[i].first(); - const word& solverName = regionSolverNames[i].second(); - - // Load the solver library - solver::load(solverName); regions_.set ( @@ -129,9 +125,24 @@ Foam::regionSolvers::regionSolvers(const Time& runTime) runTime.name(), runTime, 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])); diff --git a/applications/test/mesh/Test-mesh.C b/applications/test/mesh/Test-mesh.C index 1c1d1b61ac..b10586376e 100644 --- a/applications/test/mesh/Test-mesh.C +++ b/applications/test/mesh/Test-mesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -48,7 +48,8 @@ int main(int argc, char *argv[]) runTime.name(), runTime, IOobject::MUST_READ - ) + ), + false ); Info<< mesh.C() << endl; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C index 0c0e2e1a3f..bd71202be3 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C @@ -477,10 +477,11 @@ void Foam::vtkPVFoam::updateFoamMesh() dbPtr_(), IOobject::MUST_READ ), - false, - fvMesh::stitchType::nonGeometric + false ); + meshPtr_->postConstruct(false, fvMesh::stitchType::nonGeometric); + meshChanged_ = true; } else diff --git a/src/OpenFOAM/include/createMeshNoChangers.H b/src/OpenFOAM/include/createMeshNoChangers.H index 07bbee2445..f6d5afa1d8 100644 --- a/src/OpenFOAM/include/createMeshNoChangers.H +++ b/src/OpenFOAM/include/createMeshNoChangers.H @@ -13,3 +13,5 @@ Foam::fvMesh mesh ), false ); + +mesh.postConstruct(false, fvMesh::stitchType::geometric); diff --git a/src/OpenFOAM/include/createRegionMeshNoChangers.H b/src/OpenFOAM/include/createRegionMeshNoChangers.H index 5cefdd5b32..fe5765602f 100644 --- a/src/OpenFOAM/include/createRegionMeshNoChangers.H +++ b/src/OpenFOAM/include/createRegionMeshNoChangers.H @@ -25,3 +25,5 @@ Foam::fvMesh mesh ), false ); + +mesh.postConstruct(false, fvMesh::stitchType::geometric); diff --git a/src/finiteVolume/fvMesh/fvMesh.C b/src/finiteVolume/fvMesh/fvMesh.C index cee857faa2..3fc20777e6 100644 --- a/src/finiteVolume/fvMesh/fvMesh.C +++ b/src/finiteVolume/fvMesh/fvMesh.C @@ -267,17 +267,12 @@ Foam::surfaceLabelField::Boundary& Foam::fvMesh::polyFacesBfRef() // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::fvMesh::fvMesh -( - const IOobject& io, - const bool changers, - const stitchType stitch -) +Foam::fvMesh::fvMesh(const IOobject& io, const bool doPost) : polyMesh(io), surfaceInterpolation(*this), boundary_(*this, boundaryMesh()), - stitcher_(fvMeshStitcher::New(*this, changers).ptr()), + stitcher_(nullptr), topoChanger_(nullptr), distributor_(nullptr), mover_(nullptr), @@ -307,54 +302,9 @@ Foam::fvMesh::fvMesh Pout<< FUNCTION_NAME << "Constructing fvMesh from IOobject" << endl; } - // Stitch or Re-stitch if necessary - if (stitch != stitchType::none) + if (doPost) { - 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 - if (fileHandler().isFile(time().timePath()/"Vc0")) - { - V0Ptr_ = new DimensionedField - ( - 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 - ); - } + postConstruct(true, stitchType::geometric); } } @@ -572,6 +522,66 @@ Foam::fvMesh::~fvMesh() // * * * * * * * * * * * * * * * 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 + ( + 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 { return topoChanger_.valid() && topoChanger_->dynamic(); @@ -649,7 +659,7 @@ bool Foam::fvMesh::move() void Foam::fvMesh::addFvPatches ( - const List & p, + const List& p, const bool validBoundary ) { @@ -748,11 +758,11 @@ Foam::fvMesh::readUpdateState Foam::fvMesh::readUpdate if ( stitcher_.valid() - && stitch != stitchType::none + && stitcher_->stitches() && state != polyMesh::UNCHANGED ) { - stitcher_->disconnect(false, stitch == stitchType::geometric); + stitcher_->disconnect(false, false); } if (state == polyMesh::TOPO_PATCH_CHANGE) @@ -793,8 +803,9 @@ Foam::fvMesh::readUpdateState Foam::fvMesh::readUpdate if ( stitcher_.valid() - && stitch != stitchType::none + && stitcher_->stitches() && state != polyMesh::UNCHANGED + && stitch != stitchType::none ) { 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 { return topoChanger_(); diff --git a/src/finiteVolume/fvMesh/fvMesh.H b/src/finiteVolume/fvMesh/fvMesh.H index 2730627231..06b9f65481 100644 --- a/src/finiteVolume/fvMesh/fvMesh.H +++ b/src/finiteVolume/fvMesh/fvMesh.H @@ -327,15 +327,10 @@ public: // Constructors - //- Construct from IOobject - // with the option to not instantiate the mesh changers and the option - // to prevent some or all of the stitching - explicit fvMesh - ( - const IOobject& io, - const bool changers = true, - const stitchType stitch = stitchType::geometric - ); + //- Construct from IOobject. Optionally prevent post-construction, so + // that postConstruct may be called manually for finer control of + // construction of mesh changes and the level of stitching. + explicit fvMesh(const IOobject& io, const bool doPost = true); //- Construct from cellShapes with boundary. fvMesh @@ -364,7 +359,7 @@ public: ); //- Construct without boundary from cells rather than owner/neighbour. - // Boundary is added using addPatches() member function + // Boundary is added using addFvPatches() member function fvMesh ( const IOobject& io, @@ -389,6 +384,13 @@ public: // Helpers + //- Complete construction of the mesh + void postConstruct + ( + const bool changers, + const stitchType stitch + ); + //- Add boundary patches. Constructor helper void addFvPatches ( @@ -488,6 +490,9 @@ public: //- Return the stitcher function class const fvMeshStitcher& stitcher() const; + //- Return the stitcher function class + fvMeshStitcher& stitcher(); + //- Return the topo-changer function class const fvMeshTopoChanger& topoChanger() const; diff --git a/src/fvMeshTopoChangers/meshToMesh/fvMeshTopoChangersMeshToMesh.C b/src/fvMeshTopoChangers/meshToMesh/fvMeshTopoChangersMeshToMesh.C index 2b1a139104..35937cae68 100644 --- a/src/fvMeshTopoChangers/meshToMesh/fvMeshTopoChangersMeshToMesh.C +++ b/src/fvMeshTopoChangers/meshToMesh/fvMeshTopoChangersMeshToMesh.C @@ -245,8 +245,7 @@ bool Foam::fvMeshTopoChangers::meshToMesh::update() time, IOobject::MUST_READ ), - false, - fvMesh::stitchType::none + false ); mesh().swap(otherMesh); diff --git a/src/parallel/parallel/domainDecomposition.C b/src/parallel/parallel/domainDecomposition.C index f9b5912802..935a714ecf 100644 --- a/src/parallel/parallel/domainDecomposition.C +++ b/src/parallel/parallel/domainDecomposition.C @@ -106,12 +106,17 @@ void Foam::domainDecomposition::readComplete(const bool stitch) IOobject::NO_WRITE, false ), - false, - stitch - ? fvMesh::stitchType::nonGeometric - : fvMesh::stitchType::none + false ) ); + + completeMesh_->init + ( + false, + stitch + ? fvMesh::stitchType::nonGeometric + : fvMesh::stitchType::none + ); } @@ -136,6 +141,12 @@ void Foam::domainDecomposition::readProcs() false ) ); + + procMeshes_[proci].init + ( + false, + fvMesh::stitchType::nonGeometric + ); } }