schwz  Generated automatically from develop
initialization.hpp (200bbde)
1 
2 /*******************************<SCHWARZ LIB LICENSE>***********************
3 Copyright (c) 2019, the SCHWARZ LIB authors
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its
18 contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ******************************<SCHWARZ LIB LICENSE>*************************/
33 
34 #ifndef initialization_hpp
35 #define initialization_hpp
36 
37 
38 #include <cmath>
39 #include <functional>
40 #include <memory>
41 #include <random>
42 #include <vector>
43 
44 
45 #include <schwarz/config.hpp>
46 
47 
48 #if SCHW_HAVE_DEALII
49 #include <deal.II/lac/sparse_matrix.h>
50 #endif
51 
52 
53 #include <partition_tools.hpp>
54 #include <settings.hpp>
55 
56 
57 namespace schwz {
58 
59 
70 template <typename ValueType = gko::default_precision,
71  typename IndexType = gko::int32>
72 class Initialize : public Settings, public Metadata<ValueType, IndexType> {
73 public:
75 
80  std::vector<unsigned int> partition_indices;
81 
85  std::vector<unsigned int> cell_weights;
86 
92  void generate_rhs(std::vector<ValueType> &rhs);
93 
100 #if SCHW_HAVE_DEALII
101  void setup_global_matrix(
102  const std::string &filename, const gko::size_type &oned_laplacian_size,
103  const dealii::SparseMatrix<ValueType> &matrix,
104  std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>> &global_matrix);
105 #else
106  void setup_global_matrix(
107  const std::string &filename, const gko::size_type &oned_laplacian_size,
108  std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>> &global_matrix);
109 #endif
110 
120  void partition(const Settings &settings,
121  const Metadata<ValueType, IndexType> &metadata,
122  const std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
123  &global_matrix,
124  std::vector<unsigned int> &partition_indices);
125 
136  void setup_vectors(
137  const Settings &settings,
138  const Metadata<ValueType, IndexType> &metadata,
139  std::vector<ValueType> &rhs,
140  std::shared_ptr<gko::matrix::Dense<ValueType>> &local_rhs,
141  std::shared_ptr<gko::matrix::Dense<ValueType>> &global_rhs,
142  std::shared_ptr<gko::matrix::Dense<ValueType>> &local_solution);
143 
158  virtual void setup_local_matrices(
159  Settings &settings, Metadata<ValueType, IndexType> &metadata,
160  std::vector<unsigned int> &partition_indices,
161  std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>> &global_matrix,
162  std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>> &local_matrix,
163  std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
164  &interface_matrix) = 0;
165 
166 private:
167  Settings &settings;
168 
170 };
171 
172 } // namespace schwz
173 
174 #endif // initialization.hpp
void setup_vectors(const Settings &settings, const Metadata< ValueType, IndexType > &metadata, std::vector< ValueType > &rhs, std::shared_ptr< gko::matrix::Dense< ValueType >> &local_rhs, std::shared_ptr< gko::matrix::Dense< ValueType >> &global_rhs, std::shared_ptr< gko::matrix::Dense< ValueType >> &local_solution)
Setup the vectors with default values and allocate mameory if not allocated.
Definition: initialization.cpp:333
gko::size_type oned_laplacian_size
The size of the 1 dimensional laplacian grid.
Definition: settings.hpp:333
The solver metadata struct.
Definition: settings.hpp:319
virtual void setup_local_matrices(Settings &settings, Metadata< ValueType, IndexType > &metadata, std::vector< unsigned int > &partition_indices, std::shared_ptr< gko::matrix::Csr< ValueType, IndexType >> &global_matrix, std::shared_ptr< gko::matrix::Csr< ValueType, IndexType >> &local_matrix, std::shared_ptr< gko::matrix::Csr< ValueType, IndexType >> &interface_matrix)=0
Sets up the local and the interface matrices from the global matrix and the partition indices...
Definition: initialization.cpp:79
void partition(const Settings &settings, const Metadata< ValueType, IndexType > &metadata, const std::shared_ptr< gko::matrix::Csr< ValueType, IndexType >> &global_matrix, std::vector< unsigned int > &partition_indices)
The partitioning function.
Definition: initialization.cpp:279
The struct that contains the solver settings and the parameters to be set by the user.
Definition: settings.hpp:77
std::vector< unsigned int > cell_weights
The cell weights for the partition algorithm.
Definition: initialization.hpp:85
The Schwarz wrappers namespace.
Definition: comm_helpers.hpp:49
The initialization class that provides methods for initialization of the solver.
Definition: initialization.hpp:72
std::vector< unsigned int > partition_indices
The partition indices containing the subdomains to which each row(vertex) of the matrix(graph) belong...
Definition: initialization.hpp:80
void generate_rhs(std::vector< ValueType > &rhs)
Generates the right hand side vector.
Definition: initialization.cpp:89
void setup_global_matrix(const std::string &filename, const gko::size_type &oned_laplacian_size, std::shared_ptr< gko::matrix::Csr< ValueType, IndexType >> &global_matrix)
Generates the 2D global laplacian matrix.
Definition: initialization.cpp:197