Module: CodeRunner::Gs2::GSLVectors
- Included in:
- CodeRunner::Gs2
- Defined in:
- lib/gs2crmod/gsl_data.rb
Instance Method Summary collapse
- #apar2_over_time_gsl_vector(options) ⇒ Object
-
#dt_gsl_vector(options) ⇒ Object
The size of each time step, indexed by time, normalised to a/v_th1.
- #es_heat_by_kx_over_time_gsl_vector(options) ⇒ Object
- #es_heat_by_ky_over_time_gsl_vector(options) ⇒ Object
- #es_heat_flux_over_time_gsl_vector(options) ⇒ Object
- #es_heat_par_over_time_gsl_vector(options) ⇒ Object (also: #es_heat_par_gsl_vector)
- #es_heat_perp_over_time_gsl_vector(options) ⇒ Object (also: #es_heat_perp_gsl_vector)
- #es_mom_flux_over_time_gsl_vector(options) ⇒ Object
-
#frequency_by_kx_over_time_gsl_vector(options) ⇒ Object
The real frequency of the fluctuations, read from the .out file, indexed by time and normalised to vth_1/a.
- #frequency_by_kxy_over_time_gsl_vector(options) ⇒ Object
- #frequency_by_ky_over_time_gsl_vector(options) ⇒ Object
-
#frequency_over_ky_gsl_vector(options) ⇒ Object
Frequency, indexed over ky, taken direct from the gs2 output file.
-
#growth_rate_by_kx_over_time_gsl_vector(options) ⇒ Object
:kx or :kx_index must be specified in options.
- #growth_rate_by_kxy_over_time_gsl_vector(options) ⇒ Object
-
#growth_rate_by_ky_over_time_gsl_vector(options) ⇒ Object
:ky or :ky_index must be specified in options.
-
#growth_rate_over_kx_gsl_vector(options) ⇒ Object
The growth rate, calculated from the potential, indexed by kx.
-
#growth_rate_over_kx_slice_gsl_vector(options) ⇒ Object
The growth rate, calculated from the potential, indexed by kx.
-
#growth_rate_over_ky_gsl_vector(options) ⇒ Object
The growth rate, calculated from the potential, indexed by ky.
-
#growth_rate_over_ky_slice_gsl_vector(options) ⇒ Object
The growth rate, calculated from the potential, indexed by ky.
- #hflux_tot_over_time_gsl_vector(options) ⇒ Object (also: #hflux_tot_gsl_vector)
- #kpar_gsl_vector(options) ⇒ Object
- #linked_kx_elements_gsl_vector(options) ⇒ Object
-
#lpc_energy_gsl_vector(options) ⇒ Object
Velocity space diagnostics: fraction of dist func in higher energy harmonics.
-
#lpc_pitch_angle_gsl_vector(options) ⇒ Object
Velocity space diagnostics: fraction of dist func in higher pitch angle harmonics.
- #par_mom_flux_over_time_gsl_vector(options) ⇒ Object
- #perp_mom_flux_over_time_gsl_vector(options) ⇒ Object
- #phi0_by_kx_by_ky_over_time_gsl_vector(options) ⇒ Object
- #phi2_by_kx_over_time_gsl_vector(options) ⇒ Object
- #phi2_by_ky_over_time_gsl_vector(options) ⇒ Object
- #phi2_by_mode_over_time_gsl_vector(options) ⇒ Object
-
#phi2tot_over_time_gsl_vector(options) ⇒ Object
The square of the potential summed over all wave numbers, indexed by time, normalised to (e/T)(rho_1/a).
- #phi_along_field_line_gsl_vector(options) ⇒ Object
- #phi_for_eab_movie_gsl_vector(options) ⇒ Object
- #scan_parameter_value_gsl_vector(options) ⇒ Object
- #spectrum_over_kpar_gsl_vector(options) ⇒ Object
- #spectrum_over_kx_gsl_vector(options) ⇒ Object
- #spectrum_over_kxy_gsl_vector(options) ⇒ Object
- #spectrum_over_ky_gsl_vector(options) ⇒ Object
- #theta_along_field_line_gsl_vector(options) ⇒ Object
- #tpar2_by_mode_over_time_gsl_vector(options) ⇒ Object
- #tperp2_by_mode_over_time_gsl_vector(options) ⇒ Object
- #transient_amplification_over_kx_gsl_vector(options) ⇒ Object
- #transient_amplification_over_ky_gsl_vector(options) ⇒ Object
- #transient_es_heat_flux_amplification_over_kx_gsl_vector(options) ⇒ Object
- #transient_es_heat_flux_amplification_over_kxy_gsl_vector(options) ⇒ Object
- #transient_es_heat_flux_amplification_over_ky_gsl_vector(options) ⇒ Object
-
#vres_energy_gsl_vector(options) ⇒ Object
Velocity space diagnostics: integral error due to energy resolution.
-
#vres_pitch_angle_gsl_vector(options) ⇒ Object
Velocity space diagnostics: integral error due to pitch angle resolution.
- #x_gsl_vector(options) ⇒ Object
- #y_gsl_vector(options) ⇒ Object
- #zonal_spectrum_gsl_vector(options) ⇒ Object
Instance Method Details
#apar2_over_time_gsl_vector(options) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/gs2crmod/gsl_data.rb', line 228 def apar2_over_time_gsl_vector() Dir.chdir(@directory) do #Necessary options: ky #log 'about to open netcdf file' #options.setup_time_window phis = netcdf_file.var('apar2').get('start'=>[[:begin_element]], 'end'=>[[:end_element]] ).to_a log 'about to allocate gsl vector' vec = GSL::Vector.alloc(phis) log 'finished' return fix_norm(vec, 1, ) end end |
#dt_gsl_vector(options) ⇒ Object
The size of each time step, indexed by time, normalised to a/v_th1.
362 363 364 365 366 367 |
# File 'lib/gs2crmod/gsl_data.rb', line 362 def dt_gsl_vector() t = gsl_vector('t', ) size = t.size # NB t already has norm fixed return t.subvector(1, size - 1) - t.subvector(0, size-1) end |
#es_heat_by_kx_over_time_gsl_vector(options) ⇒ Object
415 416 417 418 |
# File 'lib/gs2crmod/gsl_data.rb', line 415 def es_heat_by_kx_over_time_gsl_vector() [:direction] = :kx es_heat_by_kxy_over_time_gsl_vector() end |
#es_heat_by_ky_over_time_gsl_vector(options) ⇒ Object
419 420 421 422 |
# File 'lib/gs2crmod/gsl_data.rb', line 419 def es_heat_by_ky_over_time_gsl_vector() [:direction] = :ky es_heat_by_kxy_over_time_gsl_vector() end |
#es_heat_flux_over_time_gsl_vector(options) ⇒ Object
809 810 811 812 813 814 815 |
# File 'lib/gs2crmod/gsl_data.rb', line 809 def es_heat_flux_over_time_gsl_vector() Dir.chdir(@directory) do .setup_time_window return GSL::Vector.alloc(netcdf_file.var('es_heat_flux').get('start' => [[:species_index].to_i - 1, [:begin_element]], 'end' => [[:species_index].to_i - 1, [:end_element]]).to_a.flatten) end end |
#es_heat_par_over_time_gsl_vector(options) ⇒ Object Also known as: es_heat_par_gsl_vector
816 817 818 819 820 821 822 |
# File 'lib/gs2crmod/gsl_data.rb', line 816 def es_heat_par_over_time_gsl_vector() Dir.chdir(@directory) do .setup_time_window return GSL::Vector.alloc(netcdf_file.var('es_heat_par').get('start' => [[:species_index].to_i - 1, [:begin_element]], 'end' => [[:species_index].to_i - 1, [:end_element]]).to_a.flatten) end end |
#es_heat_perp_over_time_gsl_vector(options) ⇒ Object Also known as: es_heat_perp_gsl_vector
824 825 826 827 828 829 830 |
# File 'lib/gs2crmod/gsl_data.rb', line 824 def es_heat_perp_over_time_gsl_vector() Dir.chdir(@directory) do .setup_time_window return GSL::Vector.alloc(netcdf_file.var('es_heat_perp').get('start' => [[:species_index].to_i - 1, [:begin_element]], 'end' => [[:species_index].to_i - 1, [:end_element]]).to_a.flatten) end end |
#es_mom_flux_over_time_gsl_vector(options) ⇒ Object
839 840 841 842 843 844 845 |
# File 'lib/gs2crmod/gsl_data.rb', line 839 def es_mom_flux_over_time_gsl_vector() Dir.chdir(@directory) do .setup_time_window return GSL::Vector.alloc(netcdf_file.var('es_mom_flux').get('start' => [[:species_index].to_i - 1, [:begin_element]], 'end' => [[:species_index].to_i - 1, [:end_element]]).to_a.flatten) end end |
#frequency_by_kx_over_time_gsl_vector(options) ⇒ Object
The real frequency of the fluctuations, read from the .out file, indexed by time and normalised to vth_1/a. :ky_index or :kx_index must be specified in options.
311 312 313 314 |
# File 'lib/gs2crmod/gsl_data.rb', line 311 def frequency_by_kx_over_time_gsl_vector() [:direction] = :kx frequency_by_kxy_over_time_gsl_vector() end |
#frequency_by_kxy_over_time_gsl_vector(options) ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/gs2crmod/gsl_data.rb', line 321 def frequency_by_kxy_over_time_gsl_vector() kxy = [:direction] kxy_index = kxy + :_index kxys = get_list_of(kxy) desired_kxy = kxys[[kxy_index]] raise "No k found at the desired index" if desired_kxy.nil? omega_reals = [] File.open(@run_name+".out",'r') do |fileHandle| fileHandle.each_line do |fileLine| if fileLine.include?('aky=') # Only examine the lines of the .out file that contain frequency information. index = fileLine.index('akx=') raise "akx wasn't found where it was expected in the .out file." if index.nil? akx = fileLine[(index+4)..-1].to_f index = fileLine.index('aky=') raise "aky wasn't found where it was expected in the .out file." if index.nil? aky = fileLine[(index+4)..-1].to_f index = fileLine.index('om=') raise "om wasn't found where it was expected in the .out file." if index.nil? omr = fileLine[(index+3)..-1].to_f if kxy == :kx # You need to be careful when testing equality of the desired k with the k in the .out file # since the .out file is only written to ~ 5 significant digits: omega_reals << omr if ((desired_kxy - akx).abs/(desired_kxy.abs + 1e-7) < 1e-4) else omega_reals << omr if ((desired_kxy - aky).abs/(desired_kxy.abs + 1e-7) < 1e-4) end end end end raise "No real frequencies found in the .out file for the desired k" if (omega_reals.size==0) GSL::Vector.alloc(omega_reals) end |
#frequency_by_ky_over_time_gsl_vector(options) ⇒ Object
316 317 318 319 |
# File 'lib/gs2crmod/gsl_data.rb', line 316 def frequency_by_ky_over_time_gsl_vector() [:direction] = :ky frequency_by_kxy_over_time_gsl_vector() end |
#frequency_over_ky_gsl_vector(options) ⇒ Object
Frequency, indexed over ky, taken direct from the gs2 output file
410 411 412 413 |
# File 'lib/gs2crmod/gsl_data.rb', line 410 def frequency_over_ky_gsl_vector() .convert_to_index(self, :kx) return GSL::Vector.alloc(gsl_vector('ky').to_a.map{|ky| frequency_at_ky_at_kx[ky].values[[:kx_index]-1]}) end |
#growth_rate_by_kx_over_time_gsl_vector(options) ⇒ Object
:kx or :kx_index must be specified in options
282 283 284 285 |
# File 'lib/gs2crmod/gsl_data.rb', line 282 def growth_rate_by_kx_over_time_gsl_vector() [:direction] = :kx growth_rate_by_kxy_over_time_gsl_vector() end |
#growth_rate_by_kxy_over_time_gsl_vector(options) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/gs2crmod/gsl_data.rb', line 294 def growth_rate_by_kxy_over_time_gsl_vector() # i.e. time_dependent_gr_by_ky_vs_time or phi2_by_kx_vs_time kxy = [:direction] phi = gsl_vector("phi2_by_#{kxy}_over_time", ).log / 2.0 size = phi.size dphi = phi.subvector(1, size - 1) - phi.subvector(0, size-1) # NB dt already has norm fixed, dphi is dimensionless return fix_norm(dphi/gsl_vector('dt'), 0, ) end |
#growth_rate_by_ky_over_time_gsl_vector(options) ⇒ Object
:ky or :ky_index must be specified in options
290 291 292 293 |
# File 'lib/gs2crmod/gsl_data.rb', line 290 def growth_rate_by_ky_over_time_gsl_vector() [:direction] = :ky growth_rate_by_kxy_over_time_gsl_vector() end |
#growth_rate_over_kx_gsl_vector(options) ⇒ Object
The growth rate, calculated from the potential, indexed by kx. Only makes sense in linear calculations.
370 371 372 373 |
# File 'lib/gs2crmod/gsl_data.rb', line 370 def growth_rate_over_kx_gsl_vector() [:direction] = :kx growth_rate_over_kxy_gsl_vector() end |
#growth_rate_over_kx_slice_gsl_vector(options) ⇒ Object
The growth rate, calculated from the potential, indexed by kx. Only makes sense in linear calculations.
391 392 393 394 395 396 397 398 |
# File 'lib/gs2crmod/gsl_data.rb', line 391 def growth_rate_over_kx_slice_gsl_vector() Dir.chdir(@directory) do slice_of_growth_rates = send(:growth_rate_at_ky_at_kx)[[:ky]].values raise "Something went wrong: slice of growth rates seems empty" if slice_of_growth_rates.nil? return GSL::Vector.alloc(slice_of_growth_rates) #return GSL::Vector.alloc(send(:growth_rate_at_ky_at_kx[ky]).values) end end |
#growth_rate_over_ky_gsl_vector(options) ⇒ Object
The growth rate, calculated from the potential, indexed by ky. Only makes sense in linear calculations.
375 376 377 378 |
# File 'lib/gs2crmod/gsl_data.rb', line 375 def growth_rate_over_ky_gsl_vector() [:direction] = :ky growth_rate_over_kxy_gsl_vector() end |
#growth_rate_over_ky_slice_gsl_vector(options) ⇒ Object
The growth rate, calculated from the potential, indexed by ky. Only makes sense in linear calculations.
401 402 403 404 405 406 407 |
# File 'lib/gs2crmod/gsl_data.rb', line 401 def growth_rate_over_ky_slice_gsl_vector() Dir.chdir(@directory) do slice_of_growth_rates = send(:growth_rate_at_ky_at_kx).values.map{|h| h[[:kx]]} raise "Something went wrong: slice of growth rates seems empty" if slice_of_growth_rates.nil? return GSL::Vector.alloc(slice_of_growth_rates) end end |
#hflux_tot_over_time_gsl_vector(options) ⇒ Object Also known as: hflux_tot_gsl_vector
798 799 800 801 802 803 804 805 806 807 |
# File 'lib/gs2crmod/gsl_data.rb', line 798 def hflux_tot_over_time_gsl_vector() Dir.chdir(@directory) do .setup_time_window narr = netcdf_file.var('hflux_tot').get('start' => [[:begin_element]], 'end' => [[:end_element]]) #eputs 'Got narr' #ep 'hflux_tot', hflux #eputs "fixing norm" return fix_heat_flux_norm(GSL::Vector.alloc(narr.to_a), ) end end |
#kpar_gsl_vector(options) ⇒ Object
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'lib/gs2crmod/gsl_data.rb', line 669 def kpar_gsl_vector() Dir.chdir(@directory) do if agk? or (@s_hat_input||@shat).abs < 1.0e-5 dk = 1 phi = list(:theta).values else kxe = gsl_vector('linked_kx_elements', ) dk = 1.0/kxe.size phi = gsl_vector_complex('phi_along_field_line', ) end case phi.size%2 when 0 kpar = GSL::Vector.indgen(phi.size-1, -((phi.size-3)/2))*dk when 1 kpar = GSL::Vector.indgen(phi.size-1, -((phi.size-2)/2))*dk end #ep 'kpar', kpar, 'phi.size', phi.size #ep 'kpar.class', kpar.class return kpar end end |
#linked_kx_elements_gsl_vector(options) ⇒ Object
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
# File 'lib/gs2crmod/gsl_data.rb', line 577 def linked_kx_elements_gsl_vector() Dir.chdir(@directory) do return GSL::Vector.alloc([0]) if @grid_option == "single" or agk? if agk? or (@s_hat_input or @shat).abs < 1.0e-5 #p 'op1', options .convert_to_index(self, :ky, :kx) #p 'op2', options #eputs "No Magnetic Shear" # begin # options.convert_to_index(:kx) # rescue # raise "Must specify kx or kx_index if no magnetics shear" # end # # theta0 = (options[:theta0] || 0) # # theta0 += jump(options) if @g_exb #theta0 = (options[:kx_index]) #if @g_exb and @g_exb.abs > 0.0 #theta0 += jump(options) #theta0 = theta0%((list(:kx).size-1)/2) if list(:kx).size > 1 #end return GSL::Vector.alloc([[:kx_index] - 1]) end .convert_to_index(self, :ky, :kx) nkx = netcdf_file.var('kx').dims[0].length # p nkx stride = @jtwist * ([:ky_index] -1 ) #stride = 3 nlinks = [(nkx / stride).floor, 1].max theta0 = [:kx_index] % @jtwist #(options[:theta0] || 0) log 'stride', stride, 'nlinks', nlinks, 'theta0', theta0 #if @g_exb and @jtwist > 1 #and options[:t_index] # kx_shift = list(:ky)[options[:ky_index]] * @g_exb # p list(:t)[options[:t_index]], options[:t_index], kx_shift # kx_shift *= list(:t)[(options[:t_index] or list(:t).keys.max)] # jump = (kx_shift / list(:kx)[2]).round #theta0 += (@jtwist - jump(options) % @jtwist) % @jtwist # else # jump = 0 #end ep 'stride', stride, 'nlinks', nlinks, 'theta0', theta0 ep GSL::Vector.indgen(nlinks / 2, nkx + theta0 - nlinks / 2 * stride, stride).connect(GSL::Vector.indgen(nlinks / 2, theta0, stride)).reverse if nlinks > 1 #return [7,5,3,1,34].to_gslv return GSL::Vector.alloc([theta0 % jtwist]) if nlinks ==1 return GSL::Vector.indgen(nlinks / 2, nkx + theta0 - nlinks / 2 * stride, stride).connect(GSL::Vector.indgen(nlinks / 2, theta0, stride)).reverse end end |
#lpc_energy_gsl_vector(options) ⇒ Object
Velocity space diagnostics: fraction of dist func in higher energy harmonics
855 856 857 858 859 |
# File 'lib/gs2crmod/gsl_data.rb', line 855 def lpc_energy_gsl_vector() raise "Velocity space lpc diagnostics not found" unless FileTest.exist? "#@directory/#@run_name.lpc" lpc = GSL::Vector.filescan("#@directory/#@run_name.lpc") return lpc[2] end |
#lpc_pitch_angle_gsl_vector(options) ⇒ Object
Velocity space diagnostics: fraction of dist func in higher pitch angle harmonics
848 849 850 851 852 |
# File 'lib/gs2crmod/gsl_data.rb', line 848 def lpc_pitch_angle_gsl_vector() raise "Velocity space lpc diagnostics not found" unless FileTest.exist? "#@directory/#@run_name.lpc" lpc = GSL::Vector.filescan("#@directory/#@run_name.lpc") return lpc[1] end |
#par_mom_flux_over_time_gsl_vector(options) ⇒ Object
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 |
# File 'lib/gs2crmod/gsl_data.rb', line 874 def par_mom_flux_over_time_gsl_vector() Dir.chdir(@directory) do .setup_time_window # This is a hack... one day some one will put it in the NetCDF file (haha). momlines = `grep parmom #@run_name.out` mom = [] momlines.scan(Regexp.new("#{LongRegexen::FLOAT.to_s}$")) do mom.push $~[:float].to_f end [:end_element] = (mom.size + [:end_element]) if [:end_element] < 0 # p options return GSL::Vector.alloc(mom).subvector([:begin_element], [:end_element] - [:begin_element] + 1) end end |
#perp_mom_flux_over_time_gsl_vector(options) ⇒ Object
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 |
# File 'lib/gs2crmod/gsl_data.rb', line 890 def perp_mom_flux_over_time_gsl_vector() Dir.chdir(@directory) do .setup_time_window # This is a hack... one day some one will put it in the NetCDF file (haha). momlines = `grep perpmom #@run_name.out` mom = [] momlines.scan(Regexp.new("#{LongRegexen::FLOAT.to_s}$")) do mom.push $~[:float].to_f end [:end_element] = (mom.size + [:end_element]) if [:end_element] < 0 # p options return GSL::Vector.alloc(mom).subvector([:begin_element], [:end_element] - [:begin_element] + 1) end end |
#phi0_by_kx_by_ky_over_time_gsl_vector(options) ⇒ Object
568 569 570 571 572 573 574 575 |
# File 'lib/gs2crmod/gsl_data.rb', line 568 def phi0_by_kx_by_ky_over_time_gsl_vector() Dir.chdir(@directory) do .convert_to_index(self, :kx, :ky) phi0_array = netcdf_file.var('phi0').get.to_a.map{|arr| arr[[:kx_index] - 1][[:ky_index] - 1][[:ri]]} return GSL::Vector.alloc(phi0_array) end end |
#phi2_by_kx_over_time_gsl_vector(options) ⇒ Object
452 453 454 455 |
# File 'lib/gs2crmod/gsl_data.rb', line 452 def phi2_by_kx_over_time_gsl_vector() [:direction] = :kx phi2_by_kxy_over_time_gsl_vector() end |
#phi2_by_ky_over_time_gsl_vector(options) ⇒ Object
456 457 458 459 |
# File 'lib/gs2crmod/gsl_data.rb', line 456 def phi2_by_ky_over_time_gsl_vector() [:direction] = :ky phi2_by_kxy_over_time_gsl_vector() end |
#phi2_by_mode_over_time_gsl_vector(options) ⇒ Object
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
# File 'lib/gs2crmod/gsl_data.rb', line 496 def phi2_by_mode_over_time_gsl_vector() Dir.chdir(@directory) do #Necessary options: :ky and :kx #Optional options: :t_index_window # eputs "got here" #options[:begin_element], options[:end_element] = (options[:t_index_window] ? options[:t_index_window].map{|ind| ind -1} : [0, -1]) .setup_time_window phi_t_array=nil if @grid_option == "single" phi_t_array = netcdf_file.var('phi2').get('start' => [[:begin_element]], 'end' => [[:end_element]]).to_a.flatten else # value = options[:ky] # eputs value # get_list_of(:ky) # index = @ky_list.find{|index,val| (val-value).abs < Float::EPSILON}[0] .convert_to_index(self, :kx, :ky) # p options phi_t_array = netcdf_file.var("phi2_by_mode").get('start' => [[:kx_index] - 1, [:ky_index] - 1, [:begin_element]], 'end' => [[:kx_index] - 1, [:ky_index] - 1, [:end_element]]).to_a.flatten # eputs 'phi_t_array.size', phi_t_array.size end return GSL::Vector.alloc(phi_t_array) end end |
#phi2tot_over_time_gsl_vector(options) ⇒ Object
The square of the potential summed over all wave numbers, indexed by time, normalised to (e/T)(rho_1/a).
216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/gs2crmod/gsl_data.rb', line 216 def phi2tot_over_time_gsl_vector() Dir.chdir(@directory) do #Necessary options: ky #log 'about to open netcdf file' #options.setup_time_window phis = netcdf_file.var('phi2').get('start'=>[[:begin_element]], 'end'=>[[:end_element]] ).to_a log 'about to allocate gsl vector' vec = GSL::Vector.alloc(phis) log 'finished' return fix_norm(vec, 1, ) end end |
#phi_along_field_line_gsl_vector(options) ⇒ Object
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 |
# File 'lib/gs2crmod/gsl_data.rb', line 694 def phi_along_field_line_gsl_vector() Dir.chdir(@directory) do complex_phi_vector= gsl_vector_complex('phi_along_field_line', ) case [:imrc] when :im phi_vector = complex_phi_vector.imag when :mag mag = true phi_vector = complex_phi_vector.abs2 when :corr thetas = gsl_vector('theta_along_field_line', ) min = thetas.abs.to_a.index(thetas.abs.min) at_0 = complex_phi_vector[min] # ep at_0.class phi_vector = (complex_phi_vector * (at_0 / at_0.mag).conj).real # gsl_complex('correcting_phase', options)).real when :real phi_vector = complex_phi_vector.real else raise CRError.new("options[:imrc] was: #{[:irmc]}") end phi_vector *= -1.0 if [:flip] (phi_vector /= phi_vector.abs.max; phi_vector *= ([:height] || 1.0)) if [:norm] phi_vector = phi_vector.reverse if [:rev] return phi_vector end end |
#phi_for_eab_movie_gsl_vector(options) ⇒ Object
787 788 789 790 791 792 793 794 795 796 |
# File 'lib/gs2crmod/gsl_data.rb', line 787 def phi_for_eab_movie_gsl_vector() Dir.chdir(@directory) do #options required are x_index, y_index and tm_index (Time) mvf_name = @run_name + '.movie.nc' raise CRError.new("cannot find file #{mvf_name}") unless FileTest.exist? mvf_name ncf = NumRu::NetCDF.open(mvf_name) # p ncf.var('phi_by_xmode').get.to_a[0][0][0] return GSL::Vector.alloc(ncf.var('phi_by_xmode').get.to_a[[:tm_index] - 1].map{|xy_arr| xy_arr[[:x_index] - 1][[:y_index] - 1]}) end end |
#scan_parameter_value_gsl_vector(options) ⇒ Object
906 907 908 |
# File 'lib/gs2crmod/gsl_data.rb', line 906 def scan_parameter_value_gsl_vector() return GSL::Vector.alloc(netcdf_file.var('scan_parameter_value').get.to_a) end |
#spectrum_over_kpar_gsl_vector(options) ⇒ Object
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 |
# File 'lib/gs2crmod/gsl_data.rb', line 631 def spectrum_over_kpar_gsl_vector() Dir.chdir(@directory) do # , /kpar_spectrum/ #ep 'zero?', (@s_hat_input||@shat)==0.0 unless agk? or (@s_hat_input||@shat||0.0).abs<1.0e-5 phi = gsl_vector_complex('phi_along_field_line', ) phi = phi.subvector(0,phi.size-1) #i = 0 #phi = phi.collect{|re,im| #i+=1; GSL::Complex.alloc(Math.sin(0.1*i), Math.cos(0.1*i))+ #GSL::Complex.alloc(Math.sin(0.4*i), Math.cos(0.4*i)) #} ##GraphKit.quick_create([phi.square]).gnuplot phi_k = phi.forward phi_kr = phi_k.square case phi_kr.size%2 when 0 spec = phi_kr.subvector((phi_kr.size+2)/2, (phi_kr.size-2)/2).connect(phi_kr.subvector(0, (phi_kr.size+2)/2)) when 1 spec = phi_kr.subvector((phi_kr.size + 1)/2, (phi_kr.size-1)/2).connect(phi_kr.subvector(0, (phi_kr.size+1)/2)) end ##spec = phi_kr #ep 'spec.class', spec.class return spec else gm = gsl_matrix('spectrum_over_ky_over_kpar', ) vec = GSL::Vector.alloc(gm.shape[1]) vec.set_all(0.0) for ky_element in 0...gm.shape[0] vec+= gm.row(ky_element) end vec = vec/gm.shape[0] return vec end end end |
#spectrum_over_kx_gsl_vector(options) ⇒ Object
909 910 911 912 |
# File 'lib/gs2crmod/gsl_data.rb', line 909 def spectrum_over_kx_gsl_vector() [:direction] = :kx spectrum_over_kxy_gsl_vector() end |
#spectrum_over_kxy_gsl_vector(options) ⇒ Object
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 |
# File 'lib/gs2crmod/gsl_data.rb', line 917 def spectrum_over_kxy_gsl_vector() Dir.chdir(@directory) do # i.e. spectrum_over_ky or spectrum_over_kx kxy = [:direction] # eputs options[:t_index] raise "Spectrum makes no sense for single modes" if @grid_option == "single" .convert_to_index(:t) if [:t] or [:t_element] # eputs options[:t_index] [:t_index] ||= list(:t).keys.max # eputs options[:t_index] phi_array = netcdf_file.var("phi2_by_#{kxy}").get('start' => [0, [:t_index] - 1], 'end' => [-1, [:t_index] - 1]).to_a.flatten v = GSL::Vector.alloc(phi_array) v = v.from_box_order if kxy == :kx v = v.mul(gsl_vector(kxy).square) unless [:phi2_only] return v end end |
#spectrum_over_ky_gsl_vector(options) ⇒ Object
913 914 915 916 |
# File 'lib/gs2crmod/gsl_data.rb', line 913 def spectrum_over_ky_gsl_vector() [:direction] = :ky spectrum_over_kxy_gsl_vector() end |
#theta_along_field_line_gsl_vector(options) ⇒ Object
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 |
# File 'lib/gs2crmod/gsl_data.rb', line 723 def theta_along_field_line_gsl_vector() Dir.chdir(@directory) do case @grid_option when "single", "range" theta_vector = gsl_vector(:theta) when "box" #eputs "Start theta_along_field_line" kx_elements = gsl_vector('linked_kx_elements', ).to_a #if @grid_option == "range" #kx_elements = kx_elements.to_gslv.from_box_order.to_a #end ep 'kx_elements', kx_elements.to_a # ep list(:kx).keys.max # ep kx_elements[0], list(:kx)[(kx_elements[0] + 1).to_i] # ep kx_elements[-1], list(:kx)[(kx_elements[-1] + 1).to_i] thetas = gsl_vector(:theta) # ep thetas #eputs "End theta_along_field_line" return thetas if agk? or (@s_hat_input or @shat).abs < 1.0e-5 if gryfx? theta_list = ((1..kx_elements.size).to_a.map do |i| thetas * i end) thetas = theta_list.inject{|o,n| o.connect(n)} thetas -= Math::PI*(kx_elements.size-1) return thetas end theta_list = (kx_elements.map do |element| kx = list(:kx)[(element + 1).to_i] # ep element #ep 'kx', kx, 'shat', (@s_hat_input or @shat), 'ky', list(:ky)[options[:ky_index]] thetas - 1.0 / (@s_hat_input or @shat) / list(:ky)[[:ky_index]] * kx end).inject{|old, new| old.connect(new)} # thetas = gsl_vector(:theta) - 1.0 / @shat / list(:ky)[options[:ky_index]] * list(:kx)[(kx_elements[0] + 1).to_i] #- Math::PI*(kx_elements.size - 1) # get_list_of(:ky, :t) # if @g_exb #and options[:t_index] if [:moving] theta_list = theta_list - Math::PI * 2.0 * (jump() / @jtwist) else # ep 'jump % jtwist is!!', jump(options) % @jtwist theta_list = theta_list - Math::PI * 2.0 / @nx.to_f * ((jump() % @jtwist).to_f / @jtwist.to_f) end # jump = 0 # end # theta_list = thetas.dup #gsl_vector(:theta) - Math::PI*kx_elements.size # (kx_elements.size - 1).times do # thetas = thetas + Math::PI * 2.0 # theta_list = theta_list.connect(thetas) # end # pp theta_list.to_a.values_at(0, theta_list.size - 1) # pp theta_list.to_a.max theta_vector = theta_list end # theta_vector = theta_vector.reverse if options[:rev] theta_vector *= (@shat) if [:z] return theta_vector end end |
#tpar2_by_mode_over_time_gsl_vector(options) ⇒ Object
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/gs2crmod/gsl_data.rb', line 520 def tpar2_by_mode_over_time_gsl_vector() Dir.chdir(@directory) do #Necessary options: :ky and :kx #Optional options: :t_index_window # eputs "got here" #options[:begin_element], options[:end_element] = (options[:t_index_window] ? options[:t_index_window].map{|ind| ind -1} : [0, -1]) .setup_time_window tpar_t_array=nil if @grid_option == "single" tpar_t_array = netcdf_file.var('tpar2').get('start' => [[:begin_element]], 'end' => [[:end_element]]).to_a.flatten else # value = options[:ky] # eputs value # get_list_of(:ky) # index = @ky_list.find{|index,val| (val-value).abs < Float::EPSILON}[0] .convert_to_index(self, :kx, :ky, :species) # p options tpar_t_array = netcdf_file.var("tpar2_by_mode").get('start' => [[:kx_index] - 1, [:ky_index] - 1, [:species_index] - 1, [:begin_element]], 'end' => [[:kx_index] - 1, [:ky_index] - 1, [:species_index] - 1, [:end_element]]).to_a.flatten # eputs 'tpar_t_array.size', tpar_t_array.size end return GSL::Vector.alloc(tpar_t_array) end end |
#tperp2_by_mode_over_time_gsl_vector(options) ⇒ Object
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/gs2crmod/gsl_data.rb', line 544 def tperp2_by_mode_over_time_gsl_vector() Dir.chdir(@directory) do #Necessary options: :ky and :kx #Optional options: :t_index_window # eputs "got here" #options[:begin_element], options[:end_element] = (options[:t_index_window] ? options[:t_index_window].map{|ind| ind -1} : [0, -1]) .setup_time_window tperp_t_array=nil if @grid_option == "single" tperp_t_array = netcdf_file.var('tperp2').get('start' => [[:begin_element]], 'end' => [[:end_element]]).to_a.flatten else # value = options[:ky] # eputs value # get_list_of(:ky) # index = @ky_list.find{|index,val| (val-value).abs < Float::EPSILON}[0] .convert_to_index(self, :kx, :ky, :species) # p options tperp_t_array = netcdf_file.var("tperp2_by_mode").get('start' => [[:kx_index] - 1, [:ky_index] - 1, [:species_index] - 1, [:begin_element]], 'end' => [[:kx_index] - 1, [:ky_index] - 1, [:species_index] - 1, [:end_element]]).to_a.flatten # eputs 'tperp_t_array.size', tperp_t_array.size end return GSL::Vector.alloc(tperp_t_array) end end |
#transient_amplification_over_kx_gsl_vector(options) ⇒ Object
261 262 263 264 |
# File 'lib/gs2crmod/gsl_data.rb', line 261 def transient_amplification_over_kx_gsl_vector() [:direction] = :kx transient_amplification_over_kxy_gsl_vector() end |
#transient_amplification_over_ky_gsl_vector(options) ⇒ Object
265 266 267 268 |
# File 'lib/gs2crmod/gsl_data.rb', line 265 def transient_amplification_over_ky_gsl_vector() [:direction] = :ky transient_amplification_over_kxy_gsl_vector() end |
#transient_es_heat_flux_amplification_over_kx_gsl_vector(options) ⇒ Object
241 242 243 244 |
# File 'lib/gs2crmod/gsl_data.rb', line 241 def transient_es_heat_flux_amplification_over_kx_gsl_vector() [:direction] = :kx transient_es_heat_flux_amplification_over_kxy_gsl_vector() end |
#transient_es_heat_flux_amplification_over_kxy_gsl_vector(options) ⇒ Object
250 251 252 253 254 255 256 257 258 259 |
# File 'lib/gs2crmod/gsl_data.rb', line 250 def transient_es_heat_flux_amplification_over_kxy_gsl_vector() Dir.chdir(@directory) do # i.e. phi2_by_ky_vs_time or phi2_by_kx_vs_time kxy = [:direction].to_sym # ep :growth_rate_at_ + kxy p send(:transient_es_heat_flux_amplification_at_species_at_ + kxy) return GSL::Vector.alloc(send(:transient_es_heat_flux_amplification_at_species_at_ + kxy)[[:species_index]-1].values) end end |
#transient_es_heat_flux_amplification_over_ky_gsl_vector(options) ⇒ Object
246 247 248 249 |
# File 'lib/gs2crmod/gsl_data.rb', line 246 def transient_es_heat_flux_amplification_over_ky_gsl_vector() [:direction] = :ky transient_es_heat_flux_amplification_over_kxy_gsl_vector() end |
#vres_energy_gsl_vector(options) ⇒ Object
Velocity space diagnostics: integral error due to energy resolution
869 870 871 872 873 |
# File 'lib/gs2crmod/gsl_data.rb', line 869 def vres_energy_gsl_vector() raise "Velocity space vres diagnostics not found" unless FileTest.exist? "#@directory/#@run_name.vres" vres = GSL::Vector.filescan("#@directory/#@run_name.vres") return vres[2] end |
#vres_pitch_angle_gsl_vector(options) ⇒ Object
Velocity space diagnostics: integral error due to pitch angle resolution
862 863 864 865 866 |
# File 'lib/gs2crmod/gsl_data.rb', line 862 def vres_pitch_angle_gsl_vector() raise "Velocity space vres diagnostics not found" unless FileTest.exist? "#@directory/#@run_name.vres" vres = GSL::Vector.filescan("#@directory/#@run_name.vres") return vres[1] end |
#x_gsl_vector(options) ⇒ Object
936 937 938 939 940 941 942 943 |
# File 'lib/gs2crmod/gsl_data.rb', line 936 def x_gsl_vector() raise "options nakx and interpolate_x are incompatible" if [:nakx] and [:interpolate_x] kx = gsl_vector(:kx, ) lx = 2*Math::PI/kx.to_box_order[1] #ep 'lx', lx nx = [:nakx]||kx.size GSL::Vector.indgen(nx, 0, lx/nx) end |
#y_gsl_vector(options) ⇒ Object
944 945 946 947 948 949 950 951 |
# File 'lib/gs2crmod/gsl_data.rb', line 944 def y_gsl_vector() raise "options naky and interpolate_y are incompatible" if [:naky] and [:interpolate_y] ky = gsl_vector(:ky, ) ly = 2*Math::PI/ky[1] ny = [:naky]||ky.size ysize = ny*2-2+ny%2 GSL::Vector.indgen(ysize, 0, ly/ysize) end |
#zonal_spectrum_gsl_vector(options) ⇒ Object
952 953 954 955 956 957 958 959 960 961 962 963 964 965 |
# File 'lib/gs2crmod/gsl_data.rb', line 952 def zonal_spectrum_gsl_vector() Dir.chdir(@directory) do gmzf = gsl_matrix('spectrum_over_ky_over_kx',) veczf = GSL::Vector.alloc(gmzf.shape[1]) # p gmzf.get_row(0).size # p gmzf.get_row(0) gmzf.shape[1].times{|i| veczf[i] = gmzf[0,i]} return veczf #else #raise CRError.new("Unknown gsl_vector requested: #{name}") end # eputs data; gets end |