Skip to content

Commit

Permalink
Merge pull request #23 from bblankrot/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
bblankrot committed Sep 3, 2018
2 parents c03071a + 9db8d20 commit 565fc47
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/src/tutorial_optim_angle.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tutorial 3: Angle Optimization

In this tutorial, we build upon the [previous tutorial]@(ref tutorial2) by
In this tutorial, we build upon the [previous tutorial](@ref tutorial2) by
optimizing the rotation angles of the particles (`φs`) to maximize the field
intensity at a specific point.
Depending on the scattering problem, wavelengths, and incident field,
Expand Down
3 changes: 2 additions & 1 deletion docs/src/tutorial_optim_radius.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ structure, assert that this point will remain outside the particles regardless
of their size, and set the lower and upper bounds for each circle:

```julia
optim_options = Optim.Options(x_tol = 1e-6, iterations = 5,
optim_options = Optim.Options(x_tol = 1e-6, outer_x_tol = 1e-6,
iterations = 5, outer_iterations = 5,
store_trace = true, show_trace = true,
allow_f_increases = true)

Expand Down
2 changes: 1 addition & 1 deletion src/optimize_phis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function optimize_φ_g!(grad_stor, φs, shared_var, last_φs, α, H, points, P,
rotateMultipole!(v, φs[n], P)
v[:] += D.*shared_var.β[rng]

shared_var.∂β[:,n], ch = gmres!(shared_var.∂β[:,n], MVP,
shared_var.∂β[:,n], ch = gmres!(view(shared_var.∂β,:,n), MVP,
shared_var.rhs_grad, restart = Ns*(2*P+1),
tol = 10*opt.tol, log = true,
initially_zero = true)
Expand Down
16 changes: 5 additions & 11 deletions src/optimize_rs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,12 @@ function optimize_radius(rs0, r_min, r_max, points, ids, P, ui, k0, kin,
initial_rs)
end

outer_iterations = optimopts.iterations

if method == "LBFGS"
optimize(df, initial_rs, r_min, r_max, Fminbox{LBFGS}();
optimizer_o = optimopts, iterations = outer_iterations,
linesearch = LineSearches.BackTracking(), x_tol = optimopts.x_tol,
f_tol = optimopts.f_tol, g_tol = optimopts.g_tol)
optimize(df, r_min, r_max, initial_rs,
Fminbox(LBFGS(linesearch = LineSearches.BackTracking())), optimopts)
elseif method == "BFGS"
optimize(df, initial_rs, r_min, r_max, Fminbox{BFGS}();
optimizer_o = optimopts, iterations = outer_iterations,
linesearch = LineSearches.BackTracking(), x_tol = optimopts.x_tol,
f_tol = optimopts.f_tol, g_tol = optimopts.g_tol)
optimize(df, r_min, r_max, initial_rs,
Fminbox(BFGS(linesearch = LineSearches.BackTracking())), optimopts)
end
end

Expand Down Expand Up @@ -167,7 +161,7 @@ function optimize_radius_g!(grad_stor, rs, last_rs, shared_var, φs, α, H, poin
shared_var.rhs_grad[rng] = 0.0
end
end
shared_var.∂β[:,n], ch = gmres!(shared_var.∂β[:,n], MVP,
shared_var.∂β[:,n], ch = gmres!(view(shared_var.∂β,:,n), MVP,
shared_var.rhs_grad,
restart = Ns*(2*P+1) + 1,
maxiter = Ns*(2*P+1), tol = opt.tol,
Expand Down
5 changes: 2 additions & 3 deletions src/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,16 @@ function tagpoints(sp, points)
X[1] = points[ix,1] - centers[ic,1]
X[2] = points[ix,2] - centers[ic,2]
if hypot(X[1], X[2]) shapes[ids[ic]].R
if typeof(shapes[ids[ic]]) == ShapeParams
if isa(shapes[ids[ic]], ShapeParams)
if φs[ic] != 0.0 #rotate point backwards instead of shape forwards
Rot = cartesianrotation(-φs[ic])
X = Rot*X
end
tags[ix] = pInPolygon(X, shapes[ids[ic]].ft) ? ic : -ic
break #can't be in two shapes
else #CircleParams
tags[ix] = ic
break #can't be in two shapes
end
break #can't be in two shapes
end
end
end
Expand Down
9 changes: 5 additions & 4 deletions test/optimize_radius_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import Optim
φs = zeros(M)

fmm_options = FMMoptions(true, acc = 6, dx = 2a)
optim_options = Optim.Options(x_tol = 1e-6, iterations = 10,
store_trace = true, show_trace = false,
allow_f_increases = true)
optim_options = Optim.Options(x_tol = 1e-4, outer_x_tol = 1e-4,
iterations = 10, outer_iterations = 10,
store_trace = true, allow_f_increases = true)

points = [3a 0.0]
r_max = (0.4*a)*ones(J)
Expand All @@ -34,7 +34,8 @@ import Optim
rs = res.minimizer
@test res.x_converged

optim_options2 = Optim.Options(f_tol = 1e-7, iterations = 10,
optim_options2 = Optim.Options(f_tol = 1e-7, outer_f_tol = 1e-7,
iterations = 10, outer_iterations = 10,
store_trace = true, show_trace = false,
allow_f_increases = true)
res2 = optimize_radius(rs0, r_min, r_max, points, ids, P, ui, k0, kin,
Expand Down

0 comments on commit 565fc47

Please sign in to comment.