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-------------------------------------------------------------------------------
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 foamToCcm
28
29Group
30 grpMeshConversionUtilities
31
32Description
33 Translates OPENFOAM mesh and/or results to CCM format
34
35Usage
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
55Note
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
61See 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
78using namespace Foam;
79
80// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81
82// Main program:
83
84int main(int argc, char *argv[])
85{
86 argList::addNote
87 (
88 "Translate OPENFOAM data to CCM format"
89 );
90
91 timeSelector::addOptions();
92 argList::noParallel();
93 argList::addBoolOption
94 (
95 "mesh",
96 "Convert mesh only"
97 );
98 argList::addOption
99 (
100 "name",
101 "name",
102 "Provide alternative base name. Default is <meshExport>."
103 );
104 argList::addBoolOption
105 (
106 "overwrite",
107 "No backup of existing output files"
108 );
109 argList::addOption
110 (
111 "remap",
112 "name",
113 "Use specified remapping dictionary instead of <constant/remapping>"
114 );
115 argList::addBoolOption
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
133 fileName exportName = ccm::writer::defaultMeshName;
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;
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// ************************************************************************* //
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Reader/writer for handling ccm files.
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
T & last()
Return the last element of the list.
Definition: UListI.H:216
void printUsage(bool full=true) const
Print usage.
Definition: argListHelp.C:366
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
Write OpenFOAM meshes and/or results to CCM format.
Definition: ccmWriter.H:123
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
Definition: error.C:331
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
static instantList select0(Time &runTime, const argList &args)
Definition: timeSelector.C:235
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
engineTime & runTime
Required Variables.
Required Variables.
word timeName
Definition: getTimeIndex.H:3
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
error FatalError
messageStream Warning
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333