realroot_doc 0.1.1
solver_bspline< Real > Struct Template Reference

#include <solver_uv_bspline.hpp>

List of all members.

Public Member Functions

Public Attributes


Detailed Description

template<class Real>
struct mmx::solver_bspline< Real >

Definition at line 30 of file solver_uv_bspline.hpp.


Constructor & Destructor Documentation

solver_bspline ( unsigned  n,
unsigned  d,
unsigned  N = 100 
) [inline]

Definition at line 36 of file solver_uv_bspline.hpp.

References solver_bspline< Real >::m_c, solver_bspline< Real >::m_t, and mmx::N().

                                                        : m_n(n), maxn(N+n), m_d(d), eps(1e-7) { 
    m_t= new Real[2*n+N]; 
    for(unsigned i=0; i< 2*n+N; i++) m_t[i]=Real(1);
    m_c = new Real[n+N];
    for(unsigned i=0; i< n+N; i++) m_c[i]=Real(0);
  }

Member Function Documentation

Real first_root ( void  )

Definition at line 79 of file solver_uv_bspline.hpp.

References mmx::diff(), mmx::knotSum(), mmx::max(), mmx::min(), and NO_ROOT.

Referenced by solver< Ring, Bspline >::first_root().

{

  unsigned k = 1;
  Real x = NO_ROOT;
    
  for ( ;  m_n < maxn; ++m_n ) {
    
    while( k<m_n && (m_c[k-1]*m_c[k] > 0.0) )
      ++k;
    
    
    // Off end?
    if ( k >= m_n ) {
      //if (x!= NO_ROOT)
      //x = -x; // NO_ROOT;
      x = NO_ROOT;
      break;
    }
    
    // Interval converged?
    const Real diff = m_t[k+m_d]-m_t[k];

    if (diff<eps) {
      x = m_t[k];
      break;
    }
    
    const Real av = knotSum(m_t,k-1, m_d);
    const Real lambda = m_c[k-1]/(m_c[k-1]-m_c[k]);
    x = (av + lambda*diff)/Real(m_d);

    // Stopping criterion
    const Real e = std::max(x, m_t[k+m_d-1]) - std::min(x, m_t[k+1] );
    // const Real e = max(fabs(x-t[k+1]),fabs(x-t[k+m_d-1]));
    if (e < eps)
      break;
    
    // Refine spline
    insert_knot(x,k);
  }
  
  //  dx = d*(m_c[k]-m_c[k-1])/(t[k+m_d]-t[k]);
  m_k  = k;
  return x;
}
int insert_knot ( const Real &  x,
int  mu 
)

Definition at line 53 of file solver_uv_bspline.hpp.

References mmx::max().

{
  mu = std::max(mu,m_d);
  while ( x>=m_t[mu+1]) mu++;
  
  for ( int i=m_n; i>mu; i--) {
    m_c[i] = m_c[i-1];
  }
  
  for ( int i=mu; i>=mu-m_d+1; i--) {
    const Real alpha = (x-m_t[i])/(m_t[i+m_d]-m_t[i]);
    m_c[i] = (1.0-alpha) * m_c[i-1] + alpha * m_c[i];
  }

  m_t[m_n+m_d] = 1.0;
  
  for ( int i=m_n; i>mu+1; --i)
    m_t[i] = m_t[i-1];
  m_t[mu+1] = x;
  
  //    n++;
  return mu;
}

Member Data Documentation

Real eps

Definition at line 34 of file solver_uv_bspline.hpp.

int m_d

Definition at line 33 of file solver_uv_bspline.hpp.

unsigned m_k

Definition at line 32 of file solver_uv_bspline.hpp.

unsigned m_n

Definition at line 32 of file solver_uv_bspline.hpp.

unsigned maxn

Definition at line 32 of file solver_uv_bspline.hpp.


The documentation for this struct was generated from the following file: