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

Specialization for DisplacementCubitBcData. More...

#include <src/boundary_conditions/EssentialMPCsData.hpp>

Collaboration diagram for MoFEM::EssentialPostProcRhs< MPCsType >:
[legend]

Public Member Functions

 EssentialPostProcRhs (MoFEM::Interface &m_field, boost::shared_ptr< FEMethod > fe_ptr, double diag=1, SmartPetscObj< Vec > rhs=nullptr)
 
MoFEMErrorCode operator() ()
 

Protected Attributes

MoFEM::InterfacemField
 
boost::weak_ptr< FEMethodfePtr
 
double vDiag
 
SmartPetscObj< Vec > vRhs
 

Detailed Description

Specialization for DisplacementCubitBcData.

Template Parameters
Examples
nonlinear_elastic.cpp.

Definition at line 80 of file EssentialMPCsData.hpp.

Constructor & Destructor Documentation

◆ EssentialPostProcRhs()

MoFEM::EssentialPostProcRhs< MPCsType >::EssentialPostProcRhs ( MoFEM::Interface m_field,
boost::shared_ptr< FEMethod fe_ptr,
double  diag = 1,
SmartPetscObj< Vec >  rhs = nullptr 
)

Definition at line 531 of file EssentialMPCsData.cpp.

534  : mField(m_field), fePtr(fe_ptr), vDiag(diag), vRhs(rhs) {}

Member Function Documentation

◆ operator()()

Definition at line 536 of file EssentialMPCsData.cpp.

536  {
537  MOFEM_LOG_CHANNEL("WORLD");
539 
540  if (auto fe_method_ptr = fePtr.lock()) {
541 
542  auto bc_mng = mField.getInterface<BcManager>();
543  auto is_mng = mField.getInterface<ISManager>();
544  auto vec_mng = mField.getInterface<VecManager>();
545  const auto problem_name = fe_method_ptr->problemPtr->getName();
546  // get connectivity from edge and assign master, slave ents
547  for (auto bc : bc_mng->getBcMapByBlockName()) {
548  if (auto mpc_bc = bc.second->mpcPtr) {
549 
550  auto &bc_id = bc.first;
551 
552  auto regex_str = (boost::format("%s_(.*)") % problem_name).str();
553  if (std::regex_match(bc_id, std::regex(regex_str))) {
554 
555  auto [field_name, block_name] =
556  BcManager::extractStringFromBlockId(bc_id, problem_name);
557 
558  auto get_field_coeffs = [&](auto field_name) {
559  auto field_ptr = mField.get_field_structure(field_name);
560  return field_ptr->getNbOfCoeffs();
561  };
562 
563  const auto nb_field_coeffs = get_field_coeffs(field_name);
564  constexpr auto max_nb_dofs_per_node = 6;
565 
566  if (nb_field_coeffs > max_nb_dofs_per_node)
567  MOFEM_LOG("WORLD", Sev::error)
568  << "MultiPointConstraints PreProcLhs<MPCsType>: support only "
569  "up to 6 dofs per node for now.";
570 
571  MOFEM_LOG("WORLD", Sev::noisy)
572  << "Apply MultiPointConstraints PreProc<MPCsType>: "
573  << problem_name << "_" << field_name << "_" << block_name;
574 
575  auto mpc_type = mpc_bc->mpcType;
576  switch (mpc_type) {
577  case MPC::COUPLING:
578  case MPC::TIE:
579  case MPC::RIGID_BODY:
580  break;
581  default:
582  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
583  "MPC type not implemented");
584  }
585 
586  auto master_verts = mpc_bc->mpcMasterEnts.subset_by_type(MBVERTEX);
587  auto slave_verts = mpc_bc->mpcSlaveEnts.subset_by_type(MBVERTEX);
588 
589  auto prb_name = fe_method_ptr->problemPtr->getName();
590 
591  auto get_flag = [&](int idx) { return (&mpc_bc->data.flag1)[idx]; };
592 
593  auto add_is = [](auto is1, auto is2) {
594  IS is;
595  CHK_THROW_MESSAGE(ISExpand(is1, is2, &is), "is sum");
596  return SmartPetscObj<IS>(is);
597  };
598 
599  SmartPetscObj<IS> is_m[max_nb_dofs_per_node];
600  SmartPetscObj<IS> is_s[max_nb_dofs_per_node];
601 
602  for (int dd = 0; dd != nb_field_coeffs; dd++) {
603  if (get_flag(dd)) {
604 
605  CHKERR is_mng->isCreateProblemFieldAndRankLocal(
606  prb_name, ROW, field_name, dd, dd, is_m[dd], &master_verts);
607  CHKERR is_mng->isCreateProblemFieldAndRankLocal(
608  prb_name, ROW, field_name, dd, dd, is_s[dd], &slave_verts);
609 
610  }
611  }
612 
613  {
614 
615  if (auto fe_ptr = fePtr.lock()) {
616  auto snes_ctx = fe_ptr->snes_ctx;
617  auto ts_ctx = fe_ptr->ts_ctx;
618  const bool is_nonlinear = snes_ctx != FEMethod::CTX_SNESNONE ||
620  // is_nonlinear = is_nonlinear || mpc_bc->isReprocitical;
621  const int contrb = mpc_bc->isReprocitical ? 1 : 0;
622  SmartPetscObj<Vec> F =
623  vRhs ? vRhs : SmartPetscObj<Vec>(fe_ptr->f, true);
624 
625  if (fe_ptr->vecAssembleSwitch) {
626  if ((*fe_ptr->vecAssembleSwitch) && !vRhs) {
627  CHKERR VecGhostUpdateBegin(F, ADD_VALUES, SCATTER_REVERSE);
628  CHKERR VecGhostUpdateEnd(F, ADD_VALUES, SCATTER_REVERSE);
629  CHKERR VecAssemblyBegin(F);
630  CHKERR VecAssemblyEnd(F);
631  *fe_ptr->vecAssembleSwitch = false;
632  }
633  }
634 
635  auto vec_set_values = [&](auto is_xyz_m, auto is_xyz_s, double val) {
637  const int *m_index_ptr;
638  CHKERR ISGetIndices(is_xyz_m, &m_index_ptr);
639  const int *s_index_ptr;
640  CHKERR ISGetIndices(is_xyz_s, &s_index_ptr);
641  int size_m;
642  CHKERR ISGetLocalSize(is_xyz_m, &size_m);
643  int size_s;
644  CHKERR ISGetLocalSize(is_xyz_s, &size_s);
645 
646  double *f;
647  CHKERR VecGetArray(F, &f);
648  // if (size_m > size_s)
649  // MOFEM_LOG("WORLD", Sev::error)
650  // << "Size of master IS > Size of slave IS : " << size_m
651  // << " > " << size_s;
652  // if (size_m == 0)
653  // MOFEM_LOG("WORLD", Sev::error)
654  // << "Size of master IS is " << size_m;
655 
656  if (is_nonlinear) {
657  auto x = fe_ptr->x;
658  auto tmp_x = vectorDuplicate(F);
659 
660  CHKERR vec_mng->setLocalGhostVector(problem_name, ROW,
661  tmp_x, INSERT_VALUES,
662  SCATTER_FORWARD);
663  const double *v;
664  const double *u;
665 
666  CHKERR VecGetArrayRead(tmp_x, &u);
667  CHKERR VecGetArrayRead(x, &v);
668  if (size_m && size_s) {
669  for (auto i = 0; i != size_s; ++i) {
670  auto m_idx = size_m == 1 ? 0 : i;
671  f[s_index_ptr[i]] = val * (v[s_index_ptr[i]] - v[m_index_ptr[m_idx]]) + f[s_index_ptr[i]] * contrb ;
672  }
673  }
674  CHKERR VecRestoreArrayRead(x, &v);
675  CHKERR VecRestoreArrayRead(tmp_x, &u);
676  } else {
677  if (size_m && size_s)
678  for (auto i = 0; i != size_s; ++i) {
679  f[s_index_ptr[i]] = 0;
680  }
681  }
682 
683  CHKERR VecRestoreArray(F, &f);
684  CHKERR ISRestoreIndices(is_xyz_m, &m_index_ptr);
685  CHKERR ISRestoreIndices(is_xyz_s, &s_index_ptr);
686 
688  };
689 
690  for (int dd = 0; dd != nb_field_coeffs; dd++)
691  if (get_flag(dd)) {
692 
693  if (!mpc_bc->isReprocitical) {
694  CHKERR vec_set_values(is_m[dd], is_s[dd], vDiag);
695  } else {
696  auto &pn = mpc_bc->mPenalty;
697  CHKERR vec_set_values(is_m[dd], is_s[dd], pn);
698  CHKERR vec_set_values(is_s[dd], is_m[dd], pn);
699  }
700  }
701  };
702 
703  // User is responsible for assembly if vLhs is provided
704 
705  // ISView(is_xyz_m, PETSC_VIEWER_STDOUT_WORLD);
706  // CHKERR MatZeroRowsColumnsIS(B, is_xyz_m, vDiag, PETSC_NULL,
707  // PETSC_NULL);
708  }
709  }
710  }
711  }
712  } else {
713  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
714  "Can not lock shared pointer");
715  }
716 
718 }

Member Data Documentation

◆ fePtr

boost::weak_ptr<FEMethod> MoFEM::EssentialPostProcRhs< MPCsType >::fePtr
protected

Definition at line 89 of file EssentialMPCsData.hpp.

◆ mField

Definition at line 88 of file EssentialMPCsData.hpp.

◆ vDiag

Definition at line 90 of file EssentialMPCsData.hpp.

◆ vRhs

Definition at line 91 of file EssentialMPCsData.hpp.


The documentation for this struct was generated from the following files:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
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
MoFEM::Field::getNbOfCoeffs
FieldCoefficientsNumber getNbOfCoeffs() const
Get number of field coefficients.
Definition: FieldMultiIndices.hpp:188
MOFEM_LOG_CHANNEL
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
CHK_THROW_MESSAGE
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
Definition: definitions.h:596
MoFEM::CoreInterface::get_field_structure
virtual const Field * get_field_structure(const std::string &name, enum MoFEMTypes bh=MF_EXIST) const =0
get field structure
MoFEM::EssentialPostProcRhs< MPCsType >::fePtr
boost::weak_ptr< FEMethod > fePtr
Definition: EssentialMPCsData.hpp:89
ts_ctx
MoFEM::TsCtx * ts_ctx
Definition: level_set.cpp:1932
ROW
@ ROW
Definition: definitions.h:123
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::SnesMethod::CTX_SNESNONE
@ CTX_SNESNONE
Definition: LoopMethods.hpp:107
MoFEM::MPC::RIGID_BODY
@ RIGID_BODY
MoFEM::TSMethod::CTX_TSNONE
@ CTX_TSNONE
Definition: LoopMethods.hpp:145
MoFEM::EssentialPostProcRhs< MPCsType >::mField
MoFEM::Interface & mField
Definition: EssentialMPCsData.hpp:88
MoFEM::MPC::TIE
@ TIE
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
v
const double v
phase velocity of light in medium (cm/ns)
Definition: initial_diffusion.cpp:40
FTensor::dd
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: ddTensor0.hpp:33
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
MoFEM::vectorDuplicate
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
Definition: PetscSmartObj.hpp:217
HenckyOps::f
auto f
Definition: HenckyOps.hpp:15
MoFEM::EssentialPostProcRhs< MPCsType >::vRhs
SmartPetscObj< Vec > vRhs
Definition: EssentialMPCsData.hpp:91
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
MoFEM::EssentialPostProcRhs< MPCsType >::vDiag
double vDiag
Definition: EssentialMPCsData.hpp:90
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::MPC::COUPLING
@ COUPLING
F
@ F
Definition: free_surface.cpp:394