bvp::interpolator< RBF > Class Template Reference

#include <interpolator.hpp>

Inheritance diagram for bvp::interpolator< RBF >:

Inheritance graph
[legend]
Collaboration diagram for bvp::interpolator< RBF >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 interpolator ()
 interpolator (shared_ptr< linear_BVP2 > bvp)
 interpolator (const map< point, double > &Xi)
void interpolate (const map< point, double > &Xi)
void interpolate (shared_ptr< linear_BVP2 > bvp)
double operator() (const point &p) const
double at (const point &p) const
double d (const point &p, size_t k) const
double d2 (const point &p, size_t k1, size_t k2) const
void set_f (const realfunc &f)
void set_g (const realfunc &g)
void set_f (const map< point, double > &f)
void set_g (const map< point, double > &g)
interpolator< RBF > operator+ (const interpolator< RBF > &u) const
interpolator< RBF > operator* (double a) const
interpolator< RBF > operator/ (double a) const

Public Attributes

size_t rbfs_hash

Private Types

typedef std::pair
< linalg::point, std::vector
< size_t > > 
diff_data

Private Member Functions

void computecoeffs ()
void init (shared_ptr< linear_BVP2 > bvp)
void not_initted (int line, string file) const
size_t hash_value (const std::vector< RBF > &rbfs_in)

Private Attributes

shared_ptr< linear_BVP2thebvp
size_t n
size_t m
matrix M
bool initted
linalg::vector coeffs
std::vector< RBF > rbfs
map< diff_data, double > remtable

template<typename RBF>
class bvp::interpolator< RBF >


Member Typedef Documentation

template<typename RBF>
typedef std::pair<linalg::point, std::vector<size_t> > bvp::interpolator< RBF >::diff_data [private]


Constructor & Destructor Documentation

template<typename RBF>
bvp::interpolator< RBF >::interpolator (  )  [inline]

00018                                  {
00019     initted = false;
00020     rbfs_hash = 0;
00021   }

template<typename RBF>
bvp::interpolator< RBF >::interpolator ( shared_ptr< linear_BVP2 bvp  )  [inline]

00024                                                             {
00025     //Workaround because gdb can't break inside constructors. :-(
00026     init(bvp);
00027   }

Here is the call graph for this function:

template<typename RBF>
bvp::interpolator< RBF >::interpolator ( const map< point, double > &  Xi  )  [inline]

00030                                                              {
00031     interpolate(Xi);
00032   }

Here is the call graph for this function:


Member Function Documentation

template<typename RBF>
void bvp::interpolator< RBF >::interpolate ( const map< point, double > &  Xi  )  [inline]

00035                                                                  {
00036     
00037     if(Xi.empty()){//Dude, wtf?
00038       badArgument exc;
00039       exc.reason = "Cannot interpolate if no data is given.";
00040       exc.line = __LINE__;
00041       exc.file = __FILE__;
00042       throw exc;
00043     }
00044 
00045     //Create a trivial bvp.
00046     shared_ptr<Id_op> Id(new Id_op);
00047     shared_ptr<dirichlet_op> D(new dirichlet_op);
00048     set<point> intr;
00049     set<point> bdry; //empty
00050     map<point, point> nrml; //empty
00051     map<point, double> g; //empty
00052     
00053     bool dim_set = false;
00054     size_t dimension = 0;
00055     for(map<point,double>::const_iterator i = Xi.begin(); i != Xi.end(); i++){
00056       if(!dim_set){
00057         dimension = (i -> first).size();
00058         dim_set = true;
00059       }
00060       else if(dimension != (i -> first).size()){
00061         badArgument exc;
00062         exc.reason = "Inconformant dimensions in interpolation data.";
00063         exc.line = __LINE__;
00064         exc.file = __FILE__;
00065         throw exc;
00066       }
00067       intr.insert( i->first);
00068     }
00069     shared_ptr<domain> Omega(new domain(dimension, intr,bdry,nrml));
00070     shared_ptr<linear_BVP2> bvp(new linear_BVP2(Omega, Id, D, Xi, g));
00071     
00072     init(bvp);
00073   }

Here is the call graph for this function:

template<typename RBF>
void bvp::interpolator< RBF >::interpolate ( shared_ptr< linear_BVP2 bvp  )  [inline]

00076                                                                 {
00077     init(bvp);
00078   }

Here is the call graph for this function:

template<typename RBF>
double bvp::interpolator< RBF >::operator() ( const point &  p  )  const [inline]

Reimplemented from bvp::realfunc.

00160                                                           {
00161     return at(p);
00162   }

Here is the call graph for this function:

template<typename RBF>
double bvp::interpolator< RBF >::at ( const point &  p  )  const [inline, virtual]

Reimplemented from bvp::realfunc.

00166                                                   {
00167     if(!initted){
00168       not_initted(__LINE__, __FILE__);
00169     }
00170     std::vector<size_t> alpha; //empty vector
00171     diff_data loc = std::make_pair(p,alpha);
00172     if(remtable.find(loc) != remtable.end())
00173       return remtable[loc];
00174     
00175     double result = 0;
00176     for(size_t i = 1; i <= coeffs.size(); i++)
00177       result += coeffs(i)*rbfs[i-1].at(p);
00178     
00179     remtable[loc] = result;
00180     return result;
00181   }

Here is the call graph for this function:

template<typename RBF>
double bvp::interpolator< RBF >::d ( const point &  p,
size_t  k 
) const [inline, virtual]

Reimplemented from bvp::realfunc.

00184                                                            {
00185     if(!initted){
00186       not_initted(__LINE__, __FILE__);
00187     }
00188     std::vector<size_t> alpha(k); alpha[k-1]++;
00189     diff_data loc = std::make_pair(p,alpha);
00190     if(remtable.find(loc) != remtable.end())
00191       return remtable[loc];
00192 
00193     double result = 0;
00194     for(size_t i = 1; i <= coeffs.size(); i++)
00195       result += coeffs(i)*rbfs[i-1].d(p,k);
00196 
00197     remtable[loc] = result;
00198     return result;
00199   }

Here is the call graph for this function:

template<typename RBF>
double bvp::interpolator< RBF >::d2 ( const point &  p,
size_t  k1,
size_t  k2 
) const [inline, virtual]

Reimplemented from bvp::realfunc.

00202                                                                         {
00203     if(!initted){
00204       not_initted(__LINE__, __FILE__);
00205     }
00206     std::vector<size_t> alpha(k1>k2?k1:k2); alpha[k1-1]++; alpha[k2-1]++;
00207     diff_data loc = std::make_pair(p,alpha);
00208     if(remtable.find(loc) != remtable.end())
00209       return remtable[loc];
00210 
00211     double result = 0;
00212     for(size_t i = 1; i <= coeffs.size(); i++)
00213       result += coeffs(i)*rbfs[i-1].d2(p,k1,k2);
00214 
00215     remtable[loc] = result;
00216     return result;
00217   }

Here is the call graph for this function:

template<typename RBF>
void bvp::interpolator< RBF >::set_f ( const realfunc f  )  [inline]

00265                                                 {
00266     if(!initted){
00267       not_initted(__LINE__, __FILE__);
00268     }
00269     thebvp -> set_f(f);
00270     computecoeffs();
00271   }

Here is the call graph for this function:

template<typename RBF>
void bvp::interpolator< RBF >::set_g ( const realfunc g  )  [inline]

00274                                                 {
00275     if(!initted){
00276       not_initted(__LINE__, __FILE__);
00277     }
00278     thebvp -> set_g(g);
00279     computecoeffs();
00280   }

Here is the call graph for this function:

template<typename RBF>
void bvp::interpolator< RBF >::set_f ( const map< point, double > &  f  )  [inline]

00283                                                           {
00284     if(!initted){
00285       not_initted(__LINE__, __FILE__);
00286     }
00287     thebvp -> set_f(f);
00288     computecoeffs();
00289   }

Here is the call graph for this function:

template<typename RBF>
void bvp::interpolator< RBF >::set_g ( const map< point, double > &  g  )  [inline]

00292                                                           {
00293     if(!initted){
00294       not_initted(__LINE__, __FILE__);
00295     }
00296     thebvp -> set_g(g);
00297     computecoeffs();
00298   }

Here is the call graph for this function:

template<typename RBF>
interpolator< RBF > bvp::interpolator< RBF >::operator+ ( const interpolator< RBF > &  u  )  const [inline]

00224   {    
00225     if(this -> rbfs_hash != u.rbfs_hash){
00226       badArgument exc;
00227       exc.reason = 
00228         "Cannot add interpolators with different radial basis functions."; 
00229       exc.line = __LINE__;
00230       exc.file = __FILE__;
00231       throw exc;        
00232     }
00233 
00234     interpolator<RBF> out = *this;
00235     out.coeffs = (this -> coeffs) + u.coeffs;
00236     
00237     out.remtable.clear();
00238     
00239     return out;
00240   }

template<typename RBF>
interpolator< RBF > bvp::interpolator< RBF >::operator* ( double  a  )  const [inline]

00245   {
00246     interpolator<RBF> u = *this;
00247     u.coeffs = (this -> coeffs)*a;
00248     u.remtable.clear();
00249     return u;
00250   }

template<typename RBF>
interpolator< RBF > bvp::interpolator< RBF >::operator/ ( double  a  )  const [inline]

00255   {
00256     interpolator<RBF> u = *this;
00257     u.coeffs = (this -> coeffs)*(1/a);
00258     u.remtable.clear();
00259     return u;
00260   }

template<typename RBF>
void bvp::interpolator< RBF >::computecoeffs (  )  [inline, private]

00311                                        {
00312     using namespace std;
00313     linalg::vector rhs(n+m);
00314 
00315     map<point, double>::const_iterator I;
00316 
00317     I = (thebvp -> get_f()).begin();
00318     for(size_t i = 1; i <= n; i++){
00319       rhs(i) = I->second;
00320       I++;
00321     }
00322     I = (thebvp -> get_g()).begin();   
00323     for(size_t i = n+1; i <= n+m; i++){
00324       rhs(i) = I->second;
00325       I++;
00326     }
00327 
00328     //cout << "Condition number: " << M.cond() << endl;
00329     coeffs = M.inv(rhs);
00330     remtable.clear();
00331   }

Here is the call graph for this function:

template<typename RBF>
void bvp::interpolator< RBF >::init ( shared_ptr< linear_BVP2 bvp  )  [inline, private]

00082   {
00083     thebvp = bvp;
00084 
00085     using namespace linalg;
00086     using std::set;
00087     
00088     shared_ptr<const domain> Omega = bvp -> get_domain();
00089     set<point> interior = Omega -> get_interior();
00090     set<point> boundary = Omega -> get_boundary();
00091     map<point, vector> normals = Omega -> get_normals();
00092     n = interior.size();
00093     m = boundary.size();
00094     
00095     vector temp(n+m);
00096     coeffs = temp;
00097     rbfs.reserve(n+m);
00098 
00099     
00100     RBF::set_dimension(Omega -> get_dimension());
00101     
00102     set<point>::iterator I;
00103     //Define all the rbfs...
00104     for(I = interior.begin(); I != interior.end(); I++){
00105       RBF r(*I);
00106       rbfs.push_back(r);
00107     }
00108     for(I = boundary.begin(); I != boundary.end(); I++){
00109       RBF r(*I);
00110       rbfs.push_back(r);
00111     }
00112     
00113     //Now define the matrix to be inverted...
00114     matrix Mtemp(n+m,n+m);
00115     M = Mtemp;
00116     shared_ptr<const linear_diff_op2> L = thebvp -> get_linear_diff_op2(); 
00117 
00118     shared_ptr<const bdry_diff_op> B = thebvp -> get_bdry_diff_op();
00119 
00120     I = interior.begin();
00121     for(size_t i = 1; i <= n; i++){
00122       for(size_t j = 1; j <= n+m; j++)
00123         M(i,j) = L -> at(rbfs[j-1], *I);
00124       I++;
00125     }
00126     
00127     map<point, vector>::iterator J;
00128     J = normals.begin();
00129     for(size_t i = n+1; i <= n+m; i++){
00130       for(size_t j = 1; j <= n+m; j++)
00131         M(i,j) = B -> at(rbfs[j-1], J->first, J->second);
00132       J++;
00133     }
00134 
00135        
00136     computecoeffs();
00137     initted = true;
00138     rbfs_hash = hash_value(rbfs);
00139   }

Here is the call graph for this function:

template<typename RBF>
void bvp::interpolator< RBF >::not_initted ( int  line,
string  file 
) const [inline, private]

00301                                                                 {
00302     badArgument exc;
00303     exc.reason = 
00304       "Interpolator can't interpolate without initialisation data.";
00305     exc.line = line;
00306     exc.file = file;
00307     throw exc;
00308   }

template<typename RBF>
size_t bvp::interpolator< RBF >::hash_value ( const std::vector< RBF > &  rbfs_in  )  [inline, private]

00142                                                                    {
00143     set<RBF> rbfs_set;
00144     for(size_t i = 0; i < rbfs_in.size(); i++)
00145       rbfs_set.insert(rbfs_in[i]);
00146 
00147     size_t seed = 0;
00148     
00149     for(typename set<RBF>::iterator i = rbfs_set.begin();
00150         i != rbfs_set.end(); i++){
00151       boost::hash_combine(seed,*i);
00152     }
00153 
00154     return seed;
00155   }


Member Data Documentation

template<typename RBF>
size_t bvp::interpolator< RBF >::rbfs_hash

template<typename RBF>
shared_ptr<linear_BVP2> bvp::interpolator< RBF >::thebvp [private]

template<typename RBF>
size_t bvp::interpolator< RBF >::n [private]

template<typename RBF>
size_t bvp::interpolator< RBF >::m [private]

template<typename RBF>
matrix bvp::interpolator< RBF >::M [private]

template<typename RBF>
bool bvp::interpolator< RBF >::initted [private]

template<typename RBF>
linalg::vector bvp::interpolator< RBF >::coeffs [private]

template<typename RBF>
std::vector<RBF> bvp::interpolator< RBF >::rbfs [private]

template<typename RBF>
map<diff_data, double> bvp::interpolator< RBF >::remtable [mutable, private]


The documentation for this class was generated from the following files:

Generated on Fri Jun 6 17:28:28 2008 by  doxygen 1.5.6