Rythmos - Transient Integration for Differential Equations  Version of the Day
Rythmos_StateAndForwardSensitivityModelEvaluator.hpp
1 //@HEADER
2 // ***********************************************************************
3 //
4 // Rythmos Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // USA
24 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 
29 #ifndef RYTHMOS_STATE_AND_FORWARD_SENSITIVITY_MODEL_EVALUATOR_HPP
30 #define RYTHMOS_STATE_AND_FORWARD_SENSITIVITY_MODEL_EVALUATOR_HPP
31 
32 
33 #include "Rythmos_ForwardSensitivityModelEvaluatorBase.hpp"
34 #include "Thyra_ModelEvaluator.hpp" // Interface
35 #include "Thyra_StateFuncModelEvaluatorBase.hpp" // Implementation
36 #include "Thyra_DefaultProductVectorSpace.hpp"
37 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
38 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
39 #include "Thyra_DefaultMultiVectorProductVector.hpp"
40 #include "Thyra_DefaultMultiVectorLinearOpWithSolve.hpp"
41 #include "Teuchos_implicit_cast.hpp"
42 
43 
44 namespace Rythmos {
45 
46 
183 template<class Scalar>
185  : virtual public Thyra::StateFuncModelEvaluatorBase<Scalar>
186 {
187 public:
188 
191 
194 
202  void initializeStructure(
203  const Teuchos::RCP<const ForwardSensitivityModelEvaluatorBase<Scalar> > &sensModel
204  );
205 
206  // 2007/05/30: rabartl: ToDo: Add function to set the nominal values etc.
207 
213  Teuchos::RCP<const Thyra::DefaultProductVector<Scalar> >
215  const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &x_vec,
216  const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &s_bar_vec
217  ) const;
218 
220 
223 
225  int Np() const;
227  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(int l) const;
229  Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
231  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
233  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
235  Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
237  Teuchos::RCP<Thyra::LinearOpWithSolveBase<Scalar> > create_W() const;
239  Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
240 
242 
243 private:
244 
247 
249  Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
251  void evalModelImpl(
252  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
253  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs
254  ) const;
255 
257 
258 private:
259 
260  // /////////////////////////
261  // Private data members
262 
263  Teuchos::RCP<const ForwardSensitivityModelEvaluatorBase<Scalar> > sensModel_;
264 
265  int Np_;
266  Teuchos::RCP<const Thyra::DefaultProductVectorSpace<Scalar> > x_bar_space_;
267  Teuchos::RCP<const Thyra::DefaultProductVectorSpace<Scalar> > f_bar_space_;
268 
269 };
270 
271 
272 // /////////////////////////////////
273 // Implementations
274 
275 
276 // Constructors/Intializers/Accessors
277 
278 
279 template<class Scalar>
281  :Np_(0)
282 {}
283 
284 
285 template<class Scalar>
287  const Teuchos::RCP<const ForwardSensitivityModelEvaluatorBase<Scalar> > &sensModel
288  )
289 {
290 
291  using Teuchos::tuple; using Teuchos::RCP;
292  typedef Thyra::ModelEvaluatorBase MEB;
293 
294  TEUCHOS_TEST_FOR_EXCEPT( is_null(sensModel) );
295 
296  sensModel_ = sensModel;
297 
298  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
299  stateModel = sensModel_->getStateModel();
300 
301  x_bar_space_ = Thyra::productVectorSpace<Scalar>(
302  tuple<RCP<const Thyra::VectorSpaceBase<Scalar> > >(
303  stateModel->get_x_space(), sensModel_->get_x_space()
304  )
305  );
306 
307  f_bar_space_ = Thyra::productVectorSpace<Scalar>(
308  tuple<RCP<const Thyra::VectorSpaceBase<Scalar> > >(
309  stateModel->get_f_space(), sensModel_->get_f_space()
310  )
311  );
312 
313  Np_ = stateModel->Np();
314 
315 }
316 
317 
318 template<class Scalar>
319 Teuchos::RCP<const Thyra::DefaultProductVector<Scalar> >
321  const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &x_vec,
322  const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &s_bar_vec
323  ) const
324 {
325 
326  using Teuchos::tuple;
327  using Teuchos::RCP;
328  typedef RCP<const Thyra::VectorBase<Scalar> > RCPCV;
329 
330  return Thyra::defaultProductVector<Scalar>(
331  x_bar_space_, tuple<RCPCV>(x_vec,s_bar_vec)
332  );
333 
334 }
335 
336 
337 // Public functions overridden from ModelEvaulator
338 
339 
340 template<class Scalar>
342 {
343  return Np_;
344 }
345 
346 
347 template<class Scalar>
348 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
350 {
351  return sensModel_->getStateModel()->get_p_space(l);
352 }
353 
354 
355 template<class Scalar>
356 Teuchos::RCP<const Teuchos::Array<std::string> >
358 {
359  return sensModel_->getStateModel()->get_p_names(l);
360 }
361 
362 
363 template<class Scalar>
364 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
366 {
367  return x_bar_space_;
368 }
369 
370 
371 template<class Scalar>
372 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
374 {
375  return f_bar_space_;
376 }
377 
378 
379 template<class Scalar>
380 Thyra::ModelEvaluatorBase::InArgs<Scalar>
382 {
383  return this->createInArgs();
384 }
385 
386 
387 template<class Scalar>
388 Teuchos::RCP<Thyra::LinearOpWithSolveBase<Scalar> >
390 {
391  TEUCHOS_TEST_FOR_EXCEPT("ToDo: Implement create_W() when needed!");
392  return Teuchos::null;
393 }
394 
395 
396 template<class Scalar>
397 Thyra::ModelEvaluatorBase::InArgs<Scalar>
399 {
400  typedef Thyra::ModelEvaluatorBase MEB;
401  MEB::InArgs<Scalar>
402  stateModelInArgs = sensModel_->getStateModel()->createInArgs();
403  MEB::InArgsSetup<Scalar> inArgs;
404  inArgs.setModelEvalDescription(this->description());
405  inArgs.set_Np(Np_);
406  inArgs.setSupports( MEB::IN_ARG_x_dot,
407  stateModelInArgs.supports(MEB::IN_ARG_x_dot) );
408  inArgs.setSupports( MEB::IN_ARG_x );
409  inArgs.setSupports( MEB::IN_ARG_t );
410  inArgs.setSupports( MEB::IN_ARG_alpha,
411  stateModelInArgs.supports(MEB::IN_ARG_alpha) );
412  inArgs.setSupports( MEB::IN_ARG_beta,
413  stateModelInArgs.supports(MEB::IN_ARG_beta) );
414  return inArgs;
415 }
416 
417 
418 // Private functions overridden from ModelEvaulatorDefaultBase
419 
420 
421 template<class Scalar>
422 Thyra::ModelEvaluatorBase::OutArgs<Scalar>
424 {
425  typedef Thyra::ModelEvaluatorBase MEB;
426  MEB::OutArgs<Scalar>
427  stateModelOutArgs = sensModel_->getStateModel()->createOutArgs();
428  MEB::OutArgsSetup<Scalar> outArgs;
429  outArgs.setModelEvalDescription(this->description());
430  outArgs.set_Np_Ng(Np_,0);
431  outArgs.setSupports(MEB::OUT_ARG_f);
432  if (stateModelOutArgs.supports(MEB::OUT_ARG_W) ) {
433  outArgs.setSupports(MEB::OUT_ARG_W);
434  outArgs.set_W_properties(stateModelOutArgs.get_W_properties());
435  }
436  return outArgs;
437 }
438 
439 
440 template<class Scalar>
442  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
443  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs
444  ) const
445 {
446  TEUCHOS_TEST_FOR_EXCEPT("ToDo: Implement evalModel(...) when needed!");
447 }
448 
449 
450 } // namespace Rythmos
451 
452 
453 #endif // RYTHMOS_STATE_AND_FORWARD_SENSITIVITY_MODEL_EVALUATOR_HPP
Combined State and Forward sensitivity transient ModelEvaluator subclass.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Teuchos::RCP< const Thyra::DefaultProductVector< Scalar > > create_x_bar_vec(const Teuchos::RCP< const Thyra::VectorBase< Scalar > > &x_vec, const Teuchos::RCP< const Thyra::VectorBase< Scalar > > &s_bar_vec) const
Create a wrapped product vector of the form x_bar = [ x; s_bar ].
Forward sensitivity transient ModelEvaluator node interface class.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
void initializeStructure(const Teuchos::RCP< const ForwardSensitivityModelEvaluatorBase< Scalar > > &sensModel)
Set up the structure of the state and sensitivity equations.