v0.14.0
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
MoFEM::ProblemsManager Struct Reference

Problem manager is used to build and partition problems. More...

#include <src/interfaces/ProblemsManager.hpp>

Inheritance diagram for MoFEM::ProblemsManager:
[legend]
Collaboration diagram for MoFEM::ProblemsManager:
[legend]

Public Types

enum  MarkOP { OR, AND }
 

Public Member Functions

MoFEMErrorCode query_interface (boost::typeindex::type_index type_index, UnknownInterface **iface) const
 
 ProblemsManager (const MoFEM::Core &core)
 
virtual ~ProblemsManager ()=default
 
MoFEMErrorCode getOptions ()
 
DEPRECATED MoFEMErrorCode 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. More...
 
MoFEMErrorCode buildProblem (const std::string name, const bool square_matrix, int verb=VERBOSE)
 build problem data structures More...
 
MoFEMErrorCode buildProblem (Problem *problem_ptr, const bool square_matrix, int verb=VERBOSE)
 build problem data structures More...
 
MoFEMErrorCode buildProblemOnDistributedMesh (const std::string name, const bool square_matrix, int verb=VERBOSE)
 build problem data structures, assuming that mesh is distributed (collective) More...
 
MoFEMErrorCode buildProblemOnDistributedMesh (Problem *problem_ptr, const bool square_matrix=true, int verb=VERBOSE)
 build problem data structures, assuming that mesh is distributed (collective) More...
 
MoFEMErrorCode 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 More...
 
MoFEMErrorCode 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 More...
 
MoFEMErrorCode 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 More...
 
MoFEMErrorCode partitionSimpleProblem (const std::string name, int verb=VERBOSE)
 partition problem dofs More...
 
MoFEMErrorCode partitionProblem (const std::string name, int verb=VERBOSE)
 partition problem dofs (collective) More...
 
MoFEMErrorCode printPartitionedProblem (const Problem *problem_ptr, int verb=VERBOSE)
 
MoFEMErrorCode debugPartitionedProblem (const Problem *problem_ptr, int verb=VERBOSE)
 
MoFEMErrorCode partitionFiniteElements (const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
 partition finite elements More...
 
MoFEMErrorCode partitionGhostDofs (const std::string name, int verb=VERBOSE)
 determine ghost nodes More...
 
MoFEMErrorCode partitionGhostDofsOnDistributedMesh (const std::string name, int verb=VERBOSE)
 determine ghost nodes on distributed meshes More...
 
MoFEMErrorCode getFEMeshset (const std::string prb_name, const std::string &fe_name, EntityHandle *meshset) const
 create add entities of finite element in the problem More...
 
MoFEMErrorCode getProblemElementsLayout (const std::string name, const std::string &fe_name, PetscLayout *layout) const
 Get layout of elements in the problem. More...
 
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. More...
 
MoFEMErrorCode removeDofsOnEntitiesNotDistributed (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. More...
 
MoFEMErrorCode 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. More...
 
MoFEMErrorCode removeDofsOnEntitiesNotDistributed (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. More...
 
MoFEMErrorCode 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. More...
 
MoFEMErrorCode 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 broke space. More...
 
MoFEMErrorCode markDofs (const std::string problem_name, RowColData rc, const enum MarkOP op, const Range ents, std::vector< unsigned char > &marker) const
 Create vector with marked indices. More...
 
DEPRECATED MoFEMErrorCode markDofs (const std::string problem_name, RowColData rc, const Range ents, std::vector< unsigned char > &marker) const
 
MoFEMErrorCode 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
 Mark DOFs. More...
 
MoFEMErrorCode 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 indices. More...
 
MoFEMErrorCode addFieldToEmptyFieldBlocks (const std::string problem_name, const std::string row_field, const std::string col_field) const
 add empty block to problem More...
 
- Public Member Functions inherited from MoFEM::UnknownInterface
template<class IFACE >
MoFEMErrorCode registerInterface (bool error_if_registration_failed=true)
 Register interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE *&iface) const
 Get interface reference to pointer of interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE **const iface) const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get reference to interface. More...
 
template<class IFACE >
IFACE * getInterface () const
 Function returning pointer to interface. More...
 
virtual ~UnknownInterface ()=default
 

Public Attributes

MoFEM::CorecOre
 
PetscBool buildProblemFromFields
 
PetscBool synchroniseProblemEntities
 DOFs in fields, not from DOFs on elements. More...
 

Private Attributes

PetscLogEvent MOFEM_EVENT_ProblemsManager
 

Additional Inherited Members

- Static Public Member Functions inherited from MoFEM::UnknownInterface
static MoFEMErrorCode getLibVersion (Version &version)
 Get library version. More...
 
static MoFEMErrorCode getFileVersion (moab::Interface &moab, Version &version)
 Get database major version. More...
 
static MoFEMErrorCode setFileVersion (moab::Interface &moab, Version version=Version(MoFEM_VERSION_MAJOR, MoFEM_VERSION_MINOR, MoFEM_VERSION_BUILD))
 Get database major version. More...
 
static MoFEMErrorCode getInterfaceVersion (Version &version)
 Get database major version. More...
 

Detailed Description

Problem manager is used to build and partition problems.

Examples
boundary_marker.cpp, build_large_problem.cpp, build_problems.cpp, child_and_parent.cpp, continuity_check_on_contact_prism_side_ele.cpp, continuity_check_on_skeleton_3d.cpp, EshelbianPlasticity.cpp, forces_and_sources_testing_edge_element.cpp, forces_and_sources_testing_flat_prism_element.cpp, forces_and_sources_testing_users_base.cpp, free_surface.cpp, hanging_node_approx.cpp, hcurl_divergence_operator_2d.cpp, heat_method.cpp, helmholtz.cpp, level_set.cpp, mesh_insert_interface_atom.cpp, mixed_poisson.cpp, nonlinear_dynamics.cpp, nonlinear_elastic.cpp, photon_diffusion.cpp, plate.cpp, prism_elements_from_surface.cpp, prism_polynomial_approximation.cpp, quad_polynomial_approximation.cpp, reaction_diffusion.cpp, Remodeling.cpp, remove_entities_from_problem.cpp, remove_entities_from_problem_not_partitioned.cpp, seepage.cpp, test_cache_on_entities.cpp, and thermo_elastic.cpp.

Definition at line 21 of file ProblemsManager.hpp.

Member Enumeration Documentation

◆ MarkOP

Enumerator
OR 
AND 

Definition at line 416 of file ProblemsManager.hpp.

416 { OR, AND };

Constructor & Destructor Documentation

◆ ProblemsManager()

MoFEM::ProblemsManager::ProblemsManager ( const MoFEM::Core core)

Definition at line 55 of file ProblemsManager.cpp.

56  : cOre(const_cast<MoFEM::Core &>(core)),
57  buildProblemFromFields(PETSC_FALSE),
58  synchroniseProblemEntities(PETSC_FALSE) {
59  PetscLogEventRegister("ProblemsManager", 0, &MOFEM_EVENT_ProblemsManager);
60 }

◆ ~ProblemsManager()

virtual MoFEM::ProblemsManager::~ProblemsManager ( )
virtualdefault

Member Function Documentation

◆ addFieldToEmptyFieldBlocks()

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

add empty block to problem

MatrixManager assumes that all blocks, i.e. all fields combinations are non zero. This is not always the case, to optimise code and reduce memory usage user can specify which blocks are empty.

Parameters
problem_nameproblem name
row_fieldrow filed name
col_fieldcol field name
Returns
MoFEMErrorCode

Definition at line 3695 of file ProblemsManager.cpp.

3697  {
3698 
3699  Interface &m_field = cOre;
3701 
3702  const auto problem_ptr = m_field.get_problem(problem_name);
3703  auto get_field_id = [&](const std::string field_name) {
3704  return m_field.get_field_structure(field_name)->getId();
3705  };
3706  const auto row_id = get_field_id(row_field);
3707  const auto col_id = get_field_id(col_field);
3708 
3709  problem_ptr->addFieldToEmptyFieldBlocks(BlockFieldPair(row_id, col_id));
3710 
3712 }

◆ debugPartitionedProblem()

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

Definition at line 2089 of file ProblemsManager.cpp.

2089  {
2090  MoFEM::Interface &m_field = cOre;
2092 
2093  auto save_ent = [](moab::Interface &moab, const std::string name,
2094  const EntityHandle ent) {
2096  EntityHandle out_meshset;
2097  CHKERR moab.create_meshset(MESHSET_SET, out_meshset);
2098  CHKERR moab.add_entities(out_meshset, &ent, 1);
2099  CHKERR moab.write_file(name.c_str(), "VTK", "", &out_meshset, 1);
2100  CHKERR moab.delete_entities(&out_meshset, 1);
2102  };
2103 
2104  if (debug > 0) {
2105 
2107  NumeredDofEntitysByIdx;
2108  NumeredDofEntitysByIdx::iterator dit, hi_dit;
2109  const NumeredDofEntitysByIdx *numered_dofs_ptr[] = {
2110  &(problem_ptr->numeredRowDofsPtr->get<Idx_mi_tag>()),
2111  &(problem_ptr->numeredColDofsPtr->get<Idx_mi_tag>())};
2112 
2113  int *nbdof_ptr[] = {&problem_ptr->nbDofsRow, &problem_ptr->nbDofsCol};
2114  int *local_nbdof_ptr[] = {&problem_ptr->nbLocDofsRow,
2115  &problem_ptr->nbLocDofsCol};
2116 
2117  for (int ss = 0; ss < 2; ss++) {
2118 
2119  dit = numered_dofs_ptr[ss]->begin();
2120  hi_dit = numered_dofs_ptr[ss]->end();
2121  for (; dit != hi_dit; dit++) {
2122  if ((*dit)->getPart() == (unsigned int)m_field.get_comm_rank()) {
2123  if ((*dit)->getPetscLocalDofIdx() < 0) {
2124  std::ostringstream zz;
2125  zz << "rank " << m_field.get_comm_rank() << " " << **dit;
2126  SETERRQ2(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2127  "local dof index for %d (0-row, 1-col) not set, i.e. has "
2128  "negative value\n %s",
2129  ss, zz.str().c_str());
2130  }
2131  if ((*dit)->getPetscLocalDofIdx() >= *local_nbdof_ptr[ss]) {
2132  std::ostringstream zz;
2133  zz << "rank " << m_field.get_comm_rank() << " " << **dit;
2134  SETERRQ2(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2135  "local dofs for %d (0-row, 1-col) out of range\n %s", ss,
2136  zz.str().c_str());
2137  }
2138  } else {
2139  if ((*dit)->getPetscGlobalDofIdx() < 0) {
2140 
2141  const EntityHandle ent = (*dit)->getEnt();
2142  CHKERR save_ent(
2143  m_field.get_moab(),
2144  "debug_part" +
2145  boost::lexical_cast<std::string>(m_field.get_comm_rank()) +
2146  "_negative_global_index.vtk",
2147  ent);
2148 
2149  std::ostringstream zz;
2150  zz << "rank " << m_field.get_comm_rank() << " "
2151  << dit->get()->getBitRefLevel() << " " << **dit;
2152  SETERRQ2(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2153  "global dof index for %d (0-row, 1-col) row not set, i.e. "
2154  "has negative value\n %s",
2155  ss, zz.str().c_str());
2156  }
2157  if ((*dit)->getPetscGlobalDofIdx() >= *nbdof_ptr[ss]) {
2158  std::ostringstream zz;
2159  zz << "rank " << m_field.get_comm_rank() << " nb_dofs "
2160  << *nbdof_ptr[ss] << " " << **dit;
2161  SETERRQ2(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2162  "global dofs for %d (0-row, 1-col) out of range\n %s", ss,
2163  zz.str().c_str());
2164  }
2165  }
2166  }
2167  }
2168  }
2170 }

◆ getOptions()

MoFEMErrorCode MoFEM::ProblemsManager::getOptions ( )

Definition at line 62 of file ProblemsManager.cpp.

62  {
63  MoFEM::Interface &m_field = cOre;
65  CHKERR PetscOptionsBegin(m_field.get_comm(), "", "Problem manager", "none");
66  {
67  CHKERR PetscOptionsBool(
68  "-problem_build_from_fields",
69  "Add DOFs to problem directly from fields not through DOFs on elements",
71  }
72  ierr = PetscOptionsEnd();
73  CHKERRG(ierr);
75 }

◆ 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

Get DOFs on side entities for broke space.

Parameters
dof_view
problem_name
rcrow or column
field_name
entsside entities
bridge_dimdimension of bridge entity (dofs are on iterator by have associated side entity)
lo_coeff
hi_coeff
lo_order
hi_order
verb
debug
Returns
MoFEMErrorCode

Definition at line 2619 of file ProblemsManager.cpp.

2627  {
2628  MoFEM::Interface &m_field = cOre;
2630 
2631  switch (rc) {
2632  case ROW:
2633  case COL:
2634  break;
2635  default:
2636  SETERRQ(m_field.get_comm(), MOFEM_INVALID_DATA, "invalid RowColData");
2637  break;
2638  }
2639 
2640  const Problem *prb_ptr;
2641  CHKERR m_field.get_problem(problem_name, &prb_ptr);
2642 
2643  decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
2644  prb_ptr->numeredRowDofsPtr, nullptr};
2645  if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
2646  numered_dofs[1] = prb_ptr->numeredColDofsPtr;
2647 
2648  Range bridge_ents;
2649  CHKERR m_field.get_moab().get_adjacencies(
2650  ents, bridge_dim, false, bridge_ents, moab::Interface::UNION);
2651 
2652  auto &moab = m_field.get_moab();
2653  const auto bit_number = m_field.get_field_bit_number(field_name);
2654  const auto nb_coeffs =
2656  const auto &side_dof_map = m_field.get_field_structure(field_name)
2657  ->getDofSideMap();
2658 
2659  using NumeredDofEntity_it_view_multiIndex = multi_index_container<
2660 
2661  NumeredDofEntity_multiIndex::iterator, indexed_by<sequenced<>>
2662 
2663  >;
2664  NumeredDofEntity_it_view_multiIndex dofs_it_view;
2665 
2666  for (auto pit = bridge_ents.const_pair_begin();
2667  pit != bridge_ents.const_pair_end(); ++pit) {
2668  auto lo = numered_dofs[rc]->get<Unique_mi_tag>().lower_bound(
2669  DofEntity::getLoFieldEntityUId(bit_number, pit->first));
2670  auto hi = numered_dofs[rc]->get<Unique_mi_tag>().upper_bound(
2671  DofEntity::getHiFieldEntityUId(bit_number, pit->second));
2672 
2673  auto bride_type = moab.type_from_handle(pit->first);
2674 
2675  for (; lo != hi; ++lo) {
2676  if ((*lo)->getDofCoeffIdx() >= lo_coeff &&
2677  (*lo)->getDofCoeffIdx() <= hi_coeff &&
2678  (*lo)->getDofOrder() >= lo_order &&
2679  (*lo)->getDofOrder() <= hi_order) {
2680  auto ent_dof_index = (*lo)->getEntDofIdx();
2681  auto side_it = side_dof_map.at(bride_type)
2682  .get<EntDofIdx_mi_tag>()
2683  .find(std::floor(static_cast<double>(ent_dof_index) /
2684  nb_coeffs));
2685  if (side_it !=
2686  side_dof_map.at(bride_type).get<EntDofIdx_mi_tag>().end()) {
2687  auto bridge_ent = (*lo)->getEnt();
2688  auto type = side_it->type;
2689  auto side = side_it->side;
2690  auto dim = CN::Dimension(type);
2691  EntityHandle side_ent = 0;
2692  CHKERR moab.side_element(bridge_ent, dim, side, side_ent);
2693  if (ents.find(side_ent) != ents.end()) {
2694  dofs_it_view.emplace_back(numered_dofs[rc]->project<0>(lo));
2695  }
2696  } else {
2697 #ifndef NDEBUG
2698  MOFEM_LOG("SELF", Sev::error)
2699  << *m_field.get_field_structure(field_name);
2700  MOFEM_LOG("SELF", Sev::error)
2701  << "side not found for entity " << CN::EntityTypeName(bride_type);
2702  MOFEM_LOG("SELF", Sev::error)
2703  << "ent_dof_index / nb_coeffs "
2704  << std::floor(static_cast<double>(ent_dof_index) / nb_coeffs);
2705  MOFEM_LOG("SELF", Sev::error)
2706  << "side_dof_map.size() " << side_dof_map.size();
2707 #endif // NDEBUG
2708  SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2709  "side not found - you will get more information in debug");
2710  }
2711  }
2712  }
2713  }
2714 
2715  if (verb > QUIET) {
2716  for (auto &dof : dofs_it_view)
2717  MOFEM_LOG("SYNC", Sev::noisy) << **dof;
2718  MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::noisy);
2719  }
2720 
2721  vec_dof_view.reserve(vec_dof_view.size() + dofs_it_view.size());
2722  for (auto dit : dofs_it_view)
2723  vec_dof_view.push_back(*dit);
2724 
2726 }

◆ markDofs() [1/3]

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

Create vector with marked indices.

Vector with local DOFs marked by entities

Parameters
problem_name
row
ents
marker
Returns
MoFEMErrorCode
Examples
helmholtz.cpp, and test_cache_on_entities.cpp.

Definition at line 3562 of file ProblemsManager.cpp.

3564  {
3565 
3566  Interface &m_field = cOre;
3567  const Problem *problem_ptr;
3569  CHKERR m_field.get_problem(problem_name, &problem_ptr);
3570  boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
3571  switch (rc) {
3572  case ROW:
3573  dofs = problem_ptr->getNumeredRowDofsPtr();
3574  break;
3575  case COL:
3576  dofs = problem_ptr->getNumeredColDofsPtr();
3577  default:
3578  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
3579  }
3580  marker.resize(dofs->size(), 0);
3581  std::vector<unsigned char> marker_tmp;
3582 
3583  switch (op) {
3584  case MarkOP::OR:
3585  for (auto p = ents.pair_begin(); p != ents.pair_end(); ++p) {
3586  auto lo = dofs->get<Ent_mi_tag>().lower_bound(p->first);
3587  auto hi = dofs->get<Ent_mi_tag>().upper_bound(p->second);
3588  for (; lo != hi; ++lo)
3589  marker[(*lo)->getPetscLocalDofIdx()] |= 1;
3590  }
3591  break;
3592  case MarkOP::AND:
3593  marker_tmp.resize(dofs->size(), 0);
3594  for (auto p = ents.pair_begin(); p != ents.pair_end(); ++p) {
3595  auto lo = dofs->get<Ent_mi_tag>().lower_bound(p->first);
3596  auto hi = dofs->get<Ent_mi_tag>().upper_bound(p->second);
3597  for (; lo != hi; ++lo)
3598  marker_tmp[(*lo)->getPetscLocalDofIdx()] = 1;
3599  }
3600  for (int i = 0; i != marker.size(); ++i) {
3601  marker[i] &= marker_tmp[i];
3602  }
3603  break;
3604  }
3605 
3607 }

◆ markDofs() [2/3]

DEPRECATED MoFEMErrorCode MoFEM::ProblemsManager::markDofs ( const std::string  problem_name,
RowColData  rc,
const Range  ents,
std::vector< unsigned char > &  marker 
) const
inline
Deprecated:
use function with MarkOP

Definition at line 438 of file ProblemsManager.hpp.

439  {
440  return markDofs(problem_name, rc, MarkOP::OR, ents, marker);
441  }

◆ markDofs() [3/3]

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 indices.

Vector with local DOFs marked by entities

Parameters
problem_name
row
ents
marker
Returns
MoFEMErrorCode

Definition at line 3657 of file ProblemsManager.cpp.

3663  {
3664  Interface &m_field = cOre;
3666 
3667  const Problem *problem_ptr;
3668  CHKERR m_field.get_problem(problem_name, &problem_ptr);
3669  boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
3670  switch (rc) {
3671  case ROW:
3672  dofs = problem_ptr->getNumeredRowDofsPtr();
3673  break;
3674  case COL:
3675  dofs = problem_ptr->getNumeredColDofsPtr();
3676  break;
3677  default:
3678  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
3679  }
3680  marker.resize(dofs->size(), 0);
3681 
3682  for (auto &dof : vec_dof_view) {
3683  if (auto dof_ptr = dof.lock()) {
3684  if (op == MarkOP::OR)
3685  marker[dof_ptr->getPetscLocalDofIdx()] |= 1;
3686  else
3687  marker[dof_ptr->getPetscLocalDofIdx()] &= 1;
3688  }
3689  }
3690 
3692 }

◆ 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

Mark DOFs.

Parameters
problem_name
rc
field_name
lo
hi
op
marker
Returns
MoFEMErrorCode

Definition at line 3609 of file ProblemsManager.cpp.

3612  {
3613 
3614  Interface &m_field = cOre;
3615  const Problem *problem_ptr;
3617  CHKERR m_field.get_problem(problem_name, &problem_ptr);
3618  boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
3619  switch (rc) {
3620  case ROW:
3621  dofs = problem_ptr->getNumeredRowDofsPtr();
3622  break;
3623  case COL:
3624  dofs = problem_ptr->getNumeredColDofsPtr();
3625  default:
3626  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
3627  }
3628  marker.resize(dofs->size(), 0);
3629 
3630  auto dof_lo = dofs->get<Unique_mi_tag>().lower_bound(
3631  FieldEntity::getLoBitNumberUId(m_field.get_field_bit_number(field_name)));
3632  auto dof_hi = dofs->get<Unique_mi_tag>().upper_bound(
3633  FieldEntity::getHiBitNumberUId(m_field.get_field_bit_number(field_name)));
3634 
3635  auto marker_ref = [marker](auto &it) -> unsigned int & {
3636  return marker[(*it)->getPetscLocalDofIdx()];
3637  };
3638 
3639  switch (op) {
3640  case MarkOP::OR:
3641  for (; dof_lo != dof_hi; ++dof_lo)
3642  if ((*dof_lo)->getDofCoeffIdx() >= lo &&
3643  (*dof_lo)->getDofCoeffIdx() <= hi)
3644  marker[(*dof_lo)->getPetscLocalDofIdx()] |= c;
3645  break;
3646  case MarkOP::AND:
3647  for (; dof_lo != dof_hi; ++dof_lo)
3648  if ((*dof_lo)->getDofCoeffIdx() >= lo &&
3649  (*dof_lo)->getDofCoeffIdx() <= hi)
3650  marker[(*dof_lo)->getPetscLocalDofIdx()] &= c;
3651  break;
3652  }
3653 
3655 }

◆ printPartitionedProblem()

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

Definition at line 2070 of file ProblemsManager.cpp.

2070  {
2071  MoFEM::Interface &m_field = cOre;
2073 
2074  if (verb > QUIET) {
2075 
2076  MOFEM_LOG("SYNC", Sev::inform)
2077  << problem_ptr->getName() << " Nb. local dof "
2078  << problem_ptr->getNbLocalDofsRow() << " by "
2079  << problem_ptr->getNbLocalDofsCol() << " nb global dofs "
2080  << problem_ptr->getNbDofsRow() << " by " << problem_ptr->getNbDofsCol();
2081 
2082  MOFEM_LOG_SYNCHRONISE(m_field.get_comm())
2083  }
2084 
2086 }

◆ query_interface()

MoFEMErrorCode MoFEM::ProblemsManager::query_interface ( boost::typeindex::type_index  type_index,
UnknownInterface **  iface 
) const
virtual

Implements MoFEM::UnknownInterface.

Definition at line 49 of file ProblemsManager.cpp.

50  {
51  *iface = const_cast<ProblemsManager *>(this);
52  return 0;
53 }

◆ 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 
)

Remove DOFs from problem on broken space.

Parameters
problem_name
field_name
ents
lo_coeff
hi_coeff
lo_order
hi_order
verb
debug
Returns
MoFEMErrorCode

Definition at line 2728 of file ProblemsManager.cpp.

2731  {
2732 
2733  MoFEM::Interface &m_field = cOre;
2735 
2736  switch (rc) {
2737  case ROW:
2738  case COL:
2739  break;
2740  default:
2741  SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
2742  }
2743 
2744  const Problem *prb_ptr;
2745  CHKERR m_field.get_problem(problem_name, &prb_ptr);
2746 
2747  decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
2748  prb_ptr->numeredRowDofsPtr, nullptr};
2749  if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
2750  numered_dofs[1] = prb_ptr->numeredColDofsPtr;
2751 
2752  int *nbdof_ptr[] = {&prb_ptr->nbDofsRow, &prb_ptr->nbDofsCol};
2753  int *local_nbdof_ptr[] = {&prb_ptr->nbLocDofsRow, &prb_ptr->nbLocDofsCol};
2754  int *ghost_nbdof_ptr[] = {&prb_ptr->nbGhostDofsRow, &prb_ptr->nbGhostDofsCol};
2755 
2756  const int nb_init_row_dofs = prb_ptr->getNbDofsRow();
2757  const int nb_init_col_dofs = prb_ptr->getNbDofsCol();
2758  const int nb_init_loc_row_dofs = prb_ptr->getNbLocalDofsRow();
2759  const int nb_init_ghost_row_dofs = prb_ptr->getNbGhostDofsRow();
2760  const int nb_init_ghost_col_dofs = prb_ptr->getNbGhostDofsCol();
2761 
2762  if (numered_dofs[rc]) {
2763 
2764  if (verb >= NOISY)
2765  MOFEM_LOG_C("SYNC", Sev::noisy,
2766  "Number of DOFs in multi-index %d and to delete %d\n",
2767  numered_dofs[rc]->size(), vec_dof_view.size());
2768 
2769  // erase dofs from problem
2770  for (auto weak_dit : vec_dof_view)
2771  if (auto dit = weak_dit.lock()) {
2772  numered_dofs[rc]->erase(dit->getLocalUniqueId());
2773  }
2774 
2775  if (verb >= NOISY)
2776  MOFEM_LOG_C("SYNC", Sev::noisy,
2777  "Number of DOFs in multi-index after delete %d\n",
2778  numered_dofs[rc]->size());
2779 
2780  // get current number of ghost dofs
2781  int nb_local_dofs = 0;
2782  int nb_ghost_dofs = 0;
2783  for (auto dit = numered_dofs[rc]->get<PetscLocalIdx_mi_tag>().begin();
2784  dit != numered_dofs[rc]->get<PetscLocalIdx_mi_tag>().end(); ++dit) {
2785  if ((*dit)->getPetscLocalDofIdx() >= 0 &&
2786  (*dit)->getPetscLocalDofIdx() < *(local_nbdof_ptr[rc]))
2787  ++nb_local_dofs;
2788  else if ((*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[rc]))
2789  ++nb_ghost_dofs;
2790  else
2791  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2792  "Impossible case. You could run problem on no distributed "
2793  "mesh. That is not implemented. Dof local index is %d",
2794  (*dit)->getPetscLocalDofIdx());
2795  }
2796 
2797  // get indices
2798  auto get_indices_by_tag = [&](auto tag, auto &indices, bool only_local) {
2799  const int nb_dofs = numered_dofs[rc]->size();
2800  indices.clear();
2801  indices.reserve(nb_dofs);
2802  for (auto dit = numered_dofs[rc]->get<decltype(tag)>().begin();
2803  dit != numered_dofs[rc]->get<decltype(tag)>().end(); ++dit) {
2804  bool add = true;
2805  if (only_local) {
2806  if ((*dit)->getPetscLocalDofIdx() < 0 ||
2807  (*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[rc])) {
2808  add = false;
2809  }
2810  }
2811  if (add)
2812  indices.push_back(decltype(tag)::get_index(dit));
2813  }
2814  };
2815 
2816  auto get_indices_by_uid = [&](auto tag, auto &indices) {
2817  const int nb_dofs = numered_dofs[rc]->size();
2818  indices.clear();
2819  indices.reserve(nb_dofs);
2820  for (auto dit = numered_dofs[rc]->begin(); dit != numered_dofs[rc]->end();
2821  ++dit)
2822  indices.push_back(decltype(tag)::get_index(dit));
2823  };
2824 
2825  auto get_sub_ao = [&](auto sub_data) {
2826  if (rc == 0) {
2827  return sub_data->getSmartRowMap();
2828  } else {
2829  return sub_data->getSmartColMap();
2830  }
2831  };
2832 
2833  auto set_sub_is_and_ao = [&rc, &prb_ptr](auto sub_data, auto is, auto ao) {
2834  if (rc == ROW) {
2835  sub_data->rowIs = is;
2836  sub_data->rowMap = ao;
2837  sub_data->colIs = is; // if square problem col is equal to row
2838  sub_data->colMap = ao;
2839  } else {
2840  sub_data->colIs = is;
2841  sub_data->colMap = ao;
2842  }
2843  };
2844 
2845  auto apply_symmetry = [&rc, &prb_ptr](auto sub_data) {
2846  if (rc == ROW) {
2847  if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
2848  sub_data->colIs = sub_data->getSmartRowIs();
2849  sub_data->colMap = sub_data->getSmartRowMap();
2850  }
2851  }
2852  };
2853 
2854  auto concatenate_dofs = [&](auto tag, auto &indices,
2855  const auto local_only) {
2857  get_indices_by_tag(tag, indices, local_only);
2858 
2859  SmartPetscObj<AO> ao;
2860  // Create AO from app indices (i.e. old), to pestc indices (new after
2861  // remove)
2862  if (local_only)
2863  ao = createAOMapping(m_field.get_comm(), indices.size(),
2864  &*indices.begin(), PETSC_NULL);
2865  else
2866  ao = createAOMapping(PETSC_COMM_SELF, indices.size(), &*indices.begin(),
2867  PETSC_NULL);
2868 
2869  // Set mapping to sub dm data
2870  if (local_only) {
2871  if (auto sub_data = prb_ptr->getSubData()) {
2872  // create is and then map it to main problem of sub-problem
2873  auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
2874  &*indices.begin(), PETSC_COPY_VALUES);
2875  // get old app, i.e. oroginal befor sub indices, and ao, from app,
2876  // to petsc sub indices.
2877  auto sub_ao = get_sub_ao(sub_data);
2878  CHKERR AOPetscToApplicationIS(sub_ao, sub_is);
2879  sub_ao = createAOMappingIS(sub_is, PETSC_NULL);
2880  // set new sub ao
2881  set_sub_is_and_ao(sub_data, sub_is, sub_ao);
2882  apply_symmetry(sub_data);
2883  } else {
2884  // create sub data
2885  prb_ptr->getSubData() = boost::make_shared<Problem::SubProblemData>();
2886  auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
2887  &*indices.begin(), PETSC_COPY_VALUES);
2888  // set sub is ao
2889  set_sub_is_and_ao(prb_ptr->getSubData(), sub_is, ao);
2890  apply_symmetry(prb_ptr->getSubData());
2891  }
2892  }
2893 
2894  get_indices_by_uid(tag, indices);
2895  CHKERR AOApplicationToPetsc(ao, indices.size(), &*indices.begin());
2896 
2898  };
2899 
2900  // set indices index
2901  auto set_concatenated_indices = [&]() {
2902  std::vector<int> global_indices;
2903  std::vector<int> local_indices;
2905  CHKERR concatenate_dofs(PetscGlobalIdx_mi_tag(), global_indices, true);
2906  CHKERR concatenate_dofs(PetscLocalIdx_mi_tag(), local_indices, false);
2907  auto gi = global_indices.begin();
2908  auto li = local_indices.begin();
2909  for (auto dit = numered_dofs[rc]->begin(); dit != numered_dofs[rc]->end();
2910  ++dit) {
2911  auto mod = NumeredDofEntity_part_and_all_indices_change(
2912  (*dit)->getPart(), (*dit)->getDofIdx(), *gi, *li);
2913  bool success = numered_dofs[rc]->modify(dit, mod);
2914  if (!success)
2915  SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
2916  "can not set negative indices");
2917  ++gi;
2918  ++li;
2919  }
2921  };
2922  CHKERR set_concatenated_indices();
2923 
2924  MPI_Allreduce(&nb_local_dofs, nbdof_ptr[rc], 1, MPI_INT, MPI_SUM,
2925  m_field.get_comm());
2926  *(local_nbdof_ptr[rc]) = nb_local_dofs;
2927  *(ghost_nbdof_ptr[rc]) = nb_ghost_dofs;
2928 
2929  if (debug)
2930  for (auto dof : (*numered_dofs[rc])) {
2931  if (dof->getPetscGlobalDofIdx() < 0) {
2932  SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2933  "Negative global idx");
2934  }
2935  if (dof->getPetscLocalDofIdx() < 0) {
2936  SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2937  "Negative local idx");
2938  }
2939  }
2940 
2941  } else {
2942 
2943  *(nbdof_ptr[1]) = *(nbdof_ptr[0]);
2944  *(local_nbdof_ptr[1]) = *(local_nbdof_ptr[0]);
2945  *(ghost_nbdof_ptr[1]) = *(ghost_nbdof_ptr[0]);
2946  }
2947 
2948  if (verb > QUIET) {
2949  MOFEM_LOG_C(
2950  "WORLD", Sev::inform,
2951  "Removed DOFs from problem %s dofs [%d / %d (before %d / %d) global]",
2952  prb_ptr->getName().c_str(), prb_ptr->getNbDofsRow(),
2953  prb_ptr->getNbDofsCol(), nb_init_row_dofs, nb_init_col_dofs);
2954  MOFEM_LOG_C("SYNC", Sev::verbose,
2955  "Removed DOFs from problem %s dofs [ %d / %d "
2956  "(before %d / %d) local, %d / %d (before %d / %d)]",
2957  prb_ptr->getName().c_str(), prb_ptr->getNbLocalDofsRow(),
2958  prb_ptr->getNbLocalDofsCol(), nb_init_loc_row_dofs,
2959  nb_init_loc_row_dofs, prb_ptr->getNbGhostDofsRow(),
2960  prb_ptr->getNbGhostDofsCol(), nb_init_ghost_row_dofs,
2961  nb_init_ghost_col_dofs);
2962  MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
2963  }
2964 
2966 }

◆ removeDofsOnEntitiesNotDistributed() [1/2]

MoFEMErrorCode MoFEM::ProblemsManager::removeDofsOnEntitiesNotDistributed ( 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.

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
Note
Use this function for non distributed meshes

Definition at line 3534 of file ProblemsManager.cpp.

3538  {
3539  MoFEM::Interface &m_field = cOre;
3541 
3542  auto bit_manager = m_field.getInterface<BitRefManager>();
3543 
3544  Range ents;
3545  if (ents_ptr) {
3546  ents = *ents_ptr;
3547  CHKERR bit_manager->filterEntitiesByRefLevel(bit_ref_level, bit_ref_mask,
3548  ents, verb);
3549  } else {
3550  CHKERR bit_manager->getEntitiesByRefLevel(bit_ref_level, bit_ref_mask, ents,
3551  verb);
3552  }
3553 
3555  lo_coeff, hi_coeff, lo_order,
3556  hi_order, verb, debug);
3557 
3559 }

◆ removeDofsOnEntitiesNotDistributed() [2/2]

MoFEMErrorCode MoFEM::ProblemsManager::removeDofsOnEntitiesNotDistributed ( 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.

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
Note
Use this function for non-distributed meshes
Examples
remove_entities_from_problem_not_partitioned.cpp.

Definition at line 3240 of file ProblemsManager.cpp.

3243  {
3244 
3245  MoFEM::Interface &m_field = cOre;
3247 
3248  const Problem *prb_ptr;
3249  CHKERR m_field.get_problem(problem_name, &prb_ptr);
3250 
3251  decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
3252  prb_ptr->numeredRowDofsPtr, nullptr};
3253  if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
3254  numered_dofs[1] = prb_ptr->numeredColDofsPtr;
3255 
3256  int *nbdof_ptr[] = {&prb_ptr->nbDofsRow, &prb_ptr->nbDofsCol};
3257  int *local_nbdof_ptr[] = {&prb_ptr->nbLocDofsRow, &prb_ptr->nbLocDofsCol};
3258  int *ghost_nbdof_ptr[] = {&prb_ptr->nbGhostDofsRow, &prb_ptr->nbGhostDofsCol};
3259 
3260  const int nb_init_row_dofs = prb_ptr->getNbDofsRow();
3261  const int nb_init_col_dofs = prb_ptr->getNbDofsCol();
3262  const int nb_init_loc_row_dofs = prb_ptr->getNbLocalDofsRow();
3263  // const int nb_init_loc_col_dofs = prb_ptr->getNbLocalDofsCol();
3264  const int nb_init_ghost_row_dofs = prb_ptr->getNbGhostDofsRow();
3265  const int nb_init_ghost_col_dofs = prb_ptr->getNbGhostDofsCol();
3266 
3267  const std::array<int, 2> nb_init_dofs = {nb_init_row_dofs, nb_init_col_dofs};
3268 
3269  for (int s = 0; s != 2; ++s)
3270  if (numered_dofs[s]) {
3271 
3272  typedef multi_index_container<
3273 
3274  NumeredDofEntity_multiIndex::iterator, indexed_by<sequenced<>>
3275 
3276  >
3277  NumeredDofEntity_it_view_multiIndex;
3278 
3279  const auto bit_number = m_field.get_field_bit_number(field_name);
3280  NumeredDofEntity_it_view_multiIndex dofs_it_view;
3281 
3282  // Set -1 to global and local dofs indices
3283  for (auto pit = ents.const_pair_begin(); pit != ents.const_pair_end();
3284  ++pit) {
3285  auto lo = numered_dofs[s]->get<Unique_mi_tag>().lower_bound(
3286  DofEntity::getLoFieldEntityUId(bit_number, pit->first));
3287  auto hi = numered_dofs[s]->get<Unique_mi_tag>().upper_bound(
3288  DofEntity::getHiFieldEntityUId(bit_number, pit->second));
3289 
3290  for (; lo != hi; ++lo)
3291  if ((*lo)->getDofCoeffIdx() >= lo_coeff &&
3292  (*lo)->getDofCoeffIdx() <= hi_coeff &&
3293  (*lo)->getDofOrder() >= lo_order &&
3294  (*lo)->getDofOrder() <= hi_order)
3295  dofs_it_view.emplace_back(numered_dofs[s]->project<0>(lo));
3296  }
3297 
3298  if (verb > QUIET) {
3299  for (auto &dof : dofs_it_view)
3300  MOFEM_LOG("SYNC", Sev::noisy) << **dof;
3301  }
3302 
3303  // set negative index
3304  auto mod = NumeredDofEntity_part_and_all_indices_change(-1, -1, -1, -1);
3305  for (auto dit : dofs_it_view) {
3306  bool success = numered_dofs[s]->modify(dit, mod);
3307  if (!success)
3308  SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3309  "can not set negative indices");
3310  }
3311 
3312  // create weak view
3313  std::vector<boost::weak_ptr<NumeredDofEntity>> dosf_weak_view;
3314  dosf_weak_view.reserve(dofs_it_view.size());
3315  for (auto dit : dofs_it_view)
3316  dosf_weak_view.push_back(*dit);
3317 
3318  if (verb >= NOISY)
3319  MOFEM_LOG_C("SYNC", Sev::noisy,
3320  "Number of DOFs in multi-index %d and to delete %d\n",
3321  numered_dofs[s]->size(), dofs_it_view.size());
3322 
3323  // erase dofs from problem
3324  for (auto weak_dit : dosf_weak_view)
3325  if (auto dit = weak_dit.lock()) {
3326  numered_dofs[s]->erase(dit->getLocalUniqueId());
3327  }
3328 
3329  if (verb >= NOISY)
3330  MOFEM_LOG_C("SYNC", Sev::noisy,
3331  "Number of DOFs in multi-index after delete %d\n",
3332  numered_dofs[s]->size());
3333 
3334  // get current number of ghost dofs
3335  int nb_global_dof = 0;
3336  int nb_local_dofs = 0;
3337  int nb_ghost_dofs = 0;
3338 
3339  for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
3340  ++dit) {
3341 
3342  if ((*dit)->getDofIdx() >= 0) {
3343 
3344  if ((*dit)->getPetscLocalDofIdx() >= 0 &&
3345  (*dit)->getPetscLocalDofIdx() < *(local_nbdof_ptr[s]))
3346  ++nb_local_dofs;
3347  else if ((*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[s]))
3348  ++nb_ghost_dofs;
3349 
3350  ++nb_global_dof;
3351  }
3352  }
3353 
3354  if (debug) {
3355  MPI_Allreduce(&nb_local_dofs, nbdof_ptr[s], 1, MPI_INT, MPI_SUM,
3356  m_field.get_comm());
3357  if (*(nbdof_ptr[s]) != nb_global_dof)
3358  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3359  "Number of local DOFs do not add up %d != %d",
3360  *(nbdof_ptr[s]), nb_global_dof);
3361  }
3362 
3363  *(nbdof_ptr[s]) = nb_global_dof;
3364  *(local_nbdof_ptr[s]) = nb_local_dofs;
3365  *(ghost_nbdof_ptr[s]) = nb_ghost_dofs;
3366 
3367  // get indices
3368  auto get_indices_by_tag = [&](auto tag) {
3369  std::vector<int> indices;
3370  indices.resize(nb_init_dofs[s], -1);
3371  for (auto dit = numered_dofs[s]->get<Idx_mi_tag>().lower_bound(0);
3372  dit != numered_dofs[s]->get<Idx_mi_tag>().end(); ++dit) {
3373  indices[(*dit)->getDofIdx()] = decltype(tag)::get_index(dit);
3374  }
3375  return indices;
3376  };
3377 
3378  auto renumber = [&](auto tag, auto &indices) {
3380  int idx = 0;
3381  for (auto dit = numered_dofs[s]->get<decltype(tag)>().lower_bound(0);
3382  dit != numered_dofs[s]->get<decltype(tag)>().end(); ++dit) {
3383  indices[(*dit)->getDofIdx()] = idx++;
3384  }
3386  };
3387 
3388  auto get_sub_ao = [&](auto sub_data) {
3389  if (s == 0) {
3390  return sub_data->getSmartRowMap();
3391  } else {
3392  return sub_data->getSmartColMap();
3393  }
3394  };
3395 
3396  auto set_sub_is_and_ao = [&s, &prb_ptr](auto sub_data, auto is, auto ao) {
3397  if (s == 0) {
3398  sub_data->rowIs = is;
3399  sub_data->rowMap = ao;
3400  sub_data->colIs = is;
3401  sub_data->colMap = ao;
3402  } else {
3403  sub_data->colIs = is;
3404  sub_data->colMap = ao;
3405  }
3406  };
3407 
3408  auto apply_symmetry = [&s, &prb_ptr](auto sub_data) {
3409  if (s == 0) {
3410  if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3411  sub_data->colIs = sub_data->getSmartRowIs();
3412  sub_data->colMap = sub_data->getSmartRowMap();
3413  }
3414  }
3415  };
3416 
3417  auto set_sub_data = [&](auto &indices) {
3419  if (auto sub_data = prb_ptr->getSubData()) {
3420  // create is and then map it to main problem of sub-problem
3421  auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
3422  &*indices.begin(), PETSC_COPY_VALUES);
3423  // get old app, i.e. oroginal befor sub indices, and ao, from
3424  // app, to petsc sub indices.
3425  auto sub_ao = get_sub_ao(sub_data);
3426  CHKERR AOPetscToApplicationIS(sub_ao, sub_is);
3427  sub_ao = createAOMappingIS(sub_is, PETSC_NULL);
3428  // set new sub ao
3429  set_sub_is_and_ao(sub_data, sub_is, sub_ao);
3430  apply_symmetry(sub_data);
3431  } else {
3432  prb_ptr->getSubData() = boost::make_shared<Problem::SubProblemData>();
3433  auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
3434  &*indices.begin(), PETSC_COPY_VALUES);
3435  auto sub_ao = createAOMappingIS(sub_is, PETSC_NULL);
3436  // set sub is ao
3437  set_sub_is_and_ao(prb_ptr->getSubData(), sub_is, sub_ao);
3438  apply_symmetry(prb_ptr->getSubData());
3439  }
3441  };
3442 
3443  auto global_indices = get_indices_by_tag(PetscGlobalIdx_mi_tag());
3444  auto local_indices = get_indices_by_tag(PetscLocalIdx_mi_tag());
3445  CHKERR set_sub_data(global_indices);
3446  CHKERR renumber(PetscGlobalIdx_mi_tag(), global_indices);
3447  CHKERR renumber(PetscLocalIdx_mi_tag(), local_indices);
3448 
3449  int i = 0;
3450  for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
3451  ++dit) {
3452  auto idx = (*dit)->getDofIdx();
3453  if (idx >= 0) {
3454  auto mod = NumeredDofEntity_part_and_all_indices_change(
3455  (*dit)->getPart(), i++, global_indices[idx], local_indices[idx]);
3456  bool success = numered_dofs[s]->modify(dit, mod);
3457  if (!success)
3458  SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3459  "can not set negative indices");
3460  } else {
3461  auto mod = NumeredDofEntity_part_and_all_indices_change(
3462  (*dit)->getPart(), -1, -1, -1);
3463  bool success = numered_dofs[s]->modify(dit, mod);
3464  if (!success)
3465  SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3466  "can not set negative indices");
3467  }
3468  };
3469 
3470  if (debug) {
3471  for (auto dof : (*numered_dofs[s])) {
3472  if (dof->getDofIdx() >= 0 && dof->getPetscGlobalDofIdx() < 0) {
3473  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3474  "Negative global idx");
3475  }
3476  }
3477  }
3478 
3479  } else {
3480 
3481  *(nbdof_ptr[1]) = *(nbdof_ptr[0]);
3482  *(local_nbdof_ptr[1]) = *(local_nbdof_ptr[0]);
3483  *(ghost_nbdof_ptr[1]) = *(ghost_nbdof_ptr[0]);
3484  }
3485 
3486  if (verb >= NOISY)
3487  MOFEM_LOG_SYNCHRONISE(m_field.get_comm());
3488 
3489  if (verb > QUIET) {
3490  MOFEM_LOG_C(
3491  "WORLD", Sev::inform,
3492  "Removed DOFs from problem %s dofs [%d / %d (before %d / %d) global]",
3493  prb_ptr->getName().c_str(), prb_ptr->getNbDofsRow(),
3494  prb_ptr->getNbDofsCol(), nb_init_row_dofs, nb_init_col_dofs);
3495  MOFEM_LOG_C("SYNC", Sev::verbose,
3496  "Removed DOFs from problem %s dofs [ %d / %d "
3497  "(before %d / %d) local, %d / %d (before %d / %d)]",
3498  prb_ptr->getName().c_str(), prb_ptr->getNbLocalDofsRow(),
3499  prb_ptr->getNbLocalDofsCol(), nb_init_loc_row_dofs,
3500  nb_init_loc_row_dofs, prb_ptr->getNbGhostDofsRow(),
3501  prb_ptr->getNbGhostDofsCol(), nb_init_ghost_row_dofs,
3502  nb_init_ghost_col_dofs);
3503  MOFEM_LOG_SYNCHRONISE(m_field.get_comm());
3504  }
3506 }

Member Data Documentation

◆ buildProblemFromFields

PetscBool MoFEM::ProblemsManager::buildProblemFromFields

If set to true, problem is build from

Definition at line 30 of file ProblemsManager.hpp.

◆ cOre

MoFEM::Core& MoFEM::ProblemsManager::cOre

Definition at line 26 of file ProblemsManager.hpp.

◆ MOFEM_EVENT_ProblemsManager

PetscLogEvent MoFEM::ProblemsManager::MOFEM_EVENT_ProblemsManager
private

Definition at line 495 of file ProblemsManager.hpp.

◆ synchroniseProblemEntities

PetscBool MoFEM::ProblemsManager::synchroniseProblemEntities

DOFs in fields, not from DOFs on elements.

Definition at line 33 of file ProblemsManager.hpp.


The documentation for this struct was generated from the following files:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::createAOMappingIS
auto createAOMappingIS(IS isapp, IS ispetsc)
Creates an application mapping using two index sets.
Definition: PetscSmartObj.hpp:318
MoFEM::ProblemsManager::buildProblemFromFields
PetscBool buildProblemFromFields
Definition: ProblemsManager.hpp:30
MoFEM::Field::getNbOfCoeffs
FieldCoefficientsNumber getNbOfCoeffs() const
Get number of field coefficients.
Definition: FieldMultiIndices.hpp:202
MoFEM::debug
const static bool debug
Definition: ConstrainMatrixCtx.cpp:9
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
ProblemManagerFunctionBegin
#define ProblemManagerFunctionBegin
Definition: ProblemsManager.cpp:8
MOFEM_LOG_SEVERITY_SYNC
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
Definition: LogManager.hpp:352
MoFEM::createISGeneral
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.
Definition: PetscSmartObj.hpp:287
EntityHandle
NOISY
@ NOISY
Definition: definitions.h:224
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
MoFEM::CoreInterface::get_field_structure
virtual const Field * get_field_structure(const std::string &name, enum MoFEMTypes bh=MF_EXIST) const =0
get field structure
MoFEM::CoreInterface::get_field_bit_number
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
MoFEM::CoreInterface::get_comm_rank
virtual int get_comm_rank() const =0
MoFEM::CoreInterface::get_problem
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
MoFEM::ProblemsManager::OR
@ OR
Definition: ProblemsManager.hpp:416
MOFEM_IMPOSSIBLE_CASE
@ MOFEM_IMPOSSIBLE_CASE
Definition: definitions.h:35
MoFEM::Field::getDofSideMap
std::map< int, BaseFunction::DofsSideMap > & getDofSideMap() const
Get the dofs side map.
Definition: FieldMultiIndices.hpp:292
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
ROW
@ ROW
Definition: definitions.h:136
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
c
const double c
speed of light (cm/ns)
Definition: initial_diffusion.cpp:39
MoFEM::createAOMapping
auto createAOMapping(MPI_Comm comm, PetscInt napp, const PetscInt myapp[], const PetscInt mypetsc[])
Creates an application mapping using two integer arrays.
Definition: PetscSmartObj.hpp:338
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::CoreInterface::get_moab
virtual moab::Interface & get_moab()=0
MoFEM::ProblemsManager::cOre
MoFEM::Core & cOre
Definition: ProblemsManager.hpp:26
MoFEM::ProblemsManager::removeDofsOnEntitiesNotDistributed
MoFEMErrorCode removeDofsOnEntitiesNotDistributed(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.
Definition: ProblemsManager.cpp:3240
MOFEM_LOG_C
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:311
convert.type
type
Definition: convert.py:64
MOFEM_LOG_SYNCHRONISE
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
Definition: LogManager.hpp:345
MoFEM::FieldEntity::getLoBitNumberUId
static UId getLoBitNumberUId(const FieldBitNumber bit_number)
Definition: FieldEntsMultiIndices.hpp:222
COL
@ COL
Definition: definitions.h:136
MoFEM::ProblemsManager::markDofs
MoFEMErrorCode markDofs(const std::string problem_name, RowColData rc, const enum MarkOP op, const Range ents, std::vector< unsigned char > &marker) const
Create vector with marked indices.
Definition: ProblemsManager.cpp:3562
MoFEM::BlockFieldPair
Problem::BlockFieldPair BlockFieldPair
Definition: ProblemsMultiIndices.hpp:566
MOFEM_OPERATION_UNSUCCESSFUL
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition: definitions.h:34
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
MoFEM::DofEntity::getLoFieldEntityUId
static UId getLoFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
Definition: DofsMultiIndices.hpp:69
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
MoFEM::ProblemsManager::AND
@ AND
Definition: ProblemsManager.hpp:416
MoFEM::Problem::numeredRowDofsPtr
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredRowDofsPtr
store DOFs on rows for this problem
Definition: ProblemsMultiIndices.hpp:73
Range
MoFEM::ProblemsManager::MOFEM_EVENT_ProblemsManager
PetscLogEvent MOFEM_EVENT_ProblemsManager
Definition: ProblemsManager.hpp:495
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
MoFEM::DofEntity::getHiFieldEntityUId
static UId getHiFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
Definition: DofsMultiIndices.hpp:75
MoFEM::ProblemsManager::synchroniseProblemEntities
PetscBool synchroniseProblemEntities
DOFs in fields, not from DOFs on elements.
Definition: ProblemsManager.hpp:33
MoFEM::Exceptions::ierr
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::ProblemsManager::ProblemsManager
ProblemsManager(const MoFEM::Core &core)
Definition: ProblemsManager.cpp:55
MoFEM::FieldEntity::getHiBitNumberUId
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
Definition: FieldEntsMultiIndices.hpp:228
marker
auto marker
set bit to marker
Definition: hanging_node_approx.cpp:82
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:453
QUIET
@ QUIET
Definition: definitions.h:221
convert.int
int
Definition: convert.py:64
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
CHKERRG
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:496
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
MOFEM_INVALID_DATA
@ MOFEM_INVALID_DATA
Definition: definitions.h:36