-
Notifications
You must be signed in to change notification settings - Fork 0
/
runscript_example_1_2_source_in_outer_domain.py
129 lines (96 loc) · 3.44 KB
/
runscript_example_1_2_source_in_outer_domain.py
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
import os
N_THREADS = "1"
os.environ["MKL_NUM_THREADS"] = N_THREADS
os.environ["NUMEXPR_NUM_THREADS"] = N_THREADS
os.environ["OMP_NUM_THREADS"] = N_THREADS
os.environ["OPENBLAS_NUM_THREADS"] = N_THREADS
import numpy as np
import porepy as pp
from models.elastic_wave_equation_abc import DynamicMomentumBalanceABC2
from utils import TransverselyAnisotropicStiffnessTensor
class MyGeometry:
def nd_rect_domain(self, x, y, z) -> pp.Domain:
box: dict[str, pp.number] = {"xmin": 0, "xmax": x}
box.update({"ymin": 0, "ymax": y, "zmin": 0, "zmax": z})
return pp.Domain(box)
def set_domain(self) -> None:
x = self.solid.convert_units(1.0, "m")
y = self.solid.convert_units(1.0, "m")
z = self.solid.convert_units(1.0, "m")
self._domain = self.nd_rect_domain(x, y, z)
def meshing_arguments(self) -> dict:
cell_size = self.solid.convert_units(0.0125)
mesh_args: dict[str, float] = {"cell_size": cell_size}
return mesh_args
class MomentumBalanceABCModifiedGeometry(
MyGeometry,
TransverselyAnisotropicStiffnessTensor,
DynamicMomentumBalanceABC2,
):
def initial_velocity(self, dofs: int) -> np.ndarray:
"""Initial velocity values."""
sd = self.mdg.subdomains()[0]
t = self.time_manager.time
x = sd.cell_centers[0, :]
y = sd.cell_centers[1, :]
z = sd.cell_centers[2, :]
vals = np.zeros((self.nd, sd.num_cells))
theta = 1
lam = 0.125
common_part = theta * np.exp(
-np.pi**2 * ((x - 0.5) ** 2 + (y - 0.5) ** 2 + (z - 0.7) ** 2) / lam**2
)
vals[0] = common_part * (x - 0.5)
vals[1] = common_part * (y - 0.5)
vals[2] = common_part * (z - 0.7)
return vals.ravel("F")
def data_to_export(self):
"""Define the data to export to vtu.
Returns:
list: List of tuples containing the subdomain, variable name,
and values to export.
"""
data = super().data_to_export()
for sd in self.mdg.subdomains(dim=self.nd):
vel_op = self.velocity_time_dep_array([sd]) * self.velocity_time_dep_array(
[sd]
)
vel_op_int = self.volume_integral(integrand=vel_op, grids=[sd], dim=3)
vel_op_int_val = vel_op_int.value(self.equation_system)
vel = self.velocity_time_dep_array([sd]).value(self.equation_system)
data.append((sd, "energy", vel_op_int_val))
data.append((sd, "velocity", vel))
return data
tf = 0.15
dt = tf / 90.0
time_manager = pp.TimeManager(
schedule=[0.0, tf],
dt_init=dt,
constant_dt=True,
)
anisotropy_constants = {
"mu_parallel": 1,
"mu_orthogonal": 1,
"lambda_parallel": 5,
"lambda_orthogonal": 5,
"volumetric_compr_lambda": 10,
}
params = {
"time_manager": time_manager,
"grid_type": "cartesian",
"folder_name": "example_1_heterogeneous",
"manufactured_solution": "simply_zero",
"anisotropy_constants": anisotropy_constants,
"progressbars": True,
"inner_domain_width": 0.5,
"inner_domain_center": (0.5, 0.5, 0.3),
"prepare_simulation": False,
}
model = MomentumBalanceABCModifiedGeometry(params)
import time
start = time.time()
model.prepare_simulation()
end = time.time() - start
print("Num dofs system, cartesian", model.equation_system.num_dofs())
print("Time for prep sim:", end)
pp.run_time_dependent_model(model, params)