PolyFEM
|
#include <MatrixCache.hpp>
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< MatrixCache > | copy () 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< MatrixCache > | operator+ (const MatrixCache &a) const override |
std::shared_ptr< MatrixCache > | operator+ (const SparseMatrixCache &a) const |
void | operator+= (const MatrixCache &o) override |
void | operator+= (const SparseMatrixCache &o) |
const StiffnessMatrix & | mat () 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 SparseMatrixCache * | main_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 SparseMatrixCache * | main_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 |
Definition at line 43 of file MatrixCache.hpp.
|
inline |
Definition at line 47 of file MatrixCache.hpp.
polyfem::utils::SparseMatrixCache::SparseMatrixCache | ( | const size_t | size | ) |
Definition at line 8 of file MatrixCache.cpp.
References init().
polyfem::utils::SparseMatrixCache::SparseMatrixCache | ( | const size_t | rows, |
const size_t | cols | ||
) |
Definition at line 13 of file MatrixCache.cpp.
References init().
polyfem::utils::SparseMatrixCache::SparseMatrixCache | ( | const MatrixCache & | other | ) |
Definition at line 18 of file MatrixCache.cpp.
References init().
polyfem::utils::SparseMatrixCache::SparseMatrixCache | ( | const SparseMatrixCache & | other, |
const bool | copy_main_cache_ptr = false |
||
) |
Definition at line 23 of file MatrixCache.cpp.
References init().
|
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_.
|
inlineoverridevirtual |
Implements polyfem::utils::MatrixCache.
Definition at line 74 of file MatrixCache.hpp.
References entries_.
|
inlineoverridevirtual |
Implements polyfem::utils::MatrixCache.
Definition at line 53 of file MatrixCache.hpp.
|
inline |
Definition at line 104 of file MatrixCache.hpp.
References entries_.
|
inlineoverridevirtual |
Implements polyfem::utils::MatrixCache.
Definition at line 73 of file MatrixCache.hpp.
References entries_.
|
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_.
|
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().
|
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_.
|
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().
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_.
|
inlineoverridevirtual |
Implements polyfem::utils::MatrixCache.
Definition at line 77 of file MatrixCache.hpp.
|
inlineprivate |
Definition at line 120 of file MatrixCache.hpp.
References main_cache_.
Referenced by get_matrix(), init(), mapping(), operator+(), operator+=(), and second_cache().
|
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().
|
inline |
Definition at line 78 of file MatrixCache.hpp.
References mapping_.
|
inline |
Definition at line 103 of file MatrixCache.hpp.
References mat_.
|
inlineoverridevirtual |
Implements polyfem::utils::MatrixCache.
Definition at line 75 of file MatrixCache.hpp.
|
overridevirtual |
Implements polyfem::utils::MatrixCache.
Definition at line 231 of file MatrixCache.cpp.
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_.
|
overridevirtual |
Implements polyfem::utils::MatrixCache.
Definition at line 284 of file MatrixCache.cpp.
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_.
|
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().
|
inlineoverridevirtual |
Implements polyfem::utils::MatrixCache.
Definition at line 72 of file MatrixCache.hpp.
References entries_.
|
inlineprivate |
Definition at line 130 of file MatrixCache.hpp.
References main_cache(), and second_cache_.
Referenced by add_value().
|
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.
|
inlineoverridevirtual |
Implements polyfem::utils::MatrixCache.
Definition at line 76 of file MatrixCache.hpp.
|
private |
Definition at line 117 of file MatrixCache.hpp.
Referenced by add_value(), and get_matrix().
|
private |
Definition at line 118 of file MatrixCache.hpp.
Referenced by add_value(), and get_matrix().
|
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().
|
private |
Definition at line 111 of file MatrixCache.hpp.
Referenced by get_matrix(), operator+(), and operator+=().
|
private |
Definition at line 113 of file MatrixCache.hpp.
Referenced by get_matrix(), init(), and main_cache().
|
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().
|
private |
Definition at line 108 of file MatrixCache.hpp.
Referenced by get_matrix(), init(), init(), init(), mat(), non_zeros(), operator+(), operator+=(), prune(), set_zero(), and triplet_count().
|
private |
saves inner/outer indices for sparse matrix
Definition at line 111 of file MatrixCache.hpp.
Referenced by get_matrix(), operator+(), and operator+=().
|
private |
maps element index to local index
Definition at line 115 of file MatrixCache.hpp.
Referenced by get_matrix(), and second_cache().
|
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+=().
|
private |
Definition at line 107 of file MatrixCache.hpp.
Referenced by get_matrix(), init(), init(), and init().
|
private |
Definition at line 108 of file MatrixCache.hpp.
Referenced by init(), init(), init(), prune(), and set_zero().
|
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().