RipleySystemMatrix.h
Go to the documentation of this file.
/*****************************************************************************
*
* Copyright (c) 2014-2018 by The University of Queensland
* http://www.uq.edu.au
*
* Primary Business: Queensland, Australia
* Licensed under the Apache License, version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
* Development 2012-2013 by School of Earth Sciences
* Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
* Development from 2019 by School of Earth and Environmental Sciences
**
*****************************************************************************/
#ifndef __RIPLEY_SYSTEMMATRIX_H__
#define __RIPLEY_SYSTEMMATRIX_H__
#include <escript/AbstractSystemMatrix.h>
#include <escript/FunctionSpace.h>
#include <ripley/Ripley.h>
namespace escript {
class SolverBuddy;
}
#include <cusp/cds_matrix.h>
namespace ripley {
typedef cusp::cds_matrix<int, double, cusp::host_memory> HostMatrixType;
typedef cusp::cds_matrix<int, double, cusp::device_memory> DeviceMatrixType;
typedef cusp::array1d<double, cusp::host_memory> HostVectorType;
typedef cusp::array1d<double, cusp::device_memory> DeviceVectorType;
class SystemMatrix : public escript::AbstractSystemMatrix
{
public:
SystemMatrix(escript::JMPI mpiInfo, int blocksize,
const escript::FunctionSpace& fs, int nRows,
const IndexVector& diagonalOffsets, bool symmetric);
virtual ~SystemMatrix() {}
virtual void nullifyRowsAndCols(escript::Data& row_q,
escript::Data& col_q,
double mdv);
virtual void saveMM(const std::string& filename) const;
virtual void saveHB(const std::string& filename) const;
virtual void resetValues(bool preserveSolverData = false);
void add(const IndexVector& rowIndex, const std::vector<double>& array);
inline int getBlockSize() const { return getRowBlockSize(); }
private:
template<class LinearOperator, class Vector, class Preconditioner>
void runSolver(LinearOperator& A, Vector& x, Vector& b, Preconditioner& M,
escript::SolverBuddy& sb) const;
void copyMatrixToDevice(bool verbose=false) const;
virtual void setToSolution(escript::Data& out, escript::Data& in,
boost::python::object& options) const;
virtual void ypAx(escript::Data& y, escript::Data& x) const;
static void checkCUDA();
static std::vector<int> cudaDevices;
escript::JMPI m_mpiInfo;
HostMatrixType mat;
mutable DeviceMatrixType dmat;
mutable bool matrixAltered;
bool symmetric;
};
} // namespace ripley
#endif // __RIPLEY_SYSTEMMATRIX_H__
escript::AbstractSystemMatrix
Base class for escript system matrices.
Definition: AbstractSystemMatrix.h:44
escript::AbstractSystemMatrix::getRowBlockSize
int getRowBlockSize() const
returns the row block size
Definition: AbstractSystemMatrix.h:114
escript::Data
Data represents a collection of datapoints.
Definition: Data.h:64
escript::FunctionSpace
Definition: FunctionSpace.h:36
escript::SolverBuddy
Definition: SolverOptions.h:161
ripley::SystemMatrix
Definition: RipleySystemMatrix.h:40
ripley::SystemMatrix::matrixAltered
bool matrixAltered
Definition: RipleySystemMatrix.h:83
ripley::SystemMatrix::saveHB
virtual void saveHB(const std::string &filename) const
writes the matrix to a file using the Harwell-Boeing file format
ripley::SystemMatrix::m_mpiInfo
escript::JMPI m_mpiInfo
Definition: RipleySystemMatrix.h:80
ripley::SystemMatrix::saveMM
virtual void saveMM(const std::string &filename) const
writes the matrix to a file using the Matrix Market file format
ripley::SystemMatrix::ypAx
virtual void ypAx(escript::Data &y, escript::Data &x) const
performs y+=this*x
ripley::SystemMatrix::checkCUDA
static void checkCUDA()
ripley::SystemMatrix::cudaDevices
static std::vector< int > cudaDevices
GPU device IDs supporting CUDA.
Definition: RipleySystemMatrix.h:78
ripley::SystemMatrix::copyMatrixToDevice
void copyMatrixToDevice(bool verbose=false) const
copies the current matrix stored on host to device if required
ripley::SystemMatrix::nullifyRowsAndCols
virtual void nullifyRowsAndCols(escript::Data &row_q, escript::Data &col_q, double mdv)
sets matrix entries to zero in specified rows and columns. The rows and columns are marked by positiv...
ripley::SystemMatrix::runSolver
void runSolver(LinearOperator &A, Vector &x, Vector &b, Preconditioner &M, escript::SolverBuddy &sb) const
ripley::SystemMatrix::dmat
DeviceMatrixType dmat
Definition: RipleySystemMatrix.h:82
ripley::SystemMatrix::getBlockSize
int getBlockSize() const
Definition: RipleySystemMatrix.h:60
ripley::SystemMatrix::setToSolution
virtual void setToSolution(escript::Data &out, escript::Data &in, boost::python::object &options) const
solves the linear system this*out=in
ripley::SystemMatrix::mat
HostMatrixType mat
Definition: RipleySystemMatrix.h:81
ripley::SystemMatrix::SystemMatrix
SystemMatrix(escript::JMPI mpiInfo, int blocksize, const escript::FunctionSpace &fs, int nRows, const IndexVector &diagonalOffsets, bool symmetric)
ripley::SystemMatrix::~SystemMatrix
virtual ~SystemMatrix()
Definition: RipleySystemMatrix.h:46
ripley::SystemMatrix::add
void add(const IndexVector &rowIndex, const std::vector< double > &array)
ripley::SystemMatrix::symmetric
bool symmetric
Definition: RipleySystemMatrix.h:84
ripley::SystemMatrix::resetValues
virtual void resetValues(bool preserveSolverData=false)
resets the matrix entries
escript
Definition: AbstractContinuousDomain.cpp:23
escript::Vector
Data Vector(double value, const FunctionSpace &what, bool expanded)
Return a Data object containing vector data-points. ie: rank 1 data-points.
Definition: DataFactory.cpp:125
escript::JMPI
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:74
paso::M
static dim_t M
Definition: SparseMatrix_saveHB.cpp:37
ripley
Definition: ripley/src/AbstractAssembler.h:26
ripley::IndexVector
std::vector< index_t > IndexVector
Definition: Ripley.h:44
ripley::DeviceMatrixType
cusp::cds_matrix< int, double, cusp::device_memory > DeviceMatrixType
Definition: RipleySystemMatrix.h:35
ripley::HostVectorType
cusp::array1d< double, cusp::host_memory > HostVectorType
Definition: RipleySystemMatrix.h:36
ripley::HostMatrixType
cusp::cds_matrix< int, double, cusp::host_memory > HostMatrixType
Definition: RipleySystemMatrix.h:34
ripley::DeviceVectorType
cusp::array1d< double, cusp::device_memory > DeviceVectorType
Definition: RipleySystemMatrix.h:37