gs2crmod 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/README.rdoc +19 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/ext/extconf.rb +9 -0
- data/ext/gs2crmod_ext.c +366 -0
- data/gs2crmod.gemspec +98 -0
- data/include/gs2crmod_ext.h +58 -0
- data/lib/gs2crmod/astrogk/astrogk.rb +201 -0
- data/lib/gs2crmod/astrogk/calculations.rb +57 -0
- data/lib/gs2crmod/astrogk/check_convergence.rb +7 -0
- data/lib/gs2crmod/astrogk/deleted_variables.rb +76 -0
- data/lib/gs2crmod/astrogk/graphs.rb +13 -0
- data/lib/gs2crmod/astrogk/gsl_data.rb +13 -0
- data/lib/gs2crmod/astrogk/gsl_tools.rb +182 -0
- data/lib/gs2crmod/astrogk/ingen.rb +18 -0
- data/lib/gs2crmod/astrogk/input_file_tools.rb +7 -0
- data/lib/gs2crmod/astrogk/namelist_tools.rb +14 -0
- data/lib/gs2crmod/astrogk/namelists.rb +2800 -0
- data/lib/gs2crmod/astrogk/properties.rb +17 -0
- data/lib/gs2crmod/astrogk/species_dependent_namelists.rb +228 -0
- data/lib/gs2crmod/astrogk/test_gs2.rb +231 -0
- data/lib/gs2crmod/astrogk.rb +200 -0
- data/lib/gs2crmod/calculations.rb +780 -0
- data/lib/gs2crmod/check_convergence.rb +179 -0
- data/lib/gs2crmod/deleted_variables.rb +916 -0
- data/lib/gs2crmod/graphs.rb +1899 -0
- data/lib/gs2crmod/graphs_rdoc.rb +556 -0
- data/lib/gs2crmod/gs2.rb +1143 -0
- data/lib/gs2crmod/gsl_data.rb +1181 -0
- data/lib/gs2crmod/gsl_data_3d.rb +705 -0
- data/lib/gs2crmod/gsl_tools.rb +187 -0
- data/lib/gs2crmod/ingen.rb +218 -0
- data/lib/gs2crmod/namelists.rb +5142 -0
- data/lib/gs2crmod/properties.rb +22 -0
- data/lib/gs2crmod/species_dependent_namelists.rb +228 -0
- data/lib/gs2crmod/test_gs2.rb +231 -0
- data/lib/gs2crmod.rb +2 -0
- data/lib/gs2crmod_extension.rb +1 -0
- data/test/helper.rb +18 -0
- data/test/test_gs2crmod.rb +7 -0
- metadata +176 -0
@@ -0,0 +1,201 @@
|
|
1
|
+
##########################################
|
2
|
+
# = Code Runner GS2 Module
|
3
|
+
##########################################
|
4
|
+
#
|
5
|
+
# Authors: Edmund Highcock
|
6
|
+
# Copyright: 2009 Edmund Highcock
|
7
|
+
#
|
8
|
+
# This is free software released under the GPL v3
|
9
|
+
#
|
10
|
+
# This module allows easy running of the plasma turbulence simulation code gs2 using Code Runner, by automatically organising, naming and submitting runs, and analysing the run data.
|
11
|
+
#
|
12
|
+
# See Code Runner documentation, or documentation for individual methods.
|
13
|
+
#
|
14
|
+
# Notes
|
15
|
+
#
|
16
|
+
# index variables, e.g. kx_index, ky_index etc always refer to the 1-based Fortran index, to keep correspondance with the gs2 indices. Element variables, e.g. kx_element, always refer to the 0-based C/ruby index
|
17
|
+
#
|
18
|
+
# raw NumRu::NetCDF grids are in Fortran row-major order. This means that when you access grids using the NetCDF function NetCDF#get, you must specify the indices in fortran order (but 0-based!). The NetCDF#get function then returns a C-like NArray with the indices in the opposite order. You can convert this to a Ruby Array using the method NArray#to_a (the indices will still be in the same order).
|
19
|
+
|
20
|
+
|
21
|
+
#
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
class CodeRunner
|
26
|
+
|
27
|
+
|
28
|
+
#CodeRunner.setup_run_class('g2') # Astrogk Inherits from GS2
|
29
|
+
|
30
|
+
# This is a customised subclass of CodeRunner::Run which allows CodeRunner to submit and analyse simulations from the gyrokinetic flux tube code GS2, which is principally used for simulating plasmas in magnetic confinement fusion.
|
31
|
+
#
|
32
|
+
# It performs two distinct roles: submitting simulations and analysing the data.
|
33
|
+
#
|
34
|
+
# = Submitting Simulations
|
35
|
+
#
|
36
|
+
# This principally involves generating the input file, which is a very nontrivial task. In order to do this, it maintains a complete record of every possible input parameter for GS2, as well as what datatype that parameter is, and sometimes what values it is allowed to take. This allows that not only to generate the input file, but to check that the input file makes sense. However, although generating the input file works beautifully, the set of sanity checks that it makes is not exhaustive: intelligent use is still required!
|
37
|
+
#
|
38
|
+
# In tandem with this, it maintains a whole set of tools for manipulating its database of input parameters. This includes updating their allowed values and also editing and accessing help for every input parameter.
|
39
|
+
#
|
40
|
+
# = Analysing Simulations
|
41
|
+
#
|
42
|
+
# The amount of analysis possible on GS2 data is enormous, and CodeRunner hasn't got close to getting there. What it can do is:
|
43
|
+
#
|
44
|
+
# * Check if the run is complete by comparing the number of completed timesteps against nstep
|
45
|
+
# * Calculate growth rates for linear runs.
|
46
|
+
# * Check if non-linear runs have saturated and calculate fluxes for those runs.
|
47
|
+
# * Automatically plot a huge variety of different graphs, ranging from simple plots of heat flux versus time to three-dimensional plots of the spectrum and potential.
|
48
|
+
|
49
|
+
|
50
|
+
CodeRunner.setup_run_class('gs2')
|
51
|
+
class Gs2::Astrogk < Gs2
|
52
|
+
|
53
|
+
ASTROGK_CRMOD_VERSION = Version.new('0.3.0')
|
54
|
+
|
55
|
+
|
56
|
+
def agk?
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
# Include the other files
|
61
|
+
@code_module_folder = folder = File.dirname(File.expand_path(__FILE__)) # i.e. the directory this file is in
|
62
|
+
setup_namelists(folder)
|
63
|
+
require folder + '/graphs.rb'
|
64
|
+
# require folder + '/namelist_tools.rb'
|
65
|
+
# require folder + '/input_file_tools.rb'
|
66
|
+
require folder + '/gsl_data.rb'
|
67
|
+
require folder + '/check_convergence.rb'
|
68
|
+
require folder + '/calculations.rb'
|
69
|
+
require folder + '/ingen.rb'
|
70
|
+
require folder + '/properties.rb'
|
71
|
+
require folder + '/test_gs2.rb'
|
72
|
+
|
73
|
+
NaN = GSL::NAN
|
74
|
+
# GSL::Neg
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
################################################
|
81
|
+
# Quantities that are calculated or determined by CodeRunner
|
82
|
+
# after the simulation has ended, i.e. quantities
|
83
|
+
# that are not available from the AstroGK output files.
|
84
|
+
################################################
|
85
|
+
# Get GS2 results and add any
|
86
|
+
# astrogk ones (currently empty)
|
87
|
+
|
88
|
+
@results = rcp.results + []
|
89
|
+
|
90
|
+
###############################################
|
91
|
+
# Other useful information about the run
|
92
|
+
###############################################
|
93
|
+
|
94
|
+
@astrogk_run_info = rcp.gs2_run_info + []
|
95
|
+
|
96
|
+
@run_info = @astrogk_run_info.dup
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
@naming_pars = rcp.naming_pars + []
|
101
|
+
|
102
|
+
@code_long = "AstroGK Astrophysical Gyrokinetic Code"
|
103
|
+
|
104
|
+
@excluded_sub_folders =[]
|
105
|
+
|
106
|
+
def run_namelist_backwards_compatibility
|
107
|
+
end
|
108
|
+
def set_nprocs
|
109
|
+
|
110
|
+
if (nprocs_in = @nprocs) =~ /^x/
|
111
|
+
max = max_nprocs_no_x
|
112
|
+
#Astrogk seems to not like you actually having naky * nspec * negrid processors.. reduce it
|
113
|
+
for i in 2...max
|
114
|
+
if max%i ==0
|
115
|
+
max = max / i
|
116
|
+
break
|
117
|
+
end
|
118
|
+
end
|
119
|
+
nodes = 0
|
120
|
+
@nprocs = "#{nodes}#{nprocs_in}"
|
121
|
+
loop do
|
122
|
+
nodes += 1
|
123
|
+
@nprocs = "#{nodes}#{nprocs_in}"
|
124
|
+
if actual_number_of_processors > max
|
125
|
+
nodes -= 1
|
126
|
+
@nprocs = "#{nodes}#{nprocs_in}"
|
127
|
+
break
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
def input_file_header
|
133
|
+
<<EOF
|
134
|
+
!==============================================================================
|
135
|
+
! AstroGK INPUT FILE automatically generated by CodeRunner
|
136
|
+
!==============================================================================
|
137
|
+
!
|
138
|
+
! AstroGK is a gyrokinetic flux tube initial value turbulence code
|
139
|
+
! which can be used for fusion or astrophysical plasmas.
|
140
|
+
!
|
141
|
+
! See http://gyrokinetics.sourceforge.net
|
142
|
+
!
|
143
|
+
! CodeRunner is a framework for the automated running and analysis
|
144
|
+
! of large simulations.
|
145
|
+
!
|
146
|
+
! See http://coderunner.sourceforge.net
|
147
|
+
! by CodeRunner version #{CodeRunner::CODE_RUNNER_VERSION.to_s}
|
148
|
+
!
|
149
|
+
!==============================================================================
|
150
|
+
|
151
|
+
EOF
|
152
|
+
end
|
153
|
+
def self.defaults_file_header
|
154
|
+
<<EOF1
|
155
|
+
######################################################################
|
156
|
+
# Automatically generated defaults file for AstroGK CodeRunner module#
|
157
|
+
# #
|
158
|
+
# This defaults file specifies a set of defaults for AstroGK which are#
|
159
|
+
# used by CodeRunner to set up and run GS2 simulations. #
|
160
|
+
# #
|
161
|
+
# Created #{Time.now.to_s} #
|
162
|
+
# #
|
163
|
+
######################################################################
|
164
|
+
|
165
|
+
@defaults_file_description = ""
|
166
|
+
EOF1
|
167
|
+
end
|
168
|
+
|
169
|
+
@source_code_subfolders = ['utils']
|
170
|
+
|
171
|
+
folder = File.dirname(File.expand_path(__FILE__)) # i.e. the directory this file is in
|
172
|
+
|
173
|
+
def self.transfer_gs2_docs
|
174
|
+
CodeRunner.setup_run_class('gs2')
|
175
|
+
p CodeRunner::Gs2::Astrogk.ancestors
|
176
|
+
intersection = (CodeRunner::Gs2.rcp.namelists.keys&CodeRunner::Gs2::Astrogk.rcp.namelists.keys)
|
177
|
+
gs2namelists=CodeRunner::Gs2.rcp.namelists
|
178
|
+
intersection.each do | namelist |
|
179
|
+
p namelist
|
180
|
+
gs2namelist=gs2namelists[namelist]
|
181
|
+
next unless gs2namelist
|
182
|
+
self.rcp.namelists[namelist][:variables].each do | varname, varhash |
|
183
|
+
p varname
|
184
|
+
if match = (gs2namelist[:variables][varname]) # or gs2namelist[:variables].find{|gs2varname,gs2varhash| gs2varhash[:code_name]==varhash[:code_name]}[1])
|
185
|
+
puts "Found corresponding variable #{varname}"
|
186
|
+
#p match
|
187
|
+
puts "Found help: #{match[:help]}"
|
188
|
+
varhash[:help] = match[:help] if match[:help]
|
189
|
+
varhash[:description] = match[:description]
|
190
|
+
save_namelists
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end # class Gs2::Astrogk
|
197
|
+
# For backwards compatibility
|
198
|
+
|
199
|
+
end # class CodeRunner
|
200
|
+
|
201
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
##########################################
|
2
|
+
# Calculations for AGK Code Runner Module
|
3
|
+
# (Only if they differ from GS2)
|
4
|
+
#
|
5
|
+
# This module contains any methods that
|
6
|
+
# begin with the word calculate.
|
7
|
+
#
|
8
|
+
# These methods calculate results and
|
9
|
+
# quantities that are not directly
|
10
|
+
# obtainable from the GS2 output files.
|
11
|
+
#
|
12
|
+
##########################################
|
13
|
+
|
14
|
+
|
15
|
+
class CodeRunner
|
16
|
+
class Gs2::Astrogk
|
17
|
+
|
18
|
+
def read_transfers
|
19
|
+
Dir.chdir(@directory) do
|
20
|
+
raise "No ktrans file" unless FileTest.exist? "#@run_name.ktrans"
|
21
|
+
file = File.open("#@run_name.ktrans", "r")
|
22
|
+
wtr_hash = {}
|
23
|
+
etr_hash = {}
|
24
|
+
while line = file.gets
|
25
|
+
#p line;
|
26
|
+
arr = line.split(/\s+/).map{|w| w.to_f}
|
27
|
+
#p arr
|
28
|
+
dud, t, kf, kt, w, e = arr
|
29
|
+
next unless t
|
30
|
+
etr_hash[t] ||= {}
|
31
|
+
etr_hash[t][kf] ||= {}
|
32
|
+
etr_hash[t][kf][kt] = e
|
33
|
+
|
34
|
+
wtr_hash[t] ||= {}
|
35
|
+
wtr_hash[t][kf] ||= {}
|
36
|
+
wtr_hash[t][kf][kt] = w
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#p etr_hash
|
45
|
+
|
46
|
+
File.open('energy_transfer.rb', 'w'){|file| file.puts etr_hash.pretty_inspect}
|
47
|
+
File.open('w_transfer.rb', 'w'){|file| file.puts wtr_hash.pretty_inspect}
|
48
|
+
|
49
|
+
end # Dir.chdir(@directory)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
{:stir_mode_amplitude=>
|
2
|
+
{:should_include=>"true",
|
3
|
+
:description=>nil,
|
4
|
+
:help=>nil,
|
5
|
+
:tests=>["Tst::FLOAT"],
|
6
|
+
:code_name=>:stir_mode_amplitude,
|
7
|
+
:must_pass=>
|
8
|
+
[{:test=>"kind_of? Numeric",
|
9
|
+
:explanation=>
|
10
|
+
"This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
|
11
|
+
:type=>:Float},
|
12
|
+
:stir_kx=>
|
13
|
+
{:should_include=>"true",
|
14
|
+
:description=>nil,
|
15
|
+
:help=>" Mode number for stirring\n",
|
16
|
+
:tests=>["Tst::INT"],
|
17
|
+
:code_name=>:stir_kx,
|
18
|
+
:must_pass=>
|
19
|
+
[{:test=>"kind_of? Integer",
|
20
|
+
:explanation=>"This variable must be an integer."}],
|
21
|
+
:type=>:Integer},
|
22
|
+
:stir_ky=>
|
23
|
+
{:should_include=>"true",
|
24
|
+
:description=>nil,
|
25
|
+
:help=>" Mode number for stirring\n",
|
26
|
+
:tests=>["Tst::INT"],
|
27
|
+
:code_name=>:stir_ky,
|
28
|
+
:must_pass=>
|
29
|
+
[{:test=>"kind_of? Integer",
|
30
|
+
:explanation=>"This variable must be an integer."}],
|
31
|
+
:type=>:Integer},
|
32
|
+
:stir_kz=>
|
33
|
+
{:should_include=>"true",
|
34
|
+
:description=>nil,
|
35
|
+
:help=>" Mode number for stirring\n",
|
36
|
+
:tests=>["Tst::INT"],
|
37
|
+
:code_name=>:stir_kz,
|
38
|
+
:must_pass=>
|
39
|
+
[{:test=>"kind_of? Integer",
|
40
|
+
:explanation=>"This variable must be an integer."}],
|
41
|
+
:type=>:Integer},
|
42
|
+
:stir_travel=>
|
43
|
+
{:should_include=>"true",
|
44
|
+
:description=>nil,
|
45
|
+
:help=>" Launches traveling wave (or standing wave if F). \n",
|
46
|
+
:tests=>["Tst::FORTRAN_BOOL"],
|
47
|
+
:code_name=>:stir_travel,
|
48
|
+
:must_pass=>
|
49
|
+
[{:test=>"kind_of? String and FORTRAN_BOOLS.include? self",
|
50
|
+
:explanation=>
|
51
|
+
"This variable must be a fortran boolean. (In Ruby this is represented as a string: e.g. '.true.')"}],
|
52
|
+
:type=>:Fortran_Bool},
|
53
|
+
:stir_a=>
|
54
|
+
{:should_include=>"true",
|
55
|
+
:description=>nil,
|
56
|
+
:help=>
|
57
|
+
" Initial amplitude of right-moving component. It is not necessary to set a and b unless you are\ndoing restarts, which are rather clunky at the moment with the antenna included. \n",
|
58
|
+
:tests=>["Tst::FLOAT"],
|
59
|
+
:code_name=>:stir_a,
|
60
|
+
:must_pass=>
|
61
|
+
[{:test=>"kind_of? Numeric",
|
62
|
+
:explanation=>
|
63
|
+
"This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
|
64
|
+
:type=>:Float},
|
65
|
+
:stir_b=>
|
66
|
+
{:should_include=>"true",
|
67
|
+
:description=>nil,
|
68
|
+
:help=>
|
69
|
+
" Initial amplitude of left-moving component. It is not necessary to set a and b unless you are\ndoing restarts, which are rather clunky at the moment with the antenna included. \n",
|
70
|
+
:tests=>["Tst::FLOAT"],
|
71
|
+
:code_name=>:stir_b,
|
72
|
+
:must_pass=>
|
73
|
+
[{:test=>"kind_of? Numeric",
|
74
|
+
:explanation=>
|
75
|
+
"This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
|
76
|
+
:type=>:Float}}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CodeRunner
|
2
|
+
class Gs2::Astrogk
|
3
|
+
module AstrogkGSLVectors
|
4
|
+
def etrans_by_kfrom_by_kto_over_time_gsl_vector(options)
|
5
|
+
read_transfers unless FileTest.exist? "energy_transfer.rb"
|
6
|
+
etr_hash = eval(File.read("energy_transfer.rb"))
|
7
|
+
etr_hash.values.map{|hash| hash[options[:kf]][options[:kt]]}.to_gslv
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
11
|
+
include AstrogkGSLVectors
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
###################################
|
2
|
+
# GS2 CodeRunner Module: GSL Tools
|
3
|
+
#
|
4
|
+
# Various useful methods for manipulating gsl data.
|
5
|
+
#
|
6
|
+
###################################
|
7
|
+
|
8
|
+
module GSL
|
9
|
+
def self.cache
|
10
|
+
@cache ||= {}
|
11
|
+
@cache
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
class GSL::Vector
|
17
|
+
def pieces(no_pieces)
|
18
|
+
ans = []
|
19
|
+
piece_sizes = []
|
20
|
+
|
21
|
+
for i in 0...no_pieces
|
22
|
+
ans.push []; piece_sizes[i] = 0
|
23
|
+
end
|
24
|
+
for j in 0...size
|
25
|
+
piece_sizes[j % no_pieces] += 1
|
26
|
+
end
|
27
|
+
# p ans, piece_sizes
|
28
|
+
accum = 0
|
29
|
+
piece_sizes.each_with_index do |piece_size, piece|
|
30
|
+
ans[piece] = self.subvector(accum, piece_size)
|
31
|
+
accum += piece_size
|
32
|
+
end
|
33
|
+
return ans
|
34
|
+
end
|
35
|
+
|
36
|
+
def from_box_order
|
37
|
+
size = self.size
|
38
|
+
v1, v2 = self.subvector(0, (size+1)/2), self.subvector((size+1)/2, (size-1)/2)
|
39
|
+
return v2.connect(v1)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
class GSL::Matrix::Complex
|
47
|
+
|
48
|
+
def self.re_im(re, im)
|
49
|
+
raise "Shape of real and imaginary matrices must match" unless re.shape == im.shape
|
50
|
+
rows, cols = re.shape
|
51
|
+
mat = alloc(rows, cols)
|
52
|
+
for i in 0...rows
|
53
|
+
for j in 0...cols
|
54
|
+
mat[i,j] = GSL::Complex.alloc([re[i,j], im[i,j]])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
return mat
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def backward_cols_c2c(normalise = false)
|
62
|
+
gm = self.dup
|
63
|
+
rows, cols = gm.shape
|
64
|
+
table = GSL.cache[[:fft_table, :complex, rows]] ||= GSL::FFT::ComplexWavetable.alloc(rows)
|
65
|
+
work = GSL.cache[[:fft_work, :complex, rows]] ||= GSL::FFT::ComplexWorkspace.alloc(rows)
|
66
|
+
for i in 0...cols
|
67
|
+
vec = gm.col(i)
|
68
|
+
vec.backward!(table, work)
|
69
|
+
for j in 0...rows
|
70
|
+
gm[j,i] = vec[j]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
gm = gm / rows if normalise
|
74
|
+
gm
|
75
|
+
end
|
76
|
+
|
77
|
+
def forward_cols_c2c
|
78
|
+
gm = self.dup
|
79
|
+
rows, cols = gm.shape
|
80
|
+
table = GSL.cache[[:fft_table, :complex, rows]] ||= GSL::FFT::ComplexWavetable.alloc(rows)
|
81
|
+
work = GSL.cache[[:fft_work, :complex, rows]] ||= GSL::FFT::ComplexWorkspace.alloc(rows)
|
82
|
+
for i in 0...cols
|
83
|
+
vec = gm.col(i)
|
84
|
+
vec.forward!(table, work)
|
85
|
+
for j in 0...rows
|
86
|
+
gm[j,i] = vec[j]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
gm
|
90
|
+
end
|
91
|
+
|
92
|
+
def backward_rows_cc2r(normalise = false)
|
93
|
+
gm = self.dup
|
94
|
+
rows, cols = gm.shape
|
95
|
+
# if cols%2 == 0
|
96
|
+
# newcols = cols*2
|
97
|
+
# else
|
98
|
+
# newcols = cols*2 - 1
|
99
|
+
# end
|
100
|
+
was_even = rows.times.inject(true) do |bool, i|
|
101
|
+
bool and (gm[i, cols - 1].imag == 0.0)
|
102
|
+
end
|
103
|
+
# ep was_even
|
104
|
+
|
105
|
+
if was_even
|
106
|
+
newcols = cols * 2 - 2
|
107
|
+
else
|
108
|
+
newcols = cols * 2 - 1
|
109
|
+
end
|
110
|
+
gm_re = GSL::Matrix.alloc(rows, newcols)
|
111
|
+
|
112
|
+
table = GSL.cache[[:fft_table, :real, newcols]] ||= GSL::FFT::RealWavetable.alloc(newcols)
|
113
|
+
work = GSL.cache[[:fft_work, :real, newcols]] ||= GSL::FFT::RealWorkspace.alloc(newcols)
|
114
|
+
row = GSL::Vector::Complex.alloc(cols)
|
115
|
+
# p rows
|
116
|
+
for i in 0...rows
|
117
|
+
# p i
|
118
|
+
# row = gm.row(i)
|
119
|
+
(0...cols).each{|j| row[j] = gm[i,j]}
|
120
|
+
if was_even
|
121
|
+
vec = row.concat(row.subvector(1, row.size - 2).reverse.conjugate) if cols > 2
|
122
|
+
else
|
123
|
+
vec = row.concat(row.subvector(1, row.size - 1).reverse.conjugate) if cols > 1
|
124
|
+
end
|
125
|
+
vec.backward!(table, work)
|
126
|
+
for j in 0...newcols
|
127
|
+
gm_re[i,j] = vec[j].real
|
128
|
+
end
|
129
|
+
end
|
130
|
+
gm_re = gm_re / newcols.to_f if normalise
|
131
|
+
gm_re
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
class GSL::Matrix
|
137
|
+
|
138
|
+
def move_rows_from_box_order
|
139
|
+
rows, cols = self.shape
|
140
|
+
gm1, gm2 = self.view(0,0, (rows + 1)/2, cols), self.view((rows + 1)/2, 0, (rows - 1)/2, cols)
|
141
|
+
return gm2.vertcat(gm1)
|
142
|
+
end
|
143
|
+
def move_cols_from_box_order
|
144
|
+
rows, cols = self.shape
|
145
|
+
gm1, gm2 = self.view(0,0, rows, (cols + 1)/2), self.view(0, (cols + 1)/2, rows, (cols - 1)/2)
|
146
|
+
return gm2.horzcat(gm1)
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
def forward_rows_r2cc
|
151
|
+
gm = self.dup
|
152
|
+
rows, cols = gm.shape
|
153
|
+
if cols%2 == 0
|
154
|
+
newcols = (cols+2)/2
|
155
|
+
else
|
156
|
+
newcols = (cols+1)/2
|
157
|
+
end
|
158
|
+
gm_cc = GSL::Matrix::Complex.alloc(rows, newcols)
|
159
|
+
|
160
|
+
table = GSL.cache[[:fft_table, :real, cols]] ||= GSL::FFT::RealWavetable.alloc(cols)
|
161
|
+
work = GSL.cache[[:fft_work, :real, cols]] ||= GSL::FFT::RealWorkspace.alloc(cols)
|
162
|
+
row = GSL::Vector.alloc(cols)
|
163
|
+
for i in 0...rows
|
164
|
+
(0...cols).each{|j| row[j] = gm[i,j]}
|
165
|
+
# p i
|
166
|
+
# row = gm.get_row(i)
|
167
|
+
# vec_out = GSL::Vector::Complex.alloc(row.size)
|
168
|
+
# (0...row.size).each{|j| vec[j] = row[j]}
|
169
|
+
# if cols%2 == 0
|
170
|
+
# vec_out = vec.concat(vec.subvector(1, vec.size - 2).reverse.conjugate)
|
171
|
+
# else
|
172
|
+
# vec_out = vec.concat(vec.subvector(1, vec.size - 1).reverse.conjugate)
|
173
|
+
# end
|
174
|
+
view = row.forward(table, work).halfcomplex_to_complex
|
175
|
+
for j in 0...newcols
|
176
|
+
gm_cc[i,j] = view[j]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
return gm_cc
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CodeRunner
|
2
|
+
class Gs2::Astrogk
|
3
|
+
|
4
|
+
def ingen
|
5
|
+
|
6
|
+
# Misc Errors
|
7
|
+
|
8
|
+
warning("Write k energy transfer currently only works with layout = 'yxles'") if @write_ktrans and @write_ktrans.fortran_true? and not @layout == "yxles"
|
9
|
+
|
10
|
+
super # call GS2 ingen
|
11
|
+
end
|
12
|
+
|
13
|
+
def diagnostics_namelist
|
14
|
+
:diagnostics
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|