10. Base Classes for Operators
torchfsm.operator.LinearCoef
¤
Bases: ABC
Abstract class for linear coefficients.
Source code in torchfsm/operator/_base.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
__call__
abstractmethod
¤
__call__(
f_mesh: FourierMesh, n_channel: int
) -> FourierTensor["B C H ..."]
Abstract method to be implemented by subclasses. It should define the linear coefficient tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f_mesh
|
FourierMesh
|
Fourier mesh object. |
required |
n_channel
|
int
|
Number of channels of the input tensor. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FourierTensor |
FourierTensor['B C H ...']
|
Linear coefficient tensor. |
Source code in torchfsm/operator/_base.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
nonlinear_like
¤
nonlinear_like(
u_fft: FourierTensor["B C H ..."],
f_mesh: FourierMesh,
u: Optional[SpatialTensor["B C H ..."]] = None,
) -> FourierTensor["B C H ..."]
Calculate the result out based on the linear coefficient. It is designed to have same pattern as the nonlinear function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_fft
|
FourierTensor
|
Fourier-transformed input tensor. |
required |
f_mesh
|
FourierMesh
|
Fourier mesh object. |
required |
u
|
Optional[SpatialTensor]
|
Corresponding tensor of u_fft in spatial domain. This option aims to avoid repeating the inverse FFT operation in operators. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FourierTensor |
FourierTensor['B C H ...']
|
Nonlinear-like tensor. |
Source code in torchfsm/operator/_base.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
torchfsm.operator.NonlinearFunc
¤
Bases: ABC
Abstract class for nonlinear functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dealiasing_swtich
|
bool
|
Whether to apply dealiasing. Default is True. If True, the dealiased version of u_fft will be input to the function in operator. If False, the original u_fft will be used. |
True
|
Source code in torchfsm/operator/_base.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
__init__
¤
__init__(dealiasing_swtich: bool = True) -> None
Source code in torchfsm/operator/_base.py
69 70 | |
__call__
abstractmethod
¤
__call__(
u_fft: FourierTensor["B C H ..."],
f_mesh: FourierMesh,
u: Optional[SpatialTensor["B C H ..."]] = None,
) -> FourierTensor["B C H ..."]
Abstract method to be implemented by subclasses. It should define the nonlinear function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_fft
|
FourierTensor
|
Fourier-transformed input tensor. |
required |
f_mesh
|
FourierMesh
|
Fourier mesh object. |
required |
u
|
Optional[SpatialTensor]
|
Corresponding tensor of u_fft in spatial domain. This option aims to avoid repeating the inverse FFT operation in operators. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FourierTensor |
FourierTensor['B C H ...']
|
Result of the nonlinear function. |
Source code in torchfsm/operator/_base.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
spatial_value
¤
spatial_value(
u_fft: FourierTensor["B C H ..."],
f_mesh: FourierMesh,
u: Optional[SpatialTensor["B C H ..."]] = None,
) -> SpatialTensor["B C H ..."]
Return the result of the nonlinear function in spatial domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_fft
|
FourierTensor
|
Fourier-transformed input tensor. |
required |
f_mesh
|
FourierMesh
|
Fourier mesh object. |
required |
u
|
Optional[SpatialTensor]
|
Corresponding tensor of u_fft in spatial domain. This option aims to avoid repeating the inverse FFT operation in operators. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
SpatialTensor |
SpatialTensor['B C H ...']
|
Result of the nonlinear function in spatial domain. |
Source code in torchfsm/operator/_base.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
torchfsm.operator.CoreGenerator
¤
Bases: ABC
Abstract class for core generator. A core generator is a callable that generates a linear coefficient or a nonlinear function based on the Fourier mesh and channels of the tensor.
Source code in torchfsm/operator/_base.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
__call__
abstractmethod
¤
__call__(
f_mesh: FourierMesh, n_channel: int
) -> Union[LinearCoef, NonlinearFunc]
Abstract method to be implemented by subclasses. It should define the core generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f_mesh
|
FourierMesh
|
Fourier mesh object. |
required |
n_channel
|
int
|
Number of channels of the input tensor. |
required |
Returns:
| Type | Description |
|---|---|
Union[LinearCoef, NonlinearFunc]
|
Union[LinearCoef, NonlinearFunc]: Linear coefficient or nonlinear function. |
Source code in torchfsm/operator/_base.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
torchfsm.operator._base._MutableMixIn
¤
Mixin class for mutable operations. This class supports basic arithmetic operations for the operator.
Source code in torchfsm/operator/_base.py
171 172 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 | |
__radd__
¤
__radd__(other)
Source code in torchfsm/operator/_base.py
176 177 | |
__iadd__
¤
__iadd__(other)
Source code in torchfsm/operator/_base.py
179 180 | |
__sub__
¤
__sub__(other)
Source code in torchfsm/operator/_base.py
182 183 184 185 186 | |
__rsub__
¤
__rsub__(other)
Source code in torchfsm/operator/_base.py
188 189 190 191 192 | |
__isub__
¤
__isub__(other)
Source code in torchfsm/operator/_base.py
194 195 | |
__rmul__
¤
__rmul__(other)
Source code in torchfsm/operator/_base.py
197 198 | |
__imul__
¤
__imul__(other)
Source code in torchfsm/operator/_base.py
200 201 | |
__truediv__
¤
__truediv__(other)
Source code in torchfsm/operator/_base.py
203 204 205 206 207 | |
torchfsm.operator._base._InverseSolveMixin
¤
Source code in torchfsm/operator/_base.py
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 | |
register_mesh
instance-attribute
¤
register_mesh: Callable
Mixin class for inverse solving operations. This class supports solving the linear operator equation.
solve
¤
solve(
b: Optional[Tensor] = None,
b_fft: Optional[Tensor] = None,
mesh: Optional[
Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
]
] = None,
n_channel: Optional[int] = None,
return_in_fourier=False,
) -> Union[
SpatialTensor["B C H ..."], SpatialTensor["B C H ..."]
]
Solve the linear operator equation \(Ax = b\), where \(A\) is the linear operator and \(b\) is the right-hand side.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
Optional[Tensor]
|
Right-hand side tensor in spatial domain. If None, b_fft should be provided. |
None
|
b_fft
|
Optional[Tensor]
|
Right-hand side tensor in Fourier domain. If None, b should be provided. |
None
|
mesh
|
Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]
|
Mesh information or mesh object. If None, the mesh registered in the operator will be used. |
None
|
n_channel
|
Optional[int]
|
Number of channels of \(x\). If None, the number of channels registered in the operator will be used. |
None
|
return_in_fourier
|
bool
|
If True, return the result in Fourier domain. If False, return the result in spatial domain. |
False
|
Returns:
| Type | Description |
|---|---|
Union[SpatialTensor['B C H ...'], SpatialTensor['B C H ...']]
|
Union[SpatialTensor["B C H ..."], FourierTensor["B C H ..."]]: Solution tensor in spatial or Fourier domain. |
Source code in torchfsm/operator/_base.py
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 | |
torchfsm.operator._base._DeAliasMixin
¤
Source code in torchfsm/operator/_base.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
set_de_aliasing_rate
¤
set_de_aliasing_rate(de_aliasing_rate: float)
Set the de-aliasing rate for the nonlinear operator. Args: de_aliasing_rate (float): De-aliasing rate. Default is ⅔.
Source code in torchfsm/operator/_base.py
274 275 276 277 278 279 280 281 282 | |
torchfsm.operator.OperatorLike
¤
Bases: _MutableMixIn
Base class for All Operators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator_cores
|
Optional[ValueList[Union[LinearCoef, NonlinearFunc, GeneratorLike]]]
|
List of operator generators/LinearCoef/NonLinearFunc. Default is None. that represent the real manipulations. |
None
|
coefs
|
Optional[List]
|
List of coefficients for each operator_core. Default is None. If None, all coefficients are set to 1. The length of the list should match the number of operator_core. |
None
|
Source code in torchfsm/operator/_base.py
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 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | |
is_linear
property
¤
is_linear: bool
Check if the operator is linear.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the operator is linear, False otherwise. |
__radd__
¤
__radd__(other)
Source code in torchfsm/operator/_base.py
176 177 | |
__iadd__
¤
__iadd__(other)
Source code in torchfsm/operator/_base.py
179 180 | |
__sub__
¤
__sub__(other)
Source code in torchfsm/operator/_base.py
182 183 184 185 186 | |
__rsub__
¤
__rsub__(other)
Source code in torchfsm/operator/_base.py
188 189 190 191 192 | |
__isub__
¤
__isub__(other)
Source code in torchfsm/operator/_base.py
194 195 | |
__rmul__
¤
__rmul__(other)
Source code in torchfsm/operator/_base.py
197 198 | |
__imul__
¤
__imul__(other)
Source code in torchfsm/operator/_base.py
200 201 | |
__truediv__
¤
__truediv__(other)
Source code in torchfsm/operator/_base.py
203 204 205 206 207 | |
__init__
¤
__init__(
operator_cores: Optional[
ValueList[
Union[LinearCoef, NonlinearFunc, GeneratorLike]
]
] = None,
coefs: Optional[List] = None,
) -> None
Source code in torchfsm/operator/_base.py
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 | |
register_mesh
¤
register_mesh(
mesh: Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
],
n_channel: int,
device=None,
dtype=None,
)
Register the mesh and number of channels for the operator. Once a mesh is registered, mesh information is not required for integration and operator call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]
|
Mesh information or mesh object. |
required |
n_channel
|
int
|
Number of channels of the input tensor. |
required |
device
|
Optional[device]
|
Device to which the mesh should be moved. Default is None. |
None
|
dtype
|
Optional[dtype]
|
Data type of the mesh. Default is None. |
None
|
Source code in torchfsm/operator/_base.py
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 | |
register_additional_check
¤
register_additional_check(func: Callable[[int, int], bool])
Register an additional check function for the value and mesh compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[int, int], bool]
|
Function that takes the dimension of the value and mesh as input and returns a boolean indicating whether they are compatible. |
required |
Source code in torchfsm/operator/_base.py
635 636 637 638 639 640 641 642 | |
add_core
¤
add_core(
core: Union[LinearCoef, NonlinearFunc, GeneratorLike],
coef=1,
)
Add a generator to the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
core
|
Union[LinearCoef, NonlinearFunc, GeneratorLike]
|
Core to be added. |
required |
coef
|
float
|
Coefficient for the generator. Default is 1. |
1
|
Source code in torchfsm/operator/_base.py
644 645 646 647 648 649 650 651 652 653 | |
set_integrator
¤
set_integrator(
integrator: Union[
Literal["auto"],
ETDRKIntegrator,
SETDRKIntegrator,
RKIntegrator,
],
**integrator_config
)
Set the integrator for the operator. The integrator is used for time integration of the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integrator
|
Union[Literal['auto'], ETDRKIntegrator, SETDRKIntegrator, RKIntegrator]
|
Integrator to be used. If "auto", the integrator will be chosen automatically based on the operator type. If "auto", the integrator will be set as ETDRKIntegrator.ETDRK0 for linear operators and ETDRKIntegrator.ETDRK2 for nonlinear operators. |
required |
**integrator_config
|
Additional configuration for the integrator. |
{}
|
Source code in torchfsm/operator/_base.py
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 | |
set_default_nonlinear_integrator
¤
set_default_nonlinear_integrator(
integrator: Union[
ETDRKIntegrator, SETDRKIntegrator, RKIntegrator
],
**integrator_config
)
Set the default nonlinear integrator for the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integrator
|
Union[ETDRKIntegrator, SETDRKIntegrator, RKIntegrator]
|
Integrator to be used. |
required |
**integrator_config
|
Additional configuration for the integrator. |
{}
|
Source code in torchfsm/operator/_base.py
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
integrate
¤
integrate(
u_0: Optional[Tensor] = None,
u_0_fft: Optional[Tensor] = None,
dt: float = 1,
step: int = 1,
mesh: Optional[
Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
]
] = None,
progressive: bool = False,
trajectory_recorder: Optional[_TrajRecorder] = None,
return_in_fourier: bool = False,
nan_check: bool = False,
) -> Union[
SpatialTensor["B C H ..."],
SpatialTensor["B T C H ..."],
FourierTensor["B C H ..."],
FourierTensor["B T C H ..."],
]
Integrate the operator using the provided initial condition and time step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_0
|
Optional[Tensor]
|
Initial condition in spatial domain. Default is None. |
None
|
u_0_fft
|
Optional[Tensor]
|
Initial condition in Fourier domain. Default is None. At least one of u_0 or u_0_fft should be provided. |
None
|
dt
|
float
|
Time step for the integrator. Default is 1. |
1
|
step
|
int
|
Number of time steps to integrate. Default is 1. |
1
|
mesh
|
Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]
|
Mesh information or mesh object. Default is None.
If None, the mesh registered in the operator will be used. You can use |
None
|
progressive
|
bool
|
If True, show a progress bar during integration. Default is False. |
False
|
trajectory_recorder
|
Optional[_TrajRecorder]
|
Trajectory recorder for recording the trajectory during integration. Default is None. If None, no trajectory will be recorded. The function will only return the final frame. |
None
|
return_in_fourier
|
bool
|
If True, return the result in Fourier domain. If False, return the result in spatial domain. Default is False. |
False
|
nan_check
|
bool
|
If True, check for NaN values in the result. If NaN values are found, raise a NanSimulationError. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[SpatialTensor['B C H ...'], SpatialTensor['B T C H ...'], FourierTensor['B C H ...'], FourierTensor['B T C H ...']]
|
Union[SpatialTensor["B C H ..."], SpatialTensor["B T C H ..."], FourierTensor["B C H ..."], FourierTensor["B T C H ..."]]: Integrated result in spatial or Fourier domain. If trajectory_recorder is provided, the result will be a trajectory tensor of shape (B, T, C, H, ...). Otherwise, the result will be a tensor of shape (B, C, H, ...). If return_in_fourier is True, the result will be in Fourier domain. Otherwise, it will be in spatial domain. |
Source code in torchfsm/operator/_base.py
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 | |
__call__
¤
__call__(
u: Optional[SpatialTensor["B C H ..."]] = None,
u_fft: Optional[FourierTensor["B C H ..."]] = None,
mesh: Optional[
Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
]
] = None,
return_in_fourier=False,
) -> Union[
SpatialTensor["B C H ..."], FourierTensor["B C H ..."]
]
Call the operator with the provided input tensor. The operator will apply the linear coefficient and nonlinear function to the input tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Optional[SpatialTensor]
|
Input tensor in spatial domain. Default is None. |
None
|
u_fft
|
Optional[FourierTensor]
|
Input tensor in Fourier domain. Default is None. At least one of u or u_fft should be provided. |
None
|
mesh
|
Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]
|
Mesh information or mesh object. Default is None.
If None, the mesh registered in the operator will be used. You can use |
None
|
return_in_fourier
|
bool
|
If True, return the result in Fourier domain. If False, return the result in spatial domain. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[SpatialTensor['B C H ...'], FourierTensor['B C H ...']]
|
Union[SpatialTensor["B C H ..."], FourierTensor["B C H ..."]]: Result of the operator in spatial or Fourier domain. |
Source code in torchfsm/operator/_base.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | |
to
¤
to(device=None, dtype=None)
Move the operator to the specified device and change the data type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Optional[device]
|
Device to which the operator should be moved. Default is None. |
None
|
dtype
|
Optional[dtype]
|
Data type of the operator. Default is None. |
None
|
Source code in torchfsm/operator/_base.py
835 836 837 838 839 840 841 842 843 844 845 846 847 | |
torchfsm.operator.Operator
¤
Bases: OperatorLike, _DeAliasMixin
Operator class for linear and nonlinear operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator_cores
|
Optional[ValueList[Union[LinearCoef, NonlinearFunc, GeneratorLike]]]
|
List of operator generators/LinearCoef/NonLinearFunc. Default is None. that represent the real manipulations. |
None
|
coefs
|
Optional[List]
|
List of coefficients for each operator_core. Default is None. If None, all coefficients are set to 1. The length of the list should match the number of operator_core. |
None
|
Source code in torchfsm/operator/_base.py
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 | |
is_linear
property
¤
is_linear: bool
Check if the operator is linear.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the operator is linear, False otherwise. |
set_de_aliasing_rate
¤
set_de_aliasing_rate(de_aliasing_rate: float)
Set the de-aliasing rate for the nonlinear operator. Args: de_aliasing_rate (float): De-aliasing rate. Default is ⅔.
Source code in torchfsm/operator/_base.py
274 275 276 277 278 279 280 281 282 | |
__radd__
¤
__radd__(other)
Source code in torchfsm/operator/_base.py
176 177 | |
__iadd__
¤
__iadd__(other)
Source code in torchfsm/operator/_base.py
179 180 | |
__sub__
¤
__sub__(other)
Source code in torchfsm/operator/_base.py
182 183 184 185 186 | |
__rsub__
¤
__rsub__(other)
Source code in torchfsm/operator/_base.py
188 189 190 191 192 | |
__isub__
¤
__isub__(other)
Source code in torchfsm/operator/_base.py
194 195 | |
__rmul__
¤
__rmul__(other)
Source code in torchfsm/operator/_base.py
197 198 | |
__imul__
¤
__imul__(other)
Source code in torchfsm/operator/_base.py
200 201 | |
__truediv__
¤
__truediv__(other)
Source code in torchfsm/operator/_base.py
203 204 205 206 207 | |
register_mesh
¤
register_mesh(
mesh: Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
],
n_channel: int,
device=None,
dtype=None,
)
Register the mesh and number of channels for the operator. Once a mesh is registered, mesh information is not required for integration and operator call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]
|
Mesh information or mesh object. |
required |
n_channel
|
int
|
Number of channels of the input tensor. |
required |
device
|
Optional[device]
|
Device to which the mesh should be moved. Default is None. |
None
|
dtype
|
Optional[dtype]
|
Data type of the mesh. Default is None. |
None
|
Source code in torchfsm/operator/_base.py
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 | |
register_additional_check
¤
register_additional_check(func: Callable[[int, int], bool])
Register an additional check function for the value and mesh compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[int, int], bool]
|
Function that takes the dimension of the value and mesh as input and returns a boolean indicating whether they are compatible. |
required |
Source code in torchfsm/operator/_base.py
635 636 637 638 639 640 641 642 | |
add_core
¤
add_core(
core: Union[LinearCoef, NonlinearFunc, GeneratorLike],
coef=1,
)
Add a generator to the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
core
|
Union[LinearCoef, NonlinearFunc, GeneratorLike]
|
Core to be added. |
required |
coef
|
float
|
Coefficient for the generator. Default is 1. |
1
|
Source code in torchfsm/operator/_base.py
644 645 646 647 648 649 650 651 652 653 | |
set_integrator
¤
set_integrator(
integrator: Union[
Literal["auto"],
ETDRKIntegrator,
SETDRKIntegrator,
RKIntegrator,
],
**integrator_config
)
Set the integrator for the operator. The integrator is used for time integration of the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integrator
|
Union[Literal['auto'], ETDRKIntegrator, SETDRKIntegrator, RKIntegrator]
|
Integrator to be used. If "auto", the integrator will be chosen automatically based on the operator type. If "auto", the integrator will be set as ETDRKIntegrator.ETDRK0 for linear operators and ETDRKIntegrator.ETDRK2 for nonlinear operators. |
required |
**integrator_config
|
Additional configuration for the integrator. |
{}
|
Source code in torchfsm/operator/_base.py
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 | |
set_default_nonlinear_integrator
¤
set_default_nonlinear_integrator(
integrator: Union[
ETDRKIntegrator, SETDRKIntegrator, RKIntegrator
],
**integrator_config
)
Set the default nonlinear integrator for the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integrator
|
Union[ETDRKIntegrator, SETDRKIntegrator, RKIntegrator]
|
Integrator to be used. |
required |
**integrator_config
|
Additional configuration for the integrator. |
{}
|
Source code in torchfsm/operator/_base.py
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
integrate
¤
integrate(
u_0: Optional[Tensor] = None,
u_0_fft: Optional[Tensor] = None,
dt: float = 1,
step: int = 1,
mesh: Optional[
Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
]
] = None,
progressive: bool = False,
trajectory_recorder: Optional[_TrajRecorder] = None,
return_in_fourier: bool = False,
nan_check: bool = False,
) -> Union[
SpatialTensor["B C H ..."],
SpatialTensor["B T C H ..."],
FourierTensor["B C H ..."],
FourierTensor["B T C H ..."],
]
Integrate the operator using the provided initial condition and time step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_0
|
Optional[Tensor]
|
Initial condition in spatial domain. Default is None. |
None
|
u_0_fft
|
Optional[Tensor]
|
Initial condition in Fourier domain. Default is None. At least one of u_0 or u_0_fft should be provided. |
None
|
dt
|
float
|
Time step for the integrator. Default is 1. |
1
|
step
|
int
|
Number of time steps to integrate. Default is 1. |
1
|
mesh
|
Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]
|
Mesh information or mesh object. Default is None.
If None, the mesh registered in the operator will be used. You can use |
None
|
progressive
|
bool
|
If True, show a progress bar during integration. Default is False. |
False
|
trajectory_recorder
|
Optional[_TrajRecorder]
|
Trajectory recorder for recording the trajectory during integration. Default is None. If None, no trajectory will be recorded. The function will only return the final frame. |
None
|
return_in_fourier
|
bool
|
If True, return the result in Fourier domain. If False, return the result in spatial domain. Default is False. |
False
|
nan_check
|
bool
|
If True, check for NaN values in the result. If NaN values are found, raise a NanSimulationError. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[SpatialTensor['B C H ...'], SpatialTensor['B T C H ...'], FourierTensor['B C H ...'], FourierTensor['B T C H ...']]
|
Union[SpatialTensor["B C H ..."], SpatialTensor["B T C H ..."], FourierTensor["B C H ..."], FourierTensor["B T C H ..."]]: Integrated result in spatial or Fourier domain. If trajectory_recorder is provided, the result will be a trajectory tensor of shape (B, T, C, H, ...). Otherwise, the result will be a tensor of shape (B, C, H, ...). If return_in_fourier is True, the result will be in Fourier domain. Otherwise, it will be in spatial domain. |
Source code in torchfsm/operator/_base.py
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 | |
__call__
¤
__call__(
u: Optional[SpatialTensor["B C H ..."]] = None,
u_fft: Optional[FourierTensor["B C H ..."]] = None,
mesh: Optional[
Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
]
] = None,
return_in_fourier=False,
) -> Union[
SpatialTensor["B C H ..."], FourierTensor["B C H ..."]
]
Call the operator with the provided input tensor. The operator will apply the linear coefficient and nonlinear function to the input tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Optional[SpatialTensor]
|
Input tensor in spatial domain. Default is None. |
None
|
u_fft
|
Optional[FourierTensor]
|
Input tensor in Fourier domain. Default is None. At least one of u or u_fft should be provided. |
None
|
mesh
|
Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]
|
Mesh information or mesh object. Default is None.
If None, the mesh registered in the operator will be used. You can use |
None
|
return_in_fourier
|
bool
|
If True, return the result in Fourier domain. If False, return the result in spatial domain. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[SpatialTensor['B C H ...'], FourierTensor['B C H ...']]
|
Union[SpatialTensor["B C H ..."], FourierTensor["B C H ..."]]: Result of the operator in spatial or Fourier domain. |
Source code in torchfsm/operator/_base.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | |
to
¤
to(device=None, dtype=None)
Move the operator to the specified device and change the data type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Optional[device]
|
Device to which the operator should be moved. Default is None. |
None
|
dtype
|
Optional[dtype]
|
Data type of the operator. Default is None. |
None
|
Source code in torchfsm/operator/_base.py
835 836 837 838 839 840 841 842 843 844 845 846 847 | |
__init__
¤
__init__(
operator_cores: Optional[
ValueList[
Union[LinearCoef, NonlinearFunc, GeneratorLike]
]
] = None,
coefs: Optional[List] = None,
) -> None
Source code in torchfsm/operator/_base.py
863 864 865 866 867 868 | |
__add__
¤
__add__(other)
Source code in torchfsm/operator/_base.py
870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |
__mul__
¤
__mul__(other)
Source code in torchfsm/operator/_base.py
885 886 887 888 889 890 891 | |
__neg__
¤
__neg__()
Source code in torchfsm/operator/_base.py
893 894 | |
torchfsm.operator.LinearOperator
¤
Bases: OperatorLike, _InverseSolveMixin
Operators that contain only linear operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
linear_coef
|
ValueList[Union[LinearCoef, GeneratorLike]]
|
List of LinearCoef or linear coefficient generators. Default is None. |
None
|
coefs
|
Optional[List]
|
List of coefficients for each linear_coef. Default is None. If None, all coefficients are set to 1. The length of the list should match the number of linear_coef. |
None
|
Source code in torchfsm/operator/_base.py
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 | |
register_mesh
¤
register_mesh(
mesh: Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
],
n_channel: int,
device=None,
dtype=None,
)
Register the mesh and number of channels for the operator. Once a mesh is registered, mesh information is not required for integration and operator call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]
|
Mesh information or mesh object. |
required |
n_channel
|
int
|
Number of channels of the input tensor. |
required |
device
|
Optional[device]
|
Device to which the mesh should be moved. Default is None. |
None
|
dtype
|
Optional[dtype]
|
Data type of the mesh. Default is None. |
None
|
Source code in torchfsm/operator/_base.py
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 | |
solve
¤
solve(
b: Optional[Tensor] = None,
b_fft: Optional[Tensor] = None,
mesh: Optional[
Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
]
] = None,
n_channel: Optional[int] = None,
return_in_fourier=False,
) -> Union[
SpatialTensor["B C H ..."], SpatialTensor["B C H ..."]
]
Solve the linear operator equation \(Ax = b\), where \(A\) is the linear operator and \(b\) is the right-hand side.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
Optional[Tensor]
|
Right-hand side tensor in spatial domain. If None, b_fft should be provided. |
None
|
b_fft
|
Optional[Tensor]
|
Right-hand side tensor in Fourier domain. If None, b should be provided. |
None
|
mesh
|
Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]
|
Mesh information or mesh object. If None, the mesh registered in the operator will be used. |
None
|
n_channel
|
Optional[int]
|
Number of channels of \(x\). If None, the number of channels registered in the operator will be used. |
None
|
return_in_fourier
|
bool
|
If True, return the result in Fourier domain. If False, return the result in spatial domain. |
False
|
Returns:
| Type | Description |
|---|---|
Union[SpatialTensor['B C H ...'], SpatialTensor['B C H ...']]
|
Union[SpatialTensor["B C H ..."], FourierTensor["B C H ..."]]: Solution tensor in spatial or Fourier domain. |
Source code in torchfsm/operator/_base.py
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 | |
__radd__
¤
__radd__(other)
Source code in torchfsm/operator/_base.py
176 177 | |
__iadd__
¤
__iadd__(other)
Source code in torchfsm/operator/_base.py
179 180 | |
__sub__
¤
__sub__(other)
Source code in torchfsm/operator/_base.py
182 183 184 185 186 | |
__rsub__
¤
__rsub__(other)
Source code in torchfsm/operator/_base.py
188 189 190 191 192 | |
__isub__
¤
__isub__(other)
Source code in torchfsm/operator/_base.py
194 195 | |
__rmul__
¤
__rmul__(other)
Source code in torchfsm/operator/_base.py
197 198 | |
__imul__
¤
__imul__(other)
Source code in torchfsm/operator/_base.py
200 201 | |
__truediv__
¤
__truediv__(other)
Source code in torchfsm/operator/_base.py
203 204 205 206 207 | |
register_additional_check
¤
register_additional_check(func: Callable[[int, int], bool])
Register an additional check function for the value and mesh compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[int, int], bool]
|
Function that takes the dimension of the value and mesh as input and returns a boolean indicating whether they are compatible. |
required |
Source code in torchfsm/operator/_base.py
635 636 637 638 639 640 641 642 | |
add_core
¤
add_core(
core: Union[LinearCoef, NonlinearFunc, GeneratorLike],
coef=1,
)
Add a generator to the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
core
|
Union[LinearCoef, NonlinearFunc, GeneratorLike]
|
Core to be added. |
required |
coef
|
float
|
Coefficient for the generator. Default is 1. |
1
|
Source code in torchfsm/operator/_base.py
644 645 646 647 648 649 650 651 652 653 | |
set_integrator
¤
set_integrator(
integrator: Union[
Literal["auto"],
ETDRKIntegrator,
SETDRKIntegrator,
RKIntegrator,
],
**integrator_config
)
Set the integrator for the operator. The integrator is used for time integration of the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integrator
|
Union[Literal['auto'], ETDRKIntegrator, SETDRKIntegrator, RKIntegrator]
|
Integrator to be used. If "auto", the integrator will be chosen automatically based on the operator type. If "auto", the integrator will be set as ETDRKIntegrator.ETDRK0 for linear operators and ETDRKIntegrator.ETDRK2 for nonlinear operators. |
required |
**integrator_config
|
Additional configuration for the integrator. |
{}
|
Source code in torchfsm/operator/_base.py
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 | |
set_default_nonlinear_integrator
¤
set_default_nonlinear_integrator(
integrator: Union[
ETDRKIntegrator, SETDRKIntegrator, RKIntegrator
],
**integrator_config
)
Set the default nonlinear integrator for the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integrator
|
Union[ETDRKIntegrator, SETDRKIntegrator, RKIntegrator]
|
Integrator to be used. |
required |
**integrator_config
|
Additional configuration for the integrator. |
{}
|
Source code in torchfsm/operator/_base.py
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
integrate
¤
integrate(
u_0: Optional[Tensor] = None,
u_0_fft: Optional[Tensor] = None,
dt: float = 1,
step: int = 1,
mesh: Optional[
Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
]
] = None,
progressive: bool = False,
trajectory_recorder: Optional[_TrajRecorder] = None,
return_in_fourier: bool = False,
nan_check: bool = False,
) -> Union[
SpatialTensor["B C H ..."],
SpatialTensor["B T C H ..."],
FourierTensor["B C H ..."],
FourierTensor["B T C H ..."],
]
Integrate the operator using the provided initial condition and time step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_0
|
Optional[Tensor]
|
Initial condition in spatial domain. Default is None. |
None
|
u_0_fft
|
Optional[Tensor]
|
Initial condition in Fourier domain. Default is None. At least one of u_0 or u_0_fft should be provided. |
None
|
dt
|
float
|
Time step for the integrator. Default is 1. |
1
|
step
|
int
|
Number of time steps to integrate. Default is 1. |
1
|
mesh
|
Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]
|
Mesh information or mesh object. Default is None.
If None, the mesh registered in the operator will be used. You can use |
None
|
progressive
|
bool
|
If True, show a progress bar during integration. Default is False. |
False
|
trajectory_recorder
|
Optional[_TrajRecorder]
|
Trajectory recorder for recording the trajectory during integration. Default is None. If None, no trajectory will be recorded. The function will only return the final frame. |
None
|
return_in_fourier
|
bool
|
If True, return the result in Fourier domain. If False, return the result in spatial domain. Default is False. |
False
|
nan_check
|
bool
|
If True, check for NaN values in the result. If NaN values are found, raise a NanSimulationError. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[SpatialTensor['B C H ...'], SpatialTensor['B T C H ...'], FourierTensor['B C H ...'], FourierTensor['B T C H ...']]
|
Union[SpatialTensor["B C H ..."], SpatialTensor["B T C H ..."], FourierTensor["B C H ..."], FourierTensor["B T C H ..."]]: Integrated result in spatial or Fourier domain. If trajectory_recorder is provided, the result will be a trajectory tensor of shape (B, T, C, H, ...). Otherwise, the result will be a tensor of shape (B, C, H, ...). If return_in_fourier is True, the result will be in Fourier domain. Otherwise, it will be in spatial domain. |
Source code in torchfsm/operator/_base.py
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 | |
__call__
¤
__call__(
u: Optional[SpatialTensor["B C H ..."]] = None,
u_fft: Optional[FourierTensor["B C H ..."]] = None,
mesh: Optional[
Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
]
] = None,
return_in_fourier=False,
) -> Union[
SpatialTensor["B C H ..."], FourierTensor["B C H ..."]
]
Call the operator with the provided input tensor. The operator will apply the linear coefficient and nonlinear function to the input tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Optional[SpatialTensor]
|
Input tensor in spatial domain. Default is None. |
None
|
u_fft
|
Optional[FourierTensor]
|
Input tensor in Fourier domain. Default is None. At least one of u or u_fft should be provided. |
None
|
mesh
|
Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]
|
Mesh information or mesh object. Default is None.
If None, the mesh registered in the operator will be used. You can use |
None
|
return_in_fourier
|
bool
|
If True, return the result in Fourier domain. If False, return the result in spatial domain. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[SpatialTensor['B C H ...'], FourierTensor['B C H ...']]
|
Union[SpatialTensor["B C H ..."], FourierTensor["B C H ..."]]: Result of the operator in spatial or Fourier domain. |
Source code in torchfsm/operator/_base.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | |
to
¤
to(device=None, dtype=None)
Move the operator to the specified device and change the data type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Optional[device]
|
Device to which the operator should be moved. Default is None. |
None
|
dtype
|
Optional[dtype]
|
Data type of the operator. Default is None. |
None
|
Source code in torchfsm/operator/_base.py
835 836 837 838 839 840 841 842 843 844 845 846 847 | |
__init__
¤
__init__(
linear_coef: ValueList[
Union[LinearCoef, GeneratorLike]
] = None,
coefs: Optional[List] = None,
) -> None
Source code in torchfsm/operator/_base.py
908 909 910 911 912 913 914 915 916 917 918 | |
__add__
¤
__add__(other)
Source code in torchfsm/operator/_base.py
924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 | |
__mul__
¤
__mul__(other)
Source code in torchfsm/operator/_base.py
944 945 946 947 948 949 950 | |
__neg__
¤
__neg__()
Source code in torchfsm/operator/_base.py
952 953 954 955 | |
torchfsm.operator.NonlinearOperator
¤
Bases: OperatorLike, _DeAliasMixin
Operators that contain only nonlinear operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nonlinear_func
|
ValueList[Union[NonlinearFunc, GeneratorLike]]
|
List of NonlinearFunc or nonlinear function generators. Default is None. |
None
|
coefs
|
Optional[List]
|
List of coefficients for each nonlinear nonlinear_func. Default is None. If None, all coefficients are set to 1. The length of the list should match the number of nonlinear nonlinear_func. |
None
|
Source code in torchfsm/operator/_base.py
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
set_de_aliasing_rate
¤
set_de_aliasing_rate(de_aliasing_rate: float)
Set the de-aliasing rate for the nonlinear operator. Args: de_aliasing_rate (float): De-aliasing rate. Default is ⅔.
Source code in torchfsm/operator/_base.py
274 275 276 277 278 279 280 281 282 | |
__radd__
¤
__radd__(other)
Source code in torchfsm/operator/_base.py
176 177 | |
__iadd__
¤
__iadd__(other)
Source code in torchfsm/operator/_base.py
179 180 | |
__sub__
¤
__sub__(other)
Source code in torchfsm/operator/_base.py
182 183 184 185 186 | |
__rsub__
¤
__rsub__(other)
Source code in torchfsm/operator/_base.py
188 189 190 191 192 | |
__isub__
¤
__isub__(other)
Source code in torchfsm/operator/_base.py
194 195 | |
__rmul__
¤
__rmul__(other)
Source code in torchfsm/operator/_base.py
197 198 | |
__imul__
¤
__imul__(other)
Source code in torchfsm/operator/_base.py
200 201 | |
__truediv__
¤
__truediv__(other)
Source code in torchfsm/operator/_base.py
203 204 205 206 207 | |
register_mesh
¤
register_mesh(
mesh: Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
],
n_channel: int,
device=None,
dtype=None,
)
Register the mesh and number of channels for the operator. Once a mesh is registered, mesh information is not required for integration and operator call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]
|
Mesh information or mesh object. |
required |
n_channel
|
int
|
Number of channels of the input tensor. |
required |
device
|
Optional[device]
|
Device to which the mesh should be moved. Default is None. |
None
|
dtype
|
Optional[dtype]
|
Data type of the mesh. Default is None. |
None
|
Source code in torchfsm/operator/_base.py
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 | |
register_additional_check
¤
register_additional_check(func: Callable[[int, int], bool])
Register an additional check function for the value and mesh compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[int, int], bool]
|
Function that takes the dimension of the value and mesh as input and returns a boolean indicating whether they are compatible. |
required |
Source code in torchfsm/operator/_base.py
635 636 637 638 639 640 641 642 | |
add_core
¤
add_core(
core: Union[LinearCoef, NonlinearFunc, GeneratorLike],
coef=1,
)
Add a generator to the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
core
|
Union[LinearCoef, NonlinearFunc, GeneratorLike]
|
Core to be added. |
required |
coef
|
float
|
Coefficient for the generator. Default is 1. |
1
|
Source code in torchfsm/operator/_base.py
644 645 646 647 648 649 650 651 652 653 | |
set_integrator
¤
set_integrator(
integrator: Union[
Literal["auto"],
ETDRKIntegrator,
SETDRKIntegrator,
RKIntegrator,
],
**integrator_config
)
Set the integrator for the operator. The integrator is used for time integration of the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integrator
|
Union[Literal['auto'], ETDRKIntegrator, SETDRKIntegrator, RKIntegrator]
|
Integrator to be used. If "auto", the integrator will be chosen automatically based on the operator type. If "auto", the integrator will be set as ETDRKIntegrator.ETDRK0 for linear operators and ETDRKIntegrator.ETDRK2 for nonlinear operators. |
required |
**integrator_config
|
Additional configuration for the integrator. |
{}
|
Source code in torchfsm/operator/_base.py
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 | |
set_default_nonlinear_integrator
¤
set_default_nonlinear_integrator(
integrator: Union[
ETDRKIntegrator, SETDRKIntegrator, RKIntegrator
],
**integrator_config
)
Set the default nonlinear integrator for the operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integrator
|
Union[ETDRKIntegrator, SETDRKIntegrator, RKIntegrator]
|
Integrator to be used. |
required |
**integrator_config
|
Additional configuration for the integrator. |
{}
|
Source code in torchfsm/operator/_base.py
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
integrate
¤
integrate(
u_0: Optional[Tensor] = None,
u_0_fft: Optional[Tensor] = None,
dt: float = 1,
step: int = 1,
mesh: Optional[
Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
]
] = None,
progressive: bool = False,
trajectory_recorder: Optional[_TrajRecorder] = None,
return_in_fourier: bool = False,
nan_check: bool = False,
) -> Union[
SpatialTensor["B C H ..."],
SpatialTensor["B T C H ..."],
FourierTensor["B C H ..."],
FourierTensor["B T C H ..."],
]
Integrate the operator using the provided initial condition and time step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_0
|
Optional[Tensor]
|
Initial condition in spatial domain. Default is None. |
None
|
u_0_fft
|
Optional[Tensor]
|
Initial condition in Fourier domain. Default is None. At least one of u_0 or u_0_fft should be provided. |
None
|
dt
|
float
|
Time step for the integrator. Default is 1. |
1
|
step
|
int
|
Number of time steps to integrate. Default is 1. |
1
|
mesh
|
Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]
|
Mesh information or mesh object. Default is None.
If None, the mesh registered in the operator will be used. You can use |
None
|
progressive
|
bool
|
If True, show a progress bar during integration. Default is False. |
False
|
trajectory_recorder
|
Optional[_TrajRecorder]
|
Trajectory recorder for recording the trajectory during integration. Default is None. If None, no trajectory will be recorded. The function will only return the final frame. |
None
|
return_in_fourier
|
bool
|
If True, return the result in Fourier domain. If False, return the result in spatial domain. Default is False. |
False
|
nan_check
|
bool
|
If True, check for NaN values in the result. If NaN values are found, raise a NanSimulationError. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[SpatialTensor['B C H ...'], SpatialTensor['B T C H ...'], FourierTensor['B C H ...'], FourierTensor['B T C H ...']]
|
Union[SpatialTensor["B C H ..."], SpatialTensor["B T C H ..."], FourierTensor["B C H ..."], FourierTensor["B T C H ..."]]: Integrated result in spatial or Fourier domain. If trajectory_recorder is provided, the result will be a trajectory tensor of shape (B, T, C, H, ...). Otherwise, the result will be a tensor of shape (B, C, H, ...). If return_in_fourier is True, the result will be in Fourier domain. Otherwise, it will be in spatial domain. |
Source code in torchfsm/operator/_base.py
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 | |
__call__
¤
__call__(
u: Optional[SpatialTensor["B C H ..."]] = None,
u_fft: Optional[FourierTensor["B C H ..."]] = None,
mesh: Optional[
Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
]
] = None,
return_in_fourier=False,
) -> Union[
SpatialTensor["B C H ..."], FourierTensor["B C H ..."]
]
Call the operator with the provided input tensor. The operator will apply the linear coefficient and nonlinear function to the input tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Optional[SpatialTensor]
|
Input tensor in spatial domain. Default is None. |
None
|
u_fft
|
Optional[FourierTensor]
|
Input tensor in Fourier domain. Default is None. At least one of u or u_fft should be provided. |
None
|
mesh
|
Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]
|
Mesh information or mesh object. Default is None.
If None, the mesh registered in the operator will be used. You can use |
None
|
return_in_fourier
|
bool
|
If True, return the result in Fourier domain. If False, return the result in spatial domain. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[SpatialTensor['B C H ...'], FourierTensor['B C H ...']]
|
Union[SpatialTensor["B C H ..."], FourierTensor["B C H ..."]]: Result of the operator in spatial or Fourier domain. |
Source code in torchfsm/operator/_base.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | |
to
¤
to(device=None, dtype=None)
Move the operator to the specified device and change the data type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Optional[device]
|
Device to which the operator should be moved. Default is None. |
None
|
dtype
|
Optional[dtype]
|
Data type of the operator. Default is None. |
None
|
Source code in torchfsm/operator/_base.py
835 836 837 838 839 840 841 842 843 844 845 846 847 | |
__init__
¤
__init__(
nonlinear_func: ValueList[
Union[NonlinearFunc, GeneratorLike]
] = None,
coefs: Optional[List] = None,
) -> None
Source code in torchfsm/operator/_base.py
969 970 971 972 973 974 975 976 977 978 979 | |
__add__
¤
__add__(other)
Source code in torchfsm/operator/_base.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 | |
__mul__
¤
__mul__(other)
Source code in torchfsm/operator/_base.py
1005 1006 1007 1008 1009 1010 1011 | |
__neg__
¤
__neg__()
Source code in torchfsm/operator/_base.py
1013 1014 1015 1016 | |