540 if (
auto fe_method_ptr =
fePtr.lock()) {
545 const auto problem_name = fe_method_ptr->problemPtr->getName();
547 for (
auto bc : bc_mng->getBcMapByBlockName()) {
548 if (
auto mpc_bc = bc.second->mpcPtr) {
550 auto &bc_id = bc.first;
552 auto regex_str = (boost::format(
"%s_(.*)") % problem_name).str();
553 if (std::regex_match(bc_id, std::regex(regex_str))) {
558 auto get_field_coeffs = [&](
auto field_name) {
563 const auto nb_field_coeffs = get_field_coeffs(
field_name);
564 constexpr
auto max_nb_dofs_per_node = 6;
566 if (nb_field_coeffs > max_nb_dofs_per_node)
568 <<
"MultiPointConstraints PreProcLhs<MPCsType>: support only "
569 "up to 6 dofs per node for now.";
572 <<
"Apply MultiPointConstraints PreProc<MPCsType>: "
573 << problem_name <<
"_" <<
field_name <<
"_" << block_name;
575 auto mpc_type = mpc_bc->mpcType;
583 "MPC type not implemented");
586 auto master_verts = mpc_bc->mpcMasterEnts.subset_by_type(MBVERTEX);
587 auto slave_verts = mpc_bc->mpcSlaveEnts.subset_by_type(MBVERTEX);
589 auto prb_name = fe_method_ptr->problemPtr->getName();
591 auto get_flag = [&](
int idx) {
return (&mpc_bc->data.flag1)[idx]; };
593 auto add_is = [](
auto is1,
auto is2) {
596 return SmartPetscObj<IS>(is);
599 SmartPetscObj<IS> is_m[max_nb_dofs_per_node];
600 SmartPetscObj<IS> is_s[max_nb_dofs_per_node];
602 for (
int dd = 0;
dd != nb_field_coeffs;
dd++) {
605 CHKERR is_mng->isCreateProblemFieldAndRankLocal(
607 CHKERR is_mng->isCreateProblemFieldAndRankLocal(
615 if (
auto fe_ptr =
fePtr.lock()) {
616 auto snes_ctx = fe_ptr->snes_ctx;
617 auto ts_ctx = fe_ptr->ts_ctx;
621 const int contrb = mpc_bc->isReprocitical ? 1 : 0;
622 SmartPetscObj<Vec>
F =
623 vRhs ?
vRhs : SmartPetscObj<Vec>(fe_ptr->f,
true);
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);
631 *fe_ptr->vecAssembleSwitch =
false;
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);
642 CHKERR ISGetLocalSize(is_xyz_m, &size_m);
644 CHKERR ISGetLocalSize(is_xyz_s, &size_s);
660 CHKERR vec_mng->setLocalGhostVector(problem_name,
ROW,
661 tmp_x, INSERT_VALUES,
666 CHKERR VecGetArrayRead(tmp_x, &u);
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 ;
674 CHKERR VecRestoreArrayRead(x, &
v);
675 CHKERR VecRestoreArrayRead(tmp_x, &u);
677 if (size_m && size_s)
678 for (
auto i = 0;
i != size_s; ++
i) {
679 f[s_index_ptr[
i]] = 0;
684 CHKERR ISRestoreIndices(is_xyz_m, &m_index_ptr);
685 CHKERR ISRestoreIndices(is_xyz_s, &s_index_ptr);
690 for (
int dd = 0;
dd != nb_field_coeffs;
dd++)
693 if (!mpc_bc->isReprocitical) {
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);
714 "Can not lock shared pointer");