-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpde.py
More file actions
168 lines (134 loc) · 3.5 KB
/
Copy pathpde.py
File metadata and controls
168 lines (134 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from dataclasses import dataclass
@dataclass
class PDEConfig:
"""Base inheritance for configuration of PDEs."""
pass
@dataclass
class NavierStokes2D(PDEConfig):
tmin: float = 0
tmax: float = 20.0
Lx: float = 32.0
Ly: float = 32.0
nt: int = 100
nx: int = 128
ny: int = 128
skip_nt: int = 0
sample_rate: int = 1
nu: float = 0.03
buoyancy_x: float = 0.0
buoyancy_y: float = 0.05
correction_strength: float = 1.0
force_strength: float = 0.2
force_frequency: int = 4
n_scalar_components: int = 1 # u
n_vector_components: int = 1 # vx, vy
device: str = "cpu"
def __post_init__(self):
assert self.n_scalar_components <= 1 and self.n_vector_components <= 1
def __repr__(self):
return "NavierStokes2D"
@property
def trajlen(self):
return int(self.nt / self.sample_rate)
@property
def grid_size(self):
return (self.trajlen, self.nx, self.ny)
@property
def dt(self):
return (self.tmax - self.tmin) / (self.nt)
@property
def dx(self):
return self.Lx / (self.nx - 1)
@property
def dy(self):
return self.Ly / (self.ny - 1)
@dataclass
class ShallowWaterWeather(PDEConfig):
tmin: float = 0
tmax: float = 90
nt: int = 90
skip_nt: int = 0
sample_rate: int = 1
nx: int = 64
ny: int = 128
Lx: float = 64.0
Ly: float = 128.0
n_scalar_components: int = 1 # pres
n_vector_components: int = 1 # vx, vy
def __post_init__(self):
assert self.n_scalar_components <= 2 and self.n_vector_components <= 1
def __repr__(self):
return "ShallowWaterWeather"
@property
def trajlen(self):
return int(self.nt / self.sample_rate)
@property
def grid_size(self):
return (self.trajlen, self.nx, self.ny)
@property
def dt(self):
return (self.tmax - self.tmin) / (self.nt)
@property
def dx(self):
return self.Lx / (self.nx - 1)
@property
def dy(self):
return self.Ly / (self.ny - 1)
@dataclass
class Maxwell2D(PDEConfig):
wavelength: float = 1.0e-5
sol: float = 299_792_458.0
amplitude: float = 1.0
permittivity: float = 10.0
permeability: float = 1.0
L: float = 3.2e-5
n: int = 32
n_large: int = 64
nt: int = 12
skip_nt: int = 250
sample_rate: int = 15
device: str = "cpu"
def __repr__(self):
return "Maxwell3D"
@property
def trajlen(self):
return self.nt
@property
def grid_size(self):
return (self.nt, self.n, self.n, 1)
@property
def spatial_grid_size(self):
return (self.n, self.n, 1)
@property
def grid_spacing(self):
return self.L / self.n_large
@dataclass
class Maxwell3D(PDEConfig):
wavelength: float = 1.0e-5
sol: float = 299_792_458.0
amplitude: float = 1.0
permittivity: float = 10.0
permeability: float = 1.0
L: float = 3.2e-5
n: int = 32
n_large: int = 64
nt: int = 12
skip_nt: int = 250
sample_rate: int = 15
device: str = "cpu"
def __repr__(self):
return "Maxwell3D"
@property
def trajlen(self):
return self.nt
@property
def grid_size(self):
return (self.nt, self.n, self.n, self.n)
@property
def spatial_grid_size(self):
return (self.n, self.n, self.n)
@property
def grid_spacing(self):
return self.L / self.n_large