00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #include "argList.H"
00061 #include "Time.H"
00062 #include "fvMesh.H"
00063 #include "volFields.H"
00064 #include "surfaceFields.H"
00065 #include "ReadFields.H"
00066 #include "pointFields.H"
00067 #include "transformField.H"
00068 #include "transformGeometricField.H"
00069 #include "IStringStream.H"
00070
00071 using namespace Foam;
00072 using namespace Foam::mathematicalConstant;
00073
00074
00075
00076 template<class GeoField>
00077 void readAndRotateFields
00078 (
00079 PtrList<GeoField>& flds,
00080 const fvMesh& mesh,
00081 const tensor& T,
00082 const IOobjectList& objects
00083 )
00084 {
00085 ReadFields(mesh, objects, flds);
00086 forAll(flds, i)
00087 {
00088 Info<< "Transforming " << flds[i].name() << endl;
00089 dimensionedTensor dimT("t", flds[i].dimensions(), T);
00090 transform(flds[i], dimT, flds[i]);
00091 }
00092 }
00093
00094
00095 void rotateFields(const Time& runTime, const tensor& T)
00096 {
00097 # include "createMesh.H"
00098
00099
00100 IOobjectList objects(mesh, runTime.timeName());
00101
00102
00103
00104 PtrList<volScalarField> vsFlds;
00105 readAndRotateFields(vsFlds, mesh, T, objects);
00106
00107 PtrList<volVectorField> vvFlds;
00108 readAndRotateFields(vvFlds, mesh, T, objects);
00109
00110 PtrList<volSphericalTensorField> vstFlds;
00111 readAndRotateFields(vstFlds, mesh, T, objects);
00112
00113 PtrList<volSymmTensorField> vsymtFlds;
00114 readAndRotateFields(vsymtFlds, mesh, T, objects);
00115
00116 PtrList<volTensorField> vtFlds;
00117 readAndRotateFields(vtFlds, mesh, T, objects);
00118
00119
00120
00121 PtrList<surfaceScalarField> ssFlds;
00122 readAndRotateFields(ssFlds, mesh, T, objects);
00123
00124 PtrList<surfaceVectorField> svFlds;
00125 readAndRotateFields(svFlds, mesh, T, objects);
00126
00127 PtrList<surfaceSphericalTensorField> sstFlds;
00128 readAndRotateFields(sstFlds, mesh, T, objects);
00129
00130 PtrList<surfaceSymmTensorField> ssymtFlds;
00131 readAndRotateFields(ssymtFlds, mesh, T, objects);
00132
00133 PtrList<surfaceTensorField> stFlds;
00134 readAndRotateFields(stFlds, mesh, T, objects);
00135
00136 mesh.write();
00137 }
00138
00139
00140
00141
00142 int main(int argc, char *argv[])
00143 {
00144 argList::validOptions.insert("translate", "vector");
00145 argList::validOptions.insert("rotate", "(vector vector)");
00146 argList::validOptions.insert("rollPitchYaw", "(roll pitch yaw)");
00147 argList::validOptions.insert("yawPitchRoll", "(yaw pitch roll)");
00148 argList::validOptions.insert("rotateFields", "");
00149 argList::validOptions.insert("scale", "vector");
00150
00151 # include "setRootCase.H"
00152 # include "createTime.H"
00153
00154 pointIOField points
00155 (
00156 IOobject
00157 (
00158 "points",
00159 runTime.findInstance(polyMesh::meshSubDir, "points"),
00160 polyMesh::meshSubDir,
00161 runTime,
00162 IOobject::MUST_READ,
00163 IOobject::NO_WRITE,
00164 false
00165 )
00166 );
00167
00168
00169 if (args.options().empty())
00170 {
00171 FatalErrorIn(args.executable())
00172 << "No options supplied, please use one or more of "
00173 "-translate, -rotate or -scale options."
00174 << exit(FatalError);
00175 }
00176
00177 if (args.optionFound("translate"))
00178 {
00179 vector transVector(args.optionLookup("translate")());
00180
00181 Info<< "Translating points by " << transVector << endl;
00182
00183 points += transVector;
00184 }
00185
00186 if (args.optionFound("rotate"))
00187 {
00188 Pair<vector> n1n2(args.optionLookup("rotate")());
00189 n1n2[0] /= mag(n1n2[0]);
00190 n1n2[1] /= mag(n1n2[1]);
00191 tensor T = rotationTensor(n1n2[0], n1n2[1]);
00192
00193 Info<< "Rotating points by " << T << endl;
00194
00195 points = transform(T, points);
00196
00197 if (args.optionFound("rotateFields"))
00198 {
00199 rotateFields(runTime, T);
00200 }
00201 }
00202 else if (args.optionFound("rollPitchYaw"))
00203 {
00204 vector v(args.optionLookup("rollPitchYaw")());
00205
00206 Info<< "Rotating points by" << nl
00207 << " roll " << v.x() << nl
00208 << " pitch " << v.y() << nl
00209 << " yaw " << v.z() << endl;
00210
00211
00212
00213 v *= pi/180.0;
00214
00215 quaternion R(v.x(), v.y(), v.z());
00216
00217 Info<< "Rotating points by quaternion " << R << endl;
00218 points = transform(R, points);
00219
00220 if (args.optionFound("rotateFields"))
00221 {
00222 rotateFields(runTime, R.R());
00223 }
00224 }
00225 else if (args.optionFound("yawPitchRoll"))
00226 {
00227 vector v(args.optionLookup("yawPitchRoll")());
00228
00229 Info<< "Rotating points by" << nl
00230 << " yaw " << v.x() << nl
00231 << " pitch " << v.y() << nl
00232 << " roll " << v.z() << endl;
00233
00234
00235
00236 v *= pi/180.0;
00237
00238 scalar yaw = v.x();
00239 scalar pitch = v.y();
00240 scalar roll = v.z();
00241
00242 quaternion R = quaternion(vector(0, 0, 1), yaw);
00243 R *= quaternion(vector(0, 1, 0), pitch);
00244 R *= quaternion(vector(1, 0, 0), roll);
00245
00246 Info<< "Rotating points by quaternion " << R << endl;
00247 points = transform(R, points);
00248
00249 if (args.optionFound("rotateFields"))
00250 {
00251 rotateFields(runTime, R.R());
00252 }
00253 }
00254
00255 if (args.optionFound("scale"))
00256 {
00257 vector scaleVector(args.optionLookup("scale")());
00258
00259 Info<< "Scaling points by " << scaleVector << endl;
00260
00261 points.replace(vector::X, scaleVector.x()*points.component(vector::X));
00262 points.replace(vector::Y, scaleVector.y()*points.component(vector::Y));
00263 points.replace(vector::Z, scaleVector.z()*points.component(vector::Z));
00264 }
00265
00266
00267 IOstream::defaultPrecision(10);
00268
00269 Info << "Writing points into directory " << points.path() << nl << endl;
00270 points.write();
00271
00272 return 0;
00273 }
00274
00275
00276