Discontinuous Galerkin Library
#include "dg/algorithm.h"
helmholtz.h
Go to the documentation of this file.
1#pragma once
2
3#include <cassert>
4
5#include "blas.h"
6#include "elliptic.h"
7
12namespace dg{
13
32template<class Matrix, class Container>
34{
35 using matrix_type = Matrix;
36 using container_type = Container;
38
40 GeneralHelmholtz() = default;
41
48 m_alpha(alpha), m_matrix(matrix), m_chi( m_matrix.weights())
49 {
50 dg::blas1::copy( 1., m_chi);
51 }
52
54 template<class ...Params>
55 void construct( Params&& ...ps)
56 {
57 //construct and swap
58 *this = GeneralHelmholtz( std::forward<Params>( ps)...);
59 }
60
62 const Container& weights()const {return m_matrix.weights();}
64 const Container& precond()const {return m_matrix.precond();}
65
73 template<class ContainerType0, class ContainerType1>
74 void symv( const ContainerType0& x, ContainerType1& y)
75 {
76 if( m_alpha != 0)
77 blas2::symv( m_matrix, x, y);
78 dg::blas1::pointwiseDot( 1., m_chi, x, -m_alpha, y);
79
80 }
81
83 Matrix& matrix(){
84 return m_matrix;
85 }
87 const Matrix& matrix()const{
88 return m_matrix;
89 }
95 value_type& alpha( ){ return m_alpha;}
101 value_type alpha( ) const {return m_alpha;}
108 template<class ContainerType0>
109 void set_chi( const ContainerType0& chi) {
110 dg::blas1::copy( chi, m_chi);
111 }
116 const Container& chi() const{return m_chi;}
117 private:
118 value_type m_alpha;
119 Matrix m_matrix;
120 Container m_chi;
121};
122
126template<class Geometry, class Matrix, class Container>
131template<class Geometry, class Matrix, class Container>
136template<class Geometry, class Matrix, class Container>
141template<class Geometry, class Matrix, class Container>
143
158template< class Geometry, class Matrix, class Container>
160{
161 using container_type = Container;
162 using geometry_type = Geometry;
163 using matrix_type = Matrix;
176 Helmholtz2( const Geometry& g, value_type alpha = 1., direction dir = dg::forward, value_type jfactor=1.)
177 {
178 construct( g, alpha, dir, jfactor);
179 }
191 Helmholtz2( const Geometry& g, bc bcx, bc bcy, value_type alpha = 1., direction dir = dg::forward, value_type jfactor=1.)
192 {
193 construct( g, bcx, bcy, alpha, dir, jfactor);
194 }
196 void construct( const Geometry& g, bc bcx, bc bcy, value_type alpha = 1, direction dir = dg::forward, value_type jfactor = 1.)
197 {
198 m_laplaceM.construct( g, bcx, bcy, dir, jfactor);
199 dg::assign( dg::evaluate( dg::one, g), temp1_);
200 dg::assign( dg::evaluate( dg::one, g), temp2_);
201 alpha_ = alpha;
202 }
204 void construct( const Geometry& g, value_type alpha = 1, direction dir = dg::forward, value_type jfactor = 1.)
205 {
206 construct( g, g.bcx(), g.bcy(), alpha, dir, jfactor);
207 }
217 void symv(const Container& x, Container& y)
218 {
219 if( alpha_ != 0)
220 {
221 blas2::symv( m_laplaceM, x, temp1_); // temp1_ = -nabla_perp^2 x
222 blas1::pointwiseDivide(temp1_, chi_, y); //temp2_ = (chi^-1)*nabla_perp^2 x
223 blas2::symv( m_laplaceM, y, temp2_);//temp2_ = nabla_perp^2 *(chi^-1)*nabla_perp^2 x
224 }
225 blas1::pointwiseDot( chi_, x, y); //y = chi*x
226 blas1::axpby( 1., y, -2.*alpha_, temp1_, y);
227 blas1::axpby( alpha_*alpha_, temp2_, 1., y, y);
228 }
230 const Container& weights()const {return m_laplaceM.weights();}
236 const Container& precond()const {return m_laplaceM.precond();}
241 value_type& alpha( ){ return alpha_;}
246 value_type alpha( ) const {return alpha_;}
252 void set_chi( const Container& chi) {chi_=chi; }
258 const Container& chi()const {return chi_;}
259 private:
261 Container temp1_, temp2_;
262 Container chi_;
263 value_type alpha_;
264};
266template< class M, class V>
267struct TensorTraits< GeneralHelmholtz<M, V> >
268{
269 using value_type = get_value_type<V>;
270 using tensor_category = SelfMadeMatrixTag;
271};
272template< class G, class M, class V>
273struct TensorTraits< Helmholtz2<G, M, V> >
274{
275 using value_type = get_value_type<V>;
276 using tensor_category = SelfMadeMatrixTag;
277};
279
280
281} //namespace dg
282
A 2d negative elliptic differential operator .
Definition: elliptic.h:231
General negative elliptic operators.
void assign(const from_ContainerType &from, ContainerType &to, Params &&... ps)
Generic way to assign the contents of a from_ContainerType object to a ContainerType object optionall...
Definition: blas1.h:665
static DG_DEVICE double one(double x)
Definition: functions.h:20
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
Definition: blas1.h:164
void axpby(get_value_type< ContainerType > alpha, const ContainerType1 &x, get_value_type< ContainerType > beta, ContainerType &y)
Definition: blas1.h:231
void pointwiseDivide(get_value_type< ContainerType > alpha, const ContainerType1 &x1, const ContainerType2 &x2, get_value_type< ContainerType > beta, ContainerType &y)
Definition: blas1.h:428
void pointwiseDot(get_value_type< ContainerType > alpha, const ContainerType1 &x1, const ContainerType2 &x2, get_value_type< ContainerType > beta, ContainerType &y)
Definition: blas1.h:336
void symv(MatrixType &&M, const ContainerType1 &x, ContainerType2 &y)
Definition: blas2.h:287
bc
Switch between boundary conditions.
Definition: enums.h:15
direction
Direction of a discrete derivative.
Definition: enums.h:97
@ forward
forward derivative (cell to the right and current cell)
Definition: enums.h:98
@ y
y direction
@ x
x direction
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
Evaluate a 1d function on grid coordinates.
Definition: evaluation.h:67
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition: tensor_traits.h:38
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
A general Helmholtz-type operator .
Definition: helmholtz.h:34
Matrix matrix_type
Definition: helmholtz.h:35
value_type & alpha()
Change alpha.
Definition: helmholtz.h:95
GeneralHelmholtz()=default
empty object ( no memory allocation)
const Container & chi() const
Access chi.
Definition: helmholtz.h:116
void symv(const ContainerType0 &x, ContainerType1 &y)
Compute.
Definition: helmholtz.h:74
get_value_type< Container > value_type
Definition: helmholtz.h:37
void set_chi(const ContainerType0 &chi)
Set Chi in the above formula.
Definition: helmholtz.h:109
const Matrix & matrix() const
Read access to Matrix object.
Definition: helmholtz.h:87
value_type alpha() const
Access alpha.
Definition: helmholtz.h:101
Matrix & matrix()
Write access to Matrix object.
Definition: helmholtz.h:83
const Container & weights() const
Call weights() of Matrix class.
Definition: helmholtz.h:62
Container container_type
Definition: helmholtz.h:36
void construct(Params &&...ps)
Perfect forward parameters to one of the constructors.
Definition: helmholtz.h:55
const Container & precond() const
Call precond() of Matrix class.
Definition: helmholtz.h:64
GeneralHelmholtz(value_type alpha, Matrix matrix)
Construct from given Matrix object.
Definition: helmholtz.h:47
DEPRECATED, Matrix class that represents a more general Helmholtz-type operator.
Definition: helmholtz.h:160
get_value_type< Container > value_type
Definition: helmholtz.h:164
Helmholtz2(const Geometry &g, bc bcx, bc bcy, value_type alpha=1., direction dir=dg::forward, value_type jfactor=1.)
Construct Helmholtz2 operator.
Definition: helmholtz.h:191
void construct(const Geometry &g, bc bcx, bc bcy, value_type alpha=1, direction dir=dg::forward, value_type jfactor=1.)
Construct Helmholtz2 operator.
Definition: helmholtz.h:196
void set_chi(const Container &chi)
Set Chi in the above formula.
Definition: helmholtz.h:252
Geometry geometry_type
Definition: helmholtz.h:162
void construct(const Geometry &g, value_type alpha=1, direction dir=dg::forward, value_type jfactor=1.)
Construct Helmholtz2 operator.
Definition: helmholtz.h:204
const Container & precond() const
Preconditioner to use in conjugate gradient solvers.
Definition: helmholtz.h:236
Container container_type
Definition: helmholtz.h:161
const Container & weights() const
Return the weights making the operator self-adjoint.
Definition: helmholtz.h:230
void symv(const Container &x, Container &y)
apply operator
Definition: helmholtz.h:217
const Container & chi() const
Access chi.
Definition: helmholtz.h:258
Helmholtz2(const Geometry &g, value_type alpha=1., direction dir=dg::forward, value_type jfactor=1.)
Construct Helmholtz2 operator.
Definition: helmholtz.h:176
value_type alpha() const
Access alpha.
Definition: helmholtz.h:246
value_type & alpha()
Change alpha.
Definition: helmholtz.h:241
Matrix matrix_type
Definition: helmholtz.h:163
Helmholtz2()
empty object ( no memory allocation)
Definition: helmholtz.h:166
NotATensorTag tensor_category
Definition: tensor_traits.h:33
void value_type
Definition: tensor_traits.h:32