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, boost::shared_ptr< std::vector< double >> reaction_ptr=nullptr)
 
MoFEMErrorCode operator() ()
 

Protected Attributes

MoFEM::InterfacemField
 
boost::weak_ptr< FEMethodfePtr
 
SmartPetscObj< Vec > vRhs
 
LogManager::SeverityLevel sevLevel
 
PetscBool printBlockName
 
boost::shared_ptr< std::vector< double > > reactionPtr
 
char reactionBlockName [255]
 

Detailed Description

Specialization for DisplacementCubitBcData.

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

Definition at line 157 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,
boost::shared_ptr< std::vector< double >>  reaction_ptr = nullptr 
)

Definition at line 415 of file EssentialDisplacementCubitBcData.cpp.

419  : mField(m_field), fePtr(fe_ptr), vRhs(rhs), sevLevel(sev),
420  printBlockName(PETSC_FALSE), reactionPtr(reaction_ptr),
421  reactionBlockName("") {
422 
423  CHK_THROW_MESSAGE(PetscOptionsGetBool(PETSC_NULL, PETSC_NULL,
424  "-reaction_print_block_name",
425  &printBlockName, PETSC_NULL),
426  "can not get option");
427  CHKERR PetscOptionsGetString(PETSC_NULL, "-reaction_block_name",
428  reactionBlockName, 255, PETSC_NULL);
429 }

Member Function Documentation

◆ operator()()

Definition at line 431 of file EssentialDisplacementCubitBcData.cpp.

431  {
432  MOFEM_LOG_CHANNEL("WORLD");
434 
435  enum { X = 0, Y, Z, MX, MY, MZ, LAST };
436 
437  if (auto fe_ptr = fePtr.lock()) {
438 
439  SmartPetscObj<Vec> f = vRhs ? vRhs : SmartPetscObj<Vec>(fe_ptr->f, true);
440 
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);
445  CHKERR VecAssemblyBegin(f);
446  CHKERR VecAssemblyEnd(f);
447  *fe_ptr->vecAssembleSwitch = false;
448  }
449  }
450 
451  auto get_low_hi_uid_by_entities = [](auto bit_number, auto f, auto s) {
452  return std::make_pair(DofEntity::getLoFieldEntityUId(bit_number, f),
453  DofEntity::getHiFieldEntityUId(bit_number, s));
454  };
455 
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);
462  };
463 
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,
467  mField.get_comm());
468  return array_sum;
469  };
470 
471  const double *a;
472  CHKERR VecGetArrayRead(f, &a);
473 
474  auto bc_mng = mField.getInterface<BcManager>();
475  const auto problem_name = fe_ptr->problemPtr->getName();
476  const auto nb_local_dofs = fe_ptr->problemPtr->nbLocDofsRow;
477 
478  std::array<double, LAST> total_reactions{0, 0, 0, 0, 0, 0};
479 
480  for (auto bc : bc_mng->getBcMapByBlockName()) {
481  if (auto disp_bc = bc.second->dispBcPtr) {
482 
483  auto &bc_id = bc.first;
484 
485  auto regex_str = (boost::format("%s_(.*)") % problem_name).str();
486  if (std::regex_match(bc_id, std::regex(regex_str))) {
487 
488  auto [field_name, block_name] =
489  BcManager::extractStringFromBlockId(bc_id, problem_name);
490 
491  MOFEM_TAG_AND_LOG("WORLD", sevLevel, "Essential")
492  << "EssentialPreProc<DisplacementCubitBcData>: " << problem_name
493  << "_" << field_name << "_" << block_name;
494  auto bit_number = mField.get_field_bit_number(field_name);
495 
496  FTensor::Tensor1<double, 3> t_off{0., 0., 0.};
497  if (auto ext_disp_bc =
498  dynamic_cast<DisplacementCubitBcDataWithRotation const *>(
499  disp_bc.get())) {
500  for (int a = 0; a != 3; ++a)
501  t_off(a) = ext_disp_bc->rotOffset[a];
502  }
503 
504  auto verts = bc.second->bcEnts.subset_by_type(MBVERTEX);
505 
509 
510  auto get_coords_vec = [&]() {
511  VectorDouble coords_vec(3 * verts.size());
512  if (verts.size()) {
513  CHKERR mField.get_moab().get_coords(verts, &*coords_vec.begin());
514  }
515  return coords_vec;
516  };
517 
518  auto coords_vec = get_coords_vec();
519  std::array<double, LAST> reactions{0, 0, 0, 0, 0, 0};
520 
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);
526 
527  for (; lo != hi; ++lo) {
528  const auto loc_dof = (*lo)->getPetscLocalDofIdx();
529  if (loc_dof < nb_local_dofs) {
530 
531  const auto coeff = (*lo)->getDofCoeffIdx();
532 
533  if (
534 
535  ((disp_bc->data.flag1 || disp_bc->data.flag4) &&
536  coeff == 0) ||
537  ((disp_bc->data.flag2 || disp_bc->data.flag5) &&
538  coeff == 1) ||
539  ((disp_bc->data.flag3 || disp_bc->data.flag6) &&
540  coeff == 2)) {
541 
542  const auto ent = (*lo)->getEnt();
543  reactions[coeff] += a[loc_dof];
544 
545  auto force = [&]() {
546  FTensor::Tensor1<double, 3> t_force{0., 0., 0.};
547  t_force(coeff) = a[loc_dof];
548  return t_force;
549  };
550 
551  auto coord = [&]() {
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);
557  return t_coords;
558  };
559 
560  auto moment = [&](auto &&t_force, auto &&t_coords) {
562  t_moment(i) =
563  (FTensor::levi_civita<double>(i, j, k) * t_coords(k)) *
564  t_force(j);
565  return t_moment;
566  };
567 
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);
572  }
573  }
574  }
575  }
576 
577  FTensor::Tensor1<double, 3> t_force{reactions[X], reactions[Y],
578  reactions[Z]};
579  FTensor::Tensor1<double, 3> t_moment{reactions[MX], reactions[MY],
580  reactions[MZ]};
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);
586  t_total_moment(i) +=
587  t_moment(i) +
588  (FTensor::levi_civita<double>(i, j, k) * t_off(k)) * t_force(j);
589 
590  auto mpi_reactions = mpi_array_reduce(reactions);
591  if (printBlockName) {
592  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
593  "Block %s Offset: %6.4e %6.4e %6.4e",
594  block_name.c_str(), t_off(X), t_off(Y),
595  t_off(Z));
596  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
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]);
600  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
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]);
604  if ((reactionPtr != nullptr) &&
605  (block_name.compare(reactionBlockName) == 0)) {
606  (*reactionPtr)[X] = mpi_reactions[X];
607  (*reactionPtr)[Y] = mpi_reactions[Y];
608  (*reactionPtr)[Z] = mpi_reactions[Z];
609  }
610  } else {
611  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
612  "Offset: %6.4e %6.4e %6.4e", t_off(X), t_off(Y),
613  t_off(Z));
614  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
615  "Force: %6.4e %6.4e %6.4e", mpi_reactions[X],
616  mpi_reactions[Y], mpi_reactions[Z]);
617  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
618  "Moment: %6.4e %6.4e %6.4e", mpi_reactions[MX],
619  mpi_reactions[MY], mpi_reactions[MZ]);
620  }
621  }
622  }
623  }
624 
625  CHKERR VecRestoreArrayRead(f, &a);
626 
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]);
631  MOFEM_TAG_AND_LOG_C("WORLD", sevLevel, "Essential",
632  "Total moment: %6.4e %6.4e %6.4e",
633  mpi_total_reactions[MX], mpi_total_reactions[MY],
634  mpi_total_reactions[MZ]);
635 
636  } else {
637  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
638  "Can not lock shared pointer");
639  }
640 
642 }

Member Data Documentation

◆ fePtr

Definition at line 168 of file EssentialDisplacementCubitBcData.hpp.

◆ mField

Definition at line 167 of file EssentialDisplacementCubitBcData.hpp.

◆ printBlockName

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

Definition at line 171 of file EssentialDisplacementCubitBcData.hpp.

◆ reactionBlockName

char MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::reactionBlockName[255]
protected

Definition at line 173 of file EssentialDisplacementCubitBcData.hpp.

◆ reactionPtr

boost::shared_ptr<std::vector<double> > MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::reactionPtr
protected

Definition at line 172 of file EssentialDisplacementCubitBcData.hpp.

◆ sevLevel

Definition at line 170 of file EssentialDisplacementCubitBcData.hpp.

◆ vRhs

Definition at line 169 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 reference 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:1381
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:609
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:169
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
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:168
MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::mField
MoFEM::Interface & mField
Definition: EssentialDisplacementCubitBcData.hpp:167
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::EssentialPreProcReaction< DisplacementCubitBcData >::reactionPtr
boost::shared_ptr< std::vector< double > > reactionPtr
Definition: EssentialDisplacementCubitBcData.hpp:172
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:170
MoFEM::MPC::LAST
@ LAST
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:172
MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::printBlockName
PetscBool printBlockName
Definition: EssentialDisplacementCubitBcData.hpp:171
MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >::reactionBlockName
char reactionBlockName[255]
Definition: EssentialDisplacementCubitBcData.hpp:173
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:429
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
MoFEM::PetscOptionsGetBool
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
Definition: DeprecatedPetsc.hpp:182