ccmToFoam.C
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-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Application
27 ccmToFoam
28
29Group
30 grpMeshConversionUtilities
31
32Description
33 Reads CCM files as written by PROSTAR/STARCCM and writes an
34 OPENFOAM polyMesh.
35
36Usage
37 \b ccmToFoam [OPTION] ccmMesh
38
39 Options:
40 - \par -ascii
41 Write in ASCII format instead of binary
42
43 - \par -export
44 re-export mesh in CCM format for post-processing
45
46 - \par -list
47 List some information about the geometry
48
49 - \par -name <name>
50 Provide alternative base name for export.
51 Default is <tt>meshExport</tt>.
52
53 - \par -noBaffles
54 Remove any baffles by merging the faces.
55
56 - \par -merge
57 Merge in-place interfaces
58
59 - \par -numbered
60 Use numbered patch/zone (not names) directly from ccm ids.
61
62 - \par -remap <name>
63 Use specified remapping dictionary instead of
64 <tt>constant/remapping</tt>
65
66 - \par -scale <factor>
67 Specify an alternative geometry scaling factor.
68 The default is \b 1 (no scaling).
69
70 - \par -solids
71 Treat any solid cells present just like fluid cells.
72 The default is to remove them.
73
74Note
75 - sub-domains (fluid | solid | porosity) are stored as separate domains
76 within the CCM file. These are merged together to form a single mesh.
77 - baffles are written as interfaces for later use
78
79See also
80 Foam::ccm::reader for more information about the File Locations
81
82\*---------------------------------------------------------------------------*/
83
84#include "argList.H"
85#include "Time.H"
86#include "ccm.H"
87#include "regionSplit.H"
88
89using namespace Foam;
90
91// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92
93int main(int argc, char *argv[])
94{
95 argList::addNote
96 (
97 "Reads CCM files as written by PROSTAR/STARCCM and writes an OPENFOAM "
98 " polyMesh. Multi-region support for PROSTAR meshes should be stable."
99 " Multi-region merging for STARCCM meshes will not always be"
100 " successful."
101 );
102
103 argList::noParallel();
104 argList::addArgument("ccm-file", "The input .ccm or .ccmg file");
105 argList::addBoolOption
106 (
107 "ascii",
108 "Write in ASCII format instead of binary"
109 );
110 argList::addBoolOption
111 (
112 "export",
113 "Re-export mesh in CCM format for post-processing"
114 );
115 argList::addBoolOption
116 (
117 "list",
118 "List some information about the geometry"
119 );
120 argList::addOption
121 (
122 "remap",
123 "name",
124 "Use specified remapping dictionary instead of <constant/remapping>"
125 );
126 argList::addOption
127 (
128 "name",
129 "name",
130 "Provide alternative base name when re-exporting (implies -export). "
131 "Default is <meshExport>."
132 );
133 argList::addBoolOption
134 (
135 "noBaffles",
136 "Remove any baffles by merging the faces"
137 );
138 argList::addBoolOption
139 (
140 "merge",
141 "Merge in-place interfaces"
142 );
143 argList::addBoolOption
144 (
145 "numbered",
146 "Use numbered names (eg, patch_0, zone_0) only"
147 );
148 argList::addOption
149 (
150 "scale",
151 "scale",
152 "Geometry scaling factor - default is 1 (ie, no scaling)"
153 );
154 argList::addBoolOption
155 (
156 "solids",
157 "Treat any solid cells present just like fluid cells. "
158 "The default is to remove them."
159 );
160
161 argList::noFunctionObjects(); // Never use function objects
162
163 argList args(argc, argv);
165
166 runTime.functionObjects().off(); // Extra safety
167
168 const bool optList = args.found("list");
169
170 // exportName only has a size when export is in effect
171 fileName exportName;
172 if (args.readIfPresent("name", exportName))
173 {
174 const word ext(exportName.ext());
175 // strip erroneous extension (.ccm, .ccmg, .ccmp)
176 if (ext == "ccm" || ext == "ccmg" || ext == "ccmp")
177 {
178 exportName = exportName.lessExt();
179 }
180 }
181 else if (args.found("export"))
182 {
183 exportName = ccm::writer::defaultMeshName;
184 if (args.found("case"))
185 {
186 exportName += '-' + args.globalCaseName();
187 }
188 }
189
190 // By default, no scaling
191 const scalar scaleFactor = args.getOrDefault<scalar>("scale", 1);
192
193 // Default to binary output, unless otherwise specified
195 (
196 args.found("ascii")
197 ? IOstreamOption::ASCII
198 : IOstreamOption::BINARY
199 );
200
201 // Increase the precision of the points data
202 IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));
203
204
205 // Read control options
206 // ~~~~~~~~~~~~~~~~~~~~
207
209 rOpts.removeBaffles(args.found("noBaffles"));
210 rOpts.mergeInterfaces(args.found("merge"));
211
212 if (args.found("numbered"))
213 {
214 rOpts.useNumberedNames(true);
215 }
216
217 if (args.found("solids"))
218 {
219 Info<< "treating solids like fluids" << endl;
220 rOpts.keepSolid(true);
221 }
222 else
223 {
224 rOpts.keepSolid(false);
225 }
226
227 // CCM reader for reading geometry/solution
228 ccm::reader reader(args.get<fileName>(1), rOpts);
229
230 // list the geometry information
231 if (optList)
232 {
233 Info<< "mesh geometry information:" << endl;
234 if (reader.hasGeometry())
235 {
236 Info<< nl << "cellTable:" << reader.cellTableInfo()
237 << nl << "boundaryRegion:" << reader.boundaryTableInfo()
238 << nl << "interfaces:" << reader.interfaceDefinitionsInfo()
239 << endl;
240
241 if
242 (
243 args.found("remap")
244 ? reader.remapMeshInfo(runTime, args["remap"])
245 : reader.remapMeshInfo(runTime)
246 )
247 {
248 Info<< nl
249 << "Remapped cellTable:" << reader.cellTableInfo() << nl
250 << "Remapped boundaryRegion:" << reader.boundaryTableInfo()
251 << endl;
252 }
253 }
254 else
255 {
256 Info<< "NONE" << endl;
257 }
258
259 return 0;
260 }
261 else if (reader.readGeometry(scaleFactor))
262 {
264 (
265 args.found("remap")
266 ? reader.mesh(runTime, args["remap"])
267 : reader.mesh(runTime)
268 );
269
270 // report mesh bounding box information
271 Info<< nl << "Bounding box size: " << mesh().bounds().span() << nl;
272
273 // check number of regions
274 regionSplit rs(mesh());
275
276 Info<< "Number of regions: " << rs.nRegions();
277 if (rs.nRegions() == 1)
278 {
279 Info<< " (OK)." << nl;
280 }
281 else
282 {
283 Info<< nl << nl
284 << "**************************************************" << nl
285 << "** WARNING: the mesh has disconnected regions **" << nl
286 << "**************************************************" << nl;
287 }
288 Info<< endl;
289 reader.writeMesh(mesh(), format);
290
291 // exportName only has a size when export is in effect
292 if (exportName.size())
293 {
294 const fileName geomName = exportName + ".ccmg";
295 Info<< nl << "Re-exporting geometry as " << geomName << nl;
296 ccm::writer(geomName, mesh()).writeGeometry();
297 }
298 }
299 else
300 {
302 << "could not read geometry"
303 << exit(FatalError);
304 }
305
306 Info<< "\nEnd\n" << endl;
307
308 return 0;
309}
310
311// ************************************************************************* //
Y[inertIndex] max(0.0)
Reader/writer for handling ccm files.
streamFormat
Data format (ascii | binary)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:124
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
const fileName & rootPath() const noexcept
Return root path.
Definition: argListI.H:63
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition: argListI.H:323
const fileName & globalCaseName() const noexcept
Return global case name.
Definition: argListI.H:75
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Definition: argListI.H:307
const fileName & caseName() const noexcept
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:69
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
bool mergeInterfaces() const
Merge in-place interfaces (default true)
bool useNumberedNames() const
Use numbered names (eg, patch_0, zone_0) instead of human-readable.
bool removeBaffles() const
Remove baffles by merging their respective faces (default false)
bool keepSolid() const
Keep solid regions (default true)
Reads CCM files as written by PROSTAR/STARCCM.
Definition: ccmReader.H:187
Write OpenFOAM meshes and/or results to CCM format.
Definition: ccmWriter.H:123
void writeGeometry()
Write the mesh.
A class for handling file names.
Definition: fileName.H:76
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileNameI.H:230
word ext() const
Return file name extension (part after last .)
Definition: fileNameI.H:218
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
Definition: regionSplit.H:144
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
engineTime & runTime
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
word format(conversionProperties.get< word >("format"))
Foam::argList args(argc, argv)