Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_MUMPS_TypeMap.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Amesos2: Templated Direct Sparse Solver Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
53 #ifndef AMESOS2_MUMPS_TYPEMAP_HPP
54 #define AMESOS2_MUMPS_TYPEMAP_HPP
55 
56 //#include <functional>
57 #ifdef HAVE_TEUCHOS_COMPLEX
58 #include <complex>
59 #endif
60 
61 #include <Teuchos_as.hpp>
62 #ifdef HAVE_TEUCHOS_COMPLEX
63 #include <Teuchos_SerializationTraits.hpp>
64 #endif
65 
66 #include "Amesos2_TypeMap.hpp"
67 
68 namespace Amesos2
69 {
70  namespace MUMPST
71  {
72  extern "C"
73  {
74  #include "smumps_c.h"
75  #include "dmumps_c.h"
76  #ifdef HAVE_TEUCHOS_COMPLEX
77  #include "cmumps_c.h"
78  #include "zmumps_c.h"
79  #endif
80  }
81  }
82 }
83 
84 
85 namespace Amesos2 {
86 
87 template <class, class> class MUMPS;
88 
89 /* Specialize the Amesos2::TypeMap struct for Mumps types
90  * TODO: Mostly dummy assignments as MUMPS is templated. Remove if possible.
91  *
92  * \cond Mumps_type_specializations
93  */
94 
95 
96  template <>
97  struct TypeMap<MUMPS,float>
98  {
99  typedef float type;
100  typedef float magnitude_type;
101  typedef MUMPST::SMUMPS_STRUC_C MUMPS_STRUC_C;
102  };
103 
104 
105  template <>
106  struct TypeMap<MUMPS,double>
107  {
108  typedef double type;
109  typedef double magnitude_type;
110  typedef MUMPST::DMUMPS_STRUC_C MUMPS_STRUC_C;
111  };
112 
113 #ifdef HAVE_TEUCHOS_COMPLEX
114 
115  template <>
116  struct TypeMap<MUMPS,std::complex<float> >
117  {
118  typedef MUMPST::CMUMPS_COMPLEX type;
119  typedef float magnitude_type;
120  typedef MUMPST::CMUMPS_STRUC_C MUMPS_STRUC_C;
121  };
122 
123  template <>
124  struct TypeMap<MUMPS,std::complex<double> >
125  {
126  typedef MUMPST::ZMUMPS_COMPLEX type;
127  typedef double magnitude_type;
128  typedef MUMPST::ZMUMPS_STRUC_C MUMPS_STRUC_C;
129  };
130 
131  template <>
132  struct TypeMap<MUMPS, MUMPST::CMUMPS_COMPLEX>
133  {
134  typedef MUMPST::CMUMPS_COMPLEX type;
135  typedef float magnitude_type;
136  typedef MUMPST::CMUMPS_STRUC_C MUMPS_STRUC_C;
137  };
138 
139  template <>
140  struct TypeMap<MUMPS, MUMPST::ZMUMPS_COMPLEX>
141  {
142  typedef MUMPST::ZMUMPS_COMPLEX type;
143  typedef double magnitude_type;
144  typedef MUMPST::ZMUMPS_STRUC_C MUMPS_STRUC_C;
145  };
146 
147 #endif // HAVE_TEUCHOS_COMPLEX
148 
149 /* \endcond MUMPS_type_specializations */
150 
151 } // end namespace Amesos2
152 
153 
154 #ifdef HAVE_TEUCHOS_COMPLEX
155 
156 /* ==================== Conversion ==================== */
157 namespace Teuchos {
158 
171  template <typename TypeFrom> //float based complex
172  class ValueTypeConversionTraits<Amesos2::MUMPST::CMUMPS_COMPLEX, TypeFrom >
173  {
174  public:
175  static Amesos2::MUMPST::CMUMPS_COMPLEX convert( const TypeFrom t )
176  {
177  Amesos2::MUMPST::CMUMPS_COMPLEX ret;
178  ret.r = Teuchos::as<float>(t.real());
179  ret.i = Teuchos::as<float>(t.imag());
180  return( ret );
181  }
182 
183  static Amesos2::MUMPST::CMUMPS_COMPLEX safeConvert( const TypeFrom t )
184  {
185  Amesos2::MUMPST::CMUMPS_COMPLEX ret;
186  ret.r = Teuchos::as<float>(t.real());
187  ret.i = Teuchos::as<float>(t.imag());
188  return( ret );
189  }
190  };
191 
192 
193 
194  template <typename TypeFrom> //double based
195  class ValueTypeConversionTraits<Amesos2::MUMPST::ZMUMPS_COMPLEX , TypeFrom >
196  {
197  public:
198  static Amesos2::MUMPST::ZMUMPS_COMPLEX convert( const TypeFrom t )
199  {
200  Amesos2::MUMPST::ZMUMPS_COMPLEX ret;
201  ret.r = Teuchos::as<double>( t.real() );
202  ret.i = Teuchos::as<double>( t.imag() );
203  return (ret);
204  }
205 
206  // No special checks for safe Convert
207  static Amesos2::MUMPST::ZMUMPS_COMPLEX safeConvert( const TypeFrom t )
208  {
209  Amesos2::MUMPST::ZMUMPS_COMPLEX ret;
210  ret.r = Teuchos::as<double>( t.real() );
211  ret.i = Teuchos::as<double>( t.imag() );
212  return (ret);
213  }
214  };
215 
216  template <typename TypeTo>
217  class ValueTypeConversionTraits<TypeTo, Amesos2::MUMPST::CMUMPS_COMPLEX>
218  {
219  public:
220  static TypeTo convert(const Amesos2::MUMPST::CMUMPS_COMPLEX t)
221  {
222  typedef typename TypeTo::value_type value_type;
223  value_type ret_r = Teuchos::as<value_type>(t.r);
224  value_type ret_i = Teuchos::as<value_type>(t.i);
225  return (TypeTo(ret_r, ret_i));
226  }
227  //No special checks for safe convert
228  static TypeTo safeConvert(const Amesos2::MUMPST::CMUMPS_COMPLEX t)
229  {
230  typedef typename TypeTo::value_type value_type;
231  value_type ret_r = Teuchos::as<value_type>(t.r);
232  value_type ret_i = Teuchos::as<value_type>(t.i);
233  return (TypeTo(ret_r, ret_i));
234  }
235 
236  };
237 
238  template <typename TypeTo>
239  class ValueTypeConversionTraits<TypeTo, Amesos2::MUMPST::ZMUMPS_COMPLEX>
240  {
241  public:
242  static TypeTo convert(const Amesos2::MUMPST::ZMUMPS_COMPLEX t)
243  {
244  typedef typename TypeTo::value_type value_type;
245  value_type ret_r = Teuchos::as<value_type>(t.r);
246  value_type ret_i = Teuchos::as<value_type>(t.i);
247  return (TypeTo(ret_r, ret_i));
248  }
249  //No special checks for safe convert
250  static TypeTo safeConvert(const Amesos2::MUMPST::ZMUMPS_COMPLEX t)
251  {
252  typedef typename TypeTo::value_type value_type;
253  value_type ret_r = Teuchos::as<value_type>(t.r);
254  value_type ret_i = Teuchos::as<value_type>(t.i);
255  return (TypeTo(ret_r, ret_i));
256  }
257 
258  };
259 
260 
261 //#endif
263 
264 
265 } // end namespace Teuchos
266 
267 #endif // HAVE_TEUCHOS_COMPLEX
268 
269 
270 
271 #endif // AMESOS2_MUMPS_TYPEMAP_HPP