gryfxcrmod 0.0.0 → 0.1.0

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/Gemfile CHANGED
@@ -3,11 +3,14 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "coderunner", ">= 0.13.0"
6
+ gem "gs2crmod", ">= 0.9.9"
7
+ gem "ruby-netcdf", ">= 0.6.6"
6
8
 
7
9
  # Add dependencies to develop your gem here.
8
10
  # Include everything needed to run rake, tests, features, etc.
9
11
  group :development do
10
12
  gem "shoulda", ">= 0"
13
+ gem "shoulda-context", ">= 1.1.5"
11
14
  gem "rdoc", "~> 3.12"
12
15
  gem "bundler", ">= 1.0.0"
13
16
  gem "jeweler", ">= 1.8.4"
data/Rakefile CHANGED
@@ -31,6 +31,16 @@ Rake::TestTask.new(:test) do |test|
31
31
  test.pattern = 'test/**/test_*.rb'
32
32
  test.verbose = true
33
33
  end
34
+ Rake::TestTask.new(:sync_variables) do |test|
35
+ test.libs << 'lib' << 'sync_variables'
36
+ test.pattern = 'sync_variables/sync_variables.rb'
37
+ test.verbose = true
38
+ end
39
+ Rake::TestTask.new(:sync_mediawiki) do |test|
40
+ test.libs << 'lib' << 'sync_mediawiki'
41
+ test.pattern = 'sync_mediawiki/sync_mediawiki.rb'
42
+ test.verbose = true
43
+ end
34
44
 
35
45
  #require 'rcov/rcovtask'
36
46
  #Rcov::RcovTask.new do |test|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
data/gryfxcrmod.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gryfxcrmod"
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Edmund Highcock"]
12
- s.date = "2013-08-09"
12
+ s.date = "2013-08-15"
13
13
  s.description = "This is a customised subclass of the CodeRunner::Run class which allows CodeRunner to run and analyse the gyrofluid GPU turbulent transport solver Gryfx."
14
14
  s.email = "edmundhighcock@users.sourceforge.net"
15
15
  s.extra_rdoc_files = [
@@ -25,8 +25,16 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "gryfxcrmod.gemspec",
27
27
  "lib/gryfxcrmod.rb",
28
+ "lib/gryfxcrmod/deleted_variables.rb",
28
29
  "lib/gryfxcrmod/gryfx.rb",
30
+ "lib/gryfxcrmod/namelist_tools.rb",
29
31
  "lib/gryfxcrmod/namelists.rb",
32
+ "sync_mediawiki/helper.rb",
33
+ "sync_mediawiki/sync_mediawiki.rb",
34
+ "sync_variables/helper.rb",
35
+ "sync_variables/sync_variables.rb",
36
+ "test/cyclone_miller_ke.in",
37
+ "test/cyclone_miller_ke.tgz",
30
38
  "test/helper.rb",
31
39
  "test/test_gryfxcrmod.rb"
32
40
  ]
@@ -41,20 +49,29 @@ Gem::Specification.new do |s|
41
49
 
42
50
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
51
  s.add_runtime_dependency(%q<coderunner>, [">= 0.13.0"])
52
+ s.add_runtime_dependency(%q<gs2crmod>, [">= 0.9.9"])
53
+ s.add_runtime_dependency(%q<ruby-netcdf>, [">= 0.6.6"])
44
54
  s.add_development_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_development_dependency(%q<shoulda-context>, [">= 1.1.5"])
45
56
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
46
57
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
47
58
  s.add_development_dependency(%q<jeweler>, [">= 1.8.4"])
48
59
  else
49
60
  s.add_dependency(%q<coderunner>, [">= 0.13.0"])
61
+ s.add_dependency(%q<gs2crmod>, [">= 0.9.9"])
62
+ s.add_dependency(%q<ruby-netcdf>, [">= 0.6.6"])
50
63
  s.add_dependency(%q<shoulda>, [">= 0"])
64
+ s.add_dependency(%q<shoulda-context>, [">= 1.1.5"])
51
65
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
52
66
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
53
67
  s.add_dependency(%q<jeweler>, [">= 1.8.4"])
54
68
  end
55
69
  else
56
70
  s.add_dependency(%q<coderunner>, [">= 0.13.0"])
71
+ s.add_dependency(%q<gs2crmod>, [">= 0.9.9"])
72
+ s.add_dependency(%q<ruby-netcdf>, [">= 0.6.6"])
57
73
  s.add_dependency(%q<shoulda>, [">= 0"])
74
+ s.add_dependency(%q<shoulda-context>, [">= 1.1.5"])
58
75
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
59
76
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
60
77
  s.add_dependency(%q<jeweler>, [">= 1.8.4"])
@@ -0,0 +1,253 @@
1
+ {:tite=>
2
+ {:should_include=>"true",
3
+ :description=>"Ratio of ion to electron temperatures.",
4
+ :help=>
5
+ "Ratio of ion to electron temperatures. This parameter is used only when there is no species called \"electron\" included.",
6
+ :code_name=>:TiTe,
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
+ :autoscanned_defaults=>[1.0]},
13
+ :beta=>
14
+ {:should_include=>"true",
15
+ :description=>"",
16
+ :help=>"",
17
+ :code_name=>:beta,
18
+ :must_pass=>
19
+ [{:test=>"kind_of? Numeric",
20
+ :explanation=>
21
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
22
+ :type=>:Float},
23
+ :zeff=>
24
+ {:should_include=>"true",
25
+ :description=>"",
26
+ :help=>"",
27
+ :code_name=>:zeff,
28
+ :must_pass=>
29
+ [{:test=>"kind_of? Numeric",
30
+ :explanation=>
31
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
32
+ :type=>:Float},
33
+ :dens0=>
34
+ {:should_include=>"true",
35
+ :description=>nil,
36
+ :help=>nil,
37
+ :tests=>["Tst::FLOAT"],
38
+ :gs2_name=>:dens0,
39
+ :must_pass=>
40
+ [{:test=>"kind_of? Float or kind_of? Integer",
41
+ :explanation=>
42
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
43
+ :type=>:Float,
44
+ :code_name=>:dens0,
45
+ :autoscanned_defaults=>[]},
46
+ :u0=>
47
+ {:should_include=>"true",
48
+ :description=>nil,
49
+ :help=>nil,
50
+ :tests=>["Tst::FLOAT"],
51
+ :gs2_name=>:u0,
52
+ :must_pass=>
53
+ [{:test=>"kind_of? Float or kind_of? Integer",
54
+ :explanation=>
55
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
56
+ :type=>:Float,
57
+ :code_name=>:u0,
58
+ :autoscanned_defaults=>[]},
59
+ :uprim2=>
60
+ {:should_include=>"true",
61
+ :description=>nil,
62
+ :help=>" \n",
63
+ :tests=>["Tst::FLOAT"],
64
+ :gs2_name=>:uprim2,
65
+ :must_pass=>
66
+ [{:test=>"kind_of? Float or kind_of? Integer",
67
+ :explanation=>
68
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
69
+ :type=>:Float,
70
+ :code_name=>:uprim2,
71
+ :autoscanned_defaults=>[]},
72
+ :nustar=>
73
+ {:should_include=>"true",
74
+ :description=>nil,
75
+ :help=>nil,
76
+ :tests=>["Tst::FLOAT"],
77
+ :gs2_name=>:nustar,
78
+ :must_pass=>
79
+ [{:test=>"kind_of? Float or kind_of? Integer",
80
+ :explanation=>
81
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
82
+ :type=>:Float,
83
+ :code_name=>:nustar,
84
+ :autoscanned_defaults=>[]},
85
+ :nu=>
86
+ {:should_include=>"true",
87
+ :description=>nil,
88
+ :help=>nil,
89
+ :tests=>["Tst::FLOAT"],
90
+ :gs2_name=>:nu,
91
+ :must_pass=>
92
+ [{:test=>"kind_of? Float or kind_of? Integer",
93
+ :explanation=>
94
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
95
+ :type=>:Float,
96
+ :code_name=>:nu,
97
+ :autoscanned_defaults=>[]},
98
+ :nu_h=>
99
+ {:should_include=>"true",
100
+ :description=>nil,
101
+ :help=>nil,
102
+ :tests=>["Tst::FLOAT"],
103
+ :gs2_name=>:nu_h,
104
+ :must_pass=>
105
+ [{:test=>"kind_of? Float or kind_of? Integer",
106
+ :explanation=>
107
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
108
+ :type=>:Float,
109
+ :code_name=>:nu_h,
110
+ :autoscanned_defaults=>[]},
111
+ :tperp0=>
112
+ {:should_include=>"true",
113
+ :description=>nil,
114
+ :help=>nil,
115
+ :tests=>["Tst::FLOAT"],
116
+ :gs2_name=>:tperp0,
117
+ :must_pass=>
118
+ [{:test=>"kind_of? Float or kind_of? Integer",
119
+ :explanation=>
120
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
121
+ :type=>:Float,
122
+ :code_name=>:tperp0,
123
+ :autoscanned_defaults=>[]},
124
+ :tpar0=>
125
+ {:should_include=>"true",
126
+ :description=>nil,
127
+ :help=>nil,
128
+ :tests=>["Tst::FLOAT"],
129
+ :gs2_name=>:tpar0,
130
+ :must_pass=>
131
+ [{:test=>"kind_of? Float or kind_of? Integer",
132
+ :explanation=>
133
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
134
+ :type=>:Float,
135
+ :code_name=>:tpar0,
136
+ :autoscanned_defaults=>[]},
137
+ :source=>
138
+ {:should_include=>"true",
139
+ :description=>
140
+ "Normalised alpha source. If set -ve automatically adjusted to give specified alpha density.",
141
+ :help=>
142
+ "Sets the normalised source for alphas. If set negative will be automatically adjusted to give the specified alpha density.",
143
+ :code_name=>:source,
144
+ :must_pass=>
145
+ [{:test=>"kind_of? Numeric",
146
+ :explanation=>
147
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
148
+ :type=>:Float,
149
+ :autoscanned_defaults=>[]},
150
+ :sprim=>
151
+ {:should_include=>"true",
152
+ :description=>"Gradient of normalised source.",
153
+ :help=>"Gradient of normalised source.",
154
+ :code_name=>:sprim,
155
+ :must_pass=>
156
+ [{:test=>"kind_of? Numeric",
157
+ :explanation=>
158
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
159
+ :type=>:Float,
160
+ :autoscanned_defaults=>[]},
161
+ :gamma_ai=>
162
+ {:should_include=>"true",
163
+ :description=>
164
+ "Alpha ion collion rate. Should be roughly the same as nu_ii.",
165
+ :help=>
166
+ "Alpha ion collion rate. Normalisation chosen so that this parameter should be roughly the same as nu_ii.",
167
+ :code_name=>:gamma_ai,
168
+ :must_pass=>
169
+ [{:test=>"kind_of? Numeric",
170
+ :explanation=>
171
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
172
+ :type=>:Float,
173
+ :autoscanned_defaults=>[]},
174
+ :gamma_ae=>
175
+ {:should_include=>"true",
176
+ :description=>
177
+ "Alpha electron collion rate. Should be roughly the same as nu_ee.",
178
+ :help=>
179
+ "Alpha electron collion rate. Normalisation chosen so that this parameter should be roughly the same as nu_ee.",
180
+ :code_name=>:gamma_ae,
181
+ :must_pass=>
182
+ [{:test=>"kind_of? Numeric",
183
+ :explanation=>
184
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
185
+ :type=>:Float,
186
+ :autoscanned_defaults=>[]},
187
+ :itor=>
188
+ {:should_include=>"true",
189
+ :description=>"",
190
+ :help=>"",
191
+ :code_name=>:itor,
192
+ :must_pass=>
193
+ [{:test=>"kind_of? Integer",
194
+ :explanation=>"This variable must be an integer."}],
195
+ :type=>:Integer},
196
+ :iflux=>
197
+ {:should_include=>"true",
198
+ :description=>"",
199
+ :help=>"",
200
+ :code_name=>:iflux,
201
+ :must_pass=>
202
+ [{:test=>"kind_of? Integer",
203
+ :explanation=>"This variable must be an integer."}],
204
+ :type=>:Integer},
205
+ :ppl_eq=>
206
+ {:should_include=>"true",
207
+ :description=>"",
208
+ :help=>"",
209
+ :code_name=>:ppl_eq,
210
+ :must_pass=>
211
+ [{:test=>"kind_of? String and FORTRAN_BOOLS.include? self",
212
+ :explanation=>
213
+ "This variable must be a fortran boolean. (In Ruby this is represented as a string: e.g. '.true.')"}],
214
+ :type=>:Fortran_Bool},
215
+ :gen_eq=>
216
+ {:should_include=>"true",
217
+ :description=>"",
218
+ :help=>"",
219
+ :code_name=>:gen_eq,
220
+ :must_pass=>
221
+ [{:test=>"kind_of? String and FORTRAN_BOOLS.include? self",
222
+ :explanation=>
223
+ "This variable must be a fortran boolean. (In Ruby this is represented as a string: e.g. '.true.')"}],
224
+ :type=>:Fortran_Bool},
225
+ :efit_eq=>
226
+ {:should_include=>"true",
227
+ :description=>"",
228
+ :help=>"",
229
+ :code_name=>:efit_eq,
230
+ :must_pass=>
231
+ [{:test=>"kind_of? String and FORTRAN_BOOLS.include? self",
232
+ :explanation=>
233
+ "This variable must be a fortran boolean. (In Ruby this is represented as a string: e.g. '.true.')"}],
234
+ :type=>:Fortran_Bool},
235
+ :delrho=>
236
+ {:should_include=>"true",
237
+ :description=>"",
238
+ :help=>"",
239
+ :code_name=>:delrho,
240
+ :must_pass=>
241
+ [{:test=>"kind_of? Numeric",
242
+ :explanation=>
243
+ "This variable must be a floating point number (an integer is also acceptable: it will be converted into a floating point number)."}],
244
+ :type=>:Float},
245
+ :isym=>
246
+ {:should_include=>"true",
247
+ :description=>"",
248
+ :help=>"",
249
+ :code_name=>:isym,
250
+ :must_pass=>
251
+ [{:test=>"kind_of? Integer",
252
+ :explanation=>"This variable must be an integer."}],
253
+ :type=>:Integer}}
@@ -2,7 +2,8 @@ class CodeRunner
2
2
  # This is a customised subclass of the CodeRunner::Run class which allows CodeRunner to run and analyse the gyrofluid GPU turbulent transport solver Gryfx.
3
3
  #
4
4
  # It generates the Gryfx input file, and both analyses the results and allows easy plotting of them.
5
- class Gryfx < Run::FortranNamelistC
5
+ CodeRunner.setup_run_class('gs2')
6
+ class Gryfx < Gs2
6
7
  #include CodeRunner::SYSTEM_MODULE
7
8
 
8
9
 
@@ -12,7 +13,7 @@ class CodeRunner
12
13
 
13
14
  # Use the Run::FortranNamelist tools to process the variable database
14
15
  setup_namelists(@code_module_folder)
15
- #require 'trinitycrmod/output_files'
16
+ require 'gryfxcrmod/namelist_tools'
16
17
  #require 'trinitycrmod/graphs'
17
18
 
18
19
  ################################################
@@ -44,7 +45,7 @@ class CodeRunner
44
45
  name += " real_id: #@real_id" if @real_id
45
46
  beginning = sprintf("%2d:%d %-60s %1s:%2.1f(%s) %3s%1s", @id, @job_no, name, @status.to_s[0,1], @run_time.to_f / 60.0, @nprocs.to_s, percent_complete, "%")
46
47
  if ctd
47
- beginning += sprintf("Q:%f, Pfusion:%f MW, Ti0:%f keV, Te0:%f keV, n0:%f x10^20", fusionQ, pfus, ti0, te0, ne0)
48
+ #beginning += sprintf("Q:%f, Pfusion:%f MW, Ti0:%f keV, Te0:%f keV, n0:%f x10^20", fusionQ, pfus, ti0, te0, ne0)
48
49
  end
49
50
  beginning += " ---#{@comment}" if @comment
50
51
  beginning
@@ -83,5 +84,33 @@ class CodeRunner
83
84
  #p ['fusionQ is ', fusionQ]
84
85
  end
85
86
 
87
+ def get_status
88
+ if @running
89
+ @status = :Incomplete
90
+ else
91
+ get_completed_timesteps
92
+ if percent_complete = 100.0*@completed_timesteps.to_f/(nstep/nwrite) > 5.0
93
+ @status = :Complete
94
+ else
95
+ @status = :Failed
96
+ end
97
+ end
98
+ end
99
+
100
+ def get_completed_timesteps
101
+ if FileTest.exist?(@run_name + '.cdf')
102
+ @completed_timesteps = gsl_vector('t').size
103
+ else
104
+ @completed_timesteps = 0
105
+ end
106
+ end
107
+
108
+ def netcdf_filename
109
+ @directory + '/' + @run_name + '.cdf'
110
+ end
111
+
112
+ def calculate_results
113
+ end
114
+
86
115
  end
87
116
  end
@@ -0,0 +1,58 @@
1
+
2
+ class CodeRunner::Gryfx
3
+ @fortran_namelist_source_file_match = /(\.c|\.cpp|\.cu|\.cc)$/
4
+
5
+ @fortran_namelist_variable_match_regex = /^[^\/]*?fnr_get_(?<type>\w+)\(\&?[\w\s]+\s*,\s*["'](?<namelist>\w+)[\d()]*?['"]\s*,\s*['"](?<variable>\w+)['"],[^)]+\)\)\s*[&*\w\[\]\d]+\s*=\s*(?<default>\S+)\s*;/
6
+ #
7
+ # Find all input namelists and variables by scanning the source code
8
+ #
9
+ def self.get_namelists_and_variables_from_source_code(source)
10
+ nms = {}
11
+ all_variables_in_source = {}
12
+ namelist_declarations = {}
13
+ #source.scan(/^\s*namelist\s*\/(?<namelist>\w+)\/(?<variables>(?:(?:&\s*[\n\r]+)|[^!\n\r])*)/) do
14
+ #source.scan(Regexp.new("#{/^\s*namelist\s*\/\s*(?<namelist>\w+)\s*\//}(?<variables>#{FORTRAN_SINGLE_LINE})")) do
15
+ source.scan(rcp.fortran_namelist_variable_match_regex) do
16
+ namelist = $~[:namelist].to_s.downcase.to_sym
17
+ #variables = $~[:variables].gsub(/!.*/, '')
18
+ #eputs namelist, variables
19
+ #namelist_declarations[namelist] = variables
20
+ #gets # if namelist == :collisions_knobs
21
+
22
+ #next if [:stuff, :ingen_knobs].include? namelist
23
+ nms[namelist] ||= []
24
+ all_variables_in_source[namelist] ||= []
25
+ # puts variables
26
+ #variables.scan(/\w+/) do
27
+ var = $~[:variable].to_sym
28
+ # (p variables, namelist; exit) if var == :following or var == :sou
29
+ all_variables_in_source[namelist].push var
30
+ next if known_code_variable?(namelist, var)
31
+ nms[namelist].push var
32
+ #end
33
+ nms[namelist].uniq!
34
+ all_variables_in_source[namelist].uniq!
35
+ end
36
+ return [nms, all_variables_in_source, namelist_declarations]
37
+ end
38
+ def self.get_sample_value(source, var)
39
+ sample_val = nil
40
+ source.scan(rcp.fortran_namelist_variable_match_regex) do
41
+ #p $~
42
+
43
+ next unless var == $~[:variable].to_sym
44
+ sample_val = eval($~[:default].sub(/(\d\.)$/, '\10').sub(/^(\.\d)/, '0\1').sub(/(\d\.)[eE]/, '\10e'))
45
+ end
46
+ raise "Couldn't get a sample value for #{var.inspect}" unless sample_val
47
+ return sample_val
48
+ end
49
+ def self.update_defaults_from_source_code(source_code_folder = ARGV[-1])
50
+ source = get_aggregated_source_code_text(source_code_folder)
51
+ rcp.namelists.each do |nml, nmlhash|
52
+ nmlhash[:variables].each do |var, varhash|
53
+ varhash[:autoscanned_defaults] = [get_sample_value(source, varhash[:code_name]||var)] rescue []
54
+ save_namelists
55
+ end
56
+ end
57
+ end
58
+ end