00001
00002
00003
00004 #ifndef INCLUDED_ODESOLV_H
00005 #define INCLUDED_ODESOLV_H
00006
00007
00008 #include "vndflags.h"
00009 #include "vndstat.h"
00010 #include "odenum.h"
00011 #include "stepctrl.h"
00012 #include "datarepr.h"
00013
00014
00015 class ODE_SOLVER;
00016
00018 typedef ODE_SOLVER* PtrODESolver;
00019
00020
00026 class ODE_SOLVER
00027 {
00028
00029 public:
00030
00045 virtual void IntegrateTo ( double tEnd, bool Continue = false ) = 0;
00046
00055 void Integrate ( bool Continue = false );
00056
00066 template<class T> friend T* GetDataRepr( const PtrODESolver Solver );
00067
00073 void SetDataRepr ( const PtrDataRepr Data );
00074
00080 void SetStepControl ( const PtrStepCtrl Step );
00081
00083 const PtrStepCtrl GetStepCtrl() const;
00084
00085
00092 void VerboseOutput ( bool b );
00093
00099 bool VerboseOutput () const;
00100
00118 void PrintData( ostream & os = cout );
00119
00125 void GraphOutput ( bool b );
00126
00132 bool GraphOutput () const;
00133
00139 void ContinueOutput( bool b );
00140
00146 bool ContinueOutput() const;
00147
00159 void DisplayStepSize ( const char * file_name = 0 ) const ;
00160
00173 void DisplayOrder ( const char *file_name = 0 ) const ;
00174
00179 bool FirstStep() const;
00180
00185 bool AcceptedStep() const;
00186
00187
00189 virtual ~ODE_SOLVER();
00190
00191
00192 protected:
00193
00204 ODE_SOLVER( const PtrODENumeric ODE,
00205 const PtrDataRepr Data,
00206 const PtrStepCtrl Step,
00207 const PtrSolverFlags Flags = new SOLVER_FLAGS,
00208 const PtrSolverStats Stats = new SOLVER_STATS );
00209
00210
00212 virtual void InitSolver() = 0;
00213
00214
00222 void SetErrors( double t, const INTERVAL_VECTOR & Y );
00223
00224 protected:
00225
00227 PtrODENumeric ODE;
00228
00230 PtrDataRepr DataRepr;
00231
00233 PtrStepCtrl StepControl;
00234
00236 PtrSolverFlags SolverFlags;
00237
00239 PtrSolverStats SolverStats;
00240
00241 };
00242
00243
00244
00245 template<class T> T* GetDataRepr( const PtrODESolver Solver )
00246 {
00247 assert(Solver);
00248 return static_cast<T*>( Solver->DataRepr );
00249 }
00250
00251
00252 inline const PtrStepCtrl ODE_SOLVER :: GetStepCtrl() const
00253 {
00254 return StepControl;
00255 }
00256
00257
00258 inline ODE_SOLVER :: ODE_SOLVER( const PtrODENumeric ODE,
00259 const PtrDataRepr Data,
00260 const PtrStepCtrl Step,
00261 const PtrSolverFlags Flags,
00262 const PtrSolverStats Stats )
00263 : ODE(ODE),
00264 DataRepr(Data),
00265 StepControl(Step),
00266 SolverFlags( Flags ),
00267 SolverStats( Stats )
00268 {
00269 assert( NotNull(ODE) );
00270 assert( NotNull(Data) );
00271 assert( NotNull(Step) );
00272 assert( NotNull(Flags) );
00273 assert( NotNull(Stats) );
00274 }
00275
00276
00277 inline void ODE_SOLVER :: SetDataRepr ( const PtrDataRepr Data )
00278 {
00279 assert(Data);
00280 DELETE(DataRepr);
00281 DataRepr = Data;
00282 }
00283
00284
00285 inline void ODE_SOLVER :: Integrate( bool Continue )
00286 {
00287 IntegrateTo( ODE->GetTend(), Continue );
00288 }
00289
00290
00291 inline ODE_SOLVER :: ~ODE_SOLVER()
00292 {
00293 DELETE(ODE);
00294 DELETE(DataRepr);
00295 DELETE(StepControl);
00296 DELETE(SolverFlags);
00297 DELETE(SolverStats);
00298 }
00299
00300
00301 inline void ODE_SOLVER :: SetStepControl ( const PtrStepCtrl Step )
00302 {
00303 assert( NotNull(Step) );
00304 DELETE(StepControl);
00305 StepControl = Step;
00306 }
00307
00308
00309 inline void ODE_SOLVER :: GraphOutput( bool b )
00310 {
00311 SolverFlags->GraphOutput(b);
00312 }
00313
00314
00315 inline bool ODE_SOLVER :: GraphOutput() const
00316 {
00317 return SolverFlags->GraphOutput();
00318 }
00319
00320
00321 inline void ODE_SOLVER :: VerboseOutput( bool b )
00322 {
00323 SolverFlags->VerboseOutput( b );
00324 }
00325
00326
00327 inline bool ODE_SOLVER :: VerboseOutput() const
00328 {
00329 return SolverFlags->VerboseOutput();
00330 }
00331
00332
00333 inline void ODE_SOLVER :: ContinueOutput( bool b )
00334 {
00335 assert( GraphOutput() && b );
00336 SolverFlags->ContinueOutput( b );
00337 }
00338
00339
00340 inline bool ODE_SOLVER :: ContinueOutput() const
00341 {
00342 return SolverFlags->ContinueOutput();
00343 }
00344
00345
00346 inline bool ODE_SOLVER :: FirstStep() const
00347 {
00348 return SolverFlags->FirstStep();
00349 }
00350
00351
00352 inline bool ODE_SOLVER :: AcceptedStep() const
00353 {
00354 return SolverFlags->AcceptedStep();
00355 }
00356
00357
00358 #endif
00359
00360
00361
00362
00363