diff --git a/applications/utilities/mesh/manipulation/singleCellMesh/Make/files b/applications/utilities/mesh/manipulation/singleCellMesh/Make/files new file mode 100644 index 0000000000..db941393b0 --- /dev/null +++ b/applications/utilities/mesh/manipulation/singleCellMesh/Make/files @@ -0,0 +1,3 @@ +singleCellMesh.C + +EXE = $(FOAM_APPBIN)/singleCellMesh diff --git a/applications/utilities/mesh/manipulation/singleCellMesh/Make/options b/applications/utilities/mesh/manipulation/singleCellMesh/Make/options new file mode 100644 index 0000000000..89e52b6d52 --- /dev/null +++ b/applications/utilities/mesh/manipulation/singleCellMesh/Make/options @@ -0,0 +1,6 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude + +EXE_LIBS = \ + -lfiniteVolume + diff --git a/applications/utilities/mesh/manipulation/singleCellMesh/singleCellMesh.C b/applications/utilities/mesh/manipulation/singleCellMesh/singleCellMesh.C new file mode 100644 index 0000000000..fe1e2850b9 --- /dev/null +++ b/applications/utilities/mesh/manipulation/singleCellMesh/singleCellMesh.C @@ -0,0 +1,142 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 + +Application + singleCellMesh + +Description + Removes all but one cells of the mesh. Used to generate mesh and fields + that can be used for boundary-only data. + Might easily result in illegal mesh though so only look at boundaries + in paraview. + +\*---------------------------------------------------------------------------*/ + + +#include "argList.H" +#include "fvMesh.H" +#include "volFields.H" +#include "Time.H" +#include "ReadFields.H" +#include "singleCellFvMesh.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +void interpolateFields +( + const singleCellFvMesh& scMesh, + const PtrList& flds +) +{ + forAll(flds, i) + { + tmp scFld = scMesh.interpolate(flds[i]); + GeoField* scFldPtr = scFld.ptr(); + scFldPtr->writeOpt() = IOobject::AUTO_WRITE; + scFldPtr->store(); + } +} + + +// Main program: + +int main(int argc, char *argv[]) +{ + Foam::argList::validOptions.insert("overwrite", ""); +# include "addTimeOptions.H" +# include "setRootCase.H" +# include "createTime.H" + // Get times list + instantList Times = runTime.times(); +# include "checkTimeOptions.H" + runTime.setTime(Times[startTime], startTime); +# include "createMesh.H" + const word oldInstance = mesh.pointsInstance(); + + bool overwrite = args.optionFound("overwrite"); + + + // Read objects in time directory + IOobjectList objects(mesh, runTime.timeName()); + + // Read vol fields. + PtrList vsFlds; + ReadFields(mesh, objects, vsFlds); + + PtrList vvFlds; + ReadFields(mesh, objects, vvFlds); + + PtrList vstFlds; + ReadFields(mesh, objects, vstFlds); + + PtrList vsymtFlds; + ReadFields(mesh, objects, vsymtFlds); + + PtrList vtFlds; + ReadFields(mesh, objects, vtFlds); + + + if (!overwrite) + { + runTime++; + } + + // Create the mesh + singleCellFvMesh scMesh + ( + IOobject + ( + mesh.name(), + mesh.polyMesh::instance(), + runTime, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh + ); + + + // Map and store the fields on the scMesh. + interpolateFields(scMesh, vsFlds); + interpolateFields(scMesh, vvFlds); + interpolateFields(scMesh, vstFlds); + interpolateFields(scMesh, vsymtFlds); + interpolateFields(scMesh, vtFlds); + + + // Write + Info<< "Writing mesh to time " << runTime.timeName() << endl; + scMesh.write(); + + + Info<< "End\n" << endl; + + return 0; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitivePatch/uindirectPrimitivePatch.H b/src/OpenFOAM/meshes/primitiveMesh/primitivePatch/uindirectPrimitivePatch.H new file mode 100644 index 0000000000..4afb30dd22 --- /dev/null +++ b/src/OpenFOAM/meshes/primitiveMesh/primitivePatch/uindirectPrimitivePatch.H @@ -0,0 +1,53 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 + +Typedef + Foam::uindirectPrimitivePatch + +Description + Foam::uindirectPrimitivePatch + +\*---------------------------------------------------------------------------*/ + +#ifndef uindirectPrimitivePatch_H +#define uindirectPrimitivePatch_H + +#include "PrimitivePatch.H" +#include "face.H" +#include "UIndirectList.H" +#include "pointField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef PrimitivePatch + uindirectPrimitivePatch; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index c387ac994d..5fe44b9357 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -1,6 +1,7 @@ fvMesh/fvMeshGeometry.C fvMesh/fvMesh.C +fvMesh/singleCellFvMesh/singleCellFvMesh.C fvMesh/fvMeshSubset/fvMeshSubset.C fvBoundaryMesh = fvMesh/fvBoundaryMesh diff --git a/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C b/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C new file mode 100644 index 0000000000..65965f15d9 --- /dev/null +++ b/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C @@ -0,0 +1,640 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-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 "singleCellFvMesh.H" +#include "syncTools.H" +#include "uindirectPrimitivePatch.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +// Conversion is a two step process: +// - from original (fine) patch faces to agglomerations (aggloms might not +// be in correct patch order) +// - from agglomerations to coarse patch faces +void Foam::singleCellFvMesh::agglomerateMesh +( + const fvMesh& mesh, + const labelListList& agglom +) +{ + const polyBoundaryMesh& oldPatches = mesh.boundaryMesh(); + + // Check agglomeration within patch face range and continuous + labelList nAgglom(oldPatches.size()); + + forAll(oldPatches, patchI) + { + const polyPatch& pp = oldPatches[patchI]; + + nAgglom[patchI] = max(agglom[patchI])+1; + + forAll(pp, i) + { + if (agglom[patchI][i] < 0 || agglom[patchI][i] >= pp.size()) + { + FatalErrorIn + ( + "singleCellFvMesh::agglomerateMesh(..)" + ) << "agglomeration on patch " << patchI + << " is out of range 0.." << pp.size()-1 + << exit(FatalError); + } + } + } + + // Check agglomeration is sync + { + // Get neighbouring agglomeration + labelList nbrAgglom(mesh.nFaces()-mesh.nInternalFaces()); + forAll(oldPatches, patchI) + { + const polyPatch& pp = oldPatches[patchI]; + + if (pp.coupled()) + { + label offset = pp.start()-mesh.nInternalFaces(); + forAll(pp, i) + { + nbrAgglom[offset+i] = agglom[patchI][i]; + } + } + } + syncTools::swapBoundaryFaceList(mesh, nbrAgglom, false); + + + // Get correspondence between this agglomeration and remote one + Map