Particle rotation in galaxy - runge kutta 2nd order help

In summary, the conversation is about a student seeking help with implementing a Runge-Kutta 2nd order method to make gas clouds move in a spiral galaxy simulation. The student provides code for calculating gravitational acceleration and scaling the velocity to centrifugal force. They also share a code for a practice Runge-Kutta program and ask for guidance on how to integrate it into their galaxy simulation code.
  • #1
InuYasha
3
0

Homework Statement


Hi everyone,
I'm a bit stuck and have been staring at my fortran code all day. For my project this year I'm writing a program to model a spiral galaxy in which gas clouds circulate, collide and produce star formation. I've written code for gravitational acceleration due to the disk, halo, bulge and spiral arms. So I have gaccel(x,y,z). I was then able to produce a plot showing the correct galaxy rotation curve using the code below. p_TOT = total gas clouds, factor was an adjustment to get km/s

I now want to make the clouds move using a runge kutta 2nd order method like below. I wrote an RK2 program to solve an ODE as practice and it worked ok (though the method is slightly different from the one I've been asked to implement). I've got a mental block on how to implement RK2 to make the clouds go round the galaxy. Am I being a bit dumb and missing something obvious :-/
Any help would be really appreciated.
Thanks.


Homework Equations



a(n) = a(r(n))
r(n+1/2) = r(n) + v(n)*tstep/2
v(n+1/2) = v(n) + a*tstep/2
a(n+1/2) = a(r(n+1/2)
r(n+1) = r(n) + v(n+1/2)*tstep
v(n+1) = v(n) +a(n+1/2)*tstep
t(n+1) = t(n) +tstep

The Attempt at a Solution


Code:
DO p=1,p_TOT                                      ! loop over particles
    r_MAG=SQRT(r(1,p)**2+r(2,p)**2+r(3,p)**2)     ! compute distance from centre
    a_MAG=SQRT(a(1,p)**2+a(2,p)**2+a(3,p)**2)     ! compute magnitude of acceleration
    v(1,p)=+a(2,p)                                ! compute x-component of velocity
    v(2,p)=-a(1,p)                                ! compute y-component of velocity
    v(3,p)=0.                                     ! set z-component of velocity to zero
    v(1:3,p)=v(1:3,p)*SQRT(r_MAG/a_MAG)           ! scale velocity to centrifugal balance
    v_MAG=SQRT(v(1,p)**2+v(2,p)**2+v(3,p)**2)     ! compute magnitude of velocity
    x(p)=r_MAG                                    ! compute abscissa of plotted point
    y(p)=factor*v_MAG                             ! compute ordinate of plotted point
ENDDO                                             ! end loop over particles

Code:
PROGRAM RK2
IMPLICIT NONE

REAL(kind=8) :: t=0.0,h=0.1
INTEGER :: i, tmax=30
REAL(kind=8),DIMENSION(30) :: y
y(1)=5
DO i=1, tmax
    CALL RUNGEKUTTA(t,y,h,i)
    t=i*h
    WRITE (*,*) "y=",y(i+1)
ENDDO

END PROGRAM RK2

SUBROUTINE RUNGEKUTTA(t,y,h,i)
IMPLICIT NONE
INTEGER :: i
REAL(kind=8) :: t,k1,k2,h
REAL(kind=8),DIMENSION(30) :: y
REAL :: EQN
k1=EQN(t,y,i)
k2=EQN(t+h,y+k1*h,i)
y(i+1)=y(i)+0.5*(k1+k2)*h
END SUBROUTINE RUNGEKUTTA

REAL FUNCTION EQN(t,y,i)
IMPLICIT NONE
INTEGER :: i
REAL(kind=8) :: t
REAL(kind=8),DIMENSION(30) :: y
EQN=3*exp(-t)-0.4*y(i)
RETURN
END FUNCTION EQN
 
Physics news on Phys.org
  • #2
I think what I'm asking is what would the likely function be that I'm integrating?
I'm pretty sure the code regarding scaling the velocity to centrifugal force only gets called once. Would I need to call the subroutine calculating the gravitational accel (I haven't posted this as it's pretty long. It just gives an acceleration value for x,y,z at the end though). That isn't a differential equation though.
It doesn't help that we haven't been exposed to much programming apart from Mathcad and a little Matlab and now in 3rd year physics we're expected to code everything in languages we don't know. Ay carumba.
 

1. What is particle rotation in a galaxy?

Particle rotation in a galaxy refers to the movement of individual particles within a galaxy as it rotates. This rotation is caused by the gravitational pull of the galaxy's center, and can also be influenced by other factors such as interactions with neighboring galaxies.

2. How is particle rotation in a galaxy calculated?

The most common method for calculating particle rotation in a galaxy is through the use of numerical integration techniques, such as the Runge-Kutta 2nd order method. This method involves breaking down the galaxy into smaller segments and using mathematical equations to track the movement of particles over time.

3. What is the significance of understanding particle rotation in a galaxy?

Studying particle rotation in a galaxy can provide valuable insights into the dynamics and structure of galaxies. It can also help us understand the role of dark matter and the formation of spiral arms in galaxies.

4. How does the Runge-Kutta 2nd order method help with calculating particle rotation in a galaxy?

The Runge-Kutta 2nd order method is a numerical integration technique that is particularly useful for solving complex differential equations, such as those involved in calculating particle rotation in a galaxy. It is more accurate than simpler methods and can handle a larger range of conditions.

5. Are there any limitations to using the Runge-Kutta 2nd order method for calculating particle rotation in a galaxy?

While the Runge-Kutta 2nd order method is a powerful tool, it does have some limitations. It can become computationally expensive when dealing with large numbers of particles, and it may not accurately capture certain complex interactions in a galaxy. Additionally, it relies on certain assumptions and simplifications, so it may not always provide a completely accurate representation of particle rotation in a galaxy.

Similar threads

Replies
47
Views
586
  • Programming and Computer Science
Replies
15
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
195
  • Introductory Physics Homework Help
Replies
32
Views
1K
Replies
1
Views
9K
Replies
1
Views
9K
Replies
1
Views
10K
  • Introductory Physics Homework Help
Replies
7
Views
232
  • Calculus and Beyond Homework Help
Replies
14
Views
3K
  • Advanced Physics Homework Help
Replies
3
Views
2K
Back
Top