Discontinuous Galerkin Library
#include "dg/algorithm.h"
tensor.h
Go to the documentation of this file.
1#pragma once
2
3#include "grid.h"
4#include "operator.h"
5#include "evaluation.h"
6#include "evaluationX.h"
7#include "dg/functors.h"
8#include "dg/blas1.h"
9
15namespace dg
16{
17 //separate algorithms from interface!!
18
64template<class container>
66{
67 using container_type = container;
69 SparseTensor( ):m_mat_idx(3,-1) {}
70
75 template<class Topology>
76 SparseTensor( const Topology& grid){
77 construct(grid);
78 }
79
84 SparseTensor( const container& copyable ){
85 construct(copyable);
86 }
91 template<class Topology>
92 void construct( const Topology& grid){
93 m_mat_idx.resize(3,0);
94 for( int i=0; i<3; i++)
95 m_mat_idx( i,i) = 1;
96 m_values.resize(2);
97 dg::assign( dg::evaluate( dg::zero, grid), m_values[0]);
98 dg::assign( dg::evaluate( dg::one, grid), m_values[1]);
99 }
104 void construct( const container& copyable ){
105 m_mat_idx.resize(3,0);
106 for( int i=0; i<3; i++)
107 m_mat_idx( i,i) = 1;
108 m_values.assign(2,copyable);
109 dg::blas1::copy( 0., m_values[0]);
110 dg::blas1::copy( 1., m_values[1]);
111 }
112
118 template<class OtherContainer>
119 SparseTensor( const SparseTensor<OtherContainer>& src): m_mat_idx(3,-1), m_values(src.values().size()){
120 for(unsigned i=0; i<3; i++)
121 for(unsigned j=0; j<3; j++)
122 m_mat_idx(i,j)=src.idx(i,j);
123
124 for( unsigned i=0; i<src.values().size(); i++)
125 dg::assign( src.values()[i], m_values[i]);
126 }
127
134 int idx(unsigned i, unsigned j)const{
135 return m_mat_idx(i,j);
136 }
145 int& idx(unsigned i, unsigned j){
146 return m_mat_idx(i,j);
147 }
148
156 const container& value(size_t i, size_t j)const{
157 int k = m_mat_idx(i,j);
158 return m_values[k];
159 }
160 //if you're looking for this function: YOU DON'T NEED IT!! (ALIASING)
161 //T& value(size_t i, size_t j);
166 std::vector<container>& values() {
167 return m_values;
168 }
173 const std::vector<container>& values()const{
174 return m_values;
175 }
176
182 SparseTensor tmp(*this);
183 tmp.m_mat_idx = m_mat_idx.transpose();
184 return tmp;
185 }
186
187 private:
188 dg::Operator<int> m_mat_idx;
189 std::vector<container> m_values;
190};
191
192}//namespace dg
void resize(unsigned m, T val=T())
Resize.
Definition: operator.h:120
Operator transpose() const
Transposition.
Definition: operator.h:152
Function discretization routines.
Function discretization routines on X-point topology.
base topology classes
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:665
static DG_DEVICE double one(double x)
Definition: functions.h:20
static DG_DEVICE double zero(double x)
Definition: functions.h:29
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
Definition: blas1.h:164
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
Evaluate a 1d function on grid coordinates.
Definition: evaluation.h:67
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Class for 2x2 and 3x3 matrices sharing elements.
Definition: tensor.h:66
void construct(const Topology &grid)
Construct the unit tensor.
Definition: tensor.h:92
SparseTensor(const SparseTensor< OtherContainer > &src)
Type conversion from other value types.
Definition: tensor.h:119
int idx(unsigned i, unsigned j) const
read index into the values array at the given position
Definition: tensor.h:134
SparseTensor transpose() const
Return the transpose of the currrent tensor.
Definition: tensor.h:181
SparseTensor()
no value is set, Indices default to -1
Definition: tensor.h:69
SparseTensor(const container &copyable)
Construct the unit tensor.
Definition: tensor.h:84
container container_type
Definition: tensor.h:67
std::vector< container > & values()
Return write access to the values array.
Definition: tensor.h:166
int & idx(unsigned i, unsigned j)
write index into the values array at the given position
Definition: tensor.h:145
const std::vector< container > & values() const
Return read access to the values array.
Definition: tensor.h:173
void construct(const container &copyable)
Construct the unit tensor.
Definition: tensor.h:104
SparseTensor(const Topology &grid)
Construct the unit tensor.
Definition: tensor.h:76
const container & value(size_t i, size_t j) const
Read access the underlying container.
Definition: tensor.h:156