DAInputFvSourcePar.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v4
5 
6 \*---------------------------------------------------------------------------*/
7 
8 #include "DAInputFvSourcePar.H"
9 
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
11 
12 namespace Foam
13 {
14 
15 defineTypeNameAndDebug(DAInputFvSourcePar, 0);
16 addToRunTimeSelectionTable(DAInput, DAInputFvSourcePar, 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  fvSourceName_ = daOption_.getAllOptions().subDict("inputInfo").subDict(inputName_).getWord("fvSourceName");
35  fvSourceType_ = daOption_.getAllOptions().subDict("fvSource").subDict(fvSourceName_).getWord("type");
36 
37  // if users set the indices, read it from inputInto, otherwise, use all indices
38  if (daOption_.getAllOptions().subDict("inputInfo").subDict(inputName_).found("indices"))
39  {
40  daOption_.getAllOptions().subDict("inputInfo").subDict(inputName_).readEntry<labelList>("indices", indices_);
41  }
42  else
43  {
44  label size = 0;
45  if (fvSourceType_ == "actuatorDisk")
46  {
47  size = 13;
48  }
49  else if (fvSourceType_ == "actuatorLine")
50  {
51  size = 18;
52  }
53  else if (fvSourceType_ == "actuatorPoint")
54  {
55  size = 13;
56  }
57  else if (fvSourceType_ == "heatSource")
58  {
59  size = 9;
60  }
61  else
62  {
63  FatalErrorIn("DAInputFvSourcePar") << "fvSourceType not supported "
64  << abort(FatalError);
65  }
66 
67  indices_.setSize(size);
68  forAll(indices_, idxI)
69  {
70  indices_[idxI] = idxI;
71  }
72  }
73 }
74 
75 void DAInputFvSourcePar::run(const scalarList& input)
76 {
77  /*
78  Description:
79  Assign the input to OF fields
80  */
81 
82 #ifndef CODI_ADR
83  Info << "DAInputFvSourcePar. " << endl;
84  Info << "Setting fvSource indices " << indices_ << " with " << input << endl;
85 #endif
86 
87  DAGlobalVar& globalVar =
88  const_cast<DAGlobalVar&>(mesh_.thisDb().lookupObject<DAGlobalVar>("DAGlobalVar"));
89 
90  DAFvSource& daFvSource =
91  const_cast<DAFvSource&>(mesh_.thisDb().lookupObject<DAFvSource>("DAFvSource"));
92 
93  if (fvSourceType_ == "actuatorDisk")
94  {
95 
96  forAll(indices_, idxI)
97  {
98  label selectedIndex = indices_[idxI];
99  globalVar.actuatorDiskPars[fvSourceName_][selectedIndex] = input[idxI];
100  }
101  }
102  else if (fvSourceType_ == "actuatorLine")
103  {
104  forAll(indices_, idxI)
105  {
106  label selectedIndex = indices_[idxI];
107  globalVar.actuatorLinePars[fvSourceName_][selectedIndex] = input[idxI];
108  }
109  }
110  else if (fvSourceType_ == "actuatorPoint")
111  {
112  forAll(indices_, idxI)
113  {
114  label selectedIndex = indices_[idxI];
115  globalVar.actuatorPointPars[fvSourceName_][selectedIndex] = input[idxI];
116  }
117  }
118  else if (fvSourceType_ == "heatSource")
119  {
120  forAll(indices_, idxI)
121  {
122  label selectedIndex = indices_[idxI];
123  globalVar.heatSourcePars[fvSourceName_][selectedIndex] = input[idxI];
124  }
125  }
126  else
127  {
128  FatalErrorIn("DAInputFvSourcePar") << "fvSourceType not supported "
129  << abort(FatalError);
130  }
131 
132  daFvSource.updateFvSource();
133 }
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 } // End namespace Foam
138 
139 // ************************************************************************* //
Foam::DAFvSource
Definition: DAFvSource.H:34
Foam::DAGlobalVar::actuatorDiskPars
HashTable< List< scalar > > actuatorDiskPars
the list of parameters for all the actuator disks
Definition: DAGlobalVar.H:65
Foam::DAInputFvSourcePar::fvSourceName_
word fvSourceName_
Definition: DAInputFvSourcePar.H:35
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::DAInputFvSourcePar::size
virtual label size()
Definition: DAInputFvSourcePar.H:59
Foam::DAInputFvSourcePar::indices_
labelList indices_
Definition: DAInputFvSourcePar.H:37
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::DAFvSource::updateFvSource
void updateFvSource()
calculate fvSource based on the latest parameters defined in DAGlobalVar
Definition: DAFvSource.C:163
Foam::DAGlobalVar::heatSourcePars
HashTable< List< scalar > > heatSourcePars
the list of parameters for all the actuator disks
Definition: DAGlobalVar.H:74
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::DAInputFvSourcePar::DAInputFvSourcePar
DAInputFvSourcePar(const word inputName, const word inputType, fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex)
Definition: DAInputFvSourcePar.C:19
Foam::DAInput
Definition: DAInput.H:30
forAll
forAll(nuTilda1, cellI)
Definition: nuTilda1EqnIrkPimple.H:19
Foam::DAInputFvSourcePar::fvSourceType_
word fvSourceType_
Definition: DAInputFvSourcePar.H:33
DAInputFvSourcePar.H
Foam::DAGlobalVar::actuatorPointPars
HashTable< List< scalar > > actuatorPointPars
the list of parameters for all the actuator points
Definition: DAGlobalVar.H:71
Foam::DAGlobalVar
Definition: DAGlobalVar.H:26
Foam::DAInputFvSourcePar::run
virtual void run(const scalarList &input)
Definition: DAInputFvSourcePar.C:75
Foam::DAInput::mesh_
fvMesh & mesh_
fvMesh
Definition: DAInput.H:48
Foam::DAGlobalVar::actuatorLinePars
HashTable< List< scalar > > actuatorLinePars
the list of parameters for all the actuator lines
Definition: DAGlobalVar.H:68