1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 Export from surfMesh to various third-party surface formats with
29 optional scaling or transformations (rotate/translate) on a
33 - surfaceMeshExport outputFile [OPTION]
36 Perform some surface checking/cleanup on the input surface.
38 \param -name \<name\> \n
39 Specify an alternative surface name when writing.
41 \param -scaleIn \<scale\> \n
42 Specify a scaling factor when reading files.
44 \param -scaleOut \<scale\> \n
45 Specify a scaling factor when writing files.
47 \param -dict \<dictionary\> \n
48 Specify an alternative dictionary for constant/coordinateSystems.
50 \param -from \<coordinateSystem\> \n
51 Specify a coordinate system when reading files.
53 \param -to \<coordinateSystem\> \n
54 Specify a coordinate system when writing files.
57 The filename extensions are used to determine the file format type.
59 \*---------------------------------------------------------------------------*/
62 #include "timeSelector.H"
65 #include "MeshedSurfaces.H"
66 #include "coordinateSystems.H"
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 int main(int argc, char *argv[])
77 "export from surfMesh to various third-party surface formats"
80 argList::noParallel();
81 argList::validArgs.append("outputFile");
83 argList::addBoolOption
86 "perform some surface checking/cleanup on the input surface"
92 "specify an alternative surface name when reading - "
93 "default is 'default'"
99 "geometry scaling factor on input - default is 1"
105 "geometry scaling factor on output - default is 1"
111 "specify an alternative dictionary for constant/coordinateSystems"
117 "specify the source coordinate system, applied after '-scaleIn'"
123 "specify the target coordinate system, applied before '-scaleOut'"
126 argList args(argc, argv);
127 Time runTime(args.rootPath(), args.caseName());
129 const fileName exportName = args[1];
130 const word importName = args.optionLookupOrDefault<word>("name", "default");
132 // check that writing is supported
133 if (!MeshedSurface<face>::canWriteType(exportName.ext(), true))
139 // get the coordinate transformations
140 autoPtr<coordinateSystem> fromCsys;
141 autoPtr<coordinateSystem> toCsys;
143 if (args.optionFound("from") || args.optionFound("to"))
145 autoPtr<IOobject> ioPtr;
147 if (args.optionFound("dict"))
149 const fileName dictPath = args["dict"];
157 ? dictPath/coordinateSystems::typeName
173 coordinateSystems::typeName,
184 if (!ioPtr->headerOk())
186 FatalErrorIn(args.executable())
187 << "Cannot open coordinateSystems file\n "
188 << ioPtr->objectPath() << nl
192 coordinateSystems csLst(ioPtr());
194 if (args.optionFound("from"))
196 const word csName = args["from"];
198 const label csIndex = csLst.findIndex(csName);
201 FatalErrorIn(args.executable())
202 << "Cannot find -from " << csName << nl
203 << "available coordinateSystems: " << csLst.toc() << nl
207 fromCsys.reset(new coordinateSystem(csLst[csIndex]));
210 if (args.optionFound("to"))
212 const word csName = args["to"];
214 const label csIndex = csLst.findIndex(csName);
217 FatalErrorIn(args.executable())
218 << "Cannot find -to " << csName << nl
219 << "available coordinateSystems: " << csLst.toc() << nl
223 toCsys.reset(new coordinateSystem(csLst[csIndex]));
227 // maybe fix this later
228 if (fromCsys.valid() && toCsys.valid())
230 FatalErrorIn(args.executable())
231 << "Only allowed '-from' or '-to' option at the moment."
244 IOobject::MUST_READ_IF_MODIFIED,
249 Info<< "read surfMesh:\n " << smesh.objectPath() << endl;
252 // Simply copy for now, but really should have a separate write method
254 MeshedSurface<face> surf(smesh);
256 if (args.optionFound("clean"))
262 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
264 Info<< " -scaleIn " << scaleIn << endl;
265 surf.scalePoints(scaleIn);
268 if (fromCsys.valid())
270 Info<< " -from " << fromCsys().name() << endl;
271 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
272 surf.movePoints(tpf());
277 Info<< " -to " << toCsys().name() << endl;
278 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
279 surf.movePoints(tpf());
283 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
285 Info<< " -scaleOut " << scaleOut << endl;
286 surf.scalePoints(scaleOut);
290 surf.writeStats(Info);
293 Info<< "writing " << exportName << endl;
294 surf.write(exportName);
296 Info<< "\nEnd\n" << endl;
301 // ************************************************************************* //