Discontinuous Galerkin Library
#include "dg/algorithm.h"
xspacelib.h
Go to the documentation of this file.
1#ifndef _DG_XSPACELIB_CUH_
2#define _DG_XSPACELIB_CUH_
3
4#include <thrust/host_vector.h>
5
6#include <cusp/coo_matrix.h>
7#include <cassert>
8
10#include "grid.h"
11#include "dlt.h"
12#include "operator.h"
13#include "operator_tensor.h"
14
15
21namespace dg{
22
39template< class T>
40cusp::csr_matrix< int, T, cusp::host_memory> tensorproduct(
41 const cusp::csr_matrix< int, T, cusp::host_memory>& lhs,
42 const cusp::csr_matrix< int, T, cusp::host_memory>& rhs)
43{
44 //dimensions of the matrix
45 int num_rows = lhs.num_rows*rhs.num_rows;
46 int num_cols = lhs.num_cols*rhs.num_cols;
47 int num_entries = lhs.num_entries* rhs.num_entries;
48 // allocate output matrix
49 cusp::csr_matrix<int, T, cusp::host_memory> A(num_rows, num_cols, num_entries);
50 //LHS x RHS
51 A.row_offsets[0] = 0;
52 int counter = 0;
53 for( unsigned i=0; i<lhs.num_rows; i++)
54 for( unsigned j=0; j<rhs.num_rows; j++)
55 {
56 int num_entries_in_row =
57 (lhs.row_offsets[i+1] - lhs.row_offsets[i])*
58 (rhs.row_offsets[j+1] - rhs.row_offsets[j]);
59 A.row_offsets[i*rhs.num_rows+j+1] =
60 A.row_offsets[i*rhs.num_rows+j] + num_entries_in_row;
61 for( int k=lhs.row_offsets[i]; k<lhs.row_offsets[i+1]; k++)
62 for( int l=rhs.row_offsets[j]; l<rhs.row_offsets[j+1]; l++)
63 {
64 A.column_indices[counter] =
65 lhs.column_indices[k]*rhs.num_cols + rhs.column_indices[l];
66 A.values[counter] = lhs.values[k]*rhs.values[l];
67 counter++;
68 }
69 }
70 return A;
71}
72
73namespace create{
76
86template<class real_type>
88{
89 //create equidistant backward transformation
90 dg::Operator<real_type> backwardeq( g.dlt().backwardEQ());
91 dg::Operator<real_type> forward( g.dlt().forward());
92 dg::Operator<real_type> backward1d = backwardeq*forward;
93
94 return (dg::IHMatrix_t<real_type>)dg::tensorproduct( g.N(), backward1d);
95}
96
98template<class real_type>
100{
101 //create equidistant backward transformation
102 auto transformX = backscatter( g.gx());
103 auto transformY = backscatter( g.gy());
104 return dg::tensorproduct( transformY, transformX);
105}
106
108template<class real_type>
110{
111 auto transformX = backscatter( g.gx());
112 auto transformY = backscatter( g.gy());
113 auto transformZ = backscatter( g.gz());
114 return dg::tensorproduct( transformZ, dg::tensorproduct(transformY, transformX));
115}
116
128template<class real_type>
130{
131 //create equidistant backward transformation
132 dg::Operator<real_type> backwardeq( g.dlt().backwardEQ());
133 dg::Operator<real_type> backward( g.dlt().backward());
134 dg::Operator<real_type> forward1d = backward*dg::invert(backwardeq);
135
136 return (dg::IHMatrix_t<real_type>)dg::tensorproduct( g.N(), forward1d);
137}
139template<class real_type>
141{
142 //create equidistant backward transformation
143 auto transformX = inv_backscatter( g.gx());
144 auto transformY = inv_backscatter( g.gy());
145 return dg::tensorproduct( transformY, transformX);
146}
147
149template<class real_type>
151{
152 auto transformX = inv_backscatter( g.gx());
153 auto transformY = inv_backscatter( g.gy());
154 auto transformZ = inv_backscatter( g.gz());
155 return dg::tensorproduct( transformZ, dg::tensorproduct(transformY, transformX));
156}
157
159
160} //namespace create
161} //namespace dg
162#endif // _DG_XSPACELIB_CUH_
The discrete legendre trafo class.
base topology classes
@ backward
backward derivative (cell to the left and current cell)
Definition: enums.h:99
@ forward
forward derivative (cell to the right and current cell)
Definition: enums.h:98
dg::Operator< T > invert(const dg::Operator< T > &in)
Alias for dg::create::inverse. Compute inverse of square matrix.
Definition: operator.h:695
Operator< T > tensorproduct(const Operator< T > &op1, const Operator< T > &op2)
Form the tensor product between two operators.
Definition: operator_tensor.h:27
dg::IHMatrix_t< real_type > backscatter(const RealGrid1d< real_type > &g)
Create a matrix that interpolates values to an equidistant grid ready for visualisation.
Definition: xspacelib.h:87
dg::IHMatrix_t< real_type > inv_backscatter(const RealGrid1d< real_type > &g)
Create a matrix that transforms values from an equidistant grid back to a dg grid.
Definition: xspacelib.h:129
cusp::csr_matrix< int, real_type, cusp::host_memory > IHMatrix_t
Definition: typedefs.h:37
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
1D grid
Definition: grid.h:80
const DLT< real_type > & dlt() const
the discrete legendre transformation
Definition: grid.h:197
unsigned N() const
number of cells
Definition: grid.h:135
An abstract base class for two-dimensional grids.
Definition: grid.h:277
const RealGrid1d< real_type > & gy() const
The y-axis grid.
Definition: grid.h:379
const RealGrid1d< real_type > & gx() const
The x-axis grid.
Definition: grid.h:377
An abstract base class for three-dimensional grids.
Definition: grid.h:523
const RealGrid1d< real_type > & gz() const
The z-axis grid.
Definition: grid.h:664
const RealGrid1d< real_type > & gx() const
The x-axis grid.
Definition: grid.h:660
const RealGrid1d< real_type > & gy() const
The y-axis grid.
Definition: grid.h:662
Useful typedefs of commonly used types.