G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsVisitorMixedNonLinearElasticity.h
Go to the documentation of this file.
1
16#pragma once
17
20
22#include <gsCore/gsFuncData.h>
23
24namespace gismo
25{
26
27template <class T>
28class gsVisitorMixedNonLinearElasticity
29{
30public:
31 gsVisitorMixedNonLinearElasticity(const gsPde<T> & pde_, const gsMultiPatch<T> & displacement_,
32 const gsMultiPatch<T> & pressure_)
33 : pde_ptr(static_cast<const gsBasePde<T>*>(&pde_)),
34 displacement(displacement_),
35 pressure(pressure_){}
36
37 void initialize(const gsBasisRefs<T> & basisRefs,
38 const index_t patchIndex,
39 const gsOptionList & options,
40 gsQuadRule<T> & rule)
41 {
42 GISMO_UNUSED(patchIndex);
43 // parametric dimension of the first displacement component
44 dim = basisRefs.front().dim();
45 // a quadrature rule is defined by the basis for the first velocity component.
46 // the same rule is used for the presure
47 rule = gsQuadrature::get(basisRefs.front(), options);
48 // saving necessary info
49 patch = patchIndex;
50 T YM = options.getReal("YoungsModulus");
51 T PR = options.getReal("PoissonsRatio");
52 lambda_inv = ( 1. + PR ) * ( 1. - 2. * PR ) / YM / PR ;
53 mu = YM / ( 2. * ( 1. + PR ) );
54 forceScaling = options.getReal("ForceScaling");
55 I = gsMatrix<T>::Identity(dim,dim);
56 // resize containers for global indices
57 globalIndices.resize(dim+1);
58 blockNumbers.resize(dim+1);
59 }
60
61 inline void evaluate(const gsBasisRefs<T> & basisRefs,
62 const gsGeometry<T> & geo,
63 const gsMatrix<T> & quNodes)
64 {
65 // store quadrature points of the element for geometry evaluation
66 md.points = quNodes;
67 // NEED_VALUE to get points in the physical domain for evaluation of the RHS
68 // NEED_MEASURE to get the Jacobian determinant values for integration
69 // NEED_GRAD_TRANSFORM to get the Jacobian matrix to transform gradient from the parametric to physical domain
71 // Compute image of the quadrature points plus gradient, jacobian and other necessary data
72 geo.computeMap(md);
73 // find local indices of the displacement and pressure basis functions active on the element
74 basisRefs.front().active_into(quNodes.col(0),localIndicesDisp);
75 N_D = localIndicesDisp.rows();
76 basisRefs.back().active_into(quNodes.col(0), localIndicesPres);
77 N_P = localIndicesPres.rows();
78 // Evaluate displacement basis functions and their derivatives on the element
79 basisRefs.front().evalAllDers_into(quNodes,1,basisValuesDisp);
80 // Evaluate pressure basis functions on the element
81 basisRefs.back().eval_into(quNodes,basisValuesPres);
82 // Evaluate right-hand side at the image of the quadrature points
83 pde_ptr->rhs()->eval_into(md.values[0],forceValues);
84 // store quadrature points of the element for displacement evaluation
85 mdDisplacement.points = quNodes;
86 // NEED_DERIV to compute deformation gradient
87 mdDisplacement.flags = NEED_DERIV;
88 // evaluate displacement gradient
89 displacement.patch(patch).computeMap(mdDisplacement);
90 // evaluate pressure; we use eval_into instead of another gsMapData object
91 // because it easier for simple value evaluation
92 pressure.patch(patch).eval_into(quNodes,pressureValues);
93 }
94
95 inline void assemble(gsDomainIterator<T> & element,
96 const gsVector<T> & quWeights)
97 {
98 GISMO_UNUSED(element);
99 // Initialize local matrix/rhs // A | B^T
100 localMat.setZero(dim*N_D + N_P, dim*N_D + N_P); // --|-- matrix structure
101 localRhs.setZero(dim*N_D + N_P,1); // B | C
102 // Loop over the quadrature nodes
103 for (index_t q = 0; q < quWeights.rows(); ++q)
104 {
105 // Multiply quadrature weight by the geometry measure
106 const T weight = quWeights[q] * md.measure(q);
107 // Compute physical gradients of basis functions at q as a dim x numActiveFunction matrix
108 transformGradients(md,q,basisValuesDisp[1],physGradDisp);
109 // physical jacobian of displacemnt du/dx = du/dxi * dxi/dx
110 physDispJac = mdDisplacement.jacobian(q)*(md.jacobian(q).cramerInverse());
111 // deformation gradient F = I + du/dx
112 F = I + physDispJac;
113 // deformation jacobian J = det(F)
114 T J = F.determinant();
115 // Right Cauchy Green strain, C = F'*F
116 RCG = F.transpose() * F;
117 // logarithmic neo-Hooke
118 GISMO_ENSURE(J>0,"Invalid configuration: J < 0");
119 RCGinv = RCG.cramerInverse();
120 // Second Piola-Kirchhoff stress tensor
121 S = (pressureValues.at(q)-mu)*RCGinv + mu*I;
122 // elasticity tensor
123 symmetricIdentityTensor<T>(C,RCGinv);
124 C *= mu-pressureValues.at(q);
125 // Matrix A and reisdual: loop over displacement basis functions
126 for (index_t i = 0; i < N_D; i++)
127 {
128 setB<T>(B_i,F,physGradDisp.col(i));
129 materialTangentTemp = B_i.transpose() * C;
130 // Geometric tangent K_tg_geo = gradB_i^T * S * gradB_j;
131 geometricTangentTemp = S * physGradDisp.col(i);
132 // A-matrix
133 for (index_t j = 0; j < N_D; j++)
134 {
135 setB<T>(B_j,F,physGradDisp.col(j));
136 materialTangent = materialTangentTemp * B_j;
137 T geometricTangent = geometricTangentTemp.transpose() * physGradDisp.col(j);
138 // K_tg = K_tg_mat + I*K_tg_geo;
139 for (short_t d = 0; d < dim; ++d)
140 materialTangent(d,d) += geometricTangent;
141
142 for (short_t di = 0; di < dim; ++di)
143 for (short_t dj = 0; dj < dim; ++dj)
144 localMat(di*N_D+i, dj*N_D+j) += weight * materialTangent(di,dj);
145 }
146
147 // Second Piola-Kirchhoff stress tensor as vector
148 voigtStress<T>(Svec,S);
149 // rhs = -r = force - B*Svec,
150 localResidual = B_i.transpose() * Svec;
151 for (short_t d = 0; d < dim; d++)
152 localRhs(d*N_D+i) -= weight * localResidual(d);
153 }
154 // B-matrix
155 divV = F.cramerInverse().transpose() * physGradDisp;
156 for (short_t d = 0; d < dim; ++d)
157 {
158 block = weight*basisValuesPres.col(q)*divV.row(d);
159 localMat.block(dim*N_D,d*N_D,N_P,N_D) += block.block(0,0,N_P,N_D);
160 localMat.block(d*N_D,dim*N_D,N_D,N_P) += block.transpose().block(0,0,N_D,N_P);
161 }
162 // C-matrix
163 if (abs(lambda_inv) > 0)
164 localMat.block(dim*N_D,dim*N_D,N_P,N_P) -=
165 (weight*lambda_inv*basisValuesPres.col(q)*basisValuesPres.col(q).transpose()).block(0,0,N_P,N_P);
166 // rhs: constraint residual
167 localRhs.middleRows(dim*N_D,N_P) += weight*basisValuesPres.col(q)*(lambda_inv*pressureValues.at(q)-log(J));
168 // rhs: force
169 for (short_t d = 0; d < dim; ++d)
170 localRhs.middleRows(d*N_D,N_D).noalias() += weight * forceScaling * forceValues(d,q) * basisValuesDisp[0].col(q) ;
171 }
172 }
173
174 inline void localToGlobal(const int patchIndex,
175 const std::vector<gsMatrix<T> > & eliminatedDofs,
176 gsSparseSystem<T> & system)
177 {
178 // computes global indices for displacement components
179 for (short_t d = 0; d < dim; ++d)
180 {
181 system.mapColIndices(localIndicesDisp,patchIndex,globalIndices[d],d);
182 blockNumbers.at(d) = d;
183 }
184 // computes global indices for pressure
185 system.mapColIndices(localIndicesPres, patchIndex, globalIndices[dim], dim);
186 blockNumbers.at(dim) = dim;
187 // push to global system
188 system.pushToRhs(localRhs,globalIndices,blockNumbers);
189 system.pushToMatrix(localMat,globalIndices,eliminatedDofs,blockNumbers,blockNumbers);
190 }
191
192protected:
193 // problem info
194 short_t dim;
195 const gsBasePde<T> * pde_ptr;
196 index_t patch; // current patch
197 // Lame coefficients and force scaling factor
198 T lambda_inv, mu, forceScaling;
199 // geometry mapping
200 gsMapData<T> md;
201 // local components of the global linear system
202 gsMatrix<T> localMat;
203 gsMatrix<T> localRhs;
204 // local indices (at the current patch) of basis functions active at the current element
205 gsMatrix<index_t> localIndicesDisp;
206 gsMatrix<index_t> localIndicesPres;
207 // number of displacement and pressure basis functions active at the current element
208 index_t N_D, N_P;
209 // values and derivatives of displacement basis functions at quadrature points at the current element
210 // values are stored as a N_D x numQuadPoints matrix; not sure about derivatives, must be smth like N_D*dim x numQuadPoints
211 std::vector<gsMatrix<T> > basisValuesDisp;
212 // values of pressure basis functions active at the current element;
213 // stores as a N_P x numQuadPoints matrix
214 gsMatrix<T> basisValuesPres;
215 // RHS values at quadrature points at the current element; stored as a dim x numQuadPoints matrix
216 gsMatrix<T> forceValues;
217 // current displacement field
218 const gsMultiPatch<T> & displacement;
219 // evaluation data of the current displacement field
220 gsMapData<T> mdDisplacement;
221 // current pressure field
222 const gsMultiPatch<T> & pressure;
223 // evaluation data of the current pressure field stored as a 1 x numQuadPoints matrix
224 gsMatrix<T> pressureValues;
225
226 // all temporary matrices defined here for efficiency
227 gsMatrix<T> C, Ctemp, physGradDisp, physDispJac, F, RCG, E, S, RCGinv, B_i, materialTangentTemp, B_j, materialTangent, divV, block, I;
228 gsVector<T> geometricTangentTemp, Svec, localResidual;
229 // containers for global indices
230 std::vector< gsMatrix<index_t> > globalIndices;
231 gsVector<index_t> blockNumbers;
232};
233
234} // namespace gismo
IMHO, a useless class, but it is necessary to use the gsAssembler class. Contains proper information ...
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_UNUSED(x)
Definition gsDebug.h:112
#define GISMO_ENSURE(cond, message)
Definition gsDebug.h:102
This object is a cache for computed values from an evaluator.
Creates a variety of quadrature rules.
Tensor operations for elasticity.
EIGEN_STRONG_INLINE abs_expr< E > abs(const E &u)
Absolute value.
Definition gsExpressions.h:4486
The G+Smo namespace, containing all definitions for the library.
@ NEED_VALUE
Value of the object.
Definition gsForwardDeclarations.h:72
@ NEED_DERIV
Gradient of the object.
Definition gsForwardDeclarations.h:73
@ NEED_GRAD_TRANSFORM
Gradient transformation matrix.
Definition gsForwardDeclarations.h:77
@ NEED_MEASURE
The density of the measure pull back.
Definition gsForwardDeclarations.h:76
static gsQuadRule< T > get(const gsBasis< T > &basis, const gsOptionList &options, short_t fixDir=-1)
Constructs a quadrature rule based on input options.
Definition gsQuadrature.h:51