Skip to content

Commit 102d927

Browse files
authored
Merge pull request #2776 from su2code/pedro/cleanup_elasticity
Cleanup elasticity numerics
2 parents 8dc22dd + 99c1203 commit 102d927

15 files changed

Lines changed: 245 additions & 624 deletions

File tree

Common/include/geometry/elements/CElement.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ class CElement {
249249
* \param[in] nodeB - index of Node b.
250250
* \param[in] val_Kab - value of the matrix K.
251251
*/
252-
inline void Add_Kab(unsigned short nodeA, unsigned short nodeB, su2double** val_Kab) {
252+
template <typename Matrix>
253+
inline void Add_Kab(unsigned short nodeA, unsigned short nodeB, Matrix& val_Kab) {
253254
for (unsigned short iDim = 0; iDim < nDim; iDim++)
254255
for (unsigned short jDim = 0; jDim < nDim; jDim++) Kab[nodeA](nodeB, iDim * nDim + jDim) += val_Kab[iDim][jDim];
255256
}
@@ -259,7 +260,8 @@ class CElement {
259260
* transpose) \param[in] nodeA - index of Node a. \param[in] nodeB - index of Node b. \param[in] val_Kab - value of
260261
* the matrix K.
261262
*/
262-
inline void Add_Kab_T(unsigned short nodeA, unsigned short nodeB, su2double** val_Kab) {
263+
template <typename Matrix>
264+
inline void Add_Kab_T(unsigned short nodeA, unsigned short nodeB, Matrix& val_Kab) {
263265
for (unsigned short iDim = 0; iDim < nDim; iDim++)
264266
for (unsigned short jDim = 0; jDim < nDim; jDim++) Kab[nodeA](nodeB, iDim * nDim + jDim) += val_Kab[jDim][iDim];
265267
}

Common/include/linear_algebra/CPastixWrapper.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class CPastixWrapper {
5757
pastix_int_t nCols; /*!< \brief Local number of columns. */
5858
vector<pastix_int_t> colptr; /*!< \brief Equiv. to our "row_ptr". */
5959
vector<pastix_int_t> rowidx; /*!< \brief Equiv. to our "col_ind". */
60-
vector<passivedouble> values; /*!< \brief Equiv. to our "matrix". */
60+
vector<su2mixedfloat> values; /*!< \brief Equiv. to our "matrix". */
6161
vector<pastix_int_t> loc2glb; /*!< \brief Global index of the columns held by this rank. */
6262
vector<pastix_int_t> perm; /*!< \brief Ordering computed by PaStiX. */
63-
vector<passivedouble> workvec; /*!< \brief RHS vector which then becomes the solution. */
63+
vector<su2mixedfloat> workvec; /*!< \brief RHS vector which then becomes the solution. */
6464

6565
pastix_int_t iparm[IPARM_SIZE]; /*!< \brief Integer parameters for PaStiX. */
6666
passivedouble dparm[DPARM_SIZE]; /*!< \brief Floating point parameters for PaStiX. */

Common/src/linear_algebra/CPastixWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void CPastixWrapper<ScalarType>::Initialize(CGeometry* geometry, const CConfig*
181181

182182
spmInitDist(&spm, SU2_MPI::GetComm());
183183
spm.mtxtype = SpmGeneral; // Despite being symmetric, we store the entire matrix.
184-
spm.flttype = SpmDouble;
184+
spm.flttype = std::is_same_v<su2mixedfloat, double> ? SpmDouble : SpmFloat;
185185
spm.fmttype = SpmCSC;
186186
spm.layout = SpmColMajor;
187187
spm.baseval = 1;

SU2_CFD/include/numerics/elasticity/CFEAElasticity.hpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#pragma once
2929

30+
#include <memory>
3031
#include "../CNumerics.hpp"
3132
#include "../../../../Common/include/geometry/elements/CElement.hpp"
3233

@@ -61,23 +62,17 @@ class CFEAElasticity : public CNumerics {
6162
su2double Kappa = 0.0; /*!< \brief Aux. variable, Compressibility constant. */
6263
su2double ThermalStressTerm = 0.0; /*!< \brief Aux. variable, Relationship between stress and delta T. */
6364

64-
su2double *E_i = nullptr; /*!< \brief Young's modulus of elasticity. */
65-
su2double *Nu_i = nullptr; /*!< \brief Poisson's ratio. */
66-
su2double *Rho_s_i = nullptr; /*!< \brief Structural density. */
67-
su2double *Rho_s_DL_i = nullptr; /*!< \brief Structural density (for dead loads). */
68-
su2double *Alpha_i = nullptr; /*!< \brief Thermal expansion coefficient. */
65+
std::unique_ptr<su2double[]> E_i; /*!< \brief Young's modulus of elasticity. */
66+
std::unique_ptr<su2double[]> Nu_i; /*!< \brief Poisson's ratio. */
67+
std::unique_ptr<su2double[]> Rho_s_i; /*!< \brief Structural density. */
68+
std::unique_ptr<su2double[]> Rho_s_DL_i; /*!< \brief Structural density (for dead loads). */
69+
std::unique_ptr<su2double[]> Alpha_i; /*!< \brief Thermal expansion coefficient. */
6970

7071
su2double ReferenceTemperature = 0.0; /*!< \brief Reference temperature for thermal expansion. */
7172

72-
su2double **Ba_Mat = nullptr; /*!< \brief Matrix B for node a - Auxiliary. */
73-
su2double **Bb_Mat = nullptr; /*!< \brief Matrix B for node b - Auxiliary. */
74-
su2double *Ni_Vec = nullptr; /*!< \brief Vector of shape functions - Auxiliary. */
75-
su2double **D_Mat = nullptr; /*!< \brief Constitutive matrix - Auxiliary. */
76-
su2double **KAux_ab = nullptr; /*!< \brief Node ab stiffness matrix - Auxiliary. */
77-
su2double **GradNi_Ref_Mat = nullptr; /*!< \brief Gradients of Ni - Auxiliary. */
78-
su2double **GradNi_Curr_Mat = nullptr; /*!< \brief Gradients of Ni - Auxiliary. */
73+
su2double D_Mat[DIM_STRAIN_3D][DIM_STRAIN_3D]; /*!< \brief Constitutive matrix - Auxiliary. */
7974

80-
su2double *DV_Val = nullptr; /*!< \brief For optimization cases, value of the design variables. */
75+
std::unique_ptr<su2double[]> DV_Val; /*!< \brief For optimization cases, value of the design variables. */
8176
unsigned short n_DV = 0; /*!< \brief For optimization cases, number of design variables. */
8277

8378
bool plane_stress = false; /*!< \brief Checks if we are solving a plane stress case. */
@@ -97,11 +92,6 @@ class CFEAElasticity : public CNumerics {
9792
*/
9893
CFEAElasticity(unsigned short val_nDim, unsigned short val_nVar, const CConfig *config);
9994

100-
/*!
101-
* \brief Destructor of the class.
102-
*/
103-
~CFEAElasticity(void) override;
104-
10595
/*!
10696
* \brief Set elasticity modulus and Poisson ratio.
10797
* \param[in] iVal - Index of the property.
@@ -245,4 +235,25 @@ class CFEAElasticity : public CNumerics {
245235
return static_cast<passivedouble>(iVar == jVar);
246236
}
247237

238+
template <typename Mat1, typename Mat2>
239+
void FillBMat(unsigned short iNode, const Mat1& GradNi_Mat, Mat2& B_Mat) const {
240+
if (nDim == 2) {
241+
B_Mat[0][0] = GradNi_Mat[iNode][0];
242+
B_Mat[1][1] = GradNi_Mat[iNode][1];
243+
B_Mat[2][0] = GradNi_Mat[iNode][1];
244+
B_Mat[2][1] = GradNi_Mat[iNode][0];
245+
}
246+
else {
247+
B_Mat[0][0] = GradNi_Mat[iNode][0];
248+
B_Mat[1][1] = GradNi_Mat[iNode][1];
249+
B_Mat[2][2] = GradNi_Mat[iNode][2];
250+
B_Mat[3][0] = GradNi_Mat[iNode][1];
251+
B_Mat[3][1] = GradNi_Mat[iNode][0];
252+
B_Mat[4][0] = GradNi_Mat[iNode][2];
253+
B_Mat[4][2] = GradNi_Mat[iNode][0];
254+
B_Mat[5][1] = GradNi_Mat[iNode][2];
255+
B_Mat[5][2] = GradNi_Mat[iNode][1];
256+
}
257+
}
258+
248259
};

SU2_CFD/include/numerics/elasticity/CFEALinearElasticity.hpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ class CFEALinearElasticity : public CFEAElasticity {
5555
*/
5656
CFEALinearElasticity(unsigned short val_nDim, unsigned short val_nVar, const CConfig *config);
5757

58-
/*!
59-
* \brief Destructor of the class.
60-
*/
61-
~CFEALinearElasticity(void) override = default;
62-
6358
/*!
6459
* \brief Build the tangent stiffness matrix of an element.
6560
* \param[in,out] element_container - Element whose tangent matrix is being built.
@@ -110,11 +105,6 @@ class CFEAMeshElasticity final : public CFEALinearElasticity {
110105
*/
111106
CFEAMeshElasticity(unsigned short val_nDim, unsigned short val_nVar, unsigned long val_nElem, const CConfig *config);
112107

113-
/*!
114-
* \brief Destructor of the class.
115-
*/
116-
~CFEAMeshElasticity(void) override = default;
117-
118108
/*!
119109
* \brief Set the element-based local Young's modulus in mesh problems
120110
* \param[in] iElem - Element index.

SU2_CFD/include/numerics/elasticity/CFEANonlinearElasticity.hpp

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,39 +43,29 @@ class CFEANonlinearElasticity : public CFEAElasticity {
4343

4444
protected:
4545

46-
su2double **F_Mat; /*!< \brief Deformation gradient. */
47-
su2double **b_Mat; /*!< \brief Left Cauchy-Green Tensor. */
48-
su2double **currentCoord; /*!< \brief Current coordinates. */
49-
su2double **Stress_Tensor; /*!< \brief Cauchy stress tensor */
50-
51-
su2double **FmT_Mat; /*!< \brief Deformation gradient inverse and transpose. */
52-
53-
su2double **KAux_P_ab; /*!< \brief Auxiliar matrix for the pressure term */
54-
su2double *KAux_t_a; /*!< \brief Auxiliar matrix for the pressure term */
46+
su2double F_Mat[MAXNDIM][MAXNDIM]; /*!< \brief Deformation gradient. */
47+
su2double b_Mat[MAXNDIM][MAXNDIM]; /*!< \brief Left Cauchy-Green Tensor. */
48+
su2double Stress_Tensor[MAXNDIM][MAXNDIM];
5549

5650
su2double J_F; /*!< \brief Jacobian of the transformation (determinant of F) */
5751

5852
su2double f33; /*!< \brief Plane stress term for non-linear 2D plane stress analysis */
5953

6054
bool nearly_incompressible; /*!< \brief Boolean to consider nearly_incompressible effects */
6155

62-
su2double **F_Mat_Iso; /*!< \brief Isocoric component of the deformation gradient. */
63-
su2double **b_Mat_Iso; /*!< \brief Isocoric component of the left Cauchy-Green tensor. */
64-
65-
su2double C10, D1; /*!< \brief C10 = Mu/2. D1 = Kappa/2. */
66-
su2double J_F_Iso; /*!< \brief J_F_Iso: det(F)^-1/3. */
56+
su2double b_Mat_Iso[MAXNDIM][MAXNDIM]; /*!< \brief Isocoric component of the left Cauchy-Green tensor. */
6757

6858
su2double cijkl[3][3][3][3]; /*!< \brief Constitutive tensor i,j,k,l (defined only for incompressibility - near inc.). */
6959

7060
bool maxwell_stress; /*!< \brief Consider the effects of the dielectric loads */
7161

72-
su2double *EField_Ref_Unit, /*!< \brief Electric Field, unitary, in the reference configuration. */
73-
*EField_Ref_Mod; /*!< \brief Electric Field, modulus, in the reference configuration. */
74-
su2double *EField_Curr_Unit; /*!< \brief Auxiliary vector for the unitary Electric Field in the current configuration. */
62+
std::unique_ptr<su2double[]> EField_Ref_Unit; /*!< \brief Electric Field, unitary, in the reference configuration. */
63+
std::unique_ptr<su2double[]> EField_Ref_Mod; /*!< \brief Electric Field, modulus, in the reference configuration. */
64+
std::unique_ptr<su2double[]> EField_Curr_Unit; /*!< \brief Auxiliary vector for the unitary Electric Field in the current configuration. */
7565
unsigned short nElectric_Field,
7666
nDim_Electric_Field;
7767

78-
su2double *ke_DE_i; /*!< \brief Electric Constant for Dielectric Elastomers. */
68+
std::unique_ptr<su2double[]> ke_DE_i; /*!< \brief Electric Constant for Dielectric Elastomers. */
7969

8070
su2double ke_DE; /*!< \brief Electric Constant for Dielectric Elastomers. */
8171
su2double EFieldMod_Ref; /*!< \brief Modulus of the electric field in the reference configuration. */
@@ -94,11 +84,6 @@ class CFEANonlinearElasticity : public CFEAElasticity {
9484
*/
9585
CFEANonlinearElasticity(unsigned short val_nDim, unsigned short val_nVar, const CConfig *config);
9686

97-
/*!
98-
* \brief Destructor of the class.
99-
*/
100-
~CFEANonlinearElasticity(void) override;
101-
10287
/*!
10388
* \brief Set element electric field.
10489
* \param[in] i_DV - Index of the variable.
@@ -161,9 +146,48 @@ class CFEANonlinearElasticity : public CFEAElasticity {
161146
void SetElectric_Properties(const CElement *element_container, const CConfig *config);
162147

163148
/*!
164-
* \brief TODO: Describe what this does.
149+
* \brief Computes b_Mat.
150+
*/
151+
void ComputeLeftCauchyGreenTensor() {
152+
for (unsigned short iVar = 0; iVar < MAXNDIM; iVar++) {
153+
for (unsigned short jVar = 0; jVar < MAXNDIM; jVar++) {
154+
b_Mat[iVar][jVar] = 0;
155+
for (unsigned short kVar = 0; kVar < MAXNDIM; kVar++) {
156+
b_Mat[iVar][jVar] += F_Mat[iVar][kVar]*F_Mat[jVar][kVar];
157+
}
158+
}
159+
}
160+
}
161+
162+
/*!
163+
* \brief Computes the determinant of the deformation gradient.
164+
*/
165+
void ComputeJ_F() {
166+
J_F = F_Mat[0][0]*F_Mat[1][1]*F_Mat[2][2]+
167+
F_Mat[0][1]*F_Mat[1][2]*F_Mat[2][0]+
168+
F_Mat[0][2]*F_Mat[1][0]*F_Mat[2][1]-
169+
F_Mat[0][2]*F_Mat[1][1]*F_Mat[2][0]-
170+
F_Mat[1][2]*F_Mat[2][1]*F_Mat[0][0]-
171+
F_Mat[2][2]*F_Mat[0][1]*F_Mat[1][0];
172+
}
173+
174+
/*!
175+
* \brief Computes the deformation gradient transpose inverse.
165176
*/
166-
void Compute_FmT_Mat(void);
177+
template <typename Mat>
178+
void Compute_FmT_Mat(const Mat& F_Mat, const su2double& J_F, Mat& FmT_Mat) const {
179+
FmT_Mat[0][0] = (F_Mat[1][1]*F_Mat[2][2] - F_Mat[1][2]*F_Mat[2][1]) / J_F;
180+
FmT_Mat[0][1] = (F_Mat[1][2]*F_Mat[2][0] - F_Mat[2][2]*F_Mat[1][0]) / J_F;
181+
FmT_Mat[0][2] = (F_Mat[1][0]*F_Mat[2][1] - F_Mat[1][1]*F_Mat[2][0]) / J_F;
182+
183+
FmT_Mat[1][0] = (F_Mat[0][2]*F_Mat[2][1] - F_Mat[0][1]*F_Mat[2][2]) / J_F;
184+
FmT_Mat[1][1] = (F_Mat[0][0]*F_Mat[2][2] - F_Mat[2][0]*F_Mat[0][2]) / J_F;
185+
FmT_Mat[1][2] = (F_Mat[0][1]*F_Mat[2][1] - F_Mat[0][0]*F_Mat[2][0]) / J_F;
186+
187+
FmT_Mat[2][0] = (F_Mat[0][1]*F_Mat[1][2] - F_Mat[0][2]*F_Mat[1][1]) / J_F;
188+
FmT_Mat[2][1] = (F_Mat[0][2]*F_Mat[1][0] - F_Mat[0][0]*F_Mat[1][2]) / J_F;
189+
FmT_Mat[2][2] = (F_Mat[0][0]*F_Mat[1][1] - F_Mat[0][1]*F_Mat[1][0]) / J_F;
190+
}
167191

168192
/*!
169193
* \brief TODO: Describe what this does.

SU2_CFD/include/numerics/elasticity/nonlinear_models.hpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ class CFEM_NeoHookean_Comp final : public CFEANonlinearElasticity {
4848
*/
4949
CFEM_NeoHookean_Comp(unsigned short val_nDim, unsigned short val_nVar, const CConfig *config);
5050

51-
/*!
52-
* \brief Destructor of the class.
53-
*/
54-
~CFEM_NeoHookean_Comp(void) override = default;
55-
5651
private:
5752
/*!
5853
* \brief Compute the plane stress term.
@@ -100,11 +95,6 @@ class CFEM_Knowles_NearInc final : public CFEANonlinearElasticity {
10095
*/
10196
CFEM_Knowles_NearInc(unsigned short val_nDim, unsigned short val_nVar, const CConfig *config);
10297

103-
/*!
104-
* \brief Destructor of the class.
105-
*/
106-
~CFEM_Knowles_NearInc(void) override = default;
107-
10898
private:
10999
/*!
110100
* \brief Compute the plane stress term.
@@ -150,11 +140,6 @@ class CFEM_DielectricElastomer final : public CFEANonlinearElasticity {
150140
*/
151141
CFEM_DielectricElastomer(unsigned short val_nDim, unsigned short val_nVar, const CConfig *config);
152142

153-
/*!
154-
* \brief Destructor of the class.
155-
*/
156-
~CFEM_DielectricElastomer(void) override = default;
157-
158143
private:
159144
/*!
160145
* \brief Compute the plane stress term.
@@ -202,11 +187,6 @@ class CFEM_IdealDE final : public CFEANonlinearElasticity {
202187
*/
203188
CFEM_IdealDE(unsigned short val_nDim, unsigned short val_nVar, const CConfig *config);
204189

205-
/*!
206-
* \brief Destructor of the class.
207-
*/
208-
~CFEM_IdealDE(void) override = default;
209-
210190
private:
211191
/*!
212192
* \brief Compute the plane stress term.

SU2_CFD/include/output/filewriter/CTecplotBinaryFileWriter.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727

2828
#pragma once
2929

30+
#include <assert.h>
31+
#include <cstdint>
32+
3033
#include "CFileWriter.hpp"
3134

32-
#include <assert.h>
3335

3436
class CTecplotBinaryFileWriter final: public CFileWriter{
3537

SU2_CFD/src/iteration/CFEAIteration.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ void CFEAIteration::Iterate(COutput* output, CIntegration**** integration, CGeom
123123
config[val_iZone]->SetInnerIter(CurIter);
124124
break;
125125
}
126-
/*--- Linear elasticity without thermal effects only needs one iteration. ---*/
126+
/*--- Linear elasticity without thermal effects and double precision only needs one iteration. ---*/
127+
#ifndef USE_MIXED_PRECISION
127128
if (linear && !heat) {
128129
output->SetConvergence(true);
129130
break;
130131
}
132+
#endif
131133
/*--- Normal stopping criteria. ---*/
132134
if (StopCalc && IntIter > 0) break;
133135
}

0 commit comments

Comments
 (0)