Bridge++  Ver. 1.1.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fopr_CRS.h
Go to the documentation of this file.
1 
15 #ifndef FOPR_CRS_INCLUDED
16 #define FOPR_CRS_INCLUDED
17 
18 #include <valarray>
19 #include <string>
20 
21 #include "fopr.h"
22 
23 #include "bridgeIO.h"
24 using Bridge::vout;
25 
27 
38 class Fopr_CRS : public Fopr
39 {
40  private:
42  int m_Nsize, m_Nnz;
43  std::valarray<int> m_rowidx_nz;
44  std::valarray<int> m_column_nz;
45  std::valarray<double> m_elem_nz;
46  std::string m_mode;
48 
49  public:
50 
51  Fopr_CRS(Fopr *fopr)
52  : Fopr(), m_fopr(fopr)
53  {
54  set_matrix();
55  }
56 
57  Fopr_CRS(std::string fname)
58  : Fopr(), m_fopr(0)
59  {
60  set_matrix(fname);
61  }
62 
63  void set_parameters(const Parameters&);
64 
65  void write_matrix(std::string);
66 
67  void set_config(Field *U)
68  {
69  if (m_fopr == 0) {
70  vout.crucial(m_vl, "Fopr_CRS: fopr is not set.\n");
71  abort();
72  } else {
73  m_fopr->set_config(U);
74  }
75  }
76 
77  void set_mode(std::string mode)
78  {
79  m_mode = mode;
80  }
81 
82  std::string get_mode() const
83  {
84  return m_mode;
85  }
86 
87  const Field mult(const Field& f)
88  {
89  Field v(f.nin(), f.nvol(), f.nex());
90 
91  mult(v, f);
92  return v;
93  }
94 
95  const Field mult_dag(const Field& f)
96  {
97  Field v(f.nin(), f.nvol(), f.nex());
98 
99  mult_dag(v, f);
100  return v;
101  }
102 
103  void mult(Field& v, const Field& f)
104  {
105  if (m_mode == "D") {
106  D(v, f);
107  } else if (m_mode == "DdagD") {
108  DdagD(v, f);
109  } else if (m_mode == "Ddag") {
110  Ddag(v, f);
111  } else {
112  vout.crucial(m_vl, "Fopr_CRS: mode undefined.\n");
113  abort();
114  }
115  }
116 
117  void mult_dag(Field& v, const Field& f)
118  {
119  if (m_mode == "D") {
120  Ddag(v, f);
121  } else if (m_mode == "DdagD") {
122  DdagD(v, f);
123  } else if (m_mode == "Ddag") {
124  D(v, f);
125  } else {
126  vout.crucial(m_vl, "Fopr_CRS: mode undefined.\n");
127  abort();
128  }
129  }
130 
131  void DdagD(Field&, const Field&);
132  void D(Field&, const Field&);
133  void Ddag(Field&, const Field&);
134  void H(Field&, const Field&);
135 
136  int field_nvol() { return m_Nvol; }
137  int field_nin() { return m_Nin; }
138  int field_nex() { return m_Nex; }
139 
140  private:
141  void set_matrix();
142  void set_matrix(std::string);
143 
144  void set_matrix_1row(int&, std::valarray<int>&,
145  std::valarray<double>&, Field&);
146 };
147 #endif