Class: AppMath::Kep2D

Inherits:
Object
  • Object
show all
Defined in:
lib/kepler_2d.rb

Overview

Kepler problem in 2 dimensions mass of the test particle is 1. space-fixed central mass times constant of gravity is @g

Instance Method Summary collapse

Constructor Details

#initialize(x, v, g) ⇒ Kep2D

Returns a new instance of Kep2D.



102
103
104
105
106
107
# File 'lib/kepler_2d.rb', line 102

def initialize(x,v,g)
  @t = R.c0
  @x = x
  @v = v
  @g = g
end

Instance Method Details

#accObject

acceleration



110
111
112
113
114
# File 'lib/kepler_2d.rb', line 110

def acc
  r = @x.abs
  k = -@g * r**-3
  @x * k
end

#ang_momObject

angular momentum



150
151
152
# File 'lib/kepler_2d.rb', line 150

def ang_mom
  @x.x * @v.y - @x.y * @v.x
end

#energyObject

total energy



145
146
147
# File 'lib/kepler_2d.rb', line 145

def energy
  @v.abs2 * 0.5 - @g/@x.abs
end

#get_tObject



140
141
142
# File 'lib/kepler_2d.rb', line 140

def get_t
  @t
end

#get_xObject



132
133
134
# File 'lib/kepler_2d.rb', line 132

def get_x 
  @x.x
end

#get_yObject



136
137
138
# File 'lib/kepler_2d.rb', line 136

def get_y
  @x.y
end

#lenzObject

Runge-Lenz vector



155
156
157
# File 'lib/kepler_2d.rb', line 155

def lenz
  @x * @v.abs2 - @x * @v.spr(@x) - @x.uv * @g 
end

#step!(dt) ⇒ Object

time step of the direct midpoint integrator, highly symmetric !



117
118
119
120
121
122
123
124
# File 'lib/kepler_2d.rb', line 117

def step!(dt)
  h = dt * 0.5
  @t += h
  @x += @v * h
  @v += acc * dt
  @x += @v * h
  @t += h
end

#to_sObject



126
127
128
129
130
# File 'lib/kepler_2d.rb', line 126

def to_s
  res = "x = " + @x.to_s + "\n" +
  "v = " + @v.to_s + "\n" +
  "t = " + @t.to_s
end