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

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-2009 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 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     rotateMesh
00027 
00028 Description
00029     Rotates the mesh and fields from the direcion n1 to the direction n2.
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #include "argList.H"
00034 #include "timeSelector.H"
00035 #include "Time.H"
00036 #include "fvMesh.H"
00037 #include "volFields.H"
00038 #include "surfaceFields.H"
00039 #include "transformGeometricField.H"
00040 #include "IOobjectList.H"
00041 
00042 using namespace Foam;
00043 
00044 template<class GeometricField>
00045 void RotateFields
00046 (
00047     const fvMesh& mesh,
00048     const IOobjectList& objects,
00049     const tensor& T
00050 )
00051 {
00052     // Search list of objects for volScalarFields
00053     IOobjectList fields(objects.lookupClass(GeometricField::typeName));
00054 
00055     forAllIter(IOobjectList, fields, fieldIter)
00056     {
00057         Info<< "    Rotating " << fieldIter()->name() << endl;
00058 
00059         GeometricField theta(*fieldIter(), mesh);
00060         transform(theta, dimensionedTensor(T), theta);
00061         theta.write();
00062     }
00063 }
00064 
00065 
00066 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00067 
00068 int main(int argc, char *argv[])
00069 {
00070     timeSelector::addOptions();
00071 
00072     argList::validArgs.append("n1");
00073     argList::validArgs.append("n2");
00074 
00075 #   include "setRootCase.H"
00076 #   include "createTime.H"
00077 
00078     vector n1(IStringStream(args.additionalArgs()[0])());
00079     n1 /= mag(n1);
00080 
00081     vector n2(IStringStream(args.additionalArgs()[1])());
00082     n2 /= mag(n2);
00083 
00084     tensor T = rotationTensor(n1, n2);
00085 
00086     {
00087         pointIOField points
00088         (
00089             IOobject
00090             (
00091                 "points",
00092                 runTime.findInstance(polyMesh::meshSubDir, "points"),
00093                 polyMesh::meshSubDir,
00094                 runTime,
00095                 IOobject::MUST_READ,
00096                 IOobject::NO_WRITE,
00097                 false
00098             )
00099         );
00100 
00101         points = transform(T, points);
00102 
00103         // Set the precision of the points data to 10
00104         IOstream::defaultPrecision(10);
00105 
00106         Info << "Writing points into directory " << points.path() << nl << endl;
00107         points.write();
00108     }
00109 
00110 
00111     instantList timeDirs = timeSelector::select0(runTime, args);
00112 
00113 #   include "createMesh.H"
00114 
00115 
00116     forAll(timeDirs, timeI)
00117     {
00118         runTime.setTime(timeDirs[timeI], timeI);
00119 
00120         Info<< "Time = " << runTime.timeName() << endl;
00121 
00122         // Search for list of objects for this time
00123         IOobjectList objects(mesh, runTime.timeName());
00124 
00125         RotateFields<volVectorField>(mesh, objects, T);
00126         RotateFields<volSphericalTensorField>(mesh, objects, T);
00127         RotateFields<volSymmTensorField>(mesh, objects, T);
00128         RotateFields<volTensorField>(mesh, objects, T);
00129 
00130         RotateFields<surfaceVectorField>(mesh, objects, T);
00131         RotateFields<surfaceSphericalTensorField>(mesh, objects, T);
00132         RotateFields<surfaceSymmTensorField>(mesh, objects, T);
00133         RotateFields<surfaceTensorField>(mesh, objects, T);
00134     }
00135 
00136     Info<< "\nEnd.\n" << endl;
00137 
00138     return 0;
00139 }
00140 
00141 
00142 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd