Discontinuous Galerkin Library
#include "dg/algorithm.h"
Loading...
Searching...
No Matches
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
31template<class Matrix, class Container>
33{
37
39 GeneralHelmholtz() = default;
40
47 m_alpha(alpha), m_matrix(matrix), m_chi( m_matrix.weights())
48 {
49 dg::blas1::copy( 1., m_chi);
50 }
51
53 template<class ...Params>
54 void construct( Params&& ...ps)
55 {
56 //construct and swap
57 *this = GeneralHelmholtz( std::forward<Params>( ps)...);
58 }
59
61 const Container& weights()const {return m_matrix.weights();}
63 const Container& precond()const {return m_matrix.precond();}
64
72 template<class ContainerType0, class ContainerType1>
73 void symv( const ContainerType0& x, ContainerType1& y)
74 {
75 if( m_alpha != 0)
76 blas2::symv( m_matrix, x, y);
77 dg::blas1::pointwiseDot( 1., m_chi, x, -m_alpha, y);
78
79 }
80
83 return m_matrix;
84 }
86 const Matrix& matrix()const{
87 return m_matrix;
88 }
94 value_type& alpha( ){ return m_alpha;}
100 value_type alpha( ) const {return m_alpha;}
107 template<class ContainerType0>
108 void set_chi( const ContainerType0& chi) {
109 dg::blas1::copy( chi, m_chi);
110 }
115 const Container& chi() const{return m_chi;}
116 private:
117 value_type m_alpha;
118 Matrix m_matrix;
119 Container m_chi;
120};
121
125template<class Geometry, class Matrix, class Container, class ContainerTmp = Container>
130template<class Geometry, class Matrix, class Container, class ContainerTmp = Container>
135template<class Geometry, class Matrix, class Container, class ContainerTmp = Container>
140template<class Geometry, class Matrix, class Container, class ContainerTmp = Container>
142
157template< class Geometry, class Matrix, class Container>
159{
161 using geometry_type = Geometry;
175 Helmholtz2( const Geometry& g, value_type alpha = 1., direction dir = dg::forward, value_type jfactor=1.)
176 {
177 construct( g, alpha, dir, jfactor);
178 }
190 Helmholtz2( const Geometry& g, bc bcx, bc bcy, value_type alpha = 1., direction dir = dg::forward, value_type jfactor=1.)
191 {
192 construct( g, bcx, bcy, alpha, dir, jfactor);
193 }
195 void construct( const Geometry& g, bc bcx, bc bcy, value_type alpha = 1, direction dir = dg::forward, value_type jfactor = 1.)
196 {
197 m_laplaceM.construct( g, bcx, bcy, dir, jfactor);
198 dg::assign( dg::evaluate( dg::one, g), temp1_);
199 dg::assign( dg::evaluate( dg::one, g), temp2_);
200 alpha_ = alpha;
201 }
203 void construct( const Geometry& g, value_type alpha = 1, direction dir = dg::forward, value_type jfactor = 1.)
204 {
205 construct( g, g.bcx(), g.bcy(), alpha, dir, jfactor);
206 }
216 void symv(const Container& x, Container& y)
217 {
218 if( alpha_ != 0)
219 {
220 blas2::symv( m_laplaceM, x, temp1_); // temp1_ = -nabla_perp^2 x
221 blas1::pointwiseDivide(temp1_, chi_, y); //temp2_ = (chi^-1)*nabla_perp^2 x
222 blas2::symv( m_laplaceM, y, temp2_);//temp2_ = nabla_perp^2 *(chi^-1)*nabla_perp^2 x
223 }
224 blas1::pointwiseDot( chi_, x, y); //y = chi*x
225 blas1::axpby( 1., y, -2.*alpha_, temp1_, y);
226 blas1::axpby( alpha_*alpha_, temp2_, 1., y, y);
227 }
229 const Container& weights()const {return m_laplaceM.weights();}
235 const Container& precond()const {return m_laplaceM.precond();}
240 value_type& alpha( ){ return alpha_;}
245 value_type alpha( ) const {return alpha_;}
251 void set_chi( const Container& chi) {chi_=chi; }
257 const Container& chi()const {return chi_;}
258 private:
260 Container temp1_, temp2_;
261 Container chi_;
262 value_type alpha_;
263};
265template< class M, class V>
266struct TensorTraits< GeneralHelmholtz<M, V> >
267{
269 using tensor_category = SelfMadeMatrixTag;
270};
271template< class G, class M, class V>
272struct TensorTraits< Helmholtz2<G, M, V> >
273{
275 using tensor_category = SelfMadeMatrixTag;
276};
278
279
280} //namespace dg
281
A 2d negative elliptic differential operator .
Definition elliptic.h:263
General negative elliptic operators.
DG_DEVICE T one(T, Ts ...)
Definition functions.h:24
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
Definition blas1.h:243
void axpby(value_type alpha, const ContainerType1 &x, value_type1 beta, ContainerType &y)
Definition blas1.h:306
void pointwiseDot(value_type alpha, const ContainerType1 &x1, const ContainerType2 &x2, value_type1 beta, ContainerType &y)
Definition blas1.h:406
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:767
void pointwiseDivide(value_type alpha, const ContainerType1 &x1, const ContainerType2 &x2, value_type1 beta, ContainerType &y)
Definition blas1.h:495
void symv(MatrixType &&M, const ContainerType1 &x, ContainerType2 &y)
Definition blas2.h:331
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
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition tensor_traits.h:45
auto evaluate(Functor &&f, const Topology &g)
Evaluate a function on grid coordinates
Definition evaluation.h:74
dg::bc bcy
dg::DVec Container
dg::bc bcx
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Ell Sparse Block Matrix format.
Definition sparseblockmat.h:46
A general Helmholtz-type operator .
Definition helmholtz.h:33
value_type & alpha()
Change alpha.
Definition helmholtz.h:94
GeneralHelmholtz()=default
empty object ( no memory allocation)
const Container & chi() const
Access chi.
Definition helmholtz.h:115
void symv(const ContainerType0 &x, ContainerType1 &y)
Compute.
Definition helmholtz.h:73
get_value_type< Container > value_type
Definition helmholtz.h:36
void set_chi(const ContainerType0 &chi)
Set Chi in the above formula.
Definition helmholtz.h:108
const Matrix & matrix() const
Read access to Matrix object.
Definition helmholtz.h:86
value_type alpha() const
Access alpha.
Definition helmholtz.h:100
Matrix & matrix()
Write access to Matrix object.
Definition helmholtz.h:82
const Container & weights() const
Call weights() of Matrix class.
Definition helmholtz.h:61
Container container_type
Definition helmholtz.h:35
void construct(Params &&...ps)
Perfect forward parameters to one of the constructors.
Definition helmholtz.h:54
const Container & precond() const
Call precond() of Matrix class.
Definition helmholtz.h:63
GeneralHelmholtz(value_type alpha, Matrix matrix)
Construct from given Matrix object.
Definition helmholtz.h:46
DEPRECATED, Matrix class that represents a more general Helmholtz-type operator.
Definition helmholtz.h:159
get_value_type< Container > value_type
Definition helmholtz.h:163
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:190
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:195
void set_chi(const Container &chi)
Set Chi in the above formula.
Definition helmholtz.h:251
Geometry geometry_type
Definition helmholtz.h:161
void construct(const Geometry &g, value_type alpha=1, direction dir=dg::forward, value_type jfactor=1.)
Construct Helmholtz2 operator.
Definition helmholtz.h:203
const Container & precond() const
Preconditioner to use in conjugate gradient solvers.
Definition helmholtz.h:235
Container container_type
Definition helmholtz.h:160
const Container & weights() const
Return the weights making the operator self-adjoint.
Definition helmholtz.h:229
void symv(const Container &x, Container &y)
apply operator
Definition helmholtz.h:216
const Container & chi() const
Access chi.
Definition helmholtz.h:257
Helmholtz2(const Geometry &g, value_type alpha=1., direction dir=dg::forward, value_type jfactor=1.)
Construct Helmholtz2 operator.
Definition helmholtz.h:175
value_type alpha() const
Access alpha.
Definition helmholtz.h:245
value_type & alpha()
Change alpha.
Definition helmholtz.h:240
Helmholtz2()
empty object ( no memory allocation)
Definition helmholtz.h:165
NotATensorTag tensor_category
Definition tensor_traits.h:40
double value_type