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

Specialization for MPCsType. More...

#include <src/boundary_conditions/EssentialMPCsData.hpp>

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

Public Member Functions

 EssentialPostProcLhs (MoFEM::Interface &m_field, boost::shared_ptr< FEMethod > fe_ptr, double diag=1, SmartPetscObj< Mat > lhs=nullptr, SmartPetscObj< AO > ao=nullptr)
 
MoFEMErrorCode operator() ()
 

Protected Attributes

MoFEM::InterfacemField
 
boost::weak_ptr< FEMethodfePtr
 
double vDiag
 
SmartPetscObj< Mat > vLhs
 
SmartPetscObj< AO > vAO
 

Detailed Description

Specialization for MPCsType.

Template Parameters
Examples
nonlinear_elastic.cpp.

Definition at line 99 of file EssentialMPCsData.hpp.

Constructor & Destructor Documentation

◆ EssentialPostProcLhs()

MoFEM::EssentialPostProcLhs< MPCsType >::EssentialPostProcLhs ( MoFEM::Interface m_field,
boost::shared_ptr< FEMethod fe_ptr,
double  diag = 1,
SmartPetscObj< Mat >  lhs = nullptr,
SmartPetscObj< AO >  ao = nullptr 
)

Definition at line 328 of file EssentialMPCsData.cpp.

331  : mField(m_field), fePtr(fe_ptr), vDiag(diag), vLhs(lhs), vAO(ao) {}

Member Function Documentation

◆ operator()()

Definition at line 333 of file EssentialMPCsData.cpp.

333  {
334  MOFEM_LOG_CHANNEL("WORLD");
336 
337  if (auto fe_ptr = fePtr.lock()) {
338 
339  auto bc_mng = mField.getInterface<BcManager>();
340  auto is_mng = mField.getInterface<ISManager>();
341  const auto problem_name = fe_ptr->problemPtr->getName();
342  bool do_assembly = false;
343  for (auto bc : bc_mng->getBcMapByBlockName()) {
344  if (auto mpc_bc = bc.second->mpcPtr) {
345 
346  auto &bc_id = bc.first;
347 
348  auto regex_str = (boost::format("%s_(.*)") % problem_name).str();
349  if (std::regex_match(bc_id, std::regex(regex_str))) {
350 
351  auto [field_name, block_name] =
352  BcManager::extractStringFromBlockId(bc_id, problem_name);
353 
354  auto get_field_coeffs = [&](auto field_name) {
355  auto field_ptr = mField.get_field_structure(field_name);
356  return field_ptr->getNbOfCoeffs();
357  };
358 
359  const auto nb_field_coeffs = get_field_coeffs(field_name);
360  constexpr auto max_nb_dofs_per_node = 6;
361 
362  if (nb_field_coeffs > max_nb_dofs_per_node)
363  MOFEM_LOG("WORLD", Sev::error)
364  << "MultiPointConstraints PreProcLhs<MPCsType>: support only "
365  "up to 6 dofs per node.";
366  MOFEM_LOG("WORLD", Sev::noisy)
367  << "Apply MultiPointConstraints PreProc<MPCsType>: "
368  << problem_name << "_" << field_name << "_" << block_name;
369 
370  auto mpc_type = mpc_bc->mpcType;
371  switch (mpc_type) {
372  case MPC::COUPLING:
373  case MPC::TIE:
374  case MPC::RIGID_BODY:
375  break;
376  default:
377  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
378  "MPC type not implemented");
379  }
380 
381  // FIXME: there handle the vertices differently (block level)
382  auto master_verts = mpc_bc->mpcMasterEnts.subset_by_type(MBVERTEX);
383  auto slave_verts = mpc_bc->mpcSlaveEnts.subset_by_type(MBVERTEX);
384 
385  auto prb_name = fe_ptr->problemPtr->getName();
386  auto get_flag = [&](int idx) { return (&mpc_bc->data.flag1)[idx]; };
387  MOFEM_LOG("WORLD", Sev::verbose)
388  << "Size of master nodes: " << mpc_bc->mpcMasterEnts.size()
389  << " Size of slave nodes : " << mpc_bc->mpcSlaveEnts.size();
390 
391  if (mpc_bc->mpcMasterEnts.size() > mpc_bc->mpcSlaveEnts.size()) {
392  MOFEM_LOG("WORLD", Sev::error)
393  << "Size of master nodes < Size of slave nodes : "
394  << mpc_bc->mpcMasterEnts.size() << " > " << mpc_bc->mpcSlaveEnts.size();
395  // SETERRQ(PETSC_COMM_WORLD, MOFEM_OPERATION_UNSUCCESSFUL,
396  // "data inconsistency");
397  }
398 
399  auto add_is = [](auto is1, auto is2) {
400  IS is;
401  CHK_THROW_MESSAGE(ISExpand(is1, is2, &is), "is sum");
402  return SmartPetscObj<IS>(is);
403  };
404 
405  SmartPetscObj<IS> is_xyz_row_sum;
406  SmartPetscObj<IS> is_m_row[max_nb_dofs_per_node];
407  SmartPetscObj<IS> is_m_col[max_nb_dofs_per_node];
408  SmartPetscObj<IS> is_s_row[max_nb_dofs_per_node];
409  SmartPetscObj<IS> is_s_col[max_nb_dofs_per_node];
410 
411  for (int dd = 0; dd != nb_field_coeffs; dd++) {
412  if (get_flag(dd)) {
413  // SmartPetscObj<IS> is_xyz_m;
414  CHKERR is_mng->isCreateProblemFieldAndRank(
415  prb_name, ROW, field_name, dd, dd, is_m_row[dd],
416  &master_verts);
417  CHKERR is_mng->isCreateProblemFieldAndRank(
418  prb_name, COL, field_name, dd, dd, is_m_col[dd],
419  &master_verts);
420  CHKERR is_mng->isCreateProblemFieldAndRank(
421  prb_name, COL, field_name, dd, dd, is_s_col[dd],
422  &slave_verts);
423  CHKERR is_mng->isCreateProblemFieldAndRank(
424  prb_name, ROW, field_name, dd, dd, is_s_row[dd],
425  &slave_verts);
426  // ISView(is_s_row[dd], PETSC_VIEWER_STDOUT_WORLD);
427  // ISView(is_s_col[dd], PETSC_VIEWER_STDOUT_WORLD);
428 
429  if (!mpc_bc->isReprocitical) {
430  if (!is_xyz_row_sum) {
431  is_xyz_row_sum = is_s_row[dd];
432  } else {
433  is_xyz_row_sum = add_is(is_xyz_row_sum, is_s_row[dd]);
434  }
435  }
436  }
437  }
438 
439  // if (is_xyz_row_sum) {
440  SmartPetscObj<Mat> B =
441  vLhs ? vLhs : SmartPetscObj<Mat>(fe_ptr->B, true);
442  // The user is responsible for assembly if vLhs is provided
443  MatType typem;
444  CHKERR MatGetType(B, &typem);
445  CHKERR MatSetOption(B, MAT_NEW_NONZERO_LOCATIONS, PETSC_TRUE);
446  if (typem == MATMPIBAIJ)
447  CHKERR MatSetOption(B, MAT_USE_HASH_TABLE, PETSC_TRUE);
448 
449  if ((*fe_ptr->matAssembleSwitch) && !vLhs) {
450  if (*fe_ptr->matAssembleSwitch) {
451  CHKERR MatAssemblyBegin(B, MAT_FLUSH_ASSEMBLY);
452  CHKERR MatAssemblyEnd(B, MAT_FLUSH_ASSEMBLY);
453  *fe_ptr->matAssembleSwitch = false;
454  }
455  }
456 
457  if (vAO) {
458  MOFEM_LOG("WORLD", Sev::error) << "No support for AO yet";
459  }
460 
461  CHKERR MatZeroRowsIS(B, is_xyz_row_sum, 0, PETSC_NULL,
462  PETSC_NULL);
463  // }
464  auto set_mat_values = [&](auto row_is, auto col_is, double val, double perturb = 0) {
466  const int *row_index_ptr;
467  CHKERR ISGetIndices(row_is, &row_index_ptr);
468  const int *col_index_ptr;
469  CHKERR ISGetIndices(col_is, &col_index_ptr);
470  int row_size, col_size;
471  CHKERR ISGetLocalSize(row_is, &row_size);
472  CHKERR ISGetLocalSize(col_is, &col_size);
473 
474  MatrixDouble locMat(row_size, col_size);
475  fill(locMat.data().begin(), locMat.data().end(), 0.0);
476  for (int i = 0; i != row_size; i++)
477  for (int j = 0; j != col_size; j++)
478  if (i == j || col_size == 1)
479  locMat(i, j) = val;
480 
481  if (mpc_bc->isReprocitical) {
482  locMat *= perturb;
483  CHKERR ::MatSetValues(B, row_size, row_index_ptr, col_size,
484  col_index_ptr, &*locMat.data().begin(),
485  ADD_VALUES);
486  } else {
487  CHKERR ::MatSetValues(B, row_size, row_index_ptr, col_size,
488  col_index_ptr, &*locMat.data().begin(),
489  INSERT_VALUES);
490  }
491 
492  CHKERR ISRestoreIndices(row_is, &row_index_ptr);
493  CHKERR ISRestoreIndices(col_is, &col_index_ptr);
494 
496  };
497 
498  for (int dd = 0; dd != nb_field_coeffs; dd++) {
499  if (get_flag(dd)) {
500  do_assembly = true;
501  if (!mpc_bc->isReprocitical) {
502  CHKERR set_mat_values(is_s_row[dd], is_s_col[dd], vDiag);
503  CHKERR set_mat_values(is_s_row[dd], is_m_col[dd], -vDiag);
504  }
505  else
506  {
507  auto &pn = mpc_bc->mPenalty;
508  CHKERR set_mat_values(is_s_row[dd], is_s_col[dd], vDiag, pn);
509  CHKERR set_mat_values(is_s_row[dd], is_m_col[dd], -vDiag, pn);
510  CHKERR set_mat_values(is_m_row[dd], is_m_col[dd], vDiag, pn);
511  CHKERR set_mat_values(is_m_row[dd], is_s_col[dd], -vDiag, pn);
512  }
513  }
514  }
515  } // if regex
516  } // mpc loop
517  } // bc loop
518  if (do_assembly) {
519  SmartPetscObj<Mat> B = vLhs ? vLhs : SmartPetscObj<Mat>(fe_ptr->B, true);
520  CHKERR MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY);
521  CHKERR MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY);
522  }
523 
524  } else {
525  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
526  "Can not lock shared pointer");
527  } // if fe_ptr
529 }

Member Data Documentation

◆ fePtr

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

Definition at line 110 of file EssentialMPCsData.hpp.

◆ mField

Definition at line 109 of file EssentialMPCsData.hpp.

◆ vAO

Definition at line 113 of file EssentialMPCsData.hpp.

◆ vDiag

Definition at line 111 of file EssentialMPCsData.hpp.

◆ vLhs

Definition at line 112 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::MatSetValues
MoFEMErrorCode MatSetValues(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const double *ptr, InsertMode iora)
Assemble PETSc matrix.
Definition: EntitiesFieldData.hpp:1631
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::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
ROW
@ ROW
Definition: definitions.h:123
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::EssentialPostProcLhs< MPCsType >::fePtr
boost::weak_ptr< FEMethod > fePtr
Definition: EssentialMPCsData.hpp:110
MoFEM::EssentialPostProcLhs< MPCsType >::vDiag
double vDiag
Definition: EssentialMPCsData.hpp:111
MoFEM::MPC::RIGID_BODY
@ RIGID_BODY
COL
@ COL
Definition: definitions.h:123
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
MoFEM::EssentialPostProcLhs< MPCsType >::vAO
SmartPetscObj< AO > vAO
Definition: EssentialMPCsData.hpp:113
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
j
FTensor::Index< 'j', 3 > j
Definition: matrix_function.cpp:19
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::EssentialPostProcLhs< MPCsType >::vLhs
SmartPetscObj< Mat > vLhs
Definition: EssentialMPCsData.hpp:112
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
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
MoFEM::EssentialPostProcLhs< MPCsType >::mField
MoFEM::Interface & mField
Definition: EssentialMPCsData.hpp:109