zoomy-core 0.1.1__py3-none-any.whl → 0.1.3__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/mesh.py +1234 -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/interpolation.py +140 -0
- zoomy_core/misc/io.py +438 -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/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/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.1.dist-info → zoomy_core-0.1.3.dist-info}/METADATA +2 -1
- zoomy_core-0.1.3.dist-info/RECORD +51 -0
- zoomy_core-0.1.3.dist-info/top_level.txt +1 -0
- zoomy_core-0.1.1.dist-info/RECORD +0 -5
- zoomy_core-0.1.1.dist-info/top_level.txt +0 -1
- {zoomy_core-0.1.1.dist-info → zoomy_core-0.1.3.dist-info}/WHEEL +0 -0
- {zoomy_core-0.1.1.dist-info → zoomy_core-0.1.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import numpy.polynomial.legendre as L
|
|
3
|
+
import numpy.polynomial.chebyshev as C
|
|
4
|
+
from scipy.optimize import least_squares as lsq
|
|
5
|
+
import sympy
|
|
6
|
+
from sympy import Matrix, sqrt
|
|
7
|
+
from sympy.abc import x
|
|
8
|
+
|
|
9
|
+
from sympy import integrate, diff
|
|
10
|
+
from sympy import legendre
|
|
11
|
+
from sympy import lambdify
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from library.zoomy_core.model.basemodel import (
|
|
15
|
+
register_sympy_attribute,
|
|
16
|
+
eigenvalue_dict_to_matrix,
|
|
17
|
+
)
|
|
18
|
+
from library.zoomy_core.model.basemodel import Model
|
|
19
|
+
import library.zoomy_core.model.initial_conditions as IC
|
|
20
|
+
|
|
21
|
+
class VAMHyperbolic(Model):
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
boundary_conditions,
|
|
25
|
+
initial_conditions,
|
|
26
|
+
dimension=1,
|
|
27
|
+
fields=6,
|
|
28
|
+
aux_variables=['hw2', 'hp0', 'hp1', 'dbdx', 'dhdx', 'dhp0dx', 'dhp1dx'],
|
|
29
|
+
parameters={},
|
|
30
|
+
_default_parameters={"g": 9.81},
|
|
31
|
+
settings={},
|
|
32
|
+
settings_default={},
|
|
33
|
+
):
|
|
34
|
+
self.variables = register_sympy_attribute(fields, "q")
|
|
35
|
+
self.n_variables = self.variables.length()
|
|
36
|
+
super().__init__(
|
|
37
|
+
dimension=dimension,
|
|
38
|
+
fields=fields,
|
|
39
|
+
aux_variables=aux_variables,
|
|
40
|
+
parameters=parameters,
|
|
41
|
+
_default_parameters=_default_parameters,
|
|
42
|
+
boundary_conditions=boundary_conditions,
|
|
43
|
+
initial_conditions=initial_conditions,
|
|
44
|
+
settings={**settings_default, **settings},
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def flux(self):
|
|
48
|
+
fx = Matrix([0 for i in range(self.n_variables)])
|
|
49
|
+
hw2 = self.aux_variables.hw2
|
|
50
|
+
h = self.variables[0]
|
|
51
|
+
hu0 = self.variables[1]
|
|
52
|
+
hu1 = self.variables[2]
|
|
53
|
+
hw0 = self.variables[3]
|
|
54
|
+
hw1 = self.variables[4]
|
|
55
|
+
param = self.parameters
|
|
56
|
+
|
|
57
|
+
u0 = hu0 / h
|
|
58
|
+
u1 = hu1 / h
|
|
59
|
+
w0 = hw0 / h
|
|
60
|
+
w1 = hw1 / h
|
|
61
|
+
|
|
62
|
+
fx[0] = hu0
|
|
63
|
+
fx[1] = hu0 * u0 + 1/3 * hu1 * u1 * u1
|
|
64
|
+
fx[2] = hu0 * w0 + 1/3 * hu1 * w1
|
|
65
|
+
fx[3] = 2*hu0 * u1
|
|
66
|
+
fx[4] = hu0 * w1 + u1 * (hw0 + 2/5*hw2)
|
|
67
|
+
|
|
68
|
+
return [fx]
|
|
69
|
+
|
|
70
|
+
def nonconservative_matrix(self):
|
|
71
|
+
nc = Matrix([[0 for i in range(self.n_variables)] for j in range(self.n_variables)])
|
|
72
|
+
|
|
73
|
+
hw2 = self.aux_variables.hw2
|
|
74
|
+
h = self.variables[0]
|
|
75
|
+
hu0 = self.variables[1]
|
|
76
|
+
hu1 = self.variables[2]
|
|
77
|
+
hw0 = self.variables[3]
|
|
78
|
+
hw1 = self.variables[4]
|
|
79
|
+
param = self.parameters
|
|
80
|
+
|
|
81
|
+
u0 = hu0 / h
|
|
82
|
+
u1 = hu1 / h
|
|
83
|
+
w0 = hw0 / h
|
|
84
|
+
w1 = hw1 / h
|
|
85
|
+
w2 = hw2 / h
|
|
86
|
+
|
|
87
|
+
nc[1, 0] = param.g * h
|
|
88
|
+
nc[3, 2] = u0
|
|
89
|
+
nc[4, 2] = - 1/5 * w2 + w0
|
|
90
|
+
nc[1, 5] = param.g * h
|
|
91
|
+
return [-nc]
|
|
92
|
+
|
|
93
|
+
def eigenvalues(self):
|
|
94
|
+
ev = Matrix([0 for i in range(self.n_variables)])
|
|
95
|
+
h = self.variables[0]
|
|
96
|
+
hu0 = self.variables[1]
|
|
97
|
+
hu1 = self.variables[2]
|
|
98
|
+
param = self.parameters
|
|
99
|
+
|
|
100
|
+
u0 = hu0 / h
|
|
101
|
+
u1 = hu1 / h
|
|
102
|
+
|
|
103
|
+
ev[0] = u0
|
|
104
|
+
ev[1] = u0 + 1/sqrt(3) * u1
|
|
105
|
+
ev[2] = u0 - 1/sqrt(3) * u1
|
|
106
|
+
ev[3] = u0 + sqrt(param.g * h + u1**2)
|
|
107
|
+
ev[4] = u0 - sqrt(param.g * h + u1**2)
|
|
108
|
+
ev[5] = 0
|
|
109
|
+
|
|
110
|
+
return ev
|
|
111
|
+
|
|
112
|
+
def source_implicit(self):
|
|
113
|
+
R = Matrix([0 for i in range(self.n_variables)])
|
|
114
|
+
hw2 = self.aux_variables.hw2
|
|
115
|
+
h = self.variables[0]
|
|
116
|
+
hu0 = self.variables[1]
|
|
117
|
+
hu1 = self.variables[2]
|
|
118
|
+
hw0 = self.variables[3]
|
|
119
|
+
hw1 = self.variables[4]
|
|
120
|
+
b = self.variables[5]
|
|
121
|
+
param = self.parameters
|
|
122
|
+
|
|
123
|
+
u0 = hu0 / h
|
|
124
|
+
u1 = hu1 / h
|
|
125
|
+
w0 = hw0 / h
|
|
126
|
+
w1 = hw1 / h
|
|
127
|
+
w2 = hw2 /h
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
p0 = self.aux_variables.hp0/h
|
|
131
|
+
p1 = self.aux_variables.hp1/h
|
|
132
|
+
dbdx = self.aux_variables.dbdx
|
|
133
|
+
dhdx = self.aux_variables.dhdx
|
|
134
|
+
dhp0dx = self.aux_variables.dhp0dx
|
|
135
|
+
dhp1dx = self.aux_variables.dhp1dx
|
|
136
|
+
|
|
137
|
+
R[0] = 0.
|
|
138
|
+
R[1] = dhp0dx + 2 * p1 * dbdx
|
|
139
|
+
R[2] = -2*p1
|
|
140
|
+
R[3] = dhp1dx - (3*p0 - p1)*dhdx -6*(p0-p1)*dbdx
|
|
141
|
+
R[4] = 6*(p0-p1)
|
|
142
|
+
R[5] = 0.
|
|
143
|
+
return R
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class VAMPoisson(Model):
|
|
147
|
+
def __init__(
|
|
148
|
+
self,
|
|
149
|
+
boundary_conditions,
|
|
150
|
+
initial_conditions,
|
|
151
|
+
dimension=1,
|
|
152
|
+
fields=['hp0', 'hp1'],
|
|
153
|
+
aux_variables=['h', 'hu0', 'hu1', 'hw0', 'hw1' ,'b', 'hw2', 'dbdx', 'ddbdxx', 'dhdx', 'ddhdxx', 'du0dx', 'du1dx', 'dhp0dx', 'ddhp0dxx', 'dhp1dx', 'ddhp1dxx', 'dt', 'd4hp0dx4', 'd4hp1dx4'],
|
|
154
|
+
parameters={},
|
|
155
|
+
_default_parameters={"g": 9.81},
|
|
156
|
+
settings={},
|
|
157
|
+
settings_default={},
|
|
158
|
+
):
|
|
159
|
+
self.variables = register_sympy_attribute(fields, "q")
|
|
160
|
+
self.n_variables = self.variables.length()
|
|
161
|
+
super().__init__(
|
|
162
|
+
dimension=dimension,
|
|
163
|
+
fields=fields,
|
|
164
|
+
aux_variables=aux_variables,
|
|
165
|
+
parameters=parameters,
|
|
166
|
+
_default_parameters=_default_parameters,
|
|
167
|
+
boundary_conditions=boundary_conditions,
|
|
168
|
+
initial_conditions=initial_conditions,
|
|
169
|
+
settings={**settings_default, **settings},
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
def source_implicit(self):
|
|
173
|
+
R = Matrix([0 for i in range(self.n_variables)])
|
|
174
|
+
|
|
175
|
+
h = self.aux_variables.h
|
|
176
|
+
#p0 = self.variables.p0/h
|
|
177
|
+
#p1 = self.variables.p1/h
|
|
178
|
+
dt = self.aux_variables.dt
|
|
179
|
+
|
|
180
|
+
dbdx = self.aux_variables.dbdx
|
|
181
|
+
ddbdxx = self.aux_variables.ddbdxx
|
|
182
|
+
dhdx = self.aux_variables.dhdx
|
|
183
|
+
ddhdxx = self.aux_variables.ddhdxx
|
|
184
|
+
#dp0dx = self.aux_variables.dp0dx
|
|
185
|
+
#ddp0dxx = self.aux_variables.ddp0dxx
|
|
186
|
+
#dp1dx = self.aux_variables.dp1dx
|
|
187
|
+
#ddp1dxx = self.aux_variables.ddp1dxx
|
|
188
|
+
du0dx = self.aux_variables.du0dx
|
|
189
|
+
du1dx = self.aux_variables.du1dx
|
|
190
|
+
|
|
191
|
+
u0 = self.aux_variables.hu0/h
|
|
192
|
+
u1 = self.aux_variables.hu1/h
|
|
193
|
+
w0 = self.aux_variables.hw0/h
|
|
194
|
+
w1 = self.aux_variables.hw1/h
|
|
195
|
+
|
|
196
|
+
hp0 = self.variables.hp0
|
|
197
|
+
hp1 = self.variables.hp1
|
|
198
|
+
dhp0dx = self.aux_variables.dhp0dx
|
|
199
|
+
ddhp0dxx = self.aux_variables.ddhp0dxx
|
|
200
|
+
dhp1dx = self.aux_variables.dhp1dx
|
|
201
|
+
ddhp1dxx = self.aux_variables.ddhp1dxx
|
|
202
|
+
d4hp0dx4 = self.aux_variables.d4hp0dx4
|
|
203
|
+
d4hp1dx4 = self.aux_variables.d4hp1dx4
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
delta = 0.
|
|
209
|
+
#I1 = 0.666666666666667*dt*dp0dx - 2*(-dt*(h*ddp0dxx + p0*dhdx + 2*p1*dbdx) + h*dp1dx)*dbdx/h + 2*(-dt*(-(3*p0 - p1)*dhdx - (6*p0 - 6*p1)*dbdx + h*dp0dx + p1*dhdx) + h*u1)/h + 0.333333333333333*(2*dt*p1 + h*u0)*dhdx/h + (-(-dt*(h*ddp0dxx + p0*dhdx + 2*p1*dbdx) + h*dp1dx)*dhdx/h**2 + (-dt*(h*du1dx + p0*ddhdxx + 2*p1*ddbdxx + 2*dbdx*dp0dx + 2*dhdx*ddp0dxx) + h*dhdx + dp1dx*dhdx)/h)*h + 0.333333333333333*h*du0dx + 0.333333333333333*u0*dhdx + delta * ddp0dxx
|
|
210
|
+
#I2 = -2*(-dt*(6*p0 - 6*p1) + h*w0)/h + 2*(2*dt*p1 + h*u0)*dbdx/h + (2*dt*p1 + h*u0)*dhdx/h + (-(-dt*(h*ddp0dxx + p0*dhdx + 2*p1*dbdx) + h*dp1dx)*dhdx/h**2 + (-dt*(h*du1dx + p0*ddhdxx + 2*p1*ddbdxx + 2*dbdx*dp0dx + 2*dhdx*ddp0dxx) + h*dhdx + dp1dx*dhdx)/h)*h + delta * ddp1dxx
|
|
211
|
+
I1 = 0.666666666666667*dt*dhp1dx/h - 0.666666666666667*dt*hp1*dhdx/h**2 - 2*(-dt*(dhp0dx + 2*hp1*dbdx/h) + h*u0)*dbdx/h + 2*(-dt*(-(3*hp0/h - hp1/h)*dhdx - (6*hp0/h - 6*hp1/h)*dbdx + dhp1dx) + h*w0)/h + 0.333333333333333*(2*dt*hp1/h + h*u1)*dhdx/h + (-(-dt*(dhp0dx + 2*hp1*dbdx/h) + h*u0)*dhdx/h**2 + (-dt*(ddhp0dxx + 2*hp1*ddbdxx/h + 2*dbdx*dhp1dx/h - 2*hp1*dbdx*dhdx/h**2) + h*du0dx + u0*dhdx)/h)*h + 0.333333333333333*h*du1dx + 0.333333333333333*u1*dhdx + delta *ddhp0dxx
|
|
212
|
+
I2 = -2*(-dt*(6*hp0/h - 6*hp1/h) + h*w1)/h + 2*(2*dt*hp1/h + h*u1)*dbdx/h + (2*dt*hp1/h + h*u1)*dhdx/h + (-(-dt*(dhp0dx + 2*hp1*dbdx/h) + h*u0)*dhdx/h**2 + (-dt*(ddhp0dxx + 2*hp1*ddbdxx/h + 2*dbdx*dhp1dx/h - 2*hp1*dbdx*dhdx/h**2) + h*du0dx + u0*dhdx)/h)*h + delta *ddhp1dxx
|
|
213
|
+
R[0] = I1 +I2
|
|
214
|
+
R[1] = -I2 + I1
|
|
215
|
+
|
|
216
|
+
return R
|
|
217
|
+
|
|
218
|
+
def eigenvalues(self):
|
|
219
|
+
ev = Matrix([0 for i in range(self.n_variables)])
|
|
220
|
+
return ev
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class VAMPoissonFull(Model):
|
|
224
|
+
def __init__(
|
|
225
|
+
self,
|
|
226
|
+
boundary_conditions,
|
|
227
|
+
initial_conditions,
|
|
228
|
+
dimension=1,
|
|
229
|
+
fields=8,
|
|
230
|
+
aux_variables=['dhdt', 'dhu0dt', 'dhu1dt', 'dhw0dt', 'dhw1dt', 'dhdx', 'dhu0dx', 'dhu1dx', 'dhw0dx', 'dhw1dx', 'dhp0dx', 'dhp1dx', 'dbdx', 'hw2', 'ddp0dxx', 'ddp1dxx', 'du0dx', 'du1dx'],
|
|
231
|
+
parameters={},
|
|
232
|
+
_default_parameters={"g": 1},
|
|
233
|
+
settings={},
|
|
234
|
+
settings_default={},
|
|
235
|
+
):
|
|
236
|
+
self.variables = register_sympy_attribute(fields, "q")
|
|
237
|
+
self.n_variables = self.variables.length()
|
|
238
|
+
super().__init__(
|
|
239
|
+
dimension=dimension,
|
|
240
|
+
fields=fields,
|
|
241
|
+
aux_variables=aux_variables,
|
|
242
|
+
parameters=parameters,
|
|
243
|
+
_default_parameters=_default_parameters,
|
|
244
|
+
boundary_conditions=boundary_conditions,
|
|
245
|
+
initial_conditions=initial_conditions,
|
|
246
|
+
settings={**settings_default, **settings},
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
def source_implicit(self):
|
|
250
|
+
R = Matrix([0 for i in range(self.n_variables)])
|
|
251
|
+
hw2 = self.aux_variables.hw2
|
|
252
|
+
h = self.variables[0]
|
|
253
|
+
hu0 = self.variables[1]
|
|
254
|
+
hu1 = self.variables[2]
|
|
255
|
+
hw0 = self.variables[3]
|
|
256
|
+
hw1 = self.variables[4]
|
|
257
|
+
b = self.variables[5]
|
|
258
|
+
p0 = self.variables[6]/h
|
|
259
|
+
p1 = self.variables[7]/h
|
|
260
|
+
param = self.parameters
|
|
261
|
+
|
|
262
|
+
u0 = hu0 / h
|
|
263
|
+
u1 = hu1 / h
|
|
264
|
+
w0 = hw0 / h
|
|
265
|
+
w1 = hw1 / h
|
|
266
|
+
w2 = hw2 /h
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
dhdt = self.aux_variables.dhdt
|
|
270
|
+
dhu0dt = self.aux_variables.dhu0dt
|
|
271
|
+
dhu1dt = self.aux_variables.dhu1dt
|
|
272
|
+
dhw0dt = self.aux_variables.dhw0dt
|
|
273
|
+
dhw1dt = self.aux_variables.dhw1dt
|
|
274
|
+
dhdx = self.aux_variables.dhdx
|
|
275
|
+
dhu0dx = self.aux_variables.dhu0dx
|
|
276
|
+
dhu1dx = self.aux_variables.dhu1dx
|
|
277
|
+
dhw0dx = self.aux_variables.dhw0dx
|
|
278
|
+
dhw1dx = self.aux_variables.dhw1dx
|
|
279
|
+
dhp0dx = self.aux_variables.dhp0dx
|
|
280
|
+
dhp1dx = self.aux_variables.dhp1dx
|
|
281
|
+
dbdx = self.aux_variables.dbdx
|
|
282
|
+
du0dx = self.aux_variables.du0dx
|
|
283
|
+
ddp0dxx = self.aux_variables.ddp0dxx
|
|
284
|
+
ddp1dxx = self.aux_variables.ddp1dxx
|
|
285
|
+
|
|
286
|
+
R[0] = dhdt
|
|
287
|
+
R[1] = dhu0dt + dhp0dx + 2 * p1 * dbdx
|
|
288
|
+
R[2] = dhu1dt -2*p1
|
|
289
|
+
R[3] = dhw0dt + dhp1dx - (3*p0 - p1)*dhdx -6*(p0-p1)*dbdx
|
|
290
|
+
R[4] = 6*(p0-p1)
|
|
291
|
+
R[5] = 0.
|
|
292
|
+
I1 = h*du0dx + 1/3 * dhu1dx + 1/3 * u1 * dhdx + 2*(w0 - u0 * dbdx)
|
|
293
|
+
I2 = h * du0dx + u1*dhdx + 2*(u1 * dbdx - w1)
|
|
294
|
+
R[6] = I1 + I2
|
|
295
|
+
R[7] = I1 - I2
|
|
296
|
+
|
|
297
|
+
delta = 0.0
|
|
298
|
+
R[6] += delta * (ddp0dxx )
|
|
299
|
+
R[7] += delta * (ddp1dxx)
|
|
300
|
+
|
|
301
|
+
return R
|
|
302
|
+
|
|
303
|
+
def eigenvalues(self):
|
|
304
|
+
ev = Matrix([0 for i in range(self.n_variables)])
|
|
305
|
+
return ev
|
|
306
|
+
|
|
307
|
+
class VAMFullImplicit(Model):
|
|
308
|
+
def __init__(
|
|
309
|
+
self,
|
|
310
|
+
boundary_conditions,
|
|
311
|
+
initial_conditions,
|
|
312
|
+
dimension=1,
|
|
313
|
+
fields=8,
|
|
314
|
+
aux_variables=[ 'hw2', 'dhdt', 'dhu0dt', 'dhu1dt', 'dhw0dt', 'dhw1dt', 'dhdx', 'dhu0dx', 'dhu1dx', 'dhw0dx', 'dhw1dx', 'dhp0dx', 'dhp1dx', 'dbdx','ddhp0dxx', 'ddhp1dxx', 'du0dx', 'du1dx'],
|
|
315
|
+
parameters={},
|
|
316
|
+
_default_parameters={"g": 9.81},
|
|
317
|
+
settings={},
|
|
318
|
+
settings_default={},
|
|
319
|
+
):
|
|
320
|
+
self.variables = register_sympy_attribute(fields, "q")
|
|
321
|
+
self.n_variables = self.variables.length()
|
|
322
|
+
super().__init__(
|
|
323
|
+
dimension=dimension,
|
|
324
|
+
fields=fields,
|
|
325
|
+
aux_variables=aux_variables,
|
|
326
|
+
parameters=parameters,
|
|
327
|
+
_default_parameters=_default_parameters,
|
|
328
|
+
boundary_conditions=boundary_conditions,
|
|
329
|
+
initial_conditions=initial_conditions,
|
|
330
|
+
settings={**settings_default, **settings},
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
def source_implicit(self):
|
|
334
|
+
R = Matrix([0 for i in range(self.n_variables)])
|
|
335
|
+
hw2 = self.aux_variables.hw2
|
|
336
|
+
h = self.variables[0]
|
|
337
|
+
hu0 = self.variables[1]
|
|
338
|
+
hu1 = self.variables[2]
|
|
339
|
+
hw0 = self.variables[3]
|
|
340
|
+
hw1 = self.variables[4]
|
|
341
|
+
b = self.variables[5]
|
|
342
|
+
p0 = self.variables[6]/h
|
|
343
|
+
p1 = self.variables[7]/h
|
|
344
|
+
param = self.parameters
|
|
345
|
+
|
|
346
|
+
u0 = hu0 / h
|
|
347
|
+
u1 = hu1 / h
|
|
348
|
+
w0 = hw0 / h
|
|
349
|
+
w1 = hw1 / h
|
|
350
|
+
w2 = hw2 /h
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
dhdt = self.aux_variables.dhdt
|
|
354
|
+
dhu0dt = self.aux_variables.dhu0dt
|
|
355
|
+
dhu1dt = self.aux_variables.dhu1dt
|
|
356
|
+
dhw0dt = self.aux_variables.dhw0dt
|
|
357
|
+
dhw1dt = self.aux_variables.dhw1dt
|
|
358
|
+
dhdx = self.aux_variables.dhdx
|
|
359
|
+
dhu0dx = self.aux_variables.dhu0dx
|
|
360
|
+
dhu1dx = self.aux_variables.dhu1dx
|
|
361
|
+
dhw0dx = self.aux_variables.dhw0dx
|
|
362
|
+
dhw1dx = self.aux_variables.dhw1dx
|
|
363
|
+
dhp0dx = self.aux_variables.dhp0dx
|
|
364
|
+
dhp1dx = self.aux_variables.dhp1dx
|
|
365
|
+
dbdx = self.aux_variables.dbdx
|
|
366
|
+
du0dx = self.aux_variables.du0dx
|
|
367
|
+
ddhp0dxx = self.aux_variables.ddhp0dxx
|
|
368
|
+
ddhp1dxx = self.aux_variables.ddhp1dxx
|
|
369
|
+
|
|
370
|
+
R[0] = dhdt
|
|
371
|
+
R[1] = dhu0dt + dhp0dx + 2 * p1 * dbdx
|
|
372
|
+
R[2] = dhu1dt -2*p1
|
|
373
|
+
R[3] = dhw0dt + dhp1dx - (3*p0 - p1)*dhdx -6*(p0-p1)*dbdx
|
|
374
|
+
R[4] = 6*(p0-p1)
|
|
375
|
+
R[5] = 0.
|
|
376
|
+
I1 = h*du0dx + 1/3 * dhu1dx + 1/3 * u1 * dhdx + 2*(w0 - u0 * dbdx)
|
|
377
|
+
I2 = h * du0dx + u1*dhdx + 2*(u1 * dbdx - w1)
|
|
378
|
+
R[6] = I1
|
|
379
|
+
R[7] = I2
|
|
380
|
+
|
|
381
|
+
delta = 0.1
|
|
382
|
+
R[6] += delta * (ddhp0dxx )
|
|
383
|
+
R[7] += delta * (ddhp1dxx)
|
|
384
|
+
|
|
385
|
+
return R
|
|
386
|
+
|
|
387
|
+
def flux(self):
|
|
388
|
+
fx = Matrix([0 for i in range(self.n_variables)])
|
|
389
|
+
hw2 = self.aux_variables.hw2
|
|
390
|
+
h = self.variables[0]
|
|
391
|
+
hu0 = self.variables[1]
|
|
392
|
+
hu1 = self.variables[2]
|
|
393
|
+
hw0 = self.variables[3]
|
|
394
|
+
hw1 = self.variables[4]
|
|
395
|
+
param = self.parameters
|
|
396
|
+
|
|
397
|
+
u0 = hu0 / h
|
|
398
|
+
u1 = hu1 / h
|
|
399
|
+
w0 = hw0 / h
|
|
400
|
+
w1 = hw1 / h
|
|
401
|
+
|
|
402
|
+
fx[0] = hu0
|
|
403
|
+
fx[1] = hu0 * u0 + 1/3 * hu1 * u1 * u1
|
|
404
|
+
fx[2] = hu0 * w0 + 1/3 * hu1 * w1
|
|
405
|
+
fx[3] = 2*hu0 * u1
|
|
406
|
+
fx[4] = hu0 * w1 + u1 * (hw0 + 2/5*hw2)
|
|
407
|
+
|
|
408
|
+
return [fx]
|
|
409
|
+
|
|
410
|
+
def nonconservative_matrix(self):
|
|
411
|
+
nc = Matrix([[0 for i in range(self.n_variables)] for j in range(self.n_variables)])
|
|
412
|
+
|
|
413
|
+
hw2 = self.aux_variables.hw2
|
|
414
|
+
h = self.variables[0]
|
|
415
|
+
hu0 = self.variables[1]
|
|
416
|
+
hu1 = self.variables[2]
|
|
417
|
+
hw0 = self.variables[3]
|
|
418
|
+
hw1 = self.variables[4]
|
|
419
|
+
param = self.parameters
|
|
420
|
+
|
|
421
|
+
u0 = hu0 / h
|
|
422
|
+
u1 = hu1 / h
|
|
423
|
+
w0 = hw0 / h
|
|
424
|
+
w1 = hw1 / h
|
|
425
|
+
w2 = hw2 / h
|
|
426
|
+
|
|
427
|
+
nc[1, 0] = param.g * h
|
|
428
|
+
nc[3, 2] = u0
|
|
429
|
+
nc[4, 2] = - 1/5 * w2 + w0
|
|
430
|
+
nc[1, 5] = param.g * h
|
|
431
|
+
return [-nc]
|
|
432
|
+
|
|
433
|
+
def eigenvalues(self):
|
|
434
|
+
ev = Matrix([0 for i in range(self.n_variables)])
|
|
435
|
+
h = self.variables[0]
|
|
436
|
+
hu0 = self.variables[1]
|
|
437
|
+
hu1 = self.variables[2]
|
|
438
|
+
param = self.parameters
|
|
439
|
+
|
|
440
|
+
u0 = hu0 / h
|
|
441
|
+
u1 = hu1 / h
|
|
442
|
+
|
|
443
|
+
ev[0] = u0
|
|
444
|
+
ev[1] = u0 + 1/sqrt(3) * u1
|
|
445
|
+
ev[2] = u0 - 1/sqrt(3) * u1
|
|
446
|
+
ev[3] = u0 + sqrt(param.g * h + u1**2)
|
|
447
|
+
ev[4] = u0 - sqrt(param.g * h + u1**2)
|
|
448
|
+
ev[5] = 0
|
|
449
|
+
ev[6] = 0
|
|
450
|
+
ev[7] = 0
|
|
451
|
+
|
|
452
|
+
return ev
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
import h5py
|
|
6
|
+
|
|
7
|
+
_HAVE_H5PY = True
|
|
8
|
+
except ImportError:
|
|
9
|
+
_HAVE_H5PY = False
|
|
10
|
+
|
|
11
|
+
import library.zoomy_core.mesh.mesh as petscMesh
|
|
12
|
+
import library.zoomy_core.misc.io as io
|
|
13
|
+
from library.zoomy_core.misc.logger_config import logger
|
|
14
|
+
from library.zoomy_core.transformation.to_numpy import NumpyRuntimeModel
|
|
15
|
+
|
|
16
|
+
def vtk_project_2d_to_3d(
|
|
17
|
+
model, settings, start_at_time=0, scale_h=1.0, filename='out_3d'
|
|
18
|
+
):
|
|
19
|
+
if not _HAVE_H5PY:
|
|
20
|
+
raise ImportError("h5py is required for vtk_project_2d_to_3d function.")
|
|
21
|
+
Nz = model.number_of_points_3d
|
|
22
|
+
main_dir = os.getenv("ZOOMY_DIR")
|
|
23
|
+
path_to_simulation = os.path.join(main_dir, os.path.join(settings.output.directory, f"{settings.output.filename}.h5"))
|
|
24
|
+
sim = h5py.File(path_to_simulation, "r")
|
|
25
|
+
settings = io.load_settings(settings.output.directory)
|
|
26
|
+
fields = sim["fields"]
|
|
27
|
+
mesh = petscMesh.Mesh.from_hdf5(path_to_simulation)
|
|
28
|
+
n_snapshots = len(list(fields.keys()))
|
|
29
|
+
|
|
30
|
+
Z = np.linspace(0, 1, Nz)
|
|
31
|
+
|
|
32
|
+
mesh_extr = petscMesh.Mesh.extrude_mesh(mesh, Nz)
|
|
33
|
+
output_path = os.path.join(main_dir, settings.output.directory + f"/{filename}.h5")
|
|
34
|
+
mesh_extr.write_to_hdf5(output_path)
|
|
35
|
+
save_fields = io.get_save_fields_simple(output_path, True)
|
|
36
|
+
|
|
37
|
+
#mesh = GradientMesh.fromMesh(mesh)
|
|
38
|
+
i_count = 0
|
|
39
|
+
pde = NumpyRuntimeModel(model)
|
|
40
|
+
for i_snapshot in range(n_snapshots):
|
|
41
|
+
group_name = "iteration_" + str(i_snapshot)
|
|
42
|
+
group = fields[group_name]
|
|
43
|
+
time = group["time"][()]
|
|
44
|
+
if time < start_at_time:
|
|
45
|
+
continue
|
|
46
|
+
Q = group["Q"][()]
|
|
47
|
+
Qaux = group["Qaux"][()]
|
|
48
|
+
|
|
49
|
+
rhoUVWP = np.zeros((Q.shape[1] * Nz, 6), dtype=float)
|
|
50
|
+
|
|
51
|
+
#for i_elem, (q, qaux) in enumerate(zip(Q.T, Qaux.T)):
|
|
52
|
+
# for iz, z in enumerate(Z):
|
|
53
|
+
# rhoUVWP[i_elem + (iz * mesh.n_cells), :] = pde.project_2d_to_3d(np.array([0, 0, z]), q, qaux, parameters)
|
|
54
|
+
|
|
55
|
+
for iz, z in enumerate(Z):
|
|
56
|
+
Qnew = pde.project_2d_to_3d(z, Q[:, :mesh.n_inner_cells], Qaux[:, :mesh.n_inner_cells], model.parameter_values).T
|
|
57
|
+
|
|
58
|
+
#rhoUVWP[i_elem + (iz * mesh.n_cells), :] = pde.project_2d_to_3d(np.array([0, 0, z]), q, qaux, parameters)
|
|
59
|
+
# rhoUVWP[(iz * mesh.n_inner_cells):((iz+1) * mesh.n_inner_cells), 0] = Q[0, :mesh.n_inner_cells]
|
|
60
|
+
rhoUVWP[(iz * mesh.n_inner_cells):((iz+1) * mesh.n_inner_cells), :] = Qnew[iz, :]
|
|
61
|
+
|
|
62
|
+
# rhoUVWP[mesh.n_inner_cells:mesh.n_inner_cells+mesh.n_inner_cells, 0] = Q[0, :mesh.n_inner_cells]
|
|
63
|
+
|
|
64
|
+
qaux = np.zeros((Q.shape[1]*Nz, 1), dtype=float)
|
|
65
|
+
_ = save_fields(i_snapshot, time, rhoUVWP.T, qaux.T)
|
|
66
|
+
i_count += 1
|
|
67
|
+
|
|
68
|
+
logger.info(f"Converted snapshot {i_snapshot}/{n_snapshots}")
|
|
69
|
+
|
|
70
|
+
io.generate_vtk(output_path, filename=filename)
|
|
71
|
+
logger.info(f"Output is written to: {output_path}/{filename}.*.vtk")
|
|
72
|
+
|