Rythmos - Transient Integration for Differential Equations Version of the Day
EpetraExt_DiagonalTransientModel.hpp
00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
00005 //                 Copyright (2011) Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 
00042 #ifndef EPETRA_EXT_DIAGONAL_TRANSIENT_MODEL_HPP
00043 #define EPETRA_EXT_DIAGONAL_TRANSIENT_MODEL_HPP
00044 
00045 
00046 #include "EpetraExt_ModelEvaluator.h"
00047 #include "Teuchos_VerboseObject.hpp"
00048 #include "Teuchos_ParameterListAcceptor.hpp"
00049 #include "Teuchos_Array.hpp"
00050 
00051 
00052 class Epetra_Comm;
00053 class Epetra_CrsGraph;
00054 
00055 
00056 namespace EpetraExt {
00057 
00058 
00099 class DiagonalTransientModel
00100   : public ::EpetraExt::ModelEvaluator,
00101     public Teuchos::VerboseObject<DiagonalTransientModel>,
00102     public Teuchos::ParameterListAcceptor
00103 {
00104 public:
00105 
00108 
00110   DiagonalTransientModel(
00111     Teuchos::RCP<Epetra_Comm> const& epetra_comm
00112     );
00113   
00115   Teuchos::RCP<const Epetra_Vector> get_gamma() const;
00116 
00118   Teuchos::RCP<const Epetra_Vector>
00119   getExactSolution(
00120     const double t, const Epetra_Vector *coeff_s_p = 0
00121     ) const;
00122 
00124   Teuchos::RCP<const Epetra_MultiVector>
00125   getExactSensSolution(
00126     const double t, const Epetra_Vector *coeff_s_p = 0
00127     ) const;
00128 
00130 
00133 
00135   void setParameterList(Teuchos::RCP<Teuchos::ParameterList> const& paramList);
00137   Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList();
00139   Teuchos::RCP<Teuchos::ParameterList> unsetParameterList();
00141   Teuchos::RCP<const Teuchos::ParameterList> getParameterList() const;
00143   Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
00144 
00146 
00149 
00151   Teuchos::RCP<const Epetra_Map> get_x_map() const;
00153   Teuchos::RCP<const Epetra_Map> get_f_map() const;
00155   Teuchos::RCP<const Epetra_Map> get_p_map(int l) const;
00157   Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
00159   Teuchos::RCP<const Epetra_Map> get_g_map(int j) const;
00161   Teuchos::RCP<const Epetra_Vector> get_x_init() const;
00163   Teuchos::RCP<const Epetra_Vector> get_x_dot_init() const;
00165   Teuchos::RCP<const Epetra_Vector> get_p_init(int l) const;
00167   Teuchos::RCP<Epetra_Operator> create_W() const;
00169   InArgs createInArgs() const;
00171   OutArgs createOutArgs() const;
00173   void evalModel( const InArgs& inArgs, const OutArgs& outArgs ) const;
00174 
00176 
00177 public:
00178 
00179   enum EGammaFit { GAMMA_FIT_LINEAR, GAMMA_FIT_RANDOM };
00180 
00181 private:
00182 
00183   // /////////////////////////////////////
00184   // Private types
00185 
00186   typedef Teuchos::Array<double> coeff_s_t;
00187   typedef Teuchos::Array<int> coeff_s_idx_t;
00188   typedef Teuchos::Array<Teuchos::RCP<const Epetra_Map> >  RCP_Eptra_Map_Array_t;
00189   typedef Teuchos::Array<Teuchos::RCP<Epetra_Vector> > RCP_Eptra_Vector_Array_t;
00190   typedef Teuchos::Array<Teuchos::RCP<Teuchos::Array<std::string> > > RCP_Array_String_Array_t;
00191   
00192 
00193   // /////////////////////////////////////
00194   // Private member data
00195 
00196   Teuchos::RCP<Teuchos::ParameterList> paramList_;
00197   Teuchos::RCP<Epetra_Comm> epetra_comm_;
00198   Teuchos::RCP<Epetra_Map> epetra_map_;
00199   bool implicit_;
00200   int numElements_;
00201   double gamma_min_;
00202   double gamma_max_;
00203   coeff_s_t coeff_s_;
00204   coeff_s_idx_t coeff_s_idx_;
00205   EGammaFit gamma_fit_;
00206   double x0_;
00207   bool exactSolutionAsResponse_;
00208   Teuchos::RCP<Epetra_Vector> gamma_;
00209   Teuchos::RCP<Epetra_CrsGraph> W_graph_;
00210   int Np_;
00211   int np_;
00212   int Ng_;
00213   RCP_Eptra_Map_Array_t map_p_;
00214   RCP_Array_String_Array_t names_p_;
00215   RCP_Eptra_Map_Array_t map_g_;
00216   RCP_Eptra_Vector_Array_t p_init_;
00217   Teuchos::RCP<Epetra_Vector> x_init_;
00218   Teuchos::RCP<Epetra_Vector> x_dot_init_;
00219 
00220   mutable Teuchos::RCP<const Epetra_Vector> coeff_s_p_;
00221 
00222   bool isIntialized_;
00223 
00224   // /////////////////////////////////////
00225   // Private member functions
00226 
00227   void initialize();
00228 
00229   void set_coeff_s_p( 
00230     const Teuchos::RCP<const Epetra_Vector> &coeff_s_p
00231     ) const;
00232 
00233   void unset_coeff_s_p() const;
00234 
00235   int coeff_s_idx(int i) const
00236     {
00237       return coeff_s_idx_[i];
00238     }
00239 
00240   double coeff_s(int i) const
00241     {
00242       return (*coeff_s_p_)[coeff_s_idx(i)];
00243     }
00244 
00245 };
00246 
00247 
00252 Teuchos::RCP<DiagonalTransientModel>
00253 diagonalTransientModel(
00254   Teuchos::RCP<Epetra_Comm> const& epetra_comm,
00255   Teuchos::RCP<Teuchos::ParameterList> const& paramList = Teuchos::null
00256   );
00257 
00258 
00259 } // namespace EpetraExt
00260 
00261 
00262 // RAB: Note, I wrapped this example code in a namespace mainly to make the
00263 // later definition of the nonmember functions safe (see the Thyra
00264 // Coding Guildelines document).
00265 
00266 
00267 #endif // EPETRA_EXT_DIAGONAL_TRANSIENT_MODEL_HPP
 All Classes Functions Variables Typedefs Friends