v0.16.3
Loading...
Searching...
No Matches
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< MatrixDouble > locMats
 
static boost::ptr_vector< VectorInt > rowIndices
 
static boost::ptr_vector< VectorInt > colIndices
 
static boost::ptr_vector< SchurElemMats > schurElemMats
 
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 193 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 572 of file Schur.cpp.

574 : iDX(idx), uidRow(uid_row), uidCol(uid_col) {}
const size_t iDX
Definition Schur.cpp:166

◆ ~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 577 of file Schur.cpp.

579 {
581
582#ifndef NDEBUG
583 PetscLogEventBegin(SchurEvents::MOFEM_EVENT_schurMatSetValues, 0, 0, 0, 0);
584#endif // NDEBUG
585
586 // get row indices, in case of store, get indices from storage
587 // storage keeps marked indices to manage boundary conditions
588 auto get_row_indices = [&]() -> const VectorInt & {
589 if (auto e_ptr = row_data.getFieldEntities()[0]) {
590 if (auto stored_data_ptr =
591 e_ptr->getSharedStoragePtr<EssentialBcStorage>()) {
592 return stored_data_ptr->entityIndices;
593 }
594 }
595 return row_data.getIndices();
596 };
597
598 const auto &row_ind = get_row_indices();
599 const auto &col_ind = col_data.getIndices();
600
601 const auto nb_rows = row_ind.size();
602 const auto nb_cols = col_ind.size();
603
604#ifndef NDEBUG
605 if (mat.size1() != nb_rows) {
606 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
607 "Wrong mat size %zu != %zu", mat.size1(), nb_rows);
608 }
609 if (mat.size2() != nb_cols) {
610 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
611 "Wrong mat size %zu != %zu", mat.size2(), nb_cols);
612 }
613#endif // NDEBUG
614
615 // get entity uid
616 auto get_uid = [](auto &data) {
617 if (data.getFieldEntities().size() == 1) {
618
619 return data.getFieldEntities()[0]->getLocalUniqueId();
620
621 } else {
622
623 // Is assumed that sum of entities ids gives unique id, that is not true,
624 // but corner case is improbable.
625
626 // @todo: debug version should have test
627
628 auto &uid0 = data.getFieldEntities()[0]->getLocalUniqueId();
629 auto field_id0 = FieldEntity::getFieldBitNumberFromUniqueId(uid0);
630 auto ent0 = FieldEntity::getHandleFromUniqueId(uid0);
631 auto type0 = type_from_handle(ent0);
632 auto id = id_from_handle(ent0);
633
634 for (auto i = 1; i < data.getFieldEntities().size(); ++i) {
635
636 // get entity id from ent
637 id += id_from_handle(
638
639 // get entity handle from unique uid
641 data.getFieldEntities()[i]->getLocalUniqueId())
642
643 );
644 }
645
647 field_id0,
648
649 ent_form_type_and_id(type0, id)
650
651 );
652 }
653 };
654
655 auto uid_row = get_uid(row_data);
656 auto uid_col = get_uid(col_data);
657
658 auto it =
659 SchurElemMats::schurL2Storage.template get<SchurElemMats::uid_mi_tag>()
660 .find(boost::make_tuple(uid_row, uid_col));
661
662 if (it ==
663 SchurElemMats::schurL2Storage.template get<SchurElemMats::uid_mi_tag>()
664 .end()) {
665
666 // get size of arrays of matrices
667 const auto size = SchurElemMats::locMats.size();
668
669 // expand memory allocation
671 SchurElemMats::locMats.push_back(new MatrixDouble());
672 SchurElemMats::rowIndices.push_back(new VectorInt());
673 SchurElemMats::colIndices.push_back(new VectorInt());
675 new SchurElemMats(SchurElemMats::maxIndexCounter, uid_row, uid_col));
676 } else {
678 uid_row;
680 uid_col;
681 }
682
683 // add matrix to storage
684 auto p = SchurElemMats::schurL2Storage.emplace(
686#ifndef NDEBUG
687 if (!p.second) {
688 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Failed to insert");
689 }
690#endif // NDEBUG
691
692 auto asmb = [&](auto &sm) {
693 sm.resize(nb_rows, nb_cols, false);
694 noalias(sm) = mat;
695 };
696
697 asmb((*p.first)->getMat());
698
699 auto add_indices = [](auto &storage, auto &ind) {
700 storage.resize(ind.size(), false);
701 noalias(storage) = ind;
702 };
703
704 add_indices((*p.first)->getRowInd(), row_ind);
705 add_indices((*p.first)->getColInd(), col_ind);
706
707 } else {
708 // entry (submatrix) already exists
709
710 auto asmb = [&](auto &sm) {
712
713#ifndef NDEBUG
714 if (sm.size1() != nb_rows) {
715 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
716 "Wrong mat or storage size %zu != %zu", sm.size1(), nb_rows);
717 }
718 if (sm.size2() != nb_cols) {
719 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
720 "Wrong mat or storage size %zu != %zu", sm.size2(), nb_cols);
721 }
722#endif // NDEBUG
723
724 switch (iora) {
725 case ADD_VALUES:
726 sm += mat;
727 break;
728 case INSERT_VALUES:
729 noalias(sm) = mat;
730 break;
731 default:
732 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
733 "Assembly type not implemented");
734 }
736 };
737
738 CHKERR asmb((*it)->getMat());
739
740 // no need to set indices
741 }
742
743#ifndef NDEBUG
744 PetscLogEventEnd(SchurEvents::MOFEM_EVENT_schurMatSetValues, 0, 0, 0, 0);
745#endif // NDEBUG
746
748}
PetscInt size
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
FTensor::Index< 'i', SPACE_DIM > i
UBlasMatrix< double > MatrixDouble
Definition Types.hpp:77
UBlasVector< int > VectorInt
Definition Types.hpp:67
auto type_from_handle(const EntityHandle h)
get type from entity handle
auto id_from_handle(const EntityHandle h)
auto ent_form_type_and_id(const EntityType type, const EntityID id)
get entity handle from type and id
static auto getHandleFromUniqueId(const UId uid)
Get the Handle From Unique Id.
static auto getFieldBitNumberFromUniqueId(const UId uid)
Get the Field Bit Number From Unique Id.
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
static boost::ptr_vector< VectorInt > colIndices
Definition Schur.cpp:214
static boost::ptr_vector< MatrixDouble > locMats
Definition Schur.cpp:212
SchurElemMats(const size_t idx, const UId uid_row, const UId uid_col)
Definition Schur.cpp:572
static size_t maxIndexCounter
Definition Schur.cpp:216
static boost::ptr_vector< VectorInt > rowIndices
Definition Schur.cpp:213
static boost::ptr_vector< SchurElemMats > schurElemMats
Definition Schur.cpp:215
static SchurElemStorage schurL2Storage
Definition Schur.cpp:218
static PetscLogEvent MOFEM_EVENT_schurMatSetValues
Definition Schur.hpp:27

◆ 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 4290 of file Schur.cpp.

4292 {
4294 CHKERR assembleStorage(row_data, col_data, mat, iora);
4296 mat, iora);
4298}
static MatSetValuesPtr matSetValuesPtr
backend assembly function
Definition Schur.hpp:296
static MoFEMErrorCode assembleStorage(const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
Definition Schur.cpp:577

Friends And Related Symbol 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: