Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Umfpack_FunctionMap.hpp
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 Sivasankaran Rajamanickam (srajama@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
44 #ifndef AMESOS2_UMFPACK_FUNCTIONMAP_HPP
45 #define AMESOS2_UMFPACK_FUNCTIONMAP_HPP
46 
47 #ifdef HAVE_TEUCHOS_COMPLEX
48 #include <complex>
49 #endif
50 
51 #include "Amesos2_FunctionMap.hpp"
52 #include "Amesos2_Umfpack_TypeMap.hpp"
53 
54 extern "C"
55 {
56  #include "umfpack.h"
57 }
58 
59 namespace Amesos2 {
60 
61  /* ==================== Specializations ====================
62  *
63  * \cond Umfpack_function_specializations
64  */
65 
66  template <>
67  struct FunctionMap<Umfpack,double>
68  {
69  typedef TypeMap<Umfpack,double> type_map;
70 
75  static int umfpack_solve(
76  int sys,
77  const int Ap [ ],
78  const int Ai [ ],
79  const double Ax [ ],
80  double X [ ],
81  const double B [ ],
82  void *Numeric,
83  const double Control [UMFPACK_CONTROL],
84  double Info [UMFPACK_INFO])
85  {
86  return ::umfpack_di_solve(sys, Ap, Ai, Ax, X, B, Numeric, Control, Info);
87  }
88 
89  static int umfpack_numeric(
90  const int Ap [ ],
91  const int Ai [ ],
92  const double Ax [ ],
93  void *Symbolic,
94  void **Numeric,
95  const double Control [UMFPACK_CONTROL],
96  double Info [UMFPACK_INFO])
97  {
98  return ::umfpack_di_numeric(Ap, Ai, Ax, Symbolic, Numeric, Control, Info);
99  }
100 
101  static int umfpack_symbolic(
102  int n_row,
103  int n_col,
104  const int Ap [ ],
105  const int Ai [ ],
106  const double Ax [ ],
107  void **Symbolic,
108  const double Control [UMFPACK_CONTROL],
109  double Info [UMFPACK_INFO])
110  {
111  return ::umfpack_di_symbolic(n_row, n_col, Ap, Ai, Ax, Symbolic, Control, Info);
112  }
113 
114  static void umfpack_defaults(
115  double Control [UMFPACK_CONTROL])
116  {
117  ::umfpack_di_defaults(Control);
118  }
119 
120  static void umfpack_free_numeric(void **Numeric)
121  {
122  return ::umfpack_di_free_numeric(Numeric);
123  }
124 
125  static void umfpack_free_symbolic(void **Symbolic)
126  {
127  return ::umfpack_di_free_symbolic(Symbolic);
128  }
129  };
130 
131 
132 #ifdef HAVE_TEUCHOS_COMPLEX
133 
134  template <>
135  struct FunctionMap<Umfpack,std::complex<double>>
136  {
137  typedef TypeMap<Umfpack,std::complex<double>> type_map;
138 
143  static double * stdComplexToUmfpackDoubleConversion(
144  const std::complex<double> v [ ])
145  {
146  return (double*)(&v[0]);
147  }
148 
149  static int umfpack_solve(
150  int sys,
151  const int Ap [ ],
152  const int Ai [ ],
153  const std::complex<double> Ax [ ],
154  std::complex<double> X [ ],
155  const std::complex<double> B [ ],
156  void *Numeric,
157  const double Control [UMFPACK_CONTROL],
158  double Info [UMFPACK_INFO])
159  {
160  return ::umfpack_zi_solve(sys, Ap, Ai,
161  stdComplexToUmfpackDoubleConversion(Ax), NULL,
162  stdComplexToUmfpackDoubleConversion(X), NULL,
163  stdComplexToUmfpackDoubleConversion(B), NULL,
164  Numeric, Control, Info);
165  }
166 
167  static int umfpack_numeric(
168  const int Ap [ ],
169  const int Ai [ ],
170  const std::complex<double> Ax [ ],
171  void *Symbolic,
172  void **Numeric,
173  const double Control[UMFPACK_CONTROL],
174  double Info[UMFPACK_INFO])
175  {
176  return ::umfpack_zi_numeric(Ap, Ai, stdComplexToUmfpackDoubleConversion(Ax), NULL, Symbolic, Numeric, Control, Info);
177  }
178 
179  static int umfpack_symbolic(
180  int n_row,
181  int n_col,
182  const int Ap [ ],
183  const int Ai [ ],
184  const std::complex<double> Ax [ ],
185  void **Symbolic,
186  const double Control [UMFPACK_CONTROL],
187  double Info [UMFPACK_INFO])
188  {
189  return ::umfpack_zi_symbolic(n_row, n_col, Ap, Ai, stdComplexToUmfpackDoubleConversion(Ax), NULL, Symbolic, Control, Info);
190  }
191 
192  static void umfpack_defaults(double Control [UMFPACK_CONTROL])
193  {
194  ::umfpack_zi_defaults(Control);
195  }
196 
197  static void umfpack_free_numeric(void **Numeric)
198  {
199  ::umfpack_zi_free_numeric(Numeric);
200  }
201 
202  static void umfpack_free_symbolic(void **Symbolic)
203  {
204  ::umfpack_zi_free_symbolic(Symbolic);
205  }
206  };
207 
208 #endif // HAVE_TEUCHOS_COMPLEX
209 
210  /* \endcond Umfpack_function_specializations */
211 
212 
213 } // end namespace Amesos2
214 
215 #endif // AMESOS2_UMFPACK_FUNCTIONMAP_HPP
Declaration of Function mapping class for Amesos2.