~nizamov-shawkat/python-meep/devel

« back to all changes in this revision

Viewing changes to custom.hpp

  • Committer: Nizamov Shawkat
  • Date: 2009-04-13 11:03:43 UTC
  • Revision ID: nizamov.shawkat@gmail.com-20090413110343-mhk0baa03s082kr3
Initial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <complex>
 
2
#include <math.h>
 
3
#include <cstdio>
 
4
#include <iostream>
 
5
#include <meep/vec.hpp>
 
6
 
 
7
using namespace std;
 
8
 
 
9
namespace meep {
 
10
 
 
11
//double eps(const vec &x)  { if (_EPS_CALLBACK) return _EPS_CALLBACK->eps(x); else return 1.0 ; }
 
12
double return_one(const vec &x) {return 1.0;}
 
13
 
 
14
double flux_helper(double *p, unsigned int x) {
 
15
    // function for dft_flux, which returns unbound array 
 
16
    // using this ugly hack we can access that array items
 
17
    // warning: there is no memory protection, array boundaries may be crossed !!! 
 
18
    return p[x]; }
 
19
 
 
20
class harminv_helperout {
 
21
    public:
 
22
        complex<double> *amp, *freq;
 
23
        unsigned int num;
 
24
        complex<double> get_amp(unsigned int x=0) { return (x<num) ? amp[x] : 0.0 ; };
 
25
        complex<double> get_freq(unsigned int x=0) { return (x<num) ? freq[x] : 0.0 ; };
 
26
};
 
27
 
 
28
int harminv_helper(monitor_point *p, component c, double fr1, double fr2, int maxbands, harminv_helperout *vv){
 
29
    complex<double> *amp, *freqs;
 
30
    int num;
 
31
    p->harminv(c, &amp, &freqs, &num, fr1, fr2, maxbands);
 
32
    if (!num) return 0;     // no results ???
 
33
    vv->amp = amp;
 
34
    vv->freq = freqs;
 
35
    vv->num = num;
 
36
    return num; };
 
37
 
 
38
class MPI{
 
39
    public:
 
40
        initialize *xxx;
 
41
        MPI(int argc, char **argv) { xxx = new initialize (argc,argv); };
 
42
        ~MPI() {  };
 
43
};
 
44
 
 
45
//complex<double> ff_test (const complex<double> *fields, const vec &loc, void *integrand_data_) {return 0; };
 
46
 
 
47
class Callback{
 
48
public:
 
49
        virtual ~Callback() { };
 
50
 
 
51
    complex<double> cd;
 
52
    complex<double> get_complex() { return cd; };
 
53
    void set_complex(complex<double> x) { cd = x; return; };
 
54
 
 
55
    double dbl;
 
56
    double get_double() {return dbl; };
 
57
    void set_double(double x) { dbl = x; return; };
 
58
 
 
59
    virtual void double_vec(const vec &x)  {};
 
60
    virtual void complex_vec(const vec &x) {};
 
61
    virtual void complex_time(double &t)   {};
 
62
 
 
63
};
 
64
 
 
65
static Callback * _EPS_CALLBACK;
 
66
static Callback * _INIF_CALLBACK;
 
67
static Callback * _MU_CALLBACK;
 
68
static Callback * _COND_CALLBACK;
 
69
static Callback * _CHI2_CALLBACK;
 
70
static Callback * _CHI3_CALLBACK;
 
71
static Callback * _SIGMA_CALLBACK;
 
72
 
 
73
static Callback * _CMPL1_CALLBACK;
 
74
static Callback * _CMPL2_CALLBACK;
 
75
static Callback * _CMPL3_CALLBACK;
 
76
static Callback * _CMPL4_CALLBACK;
 
77
static Callback * _CMPL5_CALLBACK;
 
78
 
 
79
static Callback * _DBL1_CALLBACK;
 
80
static Callback * _DBL2_CALLBACK;
 
81
static Callback * _DBL3_CALLBACK;
 
82
static Callback * _DBL4_CALLBACK;
 
83
static Callback * _DBL5_CALLBACK;
 
84
 
 
85
static Callback * _TIME1_CALLBACK;
 
86
static Callback * _TIME2_CALLBACK;
 
87
static Callback * _TIME3_CALLBACK;
 
88
static Callback * _TIME4_CALLBACK;
 
89
static Callback * _TIME5_CALLBACK;
 
90
 
 
91
void del_EPS_Callback()     { delete _EPS_CALLBACK;     _EPS_CALLBACK = 0;  }
 
92
void del_INIF_Callback()    { delete _INIF_CALLBACK;    _INIF_CALLBACK = 0; }
 
93
void del_MU_Callback()      { delete _MU_CALLBACK;      _MU_CALLBACK = 0;   }
 
94
void del_COND_Callback()    { delete _COND_CALLBACK;    _COND_CALLBACK = 0; }
 
95
void del_CHI2_Callback()    { delete _CHI2_CALLBACK;    _CHI2_CALLBACK = 0; }
 
96
void del_CHI3_Callback()    { delete _CHI3_CALLBACK;    _CHI3_CALLBACK = 0; }
 
97
void del_SIGMA_Callback()   { delete _SIGMA_CALLBACK;   _SIGMA_CALLBACK = 0;}
 
98
 
 
99
void del_CMPL1_Callback()   { delete _CMPL1_CALLBACK;   _CMPL1_CALLBACK = 0;}
 
100
void del_CMPL2_Callback()   { delete _CMPL2_CALLBACK;   _CMPL2_CALLBACK = 0;}
 
101
void del_CMPL3_Callback()   { delete _CMPL3_CALLBACK;   _CMPL3_CALLBACK = 0;}
 
102
void del_CMPL4_Callback()   { delete _CMPL4_CALLBACK;   _CMPL4_CALLBACK = 0;}
 
103
void del_CMPL5_Callback()   { delete _CMPL5_CALLBACK;   _CMPL5_CALLBACK = 0;}
 
104
 
 
105
void del_DBL1_Callback()    { delete _DBL1_CALLBACK;    _DBL1_CALLBACK = 0; }
 
106
void del_DBL2_Callback()    { delete _DBL2_CALLBACK;    _DBL2_CALLBACK = 0; }
 
107
void del_DBL3_Callback()    { delete _DBL3_CALLBACK;    _DBL3_CALLBACK = 0; }
 
108
void del_DBL4_Callback()    { delete _DBL4_CALLBACK;    _DBL4_CALLBACK = 0; }
 
109
void del_DBL5_Callback()    { delete _DBL5_CALLBACK;    _DBL5_CALLBACK = 0; }
 
110
 
 
111
void del_TIME1_Callback()   { delete _TIME1_CALLBACK;   _TIME1_CALLBACK = 0;}
 
112
void del_TIME2_Callback()   { delete _TIME2_CALLBACK;   _TIME2_CALLBACK = 0;}
 
113
void del_TIME3_Callback()   { delete _TIME3_CALLBACK;   _TIME3_CALLBACK = 0;}
 
114
void del_TIME4_Callback()   { delete _TIME4_CALLBACK;   _TIME4_CALLBACK = 0;}
 
115
void del_TIME5_Callback()   { delete _TIME5_CALLBACK;   _TIME5_CALLBACK = 0;}
 
116
 
 
117
void set_EPS_Callback(Callback *cb)     { del_EPS_Callback();   _EPS_CALLBACK = cb;     }
 
118
void set_INIF_Callback(Callback *cb)    { del_INIF_Callback();  _INIF_CALLBACK = cb;    }
 
119
void set_MU_Callback(Callback *cb)      { del_MU_Callback();    _MU_CALLBACK = cb;      }
 
120
void set_COND_Callback(Callback *cb)    { del_COND_Callback();  _COND_CALLBACK = cb;    }
 
121
void set_CHI2_Callback(Callback *cb)    { del_CHI2_Callback();  _CHI2_CALLBACK = cb;    }
 
122
void set_CHI3_Callback(Callback *cb)    { del_CHI3_Callback();  _CHI3_CALLBACK = cb;    }
 
123
void set_SIGMA_Callback(Callback *cb)   { del_SIGMA_Callback(); _SIGMA_CALLBACK = cb;   }
 
124
 
 
125
void set_CMPL1_Callback(Callback *cb)   { del_CMPL1_Callback(); _CMPL1_CALLBACK = cb;   }
 
126
void set_CMPL2_Callback(Callback *cb)   { del_CMPL2_Callback(); _CMPL2_CALLBACK = cb;   }
 
127
void set_CMPL3_Callback(Callback *cb)   { del_CMPL3_Callback(); _CMPL3_CALLBACK = cb;   }
 
128
void set_CMPL4_Callback(Callback *cb)   { del_CMPL4_Callback(); _CMPL4_CALLBACK = cb;   }
 
129
void set_CMPL5_Callback(Callback *cb)   { del_CMPL5_Callback(); _CMPL5_CALLBACK = cb;   }
 
130
 
 
131
void set_DBL1_Callback(Callback *cb)    { del_DBL1_Callback();  _DBL1_CALLBACK = cb;    }
 
132
void set_DBL2_Callback(Callback *cb)    { del_DBL2_Callback();  _DBL2_CALLBACK = cb;    }
 
133
void set_DBL3_Callback(Callback *cb)    { del_DBL3_Callback();  _DBL3_CALLBACK = cb;    }
 
134
void set_DBL4_Callback(Callback *cb)    { del_DBL4_Callback();  _DBL4_CALLBACK = cb;    }
 
135
void set_DBL5_Callback(Callback *cb)    { del_DBL5_Callback();  _DBL5_CALLBACK = cb;    }
 
136
 
 
137
void set_TIME1_Callback(Callback *cb)   { del_TIME1_Callback(); _TIME1_CALLBACK = cb;   }
 
138
void set_TIME2_Callback(Callback *cb)   { del_TIME2_Callback(); _TIME2_CALLBACK = cb;   }
 
139
void set_TIME3_Callback(Callback *cb)   { del_TIME3_Callback(); _TIME3_CALLBACK = cb;   }
 
140
void set_TIME4_Callback(Callback *cb)   { del_TIME4_Callback(); _TIME4_CALLBACK = cb;   }
 
141
void set_TIME5_Callback(Callback *cb)   { del_TIME5_Callback(); _TIME5_CALLBACK = cb;   }
 
142
 
 
143
double eps(const vec &x)    {if (_EPS_CALLBACK)     { _EPS_CALLBACK->double_vec(x); return _EPS_CALLBACK->dbl; } else return 1 ; }
 
144
double mu(const vec &x)     {if (_MU_CALLBACK)      { _MU_CALLBACK->double_vec(x); return _MU_CALLBACK->dbl; } else return 1 ; }
 
145
double cond(const vec &x)   {if (_COND_CALLBACK)    { _COND_CALLBACK->double_vec(x); return _COND_CALLBACK->dbl; } else return 0 ; }
 
146
double chi2(const vec &x)   {if (_CHI2_CALLBACK)    { _CHI2_CALLBACK->double_vec(x); return _CHI2_CALLBACK->dbl; } else return 0 ; }
 
147
double chi3(const vec &x)   {if (_CHI3_CALLBACK)    { _CHI3_CALLBACK->double_vec(x); return _CHI3_CALLBACK->dbl; } else return 0 ; }
 
148
double sigma(const vec &x)  {if (_SIGMA_CALLBACK)   { _SIGMA_CALLBACK->double_vec(x); return _SIGMA_CALLBACK->dbl; } else return 0 ; }
 
149
double dbl1(const vec &x)   {if (_DBL1_CALLBACK)    { _DBL1_CALLBACK->double_vec(x); return _DBL1_CALLBACK->dbl; } else return 0 ; }
 
150
double dbl2(const vec &x)   {if (_DBL2_CALLBACK)    { _DBL2_CALLBACK->double_vec(x); return _DBL2_CALLBACK->dbl; } else return 0 ; }
 
151
double dbl3(const vec &x)   {if (_DBL3_CALLBACK)    { _DBL3_CALLBACK->double_vec(x); return _DBL3_CALLBACK->dbl; } else return 0 ; }
 
152
double dbl4(const vec &x)   {if (_DBL4_CALLBACK)    { _DBL4_CALLBACK->double_vec(x); return _DBL4_CALLBACK->dbl; } else return 0 ; }
 
153
double dbl5(const vec &x)   {if (_DBL5_CALLBACK)    { _DBL5_CALLBACK->double_vec(x); return _DBL5_CALLBACK->dbl; } else return 0 ; }
 
154
 
 
155
complex<double> inif(const vec &x)  {if (_INIF_CALLBACK)  { _INIF_CALLBACK->complex_vec(x);  return _INIF_CALLBACK->cd;  } else return 0 ; }
 
156
complex<double> cmpl1(const vec &x) {if (_CMPL1_CALLBACK) { _CMPL1_CALLBACK->complex_vec(x); return _CMPL1_CALLBACK->cd; } else return 0 ; }
 
157
complex<double> cmpl2(const vec &x) {if (_CMPL2_CALLBACK) { _CMPL2_CALLBACK->complex_vec(x); return _CMPL2_CALLBACK->cd; } else return 0 ; }
 
158
complex<double> cmpl3(const vec &x) {if (_CMPL3_CALLBACK) { _CMPL3_CALLBACK->complex_vec(x); return _CMPL3_CALLBACK->cd; } else return 0 ; }
 
159
complex<double> cmpl4(const vec &x) {if (_CMPL4_CALLBACK) { _CMPL4_CALLBACK->complex_vec(x); return _CMPL4_CALLBACK->cd; } else return 0 ; }
 
160
complex<double> cmpl5(const vec &x) {if (_CMPL5_CALLBACK) { _CMPL5_CALLBACK->complex_vec(x); return _CMPL5_CALLBACK->cd; } else return 0 ; }
 
161
 
 
162
complex<double> time1(double x)  {if (_TIME1_CALLBACK) { _TIME1_CALLBACK->complex_time(x); return _TIME1_CALLBACK->cd; } else return 0 ; }
 
163
complex<double> time2(double x)  {if (_TIME2_CALLBACK) { _TIME2_CALLBACK->complex_time(x); return _TIME2_CALLBACK->cd; } else return 0 ; }
 
164
complex<double> time3(double x)  {if (_TIME3_CALLBACK) { _TIME3_CALLBACK->complex_time(x); return _TIME3_CALLBACK->cd; } else return 0 ; }
 
165
complex<double> time4(double x)  {if (_TIME4_CALLBACK) { _TIME4_CALLBACK->complex_time(x); return _TIME4_CALLBACK->cd; } else return 0 ; }
 
166
complex<double> time5(double x)  {if (_TIME5_CALLBACK) { _TIME5_CALLBACK->complex_time(x); return _TIME5_CALLBACK->cd; } else return 0 ; }
 
167
 
 
168
}