diff --git a/applications/solvers/incompressible/pimpleDyMFoam/Make/options b/applications/solvers/incompressible/pimpleDyMFoam/Make/options index e14eec2585..40023adad7 100644 --- a/applications/solvers/incompressible/pimpleDyMFoam/Make/options +++ b/applications/solvers/incompressible/pimpleDyMFoam/Make/options @@ -9,6 +9,7 @@ EXE_INC = \ EXE_LIBS = \ -ldynamicFvMesh \ + -ltopoChangerFvMesh \ -ldynamicMesh \ -lmeshTools \ -lincompressibleTransportModels \ diff --git a/applications/solvers/multiphase/compressibleInterDyMFoam/Make/options b/applications/solvers/multiphase/compressibleInterDyMFoam/Make/options index af146aaa38..75094c8b16 100644 --- a/applications/solvers/multiphase/compressibleInterDyMFoam/Make/options +++ b/applications/solvers/multiphase/compressibleInterDyMFoam/Make/options @@ -16,5 +16,6 @@ EXE_LIBS = \ -lfiniteVolume \ -ldynamicMesh \ -lmeshTools \ - -ldynamicFvMesh + -ldynamicFvMesh \ + -ltopoChangerFvMesh diff --git a/src/dynamicMesh/Make/files b/src/dynamicMesh/Make/files index 2343124597..e59bbe3800 100644 --- a/src/dynamicMesh/Make/files +++ b/src/dynamicMesh/Make/files @@ -16,16 +16,13 @@ $(enrichedPatch)/enrichedPatchPointPoints.C $(enrichedPatch)/enrichedPatchCutFaces.C $(enrichedPatch)/enrichedPatchMasterPoints.C -/* polyTopoChange/polyTopoChange/polyTopoChange.C */ -polyTopoChange/polyTopoChange/topoAction/topoActions.C polyMeshModifier = polyTopoChange/polyMeshModifier $(polyMeshModifier)/polyMeshModifier.C $(polyMeshModifier)/newPolyMeshModifier.C +polyTopoChange/polyTopoChange/topoAction/topoActions.C polyTopoChange/polyTopoChanger/polyTopoChanger.C -/* polyTopoChange/polyTopoChanger/polyTopoChangerChangeMesh.C */ - polyTopoChange/polyTopoChange/polyTopoChange.C polyTopoChange/polyTopoChange/addPatchCellLayer.C polyTopoChange/polyTopoChange/edgeCollapser.C diff --git a/src/topoChangerFvMesh/Make/files b/src/topoChangerFvMesh/Make/files index 838500fd8b..1788317304 100644 --- a/src/topoChangerFvMesh/Make/files +++ b/src/topoChangerFvMesh/Make/files @@ -1,4 +1,5 @@ topoChangerFvMesh/topoChangerFvMesh.C +rawTopoChangerFvMesh/rawTopoChangerFvMesh.C /* linearValveFvMesh/linearValveFvMesh.C diff --git a/src/topoChangerFvMesh/rawTopoChangerFvMesh/rawTopoChangerFvMesh.C b/src/topoChangerFvMesh/rawTopoChangerFvMesh/rawTopoChangerFvMesh.C new file mode 100644 index 0000000000..ccfb392b2e --- /dev/null +++ b/src/topoChangerFvMesh/rawTopoChangerFvMesh/rawTopoChangerFvMesh.C @@ -0,0 +1,180 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "rawTopoChangerFvMesh.H" +#include "mapPolyMesh.H" +#include "addToRunTimeSelectionTable.H" +#include "volFields.H" +#include "linear.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(rawTopoChangerFvMesh, 0); + addToRunTimeSelectionTable + ( + topoChangerFvMesh, + rawTopoChangerFvMesh, + IOobject + ); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +// Construct from components +Foam::rawTopoChangerFvMesh::rawTopoChangerFvMesh(const IOobject& io) +: + topoChangerFvMesh(io) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::rawTopoChangerFvMesh::~rawTopoChangerFvMesh() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::rawTopoChangerFvMesh::update() +{ + // Do mesh changes (use inflation - put new points in topoChangeMap) + Info<< "rawTopoChangerFvMesh : Checking for topology changes..." + << endl; + autoPtr topoChangeMap = topoChanger_.changeMesh(true); + + bool hasChanged = topoChangeMap.valid(); + + if (hasChanged) + { + Info<< "rawTopoChangerFvMesh : Done topology changes..." + << endl; + + // Temporary: fix fields on patch faces created out of nothing + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + // Two situations: + // - internal faces inflated out of nothing + // - patch faces created out of previously internal faces + + // Is face mapped in any way + PackedList<1> mappedFace(nFaces()); + + const label nOldInternal = topoChangeMap().oldPatchStarts()[0]; + + const labelList& faceMap = topoChangeMap().faceMap(); + for (label faceI = 0; faceI < nInternalFaces(); faceI++) + { + if (faceMap[faceI] >= 0) + { + mappedFace[faceI] = 1; + } + } + for (label faceI = nInternalFaces(); faceI < nFaces(); faceI++) + { + if (faceMap[faceI] >= 0 && faceMap[faceI] >= nOldInternal) + { + mappedFace[faceI] = 1; + } + } + + const List& fromFaces = topoChangeMap().facesFromFacesMap(); + + forAll(fromFaces, i) + { + mappedFace[fromFaces[i].index()] = 1; + } + + const List& fromEdges = topoChangeMap().facesFromEdgesMap(); + + forAll(fromEdges, i) + { + mappedFace[fromEdges[i].index()] = 1; + } + + const List& fromPts = topoChangeMap().facesFromPointsMap(); + + forAll(fromPts, i) + { + mappedFace[fromPts[i].index()] = 1; + } + + // Set unmapped faces to zero + Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values." + << endl; + zeroUnmappedValues(mappedFace); + zeroUnmappedValues(mappedFace); + zeroUnmappedValues(mappedFace); + zeroUnmappedValues(mappedFace); + zeroUnmappedValues(mappedFace); + + // Special handling for phi: set unmapped faces to recreated phi + Info<< "rawTopoChangerFvMesh :" + << " recreating phi for unmapped boundary values." << endl; + const volVectorField& U = lookupObject("U"); + surfaceScalarField& phi = const_cast + ( + lookupObject("phi") + ); + setUnmappedValues + ( + phi, + mappedFace, + (linearInterpolate(U) & Sf())() + ); + + + if (topoChangeMap().hasMotionPoints()) + { + pointField newPoints = topoChangeMap().preMotionPoints(); + + // Give the meshModifiers opportunity to modify points + Info<< "rawTopoChangerFvMesh :" + << " calling modifyMotionPoints." << endl; + topoChanger_.modifyMotionPoints(newPoints); + + // Actually move points + Info<< "rawTopoChangerFvMesh :" + << " calling movePoints." << endl; + + movePoints(newPoints); + } + } + else + { + //Pout<< "rawTopoChangerFvMesh :" + // << " no topology changes..." << endl; + } + + changing(hasChanged); + + return hasChanged; +} + + +// ************************************************************************* // diff --git a/src/topoChangerFvMesh/rawTopoChangerFvMesh/rawTopoChangerFvMesh.H b/src/topoChangerFvMesh/rawTopoChangerFvMesh/rawTopoChangerFvMesh.H new file mode 100644 index 0000000000..612829c3c8 --- /dev/null +++ b/src/topoChangerFvMesh/rawTopoChangerFvMesh/rawTopoChangerFvMesh.H @@ -0,0 +1,117 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::rawTopoChangerFvMesh + +Description + topoChangerFvMesh without any added functionality. + + Note: run without FOAM_SETNAN. Temporary has unitialised patch + data when faces get created out of nothing. + +SourceFiles + rawTopoChangerFvMesh.C + +\*---------------------------------------------------------------------------*/ + +#ifndef rawTopoChangerFvMesh_H +#define rawTopoChangerFvMesh_H + +#include "topoChangerFvMesh.H" +#include "PackedList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes + +/*---------------------------------------------------------------------------*\ + Class rawTopoChangerFvMesh Declaration +\*---------------------------------------------------------------------------*/ + +class rawTopoChangerFvMesh +: + public topoChangerFvMesh +{ + // Private Member Functions + + //- Set unmapped values + template class PatchField, class GeoMesh> + static void setUnmappedValues + ( + GeometricField& fld, + const PackedList<1>& mappedFace, + const GeometricField& baseFld + ); + + template class PatchField, class GeoMesh> + void zeroUnmappedValues(const PackedList<1>&) const; + + //- Disallow default bitwise copy construct + rawTopoChangerFvMesh(const rawTopoChangerFvMesh&); + + //- Disallow default bitwise assignment + void operator=(const rawTopoChangerFvMesh&); + +public: + + //- Runtime type information + TypeName("rawTopoChangerFvMesh"); + + + // Constructors + + //- Construct from database + explicit rawTopoChangerFvMesh(const IOobject& io); + + // Destructor + + virtual ~rawTopoChangerFvMesh(); + + + // Member Functions + + //- Update the mesh for both mesh motion and topology change + virtual bool update(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "rawTopoChangerFvMeshTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/topoChangerFvMesh/rawTopoChangerFvMesh/rawTopoChangerFvMeshTemplates.C b/src/topoChangerFvMesh/rawTopoChangerFvMesh/rawTopoChangerFvMeshTemplates.C new file mode 100644 index 0000000000..0be0306186 --- /dev/null +++ b/src/topoChangerFvMesh/rawTopoChangerFvMesh/rawTopoChangerFvMeshTemplates.C @@ -0,0 +1,107 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "rawTopoChangerFvMesh.H" +#include "Time.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template class PatchField, class GeoMesh> +void Foam::rawTopoChangerFvMesh::setUnmappedValues +( + GeometricField& fld, + const PackedList<1>& mappedFace, + const GeometricField& baseFld +) +{ + //Pout<< "Checking field " << fld.name() << endl; + + forAll(fld.boundaryField(), patchI) + { + PatchField& fvp = const_cast&> + ( + fld.boundaryField()[patchI] + ); + + label start = fvp.patch().patch().start(); + forAll(fvp, i) + { + if (!mappedFace[start+i]) + { + //Pout<< "** Resetting unassigned value on patch " + // << fvp.patch().name() + // << " localface:" << i + // << " to:" << baseFld.boundaryField()[patchI][i] << endl; + fvp[i] = baseFld.boundaryField()[patchI][i]; + } + } + } +} + + +template class PatchField, class GeoMesh> +void Foam::rawTopoChangerFvMesh::zeroUnmappedValues +( + const PackedList<1>& mappedFace +) const +{ + typedef GeometricField FieldType; + + const wordList fldNames(names(FieldType::typeName)); + + forAll(fldNames, i) + { + //Pout<< "Checking field " << fldNames[i] << endl; + + FieldType& fld = const_cast + ( + lookupObject(fldNames[i]) + ); + + setUnmappedValues + ( + fld, + mappedFace, + FieldType + ( + IOobject + ( + "zero", + time().timeName(), + *this, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + *this, + dimensioned("0", fld.dimensions(), pTraits::zero) + ) + ); + } +} + + +// ************************************************************************* //