Skip to content

Commit cd6e4e9

Browse files
committed
Azure CI commit ref 8d780d2db08987c824a7498eb77a55e95696d4c4
1 parent 0efa4a5 commit cd6e4e9

File tree

6,831 files changed

+1650141
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,831 files changed

+1650141
-1
lines changed

en/latest

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.11.0
1+
v0.11.1

en/v0.11.1/.buildinfo

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 03fcd7c1152a1a651a3bc079a15e6708
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Here we compute the values of a scalar function on the z-faces. We then create
2+
# an averaging operator to approximate the function at cell centers. We choose
3+
# to define a scalar function that is strongly discontinuous in some places to
4+
# demonstrate how the averaging operator will smooth out discontinuities.
5+
#
6+
# We start by importing the necessary packages and defining a mesh.
7+
#
8+
from discretize import TensorMesh
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
#
12+
h = np.ones(40)
13+
mesh = TensorMesh([h, h, h], x0="CCC")
14+
#
15+
# Create a scalar variable on z-faces
16+
#
17+
phi_z = np.zeros(mesh.nFz)
18+
xyz = mesh.faces_z
19+
phi_z[(xyz[:, 2] > 0)] = 25.0
20+
phi_z[(xyz[:, 2] < -10.0) & (xyz[:, 0] > -10.0) & (xyz[:, 0] < 10.0)] = 50.0
21+
#
22+
# Next, we construct the averaging operator and apply it to
23+
# the discrete scalar quantity to approximate the value at cell centers.
24+
# We plot the original scalar and its average at cell centers for a
25+
# slice at y=0.
26+
#
27+
Azc = mesh.average_face_z_to_cell
28+
phi_c = Azc @ phi_z
29+
#
30+
# And plot the results:
31+
#
32+
fig = plt.figure(figsize=(11, 5))
33+
ax1 = fig.add_subplot(121)
34+
v = np.r_[np.zeros(mesh.nFx+mesh.nFy), phi_z] # create vector for plotting
35+
mesh.plot_slice(v, ax=ax1, normal='Y', slice_loc=0, v_type="Fz")
36+
ax1.set_title("Variable at z-faces", fontsize=16)
37+
ax2 = fig.add_subplot(122)
38+
mesh.plot_image(phi_c, ax=ax2, normal='Y', slice_loc=0, v_type="CC")
39+
ax2.set_title("Averaged to cell centers", fontsize=16)
40+
plt.show()
41+
#
42+
# Below, we show a spy plot illustrating the sparsity and mapping
43+
# of the operator
44+
#
45+
fig = plt.figure(figsize=(9, 9))
46+
ax1 = fig.add_subplot(111)
47+
ax1.spy(Azc, ms=1)
48+
ax1.set_title("Z-Face Index", fontsize=12, pad=5)
49+
ax1.set_ylabel("Cell Index", fontsize=12)
50+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Here, we construct a 4 by 3 cell 2D tensor mesh and return the indices
2+
# of the x and y-boundary faces. In this case there are 3 x-faces on each
3+
# x-boundary, and there are 4 y-faces on each y-boundary.
4+
#
5+
from discretize import TensorMesh
6+
import numpy as np
7+
import matplotlib.pyplot as plt
8+
#
9+
hx = [1, 1, 1, 1]
10+
hy = [2, 2, 2]
11+
mesh = TensorMesh([hx, hy])
12+
ind_Bx1, ind_Bx2, ind_By1, ind_By2 = mesh.face_boundary_indices
13+
#
14+
ax = plt.subplot(111)
15+
mesh.plot_grid(ax=ax)
16+
ax.scatter(*mesh.faces_x[ind_Bx1].T)
17+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Here we compute the values of a scalar function on the x-edges. We then create
2+
# an averaging operator to approximate the function at cell centers. We choose
3+
# to define a scalar function that is strongly discontinuous in some places to
4+
# demonstrate how the averaging operator will smooth out discontinuities.
5+
#
6+
# We start by importing the necessary packages and defining a mesh.
7+
#
8+
from discretize import TensorMesh
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
h = np.ones(40)
12+
mesh = TensorMesh([h, h], x0="CC")
13+
#
14+
# Then we create a scalar variable on x-edges,
15+
#
16+
phi_x = np.zeros(mesh.nEx)
17+
xy = mesh.edges_x
18+
phi_x[(xy[:, 1] > 0)] = 25.0
19+
phi_x[(xy[:, 1] < -10.0) & (xy[:, 0] > -10.0) & (xy[:, 0] < 10.0)] = 50.0
20+
#
21+
# Next, we construct the averaging operator and apply it to
22+
# the discrete scalar quantity to approximate the value at cell centers.
23+
#
24+
Axc = mesh.average_edge_x_to_cell
25+
phi_c = Axc @ phi_x
26+
#
27+
# And plot the results,
28+
#
29+
fig = plt.figure(figsize=(11, 5))
30+
ax1 = fig.add_subplot(121)
31+
v = np.r_[phi_x, np.zeros(mesh.nEy)] # create vector for plotting function
32+
mesh.plot_image(v, ax=ax1, v_type="Ex")
33+
ax1.set_title("Variable at x-edges", fontsize=16)
34+
ax2 = fig.add_subplot(122)
35+
mesh.plot_image(phi_c, ax=ax2, v_type="CC")
36+
ax2.set_title("Averaged to cell centers", fontsize=16)
37+
plt.show()
38+
#
39+
# Below, we show a spy plot illustrating the sparsity and mapping
40+
# of the operator
41+
#
42+
fig = plt.figure(figsize=(9, 9))
43+
ax1 = fig.add_subplot(111)
44+
ax1.spy(Axc, ms=1)
45+
ax1.set_title("X-Edge Index", fontsize=12, pad=5)
46+
ax1.set_ylabel("Cell Index", fontsize=12)
47+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# We create a simple mesh and refine the TreeMesh such that all cells that
2+
# intersect the line segment path are at the given levels.
3+
#
4+
import discretize
5+
import matplotlib.pyplot as plt
6+
import matplotlib.patches as patches
7+
mesh = discretize.TreeMesh([32, 32, 32])
8+
mesh.max_level
9+
# Expected:
10+
## 5
11+
#
12+
# Next we define the bottom points of the prism, its heights, and the level we
13+
# want to refine to, then refine the mesh.
14+
#
15+
triangle = [[0.14, 0.31, 0.21], [0.32, 0.96, 0.34], [0.87, 0.23, 0.12]]
16+
height = 0.35
17+
levels = 5
18+
mesh.refine_vertical_trianglular_prism(triangle, height, levels)
19+
#
20+
# Now lets look at the mesh.
21+
#
22+
v = mesh.cell_levels_by_index(np.arange(mesh.n_cells))
23+
fig, axs = plt.subplots(1, 3, figsize=(12,4))
24+
mesh.plot_slice(v, ax=axs[0], normal='x', grid=True, clim=[2, 5])
25+
mesh.plot_slice(v, ax=axs[1], normal='y', grid=True, clim=[2, 5])
26+
mesh.plot_slice(v, ax=axs[2], normal='z', grid=True, clim=[2, 5])
27+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Here we compute the values of a vector function discretized to the edges.
2+
# We then create an averaging operator to approximate the function at cell centers.
3+
#
4+
# We start by importing the necessary packages and defining a mesh.
5+
#
6+
from discretize import TensorMesh
7+
import numpy as np
8+
import matplotlib.pyplot as plt
9+
h = 0.5 * np.ones(40)
10+
mesh = TensorMesh([h, h], x0="CC")
11+
#
12+
# Then we create a discrete vector on mesh edges
13+
#
14+
edges_x = mesh.edges_x
15+
edges_y = mesh.edges_y
16+
u_ex = -(edges_x[:, 1] / np.sqrt(np.sum(edges_x ** 2, axis=1))) * np.exp(
17+
-(edges_x[:, 0] ** 2 + edges_x[:, 1] ** 2) / 6 ** 2
18+
)
19+
u_ey = (edges_y[:, 0] / np.sqrt(np.sum(edges_y ** 2, axis=1))) * np.exp(
20+
-(edges_y[:, 0] ** 2 + edges_y[:, 1] ** 2) / 6 ** 2
21+
)
22+
u_e = np.r_[u_ex, u_ey]
23+
#
24+
# Next, we construct the averaging operator and apply it to
25+
# the discrete vector quantity to approximate the value at cell centers.
26+
#
27+
Aec = mesh.average_edge_to_cell_vector
28+
u_c = Aec @ u_e
29+
#
30+
# And plot the results:
31+
#
32+
fig = plt.figure(figsize=(11, 5))
33+
ax1 = fig.add_subplot(121)
34+
mesh.plot_image(u_e, ax=ax1, v_type="E", view='vec')
35+
ax1.set_title("Variable at edges", fontsize=16)
36+
ax2 = fig.add_subplot(122)
37+
mesh.plot_image(u_c, ax=ax2, v_type="CCv", view='vec')
38+
ax2.set_title("Averaged to cell centers", fontsize=16)
39+
plt.show()
40+
#
41+
# Below, we show a spy plot illustrating the sparsity and mapping
42+
# of the operator
43+
#
44+
fig = plt.figure(figsize=(9, 9))
45+
ax1 = fig.add_subplot(111)
46+
ax1.spy(Aec, ms=1)
47+
ax1.set_title("Edge Index", fontsize=12, pad=5)
48+
ax1.set_ylabel("Cell Vector Index", fontsize=12)
49+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Here we compute the values of a scalar function on the nodes. We then create
2+
# an averaging operator to approximate the function at the edges. We choose
3+
# to define a scalar function that is strongly discontinuous in some places to
4+
# demonstrate how the averaging operator will smooth out discontinuities.
5+
#
6+
# We start by importing the necessary packages and defining a mesh.
7+
#
8+
from discretize import TensorMesh
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
h = np.ones(40)
12+
mesh = TensorMesh([h, h], x0="CC")
13+
#
14+
# Then we create a scalar variable on nodes,
15+
#
16+
phi_n = np.zeros(mesh.nN)
17+
xy = mesh.nodes
18+
phi_n[(xy[:, 1] > 0)] = 25.0
19+
phi_n[(xy[:, 1] < -10.0) & (xy[:, 0] > -10.0) & (xy[:, 0] < 10.0)] = 50.0
20+
#
21+
# Next, we construct the averaging operator and apply it to
22+
# the discrete scalar quantity to approximate the value on the edges.
23+
#
24+
Ane = mesh.average_node_to_edge
25+
phi_e = Ane @ phi_n
26+
#
27+
# Plot the results,
28+
#
29+
fig = plt.figure(figsize=(11, 5))
30+
ax1 = fig.add_subplot(121)
31+
mesh.plot_image(phi_n, ax=ax1, v_type="N")
32+
ax1.set_title("Variable at nodes")
33+
ax2 = fig.add_subplot(122)
34+
mesh.plot_image(phi_e, ax=ax2, v_type="E")
35+
ax2.set_title("Averaged to edges")
36+
plt.show()
37+
#
38+
# Below, we show a spy plot illustrating the sparsity and mapping
39+
# of the operator
40+
#
41+
fig = plt.figure(figsize=(9, 9))
42+
ax1 = fig.add_subplot(111)
43+
ax1.spy(Ane, ms=1)
44+
ax1.set_title("Node Index", fontsize=12, pad=5)
45+
ax1.set_ylabel("Edge Index", fontsize=12)
46+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# For the 4 classifications allowable (scalar, isotropic, anistropic and tensor),
2+
# we construct and compare the property tensor on a small 2D mesh. For this
3+
# example, note the following:
4+
#
5+
# - The dimensions for all property tensors are the same
6+
# - All property tensors, except in the case of full anisotropy are diagonal
7+
# sparse matrices
8+
# - For the scalar case, the non-zero elements are equal
9+
# - For the isotropic case, the non-zero elements repreat in order for the x, y
10+
# (and z) components
11+
# - For the anisotropic case (diagonal anisotropy), the non-zero elements do not
12+
# repeat
13+
# - For the tensor caes (full anisotropy), there are off-diagonal components
14+
#
15+
from discretize.utils import make_property_tensor
16+
from discretize import TensorMesh
17+
import numpy as np
18+
import matplotlib.pyplot as plt
19+
import matplotlib as mpl
20+
rng = np.random.default_rng(421)
21+
#
22+
# Define a 2D tensor mesh
23+
#
24+
h = [1., 1., 1.]
25+
mesh = TensorMesh([h, h], origin='00')
26+
#
27+
# Define a physical property for all cases (2D)
28+
#
29+
sigma_scalar = 4.
30+
sigma_isotropic = rng.integers(1, 10, mesh.nC)
31+
sigma_anisotropic = rng.integers(1, 10, (mesh.nC, 2))
32+
sigma_tensor = rng.integers(1, 10, (mesh.nC, 3))
33+
#
34+
# Construct the property tensor in each case
35+
#
36+
M_scalar = make_property_tensor(mesh, sigma_scalar)
37+
M_isotropic = make_property_tensor(mesh, sigma_isotropic)
38+
M_anisotropic = make_property_tensor(mesh, sigma_anisotropic)
39+
M_tensor = make_property_tensor(mesh, sigma_tensor)
40+
#
41+
# Plot the property tensors.
42+
#
43+
M_list = [M_scalar, M_isotropic, M_anisotropic, M_tensor]
44+
case_list = ['Scalar', 'Isotropic', 'Anisotropic', 'Full Tensor']
45+
ax1 = 4*[None]
46+
fig = plt.figure(figsize=(15, 4))
47+
for ii in range(0, 4):
48+
ax1[ii] = fig.add_axes([0.05+0.22*ii, 0.05, 0.18, 0.9])
49+
ax1[ii].imshow(
50+
M_list[ii].todense(), interpolation='none', cmap='binary', vmax=10.
51+
)
52+
ax1[ii].set_title(case_list[ii], fontsize=24)
53+
ax2 = fig.add_axes([0.92, 0.15, 0.01, 0.7])
54+
norm = mpl.colors.Normalize(vmin=0., vmax=10.)
55+
cbar = mpl.colorbar.ColorbarBase(
56+
ax2, norm=norm, orientation="vertical", cmap=mpl.cm.binary
57+
)
58+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Create two meshes with the same extent, but different divisions (the meshes
2+
# do not have to be the same extent).
3+
#
4+
import numpy as np
5+
from discretize import TensorMesh
6+
rng = np.random.default_rng(853)
7+
h1 = np.ones(32)
8+
h2 = np.ones(16)*2
9+
mesh_in = TensorMesh([h1, h1])
10+
mesh_out = TensorMesh([h2, h2])
11+
#
12+
# Create a random model defined on the input mesh, and use volume averaging to
13+
# interpolate it to the output mesh.
14+
#
15+
from discretize.utils import volume_average
16+
model1 = rng.random(mesh_in.nC)
17+
model2 = volume_average(mesh_in, mesh_out, model1)
18+
#
19+
# Because these two meshes' cells are perfectly aligned, but the output mesh
20+
# has 1 cell for each 4 of the input cells, this operation should effectively
21+
# look like averaging each of those cells values
22+
#
23+
import matplotlib.pyplot as plt
24+
plt.figure(figsize=(6, 3))
25+
ax1 = plt.subplot(121)
26+
mesh_in.plot_image(model1, ax=ax1)
27+
ax2 = plt.subplot(122)
28+
mesh_out.plot_image(model2, ax=ax2)
29+
plt.show()
Binary file not shown.

0 commit comments

Comments
 (0)