OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Application
00026     surfaceMeshExport
00027 
00028 Description
00029     Export from surfMesh to various third-party surface formats with
00030     optional scaling or transformations (rotate/translate) on a
00031     coordinateSystem.
00032 
00033 Usage
00034     - surfaceMeshExport outputFile [OPTION]
00035 
00036     @param -clean \n
00037     Perform some surface checking/cleanup on the input surface.
00038 
00039     @param -name <name> \n
00040     Specify an alternative surface name when writing.
00041 
00042     @param -scaleIn <scale> \n
00043     Specify a scaling factor when reading files.
00044 
00045     @param -scaleOut <scale> \n
00046     Specify a scaling factor when writing files.
00047 
00048     @param -dict <dictionary> \n
00049     Specify an alternative dictionary for constant/coordinateSystems.
00050 
00051     @param -from <coordinateSystem> \n
00052     Specify a coordinate System when reading files.
00053 
00054     @param -to <coordinateSystem> \n
00055     Specify a coordinate System when writing files.
00056 
00057 Note
00058     The filename extensions are used to determine the file format type.
00059 
00060 \*---------------------------------------------------------------------------*/
00061 
00062 #include "argList.H"
00063 #include "timeSelector.H"
00064 #include "Time.H"
00065 
00066 #include "MeshedSurfaces.H"
00067 #include "coordinateSystems.H"
00068 
00069 using namespace Foam;
00070 
00071 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00072 //  Main program:
00073 
00074 int main(int argc, char *argv[])
00075 {
00076     argList::noParallel();
00077     argList::validArgs.append("outputFile");
00078     argList::validOptions.insert("name",  "name");
00079     argList::validOptions.insert("clean", "");
00080     argList::validOptions.insert("scaleIn",  "scale");
00081     argList::validOptions.insert("scaleOut", "scale");
00082     argList::validOptions.insert("dict", "coordinateSystemsDict");
00083     argList::validOptions.insert("from", "sourceCoordinateSystem");
00084     argList::validOptions.insert("to",   "targetCoordinateSystem");
00085 
00086     argList args(argc, argv);
00087     Time runTime(args.rootPath(), args.caseName());
00088     const stringList& params = args.additionalArgs();
00089 
00090     fileName exportName(params[0]);
00091     word importName("default");
00092     args.optionReadIfPresent("name", importName);
00093 
00094     // check that writing is supported
00095     if (!MeshedSurface<face>::canWriteType(exportName.ext(), true))
00096     {
00097         return 1;
00098     }
00099 
00100 
00101     // get the coordinate transformations
00102     autoPtr<coordinateSystem> fromCsys;
00103     autoPtr<coordinateSystem> toCsys;
00104 
00105     if (args.optionFound("from") || args.optionFound("to"))
00106     {
00107         autoPtr<IOobject> ioPtr;
00108 
00109         if (args.optionFound("dict"))
00110         {
00111             fileName dictPath(args.option("dict"));
00112 
00113             ioPtr.set
00114             (
00115                 new IOobject
00116                 (
00117                     (
00118                         isDir(dictPath)
00119                       ? dictPath/coordinateSystems::typeName
00120                       : dictPath
00121                     ),
00122                     runTime,
00123                     IOobject::MUST_READ,
00124                     IOobject::NO_WRITE,
00125                     false
00126                 )
00127             );
00128         }
00129         else
00130         {
00131             ioPtr.set
00132             (
00133                 new IOobject
00134                 (
00135                     coordinateSystems::typeName,
00136                     runTime.constant(),
00137                     runTime,
00138                     IOobject::MUST_READ,
00139                     IOobject::NO_WRITE,
00140                     false
00141                 )
00142             );
00143         }
00144 
00145 
00146         if (!ioPtr->headerOk())
00147         {
00148             FatalErrorIn(args.executable())
00149                 << "Cannot open coordinateSystems file\n    "
00150                 << ioPtr->objectPath() << nl
00151                 << exit(FatalError);
00152         }
00153 
00154         coordinateSystems csLst(ioPtr());
00155 
00156         if (args.optionFound("from"))
00157         {
00158             const word csName(args.option("from"));
00159 
00160             label csId = csLst.find(csName);
00161             if (csId < 0)
00162             {
00163                 FatalErrorIn(args.executable())
00164                     << "Cannot find -from " << csName << nl
00165                     << "available coordinateSystems: " << csLst.toc() << nl
00166                     << exit(FatalError);
00167             }
00168 
00169             fromCsys.reset(new coordinateSystem(csLst[csId]));
00170         }
00171 
00172         if (args.optionFound("to"))
00173         {
00174             const word csName(args.option("to"));
00175 
00176             label csId = csLst.find(csName);
00177             if (csId < 0)
00178             {
00179                 FatalErrorIn(args.executable())
00180                     << "Cannot find -to " << csName << nl
00181                     << "available coordinateSystems: " << csLst.toc() << nl
00182                     << exit(FatalError);
00183             }
00184 
00185             toCsys.reset(new coordinateSystem(csLst[csId]));
00186         }
00187 
00188 
00189         // maybe fix this later
00190         if (fromCsys.valid() && toCsys.valid())
00191         {
00192             FatalErrorIn(args.executable())
00193                 << "Only allowed  '-from' or '-to' option at the moment."
00194                 << exit(FatalError);
00195         }
00196     }
00197 
00198 
00199     surfMesh smesh
00200     (
00201         IOobject
00202         (
00203             importName,
00204             runTime.constant(),
00205             runTime,
00206             IOobject::MUST_READ,
00207             IOobject::NO_WRITE
00208         )
00209     );
00210 
00211     Info<< "read surfMesh:\n  " << smesh.objectPath() << endl;
00212 
00213 
00214     // Simply copy for now, but really should have a separate write method
00215 
00216     MeshedSurface<face> surf(smesh);
00217 
00218     if (args.optionFound("clean"))
00219     {
00220         surf.cleanup(true);
00221     }
00222 
00223     scalar scaleIn = 0;
00224     if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
00225     {
00226         Info<< " -scaleIn " << scaleIn << endl;
00227         surf.scalePoints(scaleIn);
00228     }
00229 
00230     if (fromCsys.valid())
00231     {
00232         Info<< " -from " << fromCsys().name() << endl;
00233         tmp<pointField> tpf = fromCsys().localPosition(surf.points());
00234         surf.movePoints(tpf());
00235     }
00236 
00237     if (toCsys.valid())
00238     {
00239         Info<< " -to " << toCsys().name() << endl;
00240         tmp<pointField> tpf = toCsys().globalPosition(surf.points());
00241         surf.movePoints(tpf());
00242     }
00243 
00244     scalar scaleOut = 0;
00245     if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
00246     {
00247         Info<< " -scaleOut " << scaleOut << endl;
00248         surf.scalePoints(scaleOut);
00249     }
00250 
00251 
00252     surf.writeStats(Info);
00253     Info<< endl;
00254 
00255     Info<< "writing " << exportName << endl;
00256     surf.write(exportName);
00257 
00258     Info<< "\nEnd\n" << endl;
00259 
00260     return 0;
00261 }
00262 
00263 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd