OGS
SimpleMatrixVectorProvider.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <map>
7#include <memory>
8
9#include "MatrixProvider.h"
10#include "VectorProvider.h"
11
12namespace NumLib
13{
23 public VectorProvider
24{
25public:
27
28 // no copies
31 delete;
32
33 GlobalVector& getVector(std::size_t& id) override;
34
35 GlobalVector& getVector(GlobalVector const& x) override;
36 GlobalVector& getVector(GlobalVector const& x, std::size_t& id) override;
37
40 std::size_t& id) override;
41
42 void releaseVector(GlobalVector const& x) override;
43
44 GlobalMatrix& getMatrix(std::size_t& id) override;
45
47 std::size_t& id) override;
48
49 void releaseMatrix(GlobalMatrix const& A) override;
50
51 void clear();
52
54
55private:
56 template <typename... Args>
57 std::pair<GlobalMatrix*, bool> getMatrix_(std::size_t& id, Args&&... args);
58
59 template <typename... Args>
60 std::pair<GlobalVector*, bool> getVector_(std::size_t& id, Args&&... args);
61
62 // returns a pair with the pointer to the matrix/vector and
63 // a boolean indicating if a new object has been built (then true else
64 // false)
65 template <typename MatVec, typename... Args>
66 std::pair<MatVec*, bool> get_(std::size_t& id,
67 std::map<MatVec*, std::size_t>& used_map,
68 Args&&... args);
69
70 std::size_t _next_id = 1;
71
72 std::map<GlobalMatrix*, std::size_t> _used_matrices;
73
74 std::map<GlobalVector*, std::size_t> _used_vectors;
75};
76
77} // namespace NumLib
MathLib::EigenMatrix GlobalMatrix
MathLib::EigenVector GlobalVector
std::pair< GlobalVector *, bool > getVector_(std::size_t &id, Args &&... args)
void releaseVector(GlobalVector const &x) override
GlobalVector & getVector(std::size_t &id) override
Get an uninitialized vector with the given id.
std::pair< GlobalMatrix *, bool > getMatrix_(std::size_t &id, Args &&... args)
std::map< GlobalMatrix *, std::size_t > _used_matrices
SimpleMatrixVectorProvider(SimpleMatrixVectorProvider const &)=delete
SimpleMatrixVectorProvider & operator=(SimpleMatrixVectorProvider const &)=delete
std::pair< MatVec *, bool > get_(std::size_t &id, std::map< MatVec *, std::size_t > &used_map, Args &&... args)
GlobalMatrix & getMatrix(std::size_t &id) override
Get an uninitialized matrix with the given id.
std::map< GlobalVector *, std::size_t > _used_vectors
void releaseMatrix(GlobalMatrix const &A) override