Skip to content

Commit

Permalink
Merge pull request #17 from bblankrot/dev
Browse files Browse the repository at this point in the history
Last PR before 0.0.2
  • Loading branch information
bblankrot committed Apr 16, 2018
2 parents b576f2d + d6056be commit 7f555f8
Show file tree
Hide file tree
Showing 18 changed files with 364 additions and 136 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ParticleScattering.jl
# ParticleScattering

[![Travis](https://travis-ci.org/bblankrot/ParticleScattering.jl.svg?branch=master)](https://travis-ci.org/bblankrot/ParticleScattering.jl)
[![AppVeyor](https://ci.appveyor.com/api/projects/status/p0p636vtrx95ch8m/branch/master?svg=true)](https://ci.appveyor.com/project/bblankrot/particlescattering-jl/branch/master)
Expand All @@ -11,11 +11,16 @@ those containing a large number of penetrable smooth
particles. Provides the ability to optimize over the
particle parameters for various design problems.

# Installation
### Installation

Currently, only Julia 0.6 is supported, and the package must be installed
manually. See directions at [the official Julia documentation](https://docs.julialang.org/en/stable/manual/packages/#Installing-Unregistered-Packages-1).
ParticleScattering can be installed using `Pkg.add`. Currently, only Julia 0.6 is supported.

```julia
Pkg.add("ParticleScattering")
using ParticleScattering
```

### Community

The easiest way to contribute is by opening issues! Of course, we'd be more than happy if you implement any fixes and send a PR. If you have any relevant scattering problems that would make good examples for the docs, feel free to open an issue for that as well.
The easiest way to contribute is by opening issues! Of course, we'd be more than happy if you implement any fixes and send a PR.
If you have any relevant scattering problems that would make good examples for the docs, feel free to open an issue for that as well.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Optim 0.14.0
PyPlot
DataFrames
CSV
PGFPlotsX
PGFPlotsX 0.2.1
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ makedocs(format = :html,
"tutorial_optim_radius.md"
],
"Choosing Minimal N and P" => "minimalNP.md",
"Adding New Shapes" => "new_shapes.md",
"API" => "api.md"
]
)
Expand Down
5 changes: 3 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ particles. Provides the ability to optimize over particle parameters for various

## Installation

Currently, only Julia 0.6 is supported. Once Julia is set up, ParticleScattering can be installed by running
ParticleScattering can be installed using `Pkg.add`. Currently, only Julia 0.6 is supported.

```julia
Pkg.clone(https://github.com/bblankrot/ParticleScattering.jl.git)
Pkg.add("ParticleScattering")
using ParticleScattering
```
which also installs the following dependencies:
Expand Down
17 changes: 17 additions & 0 deletions docs/src/new_shapes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Adding New Shapes

ParticleScattering includes functions for drawing squircles, rounded stars, and ellipses.
New shape functions can be added, provided they have the following structure:
```julia
function my_shape(args, N)
t = Float64[π*j/N for j = 0:(2*N-1)] # or t = 0:π/N:π*(2-1/N)
ft = [x y]
dft = [dx/dt dy/dt]
ShapeParams(t, ft, dft)
end
```

Where `t` is the parametrization variable, `ft[i,:] = [x(t[i]) y(t[i])]` contains the coordinates, and dft contains the derivative of `ft` with respect to `t`.
In particular, the quadrature used by ParticleScattering assumes `t`
are equidistantly distributed in ``[0, 2\pi)``, and that none of the points `ft`
lie on the origin.
44 changes: 22 additions & 22 deletions examples/sim0_min_NP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,16 @@ JLD.@load dirname(@__FILE__) * "/mindata_5_new.jld"
JLD.@load dirname(@__FILE__) * "/mindata_s_new.jld"

pgf.@pgf begin
N_plot5 = pgf.Plot(pgf.Coordinates(errN5,N5),
{blue, dashdotdotted, no_markers, thick},
label = "\$N_{\\mathrm{min}} \\, \\mathrm{(star)}\$")
P_plot5 = pgf.Plot(pgf.Coordinates(errN5,P5),
{"green!50!black", no_markers, thick},
label = "\$P_{\\mathrm{min}} \\, \\mathrm{(star)}\$")
N_plot = pgf.Plot(pgf.Coordinates(errNs,Ns),
{red, dotted, no_markers, thick},
label = "\$N_{\\mathrm{min}} \\, \\mathrm{(squircle)}\$")
P_plot = pgf.Plot(pgf.Coordinates(errNs,Ps),
{black, dashed, no_markers, thick},
label = "\$P_{\\mathrm{min}} \\, \\mathrm{(squircle)}\$")
ax = pgf.Axis([N_plot5, N_plot, P_plot5, P_plot],
{
N_plot5 = pgf.Plot({blue, dashdotdotted, no_markers, thick},
pgf.Coordinates(errN5,N5))
N_plot = pgf.Plot({red, dotted, no_markers, thick},
pgf.Coordinates(errNs,Ns))
P_plot5 = pgf.Plot({"green!50!black", no_markers, thick},
pgf.Coordinates(errN5,P5))
P_plot = pgf.Plot({black, dashed, no_markers, thick},
pgf.Coordinates(errNs,Ps))
ax = pgf.Axis(
{
xmin = 5e-10,
xmax = 1e-1,
xlabel = "\$\\Delta u\$",
Expand All @@ -144,17 +140,22 @@ pgf.@pgf begin
legend_pos = "north east",
legend_style = "font = \\footnotesize",
legend_cell_align = "left"
})
},
[N_plot5, N_plot, P_plot5, P_plot],
pgf.Legend(["\$N_{\\mathrm{min}} \\, \\mathrm{(star)}\$",
"\$N_{\\mathrm{min}} \\, \\mathrm{(squircle)}\$",
"\$P_{\\mathrm{min}} \\, \\mathrm{(star)}\$",
"\$P_{\\mathrm{min}} \\, \\mathrm{(squircle)}\$"]))

end
pgf.save(dirname(@__FILE__) * "/tikz/minNP.tex", ax ,include_preamble = false)

shape = myshapefun5(200)
pgf_shape = pgf.Coordinates([shape.ft[:,1];shape.ft[1,1]],
[shape.ft[:,2];shape.ft[1,2]])
pgf.@pgf begin
ax2 = pgf.Axis(pgf.Plot(pgf_shape, {thick, black, no_markers, fill = "black!20"}),
{ axis_equal,
ticks = "none"})
ax2 = pgf.Axis({axis_equal, ticks = "none"}, pgf.Plot({thick, black,
no_markers, fill = "black!20"}, pgf_shape))
Rd = shape.R
push!(ax2, "\\addplot [black, dashed, thick, domain=0:2*pi,samples=100]({$(shape.R)*cos(deg(x))},{$(shape.R)*sin(deg(x))});")
push!(ax2, "\\node at (axis cs: -0.28,-0.15) {\$D\$};")
Expand All @@ -169,10 +170,9 @@ shape = myshapefun_squircle(200)
pgf_shape = pgf.Coordinates([shape.ft[:,1];shape.ft[1,1]],
[shape.ft[:,2];shape.ft[1,2]])
pgf.@pgf begin
ax3 = pgf.Axis(pgf.Plot(pgf_shape, {thick, black, no_markers, fill = "black!20"}),
{ axis_equal,
ticks = "none"})
Rd = shape.R
ax3 = pgf.Axis({axis_equal, ticks = "none"}, pgf.Plot({thick, black,
no_markers, fill = "black!20", label="bla"}, pgf_shape))
Rd = shape.R
push!(ax3, "\\addplot [black, dashed, thick, domain=0:2*pi,samples=100]({$(shape.R)*cos(deg(x))},{$(shape.R)*sin(deg(x))});")
push!(ax3, "\\node at (axis cs: -0.28,-0.15) {\$D\$};")
push!(ax3, "\\node at (axis cs: 0.25,-0.25) {\$k_0\$};")
Expand Down
43 changes: 21 additions & 22 deletions examples/sim1_complexity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ for i=1:simlen-1
end
dt0 /= simlen


for is = 1:simlen, it = 1:trials
#compute shape variables
begin #setup
Expand Down Expand Up @@ -123,27 +122,27 @@ pgf.@pgf begin
ylabel = "\$ \\mathrm{Run time} \\ [\\mathrm{s}]\$",
xmode = "linear",
ymode = "log",
width = "\\figurewidth",
width = "10cm",
legend_pos = "north west",
legend_style = "font = \\footnotesize"})
push!(ax, pgf.Plot(pgf.Coordinates(M_vec, res_vec),
{blue, "only marks", mark = "*"};
label = "Elapsed time (solution)"))
temp2 = floor(log10(10^a_total))
temp1 = 10^a_total/10^temp2
push!(ax, pgf.Plot(pgf.Coordinates(M_vec, res_ana),
{blue, thick, no_markers};
label = @sprintf("\$%.1f \\cdot 10^{%d} \\cdot M^{%.2f}\$",
temp1, temp2, b_total)))
push!(ax, pgf.Plot(pgf.Coordinates(M_vec, mvp_vec),
{red, only_marks, mark = "triangle*", mark_options = {fill = "red"}};
label= "Elapsed time (MVP)"))
temp2 = floor(log10(10^a_mvp))
temp1 = 10^a_mvp/10^temp2
push!(ax, pgf.Plot(pgf.Coordinates(M_vec, mvp_ana),
{red, thick, dashed, no_markers};
label = @sprintf("\$%.1f \\cdot 10^{%d} \\cdot M^{%.2f}\$",
temp1, temp2, b_mvp)))
legend_style = "font = \\footnotesize",
legend_cell_align = "left"})
push!(ax, pgf.Plot({blue, "only marks", mark = "*"},
pgf.Coordinates(M_vec, res_vec)))
tmp_total = floor(log10(10^a_total))
push!(ax, pgf.Plot({blue, thick, no_markers},
pgf.Coordinates(M_vec, res_ana)))
push!(ax, pgf.Plot({red, only_marks, mark = "triangle*",
mark_options = {fill = "red"}},
pgf.Coordinates(M_vec, mvp_vec)))
tmp_mvp = floor(log10(10^a_mvp))
push!(ax, pgf.Plot({red, thick, dashed, no_markers},
pgf.Coordinates(M_vec, mvp_ana)))
push!(ax, pgf.Legend([
"Elapsed time (solution)",
@sprintf("\$%.1f \\cdot 10^{%d} \\cdot M^{%.2f}\$",
10^a_total/10^tmp_total, tmp_total, b_total),
"Elapsed time (MVP)",
@sprintf("\$%.1f \\cdot 10^{%d} \\cdot M^{%.2f}\$",
10^a_mvp/10^tmp_mvp, tmp_mvp, b_mvp)]))
end

pgf.save(dirname(@__FILE__) * "/sim1.tex", ax ,include_preamble = false)
43 changes: 23 additions & 20 deletions examples/sim2_LuneburgOptim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ sp1 = ScatteringProblem([CircleParams(rs_lnbrg[i]) for i in eachindex(rs_lnbrg)]
ids_lnbrg, centers, φs)
Ez1 = plot_near_field(k0, kin, P, sp1, θ_i, x_points = 150, y_points = 150,
opt = fmm_options, border = border)
plotNearField_pgf(filename1, k0, kin, P, sp1, θ_i; opt = fmm_options,
plot_near_field_pgf(filename1, k0, kin, P, sp1, θ_i; opt = fmm_options,
x_points = 201, y_points = 201, border = border)

sp2 = ScatteringProblem([CircleParams(rs_max[i]) for i in eachindex(rs_max)],
ids_max, centers, φs)
Ez2 = plot_near_field(k0, kin, P, sp2, θ_i, x_points = 150, y_points = 150,
opt = fmm_options, border = border)
plotNearField_pgf(filename2, k0, kin, P, sp2, θ_i; opt = fmm_options,
plot_near_field_pgf(filename2, k0, kin, P, sp2, θ_i; opt = fmm_options,
x_points = 201, y_points = 201, border = border)

sp3 = ScatteringProblem([CircleParams(rs0[i]) for i in eachindex(rs0)],
collect(1:length(rs0)), centers, φs)
Ez3 = plot_near_field(k0, kin, P, sp3, θ_i, x_points = 150, y_points = 150,
opt = fmm_options, border = border)
plotNearField_pgf(filename3, k0, kin, P, sp3, θ_i; opt = fmm_options,
plot_near_field_pgf(filename3, k0, kin, P, sp3, θ_i; opt = fmm_options,
x_points = 201, y_points = 201, border = border)

#plot convergence
Expand All @@ -81,23 +81,26 @@ JLD.@save output_dir * "/luneburg_optim.jld"

import PGFPlotsX; const pgf = PGFPlotsX
pgf.@pgf begin
fobj_plot = pgf.Plot(pgf.Coordinates(0:inner_iters-1, fobj),
{blue, thick, no_markers},
label = "\$f_{\\mathrm{obj}}\$")
gobj_plot = pgf.Plot(pgf.Coordinates(0:inner_iters-1, gobj),
{red, thick, dashed, no_markers},
label = "\$\\|\\mathbf{g}_{\\mathrm{obj}}\\|_{\\infty}\$")
fobj_outer = pgf.Plot(pgf.Coordinates((0:inner_iters-1)[rng], fobj[rng]),
{blue, only_marks, mark = "*", mark_options = {fill = "blue"}})
gobj_outer = pgf.Plot(pgf.Coordinates((0:inner_iters-1)[rng], gobj[rng]),
{red, only_marks, mark = "triangle*", mark_options = {fill = "red"}})
ax = pgf.Axis([fobj_plot;gobj_plot;fobj_outer;gobj_outer],
{
width = "\\figurewidth",
xlabel = "Iterations",
legend_pos = "north east",
legend_style = "font = \\footnotesize"
})
fobj_plot = pgf.Plot({blue, thick, no_markers},
pgf.Coordinates(0:inner_iters-1, fobj))
gobj_plot = pgf.Plot({red, thick, dashed, no_markers},
pgf.Coordinates(0:inner_iters-1, gobj))
fobj_outer = pgf.Plot({blue, only_marks, mark = "*",
mark_options = {fill = "blue"}},
pgf.Coordinates((0:inner_iters-1)[rng], fobj[rng]))
gobj_outer = pgf.Plot({red, only_marks, mark = "triangle*",
mark_options = {fill = "red"}},
pgf.Coordinates((0:inner_iters-1)[rng], gobj[rng]))
ax = pgf.Axis({ xmin = 0,
width = "6cm",
xlabel = "Iterations",
legend_pos = "north east",
legend_style = "font = \\footnotesize",
legend_cell_align = "left"},
fobj_plot, gobj_plot, fobj_outer, gobj_outer)
push!(ax, pgf.Legend(["\$f_{\\mathrm{obj}}\$";
"\$\\|\\mathbf{g}_{\\mathrm{obj}}\\|_{\\infty}\$"]))
ax
end
pgf.save(output_dir * "/opt_r_conv.tex", ax ,include_preamble = false)

Expand Down
37 changes: 17 additions & 20 deletions examples/sim3_AngleOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ plot_near_field(k0, kin, P, sp_before, θ_i,
x_points = 600, y_points = 200, border = plot_border);
colorbar()
clim([0;5])
plotNearField_pgf(output_dir * "/opt_phi_before.tex", k0, kin, P,
sp_before, θ_i; opt = fmm_options, x_points = 600, y_points = 200,
border = plot_border, downsample = 4)
plot_near_field_pgf(output_dir * "/opt_phi_before.tex", k0, kin, P,
sp_before, θ_i; opt = fmm_options, x_points = 150, y_points = 50,
border = plot_border, downsample = 10, include_preamble = true)

sp_after = ScatteringProblem(shapes, ids, centers, test_max.minimizer)
plot_near_field(k0, kin, P, sp_after, θ_i,
x_points = 600, y_points = 200, border = plot_border)
colorbar()
clim([0;5])
plotNearField_pgf(output_dir * "/opt_phi_after.tex", k0, kin, P,
sp_after, θ_i; opt = fmm_options, x_points = 600, y_points = 200,
border = plot_border, downsample = 4)
plot_near_field_pgf(output_dir * "/opt_phi_after.tex", k0, kin, P,
sp_after, θ_i; opt = fmm_options, x_points = 150, y_points = 50,
border = plot_border, downsample = 10, include_preamble = true)

inner_iters = length(test_max.trace)
fobj = -[test_max.trace[i].value for i=1:inner_iters]
Expand All @@ -95,20 +95,17 @@ figure()
plot(0:inner_iters-1, fobj)
plot(0:inner_iters-1, gobj)

import PGFPlotsX; const pgf = PGFPlotsX
pgf.@pgf begin
fobj_plot = pgf.Plot(pgf.Coordinates(0:inner_iters-1, fobj),
{blue, thick, no_markers},
label = "\$f_{\\mathrm{obj}}\$")
gobj_plot = pgf.Plot(pgf.Coordinates(0:inner_iters-1, gobj),
{red, thick, dashed, no_markers},
label = "\$\\|\\mathbf{g}_{\\mathrm{obj}}\\|\$")
ax = pgf.Axis([fobj_plot;gobj_plot],
{
width = "\\figurewidth",
xlabel = "Iterations",
legend_pos = "north east",
legend_style = "font = \\footnotesize"
})
fobj_plot = pgf.Plot({blue, thick, no_markers},
pgf.Coordinates(0:inner_iters-1, fobj))
gobj_plot = pgf.Plot({red, thick, dashed, no_markers},
pgf.Coordinates(0:inner_iters-1, gobj))
ax = pgf.Axis({ width = "6cm",
xlabel = "Iterations",
legend_pos = "north east",
legend_style = "font = \\footnotesize"},
fobj_plot, gobj_plot)
push!(ax, pgf.Legend(["\$f_{\\mathrm{obj}}\$";
"\$\\|\\mathbf{g}_{\\mathrm{obj}}\\|\$"]))
end
pgf.save(output_dir * "/opt_phi_conv.tex", ax ,include_preamble = false)
Binary file added paper/fig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions paper/paper.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@article{ar:blankrot2018,
author = {Boaz Blankrot and Clemens Heitzinger},
title = {Efficient computational design and optimization of dielectric metamaterial devices},
journal = {submitted for publication},
year = {2018}
}

@article{ar:optimjl,
doi = {10.21105/joss.00615},
url = {https://doi.org/10.21105/joss.00615},
year = {2018},
month = {apr},
publisher = {The Open Journal},
volume = {3},
number = {24},
pages = {615},
author = {Patrick K Mogensen and Asbj{\o}rn N Riseth},
title = {Optim: A mathematical optimization package for Julia},
journal = {Journal of Open Source Software}
}

@article{ar:alldielectric,
title={All-dielectric metamaterials},
author={Jahani, Saman and Jacob, Zubin},
journal={Nature Nanotechnology},
volume={11},
number={1},
pages={23--36},
year={2016},
publisher={Nature Research},
doi={10.1038/nnano.2015.304}
}
Loading

0 comments on commit 7f555f8

Please sign in to comment.