scantest.hh

Go to the documentation of this file.
00001 /*************************************************************************
00002 
00003 Copyright Rice University, 2004-2013
00004 All rights reserved.
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a
00007 copy of this software and associated documentation files (the "Software"),
00008 to deal in the Software without restriction, including without limitation
00009 the rights to use, copy, modify, merge, publish, distribute, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, provided that the above copyright notice(s) and this
00012 permission notice appear in all copies of the Software and that both the
00013 above copyright notice(s) and this permission notice appear in supporting
00014 documentation.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
00019 RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS
00020 NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
00021 DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
00022 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
00023 ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
00024 THIS SOFTWARE.
00025 
00026 Except as contained in this notice, the name of a copyright holder shall
00027 not be used in advertising or otherwise to promote the sale, use or other
00028 dealings in this Software without prior written authorization of the
00029 copyright holder.
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

Generated on 5 Jan 2017 for RVL by  doxygen 1.4.7