Go to the documentation of this file.
19 #include "runTimeSelectionTables.H"
21 #include "functionObjectList.H"
22 #include "fvOptions.H"
37 #include "volPointInterpolation.H"
39 #include "interpolateSplineXY.H"
127 const label printInterval)
const;
134 const dictionary& maxResConLv4JacPCMat,
135 HashTable<List<List<word>>>& stateResConInfo)
const;
183 PyObject* pyOptions),
184 (argsAll, pyOptions));
191 PyObject* pyOptions);
196 static autoPtr<DASolver>
New(
198 PyObject* pyOptions);
232 const fvSchemes& myFvSchemes =
meshPtr_->thisDb().lookupObject<fvSchemes>(
"fvSchemes");
234 word ddtSchemeName = myFvSchemes.subDict(
"ddtSchemes").getWord(
"default");
236 if (ddtSchemeName ==
"steadyState")
240 if (ddtSchemeName ==
"Euler")
244 else if (ddtSchemeName ==
"backward")
250 FatalErrorIn(
"") <<
"ddtScheme " << ddtSchemeName <<
" not supported! Options: steadyState, Euler, or backward"
251 << abort(FatalError);
260 Info <<
"ExecutionTime = " <<
runTime.elapsedCpuTime() <<
" s"
261 <<
" ClockTime = " <<
runTime.elapsedClockTime() <<
" s"
296 const word fieldName,
297 const word fieldType,
305 const word inputName,
306 const word inputType);
310 const word outputName,
311 const word outputType);
315 const word inputName,
316 const word inputType);
320 const word outputName,
321 const word outputType);
325 const word outputName,
326 const word outputType,
334 const word inputName,
335 const word inputType,
337 const word outputName,
338 const word outputType,
343 const word inputName,
344 const word inputType,
356 const label oldTimeLevel,
358 double* dRdWOldTPsi);
362 const scalar* volCoords,
395 const label oldTimeLevel = 0);
402 const word inputName,
428 const label idxPoint,
429 const label idxCoord)
const
431 return daIndexPtr_->getGlobalXvIndex(idxPoint, idxCoord);
522 if (functionName1 == functionName)
536 scalar
getdFScaling(
const word functionName,
const label timeIdx);
541 Info <<
"DAFoam option dictionary: ";
548 const label writeRes = 0);
564 const word fieldName,
565 const word fieldType);
667 label oldTimeLevel = 0);
699 const label writeMesh,
700 const wordList& additionalOutput);
717 codi::RealReverse::Tape& globalADTape_;
722 template<
class classType>
726 template<
class classType>
744 const double timeName);
749 const double* dFdField,
750 const word fieldType,
751 const double timeName);
757 scalar latestTime = timeDirs.last().value();
764 const double writeTime,
770 template<
class classType>
780 const scalar& val = field[idxI];
781 if (std::isnan(val) || std::isinf(val) || fabs(val) > 1e15)
786 forAll(field.boundaryField(), patchI)
788 forAll(field.boundaryField()[patchI], faceI)
790 const scalar& val = field.boundaryField()[patchI][faceI];
791 if (std::isnan(val) || std::isinf(val) || fabs(val) > 1e15)
801 template<
class classType>
811 for (label compI = 0; compI < 3; compI++)
813 const scalar& val = field[idxI][compI];
814 if (std::isnan(val) || std::isinf(val) || fabs(val) > 1e15)
820 forAll(field.boundaryField(), patchI)
822 forAll(field.boundaryField()[patchI], faceI)
824 for (label compI = 0; compI < 3; compI++)
826 const scalar& val = field.boundaryField()[patchI][faceI][compI];
827 if (std::isnan(val) || std::isinf(val) || fabs(val) > 1e15)
void writeSensMapField(const word name, const double *dFdField, const word fieldType, const double timeName)
write the sensitivity map for the entire field
static void readMatrixBinary(Mat matIn, const word prefix)
read petsc matrix in binary format
char * argsAll_
all the arguments
void setTime(scalar time, label timeIndex)
setTime for OF fields
void writeFailedMesh()
write the failed mesh to disk
void writeMatrixBinary(const Mat matIn, const word prefix)
write the matrix in binary format
void calcCouplingFaceCoords(const scalar *volCoords, scalar *surfCoords)
return the face coordinates based on vol coords
label checkPrimalFailure()
check whether the primal fails based on residual and regression fail flag
label getInputDistributed(const word inputName, const word inputType)
get whether the input is distributed among processors
void updateStateBoundaryConditions()
update the boundary conditions for all states and intermediate variables
static pyJacVecProdInterface pyCalcBetaJacVecProdInterface
label loop(Time &runTime)
return whether to loop the primal solution, similar to runTime::loop() except we don't do file IO
label printToScreen_
whether to print primal information to the screen
void calcdRdWOldTPsiAD(const label oldTimeLevel, const double *psi, double *dRdWOldTPsi)
compute dRdWOld^T*Psi
autoPtr< DACheckMesh > daCheckMeshPtr_
DACheckMesh object pointer.
const DAModel & getDAModel()
get DAModel object
HashTable< wordList > stateInfo_
the stateInfo_ list from DAStateInfo object
void initDynamicMesh()
resetting internal info in fvMesh, which is needed for multiple primal runs
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
autoPtr< DARegression > daRegressionPtr_
DARegression pointer.
autoPtr< DAModel > daModelPtr_
DAModel pointer.
void runColoring()
run the coloring solver
static pyComputeInterface pyCalcBetaInterface
void initInputFieldUnsteady()
initialize inputFieldUnsteady from the GlobalVar class
label getNLocalPoints() const
return the number of local points
label getInputSize(const word inputName, const word inputType)
get the array size of an input type
void registerStateVariableInput4AD(const label oldTimeLevel=0)
register all state variables as the input for reverse-mode AD
label hasVolCoordInput()
whether the volCoord input is defined
autoPtr< DAIndex > daIndexPtr_
DAIndex pointer.
label primalFinalTimeIndex_
the final time index from the primal solve. for steady state cases it can converge before endTime
void calcdRdWT(const label isPC, Mat dRdWT)
compute dRdWT
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
autoPtr< DAResidual > daResidualPtr_
DAResidual pointer.
void normalizeGradientVec(double *vecY)
normalize the reverse-mode AD derivatives stored in vecY
void initializedRdWTMatrixFree()
initialize matrix free dRdWT
void destroydRdWTMatrixFree()
destroy the matrix free dRdWT
double getTimeOpFuncVal(const word functionName)
get the function value based on timeOp
scalar primalMinResTol_
primal residual tolerance
void(* pySetCharInterface)(const char *, void *)
void updateOFMesh(const scalar *volCoords)
Update the OpenFoam mesh point coordinates based on the volume point coords array.
label getNLocalCells() const
return the number of local cells
void initTensorFlowFuncs(pyComputeInterface computeInterface, void *compute, pyJacVecProdInterface jacVecProdInterface, void *jacVecProd, pySetCharInterface setModelNameInterface, void *setModelName)
initialize tensorflow functions and interfaces for callback
void calcOutput(const word outputName, const word outputType, double *output)
get whether the output is distributed among processors
autoPtr< DAField > daFieldPtr_
DAField pointer.
void initializeGlobalADTape4dRdWT()
initialize the CoDiPack reverse-mode AD global tape for computing dRdWT*psi
virtual label solvePrimal()=0
solve the primal equations
label getDdtSchemeOrder()
get the ddtScheme order
void assignVec2ResidualGradient(const double *vecX)
assign the reverse-mode AD input seeds from vecX to the residuals in OpenFOAM
static void * pyCalcBetaJacVecProd
static pySetCharInterface pySetModelNameInterface
label getNLocalAdjointBoundaryStates() const
return the number of local adjoint boundary states
const DAField & getDAField()
get DAField object
autoPtr< DAOption > daOptionPtr_
DAOption pointer.
PyObject * pyOptions_
all options in DAFoam
void registerResidualOutput4AD()
register all residuals as the output for reverse-mode AD
void calcJacTVecProduct(const word inputName, const word inputType, const double *input, const word outputName, const word outputType, const double *seed, double *product)
calculate the Jacobian-matrix-transposed and vector product for product = [dOutput/dInput]^T * seed
void getOFMeshPoints(double *points)
get the flatten mesh points coordinates
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
void updateKSPPCMat(Mat PCMat, KSP ksp)
Update the preconditioner matrix for the ksp object.
label solveLinearEqn(const KSP ksp, const Vec rhsVec, Vec solVec)
solve the linear equation given a ksp and right-hand-side vector
void resetStateVals()
reset the states to its initial values this usually happens when we have nan in states
void readVectorBinary(Vec vecIn, const word prefix)
read petsc vector in binary format
void readMeshPoints(const scalar timeVal)
read the mesh points from the disk and run movePoints to deform the mesh
const DAStateInfo & getDAStateInfo()
get DAStateInfo object
void setDAFunctionList()
initialize DASolver::daFunctionPtrList_ one needs to call this before calling printAllFunctions
label globalADTape4dRdWTInitialized
a flag in dRdWTMatVecMultFunction to determine if the global tap is initialized
void getInitStateVals(HashTable< scalar > &initState)
calculate the initial value for validate states
UPtrList< DAFunction > daFunctionPtrList_
a list of DAFunction pointers
label printIntervalUnsteady_
how frequent do you want to print the primal info default is every 100 steps
void writeMeshPoints(const double *points, const scalar timeVal)
write the mesh points to the disk for the given timeVal
void normalizeJacTVecProduct(const word inputName, double *product)
normalize the jacobian vector product that has states as the input such as dFdW and dRdW
UPtrList< DATimeOp > daTimeOpPtrList_
a list of DATimeOp pointers
label isPrintTime(const Time &runTime, const label printInterval) const
const DAResidual & getDAResidual()
get DAResidual object
static void * pySetModelName
autoPtr< DALinearEqn > daLinearEqnPtr_
DALinearEqn pointer.
const DAIndex & getDAIndex()
get DAIndex object
void updateOFFields(const scalar *states)
Update the OpenFOAM field values (including both internal and boundary fields) based on the state arr...
static void writeVectorBinary(const Vec vecIn, const word prefix)
write petsc vector in binary format
word getFunctionName()
return the name of objective function
void writeSensMapSurface(const word name, const double *dFdXs, const double *Xs, const label size, const double timeName)
write the sensitivity map for all wall surfaces
void updateBoundaryConditions(const word fieldName, const word fieldType)
update the boundary condition for a field
label validateVectorField(const classType &field)
check if a field variable has nan
HashTable< scalar > initStateVals_
initial values for validateStates
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
label validateStates()
check if the state variables have valid values
void setRegressionParameter(word modelName, const label idxI, scalar val)
set the regression parameter
void deactivateStateVariableInput4AD(const label oldTimeLevel=0)
deactivate all state variables as the input for reverse-mode AD
label getOutputDistributed(const word outputName, const word outputType)
get whether the output is distributed among processors
void writeMatrixASCII(const Mat matIn, const word prefix)
write the matrix in ASCII format
label primalMinIters_
primal min number of iterations
void regressionModelCompute()
call the compute method of the regression model
void calcResiduals(label isPC=0)
calculate the residuals
void readStateVars(scalar timeVal, label oldTimeLevel=0)
read the state variables from the disk and assign the value to the prescribe time level
scalar prevPrimalSolTime_
the solution time for the previous primal solution
label validateField(const classType &field)
check if a field variable has nan
const DAOption & getDAOption()
get DAOption object
void setSolverInput(const word inputName, const word inputType, const int inputSize, const double *input, const double *seed)
void writeAssociatedFields()
write associated fields such as relative velocity
scalar getdFScaling(const word functionName, const label timeIdx)
get the scaling factor for dF/d? derivative computation
label getOutputSize(const word outputName, const word outputType)
get the array size of an output type
static PetscErrorCode dRdWTMatVecMultFunction(Mat dRdWT, Vec vecX, Vec vecY)
matrix free matrix-vector product function to compute vecY=dRdWT*vecX
scalar getLatestTime()
get the latest time solution from the case folder.
void(* pyJacVecProdInterface)(const double *, double *, int, const double *, const double *, int, void *)
void assignStateGradient2Vec(double *vecY, const label oldTimeLevel=0)
set the reverse-mode AD derivatives from the state variables in OpenFOAM to vecY
label regModelFail_
whether the regModel compute fails
scalar getElapsedClockTime()
return the elapsed clock time for testing speed
void meanStatesToStates()
assign the mean states values to states
scalar getElapsedCpuTime()
return the elapsed CPU time for testing speed
label getGlobalXvIndex(const label idxPoint, const label idxCoord) const
basically, we call DAIndex::getGlobalXvIndex
void calcPCMatWithFvMatrix(Mat PCMat, const label turbOnly=0)
calculate the PC mat using fvMatrix
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...
scalar getRegressionParameter(word modelName, const label idxI)
get the regression parameter
void writeVectorBinary(const Vec vecIn, const word prefix)
write petsc vector in binary format
label getNLocalAdjointStates() const
return the number of local adjoint states
label printInterval_
how frequent do you want to print the primal info default is every 100 steps
virtual void initSolver()=0
initialize fields and variables
autoPtr< fvMesh > meshPtr_
fvMesh pointer
label getNRegressionParameters(word modelName)
get the number of regression model parameters
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
static void writeMatrixASCII(const Mat matIn, const word prefix)
write petsc matrix in ascii format
void getOFFields(scalar *states)
assign the state variables from OpenFoam layer to the states array
label checkMesh() const
check the mesh quality and return meshOK
virtual label solveAdjointFP(Vec dFdW, Vec psi)
solve the adjoint equation using the fixed-point iteration method
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 writeAdjointFields(const word function, const double writeTime, const double *psi)
write the adjoint variables for all states
void updateInputFieldUnsteady()
assign the inputFieldUnsteady values to the OF field vars
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
autoPtr< DAStateInfo > daStateInfoPtr_
DAStateInfo pointer.
virtual label runFPAdj(Vec dFdW, Vec psi)
solve the adjoint equation using the fixed-point iteration method
void getOFField(const word fieldName, const word fieldType, double *field)
get a field variable from OF layer
void readMatrixBinary(Mat matIn, const word prefix)
read petsc matrix in binary format
autoPtr< pointField > points0Ptr_
the initial points for dynamicMesh without volCoord inputs
void writeAdjStates(const label writeMesh, const wordList &additionalOutput)
write state variables that are NO_WRITE to disk
void printElapsedTime(const Time &runTime, const label printToScreen)
const volScalarField & psi
Mat dRdWTMF_
matrix-free dRdWT matrix used in GMRES solution
List< scalarList > functionTimeSteps_
a list list that saves the function value for all time steps
TypeName("DASolver")
Runtime type information.
label getFunctionListIndex(const word functionName)
return the index of a give functionName in daFunctionPtrList_
void calcAllFunctions(label print=0)
calculate the values of all objective functions and print them to screen
static autoPtr< DASolver > New(char *argsAll, PyObject *pyOptions)
autoPtr< DAGlobalVar > daGlobalVarPtr_
DAGlobalVar pointer.