DAFunction.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v4
5 
6  Description:
7  Compute objective and constraint functions and their derivatives
8 
9 \*---------------------------------------------------------------------------*/
10 
11 #ifndef DAFunction_H
12 #define DAFunction_H
13 
14 #include "runTimeSelectionTables.H"
15 #include "fvOptions.H"
16 #include "DAOption.H"
17 #include "DAModel.H"
18 #include "DAIndex.H"
19 #include "topoSetSource.H"
20 #include "topoSet.H"
21 
22 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
23 
24 namespace Foam
25 {
26 
27 /*---------------------------------------------------------------------------*\
28  Class DAFunction Declaration
29 \*---------------------------------------------------------------------------*/
30 
32 {
33 
34 private:
36  DAFunction(const DAFunction&);
37 
39  void operator=(const DAFunction&);
40 
41 protected:
43  const fvMesh& mesh_;
44 
47 
49  const DAModel& daModel_;
50 
52  const DAIndex& daIndex_;
53 
56 
59 
61  word timeOp_;
62 
64  dictionary functionDict_;
65 
67  labelList faceSources_;
68 
70  labelList cellSources_;
71 
73  scalar scale_;
74 
76  label calcRefVar_;
77 
79  scalarList ref_;
80 
81 public:
83  TypeName("DAFunction");
84 
85  // Declare run-time constructor selection table
87  autoPtr,
88  DAFunction,
89  dictionary,
90  (
91  const fvMesh& mesh,
92  const DAOption& daOption,
93  const DAModel& daModel,
94  const DAIndex& daIndex,
95  const word functionName),
96  (
97  mesh,
98  daOption,
99  daModel,
100  daIndex,
101  functionName));
102 
103  // Constructors
104 
105  //- Construct from components
106  DAFunction(
107  const fvMesh& mesh,
108  const DAOption& daOption,
109  const DAModel& daModel,
110  const DAIndex& daIndex,
111  const word functionName);
112 
113  // Selectors
114 
115  //- Return a reference to the selected model
116  static autoPtr<DAFunction> New(
117  const fvMesh& mesh,
118  const DAOption& daOption,
119  const DAModel& daModel,
120  const DAIndex& daIndex,
121  const word functionName);
122 
123  //- Destructor
124  virtual ~DAFunction()
125  {
126  }
127 
129  void clear()
130  {
131  faceSources_.clear();
132  cellSources_.clear();
133  }
134 
136  void calcFunctionSources();
137 
139  virtual scalar calcFunction() = 0;
140 
143  {
144  return functionName_;
145  }
146 
149  {
150  return functionType_;
151  }
152 
155  {
156  return timeOp_;
157  }
158 
160  const labelList& getFaceSources() const
161  {
162  return faceSources_;
163  }
164 
166  const labelList& getCellSources() const
167  {
168  return cellSources_;
169  }
170 
172  void calcRefVar(scalar& functionValue);
173 };
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 } // End namespace Foam
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 #endif
182 
183 // ************************************************************************* //
Foam::DAFunction::faceSources_
labelList faceSources_
a sorted list of all face sources for the objective function
Definition: DAFunction.H:67
DAOption.H
Foam::DAFunction::calcFunctionSources
void calcFunctionSources()
calculate DAFunction::faceSources_ and DAFunction::cellSources_
Definition: DAFunction.C:107
DAIndex.H
Foam::DAFunction::getFaceSources
const labelList & getFaceSources() const
return DAFunction::faceSources_
Definition: DAFunction.H:160
Foam::DAOption
Definition: DAOption.H:29
Foam::DAFunction::getCellSources
const labelList & getCellSources() const
return DAFunction::cellSources_
Definition: DAFunction.H:166
Foam::DAFunction::calcRefVar_
label calcRefVar_
whether to calculate (obj-ref)^2
Definition: DAFunction.H:76
Foam::DAFunction::clear
void clear()
clear up members
Definition: DAFunction.H:129
Foam::DAFunction::calcRefVar
void calcRefVar(scalar &functionValue)
calculate (var-ref)^2
Definition: DAFunction.C:216
Foam::DAFunction::functionName_
word functionName_
the name of the objective function
Definition: DAFunction.H:55
Foam::DAFunction::~DAFunction
virtual ~DAFunction()
Definition: DAFunction.H:124
Foam::DAFunction::daIndex_
const DAIndex & daIndex_
DAIndex object.
Definition: DAFunction.H:52
Foam::DAFunction::getFunctionTimeOp
word getFunctionTimeOp()
return the time operator such as final, sum, average, variance
Definition: DAFunction.H:154
DAModel.H
Foam::DAFunction::timeOp_
word timeOp_
time operator such as final, sum, or average
Definition: DAFunction.H:61
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAFunction::TypeName
TypeName("DAFunction")
Runtime type information.
Foam::DAFunction::daModel_
const DAModel & daModel_
DAModel object.
Definition: DAFunction.H:49
Foam::DAFunction::getFunctionName
word getFunctionName()
return the name of objective function
Definition: DAFunction.H:142
Foam::DAIndex
Definition: DAIndex.H:32
Foam::DAModel
Definition: DAModel.H:57
Foam::DAFunction
Definition: DAFunction.H:31
Foam::DAFunction::calcFunction
virtual scalar calcFunction()=0
calculate the value of objective function
Foam::DAFunction::daOption_
const DAOption & daOption_
DAOption object.
Definition: DAFunction.H:46
Foam::DAFunction::getFunctionType
word getFunctionType()
return the part of objective function
Definition: DAFunction.H:148
Foam
Definition: checkGeometry.C:32
Foam::DAFunction::New
static autoPtr< DAFunction > New(const fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex, const word functionName)
Definition: DAFunction.C:54
Foam::DAFunction::functionType_
word functionType_
the type of the objective function
Definition: DAFunction.H:58
Foam::DAFunction::functionDict_
dictionary functionDict_
dictionary containing the information for the objective function
Definition: DAFunction.H:64
Foam::DAFunction::cellSources_
labelList cellSources_
a sorted list of all cell sources for the objective function
Definition: DAFunction.H:70
Foam::DAFunction::scale_
scalar scale_
scale of the objective function
Definition: DAFunction.H:73
Foam::DAFunction::ref_
scalarList ref_
if calcRefVar_ is True, set the reference value list
Definition: DAFunction.H:79
Foam::DAFunction::mesh_
const fvMesh & mesh_
fvMesh
Definition: DAFunction.H:43
Foam::DAFunction::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, DAFunction, dictionary,(const fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex, const word functionName),(mesh, daOption, daModel, daIndex, functionName))