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

617 : 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 620 of file Schur.cpp.

622 {
624
625#ifndef NDEBUG
626 PetscLogEventBegin(SchurEvents::MOFEM_EVENT_schurMatSetValues, 0, 0, 0, 0);
627#endif // NDEBUG
628
629 // get row indices, in case of store, get indices from storage
630 // storage keeps marked indices to manage boundary conditions
631 auto get_row_indices = [&]() -> const VectorInt & {
632 if (auto e_ptr = row_data.getFieldEntities()[0]) {
633 if (auto stored_data_ptr =
634 e_ptr->getSharedStoragePtr<EssentialBcStorage>()) {
635 return stored_data_ptr->entityIndices;
636 }
637 }
638 return row_data.getIndices();
639 };
640
641 const auto &row_ind = get_row_indices();
642 const auto &col_ind = col_data.getIndices();
643
644 const auto nb_rows = row_ind.size();
645 const auto nb_cols = col_ind.size();
646
647#ifndef NDEBUG
648 if (mat.size1() != nb_rows) {
649 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
650 "Wrong mat size %zu != %zu", mat.size1(), nb_rows);
651 }
652 if (mat.size2() != nb_cols) {
653 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
654 "Wrong mat size %zu != %zu", mat.size2(), nb_cols);
655 }
656#endif // NDEBUG
657
658 // get entity uid
659 auto get_uid = [](auto &data) {
660 if (data.getFieldEntities().size() == 1) {
661
662 return data.getFieldEntities()[0]->getLocalUniqueId();
663
664 } else {
665
666 // Is assumed that sum of entities ids gives unique id, that is not true,
667 // but corner case is improbable.
668
669 // @todo: debug version should have test
670
671 auto &uid0 = data.getFieldEntities()[0]->getLocalUniqueId();
672 auto field_id0 = FieldEntity::getFieldBitNumberFromUniqueId(uid0);
673 auto ent0 = FieldEntity::getHandleFromUniqueId(uid0);
674 auto type0 = type_from_handle(ent0);
675 auto id = id_from_handle(ent0);
676
677 for (auto i = 1; i < data.getFieldEntities().size(); ++i) {
678
679 // get entity id from ent
680 id += id_from_handle(
681
682 // get entity handle from unique uid
684 data.getFieldEntities()[i]->getLocalUniqueId())
685
686 );
687 }
688
690 field_id0,
691
692 ent_form_type_and_id(type0, id)
693
694 );
695 }
696 };
697
698 auto uid_row = get_uid(row_data);
699 auto uid_col = get_uid(col_data);
700
701 auto it =
702 SchurElemMats::schurL2Storage.template get<SchurElemMats::uid_mi_tag>()
703 .find(boost::make_tuple(uid_row, uid_col));
704
705 if (it ==
706 SchurElemMats::schurL2Storage.template get<SchurElemMats::uid_mi_tag>()
707 .end()) {
708
709 // get size of arrays of matrices
710 const auto size = SchurElemMats::locMats.size();
711
712 // expand memory allocation
714 SchurElemMats::locMats.push_back(new MatrixDouble());
715 SchurElemMats::rowIndices.push_back(new VectorInt());
716 SchurElemMats::colIndices.push_back(new VectorInt());
718 new SchurElemMats(SchurElemMats::maxIndexCounter, uid_row, uid_col));
719 } else {
721 uid_row;
723 uid_col;
724 }
725
726 // add matrix to storage
727 auto p = SchurElemMats::schurL2Storage.emplace(
729#ifndef NDEBUG
730 if (!p.second) {
731 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Failed to insert");
732 }
733#endif // NDEBUG
734
735 auto asmb = [&](auto &sm) {
736 sm.resize(nb_rows, nb_cols, false);
737 noalias(sm) = mat;
738 };
739
740 asmb((*p.first)->getMat());
741
742 auto add_indices = [](auto &storage, auto &ind) {
743 storage.resize(ind.size(), false);
744 noalias(storage) = ind;
745 };
746
747 add_indices((*p.first)->getRowInd(), row_ind);
748 add_indices((*p.first)->getColInd(), col_ind);
749
750 } else {
751 // entry (submatrix) already exists
752
753 auto asmb = [&](auto &sm) {
755
756#ifndef NDEBUG
757 if (sm.size1() != nb_rows) {
758 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
759 "Wrong mat or storage size %zu != %zu", sm.size1(), nb_rows);
760 }
761 if (sm.size2() != nb_cols) {
762 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
763 "Wrong mat or storage size %zu != %zu", sm.size2(), nb_cols);
764 }
765#endif // NDEBUG
766
767 switch (iora) {
768 case ADD_VALUES:
769 sm += mat;
770 break;
771 case INSERT_VALUES:
772 noalias(sm) = mat;
773 break;
774 default:
775 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
776 "Assembly type not implemented");
777 }
779 };
780
781 CHKERR asmb((*it)->getMat());
782
783 // no need to set indices
784 }
785
786#ifndef NDEBUG
787 PetscLogEventEnd(SchurEvents::MOFEM_EVENT_schurMatSetValues, 0, 0, 0, 0);
788#endif // NDEBUG
789
791}
std::vector< int > size
It it
Definition Schur.cpp:2568
It end
Definition Schur.cpp:2568
#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:615
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 4986 of file Schur.cpp.

4988 {
4990 CHKERR assembleStorage(row_data, col_data, mat, iora);
4992 mat, iora);
4994}
static MatSetValuesPtr matSetValuesPtr
backend assembly function
Definition Schur.hpp:372
static MoFEMErrorCode assembleStorage(const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
Definition Schur.cpp:620

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: