00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __RVL_SCANTEST
00034 #define __RVL_SCANTEST
00035
00036 #include "functional.hh"
00037
00038 namespace RVL {
00039
00043 template<class Scalar>
00044 void Scan(Functional<Scalar> const & f,
00045 const Vector<Scalar> & y,
00046 const Vector<Scalar> & p,
00047 int n=11,
00048 Scalar hmin=-ScalarFieldTraits<Scalar>::One(),
00049 Scalar hmax=ScalarFieldTraits<Scalar>::One(),
00050 ostream & str=cout) {
00051
00052 try {
00053
00054 if (!y.inSpace(f.getDomain())) {
00055 RVLException e; e<<"Error in Scan: \n";
00056 e<<" base vector is not in Domain\n";
00057 throw e;
00058 }
00059 if (!p.inSpace(f.getDomain())) {
00060 RVLException e; e<<"Error in Scan: \n";
00061 e<<" direction vector is not in Domain\n";
00062 throw e;
00063 }
00064 if (n<0) {
00065 RVLException e;
00066 e<<"Error in Scan\n";
00067 e<<" requested negative number of steps n="<<n<<"\n";
00068 throw e;
00069 }
00070
00071 if (hmax > f.getMaxStep(y,p)) {
00072 RVLException e;
00073 e<<"Error in Scan\n";
00074 e<<" max step "<<hmax<<" leaves domain of input function\n";
00075 throw e;
00076 }
00077
00078 if (hmax > f.getMaxStep(y,p)) {
00079 RVLException e;
00080 e<<"Error in Scan\n";
00081 e<<" max step "<<hmax<<" leaves domain of input function\n";
00082 throw e;
00083 }
00084 if (hmin > f.getMaxStep(y,p)) {
00085 RVLException e;
00086 e<<"Error in Scan\n";
00087 e<<" min step "<<hmax<<" leaves domain of input function\n";
00088 throw e;
00089 }
00090 if (hmax<0) {
00091 Vector<Scalar> ptemp(f.getDomain());
00092 Scalar one = ScalarFieldTraits<Scalar>::One();
00093 ptemp.scale(-one,p);
00094 if (-hmax > f.getMaxStep(y,ptemp)) {
00095 RVLException e;
00096 e<<"Error in Scan\n";
00097 e<<" max step "<<hmax<<" leaves domain of input function\n";
00098 throw e;
00099 }
00100 }
00101 if (hmin<0) {
00102 Vector<Scalar> ptemp(f.getDomain());
00103 Scalar one = ScalarFieldTraits<Scalar>::One();
00104 ptemp.scale(-one,p);
00105 if (-hmin > f.getMaxStep(y,ptemp)) {
00106 RVLException e;
00107 e<<"Error in Scan\n";
00108 e<<" max step "<<hmax<<" leaves domain of input function\n";
00109 throw e;
00110 }
00111 }
00112 Vector<Scalar> x(f.getDomain());
00113 FunctionalEvaluation<Scalar> feval(f,x);
00114
00115 int nd;
00116 if (numeric_precision<Scalar>()==1) nd = 8;
00117 if (numeric_precision<Scalar>()==2) nd = 16;
00118 int oldprecision = str.precision(nd);
00119
00120 Scalar hstep;
00121 if (n>1) hstep = (hmax-hmin)/(n-1);
00122 else hstep = ScalarFieldTraits<Scalar>::Zero();
00123
00124 for (int i=0;i<n;i++) {
00125 Scalar h = hmin+i*hstep;
00126 x.copy(y);
00127 x.linComb(h,p);
00128 str << setprecision(6) << setw(8) << h << " "
00129 << setprecision(nd) << setw(nd+6) << feval.getValue()
00130 << endl;
00131 cerr<<h<<" "<<feval.getValue()<<endl;
00132 }
00133 str.precision(oldprecision);
00134 }
00135 catch (RVLException & e) {
00136 e<<"\ncalled from Scan\n";
00137 throw e;
00138 }
00139 }
00140
00141 }
00142
00143 #endif