NanoStructures  1.0
DMFT solver for layered, strongly correlated nanostructures
cfunction.h
Go to the documentation of this file.
1 #ifndef FUNCTION_H
2 #define FUNCTION_H
3 
12 /*
13  * Copyright (c) 2014 Christoph Schuette.
14  *
15  * The license and distribution terms for this file may be
16  * found in the file LICENSE in this distribution
17  */
18 
19 #include <complex>
20 #include <vector>
21 
22 namespace mpi {
23  class OpenMPI;
24 }
25 namespace math {
26  class PFunction;
27 
34  class CFunction {
35  public:
36  typedef std::complex<double> (*tIntegrandFunction)(double, std::complex<double>, void*);
37 
38  inline static std::complex<double> one(double omega, std::complex<double> fomega, void* parameters) {
39  return 1.0;
40  }
41 
42  inline static std::complex<double> arg(double omega, std::complex<double> fomega, void* parameters) {
43  return omega;
44  }
45 
46  public:
50  CFunction();
55  CFunction(int length);
60  CFunction(const CFunction& orig);
61 
67  CFunction& operator=(const CFunction& orig);
68 
72  virtual ~CFunction();
73 
82  void resize(int length);
83 
88  int getSize() const {
89  return m_length;
90  }
91 
102  void set(int index, double argument, std::complex<double> value);
103 
110  void setArgument(int index, double argument);
111 
118  void setValue(int index, std::complex<double> value);
119 
125  double getArgument(int index) const;
126 
132  std::complex<double> getValue(int index) const;
133 
139  double getValueReal(int index) const;
140 
146  double getValueImag(int index) const;
147 
148  //IO
157  void write(std::string filename) const;
158 
168  void read(std::string filename);
169 
177  void writeBinary(std::string filename) const;
178 
188  void readBinary(std::string filename);
189 
193  void dump() const;
194 
195  // operators
200  void rescale(double factor);
201 
211  bool operator==(const CFunction& rhs) const;
212 
213  //convenience
227  void createLogGrid(double maxFrequency, double lambda, int n);
228 
229  math::CFunction transformPH() const;
230 
231  // interpolation
241  std::complex<double> interpolate(double x);
242  math::CFunction interpolate(double x1, double x2) const;
243  math::CFunction interpolate(double x1, double x2, std::complex<double> C1, std::complex<double> C2, std::complex<double> D1, std::complex<double> D2) const;
244 
245  //integration
246  std::complex<double> integrate(double x_1, double x_2) const;
247  std::complex<double> integrate(double x_1, double x_2, tIntegrandFunction g, void * parameters) const;
248 
249  protected:
250  double* m_arguments;
251  std::complex<double>* m_values;
252  int m_length;
253 
254  //befriend PFunction
255  friend class PFunction;
256 
257  //befriend OpenMPI
258  friend class mpi::OpenMPI;
259 
260  //befriend the operators
261  friend math::CFunction operator*(std::complex<double> factor, const math::CFunction& f);
262  friend math::CFunction operator/(const math::CFunction& f, const math::CFunction& g);
263  friend math::CFunction operator+(const math::CFunction& f, const math::CFunction& g);
264  friend math::CFunction operator/(const math::CFunction& f, double denominator);
265  };
266 
267  // operators
268 
269  math::CFunction operator*(std::complex<double> factor, const math::CFunction& f);
270  math::CFunction operator/(const math::CFunction& f, const math::CFunction& g);
271  math::CFunction operator+(const math::CFunction& f, const math::CFunction& g);
272  math::CFunction operator/(const math::CFunction& f, double denominator);
273  double similarity(const math::CFunction& a, const math::CFunction& b);
274 
275 }
276 #endif // FUNCTION_H
std::complex< double > interpolate(double x)
finds the linear interpolation of the discretized function at x.
Definition: cfunction.cpp:262
void writeBinary(std::string filename) const
writes the data of the instance as a binary file named filename.
Definition: cfunction.cpp:142
void rescale(double factor)
multiplies all arguments and values by the factor factor.
Definition: cfunction.cpp:187
void read(std::string filename)
reads data from the text file named filename.
Definition: cfunction.cpp:104
double getValueImag(int index) const
returns the value's imaginary part of the pair with index index.
Definition: cfunction.cpp:98
void setValue(int index, std::complex< double > value)
sets value of the argument-value pair with index index to value
Definition: cfunction.cpp:74
std::complex< double > getValue(int index) const
returns the value of the pair with index index.
Definition: cfunction.cpp:86
The MPI singleton is responsible for data exchange between compute nodes via OpenMPI.
Definition: openmpi.h:35
void write(std::string filename) const
writes the data of the instance as a text file named filename.
Definition: cfunction.cpp:128
void dump() const
dumps the data of the instance to std::cout.
Definition: cfunction.cpp:182
void resize(int length)
changes the size of the storage container to hold length argument-value pairs.
Definition: cfunction.cpp:206
void set(int index, double argument, std::complex< double > value)
sets the datapoint with indicated index.
Definition: cfunction.cpp:61
double getValueReal(int index) const
returns the value's real part of the pair with index index.
Definition: cfunction.cpp:92
double getArgument(int index) const
returns the argument of the pair with index index.
Definition: cfunction.cpp:80
void createLogGrid(double maxFrequency, double lambda, int n)
creates a logarithmic grid in argument space about 0.
Definition: cfunction.cpp:359
CFunction()
empty, default constructor
Definition: cfunction.cpp:10
int getSize() const
returns current size of the storage container
Definition: cfunction.h:88
virtual ~CFunction()
destructor frees all previously allocated memory.
Definition: cfunction.cpp:55
void setArgument(int index, double argument)
sets argument of the argument-value pair with index index to argument
Definition: cfunction.cpp:68
Definition: pfunction.h:8
void readBinary(std::string filename)
reads data to the instance as a binary file named filename.
Definition: cfunction.cpp:162
Discretized complex-valued function for real arguments.
Definition: cfunction.h:34
CFunction & operator=(const CFunction &orig)
operator=
Definition: cfunction.cpp:37
bool operator==(const CFunction &rhs) const
compares the current instance to the instance rhs
Definition: cfunction.cpp:195