v0.16.3
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
MoFEM::BlockStorage Struct Reference

Storage of block matrix, shared by block matrix and its nested (Schur) sub-matrices. More...

Collaboration diagram for MoFEM::BlockStorage:
[legend]

Classes

struct  Elem
 A00 element. More...
 
struct  ElemEntity
 DOFs on one entity (node) of A00 element. More...
 
struct  Indexes
 block data indexes More...
 
struct  Pattern
 Block pattern of A00 element and layout of element buffer. More...
 
struct  RowUIdLess
 

Public Types

enum  FactorStorage { FACTOR_NONE , FACTOR_IN_DATA , FACTOR_IN_PRECONDITIONER , FACTOR_FAILED }
 

Public Member Functions

void ensureAllocated ()
 
bool isFactorised () const
 
MoFEMErrorCode checkNotFailed () const
 Fails if factorisation failed, storage has to be zeroed.
 
MoFEMErrorCode modified () const
 Call before modification of data, fails if factors are stored in place.
 
void resetFactors ()
 
double * blockPtr (const Indexes &b, bool prec=false)
 values of block, preconditioner buffer if prec is true
 
const Indexes * find (const UId &row, const UId &col) const
 find block by row and column entity uid, return nullptr if not found
 
Indexes * findMutable (const UId &row, const UId &col)
 
auto rowRange (const UId &row) const
 range of blocks with given row entity uid
 
auto colRange (const UId &col) const
 range (in colOrder) of blocks with given column entity uid
 

Static Public Member Functions

static bool lessRowCol (const Indexes &a, const Indexes &b)
 

Public Attributes

std::vector< Indexes > blockIndex
 blocks sorted by (row uid, col uid)
 
std::vector< int > feOrder
 blocks sorted by (fe uid, row uid, col uid)
 
std::vector< int > colOrder
 blocks sorted by (col uid, row uid)
 
std::vector< Pattern > patterns
 
std::vector< Elem > elems
 
std::vector< ElemEntity > elemEntities
 
std::vector< std::vector< double > > elemData
 A00 element buffers.
 
std::vector< std::vector< double > > elemPrec
 preconditioner buffers
 
std::vector< std::vector< double > > elemDense
 dense factors (fallback)
 
int maxElemSize = 0
 maximal DOFs of element
 
size_t maxElemBuffer = 0
 maximal size of element buffer
 
size_t dataSize = 0
 required size of data
 
std::vector< double > data
 blocks not in A00, allocated on first use
 
std::vector< __CLPK_integer > pivots
 
FactorStorage factorStorage = FACTOR_NONE
 
bool nested = false
 nested Schur structure has been created
 
bool hasPreconditioner = false
 preconditioner blocks are enabled
 
bool optDense = false
 -schur_a00_dense
 
double optPivotThreshold = 0
 -schur_a00_pivot_threshold
 
double optRcondMin = 1e-12
 -schur_a00_rcond_min
 
double optBackwardError = 1e-12
 -schur_a00_backward_error
 

Detailed Description

Storage of block matrix, shared by block matrix and its nested (Schur) sub-matrices.

Block is dense sub-matrix coupling DOFs on one row entity with DOFs on one column entity, stored row-major at mat_shift with leading dimension ld.

Blocks which are not part of A00 are stored in data. When nested Schur structure is created (see createSchurNestedMatrixStruture), blocks of A00 which belong to one finite element are stored in a buffer of that element. Elements with the same block pattern (entities, numbers of DOFs and listed pairs) share a Pattern, which defines the layout of element buffers.

Element buffers start in listed layout (listed blocks only). At the first factorisation each pattern is analysed on a probe element: nodes (entities) whose diagonal block is a safe pivot are eliminated one by one (block LU in place, fill only where the pattern creates it), the remaining nodes form a dense core factorised with partial pivoting. Element buffers are then relaid element by element, and factors are kept until MatZeroEntries. Elements failing the pivot test at a later factorisation are factorised dense in a buffer of their own. See doc/development/schur.md.

Factorisation works on M = A^T, which is how LAPACK reads row-major element blocks. Slot (r, c), i.e. block of A coupling row node r with column node c, read column-major is block (c, r) of M.

If preconditioner blocks are requested, they are allocated for A00 element buffers only, with the same layout. Then factors of (A00 + preconditioner) are stored in place of preconditioner blocks, and A00 blocks are intact.

Definition at line 251 of file Schur.cpp.

Member Enumeration Documentation

◆ FactorStorage

Enumerator
FACTOR_NONE 
FACTOR_IN_DATA 
FACTOR_IN_PRECONDITIONER 
FACTOR_FAILED 

factorisation failed, data is corrupted

Definition at line 397 of file Schur.cpp.

397 {
401 FACTOR_FAILED ///< factorisation failed, data is corrupted
402 };
@ FACTOR_FAILED
factorisation failed, data is corrupted
Definition Schur.cpp:401

Member Function Documentation

◆ blockPtr()

double * MoFEM::BlockStorage::blockPtr ( const Indexes &  b,
bool  prec = false 
)
inline

values of block, preconditioner buffer if prec is true

Definition at line 447 of file Schur.cpp.

447 {
448 if (b.getElem() >= 0)
449 return (prec ? elemPrec : elemData)[b.getElem()].data() + b.getMatShift();
450 return data.data() + b.getMatShift();
451 }
std::vector< double > data
blocks not in A00, allocated on first use
Definition Schur.cpp:387
std::vector< std::vector< double > > elemPrec
preconditioner buffers
Definition Schur.cpp:381
std::vector< std::vector< double > > elemData
A00 element buffers.
Definition Schur.cpp:380

◆ checkNotFailed()

MoFEMErrorCode MoFEM::BlockStorage::checkNotFailed ( ) const
inline

Fails if factorisation failed, storage has to be zeroed.

Definition at line 416 of file Schur.cpp.

416 {
419 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
420 "A00 factorisation failed and block matrix data is corrupted, "
421 "call MatZeroEntries and assemble again");
423 }
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
FactorStorage factorStorage
Definition Schur.cpp:403

◆ colRange()

auto MoFEM::BlockStorage::colRange ( const UId &  col) const
inline

range (in colOrder) of blocks with given column entity uid

Definition at line 494 of file Schur.cpp.

494 {
495 auto lo = std::lower_bound(
496 colOrder.begin(), colOrder.end(), col,
497 [this](int i, const UId &c) { return blockIndex[i].getColUId() < c; });
498 auto hi = std::upper_bound(
499 colOrder.begin(), colOrder.end(), col,
500 [this](const UId &c, int i) { return c < blockIndex[i].getColUId(); });
501 return std::make_pair(lo, hi);
502 }
FTensor::Index< 'i', SPACE_DIM > i
const double c
speed of light (cm/ns)
uint128_t UId
Unique Id.
Definition Types.hpp:31
std::vector< int > colOrder
blocks sorted by (col uid, row uid)
Definition Schur.cpp:375

◆ ensureAllocated()

void MoFEM::BlockStorage::ensureAllocated ( )
inline

data is allocated on first use, such that storage is not allocated twice when layout is changed by createSchurNestedMatrixStruture

Definition at line 392 of file Schur.cpp.

392 {
393 if (data.size() != dataSize)
394 data.assign(dataSize, 0.);
395 }
size_t dataSize
required size of data
Definition Schur.cpp:386

◆ find()

const Indexes * MoFEM::BlockStorage::find ( const UId &  row,
const UId &  col 
) const
inline

find block by row and column entity uid, return nullptr if not found

Definition at line 460 of file Schur.cpp.

460 {
461 auto it = std::lower_bound(
462 blockIndex.begin(), blockIndex.end(), std::make_pair(row, col),
463 [](const Indexes &a, const std::pair<UId, UId> &p) {
464 if (a.getRowUId() != p.first)
465 return a.getRowUId() < p.first;
466 return a.getColUId() < p.second;
467 });
468 if (it != blockIndex.end() && it->getRowUId() == row &&
469 it->getColUId() == col)
470 return &*it;
471 return nullptr;
472 }
constexpr double a
std::vector< Indexes > blockIndex
blocks sorted by (row uid, col uid)
Definition Schur.cpp:373

◆ findMutable()

Indexes * MoFEM::BlockStorage::findMutable ( const UId &  row,
const UId &  col 
)
inline

Definition at line 474 of file Schur.cpp.

474 {
475 return const_cast<Indexes *>(find(row, col));
476 }
const Indexes * find(const UId &row, const UId &col) const
find block by row and column entity uid, return nullptr if not found
Definition Schur.cpp:460

◆ isFactorised()

bool MoFEM::BlockStorage::isFactorised ( ) const
inline

Definition at line 413 of file Schur.cpp.

413{ return factorStorage != FACTOR_NONE; }

◆ lessRowCol()

static bool MoFEM::BlockStorage::lessRowCol ( const Indexes &  a,
const Indexes &  b 
)
inlinestatic

Definition at line 453 of file Schur.cpp.

453 {
454 if (a.getRowUId() != b.getRowUId())
455 return a.getRowUId() < b.getRowUId();
456 return a.getColUId() < b.getColUId();
457 }

◆ modified()

MoFEMErrorCode MoFEM::BlockStorage::modified ( ) const
inline

Call before modification of data, fails if factors are stored in place.

Definition at line 426 of file Schur.cpp.

426 {
429 if (isFactorised())
430 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
431 "A00 element matrices are factorised in place, call "
432 "MatZeroEntries before assembling or modifying block matrix");
434 }
#define CHKERR
Inline error check.
bool isFactorised() const
Definition Schur.cpp:413
MoFEMErrorCode checkNotFailed() const
Fails if factorisation failed, storage has to be zeroed.
Definition Schur.cpp:416

◆ resetFactors()

void MoFEM::BlockStorage::resetFactors ( )
inline

Definition at line 436 of file Schur.cpp.

436 {
438 for (auto &e : elems) {
439 e.factorised = false;
440 e.dense = false;
441 }
442 for (auto &d : elemDense)
443 std::vector<double>().swap(d);
444 }
std::vector< Elem > elems
Definition Schur.cpp:378
std::vector< std::vector< double > > elemDense
dense factors (fallback)
Definition Schur.cpp:382

◆ rowRange()

auto MoFEM::BlockStorage::rowRange ( const UId &  row) const
inline

range of blocks with given row entity uid

Definition at line 488 of file Schur.cpp.

488 {
489 return std::equal_range(blockIndex.begin(), blockIndex.end(), row,
490 RowUIdLess());
491 }

Member Data Documentation

◆ blockIndex

std::vector<Indexes> MoFEM::BlockStorage::blockIndex

blocks sorted by (row uid, col uid)

Definition at line 373 of file Schur.cpp.

◆ colOrder

std::vector<int> MoFEM::BlockStorage::colOrder

blocks sorted by (col uid, row uid)

Definition at line 375 of file Schur.cpp.

◆ data

std::vector<double> MoFEM::BlockStorage::data

blocks not in A00, allocated on first use

Definition at line 387 of file Schur.cpp.

◆ dataSize

size_t MoFEM::BlockStorage::dataSize = 0

required size of data

Definition at line 386 of file Schur.cpp.

◆ elemData

std::vector<std::vector<double> > MoFEM::BlockStorage::elemData

A00 element buffers.

Definition at line 380 of file Schur.cpp.

◆ elemDense

std::vector<std::vector<double> > MoFEM::BlockStorage::elemDense

dense factors (fallback)

Definition at line 382 of file Schur.cpp.

◆ elemEntities

std::vector<ElemEntity> MoFEM::BlockStorage::elemEntities

Definition at line 379 of file Schur.cpp.

◆ elemPrec

std::vector<std::vector<double> > MoFEM::BlockStorage::elemPrec

preconditioner buffers

Definition at line 381 of file Schur.cpp.

◆ elems

std::vector<Elem> MoFEM::BlockStorage::elems

Definition at line 378 of file Schur.cpp.

◆ factorStorage

FactorStorage MoFEM::BlockStorage::factorStorage = FACTOR_NONE

Definition at line 403 of file Schur.cpp.

◆ feOrder

std::vector<int> MoFEM::BlockStorage::feOrder

blocks sorted by (fe uid, row uid, col uid)

Definition at line 374 of file Schur.cpp.

◆ hasPreconditioner

bool MoFEM::BlockStorage::hasPreconditioner = false

preconditioner blocks are enabled

Definition at line 405 of file Schur.cpp.

◆ maxElemBuffer

size_t MoFEM::BlockStorage::maxElemBuffer = 0

maximal size of element buffer

Definition at line 384 of file Schur.cpp.

◆ maxElemSize

int MoFEM::BlockStorage::maxElemSize = 0

maximal DOFs of element

Definition at line 383 of file Schur.cpp.

◆ nested

bool MoFEM::BlockStorage::nested = false

nested Schur structure has been created

Definition at line 404 of file Schur.cpp.

◆ optBackwardError

double MoFEM::BlockStorage::optBackwardError = 1e-12

-schur_a00_backward_error

Definition at line 411 of file Schur.cpp.

◆ optDense

bool MoFEM::BlockStorage::optDense = false

-schur_a00_dense

Definition at line 408 of file Schur.cpp.

◆ optPivotThreshold

double MoFEM::BlockStorage::optPivotThreshold = 0

-schur_a00_pivot_threshold

Definition at line 409 of file Schur.cpp.

◆ optRcondMin

double MoFEM::BlockStorage::optRcondMin = 1e-12

-schur_a00_rcond_min

Definition at line 410 of file Schur.cpp.

◆ patterns

std::vector<Pattern> MoFEM::BlockStorage::patterns

Definition at line 377 of file Schur.cpp.

◆ pivots

std::vector<__CLPK_integer> MoFEM::BlockStorage::pivots

Definition at line 388 of file Schur.cpp.


The documentation for this struct was generated from the following file: