DAInputPatchVelocity.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v4
5 
6 \*---------------------------------------------------------------------------*/
7 
8 #include "DAInputPatchVelocity.H"
9 
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
11 
12 namespace Foam
13 {
14 
15 defineTypeNameAndDebug(DAInputPatchVelocity, 0);
16 addToRunTimeSelectionTable(DAInput, DAInputPatchVelocity, dictionary);
17 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
18 
20  const word inputName,
21  const word inputType,
22  fvMesh& mesh,
23  const DAOption& daOption,
24  const DAModel& daModel,
25  const DAIndex& daIndex)
26  : DAInput(
27  inputName,
28  inputType,
29  mesh,
30  daOption,
31  daModel,
32  daIndex)
33 {
34 }
35 
36 void DAInputPatchVelocity::run(const scalarList& input)
37 {
38  /*
39  Description:
40  Assign the input array to OF's state variables
41  */
42 
43  // NOTE: we need to first update DAGlobalVar::patchVelocity here, so that daFunction-force
44  // can use it to compute the force direction.
45  DAGlobalVar& globalVar =
46  const_cast<DAGlobalVar&>(mesh_.thisDb().lookupObject<DAGlobalVar>("DAGlobalVar"));
47  globalVar.patchVelocity[0] = input[0];
48  globalVar.patchVelocity[1] = input[1];
49 
50  wordList patchNames;
51  dictionary patchVSubDict = daOption_.getAllOptions().subDict("inputInfo").subDict(inputName_);
52  patchVSubDict.readEntry<wordList>("patches", patchNames);
53 
54 #ifndef CODI_ADR
55  Info << "DAInputPatchVelocity. " << endl;
56  Info << "Setting UMag = " << input[0] << " AoA = " << input[1] << " degs at " << patchNames << endl;
57 #endif
58 
59  // the streamwise axis of aoa, aoa = tan( U_normal/U_flow )
60  word flowAxis = patchVSubDict.getWord("flowAxis");
61  word normalAxis = patchVSubDict.getWord("normalAxis");
62  scalar UMag = input[0];
63 
64  HashTable<label> axisIndices;
65  axisIndices.set("x", 0);
66  axisIndices.set("y", 1);
67  axisIndices.set("z", 2);
68  label flowAxisIndex = axisIndices[flowAxis];
69  label normalAxisIndex = axisIndices[normalAxis];
70 
71  volVectorField& U = const_cast<volVectorField&>(mesh_.thisDb().lookupObject<volVectorField>("U"));
72 
73  scalar aoaRad = input[1] * constant::mathematical::pi / 180.0;
74  scalar UxNew = UMag * cos(aoaRad);
75  scalar UyNew = UMag * sin(aoaRad);
76 
77  // now we assign UxNew and UyNew to the U patches
78  forAll(patchNames, idxI)
79  {
80  word patchName = patchNames[idxI];
81  label patchI = mesh_.boundaryMesh().findPatchID(patchName);
82  if (mesh_.boundaryMesh()[patchI].size() > 0)
83  {
84  if (U.boundaryField()[patchI].type() == "fixedValue")
85  {
86  forAll(U.boundaryField()[patchI], faceI)
87  {
88  U.boundaryFieldRef()[patchI][faceI][flowAxisIndex] = UxNew;
89  U.boundaryFieldRef()[patchI][faceI][normalAxisIndex] = UyNew;
90  }
91  }
92  else if (U.boundaryField()[patchI].type() == "inletOutlet")
93  {
94  mixedFvPatchField<vector>& inletOutletPatch =
95  refCast<mixedFvPatchField<vector>>(U.boundaryFieldRef()[patchI]);
96 
97  forAll(U.boundaryField()[patchI], faceI)
98  {
99  inletOutletPatch.refValue()[faceI][flowAxisIndex] = UxNew;
100  inletOutletPatch.refValue()[faceI][normalAxisIndex] = UyNew;
101  }
102  }
103  else
104  {
105  FatalErrorIn("DAInputPatchVelocity::run")
106  << "patch type not valid! only support fixedValue or inletOutlet"
107  << exit(FatalError);
108  }
109  }
110  }
111  U.correctBoundaryConditions();
112 }
113 
114 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
115 
116 } // End namespace Foam
117 
118 // ************************************************************************* //
U
volVectorField & U
Definition: createRefsPimpleDyM.H:7
Foam::DAInput::inputName_
const word inputName_
name of the input
Definition: DAInput.H:42
Foam::DAOption
Definition: DAOption.H:29
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(DAFunction, DAFunctionForce, dictionary)
Foam::DAGlobalVar::patchVelocity
scalarList patchVelocity
patch velocity list [UMag, AOA] AoA is in degrees
Definition: DAGlobalVar.H:59
DAInputPatchVelocity.H
Foam::DAInputPatchVelocity::DAInputPatchVelocity
DAInputPatchVelocity(const word inputName, const word inputType, fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex)
Definition: DAInputPatchVelocity.C:19
Foam::DAOption::getAllOptions
const dictionary & getAllOptions() const
return a reference of allOptions_ dictionary
Definition: DAOption.H:56
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAIndex
Definition: DAIndex.H:32
Foam::DAInput::daOption_
const DAOption & daOption_
DAOption object.
Definition: DAInput.H:51
Foam::DAModel
Definition: DAModel.H:57
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFunction, 0)
Foam
Definition: checkGeometry.C:32
Foam::DAInput
Definition: DAInput.H:30
forAll
forAll(nuTilda1, cellI)
Definition: nuTilda1EqnIrkPimple.H:19
Foam::DAInputPatchVelocity::run
virtual void run(const scalarList &input)
Definition: DAInputPatchVelocity.C:36
Foam::DAGlobalVar
Definition: DAGlobalVar.H:26
Foam::DAInput::mesh_
fvMesh & mesh_
fvMesh
Definition: DAInput.H:48