541 if (
auto fe_method_ptr =
fePtr.lock()) {
546 const auto problem_name = fe_method_ptr->problemPtr->getName();
548 for (
auto bc : bc_mng->getBcMapByBlockName()) {
549 if (
auto mpc_bc = bc.second->mpcPtr) {
551 auto &bc_id = bc.first;
553 auto regex_str = (boost::format(
"%s_(.*)") % problem_name).str();
554 if (std::regex_match(bc_id, std::regex(regex_str))) {
559 auto get_field_coeffs = [&](
auto field_name) {
564 const auto nb_field_coeffs = get_field_coeffs(
field_name);
565 constexpr
auto max_nb_dofs_per_node = 6;
567 if (nb_field_coeffs > max_nb_dofs_per_node)
569 <<
"MultiPointConstraints PreProcLhs<MPCsType>: support only "
570 "up to 6 dofs per node for now.";
573 <<
"Apply MultiPointConstraints PreProc<MPCsType>: "
574 << problem_name <<
"_" <<
field_name <<
"_" << block_name;
576 auto mpc_type = mpc_bc->mpcType;
584 "MPC type not implemented");
587 auto master_verts = mpc_bc->mpcMasterEnts.subset_by_type(MBVERTEX);
588 auto slave_verts = mpc_bc->mpcSlaveEnts.subset_by_type(MBVERTEX);
590 auto prb_name = fe_method_ptr->problemPtr->getName();
592 auto get_flag = [&](
int idx) {
return (&mpc_bc->data.flag1)[idx]; };
594 SmartPetscObj<IS> is_m[max_nb_dofs_per_node];
595 SmartPetscObj<IS> is_s[max_nb_dofs_per_node];
597 for (
int dd = 0;
dd != nb_field_coeffs;
dd++) {
600 CHKERR is_mng->isCreateProblemFieldAndRankLocal(
602 CHKERR is_mng->isCreateProblemFieldAndRankLocal(
610 if (
auto fe_ptr =
fePtr.lock()) {
611 auto snes_ctx = fe_ptr->snes_ctx;
612 auto ts_ctx = fe_ptr->ts_ctx;
616 const int contrb = mpc_bc->isReprocitical ? 1 : 0;
617 SmartPetscObj<Vec>
F =
618 vRhs ?
vRhs : SmartPetscObj<Vec>(fe_ptr->f,
true);
620 if (fe_ptr->vecAssembleSwitch) {
621 if ((*fe_ptr->vecAssembleSwitch) && !
vRhs) {
622 CHKERR VecGhostUpdateBegin(
F, ADD_VALUES, SCATTER_REVERSE);
623 CHKERR VecGhostUpdateEnd(
F, ADD_VALUES, SCATTER_REVERSE);
626 *fe_ptr->vecAssembleSwitch =
false;
630 auto vec_set_values = [&](
auto is_xyz_m,
auto is_xyz_s,
double val) {
632 const int *m_index_ptr;
633 CHKERR ISGetIndices(is_xyz_m, &m_index_ptr);
634 const int *s_index_ptr;
635 CHKERR ISGetIndices(is_xyz_s, &s_index_ptr);
637 CHKERR ISGetLocalSize(is_xyz_m, &size_m);
639 CHKERR ISGetLocalSize(is_xyz_s, &size_s);
655 CHKERR vec_mng->setLocalGhostVector(problem_name,
ROW,
656 tmp_x, INSERT_VALUES,
661 CHKERR VecGetArrayRead(tmp_x, &u);
663 if (size_m && size_s) {
664 for (
auto i = 0;
i != size_s; ++
i) {
665 auto m_idx = size_m == 1 ? 0 :
i;
666 f[s_index_ptr[
i]] = val * (
v[s_index_ptr[
i]] -
v[m_index_ptr[m_idx]]) +
f[s_index_ptr[
i]] * contrb ;
669 CHKERR VecRestoreArrayRead(x, &
v);
670 CHKERR VecRestoreArrayRead(tmp_x, &u);
672 if (size_m && size_s)
673 for (
auto i = 0;
i != size_s; ++
i) {
674 f[s_index_ptr[
i]] = 0;
679 CHKERR ISRestoreIndices(is_xyz_m, &m_index_ptr);
680 CHKERR ISRestoreIndices(is_xyz_s, &s_index_ptr);
685 for (
int dd = 0;
dd != nb_field_coeffs;
dd++)
688 if (!mpc_bc->isReprocitical) {
691 auto &pn = mpc_bc->mPenalty;
692 CHKERR vec_set_values(is_m[
dd], is_s[
dd], pn);
693 CHKERR vec_set_values(is_s[
dd], is_m[
dd], pn);
709 "Can not lock shared pointer");