diff --git a/python/tests/test_adjoint_solver.py b/python/tests/test_adjoint_solver.py index 8d42a4d1c..47520ea47 100644 --- a/python/tests/test_adjoint_solver.py +++ b/python/tests/test_adjoint_solver.py @@ -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, diff --git a/src/meepgeom.cpp b/src/meepgeom.cpp index 8d5b262f6..39813f409 100644 --- a/src/meepgeom.cpp +++ b/src/meepgeom.cpp @@ -2714,7 +2714,7 @@ std::complex 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. @@ -2933,10 +2933,19 @@ void material_grids_addgradient(double *v, size_t ng, std::complex 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 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) {