Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
EpetraExt_DiagonalTransientModel.hpp
1 //@HEADER
2 // ***********************************************************************
3 //
4 // EpetraExt: Epetra Extended - Linear Algebra Services Package
5 // Copyright (2011) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 
42 #ifndef EPETRA_EXT_DIAGONAL_TRANSIENT_MODEL_HPP
43 #define EPETRA_EXT_DIAGONAL_TRANSIENT_MODEL_HPP
44 
45 
46 #include "EpetraExt_ModelEvaluator.h"
47 #include "Teuchos_VerboseObject.hpp"
48 #include "Teuchos_ParameterListAcceptor.hpp"
49 #include "Teuchos_Array.hpp"
50 
51 
52 class Epetra_Comm;
53 class Epetra_CrsGraph;
54 
55 
56 namespace EpetraExt {
57 
58 
100  : public ::EpetraExt::ModelEvaluator,
101  public Teuchos::VerboseObject<DiagonalTransientModel>,
102  public Teuchos::ParameterListAcceptor
103 {
104 public:
105 
108 
111  Teuchos::RCP<Epetra_Comm> const& epetra_comm
112  );
113 
115  Teuchos::RCP<const Epetra_Vector> get_gamma() const;
116 
118  Teuchos::RCP<const Epetra_Vector>
120  const double t, const Epetra_Vector *coeff_s_p = 0
121  ) const;
122 
124  Teuchos::RCP<const Epetra_MultiVector>
126  const double t, const Epetra_Vector *coeff_s_p = 0
127  ) const;
128 
130 
133 
135  void setParameterList(Teuchos::RCP<Teuchos::ParameterList> const& paramList);
137  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList();
139  Teuchos::RCP<Teuchos::ParameterList> unsetParameterList();
141  Teuchos::RCP<const Teuchos::ParameterList> getParameterList() const;
143  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
144 
146 
149 
151  Teuchos::RCP<const Epetra_Map> get_x_map() const;
153  Teuchos::RCP<const Epetra_Map> get_f_map() const;
155  Teuchos::RCP<const Epetra_Map> get_p_map(int l) const;
157  Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
159  Teuchos::RCP<const Epetra_Map> get_g_map(int j) const;
161  Teuchos::RCP<const Epetra_Vector> get_x_init() const;
163  Teuchos::RCP<const Epetra_Vector> get_x_dot_init() const;
165  Teuchos::RCP<const Epetra_Vector> get_p_init(int l) const;
167  Teuchos::RCP<Epetra_Operator> create_W() const;
169  InArgs createInArgs() const;
171  OutArgs createOutArgs() const;
173  void evalModel( const InArgs& inArgs, const OutArgs& outArgs ) const;
174 
176 
177 public:
178 
179  enum EGammaFit { GAMMA_FIT_LINEAR, GAMMA_FIT_RANDOM };
180 
181 private:
182 
183  // /////////////////////////////////////
184  // Private types
185 
186  typedef Teuchos::Array<double> coeff_s_t;
187  typedef Teuchos::Array<int> coeff_s_idx_t;
188  typedef Teuchos::Array<Teuchos::RCP<const Epetra_Map> > RCP_Eptra_Map_Array_t;
189  typedef Teuchos::Array<Teuchos::RCP<Epetra_Vector> > RCP_Eptra_Vector_Array_t;
190  typedef Teuchos::Array<Teuchos::RCP<Teuchos::Array<std::string> > > RCP_Array_String_Array_t;
191 
192 
193  // /////////////////////////////////////
194  // Private member data
195 
196  Teuchos::RCP<Teuchos::ParameterList> paramList_;
197  Teuchos::RCP<Epetra_Comm> epetra_comm_;
198  Teuchos::RCP<Epetra_Map> epetra_map_;
199  bool implicit_;
200  int numElements_;
201  double gamma_min_;
202  double gamma_max_;
203  coeff_s_t coeff_s_;
204  coeff_s_idx_t coeff_s_idx_;
205  EGammaFit gamma_fit_;
206  double x0_;
207  bool exactSolutionAsResponse_;
208  Teuchos::RCP<Epetra_Vector> gamma_;
209  Teuchos::RCP<Epetra_CrsGraph> W_graph_;
210  int Np_;
211  int np_;
212  int Ng_;
213  RCP_Eptra_Map_Array_t map_p_;
214  RCP_Array_String_Array_t names_p_;
215  RCP_Eptra_Map_Array_t map_g_;
216  RCP_Eptra_Vector_Array_t p_init_;
217  Teuchos::RCP<Epetra_Vector> x_init_;
218  Teuchos::RCP<Epetra_Vector> x_dot_init_;
219 
220  mutable Teuchos::RCP<const Epetra_Vector> coeff_s_p_;
221 
222  bool isIntialized_;
223 
224  // /////////////////////////////////////
225  // Private member functions
226 
227  void initialize();
228 
229  void set_coeff_s_p(
230  const Teuchos::RCP<const Epetra_Vector> &coeff_s_p
231  ) const;
232 
233  void unset_coeff_s_p() const;
234 
235  int coeff_s_idx(int i) const
236  {
237  return coeff_s_idx_[i];
238  }
239 
240  double coeff_s(int i) const
241  {
242  return (*coeff_s_p_)[coeff_s_idx(i)];
243  }
244 
245 };
246 
247 
252 Teuchos::RCP<DiagonalTransientModel>
253 diagonalTransientModel(
254  Teuchos::RCP<Epetra_Comm> const& epetra_comm,
255  Teuchos::RCP<Teuchos::ParameterList> const& paramList = Teuchos::null
256  );
257 
258 
259 } // namespace EpetraExt
260 
261 
262 // RAB: Note, I wrapped this example code in a namespace mainly to make the
263 // later definition of the nonmember functions safe (see the Thyra
264 // Coding Guildelines document).
265 
266 
267 #endif // EPETRA_EXT_DIAGONAL_TRANSIENT_MODEL_HPP
Simple transient diagonal model for an implicit or explicit ODE.
Teuchos::RCP< const Epetra_Vector > getExactSolution(const double t, const Epetra_Vector *coeff_s_p=0) const
Return the exact solution as a function of time.
Teuchos::RCP< const Epetra_Vector > get_gamma() const
Return the model vector gamma,.
Teuchos::RCP< const Epetra_Map > get_p_map(int l) const
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() const
DiagonalTransientModel(Teuchos::RCP< Epetra_Comm > const &epetra_comm)
Teuchos::RCP< const Epetra_Vector > get_x_init() const
Teuchos::RCP< const Epetra_Map > get_f_map() const
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
Teuchos::RCP< const Epetra_MultiVector > getExactSensSolution(const double t, const Epetra_Vector *coeff_s_p=0) const
Return the exact sensitivity of x as a function of time.
Teuchos::RCP< const Epetra_Map > get_x_map() const
Teuchos::RCP< Epetra_Operator > create_W() const
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const &paramList)
Teuchos::RCP< const Epetra_Vector > get_x_dot_init() const
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Teuchos::RCP< const Epetra_Map > get_g_map(int j) const