Base Classes¶
Core Classes¶
fdtdx.objects.object.SimulationObject
¶
Bases: ExtendedTreeClass
, ABC
Source code in src/fdtdx/objects/object.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 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 336 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 396 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 430 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 474 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 500 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 535 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 570 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 597 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 624 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 658 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 692 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 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
|
extend_to(other, axis, direction, other_position=None, offset=0, grid_offset=0)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
other
|
Optional[SimulationObject]
|
Target object to extend to, or None to extend to simulation boundary |
required |
axis
|
int
|
Which axis to extend along (0, 1, or 2) |
required |
direction
|
Literal['+', '-']
|
Direction to extend in ('+' or '-') |
required |
other_position
|
float | 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) |
None
|
offset
|
float
|
Additional offset in meters to apply after extension. Ignored when extending to simulation boundary |
0
|
grid_offset
|
int
|
Additional offset in Yee-grid voxels to apply after extension. Ignored when extending to simulation boundary |
0
|
Returns:
Name | Type | Description |
---|---|---|
SizeExtensionConstraint |
SizeExtensionConstraint
|
Constraint defining how the object extends |
Source code in src/fdtdx/objects/object.py
face_to_face_negative_direction(other, axes, margins=None, grid_margins=None)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
other
|
SimulationObject
|
Another object in the simulation scene |
required |
axes
|
tuple[int, ...] | int
|
Either a single integer or a tuple describing which axes to align on |
required |
margins
|
tuple[float, ...] | float | None
|
Additional margins in meters between the facing surfaces. Must have same length as axes. If None, defaults to 0 |
None
|
grid_margins
|
tuple[int, ...] | int | None
|
Additional margins in Yee-grid voxels between the facing surfaces. Must have same length as axes. If None, defaults to 0 |
None
|
Returns:
Name | Type | Description |
---|---|---|
PositionConstraint |
PositionConstraint
|
Position constraint aligning objects face-to-face in negative direction |
Source code in src/fdtdx/objects/object.py
face_to_face_positive_direction(other, axes, margins=None, grid_margins=None)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
other
|
SimulationObject
|
Another object in the simulation scene |
required |
axes
|
tuple[int, ...] | int
|
Either a single integer or a tuple describing which axes to align on |
required |
margins
|
tuple[float, ...] | float | None
|
Additional margins in meters between the facing surfaces. Must have same length as axes. If None, defaults to 0 |
None
|
grid_margins
|
tuple[int, ...] | int | None
|
Additional margins in Yee-grid voxels between the facing surfaces. Must have same length as axes. If None, defaults to 0 |
None
|
Returns:
Name | Type | Description |
---|---|---|
PositionConstraint |
PositionConstraint
|
Position constraint aligning objects face-to-face in positive direction |
Source code in src/fdtdx/objects/object.py
place_above(other, margins=None, grid_margins=None)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
other
|
SimulationObject
|
Another object in the simulation scene |
required |
margins
|
tuple[float, ...] | float | None
|
Additional vertical margins in meters between objects. If None, defaults to 0 |
None
|
grid_margins
|
tuple[int, ...] | int | None
|
Additional vertical margins in Yee-grid voxels between objects. If None, defaults to 0 |
None
|
Returns:
Name | Type | Description |
---|---|---|
PositionConstraint |
PositionConstraint
|
Position constraint placing this object above the other |
Source code in src/fdtdx/objects/object.py
place_at_center(other, axes=(0, 1, 2), own_positions=None, other_positions=None, margins=None, grid_margins=None)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
other
|
SimulationObject
|
Another object in the simulation scene |
required |
axes
|
tuple[int, ...] | int
|
Either a single integer or a tuple describing which axes to center on. Defaults to all axes (0, 1, 2) |
(0, 1, 2)
|
own_positions
|
tuple[float, ...] | float | None
|
Relative positions on this object (-1 to 1). If None, defaults to center (0) |
None
|
other_positions
|
tuple[float, ...] | float | None
|
Relative positions on other object (-1 to 1). If None, defaults to center (0) |
None
|
margins
|
tuple[float, ...] | float | None
|
Additional margins in meters between objects. Must have same length as axes. If None, defaults to 0 |
None
|
grid_margins
|
tuple[int, ...] | int | None
|
Additional margins in Yee-grid voxels between objects. Must have same length as axes. If None, defaults to 0 |
None
|
Returns:
Name | Type | Description |
---|---|---|
PositionConstraint |
PositionConstraint
|
Position constraint centering objects relative to each other |
Source code in src/fdtdx/objects/object.py
place_below(other, margins=None, grid_margins=None)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
other
|
SimulationObject
|
Another object in the simulation scene |
required |
margins
|
tuple[float, ...] | float | None
|
Additional vertical margins in meters between objects. If None, defaults to 0 |
None
|
grid_margins
|
tuple[int, ...] | int | None
|
Additional vertical margins in Yee-grid voxels between objects. If None, defaults to 0 |
None
|
Returns:
Name | Type | Description |
---|---|---|
PositionConstraint |
PositionConstraint
|
Position constraint placing this object below the other |
Source code in src/fdtdx/objects/object.py
place_relative_to(other, axes, own_positions, other_positions, margins=None, grid_margins=None)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
other
|
SimulationObject
|
Another object in the simulation scene |
required |
axes
|
tuple[int, ...] | int
|
Eiter a single integer or a tuple describing the axes of the constraints |
required |
own_positions
|
tuple[float, ...] | float
|
The positions of the own anchor in the axes. Must have the same lengths as axes |
required |
other_positions
|
tuple[float, ...] | float
|
The positions of the other objects' anchor in the axes. Must have the same lengths as axes |
required |
margins
|
tuple[float, ...] | float | None
|
The margins between the anchors of both objects in meters. Must have the same lengths as axes. Defaults to no margin |
None
|
grid_margins
|
tuple[int, ...] | int | None
|
The margins between the anchors of both objects in Yee-grid voxels. Must have the same lengths as axes. Defaults to no margin |
None
|
Returns:
Name | Type | Description |
---|---|---|
PositionConstraint |
PositionConstraint
|
Positional constraint between this object and the other |
Source code in src/fdtdx/objects/object.py
same_position_and_size(other, axes=(0, 1, 2))
¶
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:
Name | Type | Description | Default |
---|---|---|---|
other
|
SimulationObject
|
Another object in the simulation scene |
required |
axes
|
tuple[int, ...] | int
|
Either a single integer or a tuple describing which axes to match. Defaults to all axes (0, 1, 2) |
(0, 1, 2)
|
Returns:
Type | Description |
---|---|
tuple[PositionConstraint, SizeConstraint]
|
tuple[PositionConstraint, SizeConstraint]: Position and size constraints for matching objects |
Source code in src/fdtdx/objects/object.py
same_size(other, axes=(0, 1, 2), offsets=None, grid_offsets=None)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
other
|
SimulationObject
|
Another object in the simulation scene |
required |
axes
|
tuple[int, ...] | int
|
Either a single integer or a tuple describing which axes should have the same size. Defaults to all axes (0, 1, 2) |
(0, 1, 2)
|
offsets
|
tuple[float, ...] | float | None
|
Additional size offsets in meters to apply. Must have same length as axes. If None, defaults to 0 |
None
|
grid_offsets
|
tuple[int, ...] | int | None
|
Additional size offsets in Yee-grid voxels to apply. Must have same length as axes. If None, defaults to 0 |
None
|
Returns:
Name | Type | Description |
---|---|---|
SizeConstraint |
SizeConstraint
|
Size constraint ensuring equal sizes between objects |
Source code in src/fdtdx/objects/object.py
set_grid_coordinates(axes, sides, coordinates)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
axes
|
tuple[int, ...] | int
|
Either a single integer or a tuple describing which axes to constrain |
required |
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 |
required |
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 |
required |
Returns:
Name | Type | Description |
---|---|---|
GridCoordinateConstraint |
GridCoordinateConstraint
|
Constraint forcing alignment with specific grid coordinates |
Source code in src/fdtdx/objects/object.py
set_real_coordinates(axes, sides, coordinates)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
axes
|
tuple[int, ...] | int
|
Either a single integer or a tuple describing which axes to constrain |
required |
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 |
required |
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 |
required |
Returns:
Name | Type | Description |
---|---|---|
RealCoordinateConstraint |
RealCoordinateConstraint
|
Constraint forcing alignment with specific real-space coordinates |
Source code in src/fdtdx/objects/object.py
size_relative_to(other, axes, other_axes=None, proportions=None, offsets=None, grid_offsets=None)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
other
|
SimulationObject
|
Another object in the simulation scene |
required |
axes
|
tuple[int, ...] | int
|
Either a single integer or a tuple describing which axes of this object to constrain |
required |
other_axes
|
tuple[int, ...] | int | 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' |
None
|
proportions
|
tuple[float, ...] | float | None
|
Scale factors to apply to the other object's dimensions. Must have same length as axes. If None, defaults to 1.0 (same size) |
None
|
offsets
|
tuple[float, ...] | float | None
|
Additional size offsets in meters to apply after scaling. Must have same length as axes. If None, defaults to 0 |
None
|
grid_offsets
|
tuple[int, ...] | int | None
|
Additional size offsets in Yee-grid voxels to apply after scaling. Must have same length as axes. If None, defaults to 0 |
None
|
Returns:
Name | Type | Description |
---|---|---|
SizeConstraint |
SizeConstraint
|
Size constraint between this object and the other |
Source code in src/fdtdx/objects/object.py
334 335 336 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 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
|
Base class for all simulation objects with positioning and sizing capabilities.
fdtdx.objects.object.UniqueName
¶
Bases: ExtendedTreeClass
Generates unique names for simulation objects.
A utility class that ensures each simulation object gets a unique name by maintaining a global counter. If no name is provided, generates names in the format "Object_N" where N is an incrementing counter.
Source code in src/fdtdx/objects/object.py
__call__(x)
¶
Generate a unique name if none is provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
str | None
|
The proposed name or None |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Either the input name if provided, or a new unique name |
Source code in src/fdtdx/objects/object.py
Utility for generating unique object identifiers.
Positioning Constraints¶
fdtdx.objects.object.PositionConstraint
dataclass
¶
Defines a positional relationship between two simulation objects.
A constraint that positions one object relative to another, with optional margins and offsets. Used to specify how objects should be placed in the simulation volume relative to each other.
Attributes:
Name | Type | Description |
---|---|---|
object |
SimulationObject
|
The "child" object whose position is being adjusted |
other_object |
SimulationObject
|
The "parent" object that serves as reference |
axes |
tuple[int, ...]
|
Which axes (x,y,z) this constraint applies to |
object_positions |
tuple[float, ...]
|
Relative positions on child object (-1 to 1) |
other_object_positions |
tuple[float, ...]
|
Relative positions on parent object (-1 to 1) |
margins |
tuple[float, ...]
|
Optional real-space margins between objects |
grid_margins |
tuple[int, ...]
|
Optional grid-space margins between objects |
Source code in src/fdtdx/objects/object.py
Defines relative positioning between simulation objects.
fdtdx.objects.object.SizeConstraint
dataclass
¶
Defines a size relationship between two simulation objects.
A constraint that sets the size of one object relative to another, with optional proportions and offsets. Used to specify how objects should be sized relative to each other in the simulation.
Attributes:
Name | Type | Description |
---|---|---|
object |
SimulationObject
|
The "child" object whose size is being adjusted |
other_object |
SimulationObject
|
The "parent" object that serves as reference |
axes |
tuple[int, ...]
|
Which axes of the child to constrain |
other_axes |
tuple[int, ...]
|
Which axes of the parent to reference |
proportions |
tuple[float, ...]
|
Size multipliers relative to parent |
offsets |
tuple[float, ...]
|
Additional real-space size offsets |
grid_offsets |
tuple[int, ...]
|
Additional grid-space size offsets |
Source code in src/fdtdx/objects/object.py
Controls size relationships between objects.
fdtdx.objects.object.SizeExtensionConstraint
dataclass
¶
Defines how an object extends toward another object or boundary.
A constraint that extends one object's size until it reaches another object or the simulation boundary. Can extend in positive or negative direction along an axis.
Attributes:
Name | Type | Description |
---|---|---|
object |
SimulationObject
|
The object being extended |
other_object |
Optional[SimulationObject]
|
Optional target object to extend to |
axis |
int
|
Which axis to extend along |
direction |
Literal['+', '-']
|
Direction to extend ('+' or '-') |
other_position |
float
|
Relative position on target (-1 to 1) |
offset |
float
|
Additional real-space offset |
grid_offset |
int
|
Additional grid-space offset |
Source code in src/fdtdx/objects/object.py
Extends objects to reach other objects or boundaries.
fdtdx.objects.object.GridCoordinateConstraint
dataclass
¶
Constrains an object's position to specific grid coordinates.
Forces specific sides of an object to align with given grid coordinates. Used for precise positioning in the discretized simulation space.
Attributes:
Name | Type | Description |
---|---|---|
object |
SimulationObject
|
The object to position |
axes |
tuple[int, ...]
|
Which axes to constrain |
sides |
tuple[Literal['+', '-'], ...]
|
Which side of each axis ('+' or '-') |
coordinates |
tuple[int, ...]
|
Grid coordinates to align with |
Source code in src/fdtdx/objects/object.py
Aligns objects to specific grid coordinates.
fdtdx.objects.object.RealCoordinateConstraint
dataclass
¶
Constrains an object's position to specific real-space coordinates.
Forces specific sides of an object to align with given real-space coordinates. Used for precise positioning in physical units.
Attributes:
Name | Type | Description |
---|---|---|
object |
SimulationObject
|
The object to position |
axes |
tuple[int, ...]
|
Which axes to constrain |
sides |
tuple[Literal['+', '-'], ...]
|
Which side of each axis ('+' or '-') |
coordinates |
tuple[float, ...]
|
Real-space coordinates to align with |
Source code in src/fdtdx/objects/object.py
Positions objects at specific physical coordinates.
Wavelength-Dependent Objects¶
fdtdx.objects.wavelength.WaveLengthDependentObject
¶
Bases: SimulationObject
, ABC
Base class for objects whose properties depend on wavelength/period.
An abstract base class for simulation objects that have wavelength-dependent behavior. Provides properties to handle either wavelength or period specification, ensuring only one is set at a time.
Attributes:
Name | Type | Description |
---|---|---|
_period |
float | None
|
Optional period in seconds. Mutually exclusive with _wavelength. |
_wavelength |
float | None
|
Optional wavelength in meters. Mutually exclusive with _period. |
Source code in src/fdtdx/objects/wavelength.py
frequency: float
property
¶
Gets the frequency in Hz.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The frequency in Hz, computed as 1/period. |
period: float
property
¶
Gets the period in seconds.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The period in seconds, either directly set or computed from wavelength. |
Raises:
Type | Description |
---|---|
Exception
|
If neither period nor wavelength is set, or if both are set. |
wavelength: float
property
¶
Gets the wavelength in meters.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The wavelength in meters, either directly set or computed from period. |
Raises:
Type | Description |
---|---|
Exception
|
If neither period nor wavelength is set, or if both are set. |
Base class for objects with wavelength/period-dependent properties.
fdtdx.objects.wavelength.WaveLengthDependentNoMaterial
¶
Bases: WaveLengthDependentObject
A wavelength-dependent object that doesn't modify material properties.
Implements WaveLengthDependentObject for cases where the object doesn't affect the permittivity or permeability of the simulation volume.
Source code in src/fdtdx/objects/wavelength.py
get_inv_permeability(prev_inv_permeability, params)
¶
Returns unchanged inverse permeability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prev_inv_permeability
|
Array
|
The existing inverse permeability array |
required |
params
|
dict[str, Array] | None
|
Optional parameter dictionary |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple[Array, dict]
|
(Unchanged inverse permeability array, Empty info dict) |
Source code in src/fdtdx/objects/wavelength.py
get_inv_permittivity(prev_inv_permittivity, params)
¶
Returns unchanged inverse permittivity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prev_inv_permittivity
|
Array
|
The existing inverse permittivity array |
required |
params
|
dict[str, Array] | None
|
Optional parameter dictionary |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple[Array, dict]
|
(Unchanged inverse permittivity array, Empty info dict) |
Source code in src/fdtdx/objects/wavelength.py
Non-material modifying wavelength-dependent object.