v0.16.0
Loading...
Searching...
No Matches
ConvectiveMassElement.cpp
Go to the documentation of this file.
1/** \file ConvectiveMassElement.cpp
2 * \brief Operators and data structures for mass and convective mass element
3 * \ingroup convective_mass_elem
4 *
5 */
6
7#include <MoFEM.hpp>
8using namespace MoFEM;
9
11
12#include <adolc/adolc.h>
13#include <MethodForForceScaling.hpp>
14#include <DirichletBC.hpp>
15#include <MethodForForceScaling.hpp>
17
18#ifndef WITH_ADOL_C
19#error "MoFEM need to be compiled with ADOL-C"
20#endif
21
23 : VolumeElementForcesAndSourcesCore(m_field), A(PETSC_NULLPTR), F(PETSC_NULLPTR) {
25
26 auto create_vec = [&]() {
27 if (mField.get_comm_rank() == 0) {
28 return createVectorMPI(mField.get_comm(), 1, 1);
29 } else {
30 return createVectorMPI(mField.get_comm(), 0, 1);
31 }
32 };
33
34 V = create_vec();
35}
36
38
41
42 CHKERR VolumeElementForcesAndSourcesCore::preProcess();
43
44 switch (ts_ctx) {
45 case CTX_TSNONE:
46 CHKERR VecZeroEntries(V);
47 break;
48 default:
49 break;
50 }
51
53}
54
57
58 CHKERR VolumeElementForcesAndSourcesCore::postProcess();
59
60 const double *array;
61 switch (ts_ctx) {
62 case CTX_TSNONE:
63 CHKERR VecAssemblyBegin(V);
64 CHKERR VecAssemblyEnd(V);
65 CHKERR VecSum(V, &eNergy);
66 break;
67 default:
68 break;
69 }
70
72}
73
75 short int tag)
76 : feMassRhs(m_field), feMassLhs(m_field), feMassAuxLhs(m_field),
77 feVelRhs(m_field), feVelLhs(m_field), feTRhs(m_field), feTLhs(m_field),
78 feEnergy(m_field), mField(m_field), tAg(tag) {}
79
81 const std::string field_name,
82 std::vector<VectorDouble> &values_at_gauss_pts,
83 std::vector<MatrixDouble> &gardient_at_gauss_pts)
86 valuesAtGaussPts(values_at_gauss_pts),
87 gradientAtGaussPts(gardient_at_gauss_pts), zeroAtType(MBVERTEX) {}
88
90 int side, EntityType type, EntitiesFieldData::EntData &data) {
92
93 int nb_dofs = data.getFieldData().size();
94 if (nb_dofs == 0) {
96 }
97 int nb_gauss_pts = data.getN().size1();
98 int nb_base_functions = data.getN().size2();
99
100 // initialize
101 // VectorDouble& values = data.getFieldData();
102 valuesAtGaussPts.resize(nb_gauss_pts);
103 gradientAtGaussPts.resize(nb_gauss_pts);
104 for (int gg = 0; gg < nb_gauss_pts; gg++) {
105 valuesAtGaussPts[gg].resize(3);
106 gradientAtGaussPts[gg].resize(3, 3);
107 }
108
109 if (type == zeroAtType) {
110 for (int gg = 0; gg < nb_gauss_pts; gg++) {
111 valuesAtGaussPts[gg].clear();
112 gradientAtGaussPts[gg].clear();
113 }
114 }
115
116 auto base_function = data.getFTensor0N();
117 auto diff_base_functions = data.getFTensor1DiffN<3>();
118 FTensor::Index<'i', 3> i;
119 FTensor::Index<'j', 3> j;
120
121 for (int gg = 0; gg != nb_gauss_pts; gg++) {
122 auto field_data = data.getFTensor1FieldData<3>();
123 FTensor::Tensor1<double *, 3> values(&valuesAtGaussPts[gg][0],
124 &valuesAtGaussPts[gg][1],
125 &valuesAtGaussPts[gg][2]);
127 &gradientAtGaussPts[gg](0, 0), &gradientAtGaussPts[gg](0, 1),
128 &gradientAtGaussPts[gg](0, 2), &gradientAtGaussPts[gg](1, 0),
129 &gradientAtGaussPts[gg](1, 1), &gradientAtGaussPts[gg](1, 2),
130 &gradientAtGaussPts[gg](2, 0), &gradientAtGaussPts[gg](2, 1),
131 &gradientAtGaussPts[gg](2, 2));
132 int bb = 0;
133 for (; bb != nb_dofs / 3; bb++) {
134 values(i) += base_function * field_data(i);
135 gradient(i, j) += field_data(i) * diff_base_functions(j);
136 ++diff_base_functions;
137 ++base_function;
138 ++field_data;
139 }
140 for (; bb != nb_base_functions; bb++) {
141 ++diff_base_functions;
142 ++base_function;
143 }
144 }
146}
147
149 const std::string field_name, CommonData &common_data)
150 : OpGetDataAtGaussPts(field_name, common_data.dataAtGaussPts[field_name],
151 common_data.gradAtGaussPts[field_name]) {}
152
154 const std::string field_name, BlockData &data, CommonData &common_data,
155 boost::ptr_vector<MethodForForceScaling> &methods_op, int tag,
156 bool jacobian)
159 dAta(data), commonData(common_data), tAg(tag), jAcobian(jacobian),
160 lInear(commonData.lInear), fieldDisp(false), methodsOp(methods_op) {}
161
163 int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data) {
165
166 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
167 dAta.tEts.end()) {
169 }
170
171 // do it only once, no need to repeat this for edges,faces or tets
172 if (row_type != MBVERTEX)
174
175 int nb_dofs = row_data.getIndices().size();
176 if (nb_dofs == 0)
178
179 {
180
181 if (a.size() != 3) {
182 a.resize(3, false);
183 dot_W.resize(3, false);
184 a_res.resize(3, false);
185 g.resize(3, 3, false);
186 G.resize(3, 3, false);
187 h.resize(3, 3, false);
188 H.resize(3, 3, false);
189 invH.resize(3, 3, false);
190 F.resize(3, 3, false);
191 }
192
193 std::fill(dot_W.begin(), dot_W.end(), 0);
194 std::fill(H.data().begin(), H.data().end(), 0);
195 std::fill(invH.data().begin(), invH.data().end(), 0);
196 for (int ii = 0; ii != 3; ii++) {
197 H(ii, ii) = 1;
198 invH(ii, ii) = 1;
199 }
200
201 int nb_gauss_pts = row_data.getN().size1();
202 commonData.valMass.resize(nb_gauss_pts);
203 commonData.jacMassRowPtr.resize(nb_gauss_pts);
204 commonData.jacMass.resize(nb_gauss_pts);
205
206 const std::vector<VectorDouble> &dot_spacial_vel =
208
209 const std::vector<MatrixDouble> &spatial_positions_grad =
211
212 const std::vector<MatrixDouble> &spatial_velocities_grad =
214
215 const std::vector<VectorDouble> &meshpos_vel =
217
218 const std::vector<MatrixDouble> &mesh_positions_gradient =
220
221 int nb_active_vars = 0;
222 for (int gg = 0; gg < nb_gauss_pts; gg++) {
223
224 if (gg == 0) {
225
226 trace_on(tAg);
227
228 for (int nn1 = 0; nn1 < 3; nn1++) { // 0
229 // commonData.dataAtGaussPts["DOT_"+commonData.spatialVelocities]
230 a[nn1] <<= dot_spacial_vel[gg][nn1];
231 nb_active_vars++;
232 }
233 for (int nn1 = 0; nn1 < 3; nn1++) { // 3
234 for (int nn2 = 0; nn2 < 3; nn2++) {
235 // commonData.gradAtGaussPts[commonData.spatialPositions][gg]
236 h(nn1, nn2) <<= spatial_positions_grad[gg](nn1, nn2);
237 if (fieldDisp) {
238 if (nn1 == nn2) {
239 h(nn1, nn2) += 1;
240 }
241 }
242 nb_active_vars++;
243 }
244 }
246 .size() > 0) {
247 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+9=12
248 for (int nn2 = 0; nn2 < 3; nn2++) {
249 // commonData.gradAtGaussPts[commonData.spatialVelocities]
250 g(nn1, nn2) <<= spatial_velocities_grad[gg](nn1, nn2);
251 nb_active_vars++;
252 }
253 }
254 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+9+9=21
255 // commonData.dataAtGaussPts["DOT_"+commonData.meshPositions]
256 dot_W(nn1) <<= meshpos_vel[gg][nn1];
257 nb_active_vars++;
258 }
259 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+9+9+3=24
260 for (int nn2 = 0; nn2 < 3; nn2++) {
261 // commonData.gradAtGaussPts[commonData.meshPositions][gg]
262 H(nn1, nn2) <<= mesh_positions_gradient[gg](nn1, nn2);
263 nb_active_vars++;
264 }
265 }
266 }
267
268 auto a0 = dAta.a0;
270
271 auto t_a_res =
272 FTensor::Tensor1<adouble *, 3>{&a_res[0], &a_res[1], &a_res[2]};
273 auto t_a = FTensor::Tensor1<adouble *, 3>{&a[0], &a[1], &a[2]};
274 auto t_a0 = FTensor::Tensor1<double *, 3>{&a0[0], &a0[1], &a0[2]};
275 auto t_dotW =
276 FTensor::Tensor1<adouble *, 3>{&dot_W[0], &dot_W[1], &dot_W[2]};
277 using ActiveMat3 = MatrixBoundedArray<adouble, 9>;
280 auto t_invH =
284
285 const double rho0 = dAta.rho0;
286
288 CHKERR invertTensor3by3(H, detH, invH);
289
290 t_G(i, j) = t_g(i, k) * t_invH(k, j);
291 t_a_res(i) = t_a(i) - t_a0(i) + t_G(i, j) * t_dotW(j);
292
293 // FIXME: there is error somewhere for nonlinear case
294 // test dam example with -is_linear 0
295 if (!lInear) {
296
297 t_F(i, j) = t_h(i, k) * t_invH(k, j);
298 t_a_res(i) *= rho0 * detH;
299 t_a_res(i) *= determinantTensor3by3(t_F);
300
301 } else {
302
303 t_a_res(i) *= rho0 * detH;
304 }
305
306 // dependant
308 res.resize(3);
309 for (int rr = 0; rr < 3; rr++) {
310 a_res[rr] >>= res[rr];
311 }
312
313 trace_off();
314 }
315
316 active.resize(nb_active_vars);
317 int aa = 0;
318 for (int nn1 = 0; nn1 < 3; nn1++) { // 0
319 active[aa++] = dot_spacial_vel[gg][nn1];
320 }
321 for (int nn1 = 0; nn1 < 3; nn1++) { // 3
322 for (int nn2 = 0; nn2 < 3; nn2++) {
323 if (fieldDisp && nn1 == nn2) {
324 active[aa++] = spatial_positions_grad[gg](nn1, nn2) + 1;
325 } else {
326 active[aa++] = spatial_positions_grad[gg](nn1, nn2);
327 }
328 }
329 }
331 0) {
332 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+9=12
333 for (int nn2 = 0; nn2 < 3; nn2++) {
334 active[aa++] = spatial_velocities_grad[gg](nn1, nn2);
335 }
336 }
337 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+9+9=21
338 active[aa++] = meshpos_vel[gg][nn1];
339 }
340 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+9+9+3=24
341 for (int nn2 = 0; nn2 < 3; nn2++) {
342 active[aa++] = mesh_positions_gradient[gg](nn1, nn2);
343 }
344 }
345 }
346
347 if (!jAcobian) {
349 if (gg > 0) {
350 res.resize(3);
351 int r;
352 r = ::function(tAg, 3, nb_active_vars, &active[0], &res[0]);
353 if (r != 3) { // function is locally analytic
354 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
355 "ADOL-C function evaluation with error r = %d", r);
356 }
357 }
358 double val = getVolume() * getGaussPts()(3, gg);
359 res *= val;
360 // cout << "my res " << res << endl;
361 } else {
362 commonData.jacMassRowPtr[gg].resize(3);
363 commonData.jacMass[gg].resize(3, nb_active_vars);
364 for (int nn1 = 0; nn1 < 3; nn1++) {
365 (commonData.jacMassRowPtr[gg])[nn1] =
366 &(commonData.jacMass[gg](nn1, 0));
367 }
368 int r;
369 r = jacobian(tAg, 3, nb_active_vars, &active[0],
370 &(commonData.jacMassRowPtr[gg])[0]);
371 if (r != 3) {
372 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
373 "ADOL-C function evaluation with error");
374 }
375 double val = getVolume() * getGaussPts()(3, gg);
376 commonData.jacMass[gg] *= val;
377 }
378 }
379 }
380
382}
383
390
392ConvectiveMassElement::OpMassRhs::doWork(int row_side, EntityType row_type,
393 EntitiesFieldData::EntData &row_data) {
395
396 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
397 dAta.tEts.end()) {
399 }
400 if (row_data.getIndices().size() == 0)
402 int nb_dofs = row_data.getIndices().size();
403
404 auto base = row_data.getFTensor0N();
405 int nb_base_functions = row_data.getN().size2();
406
407 {
408
409 nf.resize(nb_dofs);
410 nf.clear();
411
412 FTensor::Index<'i', 3> i;
413
414 for (unsigned int gg = 0; gg < row_data.getN().size1(); gg++) {
415 FTensor::Tensor1<double *, 3> t_nf(&nf[0], &nf[1], &nf[2], 3);
417 &commonData.valMass[gg][1],
418 &commonData.valMass[gg][2]);
419 int dd = 0;
420 for (; dd < nb_dofs / 3; dd++) {
421 t_nf(i) += base * res(i);
422 ++base;
423 ++t_nf;
424 }
425 for (; dd != nb_base_functions; dd++) {
426 ++base;
427 }
428 }
429
430 if ((unsigned int)nb_dofs > 3 * row_data.getN().size2()) {
431 SETERRQ(PETSC_COMM_SELF, 1, "data inconsistency");
432 }
433 CHKERR VecSetValues(getFEMethod()->ts_F, nb_dofs, &row_data.getIndices()[0],
434 &nf[0], ADD_VALUES);
435 }
436
438}
439
441 const std::string vel_field, const std::string field_name, BlockData &data,
442 CommonData &common_data, Range *forcesonlyonentities_ptr)
444 vel_field, field_name,
446 dAta(data), commonData(common_data) {
447 sYmm = false;
448 if (forcesonlyonentities_ptr != NULL) {
449 forcesOnlyOnEntities = *forcesonlyonentities_ptr;
450 }
451}
452
454 EntitiesFieldData::EntData &col_data, int gg) {
456 int nb_col = col_data.getIndices().size();
457 jac.clear();
458 if (!nb_col)
460 FTensor::Index<'i', 3> i;
461 FTensor::Index<'j', 3> j;
462 FTensor::Index<'k', 3> k;
463 FTensor::Tensor2<double *, 3, 3> t_jac(&jac(0, 0), &jac(0, 1), &jac(0, 2),
464 &jac(1, 0), &jac(1, 1), &jac(1, 2),
465 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
467 &commonData.jacMass[gg](0, 0), &commonData.jacMass[gg](0, 1),
468 &commonData.jacMass[gg](0, 2), &commonData.jacMass[gg](1, 0),
469 &commonData.jacMass[gg](1, 1), &commonData.jacMass[gg](1, 2),
470 &commonData.jacMass[gg](2, 0), &commonData.jacMass[gg](2, 1),
471 &commonData.jacMass[gg](2, 2));
472 double *base_ptr = const_cast<double *>(&col_data.getN(gg)[0]);
473 FTensor::Tensor0<double *> base(base_ptr, 1);
474 if (commonData.dataAtGaussPts["DOT_" + commonData.meshPositions].size() ==
475 0) {
476 for (int dd = 0; dd < nb_col / 3; dd++) {
477 t_jac(i, j) += t_mass1(i, j) * base * getFEMethod()->ts_a;
478 ++base;
479 ++t_jac;
480 }
481 } else {
482 const int s = 3 + 9;
484 // T* d000, T* d001, T* d002,
485 // T* d010, T* d011, T* d012,
486 // T* d020, T* d021, T* d022,
487 // T* d100, T* d101, T* d102,
488 // T* d110, T* d111, T* d112,
489 // T* d120, T* d121, T* d122,
490 // T* d200, T* d201, T* d202,
491 // T* d210, T* d211, T* d212,
492 // T* d220, T* d221, T* d222,
493 &commonData.jacMass[gg](0, s + 0), &commonData.jacMass[gg](0, s + 1),
494 &commonData.jacMass[gg](0, s + 2), &commonData.jacMass[gg](0, s + 3),
495 &commonData.jacMass[gg](0, s + 4), &commonData.jacMass[gg](0, s + 5),
496 &commonData.jacMass[gg](0, s + 6), &commonData.jacMass[gg](0, s + 7),
497 &commonData.jacMass[gg](0, s + 8), &commonData.jacMass[gg](1, s + 0),
498 &commonData.jacMass[gg](1, s + 1), &commonData.jacMass[gg](1, s + 2),
499 &commonData.jacMass[gg](1, s + 3), &commonData.jacMass[gg](1, s + 4),
500 &commonData.jacMass[gg](1, s + 5), &commonData.jacMass[gg](1, s + 6),
501 &commonData.jacMass[gg](1, s + 7), &commonData.jacMass[gg](1, s + 8),
502 &commonData.jacMass[gg](2, s + 0), &commonData.jacMass[gg](2, s + 1),
503 &commonData.jacMass[gg](2, s + 2), &commonData.jacMass[gg](2, s + 3),
504 &commonData.jacMass[gg](2, s + 4), &commonData.jacMass[gg](2, s + 5),
505 &commonData.jacMass[gg](2, s + 6), &commonData.jacMass[gg](2, s + 7),
506 &commonData.jacMass[gg](2, s + 8));
507
508 double *diff_ptr =
509 const_cast<double *>(&(col_data.getDiffN(gg, nb_col / 3)(0, 0)));
510 FTensor::Tensor1<double *, 3> diff(diff_ptr, &diff_ptr[1], &diff_ptr[2], 3);
511 for (int dd = 0; dd < nb_col / 3; dd++) {
512 t_jac(i, j) += t_mass1(i, j) * base * getFEMethod()->ts_a;
513 t_jac(i, j) += t_mass3(i, j, k) * diff(k);
514 ++base;
515 ++diff;
516 ++t_jac;
517 }
518 }
520}
521
523 int row_side, int col_side, EntityType row_type, EntityType col_type,
525 EntitiesFieldData::EntData &col_data) {
527
528 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
529 dAta.tEts.end()) {
531 }
532
533 int nb_row = row_data.getIndices().size();
534 int nb_col = col_data.getIndices().size();
535 if (nb_row == 0)
537 if (nb_col == 0)
539
540 auto base = row_data.getFTensor0N();
541 int nb_base_functions = row_data.getN().size2();
542
543 {
544
545 k.resize(nb_row, nb_col);
546 k.clear();
547 jac.resize(3, nb_col);
548
549 for (unsigned int gg = 0; gg < row_data.getN().size1(); gg++) {
550
551 try {
552 CHKERR getJac(col_data, gg);
553 } catch (const std::exception &ex) {
554 std::ostringstream ss;
555 ss << "throw in method: " << ex.what() << std::endl;
556 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "%s",
557 ss.str().c_str());
558 }
559
560 FTensor::Index<'i', 3> i;
561 FTensor::Index<'j', 3> j;
562
563 {
564 int dd1 = 0;
565 // integrate element stiffness matrix
566 for (; dd1 < nb_row / 3; dd1++) {
568 &jac(0, 0), &jac(0, 1), &jac(0, 2), &jac(1, 0), &jac(1, 1),
569 &jac(1, 2), &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
570 for (int dd2 = 0; dd2 < nb_col / 3; dd2++) {
572 &k(3 * dd1 + 0, 3 * dd2 + 0), &k(3 * dd1 + 0, 3 * dd2 + 1),
573 &k(3 * dd1 + 0, 3 * dd2 + 2), &k(3 * dd1 + 1, 3 * dd2 + 0),
574 &k(3 * dd1 + 1, 3 * dd2 + 1), &k(3 * dd1 + 1, 3 * dd2 + 2),
575 &k(3 * dd1 + 2, 3 * dd2 + 0), &k(3 * dd1 + 2, 3 * dd2 + 1),
576 &k(3 * dd1 + 2, 3 * dd2 + 2));
577 t_k(i, j) += base * t_jac(i, j);
578 ++t_jac;
579 }
580 ++base;
581 // for(int rr1 = 0;rr1<3;rr1++) {
582 // for(int dd2 = 0;dd2<nb_col;dd2++) {
583 // k(3*dd1+rr1,dd2) += row_data.getN()(gg,dd1)*jac(rr1,dd2);
584 // }
585 // }
586 }
587 for (; dd1 != nb_base_functions; dd1++) {
588 ++base;
589 }
590 }
591 }
592
593 if (!forcesOnlyOnEntities.empty()) {
594 VectorInt indices = row_data.getIndices();
595 VectorDofs &dofs = row_data.getFieldDofs();
596 VectorDofs::iterator dit = dofs.begin();
597 for (int ii = 0; dit != dofs.end(); dit++, ii++) {
598 if (forcesOnlyOnEntities.find((*dit)->getEnt()) ==
599 forcesOnlyOnEntities.end()) {
600 indices[ii] = -1;
601 }
602 }
603 CHKERR MatSetValues(getFEMethod()->ts_B, nb_row, &indices[0], nb_col,
604 &col_data.getIndices()[0], &k(0, 0), ADD_VALUES);
605 } else {
606 CHKERR MatSetValues(getFEMethod()->ts_B, nb_row,
607 &row_data.getIndices()[0], nb_col,
608 &col_data.getIndices()[0], &k(0, 0), ADD_VALUES);
609 }
610 }
612}
613
615 const std::string field_name, const std::string col_field, BlockData &data,
616 CommonData &common_data)
617 : OpMassLhs_dM_dv(field_name, col_field, data, common_data) {}
618
620 EntitiesFieldData::EntData &col_data, int gg) {
622 FTensor::Index<'i', 3> i;
623 FTensor::Index<'j', 3> j;
624 FTensor::Index<'k', 3> k;
625 int nb_col = col_data.getIndices().size();
626 jac.clear();
627 FTensor::Tensor2<double *, 3, 3> t_jac(&jac(0, 0), &jac(0, 1), &jac(0, 2),
628 &jac(1, 0), &jac(1, 1), &jac(1, 2),
629 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
630 const int s = 3;
632 // T* d000, T* d001, T* d002,
633 // T* d010, T* d011, T* d012,
634 // T* d020, T* d021, T* d022,
635 // T* d100, T* d101, T* d102,
636 // T* d110, T* d111, T* d112,
637 // T* d120, T* d121, T* d122,
638 // T* d200, T* d201, T* d202,
639 // T* d210, T* d211, T* d212,
640 // T* d220, T* d221, T* d222,
641 &commonData.jacMass[gg](0, s + 0), &commonData.jacMass[gg](0, s + 1),
642 &commonData.jacMass[gg](0, s + 2), &commonData.jacMass[gg](0, s + 3),
643 &commonData.jacMass[gg](0, s + 4), &commonData.jacMass[gg](0, s + 5),
644 &commonData.jacMass[gg](0, s + 6), &commonData.jacMass[gg](0, s + 7),
645 &commonData.jacMass[gg](0, s + 8), &commonData.jacMass[gg](1, s + 0),
646 &commonData.jacMass[gg](1, s + 1), &commonData.jacMass[gg](1, s + 2),
647 &commonData.jacMass[gg](1, s + 3), &commonData.jacMass[gg](1, s + 4),
648 &commonData.jacMass[gg](1, s + 5), &commonData.jacMass[gg](1, s + 6),
649 &commonData.jacMass[gg](1, s + 7), &commonData.jacMass[gg](1, s + 8),
650 &commonData.jacMass[gg](2, s + 0), &commonData.jacMass[gg](2, s + 1),
651 &commonData.jacMass[gg](2, s + 2), &commonData.jacMass[gg](2, s + 3),
652 &commonData.jacMass[gg](2, s + 4), &commonData.jacMass[gg](2, s + 5),
653 &commonData.jacMass[gg](2, s + 6), &commonData.jacMass[gg](2, s + 7),
654 &commonData.jacMass[gg](2, s + 8));
655 double *diff_ptr =
656 const_cast<double *>(&(col_data.getDiffN(gg, nb_col / 3)(0, 0)));
657 FTensor::Tensor1<double *, 3> diff(diff_ptr, &diff_ptr[1], &diff_ptr[2], 3);
658 for (int dd = 0; dd < nb_col / 3; dd++) {
659 t_jac(i, j) += t_mass3(i, j, k) * diff(k);
660 ++diff;
661 ++t_jac;
662 }
664}
665
667 const std::string field_name, const std::string col_field, BlockData &data,
668 CommonData &common_data)
669 : OpMassLhs_dM_dv(field_name, col_field, data, common_data) {}
670
672 EntitiesFieldData::EntData &col_data, int gg) {
674 int nb_col = col_data.getIndices().size();
675 jac.clear();
676 double *base_ptr = const_cast<double *>(&col_data.getN(gg)[0]);
677 FTensor::Tensor0<double *> base(base_ptr, 1);
678 double *diff_ptr =
679 const_cast<double *>(&(col_data.getDiffN(gg, nb_col / 3)(0, 0)));
680 FTensor::Tensor1<double *, 3> diff(diff_ptr, &diff_ptr[1], &diff_ptr[2], 3);
681 FTensor::Tensor2<double *, 3, 3> t_jac(&jac(0, 0), &jac(0, 1), &jac(0, 2),
682 &jac(1, 0), &jac(1, 1), &jac(1, 2),
683 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
684 const int u = 3 + 9 + 9;
686 &commonData.jacMass[gg](0, u + 0), &commonData.jacMass[gg](0, u + 1),
687 &commonData.jacMass[gg](0, u + 2), &commonData.jacMass[gg](1, u + 0),
688 &commonData.jacMass[gg](1, u + 1), &commonData.jacMass[gg](1, u + 2),
689 &commonData.jacMass[gg](2, u + 0), &commonData.jacMass[gg](2, u + 1),
690 &commonData.jacMass[gg](2, u + 2));
691 const int s = 3 + 9 + 9 + 3;
693 // T* d000, T* d001, T* d002,
694 // T* d010, T* d011, T* d012,
695 // T* d020, T* d021, T* d022,
696 // T* d100, T* d101, T* d102,
697 // T* d110, T* d111, T* d112,
698 // T* d120, T* d121, T* d122,
699 // T* d200, T* d201, T* d202,
700 // T* d210, T* d211, T* d212,
701 // T* d220, T* d221, T* d222,
702 &commonData.jacMass[gg](0, s + 0), &commonData.jacMass[gg](0, s + 1),
703 &commonData.jacMass[gg](0, s + 2), &commonData.jacMass[gg](0, s + 3),
704 &commonData.jacMass[gg](0, s + 4), &commonData.jacMass[gg](0, s + 5),
705 &commonData.jacMass[gg](0, s + 6), &commonData.jacMass[gg](0, s + 7),
706 &commonData.jacMass[gg](0, s + 8), &commonData.jacMass[gg](1, s + 0),
707 &commonData.jacMass[gg](1, s + 1), &commonData.jacMass[gg](1, s + 2),
708 &commonData.jacMass[gg](1, s + 3), &commonData.jacMass[gg](1, s + 4),
709 &commonData.jacMass[gg](1, s + 5), &commonData.jacMass[gg](1, s + 6),
710 &commonData.jacMass[gg](1, s + 7), &commonData.jacMass[gg](1, s + 8),
711 &commonData.jacMass[gg](2, s + 0), &commonData.jacMass[gg](2, s + 1),
712 &commonData.jacMass[gg](2, s + 2), &commonData.jacMass[gg](2, s + 3),
713 &commonData.jacMass[gg](2, s + 4), &commonData.jacMass[gg](2, s + 5),
714 &commonData.jacMass[gg](2, s + 6), &commonData.jacMass[gg](2, s + 7),
715 &commonData.jacMass[gg](2, s + 8));
716 FTensor::Index<'i', 3> i;
717 FTensor::Index<'j', 3> j;
718 FTensor::Index<'k', 3> k;
719 for (int dd = 0; dd < nb_col / 3; dd++) {
720 t_jac(i, j) += t_mass1(i, j) * base * getFEMethod()->ts_a;
721 t_jac(i, j) += t_mass3(i, j, k) * diff(k);
722 ++base_ptr;
723 ++diff_ptr;
724 ++t_jac;
725 }
727}
728
730 BlockData &data,
731 CommonData &common_data,
735 dAta(data), commonData(common_data), V(v, true),
736 lInear(commonData.lInear) {}
737
739ConvectiveMassElement::OpEnergy::doWork(int row_side, EntityType row_type,
740 EntitiesFieldData::EntData &row_data) {
742
743 if (row_type != MBVERTEX) {
745 }
746 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
747 dAta.tEts.end()) {
749 }
750
751 {
752 double energy = 0;
753 for (unsigned int gg = 0; gg < row_data.getN().size1(); gg++) {
754 double val = getVolume() * getGaussPts()(3, gg);
755 double rho0 = dAta.rho0;
756 double rho;
757 if (lInear) {
758 rho = rho0;
759 } else {
760 h.resize(3, 3);
761 noalias(h) =
764 .size() > 0) {
765 H.resize(3, 3);
766 noalias(H) =
768 auto detH = determinantTensor3by3(H);
769 invH.resize(3, 3);
770 CHKERR invertTensor3by3(H, detH, invH);
771 F.resize(3, 3);
772 noalias(F) = prod(h, invH);
773 } else {
774 F.resize(3, 3);
775 noalias(F) = h;
776 }
777 double detF = determinantTensor3by3(F);
778 rho = detF * rho0;
779 }
780 v.resize(3);
782 energy += 0.5 * (rho * val) * inner_prod(v, v);
783 }
784 CHKERR VecSetValue(V, 0, energy, ADD_VALUES);
785 }
786
788}
789
791 const std::string field_name, BlockData &data, CommonData &common_data,
792 int tag, bool jacobian)
795 dAta(data), commonData(common_data), tAg(tag), jAcobian(jacobian),
796 fieldDisp(false) {}
797
799 int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data) {
801
802 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
803 dAta.tEts.end()) {
805 }
806
807 // do it only once, no need to repeat this for edges,faces or tets
808 if (row_type != MBVERTEX)
810
811 int nb_dofs = row_data.getIndices().size();
812 if (nb_dofs == 0)
814
815 {
816
817 v.resize(3);
818 dot_w.resize(3);
819 h.resize(3, 3);
820 h.clear();
821 F.resize(3, 3);
822 dot_W.resize(3);
823 dot_W.clear();
824 H.resize(3, 3);
825 H.clear();
826 invH.resize(3, 3);
827 invH.clear();
828 dot_u.resize(3);
829 for (int dd = 0; dd < 3; dd++) {
830 H(dd, dd) = 1;
831 invH(dd, dd) = 1;
832 }
833
834 a_res.resize(3);
835 int nb_gauss_pts = row_data.getN().size1();
836 commonData.valVel.resize(nb_gauss_pts);
837 commonData.jacVelRowPtr.resize(nb_gauss_pts);
838 commonData.jacVel.resize(nb_gauss_pts);
839
840 int nb_active_vars = 0;
841 for (int gg = 0; gg < nb_gauss_pts; gg++) {
842
843 if (gg == 0) {
844
845 trace_on(tAg);
846
847 for (int nn1 = 0; nn1 < 3; nn1++) { // 0
848 v[nn1] <<=
850 nb_active_vars++;
851 }
852 for (int nn1 = 0; nn1 < 3; nn1++) { // 3
853 dot_w[nn1] <<=
855 [gg][nn1];
856 nb_active_vars++;
857 }
859 .size() > 0) {
860 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+3 = 6
861 for (int nn2 = 0; nn2 < 3; nn2++) {
862 h(nn1, nn2) <<=
864 nn1, nn2);
865 if (fieldDisp) {
866 if (nn1 == nn2) {
867 h(nn1, nn2) += 1;
868 }
869 }
870 nb_active_vars++;
871 }
872 }
873 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+3+9
874 dot_W[nn1] <<=
876 .dataAtGaussPts["DOT_" + commonData.meshPositions][gg][nn1];
877 nb_active_vars++;
878 }
879 }
881 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+3+9+3
882 for (int nn2 = 0; nn2 < 3; nn2++) {
883 H(nn1, nn2) <<=
885 nn2);
886 nb_active_vars++;
887 }
888 }
889 }
890 detH = 1;
891
892 FTensor::Index<'i', 3> i;
893 FTensor::Index<'j', 3> j;
894 FTensor::Index<'k', 3> k;
895
896 using ActiveMat3 = MatrixBoundedArray<adouble, 9>;
900 auto t_invH =
902 auto t_dot_u =
903 FTensor::Tensor1<adouble *, 3>{&dot_u[0], &dot_u[1], &dot_u[2]};
904 auto t_dot_w =
905 FTensor::Tensor1<adouble *, 3>{&dot_w[0], &dot_w[1], &dot_w[2]};
906 auto t_dot_W =
907 FTensor::Tensor1<adouble *, 3>{&dot_W[0], &dot_W[1], &dot_W[2]};
908 auto t_v = FTensor::Tensor1<adouble *, 3>{&v[0], &v[1], &v[2]};
909 auto t_a_res =
910 FTensor::Tensor1<adouble *, 3>{&a_res[0], &a_res[1], &a_res[2]};
911
913 detH = determinantTensor3by3(H);
914 CHKERR invertTensor3by3(H, detH, invH);
915 t_F(i, j) = t_h(i, k) * t_invH(k, j);
916 } else {
917 t_F(i, j) = t_h(i, j);
918 }
919
920 t_dot_u(i) = t_dot_w(i) + t_F(i, j) * t_dot_W(j);
921 t_a_res(i) = t_v(i) - t_dot_u(i);
922 t_a_res(i) *= detH;
923
924 // dependant
925 VectorDouble &res = commonData.valVel[gg];
926 res.resize(3);
927 for (int rr = 0; rr < 3; rr++) {
928 a_res[rr] >>= res[rr];
929 }
930 trace_off();
931 }
932
933 active.resize(nb_active_vars);
934 int aa = 0;
935 for (int nn1 = 0; nn1 < 3; nn1++) {
936 active[aa++] =
938 }
939 for (int nn1 = 0; nn1 < 3; nn1++) {
940 active[aa++] =
942 .dataAtGaussPts["DOT_" + commonData.spatialPositions][gg][nn1];
943 }
945 0) {
946 for (int nn1 = 0; nn1 < 3; nn1++) {
947 for (int nn2 = 0; nn2 < 3; nn2++) {
948 if (fieldDisp && nn1 == nn2) {
949 active[aa++] =
951 nn1, nn2) +
952 1;
953 } else {
954 active[aa++] =
956 nn1, nn2);
957 }
958 }
959 }
960 for (int nn1 = 0; nn1 < 3; nn1++) {
961 active[aa++] =
963 .dataAtGaussPts["DOT_" + commonData.meshPositions][gg][nn1];
964 }
965 }
967 for (int nn1 = 0; nn1 < 3; nn1++) {
968 for (int nn2 = 0; nn2 < 3; nn2++) {
969 active[aa++] =
971 nn2);
972 }
973 }
974 }
975
976 if (!jAcobian) {
977 VectorDouble &res = commonData.valVel[gg];
978 if (gg > 0) {
979 res.resize(3);
980 int r;
981 r = ::function(tAg, 3, nb_active_vars, &active[0], &res[0]);
982 if (r != 3) {
983 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
984 "ADOL-C function evaluation with error");
985 }
986 }
987 double val = getVolume() * getGaussPts()(3, gg);
988 res *= val;
989 } else {
990 commonData.jacVelRowPtr[gg].resize(3);
991 commonData.jacVel[gg].resize(3, nb_active_vars);
992 for (int nn1 = 0; nn1 < 3; nn1++) {
993 (commonData.jacVelRowPtr[gg])[nn1] = &(commonData.jacVel[gg](nn1, 0));
994 }
995 int r;
996 r = jacobian(tAg, 3, nb_active_vars, &active[0],
997 &(commonData.jacVelRowPtr[gg])[0]);
998 if (r != 3) {
999 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1000 "ADOL-C function evaluation with error");
1001 }
1002 double val = getVolume() * getGaussPts()(3, gg);
1003 commonData.jacVel[gg] *= val;
1004 // std::cerr << gg << " : " << commonData.jacVel[gg] << std::endl;
1005 }
1006 }
1007 }
1009}
1010
1016
1018 int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data) {
1020
1021 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
1022 dAta.tEts.end()) {
1024 }
1025 int nb_dofs = row_data.getIndices().size();
1026 if (nb_dofs == 0)
1028
1029 auto base = row_data.getFTensor0N();
1030 int nb_base_functions = row_data.getN().size2();
1031 FTensor::Index<'i', 3> i;
1032
1033 {
1034
1035 nf.resize(nb_dofs);
1036 nf.clear();
1037
1038 for (unsigned int gg = 0; gg < row_data.getN().size1(); gg++) {
1039 FTensor::Tensor1<double *, 3> t_nf(&nf[0], &nf[1], &nf[2], 3);
1041 &commonData.valVel[gg][1],
1042 &commonData.valVel[gg][2]);
1043 int dd = 0;
1044 for (; dd < nb_dofs / 3; dd++) {
1045 t_nf(i) += base * res(i);
1046 ++base;
1047 ++t_nf;
1048 }
1049 for (; dd != nb_base_functions; dd++) {
1050 ++base;
1051 }
1052 }
1053
1054 if (row_data.getIndices().size() > 3 * row_data.getN().size2()) {
1055 SETERRQ(PETSC_COMM_SELF, 1, "data inconsistency");
1056 }
1057 CHKERR VecSetValues(getFEMethod()->ts_F, row_data.getIndices().size(),
1058 &row_data.getIndices()[0], &nf[0], ADD_VALUES);
1059 }
1061}
1062
1064 const std::string vel_field, const std::string field_name, BlockData &data,
1065 CommonData &common_data)
1066 : OpMassLhs_dM_dv(vel_field, field_name, data, common_data) {}
1067
1069 EntitiesFieldData::EntData &col_data, int gg) {
1071 int nb_col = col_data.getIndices().size();
1072 jac.clear();
1073 if (!nb_col)
1075 double *base_ptr = const_cast<double *>(&col_data.getN(gg)[0]);
1076 FTensor::Tensor0<double *> base(base_ptr, 1);
1077 FTensor::Tensor2<double *, 3, 3> t_jac(&jac(0, 0), &jac(0, 1), &jac(0, 2),
1078 &jac(1, 0), &jac(1, 1), &jac(1, 2),
1079 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
1081 &commonData.jacVel[gg](0, 0), &commonData.jacVel[gg](0, 1),
1082 &commonData.jacVel[gg](0, 2), &commonData.jacVel[gg](1, 0),
1083 &commonData.jacVel[gg](1, 1), &commonData.jacVel[gg](1, 2),
1084 &commonData.jacVel[gg](2, 0), &commonData.jacVel[gg](2, 1),
1085 &commonData.jacVel[gg](2, 2));
1086 FTensor::Index<'i', 3> i;
1087 FTensor::Index<'j', 3> j;
1088 for (int dd = 0; dd < nb_col / 3; dd++) {
1089 t_jac(i, j) += t_mass1(i, j) * base;
1090 ++base_ptr;
1091 ++t_jac;
1092 }
1093
1095}
1096
1098 const std::string vel_field, const std::string field_name, BlockData &data,
1099 CommonData &common_data)
1100 : OpVelocityLhs_dV_dv(vel_field, field_name, data, common_data) {}
1101
1103 EntitiesFieldData::EntData &col_data, int gg) {
1105 int nb_col = col_data.getIndices().size();
1106 jac.clear();
1107 if (!nb_col)
1109 double *base_ptr = const_cast<double *>(&col_data.getN(gg)[0]);
1110 FTensor::Tensor0<double *> base(base_ptr, 1);
1111 FTensor::Tensor2<double *, 3, 3> t_jac(&jac(0, 0), &jac(0, 1), &jac(0, 2),
1112 &jac(1, 0), &jac(1, 1), &jac(1, 2),
1113 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
1114 const int u = 3;
1116 &commonData.jacVel[gg](0, u + 0), &commonData.jacVel[gg](0, u + 1),
1117 &commonData.jacVel[gg](0, u + 2), &commonData.jacVel[gg](1, u + 0),
1118 &commonData.jacVel[gg](1, u + 1), &commonData.jacVel[gg](1, u + 2),
1119 &commonData.jacVel[gg](2, u + 0), &commonData.jacVel[gg](2, u + 1),
1120 &commonData.jacVel[gg](2, u + 2));
1121 FTensor::Index<'i', 3> i;
1122 FTensor::Index<'j', 3> j;
1123 FTensor::Index<'k', 3> k;
1124 if (commonData.dataAtGaussPts["DOT_" + commonData.meshPositions].size() ==
1125 0) {
1126
1127 for (int dd = 0; dd < nb_col / 3; dd++) {
1128 t_jac(i, j) += t_mass1(i, j) * base * getFEMethod()->ts_a;
1129 ++base_ptr;
1130 ++t_jac;
1131 }
1132 } else {
1133 double *diff_ptr =
1134 const_cast<double *>(&(col_data.getDiffN(gg, nb_col / 3)(0, 0)));
1135 FTensor::Tensor1<double *, 3> diff(diff_ptr, &diff_ptr[1], &diff_ptr[2], 3);
1136 const int s = 3 + 3;
1138 // T* d000, T* d001, T* d002,
1139 // T* d010, T* d011, T* d012,
1140 // T* d020, T* d021, T* d022,
1141 // T* d100, T* d101, T* d102,
1142 // T* d110, T* d111, T* d112,
1143 // T* d120, T* d121, T* d122,
1144 // T* d200, T* d201, T* d202,
1145 // T* d210, T* d211, T* d212,
1146 // T* d220, T* d221, T* d222,
1147 &commonData.jacVel[gg](0, s + 0), &commonData.jacVel[gg](0, s + 1),
1148 &commonData.jacVel[gg](0, s + 2), &commonData.jacVel[gg](0, s + 3),
1149 &commonData.jacVel[gg](0, s + 4), &commonData.jacVel[gg](0, s + 5),
1150 &commonData.jacVel[gg](0, s + 6), &commonData.jacVel[gg](0, s + 7),
1151 &commonData.jacVel[gg](0, s + 8), &commonData.jacVel[gg](1, s + 0),
1152 &commonData.jacVel[gg](1, s + 1), &commonData.jacVel[gg](1, s + 2),
1153 &commonData.jacVel[gg](1, s + 3), &commonData.jacVel[gg](1, s + 4),
1154 &commonData.jacVel[gg](1, s + 5), &commonData.jacVel[gg](1, s + 6),
1155 &commonData.jacVel[gg](1, s + 7), &commonData.jacVel[gg](1, s + 8),
1156 &commonData.jacVel[gg](2, s + 0), &commonData.jacVel[gg](2, s + 1),
1157 &commonData.jacVel[gg](2, s + 2), &commonData.jacVel[gg](2, s + 3),
1158 &commonData.jacVel[gg](2, s + 4), &commonData.jacVel[gg](2, s + 5),
1159 &commonData.jacVel[gg](2, s + 6), &commonData.jacVel[gg](2, s + 7),
1160 &commonData.jacVel[gg](2, s + 8));
1161 for (int dd = 0; dd < nb_col / 3; dd++) {
1162 t_jac(i, j) += t_mass1(i, j) * base * getFEMethod()->ts_a;
1163 t_jac(i, j) += t_mass3(i, j, k) * diff(k);
1164 ++base_ptr;
1165 ++diff_ptr;
1166 ++t_jac;
1167 }
1168 }
1170}
1171
1173 const std::string vel_field, const std::string field_name, BlockData &data,
1174 CommonData &common_data)
1175 : OpVelocityLhs_dV_dv(vel_field, field_name, data, common_data) {}
1176
1178 EntitiesFieldData::EntData &col_data, int gg) {
1180 int nb_col = col_data.getIndices().size();
1181 jac.clear();
1182 if (!nb_col)
1184 double *base_ptr = const_cast<double *>(&col_data.getN(gg)[0]);
1185 FTensor::Tensor0<double *> base(base_ptr, 1);
1186 double *diff_ptr =
1187 const_cast<double *>(&(col_data.getDiffN(gg, nb_col / 3)(0, 0)));
1188 FTensor::Tensor1<double *, 3> diff(diff_ptr, &diff_ptr[1], &diff_ptr[2], 3);
1189 FTensor::Tensor2<double *, 3, 3> t_jac(&jac(0, 0), &jac(0, 1), &jac(0, 2),
1190 &jac(1, 0), &jac(1, 1), &jac(1, 2),
1191 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
1192 const int u = 3 + 3 + 9;
1194 &commonData.jacVel[gg](0, u + 0), &commonData.jacVel[gg](0, u + 1),
1195 &commonData.jacVel[gg](0, u + 2), &commonData.jacVel[gg](1, u + 0),
1196 &commonData.jacVel[gg](1, u + 1), &commonData.jacVel[gg](1, u + 2),
1197 &commonData.jacVel[gg](2, u + 0), &commonData.jacVel[gg](2, u + 1),
1198 &commonData.jacVel[gg](2, u + 2));
1199 const int s = 3 + 3 + 9 + 3;
1201 // T* d000, T* d001, T* d002,
1202 // T* d010, T* d011, T* d012,
1203 // T* d020, T* d021, T* d022,
1204 // T* d100, T* d101, T* d102,
1205 // T* d110, T* d111, T* d112,
1206 // T* d120, T* d121, T* d122,
1207 // T* d200, T* d201, T* d202,
1208 // T* d210, T* d211, T* d212,
1209 // T* d220, T* d221, T* d222,
1210 &commonData.jacVel[gg](0, s + 0), &commonData.jacVel[gg](0, s + 1),
1211 &commonData.jacVel[gg](0, s + 2), &commonData.jacVel[gg](0, s + 3),
1212 &commonData.jacVel[gg](0, s + 4), &commonData.jacVel[gg](0, s + 5),
1213 &commonData.jacVel[gg](0, s + 6), &commonData.jacVel[gg](0, s + 7),
1214 &commonData.jacVel[gg](0, s + 8), &commonData.jacVel[gg](1, s + 0),
1215 &commonData.jacVel[gg](1, s + 1), &commonData.jacVel[gg](1, s + 2),
1216 &commonData.jacVel[gg](1, s + 3), &commonData.jacVel[gg](1, s + 4),
1217 &commonData.jacVel[gg](1, s + 5), &commonData.jacVel[gg](1, s + 6),
1218 &commonData.jacVel[gg](1, s + 7), &commonData.jacVel[gg](1, s + 8),
1219 &commonData.jacVel[gg](2, s + 0), &commonData.jacVel[gg](2, s + 1),
1220 &commonData.jacVel[gg](2, s + 2), &commonData.jacVel[gg](2, s + 3),
1221 &commonData.jacVel[gg](2, s + 4), &commonData.jacVel[gg](2, s + 5),
1222 &commonData.jacVel[gg](2, s + 6), &commonData.jacVel[gg](2, s + 7),
1223 &commonData.jacVel[gg](2, s + 8));
1224 FTensor::Index<'i', 3> i;
1225 FTensor::Index<'j', 3> j;
1226 FTensor::Index<'k', 3> k;
1227 for (int dd = 0; dd < nb_col / 3; dd++) {
1228 t_jac(i, j) += t_mass1(i, j) * base * getFEMethod()->ts_a;
1229 t_jac(i, j) += t_mass3(i, j, k) * diff(k);
1230 ++base_ptr;
1231 ++diff_ptr;
1232 ++t_jac;
1233 }
1235}
1236
1239 BlockData &data,
1240 CommonData &common_data, int tag,
1241 bool jacobian)
1244 dAta(data), commonData(common_data), tAg(tag), jAcobian(jacobian),
1245 fieldDisp(false) {}
1246
1249 int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data) {
1251
1252 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
1253 dAta.tEts.end()) {
1255 }
1256
1257 // do it only once, no need to repeat this for edges,faces or tets
1258 if (row_type != MBVERTEX)
1260
1261 int nb_dofs = row_data.getIndices().size();
1262 if (nb_dofs == 0)
1264
1265 try {
1266
1267 a.resize(3);
1268 v.resize(3);
1269 g.resize(3, 3);
1270 G.resize(3, 3);
1271 h.resize(3, 3);
1272 F.resize(3, 3);
1273 H.resize(3, 3);
1274 H.clear();
1275 invH.resize(3, 3);
1276 invH.clear();
1277 for (int dd = 0; dd < 3; dd++) {
1278 H(dd, dd) = 1;
1279 invH(dd, dd) = 1;
1280 }
1281
1282 int nb_gauss_pts = row_data.getN().size1();
1283 commonData.valT.resize(nb_gauss_pts);
1284 commonData.jacTRowPtr.resize(nb_gauss_pts);
1285 commonData.jacT.resize(nb_gauss_pts);
1286
1287 int nb_active_vars = 0;
1288 for (int gg = 0; gg < nb_gauss_pts; gg++) {
1289
1290 if (gg == 0) {
1291
1292 trace_on(tAg);
1293
1294 for (int nn1 = 0; nn1 < 3; nn1++) { // 0
1295 a[nn1] <<=
1297 [gg][nn1];
1298 nb_active_vars++;
1299 }
1300
1301 for (int nn1 = 0; nn1 < 3; nn1++) { // 3
1302 v[nn1] <<=
1304 nb_active_vars++;
1305 }
1306 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+3
1307 for (int nn2 = 0; nn2 < 3; nn2++) {
1308 g(nn1, nn2) <<=
1310 nn1, nn2);
1311 nb_active_vars++;
1312 }
1313 }
1314 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+3+9
1315 for (int nn2 = 0; nn2 < 3; nn2++) {
1316 h(nn1, nn2) <<=
1318 nn2);
1319 nb_active_vars++;
1320 if (fieldDisp) {
1321 if (nn1 == nn2) {
1322 h(nn1, nn2) += 1;
1323 }
1324 }
1325 }
1326 }
1328 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+3+9+9
1329 for (int nn2 = 0; nn2 < 3; nn2++) {
1330 H(nn1, nn2) <<=
1332 nn2);
1333 nb_active_vars++;
1334 }
1335 }
1336 }
1337 adouble detH;
1338 detH = 1;
1340 detH = determinantTensor3by3(H);
1341 }
1342 CHKERR invertTensor3by3(H, detH, invH);
1343
1344 FTensor::Index<'i', 3> i;
1345 FTensor::Index<'j', 3> j;
1346 FTensor::Index<'k', 3> k;
1347
1348 a_T.resize(3);
1349
1350 using ActiveMat3 = MatrixBoundedArray<adouble, 9>;
1352 auto t_invH =
1357
1358 auto t_a = FTensor::Tensor1<adouble *, 3>{&a[0], &a[1], &a[2]};
1359 auto t_v = FTensor::Tensor1<adouble *, 3>{&v[0], &v[1], &v[2]};
1360 auto t_a_T = FTensor::Tensor1<adouble *, 3>{&a_T[0], &a_T[1], &a_T[2]};
1361
1362 t_F(i, j) = t_h(i, k) * t_invH(k, j);
1363 t_G(i, j) = t_g(i, k) * t_invH(k, j);
1364 t_a_T(i) = t_F(k, i) * t_a(k) + t_G(k, i) * t_v(k);
1365 const auto rho0 = dAta.rho0;
1366 t_a_T(i) = -rho0 * detH;
1367
1368 commonData.valT[gg].resize(3);
1369 for (int nn = 0; nn < 3; nn++) {
1370 a_T[nn] >>= (commonData.valT[gg])[nn];
1371 }
1372 trace_off();
1373 }
1374
1375 active.resize(nb_active_vars);
1376 int aa = 0;
1377 for (int nn1 = 0; nn1 < 3; nn1++) { // 0
1378 active[aa++] =
1380 .dataAtGaussPts["DOT_" + commonData.spatialVelocities][gg][nn1];
1381 }
1382
1383 for (int nn1 = 0; nn1 < 3; nn1++) { // 3
1384 active[aa++] =
1386 }
1387 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+3
1388 for (int nn2 = 0; nn2 < 3; nn2++) {
1389 active[aa++] =
1391 nn2);
1392 }
1393 }
1394 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+3+9
1395 for (int nn2 = 0; nn2 < 3; nn2++) {
1396 if (fieldDisp && nn1 == nn2) {
1397 active[aa++] =
1399 nn1, nn2) +
1400 1;
1401 } else {
1402 active[aa++] =
1404 nn2);
1405 }
1406 }
1407 }
1409 for (int nn1 = 0; nn1 < 3; nn1++) { // 3+3+9+9
1410 for (int nn2 = 0; nn2 < 3; nn2++) {
1411 active[aa++] =
1413 nn2);
1414 }
1415 }
1416 }
1417
1418 if (!jAcobian) {
1419 VectorDouble &res = commonData.valT[gg];
1420 if (gg > 0) {
1421 res.resize(3);
1422 int r;
1423 r = ::function(tAg, 3, nb_active_vars, &active[0], &res[0]);
1424 if (r != 3) { // function is locally analytic
1425 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1426 "ADOL-C function evaluation with error r = %d", r);
1427 }
1428 }
1429 double val = getVolume() * getGaussPts()(3, gg);
1430 res *= val;
1431 } else {
1432 commonData.jacTRowPtr[gg].resize(3);
1433 commonData.jacT[gg].resize(3, nb_active_vars);
1434 for (int nn1 = 0; nn1 < 3; nn1++) {
1435 (commonData.jacTRowPtr[gg])[nn1] = &(commonData.jacT[gg](nn1, 0));
1436 }
1437 int r;
1438 r = jacobian(tAg, 3, nb_active_vars, &active[0],
1439 &(commonData.jacTRowPtr[gg])[0]);
1440 if (r != 3) {
1441 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1442 "ADOL-C function evaluation with error");
1443 }
1444 double val = getVolume() * getGaussPts()(3, gg);
1445 commonData.jacT[gg] *= val;
1446 }
1447 }
1448
1449 } catch (const std::exception &ex) {
1450 std::ostringstream ss;
1451 ss << "throw in method: " << ex.what() << std::endl;
1452 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "%s", ss.str().c_str());
1453 }
1454
1456}
1457
1460 BlockData &data,
1461 CommonData &common_data,
1462 Range *forcesonlyonentities_ptr)
1465 dAta(data), commonData(common_data) {
1466 if (forcesonlyonentities_ptr != NULL) {
1467 forcesOnlyOnEntities = *forcesonlyonentities_ptr;
1468 }
1469}
1470
1473 int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data) {
1475
1476 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
1477 dAta.tEts.end()) {
1479 }
1480 int nb_dofs = row_data.getIndices().size();
1481 if (nb_dofs == 0)
1483
1484 try {
1485
1486 nf.resize(nb_dofs);
1487 nf.clear();
1488
1489 auto base = row_data.getFTensor0N();
1490 int nb_base_functions = row_data.getN().size2();
1491 FTensor::Index<'i', 3> i;
1492
1493 for (unsigned int gg = 0; gg < row_data.getN().size1(); gg++) {
1494 FTensor::Tensor1<double *, 3> t_nf(&nf[0], &nf[1], &nf[2], 3);
1496 &commonData.valT[gg][1],
1497 &commonData.valT[gg][2]);
1498 int dd = 0;
1499 for (; dd < nb_dofs / 3; dd++) {
1500 t_nf(i) += base * res(i);
1501 ++base;
1502 ++t_nf;
1503 }
1504 for (; dd != nb_base_functions; dd++) {
1505 ++base;
1506 }
1507 }
1508
1509 if (row_data.getIndices().size() > 3 * row_data.getN().size2()) {
1510 SETERRQ(PETSC_COMM_SELF, 1, "data inconsistency");
1511 }
1512 if (!forcesOnlyOnEntities.empty()) {
1513 VectorInt indices = row_data.getIndices();
1514 VectorDofs &dofs = row_data.getFieldDofs();
1515 VectorDofs::iterator dit = dofs.begin();
1516 for (int ii = 0; dit != dofs.end(); dit++, ii++) {
1517 if (forcesOnlyOnEntities.find((*dit)->getEnt()) ==
1518 forcesOnlyOnEntities.end()) {
1519 // std::cerr << **dit << std::endl;
1520 indices[ii] = -1;
1521 }
1522 }
1523 // std::cerr << indices << std::endl;
1524 CHKERR VecSetValues(getFEMethod()->ts_F, indices.size(), &indices[0],
1525 &nf[0], ADD_VALUES);
1526 } else {
1527 CHKERR VecSetValues(getFEMethod()->ts_F, row_data.getIndices().size(),
1528 &row_data.getIndices()[0], &nf[0], ADD_VALUES);
1529 }
1530
1531 } catch (const std::exception &ex) {
1532 std::ostringstream ss;
1533 ss << "throw in method: " << ex.what() << std::endl;
1534 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "%s", ss.str().c_str());
1535 }
1536
1538}
1539
1541 OpEshelbyDynamicMaterialMomentumLhs_dv(const std::string vel_field,
1542 const std::string field_name,
1543 BlockData &data,
1544 CommonData &common_data,
1545 Range *forcesonlyonentities_ptr)
1547 vel_field, field_name, data, common_data, forcesonlyonentities_ptr) {}
1548
1551 EntitiesFieldData::EntData &col_data, int gg) {
1553 int nb_col = col_data.getIndices().size();
1554 jac.clear();
1555 double *base_ptr = const_cast<double *>(&col_data.getN(gg)[0]);
1556 FTensor::Tensor0<double *> base(base_ptr, 1);
1557 double *diff_ptr =
1558 const_cast<double *>(&(col_data.getDiffN(gg, nb_col / 3)(0, 0)));
1559 FTensor::Tensor1<double *, 3> diff(diff_ptr, &diff_ptr[1], &diff_ptr[2], 3);
1560 FTensor::Tensor2<double *, 3, 3> t_jac(&jac(0, 0), &jac(0, 1), &jac(0, 2),
1561 &jac(1, 0), &jac(1, 1), &jac(1, 2),
1562 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
1563 const int u = 3;
1565 &commonData.jacT[gg](0, u + 0), &commonData.jacT[gg](0, u + 1),
1566 &commonData.jacT[gg](0, u + 2), &commonData.jacT[gg](1, u + 0),
1567 &commonData.jacT[gg](1, u + 1), &commonData.jacT[gg](1, u + 2),
1568 &commonData.jacT[gg](2, u + 0), &commonData.jacT[gg](2, u + 1),
1569 &commonData.jacT[gg](2, u + 2));
1570 const int s = 3 + 3;
1572 // T* d000, T* d001, T* d002,
1573 // T* d010, T* d011, T* d012,
1574 // T* d020, T* d021, T* d022,
1575 // T* d100, T* d101, T* d102,
1576 // T* d110, T* d111, T* d112,
1577 // T* d120, T* d121, T* d122,
1578 // T* d200, T* d201, T* d202,
1579 // T* d210, T* d211, T* d212,
1580 // T* d220, T* d221, T* d222,
1581 &commonData.jacT[gg](0, s + 0), &commonData.jacT[gg](0, s + 1),
1582 &commonData.jacT[gg](0, s + 2), &commonData.jacT[gg](0, s + 3),
1583 &commonData.jacT[gg](0, s + 4), &commonData.jacT[gg](0, s + 5),
1584 &commonData.jacT[gg](0, s + 6), &commonData.jacT[gg](0, s + 7),
1585 &commonData.jacT[gg](0, s + 8), &commonData.jacT[gg](1, s + 0),
1586 &commonData.jacT[gg](1, s + 1), &commonData.jacT[gg](1, s + 2),
1587 &commonData.jacT[gg](1, s + 3), &commonData.jacT[gg](1, s + 4),
1588 &commonData.jacT[gg](1, s + 5), &commonData.jacT[gg](1, s + 6),
1589 &commonData.jacT[gg](1, s + 7), &commonData.jacT[gg](1, s + 8),
1590 &commonData.jacT[gg](2, s + 0), &commonData.jacT[gg](2, s + 1),
1591 &commonData.jacT[gg](2, s + 2), &commonData.jacT[gg](2, s + 3),
1592 &commonData.jacT[gg](2, s + 4), &commonData.jacT[gg](2, s + 5),
1593 &commonData.jacT[gg](2, s + 6), &commonData.jacT[gg](2, s + 7),
1594 &commonData.jacT[gg](2, s + 8));
1595 FTensor::Index<'i', 3> i;
1596 FTensor::Index<'j', 3> j;
1597 FTensor::Index<'k', 3> k;
1598 for (int dd = 0; dd < nb_col / 3; dd++) {
1599 t_jac(i, j) += t_mass1(i, j) * base * getFEMethod()->ts_a;
1600 t_jac(i, j) += t_mass3(i, j, k) * diff(k);
1601 ++base_ptr;
1602 ++diff_ptr;
1603 ++t_jac;
1604 }
1606}
1607
1609 OpEshelbyDynamicMaterialMomentumLhs_dx(const std::string vel_field,
1610 const std::string field_name,
1611 BlockData &data,
1612 CommonData &common_data,
1613 Range *forcesonlyonentities_ptr)
1615 vel_field, field_name, data, common_data, forcesonlyonentities_ptr) {}
1616
1619 EntitiesFieldData::EntData &col_data, int gg) {
1621 int nb_col = col_data.getIndices().size();
1622 jac.clear();
1623 double *diff_ptr =
1624 const_cast<double *>(&(col_data.getDiffN(gg, nb_col / 3)(0, 0)));
1625 FTensor::Tensor1<double *, 3> diff(diff_ptr, &diff_ptr[1], &diff_ptr[2], 3);
1626 FTensor::Tensor2<double *, 3, 3> t_jac(&jac(0, 0), &jac(0, 1), &jac(0, 2),
1627 &jac(1, 0), &jac(1, 1), &jac(1, 2),
1628 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
1629 const int s = 3 + 3 + 9;
1631 // T* d000, T* d001, T* d002,
1632 // T* d010, T* d011, T* d012,
1633 // T* d020, T* d021, T* d022,
1634 // T* d100, T* d101, T* d102,
1635 // T* d110, T* d111, T* d112,
1636 // T* d120, T* d121, T* d122,
1637 // T* d200, T* d201, T* d202,
1638 // T* d210, T* d211, T* d212,
1639 // T* d220, T* d221, T* d222,
1640 &commonData.jacT[gg](0, s + 0), &commonData.jacT[gg](0, s + 1),
1641 &commonData.jacT[gg](0, s + 2), &commonData.jacT[gg](0, s + 3),
1642 &commonData.jacT[gg](0, s + 4), &commonData.jacT[gg](0, s + 5),
1643 &commonData.jacT[gg](0, s + 6), &commonData.jacT[gg](0, s + 7),
1644 &commonData.jacT[gg](0, s + 8), &commonData.jacT[gg](1, s + 0),
1645 &commonData.jacT[gg](1, s + 1), &commonData.jacT[gg](1, s + 2),
1646 &commonData.jacT[gg](1, s + 3), &commonData.jacT[gg](1, s + 4),
1647 &commonData.jacT[gg](1, s + 5), &commonData.jacT[gg](1, s + 6),
1648 &commonData.jacT[gg](1, s + 7), &commonData.jacT[gg](1, s + 8),
1649 &commonData.jacT[gg](2, s + 0), &commonData.jacT[gg](2, s + 1),
1650 &commonData.jacT[gg](2, s + 2), &commonData.jacT[gg](2, s + 3),
1651 &commonData.jacT[gg](2, s + 4), &commonData.jacT[gg](2, s + 5),
1652 &commonData.jacT[gg](2, s + 6), &commonData.jacT[gg](2, s + 7),
1653 &commonData.jacT[gg](2, s + 8));
1654 FTensor::Index<'i', 3> i;
1655 FTensor::Index<'j', 3> j;
1656 FTensor::Index<'k', 3> k;
1657 for (int dd = 0; dd < nb_col / 3; dd++) {
1658 t_jac(i, j) += t_mass3(i, j, k) * diff(k);
1659 ++diff_ptr;
1660 ++t_jac;
1661 }
1663}
1664
1666 OpEshelbyDynamicMaterialMomentumLhs_dX(const std::string vel_field,
1667 const std::string field_name,
1668 BlockData &data,
1669 CommonData &common_data,
1670 Range *forcesonlyonentities_ptr)
1672 vel_field, field_name, data, common_data, forcesonlyonentities_ptr) {}
1673
1676 EntitiesFieldData::EntData &col_data, int gg) {
1678 int nb_col = col_data.getIndices().size();
1679 jac.clear();
1680 double *diff_ptr =
1681 const_cast<double *>(&(col_data.getDiffN(gg, nb_col / 3)(0, 0)));
1682 FTensor::Tensor1<double *, 3> diff(diff_ptr, &diff_ptr[1], &diff_ptr[2], 3);
1683 FTensor::Tensor2<double *, 3, 3> t_jac(&jac(0, 0), &jac(0, 1), &jac(0, 2),
1684 &jac(1, 0), &jac(1, 1), &jac(1, 2),
1685 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
1686 const int s = 3 + 3 + 9 + 9;
1688 // T* d000, T* d001, T* d002,
1689 // T* d010, T* d011, T* d012,
1690 // T* d020, T* d021, T* d022,
1691 // T* d100, T* d101, T* d102,
1692 // T* d110, T* d111, T* d112,
1693 // T* d120, T* d121, T* d122,
1694 // T* d200, T* d201, T* d202,
1695 // T* d210, T* d211, T* d212,
1696 // T* d220, T* d221, T* d222,
1697 &commonData.jacT[gg](0, s + 0), &commonData.jacT[gg](0, s + 1),
1698 &commonData.jacT[gg](0, s + 2), &commonData.jacT[gg](0, s + 3),
1699 &commonData.jacT[gg](0, s + 4), &commonData.jacT[gg](0, s + 5),
1700 &commonData.jacT[gg](0, s + 6), &commonData.jacT[gg](0, s + 7),
1701 &commonData.jacT[gg](0, s + 8), &commonData.jacT[gg](1, s + 0),
1702 &commonData.jacT[gg](1, s + 1), &commonData.jacT[gg](1, s + 2),
1703 &commonData.jacT[gg](1, s + 3), &commonData.jacT[gg](1, s + 4),
1704 &commonData.jacT[gg](1, s + 5), &commonData.jacT[gg](1, s + 6),
1705 &commonData.jacT[gg](1, s + 7), &commonData.jacT[gg](1, s + 8),
1706 &commonData.jacT[gg](2, s + 0), &commonData.jacT[gg](2, s + 1),
1707 &commonData.jacT[gg](2, s + 2), &commonData.jacT[gg](2, s + 3),
1708 &commonData.jacT[gg](2, s + 4), &commonData.jacT[gg](2, s + 5),
1709 &commonData.jacT[gg](2, s + 6), &commonData.jacT[gg](2, s + 7),
1710 &commonData.jacT[gg](2, s + 8));
1711 FTensor::Index<'i', 3> i;
1712 FTensor::Index<'j', 3> j;
1713 FTensor::Index<'k', 3> k;
1714 for (int dd = 0; dd < nb_col / 3; dd++) {
1715 t_jac(i, j) += t_mass3(i, j, k) * diff(k);
1716 ++diff_ptr;
1717 ++t_jac;
1718 }
1720}
1721
1723 MoFEM::Interface &m_field, TS _ts, const std::string velocity_field,
1724 const std::string spatial_position_field)
1725 : mField(m_field), tS(_ts), velocityField(velocity_field),
1726 spatialPositionField(spatial_position_field), jacobianLag(-1) {}
1727
1730
1731 switch (ts_ctx) {
1732 case CTX_TSSETIFUNCTION: {
1733 snes_f = ts_F;
1734 // FIXME: This global scattering because Kuu problem and Dynamic problem
1735 // not share partitions. Both problem should use the same partitioning to
1736 // resolve this problem.
1737 CHKERR mField.getInterface<VecManager>()->setGlobalGhostVector(
1738 problemPtr, COL, ts_u, INSERT_VALUES, SCATTER_REVERSE);
1739 CHKERR mField.getInterface<VecManager>()->setOtherGlobalGhostVector(
1740 problemPtr, velocityField, "DOT_" + velocityField, COL, ts_u_t,
1741 INSERT_VALUES, SCATTER_REVERSE);
1742 CHKERR mField.getInterface<VecManager>()->setOtherGlobalGhostVector(
1743 problemPtr, spatialPositionField, "DOT_" + spatialPositionField, COL,
1744 ts_u_t, INSERT_VALUES, SCATTER_REVERSE);
1745 break;
1746 }
1747 case CTX_TSSETIJACOBIAN: {
1748 snes_B = ts_B;
1749 break;
1750 }
1751 default:
1752 break;
1753 }
1754
1756}
1757
1760 //
1761 // SNES snes;
1762 // CHKERR TSGetSNES(tS,&snes);
1763 // CHKERR SNESSetLagJacobian(snes,jacobianLag);
1765}
1766
1769
1770 Range added_tets;
1772 mField, BLOCKSET | BODYFORCESSET, it)) {
1773 int id = it->getMeshsetId();
1774 EntityHandle meshset = it->getMeshset();
1775 CHKERR mField.get_moab().get_entities_by_type(meshset, MBTET,
1776 setOfBlocks[id].tEts, true);
1777 added_tets.merge(setOfBlocks[id].tEts);
1778 Block_BodyForces mydata;
1779 CHKERR it->getAttributeDataStructure(mydata);
1780 setOfBlocks[id].rho0 = mydata.data.density;
1781 setOfBlocks[id].a0.resize(3);
1782 setOfBlocks[id].a0[0] = mydata.data.acceleration_x;
1783 setOfBlocks[id].a0[1] = mydata.data.acceleration_y;
1784 setOfBlocks[id].a0[2] = mydata.data.acceleration_z;
1785 // std::cerr << setOfBlocks[id].tEts << std::endl;
1786 }
1787
1789 mField, BLOCKSET | MAT_ELASTICSET, it)) {
1790 Mat_Elastic mydata;
1791 CHKERR it->getAttributeDataStructure(mydata);
1792 if (mydata.data.User1 == 0)
1793 continue;
1794 Range tets;
1795 EntityHandle meshset = it->getMeshset();
1796 CHKERR mField.get_moab().get_entities_by_type(meshset, MBTET, tets, true);
1797 tets = subtract(tets, added_tets);
1798 if (tets.empty())
1799 continue;
1800 int id = it->getMeshsetId();
1801 setOfBlocks[-id].tEts = tets;
1802 setOfBlocks[-id].rho0 = mydata.data.User1;
1803 setOfBlocks[-id].a0.resize(3);
1804 setOfBlocks[-id].a0[0] = mydata.data.User2;
1805 setOfBlocks[-id].a0[1] = mydata.data.User3;
1806 setOfBlocks[-id].a0[2] = mydata.data.User4;
1807 // std::cerr << setOfBlocks[id].tEts << std::endl;
1808 }
1809
1811}
1812
1814 MoFEM::Interface &m_field,
1815 boost::shared_ptr<map<int, BlockData>> &block_sets_ptr) {
1817
1818 if (!block_sets_ptr)
1819 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1820 "Pointer to block of sets is null");
1821
1823 m_field, BLOCKSET | BODYFORCESSET, it)) {
1824 Block_BodyForces mydata;
1825 CHKERR it->getAttributeDataStructure(mydata);
1826 int id = it->getMeshsetId();
1827 auto &block_data = (*block_sets_ptr)[id];
1828 EntityHandle meshset = it->getMeshset();
1829 CHKERR m_field.get_moab().get_entities_by_dimension(meshset, 3,
1830 block_data.tEts, true);
1831 block_data.rho0 = mydata.data.density;
1832 block_data.a0.resize(3);
1833 block_data.a0[0] = mydata.data.acceleration_x;
1834 block_data.a0[1] = mydata.data.acceleration_y;
1835 block_data.a0[2] = mydata.data.acceleration_z;
1836 }
1837
1839}
1840
1842 string element_name, string velocity_field_name,
1843 string spatial_position_field_name, string material_position_field_name,
1844 bool ale, BitRefLevel bit) {
1846
1847 //
1848
1849 CHKERR mField.add_finite_element(element_name, MF_ZERO);
1851 velocity_field_name);
1853 velocity_field_name);
1855 velocity_field_name);
1857 element_name, spatial_position_field_name);
1859 element_name, spatial_position_field_name);
1861 element_name, spatial_position_field_name);
1862 if (mField.check_field(material_position_field_name)) {
1863 if (ale) {
1865 element_name, material_position_field_name);
1867 element_name, material_position_field_name);
1869 element_name, "DOT_" + material_position_field_name);
1870 }
1872 element_name, material_position_field_name);
1873 }
1875 element_name, "DOT_" + velocity_field_name);
1877 element_name, "DOT_" + spatial_position_field_name);
1878
1879 Range tets;
1880 if (bit.any()) {
1881 CHKERR mField.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
1882 bit, BitRefLevel().set(), MBTET, tets);
1883 }
1884
1885 std::map<int, BlockData>::iterator sit = setOfBlocks.begin();
1886 for (; sit != setOfBlocks.end(); sit++) {
1887 Range add_tets = sit->second.tEts;
1888 if (!tets.empty()) {
1889 add_tets = intersect(add_tets, tets);
1890 }
1892 element_name);
1893 }
1894
1896}
1897
1899 string element_name, string velocity_field_name,
1900 string spatial_position_field_name, string material_position_field_name,
1901 bool ale, BitRefLevel bit) {
1903
1904 //
1905
1906 CHKERR mField.add_finite_element(element_name, MF_ZERO);
1908 velocity_field_name);
1910 velocity_field_name);
1912 velocity_field_name);
1914 element_name, spatial_position_field_name);
1916 element_name, spatial_position_field_name);
1917 if (mField.check_field(material_position_field_name)) {
1918 if (ale) {
1920 element_name, material_position_field_name);
1922 element_name, "DOT_" + material_position_field_name);
1923 }
1925 element_name, material_position_field_name);
1926 }
1928 element_name, "DOT_" + velocity_field_name);
1930 element_name, "DOT_" + spatial_position_field_name);
1931
1932 Range tets;
1933 if (bit.any()) {
1934 CHKERR mField.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
1935 bit, BitRefLevel().set(), MBTET, tets);
1936 }
1937
1938 std::map<int, BlockData>::iterator sit = setOfBlocks.begin();
1939 for (; sit != setOfBlocks.end(); sit++) {
1940 Range add_tets = sit->second.tEts;
1941 if (!tets.empty()) {
1942 add_tets = intersect(add_tets, tets);
1943 }
1945 element_name);
1946 }
1947
1949}
1950
1952 string element_name, string velocity_field_name,
1953 string spatial_position_field_name, string material_position_field_name,
1954 bool ale, BitRefLevel bit, Range *intersected) {
1956
1957 //
1958
1959 CHKERR mField.add_finite_element(element_name, MF_ZERO);
1961 velocity_field_name);
1963 velocity_field_name);
1965 element_name, spatial_position_field_name);
1967 element_name, spatial_position_field_name);
1968 if (mField.check_field(material_position_field_name)) {
1969 if (ale) {
1971 element_name, material_position_field_name);
1973 element_name, material_position_field_name);
1975 element_name, "DOT_" + material_position_field_name);
1976 }
1978 element_name, material_position_field_name);
1979 }
1981 element_name, "DOT_" + velocity_field_name);
1983 element_name, "DOT_" + spatial_position_field_name);
1984
1985 Range tets;
1986 if (bit.any()) {
1987 CHKERR mField.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
1988 bit, BitRefLevel().set(), MBTET, tets);
1989 }
1990 if (intersected != NULL) {
1991 if (tets.empty()) {
1992 tets = *intersected;
1993 } else {
1994 tets = intersect(*intersected, tets);
1995 }
1996 }
1997
1998 std::map<int, BlockData>::iterator sit = setOfBlocks.begin();
1999 for (; sit != setOfBlocks.end(); sit++) {
2000 Range add_tets = sit->second.tEts;
2001 if (!tets.empty()) {
2002 add_tets = intersect(add_tets, tets);
2003 }
2005 element_name);
2006 }
2007
2009}
2010
2012 string velocity_field_name, string spatial_position_field_name,
2013 string material_position_field_name, bool ale, bool linear) {
2015
2016 commonData.spatialPositions = spatial_position_field_name;
2017 commonData.meshPositions = material_position_field_name;
2018 commonData.spatialVelocities = velocity_field_name;
2019 commonData.lInear = linear;
2020
2021 // Rhs
2022 feMassRhs.getOpPtrVector().push_back(
2023 new OpGetCommonDataAtGaussPts(velocity_field_name, commonData));
2024 feMassRhs.getOpPtrVector().push_back(
2025 new OpGetCommonDataAtGaussPts(spatial_position_field_name, commonData));
2026 feMassRhs.getOpPtrVector().push_back(
2027 new OpGetCommonDataAtGaussPts("DOT_" + velocity_field_name, commonData));
2029 "DOT_" + spatial_position_field_name, commonData));
2030 if (mField.check_field(material_position_field_name)) {
2032 material_position_field_name, commonData));
2033 if (ale) {
2035 "DOT_" + material_position_field_name, commonData));
2036 } else {
2037 feMassRhs.meshPositionsFieldName = material_position_field_name;
2038 }
2039 }
2040 std::map<int, BlockData>::iterator sit = setOfBlocks.begin();
2041 for (; sit != setOfBlocks.end(); sit++) {
2042 feMassRhs.getOpPtrVector().push_back(
2043 new OpMassJacobian(spatial_position_field_name, sit->second, commonData,
2044 methodsOp, tAg, false));
2045 feMassRhs.getOpPtrVector().push_back(
2046 new OpMassRhs(spatial_position_field_name, sit->second, commonData));
2047 }
2048
2049 // Lhs
2050 feMassLhs.getOpPtrVector().push_back(
2051 new OpGetCommonDataAtGaussPts(velocity_field_name, commonData));
2052 feMassLhs.getOpPtrVector().push_back(
2053 new OpGetCommonDataAtGaussPts(spatial_position_field_name, commonData));
2054 feMassLhs.getOpPtrVector().push_back(
2055 new OpGetCommonDataAtGaussPts("DOT_" + velocity_field_name, commonData));
2057 "DOT_" + spatial_position_field_name, commonData));
2058 if (mField.check_field(material_position_field_name)) {
2060 material_position_field_name, commonData));
2061 if (ale) {
2063 "DOT_" + material_position_field_name, commonData));
2064 } else {
2065 feMassLhs.meshPositionsFieldName = material_position_field_name;
2066 }
2067 }
2068 sit = setOfBlocks.begin();
2069 for (; sit != setOfBlocks.end(); sit++) {
2070 feMassLhs.getOpPtrVector().push_back(
2071 new OpMassJacobian(spatial_position_field_name, sit->second, commonData,
2072 methodsOp, tAg, true));
2073 feMassLhs.getOpPtrVector().push_back(
2074 new OpMassLhs_dM_dv(spatial_position_field_name, velocity_field_name,
2075 sit->second, commonData));
2077 spatial_position_field_name, spatial_position_field_name, sit->second,
2078 commonData));
2079 if (mField.check_field(material_position_field_name)) {
2080 if (ale) {
2082 spatial_position_field_name, material_position_field_name,
2083 sit->second, commonData));
2084 } else {
2085 feMassLhs.meshPositionsFieldName = material_position_field_name;
2086 }
2087 }
2088 }
2089
2090 // Energy
2091 feEnergy.getOpPtrVector().push_back(
2092 new OpGetCommonDataAtGaussPts(velocity_field_name, commonData));
2093 feEnergy.getOpPtrVector().push_back(
2094 new OpGetCommonDataAtGaussPts(spatial_position_field_name, commonData));
2095 if (mField.check_field(material_position_field_name)) {
2097 material_position_field_name, commonData));
2098 feEnergy.meshPositionsFieldName = material_position_field_name;
2099 }
2100 sit = setOfBlocks.begin();
2101 for (; sit != setOfBlocks.end(); sit++) {
2102 feEnergy.getOpPtrVector().push_back(new OpEnergy(
2103 spatial_position_field_name, sit->second, commonData, feEnergy.V));
2104 }
2105
2107}
2108
2110 string velocity_field_name, string spatial_position_field_name,
2111 string material_position_field_name, bool ale) {
2113
2114 commonData.spatialPositions = spatial_position_field_name;
2115 commonData.meshPositions = material_position_field_name;
2116 commonData.spatialVelocities = velocity_field_name;
2117
2118 // Rhs
2119 feVelRhs.getOpPtrVector().push_back(
2120 new OpGetCommonDataAtGaussPts(velocity_field_name, commonData));
2121 feVelRhs.getOpPtrVector().push_back(
2122 new OpGetCommonDataAtGaussPts(spatial_position_field_name, commonData));
2123 feVelRhs.getOpPtrVector().push_back(
2124 new OpGetCommonDataAtGaussPts("DOT_" + velocity_field_name, commonData));
2125 if (mField.check_field(material_position_field_name)) {
2127 "DOT_" + spatial_position_field_name, commonData));
2129 material_position_field_name, commonData));
2130 if (ale) {
2132 "DOT_" + material_position_field_name, commonData));
2133 } else {
2134 feVelRhs.meshPositionsFieldName = material_position_field_name;
2135 }
2136 }
2137 std::map<int, BlockData>::iterator sit = setOfBlocks.begin();
2138 for (; sit != setOfBlocks.end(); sit++) {
2140 velocity_field_name, sit->second, commonData, tAg, false));
2141 feVelRhs.getOpPtrVector().push_back(
2142 new OpVelocityRhs(velocity_field_name, sit->second, commonData));
2143 }
2144
2145 // Lhs
2146 feVelLhs.getOpPtrVector().push_back(
2147 new OpGetCommonDataAtGaussPts(velocity_field_name, commonData));
2148 feVelLhs.getOpPtrVector().push_back(
2149 new OpGetCommonDataAtGaussPts(spatial_position_field_name, commonData));
2150 feVelLhs.getOpPtrVector().push_back(
2151 new OpGetCommonDataAtGaussPts("DOT_" + velocity_field_name, commonData));
2152 if (mField.check_field(material_position_field_name)) {
2154 "DOT_" + spatial_position_field_name, commonData));
2156 material_position_field_name, commonData));
2157 if (ale) {
2159 "DOT_" + material_position_field_name, commonData));
2160 } else {
2161 feVelLhs.meshPositionsFieldName = material_position_field_name;
2162 }
2163 }
2164 sit = setOfBlocks.begin();
2165 for (; sit != setOfBlocks.end(); sit++) {
2167 velocity_field_name, sit->second, commonData, tAg));
2169 velocity_field_name, velocity_field_name, sit->second, commonData));
2171 velocity_field_name, spatial_position_field_name, sit->second,
2172 commonData));
2173 if (mField.check_field(material_position_field_name)) {
2174 if (ale) {
2176 velocity_field_name, material_position_field_name, sit->second,
2177 commonData));
2178 } else {
2179 feVelLhs.meshPositionsFieldName = material_position_field_name;
2180 }
2181 }
2182 }
2183
2185}
2186
2188 string velocity_field_name, string spatial_position_field_name,
2189 string material_position_field_name, Range *forces_on_entities_ptr) {
2191
2192 commonData.spatialPositions = spatial_position_field_name;
2193 commonData.meshPositions = material_position_field_name;
2194 commonData.spatialVelocities = velocity_field_name;
2195
2196 // Rhs
2197 feTRhs.getOpPtrVector().push_back(
2198 new OpGetCommonDataAtGaussPts(velocity_field_name, commonData));
2199 feTRhs.getOpPtrVector().push_back(
2200 new OpGetCommonDataAtGaussPts(spatial_position_field_name, commonData));
2201 feTRhs.getOpPtrVector().push_back(
2202 new OpGetCommonDataAtGaussPts(material_position_field_name, commonData));
2203 feTRhs.getOpPtrVector().push_back(
2204 new OpGetCommonDataAtGaussPts("DOT_" + velocity_field_name, commonData));
2205
2206 std::map<int, BlockData>::iterator sit = setOfBlocks.begin();
2207 for (; sit != setOfBlocks.end(); sit++) {
2208 feTRhs.getOpPtrVector().push_back(
2210 material_position_field_name, sit->second, commonData, tAg, false));
2212 material_position_field_name, sit->second, commonData,
2213 forces_on_entities_ptr));
2214 }
2215
2216 // Lhs
2217 feTLhs.getOpPtrVector().push_back(
2218 new OpGetCommonDataAtGaussPts(velocity_field_name, commonData));
2219 feTLhs.getOpPtrVector().push_back(
2220 new OpGetCommonDataAtGaussPts(spatial_position_field_name, commonData));
2221 feTLhs.getOpPtrVector().push_back(
2222 new OpGetCommonDataAtGaussPts("DOT_" + velocity_field_name, commonData));
2223 if (mField.check_field(material_position_field_name)) {
2225 material_position_field_name, commonData));
2226 }
2227 sit = setOfBlocks.begin();
2228 for (; sit != setOfBlocks.end(); sit++) {
2229 feTLhs.getOpPtrVector().push_back(
2231 material_position_field_name, sit->second, commonData, tAg));
2232 feTLhs.getOpPtrVector().push_back(
2234 material_position_field_name, velocity_field_name, sit->second,
2235 commonData, forces_on_entities_ptr));
2236 feTLhs.getOpPtrVector().push_back(
2238 material_position_field_name, spatial_position_field_name,
2239 sit->second, commonData, forces_on_entities_ptr));
2240 feTLhs.getOpPtrVector().push_back(
2242 material_position_field_name, material_position_field_name,
2243 sit->second, commonData, forces_on_entities_ptr));
2244 }
2245
2247}
2248
2250 string velocity_field_name, string spatial_position_field_name,
2251 string material_position_field_name, bool linear) {
2253
2254 commonData.spatialPositions = spatial_position_field_name;
2255 commonData.meshPositions = material_position_field_name;
2256 commonData.spatialVelocities = velocity_field_name;
2257 commonData.lInear = linear;
2258
2259 // Rhs
2260 feMassRhs.getOpPtrVector().push_back(
2261 new OpGetCommonDataAtGaussPts(velocity_field_name, commonData));
2262 feMassRhs.getOpPtrVector().push_back(
2263 new OpGetCommonDataAtGaussPts(spatial_position_field_name, commonData));
2264 feMassRhs.getOpPtrVector().push_back(
2265 new OpGetCommonDataAtGaussPts("DOT_" + velocity_field_name, commonData));
2266 if (mField.check_field(material_position_field_name)) {
2268 material_position_field_name, commonData));
2269 feMassRhs.meshPositionsFieldName = material_position_field_name;
2270 }
2271 std::map<int, BlockData>::iterator sit = setOfBlocks.begin();
2272 for (; sit != setOfBlocks.end(); sit++) {
2273 feMassRhs.getOpPtrVector().push_back(
2274 new OpMassJacobian(spatial_position_field_name, sit->second, commonData,
2275 methodsOp, tAg, false));
2276 feMassRhs.getOpPtrVector().push_back(
2277 new OpMassRhs(spatial_position_field_name, sit->second, commonData));
2278 }
2279
2280 // Lhs
2281 feMassLhs.getOpPtrVector().push_back(
2282 new OpGetCommonDataAtGaussPts(velocity_field_name, commonData));
2283 feMassLhs.getOpPtrVector().push_back(
2284 new OpGetCommonDataAtGaussPts(spatial_position_field_name, commonData));
2285 feMassLhs.getOpPtrVector().push_back(
2286 new OpGetCommonDataAtGaussPts("DOT_" + velocity_field_name, commonData));
2287 if (mField.check_field(material_position_field_name)) {
2289 material_position_field_name, commonData));
2290 feMassLhs.meshPositionsFieldName = material_position_field_name;
2291 }
2292 sit = setOfBlocks.begin();
2293 for (; sit != setOfBlocks.end(); sit++) {
2294 feMassLhs.getOpPtrVector().push_back(
2295 new OpMassJacobian(spatial_position_field_name, sit->second, commonData,
2296 methodsOp, tAg, true));
2298 spatial_position_field_name, spatial_position_field_name, sit->second,
2299 commonData));
2300 if (mField.check_field(material_position_field_name)) {
2301 feMassLhs.meshPositionsFieldName = material_position_field_name;
2302 }
2303 }
2304
2305 // Aux Lhs
2306 feMassAuxLhs.getOpPtrVector().push_back(
2307 new OpGetCommonDataAtGaussPts(velocity_field_name, commonData));
2308 feMassAuxLhs.getOpPtrVector().push_back(
2309 new OpGetCommonDataAtGaussPts(spatial_position_field_name, commonData));
2310 feMassAuxLhs.getOpPtrVector().push_back(
2311 new OpGetCommonDataAtGaussPts("DOT_" + velocity_field_name, commonData));
2312 if (mField.check_field(material_position_field_name)) {
2314 material_position_field_name, commonData));
2315 feMassAuxLhs.meshPositionsFieldName = material_position_field_name;
2316 }
2317 sit = setOfBlocks.begin();
2318 for (; sit != setOfBlocks.end(); sit++) {
2319 feMassAuxLhs.getOpPtrVector().push_back(
2320 new OpMassJacobian(spatial_position_field_name, sit->second, commonData,
2321 methodsOp, tAg, true));
2323 spatial_position_field_name, spatial_position_field_name, sit->second,
2324 commonData));
2325 if (mField.check_field(material_position_field_name)) {
2326 feMassAuxLhs.meshPositionsFieldName = material_position_field_name;
2327 }
2328 }
2329
2330 // Energy E=0.5*rho*v*v
2331 feEnergy.getOpPtrVector().push_back(
2332 new OpGetCommonDataAtGaussPts(velocity_field_name, commonData));
2333 feEnergy.getOpPtrVector().push_back(
2334 new OpGetCommonDataAtGaussPts(spatial_position_field_name, commonData));
2335 if (mField.check_field(material_position_field_name)) {
2337 material_position_field_name, commonData));
2338 feEnergy.meshPositionsFieldName = material_position_field_name;
2339 }
2340 sit = setOfBlocks.begin();
2341 for (; sit != setOfBlocks.end(); sit++) {
2342 feEnergy.getOpPtrVector().push_back(new OpEnergy(
2343 spatial_position_field_name, sit->second, commonData, feEnergy.V));
2344 }
2345
2347}
2348
2351 if (iNitialized) {
2352
2353 CHKERR dEstroy();
2354 CHKERRABORT(PETSC_COMM_WORLD, ierr);
2355 }
2356}
2357
2360 if (!iNitialized) {
2361
2362#if PETSC_VERSION_GE(3, 5, 3)
2363 CHKERR MatCreateVecs(K, &u, &Ku);
2364 CHKERR MatCreateVecs(M, &v, &Mv);
2365#else
2366 CHKERR MatGetVecs(K, &u, &Ku);
2367 CHKERR MatGetVecs(M, &v, &Mv);
2368#endif
2369 CHKERR MatDuplicate(K, MAT_SHARE_NONZERO_PATTERN, &barK);
2370 iNitialized = true;
2371 }
2373}
2374
2377 if (iNitialized) {
2378
2379 CHKERR VecDestroy(&u);
2380 CHKERR VecDestroy(&Ku);
2381 CHKERR VecDestroy(&v);
2382 CHKERR VecDestroy(&Mv);
2383 CHKERR MatDestroy(&barK);
2384 iNitialized = false;
2385 }
2387}
2388
2391
2392 if (!initPC) {
2393 MPI_Comm comm;
2394 CHKERR PetscObjectGetComm((PetscObject)shellMat, &comm);
2395 CHKERR PCCreate(comm, &pC);
2396 initPC = true;
2397 }
2399}
2400
2403
2404 if (initPC) {
2405 CHKERR PCDestroy(&pC);
2406 initPC = false;
2407 }
2409}
2410
2414
2417
2418 if (ts_ctx != CTX_TSSETIFUNCTION) {
2419 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
2420 "It is used to residual of velocities");
2421 }
2422 if (!shellMatCtx->iNitialized) {
2423 CHKERR shellMatCtx->iNit();
2424 }
2425 // Note velocities calculate from displacements are stroed in shellMatCtx->u
2426 CHKERR VecScatterBegin(shellMatCtx->scatterU, ts_u_t, shellMatCtx->u,
2427 INSERT_VALUES, SCATTER_FORWARD);
2428 CHKERR VecScatterEnd(shellMatCtx->scatterU, ts_u_t, shellMatCtx->u,
2429 INSERT_VALUES, SCATTER_FORWARD);
2430 CHKERR VecScatterBegin(shellMatCtx->scatterV, ts_u, shellMatCtx->v,
2431 INSERT_VALUES, SCATTER_FORWARD);
2432 CHKERR VecScatterEnd(shellMatCtx->scatterV, ts_u, shellMatCtx->v,
2433 INSERT_VALUES, SCATTER_FORWARD);
2434 CHKERR VecAXPY(shellMatCtx->v, -1, shellMatCtx->u);
2435 CHKERR VecScatterBegin(shellMatCtx->scatterV, shellMatCtx->v, ts_F,
2436 ADD_VALUES, SCATTER_REVERSE);
2437 CHKERR VecScatterEnd(shellMatCtx->scatterV, shellMatCtx->v, ts_F, ADD_VALUES,
2438 SCATTER_REVERSE);
2439 // VecView(shellMatCtx->v,PETSC_VIEWER_STDOUT_WORLD);
2440
2442}
2443
2444#ifdef __DIRICHLET_HPP__
2445
2446ConvectiveMassElement::ShellMatrixElement::ShellMatrixElement(
2447 MoFEM::Interface &m_field)
2448 : mField(m_field) {}
2449
2450MoFEMErrorCode ConvectiveMassElement::ShellMatrixElement::preProcess() {
2452
2453 if (ts_ctx != CTX_TSSETIJACOBIAN) {
2454 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
2455 "It is used to calculate shell matrix only");
2456 }
2457
2458 shellMatCtx->ts_a = ts_a;
2459 DirichletBcPtr->copyTs(*((TSMethod *)this)); // copy context for TSMethod
2460
2461 DirichletBcPtr->dIag = 1;
2462 DirichletBcPtr->ts_B = shellMatCtx->K;
2463 CHKERR MatZeroEntries(shellMatCtx->K);
2464 CHKERR mField.problem_basic_method_preProcess(problemName, *DirichletBcPtr);
2465 LoopsToDoType::iterator itk = loopK.begin();
2466 for (; itk != loopK.end(); itk++) {
2467 itk->second->copyTs(*((TSMethod *)this));
2468 itk->second->ts_B = shellMatCtx->K;
2469 CHKERR mField.loop_finite_elements(problemName, itk->first, *itk->second);
2470 }
2471 LoopsToDoType::iterator itam = loopAuxM.begin();
2472 for (; itam != loopAuxM.end(); itam++) {
2473 itam->second->copyTs(*((TSMethod *)this));
2474 itam->second->ts_B = shellMatCtx->K;
2475 CHKERR mField.loop_finite_elements(problemName, itam->first, *itam->second);
2476 }
2477 CHKERR mField.problem_basic_method_postProcess(problemName, *DirichletBcPtr);
2478 CHKERR MatAssemblyBegin(shellMatCtx->K, MAT_FINAL_ASSEMBLY);
2479 CHKERR MatAssemblyEnd(shellMatCtx->K, MAT_FINAL_ASSEMBLY);
2480
2481 DirichletBcPtr->dIag = 0;
2482 DirichletBcPtr->ts_B = shellMatCtx->M;
2483 CHKERR MatZeroEntries(shellMatCtx->M);
2484 // CHKERR mField.problem_basic_method_preProcess(problemName,*DirichletBcPtr);
2485 LoopsToDoType::iterator itm = loopM.begin();
2486 for (; itm != loopM.end(); itm++) {
2487 itm->second->copyTs(*((TSMethod *)this));
2488 itm->second->ts_B = shellMatCtx->M;
2489 CHKERR mField.loop_finite_elements(problemName, itm->first, *itm->second);
2490 }
2491 CHKERR mField.problem_basic_method_postProcess(problemName, *DirichletBcPtr);
2492 CHKERR MatAssemblyBegin(shellMatCtx->M, MAT_FINAL_ASSEMBLY);
2493 CHKERR MatAssemblyEnd(shellMatCtx->M, MAT_FINAL_ASSEMBLY);
2494
2495 // barK
2496 CHKERR MatZeroEntries(shellMatCtx->barK);
2497 CHKERR MatCopy(shellMatCtx->K, shellMatCtx->barK, SAME_NONZERO_PATTERN);
2498 CHKERR MatAXPY(shellMatCtx->barK, ts_a, shellMatCtx->M, SAME_NONZERO_PATTERN);
2499 CHKERR MatAssemblyBegin(shellMatCtx->barK, MAT_FINAL_ASSEMBLY);
2500 CHKERR MatAssemblyEnd(shellMatCtx->barK, MAT_FINAL_ASSEMBLY);
2501
2502 // Matrix View
2503 // MatView(shellMatCtx->barK,PETSC_VIEWER_DRAW_WORLD);//PETSC_VIEWER_STDOUT_WORLD);
2504 // std::string wait;
2505 // std::cin >> wait;
2506
2508}
2509
2510#endif //__DIRICHLET_HPP__
Operators and data structures for mass and convective mass element.
std::string type
constexpr double a
@ COL
@ MF_ZERO
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ BODYFORCESSET
block name is "BODY_FORCES"
@ MAT_ELASTICSET
block name is "MAT_ELASTIC"
@ BLOCKSET
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
constexpr int order
@ F
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string name_row)=0
set field col which finite element use
virtual MoFEMErrorCode add_ents_to_finite_element_by_type(const EntityHandle entities, const EntityType type, const std::string name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string name_row)=0
set field row which finite element use
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
virtual bool check_field(const std::string &name) const =0
check if field is in database
virtual MoFEMErrorCode problem_basic_method_postProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethod.
virtual MoFEMErrorCode loop_finite_elements(const std::string problem_name, const std::string &fe_name, FEMethod &method, boost::shared_ptr< NumeredEntFiniteElement_multiIndex > fe_ptr=nullptr, MoFEMTypes bh=MF_EXIST, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr(), int verb=DEFAULT_VERBOSITY)=0
Make a loop over finite elements.
#define _IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet in a moFEM field.
auto bit
set bit
constexpr double a0
FTensor::Index< 'i', SPACE_DIM > i
const double v
phase velocity of light in medium (cm/ns)
constexpr IntegrationType G
Definition level_set.cpp:33
MoFEM::TsCtx * ts_ctx
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
ublas::matrix< T, ublas::row_major, ublas::bounded_array< T, N > > MatrixBoundedArray
Definition Types.hpp:104
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
UBlasVector< int > VectorInt
Definition Types.hpp:67
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
MoFEMErrorCode invertTensor3by3(ublas::matrix< T, L, A > &jac_data, ublas::vector< T, A > &det_data, ublas::matrix< T, L, A > &inv_jac_data)
Calculate inverse of tensor rank 2 at integration points.
auto createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
MoFEMErrorCode MatSetValues(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const double *ptr, InsertMode iora)
Assemble PETSc matrix.
static auto determinantTensor3by3(T &t)
Calculate the determinant of a 3x3 matrix or a tensor of rank 2.
MoFEMErrorCode VecSetValues(Vec V, const EntitiesFieldData::EntData &data, const double *ptr, InsertMode iora)
Assemble PETSc vector.
ublas::vector< FEDofEntity *, DofsAllocator > VectorDofs
constexpr AssemblyType A
double h
constexpr auto field_name
constexpr double g
data for calculation inertia forces
common data used by volume elements
std::vector< std::vector< double * > > jacTRowPtr
std::map< std::string, std::vector< VectorDouble > > dataAtGaussPts
std::vector< std::vector< double * > > jacVelRowPtr
std::map< std::string, std::vector< MatrixDouble > > gradAtGaussPts
std::vector< std::vector< double * > > jacMassRowPtr
MoFEMErrorCode postProcess()
Post-processing function executed at loop completion.
int getRule(int order)
it is used to calculate nb. of Gauss integration points
MoFEMErrorCode preProcess()
Pre-processing function executed at loop initialization.
OpEnergy(const std::string field_name, BlockData &data, CommonData &common_data, SmartPetscObj< Vec > v)
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
OpEshelbyDynamicMaterialMomentumJacobian(const std::string field_name, BlockData &data, CommonData &common_data, int tag, bool jacobian=true)
OpEshelbyDynamicMaterialMomentumLhs_dX(const std::string vel_field, const std::string field_name, BlockData &data, CommonData &common_data, Range *forcesonlyonentities_ptr)
virtual MoFEMErrorCode getJac(EntitiesFieldData::EntData &col_data, int gg)
OpEshelbyDynamicMaterialMomentumLhs_dv(const std::string vel_field, const std::string field_name, BlockData &data, CommonData &common_data, Range *forcesonlyonentities_ptr)
virtual MoFEMErrorCode getJac(EntitiesFieldData::EntData &col_data, int gg)
virtual MoFEMErrorCode getJac(EntitiesFieldData::EntData &col_data, int gg)
OpEshelbyDynamicMaterialMomentumLhs_dx(const std::string vel_field, const std::string field_name, BlockData &data, CommonData &common_data, Range *forcesonlyonentities_ptr)
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
OpEshelbyDynamicMaterialMomentumRhs(const std::string field_name, BlockData &data, CommonData &common_data, Range *forcesonlyonentities_ptr)
OpGetCommonDataAtGaussPts(const std::string field_name, CommonData &common_data)
OpGetDataAtGaussPts(const std::string field_name, std::vector< VectorDouble > &values_at_gauss_pts, std::vector< MatrixDouble > &gardient_at_gauss_pts)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
operator calculating deformation gradient
OpMassJacobian(const std::string field_name, BlockData &data, CommonData &common_data, boost::ptr_vector< MethodForForceScaling > &methods_op, int tag, bool linear=false)
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
OpMassLhs_dM_dX(const std::string field_name, const std::string col_field, BlockData &data, CommonData &common_data)
MoFEMErrorCode getJac(EntitiesFieldData::EntData &col_data, int gg)
MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
OpMassLhs_dM_dv(const std::string vel_field, const std::string field_name, BlockData &data, CommonData &common_data, Range *forcesonlyonentities_ptr=NULL)
virtual MoFEMErrorCode getJac(EntitiesFieldData::EntData &col_data, int gg)
MoFEMErrorCode getJac(EntitiesFieldData::EntData &col_data, int gg)
OpMassLhs_dM_dx(const std::string field_name, const std::string col_field, BlockData &data, CommonData &common_data)
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
OpMassRhs(const std::string field_name, BlockData &data, CommonData &common_data)
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
OpVelocityJacobian(const std::string field_name, BlockData &data, CommonData &common_data, int tag, bool jacobian=true)
OpVelocityLhs_dV_dX(const std::string vel_field, const std::string field_name, BlockData &data, CommonData &common_data)
virtual MoFEMErrorCode getJac(EntitiesFieldData::EntData &col_data, int gg)
virtual MoFEMErrorCode getJac(EntitiesFieldData::EntData &col_data, int gg)
OpVelocityLhs_dV_dv(const std::string vel_field, const std::string field_name, BlockData &data, CommonData &common_data)
OpVelocityLhs_dV_dx(const std::string vel_field, const std::string field_name, BlockData &data, CommonData &common_data)
virtual MoFEMErrorCode getJac(EntitiesFieldData::EntData &col_data, int gg)
OpVelocityRhs(const std::string field_name, BlockData &data, CommonData &common_data)
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
MoFEMErrorCode preProcess()
Calculate inconsistency between approximation of velocities and velocities calculated from displaceme...
UpdateAndControl(MoFEM::Interface &m_field, TS _ts, const std::string velocity_field, const std::string spatial_position_field)
MoFEMErrorCode postProcess()
Post-processing function executed at loop completion.
MoFEMErrorCode preProcess()
Scatter values from t_u_dt on the fields.
structure grouping operators and data used for calculation of mass (convective) element \ nonlinear_e...
ConvectiveMassElement(MoFEM::Interface &m_field, short int tag)
MoFEMErrorCode setVelocityOperators(string velocity_field_name, string spatial_position_field_name, string material_position_field_name="MESH_NODE_POSITIONS", bool ale=false)
MyVolumeFE feEnergy
calculate kinetic energy
MoFEMErrorCode setShellMatrixMassOperators(string velocity_field_name, string spatial_position_field_name, string material_position_field_name="MESH_NODE_POSITIONS", bool linear=false)
MyVolumeFE feVelRhs
calculate right hand side for tetrahedral elements
MoFEMErrorCode addVelocityElement(string element_name, string velocity_field_name, string spatial_position_field_name, string material_position_field_name="MESH_NODE_POSITIONS", bool ale=false, BitRefLevel bit=BitRefLevel())
MoFEMErrorCode addConvectiveMassElement(string element_name, string velocity_field_name, string spatial_position_field_name, string material_position_field_name="MESH_NODE_POSITIONS", bool ale=false, BitRefLevel bit=BitRefLevel())
MoFEMErrorCode setKinematicEshelbyOperators(string velocity_field_name, string spatial_position_field_name, string material_position_field_name="MESH_NODE_POSITIONS", Range *forces_on_entities_ptr=NULL)
MoFEMErrorCode addEshelbyDynamicMaterialMomentum(string element_name, string velocity_field_name, string spatial_position_field_name, string material_position_field_name="MESH_NODE_POSITIONS", bool ale=false, BitRefLevel bit=BitRefLevel(), Range *intersected=NULL)
MyVolumeFE feTRhs
calculate right hand side for tetrahedral elements
MyVolumeFE feMassRhs
calculate right hand side for tetrahedral elements
MyVolumeFE feTLhs
calculate left hand side for tetrahedral elements
MoFEMErrorCode setConvectiveMassOperators(string velocity_field_name, string spatial_position_field_name, string material_position_field_name="MESH_NODE_POSITIONS", bool ale=false, bool linear=false)
boost::ptr_vector< MethodForForceScaling > methodsOp
std::map< int, BlockData > setOfBlocks
maps block set id with appropriate BlockData
MyVolumeFE feVelLhs
calculate left hand side for tetrahedral elements
static MoFEMErrorCode applyScale(const FEMethod *fe, boost::ptr_vector< MethodForForceScaling > &methods_op, VectorDouble &nf)
Managing BitRefLevels.
Body force data structure.
virtual moab::Interface & get_moab()=0
virtual MoFEMErrorCode problem_basic_method_preProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethod.
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
Deprecated interface functions.
Data on single entity (This is passed as argument to DataOperator::doWork)
FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0N(const FieldApproximationBase base)
Get base function as Tensor0.
MatrixDouble & getDiffN(const FieldApproximationBase base)
get derivatives of base functions
auto getFTensor1FieldData()
Return FTensor of rank 1, i.e. vector from field data coefficients.
auto getFTensor1DiffN(const FieldApproximationBase base)
Get derivatives of base functions.
MatrixDouble & getN(const FieldApproximationBase base)
get base functions this return matrix (nb. of rows is equal to nb. of Gauss pts, nb....
const VectorDouble & getFieldData() const
Get DOF values on entity.
const VectorDofs & getFieldDofs() const
Get DOF data structures (const version)
const VectorInt & getIndices() const
Get global indices of degrees of freedom on entity.
structure to get information from mofem into EntitiesFieldData
boost::ptr_deque< UserDataOperator > & getOpPtrVector()
Use to push back operator for row operator.
Get FTensor2 from array.
Elastic material data structure.
intrusive_ptr for managing petsc objects
Data structure for TS (time stepping) context.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Vector manager is used to create vectors \mofem_vectors.
double rho
Definition plastic.cpp:145
double H
Hardening.
Definition plastic.cpp:129