Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CDR_Model_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef TEMPUS_CDR_MODEL_DECL_HPP
10 #define TEMPUS_CDR_MODEL_DECL_HPP
11 
12 #include "Thyra_StateFuncModelEvaluatorBase.hpp"
13 
14 class Epetra_Comm;
15 class Epetra_Map;
16 class Epetra_Vector;
17 class Epetra_CrsGraph;
18 class Epetra_Import;
19 
20 namespace Tempus_Test {
21 
22 template<class Scalar> class ModelEvaluator1DFEM;
23 
24 /** \brief 1D CGFEM model for convection/diffusion/reaction
25  *
26  * The equation modeled is:
27 
28  \verbatim
29 
30 dT dT d^2(T)
31 -- + a -- + ------ - K * T**2 = 0
32 dt dz dz^2
33 
34  subject to:
35  T = 1.0 @ z = z_min
36 
37  \endverbatim
38 
39  * The Matrix <tt>W = d(f)/d(x)</tt> is implemented as a
40  * <tt>Thyra::MultiVectorBase</tt> object and the class
41  * <tt>Thyra::DefaultSerialDenseLinearOpWithSolveFactory</tt> is used to
42  * create the linear solver.
43  */
44 template<class Scalar>
45 class CDR_Model
46  : public ::Thyra::StateFuncModelEvaluatorBase<Scalar>
47 {
48 public:
49 
50  CDR_Model(const Teuchos::RCP<const Epetra_Comm>& comm,
51  const int num_global_elements,
52  const Scalar z_min,
53  const Scalar z_max,
54  const Scalar a, // convection
55  const Scalar k); // source
56 
57  /** \name Initializers/Accessors */
58  //@{
59 
60  void set_x0(const Teuchos::ArrayView<const Scalar> &x0);
61 
62  void setShowGetInvalidArgs(bool showGetInvalidArg);
63 
64  void set_W_factory(const Teuchos::RCP<const ::Thyra::LinearOpWithSolveFactoryBase<Scalar> >& W_factory);
65 
66  //@}
67 
68  /** \name Public functions overridden from ModelEvaluator. */
69  //@{
70 
71  Teuchos::RCP<const ::Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
72  Teuchos::RCP<const ::Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
73  ::Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
74  Teuchos::RCP<Thyra::LinearOpWithSolveBase<double> > create_W() const;
75  Teuchos::RCP< ::Thyra::LinearOpBase<Scalar> > create_W_op() const;
76  Teuchos::RCP<const ::Thyra::LinearOpWithSolveFactoryBase<Scalar> > get_W_factory() const;
77  ::Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
78  Teuchos::RCP< ::Thyra::PreconditionerBase< Scalar > > create_W_prec() const;
79  //@}
80 
81 private:
82 
83  /** Allocates and returns the Jacobian matrix graph */
84  virtual Teuchos::RCP<Epetra_CrsGraph> createGraph();
85 
86  /** \name Private functions overridden from ModelEvaluatorDefaultBase. */
87  //@{
88 
89  ::Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
90  void evalModelImpl(
91  const ::Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
92  const ::Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs
93  ) const;
94 
95  //@}
96 
97 private: // data members
98 
99  const Teuchos::RCP<const Epetra_Comm> comm_;
101  const Scalar z_min_;
102  const Scalar z_max_;
103  const Scalar a_;
104  const Scalar k_;
105 
106  Teuchos::RCP<const ::Thyra::VectorSpaceBase<Scalar> > x_space_;
107  Teuchos::RCP<const Epetra_Map> x_owned_map_;
108  Teuchos::RCP<const Epetra_Map> x_ghosted_map_;
109  Teuchos::RCP<const Epetra_Import> importer_;
110 
111  Teuchos::RCP<const ::Thyra::VectorSpaceBase<Scalar> > f_space_;
112  Teuchos::RCP<const Epetra_Map> f_owned_map_;
113 
114  Teuchos::RCP<Epetra_CrsGraph> W_graph_;
115 
116  Teuchos::RCP<const ::Thyra::LinearOpWithSolveFactoryBase<Scalar> > W_factory_;
117 
118  Teuchos::RCP<Epetra_Vector> node_coordinates_;
119  Teuchos::RCP<Epetra_Vector> ghosted_node_coordinates_;
120 
121  mutable Teuchos::RCP<Epetra_Vector> u_ptr;
122  mutable Teuchos::RCP<Epetra_Vector> u_dot_ptr;
123  mutable Teuchos::RCP<Epetra_Vector> x_ptr;
124 
125  mutable Teuchos::RCP<Epetra_Vector> J_diagonal_;
126 
127  ::Thyra::ModelEvaluatorBase::InArgs<Scalar> nominalValues_;
128  Teuchos::RCP< ::Thyra::VectorBase<Scalar> > x0_;
129  Teuchos::Array<Scalar> p_;
131  ::Thyra::ModelEvaluatorBase::InArgs<Scalar> prototypeInArgs_;
132  ::Thyra::ModelEvaluatorBase::OutArgs<Scalar> prototypeOutArgs_;
133 
134 };
135 
136 //==================================================================
137 // Finite Element Basis Object
138 class Basis {
139 
140  public:
141  // Constructor
142  Basis();
143 
144  // Destructor
145  ~Basis();
146 
147  // Calculates the values of u and x at the specified gauss point
148  void computeBasis(int gp, double *z, double *u, double *u_dot = nullptr);
149 
150  public:
151  // Variables that are calculated at the gauss point
152  double *phi, *dphide;
153  double uu, zz, duu, eta, wt;
154  double dz;
155  // These are only needed for transient
156  double uu_dot, duu_dot;
157 };
158 
159 } // namespace Tempus_Test
160 
161 #endif
::Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
void evalModelImpl(const ::Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs, const ::Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs) const
Teuchos::RCP< const Epetra_Map > x_ghosted_map_
Teuchos::RCP< const ::Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
CDR_Model(const Teuchos::RCP< const Epetra_Comm > &comm, const int num_global_elements, const Scalar z_min, const Scalar z_max, const Scalar a, const Scalar k)
::Thyra::ModelEvaluatorBase::OutArgs< Scalar > prototypeOutArgs_
virtual Teuchos::RCP< Epetra_CrsGraph > createGraph()
Teuchos::RCP< Epetra_Vector > u_dot_ptr
Teuchos::RCP< Epetra_CrsGraph > W_graph_
Teuchos::RCP< Epetra_Vector > node_coordinates_
Teuchos::RCP< const Epetra_Map > f_owned_map_
Teuchos::RCP< Epetra_Vector > J_diagonal_
Teuchos::RCP< ::Thyra::VectorBase< Scalar > > x0_
Teuchos::RCP< ::Thyra::PreconditionerBase< Scalar > > create_W_prec() const
Teuchos::RCP< Epetra_Vector > x_ptr
Teuchos::RCP< Epetra_Vector > ghosted_node_coordinates_
void setShowGetInvalidArgs(bool showGetInvalidArg)
Teuchos::RCP< const Epetra_Map > x_owned_map_
::Thyra::ModelEvaluatorBase::InArgs< Scalar > nominalValues_
void set_W_factory(const Teuchos::RCP< const ::Thyra::LinearOpWithSolveFactoryBase< Scalar > > &W_factory)
void set_x0(const Teuchos::ArrayView< const Scalar > &x0)
void computeBasis(int gp, double *z, double *u, double *u_dot=nullptr)
Teuchos::RCP< const ::Thyra::VectorSpaceBase< Scalar > > x_space_
Teuchos::RCP< ::Thyra::LinearOpBase< Scalar > > create_W_op() const
Teuchos::RCP< Thyra::LinearOpWithSolveBase< double > > create_W() const
::Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
Teuchos::RCP< const ::Thyra::VectorSpaceBase< Scalar > > get_f_space() const
Teuchos::Array< Scalar > p_
Teuchos::RCP< const ::Thyra::LinearOpWithSolveFactoryBase< Scalar > > W_factory_
Teuchos::RCP< Epetra_Vector > u_ptr
::Thyra::ModelEvaluatorBase::InArgs< Scalar > prototypeInArgs_
Teuchos::RCP< const ::Thyra::VectorSpaceBase< Scalar > > get_x_space() const
const Teuchos::RCP< const Epetra_Comm > comm_
Teuchos::RCP< const ::Thyra::VectorSpaceBase< Scalar > > f_space_
::Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
1D CGFEM model for convection/diffusion/reaction
Teuchos::RCP< const Epetra_Import > importer_