Class: CodeRunner::Trinity
- Inherits:
-
Run::FortranNamelist
- Object
- Run::FortranNamelist
- CodeRunner::Trinity
- Includes:
- ActualParameterValues, OutputFiles, TrinityGraphKits
- Defined in:
- lib/trinitycrmod/trinity.rb,
lib/trinitycrmod/trinity_gs2.rb,
lib/trinitycrmod/output_files.rb,
lib/trinitycrmod/check_parameters.rb,
lib/trinitycrmod/actual_parameter_values.rb,
lib/trinitycrmod/graphs.rb,
lib/trinitycrmod/chease.rb
Overview
This is a customised subclass of the CodeRunner::Run class which allows CodeRunner to run and analyse the multiscale gyrokinetic turbulent transport solver Trinity.
It generates the Trinity input file, and both analyses the results and allows easy plotting of them. It also interfaces with the GS2 CodeRunner module to allow analysis of the individual GS2 results if GS2 is being used as the flux code.
Defined Under Namespace
Modules: ActualParameterValues, OutputFiles, TrinityGraphKits Classes: FluxOptionError
Class Method Summary collapse
- .defaults_file_header ⇒ Object
- .get_input_help_from_source_code(source_folder) ⇒ Object
-
.use_new_defaults_file_with_gs2(name = ARGV[-3], trinity_input_file = ARGV[-2], gs2_input_file = 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.
Instance Method Summary collapse
- #check_flux_option ⇒ Object
- #check_geometery ⇒ Object
- #check_parallelisation ⇒ Object
- #check_parameters ⇒ Object
-
#evaluate_defaults_file(filename) ⇒ Object
Override standard CodeRunner method to allow for Gs2 variables.
-
#flux_gs2? ⇒ Boolean
Is the flux tube code being used gs2?.
- #generate_component_runs ⇒ Object
-
#generate_gs2_input_files ⇒ Object
Writes the gs2 input files, creating separate subfolders for them if @subfolders is .true.
-
#generate_input_file ⇒ Object
This is a hook which gets called just before submitting a simulation.
-
#generate_run_name ⇒ Object
Override CodeRunner::Run method to deal with flux_pars properly when generating run_name.
-
#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.
- #get_completed_timesteps ⇒ Object
- #get_global_results ⇒ Object
- #get_status ⇒ Object
-
#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.
- #gs2_folder_name(i) ⇒ Object
- #gs2_run_name(i) ⇒ Object
-
#gs2_run_times ⇒ Object
An array of arrays containing the GS2 run times for each iteration.
-
#gs2_runs ⇒ Object
Generates the component runs for GS2 and returns the hash Raises an error if flux_option != “gs2”.
- #input_file_extension ⇒ Object
- #input_file_header ⇒ Object
-
#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.
- #n_flux_tubes ⇒ Object
-
#n_flux_tubes_jac ⇒ Object
The number of separate flux tube results needed for the jacobian.
-
#parameter_string ⇒ Object
Parameters which follow the Trinity executable, in this case just the input file.
- #parameter_transition ⇒ Object
-
#print_out_line ⇒ Object
A hook which gets called when printing the standard run information to the screen using the status command.
-
#process_directory_code_specific ⇒ Object
This method, as its name suggests, is called whenever CodeRunner is asked to analyse a run directory.
-
#restart(new_run) ⇒ Object
Modify new_run so that it becomes a restart of self.
- #run_heuristic_analysis ⇒ Object
- #save ⇒ Object
- #setup_chease ⇒ Object
-
#update_submission_parameters(parameters, start_from_defaults = true) ⇒ Object
Update submission parameters in the normal way then deal with parameters for the flux code.
- #uses_chease? ⇒ Boolean
- #vim_output ⇒ Object (also: #vo)
-
#write_input_file ⇒ Object
This command uses the infrastructure provided by Run::FortranNamelist, provided by CodeRunner itself.
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, #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, #info_outfile, #nt_outfile, #pbalance_outfile, #pwr_outfile, #time_outfile, #view_outfiles
Class Method Details
.defaults_file_header ⇒ Object
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/trinitycrmod/trinity.rb', line 534 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 |
.get_input_help_from_source_code(source_folder) ⇒ Object
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 510 |
# File 'lib/trinitycrmod/trinity.rb', line 482 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 |
.use_new_defaults_file_with_gs2(name = ARGV[-3], trinity_input_file = ARGV[-2], gs2_input_file = 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.
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 |
# File 'lib/trinitycrmod/trinity_gs2.rb', line 50 def self.use_new_defaults_file_with_gs2(name = ARGV[-3], trinity_input_file = ARGV[-2], gs2_input_file = ARGV[-1]) raise "Please specify a name, a trinity input file and a gs2 input file" if name == "use_new_gs2_defaults_file" defaults_filename = "#{name}_defaults.rb" tmp_filename = "#{name}_gs2tmp_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 make_new_defaults_file(name, trinity_input_file) CodeRunner::Gs2.make_new_defaults_file(name + '_gs2tmp', gs2_input_file) File.open(defaults_filename, 'a'){|file| file.puts "gs2_runs.each do |run|\nrun.instance_eval do\n\#{File.read(tmp_filename).gsub(/\\A|\\n/, \"\\n \")}\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
#check_flux_option ⇒ Object
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_geometery ⇒ Object
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_parallelisation ⇒ Object
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_parameters ⇒ Object
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 |
#evaluate_defaults_file(filename) ⇒ Object
Override standard CodeRunner method to allow for Gs2 variables
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/trinitycrmod/trinity_gs2.rb', line 101 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) warning("---#{var_name}---, specified in #{File.expand_path(filename)}, is not a variable. This could be an error") end end end |
#flux_gs2? ⇒ Boolean
Is the flux tube code being used gs2?
125 126 127 |
# File 'lib/trinitycrmod/trinity_gs2.rb', line 125 def flux_gs2? @flux_option == "gs2" end |
#generate_component_runs ⇒ Object
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 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/trinitycrmod/trinity.rb', line 343 def generate_component_runs #puts "HERE" @component_runs ||= [] if @flux_option == "gs2" #puts "HERE" #puts "generate_component_runs", @component_runs.size, @runner.run_list.size, caller.to_a.slice(0..9) #puts @component_runs[1].ginit_option if @component_runs.size > 0 #STDIN.gets 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] = Gs2::TrinityComponent.new(@runner, self).create_component #component.instance_variable_set(:@output_file, output_file) #p [i, '3,', component, '4', @component_runs.size] 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 #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 = gs2_folder_name(i) # "flux_tube_#{i+1}" 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_gs2_input_files ⇒ Object
Writes the gs2 input files, creating separate subfolders for them if @subfolders is .true.
269 270 271 272 273 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 |
# File 'lib/trinitycrmod/trinity.rb', line 269 def generate_gs2_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 gs2run = gs2_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 = gs2_folder_name(i) run_name = gs2_run_name(i) if @subfolders and @subfolders.fortran_true? gs2run.directory = @directory + "/" + folder FileUtils.makedirs(gs2run.directory) gs2run.relative_directory = @relative_directory + "/" + folder gs2run.restart_dir = gs2run.directory + "/nc" else gs2run.directory = @directory gs2run.relative_directory = @relative_directory end gs2run.run_name = run_name gs2run.nprocs = @nprocs if i==0 block = Proc.new{check_parameters} else block = Proc.new{} end #if @restart_id #gs2run.restart_id = Dir.chdir(gs2run.directory) do gs2run.generate_input_file(&block) gs2run.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 = gs2run.directory + "/" + gs2run.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_file ⇒ Object
This is a hook which gets called just before submitting a simulation. It sets up the folder and generates any necessary input files.
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/trinitycrmod/trinity.rb', line 162 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_gs2_input_files if @flux_option == "gs2" end |
#generate_run_name ⇒ Object
Override CodeRunner::Run method to deal with flux_pars properly when generating run_name
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/trinitycrmod/trinity.rb', line 223 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_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'.
48 49 50 51 52 |
# File 'lib/trinitycrmod/output_files.rb', line 48 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_timesteps ⇒ Object
459 460 461 462 463 464 465 |
# File 'lib/trinitycrmod/trinity.rb', line 459 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_results ⇒ Object
468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/trinitycrmod/trinity.rb', line 468 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_status ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/trinitycrmod/trinity.rb', line 437 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
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 |
# File 'lib/trinitycrmod/graphs.rb', line 101 def graphkit(name, ) [:t].each do |var| #ep 'index', var if [var].class == Symbol and [var] == :all [var] = list(var).values elsif [var+:_index].class == Symbol and [var+:_index] == :all #ep 'Symbol' [var+:_index] = list(var).keys end if [var].class == Array return [var].map{|value| graphkit(name, .dup.absorb({var => value}))}.sum elsif [var+:_index].class == Array #ep 'Array' return [var+:_index].map{|value| graphkit(name, .dup.absorb({var+:_index => value}))}.sum end if [var].class == Symbol and [var] == :max [var] = list(var).values.max elsif [var+:_index].class == Symbol and [var+:_index] == :max ep 'Symbol' [var+:_index] = list(var).keys.max end end if meth = TrinityGraphKits.instance_methods.find{|m| m.to_s == name + '_graphkit'} return send(meth, ) else raise "GraphKit not found: #{name}" end end |
#gs2_folder_name(i) ⇒ Object
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/trinitycrmod/trinity_gs2.rb', line 139 def gs2_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 |
#gs2_run_name(i) ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/trinitycrmod/trinity_gs2.rb', line 129 def gs2_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 |
#gs2_run_times ⇒ Object
An array of arrays containing the GS2 run times for each iteration. Produced unscientifically by scanning the stdout.
115 116 117 118 119 120 121 122 |
# File 'lib/trinitycrmod/trinity_gs2.rb', line 115 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 |
#gs2_runs ⇒ Object
Generates the component runs for GS2 and returns the hash Raises an error if flux_option != “gs2”
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/trinitycrmod/trinity_gs2.rb', line 83 def gs2_runs raise FluxOptionError.new("gs2_runs called and flux_option != gs2") if not flux_gs2? #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 |
#input_file_extension ⇒ Object
564 565 566 |
# File 'lib/trinitycrmod/trinity.rb', line 564 def input_file_extension '.trin' end |
#input_file_header ⇒ Object
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'lib/trinitycrmod/trinity.rb', line 512 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 |
#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
59 60 61 62 63 64 65 66 |
# File 'lib/trinitycrmod/output_files.rb', line 59 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_tubes ⇒ Object
258 259 260 261 262 263 264 265 |
# File 'lib/trinitycrmod/trinity.rb', line 258 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_jac ⇒ Object
The number of separate flux tube results needed for the jacobian
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/trinitycrmod/trinity.rb', line 236 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 |
#parameter_string ⇒ Object
Parameters which follow the Trinity executable, in this case just the input file.
336 337 338 |
# File 'lib/trinitycrmod/trinity.rb', line 336 def parameter_string @run_name + ".trin" end |
#parameter_transition ⇒ Object
340 341 |
# File 'lib/trinitycrmod/trinity.rb', line 340 def parameter_transition end |
#print_out_line ⇒ Object
A hook which gets called when printing the standard run information to the screen using the status command.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/trinitycrmod/trinity.rb', line 69 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_specific ⇒ Object
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).
427 428 429 430 431 432 433 434 435 |
# File 'lib/trinitycrmod/trinity.rb', line 427 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
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 |
# File 'lib/trinitycrmod/trinity.rb', line 95 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" gs2_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.gs2_runs[i].set(v, run.send(v)) if run.send(v) or new_run.gs2_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. raise "Restart must be on the same number of processors as the previous run: new is #{new_run.nprocs.inspect} and old is #{@nprocs.inspect}" if 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}") FileUtils.cp("#@directory/#@run_name.#{ext}", "#{new_run.directory}/.") end if new_run.flux_option == "gs2" and @flux_option == "gs2" and not new_run.no_restart_gs2 for i in 0...n_flux_tubes break if i >= new_run.n_flux_tubes #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 = gs2_folder_name(i) new_run.gs2_runs[i].directory = new_run.directory + "/#{folder}" FileUtils.makedirs(new_run.gs2_runs[i].directory) #ep ['gs2_runs[i] before', gs2_runs[i].nwrite, new_run.gs2_runs[i].nwrite, new_run.gs2_runs[i].parameter_hash] gs2_runs[i].restart(new_run.gs2_runs[i]) #ep ['gs2_runs[i] after', gs2_runs[i].nwrite, new_run.gs2_runs[i].nwrite, new_run.gs2_runs[i].parameter_hash] #new_run.gs2_runs[i].run_name = new_run.run_name + (i+1).to_s end end #@runner.submit(new_run) new_run end |
#run_heuristic_analysis ⇒ Object
551 552 553 554 555 556 557 558 559 560 561 562 |
# File 'lib/trinitycrmod/trinity.rb', line 551 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 |
#save ⇒ Object
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/trinitycrmod/trinity.rb', line 402 def save #@gs2_run_list.values.each{|r| r.runner = nil; r.component_runs = []} if @gs2_run_list.kind_of? Hash super #@gs2_run_list.values.each{|r| r.runner = @runner} if @gs2_run_list.kind_of? Hash #logf(:save) #raise CRFatal.new("Something has gone horribly wrong: runner.class is #{@runner.class} instead of CodeRunner") unless @runner.class.to_s == "CodeRunner" #runner, @runner = @runner, nil #@system_triers, old_triers = nil, @system_triers #@component_runs.each{|run| run.runner = nil; run.component_runs = []} if @component_runs ##@component_runs.each{|run| run.runner = nil} if @component_runs ## logi(self) ##pp self ##@component_runs.each{|ph| ph.instance_variables.each{|var| puts var; pp ph.instance_variable_get(var); STDIN.gets; puts ph.Marshal.dump(instance_variable_get(var))}} if @component_runs ##instance_variables.each{|var| puts var; instance_variable_get(var); puts Marshal.dump(instance_variable_get(var)); STDIN.gets} #Dir.chdir(@directory){File.open(".code_runner_run_data", 'w'){|file| file.puts Marshal.dump(self)}} #@runner = runner #@component_runs.each{|run| run.runner = runner} if @component_runs #@system_triers = old_triers end |
#setup_chease ⇒ Object
5 6 7 8 9 10 |
# File 'lib/trinitycrmod/chease.rb', line 5 def setup_chease ep "Setting up chease files..." FileUtils.mkdir('chease') unless FileTest.exist? 'chease' origfile = @runner.root_folder + '/ogyropsi.dat' FileUtils.cp(origfile, 'chease/ogyropsi.dat') if FileTest.exist? origfile 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
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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/trinitycrmod/trinity.rb', line 181 def update_submission_parameters(parameters, start_from_defaults=true) super(parameters, start_from_defaults) if @flux_pars gs2_parameter_hashes = {} @flux_pars.each do |par, val| if @flux_option == "gs2" 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 gs2_parameter_hashes[i] ||= {} gs2_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)} gs2_parameter_hashes[i] ||= {} gs2_parameter_hashes[i][par] = val end end for i in 0...n_flux_tubes gs2_runs[i].parameter_hash = (gs2_parameter_hashes[i] || {}).inspect gs2_runs[i].update_submission_parameters(gs2_runs[i].parameter_hash, false) end end end end self end |
#uses_chease? ⇒ 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_output ⇒ Object Also known as: vo
325 326 327 |
# File 'lib/trinitycrmod/trinity.rb', line 325 def vim_output system "vim -Ro #{output_file} #{error_file} #@directory/#@run_name.error #@directory/#@run_name.out " end |
#write_input_file ⇒ Object
This command uses the infrastructure provided by Run::FortranNamelist, provided by CodeRunner itself.
331 332 333 |
# File 'lib/trinitycrmod/trinity.rb', line 331 def write_input_file File.open(@run_name + ".trin", 'w'){|file| file.puts input_file_text} end |