Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Cholmod_FunctionMap.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 
44 
55 #ifndef AMESOS2_NEWSOLVER_FUNCTIONMAP_HPP
56 #define AMESOS2_NEWSOLVER_FUNCTIONMAP_HPP
57 
58 #ifdef HAVE_TEUCHOS_COMPLEX
59 #include <complex>
60 #endif
61 
62 #include "Amesos2_FunctionMap.hpp"
63 #include "Amesos2_Cholmod_TypeMap.hpp"
64 
65 
66 namespace Amesos2 {
67 
68  namespace CHOL {
69 # include "cholmod_core.h"
70 # include "cholmod.h"
71  }
72 
73 
74  template <>
75  struct FunctionMap<Cholmod,double>
76  {
77 
78  static void cholmod_init_sparse(size_t nrow, size_t ncol, size_t nzmax,
79  int sorted, void *p, void *x, void *i,
80  CHOL::cholmod_sparse *sparse)
81  {
82  sparse->nrow = nrow;
83  sparse->ncol = ncol;
84  sparse->nzmax = nzmax;
85  sparse->stype = 1;
86  sparse->itype = CHOLMOD_INT;
87  sparse->sorted = 0;
88  sparse->packed = 1;
89  sparse->xtype = CHOLMOD_REAL;
90  sparse->dtype = CHOLMOD_DOUBLE;
91  sparse->x = x;
92  sparse->p = p;
93  sparse->i = i;
94  }
95 
96  static void cholmod_init_dense(int nrow, int ncol, int d, void *x,
97  CHOL::cholmod_dense *dense)
98  {
99  dense->nrow = nrow;
100  dense->ncol = ncol;
101  dense->d = d;
102  dense->xtype = CHOLMOD_REAL;
103  dense->dtype = CHOLMOD_DOUBLE;
104  dense->x = x;
105  }
106  };
107 
108  template <>
109  struct FunctionMap<Cholmod,float>
110  {
111  static void cholmod_init_sparse(size_t nrow, size_t ncol, size_t nzmax,
112  int sorted, void *p, void *x, void*i,
113  CHOL::cholmod_sparse* sparse)
114  {
115  sparse->nrow = nrow;
116  sparse->ncol = ncol;
117  sparse->nzmax = nzmax;
118  sparse->stype = 1;
119  sparse->itype = CHOLMOD_INT;
120  sparse->sorted = 0;
121  sparse->packed = 1;
122  sparse->xtype = CHOLMOD_REAL;
123  sparse->dtype = CHOLMOD_SINGLE;
124  sparse->x = x;
125  sparse->p = p;
126  sparse->i = i;
127  }
128 
129 
130  static void cholmod_init_dense(int nrow, int ncol, int d, void *x,
131  CHOL::cholmod_dense *dense)
132  {
133  dense->nrow = nrow;
134  dense->ncol = ncol;
135  dense->d = d;
136  dense->xtype = CHOLMOD_REAL;
137  dense->dtype = CHOLMOD_SINGLE;
138  dense->x = x;
139  }
140  };
141 
142 #ifdef HAVE_TEUCHOS_COMPLEX
143  template <>
144  struct FunctionMap<Cholmod,CHOL::complex>
145  {
146 
147  static void cholmod_init_sparse(size_t nrow, size_t ncol, size_t nzmax,
148  int sorted, void *p, void *x, void *i,
149  CHOL::cholmod_sparse* sparse)
150  {
151  sparse->nrow = nrow;
152  sparse->ncol = ncol;
153  sparse->nzmax = nzmax;
154  sparse->stype = 1;
155  sparse->itype = CHOLMOD_INT;
156  sparse->sorted = 0;
157  sparse->packed = 1;
158  sparse->xtype = CHOLMOD_COMPLEX;
159  sparse->x = x;
160  sparse->p = p;
161  sparse->i = i;
162 
163  }
164 
165  static void cholmod_init_dense(int nrow, int ncol, int d, void *x,
166  CHOL::cholmod_dense *dense)
167  {
168  dense->nrow = nrow;
169  dense->ncol = ncol;
170  dense->d = d;
171  dense->xtype = CHOLMOD_COMPLEX;
172  dense->x = x;
173  }
174  };
175 #endif
176 
177 } // end namespace Amesos2
178 
179 #endif // AMESOS2_CHOLMOD_FUNCTIONMAP_HPP
Declaration of Function mapping class for Amesos2.