Rythmos - Transient Integration for Differential Equations Version of the Day
Rythmos_CompositeIntegrationObserver.hpp
00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //                     Rythmos Package
00005 //                 Copyright (2006) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
00028 
00029 #ifndef RYTHMOS_COMPOSITE_INTEGRATION_OBSERVER_HPP
00030 #define RYTHMOS_COMPOSITE_INTEGRATION_OBSERVER_HPP
00031 
00032 
00033 #include "Rythmos_IntegrationObserverBase.hpp"
00034 #include "Teuchos_as.hpp"
00035 
00036 
00037 namespace Rythmos {
00038 
00039 
00044 template<class Scalar>
00045 class CompositeIntegrationObserver
00046   : public IntegrationObserverBase<Scalar>
00047 {
00048 public:
00049 
00052 
00054   CompositeIntegrationObserver();
00055 
00057   void addObserver(
00058     const RCP<IntegrationObserverBase<Scalar> > &observer
00059     );
00060 
00061   // ToDo: Add functions to add observers
00062 
00064 
00067 
00069   virtual RCP<IntegrationObserverBase<Scalar> >
00070   cloneIntegrationObserver() const;
00071 
00073   virtual void resetIntegrationObserver(
00074     const TimeRange<Scalar> &integrationTimeDomain
00075     );
00076 
00077   void observeStartTimeIntegration(const StepperBase<Scalar> &stepper);
00078 
00079   void observeEndTimeIntegration(const StepperBase<Scalar> &stepper);
00080 
00081   void observeStartTimeStep(
00082     const StepperBase<Scalar> &stepper,
00083     const StepControlInfo<Scalar> &stepCtrlInfo,
00084     const int timeStepIter
00085     );
00086 
00088   virtual void observeCompletedTimeStep(
00089     const StepperBase<Scalar> &stepper,
00090     const StepControlInfo<Scalar> &stepCtrlInfo,
00091     const int timeStepIter
00092     );
00093 
00095   virtual void observeFailedTimeStep(
00096     const StepperBase<Scalar> &stepper,
00097     const StepControlInfo<Scalar> &stepCtrlInfo,
00098     const int timeStepIter
00099     );
00100 
00102 
00103 private:
00104 
00105   Array<RCP<IntegrationObserverBase<Scalar> > > observers_;
00106 
00107 };
00108 
00109 
00114 template<class Scalar>
00115 RCP<CompositeIntegrationObserver<Scalar> > createCompositeIntegrationObserver()
00116 {
00117   RCP<CompositeIntegrationObserver<Scalar> >
00118     frsco(new CompositeIntegrationObserver<Scalar>());
00119   return frsco;
00120 }
00121 
00122 
00123 //
00124 // Implementations
00125 //
00126 
00127 
00128 // Constructors/Initializers/Accessors
00129 
00130 
00131 template<class Scalar>
00132 CompositeIntegrationObserver<Scalar>::CompositeIntegrationObserver()
00133 {}
00134 
00135 
00136 template<class Scalar>
00137 void CompositeIntegrationObserver<Scalar>::addObserver(
00138   const RCP<IntegrationObserverBase<Scalar> > &observer
00139   )
00140 {
00141   observers_.push_back(observer);
00142 }
00143 
00144 
00145 // Overridden from IntegrationObserverBase
00146 
00147 
00148 template<class Scalar>
00149 RCP<IntegrationObserverBase<Scalar> >
00150 CompositeIntegrationObserver<Scalar>::cloneIntegrationObserver() const
00151 {
00152   using Teuchos::as;
00153   RCP<CompositeIntegrationObserver<Scalar> >
00154     compositeObserver = createCompositeIntegrationObserver<Scalar>();
00155   for (int i = 0; i < as<int>(observers_.size()); ++i ) {
00156     compositeObserver->addObserver(observers_[i]->cloneIntegrationObserver());
00157   }
00158   return compositeObserver;
00159 }
00160 
00161 
00162 template<class Scalar>
00163 void CompositeIntegrationObserver<Scalar>::resetIntegrationObserver(
00164   const TimeRange<Scalar> &integrationTimeDomain
00165   )
00166 {
00167   using Teuchos::as;
00168   for (int i = 0; i < as<int>(observers_.size()); ++i ) {
00169     observers_[i]->resetIntegrationObserver(integrationTimeDomain);
00170   }
00171 }
00172 
00173 template<class Scalar>
00174 void CompositeIntegrationObserver<Scalar>::observeStartTimeIntegration(
00175   const StepperBase<Scalar> &stepper
00176   )
00177 {
00178   using Teuchos::as;
00179 
00180   const RCP<FancyOStream> out = this->getOStream();
00181   const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00182 
00183   for (int i = 0; i < as<int>(observers_.size()); ++i ) {
00184     RCP<IntegrationObserverBase<Scalar> > observer = observers_[i];
00185     observer->setOStream(out);
00186     observer->setVerbLevel(verbLevel);
00187     observer->observeStartTimeIntegration(stepper);
00188   }
00189 }
00190 
00191 template<class Scalar>
00192 void CompositeIntegrationObserver<Scalar>::observeEndTimeIntegration(
00193   const StepperBase<Scalar> &stepper
00194   )
00195 {
00196   using Teuchos::as;
00197 
00198   const RCP<FancyOStream> out = this->getOStream();
00199   const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00200 
00201   for (int i = 0; i < as<int>(observers_.size()); ++i ) {
00202     RCP<IntegrationObserverBase<Scalar> > observer = observers_[i];
00203     observer->setOStream(out);
00204     observer->setVerbLevel(verbLevel);
00205     observer->observeEndTimeIntegration(stepper);
00206   }
00207 }
00208 
00209 template<class Scalar>
00210 void CompositeIntegrationObserver<Scalar>::observeStartTimeStep(
00211   const StepperBase<Scalar> &stepper,
00212   const StepControlInfo<Scalar> &stepCtrlInfo,
00213   const int timeStepIter
00214   )
00215 {
00216   using Teuchos::as;
00217 
00218   const RCP<FancyOStream> out = this->getOStream();
00219   const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00220 
00221   for (int i = 0; i < as<int>(observers_.size()); ++i ) {
00222     RCP<IntegrationObserverBase<Scalar> > observer = observers_[i];
00223     observer->setOStream(out);
00224     observer->setVerbLevel(verbLevel);
00225     observer->observeStartTimeStep(stepper,stepCtrlInfo,timeStepIter);
00226   }
00227 }
00228 
00229 template<class Scalar>
00230 void CompositeIntegrationObserver<Scalar>::observeCompletedTimeStep(
00231   const StepperBase<Scalar> &stepper,
00232   const StepControlInfo<Scalar> &stepCtrlInfo,
00233   const int timeStepIter
00234   )
00235 {
00236   using Teuchos::as;
00237 
00238   const RCP<FancyOStream> out = this->getOStream();
00239   const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00240 
00241   for (int i = 0; i < as<int>(observers_.size()); ++i ) {
00242     RCP<IntegrationObserverBase<Scalar> > observer = observers_[i];
00243     observer->setOStream(out);
00244     observer->setVerbLevel(verbLevel);
00245     observer->observeCompletedTimeStep(stepper,stepCtrlInfo,timeStepIter);
00246   }
00247 }
00248 
00249 
00250 template<class Scalar>
00251 void CompositeIntegrationObserver<Scalar>::observeFailedTimeStep(
00252   const StepperBase<Scalar> &stepper,
00253   const StepControlInfo<Scalar> &stepCtrlInfo,
00254   const int timeStepIter
00255   )
00256 {
00257   using Teuchos::as;
00258 
00259   const RCP<FancyOStream> out = this->getOStream();
00260   const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00261 
00262   for (int i = 0; i < as<int>(observers_.size()); ++i ) {
00263     RCP<IntegrationObserverBase<Scalar> > observer = observers_[i];
00264     observer->setOStream(out);
00265     observer->setVerbLevel(verbLevel);
00266     observer->observeFailedTimeStep(stepper,stepCtrlInfo,timeStepIter);
00267   }
00268 }
00269 
00270 
00271 } // namespace Rythmos
00272 
00273 
00274 #endif //RYTHMOS_COMPOSITE_INTEGRATOR_OBSERVER_HPP
 All Classes Functions Variables Typedefs Friends