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
29 Export from surfMesh to various third-party surface formats with
30 optional scaling or transformations (rotate/translate) on a
34 - surfaceMeshExport outputFile [OPTION]
37 Perform some surface checking/cleanup on the input surface.
39 @param -name \<name\> \n
40 Specify an alternative surface name when writing.
42 @param -scaleIn \<scale\> \n
43 Specify a scaling factor when reading files.
45 @param -scaleOut \<scale\> \n
46 Specify a scaling factor when writing files.
48 @param -dict \<dictionary\> \n
49 Specify an alternative dictionary for constant/coordinateSystems.
51 @param -from \<coordinateSystem\> \n
52 Specify a coordinate System when reading files.
54 @param -to \<coordinateSystem\> \n
55 Specify a coordinate System when writing files.
58 The filename extensions are used to determine the file format type.
60 \*---------------------------------------------------------------------------*/
63 #include "timeSelector.H"
64 #include "objectRegistry.H"
67 #include "MeshedSurfaces.H"
68 #include "coordinateSystems.H"
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 int main(int argc, char *argv[])
77 argList::noParallel();
78 argList::validArgs.append("outputFile");
79 argList::validOptions.insert("name", "name");
80 argList::validOptions.insert("clean", "");
81 argList::validOptions.insert("scaleIn", "scale");
82 argList::validOptions.insert("scaleOut", "scale");
83 argList::validOptions.insert("dict", "coordinateSystemsDict");
84 argList::validOptions.insert("from", "sourceCoordinateSystem");
85 argList::validOptions.insert("to", "targetCoordinateSystem");
87 argList args(argc, argv);
88 Time runTime(args.rootPath(), args.caseName());
89 const stringList& params = args.additionalArgs();
91 fileName exportName(params[0]);
92 word importName("default");
93 args.optionReadIfPresent("name", importName);
95 // check that writing is supported
96 if (!MeshedSurface<face>::canWriteType(exportName.ext(), true))
102 // get the coordinate transformations
103 autoPtr<coordinateSystem> fromCsys;
104 autoPtr<coordinateSystem> toCsys;
106 if (args.optionFound("from") || args.optionFound("to"))
108 autoPtr<IOobject> ioPtr;
110 if (args.optionFound("dict"))
112 fileName dictPath(args.option("dict"));
120 ? dictPath/coordinateSystems::typeName
136 coordinateSystems::typeName,
147 if (!ioPtr->headerOk())
149 FatalErrorIn(args.executable())
150 << "Cannot open coordinateSystems file\n "
151 << ioPtr->objectPath() << nl
155 coordinateSystems csLst(ioPtr());
157 if (args.optionFound("from"))
159 const word csName(args.option("from"));
161 label csId = csLst.find(csName);
164 FatalErrorIn(args.executable())
165 << "Cannot find -from " << csName << nl
166 << "available coordinateSystems: " << csLst.toc() << nl
170 fromCsys.reset(new coordinateSystem(csLst[csId]));
173 if (args.optionFound("to"))
175 const word csName(args.option("to"));
177 label csId = csLst.find(csName);
180 FatalErrorIn(args.executable())
181 << "Cannot find -to " << csName << nl
182 << "available coordinateSystems: " << csLst.toc() << nl
186 toCsys.reset(new coordinateSystem(csLst[csId]));
190 // maybe fix this later
191 if (fromCsys.valid() && toCsys.valid())
193 FatalErrorIn(args.executable())
194 << "Only allowed '-from' or '-to' option at the moment."
212 Info<< "read surfMesh:\n " << smesh.objectPath() << endl;
215 // Simply copy for now, but really should have a separate write method
217 MeshedSurface<face> surf(smesh);
219 if (args.optionFound("clean"))
225 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
227 Info<< " -scaleIn " << scaleIn << endl;
228 surf.scalePoints(scaleIn);
231 if (fromCsys.valid())
233 Info<< " -from " << fromCsys().name() << endl;
234 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
235 surf.movePoints(tpf());
240 Info<< " -to " << toCsys().name() << endl;
241 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
242 surf.movePoints(tpf());
246 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
248 Info<< " -scaleOut " << scaleOut << endl;
249 surf.scalePoints(scaleOut);
253 surf.writeStats(Info);
256 Info<< "writing " << exportName << endl;
257 surf.write(exportName);
259 Info<< "\nEnd\n" << endl;
264 // ************************************************************************* //