1#ifndef _DG_XSPACELIB_CUH_
2#define _DG_XSPACELIB_CUH_
4#include <thrust/host_vector.h>
43 size_t num_rows =
lhs.num_rows()*
rhs.num_rows();
44 size_t num_cols =
lhs.num_cols()*
rhs.num_cols();
45 size_t num_entries =
lhs.num_entries()*
rhs.num_entries();
47 thrust::host_vector<int> A_row_offsets(num_rows+1), A_column_indices( num_entries);
48 thrust::host_vector<T> A_values( num_entries);
52 for(
unsigned i=0; i<
lhs.num_rows(); i++)
53 for(
unsigned j=0; j<
rhs.num_rows(); j++)
55 int num_entries_in_row =
56 (
lhs.row_offsets()[i+1] -
lhs.row_offsets()[i])*
57 (
rhs.row_offsets()[j+1] -
rhs.row_offsets()[j]);
58 A_row_offsets[i*
rhs.num_rows()+j+1] =
59 A_row_offsets[i*
rhs.num_rows()+j] + num_entries_in_row;
60 for(
int k=
lhs.row_offsets()[i]; k<
lhs.row_offsets()[i+1]; k++)
61 for(
int l=
rhs.row_offsets()[j]; l<
rhs.row_offsets()[j+1]; l++)
63 A_column_indices[counter] =
64 lhs.column_indices()[k]*
rhs.num_cols() +
rhs.column_indices()[l];
65 A_values[counter] =
lhs.values()[k]*
rhs.values()[l];
70 return { num_rows, num_cols, A_row_offsets, A_column_indices, A_values};
93 if(
lhs.num_rows() !=
rhs.num_rows())
94 throw Error(
Message(
_ping_)<<
"lhs and rhs must have same number of rows: "<<
lhs.num_rows()<<
" rhs "<<
rhs.num_rows());
97 size_t num_rows =
lhs.num_rows();
98 size_t num_cols =
lhs.num_cols()*
rhs.num_cols();
99 size_t num_entries = 0;
100 for(
unsigned i=0; i<
lhs.num_rows(); i++)
102 int num_entries_in_row =
103 (
lhs.row_offsets()[i+1] -
lhs.row_offsets()[i])*
104 (
rhs.row_offsets()[i+1] -
rhs.row_offsets()[i]);
105 num_entries += num_entries_in_row;
108 thrust::host_vector<int> A_row_offsets(num_rows+1), A_column_indices( num_entries);
109 thrust::host_vector<T> A_values( num_entries);
111 A_row_offsets[0] = 0;
113 for(
unsigned i=0; i<
lhs.num_rows(); i++)
115 int num_entries_in_row =
116 (
lhs.row_offsets()[i+1] -
lhs.row_offsets()[i])*
117 (
rhs.row_offsets()[i+1] -
rhs.row_offsets()[i]);
118 A_row_offsets[i+1] = A_row_offsets[i] + num_entries_in_row;
119 for(
int k=
lhs.row_offsets()[i]; k<
lhs.row_offsets()[i+1]; k++)
120 for(
int l=
rhs.row_offsets()[i]; l<
rhs.row_offsets()[i+1]; l++)
122 A_column_indices[counter] =
123 lhs.column_indices()[k]*
rhs.num_cols() +
rhs.column_indices()[l];
124 A_values[counter] =
lhs.values()[k]*
rhs.values()[l];
128 return { num_rows, num_cols, A_row_offsets, A_column_indices, A_values};
145template<
class real_type>
157template<
class real_type>
167template<
class real_type>
187template<
class real_type>
198template<
class real_type>
208template<
class real_type>
class intended for the use in throw statements
Definition exceptions.h:83
small class holding a stringstream
Definition exceptions.h:29
A square nxn matrix.
Definition operator.h:31
The discrete legendre trafo class.
#define _ping_
Definition exceptions.h:12
void rhs(double t, double, double &yp)
@ 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::SquareMatrix< T > invert(const dg::SquareMatrix< T > &in)
Compute inverse of square matrix (alias for dg::create::inverse)
Definition operator.h:691
dg::SparseMatrix< int, T, thrust::host_vector > tensorproduct_cols(const dg::SparseMatrix< int, T, thrust::host_vector > &lhs, const dg::SparseMatrix< int, T, thrust::host_vector > &rhs)
Form the tensor (Kronecker) product between two matrices in the column index
Definition xspacelib.h:89
SquareMatrix< T > tensorproduct(const SquareMatrix< T > &op1, const SquareMatrix< T > &op2)
Form the tensor product between two operators.
Definition operator_tensor.h:25
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:146
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:188
double lhs(double x, double y)
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Struct providing coefficients for Discrete Legendre Transformation (DLT) related operations.
Definition dlt.h:20
The simplest implementation of aRealTopology.
Definition grid.h:710
A CSR formatted sparse matrix.
Definition sparsematrix.h:96
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
RealGrid< real_type, 1 > gx() const
Equivalent to grid(0)
Definition grid.h:354
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
Useful typedefs of commonly used types.