fpmaMesh.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 \*---------------------------------------------------------------------------*/
25 
26 #include "fpmaMesh.H"
27 #include "IOmanip.H"
28 
29 namespace Foam
30 {
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
36 // Construct from polyMeshGen
38 :
39  mesh_(mesh)
40 {
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
45 
47 {}
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
51 void Foam::fpmaMesh::writePoints(Foam::OFstream& fpmaGeometryFile) const
52 {
53  fpmaGeometryFile << mesh_.points().size() << nl;
54  const pointFieldPMG& points = mesh_.points();
55  forAll(points, pointI)
56  {
57  const point& p = points[pointI];
58  fpmaGeometryFile << p.x() << ' ' << p.y() << ' ' << p.z() << ' ';
59  }
60 
61  fpmaGeometryFile << nl;
62 }
63 
64 void fpmaMesh::writeCells(OFstream& fpmaGeometryFile) const
65 {
66  const cellListPMG& cells = mesh_.cells();
67 
68  fpmaGeometryFile << cells.size() << nl;
69  forAll(cells, cellI)
70  {
71  const cell& c = cells[cellI];
72 
73  fpmaGeometryFile << c.size();
74  forAll(c, fI)
75  fpmaGeometryFile << ' ' << c[fI];
76  fpmaGeometryFile << nl;
77  }
78 }
79 
80 void Foam::fpmaMesh::writeFaces(OFstream& fpmaGeometryFile) const
81 {
82  const faceListPMG& faces = mesh_.faces();
83  fpmaGeometryFile << faces.size() << nl;
84  forAll(faces, faceI)
85  {
86  const face& f = faces[faceI];
87 
88  fpmaGeometryFile << f.size();
89  forAllReverse(f, pI)
90  fpmaGeometryFile << ' ' << f[pI];
91  fpmaGeometryFile << nl;
92  }
93 }
94 
95 void Foam::fpmaMesh::writeSubsets(Foam::OFstream& fpmaGeometryFile) const
96 {
97  //- write patches as face selections
98  const PtrList<boundaryPatch>& patches = mesh_.boundaries();
99 
100  label nSubsets(0);
101 
102  nSubsets += patches.size();
103  DynList<label> indices;
104  mesh_.pointSubsetIndices(indices);
105  nSubsets += indices.size();
106  Info << "Mesh has " << indices.size() << " point subsets" << endl;
107  mesh_.faceSubsetIndices(indices);
108  nSubsets += indices.size();
109  Info << "Mesh has " << indices.size() << " face subsets" << endl;
110  mesh_.cellSubsetIndices(indices);
111  nSubsets += indices.size();
112  Info << "Mesh has " << indices.size() << " cell subsets" << endl;
113 
114  fpmaGeometryFile << nSubsets << nl;
115 
116  //- write patches as face selections
117  forAll(patches, patchI)
118  {
119  label start = patches[patchI].patchStart();
120  const label size = patches[patchI].patchSize();
121 
122  fpmaGeometryFile << patches[patchI].patchName() << nl;
123  fpmaGeometryFile << 3 << nl;
124  fpmaGeometryFile << size << nl;
125  for(label i=0;i<size;++i)
126  fpmaGeometryFile << start++ << ' ';
127  fpmaGeometryFile << nl;
128  }
129 
130  //- write node selections
131  mesh_.pointSubsetIndices(indices);
132  forAll(indices, indexI)
133  {
134  labelLongList nodesInSubset;
135  mesh_.pointsInSubset(indices[indexI], nodesInSubset);
136 
137  fpmaGeometryFile << mesh_.pointSubsetName(indices[indexI]) << nl;
138  fpmaGeometryFile << 1 << nl;
139  fpmaGeometryFile << nodesInSubset.size() << nl;
140  forAll(nodesInSubset, i)
141  fpmaGeometryFile << nodesInSubset[i] << ' ';
142  fpmaGeometryFile << nl;
143  }
144 
145  //- write face selections
146  mesh_.faceSubsetIndices(indices);
147  forAll(indices, indexI)
148  {
149  labelLongList facesInSubset;
150  mesh_.facesInSubset(indices[indexI], facesInSubset);
151 
152  fpmaGeometryFile << mesh_.faceSubsetName(indices[indexI]) << nl;
153  fpmaGeometryFile << 3 << nl;
154  fpmaGeometryFile << facesInSubset.size() << nl;
155  forAll(facesInSubset, i)
156  fpmaGeometryFile << facesInSubset[i] << ' ';
157  fpmaGeometryFile << nl;
158  }
159 
160  //- write cell selections
161  mesh_.cellSubsetIndices(indices);
162  forAll(indices, indexI)
163  {
164  labelLongList cellsInSubset;
165  mesh_.cellsInSubset(indices[indexI], cellsInSubset);
166 
167  fpmaGeometryFile << mesh_.cellSubsetName(indices[indexI]) << nl;
168  fpmaGeometryFile << 2 << nl;
169  fpmaGeometryFile << cellsInSubset.size() << nl;
170  forAll(cellsInSubset, i)
171  fpmaGeometryFile << cellsInSubset[i] << ' ';
172  fpmaGeometryFile << nl;
173  }
174 }
175 
176 
177 void fpmaMesh::write(OFstream& fpmaGeometryFile) const
178 {
179  writePoints(fpmaGeometryFile);
180 
181  writeFaces(fpmaGeometryFile);
182 
183  writeCells(fpmaGeometryFile);
184 
185  writeSubsets(fpmaGeometryFile);
186 }
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 } // End namespace Foam
191 
192 // ************************************************************************* //
Foam::fpmaMesh::writeFaces
void writeFaces(OFstream &fpmaGeometryFile) const
Definition: fpmaMesh.C:80
Foam::fpmaMesh::fpmaMesh
fpmaMesh(const fpmaMesh &)
Disallow default bitwise copy construct.
p
p
Definition: pEqn.H:62
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::fpmaMesh::writeCells
void writeCells(OFstream &fpmaGeometryFile) const
Definition: fpmaMesh.C:64
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
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
Foam::cellListPMG
Definition: cellListPMG.H:49
Foam::LongList< label >
Foam::fpmaMesh::writeSubsets
void writeSubsets(OFstream &fpmaGeometryFile) const
Definition: fpmaMesh.C:95
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
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::polyMeshGenCells::cells
const cellListPMG & cells() const
access to cells
Definition: polyMeshGenCellsI.H:39
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
forAllReverse
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: UList.H:418
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DynList< label >
Foam::fpmaMesh::writePoints
void writePoints(OFstream &fpmaGeometryFile) const
Definition: fpmaMesh.C:51
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
f
labelList f(nPoints)
Foam::faceListPMG::size
label size() const
return the number of used elements
Definition: faceListPMGI.H:73
Foam::Vector< scalar >
fpmaMesh.H
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::fpmaMesh::mesh_
const polyMeshGen & mesh_
Definition: fpmaMesh.H:73
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::DynList::size
label size() const
Definition: DynListI.H:235
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::fpmaMesh::~fpmaMesh
~fpmaMesh()
Definition: fpmaMesh.C:46
Foam::faceListPMG
Definition: faceListPMG.H:50
Foam::pointFieldPMG
Definition: pointFieldPMG.H:50
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56