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
 
struct OpSchurZeroRowsAndCols
 
template<typename OP_SCHUR_ASSEMBLE_BASE >
struct OpSchurAssembleEndImpl
 

Detailed Description

Schur complement data storage.

Definition at line 161 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 210 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 342 of file Schur.cpp.

344  : 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 347 of file Schur.cpp.

349  {
351 
352 #ifndef NDEBUG
353  PetscLogEventBegin(SchurEvents::MOFEM_EVENT_schurMatSetValues, 0, 0, 0, 0);
354 #endif // NDEBUG
355 
356  // get row indices, in case of store, get indices from storage
357  // storage keeps marked indices to manage boundary conditions
358  auto get_row_indices = [&]() -> const VectorInt & {
359  if (auto e_ptr = row_data.getFieldEntities()[0]) {
360  if (auto stored_data_ptr =
361  e_ptr->getSharedStoragePtr<EssentialBcStorage>()) {
362  return stored_data_ptr->entityIndices;
363  }
364  }
365  return row_data.getIndices();
366  };
367 
368  const auto &row_ind = get_row_indices();
369  const auto &col_ind = col_data.getIndices();
370 
371  const auto nb_rows = row_ind.size();
372  const auto nb_cols = col_ind.size();
373 
374 #ifndef NDEBUG
375  if (mat.size1() != nb_rows) {
376  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
377  "Wrong mat size %d != %d", mat.size1(), nb_rows);
378  }
379  if (mat.size2() != nb_cols) {
380  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
381  "Wrong mat size %d != %d", mat.size2(), nb_cols);
382  }
383 #endif // NDEBUG
384 
385  // get entity uid
386  auto get_uid = [](auto &data) {
387  if (data.getFieldEntities().size() == 1) {
388 
389  return data.getFieldEntities()[0]->getLocalUniqueId();
390 
391  } else {
392 
393  // Is assumed that sum of entities ids gives unique id, that is not true,
394  // but corner case is improbable.
395 
396  // @todo: debug version should have test
397 
398  auto &uid0 = data.getFieldEntities()[0]->getLocalUniqueId();
399  auto field_id0 = FieldEntity::getFieldBitNumberFromUniqueId(uid0);
400  auto ent0 = FieldEntity::getHandleFromUniqueId(uid0);
401  auto type0 = type_from_handle(ent0);
402  auto id = id_from_handle(ent0);
403 
404  for (auto i = 1; i < data.getFieldEntities().size(); ++i) {
405 
406  // get entity id from ent
407  id += id_from_handle(
408 
409  // get entity handle from unique uid
411  data.getFieldEntities()[i]->getLocalUniqueId())
412 
413  );
414  }
415 
417  field_id0,
418 
419  ent_form_type_and_id(type0, id)
420 
421  );
422  }
423  };
424 
425  auto uid_row = get_uid(row_data);
426  auto uid_col = get_uid(col_data);
427 
428  auto it =
429  SchurElemMats::schurL2Storage.template get<SchurElemMats::uid_mi_tag>()
430  .find(boost::make_tuple(uid_row, uid_col));
431 
432  if (it ==
433  SchurElemMats::schurL2Storage.template get<SchurElemMats::uid_mi_tag>()
434  .end()) {
435 
436  // get size of arrays of matrices
437  const auto size = SchurElemMats::locMats.size();
438 
439  // expand memory allocation
440  if (SchurElemMats::maxIndexCounter == size) {
441  SchurElemMats::locMats.push_back(new MatrixDouble());
442  SchurElemMats::rowIndices.push_back(new VectorInt());
443  SchurElemMats::colIndices.push_back(new VectorInt());
445  new SchurElemMats(SchurElemMats::maxIndexCounter, uid_row, uid_col));
446  } else {
448  uid_row;
450  uid_col;
451  }
452 
453  // add matrix to storage
454  auto p = SchurElemMats::schurL2Storage.emplace(
456 #ifndef NDEBUG
457  if (!p.second) {
458  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Failed to insert");
459  }
460 #endif // NDEBUG
461 
462  auto asmb = [&](auto &sm) {
463  sm.resize(nb_rows, nb_cols, false);
464  noalias(sm) = mat;
465  };
466 
467  asmb((*p.first)->getMat());
468 
469  auto add_indices = [](auto &storage, auto &ind) {
470  storage.resize(ind.size(), false);
471  noalias(storage) = ind;
472  };
473 
474  add_indices((*p.first)->getRowInd(), row_ind);
475  add_indices((*p.first)->getColInd(), col_ind);
476 
477  } else {
478  // entry (submatrix) already exists
479 
480  auto asmb = [&](auto &sm) {
482 
483 #ifndef NDEBUG
484  if (sm.size1() != nb_rows) {
485  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
486  "Wrong mat or storage size %d != %d", sm.size1(), nb_rows);
487  }
488  if (sm.size2() != nb_cols) {
489  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
490  "Wrong mat or storage size %d != %d", sm.size2(), nb_cols);
491  }
492 #endif // NDEBUG
493 
494  switch (iora) {
495  case ADD_VALUES:
496  sm += mat;
497  break;
498  case INSERT_VALUES:
499  noalias(sm) = mat;
500  break;
501  default:
502  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
503  "Assembly type not implemented");
504  }
506  };
507 
508  CHKERR asmb((*it)->getMat());
509 
510  // no need to set indices
511  }
512 
513 #ifndef NDEBUG
514  PetscLogEventEnd(SchurEvents::MOFEM_EVENT_schurMatSetValues, 0, 0, 0, 0);
515 #endif // NDEBUG
516 
518 }

◆ getColInd()

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

Definition at line 172 of file Schur.cpp.

172 { return colIndices[iDX]; }

◆ getMat()

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

Definition at line 170 of file Schur.cpp.

170 { return locMats[iDX]; }

◆ getRowInd()

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

Definition at line 171 of file Schur.cpp.

171 { 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 2674 of file Schur.cpp.

2676  {
2678  CHKERR assembleStorage(row_data, col_data, mat, iora);
2680  mat, iora);
2682 }

Friends And Related Function Documentation

◆ OpSchurAssembleBegin

friend struct OpSchurAssembleBegin
friend

Definition at line 185 of file Schur.cpp.

◆ OpSchurAssembleEndImpl

template<typename OP_SCHUR_ASSEMBLE_BASE >
friend struct OpSchurAssembleEndImpl
friend

Definition at line 188 of file Schur.cpp.

◆ OpSchurZeroRowsAndCols

friend struct OpSchurZeroRowsAndCols
friend

Definition at line 186 of file Schur.cpp.

Member Data Documentation

◆ colIndices

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

Definition at line 214 of file Schur.cpp.

◆ iDX

const size_t MoFEM::SchurElemMats::iDX

Definition at line 166 of file Schur.cpp.

◆ locMats

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

Definition at line 212 of file Schur.cpp.

◆ maxIndexCounter

size_t MoFEM::SchurElemMats::maxIndexCounter = 0
staticprotected

Definition at line 216 of file Schur.cpp.

◆ rowIndices

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

Definition at line 213 of file Schur.cpp.

◆ schurElemMats

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

Definition at line 215 of file Schur.cpp.

◆ schurL2Storage

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

Definition at line 218 of file Schur.cpp.

◆ uidCol

UId MoFEM::SchurElemMats::uidCol

Definition at line 168 of file Schur.cpp.

◆ uidRow

UId MoFEM::SchurElemMats::uidRow

Definition at line 167 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:1890
MoFEM::SchurElemMats::rowIndices
static boost::ptr_vector< VectorInt > rowIndices
Definition: Schur.cpp:213
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
MoFEM::SchurElemMats::colIndices
static boost::ptr_vector< VectorInt > colIndices
Definition: Schur.cpp:214
MoFEM::SchurEvents::MOFEM_EVENT_schurMatSetValues
static PetscLogEvent MOFEM_EVENT_schurMatSetValues
Definition: Schur.hpp:27
MoFEM::SchurElemMats::iDX
const size_t iDX
Definition: Schur.cpp:166
MoFEM::SchurElemMats::uidCol
UId uidCol
Definition: Schur.cpp:168
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:342
MoFEM::SchurElemMats::assembleStorage
static MoFEMErrorCode assembleStorage(const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
Definition: Schur.cpp:347
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:218
MoFEM::SchurElemMats::maxIndexCounter
static size_t maxIndexCounter
Definition: Schur.cpp:216
MoFEM::type_from_handle
auto type_from_handle(const EntityHandle h)
get type from entity handle
Definition: Templates.hpp:1898
MoFEM::SchurBackendMatSetValuesPtr::matSetValuesPtr
static MatSetValuesPtr matSetValuesPtr
backend assembly function
Definition: Schur.hpp:233
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:215
MoFEM::Types::VectorInt
UBlasVector< int > VectorInt
Definition: Types.hpp:67
MoFEM::SchurElemMats::uidRow
UId uidRow
Definition: Schur.cpp:167
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::SchurElemMats::locMats
static boost::ptr_vector< MatrixDouble > locMats
Definition: Schur.cpp:212
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:1906
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