27template<
class Container>
 
   48    template<
class Container2>
 
   54    unsigned size()
const {
return O.size();}
 
   73        unsigned size = 
M.size();
 
   82                    y[i] = 
O[i]*
x[i] + 
P[i]*
x[i+1];
 
   83                else if ( i == 
size -1 )
 
   84                    y[i] = 
M[i]*
x[i-1] + 
O[i] * 
x[i];
 
   86                    y[i] = 
M[i]*
x[i-1] + 
O[i] * 
x[i] + 
P[i] *
x[i+1];
 
   87            }, 
M.size(), 
M, 
O, 
P, 
x, 
y);
 
 
   92        unsigned size = 
M.size();
 
   93        thrust::host_vector<int> A_row_offsets(
size+1), A_column_indices( 3*
size-2);
 
   94        thrust::host_vector<value_type> A_values( 3*
size-2);
 
   96        A_column_indices[0] = 0;
 
   99        A_column_indices[1] = 1;
 
  102        A_row_offsets[1] = 2;
 
  104        for( 
unsigned i=1;i<
size; i++)
 
  106            A_column_indices[3*i-1+0] = i-1;
 
  107            A_values[3*i-1+0] = 
M[i];
 
  109            A_column_indices[3*i-1+1] = i;
 
  110            A_values[3*i-1+1] = 
O[i];
 
  114                A_column_indices[3*i-1+2] = i+1;
 
  115                A_values[3*i-1+2] = 
P[i];
 
  117            A_row_offsets[i+1] = A_row_offsets[i] + ( i != (
size-1) ? 3 : 2);
 
  119        return {
size, 
size, A_row_offsets, A_column_indices, A_values};
 
 
 
  135template<
class value_type>
 
  147    void operator()( 
const thrust::host_vector<value_type>& 
y, thrust::host_vector<value_type>& x)
 const 
  149        unsigned size = M.size();
 
  150        thrust::host_vector<value_type> ci(size), di(size);
 
  154        for( 
unsigned i=1; i<size; i++)
 
  156            ci[i] = P[i]/ ( O[i] -M[i]*ci[i-1]);
 
  157            di[i] = (
y[i]-M[i]*di[i-1])/(O[i] -M[i]*ci[i-1]);
 
  159        x[size-1] = di[size-1];
 
  160        for( 
int i=size-2; i>=0; i--)
 
  161            x[i] = di[i] - ci[i]*
x[i+1];
 
 
  164    thrust::host_vector<value_type> M, O, P;
 
 
  173template<
class Container>
 
  181    unsigned& 
nz() { 
return m_nz;}
 
  182    unsigned nz()
 const { 
return m_nz;}
 
  183    template<
class Container2>
 
  191    template<
class ContainerType0, 
class ContainerType1>
 
  194        unsigned size = m_y.size()*m_x.size()*m_nz;
 
  195        unsigned Nx = m_x.size(), Ny = m_y.size();
 
  205            unsigned j = (i/Nx)/Ny;
 
  206            unsigned k = (i/Nx)%Ny, l = i%Nx;
 
  212                    b = xO[l]*
x[(j*Ny+k)*Nx+l] + xP[l]*
x[(j*Ny+k)*Nx+l+1];
 
  213                    c = xO[l]*
x[(j*Ny+k+1)*Nx+l] + xP[l]*
x[(j*Ny+k+1)*Nx+l+1];
 
  214                    y[i] = yO[k]*b + yP[k]*c;
 
  218                    a = xO[l]*
x[(j*Ny+k-1)*Nx+l] + xP[l]*
x[(j*Ny+k-1)*Nx+l+1];
 
  219                    b = xO[l]*
x[(j*Ny+k)*Nx+l] + xP[l]*
x[(j*Ny+k)*Nx+l+1];
 
  220                    y[i] = yM[k]*a + yO[k]*b;
 
  224                    a = xO[l]*
x[(j*Ny+k-1)*Nx+l] + xP[l]*
x[(j*Ny+k-1)*Nx+l+1];
 
  225                    b = xO[l]*
x[(j*Ny+k)*Nx+l] + xP[l]*
x[(j*Ny+k)*Nx+l+1];
 
  226                    c = xO[l]*
x[(j*Ny+k+1)*Nx+l] + xP[l]*
x[(j*Ny+k+1)*Nx+l+1];
 
  227                    y[i] = yM[k]*a + yO[k]*b + yP[k]*c;
 
  230            else if ( l == Nx -1 )
 
  234                    b = xM[l]*
x[(j*Ny+k)*Nx+l-1] + xO[l]*
x[(j*Ny+k)*Nx+l];
 
  235                    c = xM[l]*
x[(j*Ny+k+1)*Nx+l-1] + xO[l]*
x[(j*Ny+k+1)*Nx+l];
 
  236                    y[i] = yO[k]*b + yP[k]*c;
 
  238                else if ( k == Ny -1)
 
  240                    a = xM[l]*
x[(j*Ny+k-1)*Nx+l-1] + xO[l]*
x[(j*Ny+k-1)*Nx+l];
 
  241                    b = xM[l]*
x[(j*Ny+k)*Nx+l-1] + xO[l]*
x[(j*Ny+k)*Nx+l];
 
  242                    y[i] = yM[k]*a + yO[k]*b;
 
  246                    a = xM[l]*
x[(j*Ny+k-1)*Nx+l-1] + xO[l]*
x[(j*Ny+k-1)*Nx+l];
 
  247                    b = xM[l]*
x[(j*Ny+k)*Nx+l-1] + xO[l]*
x[(j*Ny+k)*Nx+l];
 
  248                    c = xM[l]*
x[(j*Ny+k+1)*Nx+l-1] + xO[l]*
x[(j*Ny+k+1)*Nx+l];
 
  249                    y[i] = yM[k]*a + yO[k]*b + yP[k]*c;
 
  256                    b = xM[l]*
x[(j*Ny+k)*Nx+l-1] + xO[l]*
x[(j*Ny+k)*Nx+l] +
 
  257                        xP[l]*
x[(j*Ny+k)*Nx+l+1];
 
  258                    c = xM[l]*
x[(j*Ny+k+1)*Nx+l-1] + xO[l]*
x[(j*Ny+k+1)*Nx+l] +
 
  259                        xP[l]*
x[(j*Ny+k+1)*Nx+l+1];
 
  260                    y[i] = yO[k]*b + yP[k]*c;
 
  262                else if ( k == Ny -1)
 
  264                    a = xM[l]*
x[(j*Ny+k-1)*Nx+l-1] + xO[l]*
x[(j*Ny+k-1)*Nx+l] +
 
  265                        xP[l]*
x[(j*Ny+k-1)*Nx+l+1];
 
  266                    b = xM[l]*
x[(j*Ny+k)*Nx+l-1] + xO[l]*
x[(j*Ny+k)*Nx+l] +
 
  267                        xP[l]*
x[(j*Ny+k)*Nx+l+1];
 
  268                    y[i] = yM[k]*a + yO[k]*b;
 
  272                    a = xM[l]*
x[(j*Ny+k-1)*Nx+l-1] + xO[l]*
x[(j*Ny+k-1)*Nx+l] +
 
  273                        xP[l]*
x[(j*Ny+k-1)*Nx+l+1];
 
  274                    b = xM[l]*
x[(j*Ny+k)*Nx+l-1] + xO[l]*
x[(j*Ny+k)*Nx+l] +
 
  275                        xP[l]*
x[(j*Ny+k)*Nx+l+1];
 
  276                    c = xM[l]*
x[(j*Ny+k+1)*Nx+l-1] + xO[l]*
x[(j*Ny+k+1)*Nx+l] +
 
  277                        xP[l]*
x[(j*Ny+k+1)*Nx+l+1];
 
  278                    y[i] = yM[k]*a + yO[k]*b + yP[k]*c;
 
  281        }, size, m_y.M, m_y.O, m_y.P, m_x.M, m_x.O, m_x.P, 
x, 
y);
 
 
 
  294template<
class Container>
 
  302        unsigned size = m_t.x().size()*m_t.y().size()*m_t.nz();
 
 
  307    template<
class Container2>
 
  311        unsigned size = m_t.x().size()*m_t.y().size()*m_t.nz();
 
 
  317    template<
class ContainerType0, 
class ContainerType1>
 
  320        unsigned Nx = m_t.x().size(), Ny = m_t.y().size();
 
  330            ci[k*Nx + 0] = P[0]/O[0];
 
  331            di[k*Nx + 0] = 
y[k*Nx + 0]/O[0];
 
  332            for( 
unsigned i=1; i<Nx; i++)
 
  334                ci[k*Nx+i] = P[i]/ ( O[i] -M[i]*ci[k*Nx+i-1]);
 
  335                di[k*Nx+i] = (
y[k*Nx+i]-M[i]*di[k*Nx+i-1])/(O[i] -M[i]*ci[k*Nx+i-1]);
 
  337            x[k*Nx + Nx-1] = di[k*Nx + Nx-1];
 
  338            for( 
int i=Nx-2; i>=0; i--)
 
  339                x[k*Nx+i] = di[k*Nx+i] - ci[k*Nx+i]*
x[k*Nx +i+1];
 
  341        }, m_t.y().size()*m_t.nz(), m_t.x().M, m_t.x().O, m_t.x().P, m_ci, m_di, 
y, m_tmp);
 
  351            unsigned i = l%Nx, j = l/Nx;
 
  352            ci[(j*Ny+0)*Nx + i] = P[0]/O[0];
 
  353            di[(j*Ny+0)*Nx + i] = 
y[(j*Ny+0)*Nx + i]/O[0];
 
  354            for( 
unsigned k=1; k<Ny; k++)
 
  356                ci[(j*Ny+k)*Nx+i] = P[k]/ ( O[k] -M[k]*ci[(j*Ny+k-1)*Nx+i]);
 
  357                di[(j*Ny+k)*Nx+i] = (
y[(j*Ny+k)*Nx+i]-M[k]*di[(j*Ny+k-1)*Nx+i])/(O[k] -M[k]*ci[(j*Ny+k-1)*Nx+i]);
 
  359            x[(j*Ny+Ny-1)*Nx + i] = di[(j*Ny+Ny-1)*Nx + i];
 
  360            for( 
int k=Ny-2; k>=0; k--)
 
  361                x[(j*Ny+k)*Nx+i] = di[(j*Ny+k)*Nx+i] - ci[(j*Ny+k)*Nx+i]*
x[(j*Ny+k+1)*Nx +i];
 
  363        }, m_t.x().size()*m_t.nz(), m_t.y().M, m_t.y().O, m_t.y().P, m_ci, m_di,m_tmp, 
x);
 
 
 
  409template<
class real_type>
 
  415    std::vector<real_type> xa( g.
n()+2);
 
  416    xa[0] = (xx[g.
n()-1]-2)*g.
h()/2.; 
 
  417    for( 
unsigned i=0; i<g.
n(); i++)
 
  418        xa[i+1]=xx[i]*g.
h()/2.;
 
  419    xa[g.
n()+1] = (xx[0]+2)*g.
h()/2.; 
 
  420    const real_type* 
x = &xa[1];
 
  421    real_type xleft = -g.
h()/2., xright = g.
h()/2.;
 
  423    for( 
unsigned i=0; i<g.
N(); i++)
 
  424        for( 
int k=0; k<(int)g.
n(); k++)
 
  429                A.
O[0] = (4*
x[0]-6*xleft+2*
x[1])/6./
weights[0];
 
  434            if( (i==g.
N()-1) && (k == (
int)g.
n()-1))
 
  437                A.
O[I] = (-4*
x[k]+6*xright-2*
x[k-1])/6./
weights[I];
 
 
  449template<
class real_type>
 
  456    std::vector<real_type> xa( g.
n()+2);
 
  457    xa[0] = (xx[g.
n()-1]-2)*g.
h()/2.; 
 
  458    for( 
unsigned i=0; i<g.
n(); i++)
 
  459        xa[i+1]=xx[i]*g.
h()/2.;
 
  460    xa[g.
n()+1] = (xx[0]+2)*g.
h()/2.; 
 
  461    const real_type* 
x = &xa[1];
 
  462    real_type xleft = -g.
h()/2., xright = g.
h()/2.;
 
  465    for( 
unsigned i=0; i<g.
N(); i++)
 
  466        for( 
int k=0; k<(int)g.
n(); k++)
 
  471                A.
O[0] = (5*
x[0]-8*xleft+3*
x[1])/8./
weights[0];
 
  476            if( (i==g.
N()-1) && (k == (
int)g.
n()-1))
 
  479                A.
O[I] = (-5*
x[k]+8*xright-3*
x[k-1])/8./
weights[I];
 
 
  491template<
class real_type>
 
  501template<
class real_type>
 
  510template<
class real_type>
 
  520template<
class real_type>
 
  529template<
class real_type>
 
  535    return {g.
gz().size(), my, mx};
 
 
  539template<
class real_type>
 
  548template<
class real_type>
 
  554    return {g.
gz().size(), my, mx};
 
 
  558template<
class real_type>
 
Creation functions for finite element utilities.
 
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 parallel_for(Stencil f, unsigned N, ContainerType &&x, ContainerTypes &&... xs)
; Customizable and generic for loop
Definition blas2.h:413
 
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition tensor_traits.h:45
 
auto weights(const Topology &g)
Nodal weight coefficients.
Definition weights.h:62
 
dg::InverseKroneckerTriDiagonal2d< dg::HVec_t< real_type > > inv_fem_mass(const aRealTopology2d< real_type > &g)
Inverse finite element mass matrix .
Definition fem.h:502
 
dg::InverseKroneckerTriDiagonal2d< dg::HVec_t< real_type > > inv_fem_mass2d(const aRealTopology3d< real_type > &g)
Inverse finite element mass matrix .
Definition fem.h:540
 
thrust::host_vector< real_type > fem_weights(const RealGrid1d< real_type > &g)
finite element weight coefficients
Definition fem_weights.h:54
 
dg::InverseKroneckerTriDiagonal2d< dg::HVec_t< real_type > > inv_fem_linear2const(const aRealTopology2d< real_type > &g)
Inverse finite element mass matrix .
Definition fem.h:521
 
dg::InverseKroneckerTriDiagonal2d< dg::HVec_t< real_type > > inv_fem_linear2const2d(const aRealTopology3d< real_type > &g)
Inverse finite element mass matrix .
Definition fem.h:559
 
dg::KroneckerTriDiagonal2d< dg::HVec_t< real_type > > fem_linear2const2d(const aRealTopology3d< real_type > &g)
finite element projection matrix
Definition fem.h:549
 
dg::TriDiagonal< dg::HVec_t< real_type > > fem_mass(const RealGrid1d< real_type > &g)
finite element projection matrix
Definition fem.h:410
 
dg::KroneckerTriDiagonal2d< dg::HVec_t< real_type > > fem_mass2d(const aRealTopology3d< real_type > &g)
finite element projection matrix
Definition fem.h:530
 
dg::TriDiagonal< dg::HVec_t< real_type > > fem_linear2const(const RealGrid1d< real_type > &g)
finite element projection matrix
Definition fem.h:450
 
#define DG_DEVICE
Expands to __host__ __device__ if compiled with nvcc else is empty.
Definition dg_doc.h:378
 
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
 
static std::vector< real_type > abscissas(unsigned n)
Return Gauss-Legendre nodes on the interval [-1,1].
Definition dlt.h:27
 
Fast inverse tridiagonal sparse matrix in 2d .
Definition fem.h:296
 
InverseKroneckerTriDiagonal2d(const KroneckerTriDiagonal2d< Container > &tri)
Definition fem.h:299
 
InverseKroneckerTriDiagonal2d(const InverseKroneckerTriDiagonal2d< Container2 > &inv_tri)
Definition fem.h:308
 
dg::get_value_type< Container > value_type
Definition fem.h:297
 
InverseKroneckerTriDiagonal2d()=default
 
void operator()(const ContainerType0 &y, ContainerType1 &x)
Definition fem.h:318
 
const KroneckerTriDiagonal2d< Container > & tri() const
Definition fem.h:316
 
DEPRECATED/UNTESTED Fast inverse tridiagonal sparse matrix.
Definition fem.h:137
 
InverseTriDiagonal(const TriDiagonal< thrust::host_vector< value_type > > &tri)
Definition fem.h:139
 
void operator()(const thrust::host_vector< value_type > &y, thrust::host_vector< value_type > &x) const
Definition fem.h:147
 
InverseTriDiagonal()=default
 
Fast tridiagonal sparse matrix in 2d .
Definition fem.h:175
 
KroneckerTriDiagonal2d(unsigned nz, TriDiagonal< Container > my, TriDiagonal< Container > mx)
Definition fem.h:179
 
unsigned nz() const
Definition fem.h:182
 
dg::get_value_type< Container > value_type
Definition fem.h:176
 
unsigned & nz()
Definition fem.h:181
 
KroneckerTriDiagonal2d(const KroneckerTriDiagonal2d< Container2 > &other)
Definition fem.h:184
 
const TriDiagonal< Container > & x() const
Definition fem.h:189
 
const TriDiagonal< Container > & y() const
Definition fem.h:190
 
void operator()(const ContainerType0 &x, ContainerType1 &y) const
Definition fem.h:192
 
KroneckerTriDiagonal2d(TriDiagonal< Container > my, TriDiagonal< Container > mx)
Definition fem.h:178
 
KroneckerTriDiagonal2d()=default
 
The simplest implementation of aRealTopology.
Definition grid.h:710
 
A CSR formatted sparse matrix.
Definition sparsematrix.h:96
 
Fast (shared memory) tridiagonal sparse matrix.
Definition fem.h:29
 
Container P
Uper diagonal ["Plus" +1] P[0] maps to T_01
Definition fem.h:124
 
TriDiagonal(unsigned size)
Allocate size elements for M, O and P.
Definition fem.h:34
 
dg::get_value_type< Container > value_type
Definition fem.h:30
 
void resize(unsigned size)
Resize M, O, and P to given size.
Definition fem.h:58
 
TriDiagonal(const TriDiagonal< Container2 > &other)
Assign M, O, and P from other matrix.
Definition fem.h:49
 
dg::IHMatrix_t< value_type > asIMatrix() const
convert to a sparse matrix format
Definition fem.h:91
 
TriDiagonal(Container M, Container O, Container P)
Directly construct from M, O and P.
Definition fem.h:41
 
unsigned size() const
Definition fem.h:54
 
Container M
Subdiagonal ["Minus" -1] M[0] is ignored M[1] maps to T_10
Definition fem.h:122
 
void operator()(const Container &x, Container &y) const
Compute Matrix-vector product .
Definition fem.h:71
 
Container O
Diagonal ["zerO" 0] O[0] maps to T_00
Definition fem.h:123
 
An abstract base class for Nd-dimensional dG grids.
Definition grid.h:95
 
RealGrid< real_type, 1 > gy() const
Equivalent to grid(1)
Definition grid.h:360
 
real_type h(unsigned u=0) const
Get grid constant  for axis u.
Definition grid.h:256
 
RealGrid< real_type, 1 > gx() const
Equivalent to grid(0)
Definition grid.h:354
 
unsigned size() const
The total number of points.
Definition grid.h:532
 
unsigned n(unsigned u=0) const
Get number of polynomial coefficients  for axis u.
Definition grid.h:262
 
RealGrid< real_type, 1 > gz() const
Equivalent to grid(2)
Definition grid.h:366
 
unsigned N(unsigned u=0) const
Get number of cells  for axis u.
Definition grid.h:265