3D visualization of the Cheetah accelerator segment
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import cheetah
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Define the accelerator segment
|
| 7 |
+
segment = cheetah.Segment(
|
| 8 |
+
elements=[
|
| 9 |
+
cheetah.Drift(length=torch.tensor(0.175)),
|
| 10 |
+
cheetah.Quadrupole(length=torch.tensor(0.122), name="AREAMQZM1"),
|
| 11 |
+
cheetah.Drift(length=torch.tensor(0.428)),
|
| 12 |
+
cheetah.Quadrupole(length=torch.tensor(0.122), name="AREAMQZM2"),
|
| 13 |
+
cheetah.Drift(length=torch.tensor(0.204)),
|
| 14 |
+
cheetah.VerticalCorrector(length=torch.tensor(0.02), name="AREAMCVM1"),
|
| 15 |
+
cheetah.Drift(length=torch.tensor(0.204)),
|
| 16 |
+
cheetah.Quadrupole(length=torch.tensor(0.122), name="AREAMQZM3"),
|
| 17 |
+
cheetah.Drift(length=torch.tensor(0.179)),
|
| 18 |
+
cheetah.HorizontalCorrector(length=torch.tensor(0.02), name="AREAMCHM1"),
|
| 19 |
+
cheetah.Drift(length=torch.tensor(0.45)),
|
| 20 |
+
cheetah.Screen(name="AREABSCR1"),
|
| 21 |
+
]
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Generate the mesh
|
| 25 |
+
mesh, _ = segment.to_mesh(
|
| 26 |
+
cuteness={cheetah.HorizontalCorrector: 2.0, cheetah.VerticalCorrector: 2.0}
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Export the mesh to a .glb file
|
| 30 |
+
output_file = "ares_mesh.glb"
|
| 31 |
+
mesh.export(file_obj=output_file, file_type="glb")
|
| 32 |
+
|
| 33 |
+
# Define the Gradio interface
|
| 34 |
+
def display_3d_model():
|
| 35 |
+
return output_file
|
| 36 |
+
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown("# 3D Visualization of Cheetah Accelerator Segment")
|
| 39 |
+
gr.Markdown("This app renders a 3D model of the accelerator segment defined using the Cheetah library.")
|
| 40 |
+
gr.File(file_types=[".glb"], label="3D Model", value=output_file)
|
| 41 |
+
gr.Model3D(value=output_file, label="3D Visualization")
|
| 42 |
+
|
| 43 |
+
# Launch the Gradio app
|
| 44 |
+
demo.launch()
|