calcLiftPerS.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
5 
6  Description:
7  Calculating lift per surface area. This will be used to plot the
8  spanwise lift distribution
9 
10 \*---------------------------------------------------------------------------*/
11 
12 #include "fvCFD.H"
13 #include "argList.H"
14 #include "Time.H"
15 #include "fvMesh.H"
16 #include "OFstream.H"
17 #include "simpleControl.H"
18 #include "fvOptions.H"
19 #include "fluidThermo.H"
20 #include "turbulentFluidThermoModel.H"
21 
22 using namespace Foam;
23 
24 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
25 
26 int main(int argc, char* argv[])
27 {
28  Info << "Computing liftPerS...." << endl;
29 
30  argList::addOption(
31  "patchNames",
32  "'(inlet)'",
33  "List of patch names to compute");
34 
35  argList::addOption(
36  "liftDir",
37  "'(0 0 1)'",
38  "Lift direction");
39 
40  argList::addOption(
41  "time",
42  "1000",
43  "Tme instance to compute");
44 
45 #include "setRootCase.H"
46 #include "createTime.H"
47 
48  scalar time;
49  if (args.optionFound("time"))
50  {
51  time = readScalar(args.optionLookup("time")());
52  }
53  else
54  {
55  Info << "time not set! Exit." << endl;
56  return 1;
57  }
58  runTime.setTime(time, 0);
59 
60 #include "createMesh.H"
61 #include "createFields.H"
62 
63  List<wordRe> patchNames;
64  if (args.optionFound("patchNames"))
65  {
66  patchNames = wordReList(args.optionLookup("patchNames")());
67  }
68  else
69  {
70  Info << "patchNames not set! Exit." << endl;
71  return 1;
72  }
73 
74  List<scalar> liftDir1;
75  if (args.optionFound("liftDir"))
76  {
77  liftDir1 = scalarList(args.optionLookup("liftDir")());
78  }
79  else
80  {
81  Info << "liftDir not set! Exit." << endl;
82  return 1;
83  }
84  vector liftDir(vector::zero);
85  liftDir.x() = liftDir1[0];
86  liftDir.y() = liftDir1[1];
87  liftDir.z() = liftDir1[2];
88 
89  volScalarField liftPerS(
90  IOobject(
91  "liftPerS",
92  runTime.timeName(),
93  mesh,
94  IOobject::NO_READ,
95  IOobject::NO_WRITE),
96  mesh,
97  dimensionedScalar("liftPerS", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0),
98  fixedValueFvPatchScalarField::typeName);
99 
100  // this code is pulled from:
101  // src/functionObjects/forcces/forces.C
102  // modified slightly
103  vector forces(vector::zero);
104 
105  const surfaceVectorField::Boundary& Sfb = mesh.Sf().boundaryField();
106  const surfaceScalarField::Boundary& magSfb = mesh.magSf().boundaryField();
107 
108  tmp<volSymmTensorField> tdevRhoReff = turbulence->devRhoReff();
109  const volSymmTensorField::Boundary& devRhoReffb = tdevRhoReff().boundaryField();
110 
111  forAll(patchNames, cI)
112  {
113  // get the patch id label
114  label patchI = mesh.boundaryMesh().findPatchID(patchNames[cI]);
115  // create a shorter handle for the boundary patch
116  const fvPatch& patch = mesh.boundary()[patchI];
117  // normal force
118  vectorField fN(
119  Sfb[patchI] * p.boundaryField()[patchI]);
120  // tangential force
121  vectorField fT(Sfb[patchI] & devRhoReffb[patchI]);
122  // sum them up
123  forAll(patch, faceI)
124  {
125  forces.x() = fN[faceI].x() + fT[faceI].x();
126  forces.y() = fN[faceI].y() + fT[faceI].y();
127  forces.z() = fN[faceI].z() + fT[faceI].z();
128  scalar lift = forces & liftDir;
129  liftPerS.boundaryFieldRef()[patchI][faceI] = lift / magSfb[patchI][faceI];
130  }
131  }
132  liftPerS.write();
133 
134  Info << "Force: " << forces << endl;
135 
136  Info << "Computing liftPerS.... Completed!" << endl;
137 
138  return 0;
139 }
140 
141 // ************************************************************************* //
forAll
forAll(pseudoP.boundaryField(), patchI)
Definition: solvePseudoPEqn.H:10
turbulence
Info<< "Reading field p\n"<< endl;volScalarField p(IOobject("p", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), mesh);Info<< "Reading field U\n"<< endl;volVectorField U(IOobject("U", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), mesh);label pRefCell=0;scalar pRefValue=0.0;setRefCell(p, pimple.dict(), pRefCell, pRefValue);mesh.setFluxRequired(p.name());singlePhaseTransportModel laminarTransport(U, phi);autoPtr< incompressible::turbulenceModel > turbulence(incompressible::turbulenceModel::New(U, phi, laminarTransport))
p
volScalarField & p
Definition: createRefsPimple.H:6
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
createFields.H
Foam
Definition: multiFreqScalarFvPatchField.C:144
argc
int argc
Definition: setArgs.H:18
main
int main(int argc, char *argv[])
Definition: calcLiftPerS.C:26
args
Foam::argList & args
Definition: setRootCasePython.H:42
runTime
Time & runTime
Definition: createRefsHeatTransfer.H:1
argv
char ** argv
Definition: setArgs.H:26