LifeV
ZeroDimensionalRythmosModelInterface.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but 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 License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  * @file
29  * @brief Rythmos Model Interface
30  * @version alpha (experimental)
31  *
32  * @date 21-11-2011
33  * @author Mahmoud Jafargholi
34  *
35  * @contributors Cristiano Malossi <cristiano.malossi@epfl.ch>
36  * @mantainer Cristiano Malossi <cristiano.malossi@epfl.ch>
37  */
38 
39 #ifndef ZeroDimensionalRythmosModelInterface_H
40 #define ZeroDimensionalRythmosModelInterface_H 1
41 
42 // Include definitions
43 #include <lifev/zero_dimensional/solver/ZeroDimensionalDefinitions.hpp>
44 
45 #if ( defined(HAVE_NOX_THYRA) && defined(HAVE_TRILINOS_RYTHMOS) )
46 
47 
48 #include <NOX.H>
49 #include <NOX_Epetra.H>
50 #include <NOX_Epetra_Interface_Required.H> // base class
51 #include <NOX_Epetra_Interface_Jacobian.H> // base class
52 #include <NOX_Epetra_Interface_Preconditioner.H> // base class
53 #include <NOX_Thyra.H>
54 
55 
56 // LIFEV
57 #include <lifev/zero_dimensional/solver/ZeroDimensionalCircuitData.hpp>
58 
59 namespace NOX
60 {
61 namespace Parameter
62 {
63 class List;
64 }
65 }
66 namespace LifeV
67 {
68 
69 //! Rhytmos model interface.
70 /*!
71  * Rhytmos solver interface will communicate with this class.
72  * this class have access to circuit data. The main task of this class is to
73  * provide the residual and jacobian at every step to Rhythmos solver interface.
74  */
75 class RythmosModelInterface : public NOX::Epetra::Interface::Required,
76  public NOX::Epetra::Interface::Jacobian,
77  public NOX::Epetra::Interface::Preconditioner
78 {
79 public:
80 
81  //! Constructor
82  RythmosModelInterface (Int NumGlobalElements, Epetra_Comm* comm, zeroDimensionalCircuitDataPtr_Type circuitData);
83 
84  //! Destructor
85  virtual ~RythmosModelInterface();
86 
87  //! This method is empty.
88  virtual bool computeF (const Epetra_Vector& x, Epetra_Vector& FVec, FillType fillType = Residual);
89 
90  //! This method is empty.
91  virtual bool computeJacobian (const Epetra_Vector& x, Epetra_Operator& Jac);
92 
93  //! This method is empty
94  virtual bool computePrecMatrix (const Epetra_Vector& x);
95 
96  //! This method is empty
97  virtual bool computePreconditioner (const Epetra_Vector& x, Epetra_Operator& Prec, Teuchos::ParameterList* precParams = 0);
98 
99  //! get solution vector
100  Epetra_Vector& getSolutionY();
101 
102  //! get derivative of solution vector respect to time
103  Epetra_Vector& getSolutionYp();
104 
105  Epetra_Map& getMap();
106 
107  Epetra_CrsGraph& getGraph();
108 
109  //! this method empty.
110  virtual bool evaluate (Real t, const Epetra_Vector* x, Epetra_Vector* f );
111 
112  //! compute Implicit residual.
113  virtual bool evaluateFImplicit (const Real& t, const Epetra_Vector* x, const Epetra_Vector* x_dot, Epetra_Vector* f );
114 
115  //! compute jacobian.
116  virtual bool evaluateWImplicit (const Real& t, const Real& alpha, const Real& beta, const Epetra_Vector* x, const Epetra_Vector* x_dot, Epetra_CrsMatrix* W );
117 
118  virtual bool initializeSolnY();
119 
120  bool initializeSolnY (const vectorEpetra_Type& y);
121 
122  virtual bool initializeSolnYp();
123 
124  bool initializeSolnYp (const vectorEpetra_Type& yp);
125 
126  //! hafter complete Rythmos step, this method will update circuit data.
127  void extractSolution (const Real& t1, const vectorEpetra_Type& y , const vectorEpetra_Type& yp );
128 
129  Int numCircuitElements()
130  {
131  return M_numCircuitElements;
132  }
133 
134 protected:
135  Int M_numCircuitElements; // Total Number of elements
136  Int M_numMyElements; // Number of elements owned by this process
137  Int M_myPID; // Process number
138  Int M_numProc; // Total number of processes
139 
140  Epetra_CrsGraph* M_graph;
141  std::shared_ptr<Epetra_CrsGraph> M_graphSharedPtr;
142  Epetra_Comm* M_comm;
143  std::shared_ptr<Epetra_Comm> M_commSharedPtr;
144  Epetra_Map* M_standardMap;
145  Epetra_Vector* M_initialSolutionY;
146  Epetra_Vector* M_initialSolutionYp;
147 
148  zeroDimensionalCircuitDataPtr_Type M_circuitData;
149  matrixPtr_Type M_A;
150  matrixPtr_Type M_B;
151  vectorPtr_Type M_C;
152  vectorEpetraPtr_Type M_Y0;
153  vectorEpetraPtr_Type M_Yp0;
154  std::shared_ptr<MapEpetra> M_mapEpetraPtr;
155  vectorEpetraPtr_Type M_fA;//dummy variable
156  vectorEpetraPtr_Type M_fB;//dummy variable
157 };
158 
159 typedef std::shared_ptr< RythmosModelInterface > rythmosModelInterfacePtr_Type;
160 typedef Teuchos::RCP< RythmosModelInterface > rythmosModelInterfacePtrRCP_Type;
161 } // LifeV namespace
162 
163 #endif /* HAVE_NOX_THYRA && HAVE_TRILINOS_RYTHMOS */
164 
165 #endif //ZeroDimensionalRythmosModelInterface_H