harishaseebat92 commited on
Commit
d6700a9
·
1 Parent(s): 1065614

previews now stay minimal until the user commits to a mesh size, rename EM Scattering

Browse files
Placeholder_Images/AnsysEM.png ADDED
Placeholder_Images/AnsysFluids.png ADDED
app.py CHANGED
@@ -124,7 +124,7 @@ with SinglePageLayout(server) as layout:
124
  label=True,
125
  color="primary",
126
  text_color="white",
127
- children=["{{ current_page === 'EM' ? 'EM Scattering' : 'Quantum LBM' }}"],
128
  classes="mr-2",
129
  )
130
  vuetify3.VImg(
@@ -159,7 +159,7 @@ with SinglePageLayout(server) as layout:
159
  with vuetify3.VCol(cols=12, md=5, class_="d-flex"):
160
  with vuetify3.VCard(elevation=4, classes="pa-6 flex-grow-1"):
161
  vuetify3.VIcon("mdi-radar", size=52, color="primary", classes="mb-4")
162
- vuetify3.VCardTitle("EM Scattering", classes="text-h5 mb-2")
163
  vuetify3.VCardText(
164
  "Placeholder",
165
  classes="text-body-2 mb-6",
 
124
  label=True,
125
  color="primary",
126
  text_color="white",
127
+ children=["{{ current_page === 'EM' ? 'Electromagnetic Scattering' : 'Quantum LBM' }}"],
128
  classes="mr-2",
129
  )
130
  vuetify3.VImg(
 
159
  with vuetify3.VCol(cols=12, md=5, class_="d-flex"):
160
  with vuetify3.VCard(elevation=4, classes="pa-6 flex-grow-1"):
161
  vuetify3.VIcon("mdi-radar", size=52, color="primary", classes="mb-4")
162
+ vuetify3.VCardTitle("Electromagnetic Scattering", classes="text-h5 mb-2")
163
  vuetify3.VCardText(
164
  "Placeholder",
165
  classes="text-body-2 mb-6",
em_trame.py CHANGED
@@ -240,6 +240,8 @@ def _new_monitor_cfg(field: str = "Ez", points: str = "(8, 8)") -> dict:
240
  # --- Constants ---
241
  GRID_SIZES = ["16", "32", "64", "128", "256", "512"]
242
 
 
 
243
  # --- Plotting and Simulation Logic ---
244
 
245
  # New: Build a PyVista time series chart for QPU results (same look as simulator)
@@ -1656,7 +1658,14 @@ def _build_geometry_placeholder(message: str) -> go.Figure:
1656
  return fig
1657
 
1658
 
1659
- def _build_square_domain_plot(nx: int, title: str, hole_edges=None, *, show_edges: bool = True) -> go.Figure:
 
 
 
 
 
 
 
1660
  nx = max(int(nx), 3)
1661
  grid = np.linspace(0.0, 1.0, nx)
1662
  X, Y = np.meshgrid(grid, grid, indexing="xy")
@@ -1688,14 +1697,22 @@ def _build_square_domain_plot(nx: int, title: str, hole_edges=None, *, show_edge
1688
 
1689
  if show_edges:
1690
  base_z = -0.012
 
 
 
 
 
1691
  line_x, line_y, line_z = [], [], []
1692
- for val in grid:
1693
- line_x.extend([val, val, np.nan])
1694
- line_y.extend([grid[0], grid[-1], np.nan])
 
 
1695
  line_z.extend([base_z, base_z, np.nan])
1696
- for val in grid:
1697
- line_x.extend([grid[0], grid[-1], np.nan])
1698
- line_y.extend([val, val, np.nan])
 
1699
  line_z.extend([base_z, base_z, np.nan])
1700
  fig.add_trace(
1701
  go.Scatter3d(
@@ -1709,7 +1726,7 @@ def _build_square_domain_plot(nx: int, title: str, hole_edges=None, *, show_edge
1709
  )
1710
  )
1711
 
1712
- scale_ticks = [0.0, 0.25, 0.5, 0.75, 1.0]
1713
  tick_text = [f"{t:.2f}" for t in scale_ticks]
1714
  tick_plane = -0.02
1715
  fig.add_trace(
@@ -1840,18 +1857,26 @@ def _build_excitation_surface_plot(
1840
  base_z = -0.02
1841
 
1842
  if show_grid_lines:
 
 
1843
  if grid_line_resolution is not None and grid_line_resolution >= 2:
1844
- grid = np.linspace(x_min, x_max, int(grid_line_resolution))
 
1845
  else:
1846
- grid = x_vals
 
 
 
1847
  line_x, line_y, line_z = [], [], []
1848
- for val in grid:
1849
- line_x.extend([val, val, np.nan])
 
1850
  line_y.extend([y_min, y_max, np.nan])
1851
  line_z.extend([base_z, base_z, np.nan])
1852
- for val in grid:
 
1853
  line_x.extend([x_min, x_max, np.nan])
1854
- line_y.extend([val, val, np.nan])
1855
  line_z.extend([base_z, base_z, np.nan])
1856
 
1857
  fig.add_trace(
@@ -1866,16 +1891,17 @@ def _build_excitation_surface_plot(
1866
  )
1867
  )
1868
 
1869
- ticks = np.linspace(x_min, x_max, 5)
1870
- tick_labels = [f"{t:.2f}" for t in ticks]
1871
- x_offset = x_min - 0.03 * (x_max - x_min if x_max != x_min else 1.0)
1872
- y_offset = y_min - 0.03 * (y_max - y_min if y_max != y_min else 1.0)
 
1873
  tick_plane = base_z - 0.01
1874
  fig.add_trace(
1875
  go.Scatter3d(
1876
- x=ticks,
1877
- y=[y_offset] * len(ticks),
1878
- z=[tick_plane] * len(ticks),
1879
  mode="text",
1880
  text=tick_labels,
1881
  textfont=dict(color="#5F259F", size=12),
@@ -1883,15 +1909,13 @@ def _build_excitation_surface_plot(
1883
  hoverinfo="skip",
1884
  )
1885
  )
1886
- ticks_y = np.linspace(y_min, y_max, 5)
1887
- tick_labels_y = [f"{t:.2f}" for t in ticks_y]
1888
  fig.add_trace(
1889
  go.Scatter3d(
1890
- x=[x_offset] * len(ticks_y),
1891
- y=ticks_y,
1892
- z=[tick_plane] * len(ticks_y),
1893
  mode="text",
1894
- text=tick_labels_y,
1895
  textfont=dict(color="#5F259F", size=12),
1896
  showlegend=False,
1897
  hoverinfo="skip",
@@ -1947,8 +1971,9 @@ def update_geometry_preview():
1947
  return
1948
  plotter.clear()
1949
  current_mesh = None
 
1950
  nx = int(state.nx) if state.nx is not None else 32
1951
- fig = _build_square_domain_plot(nx, "Square Domain")
1952
  _push_geometry_plot(fig)
1953
 
1954
 
@@ -1960,6 +1985,7 @@ def update_geometry_hole_preview():
1960
  return
1961
  plotter.clear()
1962
  current_mesh = None
 
1963
  nx = int(state.nx) if state.nx is not None else 32
1964
 
1965
  try:
@@ -1971,7 +1997,7 @@ def update_geometry_hole_preview():
1971
 
1972
  mode_snap = bool(state.hole_snap)
1973
  edges = _compute_hole_edges(nx, cx, cy, a, snap=mode_snap)
1974
- fig = _build_square_domain_plot(nx, "Square Metallic Body", edges)
1975
  _push_geometry_plot(fig)
1976
 
1977
  # Helper: map normalized [0,1] to nearest node index on an nx×ny grid
@@ -2119,10 +2145,10 @@ def update_initial_state_preview():
2119
  grid_n = slider_n if slider_n is not None else preview_n
2120
  if slider_n is None:
2121
  show_grid_lines = True
2122
- grid_line_resolution = 16
2123
  else:
2124
- show_grid_lines = slider_n <= 128
2125
- grid_line_resolution = min(slider_n, 128)
2126
  grid_n = max(grid_n, 8)
2127
  if state.dist_type == "Delta":
2128
  ix, iy = _nearest_node_index(float(state.impulse_x), float(state.impulse_y), grid_n)
 
240
  # --- Constants ---
241
  GRID_SIZES = ["16", "32", "64", "128", "256", "512"]
242
 
243
+ DEFAULT_AXIS_TICKS = (0.0, 0.25, 0.5, 0.75, 1.0)
244
+
245
  # --- Plotting and Simulation Logic ---
246
 
247
  # New: Build a PyVista time series chart for QPU results (same look as simulator)
 
1658
  return fig
1659
 
1660
 
1661
+ def _build_square_domain_plot(
1662
+ nx: int,
1663
+ title: str,
1664
+ hole_edges=None,
1665
+ *,
1666
+ show_edges: bool = True,
1667
+ dense_grid: bool = False,
1668
+ ) -> go.Figure:
1669
  nx = max(int(nx), 3)
1670
  grid = np.linspace(0.0, 1.0, nx)
1671
  X, Y = np.meshgrid(grid, grid, indexing="xy")
 
1697
 
1698
  if show_edges:
1699
  base_z = -0.012
1700
+ grid_vals = (
1701
+ np.linspace(0.0, 1.0, max(int(nx), 2))
1702
+ if dense_grid
1703
+ else np.asarray(DEFAULT_AXIS_TICKS)
1704
+ )
1705
  line_x, line_y, line_z = [], [], []
1706
+ x_min_val, x_max_val = float(grid[0]), float(grid[-1])
1707
+ for val in grid_vals:
1708
+ val_f = float(val)
1709
+ line_x.extend([val_f, val_f, np.nan])
1710
+ line_y.extend([x_min_val, x_max_val, np.nan])
1711
  line_z.extend([base_z, base_z, np.nan])
1712
+ for val in grid_vals:
1713
+ val_f = float(val)
1714
+ line_x.extend([x_min_val, x_max_val, np.nan])
1715
+ line_y.extend([val_f, val_f, np.nan])
1716
  line_z.extend([base_z, base_z, np.nan])
1717
  fig.add_trace(
1718
  go.Scatter3d(
 
1726
  )
1727
  )
1728
 
1729
+ scale_ticks = list(DEFAULT_AXIS_TICKS)
1730
  tick_text = [f"{t:.2f}" for t in scale_ticks]
1731
  tick_plane = -0.02
1732
  fig.add_trace(
 
1857
  base_z = -0.02
1858
 
1859
  if show_grid_lines:
1860
+ span_x = x_max - x_min if x_max != x_min else 1.0
1861
+ span_y = y_max - y_min if y_max != y_min else 1.0
1862
  if grid_line_resolution is not None and grid_line_resolution >= 2:
1863
+ res = int(grid_line_resolution)
1864
+ norm_vals = np.linspace(0.0, 1.0, res)
1865
  else:
1866
+ norm_vals = np.asarray(DEFAULT_AXIS_TICKS)
1867
+ x_grid_vals = x_min + span_x * norm_vals
1868
+ y_grid_vals = y_min + span_y * norm_vals
1869
+
1870
  line_x, line_y, line_z = [], [], []
1871
+ for val in x_grid_vals:
1872
+ val_f = float(val)
1873
+ line_x.extend([val_f, val_f, np.nan])
1874
  line_y.extend([y_min, y_max, np.nan])
1875
  line_z.extend([base_z, base_z, np.nan])
1876
+ for val in y_grid_vals:
1877
+ val_f = float(val)
1878
  line_x.extend([x_min, x_max, np.nan])
1879
+ line_y.extend([val_f, val_f, np.nan])
1880
  line_z.extend([base_z, base_z, np.nan])
1881
 
1882
  fig.add_trace(
 
1891
  )
1892
  )
1893
 
1894
+ tick_positions_x = x_min + span_x * np.asarray(DEFAULT_AXIS_TICKS)
1895
+ tick_positions_y = y_min + span_y * np.asarray(DEFAULT_AXIS_TICKS)
1896
+ tick_labels = [f"{t:.2f}" for t in DEFAULT_AXIS_TICKS]
1897
+ x_offset = x_min - 0.03 * span_x
1898
+ y_offset = y_min - 0.03 * span_y
1899
  tick_plane = base_z - 0.01
1900
  fig.add_trace(
1901
  go.Scatter3d(
1902
+ x=tick_positions_x,
1903
+ y=[y_offset] * len(tick_positions_x),
1904
+ z=[tick_plane] * len(tick_positions_x),
1905
  mode="text",
1906
  text=tick_labels,
1907
  textfont=dict(color="#5F259F", size=12),
 
1909
  hoverinfo="skip",
1910
  )
1911
  )
 
 
1912
  fig.add_trace(
1913
  go.Scatter3d(
1914
+ x=[x_offset] * len(tick_positions_y),
1915
+ y=tick_positions_y,
1916
+ z=[tick_plane] * len(tick_positions_y),
1917
  mode="text",
1918
+ text=tick_labels,
1919
  textfont=dict(color="#5F259F", size=12),
1920
  showlegend=False,
1921
  hoverinfo="skip",
 
1971
  return
1972
  plotter.clear()
1973
  current_mesh = None
1974
+ dense_grid = state.nx is not None
1975
  nx = int(state.nx) if state.nx is not None else 32
1976
+ fig = _build_square_domain_plot(nx, "Square Domain", dense_grid=dense_grid)
1977
  _push_geometry_plot(fig)
1978
 
1979
 
 
1985
  return
1986
  plotter.clear()
1987
  current_mesh = None
1988
+ dense_grid = state.nx is not None
1989
  nx = int(state.nx) if state.nx is not None else 32
1990
 
1991
  try:
 
1997
 
1998
  mode_snap = bool(state.hole_snap)
1999
  edges = _compute_hole_edges(nx, cx, cy, a, snap=mode_snap)
2000
+ fig = _build_square_domain_plot(nx, "Square Metallic Body", edges, dense_grid=dense_grid)
2001
  _push_geometry_plot(fig)
2002
 
2003
  # Helper: map normalized [0,1] to nearest node index on an nx×ny grid
 
2145
  grid_n = slider_n if slider_n is not None else preview_n
2146
  if slider_n is None:
2147
  show_grid_lines = True
2148
+ grid_line_resolution = None
2149
  else:
2150
+ show_grid_lines = True
2151
+ grid_line_resolution = max(slider_n, 2)
2152
  grid_n = max(grid_n, 8)
2153
  if state.dist_type == "Delta":
2154
  ix, iy = _nearest_node_index(float(state.impulse_x), float(state.impulse_y), grid_n)