Class: CodeRunner::Gene
- Inherits:
-
Run::FortranNamelist
- Object
- Run::FortranNamelist
- CodeRunner::Gene
- Defined in:
- lib/genecrmod/gene.rb
Overview
This is a customised subclass of the CodeRunner::Run class which allows CodeRunner to run and analyse the GENE gyrokinetic code (see www2.ipp.mpg.de/~fsj/gene/)
p ‘hellllllooooo!!!’
Class Method Summary collapse
Instance Method Summary collapse
- #check_parameters ⇒ Object
- #generate_component_runs ⇒ Object
-
#generate_input_file ⇒ Object
This is a hook which gets called just before submitting a simulation.
- #get_completed_timesteps ⇒ Object
- #get_status ⇒ Object
- #input_file_extension ⇒ Object
- #input_file_header ⇒ Object
- #namelist_text(namelist, enum = nil) ⇒ 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.
-
#restart(new_run) ⇒ Object
Modify new_run so that it becomes a restart of self.
- #vim_output ⇒ Object (also: #vo)
-
#write_input_file ⇒ Object
This command uses the infrastructure provided by Run::FortranNamelist, provided by CodeRunner itself.
Class Method Details
.defaults_file_header ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/genecrmod/gene.rb', line 256 def self.defaults_file_header <<EOF1 ############################################################################ # # # Automatically generated defaults file for the GENE CodeRunner module # # # # This defaults file specifies a set of defaults for GENE which are # # used by CodeRunner to set up and run GENE simulations. # # # ############################################################################ # Created: #{Time.now.to_s} @defaults_file_description = "" EOF1 end |
.parse_input_file(input_file, strict = true) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/genecrmod/gene.rb', line 120 def self.parse_input_file(input_file, strict=true) if FileTest.file? input_file text = File.read(input_file) else text = input_file end i = 0 text.gsub!(/^(&species)/i){p $~; "#{$1}_#{i+=1}"} super(text) end |
Instance Method Details
#check_parameters ⇒ Object
159 160 |
# File 'lib/genecrmod/gene.rb', line 159 def check_parameters end |
#generate_component_runs ⇒ Object
183 184 185 |
# File 'lib/genecrmod/gene.rb', line 183 def generate_component_runs #puts "HERE" 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.
110 111 112 113 114 115 116 117 118 |
# File 'lib/genecrmod/gene.rb', line 110 def generate_input_file check_parameters if @restart_id @runner.run_list[@restart_id].restart(self) end @diagdir = "." @n_procs_sim = actual_number_of_processors write_input_file end |
#get_completed_timesteps ⇒ Object
224 225 226 227 228 |
# File 'lib/genecrmod/gene.rb', line 224 def get_completed_timesteps Dir.chdir(@directory) do @completed_timesteps = %x[grep '^\\s\\+\\S\\+\\s*$' nrg.dat].split("\n").size end end |
#get_status ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/genecrmod/gene.rb', line 203 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 == @ntimesteps @status = :Complete else if FileTest.exist?('GENE.finished') @status = :Complete else @status = :Failed end end end end |
#input_file_extension ⇒ Object
274 275 276 |
# File 'lib/genecrmod/gene.rb', line 274 def input_file_extension '' end |
#input_file_header ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/genecrmod/gene.rb', line 234 def input_file_header <<EOF !============================================================================== ! GENE input file automatically generated by CodeRunner !============================================================================== ! ! GENE is a code for solving the nonlinear gyrokinetic equation. ! ! See http://www2.ipp.mpg.de/~fsj/gene/ ! ! CodeRunner is a framework for the automated running and analysis ! of large simulations. ! ! See http://coderunner.sourceforge.net ! ! Created #{Time.now.to_s} ! by CodeRunner version #{CodeRunner::CODE_RUNNER_VERSION.to_s} ! !============================================================================== EOF end |
#namelist_text(namelist, enum = nil) ⇒ Object
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 |
# File 'lib/genecrmod/gene.rb', line 130 def namelist_text(namelist, enum = nil) hash = rcp.namelists[namelist] text = "" ext = enum ? "_#{enum}" : "" text << "!#{'='*30}\n!#{hash[:description]} #{enum} \n!#{'='*30}\n" if hash[:description] #text << "&#{namelist}#{ext}\n" text << "&#{namelist}\n" hash[:variables].each do |var, var_hash| code_var = (var_hash[:code_name] or var) cr_var = var+ext.to_sym value = send(cr_var) if send(cr_var) and (not var_hash[:should_include] or eval(var_hash[:should_include])) if value.kind_of? Array value.each_with_index do |v, i| output = formatted_variable_output(v) text << " #{code_var}(#{i+1}) = #{output} #{var_hash[:description] ? "! #{var_hash[:description]}": ""}\n" end else output = formatted_variable_output(value) text << " #{code_var} = #{output} #{var_hash[:description] ? "! #{var_hash[:description]}": ""}\n" end elsif rcp.namelists_to_print_not_specified? and rcp.namelists_to_print_not_specified.include?(namelist) text << " ! #{code_var} not specified --- #{var_hash[:description]}\n" end end text << "/\n\n" text end |
#parameter_string ⇒ Object
Parameters which follow the Trinity executable, in this case just the input file.
176 177 178 |
# File 'lib/genecrmod/gene.rb', line 176 def parameter_string "" end |
#parameter_transition ⇒ Object
180 181 |
# File 'lib/genecrmod/gene.rb', line 180 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.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/genecrmod/gene.rb', line 43 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).
193 194 195 196 197 198 199 200 201 |
# File 'lib/genecrmod/gene.rb', line 193 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 / ntimesteps.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
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 |
# File 'lib/genecrmod/gene.rb', line 63 def restart(new_run) raise "Restart not tested yet" #new_run = self.dup (rcp.variables).each{|v| new_run.set(v, send(v)) if send(v)} #if @flux_option == "gs2" #gs2_runs.each_with_index do |run, i| #CodeRunner::Gs2.rcp.variables.each{|v| new_run.gs2_runs[i].set(v, run.send(v)) if run.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.nopt = -1 #new_run.init_option = "restart" #new_run.iternt_file = @run_name + ".iternt" #new_run.iterflx_file = @run_name + ".iterflx" #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 #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 !new_run.nprocs or new_run.nprocs != @nprocs ### @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 GENE Restart file' ##system "ls #@directory" FileUtils.cp("#@directory/NOUT", "#{new_run.directory}/NIN") ##########if new_run.flux_option == "gs2" and @flux_option == "gs2" ##########for i in 0...n_flux_tubes ##########new_run.gs2_runs[i].directory = new_run.directory + "/flux_tube_#{i+1}" ##########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 |
#vim_output ⇒ Object Also known as: vo
164 165 166 |
# File 'lib/genecrmod/gene.rb', line 164 def vim_output system "vim -Ro #{output_file} #{error_file}" end |
#write_input_file ⇒ Object
This command uses the infrastructure provided by Run::FortranNamelist, provided by CodeRunner itself.
170 171 172 173 |
# File 'lib/genecrmod/gene.rb', line 170 def write_input_file #File.open("#@run_name.in", 'w'){|file| file.puts input_file_text} File.open("parameters", 'w'){|file| file.puts input_file_text} end |