v0.9.1
Files | Classes | Functions
Index sets (IS)

Construct index sets for MoFEM problems. More...

Collaboration diagram for Index sets (IS):

Files

file  FieldBlas.hpp
 Field basic algebraManaging problems, build and partitioning.
 
file  ISManager.cpp
 IS creating.
 
file  ISManager.hpp
 Interface managing ISManaging problems, build and partitioning.
 

Classes

struct  MoFEM::ISManager
 Section manager is used to create indexes and sectionsFIXME: ISManager is not properly testsed by atom tests. More...
 

Functions

MoFEMErrorCode MoFEM::ISManager::sectionCreate (const std::string &problem_name, PetscSection *s, const RowColData row_col=COL) const
 Create global selectionCreate section for given problem, such that points are sorted by UId, and number of dofs on point is equal to number of dofs on entity. More...
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemOrder (const std::string &problem, RowColData rc, int min_order, int max_order, IS *is) const
 create IS for given order range (collective) More...
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndRank (const std::string &problem, RowColData rc, const std::string &field, int min_coeff_idx, int max_coeff_idx, IS *is, Range *ents=nullptr) const
 create IS for given problem, field and rank range (collective) More...
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndRank (const std::string &problem, RowColData rc, const std::string &field, int min_coeff_idx, int max_coeff_idx, SmartPetscObj< IS > &smart_is, Range *ents=nullptr) const
 IS for given problem, field and rank range (collective) More...
 
MoFEMErrorCode MoFEM::ISManager::isCreateProblemFieldAndEntityType (const std::string &problem, RowColData rc, const std::string &field, EntityType low_type, EntityType hi_type, int min_coeff_idx, int max_coeff_idx, IS *is, Range *ents=nullptr) const
 create IS for given problem, field and type range (collective) More...
 
MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemFieldToOtherProblemField (const std::string &x_problem, const std::string &x_field_name, RowColData x_rc, const std::string &y_problem, const std::string &y_field_name, RowColData y_rc, std::vector< int > &idx, std::vector< int > &idy) const
 create IS for give two problems and fieldNote that indices are ordered in ascending order of local indices in problem_y More...
 
MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemFieldToOtherProblemField (const std::string &x_problem, const std::string &x_field_name, RowColData x_rc, const std::string &y_problem, const std::string &y_field_name, RowColData y_rc, IS *ix, IS *iy) const
 create IS for give two problems and fieldIndices are sorted by global PETSc index in problem_x. More...
 
MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemToOtherProblem (const std::string &x_problem, RowColData x_rc, const std::string &y_problem, RowColData y_rc, std::vector< int > &idx, std::vector< int > &idy) const
 Create is from one problem to other problem. More...
 
MoFEMErrorCode MoFEM::ISManager::isCreateFromProblemToOtherProblem (const std::string &x_problem, RowColData x_rc, const std::string &y_problem, RowColData y_rc, IS *ix, IS *iy) const
 Create is from one problem to other problem. More...
 

Detailed Description

Construct index sets for MoFEM problems.

Function Documentation

◆ isCreateFromProblemFieldToOtherProblemField() [1/2]

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

create IS for give two problems and fieldNote that indices are ordered in ascending order of local indices in problem_y

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

Definition at line 331 of file ISManager.cpp.

335  {
336  const MoFEM::Interface &m_field = cOre;
337  const Problem *px_ptr;
338  const Problem *py_ptr;
340 
341  CHKERR m_field.get_problem(x_problem, &px_ptr);
342  CHKERR m_field.get_problem(y_problem, &py_ptr);
343 
344  typedef multi_index_container<
345  boost::shared_ptr<NumeredDofEntity>,
346 
347  indexed_by<
348 
349  sequenced<>,
350 
351  ordered_non_unique<
352  tag<Composite_Ent_And_EntDofIdx_mi_tag>,
353  composite_key<
354  NumeredDofEntity,
359 
360  >>
361  NumeredDofEntity_view_multiIndex;
362 
363  NumeredDofEntity_view_multiIndex dofs_view;
364 
365  switch (x_rc) {
366  case ROW:
367  dofs_view.insert(
368  dofs_view.end(),
369  px_ptr->numeredDofsRows->get<FieldName_mi_tag>().lower_bound(
370  x_field_name),
371  px_ptr->numeredDofsRows->get<FieldName_mi_tag>().upper_bound(
372  x_field_name));
373  break;
374  case COL:
375  dofs_view.insert(
376  dofs_view.end(),
377  px_ptr->numeredDofsCols->get<FieldName_mi_tag>().lower_bound(
378  x_field_name),
379  px_ptr->numeredDofsCols->get<FieldName_mi_tag>().upper_bound(
380  x_field_name));
381  break;
382  default:
383  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
384  "only makes sense for ROWS and COLS");
385  }
386 
387  decltype(py_ptr->numeredDofsRows) dofs_ptr;
388  switch (y_rc) {
389  case ROW:
390  dofs_ptr = py_ptr->numeredDofsRows;
391  break;
392  case COL:
393  dofs_ptr = py_ptr->numeredDofsCols;
394  break;
395  default:
396  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
397  "only makes sense for ROWS and COLS");
398  }
399 
400  std::map<int, int> global_dofs_map;
401  for (auto r = dofs_ptr->get<Composite_Name_And_Part_mi_tag>().equal_range(
402  boost::make_tuple(y_field_name, m_field.get_comm_rank()));
403  r.first != r.second; ++r.first) {
404 
405  auto x_dit = dofs_view.get<Composite_Ent_And_EntDofIdx_mi_tag>().find(
406  boost::make_tuple((*r.first)->getEnt(), (*r.first)->getEntDofIdx()));
407  if (x_dit != dofs_view.get<Composite_Ent_And_EntDofIdx_mi_tag>().end()) {
408  global_dofs_map[(*x_dit)->getPetscGlobalDofIdx()] =
409  (*r.first)->getPetscGlobalDofIdx();
410  }
411  }
412 
413  idx.resize(global_dofs_map.size());
414  idy.resize(global_dofs_map.size());
415  {
416  auto ix = idx.begin();
417  auto iy = idy.begin();
418  for (auto mit = global_dofs_map.begin(); mit != global_dofs_map.end();
419  mit++, ix++, iy++) {
420  *ix = mit->first;
421  *iy = mit->second;
422  }
423  }
425 }
Deprecated interface functions.
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
virtual int get_comm_rank() const =0
#define CHKERR
Inline error check.
Definition: definitions.h:602
const MoFEM::Interface & cOre
Definition: ISManager.hpp:41
virtual const Problem * get_problem(const std::string &problem_name) const =0
Get the problem object.
interface_DofEntity< DofEntity > interface_type_DofEntity
int DofIdx
Index of DOF.
Definition: Types.hpp:29
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413

◆ isCreateFromProblemFieldToOtherProblemField() [2/2]

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

create IS for give two problems and fieldIndices are sorted by global PETSc index in problem_x.

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

Definition at line 427 of file ISManager.cpp.

430  {
432  std::vector<int> idx(0), idy(0);
434  x_problem, x_field_name, x_rc, y_problem, y_field_name, y_rc, idx, idy);
435  if (ix != PETSC_NULL) {
436  CHKERR ISCreateGeneral(PETSC_COMM_WORLD, idx.size(), &idx[0],
437  PETSC_COPY_VALUES, ix);
438  }
439  CHKERR ISCreateGeneral(PETSC_COMM_WORLD, idy.size(), &idy[0],
440  PETSC_COPY_VALUES, iy);
441  if (dEbug) {
442  ISView(*ix, PETSC_VIEWER_STDOUT_WORLD);
443  ISView(*iy, PETSC_VIEWER_STDOUT_WORLD);
444  }
446 }
MoFEMErrorCode isCreateFromProblemFieldToOtherProblemField(const std::string &x_problem, const std::string &x_field_name, RowColData x_rc, const std::string &y_problem, const std::string &y_field_name, RowColData y_rc, std::vector< int > &idx, std::vector< int > &idy) const
create IS for give two problems and fieldNote that indices are ordered in ascending order of local in...
Definition: ISManager.cpp:331
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
#define CHKERR
Inline error check.
Definition: definitions.h:602
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413

◆ isCreateFromProblemToOtherProblem() [1/2]

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

Create is from one problem to other problem.

Parameters
x_problem
x_rc
y_problem
y_rc
idx
idy
Returns
MoFEMErrorCode

Definition at line 448 of file ISManager.cpp.

450  {
451  const MoFEM::Interface &m_field = cOre;
452  const Problem *px_ptr;
453  const Problem *py_ptr;
455  CHKERR m_field.get_problem(x_problem, &px_ptr);
456  CHKERR m_field.get_problem(y_problem, &py_ptr);
457  NumeredDofEntityByLocalIdx::iterator y_dit, hi_y_dit;
458  switch (y_rc) {
459  case ROW:
460  y_dit = py_ptr->numeredDofsRows->get<PetscLocalIdx_mi_tag>().lower_bound(0);
461  hi_y_dit = py_ptr->numeredDofsRows->get<PetscLocalIdx_mi_tag>().lower_bound(
462  py_ptr->getNbLocalDofsRow()); // should be lower
463  break;
464  case COL:
465  y_dit = py_ptr->numeredDofsCols->get<PetscLocalIdx_mi_tag>().lower_bound(0);
466  hi_y_dit = py_ptr->numeredDofsCols->get<PetscLocalIdx_mi_tag>().lower_bound(
467  py_ptr->getNbLocalDofsCol()); // should be lower
468  break;
469  default:
470  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
471  }
472  const NumeredDofEntityByUId *x_numered_dofs_by_uid;
473  switch (x_rc) {
474  case ROW:
475  x_numered_dofs_by_uid = &(px_ptr->numeredDofsRows->get<Unique_mi_tag>());
476  break;
477  case COL:
478  x_numered_dofs_by_uid = &(px_ptr->numeredDofsCols->get<Unique_mi_tag>());
479  break;
480  default:
481  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
482  }
483  for (; y_dit != hi_y_dit; y_dit++) {
484  if ((*y_dit)->getPart() != (unsigned int)m_field.get_comm_rank()) {
485  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "data inconsistency");
486  }
487  NumeredDofEntityByUId::iterator x_dit;
488  x_dit = x_numered_dofs_by_uid->find((*y_dit)->getGlobalUniqueId());
489  if (x_dit == x_numered_dofs_by_uid->end())
490  continue;
491  idx.push_back((*x_dit)->getPetscGlobalDofIdx());
492  idy.push_back((*y_dit)->getPetscGlobalDofIdx());
493  }
495 }
Deprecated interface functions.
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
virtual int get_comm_rank() const =0
#define CHKERR
Inline error check.
Definition: definitions.h:602
const MoFEM::Interface & cOre
Definition: ISManager.hpp:41
virtual const Problem * get_problem(const std::string &problem_name) const =0
Get the problem object.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413
NumeredDofEntity_multiIndex::index< Unique_mi_tag >::type NumeredDofEntityByUId
Numbered DoF multi-index by UId.

◆ isCreateFromProblemToOtherProblem() [2/2]

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

Create is from one problem to other problem.

Parameters
x_problem
x_rc
y_problem
y_rc
ix
iy
Returns
MoFEMErrorCode

Definition at line 497 of file ISManager.cpp.

499  {
501  std::vector<int> idx(0), idy(0);
502  CHKERR isCreateFromProblemToOtherProblem(x_problem, x_rc, y_problem, y_rc,
503  idx, idy);
504  CHKERR ISCreateGeneral(PETSC_COMM_WORLD, idx.size(), &idx[0],
505  PETSC_COPY_VALUES, ix);
506  CHKERR ISCreateGeneral(PETSC_COMM_WORLD, idy.size(), &idy[0],
507  PETSC_COPY_VALUES, iy);
508  if (dEbug) {
509  ISView(*ix, PETSC_VIEWER_STDOUT_WORLD);
510  ISView(*iy, PETSC_VIEWER_STDOUT_WORLD);
511  }
513 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
#define CHKERR
Inline error check.
Definition: definitions.h:602
MoFEMErrorCode isCreateFromProblemToOtherProblem(const std::string &x_problem, RowColData x_rc, const std::string &y_problem, RowColData y_rc, std::vector< int > &idx, std::vector< int > &idy) const
Create is from one problem to other problem.
Definition: ISManager.cpp:448
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413

◆ isCreateProblemFieldAndEntityType()

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

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

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

Definition at line 313 of file ISManager.cpp.

316  {
317  const MoFEM::Interface &m_field = cOre;
319  EntityHandle field_meshset = m_field.get_field_meshset(field);
320  Range ents;
321  for (; low_type <= hi_type; ++low_type)
322  CHKERR m_field.get_moab().get_entities_by_type(field_meshset, low_type,
323  ents, true);
324  if (ents_ptr)
325  ents = intersect(ents, *ents_ptr);
326  CHKERR isCreateProblemFieldAndRank(problem, rc, field, min_coeff_idx,
327  max_coeff_idx, is, &ents);
329 }
Deprecated interface functions.
virtual moab::Interface & get_moab()=0
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
MoFEMErrorCode isCreateProblemFieldAndRank(const std::string &problem, RowColData rc, const std::string &field, int min_coeff_idx, int max_coeff_idx, IS *is, Range *ents=nullptr) const
create IS for given problem, field and rank range (collective)
Definition: ISManager.cpp:231
virtual EntityHandle get_field_meshset(const std::string &name) const =0
get field meshset
#define CHKERR
Inline error check.
Definition: definitions.h:602
const MoFEM::Interface & cOre
Definition: ISManager.hpp:41
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413

◆ isCreateProblemFieldAndRank() [1/2]

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

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

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

Definition at line 231 of file ISManager.cpp.

233  {
234  const MoFEM::Interface &m_field = cOre;
235  const Problem *problem_ptr;
237  CHKERR m_field.get_problem(problem, &problem_ptr);
238  typedef NumeredDofEntity_multiIndex::index<
239  Composite_Name_And_Part_mi_tag>::type DofsByNamePartAndCoeffIdx;
240  int rank = m_field.get_comm_rank();
241  DofsByNamePartAndCoeffIdx::iterator it, hi_it;
242  switch (rc) {
243  case ROW:
244  it = problem_ptr->numeredDofsRows->get<Composite_Name_And_Part_mi_tag>()
245  .lower_bound(boost::make_tuple(field, rank));
246  hi_it = problem_ptr->numeredDofsRows->get<Composite_Name_And_Part_mi_tag>()
247  .upper_bound(boost::make_tuple(field, rank));
248  break;
249  case COL:
250  it = problem_ptr->numeredDofsCols->get<Composite_Name_And_Part_mi_tag>()
251  .lower_bound(boost::make_tuple(field, rank));
252  hi_it = problem_ptr->numeredDofsCols->get<Composite_Name_And_Part_mi_tag>()
253  .upper_bound(boost::make_tuple(field, rank));
254  break;
255  default:
256  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
257  }
258 
260  dof_loc_idx_view;
261  {
262  // get min and max bound coefficient index
264  dofs_view_coeff_idx;
265  dofs_view_coeff_idx.insert(it, hi_it);
266  NumeredDofEntity_multiIndex_coeff_idx_ordered_non_unique::iterator vit,
267  hi_vit;
268  vit = dofs_view_coeff_idx.lower_bound(min_coeff_idx);
269  hi_vit = dofs_view_coeff_idx.upper_bound(max_coeff_idx);
270  // sort by local index
271  dof_loc_idx_view.insert(vit, hi_vit);
272  }
273 
274  auto true_if_dof_on_entity = [ents_ptr](auto &dof) {
275  if (ents_ptr) {
276  return ents_ptr->find(dof->get()->getEnt()) != ents_ptr->end();
277  } else {
278  return true;
279  }
280  };
281 
282  // create IS
283  NumeredDofEntity_multiIndex_petsc_local_dof_view_ordered_non_unique::iterator
284  vit,
285  hi_vit;
286  vit = dof_loc_idx_view.begin();
287  hi_vit = dof_loc_idx_view.end();
288  int size = std::distance(vit, hi_vit);
289  int *id;
290  CHKERR PetscMalloc(size * sizeof(int), &id);
291  int ii = 0;
292  for (; vit != hi_vit; vit++) {
293  if (true_if_dof_on_entity(vit)) {
294  id[ii++] = (*vit)->getPetscGlobalDofIdx();
295  }
296  }
297  CHKERR ISCreateGeneral(PETSC_COMM_WORLD, ii, id, PETSC_OWN_POINTER, is);
299 }
Deprecated interface functions.
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
multi_index_container< boost::shared_ptr< NumeredDofEntity >, indexed_by< ordered_non_unique< const_mem_fun< NumeredDofEntity, DofIdx, &NumeredDofEntity::getPetscLocalDofIdx > > > > NumeredDofEntity_multiIndex_petsc_local_dof_view_ordered_non_unique
virtual int get_comm_rank() const =0
#define CHKERR
Inline error check.
Definition: definitions.h:602
const MoFEM::Interface & cOre
Definition: ISManager.hpp:41
multi_index_container< boost::shared_ptr< NumeredDofEntity >, indexed_by< ordered_non_unique< const_mem_fun< NumeredDofEntity::interface_type_DofEntity, FieldCoefficientsNumber, &NumeredDofEntity::getDofCoeffIdx > > > > NumeredDofEntity_multiIndex_coeff_idx_ordered_non_unique
virtual const Problem * get_problem(const std::string &problem_name) const =0
Get the problem object.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413

◆ isCreateProblemFieldAndRank() [2/2]

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

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

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

Definition at line 301 of file ISManager.cpp.

304  {
306  IS is;
307  CHKERR isCreateProblemFieldAndRank(problem, rc, field, min_coeff_idx,
308  max_coeff_idx, &is, ents_ptr);
309  smart_is = SmartPetscObj<IS>(is);
311 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
MoFEMErrorCode isCreateProblemFieldAndRank(const std::string &problem, RowColData rc, const std::string &field, int min_coeff_idx, int max_coeff_idx, IS *is, Range *ents=nullptr) const
create IS for given problem, field and rank range (collective)
Definition: ISManager.cpp:231
#define CHKERR
Inline error check.
Definition: definitions.h:602
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413

◆ isCreateProblemOrder()

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

create IS for given order range (collective)

Parameters
problemname
rcROW or COL
min_order
max_order
Return values
isout value

Definition at line 174 of file ISManager.cpp.

176  {
177  const MoFEM::Interface &m_field = cOre;
178  const Problem *problem_ptr;
180  CHKERR m_field.get_problem(problem, &problem_ptr);
181 
182  typedef multi_index_container<
183  boost::shared_ptr<NumeredDofEntity>,
184 
185  indexed_by<
186 
187  sequenced<>,
188 
189  ordered_non_unique<
190  tag<Order_mi_tag>,
193 
194  >>
195  NumeredDofEntity_order_view_multiIndex;
196 
197  const int rank = m_field.get_comm_rank();
198 
199  NumeredDofEntity_order_view_multiIndex dofs_part_view;
200  auto insert_part_range = [&dofs_part_view, rank](auto &dofs) {
201  dofs_part_view.insert(dofs_part_view.end(), dofs.lower_bound(rank),
202  dofs.upper_bound(rank));
203  };
204 
205  switch (rc) {
206  case ROW:
207  insert_part_range(problem_ptr->numeredDofsRows->get<Part_mi_tag>());
208  break;
209  case COL:
210  insert_part_range(problem_ptr->numeredDofsCols->get<Part_mi_tag>());
211  break;
212  default:
213  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
214  }
215 
216  auto lo = dofs_part_view.get<Order_mi_tag>().lower_bound(min_order);
217  auto hi = dofs_part_view.get<Order_mi_tag>().upper_bound(max_order);
218  const int size = std::distance(lo, hi);
219  int *id;
220  CHKERR PetscMalloc(size * sizeof(int), &id);
221  int *id_it = id;
222  for (; lo != hi; ++lo, ++id_it)
223  *id_it = (*lo)->getPetscGlobalDofIdx();
224  sort(id, &id[size]);
225 
226  CHKERR ISCreateGeneral(PETSC_COMM_WORLD, size, id, PETSC_OWN_POINTER, is);
227 
229 }
Deprecated interface functions.
int ApproximationOrder
Approximation on the entity.
Definition: Types.hpp:37
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
virtual int get_comm_rank() const =0
#define CHKERR
Inline error check.
Definition: definitions.h:602
const MoFEM::Interface & cOre
Definition: ISManager.hpp:41
virtual const Problem * get_problem(const std::string &problem_name) const =0
Get the problem object.
interface_DofEntity< DofEntity > interface_type_DofEntity
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413

◆ sectionCreate()

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

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

It takes all fields

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

Definition at line 38 of file ISManager.cpp.

40  {
41  const MoFEM::Interface &m_field = cOre;
42  const Problem *problem_ptr;
43  auto fields_ptr = m_field.get_fields();
44  auto fe_ptr = m_field.get_finite_elements();
46  CHKERR m_field.get_problem(problem_name, &problem_ptr);
47  boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
48  BitFieldId fields_ids;
49  switch (row_col) {
50  case ROW:
51  dofs = problem_ptr->numeredDofsRows;
52  for (FiniteElement_multiIndex::iterator fit = fe_ptr->begin();
53  fit != fe_ptr->end(); fit++) {
54  if ((fit->get()->getId() & problem_ptr->getBitFEId()).any()) {
55  fields_ids |= fit->get()->getBitFieldIdRow();
56  }
57  }
58  break;
59  case COL:
60  dofs = problem_ptr->numeredDofsCols;
61  for (FiniteElement_multiIndex::iterator fit = fe_ptr->begin();
62  fit != fe_ptr->end(); fit++) {
63  if ((fit->get()->getId() & problem_ptr->getBitFEId()).any()) {
64  fields_ids |= fit->get()->getBitFieldIdCol();
65  }
66  }
67  break;
68  default:
69  SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
70  "Has to be ROW or COLUMN");
71  }
72  // get fields names on the problem
73  map<std::string, std::pair<int, int>> fields_map;
74  {
75  int field = 0;
76  for (Field_multiIndex::iterator fit = fields_ptr->begin();
77  fit != fields_ptr->end(); fit++) {
78  if ((fit->get()->getId() & fields_ids).any()) {
79  fields_map[fit->get()->getName()].first = field++;
80  fields_map[fit->get()->getName()].second = fit->get()->getNbOfCoeffs();
81  }
82  }
83  }
84  const int proc = m_field.get_comm_rank();
85  CHKERR PetscSectionCreate(PETSC_COMM_WORLD, s);
86  CHKERR PetscSectionSetNumFields(*s, fields_map.size());
87  for (map<std::string, std::pair<int, int>>::iterator mit = fields_map.begin();
88  mit != fields_map.end(); mit++) {
89  CHKERR PetscSectionSetFieldName(*s, mit->second.first, mit->first.c_str());
90  CHKERR PetscSectionSetFieldComponents(*s, mit->second.first,
91  mit->second.second);
92  }
93  // determine number of points
94  int nb_charts = 0;
95  {
96  NumeredDofEntity_multiIndex::iterator dit, hi_dit;
97  dit = dofs->begin();
98  hi_dit = dofs->end();
99  for (; dit != hi_dit;) {
100  EntityHandle ent = dit->get()->getEnt();
101  if (static_cast<int>(dit->get()->getPart()) == proc &&
102  dit->get()->getEntDofIdx() == 0) {
103  while (dit != hi_dit && ent == dit->get()->getEnt()) {
104  const int nb_of_dofs_on_ent = dit->get()->getNbDofsOnEnt();
105  for (int dd = 0; dd != nb_of_dofs_on_ent; dd++, dit++) {
106  }
107  }
108  ++nb_charts;
109  } else {
110  ++dit;
111  }
112  }
113  }
114  // get layout, i.e. chart
115  PetscLayout layout;
116  CHKERR PetscLayoutCreate(PETSC_COMM_WORLD, &layout);
117  CHKERR PetscLayoutSetBlockSize(layout, 1);
118  CHKERR PetscLayoutSetLocalSize(layout, nb_charts);
119  CHKERR PetscLayoutSetUp(layout);
120  int rstart, rend;
121  CHKERR PetscLayoutGetRange(layout, &rstart, &rend);
122  CHKERR PetscLayoutDestroy(&layout);
123  CHKERR PetscSectionSetChart(*s, rstart, rend);
124  // cerr << rstart << " " << rend << " " << proc << endl;
125  // loop of all dofs
126  {
127  NumeredDofEntity_multiIndex::iterator dit, hi_dit;
128  dit = dofs->begin();
129  hi_dit = dofs->end();
130  int point = rstart;
131  for (; dit != hi_dit;) {
132  EntityHandle ent = dit->get()->getEnt();
133  if (static_cast<int>(dit->get()->getPart()) == proc &&
134  dit->get()->getEntDofIdx() == 0) {
135  // exploit that does are continuously stored on entity
136  // that includes fields
137  while (dit != hi_dit && ent == dit->get()->getEnt()) {
138  const int nb_of_dofs_on_ent = dit->get()->getNbDofsOnEnt();
139  std::string field_name = dit->get()->getName();
140  if (fields_map.find(field_name) == fields_map.end()) {
141  PetscPrintf(PETSC_COMM_WORLD, "Warning: Field %s not found\n",
142  dit->get()->getName().c_str());
143  } else {
144  if (dit->get()->getEntDofIdx() != 0) {
145  cerr << **dit << endl;
146  SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
147  "data inconsistency");
148  }
149  CHKERR PetscSectionAddDof(*s, point, nb_of_dofs_on_ent);
150  int field = fields_map.at(field_name).first;
151  CHKERR PetscSectionSetFieldDof(*s, point, field, nb_of_dofs_on_ent);
152  }
153  for (int dd = 0; dd != nb_of_dofs_on_ent; dd++, dit++) {
154  if (field_name != dit->get()->getName()) {
155  SETERRQ2(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
156  "field name inconsistency %s!=%s", field_name.c_str(),
157  dit->get()->getName().c_str());
158  }
159  }
160  // cerr << point << endl;
161  }
162  ++point;
163  } else {
164  ++dit;
165  }
166  }
167  }
168  // cerr << "done " << proc << endl;
169  CHKERR PetscSectionSetUp(*s);
170  // cerr << "end " << proc << endl;
172 }
Deprecated interface functions.
virtual const Field_multiIndex * get_fields() const =0
Get the fields object.
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
virtual int get_comm_rank() const =0
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
virtual const FiniteElement_multiIndex * get_finite_elements() const =0
Get the finite elements object.
std::bitset< BITFIELDID_SIZE > BitFieldId
Field Id.
Definition: Types.hpp:52
#define CHKERR
Inline error check.
Definition: definitions.h:602
const MoFEM::Interface & cOre
Definition: ISManager.hpp:41
virtual const Problem * get_problem(const std::string &problem_name) const =0
Get the problem object.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413