gs2crmod 0.12.9 → 0.12.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -1
- data/VERSION +1 -1
- data/gs2crmod.gemspec +5 -7
- data/lib/gs2crmod/calculations.rb +94 -131
- data/lib/gs2crmod/graphs.rb +2332 -2342
- data/lib/gs2crmod/gs2.rb +31 -40
- data/lib/gs2crmod/gsl_data.rb +320 -326
- metadata +40 -22
- checksums.yaml +0 -7
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.
|
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.
|
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-
|
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 = "
|
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 =
|
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
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
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
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
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
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
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
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
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 /
|