Skip to content
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

fix factor in adjoint gradient from symmetry #1527

Merged
merged 3 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions python/meep.i
Original file line number Diff line number Diff line change
Expand Up @@ -1523,10 +1523,6 @@ void _get_gradient(PyObject *grad, PyObject *fields_a, PyObject *fields_f, PyObj
memcpy(PyArray_DATA((PyArrayObject*) $result), &$1[0], vec_len * sizeof(double) * 2);
}

std::vector<struct meep::sourcedata> meep::dft_near2far::near_sourcedata(const meep::vec &x_0, double* farpt_list, size_t nfar_pts, std::complex<double>* dJ);

void meep::fields::add_srcdata(struct meep::sourcedata cur_data, meep::src_time *src, size_t n, std::complex<double>* amp_arr);

struct vector3 {
double x;
double y;
Expand Down
1 change: 1 addition & 0 deletions src/meep/vec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ class symmetry {
int transform(int, int n) const;
std::complex<double> phase_shift(int, int n) const;
int multiplicity() const;
int multiplicity(vec &) const;
bool is_primitive(const ivec &) const;

volume_list *reduce(const volume_list *gl) const;
Expand Down
3 changes: 2 additions & 1 deletion src/near2far.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,8 @@ std::vector<struct sourcedata> dft_near2far::near_sourcedata(const vec &x_0, dou
idx_dft++;
if (is_electric(temp_struct.near_fd_comp))
EH0 *= -1;
temp_struct.amp_arr.push_back(EH0);
EH0 /= f->S.multiplicity(x0);
temp_struct.amp_arr.push_back(EH0 / f->S.multiplicity(x0));
}
}
temp.push_back(temp_struct);
Expand Down
9 changes: 9 additions & 0 deletions src/vec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,15 @@ int symmetry::multiplicity() const {
return g;
}

int symmetry::multiplicity(vec &x) const {
int m = multiplicity();
for (int n=1; n<m; ++n){
if (transform(x,n) == x)
stevengj marked this conversation as resolved.
Show resolved Hide resolved
return n;
}
return m;
}

symmetry symmetry::operator+(const symmetry &b) const {
// The following optimization ignores identity when adding symmetries
// together. This is important because identity has an undefined
Expand Down