DAJacCon.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v4
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 "DAFunction.H"
23 #include "DAColoring.H"
24 #include "DAField.H"
25 
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
27 
28 namespace Foam
29 {
30 
31 /*---------------------------------------------------------------------------*\
32  Class DAJacCon Declaration
33 \*---------------------------------------------------------------------------*/
34 
35 class DAJacCon
36 {
37 
38 private:
40  DAJacCon(const DAJacCon&);
41 
43  void operator=(const DAJacCon&);
44 
45 protected:
47  const word modelType_;
48 
50  const fvMesh& mesh_;
51 
54 
56  const DAModel& daModel_;
57 
59  const DAIndex& daIndex_;
60 
63 
66 
68  HashTable<wordList> stateInfo_;
69 
72 
75 
78 
80  Mat jacCon_;
81 
84 
87 
89 
95 
98 
100  void calcNeiBFaceGlobalCompact(labelList& neiBFaceGlobalCompact);
101 
103  label getLocalCoupledBFaceIndex(const label localFaceI) const;
104 
106  void setupStateBoundaryCon(Mat* stateBoundaryCon);
107 
109  void setupStateBoundaryConID(Mat* stateBoundaryConID);
110 
112  void createConnectionMat(Mat* connectedStates);
113 
115  void addStateConnections(
116  Mat connections,
117  const label cellI,
118  const label connectedLevelLocal,
119  const wordList connectedStatesLocal,
120  const List<List<word>> connectedStateInterProc,
121  const label addFace);
122 
124  void setConnections(
125  Mat conMat,
126  const label idx) const;
127 
130  Mat conMat,
131  Mat connections,
132  const label idxI);
133 
135  void combineStateBndCon(
136  Mat* stateBoundaryCon,
137  Mat* stateBoundaryConTmp);
138 
140  void addConMatCell(
141  Mat conMat,
142  const label gRow,
143  const label cellI,
144  const word stateName,
145  const PetscScalar val);
146 
149  Mat conMat,
150  const label gRow,
151  const label cellI,
152  const word stateName,
153  const PetscScalar val);
154 
156  void addConMatCellFaces(
157  Mat conMat,
158  const label gRow,
159  const label cellI,
160  const word stateName,
161  const PetscScalar val);
162 
165  Mat conMat,
166  const label gRow,
167  const label cellI,
168  const labelList v,
169  const List<List<word>> connectedStates,
170  const label addFaces);
171 
174  {
175  // Need to clean up all the matrices
176  MatDestroy(&jacCon_);
177  MatDestroy(&stateBoundaryCon_);
178  MatDestroy(&stateBoundaryConID_);
179  VecDestroy(&jacConColors_);
180  stateInfo_.clear();
181  neiBFaceGlobalCompact_.clear();
182  }
183 
185  void checkSpecialBCs();
186 
189 
191  void setPIVVec(
192  Vec iSPIV,
193  const label idxI);
194 
196  label addPhi4PIV(
197  const word stateName,
198  const label idxI,
199  const label comp = -1);
200 
202  void initializePetscVecs();
203 
206  Vec preallocOnProc,
207  Vec preallocOffProc,
208  Vec preallocOnProcT,
209  Vec preallocOffProcT,
210  Mat connections,
211  const label row);
212 
215  Mat dRMat,
216  const Vec preallocOnProc,
217  const Vec preallocOffProc) const;
218 
219  void setupdRdWCon(
220  const HashTable<List<List<word>>>& stateResConInfo,
221  const label isPrealloc);
222 
223 public:
224  // Constructors
225  DAJacCon(
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  void clear();
241 
243  void setupJacConPreallocation(const dictionary& options);
244 
246  void initializeJacCon(const dictionary& options);
247 
249  void setupJacCon(const dictionary& options);
250 
252  label getNJacConColors() const
253  {
254  return nJacConColors_;
255  }
256 
258  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 };
282 
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284 
285 } // End namespace Foam
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 #endif
290 
291 // ************************************************************************* //
Foam::DAJacCon::modelType_
const word modelType_
the name of the jacCon matrix
Definition: DAJacCon.H:47
Foam::DAJacCon
Definition: DAJacCon.H:35
Foam::DAJacCon::initializeJacCon
void initializeJacCon(const dictionary &options)
initialize the state Jacobian connectivity matrix
Definition: DAJacCon.C:254
Foam::DAJacCon::daColoring_
DAColoring daColoring_
DAColoring object.
Definition: DAJacCon.H:62
DAOption.H
Foam::DAJacCon::setPIVVec
void setPIVVec(Vec iSPIV, const label idxI)
function used to add connectivity for pressureInletVelocity
Definition: DAJacCon.C:2905
Foam::DAJacCon::checkSpecialBCs
void checkSpecialBCs()
check if there is special boundary conditions that need special treatment in jacCon_
Definition: DAJacCon.C:2824
Foam::DAJacCon::calcColoredColumns
void calcColoredColumns(const label colorI, Vec coloredColumn) const
calculate the colored column vector
Definition: DAJacCon.C:2691
Foam::DAJacCon::mesh_
const fvMesh & mesh_
fvMesh
Definition: DAJacCon.H:50
DAIndex.H
Foam::DAJacCon::jacCon_
Mat jacCon_
Jacobian connectivity mat.
Definition: DAJacCon.H:80
Foam::DAJacCon::daOption_
const DAOption & daOption_
DAOption object.
Definition: DAJacCon.H:53
Foam::DAJacCon::clearDAJacConMembers
void clearDAJacConMembers()
clear members in DAJacCon
Definition: DAJacCon.H:173
Foam::DAOption
Definition: DAOption.H:29
DAFunction.H
Foam::DAJacCon::addPhi4PIV
label addPhi4PIV(const word stateName, const label idxI, const label comp=-1)
add connectivity phi for pressureInletVelocity
Definition: DAJacCon.C:2942
DAUtility.H
Foam::DAJacCon::setupStateBoundaryConID
void setupStateBoundaryConID(Mat *stateBoundaryConID)
calculate DAJacCon::stateBoundaryConID_
Definition: DAJacCon.C:1443
Foam::DAJacCon::setupJacCon
void setupJacCon(const dictionary &options)
assign 1 to all non-zero elements for the Jacobian connecitivyt matrix
Definition: DAJacCon.C:286
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:1207
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:753
Foam::DAJacCon::dRdWPreallocOff_
Vec dRdWPreallocOff_
Definition: DAJacCon.H:93
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:56
Foam::DAJacCon::initializeStateBoundaryCon
void initializeStateBoundaryCon()
initialize state boundary connection
Definition: DAJacCon.C:45
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:111
Foam::DAJacCon::calcNeiBFaceGlobalCompact
void calcNeiBFaceGlobalCompact(labelList &neiBFaceGlobalCompact)
calculate DAJacCon::neiBFaceGlobalCompact_
Definition: DAJacCon.C:686
Foam::DAJacCon::clear
void clear()
clear members in parent and child objects
Definition: DAJacCon.C:2966
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:1509
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:1568
Foam::DAIndex
Definition: DAIndex.H:32
Foam::DAJacCon::allocateJacobianConnections
void allocateJacobianConnections(Vec preallocOnProc, Vec preallocOffProc, Vec preallocOnProcT, Vec preallocOffProcT, Mat connections, const label row)
compute preallocation vectors
Definition: DAJacCon.C:2602
Foam::DAField
Definition: DAField.H:36
Foam::DAJacCon::preallocatedRdW
void preallocatedRdW(Mat dRMat, const label transposed) const
preallocate dRdW matrix using the preallocVec
Definition: DAJacCon.C:228
Foam::DAModel
Definition: DAModel.H:57
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:188
Foam::DAColoring
Definition: DAColoring.H:32
Foam
Definition: checkGeometry.C:32
Foam::DAJacCon::dRdWTPreallocOn_
Vec dRdWTPreallocOn_
Definition: DAJacCon.H:90
Foam::DAJacCon::stateBoundaryCon_
Mat stateBoundaryCon_
matrix to store boundary connectivity levels for state Jacobians
Definition: DAJacCon.H:71
Foam::DAJacCon::daField_
DAField daField_
DAField object.
Definition: DAJacCon.H:65
Foam::DAJacCon::daIndex_
const DAIndex & daIndex_
DAIndex object.
Definition: DAJacCon.H:59
Foam::DAJacCon::coloringExists
label coloringExists(const word postFix="") const
whether the coloring file exists
Definition: DAJacCon.C:1886
Foam::DAJacCon::setupStateBoundaryCon
void setupStateBoundaryCon(Mat *stateBoundaryCon)
calculate DAJacCon::stateBoundaryCon_
Definition: DAJacCon.C:800
Foam::DAJacCon::dRdWTPreallocOff_
Vec dRdWTPreallocOff_
Definition: DAJacCon.H:91
Foam::DAJacCon::dRdWPreallocOn_
Vec dRdWPreallocOn_
Definition: DAJacCon.H:92
DAStateInfo.H
Foam::DAJacCon::nJacConColors_
label nJacConColors_
number of jacCon colors
Definition: DAJacCon.H:86
Foam::DAJacCon::neiBFaceGlobalCompact_
labelList neiBFaceGlobalCompact_
neibough face global index for a given local boundary face
Definition: DAJacCon.H:77
Foam::DAJacCon::createConnectionMat
void createConnectionMat(Mat *connectedStates)
allocate connectedState matrix
Definition: DAJacCon.C:146
Foam::DAJacCon::setupJacConPreallocation
void setupJacConPreallocation(const dictionary &options)
calculate the preallocation vector for initializing the JacCon mat, if necessary
Definition: DAJacCon.C:2016
Foam::DAJacCon::setConnections
void setConnections(Mat conMat, const label idx) const
add value 1 for the colume idx to conMat
Definition: DAJacCon.C:669
Foam::DAJacCon::calcJacConColoring
void calcJacConColoring(const word postFix="")
compute graph coloring for Jacobian connectivity matrix
Definition: DAJacCon.C:1917
Foam::DAJacCon::stateBoundaryConID_
Mat stateBoundaryConID_
matrix to store boundary connectivity ID for state Jacobians
Definition: DAJacCon.H:74
Foam::DAJacCon::preallocateJacobianMatrix
void preallocateJacobianMatrix(Mat dRMat, const Vec preallocOnProc, const Vec preallocOffProc) const
compute preallocation vectors
Definition: DAJacCon.C:173
Foam::DAJacCon::jacConColors_
Vec jacConColors_
jacCon matrix colors
Definition: DAJacCon.H:83
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:1637
DAField.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:1693
Foam::DAJacCon::setupdRdWCon
void setupdRdWCon(const HashTable< List< List< word >>> &stateResConInfo, const label isPrealloc)
Definition: DAJacCon.C:2039
Foam::DAJacCon::readJacConColoring
void readJacConColoring(const word postFix="")
read colors for JacCon
Definition: DAJacCon.C:1980
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:304
Foam::DAJacCon::stateInfo_
HashTable< wordList > stateInfo_
the regState_ list from DAStateInfo object
Definition: DAJacCon.H:68
Foam::DAJacCon::initializePetscVecs
void initializePetscVecs()
initialize petsc vectors
Definition: DAJacCon.C:83