Extension: Matrix functions
#include "dg/matrix/matrix.h"
polarization_init.h
Go to the documentation of this file.
1#pragma once
2
3#include "dg/algorithm.h"
4
5namespace dg {
6namespace mat {
7
16template <class Geometry, class Matrix, class Container>
18{
19 public:
20 using geometry_type = Geometry;
21 using matrix_type = Matrix;
22 using container_type = Container;
35 PolChargeN( const Geometry& g,
36 direction dir = forward, value_type jfactor=1.):
37 PolChargeN( g, g.bcx(), g.bcy(), dir, jfactor)
38 {
39 }
40
51 PolChargeN( const Geometry& g, bc bcx, bc bcy,
52 direction dir = forward,
53 value_type jfactor=1.):
54 m_gamma(-0.5, {g, bcx, bcy, dir, jfactor})
55 {
56 m_ell.construct(g, bcx, bcy, dir, jfactor );
59
60
61 m_tempx = m_tempx2 = m_tempy = m_tempy2 = m_temp;
62 dg::blas2::transfer( dg::create::dx( g, bcx, dir), m_rightx);
63 dg::blas2::transfer( dg::create::dy( g, bcy, dir), m_righty);
64
65 dg::assign( dg::create::inv_volume(g), m_inv_weights);
66 dg::assign( dg::create::volume(g), m_weights);
67 dg::assign( dg::create::inv_weights(g), m_precond);
68 m_temp = m_tempx = m_tempy = m_inv_weights;
69 m_chi=g.metric();
70 m_sigma = m_vol = dg::tensor::volume(m_chi);
71 dg::assign( dg::create::weights(g), m_weights_wo_vol);
72 }
73
75 template<class ...Params>
76 void construct( Params&& ...ps)
77 {
78 //construct and swap
79 *this = PolChargeN( std::forward<Params>( ps)...);
80 }
81
82 template<class ContainerType0>
83 void set_phi( const ContainerType0& phi)
84 {
85 m_phi = phi;
86 }
87 template<class ContainerType0>
88 void set_dxphi( const ContainerType0& dxphi)
89 {
90 m_dxphi = dxphi;
91 }
92 template<class ContainerType0>
93 void set_dyphi( const ContainerType0& dyphi)
94 {
95 m_dyphi = dyphi;
96 }
97 template<class ContainerType0>
98 void set_lapphi( const ContainerType0& lapphi)
99 {
100 m_lapphi = lapphi;
101 }
108 const Container& weights()const {
109 return m_ell.weights();
110 }
118 const Container& precond()const {
119 return m_ell.precond();
120 }
129 template<class ContainerType0, class ContainerType1>
130 void operator()( const ContainerType0& x, ContainerType1& y){
131 symv( 1., x, 0., y);
132 }
133
142 template<class ContainerType0, class ContainerType1>
143 void symv( const ContainerType0& x, ContainerType1& y){
144 symv( 1., x, 0., y);
145 }
156 template<class ContainerType0, class ContainerType1>
157 void symv( value_type alpha, const ContainerType0& x, value_type beta, ContainerType1& y)
158 {
159 //non-symmetric via analytical dx phi, dy phi and lap phi
160 dg::blas1::copy(x, m_temp);
161 dg::blas1::plus( m_temp, -1.);
162 dg::blas2::gemv( m_rightx, m_temp, m_tempx2); //R_x*f
163 dg::blas2::gemv( m_righty, m_temp, m_tempy2); //R_y*f
164
165 dg::tensor::scalar_product2d(1., 1., m_dxphi, m_dyphi, m_chi, 1., m_tempx2, m_tempy2, 0., y); // y= nabla phi chi nabla (N-1)
166 dg::blas1::pointwiseDot(m_lapphi, x, m_tempx); // m_temp = N Lap phi
167
168 dg::blas1::axpbypgz(1.0, m_tempx, 1.0, m_temp, 1.0, y);
169 dg::blas1::scal(y,-1.0); //y = -nabla phi chi nabla (N-1) -N Lap phi - (N-1)
170
171 //non-symmetric (only m_phi and x as input)
172// dg::blas2::gemv( m_rightx, m_phi, m_dxphi); //R_x*f
173// dg::blas2::gemv( m_righty, m_phi, m_dyphi); //R_y*f
174// dg::blas1::copy(x, m_temp);
175// dg::blas1::plus( m_temp, -1.);
176// dg::blas2::gemv( m_rightx, m_temp, m_tempx2); //R_x*f
177// dg::blas2::gemv( m_righty, m_temp, m_tempy2); //R_y*f
178//
179// dg::tensor::scalar_product2d(1., 1., m_dxphi, m_dyphi, m_chi, 1., m_tempx2, m_tempy2, 0., y); // y= nabla phi chi nabla (N-1)
180// dg::blas2::symv(m_ell, m_phi, m_lapphi);
181// dg::blas1::pointwiseDot(m_lapphi, x, m_tempx); // m_tempx = -N Lap phi
182//
183// dg::blas1::axpbypgz(-1.0, m_tempx, 1.0, m_temp, 0.0, y);;
184// dg::blas1::scal(y,-1.0);
185//
186// non-symmetric mixed analyital (only m_phi, m_lapphi and x)
187// dg::blas2::gemv( m_rightx, m_phi, m_dxphi); //R_x*f
188// dg::blas2::gemv( m_righty, m_phi, m_dyphi); //R_y*f
189// dg::blas1::copy(x, m_temp);
190// dg::blas1::plus( m_temp, -1.);
191// dg::blas2::gemv( m_rightx, m_temp, m_tempx2); //R_x*f
192// dg::blas2::gemv( m_righty, m_temp, m_tempy2); //R_y*f
193//
194// dg::tensor::scalar_product2d(1., 1., m_dxphi, m_dyphi, m_chi, 1., m_tempx2, m_tempy2, 0., y); // y= nabla phi chi nabla (N-1)
195// dg::blas1::pointwiseDot(m_lapphi, x, m_tempx); // m_temp = N Lap phi
196//
197// dg::blas1::axpbypgz(1.0, m_tempx, 1.0, m_temp, 1.0, y);
198// dg::blas1::scal(y,-1.0);
199//
200 //symmetric discr: only -lap term on rhs //TODO converges to non-physical solution
201// m_ell.set_chi(x);
202// m_ell.symv(1.0, m_phi, 0.0 , y);
203// dg::blas1::copy(x, m_temp);
204// dg::blas1::plus( m_temp, -1.);
205// dg::blas1::axpby(-1.0, m_temp, 1.0, y);
206//
207 }
208
209 private:
212 Container m_phi, m_dxphi,m_dyphi, m_lapphi, m_temp, m_tempx, m_tempx2, m_tempy, m_tempy2;
213
214 SparseTensor<Container> m_chi, m_metric;
215 Container m_sigma, m_vol;
216 Container m_weights, m_inv_weights, m_precond, m_weights_wo_vol;
217
218 Matrix m_rightx, m_righty;
219
220};
221
222} //namespace mat
223
224template< class G, class M, class V>
225struct TensorTraits< mat::PolChargeN<G, M, V> >
226{
229};
230
231} //namespace dg
EXPERIMENTAL polarization solver class for N.
Definition: polarization_init.h:18
void set_phi(const ContainerType0 &phi)
Definition: polarization_init.h:83
Geometry geometry_type
Definition: polarization_init.h:20
void set_dyphi(const ContainerType0 &dyphi)
Definition: polarization_init.h:93
void operator()(const ContainerType0 &x, ContainerType1 &y)
Compute elliptic term and store in output.
Definition: polarization_init.h:130
Container container_type
Definition: polarization_init.h:22
void symv(value_type alpha, const ContainerType0 &x, value_type beta, ContainerType1 &y)
Compute elliptic term and add to output.
Definition: polarization_init.h:157
void set_dxphi(const ContainerType0 &dxphi)
Definition: polarization_init.h:88
const Container & weights() const
Return the vector making the matrix symmetric.
Definition: polarization_init.h:108
Matrix matrix_type
Definition: polarization_init.h:21
PolChargeN()
empty object ( no memory allocation)
Definition: polarization_init.h:25
get_value_type< Container > value_type
Definition: polarization_init.h:23
void symv(const ContainerType0 &x, ContainerType1 &y)
Compute elliptic term and store in output.
Definition: polarization_init.h:143
const Container & precond() const
Return the default preconditioner to use in conjugate gradient.
Definition: polarization_init.h:118
void set_lapphi(const ContainerType0 &lapphi)
Definition: polarization_init.h:98
void construct(Params &&...ps)
Perfect forward parameters to one of the constructors.
Definition: polarization_init.h:76
PolChargeN(const Geometry &g, bc bcx, bc bcy, direction dir=forward, value_type jfactor=1.)
Construct from grid and boundary conditions.
Definition: polarization_init.h:51
PolChargeN(const Geometry &g, direction dir=forward, value_type jfactor=1.)
Construct from Grid.
Definition: polarization_init.h:35
void assign(const from_ContainerType &from, ContainerType &to, Params &&... ps)
static DG_DEVICE double one(double x)
static DG_DEVICE double zero(double x)
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
void plus(ContainerType &x, get_value_type< ContainerType > alpha)
void axpbypgz(get_value_type< ContainerType > alpha, const ContainerType1 &x, get_value_type< ContainerType > beta, const ContainerType2 &y, get_value_type< ContainerType > gamma, ContainerType &z)
void scal(ContainerType &x, get_value_type< ContainerType > alpha)
void pointwiseDot(get_value_type< ContainerType > alpha, const ContainerType1 &x1, const ContainerType2 &x2, get_value_type< ContainerType > beta, ContainerType &y)
void gemv(get_value_type< ContainerType1 > alpha, MatrixType &&M, const ContainerType1 &x, get_value_type< ContainerType1 > beta, ContainerType2 &y)
void transfer(const MatrixType &x, AnotherMatrixType &y)
EllSparseBlockMat< real_type > dx(const aRealTopology2d< real_type > &g, bc bcx, direction dir=centered)
EllSparseBlockMat< real_type > dy(const aRealTopology2d< real_type > &g, bc bcy, direction dir=centered)
direction
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
MPI_Vector< thrust::host_vector< real_type > > weights(const aRealMPITopology2d< real_type > &g)
MPI_Vector< thrust::host_vector< real_type > > inv_weights(const aRealMPITopology2d< real_type > &g)
get_host_vector< Geometry > volume(const Geometry &g)
get_host_vector< Geometry > inv_volume(const Geometry &g)
void scalar_product2d(get_value_type< ContainerType0 > alpha, const ContainerTypeL &lambda, const ContainerType0 &v0, const ContainerType1 &v1, const SparseTensor< ContainerType2 > &t, const ContainerTypeM &mu, const ContainerType3 &w0, const ContainerType4 &w1, get_value_type< ContainerType0 > beta, ContainerType5 &y)
ContainerType volume(const SparseTensor< ContainerType > &t)
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Classes for Krylov space approximations of a Matrix-Vector product.
get_value_type< V > value_type
Definition: polarization_init.h:227