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 Import from various third-party surface formats into surfMesh
29 with optional scaling or transformations (rotate/translate)
30 on a coordinateSystem.
33 - surfaceMeshImport inputFile [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 "import from various third-party surface formats into surfMesh"
80 argList::noParallel();
81 argList::validArgs.append("inputFile");
83 argList::addBoolOption
86 "perform some surface checking/cleanup on the input surface"
92 "specify an alternative surface name when writing - "
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 a local coordinate system when reading files."
123 "specify a local coordinate system when writing files."
126 #include "setRootCase.H"
127 #include "createTime.H"
129 // try for the latestTime, but create "constant" as needed
130 instantList Times = runTime.times();
133 label startTime = Times.size()-1;
134 runTime.setTime(Times[startTime], startTime);
138 runTime.setTime(instant(0, runTime.constant()), 0);
142 const fileName importName = args[1];
143 const word exportName = args.optionLookupOrDefault<word>("name", "default");
145 // check that reading is supported
146 if (!MeshedSurface<face>::canRead(importName, true))
152 // get the coordinate transformations
153 autoPtr<coordinateSystem> fromCsys;
154 autoPtr<coordinateSystem> toCsys;
156 if (args.optionFound("from") || args.optionFound("to"))
158 autoPtr<IOobject> ioPtr;
160 if (args.optionFound("dict"))
162 const fileName dictPath = args["dict"];
170 ? dictPath/coordinateSystems::typeName
186 coordinateSystems::typeName,
197 if (!ioPtr->headerOk())
199 FatalErrorIn(args.executable())
200 << "Cannot open coordinateSystems file\n "
201 << ioPtr->objectPath() << nl
205 coordinateSystems csLst(ioPtr());
207 if (args.optionFound("from"))
209 const word csName = args["from"];
211 const label csIndex = csLst.findIndex(csName);
214 FatalErrorIn(args.executable())
215 << "Cannot find -from " << csName << nl
216 << "available coordinateSystems: " << csLst.toc() << nl
220 fromCsys.reset(new coordinateSystem(csLst[csIndex]));
223 if (args.optionFound("to"))
225 const word csName = args["to"];
227 const label csIndex = csLst.findIndex(csName);
230 FatalErrorIn(args.executable())
231 << "Cannot find -to " << csName << nl
232 << "available coordinateSystems: " << csLst.toc() << nl
236 toCsys.reset(new coordinateSystem(csLst[csIndex]));
240 // maybe fix this later
241 if (fromCsys.valid() && toCsys.valid())
243 FatalErrorIn(args.executable())
244 << "Only allowed '-from' or '-to' option at the moment."
251 MeshedSurface<face> surf(importName);
253 if (args.optionFound("clean"))
260 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
262 Info<< " -scaleIn " << scaleIn << endl;
263 surf.scalePoints(scaleIn);
266 if (fromCsys.valid())
268 Info<< " -from " << fromCsys().name() << endl;
269 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
270 surf.movePoints(tpf());
275 Info<< " -to " << toCsys().name() << endl;
276 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
277 surf.movePoints(tpf());
281 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
283 Info<< " -scaleOut " << scaleOut << endl;
284 surf.scalePoints(scaleOut);
299 Info<< "writing surfMesh:\n " << smesh.objectPath() << endl;
302 Info<< "\nEnd\n" << endl;
307 // ************************************************************************* //