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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Application
28  rotateMesh
29 
30 Group
31  grpMeshManipulationUtilities
32 
33 Description
34  Rotates the mesh and fields from the direction n1 to direction n2.
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #include "argList.H"
39 #include "timeSelector.H"
40 #include "Time.H"
41 #include "fvMesh.H"
42 #include "volFields.H"
43 #include "surfaceFields.H"
45 #include "IOobjectList.H"
46 
47 using namespace Foam;
48 
49 template<class GeometricField>
50 void RotateFields
51 (
52  const fvMesh& mesh,
53  const IOobjectList& objects,
54  const tensor& rotT
55 )
56 {
57  // Objects of field type
58  IOobjectList fields(objects.lookupClass(GeometricField::typeName));
59 
60  forAllConstIters(fields, fieldIter)
61  {
62  Info<< " Rotating " << (*fieldIter)->name() << endl;
63 
64  GeometricField fld(*fieldIter(), mesh);
66  fld.write();
67  }
68 }
69 
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 
73 int main(int argc, char *argv[])
74 {
76  (
77  "Rotate mesh points and vector/tensor fields\n"
78  "Rotation from the <from> vector to the <to> vector"
79  );
80 
82 
83  argList::addArgument("from", "The vector to rotate from");
84  argList::addArgument("to", "The vector to rotate to");
85 
86  #include "setRootCase.H"
87  #include "createTime.H"
88 
89  const vector n1(args.get<vector>(1).normalise());
90  const vector n2(args.get<vector>(2).normalise());
91 
92  const tensor rotT(rotationTensor(n1, n2));
93 
94  {
96  (
97  IOobject
98  (
99  "points",
102  runTime,
105  false
106  )
107  );
108 
109  points = transform(rotT, points);
110 
111  // Set the precision of the points data to 10
113 
114  Info<< "Writing points into directory " << points.path() << nl << endl;
115  points.write();
116  }
117 
118 
120 
121  #include "createNamedMesh.H"
122 
123  forAll(timeDirs, timeI)
124  {
125  runTime.setTime(timeDirs[timeI], timeI);
126 
127  Info<< "Time = " << runTime.timeName() << endl;
128 
129  // Search for list of objects for this time
130  IOobjectList objects(mesh, runTime.timeName());
131 
132  RotateFields<volVectorField>(mesh, objects, rotT);
133  RotateFields<volSphericalTensorField>(mesh, objects, rotT);
134  RotateFields<volSymmTensorField>(mesh, objects, rotT);
135  RotateFields<volTensorField>(mesh, objects, rotT);
136 
137  RotateFields<surfaceVectorField>(mesh, objects, rotT);
138  RotateFields<surfaceSphericalTensorField>(mesh, objects, rotT);
139  RotateFields<surfaceSymmTensorField>(mesh, objects, rotT);
140  RotateFields<surfaceTensorField>(mesh, objects, rotT);
141  }
142 
143  Info<< "End\n" << endl;
144 
145  return 0;
146 }
147 
148 
149 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Tensor< scalar >
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
transformGeometricField.H
Spatial transformation functions for GeometricField.
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:315
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:785
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:413
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
surfaceFields.H
Foam::surfaceFields.
Foam::Vector::normalise
Vector< Cmpt > & normalise()
Normalise the vector by its magnitude.
Definition: VectorI.H:123
Foam::transform
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:519
Foam::argList::get
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:257
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:302
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
argList.H
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
createNamedMesh.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::Time::findInstance
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
Definition: Time.C:802
Time.H
setRootCase.H
Foam::nl
constexpr char nl
Definition: Ostream.H:385
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:333
Foam::timeSelector::addOptions
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
Definition: timeSelector.C:108
Foam::Vector< scalar >
Foam::List< instant >
Foam::Time::setTime
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Definition: Time.C:1006
points
const pointField & points
Definition: gmvOutputHeader.H:1
timeSelector.H
createTime.H
Foam::rotationTensor
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
Definition: transform.H:51
Foam::timeSelector::select0
static instantList select0(Time &runTime, const argList &args)
Definition: timeSelector.C:241
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::IOobjectList::lookupClass
IOobjectList lookupClass(const char *clsName) const
The list of IOobjects with the given headerClassName.
Definition: IOobjectList.C:290
args
Foam::argList args(argc, argv)
Foam::dimensionedTensor
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.
Definition: dimensionedTensor.H:52
fields
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
Foam::IOobject::MUST_READ
Definition: IOobject.H:120