zoomy-core 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of zoomy-core might be problematic. Click here for more details.
- zoomy_core/decorators/decorators.py +25 -0
- zoomy_core/fvm/flux.py +97 -0
- zoomy_core/fvm/nonconservative_flux.py +97 -0
- zoomy_core/fvm/ode.py +55 -0
- zoomy_core/fvm/solver_numpy.py +305 -0
- zoomy_core/fvm/timestepping.py +13 -0
- zoomy_core/mesh/gmsh_loader.py +301 -0
- zoomy_core/mesh/mesh.py +1192 -0
- zoomy_core/mesh/mesh_extrude.py +168 -0
- zoomy_core/mesh/mesh_util.py +487 -0
- zoomy_core/misc/custom_types.py +6 -0
- zoomy_core/misc/gui.py +61 -0
- zoomy_core/misc/interpolation.py +140 -0
- zoomy_core/misc/io.py +401 -0
- zoomy_core/misc/logger_config.py +18 -0
- zoomy_core/misc/misc.py +216 -0
- zoomy_core/misc/static_class.py +94 -0
- zoomy_core/model/analysis.py +147 -0
- zoomy_core/model/basefunction.py +113 -0
- zoomy_core/model/basemodel.py +512 -0
- zoomy_core/model/boundary_conditions.py +193 -0
- zoomy_core/model/initial_conditions.py +171 -0
- zoomy_core/model/model.py +63 -0
- zoomy_core/model/models/GN.py +70 -0
- zoomy_core/model/models/advection.py +53 -0
- zoomy_core/model/models/basisfunctions.py +181 -0
- zoomy_core/model/models/basismatrices.py +377 -0
- zoomy_core/model/models/core.py +564 -0
- zoomy_core/model/models/coupled_constrained.py +60 -0
- zoomy_core/model/models/old_smm copy.py +867 -0
- zoomy_core/model/models/poisson.py +41 -0
- zoomy_core/model/models/shallow_moments.py +757 -0
- zoomy_core/model/models/shallow_moments_sediment.py +378 -0
- zoomy_core/model/models/shallow_moments_topo.py +423 -0
- zoomy_core/model/models/shallow_moments_variants.py +1509 -0
- zoomy_core/model/models/shallow_water.py +266 -0
- zoomy_core/model/models/shallow_water_topo.py +111 -0
- zoomy_core/model/models/shear_shallow_flow.py +594 -0
- zoomy_core/model/models/sme_turbulent.py +613 -0
- zoomy_core/model/models/swe_old.py +1018 -0
- zoomy_core/model/models/vam.py +455 -0
- zoomy_core/postprocessing/postprocessing.py +72 -0
- zoomy_core/preprocessing/openfoam_moments.py +452 -0
- zoomy_core/transformation/helpers.py +25 -0
- zoomy_core/transformation/to_amrex.py +238 -0
- zoomy_core/transformation/to_c.py +181 -0
- zoomy_core/transformation/to_jax.py +14 -0
- zoomy_core/transformation/to_numpy.py +115 -0
- zoomy_core/transformation/to_openfoam.py +254 -0
- zoomy_core/transformation/to_ufl.py +67 -0
- {zoomy_core-0.1.0.dist-info → zoomy_core-0.1.2.dist-info}/METADATA +1 -1
- zoomy_core-0.1.2.dist-info/RECORD +55 -0
- zoomy_core-0.1.2.dist-info/top_level.txt +1 -0
- zoomy_core-0.1.0.dist-info/RECORD +0 -5
- zoomy_core-0.1.0.dist-info/top_level.txt +0 -1
- {zoomy_core-0.1.0.dist-info → zoomy_core-0.1.2.dist-info}/WHEEL +0 -0
- {zoomy_core-0.1.0.dist-info → zoomy_core-0.1.2.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import os
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
import sympy
|
|
6
|
+
from sympy import Symbol, Matrix, lambdify, transpose, Abs, sqrt
|
|
7
|
+
|
|
8
|
+
from sympy import zeros, ones
|
|
9
|
+
|
|
10
|
+
from attr import define, field
|
|
11
|
+
from typing import Optional
|
|
12
|
+
from types import SimpleNamespace
|
|
13
|
+
|
|
14
|
+
from library.zoomy_core.model.boundary_conditions import BoundaryConditions, Extrapolation
|
|
15
|
+
from library.zoomy_core.model.initial_conditions import InitialConditions, Constant
|
|
16
|
+
from library.zoomy_core.misc.custom_types import FArray
|
|
17
|
+
from library.zoomy_core.model.basemodel import Model
|
|
18
|
+
|
|
19
|
+
from library.zoomy_core.misc.misc import Zstruct
|
|
20
|
+
|
|
21
|
+
@define(frozen=True, slots=True, kw_only=True)
|
|
22
|
+
class ShallowWaterEquations(Model):
|
|
23
|
+
dimension: int = 1
|
|
24
|
+
|
|
25
|
+
@define(frozen=True, slots=True, kw_only=True)
|
|
26
|
+
class ShallowWaterEquations(Model):
|
|
27
|
+
dimension: int=1
|
|
28
|
+
variables: Zstruct = field(default=3)
|
|
29
|
+
aux_variables: Zstruct = field(default=2)
|
|
30
|
+
_default_parameters: dict = field(
|
|
31
|
+
init=False,
|
|
32
|
+
factory=lambda: {"g": 9.81, "ex": 0.0, "ey": 0.0, "ez": 1.0}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
def __attrs_post_init__(self):
|
|
36
|
+
if type(self.variables)==int:
|
|
37
|
+
object.__setattr__(self, "variables",self.dimension+1)
|
|
38
|
+
super().__attrs_post_init__()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def project_2d_to_3d(self):
|
|
42
|
+
out = Matrix([0 for i in range(5)])
|
|
43
|
+
dim = self.dimension
|
|
44
|
+
x = self.position[0]
|
|
45
|
+
y = self.position[1]
|
|
46
|
+
z = self.position[2]
|
|
47
|
+
h = self.variables[0]
|
|
48
|
+
U = [hu / h for hu in self.variables[1:1+dim]]
|
|
49
|
+
rho_w = 1000.
|
|
50
|
+
g = 9.81
|
|
51
|
+
out[0] = h
|
|
52
|
+
out[1] = U[0]
|
|
53
|
+
out[2] = 0 if dim == 1 else U[1]
|
|
54
|
+
out[3] = 0
|
|
55
|
+
out[4] = rho_w * g * h * (1-z)
|
|
56
|
+
return out
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def flux(self):
|
|
61
|
+
dim = self.dimension
|
|
62
|
+
h = self.variables[0]
|
|
63
|
+
U = Matrix([hu / h for hu in self.variables[1:1+dim]])
|
|
64
|
+
g = self.parameters.g
|
|
65
|
+
I = Matrix.eye(dim)
|
|
66
|
+
F = Matrix.zeros(self.variables.length(), dim)
|
|
67
|
+
F[0, :] = (h * U).T
|
|
68
|
+
F[1:, :] = h * U * U.T + g/2 * h**2 * I
|
|
69
|
+
return [F[:, d] for d in range(dim)]
|
|
70
|
+
|
|
71
|
+
def source(self):
|
|
72
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
73
|
+
return out
|
|
74
|
+
|
|
75
|
+
def chezy(self):
|
|
76
|
+
assert "C" in vars(self.parameters)
|
|
77
|
+
dim = self.dimension
|
|
78
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
79
|
+
h = self.variables[0]
|
|
80
|
+
hU = self.variables[1:1+dim]
|
|
81
|
+
U = Matrix([hu / h for hu in hU])
|
|
82
|
+
p = self.parameters
|
|
83
|
+
u_sq = sqrt(U.dot(U))
|
|
84
|
+
out[1:1+dim, 0] = -1.0 / p.C**2 * U * u_sq
|
|
85
|
+
return out
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@define(slots=True, frozen=False, kw_only=True)
|
|
89
|
+
class ShallowWater(Model):
|
|
90
|
+
"""
|
|
91
|
+
:gui:
|
|
92
|
+
{ 'parameters': { 'g': {'type': 'float', 'value': 9.81, 'step': 0.01}, 'ex': {'type': 'float', 'value': 0., 'step':0.1}, 'ez': {'type': 'float', 'value': 1., 'step': 0.1}, },}
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
def __init__(
|
|
96
|
+
self,
|
|
97
|
+
boundary_conditions,
|
|
98
|
+
initial_conditions,
|
|
99
|
+
dimension=1,
|
|
100
|
+
fields=2,
|
|
101
|
+
aux_variables=0,
|
|
102
|
+
parameters={},
|
|
103
|
+
_default_parameters={"g": 1.0, "ex": 0.0, "ez": 1.0},
|
|
104
|
+
settings={},
|
|
105
|
+
settings_default={"topography": False, "friction": []},
|
|
106
|
+
):
|
|
107
|
+
super().__init__(
|
|
108
|
+
dimension=dimension,
|
|
109
|
+
fields=fields,
|
|
110
|
+
aux_variables=aux_variables,
|
|
111
|
+
parameters=parameters,
|
|
112
|
+
_default_parameters=_default_parameters,
|
|
113
|
+
boundary_conditions=boundary_conditions,
|
|
114
|
+
initial_conditions=initial_conditions,
|
|
115
|
+
settings={**settings_default, **settings},
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
def flux(self):
|
|
119
|
+
flux = Matrix([0 for i in range(self.n_variables)])
|
|
120
|
+
h = self.variables[0]
|
|
121
|
+
hu = self.variables[1]
|
|
122
|
+
p = self.parameters
|
|
123
|
+
flux[0] = hu
|
|
124
|
+
flux[1] = hu**2 / h + p.g * p.ez * h * h / 2
|
|
125
|
+
return [flux]
|
|
126
|
+
|
|
127
|
+
def source(self):
|
|
128
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
129
|
+
return out
|
|
130
|
+
|
|
131
|
+
def topography(self):
|
|
132
|
+
assert "dhdx" in vars(self.aux_variables)
|
|
133
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
134
|
+
h = self.variables[0]
|
|
135
|
+
hu = self.variables[1]
|
|
136
|
+
p = self.parameters
|
|
137
|
+
dhdx = self.aux_variables.dhdx
|
|
138
|
+
out[1] = h * p.g * (p.ex - p.ez * dhdx)
|
|
139
|
+
return out
|
|
140
|
+
|
|
141
|
+
def newtonian(self):
|
|
142
|
+
assert "nu" in vars(self.parameters)
|
|
143
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
144
|
+
h = self.variables[0]
|
|
145
|
+
hu = self.variables[1]
|
|
146
|
+
p = self.parameters
|
|
147
|
+
out[1] = -p.nu * hu / h
|
|
148
|
+
return out
|
|
149
|
+
|
|
150
|
+
def manning(self):
|
|
151
|
+
assert "nm" in vars(self.parameters)
|
|
152
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
153
|
+
h = self.variables[0]
|
|
154
|
+
hu = self.variables[1]
|
|
155
|
+
u = hu / h
|
|
156
|
+
p = self.parameters
|
|
157
|
+
out[1] = -p.g * (p.nm**2) * u * Abs(u) / h ** (7 / 3)
|
|
158
|
+
return out
|
|
159
|
+
|
|
160
|
+
def chezy(self):
|
|
161
|
+
assert "C" in vars(self.parameters)
|
|
162
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
163
|
+
h = self.variables[0]
|
|
164
|
+
hu = self.variables[1]
|
|
165
|
+
u = hu / h
|
|
166
|
+
p = self.parameters
|
|
167
|
+
out[1] = -1.0 / p.C**2 * u * Abs(u)
|
|
168
|
+
return out
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class ShallowWater2d(ShallowWater):
|
|
172
|
+
"""
|
|
173
|
+
:gui:
|
|
174
|
+
{ 'parameters': { 'g': {'type': 'float', 'value': 9.81, 'step': 0.01}, 'ex': {'type': 'float', 'value': 0., 'step':0.1}, 'ey': {'type': 'float', 'value': 0., 'step':0.1}, 'ez': {'type': 'float', 'value': 1., 'step': 0.1}, },}
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
def __init__(
|
|
178
|
+
self,
|
|
179
|
+
boundary_conditions,
|
|
180
|
+
initial_conditions,
|
|
181
|
+
dimension=2,
|
|
182
|
+
fields=3,
|
|
183
|
+
aux_variables=0,
|
|
184
|
+
parameters={},
|
|
185
|
+
_default_parameters={"g": 1.0, "ex": 0.0, "ey": 0.0, "ez": 1.0},
|
|
186
|
+
settings={},
|
|
187
|
+
settings_default={"topography": False, "friction": []},
|
|
188
|
+
):
|
|
189
|
+
# combine settings_default of current class with settings such that the default settings of super() does not get overwritten.
|
|
190
|
+
super().__init__(
|
|
191
|
+
dimension=dimension,
|
|
192
|
+
fields=fields,
|
|
193
|
+
aux_variables=aux_variables,
|
|
194
|
+
parameters=parameters,
|
|
195
|
+
_default_parameters=_default_parameters,
|
|
196
|
+
boundary_conditions=boundary_conditions,
|
|
197
|
+
initial_conditions=initial_conditions,
|
|
198
|
+
settings={**settings_default, **settings},
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
def flux(self):
|
|
202
|
+
fx = Matrix([0 for i in range(self.n_variables)])
|
|
203
|
+
fy = Matrix([0 for i in range(self.n_variables)])
|
|
204
|
+
h = self.variables[0]
|
|
205
|
+
hu = self.variables[1]
|
|
206
|
+
hv = self.variables[2]
|
|
207
|
+
p = self.parameters
|
|
208
|
+
fx[0] = hu
|
|
209
|
+
fx[1] = hu**2 / h + p.g * p.ez * h * h / 2
|
|
210
|
+
fx[2] = hu * hv / h
|
|
211
|
+
fy[0] = hv
|
|
212
|
+
fy[1] = hu * hv / h
|
|
213
|
+
fy[2] = hv**2 / h + p.g * p.ez * h * h / 2
|
|
214
|
+
return [fx, fy]
|
|
215
|
+
|
|
216
|
+
def topography(self):
|
|
217
|
+
assert "dhdx" in vars(self.aux_variables)
|
|
218
|
+
assert "dhdy" in vars(self.aux_variables)
|
|
219
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
220
|
+
h = self.variables[0]
|
|
221
|
+
hu = self.variables[1]
|
|
222
|
+
hv = self.variables[2]
|
|
223
|
+
p = self.parameters
|
|
224
|
+
dhdx = self.aux_variables.dhdx
|
|
225
|
+
dhdy = self.aux_variables.dhdy
|
|
226
|
+
out[1] = h * p.g * (p.ex - p.ez * dhdx)
|
|
227
|
+
out[2] = h * p.g * (p.ey - p.ez * dhdy)
|
|
228
|
+
return out
|
|
229
|
+
|
|
230
|
+
def newtonian(self):
|
|
231
|
+
assert "nu" in vars(self.parameters)
|
|
232
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
233
|
+
h = self.variables[0]
|
|
234
|
+
hu = self.variables[1]
|
|
235
|
+
hv = self.variables[2]
|
|
236
|
+
p = self.parameters
|
|
237
|
+
out[1] = -p.nu * hu / h
|
|
238
|
+
out[2] = -p.nu * hv / h
|
|
239
|
+
return out
|
|
240
|
+
|
|
241
|
+
def manning(self):
|
|
242
|
+
assert "nu" in vars(self.parameters)
|
|
243
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
244
|
+
h = self.variables[0]
|
|
245
|
+
hu = self.variables[1]
|
|
246
|
+
hv = self.variables[2]
|
|
247
|
+
u = hu / h
|
|
248
|
+
v = hv / h
|
|
249
|
+
p = self.parameters
|
|
250
|
+
out[1] = -p.g * (p.nu**2) * hu * Abs(u) ** (7 / 3)
|
|
251
|
+
out[2] = -p.g * (p.nu**2) * hv * Abs(v) ** (7 / 3)
|
|
252
|
+
return out
|
|
253
|
+
|
|
254
|
+
def chezy(self):
|
|
255
|
+
assert "C" in vars(self.parameters)
|
|
256
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
257
|
+
h = self.variables[0]
|
|
258
|
+
hu = self.variables[1]
|
|
259
|
+
hv = self.variables[2]
|
|
260
|
+
u = hu / h
|
|
261
|
+
v = hv / h
|
|
262
|
+
p = self.parameters
|
|
263
|
+
u_sq = sqrt(u**2 + v**2)
|
|
264
|
+
out[1] = -1.0 / p.C**2 * u * u_sq
|
|
265
|
+
out[2] = -1.0 / p.C**2 * v * u_sq
|
|
266
|
+
return out
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import os
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
import sympy
|
|
6
|
+
from sympy import Symbol, Matrix, lambdify, transpose, Abs, sqrt
|
|
7
|
+
|
|
8
|
+
from sympy import zeros, ones
|
|
9
|
+
|
|
10
|
+
from attr import define, field
|
|
11
|
+
from typing import Optional
|
|
12
|
+
from types import SimpleNamespace
|
|
13
|
+
|
|
14
|
+
from library.zoomy_core.model.boundary_conditions import BoundaryConditions, Extrapolation
|
|
15
|
+
from library.zoomy_core.model.initial_conditions import InitialConditions, Constant
|
|
16
|
+
from library.zoomy_core.misc.custom_types import FArray
|
|
17
|
+
from library.zoomy_core.model.basemodel import Model, eigenvalue_dict_to_matrix
|
|
18
|
+
|
|
19
|
+
from library.zoomy_core.misc.misc import Zstruct
|
|
20
|
+
|
|
21
|
+
@define(frozen=True, slots=True, kw_only=True)
|
|
22
|
+
class ShallowWaterEquationsWithTopo1D(Model):
|
|
23
|
+
dimension: int = 1
|
|
24
|
+
variables: Zstruct = field(default=3)
|
|
25
|
+
aux_variables: Zstruct = field(default=0)
|
|
26
|
+
|
|
27
|
+
@define(frozen=True, slots=True, kw_only=True)
|
|
28
|
+
class ShallowWaterEquationsWithTopo(Model):
|
|
29
|
+
dimension: int=2
|
|
30
|
+
variables: Zstruct = field(default=4)
|
|
31
|
+
aux_variables: Zstruct = field(default=0)
|
|
32
|
+
_default_parameters: dict = field(
|
|
33
|
+
init=False,
|
|
34
|
+
factory=lambda: {"g": 9.81, "ex": 0.0, "ey": 0.0, "ez": 1.0}
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def __attrs_post_init__(self):
|
|
38
|
+
if type(self.variables)==int:
|
|
39
|
+
object.__setattr__(self, "variables",self.dimension+2)
|
|
40
|
+
super().__attrs_post_init__()
|
|
41
|
+
|
|
42
|
+
def compute_hinv(self):
|
|
43
|
+
h = self.variables[1]
|
|
44
|
+
return 1 / h
|
|
45
|
+
|
|
46
|
+
def get_primitives(self):
|
|
47
|
+
dim = self.dimension
|
|
48
|
+
b = self.variables[0]
|
|
49
|
+
h = self.variables[1]
|
|
50
|
+
hinv = self.compute_hinv()
|
|
51
|
+
U = [self.variables[2 + i] * hinv for i in range(dim)]
|
|
52
|
+
return b, h, U, hinv
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def project_2d_to_3d(self):
|
|
56
|
+
out = Matrix([0 for i in range(5)])
|
|
57
|
+
dim = self.dimension
|
|
58
|
+
x = self.position[0]
|
|
59
|
+
y = self.position[1]
|
|
60
|
+
z = self.position[2]
|
|
61
|
+
b, h, U, hinv = self.get_primitives()
|
|
62
|
+
rho_w = 1000.
|
|
63
|
+
g = 9.81
|
|
64
|
+
out[0] = h
|
|
65
|
+
out[1] = U[0]
|
|
66
|
+
out[2] = 0 if dim == 1 else U[1]
|
|
67
|
+
out[3] = 0
|
|
68
|
+
out[4] = rho_w * g * h * (1-z)
|
|
69
|
+
return out
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def flux(self):
|
|
74
|
+
dim = self.dimension
|
|
75
|
+
h = self.variables[1]
|
|
76
|
+
U = Matrix([hu / h for hu in self.variables[2:2+dim]])
|
|
77
|
+
g = self.parameters.g
|
|
78
|
+
I = Matrix.eye(dim)
|
|
79
|
+
F = Matrix.zeros(self.variables.length(), dim)
|
|
80
|
+
F[1, :] = (h * U).T
|
|
81
|
+
F[2:, :] = h * U * U.T + g/2 * h**2 * I
|
|
82
|
+
return [F[:, d] for d in range(dim)]
|
|
83
|
+
|
|
84
|
+
def nonconservative_matrix(self):
|
|
85
|
+
nc_x = Matrix([[0 for i in range(self.n_variables)] for j in range(self.n_variables)])
|
|
86
|
+
nc_y = Matrix([[0 for i in range(self.n_variables)] for j in range(self.n_variables)])
|
|
87
|
+
b, h, U, hinv = self.get_primitives()
|
|
88
|
+
p = self.parameters
|
|
89
|
+
nc_x[1, 0] = p.g * h
|
|
90
|
+
nc_y[1, 0] = p.g * h
|
|
91
|
+
return [nc_x, nc_y][:self.dimension]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def source(self):
|
|
95
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
96
|
+
return out
|
|
97
|
+
|
|
98
|
+
def chezy(self):
|
|
99
|
+
assert "C" in vars(self.parameters)
|
|
100
|
+
dim = self.dimension
|
|
101
|
+
out = Matrix([0 for i in range(self.n_variables)])
|
|
102
|
+
h = self.variables[0]
|
|
103
|
+
hU = self.variables[1:1+dim]
|
|
104
|
+
U = Matrix([hu / h for hu in hU])
|
|
105
|
+
p = self.parameters
|
|
106
|
+
u_sq = sqrt(U.dot(U))
|
|
107
|
+
out[2:2+dim] = -1.0 / p.C**2 * U * u_sq
|
|
108
|
+
return out
|
|
109
|
+
|
|
110
|
+
return self._simplify(eigenvalue_dict_to_matrix(A.eigenvals()))
|
|
111
|
+
|