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

surfaceMeshImport.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     surfaceMeshImport
00026 
00027 Description
00028     Import from various third-party surface formats into surfMesh
00029     with optional scaling or transformations (rotate/translate)
00030     on a coordinateSystem.
00031 
00032 Usage
00033     - surfaceMeshImport inputFile [OPTION]
00034 
00035     @param <inputFile> \n
00036     File from which to read the imported 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("inputFile");
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 #   include <OpenFOAM/setRootCase.H>
00101 #   include <OpenFOAM/createTime.H>
00102 
00103     const stringList& params = args.additionalArgs();
00104 
00105     // try for the latestTime, but create "constant" as needed
00106     instantList Times = runTime.times();
00107     if (Times.size())
00108     {
00109         label startTime = Times.size()-1;
00110         runTime.setTime(Times[startTime], startTime);
00111     }
00112     else
00113     {
00114         runTime.setTime(instant(0, runTime.constant()), 0);
00115     }
00116 
00117 
00118     fileName importName(params[0]);
00119     word exportName("default");
00120     args.optionReadIfPresent("name", exportName);
00121 
00122     // check that reading is supported
00123     if (!MeshedSurface<face>::canRead(importName, true))
00124     {
00125         return 1;
00126     }
00127 
00128 
00129     // get the coordinate transformations
00130     autoPtr<coordinateSystem> fromCsys;
00131     autoPtr<coordinateSystem> toCsys;
00132 
00133     if (args.optionFound("from") || args.optionFound("to"))
00134     {
00135         autoPtr<IOobject> ioPtr;
00136 
00137         if (args.optionFound("dict"))
00138         {
00139             fileName dictPath(args.option("dict"));
00140 
00141             ioPtr.set
00142             (
00143                 new IOobject
00144                 (
00145                     (
00146                         isDir(dictPath)
00147                       ? dictPath/coordinateSystems::typeName
00148                       : dictPath
00149                     ),
00150                     runTime,
00151                     IOobject::MUST_READ,
00152                     IOobject::NO_WRITE,
00153                     false
00154                 )
00155             );
00156         }
00157         else
00158         {
00159             ioPtr.set
00160             (
00161                 new IOobject
00162                 (
00163                     coordinateSystems::typeName,
00164                     runTime.constant(),
00165                     runTime,
00166                     IOobject::MUST_READ,
00167                     IOobject::NO_WRITE,
00168                     false
00169                 )
00170             );
00171         }
00172 
00173 
00174         if (!ioPtr->headerOk())
00175         {
00176             FatalErrorIn(args.executable())
00177                 << "Cannot open coordinateSystems file\n    "
00178                 << ioPtr->objectPath() << nl
00179                 << exit(FatalError);
00180         }
00181 
00182         coordinateSystems csLst(ioPtr());
00183 
00184         if (args.optionFound("from"))
00185         {
00186             const word csName(args.option("from"));
00187 
00188             label csId = csLst.find(csName);
00189             if (csId < 0)
00190             {
00191                 FatalErrorIn(args.executable())
00192                     << "Cannot find -from " << csName << nl
00193                     << "available coordinateSystems: " << csLst.toc() << nl
00194                     << exit(FatalError);
00195             }
00196 
00197             fromCsys.reset(new coordinateSystem(csLst[csId]));
00198         }
00199 
00200         if (args.optionFound("to"))
00201         {
00202             const word csName(args.option("to"));
00203 
00204             label csId = csLst.find(csName);
00205             if (csId < 0)
00206             {
00207                 FatalErrorIn(args.executable())
00208                     << "Cannot find -to " << csName << nl
00209                     << "available coordinateSystems: " << csLst.toc() << nl
00210                     << exit(FatalError);
00211             }
00212 
00213             toCsys.reset(new coordinateSystem(csLst[csId]));
00214         }
00215 
00216 
00217         // maybe fix this later
00218         if (fromCsys.valid() && toCsys.valid())
00219         {
00220             FatalErrorIn(args.executable())
00221                 << "Only allowed  '-from' or '-to' option at the moment."
00222                 << exit(FatalError);
00223         }
00224     }
00225 
00226 
00227 
00228     MeshedSurface<face> surf(importName);
00229 
00230     if (args.optionFound("clean"))
00231     {
00232         surf.cleanup(true);
00233     }
00234 
00235 
00236     scalar scaleIn = 0;
00237     if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
00238     {
00239         Info<< " -scaleIn " << scaleIn << endl;
00240         surf.scalePoints(scaleIn);
00241     }
00242 
00243     if (fromCsys.valid())
00244     {
00245         Info<< " -from " << fromCsys().name() << endl;
00246         tmp<pointField> tpf = fromCsys().localPosition(surf.points());
00247         surf.movePoints(tpf());
00248     }
00249 
00250     if (toCsys.valid())
00251     {
00252         Info<< " -to " << toCsys().name() << endl;
00253         tmp<pointField> tpf = toCsys().globalPosition(surf.points());
00254         surf.movePoints(tpf());
00255     }
00256 
00257     scalar scaleOut = 0;
00258     if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
00259     {
00260         Info<< " -scaleOut " << scaleOut << endl;
00261         surf.scalePoints(scaleOut);
00262     }
00263 
00264     surfMesh smesh
00265     (
00266         IOobject
00267         (
00268             exportName,
00269             runTime.constant(),
00270             runTime
00271         ),
00272         surf.xfer()
00273     );
00274 
00275 
00276     Info<< "writing surfMesh:\n  " << smesh.objectPath() << endl;
00277     smesh.write();
00278 
00279     Info<< "\nEnd\n" << endl;
00280 
00281     return 0;
00282 }
00283 
00284 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines