initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / manipulation / rotateMesh / rotateMesh.C
blobd7a84ee45a88d7cf9bbe91dd50a8ac728ecd65f6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anispulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Application
26     rotateMesh
28 Description
29     Rotates the mesh and fields from the direcion n1 to the direction n2.
31 \*---------------------------------------------------------------------------*/
33 #include "argList.H"
34 #include "timeSelector.H"
35 #include "Time.H"
36 #include "fvMesh.H"
37 #include "volFields.H"
38 #include "surfaceFields.H"
39 #include "transformGeometricField.H"
40 #include "IOobjectList.H"
42 using namespace Foam;
44 template<class GeometricField>
45 void RotateFields
47     const fvMesh& mesh,
48     const IOobjectList& objects,
49     const tensor& T
52     // Search list of objects for volScalarFields
53     IOobjectList fields(objects.lookupClass(GeometricField::typeName));
55     forAllIter(IOobjectList, fields, fieldIter)
56     {
57         Info<< "    Rotating " << fieldIter()->name() << endl;
59         GeometricField theta(*fieldIter(), mesh);
60         transform(theta, dimensionedTensor(T), theta);
61         theta.write();
62     }
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 int main(int argc, char *argv[])
70     timeSelector::addOptions();
72     argList::validArgs.append("n1");
73     argList::validArgs.append("n2");
75 #   include "setRootCase.H"
76 #   include "createTime.H"
78     vector n1(IStringStream(args.additionalArgs()[0])());
79     n1 /= mag(n1);
81     vector n2(IStringStream(args.additionalArgs()[1])());
82     n2 /= mag(n2);
84     tensor T = rotationTensor(n1, n2);
86     {
87         pointIOField points
88         (
89             IOobject
90             (
91                 "points",
92                 runTime.findInstance(polyMesh::meshSubDir, "points"),
93                 polyMesh::meshSubDir,
94                 runTime,
95                 IOobject::MUST_READ,
96                 IOobject::NO_WRITE,
97                 false
98             )
99         );
101         points = transform(T, points);
103         // Set the precision of the points data to 10
104         IOstream::defaultPrecision(10);
106         Info << "Writing points into directory " << points.path() << nl << endl;
107         points.write();
108     }
111     instantList timeDirs = timeSelector::select0(runTime, args);
113 #   include "createMesh.H"
116     forAll(timeDirs, timeI)
117     {
118         runTime.setTime(timeDirs[timeI], timeI);
120         Info<< "Time = " << runTime.timeName() << endl;
122         // Search for list of objects for this time
123         IOobjectList objects(mesh, runTime.timeName());
125         RotateFields<volVectorField>(mesh, objects, T);
126         RotateFields<volSphericalTensorField>(mesh, objects, T);
127         RotateFields<volSymmTensorField>(mesh, objects, T);
128         RotateFields<volTensorField>(mesh, objects, T);
130         RotateFields<surfaceVectorField>(mesh, objects, T);
131         RotateFields<surfaceSphericalTensorField>(mesh, objects, T);
132         RotateFields<surfaceSymmTensorField>(mesh, objects, T);
133         RotateFields<surfaceTensorField>(mesh, objects, T);
134     }
136     Info<< "\nEnd.\n" << endl;
138     return 0;
142 // ************************************************************************* //