1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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"
66 #include "MeshedSurfaces.H"
67 #include "coordinateSystems.H"
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 int main(int argc, char *argv[])
76 argList::noParallel();
77 argList::validArgs.append("outputFile");
78 argList::validOptions.insert("name", "name");
79 argList::validOptions.insert("clean", "");
80 argList::validOptions.insert("scaleIn", "scale");
81 argList::validOptions.insert("scaleOut", "scale");
82 argList::validOptions.insert("dict", "coordinateSystemsDict");
83 argList::validOptions.insert("from", "sourceCoordinateSystem");
84 argList::validOptions.insert("to", "targetCoordinateSystem");
86 argList args(argc, argv);
87 Time runTime(args.rootPath(), args.caseName());
88 const stringList& params = args.additionalArgs();
90 fileName exportName(params[0]);
91 word importName("default");
92 args.optionReadIfPresent("name", importName);
94 // check that writing is supported
95 if (!MeshedSurface<face>::canWriteType(exportName.ext(), true))
101 // get the coordinate transformations
102 autoPtr<coordinateSystem> fromCsys;
103 autoPtr<coordinateSystem> toCsys;
105 if (args.optionFound("from") || args.optionFound("to"))
107 autoPtr<IOobject> ioPtr;
109 if (args.optionFound("dict"))
111 fileName dictPath(args.option("dict"));
119 ? dictPath/coordinateSystems::typeName
135 coordinateSystems::typeName,
146 if (!ioPtr->headerOk())
148 FatalErrorIn(args.executable())
149 << "Cannot open coordinateSystems file\n "
150 << ioPtr->objectPath() << nl
154 coordinateSystems csLst(ioPtr());
156 if (args.optionFound("from"))
158 const word csName(args.option("from"));
160 label csId = csLst.find(csName);
163 FatalErrorIn(args.executable())
164 << "Cannot find -from " << csName << nl
165 << "available coordinateSystems: " << csLst.toc() << nl
169 fromCsys.reset(new coordinateSystem(csLst[csId]));
172 if (args.optionFound("to"))
174 const word csName(args.option("to"));
176 label csId = csLst.find(csName);
179 FatalErrorIn(args.executable())
180 << "Cannot find -to " << csName << nl
181 << "available coordinateSystems: " << csLst.toc() << nl
185 toCsys.reset(new coordinateSystem(csLst[csId]));
189 // maybe fix this later
190 if (fromCsys.valid() && toCsys.valid())
192 FatalErrorIn(args.executable())
193 << "Only allowed '-from' or '-to' option at the moment."
211 Info<< "read surfMesh:\n " << smesh.objectPath() << endl;
214 // Simply copy for now, but really should have a separate write method
216 MeshedSurface<face> surf(smesh);
218 if (args.optionFound("clean"))
224 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
226 Info<< " -scaleIn " << scaleIn << endl;
227 surf.scalePoints(scaleIn);
230 if (fromCsys.valid())
232 Info<< " -from " << fromCsys().name() << endl;
233 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
234 surf.movePoints(tpf());
239 Info<< " -to " << toCsys().name() << endl;
240 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
241 surf.movePoints(tpf());
245 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
247 Info<< " -scaleOut " << scaleOut << endl;
248 surf.scalePoints(scaleOut);
252 surf.writeStats(Info);
255 Info<< "writing " << exportName << endl;
256 surf.write(exportName);
258 Info<< "\nEnd\n" << endl;
263 // ************************************************************************* //