diff --git a/docs/src/tutorial_optim_angle.md b/docs/src/tutorial_optim_angle.md index ae89656..f49c862 100644 --- a/docs/src/tutorial_optim_angle.md +++ b/docs/src/tutorial_optim_angle.md @@ -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, diff --git a/docs/src/tutorial_optim_radius.md b/docs/src/tutorial_optim_radius.md index 93c2978..d9caab5 100644 --- a/docs/src/tutorial_optim_radius.md +++ b/docs/src/tutorial_optim_radius.md @@ -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) diff --git a/src/optimize_phis.jl b/src/optimize_phis.jl index ed20044..2122aa3 100644 --- a/src/optimize_phis.jl +++ b/src/optimize_phis.jl @@ -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) diff --git a/src/optimize_rs.jl b/src/optimize_rs.jl index 83cf2c0..655155b 100644 --- a/src/optimize_rs.jl +++ b/src/optimize_rs.jl @@ -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 @@ -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, diff --git a/src/visualization.jl b/src/visualization.jl index 4f41b74..05477ac 100644 --- a/src/visualization.jl +++ b/src/visualization.jl @@ -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 diff --git a/test/optimize_radius_test.jl b/test/optimize_radius_test.jl index 4970b3f..830ea80 100644 --- a/test/optimize_radius_test.jl +++ b/test/optimize_radius_test.jl @@ -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) @@ -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,