00001 /*************************************************************************** 00002 vfwithbump.h - description 00003 ------------------- 00004 begin : Fri May 12 2000 00005 copyright : (C) 2000 by Michael Peeters 00006 email : Michael.Peeters@vub.ac.be 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef VFWITHBUMP_H 00019 #define VFWITHBUMP_H 00020 00021 #include "vectorfunction.h" 00022 #include "newtonroot.h" 00023 #include <vector> 00024 00025 namespace MODEL { 00030 // Prev: template <integer dims, class NT = NumericTraits<number,dims> > 00031 template<integer dims, typename nelem=number, class NT = NumericTraits<nelem,dims> > 00032 class VFwithBump : public VectorFunction<dims,nelem,NT> 00033 { 00034 public: 00037 VFwithBump(vf& func,bool own=false) 00038 : f((own)?func.clone():&func), owned(own) {} 00039 00041 VFwithBump(vf& func,const vect& position,bool own=false) 00042 : f((own)?func.clone():&func), owned(own) { AddBump(position);} 00043 ~VFwithBump() {if(owned)delete f;} 00044 00046 void AddBump(const vect& position) {p.push_back(position);} 00047 00049 VFwithBump(const VFwithBump& vfb) : f(vfb.f), owned(false), p(vfb.p){} 00051 const VFwithBump& operator=(const VFwithBump& vfb) 00052 { if (this!=&vfb){f=vfb.f;owned=false;p=vfb.p;} return *this;} 00053 00055 virtual VFwithBump* clone () const {return new VFwithBump(*this);} 00056 00061 virtual const vect& function(vect& fu,const vect& u) 00062 { 00063 // Here we have to iterate over all p's 00064 vector<vect>::iterator runner(p.begin()); 00065 00066 // if we have no bumps, nothing should happen 00067 if(runner==p.end()) {return f->function(fu,u); } 00068 00069 // Otherwise 00070 nelem factor=1.; 00071 while(runner!=p.end()) 00072 { 00073 // if we have a point, 00074 00075 // Calculate delta u 00076 vect bump(u); 00077 bump-=(*runner); 00078 00079 // Calculate how far we are from the point and add a 00080 // hypersphere of zeroes 00083 number distance=abs(length(bump)-1.5*NewtonRoot<dims,nelem,NT>::tolerancex)/length(bump); 00084 00085 factor /= distance; // close to zero goes to zero 00086 ++runner; 00087 } 00088 f->function(fu,u); 00089 fu*=(1+factor); 00090 00091 return fu; 00092 } 00093 00094 private: 00095 vf* f; 00096 bool owned; 00097 vector<vect> p; // not just one position 00098 }; 00099 00100 } // end namespace 00101 #endif 00102 00103 /********************************************************************* 00104 $Id: vfwithbump.h,v 1.2 2001/07/26 12:08:28 mpeeters Exp $ 00105 ********************************************************************** 00106 00107 $Log: vfwithbump.h,v $ 00108 Revision 1.2 2001/07/26 12:08:28 mpeeters 00109 Removed a nasty error where the size of the hypersphere used to cut the zero out of existence would be absolute instead of relative. A better (relative) solution was found, but an even better one exists (see todo note). 00110 00111 Revision 1.1 2001/05/22 10:54:55 mpeeters 00112 Moved sources and headers for libModel to model/ subdirectory, in an attempt to rationalize the source tree. This should make things "netter". 00113 00114 Revision 1.2 2000/09/15 10:26:31 mpeeters 00115 Cleaned out header and added CVS tails to files, removed superfuous 00116 @author comments, inserted dates 00117 00118 *********************************************************************/
More Info? Michael Peeters. Also, check our research website: www.alna.vub.ac.be
Last update: June 2002.