Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / mesh / manipulation / rotateMesh / rotateMesh.C
blobc1f3b8f09ff44f96f08f5bc50e09f69b60a14c69
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anispulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Application
25     rotateMesh
27 Description
28     Rotates the mesh and fields from the direcion n1 to the direction n2.
30 \*---------------------------------------------------------------------------*/
32 #include "argList.H"
33 #include "timeSelector.H"
34 #include "objectRegistry.H"
35 #include "foamTime.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 // ************************************************************************* //