Skip to content
This repository has been archived by the owner on Jul 18, 2021. It is now read-only.

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
1. Rename file names.
2. Add configuration values to config files.
3. Add config.yml.dist sample file.
4. Add vertical distribution to encounter map.
5. Rename map class to EncounterMap.
  • Loading branch information
smirik committed Oct 1, 2011
1 parent e2e319b commit 03a19fe
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 84 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,7 @@ result
*.dat
*.tmp
test.rb
.DS_Store
.DS_Store
config.yml
export
old
16 changes: 16 additions & 0 deletions config.yml.dist
@@ -0,0 +1,16 @@
constants:
g: 2.23956667

params:
masses: 0.00005178
gamma: 0.0080694
y_start: -0.2
y_end: 0.2
distribution_limit: 600
iteration_limit: 400

output:
dir: export
gnuplot:
x_axis: 0.1
y_axis: 0.1
6 changes: 6 additions & 0 deletions driver.rb
@@ -0,0 +1,6 @@
require 'map.rb'

map = EncounterMap.new(CONFIG['params']['gamma'].to_f, CONFIG['params']['y_start'].to_f, CONFIG['params']['y_end'].to_f,
CONFIG['params']['distribution_limit'], CONFIG['params']['iteration_limit'], 1,
CONFIG['output']['gnuplot']['x_axis'], CONFIG['output']['gnuplot']['y_axis'])
map.distribution
44 changes: 29 additions & 15 deletions map.rb
@@ -1,6 +1,12 @@
require 'complex'
include Math

require 'yaml'

if (!defined? CONFIG)
CONFIG = YAML.load_file('config.yml')
end

# find sign of given value. Returns +1, -1 or 0. For fixnum & float class
class Float
def sgn
Expand Down Expand Up @@ -28,14 +34,14 @@ def sgn
end
end

class BaseMap
end
class EncounterMap

class Map_TwoBody
attr_accessor :gamma

@@gamma = 8.0694*(10**-3)
@@masses = 5.178*(10**-5)
@@g = 2.23956667
@@masses = CONFIG['params']['masses'].to_f
@@g = CONFIG['constants']['g'].to_f
# Neptune
#@@masses = 5.178*(10**-5)

attr_accessor :e_start
attr_accessor :y0, :e0, :y_new, :e_new
Expand All @@ -44,18 +50,19 @@ class Map_TwoBody
attr_accessor :c_file, :c_filename, :type
attr_accessor :x_axe, :y_axe

def initialize(y_start = -0.2, y_end = 0.2, dist_limit = 100, limit = 500, type = 1, x_axe = 0.2, y_axe = 0.2)
def initialize(gamma = 0.114665, y_start = -0.2, y_end = 0.2, dist_limit = 100, limit = 500, type = 1, x_axe = 0.2, y_axe = 0.2)
@gamma = gamma
@limit = limit
@type = type
self.setInitial(y_start, y_end, dist_limit)
if (type == 1)
@c_filename = @y_end.to_s+@y_start.to_s+'-'+@dist_limit.to_s+'-'+@limit.to_s
@c_filename = @gamma.to_s+'-'+@y_end.to_s+@y_start.to_s+'-'+@dist_limit.to_s+'-'+@limit.to_s
else
@c_filename = 'ln'+@y_end.to_s+@y_start.to_s+'-'+@dist_limit.to_s+'-'+@limit.to_s
end
@c_file = File.new('output/'+@c_filename+'.dat', 'w')
@c_file = File.new(CONFIG['output']['dir']+'/'+@c_filename+'.dat', 'w')
@c_file.puts "#--------------------------------------------------------------------------------------------------------"
@c_file.puts "#INITIAL DATAS: from y0 = #{@y_start} + 0*i to y_end = #{y_end} + 0*i, e0 = #{@e0}, gamma = #{@@gamma}, masses = #{@@masses}\r\n#STEP: #{@coeff}, ITERATION PER ONE DATA: #{@limit}, NUMBER OF STEPS: #{@dist_limit}"
@c_file.puts "#INITIAL DATAS: from y0 = #{@y_start} + 0*i to y_end = #{y_end} + 0*i, e0 = #{@e0}, gamma = #{@gamma}, masses = #{@@masses}\r\n#STEP: #{@coeff}, ITERATION PER ONE DATA: #{@limit}, NUMBER OF STEPS: #{@dist_limit}"
@c_file.puts "#--------------------------------------------------------------------------------------------------------"

@x_axe = x_axe
Expand All @@ -74,7 +81,7 @@ def setInitial(y_start, y_end, dist_limit)
end

def calcE0
@e0 = Math.sqrt(4.0/3.0*(@@gamma + (@y0.abs)**2))
@e0 = Math.sqrt(4.0/3.0*(@gamma + (@y0.abs)**2))
end

def func_e(e)
Expand All @@ -95,8 +102,8 @@ def by_mod(l)
end

def gnufile
gnu_file = File.new('output/'+@c_filename+'.gnu', 'w')
gnu_file.puts "set terminal png\r\nset datafile separator ','\r\nset xlabel 'Re(y)'\r\nset ylabel 'Im(y)'\r\nset xtic auto\r\nset ytic auto\r\nset xrange[-#{@x_axe}:#{@x_axe}]\r\nset yrange[-#{@y_axe}:#{@y_axe}]\r\nset pointsize 1.0\r\nset grid\r\nplot 'output/"+@c_filename+".dat' title 'Symplectic maps' with points 0 0"
gnu_file = File.new(CONFIG['output']['dir']+'/'+@c_filename+'.gnu', 'w')
gnu_file.puts "set term png size 600,600 font '/Library/Fonts/Microsoft/Calibri.ttf,15'\r\nset datafile separator ','\r\nset xlabel 'Re(y)'\r\nset ylabel 'Im(y)'\r\nset xtic auto\r\nset ytic auto\r\nset xrange[-#{@x_axe}:#{@x_axe}]\r\nset yrange[-#{@y_axe}:#{@y_axe}]\r\nset pointsize 1.0\r\nset grid\r\nplot '"+CONFIG['output']['dir']+"/"+@c_filename+".dat' notitle lt -1 lc -1 with dots"
gnu_file.close
end

Expand Down Expand Up @@ -128,17 +135,24 @@ def calculate

def distribution
#puts "dist_limit = #{@dist_limit}"
@coeff = @coeff*2
@dist_limit = @dist_limit/2
for j in 0..@dist_limit
@y0 = Complex.new(@y_start+@coeff*j, 0.0)
self.calcE0
@e_start = @e0
self.calculate
@y0 = Complex.new(0.0, @y_start+@coeff*j)
self.calcE0
@e_start = @e0
self.calculate
end
@c_file.close
self.gnufile
tmp = @c_filename+'.gnu > output/'+@c_filename+'.png'
tmp = @c_filename+'.gnu > '+CONFIG['output']['dir']+'/'+@c_filename+'.png'
tmp2 = @c_filename+'.png'
`gnuplot output/#{tmp}; open output/#{tmp2}`
`gnuplot #{CONFIG['output']['dir']}/#{tmp};`
`open #{CONFIG['output']['dir']}/#{tmp2}`
end

end
52 changes: 0 additions & 52 deletions map_zn_ln.rb

This file was deleted.

7 changes: 0 additions & 7 deletions map_zn_ln2.rb

This file was deleted.

7 changes: 0 additions & 7 deletions map_zn_yn.rb

This file was deleted.

4 changes: 2 additions & 2 deletions plot.gnu
@@ -1,4 +1,4 @@
set terminal png
set term png size 600,1000 font "/Library/Fonts/Microsoft/Calibri.ttf,15"
set datafile separator ",";
set xlabel "Re(y)"
set ylabel "Im(y)"
Expand All @@ -7,4 +7,4 @@ set ytic auto
set xrange [-0.02:0.02]
set pointsize 5.0
set grid
plot 'out.dat' title 'Symplectic maps' with points 0 0
plot 'out.dat' notitle with points 0 0

0 comments on commit 03a19fe

Please sign in to comment.