3

I'm trying to draw a path of a particle starting at (x0,y0) subject to a vortex located at (xv,yv). This is inspired by Lorena Barba's AeroPython. As stated in the lesson, the motion should be concentric circles about a given point.

I first calculate the velocity at point (x0,y0).

def get_velocity_vortex(strength, xv, yv, x0, y0):

    u = +strength / (2 * np.pi) * (y0 - yv) / ((x0 - xv)**2 + (y0 - yv)**2)
    v = -strength / (2 * np.pi) * (x0 - xv) / ((x0 - xv)**2 + (y0 - yv)**2)
    
    return u, v

I then try to calculate the suceeding positions as follows.

def get_next_pos(x0,y0,u,v,dt):
    
    x_next = x0 + u * dt
    y_next = y0 + v * dt
    
    return x_next, y_next

A complete example is as shown.

import numpy as np
import matplotlib.pyplot as plt

strength_vortex = 5.0
# coordinates of vortex
x_vortex = 0.0
y_vortex = 0.0
# coordinates of initial point
x0 = 0.1
y0 = 0.0

dt = 1e-3 # timestep
nt = 150 # number of iterations

# empty arrays for the positions
X = np.zeros(nt)
Y = np.zeros(nt)
# initial positions
X[0], Y[0] = x0, y0

# calculate the path
for i in range(1,nt):
    
    u, v = get_velocity_vortex(
        strength_vortex,
        x_vortex,
        y_vortex,
        X[i-1],
        Y[i-1]    
    )
    
    X[i],Y[i] = get_next_pos(X[i-1], Y[i-1], u, v, dt)

# plot the path 
plt.scatter(
    x_vortex,
    y_vortex,
    color="red"
)
plt.scatter(
    X,Y,
)
plt.xlim(-0.2,0.2)
plt.ylim(-0.2,0.2)
plt.grid()

However, my output does not result in a circle. I suspect that this is due to my get_next_pos function. How can I correct the path? Any help is appreciated. Thanks in advance.

Resulting path

3
  • 4
    Are you sure this is not just an integration error? e.g. a smaller timestep might work better. Commented Apr 27, 2022 at 12:15
  • 4
    It is because your integration scheme is low order, try higher order schemes. Commented May 5, 2022 at 18:37
  • @Yimin is right. You can either go for stuff like en.wikipedia.org/wiki/Leapfrog_integration if you care about this being stable (circular) for very long timescales or for en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods if you'd prefer a cheaper calculation with larger timesteps that's stable for a decent period of time. Commented Jun 1, 2022 at 11:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.