SundanceDoublingStepController.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #ifndef SUNDANCE_DOUBLING_STEP_CONTROLLER_H
00043 #define SUNDANCE_DOUBLING_STEP_CONTROLLER_H
00044 
00045 #include "SundanceFieldWriter.hpp"
00046 #include "SundanceFieldWriterFactory.hpp"
00047 #include "SundanceTransientStepProblem.hpp"
00048 #include "SundanceExprComparison.hpp"
00049 #include "SundanceEventDetector.hpp"
00050 
00051 
00052 
00053 namespace Sundance
00054 {
00055 
00056 /** */
00057 class StepControlParameters
00058 {
00059 public:
00060   /** */
00061   StepControlParameters()
00062     {initDefaults();}
00063 
00064   double tStart_;
00065 
00066   double tStop_;
00067 
00068   double tau_;
00069 
00070   double initialStepsize_;
00071 
00072   double minStepsizeFactor_;
00073 
00074   double maxStepsizeFactor_;
00075 
00076   double stepsizeReductionSafetyFactor_;
00077 
00078   int maxSteps_;
00079 
00080   int verbosity_;
00081 
00082   int stepOrder_;
00083 
00084 private:
00085   void initDefaults()
00086     {
00087       tStart_ = 0.0;
00088       tStop_ = 0.0;
00089       tau_ = 1.0e-6;
00090       initialStepsize_ = 0.01;
00091       minStepsizeFactor_ = 0.01;
00092       maxStepsizeFactor_ = 10.0;
00093       stepsizeReductionSafetyFactor_ = 0.9;
00094       maxSteps_ = 100000;
00095       verbosity_ = 0;
00096       stepOrder_ = 2;
00097     }
00098 };
00099 
00100 /** */
00101 class StepHookBase
00102 {
00103 public:
00104   virtual void call(const double& tCur, const Expr& uCur) const = 0 ;
00105 };
00106 
00107 /** */
00108 class OutputControlParameters
00109 {
00110 public:
00111   /** */
00112   OutputControlParameters(
00113     const FieldWriterFactory& wf,
00114     const string& filename,
00115     const double& writeInterval,
00116     int verb=0)
00117     : 
00118     writeInterval_(writeInterval),
00119     wf_(wf),
00120     filename_(filename),
00121     verbosity_(verb)
00122     {}
00123   
00124   double writeInterval_;
00125   FieldWriterFactory wf_;
00126   string filename_;
00127   int verbosity_;
00128 };
00129 
00130 
00131 /** */
00132 class DoublingStepController
00133 {
00134 public:
00135   /** */
00136   DoublingStepController(
00137     const TransientStepProblem& prob,
00138     const NonlinearSolver<double>& solver,
00139     const StepControlParameters& stepControl,
00140     const OutputControlParameters& outputControl,
00141     const RCP<ExprComparisonBase>& compare)
00142     : prob_(prob), 
00143       stepControl_(stepControl), 
00144       outputControl_(outputControl),
00145       solver_(solver),
00146       compare_(compare),
00147       eventHandler_()
00148     {}
00149 
00150   /** */
00151   void setEventHandler(RCP<EventDetectorBase> e)
00152     {eventHandler_ = e;}
00153 
00154   /** */
00155   void setStepHook(RCP<StepHookBase> h)
00156     {stepHook_ = h;}
00157       
00158 
00159   /** */
00160   bool run() const ;
00161 
00162   /** */
00163   void write(int index, double t, const Expr& u) const ;
00164 
00165 private:
00166   TransientStepProblem prob_;
00167   StepControlParameters stepControl_;
00168   OutputControlParameters outputControl_;
00169   NonlinearSolver<double> solver_;
00170   RCP<ExprComparisonBase> compare_;
00171   RCP<EventDetectorBase> eventHandler_;
00172   RCP<StepHookBase> stepHook_;
00173 };
00174 
00175 
00176 }
00177 
00178 
00179 #endif

Site Contact