|
Rythmos - Transient Integration for Differential Equations
Version of the Day
|
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00023 // USA 00024 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 00028 00029 #ifndef Rythmos_LOGGING_INTEGRATION_OBSERVER_HPP 00030 #define Rythmos_LOGGING_INTEGRATION_OBSERVER_HPP 00031 00032 #include "Rythmos_IntegrationObserverBase.hpp" 00033 #include "Teuchos_RCP.hpp" 00034 #include <map> 00035 #include <list> 00036 #include <string> 00037 00038 namespace Rythmos { 00039 00040 00043 template<class Scalar> 00044 class LoggingIntegrationObserver : virtual public IntegrationObserverBase<Scalar> 00045 { 00046 public: 00047 00048 LoggingIntegrationObserver(); 00049 00050 void resetLogCounters(); 00051 00052 Teuchos::RCP<const std::map<std::string,int> > getCounters(); 00053 00054 Teuchos::RCP<const std::list<std::string> > getOrder(); 00055 00058 00059 RCP<IntegrationObserverBase<Scalar> > cloneIntegrationObserver() const; 00060 00061 void 00062 resetIntegrationObserver(const TimeRange<Scalar> &integrationTimeDomain); 00063 00064 void observeStartTimeIntegration(const StepperBase<Scalar> &stepper); 00065 00066 void observeEndTimeIntegration(const StepperBase<Scalar> &stepper); 00067 00068 void observeStartTimeStep( 00069 const StepperBase<Scalar> &stepper, 00070 const StepControlInfo<Scalar> &stepCtrlInfo, 00071 const int timeStepIter 00072 ); 00073 00074 void observeCompletedTimeStep( 00075 const StepperBase<Scalar> &stepper, 00076 const StepControlInfo<Scalar> &stepCtrlInfo, 00077 const int timeStepIter 00078 ); 00079 00080 void observeFailedTimeStep( 00081 const StepperBase<Scalar> &stepper, 00082 const StepControlInfo<Scalar> &stepCtrlInfo, 00083 const int timeStepIter 00084 ); 00085 00087 00093 00094 const std::string nameCloneIntegrationObserver_; 00095 const std::string nameResetIntegrationObserver_; 00096 const std::string nameObserveStartTimeIntegration_; 00097 const std::string nameObserveEndTimeIntegration_; 00098 const std::string nameObserveStartTimeStep_; 00099 const std::string nameObserveCompletedTimeStep_; 00100 const std::string nameObserveFailedTimeStep_; 00101 00103 00104 00105 private: 00106 00112 void logCall(const std::string call) const; 00113 00114 private: 00115 00116 Teuchos::RCP< std::map<std::string,int> > counters_; 00117 Teuchos::RCP< std::list<std::string> > order_; 00118 00119 }; 00120 00121 00126 template<class Scalar> 00127 Teuchos::RCP<LoggingIntegrationObserver<Scalar> > 00128 createLoggingIntegrationObserver() 00129 { 00130 const Teuchos::RCP<LoggingIntegrationObserver<Scalar> > lio = 00131 Teuchos::rcp(new LoggingIntegrationObserver<Scalar>); 00132 00133 return lio; 00134 } 00135 00136 00137 // ////////////////////////////////////////////////////// 00138 // Implementations 00139 00140 template<typename Scalar> 00141 LoggingIntegrationObserver<Scalar>::LoggingIntegrationObserver() : 00142 nameCloneIntegrationObserver_("cloneIntegrationObserver"), 00143 nameResetIntegrationObserver_("resetIntegrationObserver"), 00144 nameObserveStartTimeIntegration_("observeStartTimeIntegration"), 00145 nameObserveEndTimeIntegration_("observeEndTimeIntegration"), 00146 nameObserveStartTimeStep_("observeStartTimeStep"), 00147 nameObserveCompletedTimeStep_("observeCompletedTimeStep"), 00148 nameObserveFailedTimeStep_("observeFailedTimeStep") 00149 { 00150 counters_ = Teuchos::rcp(new std::map<std::string,int>); 00151 order_ = Teuchos::rcp(new std::list<std::string>); 00152 this->resetLogCounters(); 00153 } 00154 00155 template<typename Scalar> 00156 void LoggingIntegrationObserver<Scalar>:: 00157 resetLogCounters() 00158 { 00159 (*counters_)[nameCloneIntegrationObserver_] = 0; 00160 (*counters_)[nameResetIntegrationObserver_] = 0; 00161 (*counters_)[nameObserveStartTimeIntegration_] = 0; 00162 (*counters_)[nameObserveEndTimeIntegration_] = 0; 00163 (*counters_)[nameObserveStartTimeStep_] = 0; 00164 (*counters_)[nameObserveCompletedTimeStep_] = 0; 00165 (*counters_)[nameObserveFailedTimeStep_] = 0; 00166 order_->clear(); 00167 } 00168 00169 template<typename Scalar> 00170 RCP<IntegrationObserverBase<Scalar> > 00171 LoggingIntegrationObserver<Scalar>::cloneIntegrationObserver() const 00172 { 00173 logCall(nameCloneIntegrationObserver_); 00174 Teuchos::RCP<IntegrationObserverBase<Scalar> > observer = 00175 Teuchos::rcp(new LoggingIntegrationObserver<Scalar>(*this)); 00176 return observer; 00177 } 00178 00179 template<typename Scalar> 00180 void 00181 LoggingIntegrationObserver<Scalar>:: 00182 resetIntegrationObserver(const TimeRange<Scalar> &integrationTimeDomain) 00183 { 00184 logCall(nameResetIntegrationObserver_); 00185 } 00186 00187 template<typename Scalar> 00188 void LoggingIntegrationObserver<Scalar>:: 00189 observeStartTimeIntegration(const StepperBase<Scalar> &stepper) 00190 { 00191 logCall(nameObserveStartTimeIntegration_); 00192 } 00193 00194 template<typename Scalar> 00195 void LoggingIntegrationObserver<Scalar>:: 00196 observeEndTimeIntegration(const StepperBase<Scalar> &stepper) 00197 { 00198 logCall(nameObserveEndTimeIntegration_); 00199 } 00200 00201 template<typename Scalar> 00202 void LoggingIntegrationObserver<Scalar>::observeStartTimeStep( 00203 const StepperBase<Scalar> &stepper, 00204 const StepControlInfo<Scalar> &stepCtrlInfo, 00205 const int timeStepIter 00206 ) 00207 { 00208 logCall(nameObserveStartTimeStep_); 00209 } 00210 00211 template<typename Scalar> 00212 void LoggingIntegrationObserver<Scalar>::observeCompletedTimeStep( 00213 const StepperBase<Scalar> &stepper, 00214 const StepControlInfo<Scalar> &stepCtrlInfo, 00215 const int timeStepIter 00216 ) 00217 { 00218 logCall(nameObserveCompletedTimeStep_); 00219 } 00220 00221 template<typename Scalar> 00222 void LoggingIntegrationObserver<Scalar>::observeFailedTimeStep( 00223 const StepperBase<Scalar> &stepper, 00224 const StepControlInfo<Scalar> &stepCtrlInfo, 00225 const int timeStepIter 00226 ) 00227 { 00228 logCall(nameObserveFailedTimeStep_); 00229 } 00230 00231 template<typename Scalar> 00232 RCP<const std::map<std::string,int> > LoggingIntegrationObserver<Scalar>::getCounters() 00233 { 00234 return counters_; 00235 } 00236 00237 template<typename Scalar> 00238 RCP<const std::list<std::string> > LoggingIntegrationObserver<Scalar>::getOrder() 00239 { 00240 return order_; 00241 } 00242 00243 00244 template<typename Scalar> 00245 void LoggingIntegrationObserver<Scalar>::logCall(const std::string call) const 00246 { 00247 (*counters_)[call] += 1; 00248 order_->push_back(call); 00249 } 00250 00251 00252 } // namespace Rythmos 00253 00254 00255 #endif //Rythmos_LOGGING_INTEGRATION_OBSERVER_HPP
1.7.6.1