Creating Models from Primitives¶
cavsim3d provides built-in parametric primitives for common waveguide and cavity shapes. These are useful for quick prototyping, benchmarking, and validation against analytical solutions.
Available Primitives¶
| Primitive | Class | Key Parameters |
|---|---|---|
| Rectangular Waveguide | RectangularWaveguide |
a (width), L (length), b (height) |
| Circular Waveguide | CircularWaveguide |
radius, length |
| Box Cavity | Box |
dimensions, port_faces |
1. Rectangular Waveguide¶
A rectangular waveguide with width $a$, height $b$ (defaults to $a/2$), and length $L$. Ports are automatically assigned at each end.
In [ ]:
Copied!
from cavsim3d.geometry.primitives import RectangularWaveguide
# Create a rectangular waveguide: 100mm wide, 200mm long
rwg = RectangularWaveguide(a=0.1, L=0.2)
rwg.print_info()
rwg.show('geometry')
from cavsim3d.geometry.primitives import RectangularWaveguide
# Create a rectangular waveguide: 100mm wide, 200mm long
rwg = RectangularWaveguide(a=0.1, L=0.2)
rwg.print_info()
rwg.show('geometry')
In [ ]:
Copied!
# Generate mesh and visualise
rwg.generate_mesh(maxh=0.02)
rwg.show('mesh')
# Generate mesh and visualise
rwg.generate_mesh(maxh=0.02)
rwg.show('mesh')
2. Circular Waveguide¶
A circular waveguide defined by its radius and length.
In [ ]:
Copied!
from cavsim3d.geometry.primitives import CircularWaveguide
# Create a circular waveguide: 50mm radius, 200mm long
cwg = CircularWaveguide(radius=0.05, length=0.2)
cwg.print_info()
cwg.show('geometry')
from cavsim3d.geometry.primitives import CircularWaveguide
# Create a circular waveguide: 50mm radius, 200mm long
cwg = CircularWaveguide(radius=0.05, length=0.2)
cwg.print_info()
cwg.show('geometry')
In [ ]:
Copied!
cwg.generate_mesh(maxh=0.02)
cwg.show('mesh')
cwg.generate_mesh(maxh=0.02)
cwg.show('mesh')
3. Box Cavity¶
A general box-shaped cavity where you can specify which faces serve as ports.
In [ ]:
Copied!
from cavsim3d.geometry.primitives import Box
# Create a box cavity: 100mm x 50mm x 200mm with ports on z-faces
box = Box(dimensions=(0.1, 0.05, 0.2), port_faces=('Min(Z)', 'Max(Z)'))
box.print_info()
box.show('geometry')
from cavsim3d.geometry.primitives import Box
# Create a box cavity: 100mm x 50mm x 200mm with ports on z-faces
box = Box(dimensions=(0.1, 0.05, 0.2), port_faces=('Min(Z)', 'Max(Z)'))
box.print_info()
box.show('geometry')
In [ ]:
Copied!
box.generate_mesh(maxh=0.02)
box.show('mesh')
box.generate_mesh(maxh=0.02)
box.show('mesh')
4. Building an Assembly from Primitives¶
Primitives can be combined into assemblies for multi-component analysis.
In [ ]:
Copied!
from cavsim3d.core.em_project import EMProject
proj = EMProject(name='primitive_assembly', base_dir='./simulations', new=True)
assembly = proj.create_assembly(main_axis='Z')
# Build an assembly from two rectangular waveguide sections
rwg1 = RectangularWaveguide(a=0.1, L=0.2)
rwg2 = RectangularWaveguide(a=0.1, L=0.2)
assembly.add("section1", rwg1)
assembly.add("section2", rwg2, after="section1")
assembly.build()
assembly.generate_mesh(maxh=0.02)
assembly.show('geometry')
from cavsim3d.core.em_project import EMProject
proj = EMProject(name='primitive_assembly', base_dir='./simulations', new=True)
assembly = proj.create_assembly(main_axis='Z')
# Build an assembly from two rectangular waveguide sections
rwg1 = RectangularWaveguide(a=0.1, L=0.2)
rwg2 = RectangularWaveguide(a=0.1, L=0.2)
assembly.add("section1", rwg1)
assembly.add("section2", rwg2, after="section1")
assembly.build()
assembly.generate_mesh(maxh=0.02)
assembly.show('geometry')
Summary¶
In this tutorial we:
- Created rectangular and circular waveguides from parametric primitives
- Created a box cavity with custom port faces
- Visualised geometry and meshes for each primitive
- Combined primitives into an assembly
Next: See Creating Geometry from the Project Object for a streamlined workflow.