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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
57
58
59
60
61
62
63
64
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
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"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:
            return 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:
        return NotImplementedError("KSConvection only supports scalar field")
    return _KSConvectionCore(self.remove_mean)

torchfsm.operator.dedicated._navier_stokes._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.py
49
50
51
52
53
54
55
56
57
58
59
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.py
56
57
58
59
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._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.py
 94
 95
 96
 97
 98
 99
100
101
102
103
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.py
100
101
102
103
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._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.py
147
148
149
150
151
152
153
154
155
156
157
158
159
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.py
153
154
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.py
156
157
158
159
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)