Class: CodeRunner::Trinity

Inherits:
Run::FortranNamelist
  • Object
show all
Includes:
ActualParameterValues, OutputFiles, ReadNetcdf, TrinityGraphKits, TrinityMultiKits
Defined in:
lib/trinitycrmod/trinity.rb,
lib/trinitycrmod/read_netcdf.rb,
lib/trinitycrmod/trinity_gs2.rb,
lib/trinitycrmod/output_files.rb,
lib/trinitycrmod/check_parameters.rb,
lib/trinitycrmod/flux_interpolator.rb,
lib/trinitycrmod/actual_parameter_values.rb,
lib/trinitycrmod/graphs.rb,
lib/trinitycrmod/chease.rb

Overview

This module reads data from the new diagnostics output file <run_name>.out.nc.

It defines a new generic reader function which can read any variable in the new netcdf file using a standard set of index constraints

Defined Under Namespace

Modules: ActualParameterValues, OutputFiles, ReadNetcdf, TrinityComponent, TrinityGraphKits, TrinityMultiKits Classes: FluxOptionError, NetcdfSmartReader

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TrinityMultiKits

#calibration_graphkit, #profiles_graphkit

Methods included from TrinityGraphKits

#ang_mom_prof_graphkit, #dens_prof_graphkit, #eln_hflux_gb_prof_graphkit, #eln_hflux_prof_graphkit, #eln_pwr_prof_graphkit, #eln_temp_prof_graphkit, #fluxes_prof_graphkit, #integrated_profiles_graphkit, #ion_hflux_gb_prof_graphkit, #ion_hflux_prof_graphkit, #ion_pwr_prof_graphkit, #ion_temp_prof_graphkit, #lflux_gb_prof_graphkit, #nt_prof_graphkit, #pbalance_prof_graphkit, #prof_graphkit, #pwr_prof_graphkit, #torque_prof_graphkit

Methods included from ActualParameterValues

#dflx_stencil_actual, #evolve_grads_only_actual, #fork_flag_actual

Methods included from OutputFiles

#fluxes_outfile, #geo_outfile, #info_outfile, #nt_outfile, #pbalance_outfile, #pwr_outfile, #time_outfile, #view_outfiles

Methods included from ReadNetcdf

#new_ncclose, #new_netcdf_file, #new_netcdf_filename

Class Method Details

.defaults_file_headerObject



533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/trinitycrmod/trinity.rb', line 533

def self.defaults_file_header
  "############################################################################\n#                                                                          #\n# Automatically generated defaults file for the Trinity CodeRunner module  #\n#                                                                          #\n# This defaults file specifies a set of defaults for Trinity which are     #\n# used by CodeRunner to set up and run Trinity simulations.                #\n#                                                                          #\n############################################################################\n\n# Created: \#{Time.now.to_s}\n\n@defaults_file_description = \"\"\n"
end

.flux_class(code) ⇒ Object



134
135
136
137
138
139
140
141
# File 'lib/trinitycrmod/trinity_gs2.rb', line 134

def self.flux_class(code)
  case code
  when "gs2"
    CodeRunner::Trinity::TrinityComponent::Gs2
  when "gryfx"
    CodeRunner::Trinity::TrinityComponent::Gryfx
  end
end

.get_input_help_from_source_code(source_folder) ⇒ Object



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/trinitycrmod/trinity.rb', line 481

def self.get_input_help_from_source_code(source_folder)
  source = get_aggregated_source_code_text(source_folder)
  rcp.namelists.each do |nmlst, hash|
    hash[:variables].each do |var, var_hash|

#       next unless var == :w_antenna
      var = var_hash[:code_name] || var
      values_text = source.scan(Regexp.new("\\W#{var}\\s*=\\s*.+")).join("\n")
      ep values_text
      values = scan_text_for_variables(values_text).map{|(_v,val)| val}
      values.uniq!
#       ep values if var == :nbeta
      values.delete_if{|val| val.kind_of? String} if values.find{|val| val.kind_of? Numeric}
      values.delete_if{|val| val.kind_of? String and not String::FORTRAN_BOOLS.include? val} if values.find{|val| val.kind_of? String and String::FORTRAN_BOOLS.include? val}
#       values.sort!
#       ep var
#       ep values
      sample_val = values[0]
      p sample_val
      help = values_text.scan(/ !(.*)/).flatten[0]
      p help
      #gets
      var_hash[:help] = help
      var_hash[:description] = help
      save_namelists

    end
  end
end

.interpolate_fluxes(old_run_folder, run_folder, grad_option, ntspec) ⇒ Object

To be used in conjunction with the shell script option in Trinity. Read the output of old_run_name (which may be a commma-separated list of multiple runs) and read the contents of <run_name>_flux_inputs.dat and use them to interpolate esitmates of the fluxes



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/trinitycrmod/flux_interpolator.rb', line 15

def interpolate_fluxes(old_run_folder, run_folder, grad_option, ntspec)
  old_run_name = nil
  Dir.chdir(old_run_folder) do
    old_cc = Dir.entries(Dir.pwd).find{|f| f =~ /\.cc$/}
    raise "Can't find cc file in #{old_run_folder}" unless old_cc
    old_run_name = File.expand_path(old_cc).sub(/.cc$/,'')
  end

  run_name = nil
  Dir.chdir(run_folder) do
    new_inp = Dir.entries(Dir.pwd).find{|f| f =~ /.flux_inputs$/}
    raise "Can't find flux_inputs in #{run_folder}" unless new_inp
    run_name = File.expand_path(new_inp).sub(/.flux_inputs$/,'')
  end
  

  ccfile = TextDataTools::Column::DataFile.new(old_run_name + '.cc', true, /\S+/, /(?:\#\s+)?\d+:.*?(?=\d+:|\Z)/)
  geofile = TextDataTools::Column::DataFile.new(old_run_name + '.geo', true, /\S+/, /(?:\#\s+)?\d+:\D*?(?=\d:|\d\d:|\Z)/)
  radius_data = ccfile.get_1d_array_float(/radius/)
  radius_uniq = radius_data.uniq
  p 'radius_uniq', radius_uniq
  ncc = radius_uniq.size
  np = radius_data.size/ncc
  p 'np is ', np, 'ncc is', ncc
  #p 'ion_tprim_perturb_data',ion_tprim_perturb_data = ccfile.get_1d_array_float(/11:/).pieces(np)
  perturb = {
    fprim: /10:/,
    ion_tprim: /11:/,
    eln_tprim: /12:/,
    dens: /18:/,
    ion_temp: /19:/,
    eln_temp: /20:/
  }
  perturb_data = perturb.inject({}) do |h,(k,v)| 
    begin
      h[k] = ccfile.get_1d_array_float(v).pieces(np).transpose
    rescue=>err
      p ccfile.get_1d_array(v)
      puts "Error reading: #{k}, #{v}"
      raise err
    end
    h
  end
  fluxes = {
    ion_hflux: /5: i/,
    eln_hflux: /6: e/,
    pflux: /3: i/,
    lflux: /9: v/,
    ion_heat: /7: i/,
    eln_heat: /8: e/
  }
  fluxes_data = fluxes.inject({}) do |h,(k,v)| 
    h[k] = ccfile.get_1d_array_float(v).pieces(np).transpose
    h
  end
  area = geofile.get_1d_array_float(/area/)
  grho = geofile.get_1d_array_float(/grho/)
  case grad_option
  when 'tigrad'
    jacobian_vecs = [:ion_temp,:ion_tprim]
    jacobian_vecs = [:ion_tprim]
    interp_vecs = [:ion_hflux]
    njac = 2
  when 'ntgrads'
    jacobian_vecs = [:ion_tprim, :eln_tprim, :fprim]
    jacobian_vecs = [:ion_tprim, :fprim]
    interp_vecs = [:ion_hflux, :eln_hflux, :pflux]
    njac = 4
  else 
    raise "Unknown grad_option: #{grad_option}"
  end
  GraphKit.quick_create([perturb_data[:ion_tprim][0].to_gslv, fluxes_data[:ion_hflux][0].to_gslv])#.gnuplot
  #p perturb_data[:ion_tprim][0]
  interp = fluxes_data.inject({}) do |h, (k,v)|
      h[k] = radius_uniq.size.times.map do |i| 
        if interp_vecs.include?(k)
          #puts 'i is', i
          GSL::ScatterInterp.alloc(
            :linear, 
            jacobian_vecs.map{|name| 
              arr = perturb_data[name]
              arr[i].to_gslv + 
              GSL::Vector.linspace(0,1e-9,arr[i].size)
            } + [v[i].to_gslv], 
            false,
           1.0
          ) 
        else
          ZeroEval.new
        end
      end
    h
  end
  if false and run_name != 'dummy'
    arr = []
    File.read(run_name + '.flux_inputs').scanf("%e"){|m| p m; arr+= m}
    # each of these quantities is a flat array with 
    # radial index varying fastest, then jacobian index
    # then species index where appropriate
    i = 0
    #p arr
    dens = arr[i...(i+=ncc*njac)]
    temp = arr[i...(i+=ncc*njac*2)].pieces(2) # This is hardwired to 2
    fprim = arr[i...(i+=ncc*njac)]
    tprim = arr[i...(i+=ncc*njac*2)].pieces(2) # This is hardwired to 2
    inputs = {}
    inputs[:dens] = dens
    inputs[:ion_temp] = temp[0]
    inputs[:eln_temp] = temp[1]
    inputs[:fprim] = fprim
    inputs[:ion_tprim] = tprim[0]
    inputs[:eln_tprim] = tprim[1]

    #p 'inputs', inputs.values.map{|v| v.size}, inputs[:eln_tprim]

    File.open(run_name + '.flux_results', 'w') do |file|
      njac.times{|ij| (ntspec+1).times{ ncc.times{|ic| file.printf("%e ",interp[:pflux][ic].eval(*jacobian_vecs.map{|v| inputs[v][ic + ij*ncc]}))}}}
      file.printf("\n")
      njac.times{|ij| 
        ncc.times{|ic| file.printf("%e ",interp[:ion_hflux][ic].eval(*jacobian_vecs.map{|v| inputs[v][ic + ij*ncc]}))}
        ntspec.times{
          ncc.times{|ic| file.printf("%e ",interp[:eln_hflux][ic].eval(*jacobian_vecs.map{|v| inputs[v][ic + ij*ncc]}))}
        }
      }
      file.printf("\n")
      njac.times{|ij| 
        ncc.times{|ic| file.printf("%e ",interp[:ion_heat][ic].eval(*jacobian_vecs.map{|v| inputs[v][ic + ij*ncc]}))}
        ntspec.times{
          ncc.times{|ic| file.printf("%e ",interp[:eln_heat][ic].eval(*jacobian_vecs.map{|v| inputs[v][ic + ij*ncc]}))}
        }
      }
      file.printf("\n")
      njac.times{|ij| ncc.times{|ic| file.printf("%e ",interp[:lflux][ic].eval(*jacobian_vecs.map{|v| inputs[v][ic + ij*ncc]}))}}
      file.printf("\n")
      area.each{|v| file.printf("%e ", v)}
      file.printf("\n")
      grho.each{|v| file.printf("%e ", v)}
      file.printf("\n")
    end
  else
    vec = GSL::Vector.linspace(perturb_data[:ion_tprim][0].min, perturb_data[:ion_tprim][0].max,20)
    vec2 = GSL::Vector.linspace(perturb_data[:fprim][0].min, perturb_data[:fprim][0].max,20)
    mat = GSL::Matrix.alloc(20,20)
    for i in 0...20
      for j in 0...20
        mat[i,j] = interp[:ion_hflux][0].eval(vec[i], vec2[j])
      end
    end
    vec3 = GSL::Vector.linspace(perturb_data[:ion_tprim][1].min, perturb_data[:ion_tprim][1].max,20)
    vec4 = GSL::Vector.linspace(perturb_data[:fprim][1].min, perturb_data[:fprim][1].max,20)
    mat2 = GSL::Matrix.alloc(20,20)
    for i in 0...20
      for j in 0...20
        mat2[i,j] = interp[:ion_hflux][1].eval(vec3[i], vec4[j])
      end
    end
    #vec.collect{|x| vec2.collect{|y| mat(interp[:ion_hflux][0].eval(x)}
    #GraphKit.quick_create([vec, vec2, mat], [perturb_data[:ion_tprim][0].to_gslv, perturb_data[:fprim][0], fluxes_data[:ion_hflux][0].to_gslv], [vec3, vec4, mat2], [perturb_data[:ion_tprim][1].to_gslv, perturb_data[:fprim][1], fluxes_data[:ion_hflux][1].to_gslv]).gnuplot live: true
    vec5 = GSL::Vector.linspace(perturb_data[:ion_tprim][2].min, perturb_data[:ion_tprim][2].max,20)
    vec6 = GSL::Vector.linspace(perturb_data[:fprim][2].min, perturb_data[:fprim][2].max,20)
    mat3 = GSL::Matrix.alloc(20,20)
    for i in 0...20
      for j in 0...20
        mat3[i,j] = interp[:ion_hflux][2].eval(vec5[i], vec6[j])
      end
    end
    #vec.collect{|x| vec2.collect{|y| mat(interp[:ion_hflux][0].eval(x)}
    #GraphKit.quick_create([vec, vec2, mat], [perturb_data[:ion_tprim][0].to_gslv, perturb_data[:fprim][0], fluxes_data[:ion_hflux][0].to_gslv], [vec3, vec4, mat2], [perturb_data[:ion_tprim][1].to_gslv, perturb_data[:fprim][1], fluxes_data[:ion_hflux][1].to_gslv],[vec5, vec6, mat3], [perturb_data[:ion_tprim][2].to_gslv, perturb_data[:fprim][2], fluxes_data[:ion_hflux][2].to_gslv]).gnuplot live: true
    vec7 = GSL::Vector.linspace(perturb_data[:ion_tprim][3].min, perturb_data[:ion_tprim][3].max,20)
    vec8 = GSL::Vector.linspace(perturb_data[:fprim][3].min, perturb_data[:fprim][3].max,20)
    mat4 = GSL::Matrix.alloc(20,20)
    for i in 0...20
      for j in 0...20
        mat4[i,j] = interp[:ion_hflux][3].eval(vec7[i], vec8[j])
      end
    end
    #vec.collect{|x| vec2.collect{|y| mat(interp[:ion_hflux][0].eval(x)}
    GraphKit.quick_create([vec, vec2, mat], [perturb_data[:ion_tprim][0].to_gslv, perturb_data[:fprim][0], fluxes_data[:ion_hflux][0].to_gslv], [vec3, vec4, mat2], [perturb_data[:ion_tprim][1].to_gslv, perturb_data[:fprim][1], fluxes_data[:ion_hflux][1].to_gslv],[vec5, vec6, mat3], [perturb_data[:ion_tprim][2].to_gslv, perturb_data[:fprim][2], fluxes_data[:ion_hflux][2].to_gslv],[vec7, vec8, mat4], [perturb_data[:ion_tprim][3].to_gslv, perturb_data[:fprim][3], fluxes_data[:ion_hflux][3].to_gslv]).gnuplot live: true
  end
    #vec = GSL::Vector.linspace(perturb_data[:ion_tprim][0].min, perturb_data[:ion_tprim][0].max,20)
    #GraphKit.quick_create([vec, vec.collect{|x| interp[:ion_hflux][0].eval(x)}], [perturb_data[:ion_tprim][0].to_gslv, fluxes_data[:ion_hflux][0].to_gslv]).gnuplot

    #vec = GSL::Vector.linspace(perturb_data[:ion_tprim][1].min, perturb_data[:ion_tprim][1].max,20)
    #GraphKit.quick_create([vec, vec.collect{|x| interp[:ion_hflux][1].eval(x)}], [perturb_data[:ion_tprim][1].to_gslv, fluxes_data[:ion_hflux][1].to_gslv]).gnuplot
    #vec = GSL::Vector.linspace(perturb_data[:ion_tprim][2].min, perturb_data[:ion_tprim][2].max,80)
    #GraphKit.quick_create([vec, vec.collect{|x| interp[:ion_hflux][2].eval(x)}], [perturb_data[:ion_tprim][2].to_gslv, fluxes_data[:ion_hflux][2].to_gslv]).gnuplot
    #STDIN.gets
  #GraphKit.quick_create([vec, vec.collect{|x| interp[:ion_hflux][0].eval(perturb_data[:ion_tprim][0].to_gslv.min, x)}]).gnuplot

  #p [tprim_perturb_data, fprim_perturb_data]
end

.use_new_defaults_file_with_flux(name = ARGV[-4], trinity_input_file = ARGV[-3], flux_input_file = ARGV[-2], fluxcode = ARGV[-1]) ⇒ Object

This function creates a new Trinity defaults file, with Trinity parameters taken from trinity_input_file, and GS2 parameters taken from gs2_input_file. The file is then moved to the CodeRunner central defaults location, the current folder is configured to use the defaults file.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/trinitycrmod/trinity_gs2.rb', line 56

def self.use_new_defaults_file_with_flux(name = ARGV[-4], trinity_input_file = ARGV[-3], flux_input_file = ARGV[-2], fluxcode=ARGV[-1])
   raise "Please specify a name, a trinity input file and a flux code input file" if name == "use_new_defaults_file_with_flux"
   defaults_filename = "#{name}_defaults.rb"
  tmp_filename = "#{name}_flxtmp_defaults.rb"
  central_defaults_filename = rcp.user_defaults_location + "/" + defaults_filename
  #FileUtils.rm(name + '_defaults.rb') if FileTest.exist?(name + '_defaults.rb')
  #FileUtils.rm(central_defaults_filename) if FileTest.exist?(central_defaults_filename)
  FileUtils.rm(tmp_filename) if FileTest.exist?(tmp_filename)
  raise "Defaults file: #{central_defaults_filename} already exists" if FileTest.exist? central_defaults_filename

    flxclass = flux_class(fluxcode)

  make_new_defaults_file(name, trinity_input_file)
  flxclass.make_new_defaults_file(name + '_flxtmp', flux_input_file)

  File.open(defaults_filename, 'a'){|file| file.puts "@set_flux_defaults_procs.push(Proc.new do\nflux_runs.each do |run|\nrun.instance_eval do\n\#{File.read(tmp_filename).gsub(/\\A|\\n/, \"\\n  \")}\nend\nend\nend)\n\n\n"
  
    }
  FileUtils.mv(defaults_filename, central_defaults_filename)
  FileUtils.rm(tmp_filename)
  CodeRunner.fetch_runner(C: rcp.code, m: (rcp.modlet? ? rcp.modlet : nil), D: name)

end

Instance Method Details

#chease_runObject



5
6
7
8
9
10
11
12
# File 'lib/trinitycrmod/chease.rb', line 5

def chease_run
  CodeRunner.setup_run_class('chease')
  chrun = CodeRunner::Chease.new(@runner)
  raise 'No chease input file' unless FileTest.exist?(chfile=@directory + '/chease/chease_namelist')
  chrun.instance_eval(CodeRunner::Chease.defaults_file_text_from_input_file(chfile))
  #puts ['chrun1', chrun.nsurf, self.class.defaults_file_text_from_input_file(chfile), chfile]
  return chrun
end

#check_flux_optionObject



21
22
23
24
25
# File 'lib/trinitycrmod/check_parameters.rb', line 21

def check_flux_option
  if @flux_option == "gs2"
   error("subfolders must be .true. ") unless @subfolders and @subfolders.fortran_true?
  end
end

#check_geometeryObject



11
12
13
# File 'lib/trinitycrmod/check_parameters.rb', line 11

def check_geometery
  error( "Can't find geo_file #@geo_file (the path of geo file should be either absolute or set relative to the run folder #@directory). If you are not using a geometry file for this run please unset the parameter geo_file.") if @geo_file and not FileTest.exist? @geo_file
end

#check_parallelisationObject



15
16
17
18
19
# File 'lib/trinitycrmod/check_parameters.rb', line 15

def check_parallelisation
  error("nrad must be explicitly specified") unless @nrad
  error("Number of jobs: #{n_flux_tubes_jac} must evenly divide the number of processors: #{actual_number_of_processors} when fork_flag is .true.") if fork_flag_actual.fortran_true? and not actual_number_of_processors%n_flux_tubes_jac == 0

end

#check_parametersObject



3
4
5
6
7
8
9
# File 'lib/trinitycrmod/check_parameters.rb', line 3

def check_parameters

  check_geometery
  check_parallelisation
  check_flux_option

end

#eln_hflux_calibration_graphkit(options) ⇒ Object

Graph of the electron heat calibration factor



135
136
137
138
139
140
# File 'lib/trinitycrmod/graphs.rb', line 135

def eln_hflux_calibration_graphkit(options)
  calibs = Calib.analyse_file("#@directory/#@run_name.calib")
  k = calibs.map{|c| c.qflux_graphkit(1)}.sum
  k.ylabel = 'Qe'
  k
end

#evaluate_defaults_file(filename) ⇒ Object

Override standard CodeRunner method to allow for flux code variables



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/trinitycrmod/trinity_gs2.rb', line 111

def evaluate_defaults_file(filename)
  text = File.read(filename)
  instance_eval(text)
  text.scan(/^\s*@(\w+)/) do
    var_name = $~[1].to_sym
    next if var_name == :defaults_file_description
    unless rcp.variables.include? var_name or (flux_gs2? and Gs2.rcp.variables.include? var_name) or (flux_gryfx? and Gryfx.rcp.variables.include? var_name)
      warning("---#{var_name}---, specified in #{File.expand_path(filename)}, is not a variable. This could be an error")
    end
  end
end

#flux_classObject



142
143
144
# File 'lib/trinitycrmod/trinity_gs2.rb', line 142

def flux_class
  self.class.flux_class(@flux_option)
end

#flux_folder_name(i) ⇒ Object



164
165
166
167
168
169
170
171
172
173
# File 'lib/trinitycrmod/trinity_gs2.rb', line 164

def flux_folder_name(i)
  if i >= n_flux_tubes_jac
    jn = i - n_flux_tubes_jac + 1
    folder = "calibrate_#{jn}"
  else
    jn = i + 1
    folder = "flux_tube_#{jn}"
  end 
  folder
end

#flux_gryfx?Boolean

Is the flux tube code being used gryfx?

Returns:

  • (Boolean)


150
151
152
# File 'lib/trinitycrmod/trinity_gs2.rb', line 150

def flux_gryfx?
  @flux_option == "gryfx"
end

#flux_gs2?Boolean

Is the flux tube code being used gs2?

Returns:

  • (Boolean)


146
147
148
# File 'lib/trinitycrmod/trinity_gs2.rb', line 146

def flux_gs2?
  @flux_option == "gs2"
end

#flux_run_name(i) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# File 'lib/trinitycrmod/trinity_gs2.rb', line 154

def flux_run_name(i)
  if i >= n_flux_tubes_jac
    jn = i - n_flux_tubes_jac + 1
    run_name = "calibrate_" + @run_name + (jn).to_s
  else
    jn = i + 1
    run_name = @run_name + (jn).to_s
  end 
  run_name
end

#flux_runsObject

Generates the component runs for GS2 and returns the hash Raises an error if flux_option != “gs2”

Raises:



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/trinitycrmod/trinity_gs2.rb', line 92

def flux_runs
  raise FluxOptionError.new("flux_runs called and flux_option != gs2 or gryfx") if not (flux_gs2? or flux_gryfx?)
   

  #puts "2@COMMMMMMMMMMMMMPOOOOOOOOOOOOOONNNETN", @component_runs
  generate_component_runs if not (@component_runs and @component_runs.size == n_flux_tubes)
  #p ["@COMMMMMMMMMMMMMPOOOOOOOOOOOOOONNNETN", @component_runs]
  @component_runs
  #@gs2_run_list ||= {}
  #raise TypeError.new("@runner is nil") if @runner.nil?
  #@gs2_run_list[key] ||= Gs2.new(@runner)
  ##if key != :base
    ##raise "key in gs2_run must be either :base or an integer" unless key.kind_of? Integer
    ##@gs2_run_list[key] ||= @gs2_run_list[:base].dup
  ##end
  #@gs2_run_list[key]
end

#generate_component_runsObject



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/trinitycrmod/trinity.rb', line 362

def generate_component_runs
  #puts "HERE"
  @component_runs ||= []
  if flux_gryfx? or flux_gs2?
    fclass = flux_class

    for i in 0...n_flux_tubes
      component = @component_runs[i]
        #p [i, '9,', component, '4', !@component_runs[i]]; STDIN.gets
      if not component
        #p "HEELO"
        #p [i, '3,', component, '4', @component_runs.size]
        component = @component_runs[i] =  fclass.new(@runner, self).create_component
        #component.instance_variable_set(:@output_file, output_file)
        #p [i, '3,', component, '4', @component_runs.size]
        if false
          if i > 0 and @component_runs[i-1]
            component.rcp.variables.each do |var|
              val = @component_runs[i-1].send(var)
              component.set(var, val) if val
            end
          end
        end
      end
      #p [i,'1', component, '2', @component_runs.size]; STDIN.gets
      component = @component_runs[i]
      #p [i,'1', component, '2']; STDIN.gets


      component.component_runs = []
      #component.runner = nil
      #pp component; STDIN.gets
      #component.instance_variables.each{|var| puts var; pp var;  puts Marshal.dump(component.instance_variable_get(var)); STDIN.gets}
      #puts Marshal.dump(component); STDIN.gets
      #pp component; STDIN.gets
      #p component.class
      component.job_no = @job_no
      #component.status = @status
  #p ["HERE2", @component_runs.size, @component_runs[i]]
      #Dir.chdir(@directory) {
        compdir = flux_folder_name(i) #  "flux_tube_#{i+1}"
        # Stop it actually checking the flux codes every time.
        component.instance_variable_set(:@status, :Complete)
        Dir.chdir(compdir){component.process_directory} if FileTest.exist? compdir
      #}
      component.component_runs = []
      component.trinity_run = self
      #@component_runs.push component
      component.real_id = @id
      #@gs2_run_list[i] = component
      #pp component; STDIN.gets
      #component.runner = nil
      #puts Marshal.dump(component); STDIN.gets
      #pp component; STDIN.gets
      #component.component_runs = []
    end
  end
end

#generate_flux_input_filesObject

Writes the gs2 input files, creating separate subfolders for them if @subfolders is .true.



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/trinitycrmod/trinity.rb', line 274

def generate_flux_input_files
  # At the moment we must use subfolders
  for i in 0...n_flux_tubes
    #gs2run = gs2_run(:base).dup
    #gs2_run(i).instance_variables.each do |var|
      #gs2run.instance_variable_set(var, gs2_run(i).instance_variable_get(var))
    #end
    fluxrun = flux_runs[i]
    #ep ['gs2_runs[i] in generate', gs2_runs[i].nwrite]
    #p ['i',i]
    #if i >= n_flux_tubes_jac
      #jn = i - n_flux_tubes_jac + 1
      #run_name = "calibrate_" + @run_name + (jn).to_s
      #folder = "calibrate_#{jn}"
    #else
      #jn = i + 1
      #run_name = @run_name + (jn).to_s
      #folder = "flux_tube_#{jn}"
    #end

    folder = flux_folder_name(i)
    run_name = flux_run_name(i)

    if @subfolders and @subfolders.fortran_true?
      fluxrun.directory = @directory + "/" + folder
      FileUtils.makedirs(fluxrun.directory)
      fluxrun.relative_directory = @relative_directory + "/" + folder
      fluxrun.restart_dir = fluxrun.directory + "/nc"
    else
      fluxrun.directory = @directory
      fluxrun.relative_directory = @relative_directory
    end
    fluxrun.run_name = run_name
    fluxrun.nprocs = @nprocs
    if i==0
      block = Proc.new{check_parameters}
    else
      block = Proc.new{}
    end
    #if @restart_id
      #gs2run.restart_id =
    Dir.chdir(fluxrun.directory) do
      fluxrun.generate_input_file(&block)
      fluxrun.write_info
    end

    ### Hack the input file so that gs2 gets the location of
    # the restart dir correctly within trinity
    if @subfolders and @subfolders.fortran_true? 
      infile = fluxrun.directory + "/" + fluxrun.run_name + ".in"
      text = File.read(infile)
      File.open(infile, 'w'){|f| f.puts text.sub(/restart_dir\s*=\s*"nc"/, "restart_dir = \"#{folder}/nc\"")}
    end
  end
end

#generate_input_fileObject

This is a hook which gets called just before submitting a simulation. It sets up the folder and generates any necessary input files.



164
165
166
167
168
169
170
171
172
173
# File 'lib/trinitycrmod/trinity.rb', line 164

def generate_input_file
    @run_name += "_t"
    if @restart_id
      @runner.run_list[@restart_id].restart(self)
    end
    setup_chease if uses_chease?
    check_parameters
    write_input_file
    generate_flux_input_files if flux_gs2? or flux_gryfx?
end

#generate_run_nameObject

Override CodeRunner::Run method to deal with flux_pars properly when generating run_name



228
229
230
231
232
233
234
235
236
237
238
# File 'lib/trinitycrmod/trinity.rb', line 228

def generate_run_name
    @run_name = %[v#@version] + @naming_pars.inject("") do |str, par|
      case par
      when :flux_pars
        str+="_flx_#{send(par).map{|k,v| "#{k}_#{v.to_s[0..8]}"}.join("_")}}"
      else
        str+="_#{par}_#{send(par).to_s[0...8]}"
      end
    end
    @run_name = @run_name.gsub(/\s+/, "_").gsub(/[\/{}"><:=]/, '') + "_id_#@id"
end

#get_1d_array_float(outfile, column_header) ⇒ Object



58
59
60
61
62
# File 'lib/trinitycrmod/output_files.rb', line 58

def get_1d_array_float(outfile, column_header)
  cache[:array_1d] = {} unless [:Complete, :Failed].include? @status
  cache[:array_1d] ||= {}
  cache[:array_1d][[outfile, column_header]] ||= send(outfile + :_outfile).get_1d_array_float(column_header)
end

#get_2d_array_float(outfile, column_header, index_header) ⇒ Object

Return a two-dimensional array of floatingpoint numbers from the file ending in outfile,

from the column whose header matches column_header,  indexed by index_header. See
TextDataTools::Column::DataFile for more information. Outfile is a symbol, use e.g. :nt 
for data from 'run_name.nt'.


52
53
54
55
56
# File 'lib/trinitycrmod/output_files.rb', line 52

def get_2d_array_float(outfile, column_header, index_header)
  cache[:array_2d] = {} unless [:Complete, :Failed].include? @status
  cache[:array_2d] ||= {}
  cache[:array_2d][[outfile, column_header, index_header]] ||= send(outfile + :_outfile).get_2d_array_float(column_header, index_header)
end

#get_completed_timestepsObject



458
459
460
461
462
463
464
# File 'lib/trinitycrmod/trinity.rb', line 458

def get_completed_timesteps
  Dir.chdir(@directory) do
    @completed_timesteps = time_outfile.exists? ?
      time_outfile.get_1d_array_integer(/itstep/).max :
      0
  end
end

#get_global_resultsObject



467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/trinitycrmod/trinity.rb', line 467

def get_global_results
  @fusionQ = info_outfile.get_variable_value('Q').to_f
  @pfus = info_outfile.get_variable_value(/fusion\s+power/i).to_f
  @pnet = info_outfile.get_variable_value(/net\s+power/i).to_f
  @aux_power = info_outfile.get_variable_value(/aux.*\s+power/i).to_f
  @alpha_power = info_outfile.get_variable_value(/alpha\s+power/i).to_f
  @rad_power = info_outfile.get_variable_value(/radiated\s+power/i).to_f
  @ne0 = info_outfile.get_variable_value(/core\s+density/i).to_f
  @ti0 = info_outfile.get_variable_value(/core\s+T_i/i).to_f
  @te0 = info_outfile.get_variable_value(/core\s+T_e/i).to_f
  @omega0 = info_outfile.get_variable_value(/core\s+omega/i).to_f rescue 0.0 # Old info files don't have omega
  #p 'send(fusionQ)', send(:fusionQ)
end

#get_statusObject



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# File 'lib/trinitycrmod/trinity.rb', line 436

def get_status
  if @running
    get_completed_timesteps
    if completed_timesteps == 0
      @status = :NotStarted
    else
      @status = :Incomplete
    end
  else
    get_completed_timesteps
    if @completed_timesteps == @ntstep
      @status = :Complete
    else
      if FileTest.exist?(output_file) and File.read(output_file) =~/trinity\s+finished/i
        @status = :Complete
      else
        @status = :Failed
      end
    end
  end
end

#graphkit(name, options) ⇒ Object

This is the hook that is called by CodeRunner, providing the graphkit with the given name and functions to the CodeRunner framework



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/trinitycrmod/graphs.rb', line 192

def graphkit(name, options)
  [:t].each do |var|
    #ep 'index', var
    if options[var].class == Symbol and options[var] == :all
      options[var] = list(var).values
    elsif options[var+:_index].class == Symbol and options[var+:_index] == :all
      #ep 'Symbol'
      options[var+:_index] = list(var).keys
    end
    if options[var].class == Array
      return options[var].map{|value| graphkit(name, options.dup.absorb({var =>  value}))}.sum
    elsif options[var+:_index].class == Array
      #ep 'Array'
      return options[var+:_index].map{|value| graphkit(name, options.dup.absorb({var+:_index =>  value}))}.sum
    end
    if options[var].class == Symbol and options[var] == :max
      options[var] = list(var).values.max
    elsif options[var+:_index].class == Symbol and options[var+:_index] == :max
      ep 'Symbol'
      options[var+:_index] = list(var).keys.max
    end
  end
  if (meth = TrinityGraphKits.instance_methods.find{|m| m.to_s == name + '_graphkit'} or 
      meth = TrinityMultiKits.instance_methods.find{|m| m.to_s == name + '_graphkit'})
    return send(meth, options)
  elsif name =~ /^nc_/
    return smart_graphkit(options.absorb({graphkit_name: name}))
  else
    raise "GraphKit not found: #{name}"
  end 
end

#gs2_run_timesObject

An array of arrays containing the GS2 run times for each iteration. Produced unscientifically by scanning the stdout.

Raises:



125
126
127
128
129
130
131
132
# File 'lib/trinitycrmod/trinity_gs2.rb', line 125

def gs2_run_times
  raise FluxOptionError.new("gs2_run_times called and flux_option != gs2") if not flux_gs2?
  run_times = []
  File.open(@directory + '/' + output_file, "r").each_line{|l| l.scan(/Job.*timer.*(\b\d+\.\d+\b)/){run_times.push $~[1].to_f}}
  sz = run_times.size.to_f
  return run_times.pieces((sz / n_flux_tubes.to_f).ceil)

end

#input_file_extensionObject



563
564
565
# File 'lib/trinitycrmod/trinity.rb', line 563

def input_file_extension
  '.trin'
end

#input_file_headerObject



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/trinitycrmod/trinity.rb', line 511

def input_file_header
  "!==============================================================================\n!     Trinity INPUT FILE automatically generated by CodeRunner\n!==============================================================================\n!\n!  Trinity is a multiscale turbulent transport code for fusion plasmas.\n!\n!   See http://gyrokinetics.sourceforge.net\n!\n!  CodeRunner is a framework for the automated running and analysis\n!  of large simulations.\n!\n!   See http://coderunner.sourceforge.net\n!\n!  Created \#{Time.now.to_s}\n!      by CodeRunner version \#{CodeRunner::CODE_RUNNER_VERSION.to_s}\n!\n!==============================================================================\n\n"
end

#ion_hflux_calibration_graphkit(options) ⇒ Object

Graph of the ion heat calibration factor



128
129
130
131
132
133
# File 'lib/trinitycrmod/graphs.rb', line 128

def ion_hflux_calibration_graphkit(options)
  calibs = Calib.analyse_file("#@directory/#@run_name.calib")
  k = calibs.map{|c| c.qflux_graphkit(0)}.sum
  k.ylabel = 'Qi'
  k
end

#list(var) ⇒ Object

Returns a hash of the specified dimension in the form value where index is 1-based Dimension can be: :t :rho :rho_cc



69
70
71
72
73
74
75
76
# File 'lib/trinitycrmod/output_files.rb', line 69

def list(var)
  case var
  when :t
    hash  = {}
    get_2d_array_float(:nt, /1:\s+time/, /1:\s+time/).map{|arr| arr[0]}.each_with_index{|t,i| hash[i+1] = t}
    hash
  end
end

#n_flux_tubesObject



263
264
265
266
267
268
269
270
# File 'lib/trinitycrmod/trinity.rb', line 263

def n_flux_tubes
  if @neval_calibrate and @neval_calibrate > 0
    raise "neval_calibrate set but ncc_calibrate not set" unless @ncc_calibrate
    n_flux_tubes_jac + @ncc_calibrate
  else
    n_flux_tubes_jac
  end
end

#n_flux_tubes_jacObject

The number of separate flux tube results needed for the jacobian



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/trinitycrmod/trinity.rb', line 241

def n_flux_tubes_jac
  d1 = dflx_stencil_actual - 1
  ngrads =d1 * case @grad_option
                when "tigrad", "ngrad", "lgrad"
                  1
                when "tgrads"
                  2
                when "ltgrads", "ntgrads"
                  3
                when "all"
                  4
                else
                  raise "unknown grad_option: #@grad_option"
                end
  if evolve_grads_only_actual.fortran_true?
    njac = ngrads + 1
  else
    njac = 2*ngrads+1
  end
  #p 'nraaad', @nrad
  (@nrad-1) * njac
end

#netcdf_smart_readerObject



142
143
144
# File 'lib/trinitycrmod/read_netcdf.rb', line 142

def netcdf_smart_reader
  NetcdfSmartReader.new(new_netcdf_file)
end

#parameter_stringObject

Parameters which follow the Trinity executable, in this case just the input file.



355
356
357
# File 'lib/trinitycrmod/trinity.rb', line 355

def parameter_string
  @run_name + ".trin"
end

#parameter_transitionObject



359
360
# File 'lib/trinitycrmod/trinity.rb', line 359

def parameter_transition
end

#pflux_calibration_graphkit(options) ⇒ Object

Graph of the particle flux calibration factor



142
143
144
145
146
147
# File 'lib/trinitycrmod/graphs.rb', line 142

def pflux_calibration_graphkit(options)
  calibs = Calib.analyse_file("#@directory/#@run_name.calib")
  k = calibs.map{|c| c.pflux_graphkit(1)}.sum
  k.ylabel = 'Gamma'
  k
end

A hook which gets called when printing the standard run information to the screen using the status command.



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/trinitycrmod/trinity.rb', line 74

def print_out_line
  #p ['id', id, 'ctd', ctd]
  #p rcp.results.zip(rcp.results.map{|r| send(r)})
  name = @run_name
  name += " (res: #@restart_id)" if @restart_id
  name += " real_id: #@real_id" if @real_id
  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, "%")
  if ctd
    beginning += sprintf("Q:%f, Pfusion:%f MW, Ti0:%f keV, Te0:%f keV, n0:%f x10^20", fusionQ, pfus, ti0, te0, ne0)
  end
  beginning += "  ---#{@comment}" if @comment
  beginning
end

#process_directory_code_specificObject

This method, as its name suggests, is called whenever CodeRunner is asked to analyse a run directory. This happens if the run status is not :Complete, or if the user has specified recalc_all(-A on the command line) or reprocess_all (-a on the command line).



426
427
428
429
430
431
432
433
434
# File 'lib/trinitycrmod/trinity.rb', line 426

def process_directory_code_specific
  get_status
  #p ['id is', id, 'ctd is ', ctd]
  if ctd
    get_global_results
  end
  #p ['fusionQ is ', fusionQ]
  @percent_complete = completed_timesteps.to_f / ntstep.to_f * 100.0
end

#restart(new_run) ⇒ Object

Modify new_run so that it becomes a restart of self. Adusts all the parameters of the new run to be equal to the parameters of the run that calls this function, and sets up its run name correctly



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/trinitycrmod/trinity.rb', line 100

def restart(new_run)
  #new_run = self.dup
  (rcp.variables).each{|v| new_run.set(v, send(v)) if send(v) or new_run.send(v)}
  if @flux_option == "gs2"
    flux_runs.each_with_index do |run, i|
      CodeRunner::Gs2.rcp.variables.each{|v|
        next if [:ginit_option, :delt_option].include? v and new_run.no_restart_gs2
        new_run.flux_runs[i].set(v, run.send(v)) if run.send(v) or new_run.flux_runs[i].send(v)
      }
    end
  end
  @naming_pars.delete(:preamble)
  SUBMIT_OPTIONS.each{|v| new_run.set(v, self.send(v)) unless new_run.send(v)}
  #(rcp.results + rcp.gs2_run_info).each{|result| new_run.set(result, nil)}
  new_run.is_a_restart = true
  new_run.restart_id = @id
  new_run.restart_run_name = @run_name
  new_run.init_option = "restart"
  new_run.iternt_file = @run_name + ".iternt"
  new_run.iterflx_file = @run_name + ".iterflx"
  new_run.itercalib_file = @run_name + ".itercalib"
  new_run.init_file = @run_name + ".tmp"
  @runner.nprocs = @nprocs if @runner.nprocs == "1" # 1 is the default so this means the user probably didn't specify nprocs
  # This is unnecessary for single restart file.
  warning( "Restart is not on the same number of processors as the previous run: new is #{new_run.nprocs.inspect} and old is #{@nprocs.inspect}... this is only OK if you are using parallel netcdf and single restart files.") if flux_gs2? and not new_run.no_restart_gs2 and (!new_run.nprocs or new_run.nprocs != @nprocs)
  raise "Restart cannot have a different sized jacobian: new is #{new_run.n_flux_tubes_jac} and old is #{n_flux_tubes_jac}" unless new_run.n_flux_tubes_jac == n_flux_tubes_jac
#   @runner.parameters.each{|var, value| new_run.set(var,value)} if @runner.parameters
#   ep @runner.parameters
  new_run.run_name = nil
  new_run.naming_pars = @naming_pars
  new_run.update_submission_parameters(new_run.parameter_hash.inspect, false) if new_run.parameter_hash
  new_run.naming_pars.delete(:restart_id)
  new_run.generate_run_name
  new_run.run_name += '_t'
  eputs 'Copying Trinity Restart files', ''
  #system "ls #@directory"
  ['iternt', 'iterflx', 'tmp', 'itercalib'].each do |ext|
    next if ext=='itercalib' and not FileTest.exist?("#@directory/#@run_name.#{ext}")
    # Unlike gs2, trinity always uses the current run name to generate the
    # restart files. Thus, the name of the restart files changes with every
    # run.
    FileUtils.cp("#@directory/#@run_name.#{ext}", "#{new_run.directory}/.")
  end
  if (new_run.flux_gs2? and flux_gs2?) and not new_run.no_restart_gs2
    for i in 0...n_flux_tubes
      break if i >= new_run.n_flux_tubes
      folder = flux_folder_name(i)

      new_run.flux_runs[i].directory = new_run.directory + "/#{folder}"
      FileUtils.makedirs(new_run.flux_runs[i].directory)
      flux_runs[i].restart(new_run.flux_runs[i])
      if new_run.neval_calibrate and new_run.neval_calibrate > 0 and 
        new_run.flux_runs[i].nonlinear_mode == "off" 

        new_run.flux_runs[i].ginit_option = "noise"
        new_run.flux_runs[i].delt_option = "default"
        new_run.flux_runs[i].is_a_restart = false
        new_run.flux_runs[i].restart_id = nil
      end
    end
  end
  new_run
end

#run_heuristic_analysisObject

Raises:

  • (CRMild)


550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/trinitycrmod/trinity.rb', line 550

def run_heuristic_analysis
  ep 'run_heuristic_analysis', Dir.pwd
  infiles = Dir.entries.grep(/^[^\.].*\.trin$/)
  ep infiles
  raise CRMild.new('No input file') unless infiles[0]
  raise CRError.new("More than one input file in this directory: \n\t#{infiles}") if infiles.size > 1
  input_file = infiles[0]
  #ep 'asdf'
  @nprocs ||= "1"
  @executable ||= "/dev/null"
  make_info_file(input_file, false)
end

#setup_cheaseObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/trinitycrmod/chease.rb', line 13

def setup_chease
  ep "Setting up chease files..."
   if evolve_geometry.fortran_true?
     FileUtils.cp_r(@gs_folder, 'chease')
     chrun = chease_run
     chrun.neqdsk = 0 # Use EXPEQ
     chrun.nsurf = 6
     puts ['chrun2', chrun.nsurf]
     chrun.nppfun = 4 # Pres profile from EXPEQ
     chrun.nfunc = 4 # Current func
     chrun.nopt = -1 # Use prev soln for initial 
     Dir.chdir(@directory + '/chease/'){chrun.write_input_file}
   else
     FileUtils.mkdir('chease') unless FileTest.exist? 'chease'
     origfile = @runner.root_folder + '/ogyropsi.dat'
     FileUtils.cp(origfile, 'chease/ogyropsi.dat') if FileTest.exist? origfile
   end
end

#smart_graphkit(options) ⇒ Object



146
147
148
149
150
151
152
153
154
155
# File 'lib/trinitycrmod/read_netcdf.rb', line 146

def smart_graphkit(options)
  case options[:command]
  when :help
    "A smart graphkit is a direct plot of a given variable from the new netcdf file. The name of the graphkit is the name of the variable prefixed by 'cdf_'. To plot, for example, the heat flux vs time, you would give the graph name cdf_heat_flux_tot. You can use index specifiers in the the options; for example, to plot the potential as a function of kx and ky for a given time index, you would use the graph name cdf_phi2_by_mode, and the options {t_index: n}. To plot the potential as function of kx for a given ky and time would use the options {t_index, n, Y_index: m}. For each dimension you can specify the index, or a minium and/or maximum."
  when :options
    [:nmat_index, :t_index, :tspec_index, :iter_index]
  else
    netcdf_smart_reader.graphkit(options[:graphkit_name].sub(/^nc_/, ''), options)
  end
end

#update_submission_parameters(parameters, start_from_defaults = true) ⇒ Object

Update submission parameters in the normal way then deal with parameters for the flux code. Each flux code will behave differently.

  • Gs2 flux_pars: 43, delt: {1=> 0.01, 2=>0.05}

will set nx for all runs to be 43, and delt for run 1 to 0.01, delt
for run 2 to be 0.05


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/trinitycrmod/trinity.rb', line 183

def update_submission_parameters(parameters, start_from_defaults=true)
  @set_flux_defaults_procs ||= []
  super(parameters, start_from_defaults)
  if flux_gs2? or flux_gryfx?
    raise "No set_flux_defaults_procs defined" unless @set_flux_defaults_procs.size > 0
    @set_flux_defaults_procs.each{|prc| prc.call}
    flux_parameter_hashes = {}
    if @flux_pars
      @flux_pars.each do |par, val|
        if val.kind_of? Hash
          #val.each{|n,v| gs2_runs[n].set(par, v)}
          val.each do |n,v|
            if n == :jac
              range =  0...n_flux_tubes_jac
            elsif n == :calib
              range =  n_flux_tubes_jac...n_flux_tubes
            else
              range = n..n
            end
            for i in range
              flux_parameter_hashes[i] ||= {}
              flux_parameter_hashes[i][par] = v
            end
            #gs2_parameter_hashes[n] ||= {}
            #gs2_parameter_hashes[n][par] = v
          end
        else
          for i in 0...n_flux_tubes
            #gs2_runs.each{|r| r.set(par, val)}
            flux_parameter_hashes[i] ||= {}
            flux_parameter_hashes[i][par] = val
          end
        end
      end
    end
    for i in 0...n_flux_tubes
      flux_runs[i].parameter_hash = (flux_parameter_hashes[i] || {}).inspect
      flux_runs[i].update_submission_parameters(flux_runs[i].parameter_hash, false)
    end
  end
  self
end

#uses_chease?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/trinitycrmod/chease.rb', line 2

def uses_chease?
  @geo_option == "chease" or @init_option == "chease" or @species_option == "chease"
end

#vim_outputObject Also known as: vo



344
345
346
# File 'lib/trinitycrmod/trinity.rb', line 344

def vim_output
  system "vim -Ro #{output_file} #{error_file} #@directory/#@run_name.error #@directory/#@run_name.out "
end

#watch_calibration_statusObject



330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/trinitycrmod/trinity.rb', line 330

def watch_calibration_status
  if @flux_option == "gs2"
    command = gs2_runs.map{|r| 
      FileTest.exist?(fn="#{r.directory}/#{r.run_name}.out.nc") ?
      "ncdump #{fn} | grep UNLIM" : nil
    }.compact
    command = "watch '#{command.join(' && ')}'"
    puts command
    system command
  else
    raise "watch_calibration_status only implemented for gs2"
  end
end

#write_input_fileObject

This command uses the infrastructure provided by Run::FortranNamelist, provided by CodeRunner itself.



350
351
352
# File 'lib/trinitycrmod/trinity.rb', line 350

def write_input_file
  File.open(@run_name + ".trin", 'w'){|file| file.puts input_file_text}
end