91struct RelaxationRuntime
94 typedef typename Backend::params backend_params;
96 template <
class Matrix>
97 explicit RelaxationRuntime(
const Matrix& A, params prm = params(),
98 const backend_params& bprm = backend_params())
99 : m_relaxation_type(prm.get(
"type", eRelaxationType::spai0))
101 if (!prm.erase(
"type"))
102 ARCCORE_ALINA_PARAM_MISSING(
"type");
103 switch (m_relaxation_type) {
105#define ARCCORE_ALINA_RUNTIME_RELAXATION(type) \
106 case eRelaxationType::type: \
107 m_relaxation = call_constructor<type>(A, prm, bprm); \
110 ARCCORE_ALINA_ALL_RUNTIME_RELAXATION();
112#undef ARCCORE_ALINA_RUNTIME_RELAXATION
124 template <
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
125 void apply_pre(
const Matrix& A,
const VectorRHS& rhs, VectorX& x, VectorTMP& tmp)
const
127 switch (m_relaxation_type) {
129#define ARCCORE_ALINA_RUNTIME_RELAXATION(type) \
130 case eRelaxationType::type: \
131 call_apply_pre<type>(A, rhs, x, tmp); \
134 ARCCORE_ALINA_ALL_RUNTIME_RELAXATION();
136#undef ARCCORE_ALINA_RUNTIME_RELAXATION
143 template <
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
144 void apply_post(
const Matrix& A,
const VectorRHS& rhs, VectorX& x, VectorTMP& tmp)
const
146 switch (m_relaxation_type) {
148#define ARCCORE_ALINA_RUNTIME_RELAXATION(type) \
149 case eRelaxationType::type: \
150 call_apply_post<type>(A, rhs, x, tmp); \
153 ARCCORE_ALINA_ALL_RUNTIME_RELAXATION();
155#undef ARCCORE_ALINA_RUNTIME_RELAXATION
162 template <
class Matrix,
class VectorRHS,
class VectorX>
163 void apply(
const Matrix& A,
const VectorRHS& rhs, VectorX& x)
const
165 switch (m_relaxation_type) {
167#define ARCCORE_ALINA_RUNTIME_RELAXATION(type) \
168 case eRelaxationType::type: \
169 call_apply<type>(A, rhs, x); \
172 ARCCORE_ALINA_ALL_RUNTIME_RELAXATION();
174#undef ARCCORE_ALINA_RUNTIME_RELAXATION
183 return m_relaxation->bytes();
186 template <
template <
class>
class Relaxation,
class Matrix>
187 typename std::enable_if_t<backend::relaxation_is_supported<Backend, Relaxation>::value,
RelaxationBase*>
188 call_constructor(
const Matrix& A,
const params& prm,
const backend_params& bprm)
190 return new Relaxation<Backend>(A, prm, bprm);
193 template <
template <
class>
class Relaxation,
class Matrix>
194 typename std::enable_if_t<!backend::relaxation_is_supported<Backend, Relaxation>::value,
RelaxationBase*>
195 call_constructor(
const Matrix&,
const params&,
const backend_params&)
197 _throwUnsupportedBackendType();
200 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
201 typename std::enable_if<backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
202 call_apply_pre(
const Matrix& A,
const VectorRHS& rhs, VectorX& x, VectorTMP& tmp)
const
204 static_cast<Relaxation<Backend>*
>(m_relaxation)->apply_pre(A, rhs, x, tmp);
207 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
208 typename std::enable_if<!backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
209 call_apply_pre(
const Matrix&,
const VectorRHS&, VectorX&, VectorTMP&)
const
211 _throwUnsupportedBackendType();
214 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
215 typename std::enable_if<backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
216 call_apply_post(
const Matrix& A,
const VectorRHS& rhs, VectorX& x, VectorTMP& tmp)
const
218 static_cast<Relaxation<Backend>*
>(m_relaxation)->apply_post(A, rhs, x, tmp);
221 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
222 typename std::enable_if<!backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
223 call_apply_post(
const Matrix&,
const VectorRHS&, VectorX&, VectorTMP&)
const
225 _throwUnsupportedBackendType();
228 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX>
229 typename std::enable_if<backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
230 call_apply(
const Matrix& A,
const VectorRHS& rhs, VectorX& x)
const
232 static_cast<Relaxation<Backend>*
>(m_relaxation)->apply(A, rhs, x);
235 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX>
236 typename std::enable_if<!backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
237 call_apply(
const Matrix&,
const VectorRHS&, VectorX&)
const
239 _throwUnsupportedBackendType();
242 void _throwBadTypeType [[noreturn]] ()
const
244 int v =
static_cast<int>(m_relaxation_type);
247 void _throwUnsupportedBackendType [[noreturn]] ()
const
249 String err_message = String::format(
"The relaxation '{0}' is not supported by the backend", m_relaxation_type);
251 throw std::logic_error(err_message.
localstr());
256 eRelaxationType m_relaxation_type = eRelaxationType::SPAI0Relaxation;