1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
29 Transforms the mesh points in the polyMesh directory according to the
30 translate, rotate and scale options.
36 Translates the points by the given vector,
38 -rotate (vector vector)
39 Rotates the points from the first vector to the second,
41 or -yawPitchRoll (yawdegrees pitchdegrees rolldegrees)
42 or -rollPitchYaw (rolldegrees pitchdegrees yawdegrees)
45 Scales the points by the given vector.
47 The any or all of the three options may be specified and are processed
50 With -rotateFields (in combination with -rotate/yawPitchRoll/rollPitchYaw)
51 it will also read & transform vector & tensor fields.
55 - transformPoints [OPTIONS]
57 @param -translate \<vector\>\n
58 Translate by given vector.
60 @param -rotateFields \n
61 Also rotate vector/tensor fields.
63 @param -rotate \<(vector vector)\>\n
64 Rotate from first to second direction.
66 @param -scale \<vector (sx sy sz)\>\n
67 Scaling factors in x, y and z direction.
69 @param -case \<dir\>\n
79 Display Doxygen API documentation page for this application.
82 Display Doxygen source documentation page for this application.
85 - yaw: rotation about z
86 - pitch: rotation about y
87 - roll: rotation about x
88 \*---------------------------------------------------------------------------*/
90 #include <OpenFOAM/argList.H>
91 #include <OpenFOAM/Time.H>
92 #include <finiteVolume/fvMesh.H>
93 #include <finiteVolume/volFields.H>
94 #include <finiteVolume/surfaceFields.H>
95 #include <OpenFOAM/ReadFields.H>
96 #include <OpenFOAM/pointFields.H>
97 #include <OpenFOAM/transformField.H>
98 #include <OpenFOAM/transformGeometricField.H>
99 #include <OpenFOAM/IStringStream.H>
101 using namespace Foam;
102 using namespace Foam::mathematicalConstant;
104 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106 template<class GeoField>
107 void readAndRotateFields
109 PtrList<GeoField>& flds,
112 const IOobjectList& objects
115 ReadFields(mesh, objects, flds);
118 Info<< "Transforming " << flds[i].name() << endl;
119 dimensionedTensor dimT("t", flds[i].dimensions(), T);
120 transform(flds[i], dimT, flds[i]);
125 void rotateFields(const Time& runTime, const tensor& T)
127 # include <OpenFOAM/createMesh.H>
129 // Read objects in time directory
130 IOobjectList objects(mesh, runTime.timeName());
134 PtrList<volScalarField> vsFlds;
135 readAndRotateFields(vsFlds, mesh, T, objects);
137 PtrList<volVectorField> vvFlds;
138 readAndRotateFields(vvFlds, mesh, T, objects);
140 PtrList<volSphericalTensorField> vstFlds;
141 readAndRotateFields(vstFlds, mesh, T, objects);
143 PtrList<volSymmTensorField> vsymtFlds;
144 readAndRotateFields(vsymtFlds, mesh, T, objects);
146 PtrList<volTensorField> vtFlds;
147 readAndRotateFields(vtFlds, mesh, T, objects);
149 // Read surface fields.
151 PtrList<surfaceScalarField> ssFlds;
152 readAndRotateFields(ssFlds, mesh, T, objects);
154 PtrList<surfaceVectorField> svFlds;
155 readAndRotateFields(svFlds, mesh, T, objects);
157 PtrList<surfaceSphericalTensorField> sstFlds;
158 readAndRotateFields(sstFlds, mesh, T, objects);
160 PtrList<surfaceSymmTensorField> ssymtFlds;
161 readAndRotateFields(ssymtFlds, mesh, T, objects);
163 PtrList<surfaceTensorField> stFlds;
164 readAndRotateFields(stFlds, mesh, T, objects);
172 int main(int argc, char *argv[])
174 argList::validOptions.insert("translate", "vector");
175 argList::validOptions.insert("rotate", "(vector vector)");
176 argList::validOptions.insert("rollPitchYaw", "(roll pitch yaw)");
177 argList::validOptions.insert("yawPitchRoll", "(yaw pitch roll)");
178 argList::validOptions.insert("rotateFields", "");
179 argList::validOptions.insert("scale", "vector");
181 # include <OpenFOAM/setRootCase.H>
182 # include <OpenFOAM/createTime.H>
189 runTime.findInstance(polyMesh::meshSubDir, "points"),
190 polyMesh::meshSubDir,
199 if (args.options().empty())
201 FatalErrorIn(args.executable())
202 << "No options supplied, please use one or more of "
203 "-translate, -rotate or -scale options."
207 if (args.optionFound("translate"))
209 vector transVector(args.optionLookup("translate")());
211 Info<< "Translating points by " << transVector << endl;
213 points += transVector;
216 if (args.optionFound("rotate"))
218 Pair<vector> n1n2(args.optionLookup("rotate")());
219 n1n2[0] /= mag(n1n2[0]);
220 n1n2[1] /= mag(n1n2[1]);
221 tensor T = rotationTensor(n1n2[0], n1n2[1]);
223 Info<< "Rotating points by " << T << endl;
225 points = transform(T, points);
227 if (args.optionFound("rotateFields"))
229 rotateFields(runTime, T);
232 else if (args.optionFound("rollPitchYaw"))
234 vector v(args.optionLookup("rollPitchYaw")());
236 Info<< "Rotating points by" << nl
237 << " roll " << v.x() << nl
238 << " pitch " << v.y() << nl
239 << " yaw " << v.z() << endl;
242 // Convert to radians
245 quaternion R(v.x(), v.y(), v.z());
247 Info<< "Rotating points by quaternion " << R << endl;
248 points = transform(R, points);
250 if (args.optionFound("rotateFields"))
252 rotateFields(runTime, R.R());
255 else if (args.optionFound("yawPitchRoll"))
257 vector v(args.optionLookup("yawPitchRoll")());
259 Info<< "Rotating points by" << nl
260 << " yaw " << v.x() << nl
261 << " pitch " << v.y() << nl
262 << " roll " << v.z() << endl;
265 // Convert to radians
269 scalar pitch = v.y();
272 quaternion R = quaternion(vector(0, 0, 1), yaw);
273 R *= quaternion(vector(0, 1, 0), pitch);
274 R *= quaternion(vector(1, 0, 0), roll);
276 Info<< "Rotating points by quaternion " << R << endl;
277 points = transform(R, points);
279 if (args.optionFound("rotateFields"))
281 rotateFields(runTime, R.R());
285 if (args.optionFound("scale"))
287 vector scaleVector(args.optionLookup("scale")());
289 Info<< "Scaling points by " << scaleVector << endl;
291 points.replace(vector::X, scaleVector.x()*points.component(vector::X));
292 points.replace(vector::Y, scaleVector.y()*points.component(vector::Y));
293 points.replace(vector::Z, scaleVector.z()*points.component(vector::Z));
296 // Set the precision of the points data to 10
297 IOstream::defaultPrecision(10);
299 Info << "Writing points into directory " << points.path() << nl << endl;
306 // ************************ vim: set sw=4 sts=4 et: ************************ //