-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtpc.py
More file actions
44 lines (39 loc) · 1.46 KB
/
Copy pathtpc.py
File metadata and controls
44 lines (39 loc) · 1.46 KB
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
import numpy as np
import matplotlib.pyplot as plt
# -----------------------------
# Parameters of asymmetric monopoles
# -----------------------------
# Each monopole has a strength Q and a position (x, y)
monopole1 = {"Q": 1.0, "pos": (-1.0, -1.0)}
monopole2 = {"Q": -0.5, "pos": (1.0, 1.5)}
# -----------------------------
# Create computational grid
# -----------------------------
x = np.linspace(-3, 3, 300)
y = np.linspace(-2, 2, 200)
X, Y = np.meshgrid(x, y)
# -----------------------------
# Function for a point source (monopole)
# -----------------------------
def potential_monopole(Q, x0, y0, X, Y):
"""Velocity potential of a monopole at (x0, y0) with strength Q"""
return Q / (4 * np.pi) * np.log(np.sqrt((X - x0)**2 + (Y - y0)**2))
# -----------------------------
# Compute potential fields
# -----------------------------
phi_total = potential_monopole(monopole1["Q"], monopole1["pos"][0], monopole1["pos"][1], X, Y)
phi_total += potential_monopole(monopole2["Q"], monopole2["pos"][0], monopole2["pos"][1], X, Y)
# -----------------------------
# Create contour plot
# -----------------------------
plt.figure(figsize=(10, 6))
contours = plt.contour(X, Y, phi_total, levels=50, cmap='plasma')
plt.clabel(contours, inline=True, fontsize=8)
plt.title("Two asymmetric monopoles")
plt.xlabel("x")
plt.ylabel("y")
plt.scatter([monopole1["pos"][0], monopole2["pos"][0]],
[monopole1["pos"][1], monopole2["pos"][1]])
plt.legend()
plt.axis("equal")
plt.show()