Flow123d  JS_before_hm-1601-gc6ac32d
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static 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_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
 

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...
 

Static Protected Attributes

static constexpr double almost_zero = std::numeric_limits<double>::min()
 Prefered values on the diagonal after elimination. More...
 

Friends

class LinSys
 

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 45 of file local_system.hh.

Constructor & Destructor Documentation

LocalSystem::LocalSystem ( )

Default constructor.

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

Definition at line 9 of file local_system.cc.

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 13 of file local_system.cc.

Member Function Documentation

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 169 of file local_system.cc.

Here is the caller graph for this function:

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 179 of file local_system.cc.

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 188 of file local_system.cc.

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 220 of file local_system.cc.

Here is the caller graph for this function:

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 102 of file local_system.cc.

Here is the caller graph for this function:

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

Definition at line 81 of file local_system.hh.

Here is the caller graph for this function:

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

Definition at line 82 of file local_system.hh.

Here is the caller graph for this function:

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 241 of file local_system.cc.

Here is the caller graph for this function:

void LocalSystem::reset ( )

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

Definition at line 45 of file local_system.cc.

Here is the caller graph for this function:

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

Resize and reset.

Definition at line 55 of file local_system.cc.

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 67 of file local_system.cc.

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

Definition at line 196 of file local_system.cc.

Here is the caller graph for this function:

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

Definition at line 202 of file local_system.cc.

Here is the caller graph for this function:

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

Definition at line 28 of file local_system.cc.

Here is the caller graph for this function:

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 81 of file local_system.cc.

Here is the caller graph for this function:

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

Definition at line 96 of file local_system.cc.

Here is the caller graph for this function:

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

Definition at line 89 of file local_system.cc.

Here is the caller graph for this function:

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 207 of file local_system.cc.

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class LinSys
friend

Definition at line 203 of file local_system.hh.

Member Data Documentation

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

Prefered values on the diagonal after elimination.

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 200 of file local_system.hh.

LocDofVec LocalSystem::col_dofs

Definition at line 53 of file local_system.hh.

arma::vec LocalSystem::diag_rows
protected

Values of the known solution (for col dofs).

Definition at line 190 of file local_system.hh.

LocDofVec LocalSystem::elim_cols
protected

Rows indices of rows to be eliminated.

Definition at line 187 of file local_system.hh.

LocDofVec LocalSystem::elim_rows
protected

Definition at line 186 of file local_system.hh.

arma::mat LocalSystem::matrix
protected

local system matrix

Definition at line 179 of file local_system.hh.

uint LocalSystem::n_elim_cols
protected

Definition at line 185 of file local_system.hh.

uint LocalSystem::n_elim_rows
protected

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

Definition at line 185 of file local_system.hh.

arma::vec LocalSystem::rhs
protected

local system RHS

Definition at line 180 of file local_system.hh.

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 53 of file local_system.hh.

arma::vec LocalSystem::solution_cols
protected

Values of the known solution (for row dofs).

Definition at line 189 of file local_system.hh.

arma::vec LocalSystem::solution_rows
protected

Cols indices of cols to be eliminated.

Definition at line 188 of file local_system.hh.

arma::mat LocalSystem::sparsity
protected

sparsity pattern

Definition at line 182 of file local_system.hh.


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