12#include <adolc/adolc.h>
13#include <MethodForForceScaling.hpp>
15#include <MethodForForceScaling.hpp>
19#error "MoFEM need to be compiled with ADOL-C"
26 auto create_vec = [&]() {
42 CHKERR VolumeElementForcesAndSourcesCore::preProcess();
58 CHKERR VolumeElementForcesAndSourcesCore::postProcess();
63 CHKERR VecAssemblyBegin(V);
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) {}
97 int nb_gauss_pts = data.
getN().size1();
98 int nb_base_functions = data.
getN().size2();
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);
109 if (
type == zeroAtType) {
110 for (
int gg = 0; gg < nb_gauss_pts; gg++) {
111 valuesAtGaussPts[gg].clear();
112 gradientAtGaussPts[gg].clear();
121 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
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));
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;
140 for (; bb != nb_base_functions; bb++) {
141 ++diff_base_functions;
155 boost::ptr_vector<MethodForForceScaling> &methods_op,
int tag,
159 dAta(data),
commonData(common_data),
tAg(tag), jAcobian(jacobian),
166 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
172 if (row_type != MBVERTEX)
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);
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++) {
201 int nb_gauss_pts = row_data.
getN().size1();
206 const std::vector<VectorDouble> &dot_spacial_vel =
209 const std::vector<MatrixDouble> &spatial_positions_grad =
212 const std::vector<MatrixDouble> &spatial_velocities_grad =
215 const std::vector<VectorDouble> &meshpos_vel =
218 const std::vector<MatrixDouble> &mesh_positions_gradient =
221 int nb_active_vars = 0;
222 for (
int gg = 0; gg < nb_gauss_pts; gg++) {
228 for (
int nn1 = 0; nn1 < 3; nn1++) {
230 a[nn1] <<= dot_spacial_vel[gg][nn1];
233 for (
int nn1 = 0; nn1 < 3; nn1++) {
234 for (
int nn2 = 0; nn2 < 3; nn2++) {
236 h(nn1, nn2) <<= spatial_positions_grad[gg](nn1, nn2);
247 for (
int nn1 = 0; nn1 < 3; nn1++) {
248 for (
int nn2 = 0; nn2 < 3; nn2++) {
250 g(nn1, nn2) <<= spatial_velocities_grad[gg](nn1, nn2);
254 for (
int nn1 = 0; nn1 < 3; nn1++) {
256 dot_W(nn1) <<= meshpos_vel[gg][nn1];
259 for (
int nn1 = 0; nn1 < 3; nn1++) {
260 for (
int nn2 = 0; nn2 < 3; nn2++) {
262 H(nn1, nn2) <<= mesh_positions_gradient[gg](nn1, nn2);
285 const double rho0 = dAta.rho0;
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);
297 t_F(
i,
j) = t_h(
i,
k) * t_invH(
k,
j);
298 t_a_res(
i) *= rho0 * detH;
303 t_a_res(
i) *= rho0 * detH;
309 for (
int rr = 0; rr < 3; rr++) {
310 a_res[rr] >>= res[rr];
316 active.resize(nb_active_vars);
318 for (
int nn1 = 0; nn1 < 3; nn1++) {
319 active[aa++] = dot_spacial_vel[gg][nn1];
321 for (
int nn1 = 0; nn1 < 3; nn1++) {
322 for (
int nn2 = 0; nn2 < 3; nn2++) {
323 if (fieldDisp && nn1 == nn2) {
324 active[aa++] = spatial_positions_grad[gg](nn1, nn2) + 1;
326 active[aa++] = spatial_positions_grad[gg](nn1, nn2);
332 for (
int nn1 = 0; nn1 < 3; nn1++) {
333 for (
int nn2 = 0; nn2 < 3; nn2++) {
334 active[aa++] = spatial_velocities_grad[gg](nn1, nn2);
337 for (
int nn1 = 0; nn1 < 3; nn1++) {
338 active[aa++] = meshpos_vel[gg][nn1];
340 for (
int nn1 = 0; nn1 < 3; nn1++) {
341 for (
int nn2 = 0; nn2 < 3; nn2++) {
342 active[aa++] = mesh_positions_gradient[gg](nn1, nn2);
352 r = ::function(
tAg, 3, nb_active_vars, &active[0], &res[0]);
355 "ADOL-C function evaluation with error r = %d", r);
358 double val = getVolume() * getGaussPts()(3, gg);
364 for (
int nn1 = 0; nn1 < 3; nn1++) {
369 r = jacobian(
tAg, 3, nb_active_vars, &active[0],
373 "ADOL-C function evaluation with error");
375 double val = getVolume() * getGaussPts()(3, gg);
396 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
405 int nb_base_functions = row_data.
getN().size2();
414 for (
unsigned int gg = 0; gg < row_data.
getN().size1(); gg++) {
420 for (; dd < nb_dofs / 3; dd++) {
421 t_nf(
i) += base * res(
i);
425 for (; dd != nb_base_functions; dd++) {
430 if ((
unsigned int)nb_dofs > 3 * row_data.
getN().size2()) {
431 SETERRQ(PETSC_COMM_SELF, 1,
"data inconsistency");
448 if (forcesonlyonentities_ptr != NULL) {
464 &jac(1, 0), &jac(1, 1), &jac(1, 2),
465 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
472 double *base_ptr =
const_cast<double *
>(&col_data.
getN(gg)[0]);
476 for (
int dd = 0; dd < nb_col / 3; dd++) {
477 t_jac(
i,
j) += t_mass1(
i,
j) * base * getFEMethod()->ts_a;
509 const_cast<double *
>(&(col_data.
getDiffN(gg, nb_col / 3)(0, 0)));
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);
523 int row_side,
int col_side, EntityType row_type, EntityType col_type,
528 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
541 int nb_base_functions = row_data.
getN().size2();
545 k.resize(nb_row, nb_col);
547 jac.resize(3, nb_col);
549 for (
unsigned int gg = 0; gg < row_data.
getN().size1(); gg++) {
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;
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);
587 for (; dd1 != nb_base_functions; dd1++) {
593 if (!forcesOnlyOnEntities.empty()) {
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()) {
628 &jac(1, 0), &jac(1, 1), &jac(1, 2),
629 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
656 const_cast<double *
>(&(col_data.
getDiffN(gg, nb_col / 3)(0, 0)));
658 for (
int dd = 0; dd < nb_col / 3; dd++) {
659 t_jac(
i,
j) += t_mass3(
i,
j,
k) * diff(
k);
676 double *base_ptr =
const_cast<double *
>(&col_data.
getN(gg)[0]);
679 const_cast<double *
>(&(col_data.
getDiffN(gg, nb_col / 3)(0, 0)));
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;
691 const int s = 3 + 9 + 9 + 3;
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);
743 if (row_type != MBVERTEX) {
746 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
753 for (
unsigned int gg = 0; gg < row_data.
getN().size1(); gg++) {
754 double val = getVolume() * getGaussPts()(3, gg);
755 double rho0 = dAta.rho0;
772 noalias(
F) = prod(
h, invH);
782 energy += 0.5 * (
rho * val) * inner_prod(
v,
v);
784 CHKERR VecSetValue(V, 0, energy, ADD_VALUES);
792 int tag,
bool jacobian)
795 dAta(data),
commonData(common_data),
tAg(tag), jAcobian(jacobian),
802 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
808 if (row_type != MBVERTEX)
829 for (
int dd = 0; dd < 3; dd++) {
835 int nb_gauss_pts = row_data.
getN().size1();
840 int nb_active_vars = 0;
841 for (
int gg = 0; gg < nb_gauss_pts; gg++) {
847 for (
int nn1 = 0; nn1 < 3; nn1++) {
852 for (
int nn1 = 0; nn1 < 3; nn1++) {
860 for (
int nn1 = 0; nn1 < 3; nn1++) {
861 for (
int nn2 = 0; nn2 < 3; nn2++) {
873 for (
int nn1 = 0; nn1 < 3; nn1++) {
881 for (
int nn1 = 0; nn1 < 3; nn1++) {
882 for (
int nn2 = 0; nn2 < 3; nn2++) {
915 t_F(
i,
j) = t_h(
i,
k) * t_invH(
k,
j);
917 t_F(
i,
j) = t_h(
i,
j);
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);
927 for (
int rr = 0; rr < 3; rr++) {
928 a_res[rr] >>= res[rr];
933 active.resize(nb_active_vars);
935 for (
int nn1 = 0; nn1 < 3; nn1++) {
939 for (
int nn1 = 0; nn1 < 3; nn1++) {
946 for (
int nn1 = 0; nn1 < 3; nn1++) {
947 for (
int nn2 = 0; nn2 < 3; nn2++) {
948 if (fieldDisp && nn1 == nn2) {
960 for (
int nn1 = 0; nn1 < 3; nn1++) {
967 for (
int nn1 = 0; nn1 < 3; nn1++) {
968 for (
int nn2 = 0; nn2 < 3; nn2++) {
981 r = ::function(
tAg, 3, nb_active_vars, &active[0], &res[0]);
984 "ADOL-C function evaluation with error");
987 double val = getVolume() * getGaussPts()(3, gg);
992 for (
int nn1 = 0; nn1 < 3; nn1++) {
996 r = jacobian(
tAg, 3, nb_active_vars, &active[0],
1000 "ADOL-C function evaluation with error");
1002 double val = getVolume() * getGaussPts()(3, gg);
1021 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
1030 int nb_base_functions = row_data.
getN().size2();
1038 for (
unsigned int gg = 0; gg < row_data.
getN().size1(); gg++) {
1044 for (; dd < nb_dofs / 3; dd++) {
1045 t_nf(
i) += base * res(
i);
1049 for (; dd != nb_base_functions; dd++) {
1054 if (row_data.
getIndices().size() > 3 * row_data.
getN().size2()) {
1055 SETERRQ(PETSC_COMM_SELF, 1,
"data inconsistency");
1058 &row_data.
getIndices()[0], &nf[0], ADD_VALUES);
1075 double *base_ptr =
const_cast<double *
>(&col_data.
getN(gg)[0]);
1078 &jac(1, 0), &jac(1, 1), &jac(1, 2),
1079 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
1088 for (
int dd = 0; dd < nb_col / 3; dd++) {
1089 t_jac(
i,
j) += t_mass1(
i,
j) * base;
1109 double *base_ptr =
const_cast<double *
>(&col_data.
getN(gg)[0]);
1112 &jac(1, 0), &jac(1, 1), &jac(1, 2),
1113 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
1127 for (
int dd = 0; dd < nb_col / 3; dd++) {
1128 t_jac(
i,
j) += t_mass1(
i,
j) * base * getFEMethod()->ts_a;
1134 const_cast<double *
>(&(col_data.
getDiffN(gg, nb_col / 3)(0, 0)));
1136 const int s = 3 + 3;
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);
1184 double *base_ptr =
const_cast<double *
>(&col_data.
getN(gg)[0]);
1187 const_cast<double *
>(&(col_data.
getDiffN(gg, nb_col / 3)(0, 0)));
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;
1199 const int s = 3 + 3 + 9 + 3;
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);
1244 dAta(data),
commonData(common_data),
tAg(tag), jAcobian(jacobian),
1252 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
1258 if (row_type != MBVERTEX)
1277 for (
int dd = 0; dd < 3; dd++) {
1282 int nb_gauss_pts = row_data.
getN().size1();
1287 int nb_active_vars = 0;
1288 for (
int gg = 0; gg < nb_gauss_pts; gg++) {
1294 for (
int nn1 = 0; nn1 < 3; nn1++) {
1301 for (
int nn1 = 0; nn1 < 3; nn1++) {
1306 for (
int nn1 = 0; nn1 < 3; nn1++) {
1307 for (
int nn2 = 0; nn2 < 3; nn2++) {
1314 for (
int nn1 = 0; nn1 < 3; nn1++) {
1315 for (
int nn2 = 0; nn2 < 3; nn2++) {
1328 for (
int nn1 = 0; nn1 < 3; nn1++) {
1329 for (
int nn2 = 0; nn2 < 3; nn2++) {
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;
1369 for (
int nn = 0; nn < 3; nn++) {
1375 active.resize(nb_active_vars);
1377 for (
int nn1 = 0; nn1 < 3; nn1++) {
1383 for (
int nn1 = 0; nn1 < 3; nn1++) {
1387 for (
int nn1 = 0; nn1 < 3; nn1++) {
1388 for (
int nn2 = 0; nn2 < 3; nn2++) {
1394 for (
int nn1 = 0; nn1 < 3; nn1++) {
1395 for (
int nn2 = 0; nn2 < 3; nn2++) {
1396 if (fieldDisp && nn1 == nn2) {
1409 for (
int nn1 = 0; nn1 < 3; nn1++) {
1410 for (
int nn2 = 0; nn2 < 3; nn2++) {
1423 r = ::function(
tAg, 3, nb_active_vars, &active[0], &res[0]);
1426 "ADOL-C function evaluation with error r = %d", r);
1429 double val = getVolume() * getGaussPts()(3, gg);
1434 for (
int nn1 = 0; nn1 < 3; nn1++) {
1438 r = jacobian(
tAg, 3, nb_active_vars, &active[0],
1442 "ADOL-C function evaluation with error");
1444 double val = getVolume() * getGaussPts()(3, gg);
1449 }
catch (
const std::exception &ex) {
1450 std::ostringstream ss;
1451 ss <<
"throw in method: " << ex.what() << std::endl;
1462 Range *forcesonlyonentities_ptr)
1466 if (forcesonlyonentities_ptr != NULL) {
1476 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
1490 int nb_base_functions = row_data.
getN().size2();
1493 for (
unsigned int gg = 0; gg < row_data.
getN().size1(); gg++) {
1499 for (; dd < nb_dofs / 3; dd++) {
1500 t_nf(
i) += base * res(
i);
1504 for (; dd != nb_base_functions; dd++) {
1509 if (row_data.
getIndices().size() > 3 * row_data.
getN().size2()) {
1510 SETERRQ(PETSC_COMM_SELF, 1,
"data inconsistency");
1512 if (!forcesOnlyOnEntities.empty()) {
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()) {
1525 &nf[0], ADD_VALUES);
1528 &row_data.
getIndices()[0], &nf[0], ADD_VALUES);
1531 }
catch (
const std::exception &ex) {
1532 std::ostringstream ss;
1533 ss <<
"throw in method: " << ex.what() << std::endl;
1545 Range *forcesonlyonentities_ptr)
1547 vel_field,
field_name, data, common_data, forcesonlyonentities_ptr) {}
1555 double *base_ptr =
const_cast<double *
>(&col_data.
getN(gg)[0]);
1558 const_cast<double *
>(&(col_data.
getDiffN(gg, nb_col / 3)(0, 0)));
1561 &jac(1, 0), &jac(1, 1), &jac(1, 2),
1562 &jac(2, 0), &jac(2, 1), &jac(2, 2), 3);
1570 const int s = 3 + 3;
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);
1613 Range *forcesonlyonentities_ptr)
1615 vel_field,
field_name, data, common_data, forcesonlyonentities_ptr) {}
1624 const_cast<double *
>(&(col_data.
getDiffN(gg, nb_col / 3)(0, 0)));
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;
1657 for (
int dd = 0; dd < nb_col / 3; dd++) {
1658 t_jac(
i,
j) += t_mass3(
i,
j,
k) * diff(
k);
1670 Range *forcesonlyonentities_ptr)
1672 vel_field,
field_name, data, common_data, forcesonlyonentities_ptr) {}
1681 const_cast<double *
>(&(col_data.
getDiffN(gg, nb_col / 3)(0, 0)));
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;
1714 for (
int dd = 0; dd < nb_col / 3; dd++) {
1715 t_jac(
i,
j) += t_mass3(
i,
j,
k) * diff(
k);
1724 const std::string spatial_position_field)
1725 :
mField(m_field), tS(_ts), velocityField(velocity_field),
1726 spatialPositionField(spatial_position_field), jacobianLag(-1) {}
1732 case CTX_TSSETIFUNCTION: {
1738 problemPtr,
COL, ts_u, INSERT_VALUES, SCATTER_REVERSE);
1740 problemPtr, velocityField,
"DOT_" + velocityField,
COL, ts_u_t,
1741 INSERT_VALUES, SCATTER_REVERSE);
1743 problemPtr, spatialPositionField,
"DOT_" + spatialPositionField,
COL,
1744 ts_u_t, INSERT_VALUES, SCATTER_REVERSE);
1747 case CTX_TSSETIJACOBIAN: {
1773 int id = it->getMeshsetId();
1774 EntityHandle meshset = it->getMeshset();
1779 CHKERR it->getAttributeDataStructure(mydata);
1791 CHKERR it->getAttributeDataStructure(mydata);
1792 if (mydata.
data.User1 == 0)
1795 EntityHandle meshset = it->getMeshset();
1797 tets = subtract(tets, added_tets);
1800 int id = it->getMeshsetId();
1815 boost::shared_ptr<map<int, BlockData>> &block_sets_ptr) {
1818 if (!block_sets_ptr)
1820 "Pointer to block of sets is null");
1825 CHKERR it->getAttributeDataStructure(mydata);
1826 int id = it->getMeshsetId();
1827 auto &block_data = (*block_sets_ptr)[id];
1828 EntityHandle meshset = it->getMeshset();
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;
1842 string element_name,
string velocity_field_name,
1843 string spatial_position_field_name,
string material_position_field_name,
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);
1865 element_name, material_position_field_name);
1867 element_name, material_position_field_name);
1869 element_name,
"DOT_" + material_position_field_name);
1872 element_name, material_position_field_name);
1875 element_name,
"DOT_" + velocity_field_name);
1877 element_name,
"DOT_" + spatial_position_field_name);
1885 std::map<int, BlockData>::iterator sit =
setOfBlocks.begin();
1887 Range add_tets = sit->second.tEts;
1888 if (!tets.empty()) {
1889 add_tets = intersect(add_tets, tets);
1899 string element_name,
string velocity_field_name,
1900 string spatial_position_field_name,
string material_position_field_name,
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);
1920 element_name, material_position_field_name);
1922 element_name,
"DOT_" + material_position_field_name);
1925 element_name, material_position_field_name);
1928 element_name,
"DOT_" + velocity_field_name);
1930 element_name,
"DOT_" + spatial_position_field_name);
1938 std::map<int, BlockData>::iterator sit =
setOfBlocks.begin();
1940 Range add_tets = sit->second.tEts;
1941 if (!tets.empty()) {
1942 add_tets = intersect(add_tets, tets);
1952 string element_name,
string velocity_field_name,
1953 string spatial_position_field_name,
string material_position_field_name,
1961 velocity_field_name);
1963 velocity_field_name);
1965 element_name, spatial_position_field_name);
1967 element_name, spatial_position_field_name);
1971 element_name, material_position_field_name);
1973 element_name, material_position_field_name);
1975 element_name,
"DOT_" + material_position_field_name);
1978 element_name, material_position_field_name);
1981 element_name,
"DOT_" + velocity_field_name);
1983 element_name,
"DOT_" + spatial_position_field_name);
1990 if (intersected != NULL) {
1992 tets = *intersected;
1994 tets = intersect(*intersected, tets);
1998 std::map<int, BlockData>::iterator sit =
setOfBlocks.begin();
2000 Range add_tets = sit->second.tEts;
2001 if (!tets.empty()) {
2002 add_tets = intersect(add_tets, tets);
2012 string velocity_field_name,
string spatial_position_field_name,
2013 string material_position_field_name,
bool ale,
bool linear) {
2029 "DOT_" + spatial_position_field_name,
commonData));
2035 "DOT_" + material_position_field_name,
commonData));
2040 std::map<int, BlockData>::iterator sit =
setOfBlocks.begin();
2057 "DOT_" + spatial_position_field_name,
commonData));
2063 "DOT_" + material_position_field_name,
commonData));
2077 spatial_position_field_name, spatial_position_field_name, sit->second,
2082 spatial_position_field_name, material_position_field_name,
2110 string velocity_field_name,
string spatial_position_field_name,
2111 string material_position_field_name,
bool ale) {
2127 "DOT_" + spatial_position_field_name,
commonData));
2132 "DOT_" + material_position_field_name,
commonData));
2137 std::map<int, BlockData>::iterator sit =
setOfBlocks.begin();
2154 "DOT_" + spatial_position_field_name,
commonData));
2159 "DOT_" + material_position_field_name,
commonData));
2169 velocity_field_name, velocity_field_name, sit->second,
commonData));
2171 velocity_field_name, spatial_position_field_name, sit->second,
2176 velocity_field_name, material_position_field_name, sit->second,
2188 string velocity_field_name,
string spatial_position_field_name,
2189 string material_position_field_name,
Range *forces_on_entities_ptr) {
2206 std::map<int, BlockData>::iterator sit =
setOfBlocks.begin();
2210 material_position_field_name, sit->second,
commonData,
tAg,
false));
2212 material_position_field_name, sit->second,
commonData,
2213 forces_on_entities_ptr));
2231 material_position_field_name, sit->second,
commonData,
tAg));
2234 material_position_field_name, velocity_field_name, sit->second,
2238 material_position_field_name, spatial_position_field_name,
2239 sit->second,
commonData, forces_on_entities_ptr));
2242 material_position_field_name, material_position_field_name,
2243 sit->second,
commonData, forces_on_entities_ptr));
2250 string velocity_field_name,
string spatial_position_field_name,
2251 string material_position_field_name,
bool linear) {
2271 std::map<int, BlockData>::iterator sit =
setOfBlocks.begin();
2298 spatial_position_field_name, spatial_position_field_name, sit->second,
2323 spatial_position_field_name, spatial_position_field_name, sit->second,
2354 CHKERRABORT(PETSC_COMM_WORLD,
ierr);
2362#if PETSC_VERSION_GE(3, 5, 3)
2363 CHKERR MatCreateVecs(
K, &u, &Ku);
2366 CHKERR MatGetVecs(
K, &u, &Ku);
2369 CHKERR MatDuplicate(
K, MAT_SHARE_NONZERO_PATTERN, &barK);
2383 CHKERR MatDestroy(&barK);
2384 iNitialized =
false;
2394 CHKERR PetscObjectGetComm((PetscObject)shellMat, &comm);
2395 CHKERR PCCreate(comm, &pC);
2418 if (
ts_ctx != CTX_TSSETIFUNCTION) {
2420 "It is used to residual of velocities");
2422 if (!shellMatCtx->iNitialized) {
2423 CHKERR shellMatCtx->iNit();
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,
2444#ifdef __DIRICHLET_HPP__
2446ConvectiveMassElement::ShellMatrixElement::ShellMatrixElement(
2450MoFEMErrorCode ConvectiveMassElement::ShellMatrixElement::preProcess() {
2453 if (
ts_ctx != CTX_TSSETIJACOBIAN) {
2455 "It is used to calculate shell matrix only");
2458 shellMatCtx->ts_a = ts_a;
2459 DirichletBcPtr->copyTs(*((
TSMethod *)
this));
2461 DirichletBcPtr->dIag = 1;
2462 DirichletBcPtr->ts_B = shellMatCtx->K;
2463 CHKERR MatZeroEntries(shellMatCtx->K);
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;
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;
2478 CHKERR MatAssemblyBegin(shellMatCtx->K, MAT_FINAL_ASSEMBLY);
2479 CHKERR MatAssemblyEnd(shellMatCtx->K, MAT_FINAL_ASSEMBLY);
2481 DirichletBcPtr->dIag = 0;
2482 DirichletBcPtr->ts_B = shellMatCtx->M;
2483 CHKERR MatZeroEntries(shellMatCtx->M);
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;
2492 CHKERR MatAssemblyBegin(shellMatCtx->M, MAT_FINAL_ASSEMBLY);
2493 CHKERR MatAssemblyEnd(shellMatCtx->M, MAT_FINAL_ASSEMBLY);
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);
Operators and data structures for mass and convective mass element.
#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"
@ MOFEM_OPERATION_UNSUCCESSFUL
@ MOFEM_DATA_INCONSISTENCY
#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 ...
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.
FTensor::Index< 'i', SPACE_DIM > i
const double v
phase velocity of light in medium (cm/ns)
constexpr IntegrationType G
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
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
UBlasVector< int > VectorInt
implementation of Data Operators for Forces and Sources
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 auto field_name
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::vector< VectorDouble > valVel
std::vector< MatrixDouble > jacMass
std::vector< VectorDouble > valT
std::vector< MatrixDouble > jacVel
std::vector< VectorDouble > valMass
std::map< std::string, std::vector< MatrixDouble > > gradAtGaussPts
std::vector< MatrixDouble > jacT
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.
MyVolumeFE(MoFEM::Interface &m_field)
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)
Range forcesOnlyOnEntities
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)
Range forcesOnlyOnEntities
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...
ShellResidualElement(MoFEM::Interface &m_field)
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
MoFEM::Interface & mField
MoFEMErrorCode setBlocks()
MyVolumeFE feVelLhs
calculate left hand side for tetrahedral elements
static MoFEMErrorCode applyScale(const FEMethod *fe, boost::ptr_vector< MethodForForceScaling > &methods_op, VectorDouble &nf)
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.
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.
Volume finite element base.
std::string meshPositionsFieldName