337 if (
auto fe_ptr =
fePtr.lock()) {
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) {
346 auto &bc_id = bc.first;
348 auto regex_str = (boost::format(
"%s_(.*)") % problem_name).str();
349 if (std::regex_match(bc_id, std::regex(regex_str))) {
354 auto get_field_coeffs = [&](
auto field_name) {
359 const auto nb_field_coeffs = get_field_coeffs(
field_name);
360 constexpr
auto max_nb_dofs_per_node = 6;
362 if (nb_field_coeffs > max_nb_dofs_per_node)
364 <<
"MultiPointConstraints PreProcLhs<MPCsType>: support only "
365 "up to 6 dofs per node.";
367 <<
"Apply MultiPointConstraints PreProc<MPCsType>: "
368 << problem_name <<
"_" <<
field_name <<
"_" << block_name;
370 auto mpc_type = mpc_bc->mpcType;
378 "MPC type not implemented");
382 auto master_verts = mpc_bc->mpcMasterEnts.subset_by_type(MBVERTEX);
383 auto slave_verts = mpc_bc->mpcSlaveEnts.subset_by_type(MBVERTEX);
385 auto prb_name = fe_ptr->problemPtr->getName();
386 auto get_flag = [&](
int idx) {
return (&mpc_bc->data.flag1)[idx]; };
388 <<
"Size of master nodes: " << mpc_bc->mpcMasterEnts.size()
389 <<
" Size of slave nodes : " << mpc_bc->mpcSlaveEnts.size();
391 if (mpc_bc->mpcMasterEnts.size() > mpc_bc->mpcSlaveEnts.size()) {
393 <<
"Size of master nodes < Size of slave nodes : "
394 << mpc_bc->mpcMasterEnts.size() <<
" > " << mpc_bc->mpcSlaveEnts.size();
399 auto add_is = [](
auto is1,
auto is2) {
402 return SmartPetscObj<IS>(is);
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];
411 for (
int dd = 0;
dd != nb_field_coeffs;
dd++) {
414 CHKERR is_mng->isCreateProblemFieldAndRank(
417 CHKERR is_mng->isCreateProblemFieldAndRank(
420 CHKERR is_mng->isCreateProblemFieldAndRank(
423 CHKERR is_mng->isCreateProblemFieldAndRank(
429 if (!mpc_bc->isReprocitical) {
430 if (!is_xyz_row_sum) {
431 is_xyz_row_sum = is_s_row[
dd];
433 is_xyz_row_sum = add_is(is_xyz_row_sum, is_s_row[
dd]);
440 SmartPetscObj<Mat> B =
441 vLhs ?
vLhs : SmartPetscObj<Mat>(fe_ptr->B,
true);
444 CHKERR MatGetType(B, &typem);
445 CHKERR MatSetOption(B, MAT_NEW_NONZERO_LOCATIONS, PETSC_TRUE);
446 PetscBool is_mat_baij = PETSC_FALSE;
447 PetscObjectTypeCompare((PetscObject)B, MATMPIBAIJ, &is_mat_baij);
449 CHKERR MatSetOption(B, MAT_USE_HASH_TABLE, PETSC_TRUE);
450 if ((*fe_ptr->matAssembleSwitch) && !
vLhs) {
451 if (*fe_ptr->matAssembleSwitch) {
452 CHKERR MatAssemblyBegin(B, MAT_FLUSH_ASSEMBLY);
453 CHKERR MatAssemblyEnd(B, MAT_FLUSH_ASSEMBLY);
454 *fe_ptr->matAssembleSwitch =
false;
459 MOFEM_LOG(
"WORLD", Sev::error) <<
"No support for AO yet";
462 CHKERR MatZeroRowsIS(B, is_xyz_row_sum, 0, PETSC_NULL,
465 auto set_mat_values = [&](
auto row_is,
auto col_is,
double val,
double perturb = 0) {
467 const int *row_index_ptr;
468 CHKERR ISGetIndices(row_is, &row_index_ptr);
469 const int *col_index_ptr;
470 CHKERR ISGetIndices(col_is, &col_index_ptr);
471 int row_size, col_size;
472 CHKERR ISGetLocalSize(row_is, &row_size);
473 CHKERR ISGetLocalSize(col_is, &col_size);
476 fill(locMat.data().begin(), locMat.data().end(), 0.0);
477 for (
int i = 0;
i != row_size;
i++)
478 for (
int j = 0;
j != col_size;
j++)
479 if (
i ==
j || col_size == 1)
482 if (mpc_bc->isReprocitical) {
485 col_index_ptr, &*locMat.data().begin(),
489 col_index_ptr, &*locMat.data().begin(),
493 CHKERR ISRestoreIndices(row_is, &row_index_ptr);
494 CHKERR ISRestoreIndices(col_is, &col_index_ptr);
499 for (
int dd = 0;
dd != nb_field_coeffs;
dd++) {
502 if (!mpc_bc->isReprocitical) {
508 auto &pn = mpc_bc->mPenalty;
520 SmartPetscObj<Mat> B =
vLhs ?
vLhs : SmartPetscObj<Mat>(fe_ptr->B,
true);
521 CHKERR MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY);
522 CHKERR MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY);
527 "Can not lock shared pointer");