ODERelax.h
00001 #ifndef gridripper_odesolver_relax_ODERelax_h
00002 #define gridripper_odesolver_relax_ODERelax_h
00003
00004 #include <gridripper/config.h>
00005 #include <gridripper/lang/Exception.h>
00006 #include <gridripper/util/GrrProperties.h>
00007 #include <gridripper/tvalarray.h>
00008 #include <string>
00009
00010 namespace gridripper { namespace odesolver {
00011
00012 class ODE;
00013
00014 namespace relax {
00015
00016 using namespace gridripper;
00017 using namespace gridripper::util;
00018 using namespace std;
00019
00027 class ODERelax
00028 {
00029 public:
00033 class Method
00034 {
00035 public:
00036 virtual ~Method() { }
00037
00048 virtual void set(tvalarray<GReal_t>& fieldValues,
00049 tvalarray<GReal_t>& matrix, tvalarray<GReal_t>& rhsvec,
00050 const tvalarray<GReal_t>& deltaField) =0;
00051
00052 virtual int getNumSubsteps() const =0;
00053
00058 int getRowLength() {
00059 int substeps = getNumSubsteps();
00060 return 2*substeps + 1;
00061 }
00062 };
00063
00067 class RelaxationException: public Exception
00068 {
00069 public:
00074 RelaxationException(const RelaxationException& other):
00075 Exception(other) { }
00076
00082 RelaxationException(const string& msg, const string& where):
00083 Exception(msg, where) { }
00084
00090 RelaxationException(const Exception& orig, const string& where):
00091 Exception(orig, where) { }
00092
00099 RelaxationException(const Exception& orig, const string& msg,
00100 const string& where):
00101 Exception(orig, msg, where) { }
00102 };
00103
00104 private:
00105 string dataFormat;
00106 ODE* theODE;
00107 int maxi;
00108 int order;
00109 tvalarray<GReal_t> matrix;
00110 tvalarray<GReal_t> rhsvec;
00111 tvalarray<GReal_t> fieldValues;
00112 tvalarray<GReal_t> deltaFieldValues;
00113 Method* method;
00114 int numIterations;
00115 double relativeError;
00116
00117 public:
00122 ODERelax(const GrrProperties& props) throw(RelaxationException&);
00123
00129 ODERelax(const GrrProperties& props, int maxi)
00130 throw(RelaxationException&);
00131
00138 ODERelax(ODE* ode, tvalarray<GReal_t>& data, int order)
00139 throw(RelaxationException&);
00140
00141 ~ODERelax();
00142
00147 ODE& getODE() const {
00148 return *theODE;
00149 }
00150
00155 int getMaxI() {
00156 return maxi;
00157 }
00158
00163 string getDataFormat() {
00164 return dataFormat;
00165 }
00166
00171 double getRelativeError() {
00172 return relativeError;
00173 }
00174
00179 int getNumIterations() {
00180 return numIterations;
00181 }
00182
00188 void setNumIterations(int n) {
00189 numIterations = n;
00190 }
00191
00196 void solve(tvalarray<GReal_t>& sol) throw(RelaxationException&);
00197
00203 double nextIteration() throw(RelaxationException&);
00204
00205 private:
00206 void init(ODE* ode, tvalarray<GReal_t>& data, int order)
00207 throw(RelaxationException&);
00208
00209 void diagonalize();
00210
00211 void unite() throw(RelaxationException&);
00212
00213 string getOrderedComponentName(int j) const;
00214 };
00215
00216 } } }
00217
00218 #endif