DAJacCon.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
5 
6  Description:
7  Compute Jacobian connectivity and coloring
8 
9 \*---------------------------------------------------------------------------*/
10 
11 #ifndef DAJacCon_H
12 #define DAJacCon_H
13 
14 #include "runTimeSelectionTables.H"
15 #include "fvOptions.H"
16 #include "DAUtility.H"
17 #include "DAOption.H"
18 #include "DAIndex.H"
19 #include "DAModel.H"
20 #include "DAStateInfo.H"
21 #include "syncTools.H"
22 #include "DAObjFunc.H"
23 #include "DAColoring.H"
24 
25 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
26 
27 namespace Foam
28 {
29 
30 /*---------------------------------------------------------------------------*\
31  Class DAJacCon Declaration
32 \*---------------------------------------------------------------------------*/
33 
34 class DAJacCon
35 {
36 
37 private:
39  DAJacCon(const DAJacCon&);
40 
42  void operator=(const DAJacCon&);
43 
44 protected:
46  const word modelType_;
47 
49  const fvMesh& mesh_;
50 
53 
55  const DAModel& daModel_;
56 
58  const DAIndex& daIndex_;
59 
62 
65 
67  HashTable<wordList> stateInfo_;
68 
71 
74 
77 
79  Mat jacCon_;
80 
83 
86 
89 
91  void calcNeiBFaceGlobalCompact(labelList& neiBFaceGlobalCompact);
92 
94  label getLocalCoupledBFaceIndex(const label localFaceI) const;
95 
97  void setupStateBoundaryCon(Mat* stateBoundaryCon);
98 
100  void setupStateBoundaryConID(Mat* stateBoundaryConID);
101 
103  void createConnectionMat(Mat* connectedStates);
104 
106  void addStateConnections(
107  Mat connections,
108  const label cellI,
109  const label connectedLevelLocal,
110  const wordList connectedStatesLocal,
111  const List<List<word>> connectedStateInterProc,
112  const label addFace);
113 
115  void setConnections(
116  Mat conMat,
117  const label idx) const;
118 
121  Mat conMat,
122  Mat connections,
123  const label idxI);
124 
126  void combineStateBndCon(
127  Mat* stateBoundaryCon,
128  Mat* stateBoundaryConTmp);
129 
131  void addConMatCell(
132  Mat conMat,
133  const label gRow,
134  const label cellI,
135  const word stateName,
136  const PetscScalar val);
137 
140  Mat conMat,
141  const label gRow,
142  const label cellI,
143  const word stateName,
144  const PetscScalar val);
145 
147  void addConMatCellFaces(
148  Mat conMat,
149  const label gRow,
150  const label cellI,
151  const word stateName,
152  const PetscScalar val);
153 
156  Mat conMat,
157  const label gRow,
158  const label cellI,
159  const labelList v,
160  const List<List<word>> connectedStates,
161  const label addFaces);
162 
165  {
166  // Need to clean up all the matrices
167  MatDestroy(&jacCon_);
168  MatDestroy(&stateBoundaryCon_);
169  MatDestroy(&stateBoundaryConID_);
170  VecDestroy(&jacConColors_);
171  stateInfo_.clear();
172  neiBFaceGlobalCompact_.clear();
173  }
174 
176  void checkSpecialBCs();
177 
180 
182  void setPIVVec(
183  Vec iSPIV,
184  const label idxI);
185 
187  label addPhi4PIV(
188  const word stateName,
189  const label idxI,
190  const label comp = -1);
191 
192 public:
194  TypeName("DAJacCon");
195 
196  // Declare run-time constructor selection table
198  autoPtr,
199  DAJacCon,
200  dictionary,
201  (const word modelType,
202  const fvMesh& mesh,
203  const DAOption& daOption,
204  const DAModel& daModel,
205  const DAIndex& daIndex),
206  (modelType,
207  mesh,
208  daOption,
209  daModel,
210  daIndex));
211 
212  // Constructors
213 
214  //- Construct from components
215  DAJacCon(
216  const word modelType,
217  const fvMesh& mesh,
218  const DAOption& daOption,
219  const DAModel& daModel,
220  const DAIndex& daIndex);
221 
222  // Selectors
223 
224  //- Return a reference to the selected model
225  static autoPtr<DAJacCon> New(
226  const word modelType,
227  const fvMesh& mesh,
228  const DAOption& daOption,
229  const DAModel& daModel,
230  const DAIndex& daIndex);
231 
232  //- Destructor
233  virtual ~DAJacCon()
234  {
235  }
236 
237  // Member functions
238 
240  virtual void clear() = 0;
241 
243  virtual void setupJacConPreallocation(const dictionary& options);
244 
246  virtual void initializeJacCon(const dictionary& options) = 0;
247 
249  virtual void setupJacCon(const dictionary& options) = 0;
250 
252  label getNJacConColors() const
253  {
254  return nJacConColors_;
255  }
256 
258  virtual void preallocatedRdW(
259  Mat dRMat,
260  const label transposed) const;
261 
263  void calcJacConColoring(const word postFix = "");
264 
266  void readJacConColoring(const word postFix = "");
267 
269  label coloringExists(const word postFix = "") const;
270 
272  Vec getJacConColor() const
273  {
274  return jacConColors_;
275  }
276 
278  void calcColoredColumns(
279  const label colorI,
280  Vec coloredColumn) const;
281 
283  virtual void setObjFuncVec(
284  scalarList objFuncFaceValues,
285  scalarList objFuncCellValues,
286  Vec objFuncVec) const;
287 };
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 } // End namespace Foam
292 
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 
295 #endif
296 
297 // ************************************************************************* //
Foam::DAJacCon::modelType_
const word modelType_
the name of the jacCon matrix
Definition: DAJacCon.H:46
Foam::DAJacCon
Definition: DAJacCon.H:34
Foam::DAJacCon::daColoring_
DAColoring daColoring_
DAColoring object.
Definition: DAJacCon.H:61
DAOption.H
Foam::DAJacCon::setPIVVec
void setPIVVec(Vec iSPIV, const label idxI)
function used to add connectivity for pressureInletVelocity
Definition: DAJacCon.C:2164
Foam::DAJacCon::checkSpecialBCs
void checkSpecialBCs()
check if there is special boundary conditions that need special treatment in jacCon_
Definition: DAJacCon.C:2083
Foam::DAJacCon::calcColoredColumns
void calcColoredColumns(const label colorI, Vec coloredColumn) const
calculate the colored column vector
Definition: DAJacCon.C:1950
Foam::DAJacCon::mesh_
const fvMesh & mesh_
fvMesh
Definition: DAJacCon.H:49
DAIndex.H
Foam::DAJacCon::jacCon_
Mat jacCon_
Jacobian connectivity mat.
Definition: DAJacCon.H:79
Foam::DAJacCon::clear
virtual void clear()=0
clear members in parent and child objects
Foam::DAJacCon::daOption_
const DAOption & daOption_
DAOption object.
Definition: DAJacCon.H:52
Foam::DAJacCon::clearDAJacConMembers
void clearDAJacConMembers()
clear members in DAJacCon
Definition: DAJacCon.H:164
Foam::DAOption
Definition: DAOption.H:29
Foam::DAJacCon::addPhi4PIV
label addPhi4PIV(const word stateName, const label idxI, const label comp=-1)
add connectivity phi for pressureInletVelocity
Definition: DAJacCon.C:2201
DAUtility.H
Foam::DAJacCon::setObjFuncVec
virtual void setObjFuncVec(scalarList objFuncFaceValues, scalarList objFuncCellValues, Vec objFuncVec) const
assign values for the objective function vector based on the face and cell value lists
Definition: DAJacCon.C:1932
daOption
DAOption daOption(mesh, pyOptions_)
Foam::DAJacCon::setupStateBoundaryConID
void setupStateBoundaryConID(Mat *stateBoundaryConID)
calculate DAJacCon::stateBoundaryConID_
Definition: DAJacCon.C:1327
Foam::DAJacCon::getJacConColor
Vec getJacConColor() const
return DAJacCon::jacConColors_
Definition: DAJacCon.H:272
Foam::DAJacCon::combineStateBndCon
void combineStateBndCon(Mat *stateBoundaryCon, Mat *stateBoundaryConTmp)
combine stateBoundaryCon and stateBoundaryConTmp, this is to ensure including all connected states fo...
Definition: DAJacCon.C:1091
Foam::DAJacCon::getLocalCoupledBFaceIndex
label getLocalCoupledBFaceIndex(const label localFaceI) const
given a local face index, return the local index of the coupled boundary face
Definition: DAJacCon.C:637
Foam::DAJacCon::TypeName
TypeName("DAJacCon")
Runtime type information.
DAColoring.H
Foam::DAJacCon::getNJacConColors
label getNJacConColors() const
get the number of JacCon colors
Definition: DAJacCon.H:252
Foam::DAJacCon::daModel_
const DAModel & daModel_
DAModel object.
Definition: DAJacCon.H:55
Foam::DAJacCon::initializeStateBoundaryCon
void initializeStateBoundaryCon()
initialize state boundary connection
Definition: DAJacCon.C:88
Foam::DAJacCon::setupJacobianConnections
void setupJacobianConnections(Mat conMat, Mat connections, const label idxI)
assign values in connections to a specific row idxI in conMat
Definition: DAJacCon.C:126
Foam::DAJacCon::calcNeiBFaceGlobalCompact
void calcNeiBFaceGlobalCompact(labelList &neiBFaceGlobalCompact)
calculate DAJacCon::neiBFaceGlobalCompact_
Definition: DAJacCon.C:570
DAModel.H
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAJacCon::addConMatCell
void addConMatCell(Mat conMat, const label gRow, const label cellI, const word stateName, const PetscScalar val)
add val to the gRow row in conMat, the column indice are the state (given by stateName) for a given c...
Definition: DAJacCon.C:1393
Foam::DAJacCon::addConMatNeighbourCells
void addConMatNeighbourCells(Mat conMat, const label gRow, const label cellI, const word stateName, const PetscScalar val)
add val to gRow row in conMat, column indice are the neighbouring states (given by stateName) for a g...
Definition: DAJacCon.C:1452
Foam::DAIndex
Definition: DAIndex.H:32
Foam::DAJacCon::setupJacCon
virtual void setupJacCon(const dictionary &options)=0
assign 1 to all non-zero elements for the Jacobian connecitivyt matrix
Foam::DAField
Definition: DAField.H:36
Foam::DAJacCon::preallocatedRdW
virtual void preallocatedRdW(Mat dRMat, const label transposed) const
preallocate dRdW matrix using the preallocVec
Definition: DAJacCon.C:1915
Foam::DAModel
Definition: DAModel.H:59
Foam::DAJacCon::isPIVBCState_
Vec isPIVBCState_
a vector to show whether a state is connected to a pressureInletVelocity boundary face (3 level max)
Definition: DAJacCon.H:179
Foam::DAColoring
Definition: DAColoring.H:32
Foam
Definition: multiFreqScalarFvPatchField.C:144
Foam::DAJacCon::initializeJacCon
virtual void initializeJacCon(const dictionary &options)=0
initialize the state Jacobian connectivity matrix
Foam::DAJacCon::stateBoundaryCon_
Mat stateBoundaryCon_
matrix to store boundary connectivity levels for state Jacobians
Definition: DAJacCon.H:70
Foam::DAJacCon::daField_
DAField daField_
DAField object.
Definition: DAJacCon.H:64
Foam::DAJacCon::daIndex_
const DAIndex & daIndex_
DAIndex object.
Definition: DAJacCon.H:58
Foam::DAJacCon::coloringExists
label coloringExists(const word postFix="") const
whether the coloring file exists
Definition: DAJacCon.C:1770
Foam::DAJacCon::setupStateBoundaryCon
void setupStateBoundaryCon(Mat *stateBoundaryCon)
calculate DAJacCon::stateBoundaryCon_
Definition: DAJacCon.C:684
DAStateInfo.H
Foam::DAJacCon::nJacConColors_
label nJacConColors_
number of jacCon colors
Definition: DAJacCon.H:85
Foam::DAJacCon::neiBFaceGlobalCompact_
labelList neiBFaceGlobalCompact_
neibough face global index for a given local boundary face
Definition: DAJacCon.H:76
daModel
DAModel daModel(mesh, daOption)
Foam::DAJacCon::createConnectionMat
void createConnectionMat(Mat *connectedStates)
allocate connectedState matrix
Definition: DAJacCon.C:161
Foam::DAJacCon::setupJacConPreallocation
virtual void setupJacConPreallocation(const dictionary &options)
calculate the preallocation vector for initializing the JacCon mat, if necessary
Definition: DAJacCon.C:1900
Foam::DAJacCon::setConnections
void setConnections(Mat conMat, const label idx) const
add value 1 for the colume idx to conMat
Definition: DAJacCon.C:553
Foam::DAJacCon::calcJacConColoring
void calcJacConColoring(const word postFix="")
compute graph coloring for Jacobian connectivity matrix
Definition: DAJacCon.C:1801
Foam::DAJacCon::stateBoundaryConID_
Mat stateBoundaryConID_
matrix to store boundary connectivity ID for state Jacobians
Definition: DAJacCon.H:73
daIndex
DAIndex daIndex(mesh, daOption, daModel)
Foam::DAJacCon::jacConColors_
Vec jacConColors_
jacCon matrix colors
Definition: DAJacCon.H:82
Foam::DAJacCon::addConMatCellFaces
void addConMatCellFaces(Mat conMat, const label gRow, const label cellI, const word stateName, const PetscScalar val)
add val to gRow row in conMat, column indice are the faces (given by stateName) for a given cellI
Definition: DAJacCon.C:1521
DAObjFunc.H
Foam::DAJacCon::addBoundaryFaceConnections
void addBoundaryFaceConnections(Mat conMat, const label gRow, const label cellI, const labelList v, const List< List< word >> connectedStates, const label addFaces)
add the column index of the (iner-proc) connected states and faces to conMat, given a local face inde...
Definition: DAJacCon.C:1577
Foam::DAJacCon::readJacConColoring
void readJacConColoring(const word postFix="")
read colors for JacCon
Definition: DAJacCon.C:1864
Foam::DAJacCon::~DAJacCon
virtual ~DAJacCon()
Definition: DAJacCon.H:233
Foam::DAJacCon::addStateConnections
void addStateConnections(Mat connections, const label cellI, const label connectedLevelLocal, const wordList connectedStatesLocal, const List< List< word >> connectedStateInterProc, const label addFace)
a high-level function to add connected state column indices to the connectivity matrix
Definition: DAJacCon.C:188
Foam::DAJacCon::stateInfo_
HashTable< wordList > stateInfo_
the regState_ list from DAStateInfo object
Definition: DAJacCon.H:67
Foam::DAJacCon::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, DAJacCon, dictionary,(const word modelType, const fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex),(modelType, mesh, daOption, daModel, daIndex))
Foam::DAJacCon::New
static autoPtr< DAJacCon > New(const word modelType, const fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex)
Definition: DAJacCon.C:47