SundanceDoublingStepController.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
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

Site Contact