foamToCcm.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 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  foamToCcm
28 
29 Group
30  grpMeshConversionUtilities
31 
32 Description
33  Translates OPENFOAM mesh and/or results to CCM format
34 
35 Usage
36  \b foamToCcm [OPTION]
37 
38  Options:
39  - \par -mesh
40  convert mesh only to CCM format
41 
42  - \par -name <name>
43  Provide alternative base name. Default is <tt>meshExport</tt>.
44 
45  - \par -overwrite
46  No backup of existing output files.
47 
48  - \par -remap <name>
49  Use specified remapping dictionary instead of
50  <tt>constant/remapping</tt>
51 
52  - \par -results
53  Convert results only to CCM format
54 
55 Note
56  - No parallel data
57  - No Lagrangian elements
58  - the -noZero time option can be useful to avoid the often incomplete
59  initial conditions (missing useful calculated values)
60 
61 See also
62  Foam::ccm::writer for information about the
63  <tt>constant/remapping</tt> file.
64 
65 \*---------------------------------------------------------------------------*/
66 
67 #include "argList.H"
68 #include "timeSelector.H"
69 
70 #include "volFields.H"
71 #include "OFstream.H"
72 #include "IOobjectList.H"
73 #include "scalarIOField.H"
74 #include "tensorIOField.H"
75 
76 #include "ccm.H"
77 
78 using namespace Foam;
79 
80 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 
82 // Main program:
83 
84 int main(int argc, char *argv[])
85 {
87  (
88  "Translate OPENFOAM data to CCM format"
89  );
90 
94  (
95  "mesh",
96  "Convert mesh only"
97  );
99  (
100  "name",
101  "name",
102  "Provide alternative base name. Default is <meshExport>."
103  );
105  (
106  "overwrite",
107  "No backup of existing output files"
108  );
110  (
111  "remap",
112  "name",
113  "Use specified remapping dictionary instead of <constant/remapping>"
114  );
116  (
117  "results",
118  "Convert results only"
119  );
120 
121  argList::noFunctionObjects(); // Never use function objects
122 
123  #include "setRootCase.H"
124  #include "createTime.H"
125 
126  // The times list
128 
129  const bool optMesh = args.found("mesh");
130  const bool optResults = args.found("results");
131  const bool optOverwrite = args.found("overwrite");
132 
134  if (args.readIfPresent("name", exportName))
135  {
136  const word ext(exportName.ext());
137  // strip erroneous extension (.ccm, .ccmg, .ccmp)
138  if (ext == "ccm" || ext == "ccmg" || ext == "ccmp")
139  {
140  exportName = exportName.lessExt();
141  }
142  }
143  else if (args.found("case"))
144  {
145  exportName += '-' + args.globalCaseName();
146  }
147 
148  if (optMesh && optResults)
149  {
150  Warning
151  << "\n-mesh and -results options are mutually exclusive\n"
152  << endl;
153  args.printUsage();
154  FatalError.exit();
155  }
156 
157 // // skip over time=0, unless some other time option has been specified
158 // if
159 // (
160 // !args.found("zeroTime")
161 // && !args.found("time")
162 // && !args.found("latestTime")
163 // && Times.size() > 2
164 // )
165 // {
166 // startTime = 2;
167 // }
168 //
169 // runTime.setTime(Times[startTime], startTime);
170 
171  runTime.setTime(timeDirs[0], 0);
172  if (optMesh)
173  {
174  // convert mesh only
175  #include "createPolyMesh.H"
176 
177  forAll(timeDirs, timeI)
178  {
179  runTime.setTime(timeDirs[timeI], timeI);
180 
181  #include "getTimeIndex.H"
182 
183  if (timeI == 0)
184  {
186  (
187  exportName + ".ccmg",
188  mesh,
189  !optOverwrite
190  );
191  writer.writeGeometry();
192  }
193  else if (mesh.moving())
194  {
196  (
197  exportName + ".ccmg_" + timeName,
198  mesh,
199  !optOverwrite
200  );
201  writer.writeGeometry();
202  }
203  }
204  }
205  else
206  {
207  // convert fields with or without converting mesh
208  #include "createNamedMesh.H"
209 
210  // #include "checkHasMovingMesh.H"
211  // #include "checkHasLagrangian.H"
212 
213  IOobjectList objects(mesh, timeDirs.last().name());
214 
215  forAll(timeDirs, timeI)
216  {
217  runTime.setTime(timeDirs[timeI], timeI);
218 
219  #include "getTimeIndex.H"
220 
221  Info<< "has "
222  << mesh.nCells() << " cells, "
223  << mesh.nPoints() << " points, "
224  << mesh.boundaryMesh().size() << " patches"
225  << endl;
226 
227  if (!optResults)
228  {
229  if (timeI == 0)
230  {
232  (
233  exportName + ".ccmg",
234  mesh,
235  !optOverwrite
236  );
237  writer.writeGeometry();
238  }
239  else if (mesh.moving())
240  {
242  (
243  exportName + ".ccmg_" + timeName,
244  mesh,
245  !optOverwrite
246  );
247  writer.writeGeometry();
248  }
249  }
250 
252  (
253  exportName + ".ccmp_" + timeName,
254  mesh,
255  !optOverwrite
256  );
257  // writer.setTopologyFile(exportName + ".ccmg");
258  Info<< "writing solution:";
259  if (args.found("remap"))
260  {
261  writer.writeSolution(objects, args["remap"]);
262  }
263  else
264  {
265  writer.writeSolution(objects);
266  }
267  }
268  }
269 
270  Info<< "\nEnd\n" << endl;
271  return 0;
272 }
273 
274 
275 // ************************************************************************* //
ccm.H
Reader/writer for handling ccm files.
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
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::Warning
messageStream Warning
Foam::ccm::writer::defaultMeshName
static string defaultMeshName
The name for the topology file reference.
Definition: ccmWriter.H:218
tensorIOField.H
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:412
Foam::argList::globalCaseName
const fileName & globalCaseName() const noexcept
Return global case name.
Definition: argListI.H:75
IOobjectList.H
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
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
scalarIOField.H
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::primitiveMesh::nPoints
label nPoints() const noexcept
Number of mesh points.
Definition: primitiveMeshI.H:37
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
OFstream.H
Foam::argList::noFunctionObjects
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition: argList.C:473
Foam::primitiveMesh::nCells
label nCells() const noexcept
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
argList.H
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::FatalError
error FatalError
createNamedMesh.H
Required Variables.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:81
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::error::exit
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
Definition: error.C:331
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
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
setRootCase.H
Foam::timeSelector::addOptions
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
Definition: timeSelector.C:102
Foam::List< instant >
Foam::Time::setTime
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Definition: Time.C:1003
Foam::polyMesh::moving
bool moving() const noexcept
Is mesh moving.
Definition: polyMesh.H:522
timeSelector.H
createTime.H
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:510
Foam::timeSelector::select0
static instantList select0(Time &runTime, const argList &args)
Definition: timeSelector.C:235
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")
createPolyMesh.H
Required Variables.
Foam::argList::printUsage
void printUsage(bool full=true) const
Print usage.
Definition: argListHelp.C:366
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
Foam::ccm::writer
Write OpenFOAM meshes and/or results to CCM format.
Definition: ccmWriter.H:119