diff --git a/src/blender_maxwell/info.py b/src/blender_maxwell/info.py index de66fbb..7b2762c 100644 --- a/src/blender_maxwell/info.py +++ b/src/blender_maxwell/info.py @@ -28,6 +28,13 @@ DEFAULT_PATH_DEPS = PATH_ADDON_ROOT / '.addon_dependencies' ## requirements.lock is written when packing the .zip. ## By default, the addon pydeps are kept in the addon dir. +#################### +# - Local Addon Cache +#################### +ADDON_CACHE = PATH_ADDON_ROOT / '.addon_cache' +ADDON_CACHE.mkdir(exist_ok=True) +## TODO: Addon preferences? + #################### # - Logging Info #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/__init__.py index 86e68f7..771061d 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/__init__.py @@ -5,10 +5,7 @@ sp.printing.str.StrPrinter._default_settings['abbrev'] = True ## By configuring this in __init__.py, we guarantee it for all subimports. ## (Unless, elsewhere, this setting is changed. Be careful!) -from . import sockets -from . import node_tree -from . import nodes -from . import categories +from . import categories, node_tree, nodes, sockets BL_REGISTER = [ *sockets.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/bl_socket_map.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/bl_socket_map.py index 7c4623b..c0d579c 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/bl_socket_map.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/bl_socket_map.py @@ -1,7 +1,6 @@ """Tools for translating between BLMaxwell sockets and pure Blender sockets. Attributes: - SOCKET_DEFS: Maps BLMaxwell SocketType objects to their corresponding SocketDef. BL_SOCKET_3D_TYPE_PREFIXES: Blender socket prefixes which indicate that the Blender socket has three values. BL_SOCKET_4D_TYPE_PREFIXES: Blender socket prefixes which indicate that the Blender socket has four values. """ @@ -15,8 +14,7 @@ import sympy as sp from ...utils import extra_sympy_units as spux from ...utils import logger as _logger from . import contracts as ct -from . import sockets as sck -from .contracts import SocketType as ST # noqa: N817 +from . import sockets log = _logger.get(__name__) @@ -25,26 +23,7 @@ BLSocketValue: typ.TypeAlias = typ.Any ## A Blender Socket Value BLSocketSize: typ.TypeAlias = int DescType: typ.TypeAlias = str Unit: typ.TypeAlias = typ.Any ## Type of a valid unit - -#################### -# - Socket to SocketDef -#################### -## TODO: It's only smelly because of the way we bubble up SocketDefs -SOCKET_DEFS = { - socket_type: getattr( - sck, - socket_type.value.removesuffix('SocketType') + 'SocketDef', - ) - for socket_type in ST - if hasattr(sck, socket_type.value.removesuffix('SocketType') + 'SocketDef') -} - -for socket_type in ST: - if not hasattr( - sck, - socket_type.value.removesuffix('SocketType') + 'SocketDef', - ): - log.warning('Missing SocketDef for %s', socket_type.value) +## TODO: Move this kind of thing to contracts #################### @@ -96,7 +75,7 @@ def _size_from_bl_socket( def _socket_type_from_bl_socket( description: str, bl_socket_type: BLSocketType, -) -> ST: +) -> ct.SocketType: """Parse a Blender socket for a matching BLMaxwell socket type, relying on both the Blender socket type and user-generated hints in the description. Arguments: @@ -141,8 +120,8 @@ def _socket_type_from_bl_socket( def _socket_def_from_bl_socket( description: str, bl_socket_type: BLSocketType, -) -> ST: - return SOCKET_DEFS[_socket_type_from_bl_socket(description, bl_socket_type)] +) -> ct.SocketType: + return sockets.SOCKET_DEFS[_socket_type_from_bl_socket(description, bl_socket_type)] def socket_def_from_bl_socket( @@ -252,7 +231,6 @@ def writable_bl_socket_value( Returns: A value corresponding to the input, which is guaranteed to be compatible with the Blender socket (incl. via a GeoNodes modifier), as well as correctly scaled with respect to the given unit system. - """ return _writable_bl_socket_value( bl_interface_socket.description, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/categories.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/categories.py index 070b9b5..0c90754 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/categories.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/categories.py @@ -2,6 +2,7 @@ import bpy import nodeitems_utils + from . import contracts as ct from .nodes import BL_NODES diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/socket_colors.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/socket_colors.py index 1ef38ae..36e434e 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/socket_colors.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/socket_colors.py @@ -1,5 +1,3 @@ -import sympy.physics.units as spu -from ....utils import extra_sympy_units as spuex from .socket_types import SocketType as ST diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/socket_types.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/socket_types.py index 909585d..5225e45 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/socket_types.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/socket_types.py @@ -3,7 +3,6 @@ import enum from ....utils.blender_type_enum import ( BlenderTypeEnum, append_cls_name_to_values, - wrap_values_in_MT, ) diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/unit_systems.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/unit_systems.py index b5a5ada..05a49d8 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/unit_systems.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/contracts/unit_systems.py @@ -17,47 +17,41 @@ UnitSystem: typ.TypeAlias = dict[ST, SympyExpr] # - Unit Systems #################### UNITS_BLENDER: UnitSystem = { - socket_type: _socket_units(socket_type)[socket_unit_prop] - for socket_type, socket_unit_prop in { - ST.PhysicalTime: spu.picosecond, - ST.PhysicalAngle: spu.radian, - ST.PhysicalLength: spu.micrometer, - ST.PhysicalArea: spu.micrometer**2, - ST.PhysicalVolume: spu.micrometer**3, - ST.PhysicalPoint2D: spu.micrometer, - ST.PhysicalPoint3D: spu.micrometer, - ST.PhysicalSize2D: spu.micrometer, - ST.PhysicalSize3D: spu.micrometer, - ST.PhysicalMass: spu.microgram, - ST.PhysicalSpeed: spu.um / spu.second, - ST.PhysicalAccelScalar: spu.um / spu.second**2, - ST.PhysicalForceScalar: spu.micronewton, - ST.PhysicalAccel3D: spu.um / spu.second**2, - ST.PhysicalForce3D: spu.micronewton, - ST.PhysicalFreq: spu.terahertz, - ST.PhysicalPol: spu.radian, - }.items() + ST.PhysicalTime: spu.picosecond, + ST.PhysicalAngle: spu.radian, + ST.PhysicalLength: spu.micrometer, + ST.PhysicalArea: spu.micrometer**2, + ST.PhysicalVolume: spu.micrometer**3, + ST.PhysicalPoint2D: spu.micrometer, + ST.PhysicalPoint3D: spu.micrometer, + ST.PhysicalSize2D: spu.micrometer, + ST.PhysicalSize3D: spu.micrometer, + ST.PhysicalMass: spu.microgram, + ST.PhysicalSpeed: spu.um / spu.second, + ST.PhysicalAccelScalar: spu.um / spu.second**2, + ST.PhysicalForceScalar: spux.micronewton, + ST.PhysicalAccel3D: spu.um / spu.second**2, + ST.PhysicalForce3D: spux.micronewton, + ST.PhysicalFreq: spux.terahertz, + ST.PhysicalPol: spu.radian, } ## TODO: Load (dynamically?) from addon preferences UNITS_TIDY3D: UnitSystem = { - socket_type: _socket_units(socket_type)[socket_unit_prop] - for socket_type, socket_unit_prop in { - ST.PhysicalTime: spu.picosecond, - ST.PhysicalAngle: spu.radian, - ST.PhysicalLength: spu.micrometer, - ST.PhysicalArea: spu.micrometer**2, - ST.PhysicalVolume: spu.micrometer**3, - ST.PhysicalPoint2D: spu.micrometer, - ST.PhysicalPoint3D: spu.micrometer, - ST.PhysicalSize2D: spu.micrometer, - ST.PhysicalSize3D: spu.micrometer, - ST.PhysicalMass: spu.microgram, - ST.PhysicalSpeed: spu.um / spu.second, - ST.PhysicalAccelScalar: spu.um / spu.second**2, - ST.PhysicalForceScalar: spu.micronewton, - ST.PhysicalAccel3D: spu.um / spu.second**2, - ST.PhysicalForce3D: spu.micronewton, - ST.PhysicalFreq: spu.terahertz, - ST.PhysicalPol: spu.radian, - }.items() + ST.PhysicalTime: spu.picosecond, + ST.PhysicalAngle: spu.radian, + ST.PhysicalLength: spu.micrometer, + ST.PhysicalArea: spu.micrometer**2, + ST.PhysicalVolume: spu.micrometer**3, + ST.PhysicalPoint2D: spu.micrometer, + ST.PhysicalPoint3D: spu.micrometer, + ST.PhysicalSize2D: spu.micrometer, + ST.PhysicalSize3D: spu.micrometer, + ST.PhysicalMass: spu.microgram, + ST.PhysicalSpeed: spu.um / spu.second, + ST.PhysicalAccelScalar: spu.um / spu.second**2, + ST.PhysicalForceScalar: spux.micronewton, + ST.PhysicalAccel3D: spu.um / spu.second**2, + ST.PhysicalForce3D: spux.micronewton, + ST.PhysicalFreq: spux.terahertz, + ST.PhysicalPol: spu.radian, } diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/managed_objs/managed_bl_image.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/managed_objs/managed_bl_image.py index b274f65..1470fba 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/managed_objs/managed_bl_image.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/managed_objs/managed_bl_image.py @@ -1,12 +1,10 @@ -import typing as typ -import typing_extensions as typx import io - -import numpy as np -import pydantic as pyd -import matplotlib.axis as mpl_ax +import typing as typ import bpy +import matplotlib.axis as mpl_ax +import numpy as np +import typing_extensions as typx from .. import contracts as ct @@ -161,7 +159,7 @@ class ManagedBLImage(ct.schemas.ManagedObj): height_px = int(_height_inches * _dpi) else: - msg = f'There must either be a preview area, or defined `width_inches`, `height_inches`, and `dpi`' + msg = 'There must either be a preview area, or defined `width_inches`, `height_inches`, and `dpi`' raise ValueError(msg) # Compute Plot Dimensions diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/__init__.py index 11dbee7..177c32f 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/__init__.py @@ -1,16 +1,17 @@ # from . import kitchen_sink -from . import inputs -from . import outputs -from . import sources -from . import mediums -from . import structures - # from . import bounds -from . import monitors -from . import simulations -from . import utilities -from . import viz +from . import ( + inputs, + mediums, + monitors, + outputs, + simulations, + sources, + structures, + utilities, + viz, +) BL_REGISTER = [ # *kitchen_sink.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/base.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/base.py index c9343cc..3a0acc8 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/base.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/base.py @@ -21,7 +21,7 @@ _DEFAULT_LOOSE_SOCKET_SER = json.dumps( 'socket_def_names': [], 'models': [], } -) +) ## TODO: What in the jesus christ is this class MaxwellSimNode(bpy.types.Node): @@ -162,6 +162,7 @@ class MaxwellSimNode(bpy.types.Node): for socket_set_id, socket_set_name in zip( socket_set_ids, socket_set_names, + strict=False, ) ], default=socket_set_names[0], @@ -316,6 +317,7 @@ class MaxwellSimNode(bpy.types.Node): semi_deser['socket_names'], semi_deser['socket_def_names'], semi_deser['models'], + strict=False, ) if hasattr(sockets, socket_def_name) } @@ -538,7 +540,7 @@ class MaxwellSimNode(bpy.types.Node): ): return output_socket_method(self) - msg = f'No output method for ({output_socket_name}, {str(kind.value)}' + msg = f'No output method for ({output_socket_name}, {kind.value!s}' raise ValueError(msg) #################### @@ -642,7 +644,6 @@ class MaxwellSimNode(bpy.types.Node): Restricted to the MaxwellSimTreeType. """ - return node_tree.bl_idname == ct.TreeType.MaxwellSim.value def init(self, context: bpy.types.Context): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/__init__.py index 104ab56..014227b 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/__init__.py @@ -1,5 +1,4 @@ -from . import bound_box -from . import bound_faces +from . import bound_box, bound_faces BL_REGISTER = [ *bound_box.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/bound_box.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/bound_box.py index b377b05..7a5a906 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/bound_box.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/bound_box.py @@ -1,6 +1,4 @@ import tidy3d as td -import sympy as sp -import sympy.physics.units as spu from ... import contracts as ct from ... import sockets diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/bound_faces/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/bound_faces/__init__.py index 52233ca..e4b13c6 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/bound_faces/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/bounds/bound_faces/__init__.py @@ -1,10 +1,11 @@ -from . import pml_bound_face -from . import pec_bound_face -from . import pmc_bound_face - -from . import bloch_bound_face -from . import periodic_bound_face -from . import absorbing_bound_face +from . import ( + absorbing_bound_face, + bloch_bound_face, + pec_bound_face, + periodic_bound_face, + pmc_bound_face, + pml_bound_face, +) BL_REGISTER = [ *pml_bound_face.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/event_decorators.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/events.py similarity index 100% rename from src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/event_decorators.py rename to src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/events.py diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/__init__.py index 821f186..b52aebc 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/__init__.py @@ -1,8 +1,6 @@ # from . import scientific_constant -from . import number_constant - # from . import physical_constant -from . import blender_constant +from . import blender_constant, number_constant BL_REGISTER = [ # *scientific_constant.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/blender_constant.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/blender_constant.py index 17a5a7c..b7b916e 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/blender_constant.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/blender_constant.py @@ -9,7 +9,7 @@ class BlenderConstantNode(base.MaxwellSimNode): node_type = ct.NodeType.BlenderConstant bl_label = 'Blender Constant' - input_socket_sets = { + input_socket_sets: typ.ClassVar = { 'Object': { 'Value': sockets.BlenderObjectSocketDef(), }, @@ -42,6 +42,4 @@ class BlenderConstantNode(base.MaxwellSimNode): BL_REGISTER = [ BlenderConstantNode, ] -BL_NODES = { - ct.NodeType.BlenderConstant: (ct.NodeCategory.MAXWELLSIM_INPUTS_CONSTANTS) -} +BL_NODES = {ct.NodeType.BlenderConstant: (ct.NodeCategory.MAXWELLSIM_INPUTS_CONSTANTS)} diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/number_constant.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/number_constant.py index bc6e706..f22021d 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/number_constant.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/number_constant.py @@ -1,8 +1,5 @@ import typing as typ -import bpy -import sympy as sp - from .... import contracts as ct from .... import sockets from ... import base @@ -12,7 +9,7 @@ class NumberConstantNode(base.MaxwellSimNode): node_type = ct.NodeType.NumberConstant bl_label = 'Numerical Constant' - input_socket_sets = { + input_socket_sets: typ.ClassVar = { 'Integer': { 'Value': sockets.IntegerNumberSocketDef(), }, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/physical_constant.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/physical_constant.py index 6284e89..42404f3 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/physical_constant.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/physical_constant.py @@ -1,19 +1,16 @@ -import bpy +import typing as typ + import sympy as sp -from .... import contracts -from .... import sockets -from ... import base +from .... import contracts, sockets +from ... import base, events class PhysicalConstantNode(base.MaxwellSimTreeNode): node_type = contracts.NodeType.PhysicalConstant - bl_label = 'Physical Constant' - # bl_icon = constants.ICON_SIM_INPUT - input_sockets = {} - input_socket_sets = { + input_socket_sets: typ.ClassVar = { 'time': { 'value': sockets.PhysicalTimeSocketDef( label='Time', @@ -51,13 +48,12 @@ class PhysicalConstantNode(base.MaxwellSimTreeNode): }, ## I got bored so maybe the rest later } - output_sockets = {} - output_socket_sets = input_socket_sets + output_socket_sets: typ.ClassVar = input_socket_sets #################### # - Callbacks #################### - @base.computes_output_socket('value') + @events.computes_output_socket('value') def compute_value(self: contracts.NodeTypeProtocol) -> sp.Expr: return self.compute_input('value') diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/scientific_constant.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/scientific_constant.py index 41fac16..2b21dc4 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/scientific_constant.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/constants/scientific_constant.py @@ -1,3 +1,4 @@ +## TODO: Discover dropdown options from sci_constants.py #################### # - Blender Registration #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/unit_system.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/unit_system.py index ee91177..84cb67d 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/unit_system.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/unit_system.py @@ -2,6 +2,7 @@ from ... import contracts as ct from ... import sockets from .. import base + class PhysicalUnitSystemNode(base.MaxwellSimNode): node_type = ct.NodeType.UnitSystem bl_label = 'Unit System' diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/wave_constant.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/wave_constant.py index 482aa0a..d33795b 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/wave_constant.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/wave_constant.py @@ -1,22 +1,20 @@ -import bpy +import typing as typ + import sympy as sp import sympy.physics.units as spu -import scipy as sc from .....utils import extra_sympy_units as spux +from .....utils import sci_constants as constants from ... import contracts as ct from ... import sockets from .. import base -VAC_SPEED_OF_LIGHT = sc.constants.speed_of_light * spu.meter / spu.second - class WaveConstantNode(base.MaxwellSimNode): node_type = ct.NodeType.WaveConstant - bl_label = 'Wave Constant' - input_socket_sets = { + input_socket_sets: typ.ClassVar = { # Single 'Vacuum WL': { 'WL': sockets.PhysicalLengthSocketDef( @@ -44,7 +42,7 @@ class WaveConstantNode(base.MaxwellSimNode): } #################### - # - Callbacks + # - Event Methods: Listy Output #################### @base.computes_output_socket( 'WL', @@ -53,14 +51,11 @@ class WaveConstantNode(base.MaxwellSimNode): def compute_vac_wl(self, input_sockets: dict) -> sp.Expr: if (vac_wl := input_sockets['WL']) is not None: return vac_wl + if (freq := input_sockets['Freq']) is not None: + return constants.vac_speed_of_light / freq - elif (freq := input_sockets['Freq']) is not None: - return spu.convert_to( - VAC_SPEED_OF_LIGHT / freq, - spu.meter, - ) - - raise RuntimeError('Vac WL and Freq are both None') + msg = 'Vac WL and Freq are both None' + raise RuntimeError(msg) @base.computes_output_socket( 'Freq', @@ -68,17 +63,15 @@ class WaveConstantNode(base.MaxwellSimNode): ) def compute_freq(self, input_sockets: dict) -> sp.Expr: if (vac_wl := input_sockets['WL']) is not None: - return spu.convert_to( - VAC_SPEED_OF_LIGHT / vac_wl, - spu.hertz, - ) - elif (freq := input_sockets['Freq']) is not None: + return constants.vac_speed_of_light / vac_wl + if (freq := input_sockets['Freq']) is not None: return freq - raise RuntimeError('Vac WL and Freq are both None') + msg = 'Vac WL and Freq are both None' + raise RuntimeError(msg) #################### - # - Listy Callbacks + # - Event Methods: Listy Output #################### @base.computes_output_socket( 'WLs', @@ -87,16 +80,11 @@ class WaveConstantNode(base.MaxwellSimNode): def compute_vac_wls(self, input_sockets: dict) -> sp.Expr: if (vac_wls := input_sockets['WLs']) is not None: return vac_wls - elif (freqs := input_sockets['Freqs']) is not None: - return [ - spu.convert_to( - VAC_SPEED_OF_LIGHT / freq, - spu.meter, - ) - for freq in freqs - ][::-1] + if (freqs := input_sockets['Freqs']) is not None: + return [constants.vac_speed_of_light / freq for freq in freqs][::-1] - raise RuntimeError('Vac WLs and Freqs are both None') + msg = 'Vac WL and Freq are both None' + raise RuntimeError(msg) @base.computes_output_socket( 'Freqs', @@ -104,25 +92,18 @@ class WaveConstantNode(base.MaxwellSimNode): ) def compute_freqs(self, input_sockets: dict) -> sp.Expr: if (vac_wls := input_sockets['WLs']) is not None: - return [ - spu.convert_to( - VAC_SPEED_OF_LIGHT / vac_wl, - spu.hertz, - ) - for vac_wl in vac_wls - ][::-1] - elif (freqs := input_sockets['Freqs']) is not None: + return [constants.vac_speed_of_light / vac_wl for vac_wl in vac_wls][::-1] + if (freqs := input_sockets['Freqs']) is not None: return freqs - raise RuntimeError('Vac WLs and Freqs are both None') + msg = 'Vac WL and Freq are both None' + raise RuntimeError(msg) #################### - # - Callbacks + # - Event Methods #################### - @base.on_value_changed( - prop_name='active_socket_set', props={'active_socket_set'} - ) - def on_value_changed__active_socket_set(self, props: dict): + @base.on_value_changed(prop_name='active_socket_set', props={'active_socket_set'}) + def on_active_socket_set_changed(self, props: dict): # Singular: Normal Output Sockets if props['active_socket_set'] in {'Vacuum WL', 'Frequency'}: self.loose_output_sockets = {} @@ -145,7 +126,7 @@ class WaveConstantNode(base.MaxwellSimNode): @base.on_init() def on_init(self): - self.on_value_changed__active_socket_set() + self.on_active_socket_set_changed() #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/web_importers/tidy_3d_web_importer.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/web_importers/tidy_3d_web_importer.py index 8216da8..20a9bdc 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/web_importers/tidy_3d_web_importer.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/inputs/web_importers/tidy_3d_web_importer.py @@ -1,15 +1,23 @@ import tempfile +import typing as typ from pathlib import Path import tidy3d as td -import tidy3d.web as td_web +from ...... import info from ......services import tdcloud from .... import contracts as ct from .... import sockets from ... import base -CACHE = {} + +def _sim_data_cache_path(task_id: str) -> Path: + """Compute an appropriate location for caching simulations downloaded from the internet, unique to each task ID. + + Arguments: + task_id: The ID of the Tidy3D cloud task. + """ + return info.ADDON_CACHE / task_id / 'sim_data.hdf5' #################### @@ -17,89 +25,44 @@ CACHE = {} #################### class Tidy3DWebImporterNode(base.MaxwellSimNode): node_type = ct.NodeType.Tidy3DWebImporter - bl_label = 'Tidy3DWebImporter' + bl_label = 'Tidy3D Web Importer' - input_sockets = { + input_sockets: typ.ClassVar = { 'Cloud Task': sockets.Tidy3DCloudTaskSocketDef( should_exist=True, ), - 'Cache Path': sockets.FilePathSocketDef( - default_path=Path('loaded_simulation.hdf5') - ), } #################### - # - Output Methods + # - Event Methods #################### @base.computes_output_socket( 'FDTD Sim Data', - input_sockets={'Cloud Task', 'Cache Path'}, - ) - def compute_fdtd_sim_data(self, input_sockets: dict) -> str: - global CACHE - if not CACHE.get(self.instance_id): - CACHE[self.instance_id] = {'fdtd_sim_data': None} - - if CACHE[self.instance_id]['fdtd_sim_data'] is not None: - return CACHE[self.instance_id]['fdtd_sim_data'] - - if not ( - (cloud_task := input_sockets['Cloud Task']) is not None - and isinstance(cloud_task, tdcloud.CloudTask) - and cloud_task.status == 'success' - ): - msg = "Won't attempt getting SimData" - raise RuntimeError(msg) - - # Load the Simulation - cache_path = input_sockets['Cache Path'] - if cache_path is None: - print('CACHE PATH IS NONE WHY') - return ## I guess? - if cache_path.is_file(): - sim_data = td.SimulationData.from_file(str(cache_path)) - - else: - sim_data = td_web.api.webapi.load( - cloud_task.task_id, - path=str(cache_path), - ) - - CACHE[self.instance_id]['fdtd_sim_data'] = sim_data - return sim_data - - @base.computes_output_socket( - 'FDTD Sim', input_sockets={'Cloud Task'}, ) - def compute_fdtd_sim(self, input_sockets: dict) -> str: - if not isinstance( - cloud_task := input_sockets['Cloud Task'], tdcloud.CloudTask - ): - msg = 'Input cloud task does not exist' + def compute_sim_data(self, input_sockets: dict) -> str: + # Validate Task Availability + if (cloud_task := input_sockets['Cloud Task']) is None: + msg = f'"{self.bl_label}" CloudTask doesn\'t exist' raise RuntimeError(msg) - # Load the Simulation - with tempfile.NamedTemporaryFile(delete=False) as f: - _path_tmp = Path(f.name) - _path_tmp.rename(f.name + '.json') - path_tmp = Path(f.name + '.json') + # Validate Task Existence + if not isinstance(cloud_task, tdcloud.CloudTask): + msg = f'"{self.bl_label}" CloudTask input "{cloud_task}" has wrong "should_exists", as it isn\'t an instance of tdcloud.CloudTask' + raise TypeError(msg) - sim = td_web.api.webapi.load_simulation( - cloud_task.task_id, - path=str(path_tmp), - ) ## TODO: Don't use td_web directly. Only through tdcloud - Path(path_tmp).unlink() + # Validate Task Status + if cloud_task.status != 'success': + msg = f'"{self.bl_label}" CloudTask is "{cloud_task.status}", not "success"' + raise RuntimeError(msg) - return sim + # Download and Return SimData + return tdcloud.TidyCloudTasks.download_task_sim_data( + cloud_task, _sim_data_cache_path(cloud_task.task_id) + ) - #################### - # - Update - #################### - @base.on_value_changed( - socket_name='Cloud Task', input_sockets={'Cloud Task'} - ) - def on_value_changed__cloud_task(self, input_sockets: dict): + @base.on_value_changed(socket_name='Cloud Task', input_sockets={'Cloud Task'}) + def on_cloud_task_changed(self, input_sockets: dict): if ( (cloud_task := input_sockets['Cloud Task']) is not None and isinstance(cloud_task, tdcloud.CloudTask) @@ -107,15 +70,13 @@ class Tidy3DWebImporterNode(base.MaxwellSimNode): ): self.loose_output_sockets = { 'FDTD Sim Data': sockets.MaxwellFDTDSimDataSocketDef(), - 'FDTD Sim': sockets.MaxwellFDTDSimSocketDef(), } - return - - self.loose_output_sockets = {} + else: + self.loose_output_sockets = {} @base.on_init() def on_init(self): - self.on_value_changed__cloud_task() + self.on_cloud_task_changed() #################### @@ -125,7 +86,5 @@ BL_REGISTER = [ Tidy3DWebImporterNode, ] BL_NODES = { - ct.NodeType.Tidy3DWebImporter: ( - ct.NodeCategory.MAXWELLSIM_INPUTS_IMPORTERS - ) + ct.NodeType.Tidy3DWebImporter: (ct.NodeCategory.MAXWELLSIM_INPUTS_IMPORTERS) } diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/kitchen_sink.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/kitchen_sink.py index 5b3069f..b9c90b2 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/kitchen_sink.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/kitchen_sink.py @@ -1,8 +1,5 @@ -from pathlib import Path -import tidy3d as td import sympy as sp -import sympy.physics.units as spu from .. import contracts as ct from .. import sockets diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/drude_lorentz_medium.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/drude_lorentz_medium.py index db6029e..ee0bfce 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/drude_lorentz_medium.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/drude_lorentz_medium.py @@ -1,9 +1,7 @@ -import tidy3d as td -import sympy as sp import sympy.physics.units as spu +import tidy3d as td -from ... import contracts -from ... import sockets +from ... import contracts, sockets from .. import base @@ -19,7 +17,7 @@ class DrudeLorentzMediumNode(base.MaxwellSimTreeNode): input_sockets = ( { 'eps_inf': sockets.RealNumberSocketDef( - label=f'εr_∞', + label='εr_∞', ), } | { @@ -52,7 +50,7 @@ class DrudeLorentzMediumNode(base.MaxwellSimTreeNode): def compute_medium(self: contracts.NodeTypeProtocol) -> td.Sellmeier: ## Retrieval return td.Lorentz( - eps_inf=self.compute_input(f'eps_inf'), + eps_inf=self.compute_input('eps_inf'), coeffs=[ ( self.compute_input(f'del_eps{i}'), diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/library_medium.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/library_medium.py index 58a0fab..066a95a 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/library_medium.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/library_medium.py @@ -1,17 +1,14 @@ import typing as typ -import functools import bpy -import tidy3d as td +import scipy as sc import sympy as sp import sympy.physics.units as spu -import numpy as np -import scipy as sc +import tidy3d as td from .....utils import extra_sympy_units as spuex from ... import contracts as ct -from ... import sockets -from ... import managed_objs +from ... import managed_objs, sockets from .. import base VAC_SPEED_OF_LIGHT = sc.constants.speed_of_light * spu.meter / spu.second diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/non_linearities/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/non_linearities/__init__.py index 349eba3..1c5a921 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/non_linearities/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/non_linearities/__init__.py @@ -1,7 +1,9 @@ -from . import add_non_linearity -from . import chi_3_susceptibility_non_linearity -from . import kerr_non_linearity -from . import two_photon_absorption_non_linearity +from . import ( + add_non_linearity, + chi_3_susceptibility_non_linearity, + kerr_non_linearity, + two_photon_absorption_non_linearity, +) BL_REGISTER = [ *add_non_linearity.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/triple_sellmeier_medium.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/triple_sellmeier_medium.py index 8c3e368..d5f16f4 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/triple_sellmeier_medium.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/mediums/triple_sellmeier_medium.py @@ -1,9 +1,7 @@ -import tidy3d as td -import sympy as sp import sympy.physics.units as spu +import tidy3d as td -from ... import contracts -from ... import sockets +from ... import contracts, sockets from .. import base diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/monitors/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/monitors/__init__.py index 5a658d3..769cc4d 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/monitors/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/monitors/__init__.py @@ -1,5 +1,5 @@ -from . import eh_field_monitor -from . import field_power_flux_monitor +from . import eh_field_monitor, field_power_flux_monitor + # from . import epsilon_tensor_monitor # from . import diffraction_monitor diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/monitors/field_power_flux_monitor.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/monitors/field_power_flux_monitor.py index 54e76b8..86b5f23 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/monitors/field_power_flux_monitor.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/monitors/field_power_flux_monitor.py @@ -1,18 +1,13 @@ -import typing as typ -import functools import bpy -import tidy3d as td import sympy as sp import sympy.physics.units as spu -import numpy as np -import scipy as sc +import tidy3d as td from .....utils import analyze_geonodes from .....utils import extra_sympy_units as spux from ... import contracts as ct -from ... import sockets -from ... import managed_objs +from ... import managed_objs, sockets from .. import base GEONODES_MONITOR_BOX = 'monitor_flux_box' diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/__init__.py index 5234037..48c3c80 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/__init__.py @@ -1,5 +1,4 @@ -from . import viewer -from . import exporters +from . import exporters, viewer BL_REGISTER = [ *viewer.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/exporters/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/exporters/__init__.py index fcf9b95..d07e2d9 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/exporters/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/exporters/__init__.py @@ -1,5 +1,4 @@ -from . import json_file_exporter -from . import tidy3d_web_exporter +from . import json_file_exporter, tidy3d_web_exporter BL_REGISTER = [ *json_file_exporter.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/exporters/json_file_exporter.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/exporters/json_file_exporter.py index 16b7b66..36914cc 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/exporters/json_file_exporter.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/outputs/exporters/json_file_exporter.py @@ -1,11 +1,9 @@ -import typing as typ import json +import typing as typ from pathlib import Path import bpy -import sympy as sp import pydantic as pyd -import tidy3d as td from .... import contracts as ct from .... import sockets diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/__init__.py index 95eae45..b84eb0e 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/__init__.py @@ -1,9 +1,6 @@ -from . import sim_domain - # from . import sim_grid # from . import sim_grid_axes - -from . import fdtd_sim +from . import fdtd_sim, sim_domain BL_REGISTER = [ *sim_domain.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/fdtd_sim.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/fdtd_sim.py index d3dd140..43ef80e 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/fdtd_sim.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/fdtd_sim.py @@ -1,6 +1,5 @@ -import tidy3d as td import sympy as sp -import sympy.physics.units as spu +import tidy3d as td from ... import contracts as ct from ... import sockets diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/sim_domain.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/sim_domain.py index d33a1ac..ea21595 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/sim_domain.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/sim_domain.py @@ -1,13 +1,11 @@ import bpy import sympy as sp import sympy.physics.units as spu -import scipy as sc from .....utils import analyze_geonodes from ... import contracts as ct -from ... import sockets +from ... import managed_objs, sockets from .. import base -from ... import managed_objs GEONODES_DOMAIN_BOX = 'simdomain_box' diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/sim_grid_axes/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/sim_grid_axes/__init__.py index c4ac0e8..b887fc1 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/sim_grid_axes/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/simulations/sim_grid_axes/__init__.py @@ -1,7 +1,9 @@ -from . import automatic_sim_grid_axis -from . import manual_sim_grid_axis -from . import uniform_sim_grid_axis -from . import array_sim_grid_axis +from . import ( + array_sim_grid_axis, + automatic_sim_grid_axis, + manual_sim_grid_axis, + uniform_sim_grid_axis, +) BL_REGISTER = [ *automatic_sim_grid_axis.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/__init__.py index 350c6cb..05bcf13 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/__init__.py @@ -1,9 +1,6 @@ -from . import temporal_shapes - -from . import point_dipole_source - # from . import uniform_current_source -from . import plane_wave_source +from . import plane_wave_source, point_dipole_source, temporal_shapes + # from . import gaussian_beam_source # from . import astigmatic_gaussian_beam_source # from . import tfsf_source diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/plane_wave_source.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/plane_wave_source.py index b8af116..478c427 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/plane_wave_source.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/plane_wave_source.py @@ -1,16 +1,13 @@ -import typing_extensions as typx import math -import tidy3d as td +import bpy import sympy as sp import sympy.physics.units as spu - -import bpy +import tidy3d as td from .....utils import analyze_geonodes -from ... import managed_objs from ... import contracts as ct -from ... import sockets +from ... import managed_objs, sockets from .. import base GEONODES_PLANE_WAVE = 'source_plane_wave' diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/point_dipole_source.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/point_dipole_source.py index a2ca1f8..f4a3a76 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/point_dipole_source.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/point_dipole_source.py @@ -1,14 +1,12 @@ import typing as typ -import tidy3d as td -import sympy as sp -import sympy.physics.units as spu import bpy +import sympy.physics.units as spu +import tidy3d as td from ... import contracts as ct -from ... import sockets +from ... import managed_objs, sockets from .. import base -from ... import managed_objs class PointDipoleSourceNode(base.MaxwellSimNode): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/__init__.py index d541c4a..e908e5b 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/__init__.py @@ -1,4 +1,5 @@ from . import gaussian_pulse_temporal_shape + # from . import continuous_wave_temporal_shape # from . import array_temporal_shape diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/continuous_wave_temporal_shape.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/continuous_wave_temporal_shape.py index 4456e06..cbff1cd 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/continuous_wave_temporal_shape.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/continuous_wave_temporal_shape.py @@ -1,9 +1,7 @@ -import tidy3d as td -import sympy as sp import sympy.physics.units as spu +import tidy3d as td -from .... import contracts -from .... import sockets +from .... import contracts, sockets from ... import base diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/gaussian_pulse_temporal_shape.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/gaussian_pulse_temporal_shape.py index a5753d9..f3969ae 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/gaussian_pulse_temporal_shape.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/sources/temporal_shapes/gaussian_pulse_temporal_shape.py @@ -1,16 +1,13 @@ import typing as typ -import tidy3d as td -import numpy as np -import sympy as sp -import sympy.physics.units as spu - import bpy +import numpy as np +import sympy.physics.units as spu +import tidy3d as td from ......utils import extra_sympy_units as spuex from .... import contracts as ct -from .... import sockets -from .... import managed_objs +from .... import managed_objs, sockets from ... import base diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/__init__.py index f0ee4e5..eae7cb2 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/__init__.py @@ -1,7 +1,5 @@ # from . import object_structure -from . import geonodes_structure - -from . import primitives +from . import geonodes_structure, primitives BL_REGISTER = [ # *object_structure.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/object_structure.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/object_structure.py index ea6d4c8..ad6fed0 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/object_structure.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/object_structure.py @@ -1,13 +1,9 @@ -import tidy3d as td -import numpy as np -import sympy as sp -import sympy.physics.units as spu - -import bpy import bmesh +import bpy +import numpy as np +import tidy3d as td -from ... import contracts -from ... import sockets +from ... import contracts, sockets from .. import base diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/__init__.py index be3aa33..7101380 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/__init__.py @@ -1,7 +1,5 @@ -from . import box_structure - # from . import cylinder_structure -from . import sphere_structure +from . import box_structure, sphere_structure BL_REGISTER = [ *box_structure.BL_REGISTER, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/cylinder_structure.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/cylinder_structure.py index cafe18f..77884bd 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/cylinder_structure.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/cylinder_structure.py @@ -1,9 +1,7 @@ -import tidy3d as td -import sympy as sp import sympy.physics.units as spu +import tidy3d as td -from .... import contracts -from .... import sockets +from .... import contracts, sockets from ... import base diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/sphere_structure.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/sphere_structure.py index 5179510..99ed6d2 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/sphere_structure.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/structures/primitives/sphere_structure.py @@ -1,13 +1,10 @@ -import tidy3d as td -import sympy as sp -import sympy.physics.units as spu - import bpy +import sympy.physics.units as spu +import tidy3d as td from ......utils import analyze_geonodes from .... import contracts as ct -from .... import sockets -from .... import managed_objs +from .... import managed_objs, sockets from ... import base GEONODES_STRUCTURE_SPHERE = 'structure_sphere' diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/__init__.py index 4ab0af1..5bf149d 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/__init__.py @@ -1,5 +1,6 @@ # from . import math from . import combine + # from . import separate BL_REGISTER = [ diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/combine.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/combine.py index f8d03c3..589067c 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/combine.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/combine.py @@ -1,8 +1,5 @@ -import sympy as sp -import sympy.physics.units as spu -import scipy as sc - import bpy +import sympy as sp from ... import contracts as ct from ... import sockets diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/separate.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/separate.py index 02197e5..2d9455a 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/separate.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/utilities/separate.py @@ -1,10 +1,8 @@ -import tidy3d as td +import scipy as sc import sympy as sp import sympy.physics.units as spu -import scipy as sc -from .... import contracts -from .... import sockets +from .... import contracts, sockets from ... import base diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/viz/sim_data_viz.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/viz/sim_data_viz.py index 4c6313c..35aceec 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/viz/sim_data_viz.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/viz/sim_data_viz.py @@ -1,18 +1,10 @@ import typing as typ -import tidy3d as td -import numpy as np -import sympy as sp -import sympy.physics.units as spu - import bpy -from .....utils import analyze_geonodes -from ... import bl_socket_map from ... import contracts as ct -from ... import sockets -from .. import base -from ... import managed_objs +from ... import managed_objs, sockets +from .. import base, events CACHE = {} @@ -252,7 +244,7 @@ class FDTDSimDataVizNode(base.MaxwellSimNode): #################### # - On Value Changed Methods #################### - @base.on_value_changed( + @events.on_value_changed( socket_name='FDTD Sim Data', managed_objs={'viz_object'}, input_sockets={'FDTD Sim Data'}, @@ -275,7 +267,7 @@ class FDTDSimDataVizNode(base.MaxwellSimNode): #################### # - Plotting #################### - @base.on_show_plot( + @events.on_show_plot( managed_objs={'viz_plot'}, props={ 'viz_monitor_name', @@ -330,7 +322,7 @@ class FDTDSimDataVizNode(base.MaxwellSimNode): bl_select=True, ) - # @base.on_show_preview( + # @events.on_show_preview( # managed_objs={"viz_object"}, # ) # def on_show_preview( diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/__init__.py index 98237f7..884845e 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/__init__.py @@ -1,73 +1,35 @@ -from . import base +from ....utils import logger +from .. import contracts as ct +from . import basic, blender, maxwell, number, physical, tidy3d, vector +from .scan_socket_defs import scan_for_socket_defs -from . import basic +log = logger.get(__name__) +sockets_modules = [basic, number, vector, physical, blender, maxwell, tidy3d] -AnySocketDef = basic.AnySocketDef -BoolSocketDef = basic.BoolSocketDef -StringSocketDef = basic.StringSocketDef -FilePathSocketDef = basic.FilePathSocketDef +#################### +# - Scan for SocketDefs +#################### +SOCKET_DEFS = {} +for sockets_module in sockets_modules: + SOCKET_DEFS |= scan_for_socket_defs(sockets_module) -from . import number +# Set Global Names from SOCKET_DEFS +## SOCKET_DEFS values are the classes themselves, which always have a __name__. +for socket_def_type in SOCKET_DEFS.values(): + globals()[socket_def_type.__name__] = socket_def_type -IntegerNumberSocketDef = number.IntegerNumberSocketDef -RationalNumberSocketDef = number.RationalNumberSocketDef -RealNumberSocketDef = number.RealNumberSocketDef -ComplexNumberSocketDef = number.ComplexNumberSocketDef - -from . import vector - -Real2DVectorSocketDef = vector.Real2DVectorSocketDef -Complex2DVectorSocketDef = vector.Complex2DVectorSocketDef -Integer3DVectorSocketDef = vector.Integer3DVectorSocketDef -Real3DVectorSocketDef = vector.Real3DVectorSocketDef -Complex3DVectorSocketDef = vector.Complex3DVectorSocketDef - -from . import physical - -PhysicalUnitSystemSocketDef = physical.PhysicalUnitSystemSocketDef -PhysicalTimeSocketDef = physical.PhysicalTimeSocketDef -PhysicalAngleSocketDef = physical.PhysicalAngleSocketDef -PhysicalLengthSocketDef = physical.PhysicalLengthSocketDef -PhysicalAreaSocketDef = physical.PhysicalAreaSocketDef -PhysicalVolumeSocketDef = physical.PhysicalVolumeSocketDef -PhysicalPoint3DSocketDef = physical.PhysicalPoint3DSocketDef -PhysicalSize3DSocketDef = physical.PhysicalSize3DSocketDef -PhysicalMassSocketDef = physical.PhysicalMassSocketDef -PhysicalSpeedSocketDef = physical.PhysicalSpeedSocketDef -PhysicalAccelScalarSocketDef = physical.PhysicalAccelScalarSocketDef -PhysicalForceScalarSocketDef = physical.PhysicalForceScalarSocketDef -PhysicalPolSocketDef = physical.PhysicalPolSocketDef -PhysicalFreqSocketDef = physical.PhysicalFreqSocketDef - -from . import blender - -BlenderMaterialSocketDef = blender.BlenderMaterialSocketDef -BlenderObjectSocketDef = blender.BlenderObjectSocketDef -BlenderCollectionSocketDef = blender.BlenderCollectionSocketDef -BlenderImageSocketDef = blender.BlenderImageSocketDef -BlenderGeoNodesSocketDef = blender.BlenderGeoNodesSocketDef -BlenderTextSocketDef = blender.BlenderTextSocketDef - -from . import maxwell - -MaxwellBoundCondSocketDef = maxwell.MaxwellBoundCondSocketDef -MaxwellBoundCondsSocketDef = maxwell.MaxwellBoundCondsSocketDef -MaxwellMediumSocketDef = maxwell.MaxwellMediumSocketDef -MaxwellMediumNonLinearitySocketDef = maxwell.MaxwellMediumNonLinearitySocketDef -MaxwellSourceSocketDef = maxwell.MaxwellSourceSocketDef -MaxwellTemporalShapeSocketDef = maxwell.MaxwellTemporalShapeSocketDef -MaxwellStructureSocketDef = maxwell.MaxwellStructureSocketDef -MaxwellMonitorSocketDef = maxwell.MaxwellMonitorSocketDef -MaxwellFDTDSimSocketDef = maxwell.MaxwellFDTDSimSocketDef -MaxwellFDTDSimDataSocketDef = maxwell.MaxwellFDTDSimDataSocketDef -MaxwellSimGridSocketDef = maxwell.MaxwellSimGridSocketDef -MaxwellSimGridAxisSocketDef = maxwell.MaxwellSimGridAxisSocketDef -MaxwellSimDomainSocketDef = maxwell.MaxwellSimDomainSocketDef - -from . import tidy3d - -Tidy3DCloudTaskSocketDef = tidy3d.Tidy3DCloudTaskSocketDef +# Validate SocketType -> SocketDef +## All SocketTypes should have a SocketDef +for socket_type in ct.SocketType: + if ( + globals().get(socket_type.value.removesuffix('SocketType') + 'SocketDef') + is None + ): + log.warning('Missing SocketDef for %s', socket_type.value) +#################### +# - Exports +#################### BL_REGISTER = [ *basic.BL_REGISTER, *number.BL_REGISTER, @@ -77,3 +39,13 @@ BL_REGISTER = [ *maxwell.BL_REGISTER, *tidy3d.BL_REGISTER, ] + +__all__ = [ + 'basic', + 'number', + 'vector', + 'physical', + 'blender', + 'maxwell', + 'tidy3d', +] + [socket_def_type.__name__ for socket_def_type in SOCKET_DEFS.values()] diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/base.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/base.py index bd402c4..4d36db1 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/base.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/base.py @@ -1,11 +1,11 @@ -import typing as typ -import typing_extensions as typx import functools +import typing as typ import bpy - import sympy as sp import sympy.physics.units as spu +import typing_extensions as typx + from .. import contracts as ct @@ -180,7 +180,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket): if self.locked: return False if self.is_output: - msg = f"Tried to sync 'link add' on output socket" + msg = "Tried to sync 'link add' on output socket" raise RuntimeError(msg) self.trigger_action('value_changed') @@ -195,7 +195,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket): if self.locked: return False if self.is_output: - msg = f"Tried to sync 'link add' on output socket" + msg = "Tried to sync 'link add' on output socket" raise RuntimeError(msg) self.trigger_action('value_changed') @@ -359,7 +359,6 @@ class MaxwellSimSocket(bpy.types.NodeSocket): Can be overridden if more specific logic is required. """ - prev_value = self.value / self.unit * self.prev_unit ## After changing units, self.value is expressed in the wrong unit. ## - Therefore, we removing the new unit, and re-add the prev unit. @@ -398,7 +397,6 @@ class MaxwellSimSocket(bpy.types.NodeSocket): text: str, ) -> None: """Called by Blender to draw the socket UI.""" - if self.is_output: self.draw_output(context, layout, node, text) else: @@ -455,9 +453,8 @@ class MaxwellSimSocket(bpy.types.NodeSocket): if self.locked: row = col.row(align=False) row.enabled = False - else: - if self.locked: - row.enabled = False + elif self.locked: + row.enabled = False # Value Column(s) col = row.column(align=True) @@ -495,11 +492,9 @@ class MaxwellSimSocket(bpy.types.NodeSocket): Can be overridden. """ - pass def draw_value_list(self, col: bpy.types.UILayout) -> None: """Called to draw the value list column in unlinked input sockets. Can be overridden. """ - pass diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/__init__.py index bc647c5..1c39ca6 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/__init__.py @@ -1,18 +1,11 @@ from . import any as any_socket +from . import bool as bool_socket +from . import file_path, string AnySocketDef = any_socket.AnySocketDef - -from . import bool as bool_socket - BoolSocketDef = bool_socket.BoolSocketDef - -from . import string - -StringSocketDef = string.StringSocketDef - -from . import file_path - FilePathSocketDef = file_path.FilePathSocketDef +StringSocketDef = string.StringSocketDef BL_REGISTER = [ diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/any.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/any.py index 140d1c1..e1662d7 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/any.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/any.py @@ -1,11 +1,8 @@ -import typing as typ -import bpy -import sympy as sp import pydantic as pyd -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/bool.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/bool.py index ab6b8f4..91642b5 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/bool.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/bool.py @@ -1,11 +1,9 @@ -import typing as typ import bpy -import sympy as sp import pydantic as pyd -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/file_path.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/file_path.py index d7f3499..b07c119 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/file_path.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/file_path.py @@ -1,12 +1,10 @@ -import typing as typ from pathlib import Path import bpy -import sympy as sp import pydantic as pyd -from .. import base from ... import contracts as ct +from .. import base #################### @@ -51,7 +49,7 @@ class FilePathBLSocket(base.MaxwellSimSocket): class FilePathSocketDef(pyd.BaseModel): socket_type: ct.SocketType = ct.SocketType.FilePath - default_path: Path = Path('') + default_path: Path = Path() def init(self, bl_socket: FilePathBLSocket) -> None: bl_socket.value = self.default_path diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/string.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/string.py index d2cc45a..2bf9527 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/string.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/basic/string.py @@ -1,11 +1,9 @@ -import typing as typ import bpy -import sympy as sp import pydantic as pyd -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/collection.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/collection.py index c8e39fb..3813797 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/collection.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/collection.py @@ -1,10 +1,9 @@ -import typing as typ import bpy import pydantic as pyd -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/image.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/image.py index 44c3b69..3aca893 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/image.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/image.py @@ -1,10 +1,9 @@ -import typing as typ import bpy import pydantic as pyd -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/text.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/text.py index 8c10a17..abbcc6d 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/text.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/blender/text.py @@ -1,10 +1,9 @@ -import typing as typ import bpy import pydantic as pyd -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/__init__.py index e17aebc..42e3a25 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/__init__.py @@ -1,19 +1,16 @@ -from . import bound_cond -from . import bound_conds +from . import bound_cond, bound_conds MaxwellBoundCondSocketDef = bound_cond.MaxwellBoundCondSocketDef MaxwellBoundCondsSocketDef = bound_conds.MaxwellBoundCondsSocketDef -from . import medium -from . import medium_non_linearity +from . import medium, medium_non_linearity MaxwellMediumSocketDef = medium.MaxwellMediumSocketDef MaxwellMediumNonLinearitySocketDef = ( medium_non_linearity.MaxwellMediumNonLinearitySocketDef ) -from . import source -from . import temporal_shape +from . import source, temporal_shape MaxwellSourceSocketDef = source.MaxwellSourceSocketDef MaxwellTemporalShapeSocketDef = temporal_shape.MaxwellTemporalShapeSocketDef @@ -26,11 +23,7 @@ from . import monitor MaxwellMonitorSocketDef = monitor.MaxwellMonitorSocketDef -from . import fdtd_sim -from . import fdtd_sim_data -from . import sim_grid -from . import sim_grid_axis -from . import sim_domain +from . import fdtd_sim, fdtd_sim_data, sim_domain, sim_grid, sim_grid_axis MaxwellFDTDSimSocketDef = fdtd_sim.MaxwellFDTDSimSocketDef MaxwellFDTDSimDataSocketDef = fdtd_sim_data.MaxwellFDTDSimDataSocketDef diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/bound_cond.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/bound_cond.py index cf04ebb..ccc1a0f 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/bound_cond.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/bound_cond.py @@ -1,12 +1,10 @@ -import typing as typ -import typing_extensions as typx - import bpy import pydantic as pyd import tidy3d as td +import typing_extensions as typx -from .. import base from ... import contracts as ct +from .. import base class MaxwellBoundCondBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/bound_conds.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/bound_conds.py index 35b0ad5..754fbf9 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/bound_conds.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/bound_conds.py @@ -1,11 +1,10 @@ -import typing as typ import bpy import pydantic as pyd import tidy3d as td -from .. import base from ... import contracts as ct +from .. import base BOUND_FACE_ITEMS = [ ('PML', 'PML', 'Perfectly matched layer'), diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/fdtd_sim.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/fdtd_sim.py index 230ca85..390045d 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/fdtd_sim.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/fdtd_sim.py @@ -1,11 +1,8 @@ -import typing as typ -import bpy import pydantic as pyd -import tidy3d as td -from .. import base from ... import contracts as ct +from .. import base class MaxwellFDTDSimBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/fdtd_sim_data.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/fdtd_sim_data.py index 50e0b5d..d1de623 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/fdtd_sim_data.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/fdtd_sim_data.py @@ -1,11 +1,8 @@ -import typing as typ -import bpy import pydantic as pyd -import tidy3d as td -from .. import base from ... import contracts as ct +from .. import base class MaxwellFDTDSimDataBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/medium.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/medium.py index 7ff6691..35c6bc2 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/medium.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/medium.py @@ -1,15 +1,13 @@ -import typing as typ import bpy import pydantic as pyd -import sympy as sp +import scipy as sc import sympy.physics.units as spu import tidy3d as td -import scipy as sc -from .....utils.pydantic_sympy import ConstrSympyExpr, Complex -from .. import base +from .....utils.pydantic_sympy import ConstrSympyExpr from ... import contracts as ct +from .. import base VAC_SPEED_OF_LIGHT = sc.constants.speed_of_light * spu.meter / spu.second @@ -93,7 +91,6 @@ class MaxwellMediumBLSocket(base.MaxwellSimSocket): def sync_unit_change(self): """Override unit change to only alter frequency unit.""" - self.value = ( self.wl * self.prev_unit, complex(*self.rel_permittivity), diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/medium_non_linearity.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/medium_non_linearity.py index 9ba3230..cf4bbd8 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/medium_non_linearity.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/medium_non_linearity.py @@ -1,11 +1,8 @@ -import typing as typ -import bpy import pydantic as pyd -import tidy3d as td -from .. import base from ... import contracts as ct +from .. import base class MaxwellMediumNonLinearityBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/monitor.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/monitor.py index 9472e40..76da5c4 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/monitor.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/monitor.py @@ -1,13 +1,8 @@ -import typing as typ -import bpy -import sympy.physics.units as spu import pydantic as pyd -import tidy3d as td -import scipy as sc -from .. import base from ... import contracts as ct +from .. import base class MaxwellMonitorBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_domain.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_domain.py index 32fab1f..28b0233 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_domain.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_domain.py @@ -1,11 +1,8 @@ -import typing as typ -import bpy import pydantic as pyd -import tidy3d as td -from .. import base from ... import contracts as ct +from .. import base class MaxwellSimDomainBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_grid.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_grid.py index 8dabddb..21122ef 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_grid.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_grid.py @@ -1,11 +1,10 @@ -import typing as typ import bpy import pydantic as pyd import tidy3d as td -from .. import base from ... import contracts as ct +from .. import base class MaxwellSimGridBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_grid_axis.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_grid_axis.py index b326e30..d54358a 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_grid_axis.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/sim_grid_axis.py @@ -1,11 +1,8 @@ -import typing as typ -import bpy import pydantic as pyd -import tidy3d as td -from .. import base from ... import contracts as ct +from .. import base class MaxwellSimGridAxisBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/source.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/source.py index f587a3f..3f21988 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/source.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/source.py @@ -1,11 +1,8 @@ -import typing as typ -import bpy import pydantic as pyd -import tidy3d as td -from .. import base from ... import contracts as ct +from .. import base class MaxwellSourceBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/structure.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/structure.py index 5340719..1bc4182 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/structure.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/structure.py @@ -1,10 +1,8 @@ -import typing as typ -import bpy import pydantic as pyd -from .. import base from ... import contracts as ct +from .. import base class MaxwellStructureBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/temporal_shape.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/temporal_shape.py index 85f4086..79fc459 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/temporal_shape.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/maxwell/temporal_shape.py @@ -1,11 +1,8 @@ -import typing as typ -import bpy import pydantic as pyd -import tidy3d as td -from .. import base from ... import contracts as ct +from .. import base class MaxwellTemporalShapeBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/complex_number.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/complex_number.py index 80de02f..ca07b0d 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/complex_number.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/complex_number.py @@ -1,12 +1,12 @@ import typing as typ import bpy -import sympy as sp import pydantic as pyd +import sympy as sp from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base #################### @@ -75,7 +75,6 @@ class ComplexNumberBLSocket(base.MaxwellSimSocket): Returns: The sympy expression representing the complex number. """ - v1, v2 = self.raw_value return { @@ -91,7 +90,6 @@ class ComplexNumberBLSocket(base.MaxwellSimSocket): - Cartesian: a,b -> a + ib - Polar: r,t -> re^(it) """ - self.raw_value = { 'CARTESIAN': (sp.re(value), sp.im(value)), 'POLAR': (sp.Abs(value), sp.arg(value)), diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/integer_number.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/integer_number.py index b08255f..acc2d6a 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/integer_number.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/integer_number.py @@ -1,10 +1,9 @@ -import typing as typ import bpy import pydantic as pyd -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/rational_number.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/rational_number.py index d8da3e5..475c517 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/rational_number.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/rational_number.py @@ -1,12 +1,11 @@ -import typing as typ import bpy -import sympy as sp import pydantic as pyd +import sympy as sp from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/real_number.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/real_number.py index 16a5225..1e4fdaf 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/real_number.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/number/real_number.py @@ -1,12 +1,10 @@ -import typing as typ import bpy -import sympy as sp import pydantic as pyd from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/__init__.py index 75d4d21..7cecef8 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/__init__.py @@ -10,9 +10,7 @@ from . import angle PhysicalAngleSocketDef = angle.PhysicalAngleSocketDef -from . import length -from . import area -from . import volume +from . import area, length, volume PhysicalLengthSocketDef = length.PhysicalLengthSocketDef PhysicalAreaSocketDef = area.PhysicalAreaSocketDef @@ -30,9 +28,7 @@ from . import mass PhysicalMassSocketDef = mass.PhysicalMassSocketDef -from . import speed -from . import accel_scalar -from . import force_scalar +from . import accel_scalar, force_scalar, speed PhysicalSpeedSocketDef = speed.PhysicalSpeedSocketDef PhysicalAccelScalarSocketDef = accel_scalar.PhysicalAccelScalarSocketDef diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/accel_scalar.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/accel_scalar.py index fe51641..2841fd1 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/accel_scalar.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/accel_scalar.py @@ -1,12 +1,11 @@ -import typing as typ import bpy -import sympy.physics.units as spu import pydantic as pyd +import sympy.physics.units as spu from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/angle.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/angle.py index ee67b5f..64ac4fc 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/angle.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/angle.py @@ -1,12 +1,11 @@ -import typing as typ import bpy -import sympy.physics.units as spu import pydantic as pyd +import sympy.physics.units as spu from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/area.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/area.py index b9ea199..2fcf12a 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/area.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/area.py @@ -1,13 +1,11 @@ import typing as typ import bpy -import sympy as sp -import sympy.physics.units as spu import pydantic as pyd +import sympy as sp -from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base class PhysicalAreaBLSocket(base.MaxwellSimSocket): @@ -43,7 +41,6 @@ class PhysicalAreaBLSocket(base.MaxwellSimSocket): Returns: The area as a sympy expression (with units). """ - return self.raw_value * self.unit @default_value.setter @@ -52,7 +49,6 @@ class PhysicalAreaBLSocket(base.MaxwellSimSocket): unit conversions to normalize the input value to the selected units. """ - self.raw_value = self.value_as_unit(value) diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/force_scalar.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/force_scalar.py index 3ae7ed0..897e364 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/force_scalar.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/force_scalar.py @@ -1,12 +1,11 @@ -import typing as typ import bpy -import sympy.physics.units as spu import pydantic as pyd +import sympy.physics.units as spu from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/freq.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/freq.py index 7a9548b..0f0847b 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/freq.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/freq.py @@ -1,16 +1,13 @@ -import typing as typ -import json -import numpy as np import bpy -import sympy as sp -import sympy.physics.units as spu +import numpy as np import pydantic as pyd +import sympy.physics.units as spu from .....utils import extra_sympy_units as spux from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/length.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/length.py index 757f9f1..40c9ac0 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/length.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/length.py @@ -1,13 +1,12 @@ -import typing as typ import bpy -import sympy.physics.units as spu import numpy as np import pydantic as pyd +import sympy.physics.units as spu from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/mass.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/mass.py index ab90818..b5e6bcb 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/mass.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/mass.py @@ -1,12 +1,11 @@ -import typing as typ import bpy -import sympy.physics.units as spu import pydantic as pyd +import sympy.physics.units as spu from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/point_3d.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/point_3d.py index 396b2bd..5deffe9 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/point_3d.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/point_3d.py @@ -1,13 +1,13 @@ import typing as typ import bpy +import pydantic as pyd import sympy as sp import sympy.physics.units as spu -import pydantic as pyd from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base class PhysicalPoint3DBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/pol.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/pol.py index 5a6eca9..6257b4d 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/pol.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/pol.py @@ -1,14 +1,13 @@ -import typing as typ import bpy -import sympy as sp -import sympy.physics.units as spu -import sympy.physics.optics.polarization as spo_pol import pydantic as pyd +import sympy as sp +import sympy.physics.optics.polarization as spo_pol +import sympy.physics.units as spu from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base StokesVector = SympyExpr diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/size_3d.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/size_3d.py index 110df09..dab37ff 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/size_3d.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/size_3d.py @@ -1,13 +1,12 @@ -import typing as typ import bpy +import pydantic as pyd import sympy as sp import sympy.physics.units as spu -import pydantic as pyd from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base class PhysicalSize3DBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/speed.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/speed.py index 1240904..9e34504 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/speed.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/speed.py @@ -1,12 +1,11 @@ -import typing as typ import bpy -import sympy.physics.units as spu import pydantic as pyd +import sympy.physics.units as spu from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/time.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/time.py index 244d124..fa14526 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/time.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/time.py @@ -1,12 +1,12 @@ import typing as typ import bpy -import sympy.physics.units as spu import pydantic as pyd +import sympy.physics.units as spu from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/unit_system.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/unit_system.py index b4368ca..c1a095d 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/unit_system.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/unit_system.py @@ -1,4 +1,3 @@ - import bpy import pydantic as pyd @@ -7,6 +6,8 @@ from ... import contracts as ct from .. import base ST = ct.SocketType + + def SU(socket_type): # noqa: N802, D103 return ct.SOCKET_UNITS[socket_type]['values'] @@ -45,9 +46,7 @@ class PhysicalUnitSystemBLSocket(base.MaxwellSimSocket): name='Show Unit System Definition', description='Toggle to show unit system definition', default=False, - update=( - lambda self, context: self.sync_prop('show_definition', context) - ), + update=(lambda self, context: self.sync_prop('show_definition', context)), ) unit_time: bpy.props.EnumProperty( @@ -93,18 +92,14 @@ class PhysicalUnitSystemBLSocket(base.MaxwellSimSocket): description='Unit of 2D points', items=contract_units_to_items(ST.PhysicalPoint2D), default=default_unit_key_for(ST.PhysicalPoint2D), - update=( - lambda self, context: self.sync_prop('unit_point_2d', context) - ), + update=(lambda self, context: self.sync_prop('unit_point_2d', context)), ) unit_point_3d: bpy.props.EnumProperty( name='Point3D Unit', description='Unit of 3D points', items=contract_units_to_items(ST.PhysicalPoint3D), default=default_unit_key_for(ST.PhysicalPoint3D), - update=( - lambda self, context: self.sync_prop('unit_point_3d', context) - ), + update=(lambda self, context: self.sync_prop('unit_point_3d', context)), ) unit_size_2d: bpy.props.EnumProperty( @@ -142,36 +137,28 @@ class PhysicalUnitSystemBLSocket(base.MaxwellSimSocket): description='Unit of acceleration', items=contract_units_to_items(ST.PhysicalAccelScalar), default=default_unit_key_for(ST.PhysicalAccelScalar), - update=( - lambda self, context: self.sync_prop('unit_accel_scalar', context) - ), + update=(lambda self, context: self.sync_prop('unit_accel_scalar', context)), ) unit_force_scalar: bpy.props.EnumProperty( name='Force Scalar Unit', description='Unit of scalar force', items=contract_units_to_items(ST.PhysicalForceScalar), default=default_unit_key_for(ST.PhysicalForceScalar), - update=( - lambda self, context: self.sync_prop('unit_force_scalar', context) - ), + update=(lambda self, context: self.sync_prop('unit_force_scalar', context)), ) unit_accel_3d: bpy.props.EnumProperty( name='Accel3D Unit', description='Unit of 3D vector acceleration', items=contract_units_to_items(ST.PhysicalAccel3D), default=default_unit_key_for(ST.PhysicalAccel3D), - update=( - lambda self, context: self.sync_prop('unit_accel_3d', context) - ), + update=(lambda self, context: self.sync_prop('unit_accel_3d', context)), ) unit_force_3d: bpy.props.EnumProperty( name='Force3D Unit', description='Unit of 3D vector force', items=contract_units_to_items(ST.PhysicalForce3D), default=default_unit_key_for(ST.PhysicalForce3D), - update=( - lambda self, context: self.sync_prop('unit_force_3d', context) - ), + update=(lambda self, context: self.sync_prop('unit_force_3d', context)), ) unit_freq: bpy.props.EnumProperty( @@ -187,9 +174,7 @@ class PhysicalUnitSystemBLSocket(base.MaxwellSimSocket): #################### def draw_label_row(self, row: bpy.types.UILayout, text) -> None: row.label(text=text) - row.prop( - self, 'show_definition', toggle=True, text='', icon='MOD_LENGTH' - ) + row.prop(self, 'show_definition', toggle=True, text='', icon='MOD_LENGTH') def draw_value(self, col: bpy.types.UILayout) -> None: if self.show_definition: @@ -263,7 +248,8 @@ class PhysicalUnitSystemBLSocket(base.MaxwellSimSocket): @property def value(self) -> dict[ST, SympyExpr]: return { - socket_type: SU(socket_type)[socket_unit_prop] for socket_type, socket_unit_prop in [ + socket_type: SU(socket_type)[socket_unit_prop] + for socket_type, socket_unit_prop in [ (ST.PhysicalTime, self.unit_time), (ST.PhysicalAngle, self.unit_angle), (ST.PhysicalLength, self.unit_length), diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/volume.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/volume.py index 2883123..b6ccdc4 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/volume.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/physical/volume.py @@ -1,13 +1,11 @@ -import typing as typ import bpy -import sympy as sp -import sympy.physics.units as spu import pydantic as pyd +import sympy.physics.units as spu from .....utils.pydantic_sympy import SympyExpr -from .. import base from ... import contracts as ct +from .. import base class PhysicalVolumeBLSocket(base.MaxwellSimSocket): diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/scan_socket_defs.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/scan_socket_defs.py new file mode 100644 index 0000000..ed6c69b --- /dev/null +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/scan_socket_defs.py @@ -0,0 +1,21 @@ +import types +import typing as typ + +from .. import contracts as ct + + +def scan_for_socket_defs( + sockets_module: types.ModuleType, +) -> dict[ct.SocketType, typ.Type[ct.schemas.SocketDef]]: + return { + socket_type: getattr( + sockets_module, + socket_type.value.removesuffix('SocketType') + 'SocketDef', + ) + for socket_type in ct.SocketType + if hasattr( + sockets_module, socket_type.value.removesuffix('SocketType') + 'SocketDef' + ) + } + +## TODO: Function for globals() filling too. diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/tidy3d/cloud_task.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/tidy3d/cloud_task.py index 24a94c1..1affa97 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/tidy3d/cloud_task.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/tidy3d/cloud_task.py @@ -89,17 +89,13 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket): name='Folder of Cloud Tasks', description='An existing folder on the Tidy3D Cloud', items=lambda self, _: self.retrieve_folders(), - update=( - lambda self, context: self.sync_prop('existing_folder_id', context) - ), + update=(lambda self, context: self.sync_prop('existing_folder_id', context)), ) existing_task_id: bpy.props.EnumProperty( name='Existing Cloud Task', description='An existing task on the Tidy3D Cloud, within the given folder', items=lambda self, _: self.retrieve_tasks(), - update=( - lambda self, context: self.sync_prop('existing_task_id', context) - ), + update=(lambda self, context: self.sync_prop('existing_task_id', context)), ) # (Potential) New Task @@ -107,9 +103,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket): name='New Cloud Task Name', description='Name of a new task to submit to the Tidy3D Cloud', default='', - update=( - lambda self, context: self.sync_prop('new_task_name', context) - ), + update=(lambda self, context: self.sync_prop('new_task_name', context)), ) #################### @@ -158,9 +152,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket): [ task.taskName, '(' - + task.created_at.astimezone().strftime( - '%y-%m-%d @ %H:%M %Z' - ) + + task.created_at.astimezone().strftime('%y-%m-%d @ %H:%M %Z') + ')', ] ), @@ -205,9 +197,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket): """ # Propagate along Link if self.is_linked: - msg = ( - 'Cannot sync newly created task to linked Cloud Task socket.' - ) + msg = 'Cannot sync newly created task to linked Cloud Task socket.' raise ValueError(msg) ## TODO: A little aggressive. Is there a good use case? @@ -223,9 +213,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket): """ # Propagate along Link if self.is_linked: - msg = ( - 'Cannot sync newly created task to linked Cloud Task socket.' - ) + msg = 'Cannot sync newly created task to linked Cloud Task socket.' raise ValueError(msg) ## TODO: A little aggressive. Is there a good use case? @@ -238,9 +226,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket): def draw_label_row(self, row: bpy.types.UILayout, text: str): row.label(text=text) - auth_icon = ( - 'LOCKVIEW_ON' if tdcloud.IS_AUTHENTICATED else 'LOCKVIEW_OFF' - ) + auth_icon = 'LOCKVIEW_ON' if tdcloud.IS_AUTHENTICATED else 'LOCKVIEW_OFF' row.operator( Authenticate.bl_idname, text='', @@ -299,11 +285,7 @@ class Tidy3DCloudTaskBLSocket(base.MaxwellSimSocket): @property def value( self, - ) -> ( - tuple[tdcloud.CloudTaskName, tdcloud.CloudFolder] - | tdcloud.CloudTask - | None - ): + ) -> tuple[tdcloud.CloudTaskName, tdcloud.CloudFolder] | tdcloud.CloudTask | None: # Retrieve Folder ## Authentication is presumed OK if ( diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/__init__.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/__init__.py index d1951bc..4011a7f 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/__init__.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/__init__.py @@ -1,12 +1,9 @@ -from . import real_2d_vector -from . import complex_2d_vector +from . import complex_2d_vector, real_2d_vector Real2DVectorSocketDef = real_2d_vector.Real2DVectorSocketDef Complex2DVectorSocketDef = complex_2d_vector.Complex2DVectorSocketDef -from . import integer_3d_vector -from . import real_3d_vector -from . import complex_3d_vector +from . import complex_3d_vector, integer_3d_vector, real_3d_vector Integer3DVectorSocketDef = integer_3d_vector.Integer3DVectorSocketDef Real3DVectorSocketDef = real_3d_vector.Real3DVectorSocketDef diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/complex_2d_vector.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/complex_2d_vector.py index ff5226e..7bab976 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/complex_2d_vector.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/complex_2d_vector.py @@ -1,9 +1,8 @@ -import typing as typ import pydantic as pyd -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/complex_3d_vector.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/complex_3d_vector.py index c824ae0..9e14fdc 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/complex_3d_vector.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/complex_3d_vector.py @@ -1,9 +1,8 @@ -import typing as typ import pydantic as pyd -from .. import base from ... import contracts as ct +from .. import base #################### diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/integer_3d_vector.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/integer_3d_vector.py index 08e816b..4dad02e 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/integer_3d_vector.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/integer_3d_vector.py @@ -1,12 +1,11 @@ -import typing as typ import bpy -import sympy as sp import pydantic as pyd +import sympy as sp from .....utils.pydantic_sympy import ConstrSympyExpr -from .. import base from ... import contracts as ct +from .. import base Integer3DVector = ConstrSympyExpr( allow_variables=False, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/real_2d_vector.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/real_2d_vector.py index 8c75978..441f5ac 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/real_2d_vector.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/real_2d_vector.py @@ -1,12 +1,11 @@ -import typing as typ import bpy -import sympy as sp import pydantic as pyd +import sympy as sp from .....utils.pydantic_sympy import ConstrSympyExpr -from .. import base from ... import contracts as ct +from .. import base Real2DVector = ConstrSympyExpr( allow_variables=False, diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/real_3d_vector.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/real_3d_vector.py index e9ebf14..c7359f1 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/real_3d_vector.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/sockets/vector/real_3d_vector.py @@ -1,12 +1,11 @@ -import typing as typ import bpy -import sympy as sp import pydantic as pyd +import sympy as sp from .....utils.pydantic_sympy import ConstrSympyExpr -from .. import base from ... import contracts as ct +from .. import base Real3DVector = ConstrSympyExpr( allow_variables=False, diff --git a/src/blender_maxwell/nodeps/utils/pydeps.py b/src/blender_maxwell/nodeps/utils/pydeps.py index 600d1f5..04086df 100644 --- a/src/blender_maxwell/nodeps/utils/pydeps.py +++ b/src/blender_maxwell/nodeps/utils/pydeps.py @@ -62,7 +62,8 @@ def _check_pydeps( def conform_pypi_package_deplock(deplock: str): """Conforms a == de-lock to match if pypi considers them the same (PyPi is case-insensitive and considers -/_ to be the same) - See """ + See + """ return deplock.lower().replace('_', '-') with path_requirementslock.open('r') as file: diff --git a/src/blender_maxwell/services/tdcloud.py b/src/blender_maxwell/services/tdcloud.py index f67c60a..c259b79 100644 --- a/src/blender_maxwell/services/tdcloud.py +++ b/src/blender_maxwell/services/tdcloud.py @@ -6,8 +6,10 @@ import datetime as dt import functools +import tempfile import typing as typ from dataclasses import dataclass +from pathlib import Path import tidy3d as td import tidy3d.web as td_web @@ -238,6 +240,37 @@ class TidyCloudTasks: return cloud_tasks + #################### + # - Task Download + #################### + @classmethod + def download_task_sim_data( + cls, cloud_task: CloudTask, download_sim_path: Path | None = None + ) -> td.SimulationData: + # Expose Path for SimData Download + if download_sim_path is None: + with tempfile.NamedTemporaryFile(delete=False) as f: + _path_tmp = Path(f.name) + _path_tmp.rename(f.name + '.hdf5') + path_sim = Path(f.name + '.hdf5') + else: + path_sim = download_sim_path + + # Get Sim Data (from file and/or download) + if path_sim.is_file(): + sim_data = td.SimulationData.from_file(str(download_sim_path)) + else: + sim_data = td_web.api.webapi.load( + cloud_task.task_id, + path=str(download_sim_path), + ) + + # Delete Temporary File (if used) + if download_sim_path is None: + Path(path_sim).unlink() + + return sim_data + #################### # - Task Create/Delete #################### diff --git a/src/blender_maxwell/utils/extra_sympy_units.py b/src/blender_maxwell/utils/extra_sympy_units.py index af01ba2..11dbe41 100644 --- a/src/blender_maxwell/utils/extra_sympy_units.py +++ b/src/blender_maxwell/utils/extra_sympy_units.py @@ -95,7 +95,7 @@ def parse_abbrev_symbols_to_units(expr: sp.Basic) -> sp.Basic: # - Units <-> Scalars #################### @functools.lru_cache(maxsize=8192) -def scale_to_unit(expr: sp.Expr, unit: sp.Quantity) -> typ.Any: +def scale_to_unit(expr: sp.Expr, unit: spu.Quantity) -> typ.Any: ## TODO: An LFU cache could do better than an LRU. unitless_expr = spu.convert_to(expr, unit) / unit if not uses_units(unitless_expr): diff --git a/src/blender_maxwell/utils/sci_constants.py b/src/blender_maxwell/utils/sci_constants.py new file mode 100644 index 0000000..3568509 --- /dev/null +++ b/src/blender_maxwell/utils/sci_constants.py @@ -0,0 +1,6 @@ +import scipy as sc +import sympy.physics.units as spu + +#from . import extra_sympy_units as spux + +vac_speed_of_light = sc.constants.speed_of_light * spu.meter / spu.second diff --git a/src/scripts/bl_run.py b/src/scripts/bl_run.py index a2461b2..ab05305 100644 --- a/src/scripts/bl_run.py +++ b/src/scripts/bl_run.py @@ -155,7 +155,7 @@ def main(): ) as path_zipped: try: install_addon(info.ADDON_NAME, path_zipped) - except Exception as exe: + except Exception: traceback.print_exc() install_failed = True