FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

surfaceMeshExport.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Application
00025     surfaceMeshExport
00026 
00027 Description
00028     Export from surfMesh to various third-party surface formats with
00029     optional scaling or transformations (rotate/translate) on a
00030     coordinateSystem.
00031 
00032 Usage
00033     - surfaceMeshExport outputFile [OPTION]
00034 
00035     @param <outputFile> \n
00036     File into which to write exported surface.
00037 
00038     @param -clean \n
00039     Perform some surface checking/cleanup on the input surface.
00040 
00041     @param -name <name> \n
00042     Specify an alternative surface name when writing.
00043 
00044     @param -scaleIn <scale> \n
00045     Specify a scaling factor when reading files.
00046 
00047     @param -scaleOut <scale> \n
00048     Specify a scaling factor when writing files.
00049 
00050     @param -dict <dictionary> \n
00051     Specify an alternative dictionary for constant/coordinateSystems.
00052 
00053     @param -from <coordinateSystem> \n
00054     Specify a coordinate System when reading files.
00055 
00056     @param -to <coordinateSystem> \n
00057     Specify a coordinate System when writing files.
00058 
00059     @param -case <dir> \n
00060     Specify the case directory
00061 
00062     @param -help \n
00063     Display short usage message
00064 
00065     @param -doc \n
00066     Display Doxygen documentation page
00067 
00068     @param -srcDoc \n
00069     Display source code
00070 
00071 Note
00072     The filename extensions are used to determine the file format type.
00073 
00074 \*---------------------------------------------------------------------------*/
00075 
00076 #include <OpenFOAM/argList.H>
00077 #include <OpenFOAM/timeSelector.H>
00078 #include <OpenFOAM/Time.H>
00079 
00080 #include <surfMesh/MeshedSurfaces.H>
00081 #include <meshTools/coordinateSystems.H>
00082 
00083 using namespace Foam;
00084 
00085 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00086 //  Main program:
00087 
00088 int main(int argc, char *argv[])
00089 {
00090     argList::noParallel();
00091     argList::validArgs.append("outputFile");
00092     argList::validOptions.insert("name",  "name");
00093     argList::validOptions.insert("clean", "");
00094     argList::validOptions.insert("scaleIn",  "scale");
00095     argList::validOptions.insert("scaleOut", "scale");
00096     argList::validOptions.insert("dict", "coordinateSystemsDict");
00097     argList::validOptions.insert("from", "sourceCoordinateSystem");
00098     argList::validOptions.insert("to",   "targetCoordinateSystem");
00099 
00100     argList args(argc, argv);
00101     Time runTime(args.rootPath(), args.caseName());
00102     const stringList& params = args.additionalArgs();
00103 
00104     fileName exportName(params[0]);
00105     word importName("default");
00106     args.optionReadIfPresent("name", importName);
00107 
00108     // check that writing is supported
00109     if (!MeshedSurface<face>::canWriteType(exportName.ext(), true))
00110     {
00111         return 1;
00112     }
00113 
00114 
00115     // get the coordinate transformations
00116     autoPtr<coordinateSystem> fromCsys;
00117     autoPtr<coordinateSystem> toCsys;
00118 
00119     if (args.optionFound("from") || args.optionFound("to"))
00120     {
00121         autoPtr<IOobject> ioPtr;
00122 
00123         if (args.optionFound("dict"))
00124         {
00125             fileName dictPath(args.option("dict"));
00126 
00127             ioPtr.set
00128             (
00129                 new IOobject
00130                 (
00131                     (
00132                         isDir(dictPath)
00133                       ? dictPath/coordinateSystems::typeName
00134                       : dictPath
00135                     ),
00136                     runTime,
00137                     IOobject::MUST_READ,
00138                     IOobject::NO_WRITE,
00139                     false
00140                 )
00141             );
00142         }
00143         else
00144         {
00145             ioPtr.set
00146             (
00147                 new IOobject
00148                 (
00149                     coordinateSystems::typeName,
00150                     runTime.constant(),
00151                     runTime,
00152                     IOobject::MUST_READ,
00153                     IOobject::NO_WRITE,
00154                     false
00155                 )
00156             );
00157         }
00158 
00159 
00160         if (!ioPtr->headerOk())
00161         {
00162             FatalErrorIn(args.executable())
00163                 << "Cannot open coordinateSystems file\n    "
00164                 << ioPtr->objectPath() << nl
00165                 << exit(FatalError);
00166         }
00167 
00168         coordinateSystems csLst(ioPtr());
00169 
00170         if (args.optionFound("from"))
00171         {
00172             const word csName(args.option("from"));
00173 
00174             label csId = csLst.find(csName);
00175             if (csId < 0)
00176             {
00177                 FatalErrorIn(args.executable())
00178                     << "Cannot find -from " << csName << nl
00179                     << "available coordinateSystems: " << csLst.toc() << nl
00180                     << exit(FatalError);
00181             }
00182 
00183             fromCsys.reset(new coordinateSystem(csLst[csId]));
00184         }
00185 
00186         if (args.optionFound("to"))
00187         {
00188             const word csName(args.option("to"));
00189 
00190             label csId = csLst.find(csName);
00191             if (csId < 0)
00192             {
00193                 FatalErrorIn(args.executable())
00194                     << "Cannot find -to " << csName << nl
00195                     << "available coordinateSystems: " << csLst.toc() << nl
00196                     << exit(FatalError);
00197             }
00198 
00199             toCsys.reset(new coordinateSystem(csLst[csId]));
00200         }
00201 
00202 
00203         // maybe fix this later
00204         if (fromCsys.valid() && toCsys.valid())
00205         {
00206             FatalErrorIn(args.executable())
00207                 << "Only allowed  '-from' or '-to' option at the moment."
00208                 << exit(FatalError);
00209         }
00210     }
00211 
00212 
00213     surfMesh smesh
00214     (
00215         IOobject
00216         (
00217             importName,
00218             runTime.constant(),
00219             runTime,
00220             IOobject::MUST_READ,
00221             IOobject::NO_WRITE
00222         )
00223     );
00224 
00225     Info<< "read surfMesh:\n  " << smesh.objectPath() << endl;
00226 
00227 
00228     // Simply copy for now, but really should have a separate write method
00229 
00230     MeshedSurface<face> surf(smesh);
00231 
00232     if (args.optionFound("clean"))
00233     {
00234         surf.cleanup(true);
00235     }
00236 
00237     scalar scaleIn = 0;
00238     if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
00239     {
00240         Info<< " -scaleIn " << scaleIn << endl;
00241         surf.scalePoints(scaleIn);
00242     }
00243 
00244     if (fromCsys.valid())
00245     {
00246         Info<< " -from " << fromCsys().name() << endl;
00247         tmp<pointField> tpf = fromCsys().localPosition(surf.points());
00248         surf.movePoints(tpf());
00249     }
00250 
00251     if (toCsys.valid())
00252     {
00253         Info<< " -to " << toCsys().name() << endl;
00254         tmp<pointField> tpf = toCsys().globalPosition(surf.points());
00255         surf.movePoints(tpf());
00256     }
00257 
00258     scalar scaleOut = 0;
00259     if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
00260     {
00261         Info<< " -scaleOut " << scaleOut << endl;
00262         surf.scalePoints(scaleOut);
00263     }
00264 
00265 
00266     surf.writeStats(Info);
00267     Info<< endl;
00268 
00269     Info<< "writing " << exportName << endl;
00270     surf.write(exportName);
00271 
00272     Info<< "\nEnd\n" << endl;
00273 
00274     return 0;
00275 }
00276 
00277 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines