-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Allow unequal DFT frequencies #1141
Conversation
…ions using dft. Need to hunt down any possible uses of them...
…per functions, etc. to header
…per functions, etc. to header
Some swig advice: When wrapping overloaded C constructors, Swig needs all of the parameters to be independently type-checked (see docs). This is good practice anyway... If you want to check a numpy array called %typecheck(SWIG_TYPECHECK_POINTER, fragment="NumPy_Fragments") double* freqs {
$1 = is_array($input);
} (all within You'll then have to define a custom typemap. You can do something like this:
Make sure you do this for all the You'll have to go through |
…per functions, etc.
…per functions, etc. to header
…per functions, etc.
…per functions, etc.
…til swig comes into play
As of now, the source code seems to be properly compiling (none of the constructors seem to have been broken). Now I'll need to update |
* Add TODOs for functions that need to be overloaded
* Wrapped add_* functions around add_*_uneven functions * Changed parameters of _add_* functions
…hat quantity df was.
As of now the package compiles all the way through, but I'm sure I'm getting SWIG wrong. The version of While attempting to run the
Which seems to tell me that the |
The python/swig UI regarding DFT stuff is a little convoluted...largely because of the load balancing requirements. But luckily I think you only need some minor changes to get your code working. First, let's remember that all the DFT functions using fluxes will call Lines 1820 to 1823 in 6c10e74
You can see that Lines 1939 to 1955 in 6c10e74
This is problematic for two reasons:
Feel free to check out PR #1095 for an example. I "overloaded" Looking forward to this feature! |
I think what you want is to apply the predefined numpy typemaps. If you have
|
python/simulation.py
Outdated
self.dft_objects.append(flux) | ||
return flux | ||
|
||
def _add_flux(self, fcen, df, nfreq, fluxes): | ||
def add_flux(self, fcen, df, nfreq, *fluxes): | ||
freqs = np.linspace(fcen - df / 2, fcen + df / 2, nfreq).tolist() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the tolist()
call since the typemaps are expecting a numpy array.
python/meep.i
Outdated
$1 = is_array($input); | ||
} | ||
|
||
%typemap(in, fragment="NumPy_Macros") double* freqs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This typemap isn't needed. It's covered by the %apply
below.
python/meep.i
Outdated
$1 = PyInteger_Check($input); | ||
} | ||
|
||
%typemap(in) int Nfreqs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This typemap isn't needed. It's covered by the %apply
below.
Removing |
src/dft_ldos.cpp
Outdated
Nomega = Nfreq; | ||
double om[Nomega]; | ||
for (int i = 0; i < Nfreq; i++) { om[i] = freqs[i] * 2 * pi; } | ||
omegas = om; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work. om
will no longer exist once this scope exits. You need to allocate on the heap with e.g. new
src/dft_ldos.cpp
Outdated
domega = 0; | ||
Nomega = 1; | ||
// TODO: overload dft_ldos constructor | ||
dft_ldos::dft_ldos(double *freqs, int Nfreq) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the object makes a copy of freqs
, then this should be declared as const double *freqs
.
src/dft.cpp
Outdated
bool use_centered_grid, int vc) { | ||
if (Nfreq < 1) abort("Nfreq must be at least 1"); | ||
double dfreq = (freq_max - freq_min) / (Nfreq - 1); | ||
double freqs[Nfreq]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem: this does not persist.
src/meep.hpp
Outdated
int Nomega; | ||
double *omegas; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might want to use std::vector<double>
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also below
Before you worry about getting the Python interface to work, I would to get the C++ tests to work, e.g. |
In fact, let's separate the Python stuff into a separate PR. Just try to get the C++ plumbing in place in this PR. |
Let's also add a C++ test for the new plumbing in this PR. |
Note that this PR is no longer necessary as it has been replaced by #1154. |
Fixes #1070.In progress of changing the relevant DFT classes' properties so that they have an array of frequencies, notfreq_min
orfreq_max
. The existing constructors will be updated so that DFT objects can be defined withfreq_min
,freq_max
, andNfreq
, but new constructors will also be added that use onlyfreqs
andNfreq
.