Skip to content

Commit 9d886e3

Browse files
committed
Putting this into a dev branch. We'll need to check against changes in v0.99
1 parent 6be9e50 commit 9d886e3

File tree

49 files changed

+5478
-452
lines changed

Some content is hidden

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

49 files changed

+5478
-452
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Jupyterbook/**/*.png
1313
Jupyterbook/**/*.vtk
1414
Jupyterbook/**/*.h5
1515

16+
**/WIP/**/*.png
17+
**/BatPumpkin/**/*.png
18+
19+
**/?????_debug.txt
20+
**/Untitled*.ipynb
21+
1622
**/.jupyter/**
1723

1824
# Byte-compiled / optimized / DLL files

Documentation/Ex_Anisotropy.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@
757757
"name": "python",
758758
"nbconvert_exporter": "python",
759759
"pygments_lexer": "ipython3",
760-
"version": "3.11.5"
760+
"version": "3.12.8"
761761
},
762762
"title": "Constitutive Models in Underworld 3"
763763
},

Notebooks/Developers/Timing/Timing_NonLinear_ShearBand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# extension: .py
66
# format_name: light
77
# format_version: '1.5'
8-
# jupytext_version: 1.14.4
8+
# jupytext_version: 1.16.6
99
# kernelspec:
1010
# display_name: Python 3 (ipykernel)
1111
# language: python

Notebooks/Developers/Timing/Timing_StokesSinker.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# extension: .py
66
# format_name: light
77
# format_version: '1.5'
8-
# jupytext_version: 1.14.1
8+
# jupytext_version: 1.16.6
99
# kernelspec:
1010
# display_name: Python 3 (ipykernel)
1111
# language: python
@@ -200,7 +200,5 @@
200200
time += dt
201201

202202

203-
# + tags=[]
204203
timing.print_table(display_fraction=0.999)
205-
# -
206204
mesh.write_checkpoint("stokesSinkerTiming", meshUpdates=False, meshVars=[p, v])
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# ---
2+
# jupyter:
3+
# jupytext:
4+
# formats: py:percent
5+
# text_representation:
6+
# extension: .py
7+
# format_name: percent
8+
# format_version: '1.3'
9+
# jupytext_version: 1.16.6
10+
# kernelspec:
11+
# display_name: Python (Pixi)
12+
# language: python
13+
# name: pixi-kernel-python3
14+
# ---
15+
16+
# %%
17+
# This is required to fix pyvista
18+
# (visualisation) crashes in interactive notebooks (including on binder)
19+
20+
import nest_asyncio
21+
nest_asyncio.apply()
22+
23+
# %%
24+
import numpy as np
25+
import sympy
26+
import underworld3 as uw
27+
28+
# %%
29+
index = 12
30+
basename = "output/Parallel_Evaluate"
31+
32+
# %%
33+
meshball = uw.discretisation.Mesh(f"{basename}.mesh.{index:05d}.h5")
34+
35+
# meshball.view()
36+
37+
x, y = meshball.CoordinateSystem.X
38+
r, th = meshball.CoordinateSystem.xR
39+
unit_rvec = meshball.CoordinateSystem.unit_e_0
40+
41+
42+
# Orientation of surface normals
43+
Gamma_N = meshball.Gamma
44+
45+
46+
# %%
47+
scalar_var = uw.discretisation.MeshVariable(
48+
varname="Radius", mesh=meshball, vtype=uw.VarType.SCALAR, varsymbol=r"r"
49+
)
50+
51+
rank_var = uw.discretisation.MeshVariable(
52+
varname="Rank",
53+
mesh=meshball,
54+
vtype=uw.VarType.SCALAR,
55+
varsymbol=r"Ra",
56+
degree=0,
57+
)
58+
59+
# %%
60+
scalar_var.read_timestep(f"{basename}", "Radius", index, verbose=True)
61+
rank_var.read_timestep(f"{basename}", "Rank", index, verbose=True)
62+
63+
# %%
64+
65+
# %%
66+
swarm = uw.swarm.Swarm(meshball)
67+
68+
error_var = uw.swarm.SwarmVariable(
69+
"Error",
70+
swarm,
71+
vtype=uw.VarType.SCALAR,
72+
_proxy=False,
73+
)
74+
75+
s_rank_var = uw.swarm.SwarmVariable(
76+
"FRank",
77+
swarm,
78+
vtype=uw.VarType.SCALAR,
79+
_proxy=False,
80+
)
81+
82+
83+
swarm.read_timestep(
84+
basename,
85+
"data_swarm",
86+
index,
87+
migrate=False,
88+
)
89+
90+
error_var.read_timestep(
91+
basename,
92+
"data_swarm",
93+
"Error",
94+
index,
95+
)
96+
97+
s_rank_var.read_timestep(
98+
basename,
99+
"data_swarm",
100+
"FRank",
101+
index,
102+
)
103+
104+
105+
106+
# %%
107+
in_or_out = meshball.points_in_domain(swarm.particle_coordinates.array[...].reshape(-1,2))
108+
109+
# %%
110+
111+
# %%
112+
import pyvista as pv
113+
114+
pvmesh = uw.visualisation.mesh_to_pv_mesh(meshball)
115+
116+
pvmesh.cell_data["rank"] = uw.visualisation.scalar_fn_to_pv_points(
117+
pvmesh.cell_centers(), rank_var.sym
118+
)
119+
120+
error_swarm = uw.visualisation.swarm_to_pv_cloud(swarm)
121+
error_swarm.point_data["E"] = np.sqrt(error_var.array[:, 0, 0]**2)
122+
error_swarm.point_data["E2"] = np.sqrt(error_var.array[:, 0, 0]**2) * in_or_out.astype(float)
123+
error_swarm.point_data["R"] = np.sqrt(s_rank_var.array[:, 0, 0]**2) * in_or_out.astype(float)
124+
125+
126+
127+
plotter = pv.Plotter()
128+
129+
plotter.add_mesh(pvmesh, scalars="rank", cmap="rainbow", show_edges=True, opacity=0.2)
130+
plotter.add_points(error_swarm, cmap="rainbow", scalars="R", point_size=4)
131+
# plotter.add_points(error_swarm, scalars="E", point_size=3)
132+
133+
plotter.show()
134+
135+
# %%
136+
swarm.dm.getLocalSize()
137+
138+
# %%
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# ---
2+
# jupyter:
3+
# jupytext:
4+
# formats: py:percent
5+
# text_representation:
6+
# extension: .py
7+
# format_name: percent
8+
# format_version: '1.3'
9+
# jupytext_version: 1.16.6
10+
# kernelspec:
11+
# display_name: Python (Pixi)
12+
# language: python
13+
# name: pixi-kernel-python3
14+
# ---
15+
16+
# %%
17+
import numpy as np
18+
import sympy
19+
import underworld3 as uw
20+
21+
# %%
22+
res = 0.05
23+
r_o = 1.0
24+
r_int = 0.825
25+
r_i = 0.55
26+
27+
meshball = uw.meshing.AnnulusInternalBoundary(radiusOuter=r_o,
28+
radiusInternal=r_int,
29+
radiusInner=r_i,
30+
cellSize_Inner=res,
31+
cellSize_Internal=res*0.5,
32+
cellSize_Outer=res,
33+
centre=False,)
34+
35+
36+
meshbox = uw.meshing.UnstructuredSimplexBox(
37+
cellSize=res,
38+
minCoords=(-1.0, -1.0),
39+
maxCoords=(+1.0, +1.0),
40+
qdegree=3,
41+
)
42+
43+
mesh = meshball
44+
45+
x, y = mesh.CoordinateSystem.X
46+
r, th = mesh.CoordinateSystem.xR
47+
unit_rvec = mesh.CoordinateSystem.unit_e_0
48+
49+
50+
# Orientation of surface normals
51+
Gamma_N = mesh.Gamma
52+
53+
54+
# %%
55+
rank_var = uw.discretisation.MeshVariable(
56+
varname="Rank",
57+
mesh=mesh,
58+
vtype = uw.VarType.SCALAR,
59+
varsymbol=r"Ra",
60+
continuous=False,
61+
degree=0,
62+
)
63+
64+
65+
scalar_var = uw.discretisation.MeshVariable(
66+
varname="Radius",
67+
mesh=mesh,
68+
vtype = uw.VarType.SCALAR,
69+
varsymbol=r"r"
70+
)
71+
72+
scalar_var.array[...] = uw.function.evaluate(r, scalar_var.coords)
73+
rank_var.array[...] = uw.mpi.rank
74+
75+
# %%
76+
## Functions that we can evaluate anywhere
77+
scalar_fn = scalar_var.sym[0,0] * sympy.sin(x) * sympy.cos(x)
78+
79+
# %%
80+
# Random points in the bounding box of the domain (on each processor)
81+
coords = 1 - 2 * np.random.random(size=(1000,2))
82+
83+
# %%
84+
results, is_extrapolated = uw.function.global_evaluate(scalar_fn, coords, rbf=False, check_extrapolated=True)
85+
86+
# %%
87+
rank, is_extrapolated = uw.function.global_evaluate(rank_var.sym[0], coords, rbf=False, check_extrapolated=True)
88+
89+
# %%
90+
true_results = uw.function.global_evaluate(r * sympy.sin(x) * sympy.cos(x) , coords, rbf=False, check_extrapolated=False)
91+
92+
# %%
93+
inside_domain = mesh.points_in_domain(coords)
94+
95+
print(f"{uw.mpi.rank} Max difference - {(results - true_results).max()}", flush=True)
96+
print(f"{uw.mpi.rank} Mean difference - {(results - true_results).mean()}", flush=True)
97+
98+
print(f"{uw.mpi.rank} Max difference [in domain] - {(results - true_results)[inside_domain].max()}", flush=True)
99+
print(f"{uw.mpi.rank} Mean difference [in domain] - {(results - true_results)[inside_domain].mean()}", flush=True)
100+
101+
# %%
102+
swarm = uw.swarm.Swarm(mesh)
103+
error_var = uw.swarm.SwarmVariable("Error", swarm, vtype=uw.VarType.SCALAR, _proxy=False)
104+
s_rank_var = uw.swarm.SwarmVariable("FRank", swarm, vtype=uw.VarType.SCALAR, _proxy=False)
105+
106+
# %%
107+
swarm.add_particles_with_global_coordinates(coords, migrate=False)
108+
109+
# %%
110+
error_var.array[...] = (results - true_results)
111+
s_rank_var.array[...] = rank[...]
112+
uw.mpi.barrier()
113+
114+
# %%
115+
mesh.write_timestep(
116+
"Parallel_Evaluate",
117+
meshUpdates=True,
118+
meshVars=[scalar_var, rank_var],
119+
outputPath="output",
120+
index=uw.mpi.size,
121+
122+
)
123+
124+
# %%
125+
swarm.write_timestep(
126+
"Parallel_Evaluate",
127+
"data_swarm",
128+
swarmVars=[error_var, s_rank_var],
129+
outputPath="output",
130+
index=uw.mpi.size,
131+
force_sequential=True,
132+
)
133+
134+
135+
# %%
136+
if uw.mpi.rank == 0:
137+
print("Complete", flush=True)
138+
139+
# %%
140+
exit(0)
141+
142+
# %%

0 commit comments

Comments
 (0)