DASolver.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
5 
6  Description:
7  Solver class that calls primal and adjoint solvers,
8  and compute the total derivatives
9 
10 \*---------------------------------------------------------------------------*/
11 
12 #ifndef DASolver_H
13 #define DASolver_H
14 
15 #include <petscksp.h>
16 #include "Python.h"
17 #include "fvCFD.H"
18 #include "fvMesh.H"
19 #include "runTimeSelectionTables.H"
20 #include "OFstream.H"
21 #include "functionObjectList.H"
22 #include "fvOptions.H"
23 #include "DAUtility.H"
24 #include "DACheckMesh.H"
25 #include "DAOption.H"
26 #include "DAStateInfo.H"
27 #include "DAModel.H"
28 #include "DAIndex.H"
29 #include "DAObjFunc.H"
30 #include "DAJacCon.H"
31 #include "DAColoring.H"
32 #include "DAResidual.H"
33 #include "DAField.H"
34 #include "DAPartDeriv.H"
35 #include "DALinearEqn.H"
36 #include "volPointInterpolation.H"
37 #include "IOMRFZoneListDF.H"
38 #include "interpolateSplineXY.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 /*---------------------------------------------------------------------------*\
46  Class DASolver Declaration
47 \*---------------------------------------------------------------------------*/
48 
49 class DASolver
50 {
51 
52 private:
54  DASolver(const DASolver&);
55 
57  void operator=(const DASolver&);
58 
59 protected:
61  char* argsAll_;
62 
64  PyObject* pyOptions_;
65 
67  autoPtr<argList> argsPtr_;
68 
70  autoPtr<Time> runTimePtr_;
71 
73  autoPtr<fvMesh> meshPtr_;
74 
76  autoPtr<DAOption> daOptionPtr_;
77 
79  autoPtr<DAModel> daModelPtr_;
80 
82  autoPtr<DAIndex> daIndexPtr_;
83 
85  autoPtr<DAField> daFieldPtr_;
86 
88  UPtrList<DAObjFunc> daObjFuncPtrList_;
89 
91  autoPtr<DACheckMesh> daCheckMeshPtr_;
92 
94  autoPtr<DALinearEqn> daLinearEqnPtr_;
95 
97  autoPtr<DAResidual> daResidualPtr_;
98 
100  autoPtr<DAStateInfo> daStateInfoPtr_;
101 
103  HashTable<wordList> stateInfo_;
104 
107 
109  dictionary psiVecDict_;
110 
112  dictionary totalDerivDict_;
113 
115  autoPtr<OFstream> objFuncAvgHistFilePtr_;
116 
118  label nItersObjFuncAvg_ = -9999;
119 
121  scalarList avgObjFuncValues_;
122 
124  Mat dRdWTPC_;
125 
128 
131 
134 
136  HashTable<PetscScalar> forwardADDerivVal_;
137 
139  scalar primalMinRes_ = 1e10;
140 
142  scalar prevPrimalSolTime_ = -1e10;
143 
145  template<class classType>
147  const SolverPerformance<classType>& solverP,
148  const label printToScreen,
149  const label printInterval,
150  const word varName);
151 
152  label isPrintTime(
153  const Time& runTime,
154  const label printInterval) const;
155 
157  label checkResidualTol();
158 
161  const dictionary& maxResConLv4JacPCMat,
162  HashTable<List<List<word>>>& stateResConInfo) const;
163 
165  void writeAssociatedFields();
166 
168  Mat dRdWTMF_;
169 
172 
174  List<List<scalar>> stateAllInstances_;
175 
177  List<List<scalar>> stateBoundaryAllInstances_;
178 
180  List<dictionary> objFuncsAllInstances_;
181 
183  List<scalar> runTimeAllInstances_;
184 
187 
189  label nTimeInstances_ = -9999;
190 
192  scalar periodicity_ = 0.0;
193 
195  scalar primalMinResTol_ = 0.0;
196 
198  label primalMinIters_ = -1;
199 
201  void saveTimeInstanceFieldHybrid(label& timeInstanceI);
202 
204  void saveTimeInstanceFieldTimeAccurate(label& timeInstanceI);
205 
206 public:
208  TypeName("DASolver");
209 
210  // Declare run-time constructor selection table
212  autoPtr,
213  DASolver,
214  dictionary,
215  (
216  char* argsAll,
217  PyObject* pyOptions),
218  (argsAll, pyOptions));
219 
220  // Constructors
221 
222  //- Construct from components
223  DASolver(
224  char* argsAll,
225  PyObject* pyOptions);
226 
227  // Selectors
228 
229  //- Return a reference to the selected model
230  static autoPtr<DASolver> New(
231  char* argsAll,
232  PyObject* pyOptions);
233 
234  //- Destructor
235  virtual ~DASolver()
236  {
237  }
238 
239  // Member functions
240 
242  virtual void initSolver() = 0;
243 
245  virtual label solvePrimal(
246  const Vec xvVec,
247  Vec wVec) = 0;
248 
250  virtual label runFPAdj(
251  const Vec xvVec,
252  const Vec wVec,
253  Vec dFdW,
254  Vec psi);
255 
257  void setTimeInstanceField(const label instanceI);
258 
260  scalar getTimeInstanceObjFunc(
261  const label instanceI,
262  const word objFuncName);
263 
265  void setTimeInstanceVar(
266  const word mode,
267  Mat stateMat,
268  Mat stateBCMat,
269  Vec timeVec,
270  Vec timeIdxVec);
271 
273  void initOldTimes();
274 
276  void calcdRdWT(
277  const Vec xvVec,
278  const Vec wVec,
279  const label isPC,
280  Mat dRdWT);
281 
283  void calcdRdWTPsiAD(
284  const Vec xvVec,
285  const Vec wVec,
286  const Vec psi,
287  Vec dRdWTPsi);
288 
290  void calcdRdWTPsiAD(
291  const label isInit,
292  const Vec psi,
293  Vec dRdWTPsi);
294 
296  void calcdFdW(
297  const Vec xvVec,
298  const Vec wVec,
299  const word objFuncName,
300  Vec dFdW);
301 
303  void createMLRKSP(
304  const Mat jacMat,
305  const Mat jacPCMat,
306  KSP ksp);
307 
309  label solveLinearEqn(
310  const KSP ksp,
311  const Vec rhsVec,
312  Vec solVec);
313 
316  const Vec mpiVec,
317  Vec seqVec);
318 
320  void updateOFField(const Vec wVec);
321 
323  void updateOFMesh(const Vec xvVec);
324 
326  void updateOFField(const scalar* volCoords);
327 
329  void updateOFMesh(const scalar* states);
330 
332  void resetOFSeeds();
333 
335  void calcdRdBC(
336  const Vec xvVec,
337  const Vec wVec,
338  const word designVarName,
339  Mat dRdBC);
340 
342  void calcdFdBC(
343  const Vec xvVec,
344  const Vec wVec,
345  const word objFuncName,
346  const word designVarName,
347  Vec dFdBC);
348 
350  void calcdRdBCTPsiAD(
351  const Vec xvVec,
352  const Vec wVec,
353  const Vec psi,
354  const word designVarName,
355  Vec dRdBCTPsi);
356 
358  void calcdFdBCAD(
359  const Vec xvVec,
360  const Vec wVec,
361  const word objFuncName,
362  const word designVarName,
363  Vec dFdBC);
364 
366  void calcdRdAOA(
367  const Vec xvVec,
368  const Vec wVec,
369  const word designVarName,
370  Mat dRdAOA);
371 
373  void calcdFdAOA(
374  const Vec xvVec,
375  const Vec wVec,
376  const word objFuncName,
377  const word designVarName,
378  Vec dFdAOA);
379 
381  void calcdRdAOATPsiAD(
382  const Vec xvVec,
383  const Vec wVec,
384  const Vec psi,
385  const word designVarName,
386  Vec dRdAOATPsi);
387 
389  void calcdRdFFD(
390  const Vec xvVec,
391  const Vec wVec,
392  const word designVarName,
393  Mat dRdFFD);
394 
396  void calcdFdFFD(
397  const Vec xvVec,
398  const Vec wVec,
399  const word objFuncName,
400  const word designVarName,
401  Vec dFdFFD);
402 
404  void calcdRdACT(
405  const Vec xvVec,
406  const Vec wVec,
407  const word designVarName,
408  const word designVarType,
409  Mat dRdACT);
410 
412  void calcdFdACT(
413  const Vec xvVec,
414  const Vec wVec,
415  const word objFuncName,
416  const word designVarName,
417  const word designVarType,
418  Vec dFdACT);
419 
421  void calcdRdFieldTPsiAD(
422  const Vec xvVec,
423  const Vec wVec,
424  const Vec psi,
425  const word designVarName,
426  Vec dRdFieldTPsi);
427 
429  void calcdFdFieldAD(
430  const Vec xvVec,
431  const Vec wVec,
432  const word objFuncName,
433  const word designVarName,
434  Vec dFdField);
435 
438  const Mat jacPCMat,
439  KSP ksp);
440 
442  void calcdFdWAD(
443  const Vec xvVec,
444  const Vec wVec,
445  const word objFuncName,
446  Vec dFdW);
447 
449  const double* volCoords,
450  const double* states,
451  const double* thermal,
452  const double* seeds,
453  double* product);
454 
456  void calcdRdXvTPsiAD(
457  const Vec xvVec,
458  const Vec wVec,
459  const Vec psi,
460  Vec dRdXvTPsi);
461 
463  void calcdForcedXvAD(
464  const Vec xvVec,
465  const Vec wVec,
466  const Vec fBarVec,
467  Vec dForcedXv);
468 
470  void calcdAcousticsdXvAD(
471  const Vec xvVec,
472  const Vec wVec,
473  const Vec fBarVec,
474  Vec dForcedXv,
475  word varName,
476  word groupName);
477 
479  void calcdFdXvAD(
480  const Vec xvVec,
481  const Vec wVec,
482  const word objFuncName,
483  const word designVarName,
484  Vec dFdXv);
485 
486  void calcdRdActTPsiAD(
487  const Vec xvVec,
488  const Vec wVec,
489  const Vec psi,
490  const word designVarName,
491  Vec dRdActTPsi);
492 
493  void calcdForcedWAD(
494  const Vec xvVec,
495  const Vec wVec,
496  const Vec fBarVec,
497  Vec dForcedW);
498 
499  void calcdAcousticsdWAD(
500  const Vec xvVec,
501  const Vec wVec,
502  const Vec fBarVec,
503  Vec dForcedW,
504  word varName,
505  word groupName);
506 
508  void calcdFdACTAD(
509  const Vec xvVec,
510  const Vec wVec,
511  const word objFuncName,
512  const word designVarName,
513  Vec dFdACT);
514 
516  void calcdRdWOldTPsiAD(
517  const label oldTimeLevel,
518  const Vec psi,
519  Vec dRdWOldTPsi);
520 
522  void getCouplingPatchList(wordList& patchList, word groupName = "NONE");
523 
525  static PetscErrorCode dRdWTMatVecMultFunction(
526  Mat dRdWT,
527  Vec vecX,
528  Vec vecY);
529 
532  const Vec xvVec,
533  const Vec wVec);
534 
536  void destroydRdWTMatrixFree();
537 
539  void registerStateVariableInput4AD(const label oldTimeLevel = 0);
540 
543  const word fieldName,
544  const word fieldType);
545 
548 
550  void registerForceOutput4AD(List<scalar>& fX, List<scalar>& fY, List<scalar>& fZ);
551 
553  void registerAcousticOutput4AD(List<scalar>& a);
554 
556  void assignVec2ResidualGradient(Vec vecX);
557 
559  void assignSeeds2ResidualGradient(const double* seeds);
560 
562  void assignVec2ForceGradient(Vec fBarVec, List<scalar>& fX, List<scalar>& fY, List<scalar>& fZ);
563 
565  void assignVec2AcousticGradient(Vec fBarVec, List<scalar>& a, label offset, label step);
566 
569  Vec vecY,
570  const label oldTimeLevel = 0);
571 
574  const word fieldName,
575  const word fieldType,
576  Vec vecY);
577 
579  void normalizeGradientVec(Vec vecY);
580 
583 
585  label loop(Time& runTime);
586 
589  const label idxPoint,
590  const label idxCoord) const
591  {
592  return daIndexPtr_->getGlobalXvIndex(idxPoint, idxCoord);
593  }
594 
596  void ofField2StateVec(Vec stateVec) const
597  {
598  daFieldPtr_->ofField2StateVec(stateVec);
599  }
600 
602  void stateVec2OFField(const Vec stateVec) const
603  {
604  daFieldPtr_->stateVec2OFField(stateVec);
605  }
606 
608  void pointVec2OFMesh(const Vec xvVec) const
609  {
610  daFieldPtr_->pointVec2OFMesh(xvVec);
611  }
612 
614  void ofMesh2PointVec(Vec xvVec) const
615  {
616  daFieldPtr_->ofMesh2PointVec(xvVec);
617  }
618 
620  void resVec2OFResField(const Vec resVec) const
621  {
622  daFieldPtr_->resVec2OFResField(resVec);
623  }
624 
626  void ofResField2ResVec(Vec resVec) const
627  {
628  daFieldPtr_->resVec2OFResField(resVec);
629  }
630 
633  const Mat matIn,
634  const word prefix)
635  {
636  DAUtility::writeMatrixBinary(matIn, prefix);
637  }
638 
641  const Mat matIn,
642  const word prefix)
643  {
644  DAUtility::writeMatrixASCII(matIn, prefix);
645  }
646 
649  Mat matIn,
650  const word prefix)
651  {
652  DAUtility::readMatrixBinary(matIn, prefix);
653  }
654 
657  const Vec vecIn,
658  const word prefix)
659  {
660  DAUtility::writeVectorASCII(vecIn, prefix);
661  }
662 
665  Vec vecIn,
666  const word prefix)
667  {
668  DAUtility::readVectorBinary(vecIn, prefix);
669  }
670 
673  const Vec vecIn,
674  const word prefix)
675  {
676  DAUtility::writeVectorBinary(vecIn, prefix);
677  }
678 
681  {
682  return daIndexPtr_->nLocalAdjointStates;
683  }
684 
687  {
688  return daIndexPtr_->nLocalAdjointBoundaryStates;
689  }
690 
692  label getNLocalCells() const
693  {
694  return meshPtr_->nCells();
695  }
696 
698  label getNLocalPoints() const
699  {
700  return meshPtr_->nPoints();
701  }
702 
704  void setDAObjFuncList();
705 
707  void printAllObjFuncs();
708 
710  label checkMesh() const
711  {
712  return daCheckMeshPtr_->run();
713  }
714 
716  scalar getObjFuncValue(const word objFuncName);
717 
719  void getForces(
720  Vec fX,
721  Vec fY,
722  Vec fZ);
723 
725  void getAcousticData(
726  Vec x,
727  Vec y,
728  Vec z,
729  Vec nX,
730  Vec nY,
731  Vec nZ,
732  Vec a,
733  Vec fX,
734  Vec fY,
735  Vec fZ,
736  word groupName);
737 
739  void getPatchInfo(
740  label& nPoints,
741  label& nFaces,
742  List<word>& patchList);
743 
745  void getForcesInternal(
746  List<scalar>& fX,
747  List<scalar>& fY,
748  List<scalar>& fZ,
749  List<word>& patchList);
750 
752  label getNCouplingFaces();
753 
755  label getNCouplingPoints();
756 
759  const scalar* volCoords,
760  scalar* surfCoords);
761 
764  const double* volCoords,
765  const double* seeds,
766  double* product);
767 
769  void getThermal(
770  const scalar* volCoords,
771  const scalar* states,
772  scalar* thermal);
773 
775  void getThermalAD(
776  const word inputName,
777  const double* volCoords,
778  const double* states,
779  const double* seeds,
780  double* product);
781 
783  void setThermal(scalar* thermal);
784 
787  List<scalar>& x,
788  List<scalar>& y,
789  List<scalar>& z,
790  List<scalar>& nX,
791  List<scalar>& nY,
792  List<scalar>& nZ,
793  List<scalar>& a,
794  List<scalar>& fX,
795  List<scalar>& fY,
796  List<scalar>& fZ,
797  List<word>& patchList);
798 
800  void calcForceProfile(
801  Vec center,
802  Vec aForceL,
803  Vec tForceL,
804  Vec rDistL);
805 
807  fvMesh& mesh,
808  const vector& center,
809  scalarList& aForceL,
810  scalarList& tForceL,
811  scalarList& rDistL);
812 
814  const word mode,
815  Vec xvVec,
816  Vec stateVec,
817  Vec psiVec,
818  Vec prodVec);
819 
822  const word propName,
823  const scalarField& aForce,
824  const scalarField& tForce,
825  const scalarField& rDistList,
826  const scalarList& targetForce,
827  const vector& center,
828  volVectorField& fvSource);
829 
830  void calcFvSource(
831  const word propName,
832  Vec aForce,
833  Vec tForce,
834  Vec rDist,
835  Vec targetForce,
836  Vec center,
837  Vec fvSource);
838 
840  const word propName,
841  const word mode,
842  Vec aForce,
843  Vec tForce,
844  Vec rDist,
845  Vec targetForce,
846  Vec center,
847  Vec psi,
848  Vec dFvSource);
849 
852  {
853  Info << "DAFoam option dictionary: ";
854  Info << daOptionPtr_->getAllOptions() << endl;
855  }
856 
859  const word mode,
860  const label writeRes = 0);
861 
863  void setdXvdFFDMat(const Mat dXvdFFDMat);
864 
866  void setFFD2XvSeedVec(Vec vecIn);
867 
869  void updateDAOption(PyObject* pyOptions)
870  {
871  daOptionPtr_->updateDAOption(pyOptions);
872  }
873 
876  {
877  return prevPrimalSolTime_;
878  }
879 
882  const word fieldName,
883  const scalar val,
884  const label globalCellI,
885  const label compI = 0);
886 
888  const word fieldName,
889  const scalar val,
890  const label localCellI,
891  const label compI = 0);
892 
895  const word fieldName,
896  const word fieldType);
897 
900  {
901  DAFvSource& fvSource = const_cast<DAFvSource&>(
902  meshPtr_->thisDb().lookupObject<DAFvSource>("DAFvSource"));
903  fvSource.syncDAOptionToActuatorDVs();
904  }
905 
908  const fvMesh& getMesh()
909  {
910  return meshPtr_();
911  }
912 
914  const Time& getRunTime()
915  {
916  return runTimePtr_();
917  }
918 
921  {
922  return daOptionPtr_();
923  }
924 
927  {
928  return daStateInfoPtr_();
929  }
930 
933  {
934  return daIndexPtr_();
935  }
936 
939  {
940  return daModelPtr_();
941  }
942 
945  {
946  return daResidualPtr_();
947  }
948 
951  {
952  return daFieldPtr_();
953  }
954 
957  {
958  return daLinearEqnPtr_();
959  }
960 
963  {
964  return daCheckMeshPtr_();
965  }
966 
968  PetscScalar getForwardADDerivVal(const word objFuncName)
969  {
970  return forwardADDerivVal_[objFuncName];
971  }
972 
974  void setPrimalBoundaryConditions(const label printInfo = 1);
975 
977  void calcResidualVec(Vec resVec);
978 
980  void writeFailedMesh();
981 
984  pyComputeInterface computeInterface,
985  void* compute,
986  pyJacVecProdInterface jacVecProdInterface,
987  void* jacVecProd)
988  {
989  DAUtility::pyCalcBetaInterface = computeInterface;
990  DAUtility::pyCalcBeta = compute;
991 
992  DAUtility::pyCalcBetaJacVecProdInterface = jacVecProdInterface;
993  DAUtility::pyCalcBetaJacVecProd = jacVecProd;
994  }
995 
996 #ifdef CODI_AD_REVERSE
997 
999  codi::RealReverse::Tape& globalADTape_;
1000 
1001 #endif
1002 };
1003 
1004 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1005 
1006 template<class classType>
1008  const SolverPerformance<classType>& solverP,
1009  const label printToScreen,
1010  const label printInterval,
1011  const word varName)
1012 {
1013  /*
1014  Description:
1015  Setup maximal residual control and print the residual as needed
1016  */
1017  if (mag(solverP.initialResidual()) < primalMinRes_)
1018  {
1019  primalMinRes_ = mag(solverP.initialResidual());
1020  }
1021  if (printToScreen)
1022  {
1023  Info << varName << " Initial residual: " << solverP.initialResidual() << endl
1024  << varName << " Final residual: " << solverP.finalResidual() << endl;
1025  }
1026 }
1027 
1028 } // End namespace Foam
1029 
1030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1031 
1032 #endif
1033 
1034 // ************************************************************************* //
Foam::DASolver::calcFvSourceInternal
void calcFvSourceInternal(const word propName, const scalarField &aForce, const scalarField &tForce, const scalarField &rDistList, const scalarList &targetForce, const vector &center, volVectorField &fvSource)
calculate the fvSource based on the radial force profile
Definition: DASolver.C:1769
Foam::DASolver::calcdFdFFD
void calcdFdFFD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdFFD)
compute dFdFFD
Definition: DASolver.C:4233
Foam::DASolver::getForcesInternal
void getForcesInternal(List< scalar > &fX, List< scalar > &fY, List< scalar > &fZ, List< word > &patchList)
compute the forces of the desired fluid-structure-interation patches
Definition: DASolver.C:1292
Foam::DAUtility::readMatrixBinary
static void readMatrixBinary(Mat matIn, const word prefix)
read petsc matrix in binary format
Definition: DAUtility.C:322
Foam::DASolver::calcdFdFieldAD
void calcdFdFieldAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdField)
compute dFdField
Definition: DASolver.C:4549
Foam::DASolver::argsAll_
char * argsAll_
all the arguments
Definition: DASolver.H:61
Foam::DASolver::writeFailedMesh
void writeFailedMesh()
write the failed mesh to disk
Definition: DASolver.C:7955
Foam::DASolver::getMesh
const fvMesh & getMesh()
Definition: DASolver.H:908
Foam::DASolver::writeMatrixBinary
void writeMatrixBinary(const Mat matIn, const word prefix)
write the matrix in binary format
Definition: DASolver.H:632
Foam::DASolver::assignStateGradient2Vec
void assignStateGradient2Vec(Vec vecY, const label oldTimeLevel=0)
set the reverse-mode AD derivatives from the state variables in OpenFOAM to vecY
Definition: DASolver.C:7129
Foam::DAFvSource
Definition: DAFvSource.H:34
Foam::DASolver::updateOFField
void updateOFField(const Vec wVec)
Update the OpenFOAM field values (including both internal and boundary fields) based on the state vec...
Definition: DASolver.C:4765
Foam::DASolver::calcCouplingFaceCoords
void calcCouplingFaceCoords(const scalar *volCoords, scalar *surfCoords)
return the face coordinates based on vol coords
Definition: DASolver.C:362
Foam::DASolver::ofMesh2PointVec
void ofMesh2PointVec(Vec xvVec) const
assign the point vector based on the points in fvMesh of OpenFOAM
Definition: DASolver.H:614
Foam::DASolver::initializedRdWTMatrixFree
void initializedRdWTMatrixFree(const Vec xvVec, const Vec wVec)
initialize matrix free dRdWT
Definition: DASolver.C:4861
DAOption.H
Foam::DASolver::primalResidualControl
void primalResidualControl(const SolverPerformance< classType > &solverP, const label printToScreen, const label printInterval, const word varName)
setup maximal residual control and print the residual as needed
Definition: DASolver.H:1007
Foam::DASolver::calcdRdAOA
void calcdRdAOA(const Vec xvVec, const Vec wVec, const word designVarName, Mat dRdAOA)
compute dRdAOA
Definition: DASolver.C:3240
Foam::DAUtility::pyCalcBetaJacVecProdInterface
static pyJacVecProdInterface pyCalcBetaJacVecProdInterface
Definition: DAUtility.H:133
Foam::DASolver::calcdAcousticsdWAD
void calcdAcousticsdWAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dForcedW, word varName, word groupName)
Definition: DASolver.C:6103
Foam::DASolver::loop
label loop(Time &runTime)
return whether to loop the primal solution, similar to runTime::loop() except we don't do file IO
Definition: DASolver.C:112
Foam::DASolver::calcForceProfileInternal
void calcForceProfileInternal(fvMesh &mesh, const vector &center, scalarList &aForceL, scalarList &tForceL, scalarList &rDistL)
Definition: DASolver.C:1649
Foam::DASolver::calcdFdXvAD
void calcdFdXvAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdXv)
compute dFdXv AD
Definition: DASolver.C:5108
Foam::DASolver::calcdRdBCTPsiAD
void calcdRdBCTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdBCTPsi)
compute dRdBCAD
Definition: DASolver.C:3326
Foam::DASolver::setFieldValue4GlobalCellI
void setFieldValue4GlobalCellI(const word fieldName, const scalar val, const label globalCellI, const label compI=0)
set the field value
Definition: DASolver.C:7550
Foam::DASolver::daCheckMeshPtr_
autoPtr< DACheckMesh > daCheckMeshPtr_
DACheckMesh object pointer.
Definition: DASolver.H:91
Foam::DASolver::getDAModel
const DAModel & getDAModel()
get DAModel object
Definition: DASolver.H:938
Foam::DASolver::stateInfo_
HashTable< wordList > stateInfo_
the stateInfo_ list from DAStateInfo object
Definition: DASolver.H:103
Foam::DASolver::setTimeInstanceField
void setTimeInstanceField(const label instanceI)
assign primal variables based on the current time instance
Definition: DASolver.C:7800
Foam::DASolver::ofResField2ResVec
void ofResField2ResVec(Vec resVec) const
assign the resVec based on OpenFOAM residual fields
Definition: DASolver.H:626
Foam::DAUtility::readVectorBinary
static void readVectorBinary(Vec vecIn, const word prefix)
read petsc vector in binary format
Definition: DAUtility.C:226
Foam::DAUtility::pyCalcBeta
static void * pyCalcBeta
define a function pointer template for Python call back
Definition: DAUtility.H:129
Foam::DASolver::getDALinearEqn
const DALinearEqn & getDALinearEqn()
get DALinearEqn object
Definition: DASolver.H:956
Foam::DASolver::calcdFdACT
void calcdFdACT(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, const word designVarType, Vec dFdACT)
compute dFdACT
Definition: DASolver.C:4434
Foam::DASolver::nItersObjFuncAvg_
label nItersObjFuncAvg_
number of iterations since the start of objFunc averaging
Definition: DASolver.H:118
Foam::DASolver::daModelPtr_
autoPtr< DAModel > daModelPtr_
DAModel pointer.
Definition: DASolver.H:79
Foam::DASolver::stateVec2OFField
void stateVec2OFField(const Vec stateVec) const
assign the fields in OpenFOAM based on the state vector
Definition: DASolver.H:602
Foam::DAUtility::pyCalcBetaInterface
static pyComputeInterface pyCalcBetaInterface
Definition: DAUtility.H:130
Foam::DASolver::assignFieldGradient2Vec
void assignFieldGradient2Vec(const word fieldName, const word fieldType, Vec vecY)
set the reverse-mode AD derivatives from the field variables in OpenFOAM to vecY
Definition: DASolver.C:7311
Foam::DACheckMesh
Definition: DACheckMesh.H:29
Foam::DASolver::getNLocalPoints
label getNLocalPoints() const
return the number of local points
Definition: DASolver.H:698
Foam::DASolver::getPatchInfo
void getPatchInfo(label &nPoints, label &nFaces, List< word > &patchList)
return the number of points and faces for MDO patches
Definition: DASolver.C:1251
Foam::DASolver::registerStateVariableInput4AD
void registerStateVariableInput4AD(const label oldTimeLevel=0)
register all state variables as the input for reverse-mode AD
Definition: DASolver.C:6445
Foam::DASolver::daIndexPtr_
autoPtr< DAIndex > daIndexPtr_
DAIndex pointer.
Definition: DASolver.H:82
Foam::DASolver::setFieldValue4LocalCellI
void setFieldValue4LocalCellI(const word fieldName, const scalar val, const label localCellI, const label compI=0)
Definition: DASolver.C:7511
Foam::DASolver::reduceStateResConLevel
void reduceStateResConLevel(const dictionary &maxResConLv4JacPCMat, HashTable< List< List< word >>> &stateResConInfo) const
reduce the connectivity level for Jacobian connectivity mat
Definition: DASolver.C:2428
Foam::DASolver::getDACheckMesh
const DACheckMesh & getDACheckMesh()
get DACheckMesh object
Definition: DASolver.H:962
Foam::DASolver::setTimeInstanceVar
void setTimeInstanceVar(const word mode, Mat stateMat, Mat stateBCMat, Vec timeVec, Vec timeIdxVec)
assign the time instance mats to/from the lists in the OpenFOAM layer depending on the mode
Definition: DASolver.C:7864
Foam::DASolver::daResidualPtr_
autoPtr< DAResidual > daResidualPtr_
DAResidual pointer.
Definition: DASolver.H:97
DAIndex.H
IOMRFZoneListDF.H
DALinearEqn.H
Foam::DASolver::totalDerivDict_
dictionary totalDerivDict_
the dictionary that stores the total derivatives reduced from processors
Definition: DASolver.H:112
Foam::DASolver::dXvdFFDMat_
Mat dXvdFFDMat_
the matrix that stores the partials dXv/dFFD computed from the idwarp and pygeo in the pyDAFoam....
Definition: DASolver.H:130
Foam::DASolver::calcdFdW
void calcdFdW(const Vec xvVec, const Vec wVec, const word objFuncName, Vec dFdW)
compute dFdW
Definition: DASolver.C:2886
Foam::DASolver::destroydRdWTMatrixFree
void destroydRdWTMatrixFree()
destroy the matrix free dRdWT
Definition: DASolver.C:4895
Foam::DASolver::registerAcousticOutput4AD
void registerAcousticOutput4AD(List< scalar > &a)
register acoustic as the ouptut for referse-mod AD
Definition: DASolver.C:6748
Foam::DASolver::primalMinResTol_
scalar primalMinResTol_
primal residual tolerance
Definition: DASolver.H:195
Foam::DASolver
Definition: DASolver.H:49
Foam::DASolver::resetOFSeeds
void resetOFSeeds()
reset the seeds (gradient to zeros) for all OpenFOAM variables
Definition: DASolver.C:4738
Foam::DAOption
Definition: DAOption.H:29
DACheckMesh.H
Foam::DASolver::normalizeGradientVec
void normalizeGradientVec(Vec vecY)
normalize the reverse-mode AD derivatives stored in vecY
Definition: DASolver.C:6767
Foam::DASolver::getNLocalCells
label getNLocalCells() const
return the number of local cells
Definition: DASolver.H:692
DAUtility.H
Foam::DASolver::registerForceOutput4AD
void registerForceOutput4AD(List< scalar > &fX, List< scalar > &fY, List< scalar > &fZ)
register all force as the ouptut for referse-mod AD
Definition: DASolver.C:6721
Foam::DASolver::daFieldPtr_
autoPtr< DAField > daFieldPtr_
DAField pointer.
Definition: DASolver.H:85
Foam::DASolver::runTimeIndexAllInstances_
List< label > runTimeIndexAllInstances_
the runtime index for all instances (unsteady)
Definition: DASolver.H:186
Foam::DASolver::initializeGlobalADTape4dRdWT
void initializeGlobalADTape4dRdWT()
initialize the CoDiPack reverse-mode AD global tape for computing dRdWT*psi
Definition: DASolver.C:4947
Foam::DASolver::calcdFdACTAD
void calcdFdACTAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdACT)
compute dFdACT AD
Definition: DASolver.C:5739
Foam::DASolver::getNCouplingFaces
label getNCouplingFaces()
Get the number of faces for the MDO coupling patches.
Definition: DASolver.C:332
Foam::DASolver::objFuncAvgHistFilePtr_
autoPtr< OFstream > objFuncAvgHistFilePtr_
pointer to the objective function file used in unsteady primal solvers
Definition: DASolver.H:115
Foam::DAUtility::pyCalcBetaJacVecProd
static void * pyCalcBetaJacVecProd
Definition: DAUtility.H:132
Foam::DASolver::getNLocalAdjointBoundaryStates
label getNLocalAdjointBoundaryStates() const
return the number of local adjoint boundary states
Definition: DASolver.H:686
Foam::DASolver::getDAField
const DAField & getDAField()
get DAField object
Definition: DASolver.H:950
Foam::DASolver::psiVecDict_
dictionary psiVecDict_
the dictionary of adjoint vector (psi) values for all objectives
Definition: DASolver.H:109
Foam::DASolver::daOptionPtr_
autoPtr< DAOption > daOptionPtr_
DAOption pointer.
Definition: DASolver.H:76
Foam::DASolver::saveTimeInstanceFieldHybrid
void saveTimeInstanceFieldHybrid(label &timeInstanceI)
save primal variable to time instance list for hybrid adjoint (unsteady)
Definition: DASolver.C:7727
Foam::DASolver::calcdRdActTPsiAD
void calcdRdActTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdActTPsi)
Definition: DASolver.C:5910
Foam::DASolver::calcdFvSourcedInputsTPsiAD
void calcdFvSourcedInputsTPsiAD(const word propName, const word mode, Vec aForce, Vec tForce, Vec rDist, Vec targetForce, Vec center, Vec psi, Vec dFvSource)
Definition: DASolver.C:2231
Foam::DASolver::calcdRdXvTPsiAD
void calcdRdXvTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, Vec dRdXvTPsi)
compute dRdXv^T*Psi
Definition: DASolver.C:5368
Foam::DASolver::pyOptions_
PyObject * pyOptions_
all options in DAFoam
Definition: DASolver.H:64
Foam::DASolver::registerResidualOutput4AD
void registerResidualOutput4AD()
register all residuals as the output for reverse-mode AD
Definition: DASolver.C:6649
Foam::DASolver::setdXvdFFDMat
void setdXvdFFDMat(const Mat dXvdFFDMat)
set the value for DASolver::dXvdFFDMat_
Definition: DASolver.C:7407
Foam::DASolver::initTensorFlowFuncs
void initTensorFlowFuncs(pyComputeInterface computeInterface, void *compute, pyJacVecProdInterface jacVecProdInterface, void *jacVecProd)
initialize tensorflow functions and interfaces for callback
Definition: DASolver.H:983
fvSource
volScalarField & fvSource
Definition: createRefsHeatTransfer.H:7
Foam::DASolver::calcPrimalResidualStatistics
void calcPrimalResidualStatistics(const word mode, const label writeRes=0)
calculate the norms of all residuals and print to screen
Definition: DASolver.C:2559
DAColoring.H
Foam::DASolver::getRunTime
const Time & getRunTime()
return the runTime object
Definition: DASolver.H:914
DAJacCon.H
Foam::DASolver::solveLinearEqn
label solveLinearEqn(const KSP ksp, const Vec rhsVec, Vec solVec)
solve the linear equation given a ksp and right-hand-side vector
Definition: DASolver.C:4709
DAResidual.H
Foam::DASolver::readVectorBinary
void readVectorBinary(Vec vecIn, const word prefix)
read petsc vector in binary format
Definition: DASolver.H:664
Foam::DASolver::assignVec2ForceGradient
void assignVec2ForceGradient(Vec fBarVec, List< scalar > &fX, List< scalar > &fY, List< scalar > &fZ)
assign the reverse-mode AD input seeds from fBarVec to the force vectors in OpenFOAM
Definition: DASolver.C:7051
Foam::DASolver::calcdRdFFD
void calcdRdFFD(const Vec xvVec, const Vec wVec, const word designVarName, Mat dRdFFD)
compute dRdFFD
Definition: DASolver.C:4151
Foam::DASolver::getDAStateInfo
const DAStateInfo & getDAStateInfo()
get DAStateInfo object
Definition: DASolver.H:926
Foam::DASolver::setFFD2XvSeedVec
void setFFD2XvSeedVec(Vec vecIn)
set the value for DASolver::FFD2XvSeedVec_
Definition: DASolver.C:7419
Foam::DASolver::calcdRdACT
void calcdRdACT(const Vec xvVec, const Vec wVec, const word designVarName, const word designVarType, Mat dRdACT)
compute dRdACT
Definition: DASolver.C:4358
Foam::DASolver::globalADTape4dRdWTInitialized
label globalADTape4dRdWTInitialized
a flag in dRdWTMatVecMultFunction to determine if the global tap is initialized
Definition: DASolver.H:171
Foam::DASolver::getAcousticDataInternal
void getAcousticDataInternal(List< scalar > &x, List< scalar > &y, List< scalar > &z, List< scalar > &nX, List< scalar > &nY, List< scalar > &nZ, List< scalar > &a, List< scalar > &fX, List< scalar > &fY, List< scalar > &fZ, List< word > &patchList)
compute the positions, normals, areas, and forces of the desired acoustic patches
Definition: DASolver.C:1459
DAModel.H
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DASolver::nSolveAdjointCalls_
label nSolveAdjointCalls_
how many times the DASolver::solveAdjoint function is called
Definition: DASolver.H:127
Foam::DASolver::isPrintTime
label isPrintTime(const Time &runTime, const label printInterval) const
Definition: DASolver.C:7460
Foam::DASolver::getAcousticData
void getAcousticData(Vec x, Vec y, Vec z, Vec nX, Vec nY, Vec nZ, Vec a, Vec fX, Vec fY, Vec fZ, word groupName)
return the positions, normals, areas, and forces of the desired acoustic patches
Definition: DASolver.C:1114
Foam::DASolver::getDAResidual
const DAResidual & getDAResidual()
get DAResidual object
Definition: DASolver.H:944
Foam::DASolver::assignSeeds2ResidualGradient
void assignSeeds2ResidualGradient(const double *seeds)
assign the reverse-mode AD input seeds from vecX to the residuals in OpenFOAM
Definition: DASolver.C:6873
Foam::DASolver::daLinearEqnPtr_
autoPtr< DALinearEqn > daLinearEqnPtr_
DALinearEqn pointer.
Definition: DASolver.H:94
Foam::DASolver::getDAIndex
const DAIndex & getDAIndex()
get DAIndex object
Definition: DASolver.H:932
Foam::DAUtility::writeVectorBinary
static void writeVectorBinary(const Vec vecIn, const word prefix)
write petsc vector in binary format
Definition: DAUtility.C:259
Foam::DASolver::updateBoundaryConditions
void updateBoundaryConditions(const word fieldName, const word fieldType)
update the boundary condition for a field
Definition: DASolver.C:7694
Foam::DASolver::saveTimeInstanceFieldTimeAccurate
void saveTimeInstanceFieldTimeAccurate(label &timeInstanceI)
save primal variable to time instance list for time accurate adjoint (unsteady)
Definition: DASolver.C:7772
Foam::DASolver::calcFvSource
void calcFvSource(const word propName, Vec aForce, Vec tForce, Vec rDist, Vec targetForce, Vec center, Vec fvSource)
Definition: DASolver.C:2129
Foam::DASolver::calcdRdWTPsiAD
void calcdRdWTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, Vec dRdWTPsi)
compute [dRdW]^T*Psi
Definition: DASolver.C:6293
Foam::DASolver::getForwardADDerivVal
PetscScalar getForwardADDerivVal(const word objFuncName)
get forwardADDerivVal_
Definition: DASolver.H:968
Foam::DASolver::writeVectorASCII
void writeVectorASCII(const Vec vecIn, const word prefix)
write petsc vector in ascii format
Definition: DASolver.H:656
Foam::DAIndex
Definition: DAIndex.H:32
Foam::DASolver::getPrevPrimalSolTime
scalar getPrevPrimalSolTime()
get the solution time folder for previous primal solution
Definition: DASolver.H:875
Foam::DASolver::calcdRdBC
void calcdRdBC(const Vec xvVec, const Vec wVec, const word designVarName, Mat dRdBC)
compute dRdBC
Definition: DASolver.C:3029
Foam::DASolver::calcdFdBCAD
void calcdFdBCAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdBC)
compute dFdBCAD
Definition: DASolver.C:3562
Foam::DASolver::forwardADDerivVal_
HashTable< PetscScalar > forwardADDerivVal_
the derivative value computed by the forward mode primal solution.
Definition: DASolver.H:136
Foam::DASolver::updateOFMesh
void updateOFMesh(const Vec xvVec)
Update the OpenFoam mesh point coordinates based on the point vector xvVec.
Definition: DASolver.C:4823
Foam::DASolver::writeMatrixASCII
void writeMatrixASCII(const Mat matIn, const word prefix)
write the matrix in ASCII format
Definition: DASolver.H:640
Foam::DASolver::syncDAOptionToActuatorDVs
void syncDAOptionToActuatorDVs()
synchronize the values in DAOption and actuatorDiskDVs_
Definition: DASolver.H:899
Foam::DAField
Definition: DAField.H:36
Foam::DASolver::objFuncNames4Adj_
wordList objFuncNames4Adj_
the list of objective function names that requires adjoint solution
Definition: DASolver.H:106
Foam::DASolver::primalMinIters_
label primalMinIters_
primal min number of iterations
Definition: DASolver.H:198
Foam::DAModel
Definition: DAModel.H:59
Foam::DASolver::registerFieldVariableInput4AD
void registerFieldVariableInput4AD(const word fieldName, const word fieldType)
register field variables as the input for reverse-mode AD
Definition: DASolver.C:6602
Foam::DASolver::getThermalAD
void getThermalAD(const word inputName, const double *volCoords, const double *states, const double *seeds, double *product)
compute the temperature on the conjugate heat transfer patches AD
Definition: DASolver.C:896
Foam::DASolver::prevPrimalSolTime_
scalar prevPrimalSolTime_
the solution time for the previous primal solution
Definition: DASolver.H:142
Foam
Definition: multiFreqScalarFvPatchField.C:144
Foam::DASolver::getDAOption
const DAOption & getDAOption()
get DAOption object
Definition: DASolver.H:920
Foam::DASolver::runTimeAllInstances_
List< scalar > runTimeAllInstances_
the runtime value for all instances (unsteady)
Definition: DASolver.H:183
Foam::DASolver::FFD2XvSeedVec_
Vec FFD2XvSeedVec_
the vector that stores the AD seeds that propagate from FFD to Xv and will be used in forward mode AD
Definition: DASolver.H:133
Foam::DASolver::setDAObjFuncList
void setDAObjFuncList()
initialize DASolver::daObjFuncPtrList_ one needs to call this before calling printAllObjFuncs
Definition: DASolver.C:235
Foam::DASolver::writeAssociatedFields
void writeAssociatedFields()
write associated fields such as relative velocity
Definition: DASolver.C:7478
Foam::DASolver::assignVec2AcousticGradient
void assignVec2AcousticGradient(Vec fBarVec, List< scalar > &a, label offset, label step)
assign the reverse-mode AD input seeds from fBarVec to the acoustic vectors in OpenFOAM
Definition: DASolver.C:7093
Foam::DASolver::convertMPIVec2SeqVec
void convertMPIVec2SeqVec(const Vec mpiVec, Vec seqVec)
convert the mpi vec to a seq vec
Definition: DASolver.C:7367
Foam::DASolver::dRdWTMatVecMultFunction
static PetscErrorCode dRdWTMatVecMultFunction(Mat dRdWT, Vec vecX, Vec vecY)
matrix free matrix-vector product function to compute vecY=dRdWT*vecX
Definition: DASolver.C:4906
Foam::DASolver::~DASolver
virtual ~DASolver()
Definition: DASolver.H:235
Foam::pyJacVecProdInterface
void(* pyJacVecProdInterface)(const double *, double *, int, const double *, const double *, int, void *)
Definition: DAUtility.H:28
Foam::DASolver::printAllObjFuncs
void printAllObjFuncs()
calculate the values of all objective functions and print them to screen
Definition: DASolver.C:160
Foam::DASolver::objFuncsAllInstances_
List< dictionary > objFuncsAllInstances_
objective function for all instances (unsteady)
Definition: DASolver.H:180
Foam::DASolver::calcdFdBC
void calcdFdBC(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdBC)
compute dFdBC
Definition: DASolver.C:3116
Foam::DASolver::resVec2OFResField
void resVec2OFResField(const Vec resVec) const
assign the OpenFOAM residual fields based on the resVec
Definition: DASolver.H:620
Foam::DASolver::getObjFuncValue
scalar getObjFuncValue(const word objFuncName)
return the value of the objective function
Definition: DASolver.C:200
Foam::DAResidual
Definition: DAResidual.H:35
Foam::DASolver::getGlobalXvIndex
label getGlobalXvIndex(const label idxPoint, const label idxCoord) const
basically, we call DAIndex::getGlobalXvIndex
Definition: DASolver.H:588
Foam::DASolver::primalMinRes_
scalar primalMinRes_
the maximal residual for primal solution
Definition: DASolver.H:139
Foam::DASolver::calcdRdAOATPsiAD
void calcdRdAOATPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdAOATPsi)
compute dRdAOAAD
Definition: DASolver.C:3977
Foam::DASolver::calcdFdWAD
void calcdFdWAD(const Vec xvVec, const Vec wVec, const word objFuncName, Vec dFdW)
compute dFdW using AD
Definition: DASolver.C:4986
DAPartDeriv.H
Foam::DASolver::runTimePtr_
autoPtr< Time > runTimePtr_
runTime pointer
Definition: DASolver.H:70
Foam::DAUtility::writeMatrixBinary
static void writeMatrixBinary(const Mat matIn, const word prefix)
write petsc matrix in binary format
Definition: DAUtility.C:355
Foam::DASolver::getCouplingPatchList
void getCouplingPatchList(wordList &patchList, word groupName="NONE")
return the coupling patch list if any scenario is active on couplingInfo dict otherwise return design...
Definition: DASolver.C:488
Foam::DASolver::writeVectorBinary
void writeVectorBinary(const Vec vecIn, const word prefix)
write petsc vector in binary format
Definition: DASolver.H:672
Foam::DASolver::setThermal
void setThermal(scalar *thermal)
assign temperature values to the conjugate heat transfer patches
Definition: DASolver.C:550
Foam::DASolver::getNLocalAdjointStates
label getNLocalAdjointStates() const
return the number of local adjoint states
Definition: DASolver.H:680
Foam::DASolver::initSolver
virtual void initSolver()=0
initialize fields and variables
Foam::DASolver::meshPtr_
autoPtr< fvMesh > meshPtr_
fvMesh pointer
Definition: DASolver.H:73
Foam::DASolver::calcCouplingFaceCoordsAD
void calcCouplingFaceCoordsAD(const double *volCoords, const double *seeds, double *product)
calc matrix-vector products for calcCouplingFaceCoords
Definition: DASolver.C:421
Foam::DASolver::calcForceProfile
void calcForceProfile(Vec center, Vec aForceL, Vec tForceL, Vec rDistL)
calculate the radial profile of the force on the propeller surface
Definition: DASolver.C:1566
DAStateInfo.H
Foam::DAUtility::writeVectorASCII
static void writeVectorASCII(const Vec vecIn, const word prefix)
write petsc vector in ascii format
Definition: DAUtility.C:291
Foam::DASolver::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, DASolver, dictionary,(char *argsAll, PyObject *pyOptions),(argsAll, pyOptions))
Foam::DASolver::argsPtr_
autoPtr< argList > argsPtr_
args pointer
Definition: DASolver.H:67
Foam::DASolver::printAllOptions
void printAllOptions()
print all DAOption
Definition: DASolver.H:851
Foam::DASolver::ofField2StateVec
void ofField2StateVec(Vec stateVec) const
set the state vector based on the latest fields in OpenFOAM
Definition: DASolver.H:596
Foam::DAUtility::writeMatrixASCII
static void writeMatrixASCII(const Mat matIn, const word prefix)
write petsc matrix in ascii format
Definition: DAUtility.C:387
Foam::DASolver::createMLRKSP
void createMLRKSP(const Mat jacMat, const Mat jacPCMat, KSP ksp)
create a multi-level, Richardson KSP object
Definition: DASolver.C:4675
Foam::DASolver::calcdRdWT
void calcdRdWT(const Vec xvVec, const Vec wVec, const label isPC, Mat dRdWT)
compute dRdWT
Definition: DASolver.C:2752
Foam::DASolver::checkMesh
label checkMesh() const
check the mesh quality and return meshOK
Definition: DASolver.H:710
Foam::DASolver::initOldTimes
void initOldTimes()
initialize the oldTime for all state variables
Foam::DASolver::checkResidualTol
label checkResidualTol()
check whether the min residual in primal satisfy the prescribed tolerance
Definition: DASolver.C:7432
Foam::DASolver::updateDAOption
void updateDAOption(PyObject *pyOptions)
update the allOptions_ dict in DAOption based on the pyOptions from pyDAFoam
Definition: DASolver.H:869
Foam::DALinearEqn
Definition: DALinearEqn.H:31
Foam::pyComputeInterface
void(* pyComputeInterface)(const double *, int, double *, int, void *)
Definition: DAUtility.H:27
Foam::DASolver::calcdFdAOA
void calcdFdAOA(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdAOA)
compute dFdAOA
Definition: DASolver.C:3853
Foam::DASolver::getForces
void getForces(Vec fX, Vec fY, Vec fZ)
return the forces of the desired fluid-structure-interaction patches
Definition: DASolver.C:1042
Foam::DASolver::nTimeInstances_
label nTimeInstances_
number of time instances for hybird adjoint (unsteady)
Definition: DASolver.H:189
Foam::DASolver::dRdWTPC_
Mat dRdWTPC_
the preconditioner matrix for the adjoint linear equation solution
Definition: DASolver.H:124
Foam::DASolver::calcdForcedWAD
void calcdForcedWAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dForcedW)
Definition: DASolver.C:6030
Foam::DASolver::calcResidualVec
void calcResidualVec(Vec resVec)
calculate the residual and assign it to the resVec vector
Definition: DASolver.C:7601
Foam::DAStateInfo
Definition: DAStateInfo.H:30
Foam::DASolver::runFPAdj
virtual label runFPAdj(const Vec xvVec, const Vec wVec, Vec dFdW, Vec psi)
solve the adjoint equation using the fixed-point iteration method
Definition: DASolver.C:8003
Foam::DASolver::calcdRdFieldTPsiAD
void calcdRdFieldTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdFieldTPsi)
compute dRdField^T*Psi
Definition: DASolver.C:5661
Foam::DASolver::calcdRdThermalTPsiAD
void calcdRdThermalTPsiAD(const double *volCoords, const double *states, const double *thermal, const double *seeds, double *product)
Definition: DASolver.C:5245
Foam::DASolver::createMLRKSPMatrixFree
void createMLRKSPMatrixFree(const Mat jacPCMat, KSP ksp)
create a multi-level, Richardson KSP object with matrix-free Jacobians
Definition: DASolver.C:4690
Foam::DASolver::setPrimalBoundaryConditions
void setPrimalBoundaryConditions(const label printInfo=1)
update the primal state boundary condition based on the primalBC dict
Definition: DASolver.C:7982
Foam::DASolver::solvePrimal
virtual label solvePrimal(const Vec xvVec, Vec wVec)=0
solve the primal equations
Foam::DASolver::daStateInfoPtr_
autoPtr< DAStateInfo > daStateInfoPtr_
DAStateInfo pointer.
Definition: DASolver.H:100
runTime
Time & runTime
Definition: createRefsHeatTransfer.H:1
Foam::DASolver::stateAllInstances_
List< List< scalar > > stateAllInstances_
state variable list for all instances (unsteady)
Definition: DASolver.H:174
Foam::DASolver::getTimeInstanceObjFunc
scalar getTimeInstanceObjFunc(const label instanceI, const word objFuncName)
return the value of objective function at the given time instance and name
Definition: DASolver.C:7970
Foam::DASolver::calcdForcedXvAD
void calcdForcedXvAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dForcedXv)
compute dForcedXv
Definition: DASolver.C:5445
Foam::DASolver::periodicity_
scalar periodicity_
periodicity of oscillating flow variables (unsteady)
Definition: DASolver.H:192
Foam::DASolver::calcdForcedStateTPsiAD
void calcdForcedStateTPsiAD(const word mode, Vec xvVec, Vec stateVec, Vec psiVec, Vec prodVec)
Definition: DASolver.C:1760
Foam::DASolver::readMatrixBinary
void readMatrixBinary(Mat matIn, const word prefix)
read petsc matrix in binary format
Definition: DASolver.H:648
Foam::DASolver::calcdRdWOldTPsiAD
void calcdRdWOldTPsiAD(const label oldTimeLevel, const Vec psi, Vec dRdWOldTPsi)
compute dRdWOld^T*Psi
Definition: DASolver.C:6370
DAField.H
DAObjFunc.H
Foam::DASolver::getNCouplingPoints
label getNCouplingPoints()
Get the number of points for the MDO coupling patches.
Definition: DASolver.C:347
Foam::DASolver::getThermal
void getThermal(const scalar *volCoords, const scalar *states, scalar *thermal)
compute the temperature on the conjugate heat transfer patches
Definition: DASolver.C:731
Foam::DASolver::pointVec2OFMesh
void pointVec2OFMesh(const Vec xvVec) const
assign the points in fvMesh of OpenFOAM based on the point vector
Definition: DASolver.H:608
Foam::DASolver::assignVec2ResidualGradient
void assignVec2ResidualGradient(Vec vecX)
assign the reverse-mode AD input seeds from vecX to the residuals in OpenFOAM
Definition: DASolver.C:6960
Foam::DASolver::daObjFuncPtrList_
UPtrList< DAObjFunc > daObjFuncPtrList_
a list of DAObjFunc pointers
Definition: DASolver.H:88
Foam::DASolver::stateBoundaryAllInstances_
List< List< scalar > > stateBoundaryAllInstances_
state boundary variable list for all instances (unsteady)
Definition: DASolver.H:177
psi
const volScalarField & psi
Definition: createRefsRhoSimpleC.H:14
Foam::DASolver::dRdWTMF_
Mat dRdWTMF_
matrix-free dRdWT matrix used in GMRES solution
Definition: DASolver.H:168
Foam::DASolver::TypeName
TypeName("DASolver")
Runtime type information.
dafoam_plot3dtransform.mode
mode
Definition: dafoam_plot3dtransform.py:21
Foam::DASolver::avgObjFuncValues_
scalarList avgObjFuncValues_
the averaged objective function values used in unsteady flow
Definition: DASolver.H:121
Foam::DASolver::calcdAcousticsdXvAD
void calcdAcousticsdXvAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dForcedXv, word varName, word groupName)
compute dAcoudXv
Definition: DASolver.C:5527
Foam::DASolver::New
static autoPtr< DASolver > New(char *argsAll, PyObject *pyOptions)
Definition: DASolver.C:69