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

surfaceMeshConvertTesting.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     surfaceMeshConvertTesting
00026 
00027 Description
00028     Converts from one surface mesh format to another, but primarily
00029     used for testing functionality.
00030 
00031 Usage
00032     - surfaceMeshConvertTesting 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 -orient \n
00044     Check face orientation on the input surface.
00045 
00046     @param -scale <scale> \n
00047     Specify a scaling factor for writing the files.
00048 
00049     @param -triSurface \n
00050     Use triSurface library for input/output.
00051 
00052     @param -keyed \n
00053     Use keyedSurface for input/output.
00054 
00055     @param -case <dir> \n
00056     Specify the case directory.
00057 
00058     @param -help \n
00059     Display short usage message.
00060 
00061     @param -doc \n
00062     Display Doxygen documentation page.
00063 
00064     @param -srcDoc \n
00065     Display source code.
00066 
00067 Note
00068     The filename extensions are used to determine the file format type.
00069 
00070 \*---------------------------------------------------------------------------*/
00071 
00072 #include <OpenFOAM/argList.H>
00073 #include <OpenFOAM/timeSelector.H>
00074 #include <OpenFOAM/Time.H>
00075 #include <OpenFOAM/polyMesh.H>
00076 #include <triSurface/triSurface.H>
00077 #include <surfMesh/surfMesh.H>
00078 #include <surfMesh/surfFields.H>
00079 #include <surfMesh/surfPointFields.H>
00080 #include <OpenFOAM/PackedBoolList.H>
00081 
00082 #include <surfMesh/MeshedSurfaces.H>
00083 #include <surfMesh/UnsortedMeshedSurfaces.H>
00084 
00085 using namespace Foam;
00086 
00087 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00088 //  Main program:
00089 
00090 int main(int argc, char *argv[])
00091 {
00092     argList::noParallel();
00093     argList::validArgs.append("inputFile");
00094     argList::validArgs.append("outputFile");
00095     argList::validOptions.insert("clean", "");
00096     argList::validOptions.insert("orient", "");
00097     argList::validOptions.insert("surfMesh", "");
00098     argList::validOptions.insert("scale", "scale");
00099     argList::validOptions.insert("triSurface", "");
00100     argList::validOptions.insert("unsorted", "");
00101     argList::validOptions.insert("triFace", "");
00102 #   include <OpenFOAM/setRootCase.H>
00103     const stringList& params = args.additionalArgs();
00104 
00105     scalar scaleFactor = 0;
00106     args.optionReadIfPresent("scale", scaleFactor);
00107 
00108     fileName importName(params[0]);
00109     fileName exportName(params[1]);
00110 
00111     if (importName == exportName)
00112     {
00113         FatalErrorIn(args.executable())
00114             << "Output file " << exportName << " would overwrite input file."
00115             << exit(FatalError);
00116     }
00117 
00118     if
00119     (
00120         !MeshedSurface<face>::canRead(importName, true)
00121      || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
00122     )
00123     {
00124         return 1;
00125     }
00126 
00127     if (args.optionFound("triSurface"))
00128     {
00129         triSurface surf(importName);
00130 
00131         Info<< "Read surface:" << endl;
00132         surf.writeStats(Info);
00133         Info<< endl;
00134 
00135         if (args.optionFound("orient"))
00136         {
00137             Info<< "Checking surface orientation" << endl;
00138             PatchTools::checkOrientation(surf, true);
00139             Info<< endl;
00140         }
00141 
00142         if (args.optionFound("clean"))
00143         {
00144             Info<< "Cleaning up surface" << endl;
00145             surf.cleanup(true);
00146             surf.writeStats(Info);
00147             Info<< endl;
00148         }
00149 
00150         Info<< "writing " << exportName;
00151         if (scaleFactor <= 0)
00152         {
00153             Info<< " without scaling" << endl;
00154         }
00155         else
00156         {
00157             Info<< " with scaling " << scaleFactor << endl;
00158             surf.scalePoints(scaleFactor);
00159             surf.writeStats(Info);
00160             Info<< endl;
00161         }
00162 
00163         // write sorted by region
00164         surf.write(exportName, true);
00165     }
00166     else if (args.optionFound("unsorted"))
00167     {
00168         UnsortedMeshedSurface<face> surf(importName);
00169 
00170         Info<< "Read surface:" << endl;
00171         surf.writeStats(Info);
00172         Info<< endl;
00173 
00174         if (args.optionFound("orient"))
00175         {
00176             Info<< "Checking surface orientation" << endl;
00177             PatchTools::checkOrientation(surf, true);
00178             Info<< endl;
00179         }
00180 
00181         if (args.optionFound("clean"))
00182         {
00183             Info<< "Cleaning up surface" << endl;
00184             surf.cleanup(true);
00185             surf.writeStats(Info);
00186             Info<< endl;
00187         }
00188 
00189         Info<< "writing " << exportName;
00190         if (scaleFactor <= 0)
00191         {
00192             Info<< " without scaling" << endl;
00193         }
00194         else
00195         {
00196             Info<< " with scaling " << scaleFactor << endl;
00197             surf.scalePoints(scaleFactor);
00198             surf.writeStats(Info);
00199             Info<< endl;
00200         }
00201         surf.write(exportName);
00202     }
00203 #if 1
00204     else if (args.optionFound("triFace"))
00205     {
00206         MeshedSurface<triFace> surf(importName);
00207 
00208         Info<< "Read surface:" << endl;
00209         surf.writeStats(Info);
00210         Info<< endl;
00211 
00212         if (args.optionFound("orient"))
00213         {
00214             Info<< "Checking surface orientation" << endl;
00215             PatchTools::checkOrientation(surf, true);
00216             Info<< endl;
00217         }
00218 
00219         if (args.optionFound("clean"))
00220         {
00221             Info<< "Cleaning up surface" << endl;
00222             surf.cleanup(true);
00223             surf.writeStats(Info);
00224             Info<< endl;
00225         }
00226 
00227         Info<< "writing " << exportName;
00228         if (scaleFactor <= 0)
00229         {
00230             Info<< " without scaling" << endl;
00231         }
00232         else
00233         {
00234             Info<< " with scaling " << scaleFactor << endl;
00235             surf.scalePoints(scaleFactor);
00236             surf.writeStats(Info);
00237             Info<< endl;
00238         }
00239         surf.write(exportName);
00240     }
00241 #endif
00242     else
00243     {
00244         MeshedSurface<face> surf(importName);
00245 
00246         Info<< "Read surface:" << endl;
00247         surf.writeStats(Info);
00248         Info<< endl;
00249 
00250         if (args.optionFound("orient"))
00251         {
00252             Info<< "Checking surface orientation" << endl;
00253             PatchTools::checkOrientation(surf, true);
00254             Info<< endl;
00255         }
00256 
00257         if (args.optionFound("clean"))
00258         {
00259             Info<< "Cleaning up surface" << endl;
00260             surf.cleanup(true);
00261             surf.writeStats(Info);
00262             Info<< endl;
00263         }
00264 
00265 
00266         Info<< "writing " << exportName;
00267         if (scaleFactor <= 0)
00268         {
00269             Info<< " without scaling" << endl;
00270         }
00271         else
00272         {
00273             Info<< " with scaling " << scaleFactor << endl;
00274             surf.scalePoints(scaleFactor);
00275             surf.writeStats(Info);
00276             Info<< endl;
00277         }
00278         surf.write(exportName);
00279 
00280         if (args.optionFound("surfMesh"))
00281         {
00282             Foam::Time runTime
00283             (
00284                 args.rootPath(),
00285                 args.caseName()
00286             );
00287 
00288             // start with "constant"
00289             runTime.setTime(instant(0, runTime.constant()), 0);
00290 
00291             Info<< "runTime.instance() = " << runTime.instance() << endl;
00292             Info<< "runTime.timeName() = " << runTime.timeName() << endl;
00293 
00294 
00295             Info<< "write MeshedSurface 'yetAnother' via proxy as surfMesh"
00296                 << endl;
00297             surf.write
00298             (
00299                 runTime,
00300                 "yetAnother"
00301             );
00302 
00303             surfMesh surfIn
00304             (
00305                 IOobject
00306                 (
00307                     "default",
00308                     runTime.timeName(),
00309                     runTime,
00310                     IOobject::MUST_READ,
00311                     IOobject::NO_WRITE
00312                 )
00313             );
00314 
00315 
00316             MeshedSurface<face> surfIn2(runTime, "foobar");
00317 
00318             Info<<"surfIn2 = " << surfIn2.size() << endl;
00319 
00320             Info<< "surfIn = " << surfIn.size() << endl;
00321 
00322 
00323             Info<< "writing surfMesh as obj = oldSurfIn.obj" << endl;
00324             surfIn.write("oldSurfIn.obj");
00325 
00326 
00327             Info<< "runTime.instance() = " << runTime.instance() << endl;
00328 
00329             surfMesh surfOut
00330             (
00331                 IOobject
00332                 (
00333                     "mySurf",
00334                     runTime.instance(),
00335                     runTime,
00336                     IOobject::NO_READ,
00337                     IOobject::NO_WRITE,
00338                     false
00339                 ),
00340                 surf.xfer()
00341             );
00342 
00343             Info<< "writing surfMesh as well: " << surfOut.objectPath() << endl;
00344             surfOut.write();
00345 
00346             surfLabelField zoneIds
00347             (
00348                 IOobject
00349                 (
00350                     "zoneIds",
00351                     surfOut.instance(),
00352                     surfOut,
00353                     IOobject::NO_READ,
00354                     IOobject::NO_WRITE
00355                 ),
00356                 surfOut,
00357                 dimless
00358             );
00359 
00360             Info<<" surf name= " << surfOut.name() <<nl;
00361             Info<< "rename to anotherSurf" << endl;
00362             surfOut.rename("anotherSurf");
00363 
00364             Info<<" surf name= " << surfOut.name() <<nl;
00365 
00366             // advance time to 1
00367             runTime.setTime(instant(1), 1);
00368             surfOut.setInstance(runTime.timeName());
00369 
00370 
00371 
00372             Info<< "writing surfMesh again well: " << surfOut.objectPath() << endl;
00373             surfOut.write();
00374 
00375             // write directly
00376             surfOut.write("someName.ofs");
00377 
00378 #if 1
00379             const surfZoneList& zones = surfOut.surfZones();
00380             forAll(zones, zoneI)
00381             {
00382                 SubList<label>
00383                 (
00384                     zoneIds,
00385                     zones[zoneI].size(),
00386                     zones[zoneI].start()
00387                 ) = zoneI;
00388             }
00389 
00390             Info<< "write zoneIds (for testing only): "
00391                 << zoneIds.objectPath() << endl;
00392             zoneIds.write();
00393 
00394             surfPointLabelField pointIds
00395             (
00396                 IOobject
00397                 (
00398                     "zoneIds.",
00399 //                    "pointIds",
00400                     surfOut.instance(),
00401 //                    "pointFields",
00402                     surfOut,
00403                     IOobject::NO_READ,
00404                     IOobject::NO_WRITE
00405                 ),
00406                 surfOut,
00407                 dimless
00408             );
00409 
00410             forAll(pointIds, i)
00411             {
00412                 pointIds[i] = i;
00413             }
00414 
00415             Info<< "write pointIds (for testing only): "
00416                 << pointIds.objectPath() << endl;
00417             pointIds.write();
00418 
00419             Info<<"surfMesh with these names: " << surfOut.names() << endl;
00420 
00421 #endif
00422         }
00423     }
00424 
00425     Info<< "\nEnd\n" << endl;
00426 
00427     return 0;
00428 }
00429 
00430 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines