|
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 00030 #ifndef RYTHMOS_SINGLE_RESIDUAL_MODEL_EVALUATOR_HPP 00031 #define RYTHMOS_SINGLE_RESIDUAL_MODEL_EVALUATOR_HPP 00032 00033 00034 #include "Rythmos_SingleResidualModelEvaluatorBase.hpp" 00035 #include "Thyra_ModelEvaluatorDelegatorBase.hpp" 00036 #include "Thyra_ModelEvaluatorHelpers.hpp" 00037 #include "Thyra_VectorStdOps.hpp" 00038 #include "Thyra_TestingTools.hpp" 00039 #include "Teuchos_as.hpp" 00040 00041 00042 namespace Rythmos { 00043 00044 00066 template<class Scalar> 00067 class SingleResidualModelEvaluator 00068 : virtual public SingleResidualModelEvaluatorBase<Scalar>, 00069 virtual public Thyra::ModelEvaluatorDelegatorBase<Scalar> 00070 { 00071 public: 00072 00075 00077 SingleResidualModelEvaluator(); 00078 00080 00083 00085 void initializeSingleResidualModel( 00086 const RCP<const Thyra::ModelEvaluator<Scalar> > &daeModel, 00087 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &basePoint, 00088 const Scalar &coeff_x_dot, 00089 const RCP<const Thyra::VectorBase<Scalar> > &x_dot_base, 00090 const Scalar &coeff_x, 00091 const RCP<const Thyra::VectorBase<Scalar> > &x_base, 00092 const Scalar &t_base, 00093 const RCP<const Thyra::VectorBase<Scalar> > &x_bar_init 00094 ); 00095 00097 Scalar get_coeff_x_dot() const; 00098 00100 RCP<const Thyra::VectorBase<Scalar> > 00101 get_x_dot_base() const; 00102 00104 Scalar get_coeff_x() const; 00105 00107 RCP<const Thyra::VectorBase<Scalar> > 00108 get_x_base() const; 00109 00111 Scalar get_t_base() const; 00112 00114 00117 00119 Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const; 00121 Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const; 00122 00124 00125 private: 00126 00129 00131 Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const; 00133 void evalModelImpl( 00134 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs, 00135 const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs 00136 ) const; 00137 00139 00140 00141 private: 00142 00143 Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_; 00144 Scalar coeff_x_dot_; 00145 RCP<const Thyra::VectorBase<Scalar> > x_dot_base_; 00146 Scalar coeff_x_; 00147 RCP<const Thyra::VectorBase<Scalar> > x_base_; 00148 Scalar t_base_; 00149 00150 Thyra::ModelEvaluatorBase::InArgs<Scalar> nominalValues_; 00151 00152 // cache 00153 RCP<Thyra::VectorBase<Scalar> > x_; 00154 RCP<Thyra::VectorBase<Scalar> > x_dot_; 00155 00156 }; 00157 00158 00159 // /////////////////////// 00160 // Definition 00161 00162 00163 // Constructors/initializers/accessors 00164 00165 00166 template<class Scalar> 00167 SingleResidualModelEvaluator<Scalar>::SingleResidualModelEvaluator() 00168 {} 00169 00170 00171 // Overridden from SingleResidualModelEvaluatorBase 00172 00173 00174 template<class Scalar> 00175 void SingleResidualModelEvaluator<Scalar>::initializeSingleResidualModel( 00176 const RCP<const Thyra::ModelEvaluator<Scalar> > &daeModel, 00177 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &basePoint, 00178 const Scalar &coeff_x_dot, 00179 const RCP<const Thyra::VectorBase<Scalar> > &x_dot_base, 00180 const Scalar &coeff_x, 00181 const RCP<const Thyra::VectorBase<Scalar> > &x_base, 00182 const Scalar &t_base, 00183 const RCP<const Thyra::VectorBase<Scalar> > &x_bar_init 00184 ) 00185 { 00186 this->Thyra::ModelEvaluatorDelegatorBase<Scalar>::initialize(daeModel); 00187 basePoint_ = basePoint; 00188 coeff_x_dot_ = coeff_x_dot; 00189 x_dot_base_ = x_dot_base; 00190 coeff_x_ = coeff_x; 00191 x_base_ = x_base; 00192 t_base_ = t_base; 00193 00194 nominalValues_ = daeModel->getNominalValues(); 00195 nominalValues_.set_x(x_bar_init); 00196 00197 x_dot_ = createMember( daeModel->get_x_space() ); 00198 x_ = createMember( daeModel->get_x_space() ); 00199 00200 // ToDo: Check that daeModel supports x_dot, x and maybe t 00201 00202 #ifdef THYRA_RYTHMOS_DEBUG 00203 std::cout << "----------------------------------------------------------------------" << std::endl; 00204 std::cout << "Rythmos::SingleResidualModelEvaluator::initialize" << std::endl; 00205 std::cout << "coeff_x_dot_ = " << coeff_x_dot_ << std::endl; 00206 std::cout << "x_dot_base_ = "; 00207 if ( x_dot_base_.get() ) 00208 std::cout << "\n" << *x_dot_base_ << std::endl; 00209 else 00210 std::cout << "null" << std::endl; 00211 std::cout << "coeff_x_ = " << coeff_x_ << std::endl; 00212 std::cout << "x_base_ = "; 00213 if ( x_base_.get() ) 00214 std::cout << "\n" << *x_base_ << std::endl; 00215 else 00216 std::cout << "null" << std::endl; 00217 std::cout << "t_base_ = " << t_base_ << std::endl; 00218 std::cout << "x_bar_init = "; 00219 if ( x_bar_init.get() ) 00220 std::cout << "\n" << *x_bar_init_ << std::endl; 00221 else 00222 std::cout << "null" << std::endl; 00223 std::cout << "x_dot_ = "; 00224 if ( x_dot_.get() ) 00225 std::cout << "\n" << *x_dot_ << std::endl; 00226 else 00227 std::cout << "null" << std::endl; 00228 std::cout << "x_ = "; 00229 if ( x_.get() ) 00230 std::cout << "\n" << *x_ << std::endl; 00231 else 00232 std::cout << "null" << std::endl; 00233 std::cout << "----------------------------------------------------------------------" << std::endl; 00234 #endif // THYRA_RYTHMOS_DEBUG 00235 } 00236 00237 00238 template<class Scalar> 00239 Scalar SingleResidualModelEvaluator<Scalar>::get_coeff_x_dot() const 00240 { 00241 return coeff_x_dot_; 00242 } 00243 00244 00245 template<class Scalar> 00246 RCP<const Thyra::VectorBase<Scalar> > 00247 SingleResidualModelEvaluator<Scalar>::get_x_dot_base() const 00248 { 00249 return x_dot_base_; 00250 } 00251 00252 00253 template<class Scalar> 00254 Scalar SingleResidualModelEvaluator<Scalar>::get_coeff_x() const 00255 { 00256 return coeff_x_; 00257 } 00258 00259 00260 template<class Scalar> 00261 RCP<const Thyra::VectorBase<Scalar> > 00262 SingleResidualModelEvaluator<Scalar>::get_x_base() const 00263 { 00264 return x_base_; 00265 } 00266 00267 00268 template<class Scalar> 00269 Scalar SingleResidualModelEvaluator<Scalar>::get_t_base() const 00270 { 00271 return t_base_; 00272 } 00273 00274 00275 // Overridden from ModelEvaluator 00276 00277 00278 template<class Scalar> 00279 Thyra::ModelEvaluatorBase::InArgs<Scalar> 00280 SingleResidualModelEvaluator<Scalar>::getNominalValues() const 00281 { 00282 return nominalValues_; 00283 } 00284 00285 00286 template<class Scalar> 00287 Thyra::ModelEvaluatorBase::InArgs<Scalar> 00288 SingleResidualModelEvaluator<Scalar>::createInArgs() const 00289 { 00290 typedef Thyra::ModelEvaluatorBase MEB; 00291 MEB::InArgsSetup<Scalar> inArgs; 00292 inArgs.setModelEvalDescription(this->description()); 00293 inArgs.setSupports(MEB::IN_ARG_x); 00294 return inArgs; 00295 } 00296 00297 00298 // Private functions overridden from ModelEvaluatorDefaultBase 00299 00300 00301 template<class Scalar> 00302 Thyra::ModelEvaluatorBase::OutArgs<Scalar> 00303 SingleResidualModelEvaluator<Scalar>::createOutArgsImpl() const 00304 { 00305 typedef Thyra::ModelEvaluatorBase MEB; 00306 const RCP<const Thyra::ModelEvaluator<Scalar> > 00307 daeModel = this->getUnderlyingModel(); 00308 MEB::OutArgs<Scalar> daeOutArgs = daeModel->createOutArgs(); 00309 MEB::OutArgsSetup<Scalar> outArgs; 00310 outArgs.setModelEvalDescription(this->description()); 00311 outArgs.setSupports(MEB::OUT_ARG_f); 00312 if (daeOutArgs.supports(MEB::OUT_ARG_W_op)) { 00313 outArgs.setSupports(MEB::OUT_ARG_W_op); 00314 } 00315 if (daeOutArgs.supports(MEB::OUT_ARG_W)) { 00316 outArgs.setSupports(MEB::OUT_ARG_W); 00317 } 00318 return outArgs; 00319 } 00320 00321 00322 template<class Scalar> 00323 void SingleResidualModelEvaluator<Scalar>::evalModelImpl( 00324 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs_bar, 00325 const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs_bar 00326 ) const 00327 { 00328 00329 using std::endl; 00330 using Teuchos::as; 00331 typedef Thyra::ModelEvaluatorBase MEB; 00332 00333 const RCP<const Thyra::ModelEvaluator<Scalar> > 00334 daeModel = this->getUnderlyingModel(); 00335 00336 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN( 00337 "Rythmos::SingleResidualModelEvaluator",inArgs_bar,outArgs_bar 00338 ); 00339 00340 const bool dumpAll = ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME) ); 00341 00342 const Thyra::VectorBase<Scalar> &x_bar = *inArgs_bar.get_x(); 00343 00344 // x_dot = coeff_x_dot * x_bar + x_dot_base 00345 00346 if (x_dot_base_.get()) 00347 Thyra::V_StVpV( x_dot_.ptr(), coeff_x_dot_, x_bar, *x_dot_base_ ); 00348 else 00349 Thyra::V_StV( x_dot_.ptr(), coeff_x_dot_, x_bar); 00350 00351 if (dumpAll) { 00352 *out << "\nx_dot_ = coeff_x_dot_ * x_bar + x_dot_base_\n"; 00353 *out << "\ncoeff_x_dot_ = " << coeff_x_dot_ << endl; 00354 *out << "\nx_bar = " << x_bar; 00355 *out << "\nx_dot_base_ = "; 00356 if ( x_dot_base_.get() ) 00357 *out << *x_dot_base_; 00358 else 00359 *out << "null" << endl; 00360 *out << "\nx_dot_ = "; 00361 if ( x_dot_.get() ) 00362 *out << *x_dot_; 00363 else 00364 *out << "null" << endl; 00365 } 00366 00367 // x = coeff_x * x_bar + x_base 00368 00369 if (x_base_.get()) 00370 Thyra::V_StVpV( x_.ptr(), coeff_x_, x_bar, *x_base_ ); 00371 else 00372 Thyra::V_StV( x_.ptr(), coeff_x_, x_bar); 00373 00374 if (dumpAll) { 00375 *out << "\nx_ = coeff_x_ * x_bar + x_base_\n"; 00376 *out << "\ncoeff_x_ = " << coeff_x_ << endl; 00377 *out << "\nx_bar = " << x_bar; 00378 *out << "\nx_base_ = "; 00379 if ( x_base_.get() ) 00380 *out << *x_base_; 00381 else 00382 *out << "null" << endl; 00383 *out << "\nx_ = "; 00384 if ( x_.get() ) 00385 *out << *x_; 00386 else 00387 *out << "null" << endl; 00388 } 00389 00390 // Compute W and f 00391 00392 if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)) 00393 *out << "\nEvaluating the underlying DAE model at (x_bar_dot,x_bar,t) ...\n"; 00394 00395 RCP<Thyra::LinearOpWithSolveBase<Scalar> > W; 00396 00397 MEB::InArgs<Scalar> daeInArgs = daeModel->createInArgs(); 00398 daeInArgs.setArgs(basePoint_); 00399 daeInArgs.set_x_dot(x_dot_); 00400 daeInArgs.set_x(x_); 00401 daeInArgs.set_t(t_base_); 00402 daeInArgs.set_alpha(coeff_x_dot_); 00403 daeInArgs.set_beta(coeff_x_); 00404 MEB::OutArgs<Scalar> daeOutArgs = daeModel->createOutArgs(); 00405 daeOutArgs.set_f(outArgs_bar.get_f()); // can be null 00406 if (daeOutArgs.supports(MEB::OUT_ARG_W)) { 00407 daeOutArgs.set_W(outArgs_bar.get_W()); // can be null 00408 } 00409 if (daeOutArgs.supports(MEB::OUT_ARG_W_op)) { 00410 daeOutArgs.set_W_op(outArgs_bar.get_W_op()); // can be null 00411 } 00412 daeModel->evalModel(daeInArgs,daeOutArgs); 00413 00414 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END(); 00415 00416 } 00417 00418 00419 } // namespace Rythmos 00420 00421 00422 #endif // RYTHMOS_SINGLE_RESIDUAL_MODEL_EVALUATOR_HPP
1.7.6.1