fdtdx.SimulationObject

Bases: TreeClass, ABC

Abstract base class for objects in a 3D simulation environment.

This class provides the foundation for simulation objects with spatial properties and positioning capabilities in both real and grid coordinate systems. It supports random positioning offsets.

Attributes:
  • partial_real_shape (PartialRealShape3D) –

    The object's shape in real-world coordinates. Defaults to UNDEFINED_SHAPE_3D if not specified.

  • partial_grid_shape (PartialGridShape3D) –

    The object's shape in grid coordinates. Defaults to UNDEFINED_SHAPE_3D if not specified.

  • color (tuple[float, float, float] | None) –

    RGB color values for the object, where each component is in the interval [0, 1]. None indicates no color is specified. Defaults to None.

  • name (str) –

    Unique identifier for the object. Automatically enforced to be unique through the UniqueName validator. The user can also set a name manually.

  • max_random_real_offsets (tuple[float, float, float]) –

    Maximum random offset values that can be applied to the object's position in real coordinates for each axis (x, y, z). Defaults to (0, 0, 0) for no random offset.

  • max_random_grid_offsets (tuple[int, int, int]) –

    Maximum random offset values that can be applied to the object's position in grid coordinates for each axis (x, y, z). Defaults to (0, 0, 0) for no random offset.

Note

This is an abstract base class and cannot be instantiated directly.

extend_to

extend_to(
    other: SimulationObject | None,
    axis: int,
    direction: Literal["+", "-"],
    other_position: float | None = None,
    offset: float = 0,
    grid_offset: int = 0,
) -> SizeExtensionConstraint

Creates a SizeExtensionConstraint that extends this object along a specified axis until it reaches another object or the simulation boundary. The extension can be in either positive or negative direction.

Parameters:
  • other (SimulationObject | None) –

    Target object to extend to, or None to extend to simulation boundary

  • axis (int) –

    Which axis to extend along (0, 1, or 2)

  • direction (Literal['+', '-']) –

    Direction to extend in ('+' or '-')

  • other_position (float | None, default: None ) –

    Relative position on target object (-1 to 1) to extend to. If None, defaults to the corresponding side (-1 for '+' direction, 1 for '-' direction). Defaults to None.

  • offset (float, default: 0 ) –

    Additional offset in meters to apply after extension. Ignored when extending to simulation boundary. Defaults to zero.

  • grid_offset (int, default: 0 ) –

    Additional offset in Yee-grid voxels to apply after extension. Ignored when extending to simulation boundary. Defaults to zero.

Returns:
Source code in src/fdtdx/objects/object.py
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
def extend_to(
    self,
    other: "SimulationObject | None",
    axis: int,
    direction: Literal["+", "-"],
    other_position: float | None = None,
    offset: float = 0,
    grid_offset: int = 0,
) -> SizeExtensionConstraint:
    """Creates a SizeExtensionConstraint that extends this object along a specified axis until it
    reaches another object or the simulation boundary. The extension can be in either positive or
    negative direction.

    Args:
        other (SimulationObject | None): Target object to extend to, or None to extend to simulation boundary
        axis (int): Which axis to extend along (0, 1, or 2)
        direction (Literal["+", "-"]): Direction to extend in ('+' or '-')
        other_position (float | None, optional): Relative position on target object (-1 to 1) to extend to.
            If None, defaults to the corresponding side (-1 for '+' direction, 1 for '-' direction). Defaults to
            None.
        offset (float, optional): Additional offset in meters to apply after extension. Ignored when extending to
            simulation boundary. Defaults to zero.
        grid_offset (int, optional): Additional offset in Yee-grid voxels to apply after extension. Ignored when
            extending to simulation boundary. Defaults to zero.

    Returns:
        SizeExtensionConstraint: Constraint defining how the object extends
    """
    # default: extend to corresponding side
    if other_position is None:
        other_position = -1 if direction == "+" else 1
    if other is None:
        if offset != 0 or grid_offset != 0:
            raise Exception("Cannot use offset when extending object to infinity")
    return SizeExtensionConstraint(
        object=self,
        other_object=other,
        axis=axis,
        direction=direction,
        other_position=other_position,
        offset=offset,
        grid_offset=grid_offset,
    )

face_to_face_negative_direction

face_to_face_negative_direction(
    other: SimulationObject,
    axes: tuple[int, ...] | int,
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint

Creates a PositionConstraint that places this object facing another object in the negative direction of specified axes. The objects will touch at their facing boundaries unless margins are specified.

Parameters:
  • other (SimulationObject) –

    Another object in the simulation scene

  • axes (tuple[int, ...] | int) –

    Either a single integer or a tuple describing which axes to align on

  • margins (tuple[float, ...] | float | None, default: None ) –

    Additional margins in meters between the facing surfaces. Must have same length as axes. If None, no margin is used. Defaults to None.

  • grid_margins (tuple[int, ...] | int | None, default: None ) –

    Additional margins in Yee-grid voxels between the facing surfaces. Must have same length as axes. If None, no margin is used. Defaults to None.

Returns:
  • PositionConstraint( PositionConstraint ) –

    Position constraint aligning objects face-to-face in negative direction

Source code in src/fdtdx/objects/object.py
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
def face_to_face_negative_direction(
    self,
    other: "SimulationObject",
    axes: tuple[int, ...] | int,
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint:
    """Creates a PositionConstraint that places this object facing another object in the negative direction
    of specified axes. The objects will touch at their facing boundaries unless margins are specified.

    Args:
        other (SimulationObject): Another object in the simulation scene
        axes (tuple[int, ...] | int): Either a single integer or a tuple describing which axes to align on
        margins (tuple[float, ...] | float | None, optional): Additional margins in meters between the facing
            surfaces. Must have same length as axes. If None, no margin is used. Defaults to None.
        grid_margins (tuple[int, ...] | int | None, optional): Additional margins in Yee-grid voxels between the
            facing surfaces. Must have same length as axes. If None, no margin is used. Defaults to None.

    Returns:
        PositionConstraint: Position constraint aligning objects face-to-face in negative direction
    """
    if isinstance(axes, int):
        axes = (axes,)
    own_positions = tuple([1 for _ in axes])
    other_positions = tuple([-1 for _ in axes])
    constraint = self.place_relative_to(
        other=other,
        axes=axes,
        own_positions=own_positions,
        other_positions=other_positions,
        margins=margins,
        grid_margins=grid_margins,
    )
    return constraint

face_to_face_positive_direction

face_to_face_positive_direction(
    other: SimulationObject,
    axes: tuple[int, ...] | int,
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint

Creates a PositionConstraint that places this object facing another object in the positive direction of specified axes. The objects will touch at their facing boundaries unless margins are specified.

Parameters:
  • other (SimulationObject) –

    Another object in the simulation scene

  • axes (tuple[int, ...] | int) –

    Either a single integer or a tuple describing which axes to align on

  • margins (tuple[float, ...] | float | None, default: None ) –

    Additional margins in meters between the facing surfaces. Must have same length as axes. If None, no margin is used. Defaults to None.

  • grid_margins (tuple[int, ...] | int | None, default: None ) –

    Additional margins in Yee-grid voxels between the facing surfaces. Must have same length as axes. If None, no margin is used. Defaults to None

Returns:
  • PositionConstraint( PositionConstraint ) –

    Position constraint aligning objects face-to-face in positive direction

Source code in src/fdtdx/objects/object.py
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
def face_to_face_positive_direction(
    self,
    other: "SimulationObject",
    axes: tuple[int, ...] | int,
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint:
    """Creates a PositionConstraint that places this object facing another object in the positive direction
    of specified axes. The objects will touch at their facing boundaries unless margins are specified.

    Args:
        other (SimulationObject): Another object in the simulation scene
        axes (tuple[int, ...] | int): Either a single integer or a tuple describing which axes to align on
        margins (tuple[float, ...] | float | None, optional): Additional margins in meters between the facing
            surfaces. Must have same length as axes. If None, no margin is used. Defaults to None.
        grid_margins (tuple[int, ...] | int | None, optional): Additional margins in Yee-grid voxels between the
            facing surfaces. Must have same length as axes. If None, no margin is used. Defaults to None

    Returns:
        PositionConstraint: Position constraint aligning objects face-to-face in positive direction
    """
    if isinstance(axes, int):
        axes = (axes,)
    own_positions = tuple([-1 for _ in axes])
    other_positions = tuple([1 for _ in axes])
    constraint = self.place_relative_to(
        other=other,
        axes=axes,
        own_positions=own_positions,
        other_positions=other_positions,
        margins=margins,
        grid_margins=grid_margins,
    )
    return constraint

place_above

place_above(
    other: SimulationObject,
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint

Creates a PositionConstraint that places this object above another object along the z-axis. This is a convenience wrapper around face_to_face_positive_direction() for axis 2 (z-axis).

Parameters:
  • other (SimulationObject) –

    Another object in the simulation scene

  • margins (tuple[float, ...] | float | None, default: None ) –

    Additional vertical margins in meters between objects. If None, no margin is used. Defaults to None.

  • grid_margins (tuple[int, ...] | int | None, default: None ) –

    Additional vertical margins in Yee-grid voxels between objects. If None, no margin is used. Defaults to None.

Returns:
  • PositionConstraint( PositionConstraint ) –

    Position constraint placing this object above the other

Source code in src/fdtdx/objects/object.py
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
def place_above(
    self,
    other: "SimulationObject",
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint:
    """Creates a PositionConstraint that places this object above another object along the z-axis.
    This is a convenience wrapper around face_to_face_positive_direction() for axis 2 (z-axis).

    Args:
        other (SimulationObject): Another object in the simulation scene
        margins (tuple[float, ...] | float | None, optional): Additional vertical margins in meters between objects.
            If None, no margin is used. Defaults to None.
        grid_margins (tuple[int, ...] | int | None, optional): Additional vertical margins in Yee-grid voxels
            between objects. If None, no margin is used. Defaults to None.

    Returns:
        PositionConstraint: Position constraint placing this object above the other
    """
    constraint = self.face_to_face_positive_direction(
        other=other,
        axes=(2,),
        margins=margins,
        grid_margins=grid_margins,
    )
    return constraint

place_at_center

place_at_center(
    other: SimulationObject,
    axes: tuple[int, ...] | int = (0, 1, 2),
    own_positions: tuple[float, ...] | float | None = None,
    other_positions: (
        tuple[float, ...] | float | None
    ) = None,
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint

Creates a PositionConstraint that centers this object relative to another object along specified axes. This is a convenience wrapper around place_relative_to() with default positions at the center (0).

Parameters:
  • other (SimulationObject) –

    Another object in the simulation scene

  • axes (tuple[int, ...] | int, default: (0, 1, 2) ) –

    Either a single integer or a tuple describing which axes to center on. Defaults to all axes (0, 1, 2).

  • own_positions (tuple[float, ...] | float | None, default: None ) –

    Relative positions on this object (-1 to 1). If None, uses center (0). Defaults to None.

  • other_positions (tuple[float, ...] | float | None, default: None ) –

    Relative positions on other object (-1 to 1). If None, uses center (0). Defaults to None.

  • margins (tuple[float, ...] | float | None, default: None ) –

    Additional margins in meters between objects. Must have same length as axes. If None, no margin is used. Defaults to None.

  • grid_margins ( tuple[int, ...] | int | None, default: None ) –

    Additional margins in Yee-grid voxels between objects. Must have same length as axes. If None, no margin is used. Defaults to None.

Returns:
  • PositionConstraint( PositionConstraint ) –

    Position constraint centering objects relative to each other

Source code in src/fdtdx/objects/object.py
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
def place_at_center(
    self,
    other: "SimulationObject",
    axes: tuple[int, ...] | int = (0, 1, 2),
    own_positions: tuple[float, ...] | float | None = None,
    other_positions: tuple[float, ...] | float | None = None,
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint:
    """Creates a PositionConstraint that centers this object relative to another object along specified axes.
    This is a convenience wrapper around place_relative_to() with default positions at the center (0).

    Args:
        other (SimulationObject): Another object in the simulation scene
        axes (tuple[int, ...] | int, optional): Either a single integer or a tuple describing which axes to center
            on. Defaults to all axes (0, 1, 2).
        own_positions (tuple[float, ...] | float | None, optional): Relative positions on this object (-1 to 1).
            If None, uses center (0). Defaults to None.
        other_positions (tuple[float, ...] | float | None, optional): Relative positions on other object (-1 to 1).
            If None, uses center (0). Defaults to None.
        margins (tuple[float, ...] | float | None, optional): Additional margins in meters between objects.
            Must have same length as axes. If None, no margin is used. Defaults to None.
        grid_margins ( tuple[int, ...] | int | None, optional): Additional margins in Yee-grid voxels between
            objects. Must have same length as axes. If None, no margin is used. Defaults to None.

    Returns:
        PositionConstraint: Position constraint centering objects relative to each other
    """
    if isinstance(axes, int):
        axes = (axes,)
    if own_positions is None:
        own_positions = tuple([0 for _ in axes])
    if other_positions is None:
        other_positions = tuple([0 for _ in axes])
    constraint = self.place_relative_to(
        other=other,
        axes=axes,
        own_positions=own_positions,
        other_positions=other_positions,
        margins=margins,
        grid_margins=grid_margins,
    )
    return constraint

place_below

place_below(
    other: SimulationObject,
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint

Creates a PositionConstraint that places this object below another object along the z-axis. This is a convenience wrapper around face_to_face_negative_direction() for axis 2 (z-axis).

Parameters:
  • other (SimulationObject) –

    Another object in the simulation scene

  • margins (tuple[float, ...] | float | None, default: None ) –

    Additional vertical margins in meters between objects. If None, no margin is used. Defaults to None.

  • grid_margins (tuple[int, ...] | int | None, default: None ) –

    Additional vertical margins in Yee-grid voxels between objects. If None, no margin is used. Defaults to None.

Returns:
  • PositionConstraint( PositionConstraint ) –

    Position constraint placing this object below the other

Source code in src/fdtdx/objects/object.py
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
def place_below(
    self,
    other: "SimulationObject",
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint:
    """Creates a PositionConstraint that places this object below another object along the z-axis.
    This is a convenience wrapper around face_to_face_negative_direction() for axis 2 (z-axis).

    Args:
        other (SimulationObject): Another object in the simulation scene
        margins (tuple[float, ...] | float | None, optional): Additional vertical margins in meters between objects.
            If None, no margin is used. Defaults to None.
        grid_margins (tuple[int, ...] | int | None, optional): Additional vertical margins in Yee-grid voxels
            between objects. If None, no margin is used. Defaults to None.

    Returns:
        PositionConstraint: Position constraint placing this object below the other
    """
    constraint = self.face_to_face_negative_direction(
        other=other,
        axes=(2,),
        margins=margins,
        grid_margins=grid_margins,
    )
    return constraint

place_relative_to

place_relative_to(
    other: SimulationObject,
    axes: tuple[int, ...] | int,
    own_positions: tuple[float, ...] | float,
    other_positions: tuple[float, ...] | float,
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint

Creates a PositionalConstraint between two objects. The constraint is defined by anchor points on both objects, which are constrainted to be at the same position. Anchors are defined in relative coordinates, i.e. a position of -1 is the left object boundary in the repective axis and a position of +1 the right boundary.

Parameters:
  • other (SimulationObject) –

    Another object in the simulation scene

  • axes (tuple[int, ...] | int) –

    Eiter a single integer or a tuple describing the axes of the constraints

  • own_positions (tuple[float, ...] | float) –

    The positions of the own anchor in the axes. Must have the same lengths as axes

  • other_positions (tuple[float, ...] | float) –

    The positions of the other objects' anchor in the axes. Must have the same lengths as axes

  • margins (tuple[float, ...] | float | None, default: None ) –

    The margins between the anchors of both objects in meters. Must have the same lengths as axes. If None, no margin is used. Defaults to None.

  • grid_margins (tuple[int, ...] | int | None, default: None ) –

    The margins between the anchors of both objects in Yee-grid voxels. Must have the same lengths as axes. If none, no margin is used. Defaults to None.

Returns:
  • PositionConstraint( PositionConstraint ) –

    Positional constraint between this object and the other

Source code in src/fdtdx/objects/object.py
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
def place_relative_to(
    self,
    other: "SimulationObject",
    axes: tuple[int, ...] | int,
    own_positions: tuple[float, ...] | float,
    other_positions: tuple[float, ...] | float,
    margins: tuple[float, ...] | float | None = None,
    grid_margins: tuple[int, ...] | int | None = None,
) -> PositionConstraint:
    """Creates a PositionalConstraint between two objects. The constraint is defined by anchor points on
    both objects, which are constrainted to be at the same position. Anchors are defined in relative coordinates,
    i.e. a position of -1 is the left object boundary in the repective axis and a position of +1 the right boundary.

    Args:
        other (SimulationObject): Another object in the simulation scene
        axes (tuple[int, ...] | int): Eiter a single integer or a tuple describing the axes of the constraints
        own_positions (tuple[float, ...] | float): The positions of the own anchor in the axes. Must have the same lengths as axes
        other_positions (tuple[float, ...] | float): The positions of the other objects' anchor in the axes. Must have the same lengths as axes
        margins (tuple[float, ...] | float | None, optional): The margins between the anchors of both objects in
            meters. Must have the same lengths as axes. If None, no margin is used. Defaults to None.
        grid_margins (tuple[int, ...] | int | None, optional): The margins between the anchors of both objects
            in Yee-grid voxels. Must have the same lengths as axes. If none, no margin is used. Defaults to None.

    Returns:
        PositionConstraint: Positional constraint between this object and the other
    """
    if isinstance(axes, int):
        axes = (axes,)
    if isinstance(own_positions, int | float):
        own_positions = (float(own_positions),)
    if isinstance(other_positions, int | float):
        other_positions = (float(other_positions),)
    if isinstance(margins, int | float):
        margins = (float(margins),)
    if isinstance(grid_margins, int):
        grid_margins = (grid_margins,)
    if margins is None:
        margins = tuple([0 for _ in axes])
    if grid_margins is None:
        grid_margins = tuple([0 for _ in axes])
    if (
        len(axes) != len(own_positions)
        or len(axes) != len(other_positions)
        or len(axes) != len(margins)
        or len(axes) != len(grid_margins)
    ):
        raise Exception("All inputs should have same lengths")
    constraint = PositionConstraint(
        axes=axes,
        other_object=other,
        object=self,
        other_object_positions=other_positions,
        object_positions=own_positions,
        margins=margins,
        grid_margins=grid_margins,
    )
    return constraint

same_position_and_size

same_position_and_size(
    other: SimulationObject,
    axes: tuple[int, ...] | int = (0, 1, 2),
) -> tuple[PositionConstraint, SizeConstraint]

Creates both position and size constraints to make this object match another object's position and size. This is a convenience wrapper combining place_at_center() and same_size().

Parameters:
  • other (SimulationObject) –

    Another object in the simulation scene

  • axes (tuple[int, ...] | int, default: (0, 1, 2) ) –

    Either a single integer or a tuple describing which axes to match. Defaults to all axes (0, 1, 2).

Returns:
Source code in src/fdtdx/objects/object.py
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
def same_position_and_size(
    self,
    other: "SimulationObject",
    axes: tuple[int, ...] | int = (0, 1, 2),
) -> tuple[PositionConstraint, SizeConstraint]:
    """Creates both position and size constraints to make this object match another object's position and size.
    This is a convenience wrapper combining place_at_center() and same_size().

    Args:
        other (SimulationObject): Another object in the simulation scene
        axes (tuple[int, ...] | int, optional): Either a single integer or a tuple describing which axes to match.
            Defaults to all axes (0, 1, 2).

    Returns:
        tuple[PositionConstraint, SizeConstraint]: Position and size constraints for matching objects
    """
    size_constraint = self.same_size(
        other=other,
        axes=axes,
    )
    pos_constraint = self.place_at_center(
        other=other,
        axes=axes,
    )
    return pos_constraint, size_constraint

same_size

same_size(
    other: SimulationObject,
    axes: tuple[int, ...] | int = (0, 1, 2),
    offsets: tuple[float, ...] | float | None = None,
    grid_offsets: tuple[int, ...] | int | None = None,
) -> SizeConstraint

Creates a SizeConstraint that makes this object the same size as another object along specified axes. This is a convenience wrapper around size_relative_to() with proportions set to 1.0.

Parameters:
  • other (SimulationObject) –

    Another object in the simulation scene

  • axes (tuple[int, ...] | int, default: (0, 1, 2) ) –

    Either a single integer or a tuple describing which axes should have the same size. Defaults to all axes (0, 1, 2).

  • offsets (tuple[float, ...] | float | None, default: None ) –

    Additional size offsets in meters to apply. Must have same length as axes. If None, no offset is used. Defaults to None.

  • grid_offsets (tuple[int, ...] | int | None, default: None ) –

    Additional size offsets in Yee-grid voxels to apply. Must have same length as axes. If None, no offset is used. Defaults to None.

Returns:
  • SizeConstraint( SizeConstraint ) –

    Size constraint ensuring equal sizes between objects

Source code in src/fdtdx/objects/object.py
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
def same_size(
    self,
    other: "SimulationObject",
    axes: tuple[int, ...] | int = (0, 1, 2),
    offsets: tuple[float, ...] | float | None = None,
    grid_offsets: tuple[int, ...] | int | None = None,
) -> SizeConstraint:
    """Creates a SizeConstraint that makes this object the same size as another object along specified axes.
    This is a convenience wrapper around size_relative_to() with proportions set to 1.0.

    Args:
        other (SimulationObject): Another object in the simulation scene
        axes (tuple[int, ...] | int, optional): Either a single integer or a tuple describing which axes should
            have the same size. Defaults to all axes (0, 1, 2).
        offsets (tuple[float, ...] | float | None, optional): Additional size offsets in meters to apply.
            Must have same length as axes. If None, no offset is used. Defaults to None.
        grid_offsets (tuple[int, ...] | int | None, optional): Additional size offsets in Yee-grid voxels to
            apply. Must have same length as axes. If None, no offset is used. Defaults to None.

    Returns:
        SizeConstraint: Size constraint ensuring equal sizes between objects
    """
    if isinstance(axes, int):
        axes = (axes,)
    proportions = tuple([1 for _ in axes])
    constraint = self.size_relative_to(
        other=other,
        axes=axes,
        proportions=proportions,
        offsets=offsets,
        grid_offsets=grid_offsets,
    )
    return constraint

set_grid_coordinates

set_grid_coordinates(
    axes: tuple[int, ...] | int,
    sides: (
        tuple[Literal["+", "-"], ...] | Literal["+", "-"]
    ),
    coordinates: tuple[int, ...] | int,
) -> GridCoordinateConstraint

Creates a GridCoordinateConstraint that forces specific sides of this object to align with given grid coordinates. Used for precise positioning in the discretized simulation space.

Parameters:
  • axes (tuple[int, ...] | int) –

    Either a single integer or a tuple describing which axes to constrain

  • sides (tuple[Literal['+', '-'], ...] | Literal['+', '-']) –

    Either a single string or a tuple of strings ('+' or '-') indicating which side of each axis to constrain. Must have same length as axes.

  • coordinates (tuple[int, ...] | int) –

    Either a single integer or a tuple of integers specifying the grid coordinates to align with. Must have same length as axes.

Returns:
Source code in src/fdtdx/objects/object.py
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
def set_grid_coordinates(
    self,
    axes: tuple[int, ...] | int,
    sides: tuple[Literal["+", "-"], ...] | Literal["+", "-"],
    coordinates: tuple[int, ...] | int,
) -> GridCoordinateConstraint:
    """Creates a GridCoordinateConstraint that forces specific sides of this object to align with
    given grid coordinates. Used for precise positioning in the discretized simulation space.

    Args:
        axes (tuple[int, ...] | int): Either a single integer or a tuple describing which axes to constrain
        sides (tuple[Literal["+", "-"], ...] | Literal["+", "-"]): Either a single string or a tuple of strings
            ('+' or '-') indicating which side of each axis to constrain. Must have same length as axes.
        coordinates (tuple[int, ...] | int): Either a single integer or a tuple of integers specifying the
            grid coordinates to align with. Must have same length as axes.

    Returns:
        GridCoordinateConstraint: Constraint forcing alignment with specific grid coordinates
    """
    if isinstance(axes, int):
        axes = (axes,)
    if isinstance(sides, str):
        sides = (sides,)
    if isinstance(coordinates, int):
        coordinates = (coordinates,)
    if len(axes) != len(sides) or len(axes) != len(coordinates):
        raise Exception("All inputs need to have the same lengths!")
    return GridCoordinateConstraint(
        object=self,
        axes=axes,
        sides=sides,
        coordinates=coordinates,
    )

set_real_coordinates

set_real_coordinates(
    axes: tuple[int, ...] | int,
    sides: (
        tuple[Literal["+", "-"], ...] | Literal["+", "-"]
    ),
    coordinates: tuple[float, ...] | float,
) -> RealCoordinateConstraint

Creates a RealCoordinateConstraint that forces specific sides of this object to align with given real-space coordinates. Used for precise positioning in physical units.

Parameters:
  • axes (tuple[int, ...] | int) –

    Either a single integer or a tuple describing which axes to constrain

  • sides (tuple[Literal['+', '-'], ...] | Literal['+', '-']) –

    Either a single string or a tuple of strings ('+' or '-') indicating which side of each axis to constrain. Must have same length as axes.

  • coordinates (tuple[float, ...] | float) –

    Either a single float or a tuple of floats specifying the real-space coordinates in meters to align with. Must have same length as axes.

Returns:
  • RealCoordinateConstraint( RealCoordinateConstraint ) –

    Constraint forcing alignment with specific real-space coordinates

Source code in src/fdtdx/objects/object.py
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
def set_real_coordinates(
    self,
    axes: tuple[int, ...] | int,
    sides: tuple[Literal["+", "-"], ...] | Literal["+", "-"],
    coordinates: tuple[float, ...] | float,
) -> RealCoordinateConstraint:
    """Creates a RealCoordinateConstraint that forces specific sides of this object to align with
    given real-space coordinates. Used for precise positioning in physical units.

    Args:
        axes (tuple[int, ...] | int): Either a single integer or a tuple describing which axes to constrain
        sides (tuple[Literal["+", "-"], ...] | Literal["+", "-"]): Either a single string or a tuple of
            strings ('+' or '-') indicating which side of each axis to constrain. Must have same length as axes.
        coordinates (tuple[float, ...] | float): Either a single float or a tuple of floats specifying the
            real-space coordinates in meters to align with. Must have same length as axes.

    Returns:
        RealCoordinateConstraint: Constraint forcing alignment with specific real-space coordinates
    """
    if isinstance(axes, int):
        axes = (axes,)
    if isinstance(sides, str):
        sides = (sides,)
    if isinstance(coordinates, int | float):
        coordinates = (float(coordinates),)
    if len(axes) != len(sides) or len(axes) != len(coordinates):
        raise Exception("All inputs need to have the same lengths!")
    return RealCoordinateConstraint(
        object=self,
        axes=axes,
        sides=sides,
        coordinates=coordinates,
    )

size_relative_to

size_relative_to(
    other: SimulationObject,
    axes: tuple[int, ...] | int,
    other_axes: tuple[int, ...] | int | None = None,
    proportions: tuple[float, ...] | float | None = None,
    offsets: tuple[float, ...] | float | None = None,
    grid_offsets: tuple[int, ...] | int | None = None,
) -> SizeConstraint

Creates a SizeConstraint between two objects. The constraint defines the size of this object relative to another object, allowing for proportional scaling and offsets in specified axes.

Parameters:
  • other (SimulationObject) –

    Another object in the simulation scene

  • axes (tuple[int, ...] | int) –

    Either a single integer or a tuple describing which axes of this object to constrain.

  • other_axes (tuple[int, ...] | int | None, default: None ) –

    Either a single integer or a tuple describing which axes of the other object to reference. If None, uses the same axes as specified in 'axes'. Defaults to None.

  • proportions (tuple[float, ...] | float | None, default: None ) –

    Scale factors to apply to the other object's dimensions. Must have same length as axes. If None, uses 1.0 (same size). Defaults to None.

  • offsets (tuple[float, ...] | float | None, default: None ) –

    Additional size offsets in meters to apply after scaling. Must have same length as axes. If None, no offset is used. Defaults to None.

  • grid_offsets (tuple[int, ...] | int | None, default: None ) –

    Additional size offsets in Yee-grid voxels to apply after scaling. Must have same length as axes. If None, no offset is used. Defaults to None.

Returns:
  • SizeConstraint( SizeConstraint ) –

    Size constraint between this object and the other

Source code in src/fdtdx/objects/object.py
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
def size_relative_to(
    self,
    other: "SimulationObject",
    axes: tuple[int, ...] | int,
    other_axes: tuple[int, ...] | int | None = None,
    proportions: tuple[float, ...] | float | None = None,
    offsets: tuple[float, ...] | float | None = None,
    grid_offsets: tuple[int, ...] | int | None = None,
) -> SizeConstraint:
    """Creates a SizeConstraint between two objects. The constraint defines the size of this object relative
    to another object, allowing for proportional scaling and offsets in specified axes.

    Args:
        other (SimulationObject): Another object in the simulation scene
        axes (tuple[int, ...] | int): Either a single integer or a tuple describing which axes of this object to
            constrain.
        other_axes (tuple[int, ...] | int | None, optional): Either a single integer or a tuple describing which
            axes of the other object to reference. If None, uses the same axes as specified in 'axes'. Defaults
            to None.
        proportions (tuple[float, ...] | float | None, optional): Scale factors to apply to the other object's
            dimensions. Must have same length as axes. If None, uses 1.0 (same size). Defaults to None.
        offsets (tuple[float, ...] | float | None, optional): Additional size offsets in meters to apply after
            scaling. Must have same length as axes. If None, no offset is used. Defaults to None.
        grid_offsets (tuple[int, ...] | int | None, optional): Additional size offsets in Yee-grid voxels to
            apply after scaling. Must have same length as axes. If None, no offset is used. Defaults to None.

    Returns:
        SizeConstraint: Size constraint between this object and the other
    """
    if isinstance(axes, int):
        axes = (axes,)
    if isinstance(other_axes, int):
        other_axes = (other_axes,)
    if isinstance(proportions, int | float):
        proportions = (float(proportions),)
    if isinstance(offsets, int | float):
        offsets = (offsets,)
    if isinstance(grid_offsets, int):
        grid_offsets = (grid_offsets,)
    if offsets is None:
        offsets = tuple([0 for _ in axes])
    if grid_offsets is None:
        grid_offsets = tuple([0 for _ in axes])
    if proportions is None:
        proportions = tuple([1.0 for _ in axes])
    if other_axes is None:
        other_axes = tuple([a for a in axes])
    if len(axes) != len(proportions) or len(axes) != len(offsets) or len(axes) != len(grid_offsets):
        raise Exception("All inputs should have same lengths")
    constraint = SizeConstraint(
        other_object=other,
        object=self,
        axes=axes,
        other_axes=other_axes,
        proportions=proportions,
        offsets=offsets,
        grid_offsets=grid_offsets,
    )
    return constraint