PolyFEM
Loading...
Searching...
No Matches
polyfem::utils::SparseMatrixCache Class Reference

#include <MatrixCache.hpp>

Inheritance diagram for polyfem::utils::SparseMatrixCache:
[legend]
Collaboration diagram for polyfem::utils::SparseMatrixCache:
[legend]

Public Member Functions

 SparseMatrixCache ()
 
 SparseMatrixCache (const size_t size)
 
 SparseMatrixCache (const size_t rows, const size_t cols)
 
 SparseMatrixCache (const MatrixCache &other)
 
 SparseMatrixCache (const SparseMatrixCache &other, const bool copy_main_cache_ptr=false)
 
std::unique_ptr< MatrixCachecopy () const override
 
void init (const size_t size) override
 set matrix to be size x size
 
void init (const size_t rows, const size_t cols) override
 set matrix to be rows x cols
 
void init (const MatrixCache &other) override
 set matrix to be a matrix of all zeros with same size as other
 
void init (const SparseMatrixCache &other, const bool copy_main_cache_ptr=false)
 set matrix to be a matrix of all zeros with same size as other (potentially with the same main cache)
 
void set_zero () override
 set matrix values to zero modifies tmp_, mat_, and values (setting all to zero)
 
void reserve (const size_t size) override
 
size_t entries_size () const override
 
size_t capacity () const override
 
size_t non_zeros () const override
 
size_t triplet_count () const override
 
bool is_sparse () const override
 
size_t mapping_size () const
 
void add_value (const int e, const int i, const int j, const double value) override
 e = element_index, i = global row_index, j = global column_index, value = value to add to matrix if the cache is yet to be constructed, save the row, column, and value to be added to the second cache in this case, modifies_ entries_ and second_cache_entries_ otherwise, save the value directly in the second cache in this case, modfies values_
 
StiffnessMatrix get_matrix (const bool compute_mapping=true) override
 if the cache is yet to be constructed, save the cached (ordered) indices in inner_index_ and outer_index_ then fill in map and second_cache_ in this case, modifies inner_index_, outer_index_, map, and second_cache_ to reflect the matrix structure also empties second_cache_entries and sets values_ to zero otherwise, update mat_ directly using the cached indices and values_ in this case, modifies mat_ and sets values_ to zero
 
void prune () override
 if caches have yet to be constructed, add the saved triplets to mat_ modifies tmp_ and mat_, also sets entries_ to be empty after writing its values to mat_
 
std::shared_ptr< MatrixCacheoperator+ (const MatrixCache &a) const override
 
std::shared_ptr< MatrixCacheoperator+ (const SparseMatrixCache &a) const
 
void operator+= (const MatrixCache &o) override
 
void operator+= (const SparseMatrixCache &o)
 
const StiffnessMatrixmat () const
 
const std::vector< Eigen::Triplet< double > > & entries () const
 
- Public Member Functions inherited from polyfem::utils::MatrixCache
 MatrixCache ()
 
virtual ~MatrixCache ()=default
 
bool is_dense () const
 

Private Member Functions

const SparseMatrixCachemain_cache () const
 
const std::vector< std::vector< std::pair< int, size_t > > > & mapping () const
 
const std::vector< std::vector< int > > & second_cache () const
 

Private Attributes

size_t size_
 
StiffnessMatrix tmp_
 
StiffnessMatrix mat_
 
std::vector< Eigen::Triplet< double > > entries_
 contains global matrix indices and corresponding value
 
std::vector< std::vector< std::pair< int, size_t > > > mapping_
 maps row indices to column index/local index pairs
 
std::vector< int > inner_index_
 
std::vector< int > outer_index_
 saves inner/outer indices for sparse matrix
 
std::vector< double > values_
 buffer for values (corresponds to inner/outer_index_ structure for sparse matrix)
 
const SparseMatrixCachemain_cache_ = nullptr
 
std::vector< std::vector< int > > second_cache_
 maps element index to local index
 
std::vector< std::vector< std::pair< int, int > > > second_cache_entries_
 maps element indices to global matrix indices
 
int current_e_ = -1
 
int current_e_index_ = -1
 

Detailed Description

Definition at line 43 of file MatrixCache.hpp.

Constructor & Destructor Documentation

◆ SparseMatrixCache() [1/5]

polyfem::utils::SparseMatrixCache::SparseMatrixCache ( )
inline

Definition at line 47 of file MatrixCache.hpp.

◆ SparseMatrixCache() [2/5]

polyfem::utils::SparseMatrixCache::SparseMatrixCache ( const size_t  size)

Definition at line 8 of file MatrixCache.cpp.

References init().

Here is the call graph for this function:

◆ SparseMatrixCache() [3/5]

polyfem::utils::SparseMatrixCache::SparseMatrixCache ( const size_t  rows,
const size_t  cols 
)

Definition at line 13 of file MatrixCache.cpp.

References init().

Here is the call graph for this function:

◆ SparseMatrixCache() [4/5]

polyfem::utils::SparseMatrixCache::SparseMatrixCache ( const MatrixCache other)

Definition at line 18 of file MatrixCache.cpp.

References init().

Here is the call graph for this function:

◆ SparseMatrixCache() [5/5]

polyfem::utils::SparseMatrixCache::SparseMatrixCache ( const SparseMatrixCache other,
const bool  copy_main_cache_ptr = false 
)

Definition at line 23 of file MatrixCache.cpp.

References init().

Here is the call graph for this function:

Member Function Documentation

◆ add_value()

void polyfem::utils::SparseMatrixCache::add_value ( const int  e,
const int  i,
const int  j,
const double  value 
)
overridevirtual

e = element_index, i = global row_index, j = global column_index, value = value to add to matrix if the cache is yet to be constructed, save the row, column, and value to be added to the second cache in this case, modifies_ entries_ and second_cache_entries_ otherwise, save the value directly in the second cache in this case, modfies values_

Implements polyfem::utils::MatrixCache.

Definition at line 88 of file MatrixCache.cpp.

References current_e_, current_e_index_, entries_, mapping(), second_cache(), second_cache_entries_, and values_.

Here is the call graph for this function:

◆ capacity()

size_t polyfem::utils::SparseMatrixCache::capacity ( ) const
inlineoverridevirtual

Implements polyfem::utils::MatrixCache.

Definition at line 74 of file MatrixCache.hpp.

References entries_.

◆ copy()

std::unique_ptr< MatrixCache > polyfem::utils::SparseMatrixCache::copy ( ) const
inlineoverridevirtual

Implements polyfem::utils::MatrixCache.

Definition at line 53 of file MatrixCache.hpp.

◆ entries()

const std::vector< Eigen::Triplet< double > > & polyfem::utils::SparseMatrixCache::entries ( ) const
inline

Definition at line 104 of file MatrixCache.hpp.

References entries_.

◆ entries_size()

size_t polyfem::utils::SparseMatrixCache::entries_size ( ) const
inlineoverridevirtual

Implements polyfem::utils::MatrixCache.

Definition at line 73 of file MatrixCache.hpp.

References entries_.

◆ get_matrix()

polyfem::StiffnessMatrix polyfem::utils::SparseMatrixCache::get_matrix ( const bool  compute_mapping = true)
overridevirtual

if the cache is yet to be constructed, save the cached (ordered) indices in inner_index_ and outer_index_ then fill in map and second_cache_ in this case, modifies inner_index_, outer_index_, map, and second_cache_ to reflect the matrix structure also empties second_cache_entries and sets values_ to zero otherwise, update mat_ directly using the cached indices and values_ in this case, modifies mat_ and sets values_ to zero

Implements polyfem::utils::MatrixCache.

Definition at line 134 of file MatrixCache.cpp.

References current_e_, current_e_index_, inner_index_, polyfem::logger(), main_cache(), main_cache_, mapping(), mapping_, mat_, outer_index_, prune(), second_cache_, second_cache_entries_, size_, and values_.

Here is the call graph for this function:

◆ init() [1/4]

void polyfem::utils::SparseMatrixCache::init ( const MatrixCache other)
overridevirtual

set matrix to be a matrix of all zeros with same size as other

Implements polyfem::utils::MatrixCache.

Definition at line 49 of file MatrixCache.cpp.

References init().

Here is the call graph for this function:

◆ init() [2/4]

void polyfem::utils::SparseMatrixCache::init ( const size_t  rows,
const size_t  cols 
)
overridevirtual

set matrix to be rows x cols

Implements polyfem::utils::MatrixCache.

Definition at line 39 of file MatrixCache.cpp.

References mapping(), mat_, size_, and tmp_.

Here is the call graph for this function:

◆ init() [3/4]

void polyfem::utils::SparseMatrixCache::init ( const size_t  size)
overridevirtual

set matrix to be size x size

Implements polyfem::utils::MatrixCache.

Definition at line 29 of file MatrixCache.cpp.

References mapping(), mat_, size_, and tmp_.

Referenced by init(), SparseMatrixCache(), SparseMatrixCache(), SparseMatrixCache(), and SparseMatrixCache().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init() [4/4]

void polyfem::utils::SparseMatrixCache::init ( const SparseMatrixCache other,
const bool  copy_main_cache_ptr = false 
)

set matrix to be a matrix of all zeros with same size as other (potentially with the same main cache)

Definition at line 56 of file MatrixCache.cpp.

References main_cache(), main_cache_, mat_, size_, tmp_, and values_.

Here is the call graph for this function:

◆ is_sparse()

bool polyfem::utils::SparseMatrixCache::is_sparse ( ) const
inlineoverridevirtual

Implements polyfem::utils::MatrixCache.

Definition at line 77 of file MatrixCache.hpp.

◆ main_cache()

const SparseMatrixCache * polyfem::utils::SparseMatrixCache::main_cache ( ) const
inlineprivate

Definition at line 120 of file MatrixCache.hpp.

References main_cache_.

Referenced by get_matrix(), init(), mapping(), operator+(), operator+=(), and second_cache().

Here is the caller graph for this function:

◆ mapping()

const std::vector< std::vector< std::pair< int, size_t > > > & polyfem::utils::SparseMatrixCache::mapping ( ) const
inlineprivate

Definition at line 125 of file MatrixCache.hpp.

References main_cache(), and mapping_.

Referenced by add_value(), get_matrix(), init(), init(), operator+(), operator+=(), and prune().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mapping_size()

size_t polyfem::utils::SparseMatrixCache::mapping_size ( ) const
inline

Definition at line 78 of file MatrixCache.hpp.

References mapping_.

◆ mat()

const StiffnessMatrix & polyfem::utils::SparseMatrixCache::mat ( ) const
inline

Definition at line 103 of file MatrixCache.hpp.

References mat_.

◆ non_zeros()

size_t polyfem::utils::SparseMatrixCache::non_zeros ( ) const
inlineoverridevirtual

Implements polyfem::utils::MatrixCache.

Definition at line 75 of file MatrixCache.hpp.

References mapping_, mat_, and values_.

◆ operator+() [1/2]

std::shared_ptr< MatrixCache > polyfem::utils::SparseMatrixCache::operator+ ( const MatrixCache a) const
overridevirtual

Implements polyfem::utils::MatrixCache.

Definition at line 231 of file MatrixCache.cpp.

◆ operator+() [2/2]

std::shared_ptr< MatrixCache > polyfem::utils::SparseMatrixCache::operator+ ( const SparseMatrixCache a) const

Definition at line 237 of file MatrixCache.cpp.

References inner_index_, main_cache(), mapping(), mat_, polyfem::utils::maybe_parallel_for(), outer_index_, second_cache_entries_, and values_.

Here is the call graph for this function:

◆ operator+=() [1/2]

void polyfem::utils::SparseMatrixCache::operator+= ( const MatrixCache o)
overridevirtual

Implements polyfem::utils::MatrixCache.

Definition at line 284 of file MatrixCache.cpp.

◆ operator+=() [2/2]

void polyfem::utils::SparseMatrixCache::operator+= ( const SparseMatrixCache o)

Definition at line 290 of file MatrixCache.cpp.

References inner_index_, main_cache(), mapping(), mat_, polyfem::utils::maybe_parallel_for(), outer_index_, second_cache_entries_, and values_.

Here is the call graph for this function:

◆ prune()

void polyfem::utils::SparseMatrixCache::prune ( )
overridevirtual

if caches have yet to be constructed, add the saved triplets to mat_ modifies tmp_ and mat_, also sets entries_ to be empty after writing its values to mat_

add saved entries to stored matrix

Implements polyfem::utils::MatrixCache.

Definition at line 115 of file MatrixCache.cpp.

References entries_, mapping(), mat_, and tmp_.

Referenced by get_matrix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reserve()

void polyfem::utils::SparseMatrixCache::reserve ( const size_t  size)
inlineoverridevirtual

Implements polyfem::utils::MatrixCache.

Definition at line 72 of file MatrixCache.hpp.

References entries_.

◆ second_cache()

const std::vector< std::vector< int > > & polyfem::utils::SparseMatrixCache::second_cache ( ) const
inlineprivate

Definition at line 130 of file MatrixCache.hpp.

References main_cache(), and second_cache_.

Referenced by add_value().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_zero()

void polyfem::utils::SparseMatrixCache::set_zero ( )
overridevirtual

set matrix values to zero modifies tmp_, mat_, and values (setting all to zero)

Implements polyfem::utils::MatrixCache.

Definition at line 80 of file MatrixCache.cpp.

References mat_, tmp_, and values_.

◆ triplet_count()

size_t polyfem::utils::SparseMatrixCache::triplet_count ( ) const
inlineoverridevirtual

Implements polyfem::utils::MatrixCache.

Definition at line 76 of file MatrixCache.hpp.

References entries_, and mat_.

Member Data Documentation

◆ current_e_

int polyfem::utils::SparseMatrixCache::current_e_ = -1
private

Definition at line 117 of file MatrixCache.hpp.

Referenced by add_value(), and get_matrix().

◆ current_e_index_

int polyfem::utils::SparseMatrixCache::current_e_index_ = -1
private

Definition at line 118 of file MatrixCache.hpp.

Referenced by add_value(), and get_matrix().

◆ entries_

std::vector<Eigen::Triplet<double> > polyfem::utils::SparseMatrixCache::entries_
private

contains global matrix indices and corresponding value

Definition at line 109 of file MatrixCache.hpp.

Referenced by add_value(), capacity(), entries(), entries_size(), prune(), reserve(), and triplet_count().

◆ inner_index_

std::vector<int> polyfem::utils::SparseMatrixCache::inner_index_
private

Definition at line 111 of file MatrixCache.hpp.

Referenced by get_matrix(), operator+(), and operator+=().

◆ main_cache_

const SparseMatrixCache* polyfem::utils::SparseMatrixCache::main_cache_ = nullptr
private

Definition at line 113 of file MatrixCache.hpp.

Referenced by get_matrix(), init(), and main_cache().

◆ mapping_

std::vector<std::vector<std::pair<int, size_t> > > polyfem::utils::SparseMatrixCache::mapping_
private

maps row indices to column index/local index pairs

Definition at line 110 of file MatrixCache.hpp.

Referenced by get_matrix(), mapping(), mapping_size(), and non_zeros().

◆ mat_

StiffnessMatrix polyfem::utils::SparseMatrixCache::mat_
private

◆ outer_index_

std::vector<int> polyfem::utils::SparseMatrixCache::outer_index_
private

saves inner/outer indices for sparse matrix

Definition at line 111 of file MatrixCache.hpp.

Referenced by get_matrix(), operator+(), and operator+=().

◆ second_cache_

std::vector<std::vector<int> > polyfem::utils::SparseMatrixCache::second_cache_
private

maps element index to local index

Definition at line 115 of file MatrixCache.hpp.

Referenced by get_matrix(), and second_cache().

◆ second_cache_entries_

std::vector<std::vector<std::pair<int, int> > > polyfem::utils::SparseMatrixCache::second_cache_entries_
private

maps element indices to global matrix indices

Definition at line 116 of file MatrixCache.hpp.

Referenced by add_value(), get_matrix(), operator+(), and operator+=().

◆ size_

size_t polyfem::utils::SparseMatrixCache::size_
private

Definition at line 107 of file MatrixCache.hpp.

Referenced by get_matrix(), init(), init(), and init().

◆ tmp_

StiffnessMatrix polyfem::utils::SparseMatrixCache::tmp_
private

Definition at line 108 of file MatrixCache.hpp.

Referenced by init(), init(), init(), prune(), and set_zero().

◆ values_

std::vector<double> polyfem::utils::SparseMatrixCache::values_
private

buffer for values (corresponds to inner/outer_index_ structure for sparse matrix)

Definition at line 112 of file MatrixCache.hpp.

Referenced by add_value(), get_matrix(), init(), non_zeros(), operator+(), operator+=(), and set_zero().


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