Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_MUMPS_TypeMap.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Amesos2: Templated Direct Sparse Solver Package
4 //
5 // Copyright 2011 NTESS and the Amesos2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
19 #ifndef AMESOS2_MUMPS_TYPEMAP_HPP
20 #define AMESOS2_MUMPS_TYPEMAP_HPP
21 
22 //#include <functional>
23 #ifdef HAVE_TEUCHOS_COMPLEX
24 #include <complex>
25 #endif
26 
27 #include <Teuchos_as.hpp>
28 #ifdef HAVE_TEUCHOS_COMPLEX
29 #include <Teuchos_SerializationTraits.hpp>
30 #endif
31 
32 #include "Amesos2_TypeMap.hpp"
33 
34 namespace Amesos2
35 {
36  namespace MUMPST
37  {
38  extern "C"
39  {
40  #include "smumps_c.h"
41  #include "dmumps_c.h"
42  #ifdef HAVE_TEUCHOS_COMPLEX
43  #include "cmumps_c.h"
44  #include "zmumps_c.h"
45  #endif
46  }
47  }
48 }
49 
50 
51 namespace Amesos2 {
52 
53 template <class, class> class MUMPS;
54 
55 /* Specialize the Amesos2::TypeMap struct for Mumps types
56  * TODO: Mostly dummy assignments as MUMPS is templated. Remove if possible.
57  *
58  * \cond Mumps_type_specializations
59  */
60 
61 
62  template <>
63  struct TypeMap<MUMPS,float>
64  {
65  typedef float type;
66  typedef float magnitude_type;
67  typedef MUMPST::SMUMPS_STRUC_C MUMPS_STRUC_C;
68  };
69 
70 
71  template <>
72  struct TypeMap<MUMPS,double>
73  {
74  typedef double type;
75  typedef double magnitude_type;
76  typedef MUMPST::DMUMPS_STRUC_C MUMPS_STRUC_C;
77  };
78 
79 #ifdef HAVE_TEUCHOS_COMPLEX
80 
81  template <>
82  struct TypeMap<MUMPS,std::complex<float> >
83  {
84  typedef MUMPST::CMUMPS_COMPLEX type;
85  typedef float magnitude_type;
86  typedef MUMPST::CMUMPS_STRUC_C MUMPS_STRUC_C;
87  };
88 
89  template <>
90  struct TypeMap<MUMPS,std::complex<double> >
91  {
92  typedef MUMPST::ZMUMPS_COMPLEX type;
93  typedef double magnitude_type;
94  typedef MUMPST::ZMUMPS_STRUC_C MUMPS_STRUC_C;
95  };
96 
97  template <>
98  struct TypeMap<MUMPS, MUMPST::CMUMPS_COMPLEX>
99  {
100  typedef MUMPST::CMUMPS_COMPLEX type;
101  typedef float magnitude_type;
102  typedef MUMPST::CMUMPS_STRUC_C MUMPS_STRUC_C;
103  };
104 
105  template <>
106  struct TypeMap<MUMPS, MUMPST::ZMUMPS_COMPLEX>
107  {
108  typedef MUMPST::ZMUMPS_COMPLEX type;
109  typedef double magnitude_type;
110  typedef MUMPST::ZMUMPS_STRUC_C MUMPS_STRUC_C;
111  };
112 
113 #endif // HAVE_TEUCHOS_COMPLEX
114 
115 /* \endcond MUMPS_type_specializations */
116 
117 } // end namespace Amesos2
118 
119 
120 #ifdef HAVE_TEUCHOS_COMPLEX
121 
122 /* ==================== Conversion ==================== */
123 namespace Teuchos {
124 
137  template <typename TypeFrom> //float based complex
138  class ValueTypeConversionTraits<Amesos2::MUMPST::CMUMPS_COMPLEX, TypeFrom >
139  {
140  public:
141  static Amesos2::MUMPST::CMUMPS_COMPLEX convert( const TypeFrom t )
142  {
143  Amesos2::MUMPST::CMUMPS_COMPLEX ret;
144  ret.r = Teuchos::as<float>(t.real());
145  ret.i = Teuchos::as<float>(t.imag());
146  return( ret );
147  }
148 
149  static Amesos2::MUMPST::CMUMPS_COMPLEX safeConvert( const TypeFrom t )
150  {
151  Amesos2::MUMPST::CMUMPS_COMPLEX ret;
152  ret.r = Teuchos::as<float>(t.real());
153  ret.i = Teuchos::as<float>(t.imag());
154  return( ret );
155  }
156  };
157 
158 
159 
160  template <typename TypeFrom> //double based
161  class ValueTypeConversionTraits<Amesos2::MUMPST::ZMUMPS_COMPLEX , TypeFrom >
162  {
163  public:
164  static Amesos2::MUMPST::ZMUMPS_COMPLEX convert( const TypeFrom t )
165  {
166  Amesos2::MUMPST::ZMUMPS_COMPLEX ret;
167  ret.r = Teuchos::as<double>( t.real() );
168  ret.i = Teuchos::as<double>( t.imag() );
169  return (ret);
170  }
171 
172  // No special checks for safe Convert
173  static Amesos2::MUMPST::ZMUMPS_COMPLEX safeConvert( const TypeFrom t )
174  {
175  Amesos2::MUMPST::ZMUMPS_COMPLEX ret;
176  ret.r = Teuchos::as<double>( t.real() );
177  ret.i = Teuchos::as<double>( t.imag() );
178  return (ret);
179  }
180  };
181 
182  template <typename TypeTo>
183  class ValueTypeConversionTraits<TypeTo, Amesos2::MUMPST::CMUMPS_COMPLEX>
184  {
185  public:
186  static TypeTo convert(const Amesos2::MUMPST::CMUMPS_COMPLEX t)
187  {
188  typedef typename TypeTo::value_type value_type;
189  value_type ret_r = Teuchos::as<value_type>(t.r);
190  value_type ret_i = Teuchos::as<value_type>(t.i);
191  return (TypeTo(ret_r, ret_i));
192  }
193  //No special checks for safe convert
194  static TypeTo safeConvert(const Amesos2::MUMPST::CMUMPS_COMPLEX t)
195  {
196  typedef typename TypeTo::value_type value_type;
197  value_type ret_r = Teuchos::as<value_type>(t.r);
198  value_type ret_i = Teuchos::as<value_type>(t.i);
199  return (TypeTo(ret_r, ret_i));
200  }
201 
202  };
203 
204  template <typename TypeTo>
205  class ValueTypeConversionTraits<TypeTo, Amesos2::MUMPST::ZMUMPS_COMPLEX>
206  {
207  public:
208  static TypeTo convert(const Amesos2::MUMPST::ZMUMPS_COMPLEX t)
209  {
210  typedef typename TypeTo::value_type value_type;
211  value_type ret_r = Teuchos::as<value_type>(t.r);
212  value_type ret_i = Teuchos::as<value_type>(t.i);
213  return (TypeTo(ret_r, ret_i));
214  }
215  //No special checks for safe convert
216  static TypeTo safeConvert(const Amesos2::MUMPST::ZMUMPS_COMPLEX t)
217  {
218  typedef typename TypeTo::value_type value_type;
219  value_type ret_r = Teuchos::as<value_type>(t.r);
220  value_type ret_i = Teuchos::as<value_type>(t.i);
221  return (TypeTo(ret_r, ret_i));
222  }
223 
224  };
225 
226 
227 //#endif
229 
230 
231 } // end namespace Teuchos
232 
233 #endif // HAVE_TEUCHOS_COMPLEX
234 
235 
236 
237 #endif // AMESOS2_MUMPS_TYPEMAP_HPP