1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 Convert between surface formats with optional scaling or
31 transformations (rotate/translate) on a coordinateSystem.
34 - surfaceMeshConvert inputFile outputFile [OPTION]
37 Perform some surface checking/cleanup on the input surface.
39 @param -scaleIn \<scale\> \n
40 Specify a scaling factor when reading files.
42 @param -scaleOut \<scale\> \n
43 Specify a scaling factor when writing files.
45 @param -dict \<dictionary\> \n
46 Specify an alternative dictionary for constant/coordinateSystems.
48 @param -from \<coordinateSystem\> \n
49 Specify a coordinate System when reading files.
51 @param -to \<coordinateSystem\> \n
52 Specify a coordinate System when writing files.
55 The filename extensions are used to determine the file format type.
57 \*---------------------------------------------------------------------------*/
60 #include "timeSelector.H"
61 #include "objectRegistry.H"
63 #include "MeshedSurfaces.H"
64 #include "coordinateSystems.H"
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 int main(int argc, char *argv[])
73 argList::noParallel();
74 argList::validArgs.append("inputFile");
75 argList::validArgs.append("outputFile");
76 argList::validOptions.insert("clean", "");
77 argList::validOptions.insert("scaleIn", "scale");
78 argList::validOptions.insert("scaleOut", "scale");
79 argList::validOptions.insert("dict", "coordinateSystemsDict");
80 argList::validOptions.insert("from", "sourceCoordinateSystem");
81 argList::validOptions.insert("to", "targetCoordinateSystem");
83 argList args(argc, argv);
84 Time runTime(args.rootPath(), args.caseName());
85 const stringList& params = args.additionalArgs();
87 fileName importName(params[0]);
88 fileName exportName(params[1]);
90 // disable inplace editing
91 if (importName == exportName)
93 FatalErrorIn(args.executable())
94 << "Output file " << exportName << " would overwrite input file."
98 // check that reading/writing is supported
101 !MeshedSurface<face>::canRead(importName, true)
102 || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
109 // get the coordinate transformations
110 autoPtr<coordinateSystem> fromCsys;
111 autoPtr<coordinateSystem> toCsys;
113 if (args.optionFound("from") || args.optionFound("to"))
115 autoPtr<IOobject> csDictIoPtr;
117 if (args.optionFound("dict"))
119 fileName dictPath(args.option("dict"));
127 ? dictPath/coordinateSystems::typeName
143 coordinateSystems::typeName,
154 if (!csDictIoPtr->headerOk())
156 FatalErrorIn(args.executable())
157 << "Cannot open coordinateSystems file\n "
158 << csDictIoPtr->objectPath() << nl
162 coordinateSystems csLst(csDictIoPtr());
164 if (args.optionFound("from"))
166 const word csName(args.option("from"));
168 label csId = csLst.find(csName);
171 FatalErrorIn(args.executable())
172 << "Cannot find -from " << csName << nl
173 << "available coordinateSystems: " << csLst.toc() << nl
177 fromCsys.reset(new coordinateSystem(csLst[csId]));
180 if (args.optionFound("to"))
182 const word csName(args.option("to"));
184 label csId = csLst.find(csName);
187 FatalErrorIn(args.executable())
188 << "Cannot find -to " << csName << nl
189 << "available coordinateSystems: " << csLst.toc() << nl
193 toCsys.reset(new coordinateSystem(csLst[csId]));
197 // maybe fix this later
198 if (fromCsys.valid() && toCsys.valid())
200 FatalErrorIn(args.executable())
201 << "Only allowed '-from' or '-to' option at the moment."
208 MeshedSurface<face> surf(importName);
210 if (args.optionFound("clean"))
216 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
218 Info<< " -scaleIn " << scaleIn << endl;
219 surf.scalePoints(scaleIn);
223 if (fromCsys.valid())
225 Info<< " -from " << fromCsys().name() << endl;
226 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
227 surf.movePoints(tpf());
232 Info<< " -to " << toCsys().name() << endl;
233 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
234 surf.movePoints(tpf());
238 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
240 Info<< " -scaleOut " << scaleOut << endl;
241 surf.scalePoints(scaleOut);
244 Info<< "writing " << exportName;
245 surf.write(exportName);
248 Info<< "\nEnd\n" << endl;
253 // ************************************************************************* //