v0.15.0
Loading...
Searching...
No Matches
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
 

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

Initial value:
multi_index_container<
const SchurElemMats *,
indexed_by<
ordered_unique<
tag<uid_mi_tag>,
composite_key<
member<SchurElemMats, const UId, &SchurElemMats::uidRow>,
member<SchurElemMats, const UId, &SchurElemMats::uidCol>
>>,
ordered_non_unique<tag<col_mi_tag>, member<SchurElemMats, const UId,
>>
uint128_t UId
Unique Id.
Definition Types.hpp:31
SchurElemMats(const size_t idx, const UId uid_row, const UId uid_col)
Definition Schur.cpp:342

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

344 : 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 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 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
377 "Wrong mat size %ld != %ld", mat.size1(), nb_rows);
378 }
379 if (mat.size2() != nb_cols) {
380 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
381 "Wrong mat size %ld != %ld", 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 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
486 "Wrong mat or storage size %ld != %ld", sm.size1(), nb_rows);
487 }
488 if (sm.size2() != nb_cols) {
489 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
490 "Wrong mat or storage size %ld != %ld", 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}
#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
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 2674 of file Schur.cpp.

2676 {
2678 CHKERR assembleStorage(row_data, col_data, mat, iora);
2680 mat, iora);
2682}
static MatSetValuesPtr matSetValuesPtr
backend assembly function
Definition Schur.hpp:233
static MoFEMErrorCode assembleStorage(const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
Definition Schur.cpp:347

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: