1 |
|
2 |
/* $Id$ */ |
3 |
|
4 |
/******************************************************* |
5 |
* |
6 |
* Copyright 2003-2007 by ACceSS MNRF |
7 |
* Copyright 2007 by University of Queensland |
8 |
* |
9 |
* http://esscc.uq.edu.au |
10 |
* Primary Business: Queensland, Australia |
11 |
* Licensed under the Open Software License version 3.0 |
12 |
* http://www.opensource.org/licenses/osl-3.0.php |
13 |
* |
14 |
*******************************************************/ |
15 |
|
16 |
#include "AbstractSystemMatrix.h" |
17 |
#include "DataException.h" |
18 |
#include "DataArrayView.h" |
19 |
#include "Data.h" |
20 |
|
21 |
namespace escript { |
22 |
|
23 |
AbstractSystemMatrix::AbstractSystemMatrix() { |
24 |
//std::cout << "Called default AbstractSystemMatrix constructor" << std::endl; |
25 |
m_empty=1; |
26 |
} |
27 |
|
28 |
AbstractSystemMatrix::AbstractSystemMatrix(const int row_blocksize, |
29 |
const FunctionSpace& row_functionspace, |
30 |
const int column_blocksize, |
31 |
const FunctionSpace& column_functionspace) |
32 |
{ |
33 |
if (row_blocksize<=0) |
34 |
throw DataException("Error - negative row block size of system matrix."); |
35 |
if (column_blocksize<=0) |
36 |
throw DataException("Error - negative column block size of system matrix."); |
37 |
|
38 |
m_empty=0; |
39 |
m_row_blocksize=row_blocksize; |
40 |
m_column_blocksize=column_blocksize; |
41 |
m_row_functionspace=row_functionspace; |
42 |
m_column_functionspace=column_functionspace; |
43 |
} |
44 |
|
45 |
AbstractSystemMatrix::~AbstractSystemMatrix() { |
46 |
} |
47 |
|
48 |
int AbstractSystemMatrix::isEmpty() const { |
49 |
return m_empty; |
50 |
} |
51 |
|
52 |
Data operator*(const AbstractSystemMatrix& left,const Data& right) |
53 |
{ |
54 |
Data tmp=(Data) right; |
55 |
return left.vectorMultiply(tmp); |
56 |
} |
57 |
|
58 |
Data AbstractSystemMatrix::vectorMultiply(Data& right) const |
59 |
{ |
60 |
if (isEmpty()) |
61 |
throw SystemMatrixException("Error - Matrix is empty."); |
62 |
if (right.getDataPointSize()!=getColumnBlockSize()) |
63 |
throw SystemMatrixException("Error - column block size and input data size do not match."); |
64 |
DataArrayView::ShapeType shape; |
65 |
if (getRowBlockSize()>1) shape.push_back(getRowBlockSize()); |
66 |
|
67 |
Data out=Data(0.,shape,getRowFunctionSpace(),true); |
68 |
Data in=Data(right,getColumnFunctionSpace()); |
69 |
ypAx(out,in); |
70 |
return out; |
71 |
} |
72 |
|
73 |
void AbstractSystemMatrix::ypAx(Data& y,Data& x) const |
74 |
{ |
75 |
throw SystemMatrixException("Error - ypAx not available"); |
76 |
} |
77 |
|
78 |
Data AbstractSystemMatrix::solve(Data& in,const boost::python::dict& options) const |
79 |
{ |
80 |
if (isEmpty()) |
81 |
throw SystemMatrixException("Error - Matrix is empty."); |
82 |
if (in.getFunctionSpace()!=getRowFunctionSpace()) |
83 |
throw SystemMatrixException("Error - row function space and function space of right hand side do not match."); |
84 |
if (in.getDataPointSize()!=getRowBlockSize()) |
85 |
throw SystemMatrixException("Error - row block size and right hand side size do not match."); |
86 |
DataArrayView::ShapeType shape; |
87 |
if (getRowBlockSize()>1) shape.push_back(getColumnBlockSize()); |
88 |
Data out=Data(0.,shape,getColumnFunctionSpace(),true); |
89 |
setToSolution(out,in,options); |
90 |
return out; |
91 |
} |
92 |
void AbstractSystemMatrix::setToSolution(Data& out,Data& in,const boost::python::dict& options) const |
93 |
{ |
94 |
throw SystemMatrixException("Error - setToSolution not available"); |
95 |
} |
96 |
void AbstractSystemMatrix::saveMM(const std::string& fileName) const |
97 |
{ |
98 |
throw SystemMatrixException("Error - Matrix Market interface not available."); |
99 |
} |
100 |
void AbstractSystemMatrix::saveHB(const std::string& fileName) const |
101 |
{ |
102 |
throw SystemMatrixException("Error - Harwell-Boeing interface not available."); |
103 |
} |
104 |
void AbstractSystemMatrix::resetValues() const |
105 |
{ |
106 |
throw SystemMatrixException("Error - setValue is not implemented."); |
107 |
} |
108 |
|
109 |
} // end of namespace |