26 init(other, copy_main_cache_ptr);
43 size_ = rows == cols ? rows : 0;
44 tmp_.resize(rows, cols);
45 mat_.resize(rows, cols);
51 assert(
this != &other);
59 assert(
this != &other);
60 if (copy_main_cache_ptr)
121 tmp_.makeCompressed();
125 tmp_.data().squeeze();
126 mat_.makeCompressed();
130 mat_.makeCompressed();
141 if (compute_mapping &&
size_ > 0)
151 const auto inn_ptr =
mat_.innerIndexPtr();
152 const auto out_ptr =
mat_.outerIndexPtr();
158 for (
size_t i = 0; i <
mat_.cols(); ++i)
164 for (
size_t ii = start; ii < end; ++ii)
169 map.emplace_back(i, index);
174 logger().trace(
"Cache computed");
184 const int i = p.first;
185 const int j = p.second;
188 const auto &map =
mapping()[i];
192 for (
const auto &p : map)
197 assert(p.second <
values_.size());
211 logger().trace(
"Second cache computed");
220 mat_ = Eigen::Map<const StiffnessMatrix>(
239 std::shared_ptr<SparseMatrixCache> out = std::make_shared<SparseMatrixCache>(a);
247 out->second_cache_entries_.resize(std::max(this_e_size, a_e_size));
248 for (
int e = 0; e < std::min(this_e_size, a_e_size); ++e)
255 for (
int e = std::min(this_e_size, a_e_size); e < std::max(this_e_size, a_e_size); ++e)
269 assert(ainner_index.size() == inner_index.size());
270 assert(aouter_index.size() == outer_index.size());
274 for (int i = start; i < end; ++i)
276 out->values_[i] = a.values_[i] + values_[i];
300 for (
int e = 0; e < o_e_size; ++e)
312 assert(inner_index.size() == oinner_index.size());
313 assert(outer_index.size() == oouter_index.size());
317 for (int i = start; i < end; ++i)
319 values_[i] += o.values_[i];
329 mat_.setZero(size, size);
334 mat_.setZero(rows, cols);
349 mat_.setZero(size, size);
354 mat_.setZero(rows, cols);
381 return mat_.sparseView();
391 std::shared_ptr<DenseMatrixCache> out = std::make_shared<DenseMatrixCache>(a);
std::shared_ptr< MatrixCache > operator+(const MatrixCache &a) const override
void init(const size_t size) override
StiffnessMatrix get_matrix(const bool compute_mapping=true) override
void add_value(const int e, const int i, const int j, const double value) override
void operator+=(const MatrixCache &o) override
abstract class used for caching
void operator+=(const MatrixCache &o) override
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 t...
void set_zero() override
set matrix values to zero modifies tmp_, mat_, and values (setting all to zero)
std::vector< int > outer_index_
saves inner/outer indices for sparse matrix
void prune() override
if caches have yet to be constructed, add the saved triplets to mat_ modifies tmp_ and mat_,...
const SparseMatrixCache * main_cache_
std::shared_ptr< MatrixCache > operator+(const MatrixCache &a) const override
const std::vector< std::vector< std::pair< int, size_t > > > & mapping() const
std::vector< std::vector< std::pair< int, int > > > second_cache_entries_
maps element indices to global matrix indices
const SparseMatrixCache * main_cache() const
std::vector< double > values_
buffer for values (corresponds to inner/outer_index_ structure for sparse matrix)
const std::vector< std::vector< int > > & second_cache() const
std::vector< Eigen::Triplet< double > > entries_
contains global matrix indices and corresponding value
std::vector< int > inner_index_
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_in...
void init(const size_t size) override
set matrix to be size x size
std::vector< std::vector< int > > second_cache_
maps element index to local index
std::vector< std::vector< std::pair< int, size_t > > > mapping_
maps row indices to column index/local index pairs
void maybe_parallel_for(int size, const std::function< void(int, int, int)> &partial_for)
spdlog::logger & logger()
Retrieves the current logger.
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix