python-meep team mailing list archive
-
python-meep team
-
Mailing list archive
-
Message #00040
Re: [python-eep] Conductivity in python meep
2011/8/2 Yu Zhang <zhamboo@xxxxxxxxx>:
> Dear Shavkat,
>
> Here is partial code from known_results.py.
>
> class sigma(Callback):
> def __init__(self, sig):
> Callback.__init__(self)
> self.sig=sig
>
> def double_vec(self,r):
> return self.sig
>
> s= structure(v, eps)
> pol1 = sigma(7.63)
> set_DBL1_Callback(pol1.__disown__())
> s.add_polarizability(DBL1, 0.3, 0.1)
>
> At your convenience, can you explain the following to me,
>
> 1) what is the variable DBL1 ? Does it store the sigmas for all cells ?
There are some requirements for callback functions (callback is python
code which is called by C/C++ library).
Details are complex and boring, you may look at SWIG documentation on
particular details.
In general, you can not callback python code directly within C++
library that expects pointer to a function to be passed.
To overcome this a bunch of proxy functions are declared within SWIG
and they are generally given names like EPS, MU, COND, SIGMA and as a
spare DBL*, CMPL*. After that it became possible to pass a pointer to
these functions as a callback functions, and these proxies are
implemented so that they call python code. That is why it is strictly
required to pass those proxies as a function pointer.
pol1 = sigma(7.63)
set_DBL1_Callback(pol1.__disown__())
This part creates a python class (sigma) and sets it as a callback to
the DBL1 proxy. Now calls to DBL1 will result in call to the
pol1.double_vec(). If callback is not set function will return 0,
otherwise it will return some value.
s.add_polarizability(DBL1, 0.3, 0.1)
Now this DBL1 proxy function is passed to add_polarizability.
And, as you have added it to the structure it will be called for the
whole cell - it means at any grid point in the simulation cell, point
vector is passed as a vector.
You may want to look inside meep_common.i and custom.hpp for the
details on implementation.
> 2) what are the third and the second parameter in function
> add_polarizability() (last line)?
s.add_polarizability(DBL1, 0.3, 0.1)
according to python-meep sources this call is overloaded and in this
case meanings are:
DBL1 - a pointer to function
0.3 - omega
0.1 - gamma.
there is another sample in the python-meep sources - dispersive.py
Strange, but looking into the latest meep sources I can not find
add_polarizability anymore. Probably it is time for me to check how
python-meep works with latest meep. They said that they will release a
new version soon and it will be sad if python-meep will not be
compatible.
Can you please confirm that known_results works OK in your case and
what version of meep you are using?
Kind regards,
Shavkat Nizamov
References