Skip to content

3. functional

torchfsm.functional.biharmonic ¤

biharmonic(
    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,
) -> SpatialTensor["B C H ..."]

Function form for the biharmonic operator. For details, see torchfsm.operator.Biharmonic.

Parameters:

Name Type Description Default
u Optional[SpatialTensor['B C H ...']]

The input field.

None
u_fft Optional[FourierTensor['B C H ...']]

The Fourier-transformed input field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the biharmonic operator to the input field.

Source code in torchfsm/functional.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def biharmonic(
    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,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the biharmonic operator.
        For details, see `torchfsm.operator.Biharmonic`.

    Args:
        u (Optional[SpatialTensor["B C H ..."]]): The input field.
        u_fft (Optional[FourierTensor["B C H ..."]]): The Fourier-transformed input field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the biharmonic operator to the input field.   
    """
    return Biharmonic()(u=u, u_fft=u_fft, mesh=mesh)

torchfsm.functional.conservative_convection ¤

conservative_convection(
    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,
) -> SpatialTensor["B C H ..."]

Function form for the conservative convection operator. For details, see torchfsm.operator.ConservativeConvection.

Parameters:

Name Type Description Default
u Optional[SpatialTensor['B C H ...']]

The input field.

None
u_fft Optional[FourierTensor['B C H ...']]

The Fourier-transformed input field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the conservative convection operator to the input field.

Source code in torchfsm/functional.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def conservative_convection(
    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,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the conservative convection operator.
        For details, see `torchfsm.operator.ConservativeConvection`.

    Args:
        u (Optional[SpatialTensor["B C H ..."]]): The input field.
        u_fft (Optional[FourierTensor["B C H ..."]]): The Fourier-transformed input field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the conservative convection operator to the input field.
    """
    return ConservativeConvection()(u=u, u_fft=u_fft, mesh=mesh)

torchfsm.functional.convection ¤

convection(
    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,
) -> SpatialTensor["B C H ..."]

Function form for the convection operator. For details, see torchfsm.operator.Convection.

Parameters:

Name Type Description Default
u Optional[SpatialTensor['B C H ...']]

The input field.

None
u_fft Optional[FourierTensor['B C H ...']]

The Fourier-transformed input field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the convection operator to the input field.

Source code in torchfsm/functional.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def convection(
    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,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the convection operator.
        For details, see `torchfsm.operator.Convection`.

    Args:
        u (Optional[SpatialTensor["B C H ..."]]): The input field.
        u_fft (Optional[FourierTensor["B C H ..."]]): The Fourier-transformed input field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the convection operator to the input field.
    """

    return Convection()(u=u, u_fft=u_fft, mesh=mesh)

torchfsm.functional.curl ¤

curl(
    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,
) -> SpatialTensor["B C H ..."]

Function form for the curl operator. For details, see torchfsm.operator.Curl.

Parameters:

Name Type Description Default
u Optional[SpatialTensor['B C H ...']]

The input field.

None
u_fft Optional[FourierTensor['B C H ...']]

The Fourier-transformed input field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the curl operator to the input field.

Source code in torchfsm/functional.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def curl(
    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,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the curl operator.
        For details, see `torchfsm.operator.Curl`.

    Args:
        u (Optional[SpatialTensor["B C H ..."]]): The input field.
        u_fft (Optional[FourierTensor["B C H ..."]]): The Fourier-transformed input field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the curl operator to the input field.
    """

    return Curl()(u=u, u_fft=u_fft, mesh=mesh)

torchfsm.functional.div ¤

div(
    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,
) -> SpatialTensor["B C H ..."]

Function form for the divergence operator. For details, see torchfsm.operator.Div.

Parameters:

Name Type Description Default
u Optional[SpatialTensor['B C H ...']]

The input field.

None
u_fft Optional[FourierTensor['B C H ...']]

The Fourier-transformed input field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the divergence operator to the input field.

Source code in torchfsm/functional.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def div(
    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,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the divergence operator.
        For details, see `torchfsm.operator.Div`.

    Args:
        u (Optional[SpatialTensor["B C H ..."]]): The input field.
        u_fft (Optional[FourierTensor["B C H ..."]]): The Fourier-transformed input field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the divergence operator to the input field.
    """

    return Div()(u=u, u_fft=u_fft, mesh=mesh)

torchfsm.functional.grad ¤

grad(
    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,
) -> SpatialTensor["B C H ..."]

Function form for the gradient operator. For details, see torchfsm.operator.Grad.

Parameters:

Name Type Description Default
u Optional[SpatialTensor['B C H ...']]

The input field.

None
u_fft Optional[FourierTensor['B C H ...']]

The Fourier-transformed input field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the gradient operator to the input field.

Source code in torchfsm/functional.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
def grad(
    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,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the gradient operator.
        For details, see `torchfsm.operator.Grad`.

    Args:
        u (Optional[SpatialTensor["B C H ..."]]): The input field.
        u_fft (Optional[FourierTensor["B C H ..."]]): The Fourier-transformed input field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the gradient operator to the input field.
    """

    return Grad()(u=u, u_fft=u_fft, mesh=mesh)

torchfsm.functional.laplacian ¤

laplacian(
    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,
) -> SpatialTensor["B C H ..."]

Function form for the Laplacian operator. For details, see torchfsm.operator.Laplacian.

Parameters:

Name Type Description Default
u Optional[SpatialTensor['B C H ...']]

The input field.

None
u_fft Optional[FourierTensor['B C H ...']]

The Fourier-transformed input field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the Laplacian operator to the input field.

Source code in torchfsm/functional.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def laplacian(
    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,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the Laplacian operator.
        For details, see `torchfsm.operator.Laplacian`.

    Args:
        u (Optional[SpatialTensor["B C H ..."]]): The input field.
        u_fft (Optional[FourierTensor["B C H ..."]]): The Fourier-transformed input field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the Laplacian operator to the input field.
    """
    return Laplacian()(u=u, u_fft=u_fft, mesh=mesh)

torchfsm.functional.spatial_derivative ¤

spatial_derivative(
    dim_index: int,
    order: int,
    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,
) -> SpatialTensor["B C H ..."]

Function form for the spatial derivative operator. For details, see torchfsm.operator.SpatialDerivative.

Parameters:

Name Type Description Default
dim_index int

The index of the dimension to take the derivative along.

required
order int

The order of the derivative.

required
u Optional[SpatialTensor['B C H ...']]

The input field.

None
u_fft Optional[FourierTensor['B C H ...']]

The Fourier-transformed input field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the spatial derivative operator to the input field.

Source code in torchfsm/functional.py
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def spatial_derivative(
    dim_index: int,
    order: int,
    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,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the spatial derivative operator.
        For details, see `torchfsm.operator.SpatialDerivative`.

    Args:
        dim_index (int): The index of the dimension to take the derivative along.
        order (int): The order of the derivative.
        u (Optional[SpatialTensor["B C H ..."]]): The input field.
        u_fft (Optional[FourierTensor["B C H ..."]]): The Fourier-transformed input field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the spatial derivative operator to the input field.
    """
    return SpatialDerivative(dim_index, order)(u=u, u_fft=u_fft, mesh=mesh)

torchfsm.functional.ks_convection ¤

ks_convection(
    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,
    remove_mean: bool = True,
) -> SpatialTensor["B C H ..."]

Function form for the Kuramoto-Sivashinsky convection operator. For details, see torchfsm.operator.KSConvection.

Parameters:

Name Type Description Default
u Optional[SpatialTensor['B C H ...']]

The input field.

None
u_fft Optional[FourierTensor['B C H ...']]

The Fourier-transformed input field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None
remove_mean bool

If True, the mean of the input field will be removed before applying the operator.

True

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the Kuramoto-Sivashinsky convection operator to the input field.

Source code in torchfsm/functional.py
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
def ks_convection(
    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,
    remove_mean: bool = True,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the Kuramoto-Sivashinsky convection operator.
        For details, see `torchfsm.operator.KSConvection`.

    Args:
        u (Optional[SpatialTensor["B C H ..."]]): The input field.
        u_fft (Optional[FourierTensor["B C H ..."]]): The Fourier-transformed input field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.
        remove_mean (bool): If True, the mean of the input field will be removed before applying the operator.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the Kuramoto-Sivashinsky convection operator to the input field.
    """
    return KSConvection(remove_mean)(u=u, u_fft=u_fft, mesh=mesh)

torchfsm.functional.vorticity_convection ¤

vorticity_convection(
    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,
) -> SpatialTensor["B C H ..."]

Function form for the vorticity convection operator. For details, see torchfsm.operator.VorticityConvection.

Parameters:

Name Type Description Default
u Optional[SpatialTensor['B C H ...']]

The input field.

None
u_fft Optional[FourierTensor['B C H ...']]

The Fourier-transformed input field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the vorticity convection operator to the input field.

Source code in torchfsm/functional.py
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
def vorticity_convection(
    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,
) -> SpatialTensor["B C H ..."]:

    r"""
    Function form for the vorticity convection operator.
        For details, see `torchfsm.operator.VorticityConvection`.

    Args:
        u (Optional[SpatialTensor["B C H ..."]]): The input field.
        u_fft (Optional[FourierTensor["B C H ..."]]): The Fourier-transformed input field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the vorticity convection operator to the input field.
    """
    return VorticityConvection()(u=u, u_fft=u_fft, mesh=mesh)

torchfsm.functional.vorticity2velocity ¤

vorticity2velocity(
    vorticity: Optional[torch.Tensor] = None,
    vorticity_fft: Optional[torch.Tensor] = None,
    mesh: Optional[
        Union[
            Sequence[tuple[float, float, int]],
            MeshGrid,
            FourierMesh,
        ]
    ] = None,
) -> SpatialTensor["B C H ..."]

Function form for the vorticity to velocity operator. For details, see torchfsm.operator.Vorticity2Velocity.

Parameters:

Name Type Description Default
vorticity Optional[Tensor]

The input vorticity field.

None
vorticity_fft Optional[Tensor]

The Fourier-transformed vorticity field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the vorticity to velocity operator to the input field.

Source code in torchfsm/functional.py
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
def vorticity2velocity(
    vorticity: Optional[torch.Tensor] = None,
    vorticity_fft: Optional[torch.Tensor] = None,
    mesh: Optional[
        Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]
    ] = None,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the vorticity to velocity operator.
        For details, see `torchfsm.operator.Vorticity2Velocity`.

    Args:
        vorticity (Optional[torch.Tensor]): The input vorticity field.
        vorticity_fft (Optional[torch.Tensor]): The Fourier-transformed vorticity field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the vorticity to velocity operator to the input field.
    """

    return Vorticity2Velocity()(u=vorticity, u_fft=vorticity_fft, mesh=mesh)

torchfsm.functional.vorticity2pressure ¤

vorticity2pressure(
    vorticity: Optional[torch.Tensor] = None,
    vorticity_fft: Optional[torch.Tensor] = None,
    mesh: Optional[
        Union[
            Sequence[tuple[float, float, int]],
            MeshGrid,
            FourierMesh,
        ]
    ] = None,
    external_force: Optional[OperatorLike] = None,
) -> SpatialTensor["B C H ..."]

Function form for the vorticity to pressure operator. For details, see torchfsm.operator.Vorticity2Pressure.

Parameters:

Name Type Description Default
vorticity Optional[Tensor]

The input vorticity field.

None
vorticity_fft Optional[Tensor]

The Fourier-transformed vorticity field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None
external_force Optional[OperatorLike]

An optional external force to be applied.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the vorticity to pressure operator to the input field.

Source code in torchfsm/functional.py
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
def vorticity2pressure(
    vorticity: Optional[torch.Tensor] = None,
    vorticity_fft: Optional[torch.Tensor] = None,
    mesh: Optional[
        Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]
    ] = None,
    external_force: Optional[OperatorLike] = None,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the vorticity to pressure operator.
        For details, see `torchfsm.operator.Vorticity2Pressure`.

    Args:
        vorticity (Optional[torch.Tensor]): The input vorticity field.
        vorticity_fft (Optional[torch.Tensor]): The Fourier-transformed vorticity field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.
        external_force (Optional[OperatorLike]): An optional external force to be applied.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the vorticity to pressure operator to the input field.
    """

    vorticity_fft, f_mesh = _get_fft_with_mesh(
        value=vorticity, value_fft=vorticity_fft, mesh=mesh
    )
    velocity_fft = Vorticity2Velocity()(
        u_fft=vorticity_fft, mesh=f_mesh, return_in_fourier=True
    )
    convection = Convection()(u_fft=velocity_fft, mesh=f_mesh, return_in_fourier=True)
    if external_force is not None:
        convection -= external_force(
            u_fft=vorticity_fft, mesh=f_mesh, return_in_fourier=True
        )
    convection = Div()(u_fft=convection, mesh=f_mesh, return_in_fourier=True)
    return Laplacian().solve(b_fft=-1 * convection, mesh=f_mesh, n_channel=1)

torchfsm.functional.velocity2pressure ¤

velocity2pressure(
    velocity: Optional[torch.Tensor] = None,
    velocity_fft: Optional[torch.Tensor] = None,
    mesh: Optional[
        Union[
            Sequence[tuple[float, float, int]],
            MeshGrid,
            FourierMesh,
        ]
    ] = None,
    external_force: Optional[OperatorLike] = None,
) -> SpatialTensor["B C H ..."]

Function form for the velocity to pressure operator. For details, see torchfsm.operator.Velocity2Pressure.

Parameters:

Name Type Description Default
velocity Optional[Tensor]

The input velocity field.

None
velocity_fft Optional[Tensor]

The Fourier-transformed velocity field.

None
mesh Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]

The mesh for the field.

None
external_force Optional[OperatorLike]

An optional external force to be applied.

None

Returns:

Type Description
SpatialTensor['B C H ...']

SpatialTensor["B C H ..."]: The result of applying the velocity to pressure operator to the input field.

Source code in torchfsm/functional.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
def velocity2pressure(
    velocity: Optional[torch.Tensor] = None,
    velocity_fft: Optional[torch.Tensor] = None,
    mesh: Optional[
        Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]
    ] = None,
    external_force: Optional[OperatorLike] = None,
) -> SpatialTensor["B C H ..."]:
    r"""
    Function form for the velocity to pressure operator.
        For details, see `torchfsm.operator.Velocity2Pressure`.

    Args:
        velocity (Optional[torch.Tensor]): The input velocity field.
        velocity_fft (Optional[torch.Tensor]): The Fourier-transformed velocity field.
        mesh (Optional[Union[Sequence[tuple[float, float, int]], MeshGrid, FourierMesh]]): The mesh for the field.
        external_force (Optional[OperatorLike]): An optional external force to be applied.

    Returns:
        SpatialTensor["B C H ..."]: The result of applying the velocity to pressure operator to the input field.
    """

    velocity_fft, f_mesh = _get_fft_with_mesh(
        value=velocity, value_fft=velocity_fft, mesh=mesh
    )
    convection = Convection()(u_fft=velocity_fft, mesh=f_mesh, return_in_fourier=True)
    if external_force is not None:
        convection -= external_force(
            u_fft=velocity_fft, mesh=f_mesh, return_in_fourier=True
        )
    convection = Div()(u_fft=convection, mesh=f_mesh, return_in_fourier=True)
    return Laplacian().solve(b_fft=-1 * convection, mesh=f_mesh, n_channel=1)