Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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 Alternative remapping dictionary
50 (default: <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{
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 );
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// ************************************************************************* //
Reader/writer routines for handling ccm files.
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edgesCentres")))
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
T & last()
Access last element of the list, position [size()-1].
Definition UList.H:971
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition argList.C:562
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition argList.C:389
static void noParallel()
Remove the parallel options.
Definition argList.C:599
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:400
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
Write OpenFOAM meshes and/or results to CCM format.
Definition ccmWriter.H:118
static FOAM_DLL_EXPORT string defaultMeshName
The name for the topology file reference.
Definition ccmWriter.H:228
A class for handling file names.
Definition fileName.H:75
bool remove_ext()
Remove extension, returning true if string changed.
Definition stringI.H:93
word ext() const
Return file name extension (part after last .).
Definition fileNameI.H:211
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
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...
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
engineTime & runTime
Required Classes.
Required Variables.
word timeName
Definition getTimeIndex.H:3
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< instant > instantList
List of instants.
Definition instantList.H:41
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional 'FOAM Warning' header text.
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299