DAInputPatchVar.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v4
5 
6 \*---------------------------------------------------------------------------*/
7 
8 #include "DAInputPatchVar.H"
9 
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
11 
12 namespace Foam
13 {
14 
15 defineTypeNameAndDebug(DAInputPatchVar, 0);
16 addToRunTimeSelectionTable(DAInput, DAInputPatchVar, 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  varName_ = daOption_.getAllOptions().subDict("inputInfo").subDict(inputName_).getWord("varName");
36  varType_ = daOption_.getAllOptions().subDict("inputInfo").subDict(inputName_).getWord("varType");
37 
38  if (varType_ != "scalar" && varType_ != "vector")
39  {
40  FatalErrorIn("DAInputPatchVar::size") << "varType not valid" << exit(FatalError);
41  }
42 }
43 
44 void DAInputPatchVar::run(const scalarList& input)
45 {
46  /*
47  Description:
48  Assign the input array to OF's state variables
49  */
50 
51  wordList patchNames;
52  dictionary patchVSubDict = daOption_.getAllOptions().subDict("inputInfo").subDict(inputName_);
53  patchVSubDict.readEntry<wordList>("patches", patchNames);
54 
55 #ifndef CODI_ADR
56  Info << "DAInputPatchVar. " << endl;
57  Info << "Setting " << varName_ << " = " << input << " at " << patchNames << endl;
58 #endif
59 
60  if (varType_ == "scalar")
61  {
62 
63  volScalarField& var = const_cast<volScalarField&>(mesh_.thisDb().lookupObject<volScalarField>(varName_));
64 
65  // now we assign input to the var patches
66  forAll(patchNames, idxI)
67  {
68  word patchName = patchNames[idxI];
69  label patchI = mesh_.boundaryMesh().findPatchID(patchName);
70  if (mesh_.boundaryMesh()[patchI].size() > 0)
71  {
72  if (var.boundaryField()[patchI].type() == "fixedValue")
73  {
74  forAll(var.boundaryField()[patchI], faceI)
75  {
76  var.boundaryFieldRef()[patchI][faceI] = input[0];
77  }
78  }
79  else if (var.boundaryField()[patchI].type() == "inletOutlet")
80  {
81  mixedFvPatchField<scalar>& inletOutletPatch =
82  refCast<mixedFvPatchField<scalar>>(var.boundaryFieldRef()[patchI]);
83 
84  forAll(var.boundaryField()[patchI], faceI)
85  {
86  inletOutletPatch.refValue()[faceI] = input[0];
87  }
88  }
89  else
90  {
91  FatalErrorIn("DAInputPatchVelocity::run")
92  << "patch type not valid! only support fixedValue or inletOutlet"
93  << exit(FatalError);
94  }
95  }
96  }
97  var.correctBoundaryConditions();
98  }
99  if (varType_ == "vector")
100  {
101 
102  volVectorField& var = const_cast<volVectorField&>(mesh_.thisDb().lookupObject<volVectorField>(varName_));
103 
104  // now we assign input to the var patches
105  forAll(patchNames, idxI)
106  {
107  word patchName = patchNames[idxI];
108  label patchI = mesh_.boundaryMesh().findPatchID(patchName);
109  if (mesh_.boundaryMesh()[patchI].size() > 0)
110  {
111  if (var.boundaryField()[patchI].type() == "fixedValue")
112  {
113  forAll(var.boundaryField()[patchI], faceI)
114  {
115  for (label i = 0; i < 3; i++)
116  {
117  var.boundaryFieldRef()[patchI][faceI][i] = input[i];
118  }
119  }
120  }
121  else if (var.boundaryField()[patchI].type() == "inletOutlet")
122  {
123  mixedFvPatchField<vector>& inletOutletPatch =
124  refCast<mixedFvPatchField<vector>>(var.boundaryFieldRef()[patchI]);
125 
126  forAll(var.boundaryField()[patchI], faceI)
127  {
128  for (label i = 0; i < 3; i++)
129  {
130  inletOutletPatch.refValue()[faceI][i] = input[i];
131  }
132  }
133  }
134  else
135  {
136  FatalErrorIn("DAInputPatchVelocity::run")
137  << "patch type not valid! only support fixedValue or inletOutlet"
138  << exit(FatalError);
139  }
140  }
141  }
142  var.correctBoundaryConditions();
143  }
144 }
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 } // End namespace Foam
149 
150 // ************************************************************************* //
Foam::DAInputPatchVar::DAInputPatchVar
DAInputPatchVar(const word inputName, const word inputType, fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex)
Definition: DAInputPatchVar.C:19
Foam::DAInputPatchVar::varType_
word varType_
the type of the variable can be either scalar or vector
Definition: DAInputPatchVar.H:36
Foam::DAInput::inputName_
const word inputName_
name of the input
Definition: DAInput.H:42
DAInputPatchVar.H
Foam::DAOption
Definition: DAOption.H:29
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(DAFunction, DAFunctionForce, dictionary)
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::DAInputPatchVar::varName_
word varName_
the name of the variable
Definition: DAInputPatchVar.H:33
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::DAInputPatchVar::run
virtual void run(const scalarList &input)
Definition: DAInputPatchVar.C:44
Foam::DAInput::mesh_
fvMesh & mesh_
fvMesh
Definition: DAInput.H:48