DUNE-FEM (unstable)

istladapter.hh
1#ifndef DUNE_FEM_OPERATOR_LINEAR_ISTLADAPTER_HH
2#define DUNE_FEM_OPERATOR_LINEAR_ISTLADAPTER_HH
3
4#if HAVE_DUNE_ISTL
6
8
9#include <dune/fem/function/blockvectorfunction.hh>
10#include <dune/fem/operator/matrix/istlpreconditioner.hh>
11
12namespace Dune
13{
14
15 namespace Fem
16 {
17
18 // ISTLLinearOperatorAdapter
19 // -------------------------
20
21 template< class Operator >
22 class ISTLLinearOperatorAdapter
23 : public Dune::LinearOperator< typename Operator::DomainFunctionType::DofStorageType, typename Operator::RangeFunctionType::DofStorageType >
24 {
25 typedef ISTLLinearOperatorAdapter< Operator > ThisType;
27
28 typedef typename Operator::DomainFunctionType DomainFunctionType;
29 typedef typename Operator::RangeFunctionType RangeFunctionType;
30
31 public:
32 typedef Operator OperatorType;
33
34 typedef typename DomainFunctionType::DiscreteFunctionSpaceType DomainFunctionSpaceType;
35 typedef typename RangeFunctionType::DiscreteFunctionSpaceType RangeFunctionSpaceType;
36
37 typedef typename BaseType::domain_type domain_type;
38 typedef typename BaseType::range_type range_type;
39 typedef typename BaseType::field_type field_type;
40
41 ISTLLinearOperatorAdapter ( const OperatorType &op,
42 const DomainFunctionSpaceType &domainSpace,
43 const RangeFunctionSpaceType &rangeSpace )
44 : op_( op ),
45 domainSpace_( domainSpace ),
46 rangeSpace_( rangeSpace )
47 {}
48
49 virtual void apply ( const domain_type &x, range_type &y ) const override
50 {
51 const DomainFunctionType fx( "ISTLLinearOperatorAdapter::apply::x", domainSpace_, x );
52 RangeFunctionType fy( "ISTLLinearOperatorAdapter::apply::y", rangeSpace_, y );
53 op_( fx, fy );
54 }
55
56 virtual void applyscaleadd ( field_type alpha, const domain_type &x, range_type &y ) const override
57 {
58 const DomainFunctionType fx( "ISTLLinearOperatorAdapter::applyscaleadd::x", domainSpace_, x );
59 RangeFunctionType fy( "ISTLLinearOperatorAdapter::applyscaleadd::y", rangeSpace_ );
60 op_( fx, fy );
61 y.axpy( alpha, fy.blockVector() );
62 }
63
64 SolverCategory::Category category () const override { return SolverCategory::sequential; }
65
66 protected:
67 const OperatorType &op_;
68 const DomainFunctionSpaceType &domainSpace_;
69 const RangeFunctionSpaceType &rangeSpace_;
70 };
71
72 template< class Operator >
73 class ISTLMatrixFreeOperatorAdapter : public ISTLLinearOperatorAdapter< Operator >
74 {
75 typedef ISTLMatrixFreeOperatorAdapter< Operator > ThisType;
76 typedef ISTLLinearOperatorAdapter< Operator > BaseType;
77
78 typedef typename Operator::DomainFunctionType DomainFunctionType;
79 typedef typename Operator::RangeFunctionType RangeFunctionType;
80
81 public:
82 typedef Operator OperatorType;
83
84 typedef typename DomainFunctionType::DiscreteFunctionSpaceType DomainFunctionSpaceType;
85 typedef typename RangeFunctionType::DiscreteFunctionSpaceType RangeFunctionSpaceType;
86
87 template <class DF>
88 struct IsISTLBlockVectorDiscreteFunction
89 {
90 static const bool value = false ;
91 };
92
93 template <class Space, class Block>
94 struct IsISTLBlockVectorDiscreteFunction< ISTLBlockVectorDiscreteFunction< Space, Block > >
95 {
96 static const bool value = true ;
97 };
98
99
100 static_assert( IsISTLBlockVectorDiscreteFunction< DomainFunctionType > :: value,
101 "ISTLMatrixFreeOperatorAdapter only works with ISTLBlockVectorDiscreteFunction" );
102 static_assert( IsISTLBlockVectorDiscreteFunction< RangeFunctionType > :: value,
103 "ISTLMatrixFreeOperatorAdapter only works with ISTLBlockVectorDiscreteFunction" );
104
105 typedef typename BaseType::domain_type domain_type;
106 typedef typename BaseType::range_type range_type;
107 typedef typename BaseType::field_type field_type;
108
109 typedef Fem::ParallelScalarProduct< RangeFunctionType > ParallelScalarProductType;
110 typedef Fem::IdentityPreconditionerWrapper< domain_type, range_type > PreconditionAdapterType;
111
113 ISTLMatrixFreeOperatorAdapter ( const OperatorType &op,
114 const DomainFunctionSpaceType &domainSpace,
115 const RangeFunctionSpaceType &rangeSpace )
116 : BaseType( op, domainSpace, rangeSpace ),
117 scp_( rangeSpace ),
118 preconditioner_()
119 {}
120
122 ISTLMatrixFreeOperatorAdapter ( const ISTLMatrixFreeOperatorAdapter& other )
123 : BaseType( other ),
124 scp_( other.rangeSpace_ ),
125 preconditioner_()
126 {}
127
129 PreconditionAdapterType& preconditionAdapter() { return preconditioner_; }
131 const PreconditionAdapterType& preconditionAdapter() const { return preconditioner_; }
132
133 virtual double residuum(const range_type& rhs, domain_type& x) const
134 {
135 range_type tmp( rhs );
136
137 this->apply(x,tmp);
138 tmp -= rhs;
139
140 // return global sum of residuum
141 return scp_.norm(tmp);
142 }
143
144 SolverCategory::Category category () const override { return SolverCategory::sequential; }
145
147 ParallelScalarProductType& scp() const { return scp_; }
148
150 double averageCommTime () const { return 0; }
151
152 protected:
153 mutable ParallelScalarProductType scp_;
154 PreconditionAdapterType preconditioner_;
155 };
156
157 } // namespace Fem
158
159} // namespace Dune
160
161#endif // #if HAVE_DUNE_ISTL
162
163#endif // #ifndef DUNE_FEM_OPERATOR_LINEAR_ISTLADAPTER_HH
A linear operator.
Definition: operators.hh:68
Various macros to work with Dune module version numbers.
Dune namespace.
Definition: alignedallocator.hh:13
Define general, extensible interface for operators. The available implementation wraps a matrix.
DomainFunction DomainFunctionType
type of discrete function in the operator's domain
Definition: operator.hh:36
RangeFunction RangeFunctionType
type of discrete function in the operator's range
Definition: operator.hh:38
Category
Definition: solvercategory.hh:23
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:25
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)