Skip to content

Commit

Permalink
Fix adjoint gradient with conductivities (NanoComp#1830)
Browse files Browse the repository at this point in the history
* damp_fix

* increase run time

Co-authored-by: Mo Chen <[email protected]>
  • Loading branch information
2 people authored and Mo Chen committed Feb 22, 2022
1 parent 1266614 commit 6114f1e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions python/tests/test_adjoint_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,19 @@ def J(mode_mon):
sim.reset_meep()
return f, dJ_du

opt = mpa.OptimizationProblem(
simulation=sim,
objective_functions=J,
objective_arguments=obj_list,
design_regions=[matgrid_region],
frequencies=frequencies,
minimum_run_time=150)

f, dJ_du = opt([design_params])

sim.reset_meep()
return f, dJ_du

def mapping(x,filter_radius,eta,beta):
filtered_field = mpa.conic_filter(x,
filter_radius,
Expand Down
11 changes: 10 additions & 1 deletion src/meepgeom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,7 @@ std::complex<double> get_material_gradient(

for (int i=0;i<3;i++) dA_du[i] = (row_1[i] - row_2[i])/(2*du);
return dA_du[dir_idx] * fields_f * cond_cmp(forward_c,r,freq,geps);
}
}
}

/* A brute force approach to calculating Aᵤ using finite differences.
Expand Down Expand Up @@ -2933,10 +2933,19 @@ void material_grids_addgradient(double *v, size_t ng, std::complex<meep::realnum
size_t idx_fields = IVEC_LOOP_COUNTER;
meep::ivec ip = gv.iloc(adjoint_c,idx);
meep::vec p = gv.loc(adjoint_c,idx);
<<<<<<< HEAD
std::complex<double> adj = GET_FIELDS(fields_a, ci_adjoint, f_i, idx_fields);
material_type md;
geps->get_material_pt(md, p);
if (!md->trivial) adj *= cond_cmp(adjoint_c,p,frequencies[f_i], geps);
=======
std::complex<double> adj = GET_FIELDS(fields_a,ci_adjoint,f_i,idx_fields);

material_type md;
geps->get_material_pt(md, p);
if (!md->trivial) adj *= cond_cmp(adjoint_c,p,frequencies[f_i], geps);

>>>>>>> Fix adjoint gradient with conductivities (#1830)
double cyl_scale;
int ci_forward = 0;
FOR_MY_COMPONENTS(forward_c) {
Expand Down

0 comments on commit 6114f1e

Please sign in to comment.