45template <std::
size_t Dim>
66template <std::
size_t Dim>
69 static_assert(Dim == 1 || Dim == 2);
71 std::conditional_t<Dim == 1, GlobalVector, GlobalMatrix>;
83 if constexpr (Dim == 2)
85 auto const n_cols =
mat_or_vec_.getNumberOfColumns();
91 for (
auto const [rc, value] : entries)
93 auto const [r, c] = rc;
95 auto const c_no_ghost =
105 for (
auto const [r, value] : entries)
120template <std::
size_t Dim>
123 static_assert(Dim == 1 || Dim == 2);
135 void add(std::vector<double>
const& local_data,
136 std::vector<GlobalIndexType>
const& indices)
145 std::vector<GlobalIndexType>
const& indices)
155 std::integral_constant<std::size_t, Dim>{});
160 std::vector<GlobalIndexType>
const& indices,
161 std::integral_constant<std::size_t, 1>)
163 auto const num_r_c = indices.size();
165 for (std::size_t r_local = 0; r_local < num_r_c; ++r_local)
168 auto const value = values[r_local];
179 auto const r_global = indices[r_local];
180 cache_.emplace_back(std::array{r_global}, value);
186 std::vector<GlobalIndexType>
const& indices,
187 std::integral_constant<std::size_t, 2>)
189 auto const num_r_c = indices.size();
194 for (std::size_t r_local = 0; r_local < num_r_c; ++r_local)
196 auto const r_global = indices[r_local];
198 for (std::size_t c_local = 0; c_local < num_r_c; ++c_local)
201 auto const value = local_mat(r_local, c_local);
214 auto const c_global = indices[c_local];
215 cache_.emplace_back(std::array{r_global, c_global}, value);
222 auto const size_initial =
cache_.size();
223 auto const cap_initial =
cache_.capacity();
225 if (size_initial + space_needed <= cap_initial)
234 auto const size_after =
cache_.size();
235 auto const cap_after =
cache_.capacity();
237 if (size_after + space_needed > cap_after)
239 cache_.reserve(size_after + 2 * space_needed);
250 std::vector<MatrixElementCacheEntry<Dim>>
cache_;
267 void add(std::vector<double>
const& local_b_data,
268 std::vector<double>
const& local_Jac_data,
269 std::vector<GlobalIndexType>
const& indices)
GlobalMatrix::IndexType GlobalIndexType
Global vector based on Eigen vector.
std::conditional_t< Dim==1, GlobalVector, GlobalMatrix > GlobalMatOrVec
GlobalMatOrVec & mat_or_vec_
ConcurrentMatrixView(GlobalMatOrVec &mat_or_vec)
void add(std::vector< MatrixElementCacheEntry< Dim > > const &entries)
void addToCacheImpl(std::vector< double > const &values, std::vector< GlobalIndexType > const &indices, std::integral_constant< std::size_t, 2 >)
static constexpr std::size_t cache_capacity
void addToCacheImpl(std::vector< double > const &values, std::vector< GlobalIndexType > const &indices, std::integral_constant< std::size_t, 1 >)
void addToCache(std::vector< double > const &values, std::vector< GlobalIndexType > const &indices)
void add(std::vector< double > const &local_data, std::vector< GlobalIndexType > const &indices)
MatrixElementCache(GlobalMatView &mat_or_vec, Stats &stats)
std::vector< MatrixElementCacheEntry< Dim > > cache_
void ensureEnoughSpace(std::size_t const space_needed)
GlobalMatView & mat_or_vec_
MultiMatrixElementCache(GlobalVectorView &b, GlobalMatrixView &Jac, MultiStats &stats)
MatrixElementCache< 2 > cache_Jac_
void add(std::vector< double > const &local_b_data, std::vector< double > const &local_Jac_data, std::vector< GlobalIndexType > const &indices)
MatrixElementCache< 1 > cache_b_
Eigen::Map< const Matrix > toMatrix(std::vector< double > const &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
GlobalIndexType transformToNonGhostIndex(GlobalIndexType const i, GlobalIndexType const n)
ConcurrentMatrixView(GlobalVector &) -> ConcurrentMatrixView< 1 >
MatrixElementCacheEntry & operator=(MatrixElementCacheEntry const &)=default
MatrixElementCacheEntry(MatrixElementCacheEntry &&)=default
std::array< GlobalIndexType, Dim > indices
MatrixElementCacheEntry()=default
MatrixElementCacheEntry & operator=(MatrixElementCacheEntry &&)=default
MatrixElementCacheEntry(std::array< GlobalIndexType, Dim > const &indices, double value)
MatrixElementCacheEntry(MatrixElementCacheEntry const &)=default
std::size_t count_nonzero