2024-03-10 11:56:37 +01:00
|
|
|
import typing as typ
|
2024-02-14 12:33:40 +01:00
|
|
|
import tidy3d as td
|
|
|
|
import sympy as sp
|
|
|
|
import sympy.physics.units as spu
|
|
|
|
|
2024-03-10 11:56:37 +01:00
|
|
|
import bpy
|
|
|
|
|
|
|
|
from ... import contracts as ct
|
2024-02-19 14:28:35 +01:00
|
|
|
from ... import sockets
|
|
|
|
from .. import base
|
2024-02-14 12:33:40 +01:00
|
|
|
|
2024-03-10 11:56:37 +01:00
|
|
|
class PointDipoleSourceNode(base.MaxwellSimNode):
|
|
|
|
node_type = ct.NodeType.PointDipoleSource
|
2024-02-14 12:33:40 +01:00
|
|
|
bl_label = "Point Dipole Source"
|
|
|
|
|
|
|
|
####################
|
|
|
|
# - Sockets
|
|
|
|
####################
|
|
|
|
input_sockets = {
|
2024-03-10 11:56:37 +01:00
|
|
|
"Temporal Shape": sockets.MaxwellTemporalShapeSocketDef(),
|
|
|
|
"Center": sockets.PhysicalPoint3DSocketDef(),
|
|
|
|
"Interpolate": sockets.BoolSocketDef(
|
2024-02-26 16:16:06 +01:00
|
|
|
default_value=True,
|
|
|
|
),
|
2024-02-14 12:33:40 +01:00
|
|
|
}
|
|
|
|
output_sockets = {
|
2024-03-10 11:56:37 +01:00
|
|
|
"Source": sockets.MaxwellSourceSocketDef(),
|
2024-02-14 12:33:40 +01:00
|
|
|
}
|
|
|
|
|
2024-03-10 11:56:37 +01:00
|
|
|
####################
|
|
|
|
# - Properties
|
|
|
|
####################
|
|
|
|
pol_axis: bpy.props.EnumProperty(
|
|
|
|
name="Polarization Axis",
|
|
|
|
description="Polarization Axis",
|
|
|
|
items=[
|
|
|
|
("EX", "Ex", "Electric field in x-dir"),
|
|
|
|
("EY", "Ey", "Electric field in y-dir"),
|
|
|
|
("EZ", "Ez", "Electric field in z-dir"),
|
|
|
|
],
|
|
|
|
default="EX",
|
|
|
|
update=(lambda self, context: self.sync_prop("pol_axis")),
|
|
|
|
)
|
|
|
|
|
|
|
|
####################
|
|
|
|
# - UI
|
|
|
|
####################
|
|
|
|
def draw_props(self, context, layout):
|
|
|
|
layout.prop(self, "pol_axis", text="Pol Axis")
|
|
|
|
|
2024-02-14 12:33:40 +01:00
|
|
|
####################
|
|
|
|
# - Output Socket Computation
|
|
|
|
####################
|
2024-03-10 11:56:37 +01:00
|
|
|
@base.computes_output_socket(
|
|
|
|
"Source",
|
|
|
|
input_sockets={"Temporal Shape", "Center", "Interpolate"},
|
|
|
|
props={"pol_axis"},
|
|
|
|
)
|
|
|
|
def compute_source(self, input_sockets: dict[str, typ.Any], props: dict[str, typ.Any]) -> td.PointDipole:
|
|
|
|
pol_axis = {
|
|
|
|
"EX": "Ex",
|
|
|
|
"EY": "Ey",
|
|
|
|
"EZ": "Ez",
|
|
|
|
}[props["pol_axis"]]
|
|
|
|
|
|
|
|
temporal_shape = input_sockets["Temporal Shape"]
|
|
|
|
_center = input_sockets["Center"]
|
|
|
|
interpolate = input_sockets["Interpolate"]
|
2024-02-14 12:33:40 +01:00
|
|
|
|
2024-02-26 16:16:06 +01:00
|
|
|
center = tuple(spu.convert_to(_center, spu.um) / spu.um)
|
2024-02-14 12:33:40 +01:00
|
|
|
|
2024-03-10 11:56:37 +01:00
|
|
|
_res = td.PointDipole(
|
2024-02-14 12:33:40 +01:00
|
|
|
center=center,
|
2024-02-19 18:36:16 +01:00
|
|
|
source_time=temporal_shape,
|
2024-02-26 16:16:06 +01:00
|
|
|
interpolate=interpolate,
|
2024-03-10 11:56:37 +01:00
|
|
|
polarization=pol_axis,
|
2024-02-14 12:33:40 +01:00
|
|
|
)
|
2024-03-10 11:56:37 +01:00
|
|
|
return _res
|
2024-02-14 12:33:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
####################
|
|
|
|
# - Blender Registration
|
|
|
|
####################
|
|
|
|
BL_REGISTER = [
|
|
|
|
PointDipoleSourceNode,
|
|
|
|
]
|
|
|
|
BL_NODES = {
|
2024-03-10 11:56:37 +01:00
|
|
|
ct.NodeType.PointDipoleSource: (
|
|
|
|
ct.NodeCategory.MAXWELLSIM_SOURCES
|
2024-02-14 12:33:40 +01:00
|
|
|
)
|
|
|
|
}
|