18 : cOre(const_cast<
MoFEM::
Core &>(core)), dEbug(false) {}
28 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
33 for (
auto fit = fe_ptr->begin(); fit != fe_ptr->end(); fit++) {
34 if ((fit->get()->getId() & problem_ptr->
getBitFEId()).any()) {
35 fields_ids |= fit->get()->getBitFieldIdRow();
41 for (
auto fit = fe_ptr->begin(); fit != fe_ptr->end(); fit++) {
42 if ((fit->get()->getId() & problem_ptr->
getBitFEId()).any()) {
43 fields_ids |= fit->get()->getBitFieldIdCol();
49 "Has to be ROW or COLUMN");
52 map<std::string, std::pair<int, int>> fields_map;
55 for (
auto fit = fields_ptr->begin(); fit != fields_ptr->end(); fit++) {
56 if ((fit->get()->getId() & fields_ids).any()) {
57 fields_map[fit->get()->getName()].first = field++;
58 fields_map[fit->get()->getName()].second = fit->get()->getNbOfCoeffs();
63 CHKERR PetscSectionCreate(PETSC_COMM_WORLD, s);
64 CHKERR PetscSectionSetNumFields(*s, fields_map.size());
65 for (
auto mit = fields_map.begin(); mit != fields_map.end(); mit++) {
66 CHKERR PetscSectionSetFieldName(*s, mit->second.first, mit->first.c_str());
67 CHKERR PetscSectionSetFieldComponents(*s, mit->second.first,
73 auto dit = dofs->begin();
74 auto hi_dit = dofs->end();
75 for (; dit != hi_dit;) {
76 if (
static_cast<int>(dit->get()->getPart()) == proc) {
77 const auto &ent_uid = dit->get()->getEntLocalUniqueId();
78 while (dit != hi_dit && dit->get()->getEntLocalUniqueId() == ent_uid) {
89 CHKERR PetscLayoutCreate(PETSC_COMM_WORLD, &layout);
90 CHKERR PetscLayoutSetBlockSize(layout, 1);
91 CHKERR PetscLayoutSetLocalSize(layout, nb_charts);
92 CHKERR PetscLayoutSetUp(layout);
94 CHKERR PetscLayoutGetRange(layout, &rstart, &rend);
95 CHKERR PetscLayoutDestroy(&layout);
96 CHKERR PetscSectionSetChart(*s, rstart, rend);
100 auto dit = dofs->begin();
101 auto hi_dit = dofs->end();
103 for (; dit != hi_dit;) {
104 if (
static_cast<int>(dit->get()->getPart()) == proc) {
106 const auto &
field_name = dit->get()->getName();
109 const auto &ent_uid = dit->get()->getEntLocalUniqueId();
110 while (dit != hi_dit && dit->get()->getEntLocalUniqueId() == ent_uid) {
111 const DofIdx loc_idx = dit->get()->getPetscLocalDofIdx();
117 if (fields_map.find(
field_name) == fields_map.end()) {
118 MOFEM_LOG_C(
"SELF", Sev::warning,
"Warning: Field %s not found",
119 dit->get()->getName().c_str());
121 CHKERR PetscSectionAddDof(*s, point,
dd);
123 CHKERR PetscSectionSetFieldDof(*s, point, field,
dd);
134 CHKERR PetscSectionSetUp(*s);
145 "Section not created");
171 auto lo = dofs_ptr->get<
Part_mi_tag>().lower_bound(rank);
172 auto hi = dofs_ptr->get<
Part_mi_tag>().upper_bound(rank);
173 const int size = std::distance(lo, hi);
176 CHKERR PetscMalloc(size *
sizeof(
int), &
id);
178 for (; lo != hi; ++lo, ++id_it)
179 *id_it = (*lo)->getPetscGlobalDofIdx();
182 CHKERR ISCreateGeneral(PETSC_COMM_WORLD, size,
id, PETSC_OWN_POINTER, is);
206 int max_order, IS *is)
const {
212 typedef multi_index_container<
213 boost::shared_ptr<NumeredDofEntity>,
225 NumeredDofEntity_order_view_multiIndex;
229 NumeredDofEntity_order_view_multiIndex dofs_by_order;
230 auto insert_part_range = [&dofs_by_order, rank](
auto &dofs) {
231 dofs_by_order.insert(dofs_by_order.end(), dofs.lower_bound(rank),
232 dofs.upper_bound(rank));
246 auto lo = dofs_by_order.get<
Order_mi_tag>().lower_bound(min_order);
247 auto hi = dofs_by_order.get<
Order_mi_tag>().upper_bound(max_order);
248 const int size = std::distance(lo, hi);
250 CHKERR PetscMalloc(size *
sizeof(
int), &
id);
252 for (; lo != hi; ++lo, ++id_it)
253 *id_it = (*lo)->getPetscGlobalDofIdx();
256 CHKERR ISCreateGeneral(PETSC_COMM_WORLD, size,
id, PETSC_OWN_POINTER, is);
273 const std::string problem_name,
RowColData rc,
const std::string field,
274 int min_coeff_idx,
int max_coeff_idx, IS *is,
Range *ents_ptr)
const {
282 DofsByUId::iterator it, hi_it;
303 std::vector<int> idx_vec;
304 idx_vec.reserve(std::distance(it, hi_it));
305 for (; it != hi_it; ++it) {
307 auto true_if_dof_on_entity = [&]() {
309 return ents_ptr->find((*it)->getEnt()) != ents_ptr->end();
316 const auto coeff_idx = (*it)->getDofCoeffIdx();
319 (*it)->getPetscLocalDofIdx() >= nb_loc_dofs ||
321 coeff_idx < min_coeff_idx || coeff_idx > max_coeff_idx
330 if (true_if_dof_on_entity()) {
331 idx_vec.emplace_back((*it)->getPetscGlobalDofIdx());
337 CHKERR PetscMalloc(idx_vec.size() *
sizeof(
int), &
id);
338 std::copy(idx_vec.begin(), idx_vec.end(),
id);
340 PETSC_OWN_POINTER, is);
346 const std::string problem_name,
RowColData rc,
const std::string field,
348 Range *ents_ptr)
const {
352 max_coeff_idx, &is, ents_ptr);
358 const std::string problem_name,
RowColData rc,
const std::string field,
359 int min_coeff_idx,
int max_coeff_idx, IS *is,
Range *ents_ptr)
const {
366 auto get_low_hi_uid = [&]() {
371 auto get_low_hi_uid_by_entities = [&](
auto f,
auto s) {
376 auto get_low_hi = [&](
auto lo_uid,
auto hi_uid) {
378 DofsByUId::iterator it, hi_it;
395 return std::make_pair(it, hi_it);
398 auto check = [&](
auto it) {
399 const auto coeff_idx = (*it)->getDofCoeffIdx();
402 coeff_idx < min_coeff_idx || coeff_idx > max_coeff_idx
410 auto emplace_indices = [&](
auto it,
auto hi_it,
auto &idx_vec) {
411 for (; it != hi_it; ++it) {
413 idx_vec.emplace_back((*it)->getPetscLocalDofIdx());
417 auto [lo_uid, hi_uid] = get_low_hi_uid();
418 auto [lo, hi] = get_low_hi(lo_uid, hi_uid);
419 std::vector<int> idx_vec;
420 idx_vec.reserve(std::distance(lo, hi));
423 for (
auto pit = ents_ptr->const_pair_begin();
424 pit != ents_ptr->const_pair_end(); ++pit) {
425 auto [lo_uid, hi_uid] =
426 get_low_hi_uid_by_entities(pit->first, pit->second);
427 auto [lo, hi] = get_low_hi(lo_uid, hi_uid);
428 emplace_indices(lo, hi, idx_vec);
431 emplace_indices(lo, hi, idx_vec);
435 CHKERR PetscMalloc(idx_vec.size() *
sizeof(
int), &
id);
436 std::copy(idx_vec.begin(), idx_vec.end(),
id);
437 CHKERR ISCreateGeneral(PETSC_COMM_SELF, idx_vec.size(),
id, PETSC_OWN_POINTER,
444 const std::string problem_name,
RowColData rc,
const std::string field,
446 Range *ents_ptr)
const {
450 min_coeff_idx, max_coeff_idx, &is,
457 const std::string problem_name,
RowColData rc,
const std::string field,
458 EntityType low_type, EntityType hi_type,
int min_coeff_idx,
459 int max_coeff_idx, IS *is,
Range *ents_ptr)
const {
464 for (; low_type <= hi_type; ++low_type)
465 CHKERR m_field.
get_moab().get_entities_by_type(field_meshset, low_type,
468 ents = intersect(ents, *ents_ptr);
470 max_coeff_idx, is, &ents);
475 const std::string x_problem,
const std::string x_field_name,
477 const std::string y_field_name,
RowColData y_rc, std::vector<int> &idx,
478 std::vector<int> &idy)
const {
487 typedef multi_index_container<
488 boost::shared_ptr<NumeredDofEntity>,
495 tag<Composite_Ent_And_EntDofIdx_mi_tag>,
504 NumeredDofEntity_view_multiIndex;
506 NumeredDofEntity_view_multiIndex dofs_view;
529 "only makes sense for ROWS and COLS");
542 "only makes sense for ROWS and COLS");
545 std::map<int, int> global_dofs_map;
552 for (; dit != hi_dit; ++dit) {
553 if ((*dit)->getPart() == rank) {
555 boost::make_tuple((*dit)->getEnt(), (*dit)->getEntDofIdx()));
557 global_dofs_map[(*x_dit)->getPetscGlobalDofIdx()] =
558 (*dit)->getPetscGlobalDofIdx();
563 idx.resize(global_dofs_map.size());
564 idy.resize(global_dofs_map.size());
566 auto ix = idx.begin();
567 auto iy = idy.begin();
568 for (
auto mit = global_dofs_map.begin(); mit != global_dofs_map.end();
578 const std::string x_problem,
const std::string x_field_name,
580 const std::string y_field_name,
RowColData y_rc, IS *ix, IS *iy)
const {
583 std::vector<int> idx(0), idy(0);
585 x_problem, x_field_name, x_rc, y_problem, y_field_name, y_rc, idx, idy);
586 if (ix != PETSC_NULL) {
588 PETSC_COPY_VALUES, ix);
591 PETSC_COPY_VALUES, iy);
593 ISView(*ix, PETSC_VIEWER_STDOUT_WORLD);
594 ISView(*iy, PETSC_VIEWER_STDOUT_WORLD);
600 const std::string x_problem,
RowColData x_rc,
const std::string y_problem,
601 RowColData y_rc, std::vector<int> &idx, std::vector<int> &idy)
const {
608 NumeredDofEntityByLocalIdx::iterator y_dit, hi_y_dit;
638 for (; y_dit != hi_y_dit; y_dit++) {
639 if ((*y_dit)->getPart() != (
unsigned int)m_field.
get_comm_rank()) {
642 NumeredDofEntityByUId::iterator x_dit;
643 x_dit = x_numered_dofs_by_uid->find((*y_dit)->getLocalUniqueId());
644 if (x_dit == x_numered_dofs_by_uid->end())
646 idx.push_back((*x_dit)->getPetscGlobalDofIdx());
647 idy.push_back((*y_dit)->getPetscGlobalDofIdx());
653 const std::string x_problem,
RowColData x_rc,
const std::string y_problem,
657 std::vector<int> idx(0), idy(0);
661 PETSC_COPY_VALUES, ix);
663 PETSC_COPY_VALUES, iy);
665 ISView(*ix, PETSC_VIEWER_STDOUT_WORLD);
666 ISView(*iy, PETSC_VIEWER_STDOUT_WORLD);