-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_parameters.py
More file actions
297 lines (251 loc) · 11.4 KB
/
Copy pathmodel_parameters.py
File metadata and controls
297 lines (251 loc) · 11.4 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#/////////////////////////////////////////////////
__author__ = "Chengshun Shang (Utrecht University)"
__copyright__ = "Copyright (C) 2026-present by Chengshun Shang"
__version__ = "0.0.1"
__maintainer__ = "Chengshun Shang"
__email__ = "c.shang@uu.nl"
__status__ = "development"
__date__ = "May 5, 2026"
__license__ = "MIT License"
#/////////////////////////////////////////////////
import numpy as np
from enum import Enum
from dataclasses import dataclass, field
from typing import Optional
from fastslippy.pre_processing.layer_parameters import Layer, LayerParameters
class CaseType(Enum):
GRONINGEN = "groningen"
LAB = "lab"
CALIFORNIA = "california"
class FrictionLaw(Enum):
RATE_STATE = "rate_state"
SLIP_WEAKENING = "slip_weakening"
class LinearSolver(str, Enum):
DIRECT = "direct"
ITERATIVE = "iterative"
class IterativeMethod(str, Enum):
GMRES = "gmres"
BICGSTAB = "bicgstab"
class BCType(str, Enum):
FIXED = "fixed"
FREE = "free"
VELOCITY = "velocity"
TRACTION = "traction"
TRACTION_FREE = "traction_free"
@dataclass
class DirectionBC:
type: BCType = BCType.FIXED
value: float = 0.0
def set_fixed(self):
self.type = BCType.FIXED
self.value = 0.0
def set_free(self):
self.type = BCType.FREE
self.value = 0.0
def set_velocity(self, value: float):
self.type = BCType.VELOCITY
self.value = value
def set_traction(self, value: float):
self.type = BCType.TRACTION
self.value = value
def set_traction_free(self):
self.type = BCType.TRACTION_FREE
self.value = 0.0
@dataclass
class BoundaryFace:
ux: DirectionBC = field(default_factory=DirectionBC)
uy: DirectionBC = field(default_factory=DirectionBC)
def set_fixed(self):
self.ux.set_fixed()
self.uy.set_fixed()
def set_free(self):
self.ux.set_free()
self.uy.set_free()
def set_traction_free(self):
self.ux.set_traction_free()
self.uy.set_traction_free()
def set_velocity_x(self, value: float):
self.ux.set_velocity(value)
def set_velocity_y(self, value: float):
self.uy.set_velocity(value)
def set_traction_x(self, value: float):
self.ux.set_traction(value)
def set_traction_y(self, value: float):
self.uy.set_traction(value)
@dataclass
class BoundaryConditions:
# Grid y increases with depth: top is y=0 (free surface) and bottom is
# y=ysize (deep boundary).
left: BoundaryFace = field(default_factory=BoundaryFace)
right: BoundaryFace = field(default_factory=BoundaryFace)
top: BoundaryFace = field(default_factory=BoundaryFace)
bottom: BoundaryFace = field(default_factory=BoundaryFace)
def set_all_fixed(self):
self.left.set_fixed()
self.right.set_fixed()
self.top.set_fixed()
self.bottom.set_fixed()
def set_all_free(self):
self.left.set_free()
self.right.set_free()
self.top.set_free()
self.bottom.set_free()
@dataclass
class Layer:
name: str
top: float
bottom: float
a: float
b: float
@dataclass
class LoadingConditions:
"""Loading conditions for the model. Edit the defaults here
or pass keyword arguments to the constructor."""
yr = 365 * 24 * 3600.0 # Seconds in a year
tload: float = 0.0 * yr # Time to apply pressure rate change [s]
# --- Pressure rate ---
dPdt_pre: float = 0.0 # Pressure rate before depletion [Pa/s]
dPdt_post: float = -0.0127 # Pressure rate after depletion starts [Pa/s]
V_p: float = 0.0 # Plate velocity [m/s] for the california case
V_L: float = 0.0 # Imposed fault slip velocity [m/s] for the california case
@dataclass
class ModelParameters:
"""
All physical and numerical parameters for the fault-slip model.
Edit the defaults here or pass keyword arguments to the constructor.
"""
case_type: CaseType = CaseType.LAB
run_mode: str = "release" # "debug" or "release"
# --- Fault geometry ---
alpha: float = 90.0 # Fault dip angle [degrees]
# --- Grid ---
xsize: float = 1.0 # Horizontal model size [m]
ysize: float = 1.0 # Vertical model size [m]
Nx: int = 11 # Horizontal grid points (must be odd)
Ny: int = 11 # Vertical grid points (must be odd)
x_stretch_enabled: bool = False
y_stretch_enabled: bool = False
x_stretch_inner_size: float = 0.0
y_stretch_inner_size: float = 0.0
x_stretch_inner_points: int = 0
y_stretch_inner_points: int = 0
x_stretch_power: int = 2
y_stretch_power: int = 2
x_stretch_max_cell_size: Optional[float] = None
y_stretch_max_cell_size: Optional[float] = None
allow_nonuniform_solver: bool = False
# --- Material ---
rho: float = 2650 # Rock density [kg/m³]
rhof: float = 1150.0 # Fluid density [kg/m³]
rhog: float = 200.0 # Gas density [kg/m³]
cs: float = 1645.0 # Shear-wave speed [m/s]
nu: float = 0.25 # Poisson's ratio
g: float = 9.81 # Gravitational acceleration [m/s²]
K0: float = 0.75 # Ratio σ_min / σ_max
E: float = 0.0 # Young's modulus [Pa]
# --- Rate-and-state defaults (used when heterogeneous profile is off) ---
friction_law: FrictionLaw = FrictionLaw.RATE_STATE
mu0: float = 0.72 # Reference friction coefficient
V0: float = 1e-6 # Reference slip rate [m/s]
a0: float = 0.0012 # Direct effect (homogeneous fallback)
a_max: float = 0.025 # Maximum direct effect (for California case)
b0: float = 0.00135 # Evolution effect (homogeneous fallback)
L: float = 2.25e-6 # Characteristic slip distance [m]
Vw: float = 1e90 # Dynamic weakening velocity [m/s]
Vi: float = 1e-30 # Initial/background slip rate [m/s]
flash_heating_option: bool = False # Whether to include flash heating in the friction law
H: float = 0.0 # California case parameter [m]
h: float = 0.0 # California case parameter [m]
W_f: float = 0.0 # California case parameter [m]
# --- Time stepping ---
Nt: int = 1000 # Number of time steps
dt_init: float = 1e-5 # Initial time step [s]
dt_max: float = 0.002 # Maximum time step [s]
# --- Output intervals ---
output_interval: int = 10
checkpoint_interval: int = 1000
output_vtk_option: bool = True
# --- Linear solver ---
linear_solver: LinearSolver = LinearSolver.DIRECT
iterative_method: IterativeMethod = IterativeMethod.GMRES
iterative_rtol: float = 1e-8
iterative_atol: float = 0.0
iterative_maxiter: int = 400
ilu_drop_tol: float = 1e-3
ilu_fill_factor: float = 10.0
ilu_permc_spec: str = "COLAMD"
fallback_to_iterative_on_oom: bool = False
# --- Derived (computed in __post_init__) ---
G: float = field(init=False)
lam: float = field(init=False) # First Lamé parameter (λ)
eta: float = field(init=False) # Radiation damping coefficient
bc: BoundaryConditions = field(default_factory=BoundaryConditions)
loading: LoadingConditions = field(default_factory=LoadingConditions)
layers: LayerParameters = field(default_factory=LayerParameters)
def __post_init__(self):
#self.G = self.rho * self.cs ** 2
if self.E > 0:
self.G = self.E / (2 * (1 + self.nu))
self.cs = np.sqrt(self.G / self.rho)
else:
self.G = self.rho * self.cs ** 2
self.lam = 2 * self.G * (1 + self.nu) / 3 / (1 - 2 * self.nu) - 2 / 3 * self.G
self.eta = self.G / 2 / self.cs
solver_mode = self.linear_solver.value if isinstance(self.linear_solver, LinearSolver) else str(self.linear_solver).lower()
if solver_mode not in (LinearSolver.DIRECT.value, LinearSolver.ITERATIVE.value):
raise ValueError(
"linear_solver must be 'direct' or 'iterative'."
)
self.linear_solver = LinearSolver(solver_mode)
method = self.iterative_method.value if isinstance(self.iterative_method, IterativeMethod) else str(self.iterative_method).lower()
if method not in (IterativeMethod.GMRES.value, IterativeMethod.BICGSTAB.value):
raise ValueError("iterative_method must be 'gmres' or 'bicgstab'.")
self.iterative_method = IterativeMethod(method)
if self.iterative_rtol <= 0.0:
raise ValueError("iterative_rtol must be > 0.")
if self.iterative_atol < 0.0:
raise ValueError("iterative_atol must be >= 0.")
if self.iterative_maxiter < 1:
raise ValueError("iterative_maxiter must be >= 1.")
if self.ilu_drop_tol < 0.0:
raise ValueError("ilu_drop_tol must be >= 0.")
if self.ilu_fill_factor <= 0.0:
raise ValueError("ilu_fill_factor must be > 0.")
if not self.ilu_permc_spec:
raise ValueError("ilu_permc_spec must be a non-empty string.")
assert self.Nx % 2 == 1, "Nx must be odd (fault at centre column)."
assert self.Ny % 2 == 1, "Ny must be odd."
if self.x_stretch_enabled:
if not (0.0 < self.x_stretch_inner_size < self.xsize):
raise ValueError("x_stretch_inner_size must be in (0, xsize).")
if self.x_stretch_inner_points < 3 or self.x_stretch_inner_points >= self.Nx:
raise ValueError("x_stretch_inner_points must be in [3, Nx-1].")
if self.x_stretch_inner_points % 2 == 0:
raise ValueError("x_stretch_inner_points must be odd for symmetric x-stretch.")
if self.x_stretch_power < 1:
raise ValueError("x_stretch_power must be >= 1.")
dx_inner = self.x_stretch_inner_size / (self.x_stretch_inner_points - 1)
dx_mean = self.xsize / (self.Nx - 1)
if dx_inner > dx_mean:
raise ValueError(
"x_stretch_inner_size/x_stretch_inner_points produces a coarser inner zone "
"than the domain-average spacing."
)
if self.x_stretch_max_cell_size is not None and self.x_stretch_max_cell_size <= 0.0:
raise ValueError("x_stretch_max_cell_size must be > 0 when provided.")
if self.y_stretch_enabled:
if not (0.0 < self.y_stretch_inner_size < self.ysize):
raise ValueError("y_stretch_inner_size must be in (0, ysize).")
if self.y_stretch_inner_points < 2 or self.y_stretch_inner_points >= self.Ny:
raise ValueError("y_stretch_inner_points must be in [2, Ny-1].")
if self.y_stretch_power < 1:
raise ValueError("y_stretch_power must be >= 1.")
dy_inner = self.y_stretch_inner_size / (self.y_stretch_inner_points - 1)
dy_mean = self.ysize / (self.Ny - 1)
if dy_inner > dy_mean:
raise ValueError(
"y_stretch_inner_size/y_stretch_inner_points produces a coarser inner zone "
"than the domain-average spacing."
)
if self.y_stretch_max_cell_size is not None and self.y_stretch_max_cell_size <= 0.0:
raise ValueError("y_stretch_max_cell_size must be > 0 when provided.")