gs2crmod 0.12.9 → 0.12.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,4 +1,16 @@
1
1
  gs2crmod
2
2
  ========
3
3
 
4
- GS2 is a gyrokinetic flux tube initial value turbulence code which can be used for fusion or astrophysical plasmas. CodeRunner is a framework for the automated running and analysis of large simulations. This module allows GS2 (and its sister code AstroGK) to harness the power of the CodeRunner framework.
4
+ GS2 is a gyrokinetic flux tube initial value turbulence code which can be used for fusion or astrophysical plasmas. CodeRunner is a framework for the automated running and analysis of large simulations. This module allows GS2 (and its sister code AstroGK) to harness the power of the CodeRunner framework.
5
+
6
+ Coding Style Guide
7
+ ==================
8
+
9
+ These bullet points are taken from here: https://github.com/bbatsov/ruby-style-guide
10
+
11
+ * Indentation is strictly two spaces, i.e. not tabs.
12
+ * Where possible do not exceed 80 columns. This makes the code much more readable.
13
+ * Do not sign your initials when contributing code, this is what revision control is for.
14
+ * Avoid unnecessary comments or inline comments, try to write code which is self documenting or have a short comment preceding your code.
15
+ * Do not use the ';' character to write several statements on one line.
16
+ * If in doubt refer to the style guide.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.12.9
1
+ 0.12.10
data/gs2crmod.gemspec CHANGED
@@ -2,17 +2,14 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: gs2crmod 0.12.9 ruby lib
6
- # stub: ext/extconf.rb
7
5
 
8
6
  Gem::Specification.new do |s|
9
7
  s.name = "gs2crmod"
10
- s.version = "0.12.9"
8
+ s.version = "0.12.10"
11
9
 
12
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
- s.require_paths = ["lib"]
14
11
  s.authors = ["Edmund Highcock", "Ferdinand van Wyk"]
15
- s.date = "2015-08-28"
12
+ s.date = "2015-09-15"
16
13
  s.description = "GS2 is a gyrokinetic flux tube initial value turbulence code which can be used for fusion or astrophysical plasmas. CodeRunner is a framework for the automated running and analysis of large simulations. This module allows GS2 (and its sister code AstroGK) to harness the power of the CodeRunner framework."
17
14
  s.email = "edmundhighcock@sourceforge.net"
18
15
  s.extensions = ["ext/extconf.rb"]
@@ -79,12 +76,13 @@ Gem::Specification.new do |s|
79
76
  ]
80
77
  s.homepage = "http://gs2crmod.sourceforge.net"
81
78
  s.licenses = ["GSLv3"]
79
+ s.require_paths = ["lib"]
82
80
  s.required_ruby_version = Gem::Requirement.new(">= 1.9.1")
83
- s.rubygems_version = "2.2.2"
81
+ s.rubygems_version = "1.8.23"
84
82
  s.summary = "Module to allow CodeRunner to run and analyse the GS2 and AstroGK codes."
85
83
 
86
84
  if s.respond_to? :specification_version then
87
- s.specification_version = 4
85
+ s.specification_version = 3
88
86
 
89
87
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
90
88
  s.add_runtime_dependency(%q<coderunner>, [">= 0.15.5"])
@@ -10,12 +10,9 @@
10
10
  #
11
11
  ##########################################
12
12
 
13
-
14
13
  class CodeRunner
15
14
  class Gs2
16
15
 
17
-
18
-
19
16
  def calculate_time_averaged_fluxes
20
17
  eputs 'Calculating time averaged fluxes'
21
18
  calculate_saturation_time_index unless @saturation_time_index
@@ -124,7 +121,6 @@ def saturated_time_average_std_dev(name, options)
124
121
  return vec.sd
125
122
  end
126
123
 
127
-
128
124
  # I.e. the time at which the primary modes are saturated and the fluxes settle around a long term average.
129
125
 
130
126
  def calculate_saturation_time_index(show_graph = false)
@@ -274,127 +270,98 @@ end
274
270
 
275
271
  alias :csti :calculate_saturation_time_index
276
272
 
277
- #Actually, this doesn't calculate the frequencies but reads them from run_name.out. Requires write_line to be .true.
278
- #
279
273
  def calculate_frequencies
280
- @real_frequencies = FloatHash.new
281
- gs2_out = FileUtils.tail(@run_name + ".out", list(:ky).size*list(:kx).size)
282
- # a = gs2_out.split("\n")
283
- final_timestep_list = gs2_out #a.slice((a.size-@ky_list.size*@kx_list.size-1)..a.size-1).join("\n")
284
- log(final_timestep_list.slice(-2..-1))
285
- # eputs final_timestep_list
286
- f = LongRegexen::FLOAT.verbatim
287
- logi(f)
288
- @frequency_at_ky_at_kx||= FloatHash.new
289
- ky_values = []
290
- regex = Regexp.new( "^.*ky=\\s*(?<aky>#{f})\s*kx=\\s*(?<akx>#{f}).*omav=\\s*(?<re>#{f})\\s*(?<gr>#{f})")
291
- final_timestep_list.scan(regex) do
292
- aky = eval($~[:aky])
293
- akx = eval($~[:akx])
294
- @frequency_at_ky_at_kx[aky] = FloatHash.new unless ky_values.include? aky
295
- ky_values.push aky
296
- @frequency_at_ky_at_kx[aky][akx] = eval($~[:re])
297
- end
274
+ @real_frequencies = FloatHash.new
275
+ omega_avg_narray = netcdf_file.var("omega_average").get('start' => [0, 0, 0, -1],
276
+ 'end' => [0, -1, -1, -1])
277
+ omega_avg_narray.reshape!(*omega_avg_narray.shape.slice(1..2))
278
+
279
+ list(:ky).values.sort.each_with_index do |kyv, i|
280
+ @frequency_at_ky_at_kx[kyv] = FloatHash.new
281
+ list(:kx).values.sort.each_with_index do |kxv, j|
282
+ @frequency_at_ky_at_kx[kyv][kxv] = omega_avg_narray[i, j]
283
+ end
284
+ write_results
285
+ end
298
286
  end
299
- def calculate_growth_rates_and_frequencies
300
- return if @grid_option == "single" and @aky == 0.0 # no meaningful results
301
- Dir.chdir(@directory) do
302
- logf(:calculate_growth_rates_and_frequencies)
303
- logd
304
287
 
305
- calculate_frequencies
306
-
307
- # get_list_of(:ky, :kx)
308
- @growth_rates= FloatHash.new
309
- #raise CRFatal.new("Unknown value of ky read from output file: #{data[:aky].to_f}. Not in list:\n#{list(:ky).values.inspect}")
310
- # pp @ky_list
311
-
312
- # With zero magnetic shear, calculate growth rates for both kx and ky
313
- #if @shat and @shat.abs < 1.0e-5 and @nx and @nx > 1
314
- to_calc = [:kx, :ky]
315
- @growth_rate_at_kx ||= FloatHash.new
316
- #else
317
- #to_calc = [:ky]
318
- #end
319
-
320
- @growth_rate_at_ky ||= FloatHash.new
321
- eputs
322
- # p @growth_rate_at_kx; exit
323
- to_calc.each do |kxy|
324
- growth_rates = send(:growth_rate_at_ + kxy)
325
- list(kxy).values.sort.each do |value|
326
-
327
- #p growth_rates.keys, value, growth_rates[value.to_f-0.0],
328
- #growth_rates.class, growth_rates.keys.include?(value); exit
329
-
330
- next if growth_rates.keys.include? value
331
-
332
-
333
- Terminal.erewind(1)
334
- #ep growth_rates.keys
335
- eputs sprintf("Calculating growth rate for #{kxy} = % 1.5e#{Terminal::CLEAR_LINE}", value)
336
-
337
-
338
- # Mode has 0 growth rate at ky==0
339
- (growth_rates[value] = 0.0; next) if value == 0.0 and kxy == :ky
340
- if @g_exb_start_timestep
341
- t_index_window = [1, [(g_exb_start_timestep-1)/@nwrite, list(:t).keys.max].min]
342
- #ep "t_index_window", t_index_window
343
- else
344
- t_index_window = nil
345
- end
346
- if list(kxy).size == 1
347
- phi2_vec = gsl_vector("phi2tot_over_time", t_index_window: t_index_window)
348
- else
349
- phi2_vec = gsl_vector("phi2_by_#{kxy}_over_time", kxy=>value, :t_index_window=> t_index_window)
350
- end
351
- (growth_rates[value] = 0.0; next) if phi2_vec.min <= 0.0
352
- growth_rates[value] = calculate_growth_rate(phi2_vec)
353
- (eputs "\n\n----------\nIn #@run_name:\n\nphi2_by_#{kxy}_over_time is all NaN; unable to calculate growth rate\n----------\n\n"; growth_rates[value] = -1; next) if growth_rates[value] == "NaN"
354
- end
355
- end
356
-
357
- write_results
358
-
359
- # ep "growth_rate_at_ky", @growth_rate_at_ky
360
- if ENV['GS2_CALCULATE_ALL']
361
- trap(0){eputs "Calculation of spectrum did not complete: run 'cgrf' (i.e. calculate_growth_rates_and_frequencies) for this run. E.g. from the command line \n $ coderunner rc 'cgrf' -j #{@id}"; exit}
362
- @growth_rate_at_ky_at_kx ||= FloatHash.new
363
- list(:ky).values.sort.each do |kyv|
364
- # MJL 2013-11-07: The line below originally used ||= instead of =. I'm not sure why, since ||= does not seem to work.
365
- @growth_rate_at_ky_at_kx[kyv] = FloatHash.new
366
- list(:kx).values.sort.each do |kxv|
367
- # MJL 2013-11-07: I'm not sure why this next line was originally included. It seemed to cause almost all k's to be skipped.
368
- #next if @growth_rate_at_ky_at_kx[kyv].keys.include? kxv
369
- Terminal.erewind(1)
370
- eputs sprintf("Calculating growth rate for kx = % 1.5e and ky = % 1.5e#{Terminal::CLEAR_LINE}", kxv, kyv)
371
- (@growth_rate_at_ky_at_kx[kyv][kxv] = 0.0; next) if kyv == 0.0 # Mode has 0 growth rate at ky==0
372
- phi2_vec = gsl_vector("phi2_by_mode_over_time", {:kx=>kxv, :ky=>kyv})
373
- (@growth_rate_at_ky_at_kx[kyv][kxv] = 0.0; next) if phi2_vec.min <= 0.0
374
- @growth_rate_at_ky_at_kx[kyv][kxv] = calculate_growth_rate(phi2_vec)
375
- (eputs "\n\n----------\nIn #@run_name:\n\nphi2_by_#{kxy}_over_time is all NaN; unable to calculate growth rates\n----------\n\n"; @growth_rate_at_ky_at_kx[kyv][kxv] = -1; next) if @growth_rate_at_ky_at_kx[kyv][kxv] == "NaN"
376
- end
377
- write_results
378
- end
379
- trap(0){}
380
- end
381
- @growth_rates = @growth_rate_at_ky
382
- @max_growth_rate = @growth_rates.values.max
383
- @fastest_growing_mode = @growth_rates.key(@max_growth_rate)
384
- @freq_of_max_growth_rate = @real_frequencies[@fastest_growing_mode] rescue nil
385
- ep @max_growth_rate, @growth_rates
386
- @decaying = (@max_growth_rate < 0) if @max_growth_rate
387
- @ky = @aky if @aky
388
- if @grid_option == "single"
389
- # ep @aky, @growth_rates
390
- @gamma_r = @growth_rates[@aky.to_f]
391
- @gamma_i = @real_frequencies[@aky.to_f]
392
- end
393
- # ep @gamma_r
394
-
395
-
396
- # eputs @growth_rates; gets
397
- end
288
+ def calculate_growth_rates_and_frequencies
289
+ return if @grid_option == "single" and @aky == 0.0 # no meaningful results
290
+
291
+ Dir.chdir(@directory) do
292
+ logf(:calculate_growth_rates_and_frequencies)
293
+ logd
294
+
295
+ calculate_frequencies
296
+
297
+ @growth_rates= FloatHash.new
298
+
299
+ # With zero magnetic shear, calculate growth rates for both kx and ky
300
+ to_calc = [:kx, :ky]
301
+ @growth_rate_at_kx ||= FloatHash.new
302
+
303
+ @growth_rate_at_ky ||= FloatHash.new
304
+ eputs
305
+ to_calc.each do |kxy|
306
+ growth_rates = send(:growth_rate_at_ + kxy)
307
+ list(kxy).values.sort.each do |value|
308
+
309
+ next if growth_rates.keys.include? value
310
+
311
+ Terminal.erewind(1)
312
+ #ep growth_rates.keys
313
+ eputs sprintf("Calculating growth rate for #{kxy} = % 1.5e#{Terminal::CLEAR_LINE}", value)
314
+
315
+ # Mode has 0 growth rate at ky==0
316
+ (growth_rates[value] = 0.0; next) if value == 0.0 and kxy == :ky
317
+ if @g_exb_start_timestep
318
+ t_index_window = [1, [(g_exb_start_timestep-1)/@nwrite, list(:t).keys.max].min]
319
+ else
320
+ t_index_window = nil
321
+ end
322
+ if list(kxy).size == 1
323
+ phi2_vec = gsl_vector("phi2tot_over_time", t_index_window: t_index_window)
324
+ else
325
+ phi2_vec = gsl_vector("phi2_by_#{kxy}_over_time", kxy=>value, :t_index_window=> t_index_window)
326
+ end
327
+ (growth_rates[value] = 0.0; next) if phi2_vec.min <= 0.0
328
+ growth_rates[value] = calculate_growth_rate(phi2_vec)
329
+ (eputs "\n\n----------\nIn #@run_name:\n\nphi2_by_#{kxy}_over_time is all NaN; unable to calculate growth rate\n----------\n\n"; growth_rates[value] = -1; next) if growth_rates[value] == "NaN"
330
+ end
331
+ end
332
+
333
+ write_results
334
+
335
+ if ENV['GS2_CALCULATE_ALL']
336
+ trap(0){eputs "Calculation of spectrum did not complete: run 'cgrf' (i.e. calculate_growth_rates_and_frequencies) for this run. E.g. from the command line \n $ coderunner rc 'cgrf' -j #{@id}"; exit}
337
+ @growth_rate_at_ky_at_kx ||= FloatHash.new
338
+ list(:ky).values.sort.each do |kyv|
339
+ @growth_rate_at_ky_at_kx[kyv] = FloatHash.new
340
+ list(:kx).values.sort.each do |kxv|
341
+ Terminal.erewind(1)
342
+ eputs sprintf("Calculating growth rate for kx = % 1.5e and ky = % 1.5e#{Terminal::CLEAR_LINE}", kxv, kyv)
343
+ (@growth_rate_at_ky_at_kx[kyv][kxv] = 0.0; next) if kyv == 0.0 # Mode has 0 growth rate at ky==0
344
+ phi2_vec = gsl_vector("phi2_by_mode_over_time", {:kx=>kxv, :ky=>kyv})
345
+ (@growth_rate_at_ky_at_kx[kyv][kxv] = 0.0; next) if phi2_vec.min <= 0.0
346
+ @growth_rate_at_ky_at_kx[kyv][kxv] = calculate_growth_rate(phi2_vec)
347
+ (eputs "\n\n----------\nIn #@run_name:\n\nphi2_by_#{kxy}_over_time is all NaN; unable to calculate growth rates\n----------\n\n"; @growth_rate_at_ky_at_kx[kyv][kxv] = -1; next) if @growth_rate_at_ky_at_kx[kyv][kxv] == "NaN"
348
+ end
349
+ write_results
350
+ end
351
+ trap(0){}
352
+ end
353
+ @growth_rates = @growth_rate_at_ky
354
+ @max_growth_rate = @growth_rates.values.max
355
+ @fastest_growing_mode = @growth_rates.key(@max_growth_rate)
356
+ @freq_of_max_growth_rate = @real_frequencies[@fastest_growing_mode] rescue nil
357
+ ep @max_growth_rate, @growth_rates
358
+ @decaying = (@max_growth_rate < 0) if @max_growth_rate
359
+ @ky = @aky if @aky
360
+ if @grid_option == "single"
361
+ @gamma_r = @growth_rates[@aky.to_f]
362
+ @gamma_i = @real_frequencies[@aky.to_f]
363
+ end
364
+ end
398
365
  end
399
366
 
400
367
  alias :cgrf :calculate_growth_rates_and_frequencies
@@ -410,18 +377,16 @@ def calculate_growth_rate(vector, options={})
410
377
  growth_rate = GSL::Fit::linear(gsl_vector(:t).subvector(offset, length-offset), 0.5*GSL::Sf::log(vector.subvector(offset, length - offset)))[1]
411
378
  divisor = 1
412
379
  while (growth_rate.to_s == "NaN")
413
- #This corrects the growth rate if phi has grown all the way to NaN during the simulation
414
- divisor *= 2
415
- length = (vector.size.to_f / divisor.to_f).floor
416
- # p length
417
- return "NaN" if length <= offset + 1
418
- growth_rate = GSL::Fit::linear(gsl_vector(:t).subvector(offset, length-offset), 0.5*GSL::Sf::log(vector.subvector(offset, length-offset)))[1]
380
+ #This corrects the growth rate if phi has grown all the way to NaN during the simulation
381
+ divisor *= 2
382
+ length = (vector.size.to_f / divisor.to_f).floor
383
+ return "NaN" if length <= offset + 1
384
+ growth_rate = GSL::Fit::linear(gsl_vector(:t).subvector(offset, length-offset), 0.5*GSL::Sf::log(vector.subvector(offset, length-offset)))[1]
419
385
  end
420
386
  growth_rate
421
387
  end
422
388
 
423
389
  # Not needed for GS2 built after 16/06/2010
424
-
425
390
  def corrected_mom_flux_stav
426
391
  par_mom_flux_stav - perp_mom_flux_stav
427
392
  end
@@ -493,7 +458,6 @@ end
493
458
 
494
459
  alias :cta :calculate_transient_amplifications
495
460
 
496
-
497
461
  def calculate_transient_es_heat_flux_amplifications
498
462
  return if @grid_option == "single" and @aky == 0.0 # no meaningful results
499
463
 
@@ -664,7 +628,6 @@ end
664
628
  alias :ctehfa :calculate_transient_es_heat_flux_amplifications
665
629
  alias :ctehfa :calculate_transient_es_heat_flux_amplifications
666
630
 
667
-
668
631
  def calculate_transient_amplification(vector, options={})
669
632
  if @g_exb and @g_exb > 0.0 and @g_exb_start_timestep
670
633
  return GSL::Sf::log(vector[(@g_exb_start_timestep/@nwrite).to_i...-1].max /