FEI Version of the Day
Loading...
Searching...
No Matches
fei_MatrixTraits_FillableMat.hpp
1/*--------------------------------------------------------------------*/
2/* Copyright 2008 Sandia Corporation. */
3/* Under the terms of Contract DE-AC04-94AL85000, there is a */
4/* non-exclusive license for use of this work by or on behalf */
5/* of the U.S. Government. Export of this program may require */
6/* a license from the United States Government. */
7/*--------------------------------------------------------------------*/
8
9#ifndef _fei_MatrixTraits_FillableMat_hpp_
10#define _fei_MatrixTraits_FillableMat_hpp_
11
12//This file defines matrix traits for fei::FillableMat matrices
13//
14
15#include <fei_CSRMat.hpp>
16#include <fei_CSVec.hpp>
17#include <fei_Vector_Impl.hpp>
18
19namespace fei {
20
22 template<>
23 struct MatrixTraits<FillableMat> {
24
26 static const char* typeName()
27 { return("FillableMat"); }
28
29 static double* getBeginPointer(FillableMat* /*mat*/)
30 {
31 return NULL;
32 }
33
34 static int getOffset(FillableMat* /*mat*/, int /*row*/, int /*col*/)
35 {
36 return -1;
37 }
38
41 static int setValues(FillableMat* mat, double scalar)
42 {
43 mat->setValues(scalar);
44 return(0);
45 }
46
50 static int getNumLocalRows(FillableMat* mat, int& numRows)
51 {
52 numRows = mat->getNumRows();
53 return(0);
54 }
55
58 static int getRowLength(FillableMat* mat, int row, int& length)
59 {
60 try {
61 const CSVec* matrixrow = mat->getRow(row);
62 length = matrixrow->size();
63 }
64 catch(...) {
65 length = 0;
66 }
67 return( 0 );
68 }
69
82 static int copyOutRow(FillableMat* mat,
83 int row, int len, double* coefs, int* indices)
84 {
85 try {
86 const CSVec* matrixrow = mat->getRow(row);
87
88 const std::vector<int>& row_indices = matrixrow->indices();
89 const std::vector<double>& row_coefs = matrixrow->coefs();
90 const int rowlen = row_indices.size();
91 for(int i=0; i<rowlen; ++i) {
92 if (i >= len) break;
93 coefs[i] = row_coefs[i];
94 indices[i] = row_indices[i];
95 }
96 }
97 catch(...) {
98 //what should we do here???
99 }
100
101 return( 0 );
102 }
103
106 static int putValuesIn(FillableMat* mat,
107 int numRows, const int* rows,
108 int numCols, const int* cols,
109 const double* const* values,
110 bool sum_into)
111 {
112 if (numCols < 1 || numRows < 1) return(0);
113 if (sum_into) {
114 for(int i=0; i<numRows; ++i) {
115 mat->sumInRow(rows[i], cols, values[i], numCols);
116 }
117 }
118 else {
119 for(int i=0; i<numRows; ++i) {
120 mat->putRow(rows[i], cols, values[i], numCols);
121 }
122 }
123
124 return( 0 );
125 }
126
131 static int globalAssemble(FillableMat* mat)
132 {
133 return(0);
134 }
135
137 static int matvec(FillableMat* mat,
138 fei::Vector* x,
139 fei::Vector* y)
140 {
142 dynamic_cast<fei::Vector_Impl<CSVec>* >(x);
144 dynamic_cast<fei::Vector_Impl<CSVec>* >(y);
145
146 if (fvx == NULL || fvy == NULL) {
147 return(-1);
148 }
149
150 fei::CSRMat A(*mat);
151 fei::CSVec csx(*(fvx->getUnderlyingVector()));
152 fei::CSVec csy(*(fvy->getUnderlyingVector()));
153
154 fei::multiply_CSRMat_CSVec(A, csx, csy);
155
156 return( 0 );
157 }
158
159 };//struct MatrixTraits
160}//namespace fei
161
162#endif // _fei_MatrixTraits_FillableMat_hpp_
163
void multiply_CSRMat_CSVec(const CSRMat &A, const CSVec &x, CSVec &y)
static int setValues(FillableMat *mat, double scalar)
static int matvec(FillableMat *mat, fei::Vector *x, fei::Vector *y)
static int getNumLocalRows(FillableMat *mat, int &numRows)
static int copyOutRow(FillableMat *mat, int row, int len, double *coefs, int *indices)
static int getRowLength(FillableMat *mat, int row, int &length)
static int putValuesIn(FillableMat *mat, int numRows, const int *rows, int numCols, const int *cols, const double *const *values, bool sum_into)