5#include "dg/algorithm.h"
12template<
class index_type,
class value_type>
18 for(
unsigned row=0; row<mat.
num_rows(); row++)
23 out( row, col ) = val;
35template<
class value_type>
36std::array<dg::SquareMatrix<value_type>,2> sym_laplace1d(
37 const thrust::host_vector<value_type>& volume,
45 for(
unsigned u=0; u<
volume.size(); u++)
54 std::array<dg::SquareMatrix<value_type>,2> out;
55 out[0] = W1D * (- leftx * (VOL * rightx) + jfactor*jumpx);
61template<
class ContainerType>
62struct LaplaceDecomposition
67 LaplaceDecomposition() =
default;
68 LaplaceDecomposition( RealGrid2d<value_type> g, bc
bcx, bc
bcy,
69 direction dir = forward,
75 unsigned Nx = g.gx().size();
77 thrust::host_vector<value_type> work( 3*Nx-1);
78 lapack::sygv( 1,
'V',
'U', Nx, lapX[0].data(), Nx, lapX[1].data(), Nx, m_EX, work);
82 for(
unsigned i=0; i<Nx; i++)
85 for(
unsigned u=0; u<Nx; u++)
86 temp[u] = lapX[0](i, u);
100 unsigned Ny = g.gy().size();
102 work.resize( 3*Ny-1);
103 lapack::sygv( 1,
'V',
'U', Ny, lapY[0].data(), Ny, lapY[1].data(), Ny, m_EY, work);
107 for(
unsigned i=0; i<Nx; i++)
110 for(
unsigned u=0; u<Ny; u++)
111 temp[u] = lapY[0](i, u);
115 thrust::host_vector<value_type> evs( m_EY.size()*m_EX.size());
116 thrust::host_vector<unsigned> idx( evs.size());
117 thrust::sequence( idx.begin(), idx.end());
118 for(
unsigned i=0; i<evs.size(); i++)
119 evs[i] = m_EY[i/m_EX.size()] + m_EX[i%m_EX.size()];
120 thrust::stable_sort_by_key( evs.begin(), evs.end(), idx.begin());
127 template<
class ContainerType0,
class UnaryOp,
128 class ContainerType1>
129 unsigned matrix_function(
132 const ContainerType1& b,
136 unsigned size = m_idx.size(), Nx = m_EX.size();
140 for(
unsigned i=0; i<size; i++)
142 unsigned ix = m_idx[i]%Nx, iy = m_idx[i]/Nx;
144 if(
alpha*normb <= eps*(sqrt(normx2)+nrmb_correction))
155 template<
class ContainerType0,
class BinaryOp,
156 class ContainerType1,
class ContainerType2>
157 unsigned product_function_adjoint(
160 const ContainerType1& diag,
161 const ContainerType2& b,
165 unsigned size = m_idx.size(), Nx = m_EX.size();
170 for(
unsigned i=0; i<size; i++)
172 unsigned ix = m_idx[i]%Nx, iy = m_idx[i]/Nx;
173 value_type err = normb*op(m_EX[ix] + m_EY[iy], dmin)*sqrt(size);
177 if( err <= eps*(sqrt(normx2)+nrmb_correction))
185 normx2 += gamma*gamma;
191 template<
class ContainerType0,
class BinaryOp,
192 class ContainerType1,
class ContainerType2>
193 unsigned product_function(
196 const ContainerType1& diag,
197 const ContainerType2& b,
201 unsigned size = m_idx.size(), Nx = m_EX.size();
205 for(
unsigned i=0; i<size; i++)
207 unsigned ix = m_idx[i]%Nx, iy = m_idx[i]/Nx;
208 value_type err = normb*op(dmin, m_EX[ix] + m_EY[iy])*sqrt(size);
210 if( err <= eps*(normx+nrmb_correction))
222 thrust::host_vector<value_type> m_EX, m_EY;
223 std::vector<ContainerType> m_VX, m_VY;
224 ContainerType m_weights, m_v, m_f;
225 thrust::host_vector<unsigned> m_idx;
DG_DEVICE T one(T, Ts ...)
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
void axpby(value_type alpha, const ContainerType1 &x, value_type1 beta, ContainerType &y)
void pointwiseDot(value_type alpha, const ContainerType1 &x1, const ContainerType2 &x2, value_type1 beta, ContainerType &y)
OutputType reduce(const ContainerType &x, OutputType zero, BinaryOp binary_op, UnaryOp unary_op=UnaryOp())
void evaluate(ContainerType &y, BinarySubroutine f, Functor g, const ContainerType0 &x0, const ContainerTypes &...xs)
void assign(const from_ContainerType &from, ContainerType &to, Params &&... ps)
void kronecker(ContainerType0 &y, BinarySubroutine f, Functor g, const ContainerType1 &x0, const ContainerTypes &...xs)
auto dot(const ContainerType1 &x, const MatrixType &m, const ContainerType2 &y)
auto dx(const Topology &g, dg::bc bc, dg::direction dir=centered)
auto jumpX(const Topology &g, bc bc)
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
auto weights(const Topology &g)
auto evaluate(Functor &&f, const Topology &g)
dg::RealGrid< T, 1 > RealGrid1d
Geometry::host_vector volume(const Geometry &g)
thrust::host_vector< double > HVec
dg::bc bcy
Definition lanczos_b.cpp:10
dg::bc bcx
Definition lanczos_b.cpp:9
const double alpha
Definition lanczos_b.cpp:11
Functions for optimizing Contours.
const double beta
Definition polarization_b.cpp:10
const Vector< Index > & row_offsets() const
const Vector< Index > & column_indices() const
const Vector< Value > & values() const
double value_type
Definition tridiaginv_b.cpp:6