-
Notifications
You must be signed in to change notification settings - Fork 0
/
appwdgt.py
141 lines (105 loc) · 3.76 KB
/
appwdgt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
import ipywidgets as widgets
from ipywidgets import HBox, VBox, Layout, Box
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from IPython.display import display, clear_output
#### ----- fem widgets
fem_header = widgets.HTML(value="<h4>Simulation parameters</h4>")
wl_box = widgets.FloatText(value=1.0, description="Wavelengh:")
pola_dropdown = widgets.Dropdown(
options=["TE", "TM"], value="TE", description="Polarization:", disabled=False
)
run_button = widgets.Button(description="Run", icon="fa-play", button_style="danger")
angle_slider = widgets.FloatSlider(
value=0, min=0, max=360.0, step=1, description="Angle:", readout_format=".1f"
)
mesh_slider = widgets.IntSlider(
value=5, min=1, max=10, step=1, description="Mesh level:"
)
hx_box = widgets.FloatText(value=4.0, step=0.01, description="Design width:")
hy_box = widgets.FloatText(value=1.0, step=0.01, description="Design length:")
target_x_box = widgets.FloatText(value=0, step=0.01, description="Target $x$:")
target_y_box = widgets.FloatText(value=-1.1, step=0.01, description="Target $y$:")
epsmin_re_box = widgets.FloatText(value=1, step=0.01, description="Re $\epsilon_1$:")
epsmin_im_box = widgets.FloatText(value=0, step=0.01, description="Im $\epsilon_1$:")
epsmax_re_box = widgets.FloatText(value=6, step=0.01, description="Re $\epsilon_2$:")
epsmax_im_box = widgets.FloatText(value=0, step=0.01, description="Im $\epsilon_2$:")
#### ----- optim widgets
opt_header = widgets.HTML(value="<h4>Optimization parameters</h4>")
maxeval_slider = widgets.IntSlider(
value=20, min=10, max=50, step=1, description="Max iter:"
)
Nitmax_slider = widgets.IntSlider(
value=7, min=1, max=7, step=1, description="Max restart:"
)
rfilt_box = widgets.FloatText(value=0.05, step=0.001, description="Filter radius:")
starting_dropdown = widgets.Dropdown(
options=["constant", "random"], value="constant", description="Init type:"
)
p0_slider = widgets.FloatSlider(
value=0.5, min=0, max=1, step=0.01, description="Init density:"
)
#### -----
sep = widgets.HTML(value="<h4></h4>")
fem_par = params = VBox(
children=[
fem_header,
wl_box,
pola_dropdown,
angle_slider,
mesh_slider,
hx_box,
hy_box,
target_x_box,
target_y_box,
epsmin_re_box,
epsmin_im_box,
epsmax_re_box,
epsmax_im_box,
## -------
opt_header,
maxeval_slider,
Nitmax_slider,
rfilt_box,
starting_dropdown,
p0_slider,
## -------
sep,
run_button,
]
)
conv_plt = go.FigureWidget()
conv_plt.add_scatter(fill="tozeroy")
s = conv_plt.data[0]
theme = "plotly_white"
# theme="none"
s.marker.color = "firebrick"
# dict(color='firebrick', width=4)
conv_plt.layout.template = theme
conv_plt.layout.title = "Convergence"
conv_plt.layout.xaxis.title = "iterations"
conv_plt.layout.yaxis.title = "objective"
# conv_plt = widgets.Output(layout=Layout(height='300px', width = '400px'))
# eps_map = widgets.Output()
eps_map = go.FigureWidget()
eps_map.add_heatmap(colorscale="amp")
eps_map.layout = dict(
plot_bgcolor="rgba(0, 0, 0, 0)",
# paper_bgcolor= "rgba(0, 0, 0, 0)",
title="Permittivity",
yaxis=dict(scaleanchor="x", scaleratio=1),
)
eps_map.layout.template = theme
field_map = go.FigureWidget()
field_map.add_heatmap(colorscale="Geyser", zsmooth="best")
field_map.layout = dict(
plot_bgcolor="rgba(0, 0, 0, 0)",
# paper_bgcolor= "rgba(0, 0, 0, 0)",
title="Field",
yaxis=dict(scaleanchor="x", scaleratio=1),
)
field_map.layout.template = theme
design = go.layout.Shape(type="rect", x0=0, y0=0, x1=1, y1=1, line=dict(color="white"))
field_map.add_shape(design)
plots = VBox(children=[conv_plt, eps_map, field_map])