1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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)
43 or -rotateAlongVector (vector and angle)
46 Scales the points by the given vector.
48 The any or all of the three options may be specified and are processed
51 With -rotateFields (in combination with -rotate/yawPitchRoll/rollPitchYaw)
52 it will also read & transform vector & tensor fields.
55 yaw (rotation about z)
56 pitch (rotation about y)
57 roll (rotation about x)
59 \*---------------------------------------------------------------------------*/
62 #include "objectRegistry.H"
65 #include "volFields.H"
66 #include "surfaceFields.H"
67 #include "ReadFields.H"
68 #include "pointFields.H"
69 #include "transformField.H"
70 #include "transformGeometricField.H"
71 #include "IStringStream.H"
72 #include "RodriguesRotation.H"
75 using namespace Foam::mathematicalConstant;
77 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
79 template<class GeoField>
80 void readAndRotateFields
82 PtrList<GeoField>& flds,
85 const IOobjectList& objects
88 ReadFields(mesh, objects, flds);
91 Info<< "Transforming " << flds[i].name() << endl;
92 dimensionedTensor dimT("t", flds[i].dimensions(), T);
93 transform(flds[i], dimT, flds[i]);
98 void rotateFields(const argList& args, const Time& runTime, const tensor& T)
100 # include "createNamedMesh.H"
102 // Read objects in time directory
103 IOobjectList objects(mesh, runTime.timeName());
107 PtrList<volScalarField> vsFlds;
108 readAndRotateFields(vsFlds, mesh, T, objects);
110 PtrList<volVectorField> vvFlds;
111 readAndRotateFields(vvFlds, mesh, T, objects);
113 PtrList<volSphericalTensorField> vstFlds;
114 readAndRotateFields(vstFlds, mesh, T, objects);
116 PtrList<volSymmTensorField> vsymtFlds;
117 readAndRotateFields(vsymtFlds, mesh, T, objects);
119 PtrList<volTensorField> vtFlds;
120 readAndRotateFields(vtFlds, mesh, T, objects);
122 // Read surface fields.
124 PtrList<surfaceScalarField> ssFlds;
125 readAndRotateFields(ssFlds, mesh, T, objects);
127 PtrList<surfaceVectorField> svFlds;
128 readAndRotateFields(svFlds, mesh, T, objects);
130 PtrList<surfaceSphericalTensorField> sstFlds;
131 readAndRotateFields(sstFlds, mesh, T, objects);
133 PtrList<surfaceSymmTensorField> ssymtFlds;
134 readAndRotateFields(ssymtFlds, mesh, T, objects);
136 PtrList<surfaceTensorField> stFlds;
137 readAndRotateFields(stFlds, mesh, T, objects);
145 int main(int argc, char *argv[])
147 # include "addRegionOption.H"
148 argList::validOptions.insert("translate", "vector");
149 argList::validOptions.insert("rotate", "(vector vector)");
150 argList::validOptions.insert("rotateAlongVector", "(vector angleInDegree)");
151 argList::validOptions.insert("rollPitchYaw", "(roll pitch yaw)");
152 argList::validOptions.insert("yawPitchRoll", "(yaw pitch roll)");
153 argList::validOptions.insert("rotateFields", "");
154 argList::validOptions.insert("scale", "vector");
156 # include "setRootCase.H"
157 # include "createTime.H"
159 word regionName = polyMesh::defaultRegion;
162 if (args.optionReadIfPresent("region", regionName))
164 meshDir = regionName/polyMesh::meshSubDir;
168 meshDir = polyMesh::meshSubDir;
176 runTime.findInstance(meshDir, "points"),
186 if (args.options().empty())
188 FatalErrorIn(args.executable())
189 << "No options supplied, please use one or more of "
190 "-translate, -rotate or -scale options."
194 if (args.optionFound("translate"))
196 vector transVector(args.optionLookup("translate")());
198 Info<< "Translating points by " << transVector << endl;
200 points += transVector;
203 if (args.optionFound("rotate"))
205 Pair<vector> n1n2(args.optionLookup("rotate")());
206 n1n2[0] /= mag(n1n2[0]);
207 n1n2[1] /= mag(n1n2[1]);
208 tensor T = rotationTensor(n1n2[0], n1n2[1]);
210 Info<< "Rotating points by " << T << endl;
212 points = transform(T, points);
214 if (args.optionFound("rotateFields"))
216 rotateFields(args, runTime, T);
219 else if (args.optionFound("rollPitchYaw"))
221 vector v(args.optionLookup("rollPitchYaw")());
223 Info<< "Rotating points by" << nl
224 << " roll " << v.x() << nl
225 << " pitch " << v.y() << nl
226 << " yaw " << v.z() << endl;
229 // Convert to radians
232 quaternion R(v.x(), v.y(), v.z());
234 Info<< "Rotating points by quaternion " << R << endl;
235 points = transform(R, points);
237 if (args.optionFound("rotateFields"))
239 rotateFields(args, runTime, R.R());
242 else if (args.optionFound("yawPitchRoll"))
244 vector v(args.optionLookup("yawPitchRoll")());
246 Info<< "Rotating points by" << nl
247 << " yaw " << v.x() << nl
248 << " pitch " << v.y() << nl
249 << " roll " << v.z() << endl;
252 // Convert to radians
256 scalar pitch = v.y();
259 quaternion R = quaternion(vector(0, 0, 1), yaw);
260 R *= quaternion(vector(0, 1, 0), pitch);
261 R *= quaternion(vector(1, 0, 0), roll);
263 Info<< "Rotating points by quaternion " << R << endl;
264 points = transform(R, points);
266 if (args.optionFound("rotateFields"))
268 rotateFields(args, runTime, R.R());
271 else if (args.optionFound("rotateAlongVector"))
274 scalar rotationAngle;
276 args.optionLookup("rotateAlongVector")()
280 tensor T = RodriguesRotation(rotationAxis, rotationAngle);
282 Info << "Rotating points by " << T << endl;
284 points = transform(T, points);
286 if (args.options().found("rotateFields"))
288 rotateFields(args, runTime, T);
294 if (args.optionFound("scale"))
296 vector scaleVector(args.optionLookup("scale")());
298 Info<< "Scaling points by " << scaleVector << endl;
300 points.replace(vector::X, scaleVector.x()*points.component(vector::X));
301 points.replace(vector::Y, scaleVector.y()*points.component(vector::Y));
302 points.replace(vector::Z, scaleVector.z()*points.component(vector::Z));
305 // Set the precision of the points data to 10
306 IOstream::defaultPrecision(10);
308 Info << "Writing points into directory " << points.path() << nl << endl;
315 // ************************************************************************* //