Flow123d  3.9.0-9663d1cde
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
LocalSystem Class Reference

#include <local_system.hh>

Public Member Functions

 LocalSystem ()
 Default constructor. More...
 
 LocalSystem (uint nrows, uint ncols)
 Constructor. More...
 
void reset ()
 Resets the matrix, RHS, dofs to zero and clears solution settings. More...
 
void reset (uint nrows, uint ncols)
 Resize and reset. More...
 
void reset (const LocDofVec &row_dofs, const LocDofVec &col_dofs)
 
const arma::mat & get_matrix ()
 
const arma::vec & get_rhs ()
 
void set_solution (uint loc_dof, double solution, double diag=0.0)
 Set the position and value of known solution. E.g. Dirichlet boundary condition. More...
 
void set_solution (LocalConstraint &loc_constraint)
 Set the position and value of known solution. E.g. Dirichlet boundary condition. More...
 
void set_solution_row (uint loc_row, double solution, double diag=0.0)
 
void set_solution_col (uint loc_col, double solution)
 
void eliminate_solution ()
 
void add_value (uint row, uint col, double mat_val, double rhs_val)
 Adds a single entry into the local system. More...
 
void add_value (uint row, uint col, double mat_val)
 Matrix entry. Adds a single entry into the local system matrix. More...
 
void add_value (uint row, double rhs_val)
 RHS entry. Adds a single entry into the local system RHS. More...
 
void set_matrix (arma::mat matrix)
 
void set_rhs (arma::vec rhs)
 
void set_sparsity (const arma::umat &sp)
 Sets the sparsity pattern for the local system. More...
 
void compute_schur_complement (uint offset, LocalSystem &schur, bool negative=false) const
 Computes Schur complement of the local system: S = C - B * invA * Bt Applicable for square matrices. It can be called either after eliminating Dirichlet dofs, or the Dirichlet dofs can be set on the Schur complement and the elimination done on the Schur complement. More...
 
void reconstruct_solution_schur (uint offset, const arma::vec &schur_solution, arma::vec &reconstructed_solution) const
 Reconstructs the solution from the Schur complement solution: x = invA*b - invA * Bt * schur_solution Applicable for square matrices. More...
 

Public Attributes

LocDofVec row_dofs
 
LocDofVec col_dofs
 

Static Public Attributes

static constexpr double almost_zero = std::numeric_limits<double>::min()
 

Protected Member Functions

void set_size (uint nrows, uint ncols)
 

Protected Attributes

arma::mat matrix
 local system matrix More...
 
arma::vec rhs
 local system RHS More...
 
arma::mat sparsity
 sparsity pattern More...
 
uint n_elim_rows
 Number of rows/cols to be eliminated due to known solution. More...
 
uint n_elim_cols
 
LocDofVec elim_rows
 
LocDofVec elim_cols
 Rows indices of rows to be eliminated. More...
 
arma::vec solution_rows
 Cols indices of cols to be eliminated. More...
 
arma::vec solution_cols
 Values of the known solution (for row dofs). More...
 
arma::vec diag_rows
 Values of the known solution (for col dofs). More...
 

Friends

class LinSys
 Prefered values on the diagonal after elimination. More...
 

Detailed Description

Local system class is meant to be used for local assembly and then pass to global linear system. The key idea is to take care of known solution values (Dirichlet boundary conditions) in a common way.

A] Usage of the class consists of 5 steps: 1) create local system, set local/global DoFs. 2) possibly setup sparsity pattern for the local system 3) set matrix and RHS entries 4) set all known values (Dirichlet BC) (the order of items 3 and 4 does not matter) 5) possibly eliminate the known solution (possibly fix the diagonal entries of the local system, where Dirichlet BC is set) 6) pass the local system to the global system, possibly with the map local_to_global

B] Scenario with computation of Schur complement: 1) do A1, do not have to set dof indices (if not doing B3) 2) do A2, A3 3) possibly do A4, A5, if there is known solution for the dofs not included in the Schur complement 3) create another LocalSystem for Schur complement (local_schur), possibly set dof indices 4) possibly do A2 on local_schur 4) compute Schur complement, passing the prepared local_schur 5) if not done before, set dof indices 6) possibly do A4, A5 on local_schur 7) do A6 with local_schur

C] Reconstruction from the Schur complement 1) do A1, A3 2) reconstruct the full solution

TODO:

Definition at line 46 of file local_system.hh.

Constructor & Destructor Documentation

◆ LocalSystem() [1/2]

LocalSystem::LocalSystem ( )

Default constructor.

Object must be initialized by subsequent call of reset(nrows, ncols).

Definition at line 10 of file local_system.cc.

◆ LocalSystem() [2/2]

LocalSystem::LocalSystem ( uint  nrows,
uint  ncols 
)

Constructor.

nrows is number of rows of local system ncols is number of columns of local system

Definition at line 14 of file local_system.cc.

Member Function Documentation

◆ add_value() [1/3]

void LocalSystem::add_value ( uint  row,
double  rhs_val 
)

RHS entry. Adds a single entry into the local system RHS.

row is local row index of local system rhs_val is RHS entry value

Definition at line 197 of file local_system.cc.

◆ add_value() [2/3]

void LocalSystem::add_value ( uint  row,
uint  col,
double  mat_val 
)

Matrix entry. Adds a single entry into the local system matrix.

row is local row index of local system col is local column index of local system mat_val is matrix entry value

Definition at line 188 of file local_system.cc.

◆ add_value() [3/3]

void LocalSystem::add_value ( uint  row,
uint  col,
double  mat_val,
double  rhs_val 
)

Adds a single entry into the local system.

row is local row index of local system col is local column index of local system mat_val is matrix entry value rhs_val is RHS entry value

Definition at line 178 of file local_system.cc.

Here is the caller graph for this function:

◆ compute_schur_complement()

void LocalSystem::compute_schur_complement ( uint  offset,
LocalSystem schur,
bool  negative = false 
) const

Computes Schur complement of the local system: S = C - B * invA * Bt Applicable for square matrices. It can be called either after eliminating Dirichlet dofs, or the Dirichlet dofs can be set on the Schur complement and the elimination done on the Schur complement.

offset index of the first row/column of submatrix C (size of A) schur (output) LocalSystem with Schur complement negative if true, the schur complement (including its rhs) is multiplied by -1.0

Definition at line 229 of file local_system.cc.

◆ eliminate_solution()

void LocalSystem::eliminate_solution ( )

When finished with assembly of the local system, this function eliminates all the known dofs.

It is skipped if there is not any solution dof set.

During elimination, the (global) diagonal entries on the rows, where the solution is set, might be zero. Therefore it is necessary to set a proper value to the diagonal entry and respective RHS entry, such that the given solution holds. If preferred diagonal value has been set by set_solution then it is used.

Calling this function after the assembly of local system and before passing the local system to the global one is finished is users's responsibility.

Definition at line 111 of file local_system.cc.

Here is the caller graph for this function:

◆ get_matrix()

const arma::mat& LocalSystem::get_matrix ( )
inline

Definition at line 82 of file local_system.hh.

Here is the caller graph for this function:

◆ get_rhs()

const arma::vec& LocalSystem::get_rhs ( )
inline

Definition at line 83 of file local_system.hh.

Here is the caller graph for this function:

◆ reconstruct_solution_schur()

void LocalSystem::reconstruct_solution_schur ( uint  offset,
const arma::vec &  schur_solution,
arma::vec &  reconstructed_solution 
) const

Reconstructs the solution from the Schur complement solution: x = invA*b - invA * Bt * schur_solution Applicable for square matrices.

offset index of the first row/column of submatrix C (size of A) schur_solution solution of the Schur complement reconstructed_solution (output) reconstructed solution of the complementary variable

Definition at line 250 of file local_system.cc.

Here is the caller graph for this function:

◆ reset() [1/3]

void LocalSystem::reset ( )

Resets the matrix, RHS, dofs to zero and clears solution settings.

Definition at line 46 of file local_system.cc.

Here is the caller graph for this function:

◆ reset() [2/3]

void LocalSystem::reset ( const LocDofVec row_dofs,
const LocDofVec col_dofs 
)

Resize and reset. Set dofs vectors to reuse arrays provided by given vectors. Given vectors can not be changed until next call to of any reset function.

Definition at line 68 of file local_system.cc.

◆ reset() [3/3]

void LocalSystem::reset ( uint  nrows,
uint  ncols 
)

Resize and reset.

Definition at line 56 of file local_system.cc.

◆ set_matrix()

void LocalSystem::set_matrix ( arma::mat  matrix)

Definition at line 205 of file local_system.cc.

Here is the caller graph for this function:

◆ set_rhs()

void LocalSystem::set_rhs ( arma::vec  rhs)

Definition at line 211 of file local_system.cc.

Here is the caller graph for this function:

◆ set_size()

void LocalSystem::set_size ( uint  nrows,
uint  ncols 
)
protected

Definition at line 29 of file local_system.cc.

Here is the caller graph for this function:

◆ set_solution() [1/2]

void LocalSystem::set_solution ( LocalConstraint loc_constraint)

Set the position and value of known solution. E.g. Dirichlet boundary condition.

LocalConstraint data object holds all needed data used in previous method

Definition at line 90 of file local_system.cc.

◆ set_solution() [2/2]

void LocalSystem::set_solution ( uint  loc_dof,
double  solution,
double  diag = 0.0 
)

Set the position and value of known solution. E.g. Dirichlet boundary condition.

loc_dofs is local row index in solution vector solution is the values of the solution diag_val is preferred diagonal value on the solution row

Definition at line 82 of file local_system.cc.

Here is the caller graph for this function:

◆ set_solution_col()

void LocalSystem::set_solution_col ( uint  loc_col,
double  solution 
)

Definition at line 105 of file local_system.cc.

Here is the caller graph for this function:

◆ set_solution_row()

void LocalSystem::set_solution_row ( uint  loc_row,
double  solution,
double  diag = 0.0 
)

Definition at line 98 of file local_system.cc.

Here is the caller graph for this function:

◆ set_sparsity()

void LocalSystem::set_sparsity ( const arma::umat &  sp)

Sets the sparsity pattern for the local system.

Due to petsc options: MatSetOption(matrix_, MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE) all zeros will be thrown away from the system. If we do not want some zero entries in the system matrix to be thrown away, we can set these entries with this almost zero value.

Almost_zero values will be set in all entries: sp(i,j) != 0

Definition at line 216 of file local_system.cc.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ LinSys

friend class LinSys
friend

Prefered values on the diagonal after elimination.

Definition at line 212 of file local_system.hh.

Member Data Documentation

◆ almost_zero

constexpr double LocalSystem::almost_zero = std::numeric_limits<double>::min()
staticconstexpr

Due to petsc options: MatSetOption(matrix_, MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE) all zeros will be thrown away from the system. If we do not want some zero entries in the system matrix to be thrown away, we can set these entries with this almost zero value.

This is done for example when BC values are eliminated and later the BC changes to different type (e.g. seepage). Another case is keeping the structure of matrix unchanged for the schur complements - for that we fill the whole diagonal (escpecially block C in darcy flow) with artificial zeros.

Definition at line 191 of file local_system.hh.

◆ col_dofs

LocDofVec LocalSystem::col_dofs

Definition at line 54 of file local_system.hh.

◆ diag_rows

arma::vec LocalSystem::diag_rows
protected

Values of the known solution (for col dofs).

Definition at line 208 of file local_system.hh.

◆ elim_cols

LocDofVec LocalSystem::elim_cols
protected

Rows indices of rows to be eliminated.

Definition at line 205 of file local_system.hh.

◆ elim_rows

LocDofVec LocalSystem::elim_rows
protected

Definition at line 204 of file local_system.hh.

◆ matrix

arma::mat LocalSystem::matrix
protected

local system matrix

Definition at line 197 of file local_system.hh.

◆ n_elim_cols

uint LocalSystem::n_elim_cols
protected

Definition at line 203 of file local_system.hh.

◆ n_elim_rows

uint LocalSystem::n_elim_rows
protected

Number of rows/cols to be eliminated due to known solution.

Definition at line 203 of file local_system.hh.

◆ rhs

arma::vec LocalSystem::rhs
protected

local system RHS

Definition at line 198 of file local_system.hh.

◆ row_dofs

LocDofVec LocalSystem::row_dofs

Global row and col indices. Are public and can be freely set. Nevertheless one can also provide reference to already existing arrays through specific constructor or reset function.

Definition at line 54 of file local_system.hh.

◆ solution_cols

arma::vec LocalSystem::solution_cols
protected

Values of the known solution (for row dofs).

Definition at line 207 of file local_system.hh.

◆ solution_rows

arma::vec LocalSystem::solution_rows
protected

Cols indices of cols to be eliminated.

Definition at line 206 of file local_system.hh.

◆ sparsity

arma::mat LocalSystem::sparsity
protected

sparsity pattern

Definition at line 200 of file local_system.hh.


The documentation for this class was generated from the following files: