v0.16.3
Loading...
Searching...
No Matches
Files | Classes | Functions
ProblemsManager

Adding and managing problems. More...

Collaboration diagram for ProblemsManager:

Files

file  ProblemsManager.cpp
 Managing complexities for problem.
 
file  ProblemsManager.hpp
 Interface for building, partitioning, and managing finite element problems.
 

Classes

struct  MoFEM::ProblemsManager
 Problem manager is used to build and partition problems. More...
 

Functions

MoFEMErrorCode MoFEM::ProblemsManager::getOptions ()
 Get command line options for ProblemsManager.
 
DEPRECATED MoFEMErrorCode MoFEM::ProblemsManager::partitionMesh (const Range &ents, const int dim, const int adj_dim, const int n_parts, Tag *th_vertex_weights=nullptr, Tag *th_edge_weights=nullptr, Tag *th_part_weights=nullptr, int verb=VERBOSE, const bool debug=false)
 Set partition tag to each finite element in the problem.
 
MoFEMErrorCode MoFEM::ProblemsManager::buildProblem (const std::string name, const bool square_matrix, int verb=VERBOSE)
 build problem data structures
 
MoFEMErrorCode MoFEM::ProblemsManager::buildProblem (Problem *problem_ptr, const bool square_matrix, int verb=VERBOSE)
 build problem data structures
 
MoFEMErrorCode MoFEM::ProblemsManager::buildProblemOnDistributedMesh (const std::string name, const bool square_matrix, int verb=VERBOSE)
 build problem data structures, assuming that mesh is distributed (collective)
 
MoFEMErrorCode MoFEM::ProblemsManager::buildProblemOnDistributedMesh (Problem *problem_ptr, const bool square_matrix=true, int verb=VERBOSE)
 build problem data structures, assuming that mesh is distributed (collective)
 
MoFEMErrorCode MoFEM::ProblemsManager::rebuildProblemOnDistributedMesh (const std::string &name, const BitRefLevel target_bit, const BitRefLevel target_mask, const bool square_matrix, int verb=VERBOSE, SmartPetscObj< IS > *old_row_indices=nullptr, SmartPetscObj< IS > *new_row_indices=nullptr)
 Rebuild a parent problem in place on a distributed mesh (collective)
 
MoFEMErrorCode MoFEM::ProblemsManager::buildSubProblem (const std::string out_name, const std::vector< std::string > &fields_row, const std::vector< std::string > &fields_col, const std::string main_problem, const bool square_matrix=true, const map< std::string, boost::shared_ptr< Range > > *entityMapRow=nullptr, const map< std::string, boost::shared_ptr< Range > > *entityMapCol=nullptr, int verb=VERBOSE)
 build sub problem
 
MoFEMErrorCode MoFEM::ProblemsManager::buildComposedProblem (const std::string out_name, const std::vector< std::string > add_row_problems, const std::vector< std::string > add_col_problems, const bool square_matrix=true, int verb=1)
 build composite problem
 
MoFEMErrorCode MoFEM::ProblemsManager::inheritPartition (const std::string name, const std::string problem_for_rows, bool copy_rows, const std::string problem_for_cols, bool copy_cols, int verb=VERBOSE)
 build indexing and partition problem inheriting indexing and partitioning from two other problems
 
MoFEMErrorCode MoFEM::ProblemsManager::partitionSimpleProblem (const std::string name, int verb=VERBOSE)
 partition problem dofs
 
MoFEMErrorCode MoFEM::ProblemsManager::partitionProblem (const std::string name, int verb=VERBOSE)
 partition problem dofs (collective)
 
MoFEMErrorCode MoFEM::ProblemsManager::printPartitionedProblem (const Problem *problem_ptr, int verb=VERBOSE)
 Print partition information for debugging.
 
MoFEMErrorCode MoFEM::ProblemsManager::debugPartitionedProblem (const Problem *problem_ptr, int verb=VERBOSE)
 Debug partition information.
 
MoFEMErrorCode MoFEM::ProblemsManager::partitionFiniteElements (const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
 partition finite elements
 
MoFEMErrorCode MoFEM::ProblemsManager::partitionGhostDofs (const std::string name, int verb=VERBOSE)
 determine ghost nodes
 
MoFEMErrorCode MoFEM::ProblemsManager::partitionGhostDofsOnDistributedMesh (const std::string name, int verb=VERBOSE)
 determine ghost nodes on distributed meshes
 
MoFEMErrorCode MoFEM::ProblemsManager::getFEMeshset (const std::string prb_name, const std::string &fe_name, EntityHandle *meshset) const
 Create finite element meshset for the problem.
 
MoFEMErrorCode MoFEM::ProblemsManager::getProblemElementsLayout (const std::string name, const std::string &fe_name, PetscLayout *layout) const
 Get layout of elements in the problem.
 
MoFEMErrorCode MoFEM::ProblemsManager::removeDofsOnEntities (const std::string problem_name, const std::string field_name, const Range ents, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false)
 Remove DOFs from problem.
 
MoFEMErrorCode MoFEM::ProblemsManager::removeDofsOnEntities (const std::string problem_name, const std::string field_name, const BitRefLevel bit_ref_level, const BitRefLevel bit_ref_mask, Range *ents_ptr=nullptr, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false)
 Remove DOFs from problem by bit ref level.
 
MoFEMErrorCode MoFEM::ProblemsManager::removeDofs (const std::string problem_name, RowColData rc, std::vector< boost::weak_ptr< NumeredDofEntity > > &vec_dof_view, int verb=VERBOSE, const bool debug=false)
 Remove DOFs from problem on broken space.
 
MoFEMErrorCode MoFEM::ProblemsManager::getSideDofsOnBrokenSpaceEntities (std::vector< boost::weak_ptr< NumeredDofEntity > > &vec_dof_view, const std::string problem_name, RowColData rc, const std::string field_name, const Range ents, int bridge_dim, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false) const
 Get DOFs on side entities for broken space.
 
MoFEMErrorCode MoFEM::ProblemsManager::modifyMarkDofs (const std::string problem_name, RowColData rc, const std::string field_name, const int lo, const int hi, const enum MarkOP op, const unsigned char c, std::vector< unsigned char > &marker) const
 Modify DOF markers for specific field and coefficient range.
 
MoFEMErrorCode MoFEM::ProblemsManager::markDofs (const std::string problem_name, RowColData rc, std::vector< boost::weak_ptr< NumeredDofEntity > > &vec_dof_view, const enum MarkOP op, std::vector< unsigned char > &marker) const
 Create vector with marked DOF indices based on DOF view.
 
MoFEMErrorCode MoFEM::ProblemsManager::addFieldToEmptyFieldBlocks (const std::string problem_name, const std::string row_field, const std::string col_field) const
 Add empty field blocks to optimize matrix storage.
 

Read, load and broadcast

@

MoFEMErrorCode MoFEM::CommInterface::partitionMesh (const Range &ents, const int dim, const int adj_dim, const int n_parts, Tag *th_vertex_weights=nullptr, Tag *th_edge_weights=nullptr, Tag *th_part_weights=nullptr, int verb=VERBOSE, const bool debug=false, const bool preserve_vertex_ids=false)
 Set partition tag to each finite element in the problem.
 

Detailed Description

Adding and managing problems.

Function Documentation

◆ addFieldToEmptyFieldBlocks()

MoFEMErrorCode MoFEM::ProblemsManager::addFieldToEmptyFieldBlocks ( const std::string  problem_name,
const std::string  row_field,
const std::string  col_field 
) const

#include <src/interfaces/ProblemsManager.hpp>

Add empty field blocks to optimize matrix storage.

Marks field combinations as empty blocks in the matrix structure to optimize memory usage and computational efficiency. The MatrixManager assumes all field combinations result in non-zero blocks, but this allows specification of blocks that will remain zero for the entire problem duration.

Parameters
problem_namename of the problem to modify
row_fieldname of the field for matrix row blocks
col_fieldname of the field for matrix column blocks
Returns
MoFEMErrorCode Error code indicating success or failure

Definition at line 3932 of file ProblemsManager.cpp.

3934 {
3935
3936 Interface &m_field = cOre;
3938
3939 const auto problem_ptr = m_field.get_problem(problem_name);
3940 auto get_field_id = [&](const std::string field_name) {
3941 return m_field.get_field_structure(field_name)->getId();
3942 };
3943 const auto row_id = get_field_id(row_field);
3944 const auto col_id = get_field_id(col_field);
3945
3946 problem_ptr->addFieldToEmptyFieldBlocks(BlockFieldPair(row_id, col_id));
3947
3949}
#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()
Problem::BlockFieldPair BlockFieldPair
DeprecatedCoreInterface Interface
constexpr auto field_name
MoFEMErrorCode get_problem(const std::string &problem_name, const Problem **problem_ptr) const
Get problem database (data structure)
Definition Core.cpp:843

◆ buildComposedProblem()

MoFEMErrorCode MoFEM::ProblemsManager::buildComposedProblem ( const std::string  out_name,
const std::vector< std::string >  add_row_problems,
const std::vector< std::string >  add_col_problems,
const bool  square_matrix = true,
int  verb = 1 
)

#include <src/interfaces/ProblemsManager.hpp>

build composite problem

Creates a composite problem by combining multiple existing problems. The resulting problem contains DOFs from all constituent problems, arranged in block matrix structure.

Parameters
out_namename of the composite problem to create
add_row_problemsvector of problem names contributing to rows
add_col_problemsvector of problem names contributing to columns
square_matrixtrue if the composite matrix is structurally symmetric
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure
Examples
mofem/atom_tests/build_problems.cpp.

Definition at line 1443 of file ProblemsManager.cpp.

1446 {
1448 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
1450 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
1452 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
1453 MoFEM::Interface &m_field = cOre;
1454 auto problems_ptr = m_field.get_problems();
1456
1457 CHKERR m_field.clear_problem(out_name);
1458 // get reference to all problems
1459 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemByName;
1460 ProblemByName &problems_by_name =
1461 const_cast<ProblemByName &>(problems_ptr->get<Problem_mi_tag>());
1462
1463 // Get iterators to out problem, i.e. build problem
1464 ProblemByName::iterator out_problem_it = problems_by_name.find(out_name);
1465 if (out_problem_it == problems_by_name.end()) {
1466 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1467 "problem with name < %s > not defined (top tip check spelling)",
1468 out_name.c_str());
1469 }
1470 // Make data structure for composed-problem data
1471 out_problem_it->composedProblemsData =
1472 boost::make_shared<ComposedProblemsData>();
1473 boost::shared_ptr<ComposedProblemsData> cmp_prb_data =
1474 out_problem_it->getComposedProblemsData();
1475
1476 const std::vector<std::string> *add_prb[] = {&add_row_problems,
1477 &add_col_problems};
1478 std::vector<const Problem *> *add_prb_ptr[] = {&cmp_prb_data->rowProblemsAdd,
1479 &cmp_prb_data->colProblemsAdd};
1480 std::vector<SmartPetscObj<IS>> *add_prb_is[] = {&cmp_prb_data->rowIs,
1481 &cmp_prb_data->colIs};
1482
1483 // Get local indices counter
1484 int *nb_local_dofs[] = {&out_problem_it->nbLocDofsRow,
1485 &out_problem_it->nbLocDofsCol};
1486 // Get global indices counter
1487 int *nb_dofs[] = {&out_problem_it->nbDofsRow, &out_problem_it->nbDofsCol};
1488
1489 // Set number of ghost nodes to zero
1490 {
1491 out_problem_it->nbDofsRow = 0;
1492 out_problem_it->nbDofsCol = 0;
1493 out_problem_it->nbLocDofsRow = 0;
1494 out_problem_it->nbLocDofsCol = 0;
1495 out_problem_it->nbGhostDofsRow = 0;
1496 out_problem_it->nbGhostDofsCol = 0;
1497 }
1498 int nb_dofs_reserve[] = {0, 0};
1499
1500 // Loop over rows and columns in the main problem and sub-problems
1501 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ss++) {
1502 add_prb_ptr[ss]->reserve(add_prb[ss]->size());
1503 add_prb_is[ss]->reserve(add_prb[ss]->size());
1504 for (std::vector<std::string>::const_iterator vit = add_prb[ss]->begin();
1505 vit != add_prb[ss]->end(); vit++) {
1506 ProblemByName::iterator prb_it = problems_by_name.find(*vit);
1507 if (prb_it == problems_by_name.end()) {
1508 SETERRQ(
1509 PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1510 "problem with name < %s > not defined (top tip check spelling)",
1511 vit->c_str());
1512 }
1513 add_prb_ptr[ss]->push_back(&*prb_it);
1514 // set number of dofs on rows and columns
1515 if (ss == 0) {
1516 // row
1517 *nb_dofs[ss] += add_prb_ptr[ss]->back()->getNbDofsRow();
1518 *nb_local_dofs[ss] += add_prb_ptr[ss]->back()->getNbLocalDofsRow();
1519 nb_dofs_reserve[ss] +=
1520 add_prb_ptr[ss]->back()->numeredRowDofsPtr->size();
1521 } else {
1522 // column
1523 *nb_dofs[ss] += add_prb_ptr[ss]->back()->getNbDofsCol();
1524 *nb_local_dofs[ss] += add_prb_ptr[ss]->back()->getNbLocalDofsCol();
1525 nb_dofs_reserve[ss] +=
1526 add_prb_ptr[ss]->back()->numeredColDofsPtr->size();
1527 }
1528 }
1529 }
1530 // if squre problem, rows and columns are the same
1531 if (square_matrix) {
1532 add_prb_ptr[1]->reserve(add_prb_ptr[0]->size());
1533 add_prb_is[1]->reserve(add_prb_ptr[0]->size());
1534 out_problem_it->numeredColDofsPtr = out_problem_it->numeredRowDofsPtr;
1535 *nb_dofs[1] = *nb_dofs[0];
1536 *nb_local_dofs[1] = *nb_local_dofs[0];
1537 }
1538
1539 // reserve memory for dofs
1540 boost::shared_ptr<std::vector<NumeredDofEntity>> dofs_array[2];
1541 // Reserve memory
1542 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ss++) {
1543 dofs_array[ss] = boost::make_shared<std::vector<NumeredDofEntity>>();
1544 dofs_array[ss]->reserve(nb_dofs_reserve[ss]);
1545 if (!ss)
1546 out_problem_it->getRowDofsSequence()->emplace_back(dofs_array[ss]);
1547 else
1548 out_problem_it->getColDofsSequence()->emplace_back(dofs_array[ss]);
1549 }
1550
1551 // Push back DOFs
1552 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ss++) {
1553 NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type::iterator
1554 dit,
1555 hi_dit;
1556 int shift_glob = 0;
1557 int shift_loc = 0;
1558 for (unsigned int pp = 0; pp != add_prb_ptr[ss]->size(); pp++) {
1559 PetscInt *dofs_out_idx_ptr;
1560 int nb_local_dofs = (*add_prb_ptr[ss])[pp]->getNbLocalDofsRow();
1561 CHKERR PetscMalloc(nb_local_dofs * sizeof(int), &dofs_out_idx_ptr);
1562 if (ss == 0) {
1563 dit = (*add_prb_ptr[ss])[pp]
1564 ->numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>()
1565 .begin();
1566 hi_dit = (*add_prb_ptr[ss])[pp]
1567 ->numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>()
1568 .end();
1569 } else {
1570 dit = (*add_prb_ptr[ss])[pp]
1571 ->numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>()
1572 .begin();
1573 hi_dit = (*add_prb_ptr[ss])[pp]
1574 ->numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>()
1575 .end();
1576 }
1577 int is_nb = 0;
1578 for (; dit != hi_dit; dit++) {
1579 const BitRefLevel &prb_bit = out_problem_it->getBitRefLevel();
1580 const BitRefLevel &prb_mask = out_problem_it->getBitRefLevelMask();
1581 const BitRefLevel &dof_bit = dit->get()->getBitRefLevel();
1582 if ((dof_bit & prb_bit).none() || ((dof_bit & prb_mask) != dof_bit))
1583 continue;
1584 const int rank = m_field.get_comm_rank();
1585 const int part = dit->get()->getPart();
1586 const int glob_idx = shift_glob + dit->get()->getPetscGlobalDofIdx();
1587 const int loc_idx =
1588 (part == rank) ? (shift_loc + dit->get()->getPetscLocalDofIdx())
1589 : -1;
1590 dofs_array[ss]->emplace_back(dit->get()->getDofEntityPtr(), glob_idx,
1591 loc_idx, part);
1592 if (part == rank) {
1593 dofs_out_idx_ptr[is_nb++] = glob_idx;
1594 }
1595 }
1596 if (is_nb > nb_local_dofs) {
1597 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
1598 "Data inconsistency");
1599 }
1600 IS is;
1601 CHKERR ISCreateGeneral(m_field.get_comm(), is_nb, dofs_out_idx_ptr,
1602 PETSC_OWN_POINTER, &is);
1603 auto smart_is = SmartPetscObj<IS>(is);
1604 (*add_prb_is[ss]).push_back(smart_is);
1605 if (ss == 0) {
1606 shift_glob += (*add_prb_ptr[ss])[pp]->getNbDofsRow();
1607 shift_loc += (*add_prb_ptr[ss])[pp]->getNbLocalDofsRow();
1608 } else {
1609 shift_glob += (*add_prb_ptr[ss])[pp]->getNbDofsCol();
1610 shift_loc += (*add_prb_ptr[ss])[pp]->getNbLocalDofsCol();
1611 }
1612 if (square_matrix) {
1613 (*add_prb_ptr[1]).push_back((*add_prb_ptr[0])[pp]);
1614 (*add_prb_is[1]).push_back(smart_is);
1615 }
1616 }
1617 }
1618
1619 if ((*add_prb_is[1]).size() != (*add_prb_is[0]).size()) {
1620 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY, "Data inconsistency");
1621 }
1622
1623 // Insert DOFs to problem multi-index
1624 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ss++) {
1625 auto &dofs = ss == 0 ? *out_problem_it->numeredRowDofsPtr
1626 : *out_problem_it->numeredColDofsPtr;
1627 publish_numbered_dofs(dofs, dofs_array[ss]);
1628 }
1629
1630 // Compress DOFs
1631 *nb_dofs[0] = 0;
1632 *nb_dofs[1] = 0;
1633 *nb_local_dofs[0] = 0;
1634 *nb_local_dofs[1] = 0;
1635 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ss++) {
1636
1637 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs_ptr;
1638 if (ss == 0) {
1639 dofs_ptr = out_problem_it->numeredRowDofsPtr;
1640 } else {
1641 dofs_ptr = out_problem_it->numeredColDofsPtr;
1642 }
1643 NumeredDofEntityByUId::iterator dit, hi_dit;
1644 dit = dofs_ptr->get<Unique_mi_tag>().begin();
1645 hi_dit = dofs_ptr->get<Unique_mi_tag>().end();
1646 std::vector<int> idx;
1647 idx.reserve(std::distance(dit, hi_dit));
1648 // set dofs in order entity and dof number on entity
1649 for (; dit != hi_dit; dit++) {
1650 if (dit->get()->getPart() == (unsigned int)m_field.get_comm_rank()) {
1651 bool success = dofs_ptr->get<Unique_mi_tag>().modify(
1652 dit, NumeredDofEntity_local_idx_change((*nb_local_dofs[ss])++));
1653 if (!success) {
1654 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
1655 "modification unsuccessful");
1656 }
1657 idx.push_back(dit->get()->getPetscGlobalDofIdx());
1658 } else {
1659 if (dit->get()->getPetscLocalDofIdx() != -1) {
1660 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
1661 "local index should be negative");
1662 }
1663 }
1664 }
1665 if (square_matrix) {
1666 *nb_local_dofs[1] = *nb_local_dofs[0];
1667 }
1668
1669 // set new dofs mapping
1670 IS is;
1671 CHKERR ISCreateGeneral(m_field.get_comm(), idx.size(), &*idx.begin(),
1672 PETSC_USE_POINTER, &is);
1673 CHKERR ISGetSize(is, nb_dofs[ss]);
1674 if (square_matrix) {
1675 *nb_dofs[1] = *nb_dofs[0];
1676 }
1677
1678 AO ao;
1679 CHKERR AOCreateMappingIS(is, PETSC_NULLPTR, &ao);
1680 for (unsigned int pp = 0; pp != (*add_prb_is[ss]).size(); pp++)
1681 CHKERR AOApplicationToPetscIS(ao, (*add_prb_is[ss])[pp]);
1682
1683 // Set DOFs numeration
1684 {
1685 std::vector<int> idx_new;
1686 idx_new.reserve(dofs_ptr->size());
1687 for (NumeredDofEntityByUId::iterator dit =
1688 dofs_ptr->get<Unique_mi_tag>().begin();
1689 dit != dofs_ptr->get<Unique_mi_tag>().end(); dit++) {
1690 idx_new.push_back(dit->get()->getPetscGlobalDofIdx());
1691 }
1692 // set new global dofs numeration
1693 IS is_new;
1694 CHKERR ISCreateGeneral(m_field.get_comm(), idx_new.size(),
1695 &*idx_new.begin(), PETSC_USE_POINTER, &is_new);
1696 CHKERR AOApplicationToPetscIS(ao, is_new);
1697 // set global indices to multi-index
1698 std::vector<int>::iterator vit = idx_new.begin();
1699 for (NumeredDofEntityByUId::iterator dit =
1700 dofs_ptr->get<Unique_mi_tag>().begin();
1701 dit != dofs_ptr->get<Unique_mi_tag>().end(); dit++) {
1702 bool success =
1703 dofs_ptr->modify(dit, NumeredDofEntity_part_and_glob_idx_change(
1704 dit->get()->getPart(), *(vit++)));
1705 if (!success) {
1706 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
1707 "modification unsuccessful");
1708 }
1709 }
1710 CHKERR ISDestroy(&is_new);
1711 }
1712 CHKERR ISDestroy(&is);
1713 CHKERR AODestroy(&ao);
1714 }
1715
1716 CHKERR printPartitionedProblem(&*out_problem_it, verb);
1717 CHKERR debugPartitionedProblem(&*out_problem_it, verb);
1718
1719 // Inidcate that porble has been build
1722
1724}
std::vector< int > size
#define ProblemManagerFunctionBegin
It end
Definition Schur.cpp:2568
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define CHKERR
Inline error check.
virtual const Problem_multiIndex * get_problems() const =0
Get the problems object.
MoFEMErrorCode printPartitionedProblem(const Problem *problem_ptr, int verb=VERBOSE)
Print partition information for debugging.
MoFEMErrorCode debugPartitionedProblem(const Problem *problem_ptr, int verb=VERBOSE)
Debug partition information.
virtual MoFEMErrorCode clear_problem(const std::string name, int verb=DEFAULT_VERBOSITY)=0
clear problem
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
static void publish_numbered_dofs(NumeredDofEntity_multiIndex &dofs, const boost::shared_ptr< std::vector< NumeredDofEntity > > &sequence_ptr, const bool serial_uid_numbering=false)
Publish stable records using hints shared by all five ordered indices.
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
int & getBuildMoFEM() const
Get flags/semaphores for different stages.
Definition Core.hpp:230
Deprecated interface functions.

◆ buildProblem() [1/2]

MoFEMErrorCode MoFEM::ProblemsManager::buildProblem ( const std::string  name,
const bool  square_matrix,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

build problem data structures

Note
If square_matrix is set to true, that indicate that problem is structurally symmetric, i.e. rows and columns have the same dofs and are indexed in the same way.
Parameters
nameproblem name
square_matrixstructurally symmetric problem
verbverbosity level
Returns
error code
Examples
mofem/atom_tests/build_problems.cpp, mofem/atom_tests/continuity_check_on_contact_prism_side_ele.cpp, mofem/atom_tests/continuity_check_on_skeleton_3d.cpp, mofem/atom_tests/field_values_from_tags.cpp, mofem/atom_tests/forces_and_sources_testing_edge_element.cpp, mofem/atom_tests/forces_and_sources_testing_flat_prism_element.cpp, mofem/atom_tests/hcurl_divergence_operator_2d.cpp, mofem/atom_tests/mesh_insert_interface_atom.cpp, mofem/atom_tests/prism_elements_from_surface.cpp, mofem/atom_tests/prism_polynomial_approximation.cpp, mofem/atom_tests/quad_polynomial_approximation.cpp, mofem/atom_tests/remove_entities_from_problem_not_partitioned.cpp, mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp, and mofem/users_modules/basic_finite_elements/nonlinear_elasticity/nonlinear_dynamics.cpp.

Definition at line 147 of file ProblemsManager.cpp.

149 {
150
151 MoFEM::Interface &m_field = cOre;
153 if (!(cOre.getBuildMoFEM() & (1 << 0)))
154 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
155 if (!(cOre.getBuildMoFEM() & (1 << 1)))
156 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
157 if (!(cOre.getBuildMoFEM() & (1 << 2)))
158 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
159 const Problem *problem_ptr;
160 CHKERR m_field.get_problem(name, &problem_ptr);
161 CHKERR buildProblem(const_cast<Problem *>(problem_ptr), square_matrix, verb);
162 cOre.getBuildMoFEM() |= 1 << 3; // It is assumed that user who uses this
163 // function knows what he is doing
165}
std::string name
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures

◆ buildProblem() [2/2]

MoFEMErrorCode MoFEM::ProblemsManager::buildProblem ( Problem *  problem_ptr,
const bool  square_matrix,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

build problem data structures

Note
If square_matrix is set to true, that indicate that problem is structurally symmetric, i.e. rows and columns have the same dofs and are indexed in the same way.
Parameters
problempointer
square_matrixstructurally symmetric problem
verbverbosity level
Returns
error code

Definition at line 167 of file ProblemsManager.cpp.

169 {
170 MoFEM::Interface &m_field = cOre;
171 auto dofs_field_ptr = m_field.get_dofs();
172 auto ents_field_ptr = m_field.get_field_ents();
173 auto adjacencies_ptr = m_field.get_ents_elements_adjacency();
175 PetscLogEventBegin(MOFEM_EVENT_ProblemsManager, 0, 0, 0, 0);
176
177 // Note: Only allowed changes on problem_ptr structure which not influence
178 // multi-index.
179
180 if (problem_ptr->getBitRefLevel().none()) {
181 SETERRQ(PETSC_COMM_SELF, 1, "problem <%s> refinement level not set",
182 problem_ptr->getName().c_str());
183 }
184 CHKERR m_field.clear_problem(problem_ptr->getName());
185
186 // zero finite elements
187 problem_ptr->numeredFiniteElementsPtr->clear();
188
189 // Field entities are visited in UID order and each contributes its DOF
190 // range at most once per view, so plain vectors arrive sorted and unique;
191 // an indexed view would pay two tree insertions per DOF for nothing.
192 using DofPtrVector = std::vector<boost::shared_ptr<DofEntity>>;
193 DofPtrVector dofs_rows, dofs_cols;
194 auto make_rows_and_cols_view = [&](auto &dofs_rows, auto &dofs_cols) {
196 for (auto it = ents_field_ptr->begin(); it != ents_field_ptr->end(); ++it) {
197
198 const auto uid = (*it)->getLocalUniqueId();
199
200 auto r = adjacencies_ptr->get<Unique_mi_tag>().equal_range(uid);
201 for (auto lo = r.first; lo != r.second; ++lo) {
202
203 if ((lo->getBitFEId() & problem_ptr->getBitFEId()).any()) {
204 std::array<bool, 2> row_col = {false, false};
205
206 const BitRefLevel &prb_bit = problem_ptr->getBitRefLevel();
207 const BitRefLevel &prb_mask = problem_ptr->getBitRefLevelMask();
208 const BitRefLevel &fe_bit = lo->entFePtr->getBitRefLevel();
209
210 // if entity is not problem refinement level
211 if ((fe_bit & prb_mask) != fe_bit)
212 continue;
213 if ((fe_bit & prb_bit).none())
214 continue;
215
216 auto add_to_view = [&](auto &nb_dofs, auto &view, auto rc) {
217 auto dit = nb_dofs->lower_bound(uid);
218 decltype(dit) hi_dit;
219 if (dit != nb_dofs->end()) {
220 hi_dit = nb_dofs->upper_bound(
221 uid | static_cast<UId>(MAX_DOFS_ON_ENTITY - 1));
222 view.insert(view.end(), dit, hi_dit);
223 row_col[rc] = true;
224 }
225 };
226
227 if ((lo->entFePtr->getBitFieldIdRow() & (*it)->getId()).any())
228 add_to_view(dofs_field_ptr, dofs_rows, ROW);
229
230 if (!square_matrix)
231 if ((lo->entFePtr->getBitFieldIdCol() & (*it)->getId()).any())
232 add_to_view(dofs_field_ptr, dofs_cols, COL);
233
234 if (square_matrix && row_col[ROW])
235 break;
236 else if (row_col[ROW] && row_col[COL])
237 break;
238 }
239 }
240 }
241 auto by_uid = [](const auto &a, const auto &b) {
242 return a->getLocalUniqueId() < b->getLocalUniqueId();
243 };
244 for (auto *view : {&dofs_rows, &dofs_cols}) {
245 if (!std::is_sorted(view->begin(), view->end(), by_uid))
246 std::sort(view->begin(), view->end(), by_uid);
247 }
249 };
250
251 CHKERR make_rows_and_cols_view(dofs_rows, dofs_cols);
252
253 // Add row dofs to problem
254 {
255 // zero rows
256 problem_ptr->nbDofsRow = 0;
257 problem_ptr->nbLocDofsRow = 0;
258 problem_ptr->nbGhostDofsRow = 0;
259
260 // add dofs for rows
261 int count_dofs = 0;
262 for (auto &dof : dofs_rows)
263 if (dof->getActive())
264 ++count_dofs;
265 boost::shared_ptr<std::vector<NumeredDofEntity>> dofs_array =
266 boost::shared_ptr<std::vector<NumeredDofEntity>>(
267 new std::vector<NumeredDofEntity>());
268 problem_ptr->getRowDofsSequence()->push_back(dofs_array);
269 dofs_array->reserve(count_dofs);
270 // The global index is the insertion order, which is the UID order and
271 // the same on every rank. On one rank it is final, with part 0 and the
272 // same local index, so partitionProblem finds nothing to modify. On more
273 // ranks it is provisional: part and local index stay -1 and
274 // partitionProblem renumbers through the adjacency of this ordering.
275 const bool serial = m_field.get_comm_size() == 1;
276 for (auto miit = dofs_rows.begin(); miit != dofs_rows.end(); miit++) {
277 if ((*miit)->getActive()) {
278 dofs_array->emplace_back(*miit);
279 auto &dof = dofs_array->back();
280 dof.petscGloablDofIdx = (problem_ptr->nbDofsRow)++;
281 if (serial) {
282 dof.pArt = 0;
283 dof.petscLocalDofIdx = dof.petscGloablDofIdx;
284 }
285 }
286 }
287 publish_numbered_dofs(*problem_ptr->numeredRowDofsPtr, dofs_array, serial);
288 }
289
290 // Add col dofs to problem
291 if (!square_matrix) {
292 // zero cols
293 problem_ptr->nbDofsCol = 0;
294 problem_ptr->nbLocDofsCol = 0;
295 problem_ptr->nbGhostDofsCol = 0;
296
297 // add dofs for cols
298 int count_dofs = 0;
299 for (auto &dof : dofs_cols)
300 if (dof->getActive())
301 ++count_dofs;
302
303 boost::shared_ptr<std::vector<NumeredDofEntity>> dofs_array =
304 boost::shared_ptr<std::vector<NumeredDofEntity>>(
305 new std::vector<NumeredDofEntity>());
306 problem_ptr->getColDofsSequence()->push_back(dofs_array);
307 dofs_array->reserve(count_dofs);
308 for (auto miit = dofs_cols.begin(); miit != dofs_cols.end(); miit++) {
309 if (!(*miit)->getActive()) {
310 continue;
311 }
312 dofs_array->emplace_back(*miit);
313 auto &dof = dofs_array->back();
314 dof.petscGloablDofIdx = problem_ptr->nbDofsCol++;
315 if (m_field.get_comm_size() == 1) {
316 dof.pArt = 0;
317 dof.petscLocalDofIdx = dof.petscGloablDofIdx;
318 }
319 }
320 publish_numbered_dofs(*problem_ptr->numeredColDofsPtr, dofs_array,
321 m_field.get_comm_size() == 1);
322 } else {
323 problem_ptr->numeredColDofsPtr = problem_ptr->numeredRowDofsPtr;
324 problem_ptr->nbLocDofsCol = problem_ptr->nbLocDofsRow;
325 problem_ptr->nbDofsCol = problem_ptr->nbDofsRow;
326 }
327
328 // job done, some debugging and postprocessing
329 if (verb >= VERBOSE) {
330 MOFEM_LOG("SYNC", Sev::verbose)
331 << problem_ptr->getName() << " Nb. local dofs "
332 << problem_ptr->numeredRowDofsPtr->size() << " by "
333 << problem_ptr->numeredColDofsPtr->size();
334 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
335 }
336
337 if (verb >= NOISY) {
338 MOFEM_LOG("SYNC", Sev::noisy)
339 << "FEs row dofs " << *problem_ptr << " Nb. row dof "
340 << problem_ptr->getNbDofsRow();
341 for (auto &miit : *problem_ptr->numeredRowDofsPtr)
342 MOFEM_LOG("SYNC", Sev::noisy) << *miit;
343
344 MOFEM_LOG("SYNC", Sev::noisy)
345 << "FEs col dofs " << *problem_ptr << " Nb. col dof "
346 << problem_ptr->getNbDofsCol();
347 for (auto &miit : *problem_ptr->numeredColDofsPtr)
348 MOFEM_LOG("SYNC", Sev::noisy) << *miit;
349 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::noisy);
350 }
351
352 cOre.getBuildMoFEM() |= Core::BUILD_PROBLEM; // It is assumed that user who
353 // uses this function knows
354 // what he is doing
355
356 PetscLogEventEnd(MOFEM_EVENT_ProblemsManager, 0, 0, 0, 0);
357
359}
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
It it
Definition Schur.cpp:2568
constexpr double a
@ NOISY
@ VERBOSE
@ COL
@ ROW
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
virtual const FieldEntity_multiIndex * get_field_ents() const =0
Get the field ents object.
virtual MoFEMErrorCode get_ents_elements_adjacency(const FieldEntityEntFiniteElementAdjacencyMap_multiIndex **dofs_elements_adjacency) const =0
Get the dofs elements adjacency object.
virtual const DofEntity_multiIndex * get_dofs() const =0
Get the dofs object.
#define MOFEM_LOG(channel, severity)
Log.
uint128_t UId
Unique Id.
Definition Types.hpp:31
MoFEM::LogManager::SeverityLevel Sev
int r
Definition sdf.py:205
virtual int get_comm_size() const =0
PetscLogEvent MOFEM_EVENT_ProblemsManager

◆ buildProblemOnDistributedMesh() [1/2]

MoFEMErrorCode MoFEM::ProblemsManager::buildProblemOnDistributedMesh ( const std::string  name,
const bool  square_matrix,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

build problem data structures, assuming that mesh is distributed (collective)

Mesh is distributed, that means that each processor keeps only own part of the mesh and shared entities.

Collective - need to be run on all processors in communicator, i.e. all functions have to call this function.

Parameters
nameproblem name to build
square_matrixtrue if problem has structurally symmetric matrix
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure
Examples
mofem/atom_tests/build_composite_problem.cpp, mofem/atom_tests/remove_entities_from_problem.cpp, and mofem/users_modules/basic_finite_elements/nonlinear_elasticity/nonlinear_dynamics.cpp.

Definition at line 361 of file ProblemsManager.cpp.

362 {
363 MoFEM::Interface &m_field = cOre;
365
367 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
368 if (!((cOre.getBuildMoFEM()) & Core::BUILD_FE))
369 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
371 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
372
373 const Problem *problem_ptr;
374 CHKERR m_field.get_problem(name, &problem_ptr);
375 CHKERR buildProblemOnDistributedMesh(const_cast<Problem *>(problem_ptr),
376 square_matrix, verb);
377
380
382}
MoFEMErrorCode buildProblemOnDistributedMesh(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures, assuming that mesh is distributed (collective)

◆ buildProblemOnDistributedMesh() [2/2]

MoFEMErrorCode MoFEM::ProblemsManager::buildProblemOnDistributedMesh ( Problem *  problem_ptr,
const bool  square_matrix = true,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

build problem data structures, assuming that mesh is distributed (collective)

Mesh is distributed, that means that each processor keeps only own part of the mesh and shared entities.

Collective - need to be run on all processors in communicator, i.e. all functions have to call this function.

Parameters
problem_ptrpointer to problem structure
square_matrixtrue if problem has structurally symmetric matrix
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure

Definition at line 488 of file ProblemsManager.cpp.

489 {
490 MoFEM::Interface &m_field = cOre;
491 auto fields_ptr = m_field.get_fields();
492 auto fe_ptr = m_field.get_finite_elements();
493 auto dofs_field_ptr = m_field.get_dofs();
495 PetscLogEventBegin(MOFEM_EVENT_ProblemsManager, 0, 0, 0, 0);
496
497 // Fetched once: every owner/status query below would otherwise look the
498 // ParallelComm up through two tag operations.
499 auto *pcomm = ParallelComm::get_pcomm(
500 &m_field.get_moab(), m_field.get_basic_entity_data_ptr()->pcommID);
501
502 // clear data structures
503 CHKERR m_field.clear_problem(problem_ptr->getName());
504
506
507 if (problem_ptr->getBitRefLevel().none())
508 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND,
509 "problem <%s> refinement level not set",
510 problem_ptr->getName().c_str());
511
512 int loop_size = 2;
513 if (square_matrix) {
514 loop_size = 1;
515 problem_ptr->numeredColDofsPtr = problem_ptr->numeredRowDofsPtr;
516 } else if (problem_ptr->numeredColDofsPtr == problem_ptr->numeredRowDofsPtr) {
517 problem_ptr->numeredColDofsPtr =
518 boost::shared_ptr<NumeredDofEntity_multiIndex>(
520 }
521
522 const BitRefLevel &prb_bit = problem_ptr->getBitRefLevel();
523 const BitRefLevel &prb_mask = problem_ptr->getBitRefLevelMask();
524
525 // Rows and columns DOF views as plain vectors of DOF pointers; they are
526 // sorted by UID and made unique once all selection and synchronisation
527 // has added to them (finalise_views below). An indexed view would pay two
528 // tree insertions per DOF for the same result.
529 using DofPtrVector = std::vector<boost::shared_ptr<DofEntity>>;
530 DofPtrVector dofs_rows, dofs_cols;
531
532 // Add DOFs to problem by visiting all elements and adding DOFs from
533 // elements to the problem
534 if (buildProblemFromFields == PETSC_FALSE) {
535
536 auto make_rows_and_cols_view = [&](auto &dofs_rows, auto &dofs_cols) {
537 auto ents_field_ptr = m_field.get_field_ents();
538 auto adjacencies_ptr = m_field.get_ents_elements_adjacency();
540 for (auto it = ents_field_ptr->begin(); it != ents_field_ptr->end();
541 ++it) {
542
543 const auto uid = (*it)->getLocalUniqueId();
544
545 auto r = adjacencies_ptr->get<Unique_mi_tag>().equal_range(uid);
546 for (auto lo = r.first; lo != r.second; ++lo) {
547
548 if ((lo->getBitFEId() & problem_ptr->getBitFEId()).any()) {
549 std::array<bool, 2> row_col = {false, false};
550
551 const BitRefLevel &fe_bit = lo->entFePtr->getBitRefLevel();
552
553 // if entity is not problem refinement level
554 if ((fe_bit & prb_bit).any() && (fe_bit & prb_mask) == fe_bit) {
555
556 auto add_to_view = [&](auto dofs, auto &view, auto rc) {
557 auto dit = dofs->lower_bound(uid);
558 decltype(dit) hi_dit;
559 if (dit != dofs->end()) {
560 hi_dit = dofs->upper_bound(
561 uid | static_cast<UId>(MAX_DOFS_ON_ENTITY - 1));
562 view.insert(view.end(), dit, hi_dit);
563 row_col[rc] = true;
564 }
565 };
566
567 if ((lo->entFePtr->getBitFieldIdRow() & (*it)->getId()).any())
568 add_to_view(dofs_field_ptr, dofs_rows, ROW);
569
570 if (!square_matrix)
571 if ((lo->entFePtr->getBitFieldIdCol() & (*it)->getId()).any())
572 add_to_view(dofs_field_ptr, dofs_cols, COL);
573
574 if (square_matrix && row_col[ROW])
575 break;
576 else if (row_col[ROW] && row_col[COL])
577 break;
578 }
579 }
580 }
581 }
583 };
584
585 CHKERR make_rows_and_cols_view(dofs_rows, dofs_cols);
586 }
587
588 // Add DOFS to the problem by searching all the filedes, and adding to
589 // problem owned or shared DOFs
590 if (buildProblemFromFields == PETSC_TRUE) {
591 // Get fields IDs on elements
592 BitFieldId fields_ids_row, fields_ids_col;
593 for (auto fit = fe_ptr->begin(); fit != fe_ptr->end(); fit++) {
594 if ((fit->get()->getId() & problem_ptr->getBitFEId()).any()) {
595 fields_ids_row |= fit->get()->getBitFieldIdRow();
596 fields_ids_col |= fit->get()->getBitFieldIdCol();
597 }
598 }
599 // Get fields DOFs
600 for (auto fit = fields_ptr->begin(); fit != fields_ptr->end(); fit++) {
601 if ((fit->get()->getId() & (fields_ids_row | fields_ids_col)).any()) {
602
603 auto dit = dofs_field_ptr->get<Unique_mi_tag>().lower_bound(
604 FieldEntity::getLoBitNumberUId((*fit)->getBitNumber()));
605 auto hi_dit = dofs_field_ptr->get<Unique_mi_tag>().upper_bound(
606 FieldEntity::getHiBitNumberUId((*fit)->getBitNumber()));
607
608 for (; dit != hi_dit; dit++) {
609
610 const int owner_proc = dit->get()->getOwnerProc(pcomm);
611 if (owner_proc != m_field.get_comm_rank()) {
612 const unsigned char pstatus = dit->get()->getPStatus(pcomm);
613 if (pstatus == 0) {
614 continue;
615 }
616 }
617
618 const auto &dof_bit = (*dit)->getBitRefLevel();
619 // if entity is not problem refinement level
620 if ((dof_bit & prb_bit).any() && (dof_bit & prb_mask) == dof_bit) {
621
622 if ((fit->get()->getId() & fields_ids_row).any()) {
623 dofs_rows.push_back(*dit);
624 }
625 if (!square_matrix) {
626 if ((fit->get()->getId() & fields_ids_col).any()) {
627 dofs_cols.push_back(*dit);
628 }
629 }
630 }
631 }
632 }
633 }
634 }
635
637 // Get fields IDs on elements
638 BitFieldId fields_ids_row, fields_ids_col;
639 BitFieldId *fields_ids[2] = {&fields_ids_row, &fields_ids_col};
640 for (FiniteElement_multiIndex::iterator fit = fe_ptr->begin();
641 fit != fe_ptr->end(); fit++) {
642 if ((fit->get()->getId() & problem_ptr->getBitFEId()).any()) {
643 fields_ids_row |= fit->get()->getBitFieldIdRow();
644 fields_ids_col |= fit->get()->getBitFieldIdCol();
645 }
646 }
647
648 DofPtrVector *dofs_ptr[] = {&dofs_rows, &dofs_cols};
649 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ++ss) {
650 Range ents_to_synchronise;
651 for (auto &dof : *dofs_ptr[ss]) {
652 if (!dof->getActive() || dof->getEntDofIdx() != 0)
653 continue;
654 ents_to_synchronise.insert(dof->getEnt());
655 }
656 Range tmp_ents = ents_to_synchronise;
657 CHKERR m_field.getInterface<CommInterface>()->synchroniseEntities(
658 ents_to_synchronise, nullptr, verb);
659 ents_to_synchronise = subtract(ents_to_synchronise, tmp_ents);
660 for (auto fit = fields_ptr->begin(); fit != fields_ptr->end(); fit++) {
661 if ((fit->get()->getId() & *fields_ids[ss]).any()) {
662 const auto bit_number = (*fit)->getBitNumber();
663 for (Range::pair_iterator pit = ents_to_synchronise.pair_begin();
664 pit != ents_to_synchronise.pair_end(); ++pit) {
665 const auto f = pit->first;
666 const auto s = pit->second;
667 const auto lo_uid =
669 const auto hi_uid =
671
672 auto dit = dofs_field_ptr->get<Unique_mi_tag>().lower_bound(lo_uid);
673 auto hi_dit =
674 dofs_field_ptr->get<Unique_mi_tag>().upper_bound(hi_uid);
675
676 dofs_ptr[ss]->insert(dofs_ptr[ss]->end(), dit, hi_dit);
677 }
678 }
679 }
680 }
681 }
682
683 // Element-based selection appends each entity's DOF range once in UID
684 // order; field-based selection and synchronisation may append out of
685 // order or twice, so sort when needed and drop duplicates.
686 auto finalise_view = [](DofPtrVector &view) {
687 auto by_uid = [](const auto &a, const auto &b) {
688 return a->getLocalUniqueId() < b->getLocalUniqueId();
689 };
690 if (!std::is_sorted(view.begin(), view.end(), by_uid))
691 std::sort(view.begin(), view.end(), by_uid);
692 view.erase(std::unique(view.begin(), view.end(),
693 [](const auto &a, const auto &b) {
694 return a->getLocalUniqueId() ==
695 b->getLocalUniqueId();
696 }),
697 view.end());
698 };
699 finalise_view(dofs_rows);
700 finalise_view(dofs_cols);
701
702 // add dofs for rows and cols and set ownership
703 DofPtrVector *dofs_ptr[] = {&dofs_rows, &dofs_cols};
704 boost::shared_ptr<NumeredDofEntity_multiIndex> numered_dofs_ptr[] = {
705 problem_ptr->numeredRowDofsPtr, problem_ptr->numeredColDofsPtr};
706 int *nbdof_ptr[] = {&problem_ptr->nbDofsRow, &problem_ptr->nbDofsCol};
707 int *local_nbdof_ptr[] = {&problem_ptr->nbLocDofsRow,
708 &problem_ptr->nbLocDofsCol};
709 int *ghost_nbdof_ptr[] = {&problem_ptr->nbGhostDofsRow,
710 &problem_ptr->nbGhostDofsCol};
711 for (int ss = 0; ss < 2; ss++) {
712 *(nbdof_ptr[ss]) = 0;
713 *(local_nbdof_ptr[ss]) = 0;
714 *(ghost_nbdof_ptr[ss]) = 0;
715 }
716
717 // Loop over dofs on rows and columns and add to multi-indices in dofs
718 // problem structure, set partition for each dof
719 int nb_local_dofs[] = {0, 0};
720 for (int ss = 0; ss < loop_size; ss++) {
721 for (auto &dof : *dofs_ptr[ss]) {
722 if (!dof->getActive())
723 continue;
724 if (dof->getOwnerProc(pcomm) == m_field.get_comm_rank())
725 nb_local_dofs[ss]++;
726 }
727 }
728
729 // get layout
730 int start_ranges[2], end_ranges[2];
731 for (int ss = 0; ss != loop_size; ss++) {
732 PetscLayout layout;
733 CHKERR PetscLayoutCreate(m_field.get_comm(), &layout);
734 CHKERR PetscLayoutSetBlockSize(layout, 1);
735 CHKERR PetscLayoutSetLocalSize(layout, nb_local_dofs[ss]);
736 CHKERR PetscLayoutSetUp(layout);
737 CHKERR PetscLayoutGetSize(layout, &*nbdof_ptr[ss]);
738 CHKERR PetscLayoutGetRange(layout, &start_ranges[ss], &end_ranges[ss]);
739 CHKERR PetscLayoutDestroy(&layout);
740 }
741 if (square_matrix) {
742 nbdof_ptr[1] = nbdof_ptr[0];
743 nb_local_dofs[1] = nb_local_dofs[0];
744 start_ranges[1] = start_ranges[0];
745 end_ranges[1] = end_ranges[0];
746 }
747
748 // set local and global indices on own dofs
749 const size_t idx_data_type_size = sizeof(IdxDataType);
750 const size_t data_block_size = idx_data_type_size / sizeof(int);
751
752 if (sizeof(IdxDataType) % sizeof(int)) {
753 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "data inconsistency");
754 }
755 std::vector<std::vector<IdxDataType>> ids_data_packed_rows(
756 m_field.get_comm_size()),
757 ids_data_packed_cols(m_field.get_comm_size());
758
759 // Loop over dofs on this processor and prepare those dofs to send on
760 // another proc
761 for (int ss = 0; ss != loop_size; ++ss) {
762
763 boost::shared_ptr<std::vector<NumeredDofEntity>> dofs_array =
764 boost::shared_ptr<std::vector<NumeredDofEntity>>(
765 new std::vector<NumeredDofEntity>());
766 int nb_dofs_to_add = 0;
767 for (auto &dof : *dofs_ptr[ss])
768 if (dof->getActive())
769 ++nb_dofs_to_add;
770 dofs_array->reserve(nb_dofs_to_add);
771 if (ss == 0) {
772 problem_ptr->getRowDofsSequence()->push_back(dofs_array);
773 } else {
774 problem_ptr->getColDofsSequence()->push_back(dofs_array);
775 }
776
777 int &local_idx = *local_nbdof_ptr[ss];
778 for (auto miit = dofs_ptr[ss]->begin(); miit != dofs_ptr[ss]->end();
779 ++miit) {
780
781 // Only set global idx for dofs on this processor part
782 if (!(miit->get()->getActive()))
783 continue;
784
785 dofs_array->emplace_back(*miit);
786
787 int owner_proc = dofs_array->back().getOwnerProc(pcomm);
788 if (owner_proc < 0) {
789 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
790 "data inconsistency");
791 }
792
793 if (owner_proc != m_field.get_comm_rank()) {
794 dofs_array->back().pArt = owner_proc;
795 dofs_array->back().petscGloablDofIdx = -1;
796 dofs_array->back().petscLocalDofIdx = -1;
797 } else {
798
799 // Set part and indexes
800 int glob_idx = start_ranges[ss] + local_idx;
801 dofs_array->back().pArt = owner_proc;
802 dofs_array->back().petscGloablDofIdx = glob_idx;
803 dofs_array->back().petscLocalDofIdx = local_idx;
804 local_idx++;
805
806 unsigned char pstatus = dofs_array->back().getPStatus(pcomm);
807 // check id dof is shared, if that is a case global idx added to data
808 // structure and is sended to other processors
809 if (pstatus > 0) {
810 const UId global_uid = dofs_array->back().getGlobalUniqueId();
811
812 for (int proc = 0;
813 proc < MAX_SHARING_PROCS &&
814 -1 != dofs_array->back().getSharingProcsPtr(pcomm)[proc];
815 proc++) {
816 // make it different for rows and columns when needed
817 if (ss == 0) {
818 ids_data_packed_rows[dofs_array->back()
819 .getSharingProcsPtr(pcomm)[proc]]
820 .emplace_back(global_uid, glob_idx);
821 } else {
822 ids_data_packed_cols[dofs_array->back()
823 .getSharingProcsPtr(pcomm)[proc]]
824 .emplace_back(global_uid, glob_idx);
825 }
826 if (!(pstatus & PSTATUS_MULTISHARED)) {
827 break;
828 }
829 }
830 }
831 }
832 }
833
834 publish_numbered_dofs(*numered_dofs_ptr[ss], dofs_array,
835 m_field.get_comm_size() == 1);
836 }
837 if (square_matrix) {
838 local_nbdof_ptr[1] = local_nbdof_ptr[0];
839 }
840
841 int nsends_rows = 0, nsends_cols = 0;
842 // Non zero lengths[i] represent a message to i of length lengths[i].
843 // Value-initialised to zero; the size must stay comm_size for the indexed
844 // writes below and for PetscGatherNumberOfMessages.
845 std::vector<int> lengths_rows(m_field.get_comm_size(), 0),
846 lengths_cols(m_field.get_comm_size(), 0);
847 for (int proc = 0; proc < m_field.get_comm_size(); proc++) {
848 lengths_rows[proc] = ids_data_packed_rows[proc].size() * data_block_size;
849 lengths_cols[proc] = ids_data_packed_cols[proc].size() * data_block_size;
850 if (!ids_data_packed_rows[proc].empty())
851 nsends_rows++;
852 if (!ids_data_packed_cols[proc].empty())
853 nsends_cols++;
854 }
855
856 MPI_Status *status;
857 CHKERR PetscMalloc1(m_field.get_comm_size(), &status);
858
859 // Do rows
860 int nrecvs_rows; // number of messages received
861 int *onodes_rows; // list of node-ids from which messages are expected
862 int *olengths_rows; // corresponding message lengths
863 int **rbuf_row; // must bee freed by user
864
865 // make sure it is a PETSc comm
866 MPI_Comm comm;
867 CHKERR PetscCommDuplicate(m_field.get_comm(), &comm, NULL);
868
869 {
870
871 // rows
872
873 // Computes the number of messages a node expects to receive
874 CHKERR PetscGatherNumberOfMessages(comm, NULL, &lengths_rows[0],
875 &nrecvs_rows);
876 // std::cerr << nrecvs_rows << std::endl;
877
878 // Computes info about messages that a MPI-node will receive, including
879 // (from-id,length) pairs for each message.
880 CHKERR PetscGatherMessageLengths(comm, nsends_rows, nrecvs_rows,
881 &lengths_rows[0], &onodes_rows,
882 &olengths_rows);
883
884 // Gets a unique new tag from a PETSc communicator. All processors that
885 // share the communicator MUST call this routine EXACTLY the same number
886 // of times. This tag should only be used with the current objects
887 // communicator; do NOT use it with any other MPI communicator.
888 int tag_row;
889 CHKERR PetscCommGetNewTag(comm, &tag_row);
890
891 // Allocate a buffer sufficient to hold messages of size specified in
892 // olengths. And post Irecvs on these buffers using node info from onodes
893 MPI_Request *r_waits_row; // must bee freed by user
894 // rbuf has a pointers to messeges. It has size of of nrecvs (number of
895 // messages) +1. In the first index a block is allocated,
896 // such that rbuf[i] = rbuf[i-1]+olengths[i-1].
897
898 CHKERR PetscPostIrecvInt(comm, tag_row, nrecvs_rows, onodes_rows,
899 olengths_rows, &rbuf_row, &r_waits_row);
900 CHKERR PetscFree(onodes_rows);
901
902 MPI_Request *s_waits_row; // status of sens messages
903 CHKERR PetscMalloc1(nsends_rows, &s_waits_row);
904
905 // Send messeges
906 for (int proc = 0, kk = 0; proc < m_field.get_comm_size(); proc++) {
907 if (!lengths_rows[proc])
908 continue; // no message to send to this proc
909 CHKERR MPI_Isend(&(ids_data_packed_rows[proc])[0], // buffer to send
910 lengths_rows[proc], // message length
911 MPIU_INT, proc, // to proc
912 tag_row, comm, s_waits_row + kk);
913 kk++;
914 }
915
916 if (nrecvs_rows) {
917 CHKERR MPI_Waitall(nrecvs_rows, r_waits_row, status);
918 }
919 if (nsends_rows) {
920 CHKERR MPI_Waitall(nsends_rows, s_waits_row, status);
921 }
922
923 CHKERR PetscFree(r_waits_row);
924 CHKERR PetscFree(s_waits_row);
925 }
926
927 // cols
928 int nrecvs_cols = nrecvs_rows;
929 int *olengths_cols = olengths_rows;
930 PetscInt **rbuf_col = rbuf_row;
931 if (!square_matrix) {
932
933 // Computes the number of messages a node expects to receive
934 CHKERR PetscGatherNumberOfMessages(comm, NULL, &lengths_cols[0],
935 &nrecvs_cols);
936
937 // Computes info about messages that a MPI-node will receive, including
938 // (from-id,length) pairs for each message.
939 int *onodes_cols;
940 CHKERR PetscGatherMessageLengths(comm, nsends_cols, nrecvs_cols,
941 &lengths_cols[0], &onodes_cols,
942 &olengths_cols);
943
944 // Gets a unique new tag from a PETSc communicator.
945 int tag_col;
946 CHKERR PetscCommGetNewTag(comm, &tag_col);
947
948 // Allocate a buffer sufficient to hold messages of size specified in
949 // olengths. And post Irecvs on these buffers using node info from onodes
950 MPI_Request *r_waits_col; // must bee freed by user
951 CHKERR PetscPostIrecvInt(comm, tag_col, nrecvs_cols, onodes_cols,
952 olengths_cols, &rbuf_col, &r_waits_col);
953 CHKERR PetscFree(onodes_cols);
954
955 MPI_Request *s_waits_col; // status of sens messages
956 CHKERR PetscMalloc1(nsends_cols, &s_waits_col);
957
958 // Send messages
959 for (int proc = 0, kk = 0; proc < m_field.get_comm_size(); proc++) {
960 if (!lengths_cols[proc])
961 continue; // no message to send to this proc
962 CHKERR MPI_Isend(&(ids_data_packed_cols[proc])[0], // buffer to send
963 lengths_cols[proc], // message length
964 MPIU_INT, proc, // to proc
965 tag_col, comm, s_waits_col + kk);
966 kk++;
967 }
968
969 if (nrecvs_cols) {
970 CHKERR MPI_Waitall(nrecvs_cols, r_waits_col, status);
971 }
972 if (nsends_cols) {
973 CHKERR MPI_Waitall(nsends_cols, s_waits_col, status);
974 }
975
976 CHKERR PetscFree(r_waits_col);
977 CHKERR PetscFree(s_waits_col);
978 }
979
980 CHKERR PetscCommDestroy(&comm);
981 CHKERR PetscFree(status);
982
983 // Cache global keys only for this receive phase: comparison must not query
984 // ownership tags, and keys must be refreshed after sharing/ownership changes.
985 using GlobalDof = std::pair<UId, boost::shared_ptr<DofEntity>>;
986 std::vector<GlobalDof> dofs_glob_uid_view;
987 if (nrecvs_rows > 0 || nrecvs_cols > 0) {
988 dofs_glob_uid_view.reserve(m_field.get_dofs()->size());
989 const FieldEntity *last_field_ptr = nullptr;
990 UId field_uid;
991 for (const auto &dof : *m_field.get_dofs()) {
992 const auto &field_ptr = dof->getFieldEntityPtr();
993 if (field_ptr.get() != last_field_ptr) {
994 field_uid = field_ptr->getGlobalUniqueId();
995 last_field_ptr = field_ptr.get();
996 }
997 dofs_glob_uid_view.emplace_back(
998 DofEntity::getUniqueIdCalculate(dof->getEntDofIdx(), field_uid), dof);
999 }
1000 // A duplicate global UID keeps the first DOF in the original UID traversal,
1001 // as the former ordered_unique view did. std::sort needs no merge buffer.
1002 std::sort(dofs_glob_uid_view.begin(), dofs_glob_uid_view.end(),
1003 [](const GlobalDof &a, const GlobalDof &b) {
1004 return a.first == b.first
1005 ? a.second->getLocalUniqueId() <
1006 b.second->getLocalUniqueId()
1007 : a.first < b.first;
1008 });
1009 }
1010
1011 // set values received from other processors
1012 for (int ss = 0; ss != loop_size; ++ss) {
1013
1014 int nrecvs;
1015 int *olengths;
1016 int **data_procs;
1017 if (ss == 0) {
1018 nrecvs = nrecvs_rows;
1019 olengths = olengths_rows;
1020 data_procs = rbuf_row;
1021 } else {
1022 nrecvs = nrecvs_cols;
1023 olengths = olengths_cols;
1024 data_procs = rbuf_col;
1025 }
1026
1027 UId uid;
1028 for (int kk = 0; kk != nrecvs; ++kk) {
1029 int len = olengths[kk];
1030 int *data_from_proc = data_procs[kk];
1031 for (int dd = 0; dd < len; dd += data_block_size) {
1032 uid = IdxDataTypePtr(&data_from_proc[dd]).getUId();
1033 auto ddit = std::lower_bound(
1034 dofs_glob_uid_view.begin(), dofs_glob_uid_view.end(), uid,
1035 [](const GlobalDof &record, const UId &key) {
1036 return record.first < key;
1037 });
1038 if (ddit != dofs_glob_uid_view.end() && ddit->first != uid)
1039 ddit = dofs_glob_uid_view.end();
1040 const auto owner_proc = FieldEntity::getOwnerFromUniqueId(uid);
1041
1042 if (owner_proc == m_field.get_comm_rank() &&
1043 PetscUnlikely(ddit == dofs_glob_uid_view.end())) {
1044
1045#ifndef NDEBUG
1046 auto ents_field_ptr = m_field.get_field_ents();
1047 MOFEM_LOG("SELF", Sev::error)
1048 << "DOF is shared or multishared between processors. For example "
1049 "if order of field on given entity is set in inconsistently, "
1050 "has different value on two processor, error such as this is "
1051 "triggered";
1052
1053 MOFEM_LOG("SELF", Sev::error) << "UId " << uid << " is not found";
1054 MOFEM_LOG("SELF", Sev::error)
1055 << "Problematic UId owner proc is " << owner_proc;
1056 const auto uid_handle = FieldEntity::getHandleFromUniqueId(uid);
1057 MOFEM_LOG("SELF", Sev::error)
1058 << "Problematic UId entity owning processor handle is "
1059 << uid_handle << " entity type "
1060 << moab::CN::EntityTypeName(type_from_handle(uid_handle));
1061 const auto uid_bit_number =
1063 MOFEM_LOG("SELF", Sev::error)
1064 << "Problematic UId field is "
1065 << m_field.get_field_name(
1066 field_bit_from_bit_number(uid_bit_number));
1067
1069 field_view.insert(ents_field_ptr->begin(), ents_field_ptr->end());
1070 auto fe_it = field_view.find(FieldEntity::getGlobalUniqueIdCalculate(
1071 owner_proc, uid_bit_number, uid_handle));
1072 if (fe_it == field_view.end()) {
1073 MOFEM_LOG("SELF", Sev::error)
1074 << "Also, no field entity in database for given global UId";
1075 } else {
1076 MOFEM_LOG("SELF", Sev::error) << "Field entity in databse exist "
1077 "(but have no DOF wih give UId";
1078 MOFEM_LOG("SELF", Sev::error) << **fe_it;
1079
1080 // Save file with missing entity
1081 auto error_file_name =
1082 "error_with_missing_entity_" +
1083 boost::lexical_cast<std::string>(m_field.get_comm_rank()) +
1084 ".vtk";
1085 MOFEM_LOG("SELF", Sev::error)
1086 << "Look to file < " << error_file_name
1087 << " > it contains entity with missing DOF.";
1088
1089 auto tmp_msh = get_temp_meshset_ptr(m_field.get_moab());
1090 const auto local_fe_ent = (*fe_it)->getEnt();
1091 CHKERR m_field.get_moab().add_entities(*tmp_msh, &local_fe_ent, 1);
1092 CHKERR m_field.get_moab().write_file(error_file_name.c_str(), "VTK",
1093 "", tmp_msh->get_ptr(), 1);
1094 }
1095#endif
1096
1097 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1098 "DOF with global UId not found (Compile code in Debug to "
1099 "learn more about problem");
1100 }
1101
1102 if (PetscUnlikely(ddit == dofs_glob_uid_view.end())) {
1103 continue;
1104 }
1105
1106 auto dit = numered_dofs_ptr[ss]->find(ddit->second->getLocalUniqueId());
1107
1108 if (dit != numered_dofs_ptr[ss]->end()) {
1109
1110 int global_idx = IdxDataTypePtr(&data_from_proc[dd]).getGlobalIdx();
1111#ifndef NDEBUG
1112 if (PetscUnlikely(global_idx < 0))
1113 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1114 "received negative dof");
1115#endif
1116 // One modify sets the global index; the part and the local index
1117 // (-1, not owned) are kept.
1118 const bool success = numered_dofs_ptr[ss]->modify(
1119 dit, NumeredDofEntity_part_and_indices_change(
1120 (*dit)->getPart(), global_idx,
1121 (*dit)->getPetscLocalDofIdx()));
1122 if (PetscUnlikely(!success))
1123 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1124 "modification unsuccessful");
1125 };
1126
1127#ifndef NDEBUG
1128 if (PetscUnlikely(ddit->second->getPStatus() == 0)) {
1129
1130 // Dof is shared on this processor, however there is no element
1131 // which have this dof. If DOF is not shared and received from other
1132 // processor, but not marked as a shared on other that means that is
1133 // data inconstancy and error should be thrown.
1134
1135 std::ostringstream zz;
1136 zz << *ddit->second << std::endl;
1137 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1138 "data inconsistency, dofs is not shared, but received "
1139 "from other proc\n"
1140 "%s",
1141 zz.str().c_str());
1142 }
1143#endif
1144 }
1145 }
1146 }
1147
1148 if (square_matrix) {
1149 (problem_ptr->nbDofsCol) = (problem_ptr->nbDofsRow);
1150 (problem_ptr->nbLocDofsCol) = (problem_ptr->nbLocDofsRow);
1151 }
1152
1153 CHKERR PetscFree(olengths_rows);
1154 CHKERR PetscFree(rbuf_row[0]);
1155 CHKERR PetscFree(rbuf_row);
1156 if (!square_matrix) {
1157 CHKERR PetscFree(olengths_cols);
1158 CHKERR PetscFree(rbuf_col[0]);
1159 CHKERR PetscFree(rbuf_col);
1160 }
1161
1162 if (square_matrix) {
1163 if (numered_dofs_ptr[0]->size() != numered_dofs_ptr[1]->size()) {
1164 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1165 "data inconsistency for square_matrix %ld!=%ld",
1166 numered_dofs_ptr[0]->size(), numered_dofs_ptr[1]->size());
1167 }
1168 if (problem_ptr->numeredRowDofsPtr != problem_ptr->numeredColDofsPtr) {
1169 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1170 "data inconsistency for square_matrix");
1171 }
1172 }
1173
1174 CHKERR printPartitionedProblem(problem_ptr, verb);
1175 CHKERR debugPartitionedProblem(problem_ptr, verb);
1176
1177 PetscLogEventEnd(MOFEM_EVENT_ProblemsManager, 0, 0, 0, 0);
1178
1180}
unsigned char status
ParentChildKey key
MPI_Comm comm
std::vector< double > empty
One value per component.
@ MOFEM_NOT_FOUND
Definition definitions.h:33
multi_index_container< boost::shared_ptr< FieldEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< FieldEntity, UId, &FieldEntity::getGlobalUniqueId > > > > FieldEntity_multiIndex_global_uid_view
multi-index view on DofEntity by uid
multi_index_container< boost::shared_ptr< NumeredDofEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, UId, &NumeredDofEntity::getLocalUniqueId > >, ordered_non_unique< tag< Part_mi_tag >, member< NumeredDofEntity, unsigned int, &NumeredDofEntity::pArt > >, ordered_non_unique< tag< PetscGlobalIdx_mi_tag >, member< NumeredDofEntity, DofIdx, &NumeredDofEntity::petscGloablDofIdx > >, ordered_non_unique< tag< PetscLocalIdx_mi_tag >, member< NumeredDofEntity, DofIdx, &NumeredDofEntity::petscLocalDofIdx > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, EntityHandle, &NumeredDofEntity::getEnt > > > > NumeredDofEntity_multiIndex
MultiIndex container keeps NumeredDofEntity.
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.
MoFEMErrorCode getOptions()
Get command line options for ProblemsManager.
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
auto type_from_handle(const EntityHandle h)
get type from entity handle
auto field_bit_from_bit_number(const int bit_number)
get field bit id from bit number
auto get_temp_meshset_ptr(moab::Interface &moab)
Create smart pointer to temporary meshset.
virtual moab::Interface & get_moab()=0
virtual std::string get_field_name(const BitFieldId id) const =0
get field name from id
virtual boost::shared_ptr< BasicEntityData > & get_basic_entity_data_ptr()=0
Get pointer to basic entity data.
static UId getUniqueIdCalculate(const DofIdx dof, const UId &ent_uid)
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
static auto getHandleFromUniqueId(const UId uid)
Get the Handle From Unique Id.
static auto getFieldBitNumberFromUniqueId(const UId uid)
Get the Field Bit Number From Unique Id.
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
static UId getLoBitNumberUId(const FieldBitNumber bit_number)
static auto getOwnerFromUniqueId(const UId uid)
UId getGlobalUniqueIdCalculate() const
Calculate global UId.
PetscBool synchroniseProblemEntities
DOFs in fields, not from DOFs on elements.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.

◆ buildSubProblem()

MoFEMErrorCode MoFEM::ProblemsManager::buildSubProblem ( const std::string  out_name,
const std::vector< std::string > &  fields_row,
const std::vector< std::string > &  fields_col,
const std::string  main_problem,
const bool  square_matrix = true,
const map< std::string, boost::shared_ptr< Range > > *  entityMapRow = nullptr,
const map< std::string, boost::shared_ptr< Range > > *  entityMapCol = nullptr,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

build sub problem

Creates a sub-problem from a main problem by selecting specific fields for rows and columns. This is useful for creating focused problems that operate on subsets of the full problem's fields.

Parameters
out_namename of the output sub-problem to create
fields_rowvector of field names for problem rows
fields_colvector of field names for problem columns
main_problemname of the main problem to extract from
square_matrixtrue if the sub-problem matrix is structurally symmetric
entityMapRowoptional map restricting row fields to specific entities
entityMapColoptional map restricting column fields to specific entities
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure
Examples
mofem/atom_tests/build_problems.cpp, mofem/atom_tests/remove_entities_from_problem.cpp, and mofem/tutorials/vec-5_free_surface/free_surface.cpp.

Definition at line 1182 of file ProblemsManager.cpp.

1193 {
1194 MoFEM::Interface &m_field = cOre;
1195 auto problems_ptr = m_field.get_problems();
1197
1198 CHKERR m_field.clear_problem(out_name);
1199
1200 // get reference to all problems
1201 using ProblemByName = decltype(problems_ptr->get<Problem_mi_tag>());
1202 auto &problems_by_name =
1203 const_cast<ProblemByName &>(problems_ptr->get<Problem_mi_tag>());
1204
1205 // get iterators to out problem, i.e. build problem
1206 auto out_problem_it = problems_by_name.find(out_name);
1207 if (out_problem_it == problems_by_name.end()) {
1208 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1209 "subproblem with name < %s > not defined (top tip check spelling)",
1210 out_name.c_str());
1211 }
1212 // get iterator to main problem, i.e. out problem is subproblem of main
1213 // problem
1214 auto main_problem_it = problems_by_name.find(main_problem);
1215 if (main_problem_it == problems_by_name.end()) {
1216 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1217 "problem of subproblem with name < %s > not defined (top tip "
1218 "check spelling)",
1219 main_problem.c_str());
1220 }
1221
1222 // get dofs for row & columns for out problem,
1223 boost::shared_ptr<NumeredDofEntity_multiIndex> out_problem_dofs[] = {
1224 out_problem_it->numeredRowDofsPtr, out_problem_it->numeredColDofsPtr};
1225 // get dofs for row & columns for main problem
1226 boost::shared_ptr<NumeredDofEntity_multiIndex> main_problem_dofs[] = {
1227 main_problem_it->numeredRowDofsPtr, main_problem_it->numeredColDofsPtr};
1228 // get local indices counter
1229 int *nb_local_dofs[] = {&out_problem_it->nbLocDofsRow,
1230 &out_problem_it->nbLocDofsCol};
1231 // get global indices counter
1232 int *nb_dofs[] = {&out_problem_it->nbDofsRow, &out_problem_it->nbDofsCol};
1233
1234 // set number of ghost nodes to zero
1235 {
1236 out_problem_it->nbGhostDofsRow = 0;
1237 out_problem_it->nbGhostDofsCol = 0;
1238 }
1239
1240 // put rows & columns field names in array
1241 std::vector<std::string> fields[] = {fields_row, fields_col};
1242 const map<std::string, boost::shared_ptr<Range>> *entityMap[] = {
1243 entityMapRow, entityMapCol};
1244
1245 // make data structure fos sub-problem data
1246 out_problem_it->subProblemData =
1247 boost::make_shared<Problem::SubProblemData>();
1248
1249 // Loop over rows and columns
1250 for (int ss = 0; ss != (square_matrix ? 1 : 2); ++ss) {
1251
1252 // reset dofs and columns counters
1253 (*nb_local_dofs[ss]) = 0;
1254 (*nb_dofs[ss]) = 0;
1255 // clear arrays
1256 out_problem_dofs[ss]->clear();
1257
1258 // If DOFs are cleared clear finite elements too.
1259 out_problem_it->numeredFiniteElementsPtr->clear();
1260
1261 // Number records in stable sequences before publishing them once.
1262 struct Record {
1263 NumeredDofEntity *dof;
1264 };
1265 std::vector<Record> records;
1266 std::vector<boost::shared_ptr<std::vector<NumeredDofEntity>>> sequences;
1267 auto fields_by_bit = fields[ss];
1268 std::sort(fields_by_bit.begin(), fields_by_bit.end(),
1269 [&](const std::string &a, const std::string &b) {
1270 return m_field.get_field_bit_number(a) <
1271 m_field.get_field_bit_number(b);
1272 });
1273
1274 // get dofs by field name and copy them into the out problem sequences
1275 for (auto field : fields_by_bit) {
1276
1277 // Following reserve memory in sequences, only two allocations are here,
1278 // once for array of objects, next for array of shared pointers
1279
1280 // aliased sequence of pointer is killed with element
1281 boost::shared_ptr<std::vector<NumeredDofEntity>> dofs_array =
1282 boost::make_shared<std::vector<NumeredDofEntity>>();
1283 sequences.push_back(dofs_array);
1284 // reserve memory for field dofs
1285 if (!ss)
1286 out_problem_it->getRowDofsSequence()->emplace_back(dofs_array);
1287 else
1288 out_problem_it->getColDofsSequence()->emplace_back(dofs_array);
1289
1290 // create elements objects
1291 auto bit_number = m_field.get_field_bit_number(field);
1292
1293 auto add_dit_to_dofs_array = [&](auto &dit) {
1294 if (dit->get()->getPetscGlobalDofIdx() >= 0)
1295 dofs_array->emplace_back(
1296 dit->get()->getDofEntityPtr(), dit->get()->getPetscGlobalDofIdx(),
1297 dit->get()->getPetscLocalDofIdx(), dit->get()->getPart());
1298 };
1299
1300 auto get_dafult_dof_range = [&]() {
1301 auto dit = main_problem_dofs[ss]->get<Unique_mi_tag>().lower_bound(
1302 FieldEntity::getLoBitNumberUId(bit_number));
1303 auto hi_dit = main_problem_dofs[ss]->get<Unique_mi_tag>().upper_bound(
1304 FieldEntity::getHiBitNumberUId(bit_number));
1305 return std::make_pair(dit, hi_dit);
1306 };
1307
1308 auto check = [&](auto &field) -> boost::shared_ptr<Range> {
1309 if (entityMap[ss]) {
1310 auto mit = entityMap[ss]->find(field);
1311 if (mit != entityMap[ss]->end()) {
1312 return mit->second;
1313 } else {
1314 return nullptr;
1315 }
1316 } else {
1317 return nullptr;
1318 }
1319 };
1320
1321 if (auto r_ptr = check(field)) {
1322 for (auto p = r_ptr->pair_begin(); p != r_ptr->pair_end(); ++p) {
1323 const auto lo_ent = p->first;
1324 const auto hi_ent = p->second;
1325 auto dit = main_problem_dofs[ss]->get<Unique_mi_tag>().lower_bound(
1326 DofEntity::getLoFieldEntityUId(bit_number, lo_ent));
1327 auto hi_dit = main_problem_dofs[ss]->get<Unique_mi_tag>().upper_bound(
1328 DofEntity::getHiFieldEntityUId(bit_number, hi_ent));
1329 dofs_array->reserve(std::distance(dit, hi_dit));
1330 for (; dit != hi_dit; dit++) {
1331 add_dit_to_dofs_array(dit);
1332 }
1333 }
1334 } else {
1335 auto [dit, hi_dit] = get_dafult_dof_range();
1336 dofs_array->reserve(std::distance(dit, hi_dit));
1337 for (; dit != hi_dit; dit++)
1338 add_dit_to_dofs_array(dit);
1339 }
1340
1341 // The sequence is complete, so pointers into it are stable.
1342 records.reserve(records.size() + dofs_array->size());
1343 for (auto &v : *dofs_array)
1344 records.push_back({&v});
1345 }
1346
1347 // Number the records before insertion, as the main problem would be
1348 // visited by its global index (the records still carry it): local index
1349 // in that order for DOFs of this part, -1 otherwise.
1350 std::vector<Record *> by_main_index;
1351 by_main_index.reserve(records.size());
1352 for (auto &r : records)
1353 by_main_index.push_back(&r);
1354 std::sort(by_main_index.begin(), by_main_index.end(),
1355 [](const Record *a, const Record *b) {
1356 return a->dof->getPetscGlobalDofIdx() <
1357 b->dof->getPetscGlobalDofIdx();
1358 });
1359 const unsigned int rank = m_field.get_comm_rank();
1360 for (auto *r : by_main_index)
1361 r->dof->petscLocalDofIdx =
1362 (r->dof->getPart() == rank) ? (*nb_local_dofs[ss])++ : -1;
1363
1364 // Map the main problem's global indices of this part's DOFs to the
1365 // compressed global indices of the out problem.
1366 {
1367 std::vector<int> main_indices;
1368 main_indices.reserve(*nb_local_dofs[ss]);
1369 for (auto *r : by_main_index)
1370 if (r->dof->petscLocalDofIdx >= 0)
1371 main_indices.push_back(r->dof->getPetscGlobalDofIdx());
1372 const int nb = main_indices.size();
1373 IS is;
1374 CHKERR ISCreateGeneral(m_field.get_comm(), nb, main_indices.data(),
1375 PETSC_USE_POINTER, &is);
1376 AO ao;
1377 CHKERR AOCreateMappingIS(is, PETSC_NULLPTR, &ao);
1378 if (ss == 0) {
1379 IS is_dup;
1380 CHKERR ISDuplicate(is, &is_dup);
1381 out_problem_it->getSubData()->rowIs = SmartPetscObj<IS>(is_dup, false);
1382 out_problem_it->getSubData()->rowMap = SmartPetscObj<AO>(ao, true);
1383 } else {
1384 IS is_dup;
1385 CHKERR ISDuplicate(is, &is_dup);
1386 out_problem_it->getSubData()->colIs = SmartPetscObj<IS>(is_dup, false);
1387 out_problem_it->getSubData()->colMap = SmartPetscObj<AO>(ao, true);
1388 }
1389 // The IS uses main_indices in place; after the mapping they are the
1390 // out problem's global indices.
1391 CHKERR AOApplicationToPetscIS(ao, is);
1392 CHKERR ISGetSize(is, nb_dofs[ss]);
1393 CHKERR ISDestroy(&is);
1394 {
1395 auto it = main_indices.begin();
1396 for (auto *r : by_main_index)
1397 if (r->dof->petscLocalDofIdx >= 0) {
1398 r->dof->petscGloablDofIdx = *it;
1399 ++it;
1400 }
1401 }
1402 // DOFs of other parts get the mapped global index. The IS and the
1403 // mapping are collective, so every rank makes them, with no entries if
1404 // it has no such DOFs.
1405 std::vector<int> main_indices_non_local;
1406 main_indices_non_local.reserve(records.size() - nb);
1407 for (auto *r : by_main_index)
1408 if (r->dof->petscLocalDofIdx < 0)
1409 main_indices_non_local.push_back(r->dof->getPetscGlobalDofIdx());
1410 {
1411 IS is_non_local;
1412 CHKERR ISCreateGeneral(m_field.get_comm(), main_indices_non_local.size(),
1413 main_indices_non_local.data(), PETSC_USE_POINTER,
1414 &is_non_local);
1415 CHKERR AOApplicationToPetscIS(ao, is_non_local);
1416 CHKERR ISDestroy(&is_non_local);
1417 auto it = main_indices_non_local.begin();
1418 for (auto *r : by_main_index)
1419 if (r->dof->petscLocalDofIdx < 0)
1420 r->dof->petscGloablDofIdx = *it++;
1421 }
1422 CHKERR AODestroy(&ao);
1423 }
1424
1425 for (auto &sequence_ptr : sequences)
1426 publish_numbered_dofs(*out_problem_dofs[ss], sequence_ptr);
1427 }
1428
1429 if (square_matrix) {
1430 out_problem_it->numeredColDofsPtr = out_problem_it->numeredRowDofsPtr;
1431 out_problem_it->nbLocDofsCol = out_problem_it->nbLocDofsRow;
1432 out_problem_it->nbDofsCol = out_problem_it->nbDofsRow;
1433 out_problem_it->getSubData()->colIs = out_problem_it->getSubData()->rowIs;
1434 out_problem_it->getSubData()->colMap = out_problem_it->getSubData()->rowMap;
1435 }
1436
1437 CHKERR printPartitionedProblem(&*out_problem_it, verb);
1438 CHKERR debugPartitionedProblem(&*out_problem_it, verb);
1439
1441}
ProjectedField & field
int nb
number of DOFs
Definition Schur.cpp:2505
const double v
phase velocity of light in medium (cm/ns)
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
static UId getLoFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
static UId getHiFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)

◆ debugPartitionedProblem()

MoFEMErrorCode MoFEM::ProblemsManager::debugPartitionedProblem ( const Problem *  problem_ptr,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

Debug partition information.

Performs detailed analysis and validation of problem partitioning, checking for inconsistencies and reporting partition quality metrics.

Parameters
problem_ptrpointer to the problem structure
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure

Definition at line 2281 of file ProblemsManager.cpp.

2281 {
2282 MoFEM::Interface &m_field = cOre;
2284
2285 auto save_ent = [](moab::Interface &moab, const std::string name,
2286 const EntityHandle ent) {
2288 EntityHandle out_meshset;
2289 CHKERR moab.create_meshset(MESHSET_SET, out_meshset);
2290 CHKERR moab.add_entities(out_meshset, &ent, 1);
2291 CHKERR moab.write_file(name.c_str(), "VTK", "", &out_meshset, 1);
2292 CHKERR moab.delete_entities(&out_meshset, 1);
2294 };
2295
2296 if (debug > 0) {
2297
2298 typedef NumeredDofEntity_multiIndex::index<Unique_mi_tag>::type
2299 NumeredDofEntitysByIdx;
2300 NumeredDofEntitysByIdx::iterator dit, hi_dit;
2301 const NumeredDofEntitysByIdx *numered_dofs_ptr[] = {
2302 &(problem_ptr->numeredRowDofsPtr->get<Unique_mi_tag>()),
2303 &(problem_ptr->numeredColDofsPtr->get<Unique_mi_tag>())};
2304
2305 int *nbdof_ptr[] = {&problem_ptr->nbDofsRow, &problem_ptr->nbDofsCol};
2306 int *local_nbdof_ptr[] = {&problem_ptr->nbLocDofsRow,
2307 &problem_ptr->nbLocDofsCol};
2308
2309 for (int ss = 0; ss < 2; ss++) {
2310
2311 dit = numered_dofs_ptr[ss]->begin();
2312 hi_dit = numered_dofs_ptr[ss]->end();
2313 for (; dit != hi_dit; dit++) {
2314 if ((*dit)->getPart() == (unsigned int)m_field.get_comm_rank()) {
2315 if ((*dit)->getPetscLocalDofIdx() < 0) {
2316 std::ostringstream zz;
2317 zz << "rank " << m_field.get_comm_rank() << " " << **dit;
2318 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2319 "local dof index for %d (0-row, 1-col) not set, i.e. has "
2320 "negative value\n %s",
2321 ss, zz.str().c_str());
2322 }
2323 if ((*dit)->getPetscLocalDofIdx() >= *local_nbdof_ptr[ss]) {
2324 std::ostringstream zz;
2325 zz << "rank " << m_field.get_comm_rank() << " " << **dit;
2326 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2327 "local dofs for %d (0-row, 1-col) out of range\n %s", ss,
2328 zz.str().c_str());
2329 }
2330 } else {
2331 if ((*dit)->getPetscGlobalDofIdx() < 0) {
2332
2333 const EntityHandle ent = (*dit)->getEnt();
2334 CHKERR save_ent(
2335 m_field.get_moab(),
2336 "debug_part" +
2337 boost::lexical_cast<std::string>(m_field.get_comm_rank()) +
2338 "_negative_global_index.vtk",
2339 ent);
2340
2341 std::ostringstream zz;
2342 zz << "rank " << m_field.get_comm_rank() << " "
2343 << dit->get()->getBitRefLevel() << " " << **dit;
2344 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2345 "global dof index for %d (0-row, 1-col) row not set, i.e. "
2346 "has negative value\n %s",
2347 ss, zz.str().c_str());
2348 }
2349 if ((*dit)->getPetscGlobalDofIdx() >= *nbdof_ptr[ss]) {
2350 std::ostringstream zz;
2351 zz << "rank " << m_field.get_comm_rank() << " nb_dofs "
2352 << *nbdof_ptr[ss] << " " << **dit;
2353 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2354 "global dofs for %d (0-row, 1-col) out of range\n %s", ss,
2355 zz.str().c_str());
2356 }
2357 }
2358 }
2359 }
2360 }
2362}
@ MOFEM_IMPOSSIBLE_CASE
Definition definitions.h:35
static const bool debug

◆ getFEMeshset()

MoFEMErrorCode MoFEM::ProblemsManager::getFEMeshset ( const std::string  prb_name,
const std::string &  fe_name,
EntityHandle *  meshset 
) const

#include <src/interfaces/ProblemsManager.hpp>

Create finite element meshset for the problem.

Creates or retrieves the meshset entity that contains all finite elements of a specific type within a problem. The meshset entity must be created before calling this function.

Parameters
prb_namename of the problem
fe_namename of the finite element type
meshsetpointer to store the meshset handle
Returns
MoFEMErrorCode Error code indicating success or failure

Definition at line 2768 of file ProblemsManager.cpp.

2770 {
2771 MoFEM::Interface &m_field = cOre;
2772 const Problem *problem_ptr;
2773 const FiniteElement_multiIndex *fes_ptr;
2775
2776 CHKERR m_field.get_moab().create_meshset(MESHSET_SET, *meshset);
2777 CHKERR m_field.get_problem(prb_name, &problem_ptr);
2778 CHKERR m_field.get_finite_elements(&fes_ptr);
2779
2780 auto fe_miit = fes_ptr->get<FiniteElement_name_mi_tag>().find(fe_name);
2781 if (fe_miit != fes_ptr->get<FiniteElement_name_mi_tag>().end()) {
2782 auto fit =
2783 problem_ptr->numeredFiniteElementsPtr->get<Unique_mi_tag>().lower_bound(
2785 0, (*fe_miit)->getFEUId()));
2786 auto hi_fe_it =
2787 problem_ptr->numeredFiniteElementsPtr->get<Unique_mi_tag>().upper_bound(
2789 get_id_for_max_type<MBENTITYSET>(), (*fe_miit)->getFEUId()));
2790 std::vector<EntityHandle> fe_vec;
2791 fe_vec.reserve(std::distance(fit, hi_fe_it));
2792 for (; fit != hi_fe_it; fit++)
2793 fe_vec.push_back(fit->get()->getEnt());
2794 CHKERR m_field.get_moab().add_entities(*meshset, &*fe_vec.begin(),
2795 fe_vec.size());
2796 }
2797
2799}
multi_index_container< boost::shared_ptr< FiniteElement >, indexed_by< hashed_unique< tag< FiniteElement_Meshset_mi_tag >, member< FiniteElement, EntityHandle, &FiniteElement::meshset > >, hashed_unique< tag< BitFEId_mi_tag >, const_mem_fun< FiniteElement, BitFEId, &FiniteElement::getId >, HashBit< BitFEId >, EqBit< BitFEId > >, ordered_unique< tag< FiniteElement_name_mi_tag >, const_mem_fun< FiniteElement, boost::string_ref, &FiniteElement::getNameRef > > > > FiniteElement_multiIndex
MultiIndex for entities for FiniteElement.
UId getLocalUniqueIdCalculate() const
Generate UId for finite element entity.

◆ getOptions()

MoFEMErrorCode MoFEM::ProblemsManager::getOptions ( )

#include <src/interfaces/ProblemsManager.hpp>

Get command line options for ProblemsManager.

Retrieves configuration options from command line arguments that control problem building behavior, such as buildProblemFromFields and synchroniseProblemEntities flags.

Returns
MoFEMErrorCode Error code indicating success or failure

Definition at line 123 of file ProblemsManager.cpp.

123 {
124 MoFEM::Interface &m_field = cOre;
126 PetscOptionsBegin(m_field.get_comm(), "", "Problem manager", "none");
127 {
128 CHKERR PetscOptionsBool(
129 "-problem_build_from_fields",
130 "Add DOFs to problem directly from fields not through DOFs on elements",
132 }
133 PetscOptionsEnd();
135}

◆ getProblemElementsLayout()

MoFEMErrorCode MoFEM::ProblemsManager::getProblemElementsLayout ( const std::string  name,
const std::string &  fe_name,
PetscLayout *  layout 
) const

#include <src/interfaces/ProblemsManager.hpp>

Get layout of elements in the problem.

In layout is stored information how many elements is on each processor, for more information look int petsc documentation http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/IS/PetscLayoutCreate.html#PetscLayoutCreate

Parameters
nameproblem name
fe_namefinite elements
layoutlayout
verbverbosity level
Returns
error code

Definition at line 2802 of file ProblemsManager.cpp.

2804 {
2805 MoFEM::Interface &m_field = cOre;
2806 const Problem *problem_ptr;
2808 CHKERR m_field.get_problem(name, &problem_ptr);
2809 CHKERR problem_ptr->getNumberOfElementsByNameAndPart(PETSC_COMM_WORLD,
2810 fe_name, layout);
2812}
MoFEMErrorCode getNumberOfElementsByNameAndPart(MPI_Comm comm, const std::string name, PetscLayout *layout) const
Get number of finite elements by name on processors.

◆ getSideDofsOnBrokenSpaceEntities()

MoFEMErrorCode MoFEM::ProblemsManager::getSideDofsOnBrokenSpaceEntities ( std::vector< boost::weak_ptr< NumeredDofEntity > > &  vec_dof_view,
const std::string  problem_name,
RowColData  rc,
const std::string  field_name,
const Range  ents,
int  bridge_dim,
const int  lo_coeff = 0,
const int  hi_coeff = MAX_DOFS_ON_ENTITY,
const int  lo_order = 0,
const int  hi_order = 100,
int  verb = VERBOSE,
const bool  debug = false 
) const

#include <src/interfaces/ProblemsManager.hpp>

Get DOFs on side entities for broken space.

Retrieves DOFs associated with side entities in broken (discontinuous) spaces. The DOFs are connected through a bridge entity of specified dimension. This is useful for implementing interface conditions in discontinuous Galerkin methods.

Parameters
vec_dof_viewoutput vector to store the DOF entities
problem_namename of the problem
rcrow or column data specification
field_namename of the field
entsrange of side entities to process
bridge_dimdimension of bridge entity connecting DOFs to side entities
lo_coefflowest coefficient (rank) to include
hi_coeffhighest coefficient (rank) to include
lo_orderlowest polynomial order to include
hi_orderhighest polynomial order to include
verbverbosity level
debugenable debug output for inconsistency checking
Returns
MoFEMErrorCode Error code indicating success or failure

Definition at line 2814 of file ProblemsManager.cpp.

2822 {
2823 MoFEM::Interface &m_field = cOre;
2825
2826 switch (rc) {
2827 case ROW:
2828 case COL:
2829 break;
2830 default:
2831 SETERRQ(m_field.get_comm(), MOFEM_INVALID_DATA, "invalid RowColData");
2832 break;
2833 }
2834
2835 const Problem *prb_ptr;
2836 CHKERR m_field.get_problem(problem_name, &prb_ptr);
2837
2838 decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
2839 prb_ptr->numeredRowDofsPtr, nullptr};
2840 if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
2841 numered_dofs[1] = prb_ptr->numeredColDofsPtr;
2842
2843 Range bridge_ents;
2844 CHKERR m_field.get_moab().get_adjacencies(
2845 ents, bridge_dim, false, bridge_ents, moab::Interface::UNION);
2846
2847 auto &moab = m_field.get_moab();
2848 const auto bit_number = m_field.get_field_bit_number(field_name);
2849 const auto nb_coeffs =
2851 const auto &side_dof_map = m_field.get_field_structure(field_name)
2852 ->getDofSideMap();
2853
2854 using NumeredDofEntity_it_view_multiIndex = multi_index_container<
2855
2856 NumeredDofEntity_multiIndex::iterator, indexed_by<sequenced<>>
2857
2858 >;
2859 NumeredDofEntity_it_view_multiIndex dofs_it_view;
2860
2861 for (auto pit = bridge_ents.const_pair_begin();
2862 pit != bridge_ents.const_pair_end(); ++pit) {
2863 auto lo = numered_dofs[rc]->get<Unique_mi_tag>().lower_bound(
2864 DofEntity::getLoFieldEntityUId(bit_number, pit->first));
2865 auto hi = numered_dofs[rc]->get<Unique_mi_tag>().upper_bound(
2866 DofEntity::getHiFieldEntityUId(bit_number, pit->second));
2867
2868 auto bride_type = moab.type_from_handle(pit->first);
2869
2870 for (; lo != hi; ++lo) {
2871 if ((*lo)->getDofCoeffIdx() >= lo_coeff &&
2872 (*lo)->getDofCoeffIdx() <= hi_coeff &&
2873 (*lo)->getDofOrder() >= lo_order &&
2874 (*lo)->getDofOrder() <= hi_order) {
2875 auto ent_dof_index = (*lo)->getEntDofIdx();
2876 auto side_it = side_dof_map.at(bride_type)
2877 .get<EntDofIdx_mi_tag>()
2878 .find(std::floor(static_cast<double>(ent_dof_index) /
2879 nb_coeffs));
2880 if (side_it !=
2881 side_dof_map.at(bride_type).get<EntDofIdx_mi_tag>().end()) {
2882 auto bridge_ent = (*lo)->getEnt();
2883 auto type = side_it->type;
2884 auto side = side_it->side;
2885 auto dim = CN::Dimension(type);
2886 EntityHandle side_ent = 0;
2887 CHKERR moab.side_element(bridge_ent, dim, side, side_ent);
2888 if (ents.find(side_ent) != ents.end()) {
2889 dofs_it_view.emplace_back(numered_dofs[rc]->project<0>(lo));
2890 }
2891 } else {
2892#ifndef NDEBUG
2893 MOFEM_LOG("SELF", Sev::error)
2894 << *m_field.get_field_structure(field_name);
2895 MOFEM_LOG("SELF", Sev::error)
2896 << "side not found for entity " << CN::EntityTypeName(bride_type);
2897 MOFEM_LOG("SELF", Sev::error)
2898 << "ent_dof_index / nb_coeffs "
2899 << std::floor(static_cast<double>(ent_dof_index) / nb_coeffs);
2900 MOFEM_LOG("SELF", Sev::error)
2901 << "side_dof_map.size() " << side_dof_map.size();
2902#endif // NDEBUG
2903 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2904 "side not found - you will get more information in debug");
2905 }
2906 }
2907 }
2908 }
2909
2910 if (verb > QUIET) {
2911 for (auto &dof : dofs_it_view)
2912 MOFEM_LOG("SYNC", Sev::noisy) << **dof;
2913 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::noisy);
2914 }
2915
2916 vec_dof_view.reserve(vec_dof_view.size() + dofs_it_view.size());
2917 for (auto dit : dofs_it_view)
2918 vec_dof_view.push_back(*dit);
2919
2921}
std::string type
@ QUIET
@ MOFEM_INVALID_DATA
Definition definitions.h:36
virtual const Field * get_field_structure(const std::string &name, enum MoFEMTypes bh=MF_EXIST) const =0
get field structure
FieldCoefficientsNumber getNbOfCoeffs() const
Get number of field coefficients per DOF.
std::map< int, BaseFunction::DofsSideMap > & getDofSideMap() const
Get DOF side mapping for broken spaces.
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredRowDofsPtr
store DOFs on rows for this problem

◆ inheritPartition()

MoFEMErrorCode MoFEM::ProblemsManager::inheritPartition ( const std::string  name,
const std::string  problem_for_rows,
bool  copy_rows,
const std::string  problem_for_cols,
bool  copy_cols,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

build indexing and partition problem inheriting indexing and partitioning from two other problems

Transfers DOF indexing and partitioning information from existing problems to a new problem. This is useful for maintaining consistent partitioning across related problems in multi-physics simulations.

Parameters
namename of the target problem to inherit partitioning
problem_for_rowssource problem for row DOF indexing and partitioning
copy_rowsif true, copy row DOF indices; if false, only copy partition info
problem_for_colssource problem for column DOF indexing and partitioning
copy_colsif true, copy column DOF indices; if false, only copy partition info
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure

If copy_rows/copy_cols is set to false only partition is copied between problems.

Examples
mofem/atom_tests/build_problems.cpp.

Definition at line 2094 of file ProblemsManager.cpp.

2096 {
2097 MoFEM::Interface &m_field = cOre;
2098 auto problems_ptr = m_field.get_problems();
2100
2102 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY, "pRoblems not build");
2103
2104 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemByName;
2105
2106 // find p_miit
2107 ProblemByName &problems_by_name =
2108 const_cast<ProblemByName &>(problems_ptr->get<Problem_mi_tag>());
2109 ProblemByName::iterator p_miit = problems_by_name.find(name);
2110 if (p_miit == problems_by_name.end()) {
2111 SETERRQ(m_field.get_comm(), MOFEM_NOT_FOUND,
2112 "problem with name < %s > not defined (top tip check spelling)",
2113 name.c_str());
2114 }
2115 if (verb > QUIET)
2116 MOFEM_LOG("WORLD", Sev::inform)
2117 << p_miit->getName() << " from rows of " << problem_for_rows
2118 << " and columns of " << problem_for_cols;
2119
2120 // find p_miit_row
2121 ProblemByName::iterator p_miit_row = problems_by_name.find(problem_for_rows);
2122 if (p_miit_row == problems_by_name.end()) {
2123 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2124 "problem with name < %s > not defined (top tip check spelling)",
2125 problem_for_rows.c_str());
2126 }
2127 const boost::shared_ptr<NumeredDofEntity_multiIndex> dofs_row =
2128 p_miit_row->numeredRowDofsPtr;
2129
2130 // find p_mit_col
2131 ProblemByName::iterator p_miit_col = problems_by_name.find(problem_for_cols);
2132 if (p_miit_col == problems_by_name.end()) {
2133 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2134 "problem with name < %s > not defined (top tip check spelling)",
2135 problem_for_cols.c_str());
2136 }
2137 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs_col =
2138 p_miit_col->numeredColDofsPtr;
2139
2140 bool copy[] = {copy_rows, copy_cols};
2141 boost::shared_ptr<NumeredDofEntity_multiIndex> composed_dofs[] = {
2142 p_miit->numeredRowDofsPtr, p_miit->numeredColDofsPtr};
2143
2144 int *nb_local_dofs[] = {&p_miit->nbLocDofsRow, &p_miit->nbLocDofsCol};
2145 int *nb_dofs[] = {&p_miit->nbDofsRow, &p_miit->nbDofsCol};
2146 boost::shared_ptr<NumeredDofEntity_multiIndex> copied_dofs[] = {dofs_row,
2147 dofs_col};
2148
2149 for (int ss = 0; ss < 2; ss++) {
2150
2151 // build indices
2152 *nb_local_dofs[ss] = 0;
2153 if (!copy[ss]) {
2154
2155 // only copy indices which are belong to some elements if this problem
2156 std::vector<int> is_local, is_new;
2157
2158 NumeredDofEntityByUId &dofs_by_uid =
2159 copied_dofs[ss]->get<Unique_mi_tag>();
2160 for (NumeredDofEntity_multiIndex::iterator dit =
2161 composed_dofs[ss]->begin();
2162 dit != composed_dofs[ss]->end(); dit++) {
2163 NumeredDofEntityByUId::iterator diit =
2164 dofs_by_uid.find((*dit)->getLocalUniqueId());
2165 if (diit == dofs_by_uid.end()) {
2166 SETERRQ(
2168 "data inconsistency, could not find dof in composite problem");
2169 }
2170 int part_number = (*diit)->getPart(); // get part number
2171 int petsc_global_dof = (*diit)->getPetscGlobalDofIdx();
2172 bool success;
2173 success = composed_dofs[ss]->modify(
2174 dit, NumeredDofEntity_part_and_glob_idx_change(part_number,
2175 petsc_global_dof));
2176 if (!success) {
2177 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2178 "modification unsuccessful");
2179 }
2180 if ((*dit)->getPart() == (unsigned int)m_field.get_comm_rank()) {
2181 success = composed_dofs[ss]->modify(
2182 dit, NumeredDofEntity_local_idx_change((*nb_local_dofs[ss])++));
2183 if (!success) {
2184 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2185 "modification unsuccessful");
2186 }
2187 is_local.push_back(petsc_global_dof);
2188 }
2189 }
2190
2191 AO ao;
2192 CHKERR AOCreateMapping(m_field.get_comm(), is_local.size(), &is_local[0],
2193 NULL, &ao);
2194
2195 // apply local to global mapping
2196 is_local.resize(0);
2197 for (NumeredDofEntity_multiIndex::iterator dit =
2198 composed_dofs[ss]->begin();
2199 dit != composed_dofs[ss]->end(); dit++) {
2200 is_local.push_back((*dit)->getPetscGlobalDofIdx());
2201 }
2202 CHKERR AOPetscToApplication(ao, is_local.size(), &is_local[0]);
2203 int idx2 = 0;
2204 for (NumeredDofEntity_multiIndex::iterator dit =
2205 composed_dofs[ss]->begin();
2206 dit != composed_dofs[ss]->end(); dit++) {
2207 int part_number = (*dit)->getPart(); // get part number
2208 int petsc_global_dof = is_local[idx2++];
2209 bool success;
2210 success = composed_dofs[ss]->modify(
2211 dit, NumeredDofEntity_part_and_glob_idx_change(part_number,
2212 petsc_global_dof));
2213 if (!success) {
2214 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2215 "modification unsuccessful");
2216 }
2217 }
2218
2219 CHKERR AODestroy(&ao);
2220
2221 } else {
2222
2223 for (NumeredDofEntity_multiIndex::iterator dit = copied_dofs[ss]->begin();
2224 dit != copied_dofs[ss]->end(); dit++) {
2225 std::pair<NumeredDofEntity_multiIndex::iterator, bool> p;
2226 p = composed_dofs[ss]->insert(boost::shared_ptr<NumeredDofEntity>(
2227 new NumeredDofEntity((*dit)->getDofEntityPtr())));
2228 if (p.second) {
2229 (*nb_dofs[ss])++;
2230 }
2231 int part_number = (*dit)->getPart(); // get part number
2232 int petsc_global_dof = (*dit)->getPetscGlobalDofIdx();
2233 if (part_number == (unsigned int)m_field.get_comm_rank()) {
2234 const bool success = composed_dofs[ss]->modify(
2235 p.first, NumeredDofEntity_part_and_indices_change(
2236 part_number, petsc_global_dof,
2237 (*nb_local_dofs[ss])++));
2238 if (!success) {
2239 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2240 "modification unsuccessful");
2241 }
2242 } else {
2243 const bool success = composed_dofs[ss]->modify(
2244 p.first, NumeredDofEntity_part_and_glob_idx_change(
2245 part_number, petsc_global_dof));
2246 if (!success) {
2247 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2248 "modification unsuccessful");
2249 }
2250 }
2251 }
2252 }
2253 }
2254
2255 CHKERR printPartitionedProblem(&*p_miit, verb);
2256 CHKERR debugPartitionedProblem(&*p_miit, verb);
2257
2259}
NumeredDofEntity_multiIndex::index< Unique_mi_tag >::type NumeredDofEntityByUId
Numbered DoF multi-index by UId.

◆ markDofs()

MoFEMErrorCode MoFEM::ProblemsManager::markDofs ( const std::string  problem_name,
RowColData  rc,
std::vector< boost::weak_ptr< NumeredDofEntity > > &  vec_dof_view,
const enum MarkOP  op,
std::vector< unsigned char > &  marker 
) const

#include <src/interfaces/ProblemsManager.hpp>

Create vector with marked DOF indices based on DOF view.

Creates or modifies a marker vector based on a DOF view, allowing selective marking of DOFs that are present in the view. This is useful for creating masks or index sets for specific DOF collections in matrix/vector operations.

Parameters
problem_namename of the problem
rcrow or column data specification
vec_dof_viewvector of DOF entities to process for marking
opmarking operation (OR, AND, XOR) to apply
markerreference to marker vector to create/modify
Returns
MoFEMErrorCode Error code indicating success or failure

Definition at line 3892 of file ProblemsManager.cpp.

3898 {
3899 Interface &m_field = cOre;
3901
3902 const Problem *problem_ptr;
3903 CHKERR m_field.get_problem(problem_name, &problem_ptr);
3904 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
3905 switch (rc) {
3906 case ROW:
3907 dofs = problem_ptr->getNumeredRowDofsPtr();
3908 break;
3909 case COL:
3910 dofs = problem_ptr->getNumeredColDofsPtr();
3911 break;
3912 default:
3913 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
3914 }
3915 marker.resize(dofs->size(), 0);
3916
3917 for (auto &dof : vec_dof_view) {
3918 if (auto dof_ptr = dof.lock()) {
3919 if (dof_ptr->getPetscLocalDofIdx() < 0)
3920 continue;
3921 if (op == MarkOP::OR)
3922 marker[dof_ptr->getPetscLocalDofIdx()] |= 1;
3923 else
3924 marker[dof_ptr->getPetscLocalDofIdx()] &= 1;
3925 }
3926 }
3927
3929}
auto marker
set bit to marker

◆ modifyMarkDofs()

MoFEMErrorCode MoFEM::ProblemsManager::modifyMarkDofs ( const std::string  problem_name,
RowColData  rc,
const std::string  field_name,
const int  lo,
const int  hi,
const enum MarkOP  op,
const unsigned char  c,
std::vector< unsigned char > &  marker 
) const

#include <src/interfaces/ProblemsManager.hpp>

Modify DOF markers for specific field and coefficient range.

Modifies the marker flags for DOFs associated with a specific field within a defined coefficient range. This allows selective marking/unmarking of DOFs based on field and polynomial order criteria using bitwise operations.

Parameters
problem_namename of the problem
rcrow or column data specification
field_namename of the field to process
lolowest coefficient (rank) to include
hihighest coefficient (rank) to include
opmarking operation (OR, AND, XOR) to apply
cmarker value to apply with the operation
markerreference to marker vector to modify
Returns
MoFEMErrorCode Error code indicating success or failure

Definition at line 3842 of file ProblemsManager.cpp.

3845 {
3846
3847 Interface &m_field = cOre;
3848 const Problem *problem_ptr;
3850 CHKERR m_field.get_problem(problem_name, &problem_ptr);
3851 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
3852 switch (rc) {
3853 case ROW:
3854 dofs = problem_ptr->getNumeredRowDofsPtr();
3855 break;
3856 case COL:
3857 dofs = problem_ptr->getNumeredColDofsPtr();
3858 default:
3859 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
3860 }
3861 marker.resize(dofs->size(), 0);
3862
3863 auto dof_lo = dofs->get<Unique_mi_tag>().lower_bound(
3864 FieldEntity::getLoBitNumberUId(m_field.get_field_bit_number(field_name)));
3865 auto dof_hi = dofs->get<Unique_mi_tag>().upper_bound(
3866 FieldEntity::getHiBitNumberUId(m_field.get_field_bit_number(field_name)));
3867
3868 switch (op) {
3869 case MarkOP::OR:
3870 for (; dof_lo != dof_hi; ++dof_lo) {
3871 if ((*dof_lo)->getPetscLocalDofIdx() < 0)
3872 continue;
3873 if ((*dof_lo)->getDofCoeffIdx() >= lo &&
3874 (*dof_lo)->getDofCoeffIdx() <= hi)
3875 marker[(*dof_lo)->getPetscLocalDofIdx()] |= c;
3876 }
3877 break;
3878 case MarkOP::AND:
3879 for (; dof_lo != dof_hi; ++dof_lo) {
3880 if ((*dof_lo)->getPetscLocalDofIdx() < 0)
3881 continue;
3882 if ((*dof_lo)->getDofCoeffIdx() >= lo &&
3883 (*dof_lo)->getDofCoeffIdx() <= hi)
3884 marker[(*dof_lo)->getPetscLocalDofIdx()] &= c;
3885 }
3886 break;
3887 }
3888
3890}
const double c
speed of light (cm/ns)

◆ partitionFiniteElements()

MoFEMErrorCode MoFEM::ProblemsManager::partitionFiniteElements ( const std::string  name,
bool  part_from_moab = false,
int  low_proc = -1,
int  hi_proc = -1,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

partition finite elements

Function which partition finite elements based on dofs partitioning. In addition it sets information about local row and cols dofs at given element on partition. Can optionally use MOAB's partitioning information or restrict partitioning to specific processor ranges.

Parameters
nameproblem name to partition finite elements for
part_from_moabif true, use MOAB's existing partition information
low_proclowest processor rank to include (-1 for all)
hi_prochighest processor rank to include (-1 for all)
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure
Examples
mofem/atom_tests/build_composite_problem.cpp, mofem/atom_tests/build_problems.cpp, mofem/atom_tests/continuity_check_on_skeleton_3d.cpp, mofem/atom_tests/forces_and_sources_testing_edge_element.cpp, mofem/atom_tests/forces_and_sources_testing_flat_prism_element.cpp, mofem/atom_tests/hcurl_divergence_operator_2d.cpp, mofem/atom_tests/mesh_insert_interface_atom.cpp, mofem/atom_tests/prism_elements_from_surface.cpp, mofem/atom_tests/prism_polynomial_approximation.cpp, mofem/atom_tests/quad_polynomial_approximation.cpp, mofem/atom_tests/remove_entities_from_problem.cpp, mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp, and mofem/users_modules/basic_finite_elements/nonlinear_elasticity/nonlinear_dynamics.cpp.

Definition at line 2364 of file ProblemsManager.cpp.

2367 {
2368 MoFEM::Interface &m_field = cOre;
2369 auto problems_ptr = m_field.get_problems();
2370 auto fe_ent_ptr = m_field.get_ents_finite_elements();
2372
2374 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY, "fields not build");
2375
2377 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY, "FEs not build");
2378
2380 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2381 "adjacencies not build");
2382
2384 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY, "problem not build");
2385
2387 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2388 "problem not partitioned");
2389
2390 if (low_proc == -1)
2391 low_proc = m_field.get_comm_rank();
2392 if (hi_proc == -1)
2393 hi_proc = m_field.get_comm_rank();
2394
2395 // Find pointer to problem of given name
2396 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemByName;
2397 auto &problems =
2398 const_cast<ProblemByName &>(problems_ptr->get<Problem_mi_tag>());
2399 ProblemByName::iterator p_miit = problems.find(name);
2400 if (p_miit == problems.end()) {
2401 SETERRQ(m_field.get_comm(), MOFEM_NOT_FOUND,
2402 "problem < %s > not found (top tip: check spelling)",
2403 name.c_str());
2404 }
2405
2406 // Get reference on finite elements multi-index on the problem
2407 NumeredEntFiniteElement_multiIndex &problem_finite_elements =
2408 *p_miit->numeredFiniteElementsPtr;
2409
2410 // Clear all elements and data, build it again
2411 problem_finite_elements.clear();
2412
2413 // Check if dofs and columns are the same, i.e. structurally symmetric
2414 // problem
2415 bool do_cols_prob = true;
2416 if (p_miit->numeredRowDofsPtr == p_miit->numeredColDofsPtr) {
2417 do_cols_prob = false;
2418 }
2419
2420 auto get_good_elems = [&]() {
2421 auto good_elems = std::vector<decltype(fe_ent_ptr->begin())>();
2422 good_elems.reserve(fe_ent_ptr->size());
2423
2424 const auto prb_bit = p_miit->getBitRefLevel();
2425 const auto prb_mask = p_miit->getBitRefLevelMask();
2426
2427 // Loop over all elements in database and if right element is there add it
2428 // to problem finite element multi-index
2429 for (auto efit = fe_ent_ptr->begin(); efit != fe_ent_ptr->end(); ++efit) {
2430
2431 // if element is not part of problem
2432 if (((*efit)->getId() & p_miit->getBitFEId()).any()) {
2433
2434 const auto &fe_bit = (*efit)->getBitRefLevel();
2435
2436 // if entity is not problem refinement level
2437 if ((fe_bit & prb_mask) == fe_bit && (fe_bit & prb_bit).any())
2438 good_elems.emplace_back(efit);
2439 }
2440 }
2441
2442 return good_elems;
2443 };
2444
2445 auto good_elems = get_good_elems();
2446
2447 auto numbered_good_elems_ptr =
2448 boost::make_shared<std::vector<NumeredEntFiniteElement>>();
2449 numbered_good_elems_ptr->reserve(good_elems.size());
2450 for (auto &efit : good_elems)
2451 numbered_good_elems_ptr->emplace_back(NumeredEntFiniteElement(*efit));
2452
2453 if (!do_cols_prob) {
2454 for (auto &fe : *numbered_good_elems_ptr) {
2455 if (fe.sPtr->getRowFieldEntsPtr() == fe.sPtr->getColFieldEntsPtr()) {
2456 fe.getColFieldEntsPtr() = fe.getRowFieldEntsPtr();
2457 }
2458 }
2459 }
2460
2461 if (part_from_moab) {
2462 for (auto &fe : *numbered_good_elems_ptr) {
2463 // All imported elements belong to rank zero in a serial communicator.
2464 if (m_field.get_comm_size() == 1 || fe.getEntType() == MBENTITYSET) {
2465 fe.part = m_field.get_comm_rank();
2466 } else {
2467 // if partition is taken from moab partition
2468 int proc = fe.getPartProc();
2469 if (proc == -1 && fe.getEntType() == MBVERTEX)
2470 proc = fe.getOwnerProc();
2471 fe.part = proc;
2472 }
2473 }
2474 }
2475
2476 // The element's row DOF view is needed only to vote on its part when the
2477 // partition is not taken from MOAB and there is more than one rank.
2478 if (!part_from_moab) {
2479 for (auto &fe : *numbered_good_elems_ptr) {
2480 if (fe.getEntType() == MBENTITYSET || m_field.get_comm_size() == 1) {
2481 fe.part = m_field.get_comm_rank();
2482 } else {
2484 CHKERR fe.sPtr->getRowDofView(*(p_miit->numeredRowDofsPtr), rows_view);
2485 std::vector<int> parts(m_field.get_comm_size(), 0);
2486 for (auto &dof_ptr : rows_view)
2487 parts[dof_ptr->pArt]++;
2488 std::vector<int>::iterator pos =
2489 max_element(parts.begin(), parts.end());
2490 const auto max_part = std::distance(parts.begin(), pos);
2491 fe.part = max_part;
2492 }
2493 }
2494 }
2495
2496 for (auto &fe : *numbered_good_elems_ptr) {
2497
2498 auto check_fields_and_dofs = [&]() {
2499 if (!part_from_moab) {
2500 if (fe.getBitFieldIdRow().none() && m_field.get_comm_size() == 0) {
2501 MOFEM_LOG("WORLD", Sev::warning)
2502 << "At least one field has to be added to element row to "
2503 "determine partition of finite element. Check element " +
2504 boost::lexical_cast<std::string>(fe.getName());
2505 }
2506 }
2507
2508 return true;
2509 };
2510
2511 if (check_fields_and_dofs()) {
2512 // Add element to the problem
2513 auto p = problem_finite_elements.insert(
2514 boost::shared_ptr<NumeredEntFiniteElement>(numbered_good_elems_ptr,
2515 &fe));
2516 if (!p.second)
2517 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "element is there");
2518 }
2519 }
2520
2521 if (verb >= VERBOSE) {
2522 auto elements_on_rank =
2523 problem_finite_elements.get<Part_mi_tag>().equal_range(
2524 m_field.get_comm_rank());
2525 MOFEM_LOG("SYNC", Sev::verbose)
2526 << p_miit->getName() << " nb. elems "
2527 << std::distance(elements_on_rank.first, elements_on_rank.second);
2528 auto fe_ptr = m_field.get_finite_elements();
2529 for (auto &fe : *fe_ptr) {
2530 auto e_range =
2531 problem_finite_elements.get<Composite_Name_And_Part_mi_tag>()
2532 .equal_range(
2533 boost::make_tuple(fe->getName(), m_field.get_comm_rank()));
2534 MOFEM_LOG("SYNC", Sev::noisy)
2535 << "Element " << fe->getName() << " nb. elems "
2536 << std::distance(e_range.first, e_range.second);
2537 }
2538
2540 }
2541
2544}
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
multi_index_container< boost::shared_ptr< NumeredEntFiniteElement >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< NumeredEntFiniteElement::interface_type_EntFiniteElement, UId, &NumeredEntFiniteElement::getLocalUniqueId > >, ordered_non_unique< tag< Part_mi_tag >, member< NumeredEntFiniteElement, unsigned int, &NumeredEntFiniteElement::part > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< NumeredEntFiniteElement::interface_type_RefEntity, EntityHandle, &NumeredEntFiniteElement::getEnt > >, ordered_non_unique< tag< Composite_Name_And_Part_mi_tag >, composite_key< NumeredEntFiniteElement, const_mem_fun< NumeredEntFiniteElement::interface_type_FiniteElement, boost::string_ref, &NumeredEntFiniteElement::getNameRef >, member< NumeredEntFiniteElement, unsigned int, &NumeredEntFiniteElement::part > > > > > NumeredEntFiniteElement_multiIndex
MultiIndex for entities for NumeredEntFiniteElement.
virtual const EntFiniteElement_multiIndex * get_ents_finite_elements() const =0
Get the ents finite elements object.
multi_index_container< boost::shared_ptr< NumeredDofEntity >, indexed_by< ordered_unique< const_mem_fun< NumeredDofEntity::interface_type_DofEntity, UId, &NumeredDofEntity::getLocalUniqueId > > > > NumeredDofEntity_multiIndex_uid_view_ordered

◆ partitionGhostDofs()

MoFEMErrorCode MoFEM::ProblemsManager::partitionGhostDofs ( const std::string  name,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

determine ghost nodes

Identifies and marks DOFs as ghost DOFs for parallel computations. DOFs are ghost dofs if they are used by elements on a given partition but not owned by that partition.

Parameters
nameproblem name to determine ghost DOFs for
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure
Examples
mofem/atom_tests/build_composite_problem.cpp, mofem/atom_tests/build_problems.cpp, mofem/atom_tests/continuity_check_on_skeleton_3d.cpp, mofem/atom_tests/forces_and_sources_testing_edge_element.cpp, mofem/atom_tests/forces_and_sources_testing_flat_prism_element.cpp, mofem/atom_tests/hcurl_divergence_operator_2d.cpp, mofem/atom_tests/mesh_insert_interface_atom.cpp, mofem/atom_tests/prism_elements_from_surface.cpp, mofem/atom_tests/prism_polynomial_approximation.cpp, mofem/atom_tests/quad_polynomial_approximation.cpp, mofem/atom_tests/remove_entities_from_problem.cpp, mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp, and mofem/users_modules/basic_finite_elements/nonlinear_elasticity/nonlinear_dynamics.cpp.

Definition at line 2546 of file ProblemsManager.cpp.

2547 {
2548 MoFEM::Interface &m_field = cOre;
2549 auto problems_ptr = m_field.get_problems();
2551
2553 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2554 "partition of problem not build");
2556 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2557 "partitions finite elements not build");
2558
2559 // get problem pointer
2560 auto p_miit = problems_ptr->get<Problem_mi_tag>().find(name);
2561 if (p_miit == problems_ptr->get<Problem_mi_tag>().end())
2562 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "Problem %s not fond",
2563 name.c_str());
2564
2565 // get reference to number of ghost dofs
2566 int &nb_row_ghost_dofs = p_miit->nbGhostDofsRow;
2567 int &nb_col_ghost_dofs = p_miit->nbGhostDofsCol;
2568 nb_row_ghost_dofs = 0;
2569 nb_col_ghost_dofs = 0;
2570
2571 // do work if more than one processor
2572 if (m_field.get_comm_size() > 1) {
2573
2575 ghost_idx_col_view;
2576
2577 // get elements on this partition
2578 auto fe_range =
2579 p_miit->numeredFiniteElementsPtr->get<Part_mi_tag>().equal_range(
2580 m_field.get_comm_rank());
2581
2582 // get dofs on elements which are not part of this partition
2583
2584 struct Inserter {
2585 using Vec = std::vector<boost::shared_ptr<NumeredDofEntity>>;
2586 using It = Vec::iterator;
2587 It operator()(Vec &dofs_view, It &hint,
2588 boost::shared_ptr<NumeredDofEntity> &&dof) {
2589 dofs_view.emplace_back(dof);
2590 return dofs_view.end();
2591 }
2592 };
2593
2594 // rows
2595 std::vector<boost::shared_ptr<NumeredDofEntity>> fe_vec_view;
2596 auto hint_r = ghost_idx_row_view.begin();
2597 for (auto fe_ptr = fe_range.first; fe_ptr != fe_range.second; ++fe_ptr) {
2598
2599 fe_vec_view.clear();
2600 CHKERR EntFiniteElement::getDofView((*fe_ptr)->getRowFieldEnts(),
2601 *(p_miit->getNumeredRowDofsPtr()),
2602 fe_vec_view, Inserter());
2603
2604 for (auto &dof_ptr : fe_vec_view) {
2605 if (dof_ptr->getPart() != (unsigned int)m_field.get_comm_rank()) {
2606 hint_r = ghost_idx_row_view.emplace_hint(hint_r, dof_ptr);
2607 ++hint_r;
2608 }
2609 }
2610 }
2611
2612 // columns
2613 if (p_miit->numeredColDofsPtr == p_miit->numeredRowDofsPtr) {
2614
2615 auto hint_c = ghost_idx_col_view.begin();
2616 for (auto fe_ptr = fe_range.first; fe_ptr != fe_range.second; ++fe_ptr) {
2617
2618 fe_vec_view.clear();
2619 CHKERR EntFiniteElement::getDofView((*fe_ptr)->getColFieldEnts(),
2620 *(p_miit->getNumeredColDofsPtr()),
2621 fe_vec_view, Inserter());
2622
2623 for (auto &dof_ptr : fe_vec_view) {
2624 if (dof_ptr->getPart() != (unsigned int)m_field.get_comm_rank()) {
2625 hint_c = ghost_idx_col_view.emplace_hint(hint_c, dof_ptr);
2626 ++hint_c;
2627 }
2628 }
2629 }
2630 }
2631
2632 int *nb_ghost_dofs[2] = {&nb_row_ghost_dofs, &nb_col_ghost_dofs};
2633 int nb_local_dofs[2] = {p_miit->nbLocDofsRow, p_miit->nbLocDofsCol};
2634
2636 &ghost_idx_row_view, &ghost_idx_col_view};
2637 NumeredDofEntityByUId *dof_by_uid_no_const[2] = {
2638 &p_miit->numeredRowDofsPtr->get<Unique_mi_tag>(),
2639 &p_miit->numeredColDofsPtr->get<Unique_mi_tag>()};
2640
2641 int loop_size = 2;
2642 if (p_miit->numeredColDofsPtr == p_miit->numeredRowDofsPtr) {
2643 loop_size = 1;
2644 }
2645
2646 // set local ghost dofs indices
2647 for (int ss = 0; ss != loop_size; ++ss) {
2648 for (auto &gid : *ghost_idx_view[ss]) {
2649 NumeredDofEntityByUId::iterator dof =
2650 dof_by_uid_no_const[ss]->find(gid->getLocalUniqueId());
2651 if (PetscUnlikely((*dof)->petscLocalDofIdx != (DofIdx)-1))
2652 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2653 "inconsistent data, ghost dof already set");
2654 bool success = dof_by_uid_no_const[ss]->modify(
2655 dof, NumeredDofEntity_local_idx_change(nb_local_dofs[ss]++));
2656 if (PetscUnlikely(!success))
2657 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2658 "modification unsuccessful");
2659 (*nb_ghost_dofs[ss])++;
2660 }
2661 }
2662 if (loop_size == 1) {
2663 (*nb_ghost_dofs[1]) = (*nb_ghost_dofs[0]);
2664 }
2665 }
2666
2667 if (verb > QUIET) {
2668 MOFEM_LOG("SYNC", Sev::inform)
2669 << " FEs ghost dofs on problem " << p_miit->getName()
2670 << " Nb. ghost dof " << p_miit->getNbGhostDofsRow() << " by "
2671 << p_miit->getNbGhostDofsCol() << " Nb. local dof "
2672 << p_miit->getNbLocalDofsRow() << " by " << p_miit->getNbLocalDofsCol();
2673
2675 }
2676
2679}
const FTensor::Tensor2< T, Dim, Dim > Vec
int DofIdx
Index of DOF.
Definition Types.hpp:18
static MoFEMErrorCode getDofView(const FE_ENTS &fe_ents_view, const MOFEM_DOFS &mofem_dofs, MOFEM_DOFS_VIEW &dofs_view, INSERTER &&inserter)

◆ partitionGhostDofsOnDistributedMesh()

MoFEMErrorCode MoFEM::ProblemsManager::partitionGhostDofsOnDistributedMesh ( const std::string  name,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

determine ghost nodes on distributed meshes

Identifies and marks DOFs as ghost DOFs specifically for distributed meshes. This function is similar to partitionGhostDofs but exploits the fact that the mesh is distributed across processors. DOFs are ghosted if they are shared but not owned by the current partition.

Parameters
nameproblem name to determine ghost DOFs for
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure
Examples
mofem/atom_tests/remove_entities_from_problem.cpp.

Definition at line 2682 of file ProblemsManager.cpp.

2683 {
2684 MoFEM::Interface &m_field = cOre;
2685 auto problems_ptr = m_field.get_problems();
2687
2689 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2690 "partition of problem not build");
2692 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2693 "partitions finite elements not build");
2694
2695 // get problem pointer
2696 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
2697 // find p_miit
2698 ProblemsByName &problems_set =
2699 const_cast<ProblemsByName &>(problems_ptr->get<Problem_mi_tag>());
2700 ProblemsByName::iterator p_miit = problems_set.find(name);
2701
2702 // get reference to number of ghost dofs
2703 // get number of local dofs
2704 DofIdx *nb_ghost_dofs[2] = {&(p_miit->nbGhostDofsRow),
2705 &(p_miit->nbGhostDofsCol)};
2706 DofIdx nb_local_dofs[2] = {p_miit->nbLocDofsRow, p_miit->nbLocDofsCol};
2707 for (int ss = 0; ss != 2; ++ss) {
2708 (*nb_ghost_dofs[ss]) = 0;
2709 }
2710
2711 // do work if more than one processor
2712 if (m_field.get_comm_size() > 1) {
2713 // determine if rows on columns are different from dofs on rows
2714 int loop_size = 2;
2715 if (p_miit->numeredColDofsPtr == p_miit->numeredRowDofsPtr) {
2716 loop_size = 1;
2717 }
2718
2719 typedef decltype(p_miit->numeredRowDofsPtr) NumbDofTypeSharedPtr;
2720 NumbDofTypeSharedPtr numered_dofs[] = {p_miit->numeredRowDofsPtr,
2721 p_miit->numeredColDofsPtr};
2722
2723 // iterate over dofs on rows and dofs on columns
2724 for (int ss = 0; ss != loop_size; ++ss) {
2725
2726 // create dofs view by uid
2727 auto r = numered_dofs[ss]->get<PetscLocalIdx_mi_tag>().equal_range(-1);
2728
2729 std::vector<NumeredDofEntity_multiIndex::iterator> ghost_idx_view;
2730 ghost_idx_view.reserve(std::distance(r.first, r.second));
2731 for (; r.first != r.second; ++r.first)
2732 ghost_idx_view.emplace_back(numered_dofs[ss]->project<0>(r.first));
2733
2734 auto cmp = [](auto a, auto b) {
2735 return (*a)->getLocalUniqueId() < (*b)->getLocalUniqueId();
2736 };
2737 sort(ghost_idx_view.begin(), ghost_idx_view.end(), cmp);
2738
2739 // iterate over dofs which have negative local index
2740 for (auto gid_it : ghost_idx_view) {
2741 bool success = numered_dofs[ss]->modify(
2742 gid_it, NumeredDofEntity_local_idx_change((nb_local_dofs[ss])++));
2743 if (!success)
2744 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
2745 "modification unsuccessful");
2746 ++(*nb_ghost_dofs[ss]);
2747 }
2748 }
2749 if (loop_size == 1) {
2750 (*nb_ghost_dofs[1]) = (*nb_ghost_dofs[0]);
2751 }
2752 }
2753
2754 if (verb > QUIET) {
2755 MOFEM_LOG("SYNC", Sev::inform)
2756 << " FEs ghost dofs on problem " << p_miit->getName()
2757 << " Nb. ghost dof " << p_miit->getNbGhostDofsRow() << " by "
2758 << p_miit->getNbGhostDofsCol() << " Nb. local dof "
2759 << p_miit->getNbLocalDofsRow() << " by " << p_miit->getNbLocalDofsCol();
2760
2762 }
2763
2766}

◆ partitionMesh() [1/2]

MoFEMErrorCode MoFEM::ProblemsManager::partitionMesh ( const Range &  ents,
const int  dim,
const int  adj_dim,
const int  n_parts,
Tag *  th_vertex_weights = nullptr,
Tag *  th_edge_weights = nullptr,
Tag *  th_part_weights = nullptr,
int  verb = VERBOSE,
const bool  debug = false 
)

#include <src/interfaces/ProblemsManager.hpp>

Set partition tag to each finite element in the problem.

Deprecated:
Use CommInterface

This will use one of the mesh partitioning programs available from PETSc See http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatPartitioningType.html

Parameters
entsEntities to partition
dimDimension of entities to partition
adj_dimAdjacency dimension
n_partsNumber of partitions
verbVerbosity level
Returns
Error code

Definition at line 137 of file ProblemsManager.cpp.

140 {
141 return static_cast<MoFEM::Interface &>(cOre)
142 .getInterface<CommInterface>()
143 ->partitionMesh(ents, dim, adj_dim, n_parts, th_vertex_weights,
144 th_edge_weights, th_part_weights, verb, debug);
145}

◆ partitionMesh() [2/2]

MoFEMErrorCode MoFEM::CommInterface::partitionMesh ( const Range &  ents,
const int  dim,
const int  adj_dim,
const int  n_parts,
Tag *  th_vertex_weights = nullptr,
Tag *  th_edge_weights = nullptr,
Tag *  th_part_weights = nullptr,
int  verb = VERBOSE,
const bool  debug = false,
const bool  preserve_vertex_ids = false 
)

#include <src/interfaces/CommInterface.hpp>

Set partition tag to each finite element in the problem.

This will use one of the mesh partitioning programs available from PETSc See http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatPartitioningType.html

Parameters
entsEntities to partition
dimDimension of entities to partition
adj_dimAdjacency dimension
n_partsNumber of partitions
verbVerbosity level
Returns
Error code
Examples
mofem/atom_tests/build_composite_problem.cpp, and mofem/atom_tests/partition_mesh.cpp.

Definition at line 1630 of file CommInterface.cpp.

1633 {
1634 MoFEM::Interface &m_field = cOre;
1636
1637 // get layout
1638 int rstart, rend, nb_elems;
1639 {
1640 PetscLayout layout;
1641 CHKERR PetscLayoutCreate(m_field.get_comm(), &layout);
1642 CHKERR PetscLayoutSetBlockSize(layout, 1);
1643 CHKERR PetscLayoutSetSize(layout, ents.size());
1644 CHKERR PetscLayoutSetUp(layout);
1645 CHKERR PetscLayoutGetSize(layout, &nb_elems);
1646 CHKERR PetscLayoutGetRange(layout, &rstart, &rend);
1647 CHKERR PetscLayoutDestroy(&layout);
1648 if (verb >= VERBOSE) {
1649 MOFEM_LOG("SYNC", Sev::inform)
1650 << "Finite elements in problem: row lower " << rstart << " row upper "
1651 << rend << " nb. elems " << nb_elems << " ( " << ents.size() << " )";
1653 }
1654 }
1655
1656 std::vector<EntityHandle> weight_ents;
1657 weight_ents.reserve(rend - rstart + 1);
1658
1659 struct AdjBridge {
1660 EntityHandle ent;
1661 std::vector<int> adj;
1662 AdjBridge(const EntityHandle ent, std::vector<int> &adj)
1663 : ent(ent), adj(adj) {}
1664 };
1665
1666 typedef multi_index_container<
1667 AdjBridge,
1668 indexed_by<
1669
1670 hashed_unique<member<AdjBridge, EntityHandle, &AdjBridge::ent>>
1671
1672 >>
1673 AdjBridgeMap;
1674
1675 auto get_it = [&](auto i) {
1676 auto it = ents.begin();
1677 for (; i > 0; --i) {
1678 if (it == ents.end())
1679 break;
1680 ++it;
1681 }
1682 return it;
1683 };
1684
1685 Range proc_ents;
1686 proc_ents.insert(get_it(rstart), get_it(rend));
1687 if (proc_ents.size() != rend - rstart)
1688 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
1689 "Wrong number of elements in range %zu != %zu", proc_ents.size(),
1690 static_cast<size_t>(rend - rstart));
1691
1692 Range all_dim_ents;
1693 CHKERR m_field.get_moab().get_adjacencies(
1694 proc_ents, adj_dim, true, all_dim_ents, moab::Interface::UNION);
1695
1696 AdjBridgeMap adj_bridge_map;
1697 auto hint = adj_bridge_map.begin();
1698 std::vector<int> adj;
1699 for (auto ent : all_dim_ents) {
1700 Range adj_ents;
1701 CHKERR m_field.get_moab().get_adjacencies(&ent, 1, dim, false, adj_ents);
1702 adj_ents = intersect(adj_ents, ents);
1703 adj.clear();
1704 adj.reserve(adj_ents.size());
1705 for (auto a : adj_ents)
1706 adj.emplace_back(ents.index(a));
1707 hint = adj_bridge_map.emplace_hint(hint, ent, adj);
1708 }
1709
1710 int *_i;
1711 int *_j;
1712 {
1713 const int nb_loc_elements = rend - rstart;
1714 std::vector<int> i(nb_loc_elements + 1, 0), j;
1715 {
1716 std::vector<int> row_adj;
1717 Range::iterator fe_it;
1718 int ii, jj;
1719 size_t max_row_size;
1720 for (fe_it = proc_ents.begin(), ii = rstart, jj = 0, max_row_size = 0;
1721 fe_it != proc_ents.end(); ++fe_it, ++ii) {
1722
1723 if (type_from_handle(*fe_it) == MBENTITYSET) {
1724 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
1725 "not yet implemented, don't know what to do for meshset "
1726 "element");
1727 } else {
1728
1729 Range dim_ents;
1730 CHKERR m_field.get_moab().get_adjacencies(&*fe_it, 1, adj_dim, false,
1731 dim_ents);
1732 dim_ents = intersect(dim_ents, all_dim_ents);
1733
1734 row_adj.clear();
1735 for (auto e : dim_ents) {
1736 auto adj_it = adj_bridge_map.find(e);
1737 if (adj_it != adj_bridge_map.end()) {
1738
1739 for (const auto idx : adj_it->adj)
1740 row_adj.push_back(idx);
1741
1742 } else
1743 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1744 "Entity not found");
1745 }
1746
1747 std::sort(row_adj.begin(), row_adj.end());
1748 auto end = std::unique(row_adj.begin(), row_adj.end());
1749
1750 size_t row_size = std::distance(row_adj.begin(), end);
1751 max_row_size = std::max(max_row_size, row_size);
1752 if (j.capacity() < (nb_loc_elements - jj) * max_row_size)
1753 j.reserve(nb_loc_elements * max_row_size);
1754
1755 i[jj] = j.size();
1756 auto diag = ents.index(*fe_it);
1757 for (auto it = row_adj.begin(); it != end; ++it)
1758 if (*it != diag)
1759 j.push_back(*it);
1760 }
1761
1762 ++jj;
1763
1764 if (th_vertex_weights != NULL)
1765 weight_ents.push_back(*fe_it);
1766 }
1767
1768 i[jj] = j.size();
1769 }
1770
1771 CHKERR PetscMalloc(i.size() * sizeof(int), &_i);
1772 CHKERR PetscMalloc(j.size() * sizeof(int), &_j);
1773 copy(i.begin(), i.end(), _i);
1774 copy(j.begin(), j.end(), _j);
1775 }
1776
1777 // get weights
1778 int *vertex_weights = NULL;
1779 if (th_vertex_weights != NULL) {
1780 CHKERR PetscMalloc(weight_ents.size() * sizeof(int), &vertex_weights);
1781 CHKERR m_field.get_moab().tag_get_data(*th_vertex_weights,
1782 &*weight_ents.begin(),
1783 weight_ents.size(), vertex_weights);
1784 }
1785
1786 {
1787 Mat Adj;
1788 // Adjacency matrix used to partition problems, f.e. METIS
1789 CHKERR MatCreateMPIAdj(m_field.get_comm(), rend - rstart, nb_elems, _i, _j,
1790 PETSC_NULLPTR, &Adj);
1791 CHKERR MatSetOption(Adj, MAT_STRUCTURALLY_SYMMETRIC, PETSC_TRUE);
1792
1793 if (debug) {
1794 Mat A;
1795 CHKERR MatConvert(Adj, MATMPIAIJ, MAT_INITIAL_MATRIX, &A);
1796 CHKERR MatView(A, PETSC_VIEWER_DRAW_WORLD);
1797 std::string wait;
1798 std::cin >> wait;
1799 CHKERR MatDestroy(&A);
1800 }
1801
1802 // run pets to do partitioning
1803 MOFEM_LOG("WORLD", Sev::verbose) << "Start";
1804
1805 MatPartitioning part;
1806 IS is;
1807 CHKERR MatPartitioningCreate(m_field.get_comm(), &part);
1808
1809 CHKERR MatPartitioningSetAdjacency(part, Adj);
1810 CHKERR MatPartitioningSetFromOptions(part);
1811 CHKERR MatPartitioningSetNParts(part, n_parts);
1812 if (th_vertex_weights != NULL) {
1813 CHKERR MatPartitioningSetVertexWeights(part, vertex_weights);
1814 }
1815 CHKERR MatPartitioningApply(part, &is);
1816
1817 MOFEM_LOG("WORLD", Sev::verbose) << "End";
1818
1819 // gather
1820 IS is_gather, is_num, is_gather_num;
1821 CHKERR ISAllGather(is, &is_gather);
1822 CHKERR ISPartitioningToNumbering(is, &is_num);
1823 CHKERR ISAllGather(is_num, &is_gather_num);
1824
1825 const int *part_number, *gids;
1826 CHKERR ISGetIndices(is_gather, &part_number);
1827 CHKERR ISGetIndices(is_gather_num, &gids);
1828
1829 // set partition tag and gid tag to entities
1830 ParallelComm *pcomm = ParallelComm::get_pcomm(
1831 &m_field.get_moab(), m_field.get_basic_entity_data_ptr()->pcommID);
1832 Tag part_tag = pcomm->part_tag();
1833 CHKERR m_field.get_moab().tag_set_data(part_tag, ents, part_number);
1834 Tag gid_tag = m_field.get_moab().globalId_tag();
1835
1836 std::map<int, Range> parts_ents;
1837 {
1838 // get entities on each part
1839 Range::iterator eit = ents.begin();
1840 for (int ii = 0; eit != ents.end(); eit++, ii++) {
1841 parts_ents[part_number[ii]].insert(*eit);
1842 }
1843 Range tagged_sets;
1844 CHKERR m_field.get_moab().get_entities_by_type_and_tag(
1845 0, MBENTITYSET, &part_tag, NULL, 1, tagged_sets,
1846 moab::Interface::UNION);
1847 if (!tagged_sets.empty())
1848 CHKERR m_field.get_moab().tag_delete_data(part_tag, tagged_sets);
1849
1850 if (n_parts > (int)tagged_sets.size()) {
1851 // too few partition sets - create missing ones
1852 int num_new = n_parts - tagged_sets.size();
1853 for (int i = 0; i < num_new; i++) {
1854 EntityHandle new_set;
1855 CHKERR m_field.get_moab().create_meshset(MESHSET_SET, new_set);
1856 tagged_sets.insert(new_set);
1857 }
1858 } else if (n_parts < (int)tagged_sets.size()) {
1859 // too many partition sets - delete extras
1860 int num_del = tagged_sets.size() - n_parts;
1861 for (int i = 0; i < num_del; i++) {
1862 EntityHandle old_set = tagged_sets.pop_back();
1863 CHKERR m_field.get_moab().delete_entities(&old_set, 1);
1864 }
1865 }
1866 // write a tag to those sets denoting they're partition sets, with a
1867 // value of the proc number
1868 std::vector<int> dum_ids(n_parts);
1869 for (int i = 0; i < n_parts; i++)
1870 dum_ids[i] = i;
1871 CHKERR m_field.get_moab().tag_set_data(part_tag, tagged_sets,
1872 &*dum_ids.begin());
1873 CHKERR m_field.get_moab().clear_meshset(tagged_sets);
1874
1875 // get lower dimension entities on each part
1876 for (int pp = 0; pp != n_parts; pp++) {
1877 Range dim_ents = parts_ents[pp].subset_by_dimension(dim);
1878 for (int dd = dim - 1; dd >= 0; dd--) {
1879 Range adj_ents;
1880 CHKERR m_field.get_moab().get_adjacencies(
1881 dim_ents, dd, false, adj_ents, moab::Interface::UNION);
1882 parts_ents[pp].merge(adj_ents);
1883 }
1884 }
1885 for (int pp = 1; pp != n_parts; pp++) {
1886 for (int ppp = 0; ppp != pp; ppp++) {
1887 parts_ents[pp] = subtract(parts_ents[pp], parts_ents[ppp]);
1888 }
1889 }
1890
1891 for (int pp = 0; pp != n_parts; pp++) {
1892 CHKERR m_field.get_moab().add_entities(tagged_sets[pp], parts_ents[pp]);
1893 }
1894
1895 auto set_part = [&]() {
1897 for (EntityType t = MBEDGE; t != MBENTITYSET; ++t) {
1898 for (int pp = 0; pp != n_parts; pp++) {
1899 Range type_ents = parts_ents[pp].subset_by_type(t);
1900 CHKERR m_field.get_moab().tag_clear_data(part_tag, type_ents, &pp);
1901 }
1902 }
1904 };
1905
1906 auto set_gid = [&]() {
1908 for (int d = 0; d != 4; ++d) {
1909 if (d == 0 && preserve_vertex_ids)
1910 continue;
1911
1912 void *ptr;
1913 int count;
1914
1915 int gid = 1; // moab indexing from 1
1916 for (int pp = 0; pp != n_parts; pp++) {
1917 Range type_ents = parts_ents[pp].subset_by_dimension(d);
1918
1919 auto eit = type_ents.begin();
1920 for (; eit != type_ents.end();) {
1921 CHKERR m_field.get_moab().tag_iterate(
1922 gid_tag, eit, type_ents.end(), count, ptr);
1923 auto gid_tag_ptr = static_cast<int *>(ptr);
1924 for (; count > 0; --count) {
1925 *gid_tag_ptr = gid;
1926 ++eit;
1927 ++gid;
1928 ++gid_tag_ptr;
1929 }
1930 }
1931 }
1932 }
1933
1935 };
1936
1937 CHKERR set_part();
1938 CHKERR set_gid();
1939 }
1940
1941 if (debug) {
1942 if (m_field.get_comm_rank() == 0) {
1943 for (int rr = 0; rr != n_parts; rr++) {
1944 ostringstream ss;
1945 ss << "out_part_" << rr << ".vtk";
1946 MOFEM_LOG("SELF", Sev::inform) << "Save debug part mesh " << ss.str();
1947 EntityHandle meshset;
1948 CHKERR m_field.get_moab().create_meshset(MESHSET_SET, meshset);
1949 CHKERR m_field.get_moab().add_entities(meshset, parts_ents[rr]);
1950 CHKERR m_field.get_moab().write_file(ss.str().c_str(), "VTK", "",
1951 &meshset, 1);
1952 CHKERR m_field.get_moab().delete_entities(&meshset, 1);
1953 }
1954 }
1955 }
1956
1957 CHKERR ISRestoreIndices(is_gather, &part_number);
1958 CHKERR ISRestoreIndices(is_gather_num, &gids);
1959 CHKERR ISDestroy(&is_num);
1960 CHKERR ISDestroy(&is_gather_num);
1961 CHKERR ISDestroy(&is_gather);
1962 CHKERR ISDestroy(&is);
1963 CHKERR MatPartitioningDestroy(&part);
1964 CHKERR MatDestroy(&Adj);
1965 }
1966
1968}
std::map< EntityHandle, int > index
Vec t
Removal: the ring edge.
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'j', 3 > j
constexpr AssemblyType A

◆ partitionProblem()

MoFEMErrorCode MoFEM::ProblemsManager::partitionProblem ( const std::string  name,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

partition problem dofs (collective)

Partitions DOFs for distributed problems where the mesh is already distributed across processors. Must be called collectively on all processors in the communicator.

Parameters
nameproblem name to partition
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure
Examples
mofem/atom_tests/build_problems.cpp, mofem/atom_tests/continuity_check_on_skeleton_3d.cpp, mofem/atom_tests/mesh_insert_interface_atom.cpp, mofem/atom_tests/remove_entities_from_problem_not_partitioned.cpp, mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp, and mofem/users_modules/basic_finite_elements/nonlinear_elasticity/nonlinear_dynamics.cpp.

Definition at line 1872 of file ProblemsManager.cpp.

1873 {
1874 MoFEM::Interface &m_field = cOre;
1875 auto problems_ptr = m_field.get_problems();
1877
1878 MOFEM_LOG("WORLD", Sev::noisy) << "Partition problem " << name;
1879
1880 // DOFs are visited in UID order, which is the order of the provisional
1881 // global index set by buildProblem, through the UID index: the global
1882 // index is modified and must not be the iterated key.
1883 using NumeredDofEntitysByIdx =
1884 NumeredDofEntity_multiIndex::index<Unique_mi_tag>::type;
1885 using ProblemsByName = Problem_multiIndex::index<Problem_mi_tag>::type;
1886
1887 // Find problem pointer by name
1888 auto &problems_set =
1889 const_cast<ProblemsByName &>(problems_ptr->get<Problem_mi_tag>());
1890 auto p_miit = problems_set.find(name);
1891 if (p_miit == problems_set.end()) {
1892 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
1893 "problem with name %s not defined (top tip check spelling)",
1894 name.c_str());
1895 }
1896 int nb_dofs_row = p_miit->getNbDofsRow();
1897
1898 if (m_field.get_comm_size() != 1) {
1899
1900 if (!(cOre.getBuildMoFEM() & (1 << 0)))
1901 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
1902 if (!(cOre.getBuildMoFEM() & (1 << 1)))
1903 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
1904 if (!(cOre.getBuildMoFEM() & (1 << 2)))
1905 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1906 "entFEAdjacencies not build");
1907 if (!(cOre.getBuildMoFEM() & (1 << 3)))
1908 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Problems not build");
1909
1910 Mat Adj;
1911 CHKERR m_field.getInterface<MatrixManager>()
1912 ->createMPIAdjWithArrays<PetscGlobalIdx_mi_tag>(name, &Adj, verb);
1913
1914 int m, n;
1915 CHKERR MatGetSize(Adj, &m, &n);
1916 if (verb > VERY_VERBOSE)
1917 MatView(Adj, PETSC_VIEWER_STDOUT_WORLD);
1918
1919 // partitioning
1920 MatPartitioning part;
1921 IS is;
1922 CHKERR MatPartitioningCreate(m_field.get_comm(), &part);
1923 CHKERR MatPartitioningSetAdjacency(part, Adj);
1924 CHKERR MatPartitioningSetFromOptions(part);
1925 CHKERR MatPartitioningSetNParts(part, m_field.get_comm_size());
1926 CHKERR MatPartitioningApply(part, &is);
1927 if (verb > VERY_VERBOSE)
1928 ISView(is, PETSC_VIEWER_STDOUT_WORLD);
1929
1930 // gather
1931 IS is_gather, is_num, is_gather_num;
1932 CHKERR ISAllGather(is, &is_gather);
1933 CHKERR ISPartitioningToNumbering(is, &is_num);
1934 CHKERR ISAllGather(is_num, &is_gather_num);
1935 const int *part_number, *petsc_idx;
1936 CHKERR ISGetIndices(is_gather, &part_number);
1937 CHKERR ISGetIndices(is_gather_num, &petsc_idx);
1938 int size_is_num, size_is_gather;
1939 CHKERR ISGetSize(is_gather, &size_is_gather);
1940 if (size_is_gather != (int)nb_dofs_row)
1941 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
1942 "data inconsistency %d != %d", size_is_gather, nb_dofs_row);
1943
1944 CHKERR ISGetSize(is_num, &size_is_num);
1945 if (size_is_num != (int)nb_dofs_row)
1946 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
1947 "data inconsistency %d != %d", size_is_num, nb_dofs_row);
1948
1949 bool square_matrix = false;
1950 if (p_miit->numeredRowDofsPtr == p_miit->numeredColDofsPtr)
1951 square_matrix = true;
1952
1953 // if (!square_matrix) {
1954 // // FIXME: This is for back compatibility, if deprecate interface
1955 // function
1956 // // build interfaces is removed, this part of the code will be obsolete
1957 // auto mit_row = p_miit->numeredRowDofsPtr->get<Unique_mi_tag>().begin();
1958 // auto hi_mit_row = p_miit->numeredRowDofsPtr->get<Unique_mi_tag>().end();
1959 // auto mit_col = p_miit->numeredColDofsPtr->get<Unique_mi_tag>().begin();
1960 // auto hi_mit_col = p_miit->numeredColDofsPtr->get<Unique_mi_tag>().end();
1961 // for (; mit_row != hi_mit_row; mit_row++, mit_col++) {
1962 // if (mit_col == hi_mit_col) {
1963 // SETERRQ(
1964 // PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1965 // "check finite element definition, nb. of rows is not equal to "
1966 // "number for columns");
1967 // }
1968 // if (mit_row->get()->getLocalUniqueId() !=
1969 // mit_col->get()->getLocalUniqueId()) {
1970 // SETERRQ(
1971 // PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1972 // "check finite element definition, nb. of rows is not equal to "
1973 // "number for columns");
1974 // }
1975 // }
1976 // }
1977
1978 auto number_dofs = [&](auto &dofs_idx, auto &counter) {
1980 for (auto miit_dofs_row = dofs_idx.begin();
1981 miit_dofs_row != dofs_idx.end(); miit_dofs_row++) {
1982 const int idx = (*miit_dofs_row)->getPetscGlobalDofIdx();
1983 const int part = part_number[idx];
1984 if (part == (unsigned int)m_field.get_comm_rank()) {
1985 const bool success = dofs_idx.modify(
1986 miit_dofs_row, NumeredDofEntity_part_and_indices_change(
1987 part, petsc_idx[idx], counter++));
1988 if (!success) {
1989 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1990 "modification unsuccessful");
1991 }
1992 } else {
1993 const bool success = dofs_idx.modify(
1994 miit_dofs_row, NumeredDofEntity_part_and_glob_idx_change(
1995 part, petsc_idx[idx]));
1996 if (!success) {
1997 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1998 "modification unsuccessful");
1999 }
2000 }
2001 }
2003 };
2004
2005 // Set petsc global indices
2006 auto &dofs_row_by_idx_no_const = const_cast<NumeredDofEntitysByIdx &>(
2007 p_miit->numeredRowDofsPtr->get<Unique_mi_tag>());
2008 int &nb_row_local_dofs = p_miit->nbLocDofsRow;
2009 int &nb_row_ghost_dofs = p_miit->nbGhostDofsRow;
2010 nb_row_local_dofs = 0;
2011 nb_row_ghost_dofs = 0;
2012
2013 CHKERR number_dofs(dofs_row_by_idx_no_const, nb_row_local_dofs);
2014
2015 int &nb_col_local_dofs = p_miit->nbLocDofsCol;
2016 int &nb_col_ghost_dofs = p_miit->nbGhostDofsCol;
2017 if (square_matrix) {
2018 nb_col_local_dofs = nb_row_local_dofs;
2019 nb_col_ghost_dofs = nb_row_ghost_dofs;
2020 } else {
2021 NumeredDofEntitysByIdx &dofs_col_by_idx_no_const =
2022 const_cast<NumeredDofEntitysByIdx &>(
2023 p_miit->numeredColDofsPtr->get<Unique_mi_tag>());
2024 nb_col_local_dofs = 0;
2025 nb_col_ghost_dofs = 0;
2026 CHKERR number_dofs(dofs_col_by_idx_no_const, nb_col_local_dofs);
2027 }
2028
2029 CHKERR ISRestoreIndices(is_gather, &part_number);
2030 CHKERR ISRestoreIndices(is_gather_num, &petsc_idx);
2031 CHKERR ISDestroy(&is_num);
2032 CHKERR ISDestroy(&is_gather_num);
2033 CHKERR ISDestroy(&is_gather);
2034 CHKERR ISDestroy(&is);
2035 CHKERR MatPartitioningDestroy(&part);
2036 CHKERR MatDestroy(&Adj);
2037 CHKERR printPartitionedProblem(&*p_miit, verb);
2038 } else {
2039
2040 auto number_dofs = [&](auto &dof_idx, auto &counter) {
2042 for (auto miit_dofs_row = dof_idx.begin(); miit_dofs_row != dof_idx.end();
2043 miit_dofs_row++) {
2044 // buildProblem numbers serial problems at insertion; a modify through
2045 // the five indices is needed only when the record does not match.
2046 const auto &dof = **miit_dofs_row;
2047 if (dof.getPart() != 0 || dof.getPetscGlobalDofIdx() != counter ||
2048 dof.getPetscLocalDofIdx() != counter) {
2049 const bool success = dof_idx.modify(
2050 miit_dofs_row,
2051 NumeredDofEntity_part_and_indices_change(0, counter, counter));
2052 if (!success) {
2053 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
2054 "modification unsuccessful");
2055 }
2056 }
2057 ++counter;
2058 }
2060 };
2061
2062 auto &dofs_row_by_idx_no_const = const_cast<NumeredDofEntitysByIdx &>(
2063 p_miit->numeredRowDofsPtr->get<Unique_mi_tag>());
2064 int &nb_row_local_dofs = p_miit->nbLocDofsRow;
2065 int &nb_row_ghost_dofs = p_miit->nbGhostDofsRow;
2066 nb_row_local_dofs = 0;
2067 nb_row_ghost_dofs = 0;
2068
2069 CHKERR number_dofs(dofs_row_by_idx_no_const, nb_row_local_dofs);
2070
2071 bool square_matrix = false;
2072 if (p_miit->numeredRowDofsPtr == p_miit->numeredColDofsPtr)
2073 square_matrix = true;
2074
2075 int &nb_col_local_dofs = p_miit->nbLocDofsCol;
2076 int &nb_col_ghost_dofs = p_miit->nbGhostDofsCol;
2077 if (square_matrix) {
2078 nb_col_local_dofs = nb_row_local_dofs;
2079 nb_col_ghost_dofs = nb_row_ghost_dofs;
2080 } else {
2081 NumeredDofEntitysByIdx &dofs_col_by_idx_no_const =
2082 const_cast<NumeredDofEntitysByIdx &>(
2083 p_miit->numeredColDofsPtr->get<Unique_mi_tag>());
2084 nb_col_local_dofs = 0;
2085 nb_col_ghost_dofs = 0;
2086 CHKERR number_dofs(dofs_col_by_idx_no_const, nb_col_local_dofs);
2087 }
2088 }
2089
2090 cOre.getBuildMoFEM() |= 1 << 4;
2092}
@ VERY_VERBOSE
FTensor::Index< 'm', 3 > m

◆ partitionSimpleProblem()

MoFEMErrorCode MoFEM::ProblemsManager::partitionSimpleProblem ( const std::string  name,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

partition problem dofs

Partitions DOFs for sequential/simple problems where the mesh is not distributed across processors. Creates local DOF numbering and assigns ownership to processors.

Parameters
nameproblem name to partition
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure
Examples
mofem/atom_tests/forces_and_sources_testing_edge_element.cpp, mofem/atom_tests/forces_and_sources_testing_flat_prism_element.cpp, mofem/atom_tests/hcurl_divergence_operator_2d.cpp, mofem/atom_tests/prism_elements_from_surface.cpp, mofem/atom_tests/prism_polynomial_approximation.cpp, and mofem/atom_tests/quad_polynomial_approximation.cpp.

Definition at line 1726 of file ProblemsManager.cpp.

1727 {
1728
1729 MoFEM::Interface &m_field = cOre;
1730 auto problems_ptr = m_field.get_problems();
1732
1734 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
1736 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
1738 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
1740 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
1741 MOFEM_LOG("WORLD", Sev::verbose) << "Simple partition problem " << name;
1742
1743 // find p_miit
1744 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemByName;
1745 ProblemByName &problems_set =
1746 const_cast<ProblemByName &>(problems_ptr->get<Problem_mi_tag>());
1747 ProblemByName::iterator p_miit = problems_set.find(name);
1748 if (p_miit == problems_set.end()) {
1749 SETERRQ(PETSC_COMM_SELF, 1,
1750 "problem < %s > is not found (top tip: check spelling)",
1751 name.c_str());
1752 }
1753 // Parts are contiguous ranges of the provisional global index set by
1754 // buildProblem; the index is kept and only the part and the local index
1755 // change, so modifying through the iterated index leaves elements in place.
1756 typedef boost::multi_index::index<NumeredDofEntity_multiIndex,
1757 PetscGlobalIdx_mi_tag>::type
1758 NumeredDofEntitysByIdx;
1759 NumeredDofEntitysByIdx &dofs_row_by_idx =
1760 p_miit->numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>();
1761 NumeredDofEntitysByIdx &dofs_col_by_idx =
1762 p_miit->numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>();
1763 NumeredDofEntitysByIdx::iterator miit_row, hi_miit_row;
1764 NumeredDofEntitysByIdx::iterator miit_col, hi_miit_col;
1765 DofIdx &nb_row_local_dofs = p_miit->nbLocDofsRow;
1766 DofIdx &nb_row_ghost_dofs = p_miit->nbGhostDofsRow;
1767 nb_row_local_dofs = 0;
1768 nb_row_ghost_dofs = 0;
1769 DofIdx &nb_col_local_dofs = p_miit->nbLocDofsCol;
1770 DofIdx &nb_col_ghost_dofs = p_miit->nbGhostDofsCol;
1771 nb_col_local_dofs = 0;
1772 nb_col_ghost_dofs = 0;
1773
1774 bool square_matrix = false;
1775 if (p_miit->numeredRowDofsPtr == p_miit->numeredColDofsPtr) {
1776 square_matrix = true;
1777 }
1778
1779 // get row range of local indices
1780 PetscLayout layout_row;
1781 const int *ranges_row;
1782
1783 DofIdx nb_dofs_row = dofs_row_by_idx.size();
1784 CHKERR PetscLayoutCreate(m_field.get_comm(), &layout_row);
1785 CHKERR PetscLayoutSetBlockSize(layout_row, 1);
1786 CHKERR PetscLayoutSetSize(layout_row, nb_dofs_row);
1787 CHKERR PetscLayoutSetUp(layout_row);
1788 CHKERR PetscLayoutGetRanges(layout_row, &ranges_row);
1789 // get col range of local indices
1790 PetscLayout layout_col;
1791 const int *ranges_col;
1792 if (!square_matrix) {
1793 DofIdx nb_dofs_col = dofs_col_by_idx.size();
1794 CHKERR PetscLayoutCreate(m_field.get_comm(), &layout_col);
1795 CHKERR PetscLayoutSetBlockSize(layout_col, 1);
1796 CHKERR PetscLayoutSetSize(layout_col, nb_dofs_col);
1797 CHKERR PetscLayoutSetUp(layout_col);
1798 CHKERR PetscLayoutGetRanges(layout_col, &ranges_col);
1799 }
1800 for (unsigned int part = 0; part < (unsigned int)m_field.get_comm_size();
1801 part++) {
1802 miit_row = dofs_row_by_idx.lower_bound(ranges_row[part]);
1803 hi_miit_row = dofs_row_by_idx.lower_bound(ranges_row[part + 1]);
1804 if (std::distance(miit_row, hi_miit_row) !=
1805 ranges_row[part + 1] - ranges_row[part]) {
1806 SETERRQ(
1807 PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
1808 "data inconsistency, std::distance(miit_row,hi_miit_row) != rend - "
1809 "rstart (%ld != %d - %d = %d) ",
1810 std::distance(miit_row, hi_miit_row), ranges_row[part + 1],
1811 ranges_row[part], ranges_row[part + 1] - ranges_row[part]);
1812 }
1813 // loop rows
1814 for (; miit_row != hi_miit_row; miit_row++) {
1815 bool success = dofs_row_by_idx.modify(
1816 miit_row, NumeredDofEntity_part_and_glob_idx_change(
1817 part, (*miit_row)->getPetscGlobalDofIdx()));
1818 if (!success)
1819 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1820 "modification unsuccessful");
1821 if (part == (unsigned int)m_field.get_comm_rank()) {
1822 success = dofs_row_by_idx.modify(
1823 miit_row, NumeredDofEntity_local_idx_change(nb_row_local_dofs++));
1824 if (!success)
1825 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1826 "modification unsuccessful");
1827 }
1828 }
1829 if (!square_matrix) {
1830 miit_col = dofs_col_by_idx.lower_bound(ranges_col[part]);
1831 hi_miit_col = dofs_col_by_idx.lower_bound(ranges_col[part + 1]);
1832 if (std::distance(miit_col, hi_miit_col) !=
1833 ranges_col[part + 1] - ranges_col[part]) {
1834 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
1835 "data inconsistency, std::distance(miit_col,hi_miit_col) != "
1836 "rend - "
1837 "rstart (%ld != %d - %d = %d) ",
1838 std::distance(miit_col, hi_miit_col), ranges_col[part + 1],
1839 ranges_col[part], ranges_col[part + 1] - ranges_col[part]);
1840 }
1841 // loop cols
1842 for (; miit_col != hi_miit_col; miit_col++) {
1843 bool success = dofs_col_by_idx.modify(
1844 miit_col, NumeredDofEntity_part_and_glob_idx_change(
1845 part, (*miit_col)->getPetscGlobalDofIdx()));
1846 if (!success)
1847 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1848 "modification unsuccessful");
1849 if (part == (unsigned int)m_field.get_comm_rank()) {
1850 success = dofs_col_by_idx.modify(
1851 miit_col, NumeredDofEntity_local_idx_change(nb_col_local_dofs++));
1852 if (!success)
1853 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1854 "modification unsuccessful");
1855 }
1856 }
1857 }
1858 }
1859 CHKERR PetscLayoutDestroy(&layout_row);
1860 if (!square_matrix) {
1861 CHKERR PetscLayoutDestroy(&layout_col);
1862 }
1863 if (square_matrix) {
1864 nb_col_local_dofs = nb_row_local_dofs;
1865 nb_col_ghost_dofs = nb_row_ghost_dofs;
1866 }
1867 CHKERR printPartitionedProblem(&*p_miit, verb);
1870}

◆ printPartitionedProblem()

MoFEMErrorCode MoFEM::ProblemsManager::printPartitionedProblem ( const Problem *  problem_ptr,
int  verb = VERBOSE 
)

#include <src/interfaces/ProblemsManager.hpp>

Print partition information for debugging.

Outputs detailed information about how DOFs and finite elements are distributed across processors for the given problem.

Parameters
problem_ptrpointer to the problem structure
verbverbosity level
Returns
MoFEMErrorCode Error code indicating success or failure

Definition at line 2262 of file ProblemsManager.cpp.

2262 {
2263 MoFEM::Interface &m_field = cOre;
2265
2266 if (verb > QUIET) {
2267
2268 MOFEM_LOG("SYNC", Sev::inform)
2269 << problem_ptr->getName() << " Nb. local dof "
2270 << problem_ptr->getNbLocalDofsRow() << " by "
2271 << problem_ptr->getNbLocalDofsCol() << " nb global dofs "
2272 << problem_ptr->getNbDofsRow() << " by " << problem_ptr->getNbDofsCol();
2273
2275 }
2276
2278}

◆ rebuildProblemOnDistributedMesh()

MoFEMErrorCode MoFEM::ProblemsManager::rebuildProblemOnDistributedMesh ( const std::string &  name,
const BitRefLevel  target_bit,
const BitRefLevel  target_mask,
const bool  square_matrix,
int  verb = VERBOSE,
SmartPetscObj< IS > *  old_row_indices = nullptr,
SmartPetscObj< IS > *  new_row_indices = nullptr 
)

#include <src/interfaces/ProblemsManager.hpp>

Rebuild a parent problem in place on a distributed mesh (collective)

The problem keeps its name, its identity and its DMs. Its selector is set to target_bit and target_mask (set, never OR-ed), and its numbered DOFs are rebuilt by buildProblemOnDistributedMesh into staged containers, which are then published by swapping the problem's container pointers, sequences and counts. Until that swap the problem is untouched, so a failure of the build leaves it as it was. Every index is renumbered; nothing is preserved. The numbered finite elements are cleared and the ghost DOFs are not set: call partitionFiniteElements and partitionGhostDofsOnDistributedMesh afterwards, or use DMMoFEMRebuildProblem, which does that and resets the DM.

Optionally returns, for the DOFs owned by this rank that exist in both numberings (same local UID), their old and their new global row indices in one order, for a VecScatter of retained vectors. The index sets are collective: pass both pointers on every rank, or none.

Parameters
nameproblem name
target_bitbit ref level of the rebuilt problem
target_maskbit ref mask of the rebuilt problem
square_matrixtrue if rows and columns are the same
verbverbosity level
old_row_indicesold global row indices of the surviving owned DOFs
new_row_indicestheir new global row indices, same order
Returns
MoFEMErrorCode Error code indicating success or failure

Definition at line 384 of file ProblemsManager.cpp.

387 {
388 MoFEM::Interface &m_field = cOre;
390
391 if (target_bit.none())
392 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
393 "rebuild of <%s>: target bit ref level is not set", name.c_str());
394
395 using ProblemsByName = Problem_multiIndex::index<Problem_mi_tag>::type;
396 auto &problems_by_name = const_cast<ProblemsByName &>(
397 m_field.get_problems()->get<Problem_mi_tag>());
398 auto live_it = problems_by_name.find(name);
399 if (live_it == problems_by_name.end())
400 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND,
401 "problem <%s> is not found (top tip: check spelling)",
402 name.c_str());
403 if (live_it->getSubData() || live_it->getComposedProblemsData())
404 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
405 "rebuild of <%s>: only a parent problem is rebuilt in place",
406 name.c_str());
407
408 auto modify = [&](auto it, auto &&change) {
410 if (!problems_by_name.modify(it, change))
411 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
412 "modification unsuccessful");
414 };
415
416 // Stage: a hidden problem with the live problem's elements and the target
417 // selector, built by the distributed builder. The live problem is not
418 // touched until the staged containers are published below, so a failure
419 // of the build leaves it as it was.
420 const std::string staged_name = name + "__REBUILD_STAGE";
421 if (m_field.check_problem(staged_name))
422 CHKERR m_field.delete_problem(staged_name);
423 CHKERR m_field.add_problem(staged_name, MF_EXCL, verb);
424 auto staged_it = problems_by_name.find(staged_name);
425 CHKERR modify(staged_it,
426 ProblemFiniteElementChangeBitAdd(live_it->getBitFEId()));
427 CHKERR modify(staged_it, ProblemChangeRefLevelBitSet(target_bit));
428 CHKERR modify(staged_it, ProblemChangeRefLevelBitDofMaskSet(target_mask));
429 staged_it->getEmptyFieldBlocks() = live_it->getEmptyFieldBlocks();
430 CHKERR buildProblemOnDistributedMesh(staged_name, square_matrix, verb);
431
432 // Survivors: DOFs owned by this rank in the new numbering that exist in
433 // the old one, with their old and new global row indices in one order.
434 if (old_row_indices || new_row_indices) {
435 std::vector<PetscInt> old_idx, new_idx;
436 const auto &old_by_uid =
437 live_it->getNumeredRowDofsPtr()->get<Unique_mi_tag>();
438 const auto &new_by_local =
439 staged_it->getNumeredRowDofsPtr()->get<PetscLocalIdx_mi_tag>();
440 const auto hi = new_by_local.lower_bound(staged_it->getNbLocalDofsRow());
441 for (auto it = new_by_local.lower_bound(0); it != hi; ++it) {
442 auto old_it = old_by_uid.find((*it)->getLocalUniqueId());
443 if (old_it != old_by_uid.end() &&
444 (*old_it)->getPetscGlobalDofIdx() >= 0) {
445 old_idx.push_back((*old_it)->getPetscGlobalDofIdx());
446 new_idx.push_back((*it)->getPetscGlobalDofIdx());
447 }
448 }
449 auto make_is = [&](std::vector<PetscInt> &idx) {
450 return createISGeneral(m_field.get_comm(), idx.size(),
451 idx.empty() ? nullptr : idx.data(),
452 PETSC_COPY_VALUES);
453 };
454 if (old_row_indices)
455 *old_row_indices = make_is(old_idx);
456 if (new_row_indices)
457 *new_row_indices = make_is(new_idx);
458 }
459
460 // Publish: the live problem takes the staged containers, sequences, counts
461 // and the target selector; the staged problem takes the old numbering and
462 // is deleted with it. The numbered finite elements are cleared, to be
463 // rebuilt by partitionFiniteElements.
464 const Problem &live = *live_it;
465 const Problem &staged = *staged_it;
466 std::swap(live.numeredRowDofsPtr, staged.numeredRowDofsPtr);
467 std::swap(live.numeredColDofsPtr, staged.numeredColDofsPtr);
468 std::swap(live.getRowDofsSequence(), staged.getRowDofsSequence());
469 std::swap(live.getColDofsSequence(), staged.getColDofsSequence());
470 std::swap(live.nbDofsRow, staged.nbDofsRow);
471 std::swap(live.nbDofsCol, staged.nbDofsCol);
472 std::swap(live.nbLocDofsRow, staged.nbLocDofsRow);
473 std::swap(live.nbLocDofsCol, staged.nbLocDofsCol);
474 std::swap(live.nbGhostDofsRow, staged.nbGhostDofsRow);
475 std::swap(live.nbGhostDofsCol, staged.nbGhostDofsCol);
476 CHKERR modify(live_it, ProblemClearNumeredFiniteElementsChange());
477 CHKERR modify(live_it, ProblemChangeRefLevelBitSet(target_bit));
478 CHKERR modify(live_it, ProblemChangeRefLevelBitDofMaskSet(target_mask));
479 CHKERR m_field.delete_problem(staged_name);
480
481 MOFEM_LOG("WORLD", Sev::verbose)
482 << "Rebuilt problem " << name << " in place: " << live.getNbDofsRow()
483 << " dofs (" << live.getNbLocalDofsRow() << " local)";
484
486}
std::map< EntityHandle, std::vector< double > > staged
@ MF_EXCL
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
virtual MoFEMErrorCode delete_problem(const std::string name)=0
Delete problem.
virtual bool check_problem(const std::string name)=0
check if problem exist
auto createISGeneral(MPI_Comm comm, PetscInt n, const PetscInt idx[], PetscCopyMode mode)
Creates a data structure for an index set containing a list of integers.

◆ removeDofs()

MoFEMErrorCode MoFEM::ProblemsManager::removeDofs ( const std::string  problem_name,
RowColData  rc,
std::vector< boost::weak_ptr< NumeredDofEntity > > &  vec_dof_view,
int  verb = VERBOSE,
const bool  debug = false 
)

#include <src/interfaces/ProblemsManager.hpp>

Remove DOFs from problem on broken space.

Removes specified DOFs from the problem for broken (discontinuous) spaces. The DOFs are marked as inactive by setting their indices to -1, which causes them to be skipped during assembly operations.

Parameters
problem_namename of the problem
rcrow or column data specification
vec_dof_viewvector of DOF entities to remove
verbverbosity level
debugenable debug output for inconsistency checking
Returns
MoFEMErrorCode Error code indicating success or failure

Definition at line 2923 of file ProblemsManager.cpp.

2926 {
2927
2928 MoFEM::Interface &m_field = cOre;
2930
2931 switch (rc) {
2932 case ROW:
2933 case COL:
2934 break;
2935 default:
2936 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
2937 }
2938
2939 const Problem *prb_ptr;
2940 CHKERR m_field.get_problem(problem_name, &prb_ptr);
2941
2942 decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
2943 prb_ptr->numeredRowDofsPtr, nullptr};
2944 if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
2945 numered_dofs[1] = prb_ptr->numeredColDofsPtr;
2946
2947 int *nbdof_ptr[] = {&prb_ptr->nbDofsRow, &prb_ptr->nbDofsCol};
2948 int *local_nbdof_ptr[] = {&prb_ptr->nbLocDofsRow, &prb_ptr->nbLocDofsCol};
2949 int *ghost_nbdof_ptr[] = {&prb_ptr->nbGhostDofsRow, &prb_ptr->nbGhostDofsCol};
2950
2951 const int nb_init_row_dofs = prb_ptr->getNbDofsRow();
2952 const int nb_init_col_dofs = prb_ptr->getNbDofsCol();
2953 const int nb_init_loc_row_dofs = prb_ptr->getNbLocalDofsRow();
2954 const int nb_init_ghost_row_dofs = prb_ptr->getNbGhostDofsRow();
2955 const int nb_init_ghost_col_dofs = prb_ptr->getNbGhostDofsCol();
2956
2957 if (numered_dofs[rc]) {
2958
2959 if (verb >= NOISY)
2960 MOFEM_LOG_C("SYNC", Sev::noisy,
2961 "Number of DOFs in multi-index %zu and to delete %zu\n",
2962 numered_dofs[rc]->size(), vec_dof_view.size());
2963
2964 // erase dofs from problem
2965 for (auto weak_dit : vec_dof_view)
2966 if (auto dit = weak_dit.lock()) {
2967 numered_dofs[rc]->erase(dit->getLocalUniqueId());
2968 }
2969
2970 if (verb >= NOISY)
2971 MOFEM_LOG_C("SYNC", Sev::noisy,
2972 "Number of DOFs in multi-index after delete %zu\n",
2973 numered_dofs[rc]->size());
2974
2975 // get current number of ghost dofs
2976 int nb_local_dofs = 0;
2977 int nb_ghost_dofs = 0;
2978 for (auto dit = numered_dofs[rc]->get<PetscLocalIdx_mi_tag>().begin();
2979 dit != numered_dofs[rc]->get<PetscLocalIdx_mi_tag>().end(); ++dit) {
2980 if ((*dit)->getPetscLocalDofIdx() >= 0 &&
2981 (*dit)->getPetscLocalDofIdx() < *(local_nbdof_ptr[rc]))
2982 ++nb_local_dofs;
2983 else if ((*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[rc]))
2984 ++nb_ghost_dofs;
2985 else
2986 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2987 "Impossible case. You could run problem on no distributed "
2988 "mesh. That is not implemented. Dof local index is %d",
2989 (*dit)->getPetscLocalDofIdx());
2990 }
2991
2992 // get indices
2993 auto get_indices_by_tag = [&](auto tag, auto &indices, bool only_local) {
2994 const int nb_dofs = numered_dofs[rc]->size();
2995 indices.clear();
2996 indices.reserve(nb_dofs);
2997 for (auto dit = numered_dofs[rc]->get<decltype(tag)>().begin();
2998 dit != numered_dofs[rc]->get<decltype(tag)>().end(); ++dit) {
2999 bool add = true;
3000 if (only_local) {
3001 if ((*dit)->getPetscLocalDofIdx() < 0 ||
3002 (*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[rc])) {
3003 add = false;
3004 }
3005 }
3006 if (add)
3007 indices.push_back(decltype(tag)::get_index(dit));
3008 }
3009 };
3010
3011 auto get_indices_by_uid = [&](auto tag, auto &indices) {
3012 const int nb_dofs = numered_dofs[rc]->size();
3013 indices.clear();
3014 indices.reserve(nb_dofs);
3015 for (auto dit = numered_dofs[rc]->begin(); dit != numered_dofs[rc]->end();
3016 ++dit)
3017 indices.push_back(decltype(tag)::get_index(dit));
3018 };
3019
3020 auto get_sub_ao = [&](auto sub_data) {
3021 if (rc == 0) {
3022 return sub_data->getSmartRowMap();
3023 } else {
3024 return sub_data->getSmartColMap();
3025 }
3026 };
3027
3028 auto set_sub_is_and_ao = [&rc, &prb_ptr](auto sub_data, auto is, auto ao) {
3029 if (rc == ROW) {
3030 sub_data->rowIs = is;
3031 sub_data->rowMap = ao;
3032 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3033 sub_data->colIs = is;
3034 sub_data->colMap = ao;
3035 }
3036 } else {
3037 sub_data->colIs = is;
3038 sub_data->colMap = ao;
3039 }
3040 };
3041
3042 auto apply_symmetry = [&rc, &prb_ptr](auto sub_data) {
3043 if (rc == ROW) {
3044 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3045 sub_data->colIs = sub_data->getSmartRowIs();
3046 sub_data->colMap = sub_data->getSmartRowMap();
3047 }
3048 }
3049 };
3050
3051 auto concatenate_dofs = [&](auto tag, auto &indices,
3052 const auto local_only) {
3054 get_indices_by_tag(tag, indices, local_only);
3055
3056 auto indices_ptr = [](auto &indices) {
3057 return indices.empty() ? nullptr : indices.data();
3058 };
3059
3060 SmartPetscObj<AO> ao;
3061 // Create AO from app indices (i.e. old), to pestc indices (new after
3062 // remove)
3063 if (local_only)
3064 ao = createAOMapping(m_field.get_comm(), indices.size(),
3065 indices_ptr(indices), PETSC_NULLPTR);
3066 else
3067 ao = createAOMapping(PETSC_COMM_SELF, indices.size(),
3068 indices_ptr(indices), PETSC_NULLPTR);
3069
3070 // Set mapping to sub dm data
3071 if (local_only) {
3072 if (auto sub_data = prb_ptr->getSubData()) {
3073 // create is and then map it to main problem of sub-problem
3074 auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
3075 indices_ptr(indices), PETSC_COPY_VALUES);
3076 // get old app, i.e. oroginal befor sub indices, and ao, from app,
3077 // to petsc sub indices.
3078 auto sub_ao = get_sub_ao(sub_data);
3079 if (sub_ao.get()) {
3080 CHKERR AOPetscToApplicationIS(sub_ao, sub_is);
3081 sub_ao = createAOMappingIS(sub_is, PETSC_NULLPTR);
3082 } else {
3083 sub_ao = ao;
3084 }
3085 // set new sub ao
3086 set_sub_is_and_ao(sub_data, sub_is, sub_ao);
3087 apply_symmetry(sub_data);
3088 } else {
3089 // create sub data
3090 prb_ptr->getSubData() = boost::make_shared<Problem::SubProblemData>();
3091 auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
3092 indices_ptr(indices), PETSC_COPY_VALUES);
3093 // set sub is ao
3094 set_sub_is_and_ao(prb_ptr->getSubData(), sub_is, ao);
3095 apply_symmetry(prb_ptr->getSubData());
3096 }
3097 }
3098
3099 get_indices_by_uid(tag, indices);
3100 CHKERR AOApplicationToPetsc(ao, indices.size(), indices_ptr(indices));
3101
3103 };
3104
3105 // set indices index
3106 auto set_concatenated_indices = [&]() {
3107 std::vector<int> global_indices;
3108 std::vector<int> local_indices;
3110 CHKERR concatenate_dofs(PetscGlobalIdx_mi_tag(), global_indices, true);
3111 CHKERR concatenate_dofs(PetscLocalIdx_mi_tag(), local_indices, false);
3112 auto gi = global_indices.begin();
3113 auto li = local_indices.begin();
3114 for (auto dit = numered_dofs[rc]->begin(); dit != numered_dofs[rc]->end();
3115 ++dit) {
3116 auto mod = NumeredDofEntity_part_and_indices_change(
3117 (*dit)->getPart(), *gi, *li);
3118 bool success = numered_dofs[rc]->modify(dit, mod);
3119 if (!success)
3120 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3121 "can not set negative indices");
3122 ++gi;
3123 ++li;
3124 }
3126 };
3127 CHKERR set_concatenated_indices();
3128
3129 MPI_Allreduce(&nb_local_dofs, nbdof_ptr[rc], 1, MPI_INT, MPI_SUM,
3130 m_field.get_comm());
3131 *(local_nbdof_ptr[rc]) = nb_local_dofs;
3132 *(ghost_nbdof_ptr[rc]) = nb_ghost_dofs;
3133
3134 if (debug)
3135 for (auto dof : (*numered_dofs[rc])) {
3136 if (dof->getPetscGlobalDofIdx() < 0) {
3137 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
3138 "Negative global idx");
3139 }
3140 if (dof->getPetscLocalDofIdx() < 0) {
3141 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
3142 "Negative local idx");
3143 }
3144 }
3145
3146 } else {
3147
3148 *(nbdof_ptr[1]) = *(nbdof_ptr[0]);
3149 *(local_nbdof_ptr[1]) = *(local_nbdof_ptr[0]);
3150 *(ghost_nbdof_ptr[1]) = *(ghost_nbdof_ptr[0]);
3151 }
3152
3153 if (verb > QUIET) {
3155 "WORLD", Sev::inform,
3156 "Removed DOFs from problem %s dofs [%d / %d (before %d / %d) global]",
3157 prb_ptr->getName().c_str(), prb_ptr->getNbDofsRow(),
3158 prb_ptr->getNbDofsCol(), nb_init_row_dofs, nb_init_col_dofs);
3159 MOFEM_LOG_C("SYNC", Sev::verbose,
3160 "Removed DOFs from problem %s dofs [ %d / %d "
3161 "(before %d / %d) local, %d / %d (before %d / %d)]",
3162 prb_ptr->getName().c_str(), prb_ptr->getNbLocalDofsRow(),
3163 prb_ptr->getNbLocalDofsCol(), nb_init_loc_row_dofs,
3164 nb_init_loc_row_dofs, prb_ptr->getNbGhostDofsRow(),
3165 prb_ptr->getNbGhostDofsCol(), nb_init_ghost_row_dofs,
3166 nb_init_ghost_col_dofs);
3167 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
3168 }
3169
3171}
Tag tag
#define MOFEM_LOG_C(channel, severity, format,...)
auto createAOMapping(MPI_Comm comm, PetscInt napp, const PetscInt myapp[], const PetscInt mypetsc[])
Creates an application mapping using two integer arrays.
auto createAOMappingIS(IS isapp, IS ispetsc)
Creates an application mapping using two index sets.

◆ removeDofsOnEntities() [1/2]

MoFEMErrorCode MoFEM::ProblemsManager::removeDofsOnEntities ( const std::string  problem_name,
const std::string  field_name,
const BitRefLevel  bit_ref_level,
const BitRefLevel  bit_ref_mask,
Range *  ents_ptr = nullptr,
const int  lo_coeff = 0,
const int  hi_coeff = MAX_DOFS_ON_ENTITY,
const int  lo_order = 0,
const int  hi_order = 100,
int  verb = VERBOSE,
const bool  debug = false 
)

#include <src/interfaces/ProblemsManager.hpp>

Remove DOFs from problem by bit ref level.

See for more detail other implementation for removeDofsOnEntities.

Parameters
problem_namename of the problem
field_namename of the field
bit_ref_levelbit ref level on which DOFs are removed
bit_ref_maskbit ref mask on which DOFs are removed
ents_ptrfilter entities with given bit and mask
lo_coefflow dof coefficient (rank)
hi_coeffhigh dof coefficient (rank)
verbverbosity level
debugto debug and seek for inconsistencies set to true
Returns
MoFEMErrorCode

Definition at line 3735 of file ProblemsManager.cpp.

3739 {
3740 MoFEM::Interface &m_field = cOre;
3742
3743 auto bit_manager = m_field.getInterface<BitRefManager>();
3744
3745 Range ents;
3746 if (ents_ptr) {
3747 ents = *ents_ptr;
3748 CHKERR bit_manager->filterEntitiesByRefLevel(bit_ref_level, bit_ref_mask,
3749 ents, verb);
3750 } else {
3751 CHKERR bit_manager->getEntitiesByRefLevel(bit_ref_level, bit_ref_mask, ents,
3752 verb);
3753 }
3754
3755 CHKERR removeDofsOnEntities(problem_name, field_name, ents, lo_coeff,
3756 hi_coeff, lo_order, hi_order, verb, debug);
3757
3759}
MoFEMErrorCode removeDofsOnEntities(const std::string problem_name, const std::string field_name, const Range ents, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false)
Remove DOFs from problem.

◆ removeDofsOnEntities() [2/2]

MoFEMErrorCode MoFEM::ProblemsManager::removeDofsOnEntities ( const std::string  problem_name,
const std::string  field_name,
const Range  ents,
const int  lo_coeff = 0,
const int  hi_coeff = MAX_DOFS_ON_ENTITY,
const int  lo_order = 0,
const int  hi_order = 100,
int  verb = VERBOSE,
const bool  debug = false 
)

#include <src/interfaces/ProblemsManager.hpp>

Remove DOFs from problem.

Remove DOFs from problem which are on entities on the given range and given field name. On the finite element level, DOFs can be still accessed however local PETSc indices and global PETSc indices are marked with the index -1.

Note
If the index is marked -1 it is not assembled and dropped by VecSetValues and MatSetValues.
Todo:
Not yet implemented update for AO maps and IS ranges if removed entities in composite problem or sub-problem
Parameters
problem_namename of the problem
field_namename of the field
entsentities on which DOFs are removed
lo_coefflow dof coefficient (rank)
hi_coeffhigh dof coefficient (rank)
verbverbosity level
debugto debug and seek for inconsistencies set to true
Returns
MoFEMErrorCode
Examples
mofem/atom_tests/hanging_node_approx.cpp, mofem/atom_tests/remove_entities_from_problem.cpp, and mofem/tutorials/clx-0_acoustics/helmholtz.cpp.

Definition at line 3173 of file ProblemsManager.cpp.

3176 {
3177
3178 MoFEM::Interface &m_field = cOre;
3180
3181 const Problem *prb_ptr;
3182 CHKERR m_field.get_problem(problem_name, &prb_ptr);
3183
3184 decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
3185 prb_ptr->numeredRowDofsPtr, nullptr};
3186 if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
3187 numered_dofs[1] = prb_ptr->numeredColDofsPtr;
3188
3189 int *nbdof_ptr[] = {&prb_ptr->nbDofsRow, &prb_ptr->nbDofsCol};
3190 int *local_nbdof_ptr[] = {&prb_ptr->nbLocDofsRow, &prb_ptr->nbLocDofsCol};
3191 int *ghost_nbdof_ptr[] = {&prb_ptr->nbGhostDofsRow, &prb_ptr->nbGhostDofsCol};
3192
3193 const int nb_init_row_dofs = prb_ptr->getNbDofsRow();
3194 const int nb_init_col_dofs = prb_ptr->getNbDofsCol();
3195 const int nb_init_loc_row_dofs = prb_ptr->getNbLocalDofsRow();
3196 const int nb_init_loc_col_dofs = prb_ptr->getNbLocalDofsCol();
3197 const int nb_init_ghost_row_dofs = prb_ptr->getNbGhostDofsRow();
3198 const int nb_init_ghost_col_dofs = prb_ptr->getNbGhostDofsCol();
3199
3200 for (int s = 0; s != 2; ++s)
3201 if (numered_dofs[s]) {
3202
3203 using NumeredDofEntity_it_view_multiIndex = multi_index_container<
3204
3205 NumeredDofEntity_multiIndex::iterator, indexed_by<sequenced<>>
3206
3207 >;
3208
3209 const auto bit_number = m_field.get_field_bit_number(field_name);
3210 NumeredDofEntity_it_view_multiIndex dofs_it_view;
3211
3212 // Set -1 to global and local dofs indices
3213 for (auto pit = ents.const_pair_begin(); pit != ents.const_pair_end();
3214 ++pit) {
3215 auto lo = numered_dofs[s]->get<Unique_mi_tag>().lower_bound(
3216 DofEntity::getLoFieldEntityUId(bit_number, pit->first));
3217 auto hi = numered_dofs[s]->get<Unique_mi_tag>().upper_bound(
3218 DofEntity::getHiFieldEntityUId(bit_number, pit->second));
3219
3220 for (; lo != hi; ++lo)
3221 if ((*lo)->getDofCoeffIdx() >= lo_coeff &&
3222 (*lo)->getDofCoeffIdx() <= hi_coeff &&
3223 (*lo)->getDofOrder() >= lo_order &&
3224 (*lo)->getDofOrder() <= hi_order)
3225 dofs_it_view.emplace_back(numered_dofs[s]->project<0>(lo));
3226 }
3227
3228 if (verb > QUIET) {
3229 for (auto &dof : dofs_it_view)
3230 MOFEM_LOG("SYNC", Sev::noisy) << **dof;
3231 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::noisy);
3232 }
3233
3234 // create weak view
3235 std::vector<boost::weak_ptr<NumeredDofEntity>> dofs_weak_view;
3236 dofs_weak_view.reserve(dofs_it_view.size());
3237 for (auto dit : dofs_it_view)
3238 dofs_weak_view.push_back(*dit);
3239
3240 if (verb >= NOISY)
3241 MOFEM_LOG_C("SYNC", Sev::noisy,
3242 "Number of DOFs in multi-index %zu and to delete %zu\n",
3243 numered_dofs[s]->size(), dofs_it_view.size());
3244
3245 // erase dofs from problem
3246 for (auto weak_dit : dofs_weak_view)
3247 if (auto dit = weak_dit.lock()) {
3248 numered_dofs[s]->erase(dit->getLocalUniqueId());
3249 }
3250
3251 if (verb >= NOISY)
3252 MOFEM_LOG_C("SYNC", Sev::noisy,
3253 "Number of DOFs in multi-index after delete %zu\n",
3254 numered_dofs[s]->size());
3255
3256 // get current number of ghost dofs
3257 int nb_local_dofs = 0;
3258 int nb_ghost_dofs = 0;
3259 for (auto dit = numered_dofs[s]->get<PetscLocalIdx_mi_tag>().begin();
3260 dit != numered_dofs[s]->get<PetscLocalIdx_mi_tag>().end(); ++dit) {
3261 if ((*dit)->getPetscLocalDofIdx() >= 0 &&
3262 (*dit)->getPetscLocalDofIdx() < *(local_nbdof_ptr[s]))
3263 ++nb_local_dofs;
3264 else if ((*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[s]))
3265 ++nb_ghost_dofs;
3266 else
3267 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3268 "Impossible case. You could run problem on no distributed "
3269 "mesh. That is not implemented. Dof local index is %d",
3270 (*dit)->getPetscLocalDofIdx());
3271 }
3272
3273 // get indices
3274 auto get_indices_by_tag = [&](auto tag, auto &indices, bool only_local) {
3275 const int nb_dofs = numered_dofs[s]->size();
3276 indices.clear();
3277 indices.reserve(nb_dofs);
3278 for (auto dit = numered_dofs[s]->get<decltype(tag)>().begin();
3279 dit != numered_dofs[s]->get<decltype(tag)>().end(); ++dit) {
3280 bool add = true;
3281 if (only_local) {
3282 if ((*dit)->getPetscLocalDofIdx() < 0 ||
3283 (*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[s])) {
3284 add = false;
3285 }
3286 }
3287 if (add)
3288 indices.push_back(decltype(tag)::get_index(dit));
3289 }
3290 };
3291
3292 auto get_indices_by_uid = [&](auto tag, auto &indices) {
3293 const int nb_dofs = numered_dofs[s]->size();
3294 indices.clear();
3295 indices.reserve(nb_dofs);
3296 for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
3297 ++dit)
3298 indices.push_back(decltype(tag)::get_index(dit));
3299 };
3300
3301 auto get_sub_ao = [&](auto sub_data) {
3302 if (s == 0) {
3303 return sub_data->getSmartRowMap();
3304 } else {
3305 return sub_data->getSmartColMap();
3306 }
3307 };
3308
3309 auto set_sub_is_and_ao = [&s, &prb_ptr](auto sub_data, auto is, auto ao) {
3310 if (s == 0) {
3311 sub_data->rowIs = is;
3312 sub_data->rowMap = ao;
3313 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3314 sub_data->colIs = is;
3315 sub_data->colMap = ao;
3316 }
3317 } else {
3318 sub_data->colIs = is;
3319 sub_data->colMap = ao;
3320 }
3321 };
3322
3323 auto apply_symmetry = [&s, &prb_ptr](auto sub_data) {
3324 if (s == 0) {
3325 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3326 sub_data->colIs = sub_data->getSmartRowIs();
3327 sub_data->colMap = sub_data->getSmartRowMap();
3328 }
3329 }
3330 };
3331
3332 auto concatenate_dofs = [&](auto tag, auto &indices,
3333 const auto local_only) {
3335 get_indices_by_tag(tag, indices, local_only);
3336
3337 auto indices_ptr = [](auto &indices) {
3338 return indices.empty() ? nullptr : indices.data();
3339 };
3340
3341 SmartPetscObj<AO> ao;
3342 // Create AO from app indices (i.e. old), to pestc indices (new after
3343 // remove)
3344 if (local_only)
3345 ao = createAOMapping(m_field.get_comm(), indices.size(),
3346 indices_ptr(indices), PETSC_NULLPTR);
3347 else
3348 ao = createAOMapping(PETSC_COMM_SELF, indices.size(),
3349 indices_ptr(indices), PETSC_NULLPTR);
3350
3351 // Set mapping to sub dm data
3352 if (local_only) {
3353 if (auto sub_data = prb_ptr->getSubData()) {
3354 // create is and then map it to main problem of sub-problem
3355 auto sub_is =
3356 createISGeneral(m_field.get_comm(), indices.size(),
3357 indices_ptr(indices), PETSC_COPY_VALUES);
3358 // get old app, i.e. oroginal befor sub indices, and ao, from app,
3359 // to petsc sub indices.
3360 auto sub_ao = get_sub_ao(sub_data);
3361 if (sub_ao.get()) {
3362 CHKERR AOPetscToApplicationIS(sub_ao, sub_is);
3363 sub_ao = createAOMappingIS(sub_is, PETSC_NULLPTR);
3364 } else {
3365 sub_ao = ao;
3366 }
3367 // set new sub ao
3368 set_sub_is_and_ao(sub_data, sub_is, sub_ao);
3369 apply_symmetry(sub_data);
3370 } else {
3371 // create sub data
3372 prb_ptr->getSubData() =
3373 boost::make_shared<Problem::SubProblemData>();
3374 auto sub_is =
3375 createISGeneral(m_field.get_comm(), indices.size(),
3376 indices_ptr(indices), PETSC_COPY_VALUES);
3377 // set sub is ao
3378 set_sub_is_and_ao(prb_ptr->getSubData(), sub_is, ao);
3379 apply_symmetry(prb_ptr->getSubData());
3380 }
3381 }
3382
3383 get_indices_by_uid(tag, indices);
3384 CHKERR AOApplicationToPetsc(ao, indices.size(), indices_ptr(indices));
3385
3387 };
3388
3389 // set indices index
3390 auto set_concatenated_indices = [&]() {
3391 std::vector<int> global_indices;
3392 std::vector<int> local_indices;
3394 CHKERR concatenate_dofs(PetscGlobalIdx_mi_tag(), global_indices, true);
3395 CHKERR concatenate_dofs(PetscLocalIdx_mi_tag(), local_indices, false);
3396 auto gi = global_indices.begin();
3397 auto li = local_indices.begin();
3398 for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
3399 ++dit) {
3400 auto mod = NumeredDofEntity_part_and_indices_change(
3401 (*dit)->getPart(), *gi, *li);
3402 bool success = numered_dofs[s]->modify(dit, mod);
3403 if (!success)
3404 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3405 "can not set negative indices");
3406 ++gi;
3407 ++li;
3408 }
3410 };
3411 CHKERR set_concatenated_indices();
3412
3413 MPI_Allreduce(&nb_local_dofs, nbdof_ptr[s], 1, MPI_INT, MPI_SUM,
3414 m_field.get_comm());
3415 *(local_nbdof_ptr[s]) = nb_local_dofs;
3416 *(ghost_nbdof_ptr[s]) = nb_ghost_dofs;
3417
3418 if (debug)
3419 for (auto dof : (*numered_dofs[s])) {
3420 if (dof->getPetscGlobalDofIdx() < 0) {
3421 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
3422 "Negative global idx");
3423 }
3424 if (dof->getPetscLocalDofIdx() < 0) {
3425 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
3426 "Negative local idx");
3427 }
3428 }
3429
3430 } else {
3431
3432 *(nbdof_ptr[1]) = *(nbdof_ptr[0]);
3433 *(local_nbdof_ptr[1]) = *(local_nbdof_ptr[0]);
3434 *(ghost_nbdof_ptr[1]) = *(ghost_nbdof_ptr[0]);
3435 }
3436
3437 if (verb > QUIET) {
3439 "WORLD", Sev::inform,
3440 "Removed DOFs from problem %s dofs [%d / %d (before %d / %d) global]",
3441 prb_ptr->getName().c_str(), prb_ptr->getNbDofsRow(),
3442 prb_ptr->getNbDofsCol(), nb_init_row_dofs, nb_init_col_dofs);
3443 MOFEM_LOG_C("SYNC", Sev::verbose,
3444 "Removed DOFs from problem %s dofs [ %d / %d "
3445 "(before %d / %d) local, %d / %d (before %d / %d)]",
3446 prb_ptr->getName().c_str(), prb_ptr->getNbLocalDofsRow(),
3447 prb_ptr->getNbLocalDofsCol(), nb_init_loc_row_dofs,
3448 nb_init_loc_col_dofs, prb_ptr->getNbGhostDofsRow(),
3449 prb_ptr->getNbGhostDofsCol(), nb_init_ghost_row_dofs,
3450 nb_init_ghost_col_dofs);
3451 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
3452 }
3453
3455}