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

surfaceMeshConvert.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     surfaceMeshConvert
00026 
00027 Description
00028     Convert between surface formats with optional scaling or
00029     transformations (rotate/translate) on a coordinateSystem.
00030 
00031 Usage
00032     - surfaceMeshConvert inputFile outputFile [OPTION]
00033 
00034     @param <inputfile> \n
00035     Surface file to be converted.
00036 
00037     @param <outputFile> \n
00038     File into which to write the converted surface.
00039 
00040     @param -clean \n
00041     Perform some surface checking/cleanup on the input surface.
00042 
00043     @param -scaleIn <scale> \n
00044     Specify a scaling factor when reading files.
00045 
00046     @param -scaleOut <scale> \n
00047     Specify a scaling factor when writing files.
00048 
00049     @param -dict <dictionary> \n
00050     Specify an alternative dictionary for constant/coordinateSystems.
00051 
00052     @param -from <coordinateSystem> \n
00053     Specify a coordinate System when reading files.
00054 
00055     @param -to <coordinateSystem> \n
00056     Specify a coordinate System when writing files.
00057 
00058     @param -case <dir> \n
00059     Specify the case directory
00060 
00061     @param -help \n
00062     Display short usage message
00063 
00064     @param -doc \n
00065     Display Doxygen documentation page
00066 
00067     @param -srcDoc \n
00068     Display source code
00069 
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::validArgs.append("outputFile");
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 importName(params[0]);
00105     fileName exportName(params[1]);
00106 
00107     // disable inplace editing
00108     if (importName == exportName)
00109     {
00110         FatalErrorIn(args.executable())
00111             << "Output file " << exportName << " would overwrite input file."
00112             << exit(FatalError);
00113     }
00114 
00115     // check that reading/writing is supported
00116     if
00117     (
00118         !MeshedSurface<face>::canRead(importName, true)
00119      || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
00120     )
00121     {
00122         return 1;
00123     }
00124 
00125 
00126     // get the coordinate transformations
00127     autoPtr<coordinateSystem> fromCsys;
00128     autoPtr<coordinateSystem> toCsys;
00129 
00130     if (args.optionFound("from") || args.optionFound("to"))
00131     {
00132         autoPtr<IOobject> csDictIoPtr;
00133 
00134         if (args.optionFound("dict"))
00135         {
00136             fileName dictPath(args.option("dict"));
00137 
00138             csDictIoPtr.set
00139             (
00140                 new IOobject
00141                 (
00142                     (
00143                         isDir(dictPath)
00144                       ? dictPath/coordinateSystems::typeName
00145                       : dictPath
00146                     ),
00147                     runTime,
00148                     IOobject::MUST_READ,
00149                     IOobject::NO_WRITE,
00150                     false
00151                 )
00152             );
00153         }
00154         else
00155         {
00156             csDictIoPtr.set
00157             (
00158                 new IOobject
00159                 (
00160                     coordinateSystems::typeName,
00161                     runTime.constant(),
00162                     runTime,
00163                     IOobject::MUST_READ,
00164                     IOobject::NO_WRITE,
00165                     false
00166                 )
00167             );
00168         }
00169 
00170 
00171         if (!csDictIoPtr->headerOk())
00172         {
00173             FatalErrorIn(args.executable())
00174                 << "Cannot open coordinateSystems file\n    "
00175                 << csDictIoPtr->objectPath() << nl
00176                 << exit(FatalError);
00177         }
00178 
00179         coordinateSystems csLst(csDictIoPtr());
00180 
00181         if (args.optionFound("from"))
00182         {
00183             const word csName(args.option("from"));
00184 
00185             label csId = csLst.find(csName);
00186             if (csId < 0)
00187             {
00188                 FatalErrorIn(args.executable())
00189                     << "Cannot find -from " << csName << nl
00190                     << "available coordinateSystems: " << csLst.toc() << nl
00191                     << exit(FatalError);
00192             }
00193 
00194             fromCsys.reset(new coordinateSystem(csLst[csId]));
00195         }
00196 
00197         if (args.optionFound("to"))
00198         {
00199             const word csName(args.option("to"));
00200 
00201             label csId = csLst.find(csName);
00202             if (csId < 0)
00203             {
00204                 FatalErrorIn(args.executable())
00205                     << "Cannot find -to " << csName << nl
00206                     << "available coordinateSystems: " << csLst.toc() << nl
00207                     << exit(FatalError);
00208             }
00209 
00210             toCsys.reset(new coordinateSystem(csLst[csId]));
00211         }
00212 
00213 
00214         // maybe fix this later
00215         if (fromCsys.valid() && toCsys.valid())
00216         {
00217             FatalErrorIn(args.executable())
00218                 << "Only allowed  '-from' or '-to' option at the moment."
00219                 << exit(FatalError);
00220         }
00221     }
00222 
00223 
00224     {
00225         MeshedSurface<face> surf(importName);
00226 
00227         if (args.optionFound("clean"))
00228         {
00229             surf.cleanup(true);
00230         }
00231 
00232         scalar scaleIn = 0;
00233         if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
00234         {
00235             Info<< " -scaleIn " << scaleIn << endl;
00236             surf.scalePoints(scaleIn);
00237         }
00238 
00239 
00240         if (fromCsys.valid())
00241         {
00242             Info<< " -from " << fromCsys().name() << endl;
00243             tmp<pointField> tpf = fromCsys().localPosition(surf.points());
00244             surf.movePoints(tpf());
00245         }
00246 
00247         if (toCsys.valid())
00248         {
00249             Info<< " -to " << toCsys().name() << endl;
00250             tmp<pointField> tpf = toCsys().globalPosition(surf.points());
00251             surf.movePoints(tpf());
00252         }
00253 
00254         scalar scaleOut = 0;
00255         if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
00256         {
00257             Info<< " -scaleOut " << scaleOut << endl;
00258             surf.scalePoints(scaleOut);
00259         }
00260 
00261         Info<< "writing " << exportName;
00262         surf.write(exportName);
00263     }
00264 
00265     Info<< "\nEnd\n" << endl;
00266 
00267     return 0;
00268 }
00269 
00270 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines