Go to the documentation of this file.
19 #include "runTimeSelectionTables.H"
21 #include "functionObjectList.H"
22 #include "fvOptions.H"
36 #include "volPointInterpolation.H"
38 #include "interpolateSplineXY.H"
145 template<
class classType>
147 const SolverPerformance<classType>& solverP,
148 const label printToScreen,
149 const label printInterval,
154 const label printInterval)
const;
161 const dictionary& maxResConLv4JacPCMat,
162 HashTable<List<List<word>>>& stateResConInfo)
const;
217 PyObject* pyOptions),
218 (argsAll, pyOptions));
225 PyObject* pyOptions);
230 static autoPtr<DASolver>
New(
232 PyObject* pyOptions);
261 const label instanceI,
262 const word objFuncName);
299 const word objFuncName,
338 const word designVarName,
345 const word objFuncName,
346 const word designVarName,
354 const word designVarName,
361 const word objFuncName,
362 const word designVarName,
369 const word designVarName,
376 const word objFuncName,
377 const word designVarName,
385 const word designVarName,
392 const word designVarName,
399 const word objFuncName,
400 const word designVarName,
407 const word designVarName,
408 const word designVarType,
415 const word objFuncName,
416 const word designVarName,
417 const word designVarType,
425 const word designVarName,
432 const word objFuncName,
433 const word designVarName,
445 const word objFuncName,
449 const double* volCoords,
450 const double* states,
451 const double* thermal,
482 const word objFuncName,
483 const word designVarName,
490 const word designVarName,
511 const word objFuncName,
512 const word designVarName,
517 const label oldTimeLevel,
543 const word fieldName,
544 const word fieldType);
570 const label oldTimeLevel = 0);
574 const word fieldName,
575 const word fieldType,
589 const label idxPoint,
590 const label idxCoord)
const
592 return daIndexPtr_->getGlobalXvIndex(idxPoint, idxCoord);
742 List<word>& patchList);
749 List<word>& patchList);
759 const scalar* volCoords,
764 const double* volCoords,
770 const scalar* volCoords,
771 const scalar* states,
776 const word inputName,
777 const double* volCoords,
778 const double* states,
797 List<word>& patchList);
808 const vector& center,
823 const scalarField& aForce,
824 const scalarField& tForce,
825 const scalarField& rDistList,
826 const scalarList& targetForce,
827 const vector& center,
853 Info <<
"DAFoam option dictionary: ";
860 const label writeRes = 0);
882 const word fieldName,
884 const label globalCellI,
885 const label compI = 0);
888 const word fieldName,
890 const label localCellI,
891 const label compI = 0);
895 const word fieldName,
896 const word fieldType);
903 fvSource.syncDAOptionToActuatorDVs();
996 #ifdef CODI_AD_REVERSE
999 codi::RealReverse::Tape& globalADTape_;
1006 template<
class classType>
1008 const SolverPerformance<classType>& solverP,
1009 const label printToScreen,
1010 const label printInterval,
1023 Info << varName <<
" Initial residual: " << solverP.initialResidual() << endl
1024 << varName <<
" Final residual: " << solverP.finalResidual() << endl;
void calcFvSourceInternal(const word propName, const scalarField &aForce, const scalarField &tForce, const scalarField &rDistList, const scalarList &targetForce, const vector ¢er, volVectorField &fvSource)
calculate the fvSource based on the radial force profile
void calcdFdFFD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdFFD)
compute dFdFFD
void getForcesInternal(List< scalar > &fX, List< scalar > &fY, List< scalar > &fZ, List< word > &patchList)
compute the forces of the desired fluid-structure-interation patches
static void readMatrixBinary(Mat matIn, const word prefix)
read petsc matrix in binary format
void calcdFdFieldAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdField)
compute dFdField
char * argsAll_
all the arguments
void writeFailedMesh()
write the failed mesh to disk
void writeMatrixBinary(const Mat matIn, const word prefix)
write the matrix in binary format
void assignStateGradient2Vec(Vec vecY, const label oldTimeLevel=0)
set the reverse-mode AD derivatives from the state variables in OpenFOAM to vecY
void updateOFField(const Vec wVec)
Update the OpenFOAM field values (including both internal and boundary fields) based on the state vec...
void calcCouplingFaceCoords(const scalar *volCoords, scalar *surfCoords)
return the face coordinates based on vol coords
void ofMesh2PointVec(Vec xvVec) const
assign the point vector based on the points in fvMesh of OpenFOAM
void initializedRdWTMatrixFree(const Vec xvVec, const Vec wVec)
initialize matrix free dRdWT
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
void calcdRdAOA(const Vec xvVec, const Vec wVec, const word designVarName, Mat dRdAOA)
compute dRdAOA
static pyJacVecProdInterface pyCalcBetaJacVecProdInterface
void calcdAcousticsdWAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dForcedW, word varName, word groupName)
label loop(Time &runTime)
return whether to loop the primal solution, similar to runTime::loop() except we don't do file IO
void calcForceProfileInternal(fvMesh &mesh, const vector ¢er, scalarList &aForceL, scalarList &tForceL, scalarList &rDistL)
void calcdFdXvAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdXv)
compute dFdXv AD
void calcdRdBCTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdBCTPsi)
compute dRdBCAD
void setFieldValue4GlobalCellI(const word fieldName, const scalar val, const label globalCellI, const label compI=0)
set the field value
autoPtr< DACheckMesh > daCheckMeshPtr_
DACheckMesh object pointer.
const DAModel & getDAModel()
get DAModel object
HashTable< wordList > stateInfo_
the stateInfo_ list from DAStateInfo object
void setTimeInstanceField(const label instanceI)
assign primal variables based on the current time instance
void ofResField2ResVec(Vec resVec) const
assign the resVec based on OpenFOAM residual fields
static void readVectorBinary(Vec vecIn, const word prefix)
read petsc vector in binary format
static void * pyCalcBeta
define a function pointer template for Python call back
const DALinearEqn & getDALinearEqn()
get DALinearEqn object
void calcdFdACT(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, const word designVarType, Vec dFdACT)
compute dFdACT
label nItersObjFuncAvg_
number of iterations since the start of objFunc averaging
autoPtr< DAModel > daModelPtr_
DAModel pointer.
void stateVec2OFField(const Vec stateVec) const
assign the fields in OpenFOAM based on the state vector
static pyComputeInterface pyCalcBetaInterface
void assignFieldGradient2Vec(const word fieldName, const word fieldType, Vec vecY)
set the reverse-mode AD derivatives from the field variables in OpenFOAM to vecY
label getNLocalPoints() const
return the number of local points
void getPatchInfo(label &nPoints, label &nFaces, List< word > &patchList)
return the number of points and faces for MDO patches
void registerStateVariableInput4AD(const label oldTimeLevel=0)
register all state variables as the input for reverse-mode AD
autoPtr< DAIndex > daIndexPtr_
DAIndex pointer.
void setFieldValue4LocalCellI(const word fieldName, const scalar val, const label localCellI, const label compI=0)
void reduceStateResConLevel(const dictionary &maxResConLv4JacPCMat, HashTable< List< List< word >>> &stateResConInfo) const
reduce the connectivity level for Jacobian connectivity mat
const DACheckMesh & getDACheckMesh()
get DACheckMesh object
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
autoPtr< DAResidual > daResidualPtr_
DAResidual pointer.
dictionary totalDerivDict_
the dictionary that stores the total derivatives reduced from processors
Mat dXvdFFDMat_
the matrix that stores the partials dXv/dFFD computed from the idwarp and pygeo in the pyDAFoam....
void calcdFdW(const Vec xvVec, const Vec wVec, const word objFuncName, Vec dFdW)
compute dFdW
void destroydRdWTMatrixFree()
destroy the matrix free dRdWT
void registerAcousticOutput4AD(List< scalar > &a)
register acoustic as the ouptut for referse-mod AD
scalar primalMinResTol_
primal residual tolerance
void resetOFSeeds()
reset the seeds (gradient to zeros) for all OpenFOAM variables
void normalizeGradientVec(Vec vecY)
normalize the reverse-mode AD derivatives stored in vecY
label getNLocalCells() const
return the number of local cells
void registerForceOutput4AD(List< scalar > &fX, List< scalar > &fY, List< scalar > &fZ)
register all force as the ouptut for referse-mod AD
autoPtr< DAField > daFieldPtr_
DAField pointer.
List< label > runTimeIndexAllInstances_
the runtime index for all instances (unsteady)
void initializeGlobalADTape4dRdWT()
initialize the CoDiPack reverse-mode AD global tape for computing dRdWT*psi
void calcdFdACTAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdACT)
compute dFdACT AD
label getNCouplingFaces()
Get the number of faces for the MDO coupling patches.
autoPtr< OFstream > objFuncAvgHistFilePtr_
pointer to the objective function file used in unsteady primal solvers
static void * pyCalcBetaJacVecProd
label getNLocalAdjointBoundaryStates() const
return the number of local adjoint boundary states
const DAField & getDAField()
get DAField object
dictionary psiVecDict_
the dictionary of adjoint vector (psi) values for all objectives
autoPtr< DAOption > daOptionPtr_
DAOption pointer.
void saveTimeInstanceFieldHybrid(label &timeInstanceI)
save primal variable to time instance list for hybrid adjoint (unsteady)
void calcdRdActTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdActTPsi)
void calcdFvSourcedInputsTPsiAD(const word propName, const word mode, Vec aForce, Vec tForce, Vec rDist, Vec targetForce, Vec center, Vec psi, Vec dFvSource)
void calcdRdXvTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, Vec dRdXvTPsi)
compute dRdXv^T*Psi
PyObject * pyOptions_
all options in DAFoam
void registerResidualOutput4AD()
register all residuals as the output for reverse-mode AD
void setdXvdFFDMat(const Mat dXvdFFDMat)
set the value for DASolver::dXvdFFDMat_
void initTensorFlowFuncs(pyComputeInterface computeInterface, void *compute, pyJacVecProdInterface jacVecProdInterface, void *jacVecProd)
initialize tensorflow functions and interfaces for callback
volScalarField & fvSource
void calcPrimalResidualStatistics(const word mode, const label writeRes=0)
calculate the norms of all residuals and print to screen
const Time & getRunTime()
return the runTime object
label solveLinearEqn(const KSP ksp, const Vec rhsVec, Vec solVec)
solve the linear equation given a ksp and right-hand-side vector
void readVectorBinary(Vec vecIn, const word prefix)
read petsc vector in binary format
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
void calcdRdFFD(const Vec xvVec, const Vec wVec, const word designVarName, Mat dRdFFD)
compute dRdFFD
const DAStateInfo & getDAStateInfo()
get DAStateInfo object
void setFFD2XvSeedVec(Vec vecIn)
set the value for DASolver::FFD2XvSeedVec_
void calcdRdACT(const Vec xvVec, const Vec wVec, const word designVarName, const word designVarType, Mat dRdACT)
compute dRdACT
label globalADTape4dRdWTInitialized
a flag in dRdWTMatVecMultFunction to determine if the global tap is initialized
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
label nSolveAdjointCalls_
how many times the DASolver::solveAdjoint function is called
label isPrintTime(const Time &runTime, const label printInterval) const
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
const DAResidual & getDAResidual()
get DAResidual object
void assignSeeds2ResidualGradient(const double *seeds)
assign the reverse-mode AD input seeds from vecX to the residuals in OpenFOAM
autoPtr< DALinearEqn > daLinearEqnPtr_
DALinearEqn pointer.
const DAIndex & getDAIndex()
get DAIndex object
static void writeVectorBinary(const Vec vecIn, const word prefix)
write petsc vector in binary format
void updateBoundaryConditions(const word fieldName, const word fieldType)
update the boundary condition for a field
void saveTimeInstanceFieldTimeAccurate(label &timeInstanceI)
save primal variable to time instance list for time accurate adjoint (unsteady)
void calcFvSource(const word propName, Vec aForce, Vec tForce, Vec rDist, Vec targetForce, Vec center, Vec fvSource)
void calcdRdWTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, Vec dRdWTPsi)
compute [dRdW]^T*Psi
PetscScalar getForwardADDerivVal(const word objFuncName)
get forwardADDerivVal_
void writeVectorASCII(const Vec vecIn, const word prefix)
write petsc vector in ascii format
scalar getPrevPrimalSolTime()
get the solution time folder for previous primal solution
void calcdRdBC(const Vec xvVec, const Vec wVec, const word designVarName, Mat dRdBC)
compute dRdBC
void calcdFdBCAD(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdBC)
compute dFdBCAD
HashTable< PetscScalar > forwardADDerivVal_
the derivative value computed by the forward mode primal solution.
void updateOFMesh(const Vec xvVec)
Update the OpenFoam mesh point coordinates based on the point vector xvVec.
void writeMatrixASCII(const Mat matIn, const word prefix)
write the matrix in ASCII format
void syncDAOptionToActuatorDVs()
synchronize the values in DAOption and actuatorDiskDVs_
wordList objFuncNames4Adj_
the list of objective function names that requires adjoint solution
label primalMinIters_
primal min number of iterations
void registerFieldVariableInput4AD(const word fieldName, const word fieldType)
register field variables as the input for reverse-mode AD
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
scalar prevPrimalSolTime_
the solution time for the previous primal solution
const DAOption & getDAOption()
get DAOption object
List< scalar > runTimeAllInstances_
the runtime value for all instances (unsteady)
Vec FFD2XvSeedVec_
the vector that stores the AD seeds that propagate from FFD to Xv and will be used in forward mode AD
void setDAObjFuncList()
initialize DASolver::daObjFuncPtrList_ one needs to call this before calling printAllObjFuncs
void writeAssociatedFields()
write associated fields such as relative velocity
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
void convertMPIVec2SeqVec(const Vec mpiVec, Vec seqVec)
convert the mpi vec to a seq vec
static PetscErrorCode dRdWTMatVecMultFunction(Mat dRdWT, Vec vecX, Vec vecY)
matrix free matrix-vector product function to compute vecY=dRdWT*vecX
void(* pyJacVecProdInterface)(const double *, double *, int, const double *, const double *, int, void *)
void printAllObjFuncs()
calculate the values of all objective functions and print them to screen
List< dictionary > objFuncsAllInstances_
objective function for all instances (unsteady)
void calcdFdBC(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdBC)
compute dFdBC
void resVec2OFResField(const Vec resVec) const
assign the OpenFOAM residual fields based on the resVec
scalar getObjFuncValue(const word objFuncName)
return the value of the objective function
label getGlobalXvIndex(const label idxPoint, const label idxCoord) const
basically, we call DAIndex::getGlobalXvIndex
scalar primalMinRes_
the maximal residual for primal solution
void calcdRdAOATPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdAOATPsi)
compute dRdAOAAD
void calcdFdWAD(const Vec xvVec, const Vec wVec, const word objFuncName, Vec dFdW)
compute dFdW using AD
autoPtr< Time > runTimePtr_
runTime pointer
static void writeMatrixBinary(const Mat matIn, const word prefix)
write petsc matrix in binary format
void getCouplingPatchList(wordList &patchList, word groupName="NONE")
return the coupling patch list if any scenario is active on couplingInfo dict otherwise return design...
void writeVectorBinary(const Vec vecIn, const word prefix)
write petsc vector in binary format
void setThermal(scalar *thermal)
assign temperature values to the conjugate heat transfer patches
label getNLocalAdjointStates() const
return the number of local adjoint states
virtual void initSolver()=0
initialize fields and variables
autoPtr< fvMesh > meshPtr_
fvMesh pointer
void calcCouplingFaceCoordsAD(const double *volCoords, const double *seeds, double *product)
calc matrix-vector products for calcCouplingFaceCoords
void calcForceProfile(Vec center, Vec aForceL, Vec tForceL, Vec rDistL)
calculate the radial profile of the force on the propeller surface
static void writeVectorASCII(const Vec vecIn, const word prefix)
write petsc vector in ascii format
declareRunTimeSelectionTable(autoPtr, DASolver, dictionary,(char *argsAll, PyObject *pyOptions),(argsAll, pyOptions))
autoPtr< argList > argsPtr_
args pointer
void printAllOptions()
print all DAOption
void ofField2StateVec(Vec stateVec) const
set the state vector based on the latest fields in OpenFOAM
static void writeMatrixASCII(const Mat matIn, const word prefix)
write petsc matrix in ascii format
void createMLRKSP(const Mat jacMat, const Mat jacPCMat, KSP ksp)
create a multi-level, Richardson KSP object
void calcdRdWT(const Vec xvVec, const Vec wVec, const label isPC, Mat dRdWT)
compute dRdWT
label checkMesh() const
check the mesh quality and return meshOK
void initOldTimes()
initialize the oldTime for all state variables
label checkResidualTol()
check whether the min residual in primal satisfy the prescribed tolerance
void updateDAOption(PyObject *pyOptions)
update the allOptions_ dict in DAOption based on the pyOptions from pyDAFoam
void(* pyComputeInterface)(const double *, int, double *, int, void *)
void calcdFdAOA(const Vec xvVec, const Vec wVec, const word objFuncName, const word designVarName, Vec dFdAOA)
compute dFdAOA
void getForces(Vec fX, Vec fY, Vec fZ)
return the forces of the desired fluid-structure-interaction patches
label nTimeInstances_
number of time instances for hybird adjoint (unsteady)
Mat dRdWTPC_
the preconditioner matrix for the adjoint linear equation solution
void calcdForcedWAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dForcedW)
void calcResidualVec(Vec resVec)
calculate the residual and assign it to the resVec vector
virtual label runFPAdj(const Vec xvVec, const Vec wVec, Vec dFdW, Vec psi)
solve the adjoint equation using the fixed-point iteration method
void calcdRdFieldTPsiAD(const Vec xvVec, const Vec wVec, const Vec psi, const word designVarName, Vec dRdFieldTPsi)
compute dRdField^T*Psi
void calcdRdThermalTPsiAD(const double *volCoords, const double *states, const double *thermal, const double *seeds, double *product)
void createMLRKSPMatrixFree(const Mat jacPCMat, KSP ksp)
create a multi-level, Richardson KSP object with matrix-free Jacobians
void setPrimalBoundaryConditions(const label printInfo=1)
update the primal state boundary condition based on the primalBC dict
virtual label solvePrimal(const Vec xvVec, Vec wVec)=0
solve the primal equations
autoPtr< DAStateInfo > daStateInfoPtr_
DAStateInfo pointer.
List< List< scalar > > stateAllInstances_
state variable list for all instances (unsteady)
scalar getTimeInstanceObjFunc(const label instanceI, const word objFuncName)
return the value of objective function at the given time instance and name
void calcdForcedXvAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dForcedXv)
compute dForcedXv
scalar periodicity_
periodicity of oscillating flow variables (unsteady)
void calcdForcedStateTPsiAD(const word mode, Vec xvVec, Vec stateVec, Vec psiVec, Vec prodVec)
void readMatrixBinary(Mat matIn, const word prefix)
read petsc matrix in binary format
void calcdRdWOldTPsiAD(const label oldTimeLevel, const Vec psi, Vec dRdWOldTPsi)
compute dRdWOld^T*Psi
label getNCouplingPoints()
Get the number of points for the MDO coupling patches.
void getThermal(const scalar *volCoords, const scalar *states, scalar *thermal)
compute the temperature on the conjugate heat transfer patches
void pointVec2OFMesh(const Vec xvVec) const
assign the points in fvMesh of OpenFOAM based on the point vector
void assignVec2ResidualGradient(Vec vecX)
assign the reverse-mode AD input seeds from vecX to the residuals in OpenFOAM
UPtrList< DAObjFunc > daObjFuncPtrList_
a list of DAObjFunc pointers
List< List< scalar > > stateBoundaryAllInstances_
state boundary variable list for all instances (unsteady)
const volScalarField & psi
Mat dRdWTMF_
matrix-free dRdWT matrix used in GMRES solution
TypeName("DASolver")
Runtime type information.
scalarList avgObjFuncValues_
the averaged objective function values used in unsteady flow
void calcdAcousticsdXvAD(const Vec xvVec, const Vec wVec, const Vec fBarVec, Vec dForcedXv, word varName, word groupName)
compute dAcoudXv
static autoPtr< DASolver > New(char *argsAll, PyObject *pyOptions)