v0.14.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Types | Private Attributes | Static Private Attributes | List of all members
MoFEM::SchurL2Mats Struct Reference

Schur complement data storage. More...

#include <src/finite_elements/Schur.hpp>

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

Classes

struct  col_mi_tag
 
struct  idx_mi_tag
 
struct  row_mi_tag
 
struct  uid_mi_tag
 

Public Types

using MatSetValuesPtr = boost::function< MoFEMErrorCode(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)>
 

Public Member Functions

 SchurL2Mats (const size_t idx, const UId uid_row, const UId uid_col)
 
virtual ~SchurL2Mats ()=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 UId uidRow
 
const UId uidCol
 

Static Public Attributes

static MatSetValuesPtr matSetValuesPtr
 backend assembly function More...
 

Private Types

using SchurL2Storage = multi_index_container< SchurL2Mats, indexed_by< ordered_unique< tag< uid_mi_tag >, composite_key< SchurL2Mats, member< SchurL2Mats, const UId, &SchurL2Mats::uidRow >, member< SchurL2Mats, const UId, &SchurL2Mats::uidCol > > >, ordered_non_unique< tag< row_mi_tag >, member< SchurL2Mats, const UId, &SchurL2Mats::uidRow > >, ordered_non_unique< tag< col_mi_tag >, member< SchurL2Mats, const UId, &SchurL2Mats::uidCol > > > >
 

Private Attributes

const size_t iDX
 
friend OpSchurAssembleBegin
 
friend OpSchurAssembleEndImpl
 

Static Private Attributes

static boost::ptr_vector< MatrixDoublelocMats
 
static boost::ptr_vector< VectorIntrowIndices
 
static boost::ptr_vector< VectorIntcolIndices
 
static SchurL2Storage schurL2Storage
 

Detailed Description

Schur complement data storage.

Definition at line 124 of file Schur.hpp.

Member Typedef Documentation

◆ MatSetValuesPtr

using MoFEM::SchurL2Mats::MatSetValuesPtr = boost::function<MoFEMErrorCode( Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)>

Definition at line 139 of file Schur.hpp.

◆ SchurL2Storage

using MoFEM::SchurL2Mats::SchurL2Storage = multi_index_container< SchurL2Mats, indexed_by< ordered_unique< tag<uid_mi_tag>, composite_key< SchurL2Mats, member<SchurL2Mats, const UId, &SchurL2Mats::uidRow>, member<SchurL2Mats, const UId, &SchurL2Mats::uidCol> > >, ordered_non_unique<tag<row_mi_tag>, member<SchurL2Mats, const UId, &SchurL2Mats::uidRow> >, ordered_non_unique<tag<col_mi_tag>, member<SchurL2Mats, const UId, &SchurL2Mats::uidCol> > > >
private

Definition at line 179 of file Schur.hpp.

Constructor & Destructor Documentation

◆ SchurL2Mats()

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

Definition at line 17 of file Schur.cpp.

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

◆ ~SchurL2Mats()

virtual MoFEM::SchurL2Mats::~SchurL2Mats ( )
virtualdefault

Member Function Documentation

◆ getColInd()

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

Definition at line 134 of file Schur.hpp.

134 { return colIndices[iDX]; }

◆ getMat()

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

Definition at line 132 of file Schur.hpp.

132 { return locMats[iDX]; }

◆ getRowInd()

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

Definition at line 133 of file Schur.hpp.

133 { return rowIndices[iDX]; }

◆ MatSetValues()

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

Definition at line 35 of file Schur.cpp.

37  {
39 
40  CHKERR matSetValuesPtr(M, row_data, col_data, mat, iora);
41 
42  auto get_row_indices = [&]() -> const VectorInt & {
43  if (auto e_ptr = row_data.getFieldEntities()[0]) {
44  if (auto stored_data_ptr =
45  e_ptr->getSharedStoragePtr<EssentialBcStorage>()) {
46  return stored_data_ptr->entityIndices;
47  }
48  }
49  return row_data.getIndices();
50  };
51 
52  const auto &row_ind = get_row_indices();
53  const auto &col_ind = col_data.getIndices();
54 
55  const auto nb_rows = row_ind.size();
56  const auto nb_cols = col_ind.size();
57 
58 #ifndef NDEBUG
59  if (mat.size1() != nb_rows) {
60  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
61  "Wrong mat size %d != %d", mat.size1(), nb_rows);
62  }
63  if (mat.size2() != nb_cols) {
64  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
65  "Wrong mat size %d != %d", mat.size2(), nb_cols);
66  }
67 #endif // NDEBUG
68 
69  const auto idx = SchurL2Mats::schurL2Storage.size();
70  const auto size = SchurL2Mats::locMats.size();
71 
72  if (idx >= size) {
73  SchurL2Mats::locMats.push_back(new MatrixDouble());
74  SchurL2Mats::rowIndices.push_back(new VectorInt());
75  SchurL2Mats::colIndices.push_back(new VectorInt());
76  }
77 
78  // insert index
79  auto get_uid = [](auto &data) {
80  if (data.getFieldEntities().size() == 1) {
81 
82  return data.getFieldEntities()[0]->getLocalUniqueId();
83 
84  } else {
85 
86  // Is assumed that sum of entities ids gives unique id, that is not true,
87  // but corner case is improbable.
88 
89  // @todo: debug version should have test
90 
91  auto &uid0 = data.getFieldEntities()[0]->getLocalUniqueId();
92  auto field_id0 = FieldEntity::getFieldBitNumberFromUniqueId(uid0);
93  auto ent0 = FieldEntity::getHandleFromUniqueId(uid0);
94  auto type0 = type_from_handle(ent0);
95  auto id = id_from_handle(ent0);
96 
97  for (auto i = 1; i < data.getFieldEntities().size(); ++i) {
98 
99  // get entity id from ent
100  id += id_from_handle(
101 
102  // get entity handle from unique uid
104  data.getFieldEntities()[i]->getLocalUniqueId())
105 
106  );
107  }
108 
110  field_id0,
111 
112  ent_form_type_and_id(type0, id)
113 
114  );
115  }
116  };
117 
118  auto uid_row = get_uid(row_data);
119  auto uid_col = get_uid(col_data);
120  auto p = SchurL2Mats::schurL2Storage.emplace(idx, uid_row, uid_col);
121 
122  auto get_storage = [&p]() { return const_cast<SchurL2Mats &>(*p.first); };
123 
124  if (p.second) {
125 
126  auto asmb = [&](auto &sm) {
127  sm.resize(nb_rows, nb_cols, false);
128  noalias(sm) = mat;
129  };
130 
131  asmb(get_storage().getMat());
132 
133  auto add_indices = [](auto &storage, auto &ind) {
134  storage.resize(ind.size(), false);
135  noalias(storage) = ind;
136  };
137 
138  add_indices(get_storage().getRowInd(), row_ind);
139  add_indices(get_storage().getColInd(), col_ind);
140 
141  } else {
142 
143  auto asmb = [&](auto &sm) {
145 
146 #ifndef NDEBUG
147  if (sm.size1() != nb_rows) {
148  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
149  "Wrong mat or storage size %d != %d", sm.size1(), nb_rows);
150  }
151  if (sm.size2() != nb_cols) {
152  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
153  "Wrong mat or storage size %d != %d", sm.size2(), nb_cols);
154  }
155 #endif // NDEBUG
156 
157  switch (iora) {
158  case ADD_VALUES:
159  sm += mat;
160  break;
161  case INSERT_VALUES:
162  noalias(sm) = mat;
163  break;
164  default:
165  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
166  "Assembly type not implemented");
167  }
169  };
170 
171  CHKERR asmb(get_storage().getMat());
172  }
173 
175 }

Member Data Documentation

◆ colIndices

boost::ptr_vector< VectorInt > MoFEM::SchurL2Mats::colIndices
staticprivate

Definition at line 183 of file Schur.hpp.

◆ iDX

const size_t MoFEM::SchurL2Mats::iDX
private

Definition at line 149 of file Schur.hpp.

◆ locMats

boost::ptr_vector< MatrixDouble > MoFEM::SchurL2Mats::locMats
staticprivate

Definition at line 181 of file Schur.hpp.

◆ matSetValuesPtr

SchurL2Mats::MatSetValuesPtr MoFEM::SchurL2Mats::matSetValuesPtr
static
Initial value:

backend assembly function

Definition at line 141 of file Schur.hpp.

◆ OpSchurAssembleBegin

friend MoFEM::SchurL2Mats::OpSchurAssembleBegin
private

Definition at line 151 of file Schur.hpp.

◆ OpSchurAssembleEndImpl

friend MoFEM::SchurL2Mats::OpSchurAssembleEndImpl
private

Definition at line 152 of file Schur.hpp.

◆ rowIndices

boost::ptr_vector< VectorInt > MoFEM::SchurL2Mats::rowIndices
staticprivate

Definition at line 182 of file Schur.hpp.

◆ schurL2Storage

SchurL2Mats::SchurL2Storage MoFEM::SchurL2Mats::schurL2Storage
staticprivate

Definition at line 184 of file Schur.hpp.

◆ uidCol

const UId MoFEM::SchurL2Mats::uidCol

Definition at line 130 of file Schur.hpp.

◆ uidRow

const UId MoFEM::SchurL2Mats::uidRow

Definition at line 129 of file Schur.hpp.


The documentation for this struct was generated from the following files:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
MoFEM::id_from_handle
auto id_from_handle(const EntityHandle h)
Definition: Templates.hpp:1861
MoFEM::SchurL2Mats::matSetValuesPtr
static MatSetValuesPtr matSetValuesPtr
backend assembly function
Definition: Schur.hpp:141
MoFEM::SchurL2Mats::SchurL2Mats
SchurL2Mats(const size_t idx, const UId uid_row, const UId uid_col)
Definition: Schur.cpp:17
MoFEM::SchurL2Mats::getColInd
auto & getColInd() const
Definition: Schur.hpp:134
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
MoFEM::SchurL2Mats::uidCol
const UId uidCol
Definition: Schur.hpp:130
MoFEM::schur_mat_set_values_wrap
MoFEMErrorCode schur_mat_set_values_wrap(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
Definition: Schur.cpp:24
PlasticOps::M
FTensor::Index< 'M', 3 > M
Definition: PlasticOps.hpp:117
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::SchurL2Mats::schurL2Storage
static SchurL2Storage schurL2Storage
Definition: Schur.hpp:184
MoFEM::SchurL2Mats::iDX
const size_t iDX
Definition: Schur.hpp:149
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::type_from_handle
auto type_from_handle(const EntityHandle h)
get type from entity handle
Definition: Templates.hpp:1869
MoFEM::SchurL2Mats::getMat
auto & getMat() const
Definition: Schur.hpp:132
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
MoFEM::SchurL2Mats::uidRow
const UId uidRow
Definition: Schur.hpp:129
MoFEM::SchurL2Mats::getRowInd
auto & getRowInd() const
Definition: Schur.hpp:133
MoFEM::SchurL2Mats::rowIndices
static boost::ptr_vector< VectorInt > rowIndices
Definition: Schur.hpp:182
MoFEM::Types::VectorInt
UBlasVector< int > VectorInt
Definition: Types.hpp:67
MoFEM::SchurL2Mats::locMats
static boost::ptr_vector< MatrixDouble > locMats
Definition: Schur.hpp:181
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
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:1877
MoFEM::SchurL2Mats::colIndices
static boost::ptr_vector< VectorInt > colIndices
Definition: Schur.hpp:183
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:416
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:346