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 #ifndef SUNDANCE_DOUBLING_STEP_CONTROLLER_H
00032 #define SUNDANCE_DOUBLING_STEP_CONTROLLER_H
00033 
00034 #include "SundanceFieldWriter.hpp"
00035 #include "SundanceFieldWriterFactory.hpp"
00036 #include "SundanceTransientStepProblem.hpp"
00037 #include "SundanceExprComparison.hpp"
00038 #include "SundanceEventDetector.hpp"
00039 
00040 
00041 
00042 namespace Sundance
00043 {
00044 
00045 
00046 class StepControlParameters
00047 {
00048 public:
00049 
00050   StepControlParameters()
00051     {initDefaults();}
00052 
00053   double tStart_;
00054 
00055   double tStop_;
00056 
00057   double tau_;
00058 
00059   double initialStepsize_;
00060 
00061   double minStepsizeFactor_;
00062 
00063   double maxStepsizeFactor_;
00064 
00065   double stepsizeReductionSafetyFactor_;
00066 
00067   int maxSteps_;
00068 
00069   int verbosity_;
00070 
00071   int stepOrder_;
00072 
00073 private:
00074   void initDefaults()
00075     {
00076       tStart_ = 0.0;
00077       tStop_ = 0.0;
00078       tau_ = 1.0e-6;
00079       initialStepsize_ = 0.01;
00080       minStepsizeFactor_ = 0.01;
00081       maxStepsizeFactor_ = 10.0;
00082       stepsizeReductionSafetyFactor_ = 0.9;
00083       maxSteps_ = 100000;
00084       verbosity_ = 0;
00085       stepOrder_ = 2;
00086     }
00087 };
00088 
00089 
00090 class StepHookBase
00091 {
00092 public:
00093   virtual void call(const double& tCur, const Expr& uCur) const = 0 ;
00094 };
00095 
00096 
00097 class OutputControlParameters
00098 {
00099 public:
00100 
00101   OutputControlParameters(
00102     const FieldWriterFactory& wf,
00103     const string& filename,
00104     const double& writeInterval,
00105     int verb=0)
00106     : 
00107     writeInterval_(writeInterval),
00108     wf_(wf),
00109     filename_(filename),
00110     verbosity_(verb)
00111     {}
00112   
00113   double writeInterval_;
00114   FieldWriterFactory wf_;
00115   string filename_;
00116   int verbosity_;
00117 };
00118 
00119 
00120 
00121 class DoublingStepController
00122 {
00123 public:
00124 
00125   DoublingStepController(
00126     const TransientStepProblem& prob,
00127     const NonlinearSolver<double>& solver,
00128     const StepControlParameters& stepControl,
00129     const OutputControlParameters& outputControl,
00130     const RCP<ExprComparisonBase>& compare)
00131     : prob_(prob), 
00132       stepControl_(stepControl), 
00133       outputControl_(outputControl),
00134       solver_(solver),
00135       compare_(compare),
00136       eventHandler_()
00137     {}
00138 
00139 
00140   void setEventHandler(RCP<EventDetectorBase> e)
00141     {eventHandler_ = e;}
00142 
00143 
00144   void setStepHook(RCP<StepHookBase> h)
00145     {stepHook_ = h;}
00146       
00147 
00148 
00149   bool run() const ;
00150 
00151 
00152   void write(int index, double t, const Expr& u) const ;
00153 
00154 private:
00155   TransientStepProblem prob_;
00156   StepControlParameters stepControl_;
00157   OutputControlParameters outputControl_;
00158   NonlinearSolver<double> solver_;
00159   RCP<ExprComparisonBase> compare_;
00160   RCP<EventDetectorBase> eventHandler_;
00161   RCP<StepHookBase> stepHook_;
00162 };
00163 
00164 
00165 }
00166 
00167 
00168 #endif