deformDynMesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v4
5 
6 Description
7  Deform the mesh for field inversion
8 
9 \*---------------------------------------------------------------------------*/
10 
11 #include "fvCFD.H"
12 #include "argList.H"
13 #include "Time.H"
14 #include "fvMesh.H"
15 #include "OFstream.H"
16 
17 using namespace Foam;
18 
19 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
20 
21 int main(int argc, char* argv[])
22 {
23 
24  Info << "Deform the mesh for field inversion...." << endl;
25 
26  argList::addOption(
27  "origin",
28  "(0 0 0)",
29  "prescribe the origin to deform the mesh");
30 
31  argList::addOption(
32  "axis",
33  "(0 0 0)",
34  "prescribe the axis to deform the mesh");
35 
36  argList::addOption(
37  "omega",
38  "0",
39  "prescribe the angular velocity to deform the mesh");
40 
41  argList::addOption(
42  "time",
43  "-1",
44  "prescribe a specific time to deform the mesh");
45 
46 #include "setRootCase.H"
47 #include "createTime.H"
48 #include "createMesh.H"
49 
50  vector origin = {0.0, 0.0, 0.0};
51  if (args.readIfPresent("origin", origin))
52  {
53  Info << "The origin to rotate the mesh: " << origin << endl;
54  }
55  else
56  {
57  Info << "origin not set!" << endl;
58  }
59 
60  vector axis = {0, 0, 0};
61  if (args.readIfPresent("axis", axis))
62  {
63  Info << "The axis to rotate the mesh: " << axis << endl;
64  }
65  else
66  {
67  Info << "axis center not set!" << endl;
68  }
69 
70  scalar omega = 0.0;
71  if (args.readIfPresent("omega", omega))
72  {
73  Info << "The angular velocity to rotate the mesh: " << omega << endl;
74  }
75  else
76  {
77  Info << "omega not set! Don't rotate mesh." << endl;
78  }
79 
80  scalar time = -1.0;
81  if (args.optionFound("time"))
82  {
83  time = readScalar(args.optionLookup("time")());
84  if (time == 9999)
85  {
86  Info << "Deform latestTime" << endl;
87  }
88  else
89  {
90  Info << "Deform time = " << time << endl;
91  }
92  }
93  else
94  {
95  Info << "Time not set! Deform all time instances." << endl;
96  }
97 
98  Info << "Deforming the mesh..." << endl;
99 
100  while (runTime.run())
101  {
102  ++runTime;
103 
104  Info << "Time = " << runTime.timeName() << nl << endl;
105 
106  pointField ourNewPoints(mesh.points());
107  scalar theta = omega * runTime.deltaT().value();
108  scalar cosTheta = std::cos(theta);
109  scalar sinTheta = std::sin(theta);
110 
111  forAll(ourNewPoints, pointI)
112  {
113  scalar xTemp = ourNewPoints[pointI][0] - origin[0];
114  scalar yTemp = ourNewPoints[pointI][1] - origin[1];
115 
116  ourNewPoints[pointI][0] = cosTheta * xTemp - sinTheta * yTemp + origin[0];
117  ourNewPoints[pointI][1] = sinTheta * xTemp + cosTheta * yTemp + origin[1];
118  }
119 
120  mesh.movePoints(ourNewPoints);
121 
122  pointIOField writePoints(
123  IOobject(
124  "points",
125  runTime.timeName(),
126  "polyMesh",
127  mesh,
128  IOobject::NO_READ,
129  IOobject::AUTO_WRITE),
130  mesh.points());
131 
132  runTime.write();
133  }
134 
135  Info << "Finished!" << endl;
136 
137  return 0;
138 }
139 
140 // ************************************************************************* //
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
dafoam_plot3dtransform.axis
axis
Definition: dafoam_plot3dtransform.py:67
Foam
Definition: checkGeometry.C:32
argc
int argc
Definition: setArgs.H:18
forAll
forAll(nuTilda1, cellI)
Definition: nuTilda1EqnIrkPimple.H:19
args
Foam::argList & args
Definition: setRootCasePython.H:42
dafoam_plot3dtransform.theta
float theta
Definition: dafoam_plot3dtransform.py:74
runTime
Time & runTime
Definition: createRefsHeatTransfer.H:1
argv
char ** argv
Definition: setArgs.H:26
main
int main(int argc, char *argv[])
Definition: deformDynMesh.C:21