v0.16.0
Loading...
Searching...
No Matches
Files | Classes | Functions
Index sets (IS)

Construct index sets for MoFEM problems. More...

Collaboration diagram for Index sets (IS):

Files

file  FieldBlas.hpp
 Field basic algebra.
 
file  ISManager.cpp
 IS creating.
 
file  ISManager.hpp
 Interface managing IS.
 

Classes

struct  MoFEM::ISManager
 Section manager is used to create indexes and sections. More...
 

Functions

MoFEMErrorCode MoFEM::ISManager::sectionCreate (const std::string problem_name, PetscSection *s, const RowColData row_col=COL) const
 Create global selection.
 
SmartPetscObj< PetscSection > MoFEM::ISManager::sectionCreate (const std::string problem_name, const RowColData row_col=COL) const
 Create global selection.
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemOrder (const std::string problem_name, RowColData rc, int min_order, int max_order, IS *is) const
 create IS for given order range (collective)
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndRank (const std::string problem_name, RowColData rc, const std::string field, int min_coeff_idx, int max_coeff_idx, IS *is, Range *ents=nullptr) const
 create IS for given problem, field and rank range (collective)
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndRank (const std::string problem_name, RowColData rc, const std::string field, int min_coeff_idx, int max_coeff_idx, SmartPetscObj< IS > &smart_is, Range *ents=nullptr) const
 IS for given problem, field and rank range (collective)
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemBrokenFieldAndRank (const std::vector< boost::weak_ptr< NumeredDofEntity > > &dofs_vec, SmartPetscObj< IS > &smart_is, MPI_Comm comm=PETSC_COMM_SELF) const
 IS for given problem, field and rank range (collective)
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemBrokenFieldAndRankLocal (const std::vector< boost::weak_ptr< NumeredDofEntity > > &dofs_vec, SmartPetscObj< IS > &smart_is) const
 IS for given problem, field and rank range (collective)
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndRankLocal (const std::string problem_name, RowColData rc, const std::string field, int min_coeff_idx, int max_coeff_idx, IS *is, Range *ents=nullptr) const
 create IS for given problem, field and rank range (collective)
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndRankLocal (const std::string problem_name, RowColData rc, const std::string field, int min_coeff_idx, int max_coeff_idx, SmartPetscObj< IS > &smart_is, Range *ents=nullptr) const
 IS for given problem, field and rank range (collective)
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndEntityType (const std::string problem_name, RowColData rc, const std::string field, EntityType low_type, EntityType hi_type, int min_coeff_idx, int max_coeff_idx, IS *is, Range *ents=nullptr) const
 create IS for given problem, field and type range (collective)
 
MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemFieldToOtherProblemField (const std::string x_problem, const std::string x_field_name, RowColData x_rc, const std::string y_problem, const std::string y_field_name, RowColData y_rc, std::vector< int > &idx, std::vector< int > &idy) const
 create IS for give two problems and field
 
MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemFieldToOtherProblemField (const std::string x_problem, const std::string x_field_name, RowColData x_rc, const std::string y_problem, const std::string y_field_name, RowColData y_rc, IS *ix, IS *iy) const
 create IS for give two problems and field
 
MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemToOtherProblem (const std::string x_problem, RowColData x_rc, const std::string y_problem, RowColData y_rc, std::vector< int > &idx, std::vector< int > &idy) const
 Create is from one problem to other problem.
 
MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemToOtherProblem (const std::string x_problem, RowColData x_rc, const std::string y_problem, RowColData y_rc, IS *ix, IS *iy) const
 Create is from one problem to other problem.
 

Detailed Description

Construct index sets for MoFEM problems.

Function Documentation

◆ isCreateFromProblemFieldToOtherProblemField() [1/2]

MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemFieldToOtherProblemField ( const std::string  x_problem,
const std::string  x_field_name,
RowColData  x_rc,
const std::string  y_problem,
const std::string  y_field_name,
RowColData  y_rc,
IS *  ix,
IS *  iy 
) const

#include <src/interfaces/ISManager.hpp>

create IS for give two problems and field

Indices are sorted by global PETSc index in problem_x.

Parameters
x_problemname of problem
x_field_namename of field in problem_x
x_rcthat is ROW or COL
y_problemname of problem
y_field_namename of field in problem_y
y_rcthat is ROW or COL
Return values
ixIS indexes in problem_x (can be PETSC_NULLPTR)
iyIS indexes in problem_y

Definition at line 623 of file ISManager.cpp.

626 {
628 const MoFEM::Interface &m_field = cOre;
629 std::vector<int> idx(0), idy(0);
631 x_problem, x_field_name, x_rc, y_problem, y_field_name, y_rc, idx, idy);
632 if (ix != PETSC_NULLPTR) {
633 CHKERR ISCreateGeneral(m_field.get_comm(), idx.size(), &idx[0],
634 PETSC_COPY_VALUES, ix);
635 }
636 CHKERR ISCreateGeneral(m_field.get_comm(), idy.size(), &idy[0],
637 PETSC_COPY_VALUES, iy);
638 if (dEbug) {
639 ISView(*ix, PETSC_VIEWER_STDOUT_WORLD);
640 ISView(*iy, PETSC_VIEWER_STDOUT_WORLD);
641 }
643}
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
MoFEMErrorCode isCreateFromProblemFieldToOtherProblemField(const std::string x_problem, const std::string x_field_name, RowColData x_rc, const std::string y_problem, const std::string y_field_name, RowColData y_rc, std::vector< int > &idx, std::vector< int > &idy) const
create IS for give two problems and field
virtual MPI_Comm & get_comm() const =0
Deprecated interface functions.
const MoFEM::Interface & cOre
Definition ISManager.hpp:28

◆ isCreateFromProblemFieldToOtherProblemField() [2/2]

MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemFieldToOtherProblemField ( const std::string  x_problem,
const std::string  x_field_name,
RowColData  x_rc,
const std::string  y_problem,
const std::string  y_field_name,
RowColData  y_rc,
std::vector< int > &  idx,
std::vector< int > &  idy 
) const

#include <src/interfaces/ISManager.hpp>

create IS for give two problems and field

Note that indices are ordered in ascending order of local indices in problem_y

Parameters
x_problemname of problem
x_field_namename of field in problem_x
x_rcthat is ROW or COL
y_problemname of problem
y_field_namename of field in problem_y
y_rcthat is ROW or COL
Return values
idxindexes in problem_x
idyindexes in problem_y

Definition at line 520 of file ISManager.cpp.

524 {
525 const MoFEM::Interface &m_field = cOre;
526 const Problem *px_ptr;
527 const Problem *py_ptr;
529
530 CHKERR m_field.get_problem(x_problem, &px_ptr);
531 CHKERR m_field.get_problem(y_problem, &py_ptr);
532
533 typedef multi_index_container<
534 boost::shared_ptr<NumeredDofEntity>,
535
536 indexed_by<
537
538 sequenced<>,
539
540 ordered_non_unique<
541 tag<Composite_Ent_And_EntDofIdx_mi_tag>,
542 composite_key<
543 NumeredDofEntity,
548
549 >>
550 NumeredDofEntity_view_multiIndex;
551
552 NumeredDofEntity_view_multiIndex dofs_view;
553
554 auto x_bit_number = m_field.get_field_bit_number(x_field_name);
555
556 switch (x_rc) {
557 case ROW:
558 dofs_view.insert(
559 dofs_view.end(),
560 px_ptr->numeredRowDofsPtr->get<Unique_mi_tag>().lower_bound(
561 FieldEntity::getLoBitNumberUId(x_bit_number)),
562 px_ptr->numeredRowDofsPtr->get<Unique_mi_tag>().upper_bound(
563 FieldEntity::getHiBitNumberUId(x_bit_number)));
564 break;
565 case COL:
566 dofs_view.insert(
567 dofs_view.end(),
568 px_ptr->numeredColDofsPtr->get<Unique_mi_tag>().lower_bound(
569 FieldEntity::getLoBitNumberUId(x_bit_number)),
570 px_ptr->numeredColDofsPtr->get<Unique_mi_tag>().upper_bound(
571 FieldEntity::getHiBitNumberUId(x_bit_number)));
572 break;
573 default:
574 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
575 "only makes sense for ROWS and COLS");
576 }
577
578 decltype(py_ptr->numeredRowDofsPtr) dofs_ptr;
579 switch (y_rc) {
580 case ROW:
581 dofs_ptr = py_ptr->numeredRowDofsPtr;
582 break;
583 case COL:
584 dofs_ptr = py_ptr->numeredColDofsPtr;
585 break;
586 default:
587 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
588 "only makes sense for ROWS and COLS");
589 }
590
591 std::map<int, int> global_dofs_map;
592 const auto y_bit_number = m_field.get_field_bit_number(y_field_name);
593 auto dit = dofs_ptr->get<Unique_mi_tag>().lower_bound(
594 FieldEntity::getLoBitNumberUId(y_bit_number));
595 auto hi_dit = dofs_ptr->get<Unique_mi_tag>().upper_bound(
596 FieldEntity::getHiBitNumberUId(y_bit_number));
597 const auto rank = m_field.get_comm_rank();
598 for (; dit != hi_dit; ++dit) {
599 if ((*dit)->getPart() == rank) {
600 auto x_dit = dofs_view.get<Composite_Ent_And_EntDofIdx_mi_tag>().find(
601 boost::make_tuple((*dit)->getEnt(), (*dit)->getEntDofIdx()));
602 if (x_dit != dofs_view.get<Composite_Ent_And_EntDofIdx_mi_tag>().end()) {
603 global_dofs_map[(*x_dit)->getPetscGlobalDofIdx()] =
604 (*dit)->getPetscGlobalDofIdx();
605 }
606 }
607 }
608
609 idx.resize(global_dofs_map.size());
610 idy.resize(global_dofs_map.size());
611 {
612 auto ix = idx.begin();
613 auto iy = idy.begin();
614 for (auto mit = global_dofs_map.begin(); mit != global_dofs_map.end();
615 mit++, ix++, iy++) {
616 *ix = mit->first;
617 *iy = mit->second;
618 }
619 }
621}
@ COL
@ ROW
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
int DofIdx
Index of DOF.
Definition Types.hpp:18
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
virtual int get_comm_rank() const =0
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
static UId getLoBitNumberUId(const FieldBitNumber bit_number)
interface_DofEntity< DofEntity > interface_type_DofEntity

◆ isCreateFromProblemToOtherProblem() [1/2]

MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemToOtherProblem ( const std::string  x_problem,
RowColData  x_rc,
const std::string  y_problem,
RowColData  y_rc,
IS *  ix,
IS *  iy 
) const

#include <src/interfaces/ISManager.hpp>

Create is from one problem to other problem.

Parameters
x_problem
x_rc
y_problem
y_rc
ix
iy
Returns
MoFEMErrorCode

Definition at line 698 of file ISManager.cpp.

700 {
701 const MoFEM::Interface &m_field = cOre;
703 std::vector<int> idx(0), idy(0);
704 CHKERR isCreateFromProblemToOtherProblem(x_problem, x_rc, y_problem, y_rc,
705 idx, idy);
706 CHKERR ISCreateGeneral(m_field.get_comm(), idx.size(), &idx[0],
707 PETSC_COPY_VALUES, ix);
708 CHKERR ISCreateGeneral(m_field.get_comm(), idy.size(), &idy[0],
709 PETSC_COPY_VALUES, iy);
710 if (dEbug) {
711 ISView(*ix, PETSC_VIEWER_STDOUT_WORLD);
712 ISView(*iy, PETSC_VIEWER_STDOUT_WORLD);
713 }
715}
MoFEMErrorCode isCreateFromProblemToOtherProblem(const std::string x_problem, RowColData x_rc, const std::string y_problem, RowColData y_rc, std::vector< int > &idx, std::vector< int > &idy) const
Create is from one problem to other problem.

◆ isCreateFromProblemToOtherProblem() [2/2]

MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemToOtherProblem ( const std::string  x_problem,
RowColData  x_rc,
const std::string  y_problem,
RowColData  y_rc,
std::vector< int > &  idx,
std::vector< int > &  idy 
) const

#include <src/interfaces/ISManager.hpp>

Create is from one problem to other problem.

Parameters
x_problem
x_rc
y_problem
y_rc
idx
idy
Returns
MoFEMErrorCode

Definition at line 645 of file ISManager.cpp.

647 {
648 const MoFEM::Interface &m_field = cOre;
649 const Problem *px_ptr;
650 const Problem *py_ptr;
652 CHKERR m_field.get_problem(x_problem, &px_ptr);
653 CHKERR m_field.get_problem(y_problem, &py_ptr);
654 NumeredDofEntityByLocalIdx::iterator y_dit, hi_y_dit;
655 switch (y_rc) {
656 case ROW:
657 y_dit =
658 py_ptr->numeredRowDofsPtr->get<PetscLocalIdx_mi_tag>().lower_bound(0);
659 hi_y_dit =
660 py_ptr->numeredRowDofsPtr->get<PetscLocalIdx_mi_tag>().lower_bound(
661 py_ptr->getNbLocalDofsRow()); // should be lower
662 break;
663 case COL:
664 y_dit =
665 py_ptr->numeredColDofsPtr->get<PetscLocalIdx_mi_tag>().lower_bound(0);
666 hi_y_dit =
667 py_ptr->numeredColDofsPtr->get<PetscLocalIdx_mi_tag>().lower_bound(
668 py_ptr->getNbLocalDofsCol()); // should be lower
669 break;
670 default:
671 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
672 }
673 const NumeredDofEntityByUId *x_numered_dofs_by_uid;
674 switch (x_rc) {
675 case ROW:
676 x_numered_dofs_by_uid = &(px_ptr->numeredRowDofsPtr->get<Unique_mi_tag>());
677 break;
678 case COL:
679 x_numered_dofs_by_uid = &(px_ptr->numeredColDofsPtr->get<Unique_mi_tag>());
680 break;
681 default:
682 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
683 }
684 for (; y_dit != hi_y_dit; y_dit++) {
685 if ((*y_dit)->getPart() != (unsigned int)m_field.get_comm_rank()) {
686 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "data inconsistency");
687 }
688 NumeredDofEntityByUId::iterator x_dit;
689 x_dit = x_numered_dofs_by_uid->find((*y_dit)->getLocalUniqueId());
690 if (x_dit == x_numered_dofs_by_uid->end())
691 continue;
692 idx.push_back((*x_dit)->getPetscGlobalDofIdx());
693 idy.push_back((*y_dit)->getPetscGlobalDofIdx());
694 }
696}
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
NumeredDofEntity_multiIndex::index< Unique_mi_tag >::type NumeredDofEntityByUId
Numbered DoF multi-index by UId.
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredRowDofsPtr
store DOFs on rows for this problem

◆ isCreateProblemBrokenFieldAndRank()

MoFEMErrorCode MoFEM::ISManager::isCreateProblemBrokenFieldAndRank ( const std::vector< boost::weak_ptr< NumeredDofEntity > > &  dofs_vec,
SmartPetscObj< IS > &  smart_is,
MPI_Comm  comm = PETSC_COMM_SELF 
) const

#include <src/interfaces/ISManager.hpp>

IS for given problem, field and rank range (collective)

Parameters
dofs_vecvector of dofs
smart_isIS
Return values
isout value
isout value

Definition at line 351 of file ISManager.cpp.

353 {
355
356 std::vector<int> idx_vec;
357 idx_vec.reserve(dofs_vec.size());
358 for (auto &dof : dofs_vec) {
359 if (auto d = dof.lock()) {
360 idx_vec.emplace_back(d->getPetscGlobalDofIdx());
361 }
362 }
363
364 IS is_raw;
365 int *id;
366 CHKERR PetscMalloc(idx_vec.size() * sizeof(int), &id);
367 std::copy(idx_vec.begin(), idx_vec.end(), id);
368 CHKERR ISCreateGeneral(comm, idx_vec.size(), id, PETSC_OWN_POINTER, &is_raw);
369
370 smart_is = SmartPetscObj<IS>(is_raw);
371
373}

◆ isCreateProblemBrokenFieldAndRankLocal()

MoFEMErrorCode MoFEM::ISManager::isCreateProblemBrokenFieldAndRankLocal ( const std::vector< boost::weak_ptr< NumeredDofEntity > > &  dofs_vec,
SmartPetscObj< IS > &  smart_is 
) const

#include <src/interfaces/ISManager.hpp>

IS for given problem, field and rank range (collective)

Parameters
dofs_vecvector of dofs
smart_isIS
Return values
isout value
isout value

Definition at line 375 of file ISManager.cpp.

377 {
379
380 std::vector<int> idx_vec;
381 idx_vec.reserve(dofs_vec.size());
382 for (auto &dof : dofs_vec) {
383 if (auto d = dof.lock()) {
384 if (d->getHasLocalIndex()) {
385 idx_vec.emplace_back(d->getPetscLocalDofIdx());
386 }
387 }
388 }
389
390 IS is_raw;
391 int *id;
392 CHKERR PetscMalloc(idx_vec.size() * sizeof(int), &id);
393 std::copy(idx_vec.begin(), idx_vec.end(), id);
394 CHKERR ISCreateGeneral(PETSC_COMM_SELF, idx_vec.size(), id, PETSC_OWN_POINTER,
395 &is_raw);
396
397 smart_is = SmartPetscObj<IS>(is_raw);
398
400}

◆ isCreateProblemFieldAndEntityType()

MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndEntityType ( const std::string  problem_name,
RowColData  rc,
const std::string  field,
EntityType  low_type,
EntityType  hi_type,
int  min_coeff_idx,
int  max_coeff_idx,
IS *  is,
Range ents = nullptr 
) const

#include <src/interfaces/ISManager.hpp>

create IS for given problem, field and type range (collective)

Parameters
problem
rc
field
low_type
hi_type
min_coeff_idx
max_coeff_idx
is
ents
Returns
MoFEMErrorCode

Definition at line 502 of file ISManager.cpp.

505 {
506 const MoFEM::Interface &m_field = cOre;
508 EntityHandle field_meshset = m_field.get_field_meshset(field);
509 Range ents;
510 for (; low_type <= hi_type; ++low_type)
511 CHKERR m_field.get_moab().get_entities_by_type(field_meshset, low_type,
512 ents, true);
513 if (ents_ptr)
514 ents = intersect(ents, *ents_ptr);
515 CHKERR isCreateProblemFieldAndRank(problem_name, rc, field, min_coeff_idx,
516 max_coeff_idx, is, &ents);
518}
MoFEMErrorCode isCreateProblemFieldAndRank(const std::string problem_name, RowColData rc, const std::string field, int min_coeff_idx, int max_coeff_idx, IS *is, Range *ents=nullptr) const
create IS for given problem, field and rank range (collective)
virtual moab::Interface & get_moab()=0
virtual EntityHandle get_field_meshset(const std::string name) const =0
get field meshset

◆ isCreateProblemFieldAndRank() [1/2]

MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndRank ( const std::string  problem_name,
RowColData  rc,
const std::string  field,
int  min_coeff_idx,
int  max_coeff_idx,
IS *  is,
Range ents = nullptr 
) const

#include <src/interfaces/ISManager.hpp>

create IS for given problem, field and rank range (collective)

Parameters
problemname
rcROW or COL
fieldname
min_coeff_idx
max_coeff_idx
entsif not null get dofs only on given entities
Return values
isout value

Definition at line 272 of file ISManager.cpp.

274 {
275 const MoFEM::Interface &m_field = cOre;
276 const Problem *problem_ptr;
278 CHKERR m_field.get_problem(problem_name, &problem_ptr);
279 const auto bit_number = m_field.get_field_bit_number(field);
280
281 using DofsByUId = NumeredDofEntity_multiIndex::index<Unique_mi_tag>::type;
282 DofsByUId::iterator it, hi_it;
283 int nb_loc_dofs;
284 switch (rc) {
285 case ROW:
286 nb_loc_dofs = problem_ptr->getNbLocalDofsRow();
287 it = problem_ptr->numeredRowDofsPtr->get<Unique_mi_tag>().lower_bound(
289 hi_it = problem_ptr->numeredRowDofsPtr->get<Unique_mi_tag>().upper_bound(
291 break;
292 case COL:
293 nb_loc_dofs = problem_ptr->getNbLocalDofsCol();
294 it = problem_ptr->numeredColDofsPtr->get<Unique_mi_tag>().lower_bound(
296 hi_it = problem_ptr->numeredColDofsPtr->get<Unique_mi_tag>().upper_bound(
298 break;
299 default:
300 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
301 }
302
303 std::vector<int> idx_vec;
304 idx_vec.reserve(std::distance(it, hi_it));
305 if (ents_ptr) {
306 const auto &ents = *ents_ptr;
307 for (; it != hi_it; ++it) {
308 const auto &dof = *(*it);
309 if (dof.getHasLocalIndex() && dof.getPetscLocalDofIdx() < nb_loc_dofs) {
310 if (dof.getDofCoeffIdx() >= min_coeff_idx &&
311 dof.getDofCoeffIdx() <= max_coeff_idx) {
312 if (ents.find(dof.getEnt()) != ents.end()) {
313 idx_vec.emplace_back(dof.getPetscGlobalDofIdx());
314 }
315 }
316 }
317 }
318 } else {
319 for (; it != hi_it; ++it) {
320 const auto &dof = *(*it);
321 if (dof.getHasLocalIndex() && dof.getPetscLocalDofIdx() < nb_loc_dofs) {
322 if (dof.getDofCoeffIdx() >= min_coeff_idx &&
323 dof.getDofCoeffIdx() <= max_coeff_idx) {
324 idx_vec.emplace_back(dof.getPetscGlobalDofIdx());
325 }
326 }
327 }
328 }
329
330 int *id;
331 CHKERR PetscMalloc(idx_vec.size() * sizeof(int), &id);
332 std::copy(idx_vec.begin(), idx_vec.end(), id);
333 CHKERR ISCreateGeneral(m_field.get_comm(), idx_vec.size(), id,
334 PETSC_OWN_POINTER, is);
335
337 }

◆ isCreateProblemFieldAndRank() [2/2]

MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndRank ( const std::string  problem_name,
RowColData  rc,
const std::string  field,
int  min_coeff_idx,
int  max_coeff_idx,
SmartPetscObj< IS > &  smart_is,
Range ents = nullptr 
) const

#include <src/interfaces/ISManager.hpp>

IS for given problem, field and rank range (collective)

Parameters
problemname
rcROW or COL
fieldname
min_coeff_idx
max_coeff_idx
entsif not null get dofs only on given entities
Return values
isout value

Definition at line 339 of file ISManager.cpp.

342 {
344 IS is;
345 CHKERR isCreateProblemFieldAndRank(problem_name, rc, field, min_coeff_idx,
346 max_coeff_idx, &is, ents_ptr);
347 smart_is = SmartPetscObj<IS>(is);
349}

◆ isCreateProblemFieldAndRankLocal() [1/2]

MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndRankLocal ( const std::string  problem_name,
RowColData  rc,
const std::string  field,
int  min_coeff_idx,
int  max_coeff_idx,
IS *  is,
Range ents = nullptr 
) const

#include <src/interfaces/ISManager.hpp>

create IS for given problem, field and rank range (collective)

Parameters
problemname
rcROW or COL
fieldname
min_coeff_idx
max_coeff_idx
entsif not null get dofs only on given entities
Return values
isout value

Definition at line 402 of file ISManager.cpp.

404 {
405 const MoFEM::Interface &m_field = cOre;
406 const Problem *problem_ptr;
408 CHKERR m_field.get_problem(problem_name, &problem_ptr);
409 const auto bit_number = m_field.get_field_bit_number(field);
410
411 auto get_low_hi_uid = [&]() {
412 return std::make_pair(FieldEntity::getLoBitNumberUId(bit_number),
414 };
415
416 auto get_low_hi_uid_by_entities = [&](auto f, auto s) {
417 return std::make_pair(DofEntity::getLoFieldEntityUId(bit_number, f),
418 DofEntity::getHiFieldEntityUId(bit_number, s));
419 };
420
421 auto get_low_hi = [&](auto lo_uid, auto hi_uid) {
422 using DofsByUId = NumeredDofEntity_multiIndex::index<Unique_mi_tag>::type;
423 DofsByUId::iterator it, hi_it;
424 switch (rc) {
425 case ROW:
426 it = problem_ptr->numeredRowDofsPtr->get<Unique_mi_tag>().lower_bound(
427 lo_uid);
428 hi_it = problem_ptr->numeredRowDofsPtr->get<Unique_mi_tag>().upper_bound(
429 hi_uid);
430 break;
431 case COL:
432 it = problem_ptr->numeredColDofsPtr->get<Unique_mi_tag>().lower_bound(
433 lo_uid);
434 hi_it = problem_ptr->numeredColDofsPtr->get<Unique_mi_tag>().upper_bound(
435 hi_uid);
436 break;
437 default:
438 THROW_MESSAGE("not implemented");
439 }
440 return std::make_pair(it, hi_it);
441 };
442
443 auto check = [&](auto it) {
444 const auto coeff_idx = (*it)->getDofCoeffIdx();
445 if (
446
447 coeff_idx < min_coeff_idx || coeff_idx > max_coeff_idx
448
449 ) {
450 return false;
451 } else {
452 return true;
453 }
454 };
455
456 auto emplace_indices = [&](auto it, auto hi_it, auto &idx_vec) {
457 for (; it != hi_it; ++it) {
458 if ((*it)->getHasLocalIndex() && check(it))
459 idx_vec.emplace_back((*it)->getPetscLocalDofIdx());
460 }
461 };
462
463 auto [lo_uid, hi_uid] = get_low_hi_uid();
464 auto [lo, hi] = get_low_hi(lo_uid, hi_uid);
465 std::vector<int> idx_vec;
466 idx_vec.reserve(std::distance(lo, hi));
467
468 if (ents_ptr) {
469 for (auto pit = ents_ptr->const_pair_begin();
470 pit != ents_ptr->const_pair_end(); ++pit) {
471 auto [lo_uid, hi_uid] =
472 get_low_hi_uid_by_entities(pit->first, pit->second);
473 auto [lo, hi] = get_low_hi(lo_uid, hi_uid);
474 emplace_indices(lo, hi, idx_vec);
475 }
476 } else {
477 emplace_indices(lo, hi, idx_vec);
478 }
479
480 int *id;
481 CHKERR PetscMalloc(idx_vec.size() * sizeof(int), &id);
482 std::copy(idx_vec.begin(), idx_vec.end(), id);
483 CHKERR ISCreateGeneral(PETSC_COMM_SELF, idx_vec.size(), id, PETSC_OWN_POINTER,
484 is);
485
487}
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
static UId getLoFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
static UId getHiFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)

◆ isCreateProblemFieldAndRankLocal() [2/2]

MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndRankLocal ( const std::string  problem_name,
RowColData  rc,
const std::string  field,
int  min_coeff_idx,
int  max_coeff_idx,
SmartPetscObj< IS > &  smart_is,
Range ents = nullptr 
) const

#include <src/interfaces/ISManager.hpp>

IS for given problem, field and rank range (collective)

Parameters
problemname
rcROW or COL
fieldname
min_coeff_idx
max_coeff_idx
entsif not null get dofs only on given entities
Return values
isout value

Definition at line 489 of file ISManager.cpp.

492 {
494 IS is;
495 CHKERR isCreateProblemFieldAndRankLocal(problem_name, rc, field,
496 min_coeff_idx, max_coeff_idx, &is,
497 ents_ptr);
498 smart_is = SmartPetscObj<IS>(is);
500}
MoFEMErrorCode isCreateProblemFieldAndRankLocal(const std::string problem_name, RowColData rc, const std::string field, int min_coeff_idx, int max_coeff_idx, IS *is, Range *ents=nullptr) const
create IS for given problem, field and rank range (collective)

◆ isCreateProblemOrder()

MoFEMErrorCode MoFEM::ISManager::isCreateProblemOrder ( const std::string  problem_name,
RowColData  rc,
int  min_order,
int  max_order,
IS *  is 
) const

#include <src/interfaces/ISManager.hpp>

create IS for given order range (collective)

Parameters
problemname
rcROW or COL
min_order
max_order
Return values
isout value

Definition at line 204 of file ISManager.cpp.

206 {
207 const MoFEM::Interface &m_field = cOre;
208 const Problem *problem_ptr;
210 CHKERR m_field.get_problem(problem_name, &problem_ptr);
211
212 typedef multi_index_container<
213 boost::shared_ptr<NumeredDofEntity>,
214
215 indexed_by<
216
217 sequenced<>,
218
219 ordered_non_unique<
220 tag<Order_mi_tag>,
223
224 >>
225 NumeredDofEntity_order_view_multiIndex;
226
227 const int rank = m_field.get_comm_rank();
228
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));
233 };
234
235 switch (rc) {
236 case ROW:
237 insert_part_range(problem_ptr->numeredRowDofsPtr->get<Part_mi_tag>());
238 break;
239 case COL:
240 insert_part_range(problem_ptr->numeredColDofsPtr->get<Part_mi_tag>());
241 break;
242 default:
243 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
244 }
245
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);
249 int *id;
250 CHKERR PetscMalloc(size * sizeof(int), &id);
251 int *id_it = id;
252 for (; lo != hi; ++lo, ++id_it)
253 *id_it = (*lo)->getPetscGlobalDofIdx();
254 sort(id, &id[size]);
255
256 CHKERR ISCreateGeneral(PETSC_COMM_WORLD, size, id, PETSC_OWN_POINTER, is);
257
259}
int ApproximationOrder
Approximation on the entity.
Definition Types.hpp:26

◆ sectionCreate() [1/2]

SmartPetscObj< PetscSection > MoFEM::ISManager::sectionCreate ( const std::string  problem_name,
const RowColData  row_col = COL 
) const

#include <src/interfaces/ISManager.hpp>

Create global selection.

Create section for given problem, such that points are sorted by UId, and number of dofs on point is equal to number of dofs on entity

It takes all fields

Parameters
problem_name
fields_list
s
row_colROW or COL, default is COL
Returns
error code

Definition at line 140 of file ISManager.cpp.

141 {
142
143 PetscSection s;
144 CHK_THROW_MESSAGE(sectionCreate(problem_name, &s, row_col),
145 "Section not created");
146 return SmartPetscObj<PetscSection>(s, false);
147}
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
MoFEMErrorCode sectionCreate(const std::string problem_name, PetscSection *s, const RowColData row_col=COL) const
Create global selection.
Definition ISManager.cpp:20

◆ sectionCreate() [2/2]

MoFEMErrorCode MoFEM::ISManager::sectionCreate ( const std::string  problem_name,
PetscSection *  s,
const RowColData  row_col = COL 
) const

#include <src/interfaces/ISManager.hpp>

Create global selection.

Create section for given problem, such that points are sorted by UId, and number of dofs on point is equal to number of dofs on entity

It takes all fields

Parameters
problem_name
fields_list
s
row_colROW or COL, default is COL
Returns
error code

Definition at line 20 of file ISManager.cpp.

22 {
23 const MoFEM::Interface &m_field = cOre;
24 const Problem *problem_ptr = m_field.get_problem(problem_name);
25 auto fields_ptr = m_field.get_fields();
26 auto fe_ptr = m_field.get_finite_elements();
28 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
29 BitFieldId fields_ids(0);
30 switch (row_col) {
31 case ROW:
32 dofs = problem_ptr->numeredRowDofsPtr;
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();
36 }
37 }
38 break;
39 case COL:
40 dofs = problem_ptr->numeredColDofsPtr;
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();
44 }
45 }
46 break;
47 default:
48 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
49 "Has to be ROW or COLUMN");
50 }
51 // get fields names on the problem
52 map<std::string, std::pair<int, int>> fields_map;
53 {
54 int field = 0;
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();
59 }
60 }
61 }
62 const int proc = m_field.get_comm_rank();
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,
68 mit->second.second);
69 }
70 // determine number of points
71 int nb_charts = 0;
72 {
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) {
79 ++dit;
80 }
81 ++nb_charts;
82 } else {
83 ++dit;
84 }
85 }
86 }
87 // get layout, i.e. chart
88 PetscLayout layout;
89 CHKERR PetscLayoutCreate(PETSC_COMM_WORLD, &layout);
90 CHKERR PetscLayoutSetBlockSize(layout, 1);
91 CHKERR PetscLayoutSetLocalSize(layout, nb_charts);
92 CHKERR PetscLayoutSetUp(layout);
93 int rstart, rend;
94 CHKERR PetscLayoutGetRange(layout, &rstart, &rend);
95 CHKERR PetscLayoutDestroy(&layout);
96 CHKERR PetscSectionSetChart(*s, rstart, rend);
97
98 // loop of all dofs
99 {
100 auto dit = dofs->begin();
101 auto hi_dit = dofs->end();
102 int point = rstart;
103 for (; dit != hi_dit;) {
104 if (static_cast<int>(dit->get()->getPart()) == proc) {
105
106 const auto &field_name = dit->get()->getName();
107
108 int dd = 0;
109 const auto &ent_uid = dit->get()->getEntLocalUniqueId();
110 while (dit != hi_dit && dit->get()->getEntLocalUniqueId() == ent_uid) {
111 if (dit->get()->getHasLocalIndex()) {
112 ++dd;
113 }
114 ++dit;
115 }
116
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());
120 } else {
121 CHKERR PetscSectionAddDof(*s, point, dd);
122 int field = fields_map.at(field_name).first;
123 CHKERR PetscSectionSetFieldDof(*s, point, field, dd);
124 }
125
126 ++point;
127
128 } else {
129 ++dit;
130 }
131 }
132 }
133 // cerr << "done " << proc << endl;
134 CHKERR PetscSectionSetUp(*s);
135 // cerr << "end " << proc << endl;
137}
#define MOFEM_LOG_C(channel, severity, format,...)
virtual const FiniteElement_multiIndex * get_finite_elements() const =0
Get the finite elements object.
virtual const Field_multiIndex * get_fields() const =0
Get the fields object.
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
std::bitset< BITFIELDID_SIZE > BitFieldId
Field Id.
Definition Types.hpp:42
constexpr auto field_name