Skip to content

Commit edea2bc

Browse files
authored
Merge pull request #5 from scaomath/0.2.3-dev
0.2.2->0.2.3
2 parents 6abe65a + 9da51cd commit edea2bc

14 files changed

+1799
-370
lines changed

examples/Kolmogrov2d_rk4_fvm_forced_turbulence.ipynb

Lines changed: 16 additions & 6 deletions
Large diffs are not rendered by default.

examples/Kolmogrov2d_rk4_spectral_forced_turbulence.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 2,
5+
"execution_count": null,
66
"metadata": {},
77
"outputs": [],
88
"source": [
99
"import torch\n",
1010
"import torch.fft as fft\n",
1111
"\n",
1212
"from torch_cfd.grids import Grid\n",
13-
"from torch_cfd.initial_conditions import vorticity_field\n",
13+
"from torch_cfd.initial_conditions import filtered_vorticity_field\n",
1414
"from torch_cfd.forcings import KolmogorovForcing\n",
1515
"from torch_cfd.spectral import *\n",
1616
"from torch_cfd.equations import *\n",
@@ -26,7 +26,7 @@
2626
},
2727
{
2828
"cell_type": "code",
29-
"execution_count": 4,
29+
"execution_count": null,
3030
"metadata": {},
3131
"outputs": [],
3232
"source": [
@@ -53,7 +53,7 @@
5353
"\n",
5454
"grid = Grid(shape=(n, n), domain=((0, diam), (0, diam)), device=device)\n",
5555
"\n",
56-
"vort_init = vorticity_field(grid, peak_wavenumber, random_state=random_state, batch_size=batch_size).data\n",
56+
"vort_init = filtered_vorticity_field(grid, peak_wavenumber, random_state=random_state, batch_size=batch_size).data\n",
5757
"vort_hat = fft.rfft2(vort_init).to(device)\n",
5858
"\n",
5959
"\n",

examples/Lid-driven_cavity_rk4_fvm.ipynb

Lines changed: 294 additions & 0 deletions
Large diffs are not rendered by default.

fno/data_gen/data_gen_Kolmogorov2d.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import torch
1313
import torch.fft as fft
14+
import torch.nn.functional as F
1415
from torch_cfd.finite_differences import curl_2d
1516
from torch_cfd.forcings import KolmogorovForcing
1617

fno/data_gen/data_gen_McWilliams2d.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
import torch
1313
import torch.fft as fft
14+
import torch.nn.functional as F
1415

1516
from torch_cfd.grids import Grid
16-
from torch_cfd.initial_conditions import vorticity_field
17+
from torch_cfd.initial_conditions import filtered_vorticity_field
1718
from torch_cfd.equations import *
1819

1920
from solvers import get_trajectory_imex
@@ -131,7 +132,7 @@ def main(args):
131132

132133
vort_init = torch.stack(
133134
[
134-
vorticity_field(
135+
filtered_vorticity_field(
135136
grid, peak_wavenumber, random_state=random_state + idx + k
136137
).data
137138
for k in range(batch_size)

torch_cfd/advection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def __init__(
225225
grid: Grid,
226226
bcs_c: Tuple[boundaries.BoundaryConditions, ...],
227227
bcs_v: Tuple[boundaries.BoundaryConditions, ...],
228-
offsets: Tuple[Tuple[float, ...], ...] = ((1.5, 0.5), (0.5, 1.5)),
228+
offsets: Tuple[Tuple[float, ...], ...] = ((1.0, 0.5), (0.5, 1.0)),
229229
**kwargs,
230230
):
231231
super().__init__()
@@ -281,10 +281,9 @@ def forward(self, cs: GridVariableVector, v: GridVariableVector) -> GridVariable
281281
# flux's bc will become None
282282
flux = GridVariableVector(tuple(c * u for c, u in zip(cs, v)))
283283

284-
# Apply boundary conditions to flux if not periodic
285-
flux = GridVariableVector(
286-
tuple(bc.impose_bc(f) for f, bc in zip(flux, self.flux_bcs))
287-
)
284+
# wrap flux with boundary conditions to flux if not periodic
285+
flux = GridVariableVector(tuple(GridVariable(f.data, offset, f.grid, bc) for f, offset, bc in zip(flux, self.offsets, self.flux_bcs)))
286+
288287

289288
# Return negative divergence of flux
290289
# after taking divergence the bc becomes None
@@ -642,13 +641,14 @@ def __init__(
642641
boundaries.periodic_boundary_conditions(ndim=2),
643642
boundaries.periodic_boundary_conditions(ndim=2),
644643
),
644+
advect: type[nn.Module] = AdvectionVanLeer,
645645
limiter: Callable = van_leer_limiter,
646646
**kwargs,
647647
):
648648
super().__init__()
649649

650650
self.advect = nn.ModuleList(
651-
AdvectionVanLeer(
651+
advect(
652652
grid=grid,
653653
offset=offset,
654654
bc_c=bc,

0 commit comments

Comments
 (0)