36template<
class ContainerType0,
class ContainerType1>
37std::vector<double>
least_squares(
const std::vector<ContainerType0>& bs,
const ContainerType1 & b)
40 unsigned size = bs.size();
42 thrust::host_vector<double> rhs( size, 0.), opIi(rhs);
43 std::vector<double> a(size,0.);
44 for(
unsigned i=0; i<size; i++)
46 for(
unsigned j=i; j<size; j++)
48 for(
unsigned j=0; j<i; j++)
54 for(
unsigned i=0; i<size; i++)
56 for(
unsigned j=0; j<size; j++)
57 opIi[j] = op_inv(i,j);
85template<
class ContainerType0,
class ContainerType1>
97 set_max(max, copyable0, copyable1);
100 void set_max(
unsigned max,
const ContainerType0& copyable0,
101 const ContainerType1& copyable1)
104 m_x.assign( max, copyable0);
105 m_y.assign( max, copyable1);
121 void extrapolate(
double alpha,
const ContainerType0& x,
double beta,
122 ContainerType1& y)
const{
123 unsigned size = m_counter;
124 thrust::host_vector<double> rhs( size, 0.), a(rhs), opIi(rhs);
125 for(
unsigned i=0; i<size; i++)
129 for(
unsigned i=0; i<size; i++)
131 for(
unsigned j=0; j<size; j++)
132 opIi[j] = m_op_inv(i,j);
142 void extrapolate(
const ContainerType0& x, ContainerType1& y)
const{
156 void update(
const ContainerType0& x_new,
const ContainerType1& y_new){
157 if( m_max == 0)
return;
158 unsigned size = m_counter < m_max ? m_counter + 1 : m_max;
162 for(
unsigned j=1; j<size; j++)
165 for(
unsigned i=1; i<size; i++)
166 for(
unsigned j=1; j<size; j++)
167 op(i,j) = m_op(i-1,j-1);
172 catch ( std::runtime_error & e){
175 m_op_inv = op_inv, m_op = op;
176 if( m_counter < m_max)
179 std::rotate( m_x.rbegin(), m_x.rbegin()+1, m_x.rend());
180 std::rotate( m_y.rbegin(), m_y.rbegin()+1, m_y.rend());
186 unsigned m_max, m_counter;
187 std::vector<ContainerType0> m_x;
188 std::vector<ContainerType1> m_y;
214template<
class ContainerType>
233 void set_max(
unsigned max,
const ContainerType& copyable)
236 m_x.assign( max, copyable);
265 if( m_max == 0)
return false;
266 for(
unsigned i=0; i<m_counter; i++)
267 if( fabs(t - m_t[i]) <1e-14)
282 template<
class ContainerType0>
291 value_type f0 = (t-m_t[1])*(t-m_t[2])/(m_t[0]-m_t[1])/(m_t[0]-m_t[2]);
292 value_type f1 =-(t-m_t[0])*(t-m_t[2])/(m_t[0]-m_t[1])/(m_t[1]-m_t[2]);
293 value_type f2 = (t-m_t[0])*(t-m_t[1])/(m_t[2]-m_t[0])/(m_t[2]-m_t[1]);
295 f0, m_x[0], f1, m_x[1], f2, m_x[2]);
319 template<
class ContainerType0>
328 value_type f0 =-(-2.*t+m_t[1]+m_t[2])/(m_t[0]-m_t[1])/(m_t[0]-m_t[2]);
329 value_type f1 = (-2.*t+m_t[0]+m_t[2])/(m_t[0]-m_t[1])/(m_t[1]-m_t[2]);
330 value_type f2 =-(-2.*t+m_t[0]+m_t[1])/(m_t[2]-m_t[0])/(m_t[2]-m_t[1]);
332 f0, m_x[0], f1, m_x[1], f2, m_x[2]);
349 template<
class ContainerType0>
360 template<
class ContainerType0>
361 void derive( ContainerType0& dot_x)
const{
371 template<
class ContainerType0>
373 if( m_max == 0)
return;
375 for(
unsigned i=0; i<m_counter; i++)
376 if( fabs(t_new - m_t[i]) <1e-14)
381 if( m_counter < m_max)
384 std::rotate( m_x.rbegin(), m_x.rbegin()+1, m_x.rend());
385 std::rotate( m_t.rbegin(), m_t.rbegin()+1, m_t.rend());
395 template<
class ContainerType0>
396 void update(
const ContainerType0& new_entry){
398 update( t_new, new_entry);
405 const ContainerType&
head()
const{
413 const ContainerType&
tail()
const{
418 unsigned m_max, m_counter;
419 std::vector<value_type> m_t;
420 std::vector<ContainerType> m_x;
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
Definition: blas1.h:164
void axpby(get_value_type< ContainerType > alpha, const ContainerType1 &x, get_value_type< ContainerType > beta, ContainerType &y)
Definition: blas1.h:231
void scal(ContainerType &x, get_value_type< ContainerType > alpha)
Definition: blas1.h:185
void evaluate(ContainerType &y, BinarySubroutine f, Functor g, const ContainerType0 &x0, const ContainerTypes &...xs)
Definition: blas1.h:556
get_value_type< ContainerType1 > dot(const ContainerType1 &x, const ContainerType2 &y)
Binary reproducible Euclidean dot product between two vectors
Definition: blas1.h:87
dg::Operator< T > inverse(const dg::Operator< T > &in)
Compute the inverse of a square matrix.
Definition: operator.h:483
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition: tensor_traits.h:38
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Definition: subroutines.h:108
Definition: subroutines.h:22