Skip to content

Generators

torchfsm.operator.generic._conservative_convection._ConservativeConvectionGenerator ¤

Bases: CoreGenerator

Generator of the Conservative Convection operator. It ensures that the operator is only applied to vector fields with the same dimension as the mesh.

Source code in torchfsm/operator/generic/_conservative_convection.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class _ConservativeConvectionGenerator(CoreGenerator):

    r"""
    Generator of the Conservative Convection operator. It ensures that the operator is only applied to vector fields with the same dimension as the mesh.
    """

    def __call__(
        self, f_mesh: FourierMesh, n_channel: int
    ) -> Union[LinearCoef, NonlinearFunc]:
        if f_mesh.n_dim != n_channel:
            raise ValueError(
                f"div operator only works for vector field with the same dimension as mesh"
            )
        return _ConservativeConvectionCore()
__call__ ¤
__call__(
    f_mesh: FourierMesh, n_channel: int
) -> Union[LinearCoef, NonlinearFunc]
Source code in torchfsm/operator/generic/_conservative_convection.py
36
37
38
39
40
41
42
43
def __call__(
    self, f_mesh: FourierMesh, n_channel: int
) -> Union[LinearCoef, NonlinearFunc]:
    if f_mesh.n_dim != n_channel:
        raise ValueError(
            f"div operator only works for vector field with the same dimension as mesh"
        )
    return _ConservativeConvectionCore()

torchfsm.operator.generic._convection._ConvectionGenerator ¤

Bases: CoreGenerator

Generator of the Convection operator. It ensures that the operator is only applied to vector fields with the same dimension as the mesh.

Source code in torchfsm/operator/generic/_convection.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class _ConvectionGenerator(CoreGenerator):

    r"""
    Generator of the Convection operator. It ensures that the operator is only applied to vector fields with the same dimension as the mesh.
    """

    def __call__(
        self, f_mesh: FourierMesh, n_channel: int
    ) -> Union[LinearCoef, NonlinearFunc]:
        if f_mesh.n_dim != n_channel:
            raise ValueError(
                f"convection operator only works for vector field with the same dimension as mesh"
            )
        return _ConvectionCore()
__call__ ¤
__call__(
    f_mesh: FourierMesh, n_channel: int
) -> Union[LinearCoef, NonlinearFunc]
Source code in torchfsm/operator/generic/_convection.py
60
61
62
63
64
65
66
67
def __call__(
    self, f_mesh: FourierMesh, n_channel: int
) -> Union[LinearCoef, NonlinearFunc]:
    if f_mesh.n_dim != n_channel:
        raise ValueError(
            f"convection operator only works for vector field with the same dimension as mesh"
        )
    return _ConvectionCore()

torchfsm.operator.generic._curl._CurlGenerator ¤

Bases: CoreGenerator

Generator of the Curl operator. It ensure that curl only works for 2D or 3D vector field with the same dimension as the mesh.

Source code in torchfsm/operator/generic/_curl.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class _CurlGenerator(CoreGenerator):
    r"""
    Generator of the Curl operator. 
        It ensure that curl only works for 2D or 3D vector field with the same dimension as the mesh.
    """

    def __call__(
        self, f_mesh: FourierMesh, n_channel: int
    ) -> Union[LinearCoef, NonlinearFunc]:
        if f_mesh.n_dim != n_channel:
            raise ValueError(
                f"div operator only works for vector field with the same dimension as mesh"
            )
        if n_channel > 3 or n_channel < 2:
            raise ValueError(f"div operator only works for 2D or 3D vector field")
        if n_channel == 2:
            return _Curl2DCore()
        else:
            return _Curl3DCore()
__call__ ¤
__call__(
    f_mesh: FourierMesh, n_channel: int
) -> Union[LinearCoef, NonlinearFunc]
Source code in torchfsm/operator/generic/_curl.py
64
65
66
67
68
69
70
71
72
73
74
75
76
def __call__(
    self, f_mesh: FourierMesh, n_channel: int
) -> Union[LinearCoef, NonlinearFunc]:
    if f_mesh.n_dim != n_channel:
        raise ValueError(
            f"div operator only works for vector field with the same dimension as mesh"
        )
    if n_channel > 3 or n_channel < 2:
        raise ValueError(f"div operator only works for 2D or 3D vector field")
    if n_channel == 2:
        return _Curl2DCore()
    else:
        return _Curl3DCore()

torchfsm.operator.generic._div._DivGenerator ¤

Bases: CoreGenerator

Generator of the Divergence operator. It ensures that divergence only works for vector fields with the same dimension as the mesh.

Source code in torchfsm/operator/generic/_div.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class _DivGenerator(CoreGenerator):
    r"""
    Generator of the Divergence operator.
        It ensures that divergence only works for vector fields with the same dimension as the mesh.
    """

    def __call__(
        self, f_mesh: FourierMesh, n_channel: int
    ) -> Union[LinearCoef, NonlinearFunc]:
        if f_mesh.n_dim != n_channel:
            raise ValueError(
                f"div operator only works for vector field with the same dimension as mesh"
            )
        return _DivCore()
__call__ ¤
__call__(
    f_mesh: FourierMesh, n_channel: int
) -> Union[LinearCoef, NonlinearFunc]
Source code in torchfsm/operator/generic/_div.py
37
38
39
40
41
42
43
44
def __call__(
    self, f_mesh: FourierMesh, n_channel: int
) -> Union[LinearCoef, NonlinearFunc]:
    if f_mesh.n_dim != n_channel:
        raise ValueError(
            f"div operator only works for vector field with the same dimension as mesh"
        )
    return _DivCore()

torchfsm.operator.generic._grad._GradGenerator ¤

Bases: CoreGenerator

Generator of the Grad operator. It ensures that grad only works for scalar field.

Source code in torchfsm/operator/generic/_grad.py
18
19
20
21
22
23
24
25
26
27
class _GradGenerator(CoreGenerator):
    r"""
    Generator of the Grad operator.
        It ensures that grad only works for scalar field.
    """

    def __call__(self, f_mesh: FourierMesh, n_channel: int) -> LinearCoef:
        if n_channel != 1:
            raise ValueError("The Grad operator only supports scalar field.")
        return _GradCore()
__call__ ¤
__call__(f_mesh: FourierMesh, n_channel: int) -> LinearCoef
Source code in torchfsm/operator/generic/_grad.py
24
25
26
27
def __call__(self, f_mesh: FourierMesh, n_channel: int) -> LinearCoef:
    if n_channel != 1:
        raise ValueError("The Grad operator only supports scalar field.")
    return _GradCore()

torchfsm.operator.generic._spatial_derivative._SpatialDerivativeGenerator ¤

Bases: CoreGenerator

Generator of the SpatialDerivative operator. It ensures that spatial derivative only works for scalar field.

Source code in torchfsm/operator/generic/_spatial_derivative.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class _SpatialDerivativeGenerator(CoreGenerator):

    r"""
    Generator of the SpatialDerivative operator.
        It ensures that spatial derivative only works for scalar field.
    """

    def __init__(self, dim_index, order) -> None:
        super().__init__()
        self.dim_index = dim_index
        self.order = order

    def __call__(self, f_mesh: FourierMesh, n_channel: int) -> LinearCoef:
        if n_channel != 1:
            raise ValueError(
                "The SpatialDerivative operator only supports scalar field."
            )
        return _SpatialDerivativeCore(self.dim_index, self.order)
dim_index instance-attribute ¤
dim_index = dim_index
order instance-attribute ¤
order = order
__init__ ¤
__init__(dim_index, order) -> None
Source code in torchfsm/operator/generic/_spatial_derivative.py
30
31
32
33
def __init__(self, dim_index, order) -> None:
    super().__init__()
    self.dim_index = dim_index
    self.order = order
__call__ ¤
__call__(f_mesh: FourierMesh, n_channel: int) -> LinearCoef
Source code in torchfsm/operator/generic/_spatial_derivative.py
35
36
37
38
39
40
def __call__(self, f_mesh: FourierMesh, n_channel: int) -> LinearCoef:
    if n_channel != 1:
        raise ValueError(
            "The SpatialDerivative operator only supports scalar field."
        )
    return _SpatialDerivativeCore(self.dim_index, self.order)

torchfsm.operator.dedicated._ks_convection._KSConvectionGenerator ¤

Bases: CoreGenerator

Generator of the KSConvection operator. It ensures that the operator is only applied to scalar fields.

Source code in torchfsm/operator/dedicated/_ks_convection.py
41
42
43
44
45
46
47
48
49
50
51
52
class _KSConvectionGenerator(CoreGenerator):
    r"""
    Generator of the KSConvection operator. It ensures that the operator is only applied to scalar fields.
    """

    def __init__(self, remove_mean: bool) -> None:
        self.remove_mean = remove_mean

    def __call__(self, f_mesh: FourierMesh, n_channel: int) -> NonlinearFunc:
        if n_channel != 1:
            raise NotImplementedError("KSConvection only supports scalar field")
        return _KSConvectionCore(self.remove_mean)
remove_mean instance-attribute ¤
remove_mean = remove_mean
__init__ ¤
__init__(remove_mean: bool) -> None
Source code in torchfsm/operator/dedicated/_ks_convection.py
46
47
def __init__(self, remove_mean: bool) -> None:
    self.remove_mean = remove_mean
__call__ ¤
__call__(
    f_mesh: FourierMesh, n_channel: int
) -> NonlinearFunc
Source code in torchfsm/operator/dedicated/_ks_convection.py
49
50
51
52
def __call__(self, f_mesh: FourierMesh, n_channel: int) -> NonlinearFunc:
    if n_channel != 1:
        raise NotImplementedError("KSConvection only supports scalar field")
    return _KSConvectionCore(self.remove_mean)

torchfsm.operator.dedicated._navier_stokes._vorticity_convection._VorticityConvectionGenerator ¤

Bases: CoreGenerator

Generator of the VorticityConvection operator. It ensures that the operator is only applied to scalar vorticity fields in 2D.

Source code in torchfsm/operator/dedicated/_navier_stokes/_vorticity_convection.py
44
45
46
47
48
49
50
51
52
53
54
class _VorticityConvectionGenerator(CoreGenerator):

    r"""
    Generator of the VorticityConvection operator. 
        It ensures that the operator is only applied to scalar vorticity fields in 2D.
    """

    def __call__(self, f_mesh: FourierMesh, n_channel: int) -> NonlinearFunc:
        if f_mesh.n_dim != 2 or n_channel != 1:
            raise ValueError("Only vorticity in 2Dmesh is supported")
        return _VorticityConvectionCore()
__call__ ¤
__call__(
    f_mesh: FourierMesh, n_channel: int
) -> NonlinearFunc
Source code in torchfsm/operator/dedicated/_navier_stokes/_vorticity_convection.py
51
52
53
54
def __call__(self, f_mesh: FourierMesh, n_channel: int) -> NonlinearFunc:
    if f_mesh.n_dim != 2 or n_channel != 1:
        raise ValueError("Only vorticity in 2Dmesh is supported")
    return _VorticityConvectionCore()

torchfsm.operator.dedicated._navier_stokes._value_transformation._Vorticity2VelocityGenerator ¤

Bases: CoreGenerator

Generator of the Vorticity2Velocity operator. It ensures that the operator is only applied to scalar vorticity fields in 2D.

Source code in torchfsm/operator/dedicated/_navier_stokes/_value_transformation.py
37
38
39
40
41
42
43
44
45
46
class _Vorticity2VelocityGenerator(CoreGenerator):

    r"""
    Generator of the Vorticity2Velocity operator.
        It ensures that the operator is only applied to scalar vorticity fields in 2D."""

    def __call__(self, f_mesh: FourierMesh, n_channel: int) -> NonlinearFunc:
        if f_mesh.n_dim != 2 or n_channel != 1:
            raise ValueError("Only vorticity in 2Dmesh is supported")
        return _Vorticity2VelocityCore()
__call__ ¤
__call__(
    f_mesh: FourierMesh, n_channel: int
) -> NonlinearFunc
Source code in torchfsm/operator/dedicated/_navier_stokes/_value_transformation.py
43
44
45
46
def __call__(self, f_mesh: FourierMesh, n_channel: int) -> NonlinearFunc:
    if f_mesh.n_dim != 2 or n_channel != 1:
        raise ValueError("Only vorticity in 2Dmesh is supported")
    return _Vorticity2VelocityCore()

torchfsm.operator.dedicated._navier_stokes._value_transformation._Vorticity2PressureGenerator ¤

Bases: CoreGenerator

Generator of the Vorticity2Pressure operator. It ensures that the operator is only applied to scalar vorticity fields in 2D.

Source code in torchfsm/operator/dedicated/_navier_stokes/_value_transformation.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
class _Vorticity2PressureGenerator(CoreGenerator):
    r"""
    Generator of the Vorticity2Pressure operator.
        It ensures that the operator is only applied to scalar vorticity fields in 2D.
    """

    def __init__(self, external_force: Optional[OperatorLike] = None) -> None:
        self.external_force = external_force

    def __call__(self, f_mesh: FourierMesh, n_channel: int) -> NonlinearFunc:
        if f_mesh.n_dim != 2 or n_channel != 1:
            raise ValueError("Only vorticity in 2Dmesh is supported")
        return _Vorticity2PressureCore(self.external_force)
external_force instance-attribute ¤
external_force = external_force
__init__ ¤
__init__(
    external_force: Optional[OperatorLike] = None,
) -> None
Source code in torchfsm/operator/dedicated/_navier_stokes/_value_transformation.py
96
97
def __init__(self, external_force: Optional[OperatorLike] = None) -> None:
    self.external_force = external_force
__call__ ¤
__call__(
    f_mesh: FourierMesh, n_channel: int
) -> NonlinearFunc
Source code in torchfsm/operator/dedicated/_navier_stokes/_value_transformation.py
 99
100
101
102
def __call__(self, f_mesh: FourierMesh, n_channel: int) -> NonlinearFunc:
    if f_mesh.n_dim != 2 or n_channel != 1:
        raise ValueError("Only vorticity in 2Dmesh is supported")
    return _Vorticity2PressureCore(self.external_force)

torchfsm.operator.dedicated._navier_stokes._leray._LerayGenerator ¤

Bases: CoreGenerator

Generator of the Leray peojection operator. It ensures that the operator only works for vector fields with the same dimension as the mesh.

Source code in torchfsm/operator/dedicated/_navier_stokes/_leray.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class _LerayGenerator(CoreGenerator):
    r"""
    Generator of the Leray peojection operator.
        It ensures that the operator only works for vector fields with the same dimension as the mesh.
    """

    def __call__(
        self, f_mesh: FourierMesh, n_channel: int
    ) -> Union[LinearCoef, NonlinearFunc]:
        if f_mesh.n_dim != n_channel:
            raise ValueError(
                f"Leray projection only works for vector field with the same dimension as mesh"
            )
        return _LerayCore()
__call__ ¤
__call__(
    f_mesh: FourierMesh, n_channel: int
) -> Union[LinearCoef, NonlinearFunc]
Source code in torchfsm/operator/dedicated/_navier_stokes/_leray.py
33
34
35
36
37
38
39
40
def __call__(
    self, f_mesh: FourierMesh, n_channel: int
) -> Union[LinearCoef, NonlinearFunc]:
    if f_mesh.n_dim != n_channel:
        raise ValueError(
            f"Leray projection only works for vector field with the same dimension as mesh"
        )
    return _LerayCore()

torchfsm.operator.dedicated._gray_scott._ChannelWisedDiffusionGenerator ¤

Bases: CoreGenerator

Generator of the ChannelWisedDiffusion operator. It ensures that the operator is only applied to fields with the same number of channels as the number of viscosities.

Source code in torchfsm/operator/dedicated/_gray_scott.py
24
25
26
27
28
29
30
31
32
33
34
35
36
class _ChannelWisedDiffusionGenerator(CoreGenerator):

    r"""
    Generator of the ChannelWisedDiffusion operator. It ensures that the operator is only applied to fields with the same number of channels as the number of viscosities.
    """

    def __init__(self, viscosities: Sequence[Union[Tensor, float]]) -> None:
        self.viscosities = viscosities

    def __call__(self, f_mesh: FourierMesh, n_channel: int) -> LinearCoef:
        if n_channel != len(self.viscosities):
            raise ValueError(f"Number of channels {n_channel} does not match number of viscosities {len(self.viscosities)} for ChannelWisedDiffusion.")
        return _ChannelWisedDiffusionCore(self.viscosities)
viscosities instance-attribute ¤
viscosities = viscosities
__init__ ¤
__init__(
    viscosities: Sequence[Union[Tensor, float]],
) -> None
Source code in torchfsm/operator/dedicated/_gray_scott.py
30
31
def __init__(self, viscosities: Sequence[Union[Tensor, float]]) -> None:
    self.viscosities = viscosities
__call__ ¤
__call__(f_mesh: FourierMesh, n_channel: int) -> LinearCoef
Source code in torchfsm/operator/dedicated/_gray_scott.py
33
34
35
36
def __call__(self, f_mesh: FourierMesh, n_channel: int) -> LinearCoef:
    if n_channel != len(self.viscosities):
        raise ValueError(f"Number of channels {n_channel} does not match number of viscosities {len(self.viscosities)} for ChannelWisedDiffusion.")
    return _ChannelWisedDiffusionCore(self.viscosities)

torchfsm.operator.dedicated._gray_scott._GrayScottSourceGenerator ¤

Bases: CoreGenerator

Generator of the GrayScottSource operator. It ensures that the operator is only applied to fields with exactly

Source code in torchfsm/operator/dedicated/_gray_scott.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class _GrayScottSourceGenerator(CoreGenerator):

    r""" 
    Generator of the GrayScottSource operator. It ensures that the operator is only applied to fields with exactly
    """

    def __init__(self, 
                 feed_rate: Union[Tensor, float],
                 kill_rate: Union[Tensor, float]) -> None:
        self.feed_rate = feed_rate
        self.kill_rate = kill_rate

    def __call__(self, f_mesh: FourierMesh, n_channel: int) -> NonlinearFunc:
        if n_channel != 2:
            raise ValueError(f"Gray-Scott source term requires exactly 2 channels, got {n_channel}.")
        return _GrayScottSourceCore(self.feed_rate, self.kill_rate)
feed_rate instance-attribute ¤
feed_rate = feed_rate
kill_rate instance-attribute ¤
kill_rate = kill_rate
__init__ ¤
__init__(
    feed_rate: Union[Tensor, float],
    kill_rate: Union[Tensor, float],
) -> None
Source code in torchfsm/operator/dedicated/_gray_scott.py
83
84
85
86
87
def __init__(self, 
             feed_rate: Union[Tensor, float],
             kill_rate: Union[Tensor, float]) -> None:
    self.feed_rate = feed_rate
    self.kill_rate = kill_rate
__call__ ¤
__call__(
    f_mesh: FourierMesh, n_channel: int
) -> NonlinearFunc
Source code in torchfsm/operator/dedicated/_gray_scott.py
89
90
91
92
def __call__(self, f_mesh: FourierMesh, n_channel: int) -> NonlinearFunc:
    if n_channel != 2:
        raise ValueError(f"Gray-Scott source term requires exactly 2 channels, got {n_channel}.")
    return _GrayScottSourceCore(self.feed_rate, self.kill_rate)