KASKADE 7 development version
combiner.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2014 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef COMBINER_HH
14#define COMBINER_HH
15
16#include <dune/common/fmatrix.hh>
17#include <dune/istl/bcrsmatrix.hh>
18
19namespace Kaskade
20{
34 template <class Scalar = double>
36 public:
45 DiagonalCombiner(int n): orient(n,1.0)
46 {
47 }
48
53 template <class Matrix>
54 void rightTransform(Matrix& A) const {
55 // multiply from right -> modify columns
56 assert(A.M()==orient.size());
57 for (int i=0; i<A.N(); ++i)
58 for (int j=0; j<A.M(); ++j)
59 A[i][j] *= orient[j];
60 }
61
63 template <int n, int m>
64 void rightTransform(std::vector<VariationalArg<Scalar,n,m> >& v) const {
65 assert(v.size()==orient.size());
66 for (int i=0; i<v.size(); ++i) {
67 v[i].value *= orient[i];
68 v[i].derivative *= orient[i];
69 // TODO: hessians
70 }
71 }
72
77 template <class Matrix>
78 void leftPseudoInverse(Matrix& A) const {
79 // Since K^{-1} = K, this is simple...
80 // multiply from left -> modify rows
81 assert(A.N()==orient.size());
82 for (int i=0; i<A.N(); ++i)
83 for (int j=0; j<A.M(); ++j)
84 A[i][j] *= orient[i];
85 }
86
89 operator Dune::BCRSMatrix<Dune::FieldMatrix<Scalar,1,1> >() const
90 {
91 int n = orient.size();
92 Dune::BCRSMatrix<Dune::FieldMatrix<Scalar,1,1> > K(n,n,Dune::BCRSMatrix<Dune::FieldMatrix<Scalar,1,1> >::random);
93 for (int i=0; i<n; ++i)
94 K.incrementrowsize(i);
95 K.endrowsizes();
96 for (int i=0; i<n; ++i)
97 K.addindex(i,i);
98 K.endindices();
99 for (int i=0; i<n; ++i)
100 *K[i].begin() = orient[i];
101 return K;
102 }
103
104 protected:
105 // contains the diagonal of K
106 std::vector<Scalar> orient;
107 };
108
109}
110
111
112#endif
A base class for implementing combiners with diagonal structure.
Definition: combiner.hh:35
void rightTransform(std::vector< VariationalArg< Scalar, n, m > > &v) const
In-place computation of row vectors .
Definition: combiner.hh:64
std::vector< Scalar > orient
Definition: combiner.hh:106
void rightTransform(Matrix &A) const
In-place computation of .
Definition: combiner.hh:54
void leftPseudoInverse(Matrix &A) const
In-place computation of .
Definition: combiner.hh:78
A class that stores values, gradients, and Hessians of evaluated shape functions.