class CodeRunner::Gryfx

Public Class Methods

defaults_file_header() click to toggle source
# File lib/gryfxcrmod/gryfx.rb, line 274
def self.defaults_file_header
        <<EOF1
######################################################################
# Automatically generated defaults file for GRYFX CodeRunner module  #
#                                                                    #
# This defaults file specifies a set of defaults for GRYFX which are #
# used by CodeRunner to set up and run GRYFX simulations.            #
#                                                                    #
# Created #{Time.now.to_s}                                           #
#                                                                    #
######################################################################

@defaults_file_description = ""
EOF1
end
get_namelists_and_variables_from_source_code(source) click to toggle source

Find all input namelists and variables by scanning the source code

# 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) click to toggle source
# 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 = ARGV[-1]) click to toggle source
# 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

Public Instance Methods

calculate_frequencies() click to toggle source

def calculate_results end

# File lib/gryfxcrmod/gryfx.rb, line 198
def calculate_frequencies
        @real_frequencies = FloatHash.new
end
code_run_environment() click to toggle source
# File lib/gryfxcrmod/gryfx.rb, line 206
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
copy_restart_files(new_run) click to toggle source
Calls superclass method
# File lib/gryfxcrmod/gryfx.rb, line 96
def copy_restart_files(new_run)
  eputs 'Copying gryfx restart file...', ''
  FileUtils.cp(
    @directory + '/' + @run_name + '.restart.cdf', 
    new_run.directory + '/' + new_run.run_name + '.restart.cdf'
  )
  super(new_run)
end
generate_component_runs() click to toggle source
# File lib/gryfxcrmod/gryfx.rb, line 193
def generate_component_runs
end
generate_input_file() click to toggle source

This is a hook which gets called just before submitting a simulation. It sets up the folder and generates any necessary input files.

# File lib/gryfxcrmod/gryfx.rb, line 107
          def generate_input_file
if @restart_id and (not @is_a_restart or @resubmit_id)   
  @runner.run_list[@restart_id].set_restart(self)
elsif ((@save_for_restart and @save_for_restart.fortran_true?) or
       (@save_for_restart_new and @save_for_restart_new.fortran_true?)) and 
  (not @is_a_restart or @resubmit_id)
  @restart_dir = "nc"
  FileUtils.makedirs @restart_dir
  @restart_file = "#@run_name.nc"
end
@avail_cpu_time = (@wall_mins - 1.0) * 60.0 if @wall_mins
                          write_input_file
          end
geometric_factors_gsl_tensor(options) click to toggle source
# File lib/gryfxcrmod/gryfx.rb, line 216
def geometric_factors_gsl_tensor(options)
                theta_vec = gsl_vector(:theta, options)
                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 options[:periodic]
                                arr += [arr[0]]
                        end
                        arr
                end
                #ep values
                shape = factors.shape
                for i in 0...shape[0]
                                unless options[:interpolate_theta]
                                        for j in 0...shape[1]
                                                factors[i,j] = values[i][j]
                                        end
                                else
                                        opts = options.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() click to toggle source
# File lib/gryfxcrmod/gryfx.rb, line 172
        def get_completed_timesteps
                if FileTest.exist?(@run_name  + '.cdf')
count = 0
begin
  @completed_timesteps = netcdf_file.var('t').get.size #gsl_vector('t').size
rescue NetcdfError => err 
  eputs err
  count += 1
  eputs "Retrying: #{count} attempt(s) out of 4"
  sleep 1
  count < 5 ?  retry : raise(err)
end
                else
                        @completed_timesteps = 0
                end
        end
get_status() click to toggle source
# File lib/gryfxcrmod/gryfx.rb, line 151
def get_status
        if @running
                unless @status==:Queueing
                        @status = :Incomplete
                        get_completed_timesteps
                        @percent_complete = 100.0*@completed_timesteps.to_f/(nstep/nwrite) 
                        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?() click to toggle source
# File lib/gryfxcrmod/gryfx.rb, line 202
def gryfx?
        true
end
input_file_header() click to toggle source
# File lib/gryfxcrmod/gryfx.rb, line 250
def input_file_header
        <<EOF
!==============================================================================
!               GRYFX INPUT FILE automatically generated by CodeRunner 
!==============================================================================
!
!  GRYFX is a gyrofluid GPU flux tube initial value turbulence code 
!  which can be used for fusion or astrophysical plasmas.
!  
!       See http://gyrokinetics.sourceforge.net
!
!  CodeRunner is a framework for the automated running and analysis 
!  of large simulations. 
!
!       See http://coderunner.sourceforge.net
!
!  Created on #{Time.now.to_s}
!      by CodeRunner version #{CodeRunner::CODE_RUNNER_VERSION.to_s}
!
!==============================================================================

EOF
end
netcdf_filename() click to toggle source
# File lib/gryfxcrmod/gryfx.rb, line 189
def netcdf_filename
        @directory + '/' +  @run_name + '.cdf'
end
parameter_string() click to toggle source

Parameters which follow the Trinity executable, in this case just the input file.

# File lib/gryfxcrmod/gryfx.rb, line 127
def parameter_string
        @run_name + ".in"
end
parameter_transition() click to toggle source
# File lib/gryfxcrmod/gryfx.rb, line 131
def parameter_transition
end
print_out_line() click to toggle source

A hook which gets called when printing the standard run information to the screen using the status command.

process_directory_code_specific() click to toggle source

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).

# File lib/gryfxcrmod/gryfx.rb, line 139
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
set_restart(new_run) click to toggle source
Calls superclass method
# File lib/gryfxcrmod/gryfx.rb, line 72
def set_restart(new_run)
  eputs 'Restarting ' + @run_name
  #(rcp.variables).each{|v| new_run.set(v, send(v)) if send(v)}
  #@naming_pars.delete(:preamble)
  #SUBMIT_OPTIONS.each{|v| new_run.set(v, self.send(v)) unless new_run.send(v)}
  #new_run.is_a_restart = true
  #new_run.restart_id = @id
  #new_run.restart_run_name = @run_name
  #@runner.nprocs = @nprocs if @runner.nprocs == "1" # 1 is the default
  #new_run.run_name = nil
  #new_run.naming_pars = @naming_pars
  #new_run.update_submission_parameters(new_run.parameter_hash_string, false) if new_run.parameter_hash
  #new_run.naming_pars.delete(:restart_id)
  #new_run.generate_run_name
  #copy_restart_files(new_run)
  super(new_run)
  new_run.restart = "on"
  # Gryfx automatically configures GS2 for restart so here we set the GS2
  # parameters to default
  new_run.delt_option = "default"
  new_run.ginit_option = "noise"
  new_run
end
write_input_file() click to toggle source

This command uses the infrastructure provided by Run::FortranNamelist, provided by CodeRunner itself.

# File lib/gryfxcrmod/gryfx.rb, line 122
def write_input_file
        File.open(@run_name + ".in", 'w'){|file| file.puts input_file_text}
end