Skip to content

Commit 7502781

Browse files
committed
run checks to make sure different apis match
1 parent f32ed89 commit 7502781

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

examples/julia/ssp2_example.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using SSP: Kernel, Pad, Convolve, Project
33
using .Kernel: conickernel
44
using .Pad: FillPadding, BoundaryPadding, Inner, PaddingProblem, DefaultPaddingAlgorithm
55
using .Convolve: DiscreteConvolutionProblem, FFTConvolution
6-
using .Project: ProjectionProblem, SSP2
6+
using .Project: ProjectionProblem, SSP1_linear, SSP1, SSP2
77

88
using Random
99
using CairoMakie
@@ -29,8 +29,8 @@ kernel = conickernel(grid, radius)
2929

3030
padprob = PaddingProblem(;
3131
data = design_vars,
32-
# boundary = BoundaryPadding(size(kernel) .- 1, size(kernel) .- 1),
33-
boundary = FillPadding(1.0, size(kernel) .- 1, size(kernel) .- 1),
32+
boundary = BoundaryPadding(size(kernel) .- 1, size(kernel) .- 1),
33+
# boundary = FillPadding(1.0, size(kernel) .- 1, size(kernel) .- 1),
3434
)
3535
padalg = DefaultPaddingAlgorithm()
3636
padsolver = init(padprob, padalg)
@@ -57,8 +57,8 @@ filtered_design_vars = depadsol.value
5757

5858
# projection points need not be the same as design variable grid
5959
target_grid = (
60-
range(-1, 1, length=Nx * 2),
61-
range(-1, 1, length=Ny * 2),
60+
range(-1, 1, length=Nx * 1),
61+
range(-1, 1, length=Ny * 1),
6262
)
6363
target_points = vec(collect(Iterators.product(target_grid...)))
6464
projprob = ProjectionProblem(;
@@ -68,6 +68,8 @@ projprob = ProjectionProblem(;
6868
beta = Inf,
6969
eta = 0.5,
7070
)
71+
# projalg = SSP1_linear()
72+
# projalg = SSP1()
7173
projalg = SSP2()
7274
projsolver = init(projprob, projalg)
7375
projsol = solve!(projsolver)
@@ -87,15 +89,15 @@ let
8789
end
8890

8991
function fom(data, grid)
90-
return sum(abs2, data) * prod(step, grid)
92+
return sum(abs2, data) / length(data)
9193
end
9294
obj = fom(projected_design_vars, grid)
9395

9496
function adjoint_fom(adj_fom, data, grid)
9597
adjoint_fom!(similar(data), adj_fom, data, grid)
9698
end
9799
function adjoint_fom!(adj_data, adj_fom, data, grid)
98-
adj_data .= adj_fom .* 2 .* data .* prod(step, grid)
100+
adj_data .= (adj_fom / length(data)) .* 2 .* data
99101
return adj_data
100102
end
101103

@@ -189,7 +191,7 @@ let
189191
projsol = solve!(projsolver)
190192

191193
fig = Figure()
192-
ax1 = Axis(fig[1,1]; title = "Objective history", yscale=log10)
194+
ax1 = Axis(fig[1,1]; title = "Objective history", yscale=log10, limits = (nothing, (1e-16, 1e1)))
193195
h1 = scatterlines!(ax1, evaluation_history)
194196

195197
ax2 = Axis(fig[1,2]; title = "Final SSP2 design", aspect=DataAspect())

examples/julia/ssp_comparison.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ end
8888

8989
let
9090
fig = Figure()
91-
ax = Axis(fig[1,1]; title = "Optimization history", yscale=log10)
91+
ax = Axis(fig[1,1]; title = "Optimization history", yscale=log10, limits = (nothing, (1e-16, 1e1)))
9292
for (i, (ssp, evaluation_history)) in enumerate(zip(ssp_algs, ssp_optimization_histories))
9393
scatterlines!(ax, evaluation_history; label=string(nameof(ssp)))
9494
end

0 commit comments

Comments
 (0)