ccmWriter.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2025 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::ccm::writer
28 
29 Description
30  Write OpenFOAM meshes and/or results to CCM format
31 
32  - partial support for interfaces
33  - no monitoring (internal) boundaries
34  - does not handle Lagrangian data
35 
36  \par Files
37 
38  The <tt>constant/boundaryRegion</tt> and <tt>constant/cellTable</tt> files,
39  which are described in ccmReader, are used to construct the CCM
40  \c ProblemDescription node.
41 
42  The <tt>constant/remapping</tt> file is an \c IOdictionary that is
43  \c READ_IF_PRESENT and can be used to remap certain information.
44  eg,
45 
46  \verbatim
47  // map OpenFOAM scalar fields to CCM output fields
48  fields
49  {
50  tracer0
51  {
52  name CONC_001;
53  Label "tracer0";
54  }
55  tracer1
56  {
57  name CONC_002;
58  Label "tracer1";
59  }
60  tracer2
61  {
62  name CONC_003;
63  Label "tracer2";
64  }
65  divPhi
66  {
67  name CONC_004;
68  Label "divPhi";
69  }
70  // an example with units:
71  p
72  {
73  name P;
74  Label "Pressure";
75  units "Pa";
76  }
77  }
78  \endverbatim
79 
80 Note
81  This class is in development
82  - any/all of the class names and members may change
83 
84 SourceFiles
85  ccmWriter.C
86  ccmWriterMesh.C
87  ccmWriterSolution.C
88 
89 \*---------------------------------------------------------------------------*/
90 
91 #ifndef Foam_ccmWriter_H
92 #define Foam_ccmWriter_H
93 
94 #include "ccmBase.H"
95 #include "STARCDCore.H"
96 
97 #include "fvMesh.H"
98 #include "boundaryRegion.H"
99 #include "cellTable.H"
100 #include "IOobjectList.H"
101 
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 
104 namespace Foam
105 {
106 namespace ccm
107 {
108 
109 // Forward Declarations
110 class ccmID;
111 class ccmMaps;
112 class ccmDimension;
113 class ccmGlobalState;
115 /*---------------------------------------------------------------------------*\
116  Class ccm::writer Declaration
117 \*---------------------------------------------------------------------------*/
118 
119 class writer
120 :
121  public base,
122  protected fileFormats::STARCDCore
123 {
124  // Private Data
125 
126  // Static Data
127 
128  //- The OpenFOAM -> CCM field mappings
129  static dictionary defaultNameMapping;
130 
131 
132  // Member Data
133 
134  //- MapIds for various components (cell, internalFaces, boundaries)
135  std::unique_ptr<ccmMaps> maps_;
136 
137  //- mesh reference
138  const polyMesh& mesh_;
139 
140  //- Lookup between cellModel shape and PROSTAR shape
141  const Map<label> prostarShapeLookup_;
142 
143  //- ccm node: ProblemDescriptions/boundaryRegion
144  boundaryRegion boundaryRegion_;
145 
146  // ccm node: ProblemDescriptions/cellType
147  cellTable cellTable_;
148 
149 
150  // Private Member Functions
151 
152  //- create a filled linear map with 'size' from 'start + 1'
153  void addLinearMap
154  (
155  const std::string& mapName,
156  ccmID& mapId,
157  label size,
158  label start = 0
159  ) const;
160 
161  void writeBoundaryRegion(const ccmID& probNode) const;
162 
163  void writeCellTable(const ccmID& probNode) const;
164 
165  //- write out problem description
166  void writeProblem(const ccmID& stateNode) const;
167 
168  //- Return the PROSTAR face id for the given cell/face
169  label prostarCellFaceId(const label cellId, const label faceI) const;
170 
171  // write the faces, the number of vertices appears before each entry
172  void writeFaces
173  (
174  const ccmID& nodeId,
175  const ccmID& mapId,
176  bool isBoundary, // boundary or internal faces
177  label size,
178  label start = 0
179  ) const;
180 
181  void writeVertices(const ccmID& verticesNode) const;
182 
183  // - write internal faces with owner/neighbour
184  void writeInternalFaces(const ccmID& topoNode) const;
185 
186  // - write boundary faces with owner
187  void writeBoundaryFaces(const ccmID& topoNode) const;
188 
189  void writeCells(const ccmID& topoNode);
190 
191  void writeInterfaces(const ccmID& cellsNode) const;
192 
193  bool newFieldNode
194  (
195  const ccmID& phaseNode,
196  const word& fieldName,
197  const dictionary& nameMapping,
198  const ccmDimension& ccmDim,
199  ccmID& fieldNode
200  ) const;
201 
202 
203  //- Return patch named 'Default_Boundary_Region' or -1 on error
204  label findDefaultBoundary() const;
205 
206 
207 public:
208 
209  // Static Data Members
210 
211  //- The name for the topology file reference
213  static string defaultMeshName;
214 
215 
216  // Generated Methods
217 
218  //- No copy construct
219  writer(const writer&) = delete;
220 
221  //- No copy assignment
222  void operator=(const writer&) = delete;
223 
224 
225  // Constructors
226 
227  //- Open a file for writing, with backup/overwrite existing file
229  writer
230  (
231  const fileName& file,
232  const polyMesh& mesh,
233  const bool backup=true
234  );
235 
236 
237  //- Destructor (closes file)
239  ~writer();
240 
241 
242  // Member Functions
243 
244  // Write
245 
246  //- Write the mesh
248  void writeGeometry();
249 
250  //- Write the solutions
251  // provide optional remapping dictionary
253  void writeSolution
254  (
255  const IOobjectList& objects,
256  const fileName& remappingDictName = fileName::null
257  );
258 };
259 
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 } // End namespace ccm
264 } // End namespace Foam
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 #endif
269 
270 // ************************************************************************* //
writer(const writer &)=delete
No copy construct.
A class for handling file names.
Definition: fileName.H:72
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
FOAM_DLL_EXPORT void writeSolution(const IOobjectList &objects, const fileName &remappingDictName=fileName::null)
Write the solutions.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
Base functionality common to reader and writer classes.
Definition: ccmBase.H:70
static const fileName null
An empty fileName.
Definition: fileName.H:111
Write OpenFOAM meshes and/or results to CCM format.
Definition: ccmWriter.H:114
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
Core routines used when reading/writing PROSTAR vrt/cel/bnd files.
Definition: STARCDCore.H:55
FOAM_DLL_EXPORT void writeGeometry()
Write the mesh.
The cellTable persistent data saved as a Map<dictionary>.
Definition: cellTable.H:77
label cellId
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
FOAM_DLL_EXPORT ~writer()
Destructor (closes file)
Definition: ccmWriter.C:369
The boundaryRegion persistent data saved as a Map<dictionary>.
#define FOAM_DLL_EXPORT
Definition: ccmBase.H:50
static FOAM_DLL_EXPORT string defaultMeshName
The name for the topology file reference.
Definition: ccmWriter.H:228
void operator=(const writer &)=delete
No copy assignment.
Namespace for OpenFOAM.