13
13
import numpy as np
14
14
15
15
16
- #- ----------------------------------------------------------------------------
16
+ # ----------------------------------------------------------------------------
17
17
# Electrical potential of a dipole
18
- #- ----------------------------------------------------------------------------
18
+ # ----------------------------------------------------------------------------
19
19
def dipole_potential (x , y ):
20
20
"""The electric dipole potential V, at position *x*, *y*."""
21
21
r_sq = x ** 2 + y ** 2
@@ -24,9 +24,9 @@ def dipole_potential(x, y):
24
24
return (np .max (z ) - z ) / (np .max (z ) - np .min (z ))
25
25
26
26
27
- #- ----------------------------------------------------------------------------
27
+ # ----------------------------------------------------------------------------
28
28
# Creating a Triangulation
29
- #- ----------------------------------------------------------------------------
29
+ # ----------------------------------------------------------------------------
30
30
# First create the x and y coordinates of the points.
31
31
n_angles = 30
32
32
n_radii = 10
@@ -50,23 +50,23 @@ def dipole_potential(x, y):
50
50
y [triang .triangles ].mean (axis = 1 ))
51
51
< min_radius )
52
52
53
- #- ----------------------------------------------------------------------------
53
+ # ----------------------------------------------------------------------------
54
54
# Refine data - interpolates the electrical potential V
55
- #- ----------------------------------------------------------------------------
55
+ # ----------------------------------------------------------------------------
56
56
refiner = UniformTriRefiner (triang )
57
57
tri_refi , z_test_refi = refiner .refine_field (V , subdiv = 3 )
58
58
59
- #- ----------------------------------------------------------------------------
59
+ # ----------------------------------------------------------------------------
60
60
# Computes the electrical field (Ex, Ey) as gradient of electrical potential
61
- #- ----------------------------------------------------------------------------
61
+ # ----------------------------------------------------------------------------
62
62
tci = CubicTriInterpolator (triang , - V )
63
63
# Gradient requested here at the mesh nodes but could be anywhere else:
64
64
(Ex , Ey ) = tci .gradient (triang .x , triang .y )
65
65
E_norm = np .sqrt (Ex ** 2 + Ey ** 2 )
66
66
67
- #- ----------------------------------------------------------------------------
67
+ # ----------------------------------------------------------------------------
68
68
# Plot the triangulation, the potential iso-contours and the vector field
69
- #- ----------------------------------------------------------------------------
69
+ # ----------------------------------------------------------------------------
70
70
fig , ax = plt .subplots ()
71
71
ax .set_aspect ('equal' )
72
72
# Enforce the margins, and enlarge them to give room for the vectors.
0 commit comments