435 enum { X = 0, Y, Z, MX, MY, MZ,
LAST };
437 if (
auto fe_ptr =
fePtr.lock()) {
439 SmartPetscObj<Vec>
f =
vRhs ?
vRhs : SmartPetscObj<Vec>(fe_ptr->f,
true);
441 if (fe_ptr->vecAssembleSwitch) {
442 if ((*fe_ptr->vecAssembleSwitch) && !
vRhs) {
443 CHKERR VecGhostUpdateBegin(
f, ADD_VALUES, SCATTER_REVERSE);
444 CHKERR VecGhostUpdateEnd(
f, ADD_VALUES, SCATTER_REVERSE);
447 *fe_ptr->vecAssembleSwitch =
false;
451 auto get_low_hi_uid_by_entities = [](
auto bit_number,
auto f,
auto s) {
456 auto get_low_hi = [fe_ptr](
auto lo_uid,
auto hi_uid) {
457 auto it = fe_ptr->problemPtr->numeredRowDofsPtr->get<Unique_mi_tag>()
458 .lower_bound(lo_uid);
459 auto hi_it = fe_ptr->problemPtr->numeredRowDofsPtr->get<Unique_mi_tag>()
460 .upper_bound(hi_uid);
461 return std::make_pair(it, hi_it);
464 auto mpi_array_reduce = [
this](
auto &array) {
465 std::array<double, LAST> array_sum{0, 0, 0, 0, 0, 0};
466 MPI_Allreduce(&array[0], &array_sum[0], LAST, MPI_DOUBLE, MPI_SUM,
475 const auto problem_name = fe_ptr->problemPtr->getName();
476 const auto nb_local_dofs = fe_ptr->problemPtr->nbLocDofsRow;
478 std::array<double, LAST> total_reactions{0, 0, 0, 0, 0, 0};
480 for (
auto bc : bc_mng->getBcMapByBlockName()) {
481 if (
auto disp_bc = bc.second->dispBcPtr) {
483 auto &bc_id = bc.first;
485 auto regex_str = (boost::format(
"%s_(.*)") % problem_name).str();
486 if (std::regex_match(bc_id, std::regex(regex_str))) {
492 <<
"EssentialPreProc<DisplacementCubitBcData>: " << problem_name
497 if (
auto ext_disp_bc =
498 dynamic_cast<DisplacementCubitBcDataWithRotation
const *
>(
500 for (
int a = 0;
a != 3; ++
a)
501 t_off(
a) = ext_disp_bc->rotOffset[
a];
504 auto verts = bc.second->bcEnts.subset_by_type(MBVERTEX);
510 auto get_coords_vec = [&]() {
518 auto coords_vec = get_coords_vec();
519 std::array<double, LAST> reactions{0, 0, 0, 0, 0, 0};
521 for (
auto pit = verts.const_pair_begin();
522 pit != verts.const_pair_end(); ++pit) {
523 auto [lo_uid, hi_uid] =
524 get_low_hi_uid_by_entities(bit_number, pit->first, pit->second);
525 auto [lo, hi] = get_low_hi(lo_uid, hi_uid);
527 for (; lo != hi; ++lo) {
528 const auto loc_dof = (*lo)->getPetscLocalDofIdx();
529 if (loc_dof < nb_local_dofs) {
531 const auto coeff = (*lo)->getDofCoeffIdx();
535 ((disp_bc->data.flag1 || disp_bc->data.flag4) &&
537 ((disp_bc->data.flag2 || disp_bc->data.flag5) &&
539 ((disp_bc->data.flag3 || disp_bc->data.flag6) &&
542 const auto ent = (*lo)->getEnt();
543 reactions[coeff] +=
a[loc_dof];
547 t_force(coeff) =
a[loc_dof];
552 const auto idx = verts.index(ent);
554 coords_vec[3 * idx + X], coords_vec[3 * idx + Y],
555 coords_vec[3 * idx + Z]};
556 t_coords(
i) -= t_off(
i);
560 auto moment = [&](
auto &&t_force,
auto &&t_coords) {
563 (FTensor::levi_civita<double>(
i,
j,
k) * t_coords(
k)) *
568 auto t_moment = moment(force(), coord());
569 reactions[MX] += t_moment(X);
570 reactions[MY] += t_moment(Y);
571 reactions[MZ] += t_moment(Z);
582 &total_reactions[X], &total_reactions[Y], &total_reactions[Z]};
584 &total_reactions[MX], &total_reactions[MY], &total_reactions[MZ]};
585 t_total_force(
i) += t_force(
i);
588 (FTensor::levi_civita<double>(
i,
j,
k) * t_off(
k)) * t_force(
j);
590 auto mpi_reactions = mpi_array_reduce(reactions);
593 "Block %s Offset: %6.4e %6.4e %6.4e",
594 block_name.c_str(), t_off(X), t_off(Y),
597 "Block %s Force: %6.4e %6.4e %6.4e",
598 block_name.c_str(), mpi_reactions[X],
599 mpi_reactions[Y], mpi_reactions[Z]);
601 "Block %s Moment: %6.4e %6.4e %6.4e",
602 block_name.c_str(), mpi_reactions[MX],
603 mpi_reactions[MY], mpi_reactions[MZ]);
606 (*reactionPtr)[X] = mpi_reactions[X];
607 (*reactionPtr)[Y] = mpi_reactions[Y];
608 (*reactionPtr)[Z] = mpi_reactions[Z];
612 "Offset: %6.4e %6.4e %6.4e", t_off(X), t_off(Y),
615 "Force: %6.4e %6.4e %6.4e", mpi_reactions[X],
616 mpi_reactions[Y], mpi_reactions[Z]);
618 "Moment: %6.4e %6.4e %6.4e", mpi_reactions[MX],
619 mpi_reactions[MY], mpi_reactions[MZ]);
627 auto mpi_total_reactions = mpi_array_reduce(total_reactions);
629 "WORLD",
sevLevel,
"Essential",
"Total force: %6.4e %6.4e %6.4e",
630 mpi_total_reactions[X], mpi_total_reactions[Y], mpi_total_reactions[Z]);
632 "Total moment: %6.4e %6.4e %6.4e",
633 mpi_total_reactions[MX], mpi_total_reactions[MY],
634 mpi_total_reactions[MZ]);
638 "Can not lock shared pointer");