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-2022 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  Alternative remapping dictionary
50  (default: <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  "Alternative remapping dictionary (default: '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.remove_ext();
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("noZero")
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  );
192  }
193  else if (mesh.moving())
194  {
196  (
197  exportName + ".ccmg_" + timeName,
198  mesh,
199  !optOverwrite
200  );
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  );
238  }
239  else if (mesh.moving())
240  {
242  (
243  exportName + ".ccmg_" + timeName,
244  mesh,
245  !optOverwrite
246  );
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 // ************************************************************************* //
static void noFunctionObjects(bool addWithOption=false)
Remove &#39;-noFunctionObjects&#39; option and ignore any occurrences.
Definition: argList.C:547
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
Required Variables.
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
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
label nPoints() const noexcept
Number of mesh points.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Required Classes.
const fileName & globalCaseName() const noexcept
Return global case name.
Definition: argListI.H:68
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:374
static void noParallel()
Remove the parallel options.
Definition: argList.C:584
Write OpenFOAM meshes and/or results to CCM format.
Definition: ccmWriter.H:115
word ext() const
Return file name extension (part after last .)
Definition: fileNameI.H:211
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
Definition: error.C:359
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void printUsage(bool full=true) const
Print usage.
Definition: argListHelp.C:359
word timeName
Definition: getTimeIndex.H:3
dynamicFvMesh & mesh
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:609
A class for handling words, derived from Foam::string.
Definition: word.H:63
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
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:385
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Definition: Time.C:902
bool remove_ext()
Remove extension, returning true if string changed.
Definition: stringI.H:93
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options and also set the runTime to the first i...
Definition: timeSelector.C:260
T & last()
Access last element of the list, position [size()-1].
Definition: UList.H:876
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional &#39;FOAM Warning&#39; header text...
bool moving() const noexcept
Is mesh moving.
Definition: polyMesh.H:732
label nCells() const noexcept
Number of mesh cells.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool writeGeometry()
Write patch topology.
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition: argListI.H:316
Reader/writer for handling ccm files.
Foam::argList args(argc, argv)
static string defaultMeshName
The name for the topology file reference.
Definition: ccmWriter.H:238
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
Definition: timeSelector.C:101
Namespace for OpenFOAM.