writeMeshFPMA.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 Description
25  Translates FOAM mesh to AVL's FPMA format
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "polyMeshGen.H"
30 #include "meshSurfaceEngine.H"
31 #include "OFstream.H"
32 #include "IOmanip.H"
33 #include "fileName.H"
34 
35 #include "fpmaMesh.H"
36 #include "writeMeshFPMA.H"
37 #include "helperFunctions.H"
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 void writeMeshFPMA(const polyMeshGen& mesh, const word& fName)
45 {
46  const Time& time = mesh.returnTime();
47 
48  const word postProcDir = "FPMA";
49 
50  fileName postProcPath = time.path()/postProcDir;
51 
52  if( !Foam::isDir(postProcPath) )
53  {
54  mkDir(postProcPath);
55  }
56 
57  // Open the Case file
58  const fileName fpmaFileName = fName + ".fpma";
59 
60  Info << "Writting mesh into " << fpmaFileName << endl;
61 
62 /* OFstream fpmaGeometryFile
63  (
64  postProcPath/fpmaFileName,
65  IOstream::ASCII,
66  IOstream::currentVersion,
67  IOstream::UNCOMPRESSED
68  );
69 */
70 
71  OFstream fpmaGeometryFile(postProcPath/fpmaFileName);
72 
73  // Construct the FIRE mesh
74  fpmaMesh Mesh(mesh);
75  Mesh.write(fpmaGeometryFile);
76 }
77 
79 {
80  if( !Pstream::parRun() )
81  return;
82 
83  const faceListPMG& faces = mesh.faces();
84  const PtrList<processorBoundaryPatch>& procBoundaries =
85  mesh.procBoundaries();
86 
87  //- create face selections from proc patches
88  forAll(procBoundaries, patchI)
89  {
90  word sName = "InterFacesToProc";
91  sName += help::scalarToText(procBoundaries[patchI].neiProcNo());
92  const label sID = mesh.addFaceSubset(sName);
93 
94  label faceI = procBoundaries[patchI].patchStart();
95  const label end = faceI + procBoundaries[patchI].patchSize();
96  for(;faceI<end;++faceI)
97  mesh.addFaceToSubset(sID, faceI);
98  }
99 
100  //- create cell selections
101  DynList<label> subsets;
102  mesh.faceSubsetIndices(subsets);
103  forAll(subsets, subsetI)
104  {
105  const word sName = mesh.faceSubsetName(subsets[subsetI]);
106 
107  if( sName.substr(0, 10) == "processor_" )
108  {
109  const word newName = "Proc" + sName.substr(10, sName.size()-10);
110 
111  labelLongList cellsInSubset;
112  mesh.cellsInSubset(subsets[subsetI], cellsInSubset);
113  const label subsetID = mesh.addCellSubset(newName);
114  forAll(cellsInSubset, i)
115  mesh.addCellToSubset(subsetID, cellsInSubset[i]);
116  }
117  }
118 
119  //- creating node selections
120  boolList bndVertex(mesh.points().size(), false);
121  forAll(mesh.boundaries(), patchI)
122  {
123  label faceI = mesh.boundaries()[patchI].patchStart();
124  const label end = faceI + mesh.boundaries()[patchI].patchSize();
125  for(;faceI<end;++faceI)
126  {
127  const face& f = mesh.faces()[faceI];
128 
129  forAll(f, pI)
130  bndVertex[f[pI]] = true;
131  }
132  }
133 
134  forAll(procBoundaries, patchI)
135  {
136  word sName = "InterSurfaceEdgesToProc";
137  sName += help::scalarToText(procBoundaries[patchI].neiProcNo());
138  const label subsetID = mesh.addPointSubset(sName);
139 
140  label faceI = procBoundaries[patchI].patchStart();
141  const label end = faceI + procBoundaries[patchI].patchSize();
142  for(;faceI<end;++faceI)
143  {
144  const face& f = faces[faceI];
145 
146  forAll(f, pI)
147  {
148  if( bndVertex[f[pI]] )
149  mesh.addPointToSubset(subsetID, f[pI]);
150  }
151  }
152  }
153 }
154 
155 }
156 
157 // ************************************************************************* //
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::writeMeshFPMA
void writeMeshFPMA(const polyMeshGen &mesh, const word &fName)
Definition: writeMeshFPMA.C:44
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::help::scalarToText
word scalarToText(const scalar s)
convert the scalar value into text
Definition: helperFunctionsStringConversion.C:61
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::createFIRESelections
void createFIRESelections(polyMeshGen &mesh)
Definition: writeMeshFPMA.C:78
Foam::fpmaMesh::write
void write(OFstream &fpmaGeometryFile) const
Definition: fpmaMesh.C:177
Foam::polyMeshGen
Definition: polyMeshGen.H:46
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
OFstream.H
Foam::LongList< label >
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
writeMeshFPMA.H
Foam::Info
messageStream Info
polyMeshGen.H
fileName.H
IOmanip.H
Istream and Ostream manipulators taking arguments.
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::fpmaMesh
Definition: fpmaMesh.H:48
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
meshSurfaceEngine.H
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::DynList< label >
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:281
helperFunctions.H
f
labelList f(nPoints)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
fpmaMesh.H
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::faceListPMG
Definition: faceListPMG.H:50
Foam::mkDir
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:419