BUG: (un)refinement: combine topochange+motion. Fixes #2492

This is on
- incompressible/pimpleFoam/laminar/mixerVesselAMI2D/mixerVesselAMI2D-topologyChange
- redistributePar -reconstruct
where the fvMesh::updateMesh does an early trigger of
mesh.phi() calculation
This commit is contained in:
mattijs
2022-06-15 17:51:13 +01:00
parent 913f844eb6
commit 8ac11f1079
7 changed files with 91 additions and 57 deletions

View File

@ -639,9 +639,14 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::repatch
// shared points (see mergeSharedPoints below). So temporarily points
// and edges do not match!
// TBD: temporarily unset mesh moving to avoid problems in meshflux
// mapping. To be investigated.
const bool oldMoving = mesh_.moving(false);
autoPtr<mapPolyMesh> mapPtr = meshMod.changeMesh(mesh_, false, true);
mesh_.moving(oldMoving);
mapPolyMesh& map = *mapPtr;
// Update fields. No inflation, parallel sync.
mesh_.updateMesh(map);
@ -766,7 +771,12 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::mergeSharedPoints
fvMeshAdder::mergePoints(mesh_, pointToMaster, meshMod);
// Change the mesh (no inflation). Note: parallel comms allowed.
// TBD: temporarily unset mesh moving to avoid problems in meshflux
// mapping. To be investigated.
const bool oldMoving = mesh_.moving(false);
autoPtr<mapPolyMesh> mapPtr = meshMod.changeMesh(mesh_, false, true);
mesh_.moving(oldMoving);
mapPolyMesh& map = *mapPtr;
// Update fields. No inflation, parallel sync.
@ -1402,7 +1412,12 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::doRemoveCells
saveInternalFields(tFlds);
// Change the mesh. No inflation. Note: no parallel comms allowed.
// TBD: temporarily unset mesh moving to avoid problems in meshflux
// mapping. To be investigated.
const bool oldMoving = mesh_.moving(false);
autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh_, false, false);
mesh_.moving(oldMoving);
// Update fields
mesh_.updateMesh(map());
@ -2825,6 +2840,10 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
const label nOldInternalFaces = mesh_.nInternalFaces();
const labelList oldFaceOwner(mesh_.faceOwner());
// TBD: temporarily unset mesh moving to avoid problems in meshflux
// mapping. To be investigated.
const bool oldMoving = mesh_.moving(false);
fvMeshAdder::add
(
Pstream::myProcNo(), // index of mesh to modify (== mesh_)
@ -2842,6 +2861,9 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
constructPointMap
);
mesh_.moving(oldMoving);
if (debug)
{
Pout<< nl << "ADDED REMOTE MESHES:" << endl;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -63,29 +63,33 @@ bool Foam::fvGeometryScheme::setMeshPhi() const
const faceList& faces = mesh_.faces();
const scalar rdt = 1.0/mesh_.time().deltaTValue();
auto& meshPhi = const_cast<fvMesh&>(mesh_).setPhi();
auto& meshPhii = meshPhi.primitiveFieldRef();
forAll(meshPhii, facei)
auto tmeshPhi(const_cast<fvMesh&>(mesh_).setPhi());
if (tmeshPhi)
{
const face& f = faces[facei];
meshPhii[facei] = f.sweptVol(oldPoints, currPoints)*rdt;
}
auto& meshPhiBf = meshPhi.boundaryFieldRef();
for (auto& meshPhip : meshPhiBf)
{
if (!meshPhip.size())
auto& meshPhi = tmeshPhi.ref();
auto& meshPhii = meshPhi.primitiveFieldRef();
forAll(meshPhii, facei)
{
// Empty patches
continue;
const face& f = faces[facei];
meshPhii[facei] = f.sweptVol(oldPoints, currPoints)*rdt;
}
const auto& pp = meshPhip.patch().patch();
forAll(pp, facei)
auto& meshPhiBf = meshPhi.boundaryFieldRef();
for (auto& meshPhip : meshPhiBf)
{
const face& f = pp[facei];
meshPhip[facei] = f.sweptVol(oldPoints, currPoints)*rdt;
if (!meshPhip.size())
{
// Empty patches
continue;
}
const auto& pp = meshPhip.patch().patch();
forAll(pp, facei)
{
const face& f = pp[facei];
meshPhip[facei] = f.sweptVol(oldPoints, currPoints)*rdt;
}
}
}

View File

@ -220,40 +220,45 @@ void Foam::solidBodyFvGeometryScheme::movePoints()
const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
const faceList& faces = mesh_.faces();
const scalar rdt = 1.0/mesh_.time().deltaTValue();
// Set the mesh flux
auto& meshPhi = const_cast<fvMesh&>(mesh_).setPhi();
auto& meshPhii = meshPhi.primitiveFieldRef();
auto& meshPhiBf = meshPhi.boundaryFieldRef();
//meshPhi == dimensionedScalar(dimVolume/dimTime, Zero);
meshPhii = Zero;
meshPhiBf == Zero;
forAll(changedFaceIDs_, i)
auto tmeshPhi(const_cast<fvMesh&>(mesh_).setPhi());
if (tmeshPhi)
{
const face& f = faces[changedFaceIDs_[i]];
const scalar rdt = 1.0/mesh_.time().deltaTValue();
if (changedPatchIDs_[i] == -1)
{
const label facei = changedFaceIDs_[i];
meshPhii[facei] = f.sweptVol(oldPoints, currPoints)*rdt;
}
else
{
const label patchi = changedPatchIDs_[i];
const polyPatch& pp = pbm[patchi];
// Set the mesh flux
auto& meshPhi = tmeshPhi.ref();
auto& meshPhii = meshPhi.primitiveFieldRef();
auto& meshPhiBf = meshPhi.boundaryFieldRef();
if (isA<emptyPolyPatch>(pp))
//meshPhi == dimensionedScalar(dimVolume/dimTime, Zero);
meshPhii = Zero;
meshPhiBf == Zero;
forAll(changedFaceIDs_, i)
{
const face& f = faces[changedFaceIDs_[i]];
if (changedPatchIDs_[i] == -1)
{
continue;
const label facei = changedFaceIDs_[i];
meshPhii[facei] = f.sweptVol(oldPoints, currPoints)*rdt;
}
else
{
const label patchi = changedPatchIDs_[i];
const polyPatch& pp = pbm[patchi];
const label patchFacei = changedFaceIDs_[i] - pp.start();
if (isA<emptyPolyPatch>(pp))
{
continue;
}
meshPhiBf[patchi][patchFacei] =
f.sweptVol(oldPoints, currPoints)*rdt;
const label patchFacei = changedFaceIDs_[i] - pp.start();
meshPhiBf[patchi][patchFacei] =
f.sweptVol(oldPoints, currPoints)*rdt;
}
}
}

View File

@ -482,8 +482,8 @@ public:
//- these fvPatches.
void removeFvBoundary();
//- Return cell face motion fluxes
surfaceScalarField& setPhi();
//- Return cell face motion fluxes (or null)
refPtr<surfaceScalarField> setPhi();
//- Return old-time cell volumes
DimensionedField<scalar, volMesh>& setV0();

View File

@ -415,16 +415,19 @@ const Foam::surfaceScalarField& Foam::fvMesh::phi() const
}
Foam::surfaceScalarField& Foam::fvMesh::setPhi()
Foam::refPtr<Foam::surfaceScalarField> Foam::fvMesh::setPhi()
{
if (!phiPtr_)
{
FatalErrorInFunction
<< "mesh flux field does not exist, is the mesh actually moving?"
<< abort(FatalError);
return nullptr;
}
else
{
// Return non-const reference
refPtr<surfaceScalarField> p;
p.ref(*phiPtr_);
return p;
}
return *phiPtr_;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019,2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -345,7 +345,7 @@ void Foam::cyclicACMIFvPatch::movePoints()
const labelListList& newTgtAddr = AMI().tgtAddress();
const fvMesh& mesh = boundaryMesh().mesh();
surfaceScalarField& meshPhi = const_cast<fvMesh&>(mesh).setPhi();
surfaceScalarField& meshPhi = const_cast<fvMesh&>(mesh).setPhi().ref();
surfaceScalarField::Boundary& meshPhiBf = meshPhi.boundaryFieldRef();
// Note: phip and phiNonOverlap will be different sizes if new faces

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2020,2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -267,7 +267,7 @@ void Foam::cyclicAMIFvPatch::movePoints()
// src = src + mapped(tgt) and tgt = tgt + mapped(src)?
const fvMesh& mesh = boundaryMesh().mesh();
surfaceScalarField& meshPhi = const_cast<fvMesh&>(mesh).setPhi();
surfaceScalarField& meshPhi = const_cast<fvMesh&>(mesh).setPhi().ref();
surfaceScalarField::Boundary& meshPhiBf = meshPhi.boundaryFieldRef();
if (cyclicAMIPolyPatch_.owner())