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 <mochen@Mos-MacBook-Pro.local>
  • Loading branch information
2 people authored and Mo Chen committed Feb 22, 2022
1 parent f1a5b90 commit 0a09fe1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions python/tests/test_adjoint_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,32 @@ def test_damping(self):
tol = 0.06 if mp.is_single_precision() else 0.03
self.assertClose(adj_scale,fd_grad,epsilon=tol)

def test_damping(self):
print("*** TESTING CONDUCTIVITIES ***")

for frequencies in [[1/1.58, fcen, 1/1.53]]:
## compute gradient using adjoint solver
adjsol_obj, adjsol_grad = adjoint_solver_damping(p, frequencies)

## compute unperturbed S12
S12_unperturbed = forward_simulation_damping(p, frequencies)

## compare objective results
print("S12 -- adjoint solver: {}, traditional simulation: {}".format(adjsol_obj,S12_unperturbed))
self.assertClose(adjsol_obj,S12_unperturbed,epsilon=1e-6)

## compute perturbed S12
S12_perturbed = forward_simulation_damping(p+dp, frequencies)

## compare gradients
if adjsol_grad.ndim < 2:
adjsol_grad = np.expand_dims(adjsol_grad,axis=1)
adj_scale = (dp[None,:]@adjsol_grad).flatten()
fd_grad = S12_perturbed-S12_unperturbed
print("Directional derivative -- adjoint solver: {}, FD: {}".format(adj_scale,fd_grad))
tol = 0.06 if mp.is_single_precision() else 0.03
self.assertClose(adj_scale,fd_grad,epsilon=tol)

def test_damping(self):
print("*** TESTING CONDUCTIVITIES ***")

Expand Down

0 comments on commit 0a09fe1

Please sign in to comment.