Skip to content

Commit

Permalink
separately delete forward dft chunk for adjoint optimization (#2251)
Browse files Browse the repository at this point in the history
* separately delete forward dft chunk

* fix

* swig fix

* dft_fields::delete_dft_chunks

* declaration

* remove()

* clean up

* Update python/adjoint/optimization_problem.py

* trailing whitespace

Co-authored-by: Mo Chen <mochen@Mos-MacBook-Pro.local>
Co-authored-by: Steven G. Johnson <stevenj@mit.edu>
  • Loading branch information
3 people authored Oct 14, 2022
1 parent 9ac05a0 commit 49aef42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 6 additions & 0 deletions python/adjoint/optimization_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ def calculate_gradient(self):
for ar in range(len(self.objective_functions))
]

for dri in range(self.num_design_regions):
for i in range(3):
# note that dft_fields::remove calls delete on its chunks, and the
# destructor ~dft_chunk automatically removes it from the fields object
self.forward_design_region_monitors[dri][i].remove()

# Cleanup list of lists
if len(self.gradient) == 1:
self.gradient = self.gradient[0] # only one objective function
Expand Down
1 change: 0 additions & 1 deletion src/meepgeom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2999,7 +2999,6 @@ void material_grids_addgradient(double *v, size_t ng, size_t nf,
for (int i = 0; i < 3; i++) {
for (int ii = 0; ii < adjoint_dft_chunks[i].size(); ii++) {
delete adjoint_dft_chunks[i][ii];
delete forward_dft_chunks[i][ii];
}
}

Expand Down

0 comments on commit 49aef42

Please sign in to comment.