Class: CodeRunner::Gryfx
- Inherits:
-
Gs2
- Object
- Gs2
- CodeRunner::Gryfx
- Defined in:
- lib/gryfxcrmod/gryfx.rb,
lib/gryfxcrmod/namelist_tools.rb
Class Method Summary collapse
- .defaults_file_header ⇒ Object
-
.get_namelists_and_variables_from_source_code(source) ⇒ Object
Find all input namelists and variables by scanning the source code.
- .get_sample_value(source, var) ⇒ Object
- .update_defaults_from_source_code(source_code_folder = ) ⇒ Object
Instance Method Summary collapse
-
#calculate_frequencies ⇒ Object
def calculate_results end.
- #code_run_environment ⇒ Object
-
#generate_input_file ⇒ Object
This is a hook which gets called just before submitting a simulation.
- #geometric_factors_gsl_tensor(options) ⇒ Object
- #get_completed_timesteps ⇒ Object
- #get_status ⇒ Object
- #gryfx? ⇒ Boolean
- #input_file_header ⇒ Object
- #netcdf_filename ⇒ 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.
Class Method Details
.defaults_file_header ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/gryfxcrmod/gryfx.rb', line 213 def self.defaults_file_header "######################################################################\n# Automatically generated defaults file for GRYFX CodeRunner module #\n# #\n# This defaults file specifies a set of defaults for GRYFX which are #\n# used by CodeRunner to set up and run GRYFX simulations. #\n# #\n# Created \#{Time.now.to_s} #\n# #\n######################################################################\n\n@defaults_file_description = \"\"\n" end |
.get_namelists_and_variables_from_source_code(source) ⇒ Object
Find all input namelists and variables by scanning the source code
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gryfxcrmod/namelist_tools.rb', line 9 def self.get_namelists_and_variables_from_source_code(source) nms = {} all_variables_in_source = {} namelist_declarations = {} #source.scan(/^\s*namelist\s*\/(?<namelist>\w+)\/(?<variables>(?:(?:&\s*[\n\r]+)|[^!\n\r])*)/) do #source.scan(Regexp.new("#{/^\s*namelist\s*\/\s*(?<namelist>\w+)\s*\//}(?<variables>#{FORTRAN_SINGLE_LINE})")) do source.scan(rcp.fortran_namelist_variable_match_regex) do namelist = $~[:namelist].to_s.downcase.to_sym #variables = $~[:variables].gsub(/!.*/, '') #eputs namelist, variables #namelist_declarations[namelist] = variables #gets # if namelist == :collisions_knobs #next if [:stuff, :ingen_knobs].include? namelist nms[namelist] ||= [] all_variables_in_source[namelist] ||= [] # puts variables #variables.scan(/\w+/) do var = $~[:variable].to_sym # (p variables, namelist; exit) if var == :following or var == :sou all_variables_in_source[namelist].push var next if known_code_variable?(namelist, var) nms[namelist].push var #end nms[namelist].uniq! all_variables_in_source[namelist].uniq! end return [nms, all_variables_in_source, namelist_declarations] end |
.get_sample_value(source, var) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gryfxcrmod/namelist_tools.rb', line 38 def self.get_sample_value(source, var) sample_val = nil source.scan(rcp.fortran_namelist_variable_match_regex) do #p $~ next unless var == $~[:variable].to_sym sample_val = eval($~[:default].sub(/(\d\.)$/, '\10').sub(/^(\.\d)/, '0\1').sub(/(\d\.)[eE]/, '\10e')) end raise "Couldn't get a sample value for #{var.inspect}" unless sample_val return sample_val end |
.update_defaults_from_source_code(source_code_folder = ) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/gryfxcrmod/namelist_tools.rb', line 49 def self.update_defaults_from_source_code(source_code_folder = ARGV[-1]) source = get_aggregated_source_code_text(source_code_folder) rcp.namelists.each do |nml, nmlhash| nmlhash[:variables].each do |var, varhash| varhash[:autoscanned_defaults] = [get_sample_value(source, varhash[:code_name]||var)] rescue [] save_namelists end end end |
Instance Method Details
#calculate_frequencies ⇒ Object
def calculate_results end
137 138 139 |
# File 'lib/gryfxcrmod/gryfx.rb', line 137 def calculate_frequencies @real_frequencies = FloatHash.new end |
#code_run_environment ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/gryfxcrmod/gryfx.rb', line 145 def code_run_environment case @sys when /stampede/ "module load cuda\n module load hdf5\n module load netcdf" when /generic_linux/, /macosx/ "# No configuration necessary" 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.
69 70 71 |
# File 'lib/gryfxcrmod/gryfx.rb', line 69 def generate_input_file write_input_file end |
#geometric_factors_gsl_tensor(options) ⇒ Object
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 |
# File 'lib/gryfxcrmod/gryfx.rb', line 155 def geometric_factors_gsl_tensor() theta_vec = gsl_vector(:theta, ) factors = GSL::Tensor.alloc(6,theta_vec.size) values = [:Rplot, :Zplot, :aplot, :Rprime, :Zprime, :aprime].map do |name| arr = netcdf_file.var(name).get.to_a if [:periodic] arr += [arr[0]] end arr end #ep values shape = factors.shape for i in 0...shape[0] unless [:interpolate_theta] for j in 0...shape[1] factors[i,j] = values[i][j] end else opts = .dup opts[:interpolate_theta] = nil opts[:thetamax] = opts[:thetamin] = nil theta_vec_short = gsl_vector(:theta, opts) #p 'sizes', [theta_vec_short.size, values[i].to_gslv.size] interp = GSL::ScatterInterp.alloc(:cubic, [theta_vec_short, values[i].to_gslv], true, [3.0].to_gslv) for j in 0...theta_vec.size factors[i,j] = interp.eval(theta_vec[j]) end end end #ep factors return factors end |
#get_completed_timesteps ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/gryfxcrmod/gryfx.rb', line 122 def get_completed_timesteps if FileTest.exist?(@run_name + '.cdf') @completed_timesteps = gsl_vector('t').size else @completed_timesteps = 0 end end |
#get_status ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/gryfxcrmod/gryfx.rb', line 102 def get_status if @running unless @status==:Queueing @status = :Incomplete get_completed_timesteps if @completed_timesteps.to_f/(nstep/nwrite) == 1.0 @status=:Complete end end else get_completed_timesteps if (@percent_complete = 100.0*@completed_timesteps.to_f/(nstep/nwrite)) > 5.0 @status = :Complete else @status = :Failed end end end |
#gryfx? ⇒ Boolean
141 142 143 |
# File 'lib/gryfxcrmod/gryfx.rb', line 141 def gryfx? true end |
#input_file_header ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/gryfxcrmod/gryfx.rb', line 189 def input_file_header "!==============================================================================\n! GRYFX INPUT FILE automatically generated by CodeRunner \n!==============================================================================\n!\n! GRYFX is a gyrofluid GPU flux tube initial value turbulence code \n! which can be used for fusion or astrophysical 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 |
#netcdf_filename ⇒ Object
130 131 132 |
# File 'lib/gryfxcrmod/gryfx.rb', line 130 def netcdf_filename @directory + '/' + @run_name + '.cdf' end |
#parameter_string ⇒ Object
Parameters which follow the Trinity executable, in this case just the input file.
79 80 81 |
# File 'lib/gryfxcrmod/gryfx.rb', line 79 def parameter_string @run_name + ".in" end |
#parameter_transition ⇒ Object
83 84 |
# File 'lib/gryfxcrmod/gryfx.rb', line 83 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.
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 |
# File 'lib/gryfxcrmod/gryfx.rb', line 40 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) if @nonlinear_mode == "off" beginning += sprintf("%3.2e %3.2e %4s", @fastest_growing_mode, @max_growth_rate, @freq_of_max_growth_rate||0.0) rescue "" elsif @nonlinear_mode == "on" # p @hflux_tot_stav beginning += " sat:#{saturated.to_s[0]}" if not @saturated.nil? beginning += sprintf(" hflux:%1.2e", @hflux_tot_stav) if @hflux_tot_stav beginning += sprintf("+/-%1.2e", @hflux_tot_stav_error) if @hflux_tot_stav_error beginning += sprintf(" momflux:%1.2e", @es_mom_flux_stav.values.sum) if @es_mom_flux_stav and @es_mom_flux_stav.values[0] beginning += ' SC:' + @spectrum_check.map{|c| c.to_s}.join(',') if @spectrum_check beginning += ' VC:' + @vspace_check.map{|c| sprintf("%d", ((c*10.0).to_i rescue -1))}.join(',') if @vspace_check end 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).
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gryfxcrmod/gryfx.rb', line 91 def process_directory_code_specific @grid_option = "box" # For compatibility with the GS2 routines @write_phi_over_time = "true" # For compatibility with the GS2 routines get_status #p ['id is', id, 'ctd is ', ctd] if ctd calculate_results end #p ['fusionQ is ', fusionQ] end |
#write_input_file ⇒ Object
This command uses the infrastructure provided by Run::FortranNamelist, provided by CodeRunner itself.
74 75 76 |
# File 'lib/gryfxcrmod/gryfx.rb', line 74 def write_input_file File.open(@run_name + ".in", 'w'){|file| file.puts input_file_text} end |