v0.14.0
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Static Protected Member Functions | Static Protected Attributes | Friends | List of all members
MoFEM::SchurElemMats Struct Reference

Schur complement data storage. More...

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

Classes

struct  col_mi_tag
 
struct  uid_mi_tag
 

Public Member Functions

 SchurElemMats (const size_t idx, const UId uid_row, const UId uid_col)
 
virtual ~SchurElemMats ()=default
 
auto & getMat () const
 
auto & getRowInd () const
 
auto & getColInd () const
 

Static Public Member Functions

static MoFEMErrorCode MatSetValues (Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
 

Public Attributes

const size_t iDX
 
UId uidRow
 
UId uidCol
 

Protected Types

using SchurElemStorage = multi_index_container< const SchurElemMats *, indexed_by< ordered_unique< tag< uid_mi_tag >, composite_key< SchurElemMats, member< SchurElemMats, const UId, &SchurElemMats::uidRow >, member< SchurElemMats, const UId, &SchurElemMats::uidCol > > >, ordered_non_unique< tag< col_mi_tag >, member< SchurElemMats, const UId, &SchurElemMats::uidCol > > > >
 

Static Protected Member Functions

static MoFEMErrorCode assembleStorage (const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
 

Static Protected Attributes

static boost::ptr_vector< MatrixDoublelocMats
 
static boost::ptr_vector< VectorIntrowIndices
 
static boost::ptr_vector< VectorIntcolIndices
 
static boost::ptr_vector< SchurElemMatsschurElemMats
 
static size_t maxIndexCounter = 0
 
static SchurElemStorage schurL2Storage
 

Friends

struct OpSchurAssembleBegin
 
template<typename OP_SCHUR_ASSEMBLE_BASE >
struct OpSchurAssembleEndImpl
 

Detailed Description

Schur complement data storage.

Definition at line 173 of file Schur.cpp.

Member Typedef Documentation

◆ SchurElemStorage

using MoFEM::SchurElemMats::SchurElemStorage = multi_index_container< const SchurElemMats *, indexed_by< ordered_unique< tag<uid_mi_tag>, composite_key< SchurElemMats, member<SchurElemMats, const UId, &SchurElemMats::uidRow>, member<SchurElemMats, const UId, &SchurElemMats::uidCol> > >, ordered_non_unique<tag<col_mi_tag>, member<SchurElemMats, const UId, &SchurElemMats::uidCol> > > >
protected

Definition at line 221 of file Schur.cpp.

Constructor & Destructor Documentation

◆ SchurElemMats()

MoFEM::SchurElemMats::SchurElemMats ( const size_t  idx,
const UId  uid_row,
const UId  uid_col 
)

Definition at line 362 of file Schur.cpp.

364  : iDX(idx), uidRow(uid_row), uidCol(uid_col) {}

◆ ~SchurElemMats()

virtual MoFEM::SchurElemMats::~SchurElemMats ( )
virtualdefault

Member Function Documentation

◆ assembleStorage()

MoFEMErrorCode MoFEM::SchurElemMats::assembleStorage ( const EntitiesFieldData::EntData row_data,
const EntitiesFieldData::EntData col_data,
const MatrixDouble mat,
InsertMode  iora 
)
staticprotected

Definition at line 367 of file Schur.cpp.

369  {
371 
372 #ifndef NDEBUG
373  PetscLogEventBegin(SchurEvents::MOFEM_EVENT_schurMatSetValues, 0, 0, 0, 0);
374 #endif // NDEBUG
375 
376  // get row indices, in case of store, get indices from storage
377  // storage keeps marked indices to manage boundary conditions
378  auto get_row_indices = [&]() -> const VectorInt & {
379  if (auto e_ptr = row_data.getFieldEntities()[0]) {
380  if (auto stored_data_ptr =
381  e_ptr->getSharedStoragePtr<EssentialBcStorage>()) {
382  return stored_data_ptr->entityIndices;
383  }
384  }
385  return row_data.getIndices();
386  };
387 
388  const auto &row_ind = get_row_indices();
389  const auto &col_ind = col_data.getIndices();
390 
391  auto zero_rows_and_cols = [&](auto &mat, auto &row_ind, auto &col_ind) {
393  for (auto i = 0; i < row_ind.size(); ++i) {
394  for (auto j = 0; j < col_ind.size(); ++j) {
395  if (row_ind[i] < 0 || col_ind[j] < 0)
396  mat(i, j) = 0;
397  }
398  }
399  if (row_data.getFieldEntities()[0]->getLocalUniqueId() ==
400  col_data.getFieldEntities()[0]->getLocalUniqueId()) {
401  for (auto i = 0; i < row_ind.size(); ++i) {
402  for (auto j = 0; j < col_ind.size(); ++j) {
403  if (i == j && row_ind[i] < 0 && col_ind[j] < 0) {
404  mat(i, j) = 1;
405  }
406  }
407  }
408  }
410  };
411 
412  const auto nb_rows = row_ind.size();
413  const auto nb_cols = col_ind.size();
414 
415 #ifndef NDEBUG
416  if (mat.size1() != nb_rows) {
417  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
418  "Wrong mat size %d != %d", mat.size1(), nb_rows);
419  }
420  if (mat.size2() != nb_cols) {
421  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
422  "Wrong mat size %d != %d", mat.size2(), nb_cols);
423  }
424 #endif // NDEBUG
425 
426  // get entity uid
427  auto get_uid = [](auto &data) {
428  if (data.getFieldEntities().size() == 1) {
429 
430  return data.getFieldEntities()[0]->getLocalUniqueId();
431 
432  } else {
433 
434  // Is assumed that sum of entities ids gives unique id, that is not true,
435  // but corner case is improbable.
436 
437  // @todo: debug version should have test
438 
439  auto &uid0 = data.getFieldEntities()[0]->getLocalUniqueId();
440  auto field_id0 = FieldEntity::getFieldBitNumberFromUniqueId(uid0);
441  auto ent0 = FieldEntity::getHandleFromUniqueId(uid0);
442  auto type0 = type_from_handle(ent0);
443  auto id = id_from_handle(ent0);
444 
445  for (auto i = 1; i < data.getFieldEntities().size(); ++i) {
446 
447  // get entity id from ent
448  id += id_from_handle(
449 
450  // get entity handle from unique uid
452  data.getFieldEntities()[i]->getLocalUniqueId())
453 
454  );
455  }
456 
458  field_id0,
459 
460  ent_form_type_and_id(type0, id)
461 
462  );
463  }
464  };
465 
466  auto uid_row = get_uid(row_data);
467  auto uid_col = get_uid(col_data);
468 
469  auto it =
470  SchurElemMats::schurL2Storage.template get<SchurElemMats::uid_mi_tag>()
471  .find(boost::make_tuple(uid_row, uid_col));
472 
473  if (it ==
474  SchurElemMats::schurL2Storage.template get<SchurElemMats::uid_mi_tag>()
475  .end()) {
476 
477  // get size of arrays of matrices
478  const auto size = SchurElemMats::locMats.size();
479 
480  // expand memory allocation
481  if (SchurElemMats::maxIndexCounter == size) {
482  SchurElemMats::locMats.push_back(new MatrixDouble());
483  SchurElemMats::rowIndices.push_back(new VectorInt());
484  SchurElemMats::colIndices.push_back(new VectorInt());
486  new SchurElemMats(SchurElemMats::maxIndexCounter, uid_row, uid_col));
487  } else {
489  uid_row;
491  uid_col;
492  }
493 
494  // add matrix to storage
495  auto p = SchurElemMats::schurL2Storage.emplace(
497 #ifndef NDEBUG
498  if (!p.second) {
499  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Failed to insert");
500  }
501 #endif // NDEBUG
502 
503  auto asmb = [&](auto &sm) {
504  sm.resize(nb_rows, nb_cols, false);
505  noalias(sm) = mat;
506  };
507 
508  asmb((*p.first)->getMat());
509  zero_rows_and_cols((*p.first)->getMat(), row_ind, col_ind);
510 
511  auto add_indices = [](auto &storage, auto &ind) {
512  storage.resize(ind.size(), false);
513  noalias(storage) = ind;
514  };
515 
516  add_indices((*p.first)->getRowInd(), row_ind);
517  add_indices((*p.first)->getColInd(), col_ind);
518 
519  } else {
520  // entry (submatrix) already exists
521 
522  auto asmb = [&](auto &sm) {
524 
525 #ifndef NDEBUG
526  if (sm.size1() != nb_rows) {
527  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
528  "Wrong mat or storage size %d != %d", sm.size1(), nb_rows);
529  }
530  if (sm.size2() != nb_cols) {
531  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
532  "Wrong mat or storage size %d != %d", sm.size2(), nb_cols);
533  }
534 #endif // NDEBUG
535 
536  switch (iora) {
537  case ADD_VALUES:
538  sm += mat;
539  break;
540  case INSERT_VALUES:
541  noalias(sm) = mat;
542  break;
543  default:
544  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
545  "Assembly type not implemented");
546  }
548  };
549 
550  CHKERR asmb((*it)->getMat());
551  CHKERR zero_rows_and_cols((*it)->getMat(), row_ind, col_ind);
552 
553  // no need to set indices
554  }
555 
556 #ifndef NDEBUG
557  PetscLogEventEnd(SchurEvents::MOFEM_EVENT_schurMatSetValues, 0, 0, 0, 0);
558 #endif // NDEBUG
559 
561 }

◆ getColInd()

auto& MoFEM::SchurElemMats::getColInd ( ) const
inline

Definition at line 184 of file Schur.cpp.

184 { return colIndices[iDX]; }

◆ getMat()

auto& MoFEM::SchurElemMats::getMat ( ) const
inline

Definition at line 182 of file Schur.cpp.

182 { return locMats[iDX]; }

◆ getRowInd()

auto& MoFEM::SchurElemMats::getRowInd ( ) const
inline

Definition at line 183 of file Schur.cpp.

183 { return rowIndices[iDX]; }

◆ MatSetValues()

MoFEMErrorCode MoFEM::SchurElemMats::MatSetValues ( Mat  M,
const EntitiesFieldData::EntData row_data,
const EntitiesFieldData::EntData col_data,
const MatrixDouble mat,
InsertMode  iora 
)
static

Definition at line 2762 of file Schur.cpp.

2764  {
2766  CHKERR assembleStorage(row_data, col_data, mat, iora);
2768  mat, iora);
2770 }

Friends And Related Function Documentation

◆ OpSchurAssembleBegin

friend struct OpSchurAssembleBegin
friend

Definition at line 197 of file Schur.cpp.

◆ OpSchurAssembleEndImpl

template<typename OP_SCHUR_ASSEMBLE_BASE >
friend struct OpSchurAssembleEndImpl
friend

Definition at line 199 of file Schur.cpp.

Member Data Documentation

◆ colIndices

boost::ptr_vector< VectorInt > MoFEM::SchurElemMats::colIndices
staticprotected

Definition at line 225 of file Schur.cpp.

◆ iDX

const size_t MoFEM::SchurElemMats::iDX

Definition at line 178 of file Schur.cpp.

◆ locMats

boost::ptr_vector< MatrixDouble > MoFEM::SchurElemMats::locMats
staticprotected

Definition at line 223 of file Schur.cpp.

◆ maxIndexCounter

size_t MoFEM::SchurElemMats::maxIndexCounter = 0
staticprotected

Definition at line 227 of file Schur.cpp.

◆ rowIndices

boost::ptr_vector< VectorInt > MoFEM::SchurElemMats::rowIndices
staticprotected

Definition at line 224 of file Schur.cpp.

◆ schurElemMats

boost::ptr_vector< SchurElemMats > MoFEM::SchurElemMats::schurElemMats
staticprotected

Definition at line 226 of file Schur.cpp.

◆ schurL2Storage

SchurElemMats::SchurElemStorage MoFEM::SchurElemMats::schurL2Storage
staticprotected

Definition at line 229 of file Schur.cpp.

◆ uidCol

UId MoFEM::SchurElemMats::uidCol

Definition at line 180 of file Schur.cpp.

◆ uidRow

UId MoFEM::SchurElemMats::uidRow

Definition at line 179 of file Schur.cpp.


The documentation for this struct was generated from the following file:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
MoFEM::id_from_handle
auto id_from_handle(const EntityHandle h)
Definition: Templates.hpp:1868
MoFEM::SchurElemMats::rowIndices
static boost::ptr_vector< VectorInt > rowIndices
Definition: Schur.cpp:224
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
MoFEM::SchurElemMats::colIndices
static boost::ptr_vector< VectorInt > colIndices
Definition: Schur.cpp:225
MoFEM::SchurEvents::MOFEM_EVENT_schurMatSetValues
static PetscLogEvent MOFEM_EVENT_schurMatSetValues
Definition: Schur.hpp:27
MoFEM::SchurElemMats::iDX
const size_t iDX
Definition: Schur.cpp:178
MoFEM::SchurElemMats::uidCol
UId uidCol
Definition: Schur.cpp:180
PlasticOps::M
FTensor::Index< 'M', 3 > M
Definition: PlasticOps.hpp:117
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::SchurElemMats::SchurElemMats
SchurElemMats(const size_t idx, const UId uid_row, const UId uid_col)
Definition: Schur.cpp:362
MoFEM::SchurElemMats::assembleStorage
static MoFEMErrorCode assembleStorage(const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
Definition: Schur.cpp:367
MoFEM::FieldEntity::getHandleFromUniqueId
static auto getHandleFromUniqueId(const UId uid)
Get the Handle From Unique Id.
Definition: FieldEntsMultiIndices.hpp:192
MoFEM::FieldEntity::getLocalUniqueIdCalculate
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
Definition: FieldEntsMultiIndices.hpp:136
MoFEM::SchurElemMats::schurL2Storage
static SchurElemStorage schurL2Storage
Definition: Schur.cpp:229
MoFEM::SchurElemMats::maxIndexCounter
static size_t maxIndexCounter
Definition: Schur.cpp:227
MoFEM::type_from_handle
auto type_from_handle(const EntityHandle h)
get type from entity handle
Definition: Templates.hpp:1876
MoFEM::SchurBackendMatSetValuesPtr::matSetValuesPtr
static MatSetValuesPtr matSetValuesPtr
backend assembly function
Definition: Schur.hpp:215
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
MoFEM::SchurElemMats::schurElemMats
static boost::ptr_vector< SchurElemMats > schurElemMats
Definition: Schur.cpp:226
MoFEM::Types::VectorInt
UBlasVector< int > VectorInt
Definition: Types.hpp:67
j
FTensor::Index< 'j', 3 > j
Definition: matrix_function.cpp:19
MoFEM::SchurElemMats::uidRow
UId uidRow
Definition: Schur.cpp:179
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::SchurElemMats::locMats
static boost::ptr_vector< MatrixDouble > locMats
Definition: Schur.cpp:223
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:453
sdf_wavy_2d.ind
float ind
Definition: sdf_wavy_2d.py:7
MoFEM::ent_form_type_and_id
auto ent_form_type_and_id(const EntityType type, const EntityID id)
get entity handle from type and id
Definition: Templates.hpp:1884
MoFEM::FieldEntity::getFieldBitNumberFromUniqueId
static auto getFieldBitNumberFromUniqueId(const UId uid)
Get the Field Bit Number From Unique Id.
Definition: FieldEntsMultiIndices.hpp:205
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
MOFEM_NOT_IMPLEMENTED
@ MOFEM_NOT_IMPLEMENTED
Definition: definitions.h:32
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359