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_over_kx_gsl_vector(options) ⇒ Object
-
#es_heat_over_kxy_gsl_vector(options) ⇒ Object
This function will output the heat flux as a function of kx or ky.
- #es_heat_over_ky_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
- #es_part_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.
-
#grho_gsl_vector(options) ⇒ Object
This function reads in the ‘grho’ variable from the netcdf file.
-
#growth_rate_by_kx_over_time_gsl_vector(options) ⇒ Object
The growth rate of the fluctuations, calculated from the potential, indexed by time and normalised to vth_1/a.
- #growth_rate_by_kxy_over_time_gsl_vector(options) ⇒ Object
-
#growth_rate_by_ky_over_time_gsl_vector(options) ⇒ Object
The growth rate of the fluctuations, calculated from the potential, indexed by time and normalised to vth_1/a.
-
#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.
-
#mean_flow_velocity_over_x_gsl_vector(options) ⇒ Object
This function returns the mean flow velocity as a function of x (the radial coordinate).
- #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_avg_gsl_vector(options) ⇒ Object
- #spectrum_over_kx_gsl_vector(options) ⇒ Object
-
#spectrum_over_kxy_avg_gsl_vector(options) ⇒ Object
spectrum averaged in time.
- #spectrum_over_kxy_gsl_vector(options) ⇒ Object
- #spectrum_over_ky_avg_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
-
#zf_velocity_over_x_gsl_vector(options) ⇒ Object
This function returns the zonal flow velocity as a function of x (the radial coordinate).
- #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
850 851 852 853 854 855 856 |
# File 'lib/gs2crmod/gsl_data.rb', line 850 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_over_kx_gsl_vector(options) ⇒ Object
452 453 454 455 |
# File 'lib/gs2crmod/gsl_data.rb', line 452 def es_heat_over_kx_gsl_vector() [:direction] = :kx es_heat_over_kxy_gsl_vector() end |
#es_heat_over_kxy_gsl_vector(options) ⇒ Object
This function will output the heat flux as a function of kx or ky. Default behaviour will be to average the heat flux over the time domain.
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'lib/gs2crmod/gsl_data.rb', line 463 def es_heat_over_kxy_gsl_vector() Dir.chdir(@directory) do kxy = [:direction] raise "Please provide species_index " unless [:species_index] if kxy==:ky es_heat = (netcdf_file.var('es_heat_by_k').get({'start' => [0,0,[:species_index]-1, 0], 'end' => [-1,-1,[:species_index]-1, -1]})) #index = [kx,ky,spec,t] #Need to average over time and sum over kx shape = es_heat.shape es_heat_av = []; temp = []; for iy in 0...shape[1] for ix in 0...shape[0] temp[ix] = es_heat[ix,iy,0,0..-1].sum / shape[3] end es_heat_av[iy] = temp.sum end return es_heat_av.to_gslv else es_heat = (netcdf_file.var('es_heat_by_k').get({'start' => [0,0,[:species_index]-1, 0], 'end' => [-1,-1,[:species_index]-1, -1]})) #index = [kx,ky,spec,t] shape = es_heat.shape es_heat_av = []; temp = []; for ix in 0...shape[0] for iy in 0...shape[1] temp[iy] = es_heat[ix,iy,0,0..-1].sum / shape[3] end es_heat_av[ix] = temp.sum end return es_heat_av.to_gslv.from_box_order end end end |
#es_heat_over_ky_gsl_vector(options) ⇒ Object
456 457 458 459 |
# File 'lib/gs2crmod/gsl_data.rb', line 456 def es_heat_over_ky_gsl_vector() [:direction] = :ky es_heat_over_kxy_gsl_vector() end |
#es_heat_par_over_time_gsl_vector(options) ⇒ Object Also known as: es_heat_par_gsl_vector
857 858 859 860 861 862 863 |
# File 'lib/gs2crmod/gsl_data.rb', line 857 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
865 866 867 868 869 870 871 |
# File 'lib/gs2crmod/gsl_data.rb', line 865 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
880 881 882 883 884 885 |
# File 'lib/gs2crmod/gsl_data.rb', line 880 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 |
#es_part_flux_over_time_gsl_vector(options) ⇒ Object
886 887 888 889 890 891 |
# File 'lib/gs2crmod/gsl_data.rb', line 886 def es_part_flux_over_time_gsl_vector() Dir.chdir(@directory) do .setup_time_window return GSL::Vector.alloc(netcdf_file.var('es_part_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 |
#grho_gsl_vector(options) ⇒ Object
This function reads in the ‘grho’ variable from the netcdf file.
1033 1034 1035 1036 |
# File 'lib/gs2crmod/gsl_data.rb', line 1033 def grho_gsl_vector() grho = GSL::Vector.alloc(netcdf_file.var('grho').get('start' => [0], 'end' => [-1]).to_a) return grho end |
#growth_rate_by_kx_over_time_gsl_vector(options) ⇒ Object
The growth rate of the fluctuations, calculated from the potential, indexed by time and normalised to vth_1/a. :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
The growth rate of the fluctuations, calculated from the potential, indexed by time and normalised to vth_1/a. :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
839 840 841 842 843 844 845 846 847 848 |
# File 'lib/gs2crmod/gsl_data.rb', line 839 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
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 |
# File 'lib/gs2crmod/gsl_data.rb', line 710 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
618 619 620 621 622 623 624 625 626 627 628 629 630 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 669 670 |
# File 'lib/gs2crmod/gsl_data.rb', line 618 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
901 902 903 904 905 |
# File 'lib/gs2crmod/gsl_data.rb', line 901 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
894 895 896 897 898 |
# File 'lib/gs2crmod/gsl_data.rb', line 894 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 |
#mean_flow_velocity_over_x_gsl_vector(options) ⇒ Object
This function returns the mean flow velocity as a function of x (the radial coordinate). This is v_g_exb = (x - x(centre))*g_exb. The x-x(centre) ensures that the flow is zero at the middle of the box.
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 |
# File 'lib/gs2crmod/gsl_data.rb', line 1076 def mean_flow_velocity_over_x_gsl_vector() Dir.chdir(@directory) do raise CRFatal.new("Need to have g_exb > 0 to have a mean flow.") unless @g_exb x = gsl_vector(:x) vec_exb_vel = GSL::Vector.alloc(x.size) #Take imaginary part since i k_x will lead to imaginary part being real vec_exb_vel = (x - x[x.size/2])*@g_exb return vec_exb_vel end end |
#par_mom_flux_over_time_gsl_vector(options) ⇒ Object
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 |
# File 'lib/gs2crmod/gsl_data.rb', line 920 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
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 |
# File 'lib/gs2crmod/gsl_data.rb', line 936 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
609 610 611 612 613 614 615 616 |
# File 'lib/gs2crmod/gsl_data.rb', line 609 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
493 494 495 496 |
# File 'lib/gs2crmod/gsl_data.rb', line 493 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
497 498 499 500 |
# File 'lib/gs2crmod/gsl_data.rb', line 497 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
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/gs2crmod/gsl_data.rb', line 537 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
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 |
# File 'lib/gs2crmod/gsl_data.rb', line 735 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
828 829 830 831 832 833 834 835 836 837 |
# File 'lib/gs2crmod/gsl_data.rb', line 828 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
952 953 954 |
# File 'lib/gs2crmod/gsl_data.rb', line 952 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
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
# File 'lib/gs2crmod/gsl_data.rb', line 672 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_avg_gsl_vector(options) ⇒ Object
960 961 962 963 |
# File 'lib/gs2crmod/gsl_data.rb', line 960 def spectrum_over_kx_avg_gsl_vector() [:direction] = :kx spectrum_over_kxy_avg_gsl_vector() end |
#spectrum_over_kx_gsl_vector(options) ⇒ Object
955 956 957 958 |
# File 'lib/gs2crmod/gsl_data.rb', line 955 def spectrum_over_kx_gsl_vector() [:direction] = :kx spectrum_over_kxy_gsl_vector() end |
#spectrum_over_kxy_avg_gsl_vector(options) ⇒ Object
spectrum averaged in time
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 |
# File 'lib/gs2crmod/gsl_data.rb', line 993 def spectrum_over_kxy_avg_gsl_vector() Dir.chdir(@directory) do # i.e. spectrum_over_ky or spectrum_over_kx kxy = [:direction] raise "Spectrum makes no sense for single modes" if @grid_option == "single" phi_array = netcdf_file.var("phi2_by_#{kxy}").get('start' => [0, 0], 'end' => [-1, -1]) #index = [kx or ky, t] shape = phi_array.shape phi_av = []; #average over time for each kx or ky individually for i in 0...shape[0] phi_av[i] = phi_array[i,0..-1].sum / shape[1] end v = GSL::Vector.alloc(phi_av) v = v.from_box_order if kxy == :kx v = v.mul(gsl_vector(kxy).square) unless [:phi2_only] return v end end |
#spectrum_over_kxy_gsl_vector(options) ⇒ Object
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 |
# File 'lib/gs2crmod/gsl_data.rb', line 972 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_avg_gsl_vector(options) ⇒ Object
968 969 970 971 |
# File 'lib/gs2crmod/gsl_data.rb', line 968 def spectrum_over_ky_avg_gsl_vector() [:direction] = :ky spectrum_over_kxy_avg_gsl_vector() end |
#spectrum_over_ky_gsl_vector(options) ⇒ Object
964 965 966 967 |
# File 'lib/gs2crmod/gsl_data.rb', line 964 def spectrum_over_ky_gsl_vector() [:direction] = :ky spectrum_over_kxy_gsl_vector() end |
#theta_along_field_line_gsl_vector(options) ⇒ Object
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 |
# File 'lib/gs2crmod/gsl_data.rb', line 764 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
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
# File 'lib/gs2crmod/gsl_data.rb', line 561 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
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/gs2crmod/gsl_data.rb', line 585 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
915 916 917 918 919 |
# File 'lib/gs2crmod/gsl_data.rb', line 915 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
908 909 910 911 912 |
# File 'lib/gs2crmod/gsl_data.rb', line 908 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
1015 1016 1017 1018 1019 1020 1021 1022 |
# File 'lib/gs2crmod/gsl_data.rb', line 1015 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
1023 1024 1025 1026 1027 1028 1029 1030 |
# File 'lib/gs2crmod/gsl_data.rb', line 1023 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 |
#zf_velocity_over_x_gsl_vector(options) ⇒ Object
This function returns the zonal flow velocity as a function of x (the radial coordinate). This is v_ZF = kxfac*IFT(i k_x phi_imag), where kxfac = (qinp/rhoc)*grho(rhoc).
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 |
# File 'lib/gs2crmod/gsl_data.rb', line 1040 def zf_velocity_over_x_gsl_vector() Dir.chdir(@directory) do raise CRFatal.new("Need to specify a theta_index.") unless [:theta_index] raise CRFatal.new("Need either qinp or pk and epsl specified in order to calculate kxfac. If using numerical equil use the option :kxfac to override calculation.") unless @qinp or (@pk and @epsl or [:kxfac]) kx = gsl_vector(:kx).to_box_order grho = gsl_vector('grho')[[:theta_index]] phi = GSL::Vector.alloc(kx.size) for it in 0...gsl_vector(:t).size [:t_index] = it phi += gsl_vector_complex('phi_zonal', ) end phi /= gsl_vector(:t).size if @qinp kxfac = (@qinp/@rhoc)*grho elsif @pk and @epsl kxfac = (@epsl/@pk)*grho elsif [:kxfac] kxfac = [:kxfac] else raise 'Error: Need qinp or pk and epsl to calculate kxfac' end vec_zf_vel = GSL::Vector.alloc(kx.size) #Take imaginary part since i k_x will lead to imaginary part being real vec_zf_vel = kxfac*(phi*kx).backward.imag return vec_zf_vel end end |
#zonal_spectrum_gsl_vector(options) ⇒ Object
1088 1089 1090 1091 1092 1093 1094 1095 |
# File 'lib/gs2crmod/gsl_data.rb', line 1088 def zonal_spectrum_gsl_vector() Dir.chdir(@directory) do gmzf = gsl_matrix('spectrum_over_ky_over_kx',) veczf = GSL::Vector.alloc(gmzf.shape[1]) gmzf.shape[1].times{|i| veczf[i] = gmzf[0,i]} return veczf end end |