/[escript]/branches/RW_WIN32/finley/src/CPPAdapter/SystemMatrixAdapter.cpp
ViewVC logotype

Annotation of /branches/RW_WIN32/finley/src/CPPAdapter/SystemMatrixAdapter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 102 - (hide annotations)
Wed Dec 15 07:08:39 2004 UTC (16 years, 2 months ago) by jgs
Original Path: trunk/esys2/finley/src/CPPAdapter/SystemMatrixAdapter.cpp
File size: 4619 byte(s)
*** empty log message ***

1 jgs 82 /*
2     ******************************************************************************
3     * *
4     * COPYRIGHT ACcESS 2004 - All Rights Reserved *
5     * *
6     * This software is the property of ACcESS. No part of this code *
7     * may be copied in any form or by any means without the expressed written *
8     * consent of ACcESS. Copying, use or modification of this software *
9     * by any unauthorised person is illegal unless that person has a software *
10     * license agreement with ACcESS. *
11     * *
12     ******************************************************************************
13 jgs 102 $Id$
14 jgs 82 */
15     extern "C" {
16     #include "finley/finleyC/System.h"
17     }
18     #include "escript/Data/Data.h"
19     #include "finley/CPPAdapter/SystemMatrixAdapter.h"
20     #include "finley/CPPAdapter/FinleyAdapterException.h"
21     #include "finley/CPPAdapter/FinleyError.h"
22     #include <boost/python/extract.hpp>
23    
24     using namespace std;
25    
26     namespace finley {
27    
28 jgs 102 struct null_deleter
29     {
30     void operator()(void const *ptr) const
31     {
32     }
33     };
34    
35    
36 jgs 82 SystemMatrixAdapter::SystemMatrixAdapter()
37     {
38     throw FinleyAdapterException("Error - Illegal to generate default SystemMatrixAdapter.");
39     }
40    
41 jgs 102 SystemMatrixAdapter::SystemMatrixAdapter(Finley_SystemMatrix* system_matrix,
42 jgs 82 const int row_blocksize,
43     const escript::FunctionSpace& row_functionspace,
44     const int column_blocksize,
45     const escript::FunctionSpace& column_functionspace):
46 jgs 102 AbstractSystemMatrix(row_blocksize,row_functionspace,column_blocksize,column_functionspace)
47 jgs 82 {
48 jgs 102 m_system_matrix.reset(system_matrix,null_deleter());
49 jgs 82 }
50    
51     SystemMatrixAdapter::~SystemMatrixAdapter()
52     {
53     if (m_system_matrix.unique()) {
54     Finley_SystemMatrix* mat=m_system_matrix.get();
55     Finley_SystemMatrix_dealloc(mat);
56     }
57     }
58    
59     Finley_SystemMatrix* SystemMatrixAdapter::getFinley_SystemMatrix() const
60     {
61     return m_system_matrix.get();
62     }
63    
64     void SystemMatrixAdapter::ypAx(escript::Data& y, const escript::Data& x) const
65     {
66     Finley_SystemMatrix* mat=getFinley_SystemMatrix();
67     Finley_SystemMatrixVector(&(y.getDataC()),mat,&(x.getDataC()));
68     checkFinleyError();
69     }
70    
71     void SystemMatrixAdapter::setToSolution(escript::Data& out, const escript::Data& in, const boost::python::dict& options) const
72     {
73     Finley_SolverOptions finley_options;
74     Finley_SystemMatrix_setDefaults(&finley_options);
75     // extract options
76     #define EXTRACT(__key__,__val__,__type__) if ( options.has_key(__key__)) finley_options.__val__=boost::python::extract<__type__>(options.get(__key__))
77     EXTRACT("verbose",verbose,int);
78     EXTRACT("reordering",reordering,int);
79 jgs 102 EXTRACT(ESCRIPT_TOLERANCE_KEY,tolerance,double);
80     EXTRACT(ESCRIPT_METHOD_KEY,method,int);
81     EXTRACT(ESCRIPT_SYMMETRY_KEY,symmetric,int);
82 jgs 82 EXTRACT("preconditioner",preconditioner,int);
83     EXTRACT("iter_max",iter_max,int);
84     EXTRACT("drop_tolerance",drop_tolerance,double);
85     EXTRACT("drop_storage",drop_storage,double);
86 jgs 102 EXTRACT("truncation",truncation,double);
87     EXTRACT("restart",restart,double);
88 jgs 82 #undef EXTRACT
89 jgs 102 Finley_SystemMatrix_solve(getFinley_SystemMatrix(),&(out.getDataC()),&(in.getDataC()),&finley_options);
90 jgs 82 checkFinleyError();
91     }
92    
93     void SystemMatrixAdapter::nullifyRowsAndCols(const escript::Data& row_q, const escript::Data& col_q, const double mdv) const
94     {
95     Finley_SystemMatrix* system_matrix_ptr = getFinley_SystemMatrix();
96     escriptDataC row_qC = row_q.getDataC();
97     escriptDataC col_qC = col_q.getDataC();
98    
99     Finley_SystemMatrix_nullifyRowsAndCols(system_matrix_ptr, &row_qC, &col_qC, mdv);
100     }
101    
102 jgs 102 void SystemMatrixAdapter::saveMM(const std::string& fileName) const
103     {
104     char fName[fileName.size()+1];
105     strcpy(fName,fileName.c_str());
106     Finley_SystemMatrix* system_matrix_ptr = getFinley_SystemMatrix();
107     Finley_SystemMatrix_saveMM(system_matrix_ptr,fName);
108     checkFinleyError();
109     }
110    
111     void SystemMatrixAdapter:: setValue(const double value) const
112     {
113     Finley_SystemMatrix* system_matrix_ptr = getFinley_SystemMatrix();
114     Finley_SystemMatrix_setValues(system_matrix_ptr,value);
115     checkFinleyError();
116     }
117    
118    
119 jgs 82 } // end of namespace

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26