DAStateInfoPimpleFoam.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v4
5 
6 \*---------------------------------------------------------------------------*/
7 
9 
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
11 
12 namespace Foam
13 {
14 
15 defineTypeNameAndDebug(DAStateInfoPimpleFoam, 0);
16 addToRunTimeSelectionTable(DAStateInfo, DAStateInfoPimpleFoam, dictionary);
17 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
18 
20  const word modelType,
21  const fvMesh& mesh,
22  const DAOption& daOption,
23  const DAModel& daModel)
24  : DAStateInfo(modelType, mesh, daOption, daModel)
25 {
26  /*
27  Description:
28  Register the names of state variables
29  NOTE:
30  For model variables, such as turbulence model, register specific names
31  For example, register "nut" to modelStates for RANS turbulence models,
32  Then, we will call correctModelStates(stateInfo_["modelStates"]) to modify
33  "nut" based on the selected turbulence model. For example, for SA model,
34  correctModelStates will just replace "nut" with "nuTilda", for SST model,
35  it will replace "nut" with "k" and append "omega" to modelStates.
36  In other words, the model variables will be modified based on the selected
37  models at runtime.
38  */
39 
40  stateInfo_["volScalarStates"].append("p");
41  stateInfo_["modelStates"].append("nut");
42  stateInfo_["volVectorStates"].append("U");
43  stateInfo_["surfaceScalarStates"].append("phi");
44 
45  // correct the names for model states based on the selected physical model at runtime
46  daModel.correctModelStates(stateInfo_["modelStates"]);
47 
48  /*
49  Description:
50  Adjoint state connectivity info, numbers denote the level of connectivity
51  N/A means this state does not connect to the corrsponding residual
52 
53  U T p nut phi
54  URes 2 2 1 1 0
55  TRes 2 2 2 1 0
56  pRes 3 2 2 2 1
57  phiRes 2 2 1 1 0
58 
59  ******************************** NOTE 1 **********************************
60  One does not need to specify connectivity for each physical model, set the
61  connectivity for original variables instead. For example, for turbulence models,
62  set nut. Then, how is nut connected to the other turbulence states will be
63  set in the DAModel class. This is done by calling correctStateResidualModelCon.
64  For example, for SA model we just replace nut with nuTilda, for SST model, we need
65  to add extract connectivity since nut depends on grad(U), k, and omega. We need
66  to do this for other pyhsical models such as radiation models.
67  **************************************************************************
68 
69  ******************************** NOTE 2 **********************************
70  Do not specify physical model connectivity here, because they will be added
71  by calling addModelResidualCon. For example, for the SA turbulence
72  model, it will add the nuTildaRes to stateResConInfo_ and setup
73  its connectivity automatically.
74  **************************************************************************
75 
76  */
77 
78  stateResConInfo_.set(
79  "URes",
80  {
81  {"U", "p", "nut", "phi"}, // lv0
82  {"U", "p", "nut"}, // lv1
83  {"U"} // lv2
84  });
85 
86  stateResConInfo_.set(
87  "pRes",
88  {
89  {"U", "p", "nut", "phi"}, // lv0
90  {"U", "p", "nut", "phi"}, // lv1
91  {"U", "p", "nut"}, // lv2
92  {"U"} // lv3
93  });
94 
95  stateResConInfo_.set(
96  "phiRes",
97  {
98  {"U", "p", "nut", "phi"}, // lv0
99  {"U", "p", "nut"}, // lv1
100  {"U"}, // lv2
101  });
102 
103  // need to correct connectivity for physical models for each residual
107 
108  label hasTField = DAUtility::isFieldReadable(mesh_, "T", "volScalarField");
109 
110  if (hasTField)
111  {
112  stateInfo_["volScalarStates"].append("T");
113  stateResConInfo_.set(
114  "TRes",
115  {
116  {"T", "nut", "phi"}, // lv0
117  {"T", "nut"}, // lv1
118  {"T"} // lv2
119  });
120 
122  }
123 
124  // add physical model residual connectivity
126 }
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 
129 } // End namespace Foam
130 
131 // ************************************************************************* //
Foam::DAModel::correctStateResidualModelCon
void correctStateResidualModelCon(List< List< word >> &stateCon) const
update the original variable connectivity for the adjoint state residuals in stateCon
Definition: DAModel.C:69
DAStateInfoPimpleFoam.H
Foam::DAOption
Definition: DAOption.H:29
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(DAFunction, DAFunctionForce, dictionary)
Foam::DAStateInfoPimpleFoam::DAStateInfoPimpleFoam
DAStateInfoPimpleFoam(const word modelType, const fvMesh &mesh, const DAOption &daOption, const DAModel &daModel)
Definition: DAStateInfoPimpleFoam.C:19
Foam::DAStateInfo::mesh_
const fvMesh & mesh_
fvMesh
Definition: DAStateInfo.H:42
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAModel::addModelResidualCon
void addModelResidualCon(HashTable< List< List< word >>> &allCon) const
add the model residual connectivity to stateCon
Definition: DAModel.C:121
Foam::DAModel
Definition: DAModel.H:57
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFunction, 0)
Foam
Definition: checkGeometry.C:32
Foam::DAStateInfo::stateResConInfo_
HashTable< List< List< word > > > stateResConInfo_
table to specify how the states are connected to the residuals for a given solver
Definition: DAStateInfo.H:54
Foam::DAUtility::isFieldReadable
static label isFieldReadable(const fvMesh &mesh, const word fieldName, const word fieldType)
Definition: DAUtility.C:817
Foam::DAStateInfo
Definition: DAStateInfo.H:30
Foam::DAModel::correctModelStates
void correctModelStates(wordList &modelStates) const
update the name in modelStates based on the selected physical model at runtime
Definition: DAModel.C:31
Foam::DAStateInfo::stateInfo_
HashTable< wordList > stateInfo_
registered states 1st hash: solverName, 2nd hash: fieldType, 3nd list, stateNames
Definition: DAStateInfo.H:51