3#include <cusp/coo_matrix.h>
19template<
class real_type>
21 cusp::array1d<real_type, cusp::host_memory>& values,
22 cusp::array1d<int, cusp::host_memory>& column_indices,
26 for(
unsigned k=0; k<values.size(); k++)
28 if( column_indices[k] < 0 )
31 column_indices[k] = -(column_indices[k]+1);
34 column_indices[k] = -(column_indices[k]+1);
38 column_indices[k] += num_cols;
40 else if( column_indices[k] >= num_cols)
43 column_indices[k] = 2*num_cols-1-column_indices[k];
46 column_indices[k] = 2*num_cols-1-column_indices[k];
50 column_indices[k] -= num_cols;
55template<
class real_type>
57 unsigned stencil_size,
58 const RealGrid1d<real_type>& local,
59 const RealGrid1d<real_type>& global,
62 cusp::array1d<real_type, cusp::host_memory> values;
63 cusp::array1d<int, cusp::host_memory> row_offsets;
64 cusp::array1d<int, cusp::host_memory> column_indices;
66 unsigned num_rows = local.size();
67 unsigned num_cols = global.size();
68 unsigned radius = stencil_size/2;
69 int L0 = round((local.x0() - global.x0())/global.h())*global.n();
71 row_offsets.push_back(0);
72 for(
unsigned k=0; k<num_rows; k++)
74 row_offsets.push_back(stencil_size + row_offsets[k]);
75 for(
unsigned l=0; l<stencil_size; l++)
77 column_indices.push_back( L0 + (
int)(k + l) - (
int)radius);
78 values.push_back( 1.0);
81 set_boundary( values, column_indices, bcx, num_cols);
83 cusp::csr_matrix<int, real_type, cusp::host_memory> A(
84 num_rows, num_cols, values.size());
85 A.row_offsets = row_offsets;
86 A.column_indices = column_indices;
91template<
class real_type>
93 const RealGrid1d<real_type>& local,
94 const RealGrid1d<real_type>& global,
97 cusp::array1d<real_type, cusp::host_memory> values;
98 cusp::array1d<int, cusp::host_memory> row_offsets;
99 cusp::array1d<int, cusp::host_memory> column_indices;
101 unsigned num_rows = local.size();
102 unsigned num_cols = global.size();
103 int L0 = round((local.x0() - global.x0())/global.h())*global.n();
112 row_offsets.push_back( 0);
113 for(
unsigned k=0; k<local.N(); k++)
115 row_offsets.push_back(row_offsets[row_offsets.size()-1] + 3*local.n());
116 for(
unsigned j=1; j<local.n(); j++)
117 row_offsets.push_back(row_offsets[row_offsets.size()-1]);
119 for(
unsigned j=0; j<local.n(); j++)
121 column_indices.push_back( L0 + (
int)((k-1)*global.n() + j) );
122 values.push_back(
forward(0, j ));
124 for(
unsigned j=0; j<local.n(); j++)
126 column_indices.push_back( L0 + (
int)(k*global.n() + j ));
127 values.push_back(
forward(1, j ));
129 for(
unsigned j=0; j<local.n(); j++)
131 column_indices.push_back( L0 + (
int)((k+1)*global.n() + j));
135 assert( row_offsets.size() == num_rows+1);
136 set_boundary( values, column_indices, bcx, num_cols);
138 cusp::csr_matrix<int, real_type, cusp::host_memory> A(
139 num_rows, num_cols, values.size());
140 A.row_offsets = row_offsets;
141 A.column_indices = column_indices;
146template<
class real_type>
147cusp::csr_matrix< int, real_type, cusp::host_memory> identity_matrix(
const RealGrid1d<real_type>& local,
const RealGrid1d<real_type>& global)
149 cusp::csr_matrix<int,real_type,cusp::host_memory> A( local.size(),
150 global.size(), local.size());
151 int L0 = round((local.x0() - global.x0())/global.h())*global.n();
152 A.row_offsets[0] = 0;
153 for(
unsigned i=0; i<local.size(); i++)
155 A.row_offsets[i+1] = 1 + A.row_offsets[i];
156 A.column_indices[i] = L0 + i;
182template<
class real_type>
184 unsigned window_size,
205template<
class real_type>
234template<
class real_type>
236 std::array<int,2> window_size,
247template<
class real_type>
256 auto einsy = detail::identity_matrix( g.
gy(), g.
gy());
260 auto einsx = detail::identity_matrix( g.
gx(), g.
gx());
266template<
class real_type>
275 auto einsy = detail::identity_matrix( g.
gy(), g.
gy());
276 auto einsz = detail::identity_matrix( g.
gz(), g.
gz());
282 auto einsx = detail::identity_matrix( g.
gx(), g.
gx());
284 auto einsz = detail::identity_matrix( g.
gz(), g.
gz());
288 auto einsy = detail::identity_matrix( g.
gy(), g.
gy());
289 auto einsx = detail::identity_matrix( g.
gx(), g.
gx());
312template<
class real_type>
314 std::array<int,2> window_size,
320 auto mz = detail::identity_matrix( g.
gz(), g.
gz());
326template<
class real_type>
328 std::array<int,2> window_size,
339template<
class real_type>
341 std::array<int,2> window_size,
347 auto mz = detail::identity_matrix( g.
local().gz(), g.
global().gz());
354template<
class real_type>
363 auto einsy = detail::identity_matrix( g.
local().gy(), g.
global().gy());
368 auto einsx = detail::identity_matrix( g.
local().gx(), g.
global().gx());
375template<
class real_type>
384 auto einsy = detail::identity_matrix( g.
local().gy(), g.
global().gy());
385 auto einsz = detail::identity_matrix( g.
local().gz(), g.
global().gz());
391 auto einsx = detail::identity_matrix( g.
local().gx(), g.
global().gx());
393 auto einsz = detail::identity_matrix( g.
local().gz(), g.
global().gz());
398 auto einsy = detail::identity_matrix( g.
local().gy(), g.
global().gy());
399 auto einsx = detail::identity_matrix( g.
local().gx(), g.
global().gx());
class intended for the use in throw statements
Definition: exceptions.h:83
small class holding a stringstream
Definition: exceptions.h:29
#define _ping_
Definition: exceptions.h:12
coo3d
3d contra- and covariant coordinates
Definition: enums.h:177
bc
Switch between boundary conditions.
Definition: enums.h:15
direction
Direction of a discrete derivative.
Definition: enums.h:97
@ NEU_DIR
Neumann on left, Dirichlet on right boundary.
Definition: enums.h:19
@ PER
periodic boundaries
Definition: enums.h:16
@ NEU
Neumann on both boundaries.
Definition: enums.h:20
@ DIR
homogeneous dirichlet boundaries
Definition: enums.h:17
@ DIR_NEU
Dirichlet on left, Neumann on right boundary.
Definition: enums.h:18
@ 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
Operator< T > tensorproduct(const Operator< T > &op1, const Operator< T > &op2)
Form the tensor product between two operators.
Definition: operator_tensor.h:27
dg::MIHMatrix_t< real_type > convert(const dg::IHMatrix_t< real_type > &global, const ConversionPolicy &policy)
Convert a (row-distributed) matrix with local row and global column indices to a row distributed MPI ...
Definition: mpi_projection.h:75
dg::MIHMatrix_t< real_type > window_stencil(std::array< int, 2 > window_size, const aRealMPITopology3d< real_type > &g, dg::bc bcx, dg::bc bcy)
A 2d centered window stencil.
Definition: stencil.h:340
dg::IHMatrix_t< real_type > limiter_stencil(const RealGrid1d< real_type > &g, dg::bc bound)
A stencil for the dg Slope limiter.
Definition: stencil.h:206
dg::MIHMatrix_t< real_type > limiter_stencil(enum coo3d direction, const aRealMPITopology3d< real_type > &g, dg::bc bound)
A stencil for the dg Slope limiter.
Definition: stencil.h:376
dg::IHMatrix_t< real_type > window_stencil(unsigned window_size, const RealGrid1d< real_type > &g, dg::bc bcx)
A 1d centered window stencil.
Definition: stencil.h:183
IHMatrix_t< double > IHMatrix
Definition: typedefs.h:47
cusp::csr_matrix< int, real_type, cusp::host_memory > IHMatrix_t
Definition: typedefs.h:37
Useful MPI typedefs and overloads of interpolation and projection.
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Distributed memory matrix class.
Definition: mpi_matrix.h:219
1D grid
Definition: grid.h:80
2D MPI abstract grid class
Definition: mpi_grid.h:45
const RealGrid2d< real_type > & local() const
Return a non-MPI grid local for the calling process.
Definition: mpi_grid.h:252
const RealGrid2d< real_type > & global() const
Return the global non-MPI grid.
Definition: mpi_grid.h:262
3D MPI Grid class
Definition: mpi_grid.h:329
const RealGrid3d< real_type > & global() const
Return the global non-MPI grid.
Definition: mpi_grid.h:562
const RealGrid3d< real_type > & local() const
Return a non-MPI grid local for the calling process.
Definition: mpi_grid.h:560
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