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

rotateMesh.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 anispulation  |
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     rotateMesh
00026 
00027 Description
00028     Rotates the mesh and fields from the direcion n1 to the direction n2.
00029 
00030 Usage
00031 
00032     - rotateMesh [OPTIONS] <old direction (nx,ny,nz)> <new direction (nx,ny,nz)>
00033 
00034     @param <old direction (nx,ny,nz)> \n
00035     @todo Detailed description of argument.
00036 
00037     @param <new direction (nx,ny,nz)> \n
00038     @todo Detailed description of argument.
00039 
00040     @param -noZero \n
00041     Ignore timestep 0.
00042 
00043     @param -constant \n
00044     Include the constant directory.
00045 
00046     @param -time <time>\n
00047     Apply only to specific time.
00048 
00049     @param -latestTime \n
00050     Only apply to latest time step.
00051 
00052     @param -case <dir>\n
00053     Case directory.
00054 
00055     @param -parallel \n
00056     Run in parallel.
00057 
00058     @param -help \n
00059     Display help message.
00060 
00061     @param -doc \n
00062     Display Doxygen API documentation page for this application.
00063 
00064     @param -srcDoc \n
00065     Display Doxygen source documentation page for this application.
00066 
00067 \*---------------------------------------------------------------------------*/
00068 
00069 #include <OpenFOAM/argList.H>
00070 #include <OpenFOAM/timeSelector.H>
00071 #include <OpenFOAM/Time.H>
00072 #include <finiteVolume/fvMesh.H>
00073 #include <finiteVolume/volFields.H>
00074 #include <finiteVolume/surfaceFields.H>
00075 #include <OpenFOAM/transformGeometricField.H>
00076 #include <OpenFOAM/IOobjectList.H>
00077 
00078 using namespace Foam;
00079 
00080 template<class GeometricField>
00081 void RotateFields
00082 (
00083     const fvMesh& mesh,
00084     const IOobjectList& objects,
00085     const tensor& T
00086 )
00087 {
00088     // Search list of objects for volScalarFields
00089     IOobjectList fields(objects.lookupClass(GeometricField::typeName));
00090 
00091     forAllIter(IOobjectList, fields, fieldIter)
00092     {
00093         Info<< "    Rotating " << fieldIter()->name() << endl;
00094 
00095         GeometricField theta(*fieldIter(), mesh);
00096         transform(theta, dimensionedTensor(T), theta);
00097         theta.write();
00098     }
00099 }
00100 
00101 
00102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00103 
00104 int main(int argc, char *argv[])
00105 {
00106     timeSelector::addOptions();
00107 
00108     argList::validArgs.append("n1");
00109     argList::validArgs.append("n2");
00110 
00111 #   include <OpenFOAM/setRootCase.H>
00112 #   include <OpenFOAM/createTime.H>
00113 
00114     vector n1(IStringStream(args.additionalArgs()[0])());
00115     n1 /= mag(n1);
00116 
00117     vector n2(IStringStream(args.additionalArgs()[1])());
00118     n2 /= mag(n2);
00119 
00120     tensor T = rotationTensor(n1, n2);
00121 
00122     {
00123         pointIOField points
00124         (
00125             IOobject
00126             (
00127                 "points",
00128                 runTime.findInstance(polyMesh::meshSubDir, "points"),
00129                 polyMesh::meshSubDir,
00130                 runTime,
00131                 IOobject::MUST_READ,
00132                 IOobject::NO_WRITE,
00133                 false
00134             )
00135         );
00136 
00137         points = transform(T, points);
00138 
00139         // Set the precision of the points data to 10
00140         IOstream::defaultPrecision(10);
00141 
00142         Info << "Writing points into directory " << points.path() << nl << endl;
00143         points.write();
00144     }
00145 
00146 
00147     instantList timeDirs = timeSelector::select0(runTime, args);
00148 
00149 #   include <OpenFOAM/createMesh.H>
00150 
00151 
00152     forAll(timeDirs, timeI)
00153     {
00154         runTime.setTime(timeDirs[timeI], timeI);
00155 
00156         Info<< "Time = " << runTime.timeName() << endl;
00157 
00158         // Search for list of objects for this time
00159         IOobjectList objects(mesh, runTime.timeName());
00160 
00161         RotateFields<volVectorField>(mesh, objects, T);
00162         RotateFields<volSphericalTensorField>(mesh, objects, T);
00163         RotateFields<volSymmTensorField>(mesh, objects, T);
00164         RotateFields<volTensorField>(mesh, objects, T);
00165 
00166         RotateFields<surfaceVectorField>(mesh, objects, T);
00167         RotateFields<surfaceSphericalTensorField>(mesh, objects, T);
00168         RotateFields<surfaceSymmTensorField>(mesh, objects, T);
00169         RotateFields<surfaceTensorField>(mesh, objects, T);
00170     }
00171 
00172     Info<< "\nEnd.\n" << endl;
00173 
00174     return 0;
00175 }
00176 
00177 
00178 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines