zoomy-core 0.1.14__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.
Files changed (57) hide show
  1. decorators/decorators.py +25 -0
  2. fvm/__init__.py +0 -0
  3. fvm/flux.py +52 -0
  4. fvm/nonconservative_flux.py +97 -0
  5. fvm/ode.py +55 -0
  6. fvm/solver_numpy.py +297 -0
  7. fvm/timestepping.py +13 -0
  8. mesh/__init__.py +0 -0
  9. mesh/mesh.py +1239 -0
  10. mesh/mesh_extrude.py +168 -0
  11. mesh/mesh_util.py +487 -0
  12. misc/__init__.py +0 -0
  13. misc/custom_types.py +6 -0
  14. misc/interpolation.py +140 -0
  15. misc/io.py +448 -0
  16. misc/logger_config.py +18 -0
  17. misc/misc.py +218 -0
  18. model/__init__.py +0 -0
  19. model/analysis.py +147 -0
  20. model/basefunction.py +113 -0
  21. model/basemodel.py +513 -0
  22. model/boundary_conditions.py +193 -0
  23. model/initial_conditions.py +171 -0
  24. model/model.py +65 -0
  25. model/models/GN.py +70 -0
  26. model/models/advection.py +53 -0
  27. model/models/basisfunctions.py +181 -0
  28. model/models/basismatrices.py +381 -0
  29. model/models/coupled_constrained.py +60 -0
  30. model/models/poisson.py +41 -0
  31. model/models/shallow_moments.py +757 -0
  32. model/models/shallow_moments_sediment.py +378 -0
  33. model/models/shallow_moments_topo.py +423 -0
  34. model/models/shallow_moments_variants.py +1509 -0
  35. model/models/shallow_water.py +266 -0
  36. model/models/shallow_water_topo.py +111 -0
  37. model/models/shear_shallow_flow.py +594 -0
  38. model/models/sme_turbulent.py +613 -0
  39. model/models/vam.py +455 -0
  40. postprocessing/__init__.py +0 -0
  41. postprocessing/plotting.py +244 -0
  42. postprocessing/postprocessing.py +75 -0
  43. preprocessing/__init__.py +0 -0
  44. preprocessing/openfoam_moments.py +453 -0
  45. transformation/__init__.py +0 -0
  46. transformation/helpers.py +25 -0
  47. transformation/to_amrex.py +241 -0
  48. transformation/to_c.py +185 -0
  49. transformation/to_jax.py +14 -0
  50. transformation/to_numpy.py +118 -0
  51. transformation/to_openfoam.py +258 -0
  52. transformation/to_ufl.py +67 -0
  53. zoomy_core-0.1.14.dist-info/METADATA +52 -0
  54. zoomy_core-0.1.14.dist-info/RECORD +57 -0
  55. zoomy_core-0.1.14.dist-info/WHEEL +5 -0
  56. zoomy_core-0.1.14.dist-info/licenses/LICENSE +674 -0
  57. zoomy_core-0.1.14.dist-info/top_level.txt +8 -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 zoomy_core.model.boundary_conditions import BoundaryConditions, Extrapolation
15
+ from zoomy_core.model.initial_conditions import InitialConditions, Constant
16
+ from zoomy_core.misc.custom_types import FArray
17
+ from zoomy_core.model.basemodel import Model
18
+
19
+ from 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 zoomy_core.model.boundary_conditions import BoundaryConditions, Extrapolation
15
+ from zoomy_core.model.initial_conditions import InitialConditions, Constant
16
+ from zoomy_core.misc.custom_types import FArray
17
+ from zoomy_core.model.basemodel import Model, eigenvalue_dict_to_matrix
18
+
19
+ from 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
+