Class: CodeRunner::Trinity
- Inherits:
-
Run::FortranNamelist
- Object
- Run::FortranNamelist
- CodeRunner::Trinity
- Includes:
- OutputFiles, TrinityGraphKits
- Defined in:
- lib/trinitycrmod/trinity.rb,
lib/trinitycrmod/output_files.rb,
lib/trinitycrmod/graphs.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: OutputFiles, TrinityGraphKits
Class Method Summary collapse
Instance Method Summary collapse
-
#generate_input_file ⇒ Object
This is a hook which gets called just before submitting a simulation.
-
#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
- #input_file_header ⇒ Object
-
#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.
-
#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, #fluxes_prof_graphkit, #ion_hflux_gb_prof_graphkit, #ion_temp_prof_graphkit, #lflux_gb_prof_graphkit, #nt_prof_graphkit, #prof_graphkit
Methods included from OutputFiles
#fluxes_outfile, #info_outfile, #nt_outfile, #time_outfile, #view_outfiles
Class Method Details
.defaults_file_header ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/trinitycrmod/trinity.rb', line 199 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
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 |
# File 'lib/trinitycrmod/trinity.rb', line 147 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 |
Instance Method Details
#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.
74 75 76 |
# File 'lib/trinitycrmod/trinity.rb', line 74 def generate_input_file write_input_file 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'.
40 41 42 43 44 |
# File 'lib/trinitycrmod/output_files.rb', line 40 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
124 125 126 127 128 129 130 |
# File 'lib/trinitycrmod/trinity.rb', line 124 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
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/trinitycrmod/trinity.rb', line 133 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 #p 'send(fusionQ)', send(:fusionQ) end |
#get_status ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/trinitycrmod/trinity.rb', line 106 def get_status if @running get_completed_timesteps if completed_timesteps == 0 @status = :NotStarted else @status = :Incomplete end else get_completed_timesteps if File.read(output_file) =~/trinity\s+finished/i @status = :Complete else @status = :Failed end end end |
#graphkit(name, options) ⇒ Object
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 |
# File 'lib/trinitycrmod/graphs.rb', line 46 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 |
#input_file_header ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/trinitycrmod/trinity.rb', line 177 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 on \#{Time.now.to_s}\n! by CodeRunner version \#{CodeRunner::CODE_RUNNER_VERSION.to_s}\n!\n!==============================================================================\n\n" end |
#parameter_string ⇒ Object
Parameters which follow the Trinity executable, in this case just the input file.
84 85 86 |
# File 'lib/trinitycrmod/trinity.rb', line 84 def parameter_string @run_name + ".trin" end |
#parameter_transition ⇒ Object
88 89 |
# File 'lib/trinitycrmod/trinity.rb', line 88 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.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/trinitycrmod/trinity.rb', line 58 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).
96 97 98 99 100 101 102 103 104 |
# File 'lib/trinitycrmod/trinity.rb', line 96 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 |
#write_input_file ⇒ Object
This command uses the infrastructure provided by Run::FortranNamelist, provided by CodeRunner itself.
79 80 81 |
# File 'lib/trinitycrmod/trinity.rb', line 79 def write_input_file File.open(@run_name + ".trin", 'w'){|file| file.puts input_file_text} end |