Пример #1
0
def loadCogs():
    for cog in os.listdir("cogs"):
        if cog.endswith("py"):
            filename = cog.split(".")[0]
            try:
                bot.load_extension(f"cogs.{filename}")
                getLogger().info(f"[Cog Management] Cog Loaded: {filename}")
            except (errors.ExtensionNotFound, errors.ExtensionAlreadyLoaded,
                    errors.NoEntryPointError, errors.ExtensionFailed) as e:
                getLogger().error(
                    f"[Cog Management] Error loading cog: {filename}; Error: {e}"
                )
Пример #2
0
 def __init__(self, logger=None):
   ''' Constructor
       @param[in] logger - python logger instance or None
   '''
   self.msg = sys.stdout
   #Base.__init__(self)
   self.datalines = [] # lines of text for read/write from/to file
   self.data = {} # internal stucture to store simulation elements
   self.data['comments'] = [] # lines of all comments for the whole simulation
   self.data['children'] = [] # list of dictionaries for all children blocks
   if logger is not None:
     self.logger = logger
   else:
     self.logger = getLogger('MooseInputFileRW')
   return
Пример #3
0
def runWholeConvectionWorkflow(mesh_file, gr_string, nb_threads):
  ''' Run the whole workflow of continuation for convection
      for given mesh and gr
  '''
  output_dir = '.'
  input_dir = os.path.realpath('.')
  mesh_short_name = os.path.splitext(os.path.split(mesh_file)[1])[0]
  running_tmp_dir = os.path.join(input_dir, 'curvy_Gr{gr}_mesh_{mesh}' .\
    format(gr=gr_string, mesh=mesh_short_name))
  parameters = {
    'continuation_variable':'Lewis', # in ['Gruntfest', 'Lewis']
    'materials_affected':['redback_materialA'],#['*'],
    'lambda_initial_1':1.0,
    'lambda_initial_2':1.01,
    'ds_initial':0.01,
    's_max':100,
    # Rescaling factor
    'rescaling_factor':1e-07, # to multiply continuation parameter
    # Numerical parameters
    'exec_loc':'~/projects/redback/redback-opt',
    'nb_threads':4,
    'input_file':os.path.join(input_dir, '2d_curvy.i'), # '2D_Gr_9e-3_LE6e-08.i' transient file name
    'starting_from_exodus':'will be set automatically', # exodus file with solution of transient simuation for Initial Guess 1
    'running_dir':os.path.realpath(running_tmp_dir),
    'result_curve_csv':os.path.join(os.path.realpath(running_tmp_dir), 'LSA_Gr{gr}_mesh_{mesh}.csv' .\
      format(gr=gr_string, mesh=mesh_short_name)),
    'error_filename':'error_output.txt',
    'plot_s_curve':True,
    'non_blocking':True,
    'plot_post_processor':'Nusselt2', # post-processor to plot. If empty, then norm is used.
    'plot_norm':'L2', # in ['L2', 'L_inf']
    'plot_solution_index':1, # index of solution to plot
    'ref_s_curve':'',
    'postprocessors_exported':['Nusselt2'],
    # overwriting parameters
    'overwriting_params':{
      'Mesh/file':os.path.realpath(mesh_file),
      'Materials/redback_materialB/gr':gr_string,
      }
  }
  logger = getLogger('sim', os.path.join(output_dir, 'log.txt'), logging.INFO)
  # Reference steady-state file
  ok = generateSteadyStateConvectionFile(parameters, logger)
  if not ok:
    sys.exit()
  sim_filename = os.path.join(parameters['running_dir'], ROOT_FILENAME_REF_SS+'.i')
  runSimulation(sim_filename, parameters, logger) # run steady state for diffusion
  # Transient file
  ok = generateTransientConvectionFile(parameters, logger)
  if not ok:
    sys.exit()
  sim_filename = os.path.join(parameters['running_dir'], ROOT_FILENAME_TRANSIENT+'.i')
  runSimulation(sim_filename, parameters, logger) # run transient
  # make a copy (to keep) that transient.e file
  dot_e_file = sim_filename[0:-2] + '.e'
  dot_e_file2 = sim_filename[0:-2] + '_original.e'
#  shutil.copyfile(dot_e_file, dot_e_file2)
  # Continuation
  parameters['starting_from_exodus'] = os.path.join(parameters['running_dir'], ROOT_FILENAME_TRANSIENT+'.e')
  parameters['overwriting_params']['UserObjects/temp_ref_uo/mesh'] = ROOT_FILENAME_REF_SS+'.e'
  results = runContinuation(parameters, logger)
  print 'Finished workflow for gr={gr}, mesh={mesh}'.\
    format(gr=gr_string, mesh=os.path.splitext(os.path.split(mesh_file)[1])[0])
from Utils import getLogger
from RedbackContinuation import runContinuation

if __name__ == "__main__":
  # User input
  outpud_dir = '.'
  ds = 1e-1
  parameters = {
    'lambda_initial_1':1e-8, #ds,
    'lambda_initial_2':2e-8, #2*ds,
    'ds_initial':ds,
    's_max':10,
    # Rescaling factor
    'rescaling_factor':5e-6,#4.5399929762e-5, # to multiply continuation parameter
    # Numerical parameters
    'exec_loc':'~/projects/redback/redback-opt',
    'nb_threads':1,
    'input_file':'bench_THC_sot_ss_test.i',
    'running_dir':'running_tmp',
    'result_curve_csv':'S_curve.csv',
    'error_filename':'error_output.txt',
    'plot_s_curve':True,
    'non_blocking':True,
    'ref_s_curve':'',
  }
  logger = getLogger('sim', os.path.join(outpud_dir, 'log.txt'), logging.INFO)
  results = runContinuation(parameters, logger)
  raw_input('press enter to finish')
  print 'Finished'
Пример #5
0
 def setUp(self):
   ''' Initial set up for all tests '''
   self.logger = getLogger('log.txt', level=logging.INFO)
   self.error_filename = os.path.join('tests', 'error.txt')
   self.nb_procs = multiprocessing.cpu_count()
Пример #6
0
def runWholeConvectionWorkflow(mesh_file, gr_string, nb_threads):
    ''' Run the whole workflow of continuation for convection
      for given mesh and gr
  '''
    output_dir = '.'
    input_dir = os.path.realpath('.')
    mesh_short_name = os.path.splitext(os.path.split(mesh_file)[1])[0]
    running_tmp_dir = os.path.join(input_dir, 'Benchmark_Case1_{mesh}' .\
      format(gr=gr_string, mesh=mesh_short_name))
    parameters = {
      'continuation_variable':'Lewis', # in ['Gruntfest', 'Lewis']
      'materials_affected':['redback_materialA'],#['*'],
      'lambda_initial_1':3.0,
      'lambda_initial_2':3.1,
      'ds_initial':0.1,
      's_max':100,
      # Rescaling factor
      'rescaling_factor':1e-08, # to multiply continuation parameter
      # Numerical parameters
      'exec_loc':'~/projects/redback/redback-opt',
      'nb_threads':4,
      'input_file':os.path.join(input_dir, 'transient_case1.i'), # '2D_Gr_9e-3_LE6e-08.i' transient file name
      'starting_from_exodus':'will be set automatically', # exodus file with solution of transient simuation for Initial Guess 1
      'running_dir':os.path.realpath(running_tmp_dir),
      'result_curve_csv':os.path.join(os.path.realpath(running_tmp_dir), 'LSA_Benchmark_Case1_mesh_{mesh}.csv' .\
        format(gr=gr_string, mesh=mesh_short_name)),
      'error_filename':'error_output.txt',
      'plot_s_curve':True,
      'non_blocking':True,
      'plot_post_processor':'Nusselt2', # post-processor to plot. If empty, then norm is used.
      'plot_norm':'L2', # in ['L2', 'L_inf']
      'plot_solution_index':1, # index of solution to plot
      'ref_s_curve':'',
      'postprocessors_exported':['Nusselt2'],
      # overwriting parameters
      'overwriting_params':{
        'Mesh/file':os.path.realpath(mesh_file),
        'Materials/redback_materialA/gr':gr_string,
        }
    }
    logger = getLogger('sim', os.path.join(output_dir, 'log.txt'),
                       logging.INFO)
    # Reference steady-state file
    ok = generateSteadyStateConvectionFile(parameters, logger)
    if not ok:
        sys.exit()
    sim_filename = os.path.join(parameters['running_dir'],
                                ROOT_FILENAME_REF_SS + '.i')
    runSimulation(sim_filename, parameters,
                  logger)  # run steady state for diffusion
    # Transient file
    ok = generateTransientConvectionFile(parameters, logger)
    if not ok:
        sys.exit()
    sim_filename = os.path.join(parameters['running_dir'],
                                ROOT_FILENAME_TRANSIENT + '.i')
    runSimulation(sim_filename, parameters, logger)  # run transient
    # make a copy (to keep) that transient.e file
    dot_e_file = sim_filename[0:-2] + '.e'
    dot_e_file2 = sim_filename[0:-2] + '_original.e'
    shutil.copyfile(dot_e_file, dot_e_file2)
    # Continuation
    parameters['starting_from_exodus'] = os.path.join(
        parameters['running_dir'], ROOT_FILENAME_TRANSIENT + '.e')
    parameters['overwriting_params'][
        'UserObjects/temp_ref_uo/mesh'] = ROOT_FILENAME_REF_SS + '.e'
    results = runContinuation(parameters, logger)
    print 'Finished workflow for gr={gr}, mesh={mesh}'.\
      format(gr=gr_string, mesh=os.path.splitext(os.path.split(mesh_file)[1])[0])
      attr['value'] = base_filename
      found_file_base = True
    elif attr['name'] == 'exodus':
      attr['value'] = 'true'
      found_exodus = True
    elif attr['name'] == 'csv':
      attr['value'] = 'true'
      found_csv = True
    elif attr['name'] == 'execute_on':
      attr['value'] = "'initial timestep_end'"
      found_execute_on = True
  if not found_file_base:
    outputs['attributes'].append({'name':'file_base','value':base_filename, 'comment':''})
  if not found_exodus:
    outputs['attributes'].append({'name':'exodus','value':'true', 'comment':''})
  if not found_csv:
    outputs['attributes'].append({'name':'csv','value':'true', 'comment':''})
  if not found_execute_on:
    outputs['attributes'].append({'name':'execute_on','value':"'initial timestep_end'", 'comment':''})
  return sim_data

if __name__ == "__main__":
  logger = getLogger('sim', 'running_tmp/log.txt', logging.INFO)
  handler = MooseInputFileRW()
  data_sim = handler.read('benchmark_4_TH/bench_TH.i')
  variable_names = getListOfActiveVariableNames(data_sim, logger)
  sim_1 = writeInitialGuessFile(1, data_sim, variable_names, 'running_tmp/extra_param_initial_guess1.i', handler, logger)
  sim_2 = writeInitialGuessFile(2, data_sim, variable_names, 'running_tmp/extra_param_initial_guess2.i', handler, logger)
  sim_i = writeIterationFile(data_sim, variable_names, 'running_tmp/extra_param_iteration.i', handler, logger)
  print 'Finished'
Пример #8
0
    outpud_dir = "."
    parameters = {
        "continuation_variable": "Lewis",  # in ['Gruntfest', 'Lewis']
        "materials_affected": ["redback_materialA"],  # ['*'],
        "lambda_initial_1": 1.0,
        "lambda_initial_2": 1.1,
        "ds_initial": 5,
        "s_max": 100,
        # Rescaling factor
        "rescaling_factor": 1e-8,  # to multiply continuation parameter
        # Numerical parameters
        "exec_loc": "~/projects/redback/redback-opt",
        "nb_threads": 1,
        "input_file": "Case4.i",
        "starting_from_exodus": "XXXXX.e",  # exodus file with solution of transient simuation for Initial Guess 1
        "running_dir": "running_tmp",
        "result_curve_csv": "S_curve_case4.csv",
        "error_filename": "error_output.txt",
        "plot_s_curve": True,
        "non_blocking": True,
        "plot_post_processor": "New_Nusselt_postproc",  # post-processor to plot. If empty, then norm is used.
        "plot_norm": "L2",  # in ['L2', 'L_inf']
        "plot_solution_index": 1,  # index of solution to plot
        "ref_s_curve": "",
        "postprocessors_exported": ["New_Nusselt_postproc"],
    }
    logger = getLogger("sim", os.path.join(outpud_dir, "log.txt"), logging.INFO)
    results = runContinuation(parameters, logger)
    raw_input("press enter to finish")
    print "Finished"
Пример #9
0
''' Script to plot S-curve '''

import os, sys, logging

# Add directory containing PlotSCurve.py to the path
sys.path.append(os.path.join('..', '..', '..'))

from Utils import getLogger
from PlotSCurve import plotSCurve


if __name__ == "__main__":
  parameters = {
    'result_curve_csv':'S_curve_case4.csv',
    'ref_s_curve':'',
    'plot_post_processor':'New_Nusselt_postproc', # post-processor to plot. If empty, then norm is used.
    'plot_norm':'L2', # in ['L2', 'L_inf'], only if no post-processor to plot is provided
    'plot_solution_index':1, # index of solution to plot
  }
  plotSCurve(parameters, getLogger('plotSCurve', level=logging.INFO))
  print 'Finished'