1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 Transforms the mesh points in the polyMesh directory according to the
29 translate, rotate and scale options.
35 Translates the points by the given vector,
37 -rotate (vector vector)
38 Rotates the points from the first vector to the second,
40 or -yawPitchRoll (yawdegrees pitchdegrees rolldegrees)
41 or -rollPitchYaw (rolldegrees pitchdegrees yawdegrees)
44 Scales the points by the given vector.
46 The any or all of the three options may be specified and are processed
49 With -rotateFields (in combination with -rotate/yawPitchRoll/rollPitchYaw)
50 it will also read & transform vector & tensor fields.
53 yaw (rotation about z)
54 pitch (rotation about y)
55 roll (rotation about x)
57 \*---------------------------------------------------------------------------*/
62 #include "volFields.H"
63 #include "surfaceFields.H"
64 #include "ReadFields.H"
65 #include "pointFields.H"
66 #include "transformField.H"
67 #include "transformGeometricField.H"
68 #include "IStringStream.H"
69 #include "mathematicalConstants.H"
72 using namespace Foam::constant::mathematical;
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 template<class GeoField>
77 void readAndRotateFields
79 PtrList<GeoField>& flds,
82 const IOobjectList& objects
85 ReadFields(mesh, objects, flds);
88 Info<< "Transforming " << flds[i].name() << endl;
89 dimensionedTensor dimT("t", flds[i].dimensions(), T);
90 transform(flds[i], dimT, flds[i]);
95 void rotateFields(const argList& args, const Time& runTime, const tensor& T)
97 # include "createNamedMesh.H"
99 // Read objects in time directory
100 IOobjectList objects(mesh, runTime.timeName());
104 PtrList<volScalarField> vsFlds;
105 readAndRotateFields(vsFlds, mesh, T, objects);
107 PtrList<volVectorField> vvFlds;
108 readAndRotateFields(vvFlds, mesh, T, objects);
110 PtrList<volSphericalTensorField> vstFlds;
111 readAndRotateFields(vstFlds, mesh, T, objects);
113 PtrList<volSymmTensorField> vsymtFlds;
114 readAndRotateFields(vsymtFlds, mesh, T, objects);
116 PtrList<volTensorField> vtFlds;
117 readAndRotateFields(vtFlds, mesh, T, objects);
119 // Read surface fields.
121 PtrList<surfaceScalarField> ssFlds;
122 readAndRotateFields(ssFlds, mesh, T, objects);
124 PtrList<surfaceVectorField> svFlds;
125 readAndRotateFields(svFlds, mesh, T, objects);
127 PtrList<surfaceSphericalTensorField> sstFlds;
128 readAndRotateFields(sstFlds, mesh, T, objects);
130 PtrList<surfaceSymmTensorField> ssymtFlds;
131 readAndRotateFields(ssymtFlds, mesh, T, objects);
133 PtrList<surfaceTensorField> stFlds;
134 readAndRotateFields(stFlds, mesh, T, objects);
142 int main(int argc, char *argv[])
148 "translate by the specified <vector> - eg, '(1 0 0)'"
154 "transform in terms of a rotation between <vectorA> and <vectorB> "
155 "- eg, '( (1 0 0) (0 0 1) )'"
161 "transform in terms of '(roll pitch yaw)' in degrees"
167 "transform in terms of '(yaw pitch roll)' in degrees"
169 argList::addBoolOption
172 "read and transform vector and tensor fields too"
178 "scale by the specified amount - eg, '(0.001 0.001 0.001)' for a "
179 "uniform [mm] to [m] scaling"
182 # include "addRegionOption.H"
183 # include "setRootCase.H"
184 # include "createTime.H"
186 word regionName = polyMesh::defaultRegion;
189 if (args.optionReadIfPresent("region", regionName))
191 meshDir = regionName/polyMesh::meshSubDir;
195 meshDir = polyMesh::meshSubDir;
203 runTime.findInstance(meshDir, "points"),
212 const bool doRotateFields = args.optionFound("rotateFields");
214 // this is not actually stringent enough:
215 if (args.options().empty())
217 FatalErrorIn(args.executable())
218 << "No options supplied, please use one or more of "
219 "-translate, -rotate or -scale options."
224 if (args.optionReadIfPresent("translate", v))
226 Info<< "Translating points by " << v << endl;
231 if (args.optionFound("rotate"))
235 args.optionLookup("rotate")()
237 n1n2[0] /= mag(n1n2[0]);
238 n1n2[1] /= mag(n1n2[1]);
239 tensor T = rotationTensor(n1n2[0], n1n2[1]);
241 Info<< "Rotating points by " << T << endl;
243 points = transform(T, points);
247 rotateFields(args, runTime, T);
250 else if (args.optionReadIfPresent("rollPitchYaw", v))
252 Info<< "Rotating points by" << nl
253 << " roll " << v.x() << nl
254 << " pitch " << v.y() << nl
255 << " yaw " << v.z() << nl;
257 // Convert to radians
260 quaternion R(v.x(), v.y(), v.z());
262 Info<< "Rotating points by quaternion " << R << endl;
263 points = transform(R, points);
267 rotateFields(args, runTime, R.R());
270 else if (args.optionReadIfPresent("yawPitchRoll", v))
272 Info<< "Rotating points by" << nl
273 << " yaw " << v.x() << nl
274 << " pitch " << v.y() << nl
275 << " roll " << v.z() << nl;
277 // Convert to radians
281 scalar pitch = v.y();
284 quaternion R = quaternion(vector(0, 0, 1), yaw);
285 R *= quaternion(vector(0, 1, 0), pitch);
286 R *= quaternion(vector(1, 0, 0), roll);
288 Info<< "Rotating points by quaternion " << R << endl;
289 points = transform(R, points);
293 rotateFields(args, runTime, R.R());
297 if (args.optionReadIfPresent("scale", v))
299 Info<< "Scaling points by " << v << endl;
301 points.replace(vector::X, v.x()*points.component(vector::X));
302 points.replace(vector::Y, v.y()*points.component(vector::Y));
303 points.replace(vector::Z, v.z()*points.component(vector::Z));
306 // Set the precision of the points data to 10
307 IOstream::defaultPrecision(10);
309 Info<< "Writing points into directory " << points.path() << nl << endl;
316 // ************************************************************************* //