1. operator
Operators¤
Operators are the core of the torchfsm library. Each operator represents a specific physical process, such as convection, diffusion, or pressure calculation.
torchfsm.operator.Advection
¤
Bases: NonlinearOperator
Advection calculates the advection of a scalar field by a constant velocity field.
If your velocity field is constant in space, please consider using LinearAdvection operator to allow you use larger simulation dt.
It is defined as \(\nabla \cdot (\phi\mathbf{u}) = \sum_{i=0}^I \frac{\phi\partial u_i}{\partial i}\)
where \(\mathbf{u}\) is the velocity field.
Note that this class is an operator wrapper. The actual implementation of the operator is in the _AdvectionCore class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity
|
SpatialTensor['B C H ...']
|
The velocity field used for advection. Please not that your velocity should be smooth enough to avoid aliasing error in Fourier space. |
required |
Source code in torchfsm/operator/generic/_advection.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
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 | |
__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 | |
__init__
¤
__init__(velocity: SpatialTensor['B C H ...']) -> None
Source code in torchfsm/operator/generic/_advection.py
44 45 46 47 | |
torchfsm.operator.Biharmonic
¤
Bases: LinearOperator
Biharmonic calculates the Biharmonic of a vector field.
It is defined as \(\nabla^4\mathbf{u}=\left[\begin{matrix}(\sum_{i=0}^I\frac{\partial^2}{\partial i^2 })(\sum_{j=0}^I\frac{\partial^2}{\partial j^2 })u_x \\ (\sum_{i=0}^I\frac{\partial^2}{\partial i^2 })(\sum_{j=0}^I\frac{\partial^2}{\partial j^2 })u_y \\ \cdots \\ (\sum_{i=0}^I\frac{\partial^2}{\partial i^2 })(\sum_{j=0}^I\frac{\partial^2}{\partial j^2 })u_I \\ \end{matrix} \right]\)
Note that this class is an operator wrapper. The real implementation of the source term is in the _BiharmonicCore class.
Source code in torchfsm/operator/generic/_biharmonic.py
19 20 21 22 23 24 25 26 27 28 | |
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 | |
__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 | |
__init__
¤
__init__() -> None
Source code in torchfsm/operator/generic/_biharmonic.py
27 28 | |
torchfsm.operator.ChannelWisedDiffusion
¤
Bases: LinearOperator
The ChannelWisedDiffusion operator applies different diffusion coefficients to each channel of a field.
It is defined as: \(\nabla^2 \phi_i = \nu_i \nabla^2 \phi_i\) for each channel \(i\).
Note that this class is an operator wrapper. The real implementation of the diffusion is in the _ChannelWisedDiffusionCore class.
Source code in torchfsm/operator/dedicated/_gray_scott.py
38 39 40 41 42 43 44 45 46 47 | |
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 | |
__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 | |
__init__
¤
__init__(viscosities: Sequence[Union[Tensor, float]])
Source code in torchfsm/operator/dedicated/_gray_scott.py
46 47 | |
torchfsm.operator.ConservativeConvection
¤
Bases: NonlinearOperator
ConservativeConvection calculates the convection of a vector field on itself.
It is defined as \(\nabla \cdot \mathbf{u}\mathbf{u}=\left[\begin{matrix}\sum_{i=0}^I \frac{\partial u_i u_x }{\partial i} \\\sum_{i=0}^I \frac{\partial u_i u_y }{\partial i} \\\cdots\\\sum_{i=0}^I \frac{\partial u_i u_I }{\partial i} \\\end{matrix}\right]\).
This operator only works for vector fields with the same dimension as the mesh.
Note that this class is an operator wrapper. The real implementation of the source term is in the _ConservativeConvectionCore class.
Source code in torchfsm/operator/generic/_conservative_convection.py
46 47 48 49 50 51 52 53 54 55 | |
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 | |
__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 | |
__init__
¤
__init__() -> None
Source code in torchfsm/operator/generic/_conservative_convection.py
54 55 | |
torchfsm.operator.Convection
¤
Bases: NonlinearOperator
Convection calculates the convection of a vector field on itself if the vector field is divergence free, i.e., \(\nabla \cdot \mathbf{u} =0\).
It is defined as \(\mathbf{u} \cdot \nabla \mathbf{u}=\left[\begin{matrix}\sum_{i=0}^I u_i\frac{\partial u_x }{\partial i} \\\sum_{i=0}^I u_i\frac{\partial u_y }{\partial i} \\\cdots\\\sum_{i=0}^I u_i\frac{\partial u_I }{\partial i} \\\end{matrix}\right]\)
This operator only works for vector fields with the same dimension as the mesh.
Note that this class is an operator wrapper. The real implementation of the source term is in the _ConvectionCore class.
Source code in torchfsm/operator/generic/_convection.py
70 71 72 73 74 75 76 77 78 79 | |
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 | |
__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 | |
__init__
¤
__init__() -> None
Source code in torchfsm/operator/generic/_convection.py
78 79 | |
torchfsm.operator.Curl
¤
Bases: NonlinearOperator
Curl operator for 2D and 3D vector fields.
It is defined as: \(\nabla \times \mathbf{u} = \frac{\partial u_y}{\partial x}-\frac{\partial u_x}{\partial y}\)
for 2D vector field \(\mathbf{u} = (u_x, u_y)\) and
\(\nabla \times \mathbf{u} = \left[\begin{matrix} \frac{\partial u_z}{\partial y}-\frac{\partial u_y}{\partial z} \\ \frac{\partial u_x}{\partial z}-\frac{\partial u_z}{\partial x} \\ \frac{\partial u_y}{\partial x}-\frac{\partial u_x}{\partial y} \end{matrix} \right]\)
for 3D vector field \(\mathbf{u} = (u_x, u_y, u_z)\).
This operator only works for vector fields with the same dimension as the mesh.
Note that this class is an operator wrapper. The real implementation of the source term is in the _Curl2DCore and _Curl2DCore class.
Source code in torchfsm/operator/generic/_curl.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
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 | |
__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 | |
__init__
¤
__init__() -> None
Source code in torchfsm/operator/generic/_curl.py
92 93 | |
torchfsm.operator.Dispersion
¤
Bases: LinearOperator
Dispersion calculates the Laplacian of a vector field.
It is defined as \(\nabla \cdot (\nabla^2\mathbf{u}) = \left[\begin{matrix}\sum_j^I \frac{\partial}{\partial j}\sum_i^I \frac{\partial^2 u_x}{\partial i^2 } \\ \sum_j^I \frac{\partial}{\partial j}\sum_i^I \frac{\partial^2 u_y}{\partial i^2 } \\ \cdots \\ \sum_j^I \frac{\partial}{\partial j}\sum_i^I \frac{\partial^2 u_I}{\partial i^2 } \\ \end{matrix} \right]\)
Note that this class is an operator wrapper. The actual implementation of the operator is in the _LaplacianCore class.
Source code in torchfsm/operator/generic/_dispersion.py
21 22 23 24 25 26 27 28 29 30 | |
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 | |
__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 | |
__init__
¤
__init__() -> None
Source code in torchfsm/operator/generic/_dispersion.py
29 30 | |
torchfsm.operator.Div
¤
Bases: NonlinearOperator
Div calculates the divergence of a vector field.
It is defined as \(\nabla \cdot \mathbf{u} = \sum_i \frac{\partial u_i}{\partial i}\).
This operator only works for vector fields with the same dimension as the mesh.
Note that this class is an operator wrapper. The actual implementation of the operator is in the _DivCore class.
Source code in torchfsm/operator/generic/_div.py
47 48 49 50 51 52 53 54 55 56 57 | |
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 | |
__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 | |
__init__
¤
__init__() -> None
Source code in torchfsm/operator/generic/_div.py
56 57 | |
torchfsm.operator.ExplicitSource
¤
Bases: NonlinearOperator
Explicit source term for the operator. This class is used to represent an explicit source term in the operator. Note that this class is an operator wrapper. The real implementation of the source term is in the _ExplicitSourceCore class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Tensor
|
Source term in spatial domain. This is a tensor that represents the source term in the spatial domain. |
required |
Source code in torchfsm/operator/_base.py
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 | |
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 | |
__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 | |
__init__
¤
__init__(source: Tensor) -> None
Source code in torchfsm/operator/_base.py
1055 1056 | |
torchfsm.operator.Grad
¤
Bases: LinearOperator
Grad calculates the spatial gradient of a scalar field.
It is defined as \(\nabla p = \left[\begin{matrix}\frac{\partial p}{\partial x} \\\frac{\partial p}{\partial y} \\\cdots \\\frac{\partial p}{\partial i} \\\end{matrix}\right]\)
Note that this class is an operator wrapper. The actual implementation of the operator is in the _GradCore class.
Source code in torchfsm/operator/generic/_grad.py
30 31 32 33 34 35 36 37 38 | |
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 | |
__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 | |
__init__
¤
__init__() -> None
Source code in torchfsm/operator/generic/_grad.py
37 38 | |
torchfsm.operator.GrayScottSource
¤
Bases: NonlinearOperator
The Gray-Scott source term operator for a two-channel field.
It is defined as: \(\left[\begin{matrix}f (1 - \phi_0) - \phi_0 \phi_1^2 \\ \phi_0 \phi_1^2 - (f + k) \phi_1 \end{matrix}\right]\)
Note that this class is an operator wrapper. The real implementation of the source term is in the _GrayScottSource class.
Source code in torchfsm/operator/dedicated/_gray_scott.py
94 95 96 97 98 99 100 101 102 103 104 105 | |
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 | |
__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 | |
__init__
¤
__init__(
feed_rate: Union[Tensor, float],
kill_rate: Union[Tensor, float],
) -> None
Source code in torchfsm/operator/dedicated/_gray_scott.py
102 103 104 105 | |
torchfsm.operator.HyperDiffusion
¤
Bases: LinearOperator
HyperDiffusion calculates the hyper diffusion of a vector field.
It is defined as \(\nabla^4\mathbf{u} = \left[\begin{matrix}\sum_i \frac{\partial^4 u_x}{\partial i^4 } \\\sum_i \frac{\partial^4 u_y}{\partial i^4 } \\\cdots \\\sum_i \frac{\partial^4 u_I}{\partial i^4 } \\\end{matrix}\right]\)
Note that this class is an operator wrapper. The actual implementation of the operator is in the _HyperDiffusionCore class.
Source code in torchfsm/operator/generic/_hyper_diffusion.py
17 18 19 20 21 22 23 24 25 26 | |
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 | |
__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 | |
__init__
¤
__init__() -> None
Source code in torchfsm/operator/generic/_hyper_diffusion.py
25 26 | |
torchfsm.operator.ImplicitSource
¤
Bases: Operator
ImplicitSource allows to define a source term in the implicit form.
Note that this class is an operator wrapper. The actual implementation of the operator is in the _ImplicitFuncSourceCore class and _ImplicitUnitSourceCore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_func
|
Callable[[Tensor], Tensor]
|
The f(x) function to be used as the source term. This function is used to define the source term in the implicit form. If None, the source term will be set to the unknown variable itself, i.e., f(x) = x. |
None
|
non_linear
|
bool
|
If True, the source term is treated as a nonlinear function. If False, it is treated as a linear function. Default is True. This actually controls whether the operator wil use the dealiased version of unknown variable for the source term. If the source term is a nonlinear function, the dealiased version of the unknown variable will be used. |
True
|
Source code in torchfsm/operator/generic/_source.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
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 | |
__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 | |
__init__
¤
__init__(
source_func: Optional[
Callable[[Tensor], Tensor]
] = None,
non_linear: bool = True,
) -> None
Source code in torchfsm/operator/generic/_source.py
63 64 65 66 67 68 69 70 71 72 73 74 | |
torchfsm.operator.KSConvection
¤
Bases: NonlinearOperator
The Kuramoto-Sivashinsky convection operator for a scalar field.
It is defined as: \(\frac{1}{2}|\nabla \phi|^2=\frac{1}{2}\sum_{i=0}^{I}(\frac{\partial \phi}{\partial i})^2\)
Note that this class is an operator wrapper. The real implementation of the source term is in the _KSConvectionCore class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remove_mean
|
bool
|
Whether to remove the mean of the result. Default is True. Set to True will improve the stability of the simulation. |
True
|
Source code in torchfsm/operator/dedicated/_ks_convection.py
55 56 57 58 59 60 61 62 63 64 65 66 67 | |
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 | |
__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 | |
__init__
¤
__init__(remove_mean: bool = True) -> None
Source code in torchfsm/operator/dedicated/_ks_convection.py
66 67 | |
torchfsm.operator.Laplacian
¤
Bases: LinearOperator
Laplacian calculates the Laplacian of a vector field.
It is defined as \(\nabla \cdot (\nabla\mathbf{u}) = \left[\begin{matrix}\sum_i \frac{\partial^2 u_x}{\partial i^2 } \\\sum_i \frac{\partial^2 u_y}{\partial i^2 } \\\cdots \\\sum_i \frac{\partial^2 u_i}{\partial i^2 } \\\end{matrix}\right]\)
Note that this class is an operator wrapper. The actual implementation of the operator is in the _LaplacianCore class.
Source code in torchfsm/operator/generic/_laplacian.py
17 18 19 20 21 22 23 24 25 26 | |
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 | |
__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 | |
__init__
¤
__init__() -> None
Source code in torchfsm/operator/generic/_laplacian.py
25 26 | |
torchfsm.operator.Leray
¤
Bases: NonlinearOperator
Leray calculates the Leray projection of a vector field.
It is defined as \(\mathbf{u} - \nabla \nabla^{-2} \nabla \cdot \mathbf{u}\).
This operator only works for vector fields with the same dimension as the mesh.
Note that this class is an operator wrapper. The actual implementation of the operator is in the _LerayCore class.
Source code in torchfsm/operator/dedicated/_navier_stokes/_leray.py
42 43 44 45 46 47 48 49 50 51 | |
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 | |
__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 | |
__init__
¤
__init__() -> None
Source code in torchfsm/operator/dedicated/_navier_stokes/_leray.py
50 51 | |
torchfsm.operator.LinearAdvection
¤
Bases: LinearOperator
LinearAdvection calculates the advection of a scalar field by a constant velocity field.
It is defined as $ \mathbf{u} \cdot \nabla \phi = \sum_{i=0}^I u_i \frac{\partial \phi}{\partial i} $
where \(\mathbf{u} = [u_x, u_y, \cdots, u_I]\) is the constant velocity field.
If your velocity is not constant in space, please consider using Advection operator instead.
Note that this class is an operator wrapper. The actual implementation of the operator is in the _AdvectionCore class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity
|
Union[float, Sequence[float]]
|
The constant velocity field. If a float is provided, it is assumed that the velocity is the same in all dimensions. If a sequence is provided, its length must match the number of dimensions of the mesh. Default is 1.0. |
1.0
|
Source code in torchfsm/operator/generic/_linear_advection.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
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 | |
__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 | |
__init__
¤
__init__(
velocity: Union[float, Sequence[float]] = 1.0,
) -> None
Source code in torchfsm/operator/generic/_linear_advection.py
62 63 | |
set_advection_velocity
¤
set_advection_velocity(
velocity: Union[float, Sequence[float]],
) -> None
Set the advection velocity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity
|
Union[float, Sequence[float]]
|
The constant velocity field. If a float is provided, it is assumed that the velocity is the same in all dimensions. If a sequence is provided, its length must match the number of dimensions of the mesh. |
required |
Source code in torchfsm/operator/generic/_linear_advection.py
65 66 67 68 69 70 71 72 73 | |
torchfsm.operator.NSPressureConvection
¤
Bases: NonlinearOperator
Operator for Navier-Stokes pressure convection.
It is defined as \(-\nabla (\nabla^{-2} \nabla \cdot (\left(\mathbf{u}\cdot\nabla\right)\mathbf{u}-f))-\left(\mathbf{u}\cdot\nabla\right)\mathbf{u} + \mathbf{f}\).
Note that this class is an operator wrapper. The real implementation of the source term is in the _NSPressureConvectionCore class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
external_force
|
Optional[OperatorLike]
|
Optional[OperatorLike], optional, default=None |
None
|
Source code in torchfsm/operator/dedicated/_navier_stokes/_ns_pressure_convection.py
50 51 52 53 54 55 56 57 58 59 60 61 | |
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 | |
__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 | |
__init__
¤
__init__(
external_force: Optional[OperatorLike] = None,
) -> None
Source code in torchfsm/operator/dedicated/_navier_stokes/_ns_pressure_convection.py
60 61 | |
torchfsm.operator.SpatialDerivative
¤
Bases: LinearOperator
SpatialDeritivate calculates the spatial derivative of a scalar field w.r.t to a spatial dimension.
It is defined as\(\frac{\partial ^n}{\partial i} p\) where \(i = x, y, z, \cdots\) and \(n=1, 2, 3, \cdots\)
Note that this class is an operator wrapper. The actual implementation of the operator is in the _SpatialDerivativeCore class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim_index
|
int
|
The index of the spatial dimension. |
required |
order
|
int
|
The order of the derivative. |
required |
Source code in torchfsm/operator/generic/_spatial_derivative.py
43 44 45 46 47 48 49 50 51 52 53 54 55 | |
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 | |
__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 | |
__init__
¤
__init__(dim_index: int, order: int) -> None
Source code in torchfsm/operator/generic/_spatial_derivative.py
54 55 | |
torchfsm.operator.Velocity2Pressure
¤
Bases: NonlinearOperator
Operator for velocity to pressure conversion.
It is defined as \(-\nabla^{-2} (\nabla \cdot (\left(\mathbf{u}\cdot\nabla\right)\mathbf{u}-f))\)
Note that this class is an operator wrapper. The real implementation of the source term is in the _Velocity2PressureCore class.
Source code in torchfsm/operator/dedicated/_navier_stokes/_value_transformation.py
152 153 154 155 156 157 158 159 160 | |
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 | |
__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 | |
__init__
¤
__init__(
external_force: Optional[OperatorLike] = None,
) -> None
Source code in torchfsm/operator/dedicated/_navier_stokes/_value_transformation.py
159 160 | |
torchfsm.operator.Vorticity2Pressure
¤
Bases: NonlinearOperator
Operator for vorticity to pressure conversion in 2D.
It is defined as \(\begin{matrix}\mathbf{u}=[u,v]=[-\frac{\partial \nabla^{-2}\omega}{\partial y},\frac{\partial \nabla^{-2}\omega}{\partial x}]\\ p= -\nabla^{-2} (\nabla \cdot (\left(\mathbf{u}\cdot\nabla\right)\mathbf{u}-f))\end{matrix}\).
Note that this class is an operator wrapper. The real implementation of the source term is in the _Vorticity2PressureCore class.
Source code in torchfsm/operator/dedicated/_navier_stokes/_value_transformation.py
105 106 107 108 109 110 111 112 113 | |
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 | |
__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 | |
__init__
¤
__init__(
external_force: Optional[OperatorLike] = None,
) -> None
Source code in torchfsm/operator/dedicated/_navier_stokes/_value_transformation.py
112 113 | |
torchfsm.operator.Vorticity2Velocity
¤
Bases: LinearOperator
Operator for vorticity to velocity conversion in 2D.
It is defined as \([u,v]=[-\frac{\partial \nabla^{-2}\omega}{\partial y},\frac{\partial \nabla^{-2}\omega}{\partial x}]\).
Note that this class is an operator wrapper. The real implementation of the source term is in the _Vorticity2VelocityCore class.
Source code in torchfsm/operator/dedicated/_navier_stokes/_value_transformation.py
49 50 51 52 53 54 55 56 57 58 | |
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 | |
__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 | |
__init__
¤
__init__()
Source code in torchfsm/operator/dedicated/_navier_stokes/_value_transformation.py
57 58 | |
torchfsm.operator.VorticityConvection
¤
Bases: NonlinearOperator
Operator for vorticity convection in 2D.
It is defined as \((\mathbf{u}\cdot\nabla) \omega\) where \(\omega\) is the vorticity and \(\mathbf{u}\) is the velocity.
Note that this class is an operator wrapper. The real implementation of the source term is in the _VorticityConvectionCore class.
Source code in torchfsm/operator/dedicated/_navier_stokes/_vorticity_convection.py
57 58 59 60 61 62 63 64 65 66 | |
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 | |
__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 | |
__init__
¤
__init__() -> None
Source code in torchfsm/operator/dedicated/_navier_stokes/_vorticity_convection.py
65 66 | |
Utils¤
torchfsm.operator.run_operators
¤
run_operators(
u: SpatialTensor["B C H ..."],
operators: Sequence[Operator],
mesh: Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
],
) -> SpatialTensor["B C H ..."]
Run a sequence of operators on the input tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
SpatialTensor
|
Input tensor of shape (B, C, H, ...). |
required |
operators
|
Sequence[Operator]
|
Sequence of operators to be applied. |
required |
mesh
|
Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]
|
Mesh information or mesh object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SpatialTensor |
SpatialTensor['B C H ...']
|
Resulting tensor after applying the operators. |
Source code in torchfsm/operator/__init__.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
torchfsm.operator.check_value_with_mesh
¤
check_value_with_mesh(
u: SpatialTensor["B C H ..."],
mesh: Union[
Sequence[tuple[float, float, int]],
MeshGrid,
FourierMesh,
],
)
Check if the value and mesh are compatible. If not, raise a ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
SpatialTensor
|
Input tensor of shape (B, C, H, ...). |
required |
mesh
|
Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]
|
Mesh information or mesh object. |
required |
Source code in torchfsm/operator/_base.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |