Greens-code
A modular quantum transport code
state.hpp
1 #ifndef PICTURE_HPP_FILE
2 #define PICTURE_HPP_FILE
3 
4 #include <string>
5 #include <vector>
6 #include <complex>
7 #include <iostream>
8 #include <string>
9 #include <algorithm>
10 #include <list>
11 
12 #include "rect_fwd.hpp"
13 #include "parallel.hpp"
14 #include "shared_ptr.hpp"
15 
16 typedef std::list<std::string> t_filename_list;
17 typedef STD_TR1::shared_ptr<t_filename_list > t_filename_list_ref;
18 
19 typedef std::complex<double> complex;
20 typedef std::vector<complex> Vector;
21 
22 class state_collection;
23 
24 class state{
25 public:
26 
27  size_t size() const;
28 
29  const std::string identifier() const;
30  void set_identifier(const std::string&);
31 
32  Rectangle_const_ref geometry() const;
33 
34  const complex* raw_storage() const;
35  complex* raw_storage();
36 
37  void write() const;
38 
39  double get_tag() const;
40  void set_tag(double t);
41 
42  STD_TR1::shared_ptr<state_collection> get_state_collection(){ return sc;};
43 
44 protected:
45 
46  state(size_t nr, STD_TR1::shared_ptr<state_collection> sc_):
47  me(nr), sc(sc_){};
48 
49 private:
50  void load(std::istream&);
51 
52  friend class state_collection;
53 
54  size_t me;
55  STD_TR1::shared_ptr<state_collection> sc;
56 };
57 
71 
73 public:
74 
75  typedef STD_TR1::shared_ptr< state_collection> ref;
76  typedef STD_TR1::shared_ptr<const state_collection> const_ref;
77 
78  static
79  ref create(MPI_Comm c);
80 
81  static
82  ref create(MPI_Comm c, t_filename_list_ref files);
83 
84  std::string filename(size_t index) const;
85 
86  std::string minimal_identifier(const std::string& , size_t, size_t );
87 
88  const std::string& state_identifier(size_t index) const;
89  Rectangle_const_ref state_geometry(size_t index) const;
90  size_t state_size(size_t index) const;
91 
92  state push_pointer(complex*);
93  void pop_pointer();
94 
95  void add_empty_state(Rectangle_const_ref,
96  const std::string& identifier);
97  void add_states(const t_filename_list_ref files);
98  void add_states(Rectangle_const_ref,
99  Vector&,
100  const std::string& identifier);
101 
102  ref copy() const;
103 
104  template <class Pr>
105  ref copy_if( Pr ) const;
106 
107  void clear();
108 
109  state get_state(size_t index);
110  const state get_state(size_t index) const;
111 
112  void write() const;
113  void write(size_t index) const;
114 
115  size_t N() const { return states.size();};
116 
117  void set_write_out_immediately(bool woi){ write_out_immediately = woi;};
118 
119  void set_prefix(const std::string& s){prefix = s;};
120  const std::string& get_prefix() const {return prefix;};
121 
123  double state_norm(int);
124 
126  void state_dot(int,int,complex& result);
127 
129  void state_scale(int, complex alpha);
130 
132  void state_axpy(int i, int j, complex alpha);
133 
135  void state_copy(int i, int j);
136 
137 /*
139 extern "C" void FROM_F(wf_apply_h)(wavefunctions* wf, int& i, int& j) {
140  wf->m->apply_H(wf->get_t(),wf->f(i),wf->f(j),wf->work());
141 }
142 
144 extern "C" void FROM_F(wf_apply_dh)(wavefunctions* wf, int& i, int& j) {
145  wf->m->apply_dH(wf->get_t(),wf->f(i),wf->f(j));
146 }
147 
148 */
149 
151  void state_maxpby(const complex* prefactors, int& istart, int& iend, complex& alpha, int& j);
152 
153 private:
154  bool write_out_immediately;
155 
156  std::string prefix;
157 
158  MPI_Comm comm;
159 
160  struct state_info{
161  std::string identifier;
162  double tag;
163  complex* p;
164  size_t size;
165  Rectangle_const_ref geometry;
166 
167  complex* raw_storage() { return p;};
168  const complex* raw_storage() const { return p;};
169  };
170 
171  void check(size_t index) const;
172 
173 
174  void write_state(std::ostream& os,
175  const state_info& st) const;
176 
177  void load_state(state_info& st,
178  std::string name,
179  std::istream& is);
180 
183 
184  friend class state;
185 
186  std::vector<state_info> states;
187 
188  std::list< STD_TR1::shared_ptr<Vector> > state_data;
189 
190  STD_TR1::weak_ptr<state_collection> my_ptr;
191 };
192 
193 template <class Pr>
194 STD_TR1::shared_ptr<state_collection>
195 state_collection::copy_if( Pr pred ) const {
196 
197  auto clone = create(comm);
198 
199  clone->write_out_immediately = false;
200  clone->prefix = prefix;
201 
202  std::copy(state_data.begin(), state_data.end(), std::back_inserter(clone->state_data));
203 
204  auto ins(std::back_inserter(clone->states));
205  for (size_t i = 0; i < states.size(); ++i)
206  if (pred(get_state(i))){
207  *ins = states[i];
208  ++ins;
209  }
210 
211  return clone;
212 }
213 
214 #endif
Definition: state.hpp:72
Definition: state.hpp:24