Class: CodeRunner::Veritas
- Inherits:
-
Run::FortranNamelist
- Object
- Run::FortranNamelist
- CodeRunner::Veritas
- Defined in:
- lib/veritascrmod/veritas.rb
Overview
This is a customised subclass of the CodeRunner::Run class which allows CodeRunner to run and analyse the Vlasov Maxwell solver Veritas.
It generates the Veritas input file, and both analyses the results and allows easy plotting of them.
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_status ⇒ Object
- #input_file_extension ⇒ Object
- #input_file_header ⇒ Object
-
#input_file_text ⇒ Object
Override CodeRunner for 0-based# Override CodeRunner for 0-based# Override CodeRunner for 0-based.
- #namelist_text(namelist, enum = nil) ⇒ Object
-
#parameter_string ⇒ Object
Parameters which follow the Veritas 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
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/veritascrmod/veritas.rb', line 149 def self.defaults_file_header "############################################################################\n# #\n# Automatically generated defaults file for the Veritas CodeRunner module #\n# #\n# This defaults file specifies a set of defaults for Veritas which are #\n# used by CodeRunner to set up and run Veritas simulations. #\n# #\n############################################################################\n\n# Created: \#{Time.now.to_s}\n\n@defaults_file_description = \"\"\n" end |
.defaults_file_text_from_input_file(input_file) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/veritascrmod/veritas.rb', line 228 def self.defaults_file_text_from_input_file(input_file) string = defaults_file_header hash = parse_input_file(input_file) #pp hash; exit #ep ['class', self.to_s, 'namelists', rcp.namelists.keys, 'code_long', rcp.code_long, 'namelist_hashes', rcp.namelists.values.map{|v| v.class}] rcp.namelists.each do |namelist, namelist_hash| #ep namelist if namelist_hash[:enumerator] # ie. This is an indexed namelist #p namelist_hash[:enumerator] enumerator = namelist_hash[:enumerator][:name] enum_hash = hash.find{|nml, nmlh| nmlh[enumerator]} next unless enum_hash #pp enum_hash enum = enum_hash[1][enumerator] enum.times{|i| string << namelist_defaults_text(hash, namelist, namelist_hash, i+0)} else string << namelist_defaults_text(hash, namelist, namelist_hash) end end string 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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/veritascrmod/veritas.rb', line 69 def generate_input_file FileUtils.makedirs("output/rectangleData") #@run_name += "_t" if @restart_id @runner.run_list[@restart_id].restart(self) end #if uses_ecom? #setup_ecom #elsif uses_chease? #setup_chease #end #check_parameters write_input_file end |
#get_status ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/veritascrmod/veritas.rb', line 117 def get_status if @running @status = :Running else @status = :Complete end end |
#input_file_extension ⇒ Object
167 168 169 |
# File 'lib/veritascrmod/veritas.rb', line 167 def input_file_extension '.in' end |
#input_file_header ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/veritascrmod/veritas.rb', line 127 def input_file_header "!==============================================================================\n! Veritas INPUT FILE automatically generated by CodeRunner\n!==============================================================================\n!\n! Veritas is a 1D continuum solver for the Vlasov-Maxwell system\n!\n! See http://ft.nephy.chalmers.se/veritas/\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 |
#input_file_text ⇒ Object
Override CodeRunner for 0-based# Override CodeRunner for 0-based# Override CodeRunner for 0-based
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/veritascrmod/veritas.rb', line 172 def input_file_text text = input_file_header rcp.namelists.each do |namelist, hash| next if hash[:should_include].kind_of? String and not eval(hash[:should_include]) if en = hash[:enumerator] # Single = is deliberate! next unless send(en[:name]) send(en[:name]).times do |i| next unless hash[:variables].keys.inject(false){|b, v| b or !send(v+"_#{i+0}".to_sym).nil?} # i.e. at least one variable must be non-nil text << namelist_text(namelist, i+0) end else next unless hash[:variables].keys.inject(false){|b, v| b or !send(v).nil?} # i.e. at least one variable must be non-nil text << namelist_text(namelist) end end text end |
#namelist_text(namelist, enum = nil) ⇒ Object
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 |
# File 'lib/veritascrmod/veritas.rb', line 191 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" 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+0}) = #{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 Veritas executable, in this case just the input file.
100 101 102 |
# File 'lib/veritascrmod/veritas.rb', line 100 def parameter_string @run_name + ".in" end |
#parameter_transition ⇒ Object
104 105 |
# File 'lib/veritascrmod/veritas.rb', line 104 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.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/veritascrmod/veritas.rb', line 38 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.to_f, "%") #if ctd and fusionQ #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).
113 114 115 |
# File 'lib/veritascrmod/veritas.rb', line 113 def process_directory_code_specific get_status 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
64 65 66 67 |
# File 'lib/veritascrmod/veritas.rb', line 64 def restart(new_run) (rcp.variables).each{|v| new_run.set(v, send(v)) if send(v) or new_run.send(v)} raise "restart not implemented yet" end |
#vim_output ⇒ Object Also known as: vo
89 90 91 |
# File 'lib/veritascrmod/veritas.rb', line 89 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.
95 96 97 |
# File 'lib/veritascrmod/veritas.rb', line 95 def write_input_file File.open(@run_name + ".in", 'w'){|file| file.puts input_file_text} end |