Skip to content

Commit

Permalink
fix factor in adjoint gradient from symmetry (#1527)
Browse files Browse the repository at this point in the history
* slight clean up meep.i

* symfix

* use ivec

Co-authored-by: Mo Chen <mochen@MacBook-Pro-2.local>
  • Loading branch information
mochen4 and Mo Chen authored Mar 11, 2021
1 parent d8ea59c commit fce7a45
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
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(ivec &) const;
bool is_primitive(const ivec &) const;

volume_list *reduce(const volume_list *gl) const;
Expand Down
2 changes: 2 additions & 0 deletions src/near2far.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ std::vector<struct sourcedata> dft_near2far::near_sourcedata(const vec &x_0, dou
sourcedata temp_struct = {component(f->c), idx_arr, f->fc->chunk_idx, amp_arr};

LOOP_OVER_IVECS(f->fc->gv, f->is, f->ie, idx) {
IVEC_LOOP_ILOC(f->fc->gv, ix0);
IVEC_LOOP_LOC(f->fc->gv, x0);
x0 = f->S.transform(x0, f->sn) + rshift;
vec xs(x0);
Expand Down Expand Up @@ -692,6 +693,7 @@ 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;
EH0 /= f->S.multiplicity(ix0);
temp_struct.amp_arr.push_back(EH0);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/vec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,15 @@ int symmetry::multiplicity() const {
return g;
}

int symmetry::multiplicity(ivec &x) const {
int m = multiplicity();
for (int n=1; n<m; ++n){
if (transform(x,n) == x)
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

0 comments on commit fce7a45

Please sign in to comment.