FreeFOAM The Cross-Platform CFD Toolkit
rotateMesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anispulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  rotateMesh
26 
27 Description
28  Rotates the mesh and fields from the direcion n1 to the direction n2.
29 
30 Usage
31 
32  - rotateMesh [OPTIONS] <old direction (nx,ny,nz)> <new direction (nx,ny,nz)>
33 
34  @param <old direction (nx,ny,nz)> \n
35  @todo Detailed description of argument.
36 
37  @param <new direction (nx,ny,nz)> \n
38  @todo Detailed description of argument.
39 
40  @param -noZero \n
41  Ignore timestep 0.
42 
43  @param -constant \n
44  Include the constant directory.
45 
46  @param -time <time>\n
47  Apply only to specific time.
48 
49  @param -latestTime \n
50  Only apply to latest time step.
51 
52  @param -case <dir>\n
53  Case directory.
54 
55  @param -parallel \n
56  Run in parallel.
57 
58  @param -help \n
59  Display help message.
60 
61  @param -doc \n
62  Display Doxygen API documentation page for this application.
63 
64  @param -srcDoc \n
65  Display Doxygen source documentation page for this application.
66 
67 \*---------------------------------------------------------------------------*/
68 
69 #include <OpenFOAM/argList.H>
70 #include <OpenFOAM/timeSelector.H>
71 #include <OpenFOAM/Time.H>
72 #include <finiteVolume/fvMesh.H>
73 #include <finiteVolume/volFields.H>
76 #include <OpenFOAM/IOobjectList.H>
77 
78 using namespace Foam;
79 
80 template<class GeometricField>
81 void RotateFields
82 (
83  const fvMesh& mesh,
84  const IOobjectList& objects,
85  const tensor& T
86 )
87 {
88  // Search list of objects for volScalarFields
90 
91  forAllIter(IOobjectList, fields, fieldIter)
92  {
93  Info<< " Rotating " << fieldIter()->name() << endl;
94 
95  GeometricField theta(*fieldIter(), mesh);
96  transform(theta, dimensionedTensor(T), theta);
97  theta.write();
98  }
99 }
100 
101 
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 
104 int main(int argc, char *argv[])
105 {
107 
110 
111 # include <OpenFOAM/setRootCase.H>
112 # include <OpenFOAM/createTime.H>
113 
115  n1 /= mag(n1);
116 
118  n2 /= mag(n2);
119 
120  tensor T = rotationTensor(n1, n2);
121 
122  {
124  (
125  IOobject
126  (
127  "points",
128  runTime.findInstance(polyMesh::meshSubDir, "points"),
130  runTime,
133  false
134  )
135  );
136 
137  points = transform(T, points);
138 
139  // Set the precision of the points data to 10
141 
142  Info << "Writing points into directory " << points.path() << nl << endl;
143  points.write();
144  }
145 
146 
148 
149 # include <OpenFOAM/createMesh.H>
150 
151 
152  forAll(timeDirs, timeI)
153  {
154  runTime.setTime(timeDirs[timeI], timeI);
155 
156  Info<< "Time = " << runTime.timeName() << endl;
157 
158  // Search for list of objects for this time
159  IOobjectList objects(mesh, runTime.timeName());
160 
161  RotateFields<volVectorField>(mesh, objects, T);
162  RotateFields<volSphericalTensorField>(mesh, objects, T);
163  RotateFields<volSymmTensorField>(mesh, objects, T);
164  RotateFields<volTensorField>(mesh, objects, T);
165 
166  RotateFields<surfaceVectorField>(mesh, objects, T);
167  RotateFields<surfaceSphericalTensorField>(mesh, objects, T);
168  RotateFields<surfaceSymmTensorField>(mesh, objects, T);
169  RotateFields<surfaceTensorField>(mesh, objects, T);
170  }
171 
172  Info<< "\nEnd.\n" << endl;
173 
174  return 0;
175 }
176 
177 
178 // ************************ vim: set sw=4 sts=4 et: ************************ //