|
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., 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 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 MEB::OutArgsSetup<Scalar> outArgs; 00307 outArgs.setModelEvalDescription(this->description()); 00308 outArgs.setSupports(MEB::OUT_ARG_f); 00309 outArgs.setSupports(MEB::OUT_ARG_W); 00310 return outArgs; 00311 } 00312 00313 00314 template<class Scalar> 00315 void SingleResidualModelEvaluator<Scalar>::evalModelImpl( 00316 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs_bar, 00317 const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs_bar 00318 ) const 00319 { 00320 00321 using std::endl; 00322 using Teuchos::as; 00323 typedef Thyra::ModelEvaluatorBase MEB; 00324 00325 const RCP<const Thyra::ModelEvaluator<Scalar> > 00326 daeModel = this->getUnderlyingModel(); 00327 00328 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN( 00329 "Rythmos::SingleResidualModelEvaluator",inArgs_bar,outArgs_bar 00330 ); 00331 00332 const bool dumpAll = ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME) ); 00333 00334 const Thyra::VectorBase<Scalar> &x_bar = *inArgs_bar.get_x(); 00335 00336 // x_dot = coeff_x_dot * x_bar + x_dot_base 00337 00338 if (x_dot_base_.get()) 00339 Thyra::V_StVpV( x_dot_.ptr(), coeff_x_dot_, x_bar, *x_dot_base_ ); 00340 else 00341 Thyra::V_StV( x_dot_.ptr(), coeff_x_dot_, x_bar); 00342 00343 if (dumpAll) { 00344 *out << "\nx_dot_ = coeff_x_dot_ * x_bar + x_dot_base_\n"; 00345 *out << "\ncoeff_x_dot_ = " << coeff_x_dot_ << endl; 00346 *out << "\nx_bar = " << x_bar; 00347 *out << "\nx_dot_base_ = "; 00348 if ( x_dot_base_.get() ) 00349 *out << *x_dot_base_; 00350 else 00351 *out << "null" << endl; 00352 *out << "\nx_dot_ = "; 00353 if ( x_dot_.get() ) 00354 *out << *x_dot_; 00355 else 00356 *out << "null" << endl; 00357 } 00358 00359 // x = coeff_x * x_bar + x_base 00360 00361 if (x_base_.get()) 00362 Thyra::V_StVpV( x_.ptr(), coeff_x_, x_bar, *x_base_ ); 00363 else 00364 Thyra::V_StV( x_.ptr(), coeff_x_, x_bar); 00365 00366 if (dumpAll) { 00367 *out << "\nx_ = coeff_x_ * x_bar + x_base_\n"; 00368 *out << "\ncoeff_x_ = " << coeff_x_ << endl; 00369 *out << "\nx_bar = " << x_bar; 00370 *out << "\nx_base_ = "; 00371 if ( x_base_.get() ) 00372 *out << *x_base_; 00373 else 00374 *out << "null" << endl; 00375 *out << "\nx_ = "; 00376 if ( x_.get() ) 00377 *out << *x_; 00378 else 00379 *out << "null" << endl; 00380 } 00381 00382 // Compute W and f 00383 00384 if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)) 00385 *out << "\nEvaluating the underlying DAE model at (x_bar_dot,x_bar,t) ...\n"; 00386 00387 RCP<Thyra::LinearOpWithSolveBase<Scalar> > W; 00388 00389 MEB::InArgs<Scalar> daeInArgs = daeModel->createInArgs(); 00390 daeInArgs.setArgs(basePoint_); 00391 daeInArgs.set_x_dot(x_dot_); 00392 daeInArgs.set_x(x_); 00393 daeInArgs.set_t(t_base_); 00394 daeInArgs.set_alpha(coeff_x_dot_); 00395 daeInArgs.set_beta(coeff_x_); 00396 MEB::OutArgs<Scalar> daeOutArgs = daeModel->createOutArgs(); 00397 daeOutArgs.set_f(outArgs_bar.get_f()); // can be null 00398 daeOutArgs.set_W(outArgs_bar.get_W()); // can be null 00399 daeModel->evalModel(daeInArgs,daeOutArgs); 00400 00401 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END(); 00402 00403 } 00404 00405 00406 } // namespace Rythmos 00407 00408 00409 #endif // RYTHMOS_SINGLE_RESIDUAL_MODEL_EVALUATOR_HPP
1.7.4