Rythmos - Transient Integration for Differential Equations Version of the Day
Rythmos_CompositeIntegratorObserver.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_INTEGRATOR_OBSERVER_HPP
00030 #define RYTHMOS_COMPOSITE_INTEGRATOR_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 CompositeIntegratorObserver
00046   : public IntegrationObserverBase<Scalar>
00047 {
00048 public:
00049 
00052 
00054   CompositeIntegratorObserver();
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 
00078   virtual void observeCompletedTimeStep(
00079     const StepperBase<Scalar> &stepper,
00080     const StepControlInfo<Scalar> &stepCtrlInfo,
00081     const int timeStepIter
00082     );
00083 
00085 
00086 private:
00087 
00088   Array<RCP<IntegrationObserverBase<Scalar> > > observers_;
00089 
00090 };
00091 
00092 
00097 template<class Scalar>
00098 RCP<CompositeIntegratorObserver<Scalar> > compositeIntegratorObserver()
00099 {
00100   RCP<CompositeIntegratorObserver<Scalar> >
00101     frsco(new CompositeIntegratorObserver<Scalar>());
00102   return frsco;
00103 }
00104 
00105 
00106 //
00107 // Implementations
00108 //
00109 
00110 
00111 // Constructors/Initializers/Accessors
00112 
00113 
00114 template<class Scalar>
00115 CompositeIntegratorObserver<Scalar>::CompositeIntegratorObserver()
00116 {}
00117 
00118 
00119 template<class Scalar>
00120 void CompositeIntegratorObserver<Scalar>::addObserver(
00121   const RCP<IntegrationObserverBase<Scalar> > &observer
00122   )
00123 {
00124 #ifdef RYTHMOS_DEBUG
00125   TEST_FOR_EXCEPT(is_null(observer));
00126 #endif
00127   observers_.push_back(observer);
00128 }
00129 
00130 
00131 // Overridden from IntegrationObserverBase
00132 
00133 
00134 template<class Scalar>
00135 RCP<IntegrationObserverBase<Scalar> >
00136 CompositeIntegratorObserver<Scalar>::cloneIntegrationObserver() const
00137 {
00138   using Teuchos::as;
00139   RCP<CompositeIntegratorObserver<Scalar> >
00140     compositeObserver = compositeIntegratorObserver<Scalar>();
00141   for (int i = 0; i < as<int>(observers_.size()); ++i ) {
00142     compositeObserver->addObserver(observers_[i]->cloneIntegrationObserver());
00143   }
00144   TEST_FOR_EXCEPTION( true, std::logic_error,
00145     "Error, I have not tested this function yet so look over this very carefully before you"
00146     " remove this this macro call!" );
00147   return compositeObserver;
00148 }
00149 
00150 
00151 template<class Scalar>
00152 void CompositeIntegratorObserver<Scalar>::resetIntegrationObserver(
00153   const TimeRange<Scalar> &integrationTimeDomain
00154   )
00155 {
00156   using Teuchos::as;
00157   for (int i = 0; i < as<int>(observers_.size()); ++i ) {
00158     observers_[i]->resetIntegrationObserver(integrationTimeDomain);
00159   }
00160 }
00161 
00162 
00163 template<class Scalar>
00164 void CompositeIntegratorObserver<Scalar>::observeCompletedTimeStep(
00165   const StepperBase<Scalar> &stepper,
00166   const StepControlInfo<Scalar> &stepCtrlInfo,
00167   const int timeStepIter
00168   )
00169 {
00170   using Teuchos::as;
00171 
00172   const RCP<FancyOStream> out = this->getOStream();
00173   const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00174 
00175   for (int i = 0; i < as<int>(observers_.size()); ++i ) {
00176     RCP<IntegrationObserverBase<Scalar> > observer = observers_[i];
00177     observer->setOStream(out);
00178     observer->setVerbLevel(verbLevel);
00179     observer->observeCompletedTimeStep(stepper,stepCtrlInfo,timeStepIter);
00180   }
00181 }
00182 
00183 
00184 } // namespace Rythmos
00185 
00186 
00187 #endif //RYTHMOS_COMPOSITE_INTEGRATOR_OBSERVER_HPP
 All Classes Functions Variables Typedefs Friends