OGS
ProcessLib::Assembly::MatrixElementCache< Dim > Class Template Referencefinal

Detailed Description

template<std::size_t Dim>
class ProcessLib::Assembly::MatrixElementCache< Dim >

Definition at line 121 of file MatrixElementCache.h.

#include <MatrixElementCache.h>

Collaboration diagram for ProcessLib::Assembly::MatrixElementCache< Dim >:
[legend]

Public Member Functions

 MatrixElementCache (GlobalMatView &mat_or_vec, Stats &stats)
void add (std::vector< double > const &local_data, std::vector< GlobalIndexType > const &indices)
 ~MatrixElementCache ()

Private Types

using GlobalMatView = ConcurrentMatrixView<Dim>

Private Member Functions

void addToCache (std::vector< double > const &values, std::vector< GlobalIndexType > const &indices)
void addToCacheImpl (std::vector< double > const &values, std::vector< GlobalIndexType > const &indices, std::integral_constant< std::size_t, 1 >)
void addToCacheImpl (std::vector< double > const &values, std::vector< GlobalIndexType > const &indices, std::integral_constant< std::size_t, 2 >)
void ensureEnoughSpace (std::size_t const space_needed)
void addToGlobal ()

Private Attributes

std::vector< MatrixElementCacheEntry< Dim > > cache_
GlobalMatViewmat_or_vec_
Statsstats_

Static Private Attributes

static constexpr std::size_t cache_capacity = 1'000'000

Member Typedef Documentation

◆ GlobalMatView

template<std::size_t Dim>
using ProcessLib::Assembly::MatrixElementCache< Dim >::GlobalMatView = ConcurrentMatrixView<Dim>
private

Definition at line 124 of file MatrixElementCache.h.

Constructor & Destructor Documentation

◆ MatrixElementCache()

template<std::size_t Dim>
ProcessLib::Assembly::MatrixElementCache< Dim >::MatrixElementCache ( GlobalMatView & mat_or_vec,
Stats & stats )
inline

◆ ~MatrixElementCache()

template<std::size_t Dim>
ProcessLib::Assembly::MatrixElementCache< Dim >::~MatrixElementCache ( )
inline

Definition at line 141 of file MatrixElementCache.h.

References addToGlobal().

Member Function Documentation

◆ add()

template<std::size_t Dim>
void ProcessLib::Assembly::MatrixElementCache< Dim >::add ( std::vector< double > const & local_data,
std::vector< GlobalIndexType > const & indices )
inline

Definition at line 135 of file MatrixElementCache.h.

137 {
139 }
void addToCache(std::vector< double > const &values, std::vector< GlobalIndexType > const &indices)

References addToCache().

◆ addToCache()

template<std::size_t Dim>
void ProcessLib::Assembly::MatrixElementCache< Dim >::addToCache ( std::vector< double > const & values,
std::vector< GlobalIndexType > const & indices )
inlineprivate

Definition at line 144 of file MatrixElementCache.h.

146 {
147 if (values.empty())
148 {
149 return;
150 }
151
153
156 }
void addToCacheImpl(std::vector< double > const &values, std::vector< GlobalIndexType > const &indices, std::integral_constant< std::size_t, 1 >)
void ensureEnoughSpace(std::size_t const space_needed)

References addToCacheImpl(), and ensureEnoughSpace().

Referenced by add().

◆ addToCacheImpl() [1/2]

template<std::size_t Dim>
void ProcessLib::Assembly::MatrixElementCache< Dim >::addToCacheImpl ( std::vector< double > const & values,
std::vector< GlobalIndexType > const & indices,
std::integral_constant< std::size_t, 1 >  )
inlineprivate

Definition at line 159 of file MatrixElementCache.h.

162 {
163 auto const num_r_c = indices.size();
164
166 {
167 ++stats_.count;
168 auto const value = values[r_local];
169
170 if (value == 0)
171 {
172 continue;
173 }
174 else
175 {
176 ++stats_.count_nonzero;
177 }
178
179 auto const r_global = indices[r_local];
180 cache_.emplace_back(std::array{r_global}, value);
181 }
182 }

References cache_, and stats_.

Referenced by addToCache().

◆ addToCacheImpl() [2/2]

template<std::size_t Dim>
void ProcessLib::Assembly::MatrixElementCache< Dim >::addToCacheImpl ( std::vector< double > const & values,
std::vector< GlobalIndexType > const & indices,
std::integral_constant< std::size_t, 2 >  )
inlineprivate

Definition at line 185 of file MatrixElementCache.h.

188 {
189 auto const num_r_c = indices.size();
190
191 // Note: There is an implicit storage order assumption, here!
193
195 {
196 auto const r_global = indices[r_local];
197
199 {
200 ++stats_.count;
201 auto const value = local_mat(r_local, c_local);
202
203 // TODO skipping zero values sometimes does not work together
204 // with the Eigen SparseLU linear solver. See also
205 // https://gitlab.opengeosys.org/ogs/ogs/-/merge_requests/4556#note_125561
206#if 0
207 if (value == 0)
208 {
209 continue;
210 }
211#endif
212 ++stats_.count_nonzero;
213
214 auto const c_global = indices[c_local];
215 cache_.emplace_back(std::array{r_global, c_global}, value);
216 }
217 }
218 }
Eigen::Map< const Matrix > toMatrix(std::vector< double > const &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)

References cache_, stats_, and MathLib::toMatrix().

◆ addToGlobal()

template<std::size_t Dim>
void ProcessLib::Assembly::MatrixElementCache< Dim >::addToGlobal ( )
inlineprivate

Definition at line 243 of file MatrixElementCache.h.

244 {
245 mat_or_vec_.add(cache_);
246 stats_.count_global += cache_.size();
247 cache_.clear();
248 }

References cache_, mat_or_vec_, and stats_.

Referenced by ~MatrixElementCache(), and ensureEnoughSpace().

◆ ensureEnoughSpace()

template<std::size_t Dim>
void ProcessLib::Assembly::MatrixElementCache< Dim >::ensureEnoughSpace ( std::size_t const space_needed)
inlineprivate

Definition at line 220 of file MatrixElementCache.h.

221 {
222 auto const size_initial = cache_.size();
223 auto const cap_initial = cache_.capacity();
224
226 {
227 return;
228 }
229
230 addToGlobal();
231
232 // ensure again that there is enough capacity (corner case, if initial
233 // capacity is too small because of whatever arcane reason)
234 auto const size_after = cache_.size();
235 auto const cap_after = cache_.capacity();
236
238 {
239 cache_.reserve(size_after + 2 * space_needed);
240 }
241 }

References addToGlobal(), and cache_.

Referenced by addToCache().

Member Data Documentation

◆ cache_

template<std::size_t Dim>
std::vector<MatrixElementCacheEntry<Dim> > ProcessLib::Assembly::MatrixElementCache< Dim >::cache_
private

◆ cache_capacity

template<std::size_t Dim>
std::size_t ProcessLib::Assembly::MatrixElementCache< Dim >::cache_capacity = 1'000'000
staticconstexprprivate

Definition at line 126 of file MatrixElementCache.h.

Referenced by MatrixElementCache().

◆ mat_or_vec_

template<std::size_t Dim>
GlobalMatView& ProcessLib::Assembly::MatrixElementCache< Dim >::mat_or_vec_
private

Definition at line 251 of file MatrixElementCache.h.

Referenced by MatrixElementCache(), and addToGlobal().

◆ stats_

template<std::size_t Dim>
Stats& ProcessLib::Assembly::MatrixElementCache< Dim >::stats_
private

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