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

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