Class: TokFile::Eqdsk
- Inherits:
-
Object
- Object
- TokFile::Eqdsk
- Defined in:
- lib/tokfile/eqdsk.rb
Constant Summary collapse
- DATANAMES =
attr_accessor :rboxlen, :zboxlen, :r0exp, :rboxlft
[ :rboxlen, :zboxlen, :r0exp, :rboxlft, :dummy, :raxis, :zaxis, :psiaxis, :dummy, :b0exp, :current, :dummy, :dummy, :dummy, :dummy, :dummy, :dummy, :dummy, :dummy, :dummy, :t, :pr, :ttprime, :pprime, :psi, :q, :nbound, :nlimiter, :bound, #:limiter ]
Instance Attribute Summary collapse
-
#nrbox ⇒ Object
Returns the value of attribute nrbox.
-
#nzbox ⇒ Object
Returns the value of attribute nzbox.
-
#rbound ⇒ Object
:limiter.
-
#rlimiter ⇒ Object
:limiter.
-
#zbound ⇒ Object
:limiter.
-
#zlimiter ⇒ Object
:limiter.
Instance Method Summary collapse
-
#initialize(file) ⇒ Eqdsk
constructor
A new instance of Eqdsk.
- #read(line) ⇒ Object
- #size(var) ⇒ Object
- #summary_graphkit ⇒ Object
Constructor Details
#initialize(file) ⇒ Eqdsk
Returns a new instance of Eqdsk.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/tokfile/eqdsk.rb', line 39 def initialize(file) iline = 0 counter = 0 #filehandle = File.open(file, 'r') lines = File.read(file).split("\n") #@datastarts = DATANAMES.inject({}){|h, name| h[name] = nil; h} #line1 = filehandle.gets #@nrbox, @nzbox = filehandle.gets.split(/\s+/).slice(-2..-1).map{|s| eval(s)} @nrbox, @nzbox = lines[0].split(/\s+/).slice(-2..-1).map{|s| eval(s)} #@rboxlen, @zboxlen, @r0exp, @rboxlft, dummy = read(filehandle.gets) #@raxis, @zaxis, @psiaxis, dummy, @b0exp = read(filehandle.gets) #@current, dummy, dummy, dummy, dummy = read(filehandle.gets) #dummy, dummy, dummy, dummy, dummy = read(filehandle.gets) array = [] i = 1 vb2 = TokFile.verbosity > 1 if vb2 eputs eputs "Reading data from eqdsk file #{file}." eputs end total_size = 0 DATANAMES.each do |name| sz = size(name) total_size += sz #ep ['name', name, 'size', sz] if vb2 Terminal.erewind(1) eputs "#{name}(#{sz})#{Terminal::CLEAR_LINE}" if vb2 end if array.size < sz #array += read(filehandle.gets) #array += read(lines[i]) #i+=1 array += read(lines.slice(i...(i+=(sz.to_f/5.0).ceil)).join(' ')) #array += lines.slice(i...(i+=(sz.to_f/5.0).ceil)).join(' ') #filehandle.gets.scanf("%e"){|scan| array.push scan[0]} end if array.size == sz data = array array = [] else data = [] while data.size < sz data.push array.shift end end self.class.attr_accessor name case name when :psi set(name, GSL::Matrix.alloc(*data.pieces(@nzbox)).transpose) when :bound data = data.pieces(@nbound).transpose set(:rbound, data[0].to_gslv) set(:zbound, data[1].to_gslv) when :limiter data = data.pieces(@nlimiter).transpose set(:rlimiter, data[0].to_gslv) set(:zlimiter, data[1].to_gslv) else case sz when 1 set(name, data[0]) else set(name, data.to_gslv) end end end @r = GSL::Vector.linspace(@rboxlft, @rboxlft+@rboxlen, @nrbox) @z = GSL::Vector.linspace(-@zboxlen/2.0, @zboxlen/2.0, @nzbox) if vb2 Terminal.erewind(1) eputs "Read total data size of #{total_size.to_f * 8.0/1.0e6} MB" end if TokFile.verbosity > 0 eputs <<EOF -------------------------------------- Tokfile -------------------------------------- Successfully read an eqdsk file called #{file} with the following parameters: nrbox = #@nrbox nzbox = #@nzbox nbound = #@nbound raxis = #@raxis -------------------------------------- EOF end #@lines = File.read(file).split("\n").map{|str| str.sub(/\A\s+/, '').sub(/\s+\Z/, '')} #@nrbox, @nzbox = @lines[0].split(/\s+/).slice(-2..-1).map{|s| eval(s)} #in_data = true; i = 1 #@atoms = [] #@lines_columns = [] #while in_data #@lines_columns[i] = @lines[i].split(/\s+|(?<=\d)[+-]/).map{|s| eval(s)} #@atoms += @lines_columns[i] #if @nbound = @atoms[start(:nbound)] #if @atoms.size > start(:limiter) #in_data = false #end #end #i+=1 #end #[:t, :p, :pprime, :ttprime, :psi, :q, :rzbound].each do |var| #attr_accessor var #st = start(var) #set(var, @atoms.slice(st...(st+@nrbox))).to_gslv #end #@rboxlen, @zboxlen, @r0exp, @rboxlft, dummy = @lines_columns[1] #ep ['lines_columns', @lines_columns[1], @lines[1]] end |
Instance Attribute Details
#nrbox ⇒ Object
Returns the value of attribute nrbox.
3 4 5 |
# File 'lib/tokfile/eqdsk.rb', line 3 def nrbox @nrbox end |
#nzbox ⇒ Object
Returns the value of attribute nzbox.
3 4 5 |
# File 'lib/tokfile/eqdsk.rb', line 3 def nzbox @nzbox end |
#rbound ⇒ Object
:limiter
20 21 22 |
# File 'lib/tokfile/eqdsk.rb', line 20 def rbound @rbound end |
#rlimiter ⇒ Object
:limiter
20 21 22 |
# File 'lib/tokfile/eqdsk.rb', line 20 def rlimiter @rlimiter end |
#zbound ⇒ Object
:limiter
20 21 22 |
# File 'lib/tokfile/eqdsk.rb', line 20 def zbound @zbound end |
#zlimiter ⇒ Object
:limiter
20 21 22 |
# File 'lib/tokfile/eqdsk.rb', line 20 def zlimiter @zlimiter end |
Instance Method Details
#read(line) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tokfile/eqdsk.rb', line 23 def read(line) #@lines_columns[i] = @lines[i].split(/\s+|(?<=\d)[+-]/).map{|s| eval(s)} line.sub(/\A\s+/, '').sub(/\s+\Z/, '').split(/\s+|(?<=\d)(?=[+-])/).map{|s| eval(s)} #line.scan(/.{15}/).map{|s| eval(s)} #ep ['line', line] #arr = [] #res = line.scanf("%16.9E"){|n| arr.push n} #line.scanf("%E"){|n| arr.push n[0]} #ep ['res', res, arr] #ep ['res', arr] #arr end |
#size(var) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/tokfile/eqdsk.rb', line 195 def size(var) case var #when :nbound, :nlimiter #1 when :bound @nbound * 2 when :limiter @nlimiter * 2 when :psi @nrbox * @nzbox when :t, :pr, :pprime, :ttprime, :q @nrbox else 1 end end |
#summary_graphkit ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/tokfile/eqdsk.rb', line 173 def summary_graphkit psivec = GSL::Vector.linspace(@psi.min, 0.0, @nrbox) multkit = GraphKit::MultiWindow.new([:pr, :pprime, :t, :ttprime, :q].map{|name| kit = GraphKit.quick_create([psivec, send(name)]) kit.title = name.to_s kit.ylabel = nil kit.xlabel = 'psi' kit }) psikit = GraphKit.quick_create([@r, @z, @psi]) psikit.data[0].gp.with = 'pm3d' psikit.gp.view = "map" boundkit = GraphKit.quick_create([@rbound, @zbound, @rbound.collect{0.0}]) psikit += boundkit psikit.gp.key = "off" psikit.title = 'psi' psikit.xlabel = 'R' psikit.ylabel = 'Z' multkit.push psikit multkit.gp.multiplot = "layout 2,3" multkit end |