Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / dataConversion / foamToFPMA / writeMeshFPMA.C
blob3597092422319af1658bba2447bb957c365a7934
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | cfMesh: A library for mesh generation
4    \\    /   O peration     |
5     \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6      \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9     This file is part of cfMesh.
11     cfMesh is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 3 of the License, or (at your
14     option) any later version.
16     cfMesh is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with cfMesh.  If not, see <http://www.gnu.org/licenses/>.
24 Description
25     Translates FOAM mesh to AVL's FPMA format
27 \*---------------------------------------------------------------------------*/
29 #include "objectRegistry.H"
30 #include "foamTime.H"
31 #include "polyMeshGen.H"
32 #include "meshSurfaceEngine.H"
33 #include "OFstream.H"
34 #include "IOmanip.H"
35 #include "fileName.H"
37 #include "fpmaMesh.H"
38 #include "writeMeshFPMA.H"
39 #include "helperFunctions.H"
41 namespace Foam
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 void writeMeshFPMA(const polyMeshGen& mesh, const word& fName)
48     const Time& time = mesh.returnTime();
50     const word postProcDir = "FPMA";
52     fileName postProcPath = time.path()/postProcDir;
54     if( !Foam::isDir(postProcPath) )
55     {
56         mkDir(postProcPath);
57     }
59     // Open the Case file
60     const fileName fpmaFileName = fName + ".fpma";
62     Info << "Writting mesh into " << fpmaFileName << endl;
64 /*    OFstream fpmaGeometryFile
65     (
66         postProcPath/fpmaFileName,
67         IOstream::ASCII,
68         IOstream::currentVersion,
69         IOstream::UNCOMPRESSED
70     );
73     OFstream fpmaGeometryFile(postProcPath/fpmaFileName);
75     // Construct the FIRE mesh
76     fpmaMesh Mesh(mesh);
77     Mesh.write(fpmaGeometryFile);
80 void createFIRESelections(polyMeshGen& mesh)
82     if( !Pstream::parRun() )
83         return;
85     const faceListPMG& faces = mesh.faces();
86     const PtrList<processorBoundaryPatch>& procBoundaries =
87         mesh.procBoundaries();
89     //- create face selections from proc patches
90     forAll(procBoundaries, patchI)
91     {
92         word sName = "InterFacesToProc";
93         sName += help::scalarToText(procBoundaries[patchI].neiProcNo());
94         const label sID = mesh.addFaceSubset(sName);
96         label faceI = procBoundaries[patchI].patchStart();
97         const label end = faceI + procBoundaries[patchI].patchSize();
98         for(;faceI<end;++faceI)
99             mesh.addFaceToSubset(sID, faceI);
100     }
102     //- create cell selections
103     DynList<label> subsets;
104     mesh.faceSubsetIndices(subsets);
105     forAll(subsets, subsetI)
106     {
107         const word sName = mesh.faceSubsetName(subsets[subsetI]);
109         if( sName.substr(0, 10) == "processor_" )
110         {
111             const word newName = "Proc" + sName.substr(10, sName.size()-10);
113             labelLongList cellsInSubset;
114             mesh.cellsInSubset(subsets[subsetI], cellsInSubset);
115             const label subsetID = mesh.addCellSubset(newName);
116             forAll(cellsInSubset, i)
117                 mesh.addCellToSubset(subsetID, cellsInSubset[i]);
118         }
119     }
121     //- creating node selections
122     boolList bndVertex(mesh.points().size(), false);
123     forAll(mesh.boundaries(), patchI)
124     {
125         label faceI = mesh.boundaries()[patchI].patchStart();
126         const label end = faceI + mesh.boundaries()[patchI].patchSize();
127         for(;faceI<end;++faceI)
128         {
129             const face& f = mesh.faces()[faceI];
131             forAll(f, pI)
132                 bndVertex[f[pI]] = true;
133         }
134     }
136     forAll(procBoundaries, patchI)
137     {
138         word sName = "InterSurfaceEdgesToProc";
139         sName += help::scalarToText(procBoundaries[patchI].neiProcNo());
140         const label subsetID = mesh.addPointSubset(sName);
142         label faceI = procBoundaries[patchI].patchStart();
143         const label end = faceI + procBoundaries[patchI].patchSize();
144         for(;faceI<end;++faceI)
145         {
146             const face& f = faces[faceI];
148             forAll(f, pI)
149             {
150                 if( bndVertex[f[pI]] )
151                     mesh.addPointToSubset(subsetID, f[pI]);
152             }
153         }
154     }
159 // ************************************************************************* //