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()

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 {
138 addToCache(local_data, indices);
139 }
void addToCache(std::vector< double > const &values, std::vector< GlobalIndexType > const &indices)

References ProcessLib::Assembly::MatrixElementCache< Dim >::addToCache().

Referenced by ProcessLib::Assembly::MultiMatrixElementCache::add().

◆ 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
152 ensureEnoughSpace(values.size());
153
154 addToCacheImpl(values, indices,
155 std::integral_constant<std::size_t, Dim>{});
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 ProcessLib::Assembly::MatrixElementCache< Dim >::addToCacheImpl(), and ProcessLib::Assembly::MatrixElementCache< Dim >::ensureEnoughSpace().

Referenced by ProcessLib::Assembly::MatrixElementCache< Dim >::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
165 for (std::size_t r_local = 0; r_local < num_r_c; ++r_local)
166 {
167 ++stats_.count;
168 auto const value = values[r_local];
169
170 if (value == 0)
171 {
172 continue;
173 }
174 else
175 {
177 }
178
179 auto const r_global = indices[r_local];
180 cache_.emplace_back(std::array{r_global}, value);
181 }
182 }

References ProcessLib::Assembly::MatrixElementCache< Dim >::cache_, ProcessLib::Assembly::Stats::count, ProcessLib::Assembly::Stats::count_nonzero, and ProcessLib::Assembly::MatrixElementCache< Dim >::stats_.

Referenced by ProcessLib::Assembly::MatrixElementCache< Dim >::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!
192 auto const local_mat = MathLib::toMatrix(values, num_r_c, num_r_c);
193
194 for (std::size_t r_local = 0; r_local < num_r_c; ++r_local)
195 {
196 auto const r_global = indices[r_local];
197
198 for (std::size_t c_local = 0; c_local < num_r_c; ++c_local)
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
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 ProcessLib::Assembly::MatrixElementCache< Dim >::cache_, ProcessLib::Assembly::Stats::count, ProcessLib::Assembly::Stats::count_nonzero, ProcessLib::Assembly::MatrixElementCache< Dim >::stats_, and MathLib::toMatrix().

◆ addToGlobal()

◆ 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
225 if (size_initial + space_needed <= cap_initial)
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
237 if (size_after + space_needed > cap_after)
238 {
239 cache_.reserve(size_after + 2 * space_needed);
240 }
241 }

References ProcessLib::Assembly::MatrixElementCache< Dim >::addToGlobal(), and ProcessLib::Assembly::MatrixElementCache< Dim >::cache_.

Referenced by ProcessLib::Assembly::MatrixElementCache< Dim >::addToCache().

Member Data Documentation

◆ cache_

◆ cache_capacity

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

◆ mat_or_vec_

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

◆ stats_


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