DASolvers.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
5 
6  Description:
7  Python wrapper library for DASolver
8 
9 \*---------------------------------------------------------------------------*/
10 
11 #ifndef DASolvers_H
12 #define DASolvers_H
13 
14 #include <petscksp.h>
15 #include "Python.h"
16 #include "DASolver.H"
17 
18 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
19 
20 namespace Foam
21 {
22 
23 /*---------------------------------------------------------------------------*\
24  Class DASolvers Declaration
25 \*---------------------------------------------------------------------------*/
26 
27 class DASolvers
28 {
29 
30 private:
32  DASolvers(const DASolvers&);
33 
35  void operator=(const DASolvers&);
36 
38  char* argsAll_;
39 
41  PyObject* pyOptions_;
42 
44  autoPtr<DASolver> DASolverPtr_;
45 
46 public:
47  // Constructors
48 
50  DASolvers(
51  char* argsAll,
52  PyObject* pyOptions);
53 
55  virtual ~DASolvers();
56 
58  void initSolver()
59  {
60  DASolverPtr_->initSolver();
61  }
62 
64  label solvePrimal(
65  const Vec xvVec,
66  Vec wVec)
67  {
68  return DASolverPtr_->solvePrimal(xvVec, wVec);
69  }
70 
72  void calcdRdWT(
73  const Vec xvVec,
74  const Vec wVec,
75  const label isPC,
76  Mat dRdWT)
77  {
78  DASolverPtr_->calcdRdWT(xvVec, wVec, isPC, dRdWT);
79  }
80 
82  void calcdFdW(
83  const Vec xvVec,
84  const Vec wVec,
85  const word objFuncName,
86  Vec dFdW)
87  {
88  DASolverPtr_->calcdFdW(xvVec, wVec, objFuncName, dFdW);
89  }
90 
92  void calcdFdWAD(
93  const Vec xvVec,
94  const Vec wVec,
95  const word objFuncName,
96  Vec dFdW)
97  {
98  DASolverPtr_->calcdFdWAD(xvVec, wVec, objFuncName, dFdW);
99  }
100 
103  const Vec xvVec,
104  const Vec wVec,
105  const word objFuncName,
106  const word designVarName,
107  Vec dFdXv)
108  {
109  DASolverPtr_->calcdFdXvAD(xvVec, wVec, objFuncName, designVarName, dFdXv);
110  }
111 
114  const Vec xvVec,
115  const Vec wVec,
116  const Vec psi,
117  Vec dRdXvTPsi)
118  {
119  DASolverPtr_->calcdRdXvTPsiAD(xvVec, wVec, psi, dRdXvTPsi);
120  }
121 
124  const Vec xvVec,
125  const Vec wVec,
126  const Vec fBarVec,
127  Vec dForcedW)
128  {
129  DASolverPtr_->calcdForcedXvAD(xvVec, wVec, fBarVec, dForcedW);
130  }
131 
134  const Vec xvVec,
135  const Vec wVec,
136  const Vec fBarVec,
137  Vec dAcoudW,
138  word varName,
139  word groupName)
140  {
141  DASolverPtr_->calcdAcousticsdXvAD(xvVec, wVec, fBarVec, dAcoudW, varName, groupName);
142  }
143 
146  const Vec xvVec,
147  const Vec wVec,
148  const Vec psi,
149  const word designVarName,
150  Vec dRdActTPsi)
151  {
152  DASolverPtr_->calcdRdActTPsiAD(xvVec, wVec, psi, designVarName, dRdActTPsi);
153  }
154 
157  const Vec xvVec,
158  const Vec wVec,
159  const Vec fBarVec,
160  Vec dForcedW)
161  {
162  DASolverPtr_->calcdForcedWAD(xvVec, wVec, fBarVec, dForcedW);
163  }
164 
167  const Vec xvVec,
168  const Vec wVec,
169  const Vec fBarVec,
170  Vec dAcoudW,
171  word varName,
172  word groupName)
173  {
174  DASolverPtr_->calcdAcousticsdWAD(xvVec, wVec, fBarVec, dAcoudW, varName, groupName);
175  }
176 
179  const Vec xvVec,
180  const Vec wVec,
181  const Vec psi,
182  const word designVarName,
183  Vec dRdAOATPsi)
184  {
185  DASolverPtr_->calcdRdAOATPsiAD(xvVec, wVec, psi, designVarName, dRdAOATPsi);
186  }
187 
190  const Mat jacMat,
191  const Mat jacPCMat,
192  KSP ksp)
193  {
194  DASolverPtr_->createMLRKSP(jacMat, jacPCMat, ksp);
195  }
196 
199  const Mat jacPCMat,
200  KSP ksp)
201  {
202  DASolverPtr_->createMLRKSPMatrixFree(jacPCMat, ksp);
203  }
204 
207  const Vec xvVec,
208  const Vec wVec)
209  {
210  DASolverPtr_->initializedRdWTMatrixFree(xvVec, wVec);
211  }
212 
215  {
216  DASolverPtr_->destroydRdWTMatrixFree();
217  }
218 
221  const KSP ksp,
222  const Vec rhsVec,
223  Vec solVec)
224  {
225  DASolverPtr_->solveLinearEqn(ksp, rhsVec, solVec);
226  }
227 
230  const Vec mpiVec,
231  Vec seqVec)
232  {
233  DASolverPtr_->convertMPIVec2SeqVec(mpiVec, seqVec);
234  }
235 
237  void calcdRdBC(
238  const Vec xvVec,
239  const Vec wVec,
240  const word designVarName,
241  Mat dRdBC)
242  {
243  DASolverPtr_->calcdRdBC(xvVec, wVec, designVarName, dRdBC);
244  }
245 
247  void calcdFdBC(
248  const Vec xvVec,
249  const Vec wVec,
250  const word objFuncName,
251  const word designVarName,
252  Vec dFdBC)
253  {
254  DASolverPtr_->calcdFdBC(xvVec, wVec, objFuncName, designVarName, dFdBC);
255  }
256 
259  const Vec xvVec,
260  const Vec wVec,
261  const word objFuncName,
262  const word designVarName,
263  Vec dFdBC)
264  {
265  DASolverPtr_->calcdFdBCAD(xvVec, wVec, objFuncName, designVarName, dFdBC);
266  }
267 
270  const Vec xvVec,
271  const Vec wVec,
272  const Vec psi,
273  const word designVarName,
274  Vec dRdBCTPsi)
275  {
276  DASolverPtr_->calcdRdBCTPsiAD(xvVec, wVec, psi, designVarName, dRdBCTPsi);
277  }
278 
281  const Vec xvVec,
282  const Vec wVec,
283  const word designVarName,
284  Mat dRdAOA)
285  {
286  DASolverPtr_->calcdRdAOA(xvVec, wVec, designVarName, dRdAOA);
287  }
288 
291  const Vec xvVec,
292  const Vec wVec,
293  const word objFuncName,
294  const word designVarName,
295  Vec dFdAOA)
296  {
297  DASolverPtr_->calcdFdAOA(xvVec, wVec, objFuncName, designVarName, dFdAOA);
298  }
299 
302  const Vec xvVec,
303  const Vec wVec,
304  const word designVarName,
305  Mat dRdFFD)
306  {
307  DASolverPtr_->calcdRdFFD(xvVec, wVec, designVarName, dRdFFD);
308  }
309 
312  const Vec xvVec,
313  const Vec wVec,
314  const word objFuncName,
315  const word designVarName,
316  Vec dFdFFD)
317  {
318  DASolverPtr_->calcdFdFFD(xvVec, wVec, objFuncName, designVarName, dFdFFD);
319  }
320 
323  const Vec xvVec,
324  const Vec wVec,
325  const word designVarName,
326  const word designVarType,
327  Mat dRdACT)
328  {
329  DASolverPtr_->calcdRdACT(xvVec, wVec, designVarName, designVarType, dRdACT);
330  }
331 
334  const Vec xvVec,
335  const Vec wVec,
336  const word objFuncName,
337  const word designVarName,
338  Vec dFdACT)
339  {
340  DASolverPtr_->calcdFdACTAD(xvVec, wVec, objFuncName, designVarName, dFdACT);
341  }
342 
345  const Vec xvVec,
346  const Vec wVec,
347  const word objFuncName,
348  const word designVarName,
349  const word designVarType,
350  Vec dFdACT)
351  {
352  DASolverPtr_->calcdFdACT(xvVec, wVec, objFuncName, designVarName, designVarType, dFdACT);
353  }
354 
357  const Vec xvVec,
358  const Vec wVec,
359  const Vec psi,
360  const word designVarName,
361  Vec dRdFieldTPsi)
362  {
363  DASolverPtr_->calcdRdFieldTPsiAD(xvVec, wVec, psi, designVarName, dRdFieldTPsi);
364  }
365 
368  const Vec xvVec,
369  const Vec wVec,
370  const word objFuncName,
371  const word designVarName,
372  Vec dFdField)
373  {
374  DASolverPtr_->calcdFdFieldAD(xvVec, wVec, objFuncName, designVarName, dFdField);
375  }
376 
379  const label oldTimeLevel,
380  const Vec psi,
381  Vec dRdWOldTPsi)
382  {
383  DASolverPtr_->calcdRdWOldTPsiAD(oldTimeLevel, psi, dRdWOldTPsi);
384  }
385 
388  const Vec xvVec,
389  const Vec wVec,
390  const Vec psi,
391  Vec dRdWTPsi)
392  {
393  DASolverPtr_->calcdRdWTPsiAD(xvVec, wVec, psi, dRdWTPsi);
394  }
395 
397  void updateOFField(const Vec wVec)
398  {
399  DASolverPtr_->updateOFField(wVec);
400  }
401 
403  void updateOFMesh(const Vec xvVec)
404  {
405  DASolverPtr_->updateOFMesh(xvVec);
406  }
407 
410  const label idxPoint,
411  const label idxCoord) const
412  {
413  return DASolverPtr_->getGlobalXvIndex(idxPoint, idxCoord);
414  }
415 
417  void ofField2StateVec(Vec stateVec) const
418  {
419  DASolverPtr_->ofField2StateVec(stateVec);
420  }
421 
423  void stateVec2OFField(const Vec stateVec) const
424  {
425  DASolverPtr_->stateVec2OFField(stateVec);
426  }
427 
429  label checkMesh() const
430  {
431  return DASolverPtr_->checkMesh();
432  }
433 
436  {
437  return DASolverPtr_->getNCouplingFaces();
438  }
439 
442  {
443  return DASolverPtr_->getNCouplingPoints();
444  }
445 
446  // return the number of local mesh points
447  label getNLocalPoints() const
448  {
449  return DASolverPtr_->getNLocalPoints();
450  }
451 
454  {
455  return DASolverPtr_->getNLocalAdjointStates();
456  }
457 
460  {
461  return DASolverPtr_->getNLocalAdjointBoundaryStates();
462  }
463 
465  label getNLocalCells() const
466  {
467  return DASolverPtr_->getNLocalCells();
468  }
469 
472  {
473  DASolverPtr_->syncDAOptionToActuatorDVs();
474  }
475 
477  double getObjFuncValue(const word objFuncName)
478  {
479  double returnVal = 0.0;
480  assignValueCheckAD(returnVal, DASolverPtr_->getObjFuncValue(objFuncName));
481  return returnVal;
482  }
483 
485  const double* volCoords,
486  double* surfCoords)
487  {
488 #if !defined(CODI_AD_REVERSE) && !defined(CODI_AD_FORWARD)
489  DASolverPtr_->calcCouplingFaceCoords(volCoords, surfCoords);
490  return;
491 #endif
492  FatalErrorIn("calcCouplingFaceCoords") << "should not call this func in AD mode!"
493  << abort(FatalError);
494  }
495 
498  const double* volCoords,
499  const double* seeds,
500  double* product)
501  {
502  DASolverPtr_->calcCouplingFaceCoordsAD(volCoords, seeds, product);
503  }
504 
506  void getForces(Vec fX, Vec fY, Vec fZ)
507  {
508  DASolverPtr_->getForces(fX, fY, fZ);
509  }
510 
513  const double* volCoords,
514  const double* states,
515  double* thermal)
516  {
517 #if !defined(CODI_AD_REVERSE) && !defined(CODI_AD_FORWARD)
518  DASolverPtr_->getThermal(volCoords, states, thermal);
519  return;
520 #endif
521  FatalErrorIn("getThermal") << "should not call this func in AD mode!"
522  << abort(FatalError);
523  }
524 
527  const word inputName,
528  const double* volCoords,
529  const double* states,
530  const double* seeds,
531  double* product)
532  {
533  DASolverPtr_->getThermalAD(inputName, volCoords, states, seeds, product);
534  }
535 
537  void setThermal(double* thermal)
538  {
539 #if !defined(CODI_AD_REVERSE) && !defined(CODI_AD_FORWARD)
540  DASolverPtr_->setThermal(thermal);
541  return;
542 #endif
543  FatalErrorIn("setThermal") << "should not call this func in AD mode!"
544  << abort(FatalError);
545  }
546 
548  const double* volCoords,
549  const double* states,
550  const double* thermal,
551  const double* seeds,
552  double* product)
553  {
554  DASolverPtr_->calcdRdThermalTPsiAD(volCoords, states, thermal, seeds, product);
555  }
556 
558  void getAcousticData(Vec x, Vec y, Vec z, Vec nX, Vec nY, Vec nZ, Vec a, Vec fX, Vec fY, Vec fZ, word groupName)
559  {
560  DASolverPtr_->getAcousticData(x, y, z, nX, nY, nZ, a, fX, fY, fZ, groupName);
561  }
562 
565  {
566  DASolverPtr_->printAllOptions();
567  }
568 
570  void setdXvdFFDMat(const Mat dXvdFFDMat)
571  {
572  DASolverPtr_->setdXvdFFDMat(dXvdFFDMat);
573  }
574 
576  void setFFD2XvSeedVec(Vec vecIn)
577  {
578  DASolverPtr_->setFFD2XvSeedVec(vecIn);
579  }
580 
582  void updateDAOption(PyObject* pyOptions)
583  {
584  DASolverPtr_->updateDAOption(pyOptions);
585  }
586 
589  {
590  double returnVal = 0.0;
591  assignValueCheckAD(returnVal, DASolverPtr_->getPrevPrimalSolTime());
592  return returnVal;
593  }
594 
596  void pointVec2OFMesh(const Vec xvVec) const
597  {
598  DASolverPtr_->pointVec2OFMesh(xvVec);
599  }
600 
602  void ofMesh2PointVec(Vec xvVec) const
603  {
604  DASolverPtr_->ofMesh2PointVec(xvVec);
605  }
606 
608  void resVec2OFResField(const Vec resVec) const
609  {
610  DASolverPtr_->resVec2OFResField(resVec);
611  }
612 
614  void ofResField2ResVec(Vec resVec) const
615  {
616  DASolverPtr_->resVec2OFResField(resVec);
617  }
618 
621  const Mat matIn,
622  const word prefix)
623  {
624  DASolverPtr_->writeMatrixBinary(matIn, prefix);
625  }
626 
629  const Mat matIn,
630  const word prefix)
631  {
632  DASolverPtr_->writeMatrixASCII(matIn, prefix);
633  }
634 
637  Mat matIn,
638  const word prefix)
639  {
640  DASolverPtr_->readMatrixBinary(matIn, prefix);
641  }
642 
645  const Vec vecIn,
646  const word prefix)
647  {
648  DASolverPtr_->writeVectorASCII(vecIn, prefix);
649  }
650 
653  Vec vecIn,
654  const word prefix)
655  {
656  DASolverPtr_->readVectorBinary(vecIn, prefix);
657  }
658 
661  const Vec vecIn,
662  const word prefix)
663  {
664  DASolverPtr_->writeVectorBinary(vecIn, prefix);
665  }
666 
668  void setTimeInstanceField(const label instanceI)
669  {
670  DASolverPtr_->setTimeInstanceField(instanceI);
671  }
672 
675  const word mode,
676  Mat stateMat,
677  Mat stateBCMat,
678  Vec timeVec,
679  Vec timeIdxVec)
680  {
681  DASolverPtr_->setTimeInstanceVar(mode, stateMat, stateBCMat, timeVec, timeIdxVec);
682  }
683 
686  const label instanceI,
687  const word objFuncName)
688  {
689  double returnVal = 0.0;
690  assignValueCheckAD(returnVal, DASolverPtr_->getTimeInstanceObjFunc(instanceI, objFuncName));
691  return returnVal;
692  }
693 
696  const word fieldName,
697  const scalar val,
698  const label globalCellI,
699  const label compI = 0)
700  {
701  DASolverPtr_->setFieldValue4GlobalCellI(fieldName, val, globalCellI, compI);
702  }
703 
706  const word fieldName,
707  const scalar val,
708  const label localCellI,
709  const label compI = 0)
710  {
711  DASolverPtr_->setFieldValue4LocalCellI(fieldName, val, localCellI, compI);
712  }
713 
716  const word fieldName,
717  const word fieldType)
718  {
719  DASolverPtr_->updateBoundaryConditions(fieldName, fieldType);
720  }
721 
724  {
725  DASolverPtr_->calcPrimalResidualStatistics(mode, 0);
726  }
727 
729  PetscScalar getForwardADDerivVal(const word objFuncName)
730  {
731  return DASolverPtr_->getForwardADDerivVal(objFuncName);
732  }
733 
735  void calcResidualVec(Vec resVec)
736  {
737  DASolverPtr_->calcResidualVec(resVec);
738  }
739 
740  void setPrimalBoundaryConditions(const label printInfo = 1)
741  {
742  DASolverPtr_->setPrimalBoundaryConditions(printInfo);
743  }
744 
747  const word propName,
748  Vec aForce,
749  Vec tForce,
750  Vec rDist,
751  Vec targetForce,
752  Vec center,
753  Vec fvSource)
754  {
755  DASolverPtr_->calcFvSource(propName, aForce, tForce, rDist, targetForce, center, fvSource);
756  }
757 
759  const word propName,
760  const word mode,
761  Vec aForce,
762  Vec tForce,
763  Vec rDist,
764  Vec targetForce,
765  Vec center,
766  Vec psi,
767  Vec dFvSource)
768  {
769  DASolverPtr_->calcdFvSourcedInputsTPsiAD(propName, mode, aForce, tForce, rDist, targetForce, center, psi, dFvSource);
770  }
771 
773  Vec center,
774  Vec aForceL,
775  Vec tForceL,
776  Vec rDistL)
777  {
778  DASolverPtr_->calcForceProfile(center, aForceL, tForceL, rDistL);
779  }
780 
782  const word mode,
783  Vec xvVec,
784  Vec stateVec,
785  Vec psiVec,
786  Vec prodVec)
787  {
788  DASolverPtr_->calcdForcedStateTPsiAD(mode, xvVec, stateVec, psiVec, prodVec);
789  }
790 
791  label runFPAdj(
792  const Vec xvVec,
793  const Vec wVec,
794  Vec dFdW,
795  Vec psi)
796  {
797  return DASolverPtr_->runFPAdj(xvVec, wVec, dFdW, psi);
798  }
799 
802  pyComputeInterface computeInterface,
803  void* compute,
804  pyJacVecProdInterface jacVecProdInterface,
805  void* jacVecProd)
806  {
807  DASolverPtr_->initTensorFlowFuncs(computeInterface, compute, jacVecProdInterface, jacVecProd);
808  }
809 };
810 
811 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
812 
813 } // End namespace Foam
814 
815 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
816 
817 #endif
Foam::DASolvers
Definition: DASolvers.H:27
Foam::DASolvers::stateVec2OFField
void stateVec2OFField(const Vec stateVec) const
basically, we call DASolver::stateVec2OFField
Definition: DASolvers.H:423
Foam::DASolvers::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: DASolvers.H:526
Foam::DASolvers::writeVectorBinary
void writeVectorBinary(const Vec vecIn, const word prefix)
write petsc vector in binary format
Definition: DASolvers.H:660
Foam::DASolvers::calcdForcedWAD
void calcdForcedWAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dForcedW)
compute dForcedW
Definition: DASolvers.H:156
Foam::DASolvers::ofMesh2PointVec
void ofMesh2PointVec(Vec xvVec) const
assign the point vector based on the points in fvMesh of OpenFOAM
Definition: DASolvers.H:602
Foam::DASolvers::calcPrimalResidualStatistics
void calcPrimalResidualStatistics(const word mode)
Calculate the mean, max, and norm2 for all residuals and print it to screen.
Definition: DASolvers.H:723
Foam::DASolvers::updateBoundaryConditions
void updateBoundaryConditions(const word fieldName, const word fieldType)
update the boundary condition for a field
Definition: DASolvers.H:715
Foam::DASolvers::setFFD2XvSeedVec
void setFFD2XvSeedVec(Vec vecIn)
set the value for DASolver::FFD2XvSeedVec_
Definition: DASolvers.H:576
Foam::DASolvers::getThermal
void getThermal(const double *volCoords, const double *states, double *thermal)
return the thermal (temperature or heat flux) on the conjugate heat transfer patches
Definition: DASolvers.H:512
Foam::DASolvers::getGlobalXvIndex
label getGlobalXvIndex(const label idxPoint, const label idxCoord) const
basically, we call DAIndex::getGlobalXvIndex
Definition: DASolvers.H:409
Foam::DASolvers::resVec2OFResField
void resVec2OFResField(const Vec resVec) const
assign the OpenFOAM residual fields based on the resVec
Definition: DASolvers.H:608
Foam::DASolvers::checkMesh
label checkMesh() const
basically, we call DASolver::checkMesh
Definition: DASolvers.H:429
Foam::DASolvers::getPrevPrimalSolTime
double getPrevPrimalSolTime()
get the solution time folder for previous primal solution
Definition: DASolvers.H:588
Foam::DASolvers::~DASolvers
virtual ~DASolvers()
Destructor.
Definition: DASolvers.C:25
Foam::DASolvers::syncDAOptionToActuatorDVs
void syncDAOptionToActuatorDVs()
synchronize the values in DAOption and actuatorDiskDVs_
Definition: DASolvers.H:471
Foam::DASolvers::setdXvdFFDMat
void setdXvdFFDMat(const Mat dXvdFFDMat)
set values for dXvdFFDMat
Definition: DASolvers.H:570
Foam::DASolvers::createMLRKSPMatrixFree
void createMLRKSPMatrixFree(const Mat jacPCMat, KSP ksp)
create a multi-level, Richardson KSP object with matrix-free Jacobians
Definition: DASolvers.H:198
Foam::DASolvers::calcdRdFieldTPsiAD
void calcdRdFieldTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdFieldTPsi)
compute dRdField
Definition: DASolvers.H:356
Foam::DASolvers::calcdFdFieldAD
void calcdFdFieldAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdField)
compute dFdField
Definition: DASolvers.H:367
Foam::DASolvers::writeMatrixBinary
void writeMatrixBinary(const Mat matIn, const word prefix)
write the matrix in binary format
Definition: DASolvers.H:620
Foam::DASolvers::calcdRdWTPsiAD
void calcdRdWTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, Vec dRdWTPsi)
compute [dRdW]^T*Psi
Definition: DASolvers.H:387
Foam::DASolvers::writeVectorASCII
void writeVectorASCII(const Vec vecIn, const word prefix)
write petsc vector in ascii format
Definition: DASolvers.H:644
Foam::DASolvers::calcdFdWAD
void calcdFdWAD(const Vec xvVec, const Vec wVec, const word objFuncName, Vec dFdW)
compute dFdW using reverse-mode AD
Definition: DASolvers.H:92
Foam::DASolvers::getForces
void getForces(Vec fX, Vec fY, Vec fZ)
return the force on the FSI patches
Definition: DASolvers.H:506
Foam::DASolvers::calcdAcousticsdWAD
void calcdAcousticsdWAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dAcoudW, word varName, word groupName)
compute dAcoudW
Definition: DASolvers.H:166
Foam::DASolvers::readVectorBinary
void readVectorBinary(Vec vecIn, const word prefix)
read petsc vector in binary format
Definition: DASolvers.H:652
Foam::DASolvers::createMLRKSP
void createMLRKSP(const Mat jacMat, const Mat jacPCMat, KSP ksp)
create the multi-level Richardson KSP for solving linear equation
Definition: DASolvers.H:189
Foam::DASolvers::calcdFdW
void calcdFdW(const Vec xvVec, const Vec wVec, const word objFuncName, Vec dFdW)
compute dFdW
Definition: DASolvers.H:82
Foam::DASolvers::calcdFdBC
void calcdFdBC(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdBC)
compute dFdBC
Definition: DASolvers.H:247
fvSource
volScalarField & fvSource
Definition: createRefsHeatTransfer.H:7
Foam::DASolvers::calcdFdBCAD
void calcdFdBCAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdBC)
compute dFdBCAD
Definition: DASolvers.H:258
Foam::DASolvers::setTimeInstanceField
void setTimeInstanceField(const label instanceI)
assign primal variables based on the current time instance
Definition: DASolvers.H:668
Foam::DASolvers::printAllOptions
void printAllOptions()
call DASolver::printAllOptions
Definition: DASolvers.H:564
Foam::DASolvers::calcdAcousticsdXvAD
void calcdAcousticsdXvAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dAcoudW, word varName, word groupName)
compute dAcoudXv
Definition: DASolvers.H:133
Foam::DASolvers::calcdFdXvAD
void calcdFdXvAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdXv)
compute dFdXv using reverse-mode AD
Definition: DASolvers.H:102
Foam::DASolvers::getForwardADDerivVal
PetscScalar getForwardADDerivVal(const word objFuncName)
get forwardADDerivVal_
Definition: DASolvers.H:729
Foam::DASolvers::solvePrimal
label solvePrimal(const Vec xvVec, Vec wVec)
solve the primal equations
Definition: DASolvers.H:64
Foam::DASolvers::readMatrixBinary
void readMatrixBinary(Mat matIn, const word prefix)
read petsc matrix in binary format
Definition: DASolvers.H:636
Foam::DASolvers::calcdFdFFD
void calcdFdFFD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdFFD)
compute dFdFFD
Definition: DASolvers.H:311
Foam::DASolvers::getNLocalPoints
label getNLocalPoints() const
Definition: DASolvers.H:447
Foam::DASolvers::calcdRdWT
void calcdRdWT(const Vec xvVec, const Vec wVec, const label isPC, Mat dRdWT)
compute dRdWT
Definition: DASolvers.H:72
Foam::DASolvers::initTensorFlowFuncs
void initTensorFlowFuncs(pyComputeInterface computeInterface, void *compute, pyJacVecProdInterface jacVecProdInterface, void *jacVecProd)
initialize the call back function pointer
Definition: DASolvers.H:801
Foam::DASolvers::calcCouplingFaceCoords
void calcCouplingFaceCoords(const double *volCoords, double *surfCoords)
Definition: DASolvers.H:484
Foam::DASolvers::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 acoustic data values
Definition: DASolvers.H:558
Foam::DASolvers::calcdForcedXvAD
void calcdForcedXvAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dForcedW)
compute dForcedXv
Definition: DASolvers.H:123
Foam::DASolvers::getNLocalAdjointStates
label getNLocalAdjointStates() const
return the number of local adjoint states
Definition: DASolvers.H:453
Foam::DASolvers::calcCouplingFaceCoordsAD
void calcCouplingFaceCoordsAD(const double *volCoords, const double *seeds, double *product)
calc matrix-vector products for calcCouplingFaceCoords
Definition: DASolvers.H:497
Foam::DASolvers::calcdForcedStateTPsiAD
void calcdForcedStateTPsiAD(const word mode, Vec xvVec, Vec stateVec, Vec psiVec, Vec prodVec)
Definition: DASolvers.H:781
Foam::DASolvers::calcdRdXvTPsiAD
void calcdRdXvTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, Vec dRdXvTPsi)
compute dRdXv^T*Psi
Definition: DASolvers.H:113
Foam::DASolvers::getTimeInstanceObjFunc
double getTimeInstanceObjFunc(const label instanceI, const word objFuncName)
return the value of objective function at the given time instance and name
Definition: DASolvers.H:685
assignValueCheckAD
#define assignValueCheckAD(valA, valB)
Definition: DAMacroFunctions.H:103
Foam::DASolvers::calcdRdAOA
void calcdRdAOA(const Vec xvVec, const Vec wVec, const word designVarName, Mat dRdAOA)
compute dRdAOA
Definition: DASolvers.H:280
Foam::DASolvers::setThermal
void setThermal(double *thermal)
set the thermal (temperature or heat flux) BC to the conjugate heat transfer patches
Definition: DASolvers.H:537
Foam::DASolvers::setPrimalBoundaryConditions
void setPrimalBoundaryConditions(const label printInfo=1)
Definition: DASolvers.H:740
Foam::DASolvers::calcdFdAOA
void calcdFdAOA(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdAOA)
compute dFdAOA
Definition: DASolvers.H:290
Foam
Definition: multiFreqScalarFvPatchField.C:144
Foam::DASolvers::calcdRdBC
void calcdRdBC(const Vec xvVec, const Vec wVec, const word designVarName, Mat dRdBC)
compute dRdBC
Definition: DASolvers.H:237
Foam::DASolvers::getNCouplingPoints
label getNCouplingPoints()
Get the number of points for the MDO coupling patches.
Definition: DASolvers.H:441
Foam::pyJacVecProdInterface
void(* pyJacVecProdInterface)(const double *, double *, int, const double *, const double *, int, void *)
Definition: DAUtility.H:28
Foam::DASolvers::destroydRdWTMatrixFree
void destroydRdWTMatrixFree()
destroy matrix free dRdWT
Definition: DASolvers.H:214
Foam::DASolvers::updateOFMesh
void updateOFMesh(const Vec xvVec)
Update the OpenFoam mesh point coordinates based on the point vector xvVec.
Definition: DASolvers.H:403
Foam::DASolvers::calcdFdACT
void calcdFdACT(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, const word designVarType, Vec dFdACT)
compute dFdACT
Definition: DASolvers.H:344
Foam::DASolvers::calcFvSource
void calcFvSource(const word propName, Vec aForce, Vec tForce, Vec rDist, Vec targetForce, Vec center, Vec fvSource)
calculate the fvSource based on the force profile
Definition: DASolvers.H:746
Foam::DASolvers::calcdRdACT
void calcdRdACT(const Vec xvVec, const Vec wVec, const word designVarName, const word designVarType, Mat dRdACT)
compute dRdACT
Definition: DASolvers.H:322
Foam::DASolvers::pointVec2OFMesh
void pointVec2OFMesh(const Vec xvVec) const
assign the points in fvMesh of OpenFOAM based on the point vector
Definition: DASolvers.H:596
Foam::DASolvers::calcdFvSourcedInputsTPsiAD
void calcdFvSourcedInputsTPsiAD(const word propName, const word mode, Vec aForce, Vec tForce, Vec rDist, Vec targetForce, Vec center, Vec psi, Vec dFvSource)
Definition: DASolvers.H:758
Foam::DASolvers::updateDAOption
void updateDAOption(PyObject *pyOptions)
update the allOptions_ dict in DAOption based on the pyOptions from pyDAFoam
Definition: DASolvers.H:582
Foam::DASolvers::initializedRdWTMatrixFree
void initializedRdWTMatrixFree(const Vec xvVec, const Vec wVec)
initialize matrix free dRdWT
Definition: DASolvers.H:206
Foam::DASolvers::setFieldValue4LocalCellI
void setFieldValue4LocalCellI(const word fieldName, const scalar val, const label localCellI, const label compI=0)
set the field value
Definition: DASolvers.H:705
Foam::DASolvers::getNCouplingFaces
label getNCouplingFaces()
Get the number of faces for the MDO coupling patches.
Definition: DASolvers.H:435
Foam::DASolvers::initSolver
void initSolver()
initialize fields and variables
Definition: DASolvers.H:58
Foam::DASolvers::runFPAdj
label runFPAdj(const Vec xvVec, const Vec wVec, Vec dFdW, Vec psi)
Definition: DASolvers.H:791
Foam::DASolvers::getNLocalAdjointBoundaryStates
label getNLocalAdjointBoundaryStates() const
return the number of local adjoint boundary states
Definition: DASolvers.H:459
Foam::DASolvers::ofResField2ResVec
void ofResField2ResVec(Vec resVec) const
assign the resVec based on OpenFOAM residual fields
Definition: DASolvers.H:614
Foam::DASolvers::getObjFuncValue
double getObjFuncValue(const word objFuncName)
return the value of objective
Definition: DASolvers.H:477
Foam::DASolvers::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: DASolvers.H:674
Foam::pyComputeInterface
void(* pyComputeInterface)(const double *, int, double *, int, void *)
Definition: DAUtility.H:27
Foam::DASolvers::writeMatrixASCII
void writeMatrixASCII(const Mat matIn, const word prefix)
write the matrix in ASCII format
Definition: DASolvers.H:628
Foam::DASolvers::calcdFdACTAD
void calcdFdACTAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdACT)
compute dFdACT
Definition: DASolvers.H:333
Foam::DASolvers::solveLinearEqn
void solveLinearEqn(const KSP ksp, const Vec rhsVec, Vec solVec)
solve the linear equation
Definition: DASolvers.H:220
Foam::DASolvers::calcdRdBCTPsiAD
void calcdRdBCTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdBCTPsi)
compute dRdBC^T*Psi
Definition: DASolvers.H:269
DASolver.H
Foam::DASolvers::getNLocalCells
label getNLocalCells() const
return the number of local cells
Definition: DASolvers.H:465
Foam::DASolvers::calcdRdFFD
void calcdRdFFD(const Vec xvVec, const Vec wVec, const word designVarName, Mat dRdFFD)
compute dRdFFD
Definition: DASolvers.H:301
Foam::DASolvers::calcdRdActTPsiAD
void calcdRdActTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdActTPsi)
compute dRdAct^T*Psi
Definition: DASolvers.H:145
Foam::DASolvers::convertMPIVec2SeqVec
void convertMPIVec2SeqVec(const Vec mpiVec, Vec seqVec)
convert the mpi vec to a seq vec
Definition: DASolvers.H:229
Foam::DASolvers::calcdRdThermalTPsiAD
void calcdRdThermalTPsiAD(const double *volCoords, const double *states, const double *thermal, const double *seeds, double *product)
Definition: DASolvers.H:547
Foam::DASolvers::setFieldValue4GlobalCellI
void setFieldValue4GlobalCellI(const word fieldName, const scalar val, const label globalCellI, const label compI=0)
set the field value
Definition: DASolvers.H:695
Foam::DASolvers::calcdRdAOATPsiAD
void calcdRdAOATPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdAOATPsi)
compute dRdAOA^T*Psi
Definition: DASolvers.H:178
Foam::DASolvers::updateOFField
void updateOFField(const Vec wVec)
Update the OpenFOAM field values (including both internal and boundary fields) based on the state vec...
Definition: DASolvers.H:397
psi
const volScalarField & psi
Definition: createRefsRhoSimpleC.H:14
dafoam_plot3dtransform.mode
mode
Definition: dafoam_plot3dtransform.py:21
Foam::DASolvers::calcResidualVec
void calcResidualVec(Vec resVec)
calculate the residual and assign it to the resVec vector
Definition: DASolvers.H:735
Foam::DASolvers::calcForceProfile
void calcForceProfile(Vec center, Vec aForceL, Vec tForceL, Vec rDistL)
Definition: DASolvers.H:772
Foam::DASolvers::ofField2StateVec
void ofField2StateVec(Vec stateVec) const
basically, we call DASolver::ofField2StateVec
Definition: DASolvers.H:417
Foam::DASolvers::calcdRdWOldTPsiAD
void calcdRdWOldTPsiAD(const label oldTimeLevel, const Vec psi, Vec dRdWOldTPsi)
compute dRdWOld^T*Psi
Definition: DASolvers.H:378