Greens-code
A modular quantum transport code
funcs_base.hpp
1 #ifndef FUNC_BASE_HEADER_INPU
2 #define FUNC_BASE_HEADER_INPU
3 
4 #include "input_file.hpp"
5 #include <vector>
6 #include <complex>
7 
8 typedef std::complex<double> complex;
9 
11 public:
12  typedef STD_TR1::shared_ptr< function_Object> ref;
13  typedef STD_TR1::shared_ptr< const function_Object> const_ref;
14 
15  virtual ~function_Object() throw() {};
16 
17  double operator()(const double d) const
18  {
19  return value((d-x0)/range_) * scale_ + y0;
20  };
21 
22  double x_min() const { return x0;};
23  double x_max() const { return x0 + range_;};
24 
25  double y_min() const { return y0;};
26  double y_max() const { return y0 + scale_;};
27 
28  double range() const { return range_;};
29  double scale() const { return scale_;};
30 
31 private:
32  double range_;
33  double scale_;
34  double x0;
35  double y0;
36 
37  void init();
38 
39  virtual void init_func() = 0;
40  virtual double value(const double d) const = 0;
41 };
42 
44 public:
45  typedef STD_TR1::shared_ptr< function_complex_Object> ref;
46  typedef STD_TR1::shared_ptr< const function_complex_Object> const_ref;
47 
48  virtual ~function_complex_Object() throw() {};
49 
50  complex operator()(const double d) const
51  {
52  return value((d-x0)/range_) * scale_ + y0;
53  };
54 
55  double x_min() const { return x0;};
56  double x_max() const { return x0 + range_;};
57 
58  double y_min() const { return y0;};
59  double y_max() const { return y0 + scale_;};
60 
61  double range() const { return range_;};
62  double scale() const { return scale_;};
63 
64 private:
65  double range_;
66  double scale_;
67  double x0;
68  double y0;
69 
70  void init();
71 
72  virtual void init_func() = 0;
73  virtual complex value(const double d) const = 0;
74 };
75 
76 /*
77 function2d_Object is an abstract base class for functions with two continuous parameters (i.e. f(x1,x2)).
78 Contrary to function_Object, no scaling features are implemented here; I suggest to define them in the derived classes if needed (see gaussian2d_func).
79 */
81 public:
82  typedef STD_TR1::shared_ptr< function2d_Object> ref;
83  typedef STD_TR1::shared_ptr< const function2d_Object> const_ref;
84 
85  function2d_Object(): start_x1_(0), start_x2_(0){};
86 
87  ~function2d_Object() throw() {};
88 
89  double operator()(const double x1,const double x2) const
90  {
91  return value(x1 - start_x1_,x2 - start_x2_);
92  };
93 
94 
95 
96 private:
97  double start_x1_;
98  double start_x2_;
99 
100  void init();
101 
102  virtual void init_func() = 0;
103  virtual double value(const double x1,const double x2) const = 0;
104 
105 };
106 
108 public:
109  typedef STD_TR1::shared_ptr< function_complex2d_Object> ref;
110  typedef STD_TR1::shared_ptr< const function_complex2d_Object> const_ref;
111 
112  function_complex2d_Object() :start_x1_(0), start_x2_(0) {};
113  virtual ~function_complex2d_Object() throw() {};
114 
115  complex operator()(const double x1,const double x2) const
116  {
117  return value(x1-start_x1_,x2-start_x2_);
118  };
119 
120 
121 
122 private:
123  double start_x1_;
124  double start_x2_;
125 
126  void init();
127 
128  virtual void init_func() = 0;
129  virtual complex value(const double x1,const double x2) const = 0;
130 
131 };
132 
133 
135 
144 public:
145  typedef STD_TR1::shared_ptr< vector_Object> ref;
146  typedef STD_TR1::shared_ptr< const vector_Object> const_ref;
147 
148  virtual ~vector_Object() throw() {};
149 
151  double operator[](const size_t i) const {
152 // if (i >= size()) throw (E_bad_index(i));
153  do_lazy_init();
154  return data[i % data.size()];
155  };
156 
158  size_t size() const { return data.size();};
159 
161  void output(std::ostream&) const;
162 
164  const std::vector<double>& provide_vector() const { return data;};
165 
167  void set_complex_vector_real(std::vector<complex>&) const;
169  void set_complex_vector_imag(std::vector<complex>&) const;
170 
171 protected:
172  void set_element(const size_t i, double d) const{
173  if (i >= data.size()) throw (E_bad_index(i));
174  data[i] = d;
175  }
176 
177  mutable bool lazy_initialized;
178 private:
179  mutable std::vector<double> data;
180 
181  void init();
182  void init_from_clone( loadable_Object::const_ref );
183 
184  void do_lazy_init() const{ if (!lazy_initialized){ lazy_initialized = true; lazy_init();}};
185 
186  virtual void init_vector() = 0;
187  virtual void lazy_init() const;
188  virtual size_t determine_size();
189 };
190 
192 
198 public:
199  ~Enumeration_vector_Object() throw() {};
200 private:
201  STD_TR1::shared_ptr<std::vector<double> > enum_data;
202 
203  virtual size_t determine_size();
204  const char* name() const {return "Enumeration_vector";};
205  void init_vector();
206 };
207 
209 
218 public:
219  ~vector_function_Object() throw() {};
220 private:
221  const char* name() const {return "vector_function";};
222 
223  void init_vector();
224 };
225 
226 #endif
Definition: exceptions.hpp:255
Definition: funcs_base.hpp:80
size_t size() const
Number of elements in vector.
Definition: funcs_base.hpp:158
Vector using an Enumeration to set its values.
Definition: funcs_base.hpp:197
const std::vector< double > & provide_vector() const
Return the internal container object, use with care.
Definition: funcs_base.hpp:164
Definition: funcs_base.hpp:107
Base class for a 1D Vector.
Definition: funcs_base.hpp:143
Definition: funcs_base.hpp:10
double operator[](const size_t i) const
indexed access to vector elements
Definition: funcs_base.hpp:151
An abstract base class supporting xml_file_reading of input parameters.
Definition: input_file.hpp:79
Vector using a function to set its values.
Definition: funcs_base.hpp:217
Definition: funcs_base.hpp:43