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  FeConnectivity
 
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
 
SchurFEOpsFEandFields feOps
 
std::vector< std::pair< UId, int > > feList
 (element uid, index in feOps) of elements of the last build, sorted
 
std::vector< FeConnectivity > feConnectivity
 Surviving elements can acquire different field entities after local flips.
 
std::vector< Pattern > patternCache
 
std::vector< std::pair< UId, std::vector< double > > > elemDataCache
 
std::vector< std::pair< UId, std::vector< double > > > elemPrecCache
 
std::vector< double > dataCache
 
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 440 of file Schur.cpp.

440 {
444 FACTOR_FAILED ///< factorisation failed, data is corrupted
445 };
@ FACTOR_FAILED
factorisation failed, data is corrupted
Definition Schur.cpp:444

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

490 {
491 if (b.getElem() >= 0)
492 return (prec ? elemPrec : elemData)[b.getElem()].data() + b.getMatShift();
493 return data.data() + b.getMatShift();
494 }
std::vector< double > data
blocks not in A00, allocated on first use
Definition Schur.cpp:403
std::vector< std::vector< double > > elemPrec
preconditioner buffers
Definition Schur.cpp:397
std::vector< std::vector< double > > elemData
A00 element buffers.
Definition Schur.cpp:396

◆ checkNotFailed()

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

Fails if factorisation failed, storage has to be zeroed.

Definition at line 459 of file Schur.cpp.

459 {
462 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
463 "A00 factorisation failed and block matrix data is corrupted, "
464 "call MatZeroEntries and assemble again");
466 }
#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:446

◆ colRange()

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

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

Definition at line 537 of file Schur.cpp.

537 {
538 auto lo = std::lower_bound(
539 colOrder.begin(), colOrder.end(), col,
540 [this](int i, const UId &c) { return blockIndex[i].getColUId() < c; });
541 auto hi = std::upper_bound(
542 colOrder.begin(), colOrder.end(), col,
543 [this](const UId &c, int i) { return c < blockIndex[i].getColUId(); });
544 return std::make_pair(lo, hi);
545 }
std::vector< FieldBitNumber > col
Definition Schur.cpp:2488
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:391

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

429 {
430 if (data.size() != dataSize) {
431 // an allocation kept by rebuildBlockMatStructure is reused, and grown
432 // only if it is too small
433 if (data.empty() && dataCache.capacity() > data.capacity())
434 data.swap(dataCache);
435 std::vector<double>().swap(dataCache);
436 data.assign(dataSize, 0.);
437 }
438 }
size_t dataSize
required size of data
Definition Schur.cpp:402
std::vector< double > dataCache
Definition Schur.cpp:425

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

503 {
504 auto it = std::lower_bound(
505 blockIndex.begin(), blockIndex.end(), std::make_pair(row, col),
506 [](const Indexes &a, const std::pair<UId, UId> &p) {
507 if (a.getRowUId() != p.first)
508 return a.getRowUId() < p.first;
509 return a.getColUId() < p.second;
510 });
511 if (it != blockIndex.end() && it->getRowUId() == row &&
512 it->getColUId() == col)
513 return &*it;
514 return nullptr;
515 }
std::vector< FieldBitNumber > row
Definition Schur.cpp:2488
It it
Definition Schur.cpp:2568
constexpr double a
std::vector< Indexes > blockIndex
blocks sorted by (row uid, col uid)
Definition Schur.cpp:389

◆ findMutable()

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

Definition at line 517 of file Schur.cpp.

517 {
518 return const_cast<Indexes *>(find(row, col));
519 }
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:503

◆ isFactorised()

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

Definition at line 456 of file Schur.cpp.

456{ return factorStorage != FACTOR_NONE; }

◆ lessRowCol()

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

Definition at line 496 of file Schur.cpp.

496 {
497 if (a.getRowUId() != b.getRowUId())
498 return a.getRowUId() < b.getRowUId();
499 return a.getColUId() < b.getColUId();
500 }

◆ modified()

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

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

Definition at line 469 of file Schur.cpp.

469 {
472 if (isFactorised())
473 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
474 "A00 element matrices are factorised in place, call "
475 "MatZeroEntries before assembling or modifying block matrix");
477 }
#define CHKERR
Inline error check.
bool isFactorised() const
Definition Schur.cpp:456
MoFEMErrorCode checkNotFailed() const
Fails if factorisation failed, storage has to be zeroed.
Definition Schur.cpp:459

◆ resetFactors()

void MoFEM::BlockStorage::resetFactors ( )
inline

Definition at line 479 of file Schur.cpp.

479 {
481 for (auto &e : elems) {
482 e.factorised = false;
483 e.dense = false;
484 }
485 for (auto &d : elemDense)
486 std::vector<double>().swap(d);
487 }
std::vector< Elem > elems
Definition Schur.cpp:394
std::vector< std::vector< double > > elemDense
dense factors (fallback)
Definition Schur.cpp:398

◆ rowRange()

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

range of blocks with given row entity uid

Definition at line 531 of file Schur.cpp.

531 {
532 return std::equal_range(blockIndex.begin(), blockIndex.end(), row,
533 RowUIdLess());
534 }

Member Data Documentation

◆ blockIndex

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

blocks sorted by (row uid, col uid)

Definition at line 389 of file Schur.cpp.

◆ colOrder

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

blocks sorted by (col uid, row uid)

Definition at line 391 of file Schur.cpp.

◆ data

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

blocks not in A00, allocated on first use

Definition at line 403 of file Schur.cpp.

◆ dataCache

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

allocation of data kept by rebuildBlockMatStructure, reused by ensureAllocated

Definition at line 425 of file Schur.cpp.

◆ dataSize

size_t MoFEM::BlockStorage::dataSize = 0

required size of data

Definition at line 402 of file Schur.cpp.

◆ elemData

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

A00 element buffers.

Definition at line 396 of file Schur.cpp.

◆ elemDataCache

std::vector<std::pair<UId, std::vector<double> > > MoFEM::BlockStorage::elemDataCache

element buffers of the nested layout before rebuildBlockMatStructure, by element uid, given back to the same elements when nested again

Definition at line 421 of file Schur.cpp.

◆ elemDense

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

dense factors (fallback)

Definition at line 398 of file Schur.cpp.

◆ elemEntities

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

Definition at line 395 of file Schur.cpp.

◆ elemPrec

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

preconditioner buffers

Definition at line 397 of file Schur.cpp.

◆ elemPrecCache

std::vector<std::pair<UId, std::vector<double> > > MoFEM::BlockStorage::elemPrecCache

Definition at line 422 of file Schur.cpp.

◆ elems

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

Definition at line 394 of file Schur.cpp.

◆ factorStorage

FactorStorage MoFEM::BlockStorage::factorStorage = FACTOR_NONE

Definition at line 446 of file Schur.cpp.

◆ feConnectivity

std::vector<FeConnectivity> MoFEM::BlockStorage::feConnectivity

Surviving elements can acquire different field entities after local flips.

Definition at line 415 of file Schur.cpp.

◆ feList

std::vector<std::pair<UId, int> > MoFEM::BlockStorage::feList

(element uid, index in feOps) of elements of the last build, sorted

Definition at line 408 of file Schur.cpp.

◆ feOps

SchurFEOpsFEandFields MoFEM::BlockStorage::feOps

elements and field pairs of the blocks

Definition at line 406 of file Schur.cpp.

◆ feOrder

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

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

Definition at line 390 of file Schur.cpp.

◆ hasPreconditioner

bool MoFEM::BlockStorage::hasPreconditioner = false

preconditioner blocks are enabled

Definition at line 448 of file Schur.cpp.

◆ maxElemBuffer

size_t MoFEM::BlockStorage::maxElemBuffer = 0

maximal size of element buffer

Definition at line 400 of file Schur.cpp.

◆ maxElemSize

int MoFEM::BlockStorage::maxElemSize = 0

maximal DOFs of element

Definition at line 399 of file Schur.cpp.

◆ nested

bool MoFEM::BlockStorage::nested = false

nested Schur structure has been created

Definition at line 447 of file Schur.cpp.

◆ optBackwardError

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

-schur_a00_backward_error

Definition at line 454 of file Schur.cpp.

◆ optDense

bool MoFEM::BlockStorage::optDense = false

-schur_a00_dense

Definition at line 451 of file Schur.cpp.

◆ optPivotThreshold

double MoFEM::BlockStorage::optPivotThreshold = 0

-schur_a00_pivot_threshold

Definition at line 452 of file Schur.cpp.

◆ optRcondMin

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

-schur_a00_rcond_min

Definition at line 453 of file Schur.cpp.

◆ patternCache

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

patterns of the nested layout before rebuildBlockMatStructure, reused by rebuildSchurNestedMatrixStruture

Definition at line 418 of file Schur.cpp.

◆ patterns

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

Definition at line 393 of file Schur.cpp.

◆ pivots

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

Definition at line 404 of file Schur.cpp.


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