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 147 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 195 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 315 of file Schur.cpp.

317  : 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 320 of file Schur.cpp.

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

◆ getColInd()

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

Definition at line 158 of file Schur.cpp.

158 { return colIndices[iDX]; }

◆ getMat()

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

Definition at line 156 of file Schur.cpp.

156 { return locMats[iDX]; }

◆ getRowInd()

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

Definition at line 157 of file Schur.cpp.

157 { 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 2270 of file Schur.cpp.

2272  {
2274  CHKERR assembleStorage(row_data, col_data, mat, iora);
2276  mat, iora);
2278 }

Friends And Related Function Documentation

◆ OpSchurAssembleBegin

friend struct OpSchurAssembleBegin
friend

Definition at line 171 of file Schur.cpp.

◆ OpSchurAssembleEndImpl

template<typename OP_SCHUR_ASSEMBLE_BASE >
friend struct OpSchurAssembleEndImpl
friend

Definition at line 173 of file Schur.cpp.

Member Data Documentation

◆ colIndices

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

Definition at line 199 of file Schur.cpp.

◆ iDX

const size_t MoFEM::SchurElemMats::iDX

Definition at line 152 of file Schur.cpp.

◆ locMats

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

Definition at line 197 of file Schur.cpp.

◆ maxIndexCounter

size_t MoFEM::SchurElemMats::maxIndexCounter = 0
staticprotected

Definition at line 201 of file Schur.cpp.

◆ rowIndices

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

Definition at line 198 of file Schur.cpp.

◆ schurElemMats

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

Definition at line 200 of file Schur.cpp.

◆ schurL2Storage

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

Definition at line 203 of file Schur.cpp.

◆ uidCol

UId MoFEM::SchurElemMats::uidCol

Definition at line 154 of file Schur.cpp.

◆ uidRow

UId MoFEM::SchurElemMats::uidRow

Definition at line 153 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:198
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
MoFEM::SchurElemMats::colIndices
static boost::ptr_vector< VectorInt > colIndices
Definition: Schur.cpp:199
MoFEM::SchurEvents::MOFEM_EVENT_schurMatSetValues
static PetscLogEvent MOFEM_EVENT_schurMatSetValues
Definition: Schur.hpp:27
MoFEM::SchurElemMats::iDX
const size_t iDX
Definition: Schur.cpp:152
MoFEM::SchurElemMats::uidCol
UId uidCol
Definition: Schur.cpp:154
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:315
MoFEM::SchurElemMats::assembleStorage
static MoFEMErrorCode assembleStorage(const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
Definition: Schur.cpp:320
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:203
MoFEM::SchurElemMats::maxIndexCounter
static size_t maxIndexCounter
Definition: Schur.cpp:201
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:191
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:200
MoFEM::Types::VectorInt
UBlasVector< int > VectorInt
Definition: Types.hpp:67
MoFEM::SchurElemMats::uidRow
UId uidRow
Definition: Schur.cpp:153
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::SchurElemMats::locMats
static boost::ptr_vector< MatrixDouble > locMats
Definition: Schur.cpp:197
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