7 #ifndef RSVSCALC_H_INCLUDED
8 #define RSVSCALC_H_INCLUDED
37 typedef Eigen::SparseMatrix<double, Eigen::ColMajor> MatrixXd_sparse;
69 return this->valueVal;
79 double &operator()(
int a,
int b)
82 if (a < 0 || a >= this->nRow || b < 0 || b >= this->nCol)
87 return TripletMap::operator()(a + this->nRow * b);
89 const double &operator()(
int a,
int b)
const
92 if (a < 0 || a >= this->nRow || b < 0 || b >= this->nCol)
97 return TripletMap::operator()(a + this->nRow * b);
100 double &coeffRef(
int a,
int b)
102 return this->operator()(a, b);
104 void resize(
int row,
int col)
111 this->TripletMap::clear();
115 return this->TripletMap::size();
117 void reserve(
size_t a);
118 void SetEqual(MatrixXd_sparse &targ);
119 void SetEqual(Eigen::MatrixXd &targ);
141 int nonZeroPerDV = 10;
158 void PrintTimers()
const;
172 MatrixXd_sparse HLag_sparse;
173 Eigen::RowVectorXd dLag;
185 Eigen::MatrixXd dvCallConstr;
248 int BuildDVMap(
const std::vector<int> &vecin);
300 bool isDeriv =
true);
314 bool isDeriv =
true);
328 bool isConstr =
true,
bool isDeriv =
true);
342 bool isConstr =
true,
bool isDeriv =
true);
388 void ComputeSQPstep(
int calcMethod, Eigen::MatrixXd &dConstrAct, Eigen::RowVectorXd &dObjAct,
389 Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct);
390 void ComputeSQPstep(
int calcMethod, MatrixXd_sparse &dConstrAct, Eigen::RowVectorXd &dObjAct,
391 Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct);
393 void ComputeSQPsens(
int calcMethod,
const Eigen::MatrixXd &sensMult,
const Eigen::MatrixXd &sensInv,
394 Eigen::MatrixXd &sensRes);
395 void ComputeSQPsens(
int calcMethod, Eigen::MatrixXd &sensMult, MatrixXd_sparse &sensInv, Eigen::MatrixXd &sensRes);
409 bool PrepareMatricesForSQP(Eigen::MatrixXd &dConstrAct, Eigen::MatrixXd &HConstrAct, Eigen::MatrixXd &HObjAct,
410 MatrixXd_sparse &dConstrAct_sparse, MatrixXd_sparse &HConstrAct_sparse,
411 MatrixXd_sparse &HObjAct_sparse, Eigen::RowVectorXd &dObjAct, Eigen::VectorXd &constrAct,
412 Eigen::VectorXd &lagMultAct);
414 void PrepareMatricesForSQPFull(Eigen::MatrixXd &dConstrAct, Eigen::MatrixXd &HConstrAct, Eigen::MatrixXd &HObjAct);
415 void PrepareMatricesForSQPSparse(MatrixXd_sparse &dConstrAct_sparse, MatrixXd_sparse &HConstrAct_sparse,
416 MatrixXd_sparse &HObjAct_sparse);
435 const Eigen::MatrixXd &HObjAct, Eigen::MatrixXd &sensMult,
436 Eigen::MatrixXd &sensInv, Eigen::MatrixXd &sensRes)
const;
438 MatrixXd_sparse &HObjAct, Eigen::MatrixXd &sensMult, MatrixXd_sparse &sensInv,
439 Eigen::MatrixXd &sensRes)
const;
448 void ReturnSensitivities(
const triangulation &triRSVS, std::vector<double> &sensVec,
int constrNum)
const;
449 void ReturnGradient(
const triangulation &triRSVS, std::vector<double> &sensVec,
int constrNum)
const;
457 return (this->nConstr);
478 void CalculateVelocities(
triangulation &triRSVS,
int calculationMethod = 0,
bool calculateDerivatives =
true,
479 int derivativeMethod = 1)
override;
481 void SetUseSurfCentreDeriv(
int in)
483 this->useSurfCentreDeriv = in;
485 bool GetUseSurfCentreDeriv()
const
487 return (this->useSurfCentreDeriv);
489 void SetUseSurfCentreHessian(
int in)
491 this->useSurfCentreHessian = in;
493 bool SetUseSurfCentreHessian()
const
495 return (this->useSurfCentreHessian);
497 void SetSparseDVcutoff(
int in)
499 this->sparseDVcutoff = in;
501 int GetSparseDVcutoff()
const
503 return (this->sparseDVcutoff);
Interface for the Snaking algorithm.
Provide std::vector container with hashed index mapping.
Class to handle the RSVS calculation.
void CalculateMesh(mesh &meshin)
Calculates the mesh volumes.
Eigen::RowVectorXd dObj
Objective Jacobian, size: [1, nDv].
Eigen::VectorXd constr
Constraint value vector, size: [nConstr, 1].
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.
void PrepTriangulationCalc(const triangulation &triRSVS)
Groups actions needed before the calculation of triangular quantities.
Eigen::MatrixXd dConstr
Constraint Jacobian, size: [nConstr, nDv].
Eigen::MatrixXd sensDv
Sensitivity of the optimum design variables to the constraint.
Eigen::MatrixXd HConstr
Constraint Hessian, size: [nDv, nDv].
void CalcTriangle(const triangle &triIn, const triangulation &triRSVS, bool isObj=true, bool isConstr=true, bool isDeriv=true)
Calculates the properties of single triangle.
HashedMap< int, int, int > constrMap
maps snakemesh() volu onto constr
int BuildDVMap(const std::vector< int > &vecin)
Builds a Design variable map.
Eigen::VectorXd deltaDV
Change in design variable, assigned to snake velocity, size: [nDv, 1].
void ReturnConstrToMesh(triangulation &triRSVS) const
Returns a constraint to the triangulation::meshDep.
void CheckAndCompute(int calcMethod=0, bool sensCalc=false)
Prepare the active arrays for SQP calculation and calculate the SQP step.
int falseaccess
Number of false access operations.
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.
std::vector< bool > isConstrAct
is the corresponding constraint active?
void BuildConstrMap(const triangulation &triangleRSVS)
Builds the constraint mapping.
Eigen::MatrixXd HObj
Objective Hessian, size: [nDv, nDv].
int sparseDVcutoff
Number of design variables to start using sparse mathematics.
bool useSurfCentreDeriv
Enable or disable surfcentroid derivatives.
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.
void CalculateTriangulation(const triangulation &triRSVS, int derivMethod=0)
Calculates the triangulation volume and area derivatives.
Eigen::MatrixXd HLag
Lagrangian Hessian, size: [nDv, nDv].
HashedVector< int, int > subConstrAct
Vector of subscripts of the active constraints.
int nConstr
Number of constraints.
void setDevParameters(const param::dev::devparam &devset) override
Set the Development parameters of the Calculator object.
std::vector< bool > isDvAct
Is the corresponding design variable active?
bool useSurfCentreHessian
Enable or disable surfcentroid derivatives.
bool SnakDVcond(const triangulation &triRSVS, int ii)
Returns wether a snaxel is a design variable or not.
int nDv
Number of design variables.
double obj
Objective function value.
void Print2Screen(int outType=0) const
Prints different amounts of RSVScalc owned data to the screen.
bool returnDeriv
Return the derivatives (obsolete/unused)
bool UseFullMath() const
Decides wether full or sparse math should be used.
int numConstr() const
Getter for the number of constraints.
void ComputeSQPstep(int calcMethod, Eigen::MatrixXd &dConstrAct, Eigen::RowVectorXd &dObjAct, Eigen::VectorXd &constrAct, Eigen::VectorXd &lagMultAct)
Calculates the next SQP step.
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.
std::vector< std::pair< int, int > > constrList
keeps pairs with parentindex and voluindex
void ReturnVelocities(triangulation &triRSVS)
Returns velocities to the snaxels.
HashedVector< int, int > subDvAct
Vector of subscripts of the active design variables.
void BuildMathArrays(int nDv, int nConstr)
Builds mathematics arrays.
Eigen::VectorXd lagMult
Lagrangian multiplier, size: [nConstr, 1].
double limLag
Value at which a Lagrangian multiplier is considered problematically large.
Eigen::VectorXd constrTarg
Constraint target values, size: [nConstr, 1].
HashedVector< int, int > dvMap
Maps the snake indices to the position in the design variable vector.
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.
void ConvergenceLog(std::ofstream &out, int loglvl=3) const
Print convergence information to file stream.
Class for development parameters.
A base class which needs to be inherited from to implement a new velocity calculation.
Class for volume cell objects in a mesh.
Provides all the mesh tools used for the generation of 3D grids and geometries.
Namespace containing the parameter classes used to control execution of the 3D-RSVS program.
Provides the core restricted surface snake container.
Provides a triangulation for snake and meshes.
Provides the error and warning system used by the RSVS3D project.
#define RSVS3D_ERROR_RANGE(M)
Throw a range_error.