1313import numpy as np
1414
1515
16- #- ----------------------------------------------------------------------------
16+ # ----------------------------------------------------------------------------
1717# Electrical potential of a dipole
18- #- ----------------------------------------------------------------------------
18+ # ----------------------------------------------------------------------------
1919def dipole_potential (x , y ):
2020 """The electric dipole potential V, at position *x*, *y*."""
2121 r_sq = x ** 2 + y ** 2
@@ -24,9 +24,9 @@ def dipole_potential(x, y):
2424 return (np .max (z ) - z ) / (np .max (z ) - np .min (z ))
2525
2626
27- #- ----------------------------------------------------------------------------
27+ # ----------------------------------------------------------------------------
2828# Creating a Triangulation
29- #- ----------------------------------------------------------------------------
29+ # ----------------------------------------------------------------------------
3030# First create the x and y coordinates of the points.
3131n_angles = 30
3232n_radii = 10
@@ -50,23 +50,23 @@ def dipole_potential(x, y):
5050 y [triang .triangles ].mean (axis = 1 ))
5151 < min_radius )
5252
53- #- ----------------------------------------------------------------------------
53+ # ----------------------------------------------------------------------------
5454# Refine data - interpolates the electrical potential V
55- #- ----------------------------------------------------------------------------
55+ # ----------------------------------------------------------------------------
5656refiner = UniformTriRefiner (triang )
5757tri_refi , z_test_refi = refiner .refine_field (V , subdiv = 3 )
5858
59- #- ----------------------------------------------------------------------------
59+ # ----------------------------------------------------------------------------
6060# Computes the electrical field (Ex, Ey) as gradient of electrical potential
61- #- ----------------------------------------------------------------------------
61+ # ----------------------------------------------------------------------------
6262tci = CubicTriInterpolator (triang , - V )
6363# Gradient requested here at the mesh nodes but could be anywhere else:
6464(Ex , Ey ) = tci .gradient (triang .x , triang .y )
6565E_norm = np .sqrt (Ex ** 2 + Ey ** 2 )
6666
67- #- ----------------------------------------------------------------------------
67+ # ----------------------------------------------------------------------------
6868# Plot the triangulation, the potential iso-contours and the vector field
69- #- ----------------------------------------------------------------------------
69+ # ----------------------------------------------------------------------------
7070fig , ax = plt .subplots ()
7171ax .set_aspect ('equal' )
7272# Enforce the margins, and enlarge them to give room for the vectors.
0 commit comments