@@ -78,254 +78,17 @@ void construct_gr(ComMod &com_mod, const mshType &lM, const Array<double> &Dg,
78
78
lR = 0.0 ;
79
79
lK = 0.0 ;
80
80
81
- // Evaluate solid equations
82
- if (eval_fd) {
83
- eval_gr_fd_ele (e, com_mod, lM, e_Dg, ptr, lR, lK);
84
- } else {
85
- // Update G&R internal variables
86
- eval_gr (e, com_mod, lM, Dg, ptr, lR, lK, false , false );
87
-
88
- // Compute stress and tangent
89
- eval_gr (e, com_mod, lM, Dg, ptr, lR, lK, true , true );
90
- }
81
+ // Update G&R internal variables
82
+ eval_gr (e, com_mod, lM, Dg, ptr, lR, lK, false , false );
83
+
84
+ // Compute stress and tangent
85
+ eval_gr (e, com_mod, lM, Dg, ptr, lR, lK, true , true );
91
86
92
87
// Assemble into global residual and tangent
93
88
lhsa_ns::do_assem (com_mod, eNoN, ptr, lK, lR);
94
89
}
95
90
}
96
91
97
- // / @brief Finite difference on each element
98
- void eval_gr_fd_ele (const int &e, ComMod &com_mod, const mshType &lM,
99
- Array<double > &Dg, Vector<int > &ptr, Array<double > &lR,
100
- Array3<double > &lK) {
101
- // Get dimensions
102
- const int eNoN = lM.eNoN ;
103
- const int dof = com_mod.dof ;
104
- const int tDof = com_mod.tDof ;
105
- const int tnNo = com_mod.tnNo ;
106
-
107
- // Set step size for finite difference
108
- const double eps = 1.0e-10 ;
109
-
110
- // Time integration parameters
111
- int Ac;
112
- int cEq = com_mod.cEq ;
113
- auto &eq = com_mod.eq [cEq];
114
-
115
- // Initialize residual and tangent
116
- Array<double > lRp (dof, eNoN);
117
- Array<double > dlR (dof, eNoN);
118
- Array3<double > lK_dummy (dof * dof, eNoN, eNoN);
119
- lRp = 0.0 ;
120
- lK_dummy = 0.0 ;
121
-
122
- // Central evaluation
123
- eval_gr (e, com_mod, lM, Dg, ptr, lR, lK_dummy, true , false );
124
-
125
- // Finite differences
126
- for (int i = 0 ; i < dof; ++i) {
127
- for (int a = 0 ; a < eNoN; ++a) {
128
- dlR = 0.0 ;
129
-
130
- // Global node ID
131
- Ac = lM.IEN (a, e);
132
-
133
- // Perturb
134
- Dg (i, Ac) += eps;
135
-
136
- // Displacement
137
- lRp = 0.0 ;
138
- eval_gr (e, com_mod, lM, Dg, ptr, lRp, lK_dummy, true , false );
139
- dlR += (lRp - lR) / eps;
140
-
141
- // Restore
142
- Dg (i, Ac) -= eps;
143
-
144
- // Assign to tangent matrix
145
- for (int j = 0 ; j < dof; ++j) {
146
- for (int b = 0 ; b < eNoN; ++b) {
147
- lK (j * dof + i, b, a) = dlR (j, b);
148
- }
149
- }
150
- }
151
- }
152
- }
153
-
154
- void construct_gr_fd_global (ComMod &com_mod, const mshType &lM,
155
- const Array<double > &Dg) {
156
- // Get dimensions
157
- const int eNoN = lM.eNoN ;
158
- const int dof = com_mod.dof ;
159
- const int tDof = com_mod.tDof ;
160
- const int tnNo = com_mod.tnNo ;
161
-
162
- // Set step size for finite difference
163
- const double eps = 1.0e-8 ;
164
-
165
- // Make editable copy
166
- Array<double > e_Dg (tDof, tnNo);
167
- e_Dg = Dg;
168
-
169
- // Initialize residual and tangent
170
- Vector<int > ptr (eNoN);
171
- Array<double > lR (dof, eNoN);
172
- Array3<double > lK (dof * dof, eNoN, eNoN);
173
-
174
- // Residual evaluation
175
- eval_gr_fd_global (com_mod, lM, Dg, 1.0 / eps);
176
-
177
- // Loop global nodes
178
- for (int Ac = 0 ; Ac < tnNo; ++Ac) {
179
- // Central evaluation
180
- eval_gr_fd_global (com_mod, lM, Dg, 1.0 / eps, Ac);
181
-
182
- // Loop DOFs
183
- for (int i = 0 ; i < dof; ++i) {
184
- // Perturb solution vectors
185
- e_Dg (i, Ac) += eps;
186
-
187
- // Perturbed evaluations
188
- eval_gr_fd_global (com_mod, lM, e_Dg, 1.0 / eps, Ac, i);
189
-
190
- // Restore solution vectors
191
- e_Dg (i, Ac) = Dg (i, Ac);
192
- }
193
- }
194
- }
195
-
196
- void eval_gr_fd_global (ComMod &com_mod, const mshType &lM,
197
- const Array<double > &Dg, const double eps, const int dAc,
198
- const int dj) {
199
- using namespace consts ;
200
-
201
- // Check if the residual should be assembled
202
- const bool residual = (dAc == -1 ) && (dj == -1 );
203
-
204
- // Check if this is the central evaluation
205
- const bool central = (dAc != -1 ) && (dj == -1 );
206
-
207
- // Get dimensions
208
- const int eNoN = lM.eNoN ;
209
- const int dof = com_mod.dof ;
210
-
211
- // Initialize residual and tangent
212
- Vector<int > ptr_dummy (eNoN);
213
- Array<double > lR_dummy (dof, eNoN);
214
- Array3<double > lK_dummy (dof * dof, eNoN, eNoN);
215
- ptr_dummy = 0 ;
216
- lR_dummy = 0.0 ;
217
- lK_dummy = 0.0 ;
218
-
219
- // Select element set to evaluate
220
- std::set<int > elements;
221
- if (residual) {
222
- // Residual evaluation: evaluate all elements
223
- for (int i = 0 ; i < lM.nEl ; ++i) {
224
- elements.insert (i);
225
- }
226
- } else {
227
- // Pick elements according to smoothing algorithm
228
- elements = lM.map_node_ele [1 ].at (dAc);
229
- }
230
-
231
- // Update internal G&R variables without evaluating stress or tangent
232
- for (int e : elements) {
233
- eval_gr (e, com_mod, lM, Dg, ptr_dummy, lR_dummy, lK_dummy, false , false );
234
- }
235
-
236
- // Index of collagen mass fraction multiplier
237
- const int igr = 37 ;
238
-
239
- // Initialize arrays
240
- Vector<double > grInt_a (lM.gnNo );
241
- Vector<double > grInt_n (lM.gnNo );
242
- grInt_a = 0.0 ;
243
- grInt_n = 0.0 ;
244
-
245
- int Ac;
246
- double w;
247
- double val;
248
- Vector<double > N (lM.eNoN );
249
-
250
- // Project: integration point -> nodes
251
- for (int g = 0 ; g < lM.nG ; g++) {
252
- w = lM.w (g);
253
- N = lM.N .col (g);
254
- for (int e : elements) {
255
- val = com_mod.grInt (e, g, igr);
256
- for (int a = 0 ; a < lM.eNoN ; a++) {
257
- Ac = lM.IEN (a, e);
258
- // todo: add jacobian
259
- grInt_n (Ac) += w * N (a) * val;
260
- grInt_a (Ac) += w * N (a);
261
- }
262
- }
263
- }
264
-
265
- // Project: nodes -> integration points
266
- for (int e : elements) {
267
- for (int g = 0 ; g < lM.nG ; g++) {
268
- N = lM.N .col (g);
269
- val = 0.0 ;
270
- for (int a = 0 ; a < lM.eNoN ; a++) {
271
- Ac = lM.IEN (a, e);
272
- val += N (a) * grInt_n (Ac) / grInt_a (Ac);
273
- }
274
- com_mod.grInt (e, g, igr) = val;
275
- }
276
- }
277
-
278
- // Store internal G&R variables
279
- if (residual) {
280
- com_mod.grInt_orig = com_mod.grInt ;
281
- }
282
-
283
- // Initialzie arrays for Finite Difference (FD)
284
- Vector<int > ptr_row (eNoN);
285
- Vector<int > ptr_col (1 );
286
- Array<double > lR (dof, eNoN);
287
- Array3<double > lK (dof * dof, eNoN, 1 );
288
-
289
- // Assemble only the FD node
290
- ptr_col = dAc;
291
-
292
- // Loop over all elements of mesh
293
- for (int e : elements) {
294
- // Reset
295
- ptr_row = 0 ;
296
- lR = 0.0 ;
297
- lK = 0.0 ;
298
-
299
- // Evaluate solid equations (with smoothed internal G&R variables)
300
- eval_gr (e, com_mod, lM, Dg, ptr_row, lR, lK_dummy, true , false );
301
-
302
- // Assemble into global residual
303
- if (residual) {
304
- lhsa_ns::do_assem_residual (com_mod, lM.eNoN , ptr_row, lR);
305
- continue ;
306
- }
307
-
308
- // Components of FD: central and difference
309
- for (int a = 0 ; a < eNoN; ++a) {
310
- for (int i = 0 ; i < dof; ++i) {
311
- if (central) {
312
- for (int j = 0 ; j < dof; ++j) {
313
- lK (i * dof + j, a, 0 ) = -lR (i, a) * eps;
314
- }
315
- } else {
316
- lK (i * dof + dj, a, 0 ) = lR (i, a) * eps;
317
- }
318
- }
319
- }
320
-
321
- // Assemble into global tangent
322
- lhsa_ns::do_assem_tangent (com_mod, lM.eNoN , 1 , ptr_row, ptr_col, lK);
323
- }
324
-
325
- // Restore internal G&R variables
326
- com_mod.grInt = com_mod.grInt_orig ;
327
- }
328
-
329
92
// / @brief
330
93
void eval_gr (const int &e, ComMod &com_mod, const mshType &lM,
331
94
const Array<double > &Dg, Vector<int > &ptr, Array<double > &lR,
0 commit comments