DAFvSource.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
5 
6 \*---------------------------------------------------------------------------*/
7 
8 #include "DAFvSource.H"
9 
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
11 
12 namespace Foam
13 {
14 
15 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16 
17 defineTypeNameAndDebug(DAFvSource, 0);
18 defineRunTimeSelectionTable(DAFvSource, dictionary);
19 
20 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
21 
22 DAFvSource::DAFvSource(
23  const word modelType,
24  const fvMesh& mesh,
25  const DAOption& daOption,
26  const DAModel& daModel,
27  const DAIndex& daIndex)
28  : regIOobject(
29  IOobject(
30  "DAFvSource", // always use DAFvSource for the db name
31  mesh.time().timeName(),
32  mesh, // register to mesh
33  IOobject::NO_READ,
34  IOobject::NO_WRITE,
35  true // always register object
36  )),
37  modelType_(modelType),
38  mesh_(mesh),
39  daOption_(daOption),
40  daModel_(daModel),
41  daIndex_(daIndex)
42 {
43 }
44 
45 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
46 
47 autoPtr<DAFvSource> DAFvSource::New(
48  const word modelType,
49  const fvMesh& mesh,
50  const DAOption& daOption,
51  const DAModel& daModel,
52  const DAIndex& daIndex)
53 {
54  // standard setup for runtime selectable classes
55 
56  if (daOption.getAllOptions().lookupOrDefault<label>("debug", 0))
57  {
58  Info << "Selecting " << modelType << " for DAFvSource" << endl;
59  }
60 
61  dictionaryConstructorTable::iterator cstrIter =
62  dictionaryConstructorTablePtr_->find(modelType);
63 
64  // if the solver name is not found in any child class, print an error
65  if (cstrIter == dictionaryConstructorTablePtr_->end())
66  {
67  FatalErrorIn(
68  "DAFvSource::New"
69  "("
70  " const word,"
71  " const fvMesh&,"
72  " const DAOption&,"
73  " const DAModel&,"
74  " const DAIndex&"
75  ")")
76  << "Unknown DAFvSource type "
77  << modelType << nl << nl
78  << "Valid DAFvSource types:" << endl
79  << dictionaryConstructorTablePtr_->sortedToc()
80  << exit(FatalError);
81  }
82 
83  // child class found
84  return autoPtr<DAFvSource>(
85  cstrIter()(modelType, mesh, daOption, daModel, daIndex));
86 }
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
90 void DAFvSource::calcFvSource(volVectorField& fvSource)
91 {
92  /*
93  Description:
94  Calculate the fvSource term
95  NOTE: this need to be implemented in the child class, if not,
96  print an error!
97  */
98  FatalErrorIn("") << "calcFvSource not implemented " << endl
99  << " in the child class for " << modelType_
100  << abort(FatalError);
101 }
102 
103 bool DAFvSource::writeData(Ostream& os) const
104 {
105  /*
106  Description:
107  This is a virtual function for regIOobject
108  */
109  // do nothing
110  return true;
111 }
112 
114 {
115  /*
116  Description:
117  Synchronize the values in DAOption and actuatorDiskDVs_.
118  We need to synchronize the values defined in fvSource from DAOption to actuatorDiskDVs_
119  NOTE: we need to call this function whenever we change the actuator design variables
120  during optimization. This is needed because we need to use actuatorDiskDVs_ in AD
121  */
122 
123  // now we need to initialize actuatorDiskDVs_
124  dictionary fvSourceSubDict = daOption_.getAllOptions().subDict("fvSource");
125  word diskName0 = fvSourceSubDict.toc()[0];
126 
127  word type0 = fvSourceSubDict.subDict(diskName0).getWord("type");
128 
129  if (type0 == "actuatorDisk")
130  {
131  word source0 = fvSourceSubDict.subDict(diskName0).getWord("source");
132 
133  if (source0 == "cylinderAnnulusSmooth")
134  {
135  forAll(fvSourceSubDict.toc(), idxI)
136  {
137  word diskName = fvSourceSubDict.toc()[idxI];
138 
139  // sub dictionary with all parameters for this disk
140  dictionary diskSubDict = fvSourceSubDict.subDict(diskName);
141 
142  // now read in all parameters for this actuator disk
143  scalarList centerList;
144  diskSubDict.readEntry<scalarList>("center", centerList);
145 
146  // we have 9 design variables for each disk
147  scalarList dvList(10);
148  dvList[0] = centerList[0];
149  dvList[1] = centerList[1];
150  dvList[2] = centerList[2];
151  dvList[3] = diskSubDict.getScalar("innerRadius");
152  dvList[4] = diskSubDict.getScalar("outerRadius");
153  dvList[5] = diskSubDict.getScalar("scale");
154  dvList[6] = diskSubDict.getScalar("POD");
155  dvList[7] = diskSubDict.getScalar("expM");
156  dvList[8] = diskSubDict.getScalar("expN");
157  dvList[9] = diskSubDict.getScalar("targetThrust");
158 
159  // set actuatorDiskDVs_
160  actuatorDiskDVs_.set(diskName, dvList);
161  }
162  }
163  }
164 }
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 
167 } // End namespace Foam
168 
169 // ************************************************************************* //
Foam::DAFvSource::writeData
bool writeData(Ostream &os) const
virtual function for regIOobject
Definition: DAFvSource.C:103
Foam::DAFvSource::actuatorDiskDVs_
HashTable< List< scalar > > actuatorDiskDVs_
the list of design variables for all the actuator disks
Definition: DAFvSource.H:62
Foam::DAFvSource::syncDAOptionToActuatorDVs
void syncDAOptionToActuatorDVs()
synchronize the values in DAOption and actuatorDiskDVs_
Definition: DAFvSource.C:113
forAll
forAll(pseudoP.boundaryField(), patchI)
Definition: solvePseudoPEqn.H:10
Foam::DAFvSource::daOption_
const DAOption & daOption_
DAOption object.
Definition: DAFvSource.H:53
Foam::DAOption
Definition: DAOption.H:29
daOption
DAOption daOption(mesh, pyOptions_)
Foam::DAFvSource::calcFvSource
virtual void calcFvSource(volVectorField &fvSource)
compute the FvSource term
Definition: DAFvSource.C:90
DAFvSource.H
fvSource
volScalarField & fvSource
Definition: createRefsHeatTransfer.H:7
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::defineRunTimeSelectionTable
defineRunTimeSelectionTable(DAFvSource, dictionary)
Foam::DAIndex
Definition: DAIndex.H:32
Foam::DAFvSource::New
static autoPtr< DAFvSource > New(const word modelType, const fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex)
Definition: DAFvSource.C:47
Foam::DAModel
Definition: DAModel.H:59
Foam
Definition: multiFreqScalarFvPatchField.C:144
Foam::DAFvSource::modelType_
const word & modelType_
model name
Definition: DAFvSource.H:47
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFvSource, 0)
daModel
DAModel daModel(mesh, daOption)
daIndex
DAIndex daIndex(mesh, daOption, daModel)