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 -------------------------------------------------------------------------------
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 Application
27  ccmToFoam
28 
29 Group
30  grpMeshConversionUtilities
31 
32 Description
33  Reads CCM files as written by PROSTAR/STARCCM and writes an
34  OPENFOAM polyMesh.
35 
36 Usage
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 
74 Note
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 
79 See 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 
89 using namespace Foam;
90 
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 
93 int main(int argc, char *argv[])
94 {
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 
104  argList::addArgument("ccm-file", "The input .ccm or .ccmg file");
106  (
107  "ascii",
108  "Write in ASCII format instead of binary"
109  );
111  (
112  "export",
113  "Re-export mesh in CCM format for post-processing"
114  );
116  (
117  "list",
118  "List some information about the geometry"
119  );
121  (
122  "remap",
123  "name",
124  "Use specified remapping dictionary instead of <constant/remapping>"
125  );
127  (
128  "name",
129  "name",
130  "Provide alternative base name when re-exporting (implies -export). "
131  "Default is <meshExport>."
132  );
134  (
135  "noBaffles",
136  "Remove any baffles by merging the faces"
137  );
139  (
140  "merge",
141  "Merge in-place interfaces"
142  );
144  (
145  "numbered",
146  "Use numbered names (eg, patch_0, zone_0) only"
147  );
149  (
150  "scale",
151  "scale",
152  "Geometry scaling factor - default is 1 (ie, no scaling)"
153  );
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")
199  );
200 
201  // Increase the precision of the points data
203 
204 
205  // Read control options
206  // ~~~~~~~~~~~~~~~~~~~~
207 
208  ccm::reader::options rOpts;
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 // ************************************************************************* //
ccm.H
Reader/writer for handling ccm files.
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::ccm::reader
Reads CCM files as written by PROSTAR/STARCCM.
Definition: ccmReader.H:183
Foam::argList::getOrDefault
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
Foam::argList::caseName
const fileName & caseName() const noexcept
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:69
Foam::ccm::writer::defaultMeshName
static string defaultMeshName
The name for the topology file reference.
Definition: ccmWriter.H:218
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:412
Foam::Time::functionObjects
const functionObjectList & functionObjects() const
Return the list of function objects.
Definition: Time.H:499
Foam::argList::globalCaseName
const fileName & globalCaseName() const noexcept
Return global case name.
Definition: argListI.H:75
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:123
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::fileName::lessExt
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileNameI.H:230
Foam::argList::get
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
Foam::argList::readIfPresent
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition: argListI.H:323
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:301
Foam::boundBox::span
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:127
Foam::ccm::reader::options::removeBaffles
bool removeBaffles() const
Remove baffles by merging their respective faces (default false)
Definition: ccmReaderOptions.C:84
format
word format(conversionProperties.get< word >("format"))
Foam::argList::noFunctionObjects
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition: argList.C:473
Foam::functionObjectList::off
void off()
Switch the function objects off.
Definition: functionObjectList.C:605
Foam::ccm::reader::options::useNumberedNames
bool useNumberedNames() const
Use numbered names (eg, patch_0, zone_0) instead of human-readable.
Definition: ccmReaderOptions.C:90
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
argList.H
regionSplit.H
Foam::regionSplit
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
Definition: regionSplit.H:140
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fileName::ext
word ext() const
Return file name extension (part after last .)
Definition: fileNameI.H:218
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::polyMesh::bounds
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:450
Foam::argList::addBoolOption
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:324
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:342
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::ccm::reader::options::mergeInterfaces
bool mergeInterfaces() const
Merge in-place interfaces (default true)
Definition: ccmReaderOptions.C:72
Foam::IOstreamOption::BINARY
"binary"
Definition: IOstreamOption.H:73
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::ccm::reader::options
Definition: ccmReader.H:587
Foam::ccm::reader::options::keepSolid
bool keepSolid() const
Keep solid regions (default true)
Definition: ccmReaderOptions.C:60
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:510
Foam::argList::addOption
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition: argList.C:335
args
Foam::argList args(argc, argv)
writer
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Foam::vtk::internalMeshWriter::writeGeometry
virtual bool writeGeometry()
Write mesh topology.
Definition: foamVtkInternalMeshWriter.C:559
Foam::argList::rootPath
const fileName & rootPath() const noexcept
Return root path.
Definition: argListI.H:63
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178