Bridge++  Version 1.5.4
 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 <string>
19 
20 #include "fopr.h"
21 
22 #include "IO/bridgeIO.h"
23 using Bridge::vout;
24 
26 
37 class Fopr_CRS : public Fopr
38 {
39  public:
40  static const std::string class_name;
41 
42  private:
44  int m_Nsize, m_Nnz;
45  std::vector<int> m_rowidx_nz;
46  std::vector<int> m_column_nz;
47  std::vector<double> m_elem_nz;
48  std::string m_mode;
50 
51  public:
52 
53  Fopr_CRS(Fopr *fopr)
54  : Fopr(), m_fopr(fopr)
55  {
56  set_matrix();
57  }
58 
60  : Fopr(), m_fopr(fopr.get())
61  {
62  set_matrix();
63  }
64 
65  Fopr_CRS(const std::string fname)
66  : Fopr(), m_fopr(0)
67  {
68  set_matrix(fname);
69  }
70 
71  void set_parameters(const Parameters&);
72 
73  void write_matrix(const std::string);
74 
75  void set_config(Field *U)
76  {
77  if (m_fopr == 0) {
78  vout.crucial(m_vl, "Error at %s: fopr is not set.\n", class_name.c_str());
79  exit(EXIT_FAILURE);
80  } else {
81  m_fopr->set_config(U);
82  }
83  }
84 
86  {
87  if (m_fopr == 0) {
88  vout.crucial(m_vl, "Error at %s: fopr is not set.\n", class_name.c_str());
89  exit(EXIT_FAILURE);
90  } else {
91  m_fopr->set_config(U.get());
92  }
93  }
94 
95  void set_mode(const std::string mode)
96  {
97  m_mode = mode;
98  }
99 
100  std::string get_mode() const
101  {
102  return m_mode;
103  }
104 
105  void mult(Field& v, const Field& f)
106  {
107  if (m_mode == "D") {
108  D(v, f);
109  } else if (m_mode == "DdagD") {
110  DdagD(v, f);
111  } else if (m_mode == "Ddag") {
112  Ddag(v, f);
113  } else {
114  vout.crucial(m_vl, "Error at %s: mode unknown: '%s'.\n", class_name.c_str(), m_mode.c_str());
115  exit(EXIT_FAILURE);
116  }
117  }
118 
119  void mult_dag(Field& v, const Field& f)
120  {
121  if (m_mode == "D") {
122  Ddag(v, f);
123  } else if (m_mode == "DdagD") {
124  DdagD(v, f);
125  } else if (m_mode == "Ddag") {
126  D(v, f);
127  } else {
128  vout.crucial(m_vl, "Error at %s: mode unknown: '%s'.\n", class_name.c_str(), m_mode.c_str());
129  exit(EXIT_FAILURE);
130  }
131  }
132 
133  void DdagD(Field&, const Field&);
134  void D(Field&, const Field&);
135  void Ddag(Field&, const Field&);
136  void H(Field&, const Field&);
137 
138  int field_nvol() { return m_Nvol; }
139  int field_nin() { return m_Nin; }
140  int field_nex() { return m_Nex; }
141 
142  private:
143  void set_matrix();
144  void set_matrix(const std::string);
145 
146  void set_matrix_1row(int&, std::vector<int>&,
147  std::vector<double>&, const Field&);
148 
149 #ifdef USE_FACTORY
150  private:
151  static Fopr *create_object_with_fopr(Fopr *fopr)
152  {
153  return new Fopr_CRS(fopr);
154  }
155 
156  static Fopr *create_object_with_filename(const std::string& fname)
157  {
158  return new Fopr_CRS(fname);
159  }
160 
161  public:
162  static bool register_factory()
163  {
164  bool init1 = Fopr::Factory_fopr::Register("CRS", create_object_with_fopr);
165  bool init2 = Fopr::Factory_string::Register("CRS", create_object_with_filename);
166 
167  return init1 && init2;
168  }
169 #endif
170 };
171 #endif
int m_Nin
Definition: fopr_CRS.h:43
int m_Nsize
Definition: fopr_CRS.h:44
BridgeIO vout
Definition: bridgeIO.cpp:503
int m_Nvol
Definition: fopr_CRS.h:43
virtual void set_config(Field *)=0
setting pointer to the gauge configuration.
Container of Field-type object.
Definition: field.h:45
Fopr_CRS(unique_ptr< Fopr > &fopr)
Definition: fopr_CRS.h:59
void Ddag(Field &, const Field &)
Definition: fopr_CRS.cpp:83
void set_matrix_1row(int &, std::vector< int > &, std::vector< double > &, const Field &)
Definition: fopr_CRS.cpp:201
void set_mode(const std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: fopr_CRS.h:95
Class for parameters.
Definition: parameters.h:46
std::string get_mode() const
only for Fopr_Overlap
Definition: fopr_CRS.h:100
int m_Nex
Definition: fopr_CRS.h:43
int field_nex()
returns the external d.o.f. for which the fermion operator is defined.
Definition: fopr_CRS.h:140
std::string m_mode
Definition: fopr_CRS.h:48
int m_Nnz
Definition: fopr_CRS.h:44
Bridge::VerboseLevel m_vl
Definition: fopr.h:127
Fopr_CRS(Fopr *fopr)
Definition: fopr_CRS.h:53
pointer get() const
void H(Field &, const Field &)
int field_nvol()
returns the volume for which the fermion operator is defined.
Definition: fopr_CRS.h:138
void set_matrix()
Definition: fopr_CRS.cpp:118
std::vector< int > m_rowidx_nz
Definition: fopr_CRS.h:45
void set_parameters(const Parameters &)
Definition: fopr_CRS.cpp:27
static const std::string class_name
Definition: fopr_CRS.h:40
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
std::vector< double > m_elem_nz
Definition: fopr_CRS.h:47
void DdagD(Field &, const Field &)
Definition: fopr_CRS.cpp:36
void write_matrix(const std::string)
Definition: fopr_CRS.cpp:271
void set_config(Field *U)
setting pointer to the gauge configuration.
Definition: fopr_CRS.h:75
std::vector< int > m_column_nz
Definition: fopr_CRS.h:46
Fopr_CRS(const std::string fname)
Definition: fopr_CRS.h:65
void D(Field &, const Field &)
Definition: fopr_CRS.cpp:46
Base class of fermion operator family.
Definition: fopr.h:46
void mult(Field &v, const Field &f)
multiplies fermion operator to a given field (2nd argument)
Definition: fopr_CRS.h:105
Fermion operator with CRS matrix format.
Definition: fopr_CRS.h:37
void mult_dag(Field &v, const Field &f)
hermitian conjugate of mult(Field&, const Field&).
Definition: fopr_CRS.h:119
void set_config(unique_ptr< Field_G > &U)
Definition: fopr_CRS.h:85
int field_nin()
returns the on-site d.o.f. for which the fermion operator is defined.
Definition: fopr_CRS.h:139
Fopr * m_fopr
Definition: fopr_CRS.h:49