v0.14.0
Public Member Functions | Protected Attributes | List of all members
MoFEM::EssentialPreProcReaction< DisplacementCubitBcData > Struct Reference

Specialization for DisplacementCubitBcData. More...

#include <src/boundary_conditions/EssentialDisplacementCubitBcData.hpp>

Collaboration diagram for MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >:
[legend]

Public Member Functions

 EssentialPreProcReaction (MoFEM::Interface &m_field, boost::shared_ptr< FEMethod > fe_ptr, SmartPetscObj< Vec > rhs=nullptr, LogManager::SeverityLevel sev=Sev::inform)
 
MoFEMErrorCode operator() ()
 

Protected Attributes

MoFEM::InterfacemField
 
boost::weak_ptr< FEMethodfePtr
 
SmartPetscObj< Vec > vRhs
 
LogManager::SeverityLevel sevLevel
 
PetscBool printBlockName
 

Detailed Description

Specialization for DisplacementCubitBcData.

Template Parameters
Examples
adolc_plasticity.cpp, nonlinear_elastic.cpp, plastic.cpp, and seepage.cpp.

Definition at line 151 of file EssentialDisplacementCubitBcData.hpp.

Constructor & Destructor Documentation

◆ EssentialPreProcReaction()

MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::EssentialPreProcReaction ( MoFEM::Interface m_field,
boost::shared_ptr< FEMethod fe_ptr,
SmartPetscObj< Vec >  rhs = nullptr,
LogManager::SeverityLevel  sev = Sev::inform 
)

Definition at line 415 of file EssentialDisplacementCubitBcData.cpp.

418  : mField(m_field), fePtr(fe_ptr), vRhs(rhs), sevLevel(sev),
419  printBlockName(PETSC_FALSE) {
420 
421  CHK_THROW_MESSAGE(PetscOptionsGetBool(PETSC_NULL, PETSC_NULL,
422  "-reaction_print_block_name",
423  &printBlockName, PETSC_NULL),
424  "can not get option");
425 }

Member Function Documentation

◆ operator()()

Definition at line 427 of file EssentialDisplacementCubitBcData.cpp.

427  {
428  MOFEM_LOG_CHANNEL("WORLD");
430 
431  enum { X = 0, Y, Z, MX, MY, MZ, LAST };
432 
433  if (auto fe_ptr = fePtr.lock()) {
434 
435  SmartPetscObj<Vec> f = vRhs ? vRhs : SmartPetscObj<Vec>(fe_ptr->f, true);
436 
437  if (fe_ptr->vecAssembleSwitch) {
438  if ((*fe_ptr->vecAssembleSwitch) && !vRhs) {
439  CHKERR VecGhostUpdateBegin(f, ADD_VALUES, SCATTER_REVERSE);
440  CHKERR VecGhostUpdateEnd(f, ADD_VALUES, SCATTER_REVERSE);
441  CHKERR VecAssemblyBegin(f);
442  CHKERR VecAssemblyEnd(f);
443  *fe_ptr->vecAssembleSwitch = false;
444  }
445  }
446 
447  auto get_low_hi_uid_by_entities = [](auto bit_number, auto f, auto s) {
448  return std::make_pair(DofEntity::getLoFieldEntityUId(bit_number, f),
449  DofEntity::getHiFieldEntityUId(bit_number, s));
450  };
451 
452  auto get_low_hi = [fe_ptr](auto lo_uid, auto hi_uid) {
453  auto it = fe_ptr->problemPtr->numeredRowDofsPtr->get<Unique_mi_tag>()
454  .lower_bound(lo_uid);
455  auto hi_it = fe_ptr->problemPtr->numeredRowDofsPtr->get<Unique_mi_tag>()
456  .upper_bound(hi_uid);
457  return std::make_pair(it, hi_it);
458  };
459 
460  auto mpi_array_reduce = [this](auto &array) {
461  std::array<double, LAST> array_sum{0, 0, 0, 0, 0, 0};
462  MPI_Allreduce(&array[0], &array_sum[0], LAST, MPI_DOUBLE, MPI_SUM,
463  mField.get_comm());
464  return array_sum;
465  };
466 
467  const double *a;
468  CHKERR VecGetArrayRead(f, &a);
469 
470  auto bc_mng = mField.getInterface<BcManager>();
471  const auto problem_name = fe_ptr->problemPtr->getName();
472  const auto nb_local_dofs = fe_ptr->problemPtr->nbLocDofsRow;
473 
474  std::array<double, LAST> total_reactions{0, 0, 0, 0, 0, 0};
475 
476  for (auto bc : bc_mng->getBcMapByBlockName()) {
477  if (auto disp_bc = bc.second->dispBcPtr) {
478 
479  auto &bc_id = bc.first;
480 
481  auto regex_str = (boost::format("%s_(.*)") % problem_name).str();
482  if (std::regex_match(bc_id, std::regex(regex_str))) {
483 
484  auto [field_name, block_name] =
485  BcManager::extractStringFromBlockId(bc_id, problem_name);
486 
487  MOFEM_TAG_AND_LOG("WORLD", sevLevel, "Essential")
488  << "EssentialPreProc<DisplacementCubitBcData>: " << problem_name
489  << "_" << field_name << "_" << block_name;
490  auto bit_number = mField.get_field_bit_number(field_name);
491 
492  FTensor::Tensor1<double, 3> t_off{0., 0., 0.};
493  if (auto ext_disp_bc =
494  dynamic_cast<DisplacementCubitBcDataWithRotation const *>(
495  disp_bc.get())) {
496  for (int a = 0; a != 3; ++a)
497  t_off(a) = ext_disp_bc->rotOffset[a];
498  }
499 
500  auto verts = bc.second->bcEnts.subset_by_type(MBVERTEX);
501 
505 
506  auto get_coords_vec = [&]() {
507  VectorDouble coords_vec(3 * verts.size());
508  if (verts.size()) {
509  CHKERR mField.get_moab().get_coords(verts, &*coords_vec.begin());
510  }
511  return coords_vec;
512  };
513 
514  auto coords_vec = get_coords_vec();
515  std::array<double, LAST> reactions{0, 0, 0, 0, 0, 0};
516 
517  for (auto pit = verts.const_pair_begin();
518  pit != verts.const_pair_end(); ++pit) {
519  auto [lo_uid, hi_uid] =
520  get_low_hi_uid_by_entities(bit_number, pit->first, pit->second);
521  auto [lo, hi] = get_low_hi(lo_uid, hi_uid);
522 
523  for (; lo != hi; ++lo) {
524  const auto loc_dof = (*lo)->getPetscLocalDofIdx();
525  if (loc_dof < nb_local_dofs) {
526 
527  const auto coeff = (*lo)->getDofCoeffIdx();
528 
529  if (
530 
531  ((disp_bc->data.flag1 || disp_bc->data.flag4) &&
532  coeff == 0) ||
533  ((disp_bc->data.flag2 || disp_bc->data.flag5) &&
534  coeff == 1) ||
535  ((disp_bc->data.flag3 || disp_bc->data.flag6) &&
536  coeff == 2)) {
537 
538  const auto ent = (*lo)->getEnt();
539  reactions[coeff] += a[loc_dof];
540 
541  auto force = [&]() {
542  FTensor::Tensor1<double, 3> t_force{0., 0., 0.};
543  t_force(coeff) = a[loc_dof];
544  return t_force;
545  };
546 
547  auto coord = [&]() {
548  const auto idx = verts.index(ent);
550  coords_vec[3 * idx + X], coords_vec[3 * idx + Y],
551  coords_vec[3 * idx + Z]};
552  t_coords(i) -= t_off(i);
553  return t_coords;
554  };
555 
556  auto moment = [&](auto &&t_force, auto &&t_coords) {
558  t_moment(i) =
559  (FTensor::levi_civita<double>(i, j, k) * t_coords(k)) *
560  t_force(j);
561  return t_moment;
562  };
563 
564  auto t_moment = moment(force(), coord());
565  reactions[MX] += t_moment(X);
566  reactions[MY] += t_moment(Y);
567  reactions[MZ] += t_moment(Z);
568  }
569  }
570  }
571  }
572 
573  FTensor::Tensor1<double, 3> t_force{reactions[X], reactions[Y],
574  reactions[Z]};
575  FTensor::Tensor1<double, 3> t_moment{reactions[MX], reactions[MY],
576  reactions[MZ]};
578  &total_reactions[X], &total_reactions[Y], &total_reactions[Z]};
580  &total_reactions[MX], &total_reactions[MY], &total_reactions[MZ]};
581  t_total_force(i) += t_force(i);
582  t_total_moment(i) +=
583  t_moment(i) +
584  (FTensor::levi_civita<double>(i, j, k) * t_off(k)) * t_force(j);
585 
586  auto mpi_reactions = mpi_array_reduce(reactions);
587  if (printBlockName) {
588  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
589  "Block %s Offset: %6.4e %6.4e %6.4e",
590  block_name.c_str(), t_off(X), t_off(Y),
591  t_off(Z));
592  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
593  "Block %s Force: %6.4e %6.4e %6.4e",
594  block_name.c_str(), mpi_reactions[X],
595  mpi_reactions[Y], mpi_reactions[Z]);
596  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
597  "Block %s Moment: %6.4e %6.4e %6.4e",
598  block_name.c_str(), mpi_reactions[MX],
599  mpi_reactions[MY], mpi_reactions[MZ]);
600  } else {
601  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
602  "Offset: %6.4e %6.4e %6.4e", t_off(X), t_off(Y),
603  t_off(Z));
604  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
605  "Force: %6.4e %6.4e %6.4e", mpi_reactions[X],
606  mpi_reactions[Y], mpi_reactions[Z]);
607  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
608  "Moment: %6.4e %6.4e %6.4e", mpi_reactions[MX],
609  mpi_reactions[MY], mpi_reactions[MZ]);
610  }
611  }
612  }
613  }
614 
615  CHKERR VecRestoreArrayRead(f, &a);
616 
617  auto mpi_total_reactions = mpi_array_reduce(total_reactions);
619  "WORLD", sevLevel, "Essential", "Total force: %6.4e %6.4e %6.4e",
620  mpi_total_reactions[X], mpi_total_reactions[Y], mpi_total_reactions[Z]);
621  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
622  "Total moment: %6.4e %6.4e %6.4e",
623  mpi_total_reactions[MX], mpi_total_reactions[MY],
624  mpi_total_reactions[MZ]);
625 
626  } else {
627  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
628  "Can not lock shared pointer");
629  }
630 
632 }

Member Data Documentation

◆ fePtr

Definition at line 161 of file EssentialDisplacementCubitBcData.hpp.

◆ mField

Definition at line 160 of file EssentialDisplacementCubitBcData.hpp.

◆ printBlockName

PetscBool MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::printBlockName
protected

Definition at line 164 of file EssentialDisplacementCubitBcData.hpp.

◆ sevLevel

Definition at line 163 of file EssentialDisplacementCubitBcData.hpp.

◆ vRhs

Definition at line 162 of file EssentialDisplacementCubitBcData.hpp.


The documentation for this struct was generated from the following files:
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::BcManager::extractStringFromBlockId
static std::pair< std::string, std::string > extractStringFromBlockId(const std::string block_id, const std::string prb_name)
Extract block name and block name form block id.
Definition: BcManager.cpp:1389
FTensor::Tensor1< double, 3 >
MOFEM_LOG_CHANNEL
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
CHK_THROW_MESSAGE
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
Definition: definitions.h:596
MoFEM::CoreInterface::get_field_bit_number
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::vRhs
SmartPetscObj< Vec > vRhs
Definition: EssentialDisplacementCubitBcData.hpp:162
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::CoreInterface::get_moab
virtual moab::Interface & get_moab()=0
a
constexpr double a
Definition: approx_sphere.cpp:30
MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::fePtr
boost::weak_ptr< FEMethod > fePtr
Definition: EssentialDisplacementCubitBcData.hpp:161
MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::mField
MoFEM::Interface & mField
Definition: EssentialDisplacementCubitBcData.hpp:160
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
MoFEM::DofEntity::getLoFieldEntityUId
static UId getLoFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
Definition: DofsMultiIndices.hpp:69
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
FTensor::Index< 'i', 3 >
MOFEM_TAG_AND_LOG
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
Definition: LogManager.hpp:362
MoFEM::DofEntity::getHiFieldEntityUId
static UId getHiFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
Definition: DofsMultiIndices.hpp:75
MOFEM_TAG_AND_LOG_C
#define MOFEM_TAG_AND_LOG_C(channel, severity, tag, format,...)
Tag and log in channel.
Definition: LogManager.hpp:370
HenckyOps::f
auto f
Definition: HenckyOps.hpp:15
j
FTensor::Index< 'j', 3 > j
Definition: matrix_function.cpp:19
MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::sevLevel
LogManager::SeverityLevel sevLevel
Definition: EssentialDisplacementCubitBcData.hpp:163
MoFEM::MPC::LAST
@ LAST
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::printBlockName
PetscBool printBlockName
Definition: EssentialDisplacementCubitBcData.hpp:164
MoFEM::Types::VectorDouble
UBlasVector< double > VectorDouble
Definition: Types.hpp:68
k
FTensor::Index< 'k', 3 > k
Definition: matrix_function.cpp:20
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
MoFEM::PetscOptionsGetBool
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
Definition: DeprecatedPetsc.hpp:182