LifeV
MatrixContainer.hpp
Go to the documentation of this file.
1 /*
2  * MatrixContainer.hpp
3  *
4  * Created on: Sep 30, 2010
5  * Author: uvilla
6  */
7 
8 #ifndef MATRIXCONTAINER_HPP_
9 #define MATRIXCONTAINER_HPP_
10 
11 
12 #include <Teuchos_ParameterList.hpp>
13 
14 
15 #include <lifev/core/LifeV.hpp>
16 
17 #include <lifev/core/array/MatrixEpetra.hpp>
18 
19 namespace LifeV
20 {
21 
22 //! @class MatrixContainer
23 /*!
24  * This class is a container for matrices and other parameters (stored in a Teuchos::ParameterList).
25  */
26 
27 template<typename KEYTYPE = std::string>
29 {
30 public:
31  //! @name Public Typedef
32  //@{
33 
34  typedef KEYTYPE KeyType;
35 
38  typedef typename std::map<KeyType, MatrixType_ptr > Container;
39  typedef typename Container::iterator Iterator;
40  typedef typename Container::const_iterator CIterator;
41  typedef typename Container::value_type ValuePair;
42  //@}
43 
44  //! Empty constructor
46 
47  //! @name setters
48  //@{
49  void set (const KeyType& _name, const MatrixType_ptr& _matrix);
50  template<typename T>
51  void setParameter (const std::string& _name, const T& par);
52  //@}
53  //! @name getters
54  //@{
55  MatrixType_ptr getMatrix (const KeyType& _name) const;
56  MatrixRawType_ptr get (const KeyType& _name) const;
57  template<typename T>
58  T getParameter (const std::string& _name, const T& dpar) const;
59  //@}
60 
61 private:
62  //! map containing the matrices
64  //! list for additional parameters
66 };
67 
68 template<typename KEYTYPE>
69 void MatrixContainer<KEYTYPE>::set (const KeyType& _name, const MatrixType_ptr& _matrix)
70 {
71  ASSERT_PRE (_matrix.get() != 0, "Setting a null pointer to matrix");
72  ValuePair valuePair (_name, _matrix);
73  M_container.insert (valuePair);
74 }
75 
76 template<typename KEYTYPE>
77 std::shared_ptr<MatrixEpetra<double> > MatrixContainer<KEYTYPE>::getMatrix (const KeyType& _name) const
78 {
79  CIterator it (M_container.find (_name) );
80  ASSERT_POS (it != M_container.end(), "Matrix not found");
81  return it->second;
82 }
83 
84 template<typename KEYTYPE>
86 {
87  CIterator it (M_container.find (_name) );
88  ASSERT_POS (it != M_container.end(), "Matrix not found");
89  return boost::shared_dynamic_cast<Epetra_CrsMatrix> (it->second->getMatrixPtr() );
90 }
91 
92 
93 template<typename KEYTYPE>
94 template<typename T>
95 void MatrixContainer<KEYTYPE>::setParameter (const std::string& _name, const T& par)
96 {
97  M_pList->set (_name, par);
98 }
99 
100 template<typename KEYTYPE>
101 template<typename T>
102 T MatrixContainer<KEYTYPE>::getParameter (const std::string& _name, const T& dpar) const
103 {
104  // get should be a const method but it is not.
105  //This is the reason why I'm using a shared_ptr and not an object.
106  return M_pList->get (_name, dpar);
107 }
108 
109 
110 } /*end namespace */
111 
112 #endif /* MATRIXCONTAINER_HPP_ */
MatrixType_ptr getMatrix(const KeyType &_name) const
void set(const KeyType &_name, const MatrixType_ptr &_matrix)
Container M_container
map containing the matrices
void updateInverseJacobian(const UInt &iQuadPt)
std::shared_ptr< Epetra_CrsMatrix > MatrixRawType_ptr
MatrixRawType_ptr get(const KeyType &_name) const
#define ASSERT_PRE(X, A)
Definition: LifeAssert.hpp:96
std::shared_ptr< MatrixEpetra< double > > MatrixType_ptr
T getParameter(const std::string &_name, const T &dpar) const
#define ASSERT_POS(X, A)
Definition: LifeAssert.hpp:102
MatrixContainer()
Empty constructor.
std::shared_ptr< Teuchos::ParameterList > M_pList
list for additional parameters
std::map< KeyType, MatrixType_ptr > Container
Container::value_type ValuePair
void setParameter(const std::string &_name, const T &par)