openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
SF_init.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #ifndef _SF_INIT_H_
5 #define _SF_INIT_H_
6 
7 // Without these, the functions below throw that the backend is not enabled, but only where the
8 // compiler inlines them, as the linker can otherwise pick the copy of another file.
9 #if !defined(WITH_PETSC) && !defined(WITH_GINKGO)
10 #error "SF_init.h needs the backends of the build: define WITH_PETSC or WITH_GINKGO"
11 #endif
12 
13 #include <initializer_list>
14 #include <utility>
15 
16 #include "SF_abstract_vector.h"
17 #include "SF_abstract_matrix.h"
18 #include "SF_abstract_lin_solver.h"
19 
20 #include "SF_ginkgo_vector.h"
21 #include "SF_ginkgo_matrix.h"
22 #include "SF_ginkgo_solver.h"
23 
24 #include "backend.h"
25 
26 namespace SF {
27 
28 #ifdef WITH_PETSC
29 // Implemented by the PETSc backend. Only its own sources include its headers.
30 void init_vector_petsc(abstract_vector<SF_int,SF_real>** vec);
31 void init_matrix_petsc(abstract_matrix<SF_int,SF_real>** mat);
32 void init_solver_petsc(abstract_linear_solver<SF_int,SF_real>** sol);
34 void petsc_log_preallocation_report(std::initializer_list<std::pair<const char*, abstract_matrix<SF_int,SF_real>*>> matrices);
35 #endif
36 
37 namespace detail {
38 
39  template <typename T>
40  struct non_deduced {
41  using type = T;
42  };
43 
44  template <typename T>
46 
48  template <typename T, typename S>
50  {
51 #ifndef WITH_GINKGO
52  throw std::runtime_error("The Ginkgo backend was not enabled");
53 #else
54  init_vector_ginkgo(object);
55 #endif
56  }
57 
59  template <typename T, typename S>
61  {
62 #ifndef WITH_GINKGO
63  throw std::runtime_error("The Ginkgo backend was not enabled");
64 #else
65  init_matrix_ginkgo(object);
66 #endif
67  }
68 
70  template <typename T, typename S>
72  {
73 #ifndef WITH_GINKGO
74  throw std::runtime_error("The Ginkgo backend was not enabled");
75 #else
76  init_solver_ginkgo(object);
77 #endif
78  }
79 
82  {
83 #ifndef WITH_PETSC
84  throw std::runtime_error("The PETSc backend was not enabled");
85 #else
86  init_vector_petsc(object);
87 #endif
88  }
89 
91  template <typename T, typename S>
93  {
94 #ifndef WITH_PETSC
95  throw std::runtime_error("The PETSc backend was not enabled");
96 #else
97  init_matrix_petsc(object);
98 #endif
99  }
100 
102  template <typename T, typename S>
104  {
105 #ifndef WITH_PETSC
106  throw std::runtime_error("The PETSc backend was not enabled");
107 #else
108  init_solver_petsc(object);
109 #endif
110  }
111 
112 } // namespace detail
113 
114 
126 template <class T, class S>
128 {
131  } else {
133  }
134 }
135 
151 template <class T, class S>
154  detail::non_deduced_t<T> ilsize, int idpn = 1,
156 {
159  } else {
161  }
162  (*vec)->init(igsize, ilsize, idpn, ilayout);
163 }
164 
179 template <class T, class S>
182  int i, typename SF::abstract_vector<T, S>::ltype ltype)
183 {
186  } else {
188  }
189  (*vec)->init(mesh, i, ltype);
190 }
191 
204 template <class T, class S>
207 {
210  } else {
212  }
213  (*vec)->init(*in);
214 }
215 
227 template <class T, class S>
229 {
232  } else {
234  }
235 }
236 
248 template <class T, class S>
250 {
253  } else {
255  }
256 }
257 
258 
259 } // namespace SF
260 
261 #endif // _SF_INIT_H_
Starts and stops the linear algebra backend the flavor parameter selects.
void init_or_throw_petsc(SF::abstract_vector< SF_int, SF_real > **object)
Definition: SF_init.h:81
typename non_deduced< T >::type non_deduced_t
Definition: SF_init.h:45
void init_or_throw_ginkgo(SF::abstract_vector< T, S > **object)
Definition: SF_init.h:49
Definition: dense_mat.hpp:19
void init_solver(SF::abstract_linear_solver< T, S > **sol)
Definition: SF_init.h:249
void init_vector(SF::abstract_vector< T, S > **vec)
Definition: SF_init.h:127
void init_matrix(SF::abstract_matrix< T, S > **mat)
Definition: SF_init.h:228
bool ginkgo_selected()
Definition: backend.cc:44