Commit b4d6f3e0 authored by mattijs's avatar mattijs
Browse files

ENH: snappyHexMesh: added mesh shrinking as separate library

parent b1441a85
......@@ -26,5 +26,11 @@ $(autoHexMesh)/shellSurfaces/shellSurfaces.C
$(autoHexMesh)/trackedParticle/trackedParticle.C
$(autoHexMesh)/trackedParticle/trackedParticleCloud.C
meshMover = $(autoHexMesh)/externalDisplacementMeshMover
$(meshMover)/displacementMeshMoverMotionSolver.C
$(meshMover)/externalDisplacementMeshMover.C
$(meshMover)/medialAxisMeshMover.C
LIB = $(FOAM_LIBBIN)/libautoMesh
......@@ -53,6 +53,7 @@ Description
#include "calculatedPointPatchFields.H"
#include "cyclicSlipPointPatchFields.H"
#include "fixedValueFvPatchFields.H"
#include "localPointRegion.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -2809,14 +2810,7 @@ void Foam::autoLayerDriver::mergePatchFacesUndo
const fvMesh& mesh = meshRefiner_.mesh();
List<labelPair> couples
(
meshRefiner_.getDuplicateFaces // get all baffles
(
identity(mesh.nFaces()-mesh.nInternalFaces())
+ mesh.nInternalFaces()
)
);
List<labelPair> couples(localPointRegion::findDuplicateFacePairs(mesh));
labelList duplicateFace(mesh.nFaces(), -1);
forAll(couples, i)
......
......@@ -36,6 +36,7 @@ License
#include "mapDistributePolyMesh.H"
#include "unitConversion.H"
#include "snapParameters.H"
#include "localPointRegion.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -1036,19 +1037,11 @@ void Foam::autoRefineDriver::splitAndMergeBaffles
// Merge all baffles that are still remaining after duplicating points.
List<labelPair> couples
(
meshRefiner_.getDuplicateFaces // get all baffles
(
identity(mesh.nFaces()-mesh.nInternalFaces())
+ mesh.nInternalFaces()
)
);
List<labelPair> couples(localPointRegion::findDuplicateFacePairs(mesh));
label nCouples = returnReduce(couples.size(), sumOp<label>());
Info<< "Detected unsplittable baffles : "
<< nCouples << endl;
Info<< "Detected unsplittable baffles : " << nCouples << endl;
if (nCouples > 0)
{
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "displacementMeshMoverMotionSolver.H"
#include "addToRunTimeSelectionTable.H"
#include "localPointRegion.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(displacementMeshMoverMotionSolver, 0);
addToRunTimeSelectionTable
(
motionSolver,
displacementMeshMoverMotionSolver,
dictionary
);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::displacementMeshMoverMotionSolver::displacementMeshMoverMotionSolver
(
const polyMesh& mesh,
const IOdictionary& dict
)
:
displacementMotionSolver(mesh, dict, typeName) // read pointDisplacement
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::displacementMeshMoverMotionSolver::
~displacementMeshMoverMotionSolver()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::externalDisplacementMeshMover&
Foam::displacementMeshMoverMotionSolver::meshMover() const
{
if (!meshMoverPtr_.valid())
{
const word moverType(coeffDict().lookup("meshMover"));
meshMoverPtr_ = externalDisplacementMeshMover::New
(
moverType,
coeffDict().subDict(moverType + "Coeffs"),
localPointRegion::findDuplicateFacePairs(mesh()),
pointDisplacement_
);
}
return meshMoverPtr_();
}
Foam::tmp<Foam::pointField>
Foam::displacementMeshMoverMotionSolver::curPoints() const
{
// Return actual points. Cannot do a reference since complains about
// assignment to self in polyMesh::movePoints
return tmp<pointField>(new pointField(mesh().points()));
}
void Foam::displacementMeshMoverMotionSolver::solve()
{
// The points have moved so before calculation update
// the mesh and motionSolver accordingly
movePoints(mesh().points());
// Update any point motion bcs (e.g. timevarying)
pointDisplacement().boundaryField().updateCoeffs();
label nAllowableErrors = 0;
meshMover().move(nAllowableErrors);
}
void Foam::displacementMeshMoverMotionSolver::movePoints(const pointField& p)
{
displacementMotionSolver::movePoints(p);
// Update meshMover for new geometry
if (meshMoverPtr_.valid())
{
meshMover().movePoints(p);
}
}
void Foam::displacementMeshMoverMotionSolver::updateMesh
(
const mapPolyMesh& map
)
{
displacementMotionSolver::updateMesh(map);
// Update meshMover for new topology
meshMoverPtr_.clear();
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::displacementMeshMoverMotionSolver
Description
Mesh motion solver for an fvMesh. Based on solving the cell-centre
Laplacian for the motion displacement.
SourceFiles
displacementMeshMoverMotionSolver.C
\*---------------------------------------------------------------------------*/
#ifndef displacementMeshMoverMotionSolver_H
#define displacementMeshMoverMotionSolver_H
#include "displacementMotionSolver.H"
#include "externalDisplacementMeshMover.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class displacementMeshMoverMotionSolver Declaration
\*---------------------------------------------------------------------------*/
class displacementMeshMoverMotionSolver
:
public displacementMotionSolver
{
// Private data
mutable autoPtr<externalDisplacementMeshMover> meshMoverPtr_;
// Private Member Functions
//- Disallow default bitwise copy construct
displacementMeshMoverMotionSolver
(
const displacementMeshMoverMotionSolver&
);
//- Disallow default bitwise assignment
void operator=(const displacementMeshMoverMotionSolver&);
public:
//- Runtime type information
TypeName("displacementMeshMover");
// Constructors
//- Construct from polyMesh and IOdictionary
displacementMeshMoverMotionSolver(const polyMesh&, const IOdictionary&);
//- Destructor
~displacementMeshMoverMotionSolver();
// Member Functions
externalDisplacementMeshMover& meshMover() const;
//- Return point location obtained from the current motion field
virtual tmp<pointField> curPoints() const;
//- Solve for motion
virtual void solve();
//- Update local data for geometry changes
virtual void movePoints(const pointField&);
//- Update topology
virtual void updateMesh(const mapPolyMesh&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "externalDisplacementMeshMover.H"
#include "mapPolyMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(externalDisplacementMeshMover, 0);
defineRunTimeSelectionTable(externalDisplacementMeshMover, dictionary);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::externalDisplacementMeshMover::externalDisplacementMeshMover
(
const dictionary& dict,
const List<labelPair>& baffles,
pointVectorField& pointDisplacement
)
:
dict_(dict),
baffles_(baffles),
pointDisplacement_(pointDisplacement)
{}
// * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::externalDisplacementMeshMover>
Foam::externalDisplacementMeshMover::New
(
const word& type,
const dictionary& dict,
const List<labelPair>& baffles,
pointVectorField& pointDisplacement
)
{
Info<< "Selecting externalDisplacementMeshMover " << type << endl;
dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(type);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorIn
(
"externalDisplacementMeshMover::New(const word&"
", pointVectorField&, const List<labelPair>&"
", const dictionary&)"
) << "Unknown externalDisplacementMeshMover type "
<< type << nl << nl
<< "Valid externalDisplacementMeshMover types:" << endl
<< dictionaryConstructorTablePtr_->sortedToc()
<< exit(FatalError);
}
return autoPtr<externalDisplacementMeshMover>
(
cstrIter()(dict, baffles, pointDisplacement)
);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::externalDisplacementMeshMover::~externalDisplacementMeshMover()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::externalDisplacementMeshMover::movePoints(const pointField&)
{
// No local data to update
}
void Foam::externalDisplacementMeshMover::updateMesh(const mapPolyMesh& mpm)
{
// Renumber baffles
DynamicList<labelPair> newBaffles(baffles_.size());
forAll(baffles_, i)
{
label f0 = mpm.reverseFaceMap()[baffles_[i].first()];
label f1 = mpm.reverseFaceMap()[baffles_[i].second()];
if (f0 >= 0 && f1 >= 0)
{
newBaffles.append(labelPair(f0, f1));
}
}
newBaffles.shrink();
baffles_.transfer(newBaffles);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::externalDisplacementMeshMover
Description
Virtual base class for mesh movers with externally provided displacement
field giving the boundary conditions. Move the mesh from the current
location to a new location (so modify the mesh; v.s. motionSolver that
only returns the new location)
SourceFiles
externalDisplacementMeshMover.C
\*---------------------------------------------------------------------------*/
#ifndef externalDisplacementMeshMover_H
#define externalDisplacementMeshMover_H
#include "pointFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class mapPolyMesh;
/*---------------------------------------------------------------------------*\
Class externalDisplacementMeshMover Declaration
\*---------------------------------------------------------------------------*/
class externalDisplacementMeshMover
{
protected:
// Protected data
//- Settings
dictionary dict_;
//- Baffles in the mesh
List<labelPair> baffles_;
//- Reference to point motion field
pointVectorField& pointDisplacement_;
private:
// Private Member Functions
//- Disallow default bitwise copy construct
externalDisplacementMeshMover
(
const externalDisplacementMeshMover&
);
//- Disallow default bitwise assignment
void operator=(const externalDisplacementMeshMover&);
public:
//- Runtime type information
TypeName("externalDisplacementMeshMover");
// Declare run-time New selection table
declareRunTimeSelectionTable
(
autoPtr,
externalDisplacementMeshMover,
dictionary,
(
const dictionary& dict,
const List<labelPair>& baffles,
pointVectorField& pointDisplacement
),
(dict, baffles, pointDisplacement)
);
// Constructors
//- Construct from dictionary and displacement field
externalDisplacementMeshMover
(
const dictionary& dict,
const List<labelPair>& baffles,
pointVectorField& pointDisplacement
);
// Selectors
//- Return a reference to the selected meshMover model
static autoPtr<externalDisplacementMeshMover> New
(
const word& type,
const dictionary& dict,
const List<labelPair>& baffles,
pointVectorField& pointDisplacement
);
//- Destructor
virtual ~externalDisplacementMeshMover();
// Member Functions
// Access
//- Return reference to the point motion displacement field
pointVectorField& pointDisplacement()
{
return pointDisplacement_;
}
//- Return const reference to the point motion displacement field
const pointVectorField& pointDisplacement() const
{
return pointDisplacement_;