Loading...
Searching...
No Matches
operators.hh
Go to the documentation of this file.
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_ISTL_OPERATORS_HH
#define DUNE_ISTL_OPERATORS_HH
#include <dune-istl-config.hh> // DUNE_ISTL_SUPPORT_OLD_CATEGORY_INTERFACE
#include <cmath>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <dune/common/exceptions.hh>
#include <dune/common/shared_ptr.hh>
#include "solvercategory.hh"
namespace Dune {
//=====================================================================
// Abstract operator interface
//=====================================================================
template<class X, class Y>
class LinearOperator {
public:
typedef X domain_type;
typedef Y range_type;
typedef typename X::field_type field_type;
virtual void apply (const X& x, Y& y) const = 0;
virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const = 0;
virtual ~LinearOperator () {}
virtual SolverCategory::Category category() const
#if DUNE_ISTL_SUPPORT_OLD_CATEGORY_INTERFACE
{
DUNE_THROW(Dune::Exception,"It is necessary to implement the category method in a derived classes, in the future this method will pure virtual.");
};
#else
= 0;
#endif
};
template<class M, class X, class Y>
class AssembledLinearOperator : public LinearOperator<X,Y> {
public:
typedef M matrix_type;
typedef X domain_type;
typedef Y range_type;
typedef typename X::field_type field_type;
virtual const M& getmat () const = 0;
};
//=====================================================================
// Implementation for ISTL-matrix based operator
//=====================================================================
template<class M, class X, class Y>
class MatrixAdapter : public AssembledLinearOperator<M,X,Y>
{
public:
typedef M matrix_type;
typedef X domain_type;
typedef Y range_type;
typedef typename X::field_type field_type;
explicit MatrixAdapter (const M& A) : _A_(stackobject_to_shared_ptr(A)) {}
explicit MatrixAdapter (std::shared_ptr<const M> A) : _A_(A) {}
void apply (const X& x, Y& y) const override
{
_A_->mv(x,y);
}
void applyscaleadd (field_type alpha, const X& x, Y& y) const override
{
_A_->usmv(alpha,x,y);
}
const M& getmat () const override
{
return *_A_;
}
SolverCategory::Category category() const override
{
return SolverCategory::sequential;
}
private:
const std::shared_ptr<const M> _A_;
};
} // end namespace
#endif
// Emacs configuration
// Local Variables:
// tab-width: 4
// indent-tabs-mode: nil
// c-basic-offset: 2
// End:
solvercategory.hh
Dune
Definition allocator.hh:11
Dune::LinearOperator
A linear operator.
Definition operators.hh:68
Dune::LinearOperator::~LinearOperator
virtual ~LinearOperator()
every abstract base class has a virtual destructor
Definition operators.hh:87
Dune::LinearOperator::field_type
X::field_type field_type
The field type of the operator.
Definition operators.hh:75
Dune::LinearOperator::applyscaleadd
virtual void applyscaleadd(field_type alpha, const X &x, Y &y) const =0
apply operator to x, scale and add:
Dune::LinearOperator::category
virtual SolverCategory::Category category() const =0
Category of the linear operator (see SolverCategory::Category).
Dune::LinearOperator::range_type
Y range_type
The type of the range of the operator.
Definition operators.hh:73
Dune::LinearOperator::apply
virtual void apply(const X &x, Y &y) const =0
apply operator to x: The input vector is consistent and the output must also be consistent on the in...
Dune::LinearOperator::domain_type
X domain_type
The type of the domain of the operator.
Definition operators.hh:71
Dune::AssembledLinearOperator
A linear operator exporting itself in matrix form.
Definition operators.hh:110
Dune::AssembledLinearOperator::getmat
virtual const M & getmat() const =0
get reference to matrix
Dune::AssembledLinearOperator::domain_type
X domain_type
Definition operators.hh:114
Dune::AssembledLinearOperator::field_type
X::field_type field_type
Definition operators.hh:116
Dune::AssembledLinearOperator::range_type
Y range_type
Definition operators.hh:115
Dune::AssembledLinearOperator::matrix_type
M matrix_type
export types, usually they come from the derived class
Definition operators.hh:113
Dune::MatrixAdapter::MatrixAdapter
MatrixAdapter(std::shared_ptr< const M > A)
constructor: store an std::shared_ptr to a matrix
Definition operators.hh:147
Dune::MatrixAdapter::MatrixAdapter
MatrixAdapter(const M &A)
constructor: just store a reference to a matrix
Definition operators.hh:144
Dune::MatrixAdapter::applyscaleadd
void applyscaleadd(field_type alpha, const X &x, Y &y) const override
apply operator to x, scale and add:
Definition operators.hh:156
Dune::MatrixAdapter< BCRSMatrix, BlockVector, BlockVector >::range_type
BlockVector range_type
Definition operators.hh:140
Dune::MatrixAdapter< BCRSMatrix, BlockVector, BlockVector >::domain_type
BlockVector domain_type
Definition operators.hh:139
Dune::MatrixAdapter< BCRSMatrix, BlockVector, BlockVector >::field_type
BlockVector::field_type field_type
Definition operators.hh:141
Dune::MatrixAdapter::getmat
const M & getmat() const override
get reference to matrix
Definition operators.hh:162
Dune::MatrixAdapter::category
SolverCategory::Category category() const override
Category of the solver (see SolverCategory::Category).
Definition operators.hh:168
Dune::MatrixAdapter::apply
void apply(const X &x, Y &y) const override
apply operator to x:
Definition operators.hh:150
Dune::MatrixAdapter< BCRSMatrix, BlockVector, BlockVector >::matrix_type
BCRSMatrix matrix_type
Definition operators.hh:138
Dune::SolverCategory::Category
Category
Definition solvercategory.hh:23
Dune::SolverCategory::sequential
@ sequential
Category for sequential solvers.
Definition solvercategory.hh:25