rsvs3D  0.0.0
Codes for the c++ implementation of the 3D RSVS
RSVScalc Class Reference

Class to handle the RSVS calculation. More...

#include <RSVScalc.hpp>

Inheritance diagram for RSVScalc:
rsvs3d::SnakeVelocityCalculator

Public Member Functions

bool UseFullMath () const
 Decides wether full or sparse math should be used. More...
 
void BuildMathArrays (int nDv, int nConstr)
 Builds mathematics arrays. More...
 
void BuildConstrMap (const triangulation &triangleRSVS)
 Builds the constraint mapping. More...
 
void BuildConstrMap (const mesh &meshin)
 Builds the constraint mapping. More...
 
int BuildDVMap (const std::vector< int > &vecin)
 Builds a Design variable map. More...
 
bool SnakDVcond (const triangulation &triRSVS, int ii)
 Returns wether a snaxel is a design variable or not. More...
 
void PrepTriangulationCalc (const triangulation &triRSVS)
 Groups actions needed before the calculation of triangular quantities. More...
 
void CalculateMesh (mesh &meshin)
 Calculates the mesh volumes. More...
 
void CalculateTriangulation (const triangulation &triRSVS, int derivMethod=0)
 Calculates the triangulation volume and area derivatives. More...
 
void CalcTriangle (const triangle &triIn, const triangulation &triRSVS, bool isObj=true, bool isConstr=true, bool isDeriv=true)
 Calculates the properties of single triangle. More...
 
void CalcTriangleFD (const triangle &triIn, const triangulation &triRSVS, bool isObj=true, bool isConstr=true, bool isDeriv=true)
 Calculates the properties of single triangle using Finite difference. More...
 
void CalcTriangleDirectVolume (const triangle &triIn, const triangulation &triRSVS, bool isObj=true, bool isConstr=true, bool isDeriv=true)
 Calculates the properties of single triangle using direct calculation. More...
 
void CalcTriangleEdgeLength (const triangle &triIn, const triangulation &triRSVS, bool isObj=true, bool isConstr=true, bool isDeriv=true)
 Calculates the properties of single triangle for 2D RSVS. More...
 
void ReturnConstrToMesh (triangulation &triRSVS) const
 Returns a constraint to the triangulation::meshDep. More...
 
void ReturnConstrToMesh (mesh &meshin, double volu::*mp=&volu::volume) const
 Returns a constraint to the mesh. More...
 
void CheckAndCompute (int calcMethod=0, bool sensCalc=false)
 Prepare the active arrays for SQP calculation and calculate the SQP step. More...
 
void ComputeSQPstep (int calcMethod, Eigen::MatrixXd &dConstrAct, Eigen::RowVectorXd &dObjAct, Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct)
 Calculates the next SQP step. More...
 
void ComputeSQPstep (int calcMethod, MatrixXd_sparse &dConstrAct, Eigen::RowVectorXd &dObjAct, Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct)
 
void ComputeSQPsens (int calcMethod, const Eigen::MatrixXd &sensMult, const Eigen::MatrixXd &sensInv, Eigen::MatrixXd &sensRes)
 
void ComputeSQPsens (int calcMethod, Eigen::MatrixXd &sensMult, MatrixXd_sparse &sensInv, Eigen::MatrixXd &sensRes)
 
bool PrepareMatricesForSQP (Eigen::MatrixXd &dConstrAct, Eigen::MatrixXd &HConstrAct, Eigen::MatrixXd &HObjAct, MatrixXd_sparse &dConstrAct_sparse, MatrixXd_sparse &HConstrAct_sparse, MatrixXd_sparse &HObjAct_sparse, Eigen::RowVectorXd &dObjAct, Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct)
 Prepares the matrices needed for the SQP step calculation. More...
 
void PrepareMatricesForSQPFull (Eigen::MatrixXd &dConstrAct, Eigen::MatrixXd &HConstrAct, Eigen::MatrixXd &HObjAct)
 
void PrepareMatricesForSQPSparse (MatrixXd_sparse &dConstrAct_sparse, MatrixXd_sparse &HConstrAct_sparse, MatrixXd_sparse &HObjAct_sparse)
 
bool PrepareMatricesForSQPSensitivity (const Eigen::MatrixXd &dConstrAct, const Eigen::MatrixXd &HConstrAct, const Eigen::MatrixXd &HObjAct, Eigen::MatrixXd &sensMult, Eigen::MatrixXd &sensInv, Eigen::MatrixXd &sensRes) const
 Prepares the matrices needed for the calculation of the sensitivity of the SQP. More...
 
bool PrepareMatricesForSQPSensitivity (const MatrixXd_sparse &dConstrAct, const MatrixXd_sparse &HConstrAct, MatrixXd_sparse &HObjAct, Eigen::MatrixXd &sensMult, MatrixXd_sparse &sensInv, Eigen::MatrixXd &sensRes) const
 
void ReturnVelocities (triangulation &triRSVS)
 Returns velocities to the snaxels. More...
 
void ReturnSensitivities (const triangulation &triRSVS, std::vector< double > &sensVec, int constrNum) const
 
void ReturnGradient (const triangulation &triRSVS, std::vector< double > &sensVec, int constrNum) const
 
int numConstr () const
 Getter for the number of constraints. More...
 
void Print2Screen (int outType=0) const
 Prints different amounts of RSVScalc owned data to the screen. More...
 
void ConvergenceLog (std::ofstream &out, int loglvl=3) const
 Print convergence information to file stream. More...
 
void CalculateVelocities (triangulation &triRSVS, int calculationMethod=0, bool calculateDerivatives=true, int derivativeMethod=1) override
 
void setDevParameters (const param::dev::devparam &devset) override
 Set the Development parameters of the Calculator object.
 
void SetUseSurfCentreDeriv (int in)
 
bool GetUseSurfCentreDeriv () const
 
void SetUseSurfCentreHessian (int in)
 
bool SetUseSurfCentreHessian () const
 
void SetSparseDVcutoff (int in)
 
int GetSparseDVcutoff () const
 

Public Attributes

Eigen::MatrixXd dConstr
 Constraint Jacobian, size: [nConstr, nDv].
 
SparseMatrixTriplet dConstr_sparse
 
Eigen::MatrixXd HConstr
 Constraint Hessian, size: [nDv, nDv].
 
SparseMatrixTriplet HConstr_sparse
 
Eigen::MatrixXd HObj
 Objective Hessian, size: [nDv, nDv].
 
SparseMatrixTriplet HObj_sparse
 
Eigen::MatrixXd HLag
 Lagrangian Hessian, size: [nDv, nDv].
 
MatrixXd_sparse HLag_sparse
 
Eigen::RowVectorXd dLag
 
Eigen::RowVectorXd dObj
 Objective Jacobian, size: [1, nDv].
 
Eigen::VectorXd constr
 Constraint value vector, size: [nConstr, 1].
 
Eigen::VectorXd lagMult
 Lagrangian multiplier, size: [nConstr, 1].
 
Eigen::VectorXd deltaDV
 Change in design variable, assigned to snake velocity, size: [nDv, 1].
 
Eigen::VectorXd constrTarg
 Constraint target values, size: [nConstr, 1].
 
Eigen::MatrixXd dvCallConstr
 
Eigen::MatrixXd sensDv
 Sensitivity of the optimum design variables to the constraint.
 
double obj = 0.0
 Objective function value.
 
double limLag = INFINITY
 Value at which a Lagrangian multiplier is considered problematically large.
 
std::vector< bool > isConstrAct
 is the corresponding constraint active?
 
std::vector< bool > isDvAct
 Is the corresponding design variable active?
 
HashedVector< int, int > subConstrAct
 Vector of subscripts of the active constraints.
 
HashedVector< int, int > subDvAct
 Vector of subscripts of the active design variables.
 
HashedVector< int, int > dvMap
 Maps the snake indices to the position in the design variable vector.
 
HashedMap< int, int, int > constrMap
 maps snakemesh() volu onto constr
 
std::vector< std::pair< int, int > > constrList
 keeps pairs with parentindex and voluindex
 

Protected Member Functions

void ZeroTimers ()
 
void PrintTimers () const
 

Protected Attributes

int nDv = 0
 Number of design variables.
 
int nConstr = 0
 Number of constraints.
 
int falseaccess = 0
 Number of false access operations.
 
int sparseDVcutoff = 200
 Number of design variables to start using sparse mathematics.
 
int nonZeroPerDV = 10
 
bool returnDeriv = true
 Return the derivatives (obsolete/unused)
 
bool useSurfCentreDeriv = true
 Enable or disable surfcentroid derivatives.
 
bool useSurfCentreHessian = false
 Enable or disable surfcentroid derivatives.
 
int timer1 = 0
 
int timer2 = 0
 
int timer3 = 0
 

Detailed Description

Class to handle the RSVS calculation.

This class calculates volume and area metrics in a triangulated snake to update the velocity and volumes. It uses an SQP algorithm to compute the velocities.

Definition at line 129 of file RSVScalc.hpp.

Member Function Documentation

◆ BuildConstrMap() [1/2]

void RSVScalc::BuildConstrMap ( const mesh meshin)

Builds the constraint mapping.

Parameters
[in]meshinmesh for constraint building.

Definition at line 505 of file RSVScalc.cpp.

◆ BuildConstrMap() [2/2]

void RSVScalc::BuildConstrMap ( const triangulation triangleRSVS)

Builds the constraint mapping.

Parameters
[in]triangleRSVSTriangulation containing the RSVS.

Definition at line 488 of file RSVScalc.cpp.

◆ BuildDVMap()

int RSVScalc::BuildDVMap ( const std::vector< int > &  vecin)

Builds a Design variable map.

Parameters
[in]vecinThe input vector of design variable indices.
Returns
The number of design variable.

Definition at line 522 of file RSVScalc.cpp.

◆ BuildMathArrays()

void RSVScalc::BuildMathArrays ( int  nDv,
int  nConstr 
)

Builds mathematics arrays.

Parameters
[in]nDvNumber of design variables.
[in]nConstrNumber of constraints.

Definition at line 443 of file RSVScalc.cpp.

◆ CalcTriangle()

void RSVScalc::CalcTriangle ( const triangle triIn,
const triangulation triRSVS,
bool  isObj = true,
bool  isConstr = true,
bool  isDeriv = true 
)

Calculates the properties of single triangle.

These values are returned to the class math arrays.

Parameters
[in]triInThe triangle to measure.
[in]triRSVSThe containing triangulation object.
[in]isObjCalculate objective?
[in]isConstrCalculate constraint?
[in]isDerivCalculate derivatives?

Definition at line 32 of file RSVScalc_core.cpp.

◆ CalcTriangleDirectVolume()

void RSVScalc::CalcTriangleDirectVolume ( const triangle triIn,
const triangulation triRSVS,
bool  isObj = true,
bool  isConstr = true,
bool  isDeriv = true 
)

Calculates the properties of single triangle using direct calculation.

These values are returned to the class math arrays.

Parameters
[in]triInThe triangle to measure.
[in]triRSVSThe containing triangulation object.
[in]isObjCalculate objective?
[in]isConstrCalculate constraint?
[in]isDerivCalculate derivatives?

<--—Change assignement

<--—Change assignement

Definition at line 355 of file RSVScalc_core.cpp.

◆ CalcTriangleEdgeLength()

void RSVScalc::CalcTriangleEdgeLength ( const triangle triIn,
const triangulation triRSVS,
bool  isObj = true,
bool  isConstr = true,
bool  isDeriv = true 
)

Calculates the properties of single triangle for 2D RSVS.

These values are returned to the class math arrays.

Parameters
[in]triInThe triangle to measure.
[in]triRSVSThe containing triangulation object.
[in]isObjCalculate objective?
[in]isConstrCalculate constraint?
[in]isDerivCalculate derivatives?

Definition at line 574 of file RSVScalc_core.cpp.

◆ CalcTriangleFD()

void RSVScalc::CalcTriangleFD ( const triangle triIn,
const triangulation triRSVS,
bool  isObj = true,
bool  isConstr = true,
bool  isDeriv = true 
)

Calculates the properties of single triangle using Finite difference.

These values are returned to the class math arrays.

Parameters
[in]triInThe triangle to measure.
[in]triRSVSThe containing triangulation object.
[in]isObjCalculate objective?
[in]isConstrCalculate constraint?
[in]isDerivCalculate derivatives?

Definition at line 199 of file RSVScalc_core.cpp.

◆ CalculateMesh()

void RSVScalc::CalculateMesh ( mesh meshin)

Calculates the mesh volumes.

Parameters
meshinThe mesh.

Definition at line 294 of file RSVScalc.cpp.

◆ CalculateTriangulation()

void RSVScalc::CalculateTriangulation ( const triangulation triRSVS,
int  derivMethod = 0 
)

Calculates the triangulation volume and area derivatives.

Parameters
[in]triRSVSThe triangle rsvs
[in]derivMethodThe differentiation method to use. 1 : Finite Difference, 2 : Direct calculation, all others : differentiation.

Definition at line 95 of file RSVScalc.cpp.

◆ CheckAndCompute()

void RSVScalc::CheckAndCompute ( int  calcMethod = 0,
bool  sensCalc = false 
)

Prepare the active arrays for SQP calculation and calculate the SQP step.

Parameters
[in]calcMethodCalculation method for SQP. Check :meth:RSVScalc::ComputeSQPstep for detail.

Definition at line 264 of file RSVScalc_SQP.cpp.

◆ ComputeSQPstep()

void RSVScalc::ComputeSQPstep ( int  calcMethod,
Eigen::MatrixXd &  dConstrAct,
Eigen::RowVectorXd &  dObjAct,
Eigen::VectorXd &  constrAct,
Eigen::VectorXd &  lagMultAct 
)

Calculates the next SQP step.

In normal operation the constraint should be 0 through 4. With 0 the default. By adding 10 to these values the "constraint only" mode is enabled which performs a gradient descent step based on the constraint.

Parameters
[in]calcMethodThe calculation method. 10 can be added to all values to enable the "constraint only" mode. Values correspond to the following: Eigen::HouseholderQR (1); * Eigen::ColPivHouseholderQR (2) - Default; Eigen::LLT<Eigen::MatrixXd> (3); Eigen::PartialPivLU (4);
dConstrActThe active constraint Jacobian
dObjActThe active objective Jacobian
constrActThe active constraint values
lagMultActThe active lagrangian multipliers.

◆ ConvergenceLog()

void RSVScalc::ConvergenceLog ( std::ofstream &  out,
int  loglvl = 3 
) const
virtual

Print convergence information to file stream.

Parameters
outThe output filestream
[in]loglvlThe logging detail to output. <1 nothing, ==1 Vector statistics, ==2 ...and constraint vectors, >2 ...and snaxel velocity vector.

Implements rsvs3d::SnakeVelocityCalculator.

Definition at line 531 of file RSVScalc.cpp.

◆ numConstr()

int RSVScalc::numConstr ( ) const
inline

Getter for the number of constraints.

Returns
The number of constraints.

Definition at line 455 of file RSVScalc.hpp.

◆ PrepareMatricesForSQP()

bool RSVScalc::PrepareMatricesForSQP ( Eigen::MatrixXd &  dConstrAct,
Eigen::MatrixXd &  HConstrAct,
Eigen::MatrixXd &  HObjAct,
MatrixXd_sparse &  dConstrAct_sparse,
MatrixXd_sparse &  HConstrAct_sparse,
MatrixXd_sparse &  HObjAct_sparse,
Eigen::RowVectorXd &  dObjAct,
Eigen::VectorXd &  constrAct,
Eigen::VectorXd &  lagMultAct 
)

Prepares the matrices needed for the SQP step calculation.

Parameters
dConstrActThe active constraint Jacobian
HConstrActThe active constraint hessian
HObjActThe active objective hessian
dObjActThe active objective Jacobian
constrActThe active constraint values
lagMultActThe active lagrangian multipliers.
Returns
Returns wether the calculation should be performed or not.

Definition at line 28 of file RSVScalc_SQP.cpp.

◆ PrepareMatricesForSQPSensitivity() [1/2]

bool RSVScalc::PrepareMatricesForSQPSensitivity ( const Eigen::MatrixXd &  dConstrAct,
const Eigen::MatrixXd &  HConstrAct,
const Eigen::MatrixXd &  HObjAct,
Eigen::MatrixXd &  sensMult,
Eigen::MatrixXd &  sensInv,
Eigen::MatrixXd &  sensRes 
) const

Prepares the matrices needed for the calculation of the sensitivity of the SQP.

This is done to then call RSVScalc::ComputeSQPsens which implements the SQP optimality sensitivity giving the change in design variables due to a small change of constraint at the optimal condition.

Parameters
dConstrActThe active constraint Jacobian
HConstrActThe active constraint hessian
HObjActThe active objective hessian
sensMultThe sensitivity RHS multiplier
sensInvThe sensitivity RHS Matrix equation
sensResThe sensitivity LHS result matrix.
Returns
Returns if the sensitivity should be computed or not.

◆ PrepareMatricesForSQPSensitivity() [2/2]

bool RSVScalc::PrepareMatricesForSQPSensitivity ( const MatrixXd_sparse &  dConstrAct,
const MatrixXd_sparse &  HConstrAct,
MatrixXd_sparse &  HObjAct,
Eigen::MatrixXd &  sensMult,
MatrixXd_sparse &  sensInv,
Eigen::MatrixXd &  sensRes 
) const

sensitivity requires : [H_d L , J_d constr; J_d constr ^T, 0]^-1 [Dd^TD_v L (=0s) ; D_V constr (=eye(lagMult))]

Definition at line 215 of file RSVScalc_SQP.cpp.

◆ PrepTriangulationCalc()

void RSVScalc::PrepTriangulationCalc ( const triangulation triRSVS)

Groups actions needed before the calculation of triangular quantities.

Parameters
[in]triRSVSThe triangulation object.

Definition at line 35 of file RSVScalc.cpp.

◆ Print2Screen()

void RSVScalc::Print2Screen ( int  outType = 0) const

Prints different amounts of RSVScalc owned data to the screen.

Parameters
[in]outTypeThe output type to print, values [2,3,4].

Definition at line 334 of file RSVScalc.cpp.

◆ ReturnConstrToMesh() [1/2]

void RSVScalc::ReturnConstrToMesh ( mesh meshin,
double volu::*  mp = &volu::volume 
) const

Returns a constraint to the mesh.

Parameters
meshinThe input mesh.
[in]voluThe volumetric field that data needs to be returned to. It is a member point of class volu.

Definition at line 429 of file RSVScalc.cpp.

◆ ReturnConstrToMesh() [2/2]

void RSVScalc::ReturnConstrToMesh ( triangulation triRSVS) const

Returns a constraint to the triangulation::meshDep.

Parameters
triRSVSThe triangulation object.

Definition at line 400 of file RSVScalc.cpp.

◆ ReturnVelocities()

void RSVScalc::ReturnVelocities ( triangulation triRSVS)

Returns velocities to the snaxels.

Returns velocities to the snake in the triangulation object.

Parameters
triRSVSThe triangulation object, affects the triangulation::snakeDep attribute.
triRSVSThe triangulation object of the RSVS

Definition at line 143 of file RSVScalc.cpp.

◆ SnakDVcond()

bool RSVScalc::SnakDVcond ( const triangulation triRSVS,
int  ii 
)

Returns wether a snaxel is a design variable or not.

If the snaxel is frozen and all its neighbours are frozen, it is not a design variable.

Parameters
[in]triRSVSThe triangulation which is being calculated
[in]iithe snaxel subscript.
Returns
wether the snaxel is design variable or not.

Definition at line 73 of file RSVScalc.cpp.

◆ UseFullMath()

bool RSVScalc::UseFullMath ( ) const
inline

Decides wether full or sparse math should be used.

Returns
True if the number of design variable is small enought to allow full matrix operations and false if the sparse maths should be used.

Definition at line 215 of file RSVScalc.hpp.


The documentation for this class was generated from the following files: