def testDiffusiveSolidification(): base_output_dir = get_base_output_dir() matlab_command = get_matlab_base_command() print(Fore.GREEN + 'Setup tests for solidification without flow' + Style.RESET_ALL) physicalProblem = 'noFlow' AMRSetup = [{'max_level': 0, 'ref_rat': 1, 'run_types': ['uniform'], 'Nzs': [8, 16, 32, 64, 128, 256]}, {'max_level': 1, 'ref_rat': 2, 'run_types': ['amr'], 'Nzs': [8, 16, 32, 64, 128]}, {'max_level': 2, 'ref_rat': 2, 'run_types': ['amr'], 'Nzs': [8, 16, 32, 64]}] # While testing: # AMRSetup = [{'max_level': 0, 'ref_rat': 1, 'run_types': ['uniform']}]; # Nzs = [16, 32, 64] num_procs = [1] * 6 # Needs to be as long as the longest Nzs # Setup up the post processing command dataFolder = os.path.join(base_output_dir, 'NoFlow') figureName = os.path.join(base_output_dir, 'Fig4NoFlow.pdf') analysis_command = matlab_command + ' "Fig4NoFlow(\'' + dataFolder + '\', \'' + figureName + '\'); exit;"' # Run extra_params = {'main.debug': 'true'} runTest(dataFolder, physicalProblem, diffusive_solidification_resolution_specific_params, AMRSetup, num_procs, analysis_command, extra_params)
def test_get_matlab_base_command(self): with mock.patch("os.path.abspath", return_value='/path/to/parent/'): self.assertEqual( util.get_matlab_base_command(), 'cd /path/to/parent/matlab/MethodsPaper;\n' 'source /etc/profile.d/modules.sh\n' 'module load idl/870\n' 'module load matlab/R2018b' '\n\n' 'matlab -nodisplay -nosplash -nodesktop -r')
def test_porous_mushy_hole(argv): # Defaults: max_time = 1.5e-4 hole_radius = 0.04 plot_interval = None try: opts, _ = getopt.getopt(argv, "t:h:p:") except getopt.GetoptError as err: print(str(err)) print('testPorousMushyHole.py -t<max time> -h<hole radius=0.02>') sys.exit(2) for opt, arg in opts: if opt in "-t": max_time = float(arg) elif opt in "-h": hole_radius = float(arg) elif opt in "-p": plot_interval = int(arg) base_output_dir = get_base_output_dir() matlab_command = get_matlab_base_command() print(Fore.GREEN + 'Setup tests for porous mushy hole' + Style.RESET_ALL) physical_problem = 'PorousMushyHole' min_concentration = -5.0 # default -5 folder_name = 'PorousMushyHole-t%s-minC%s' % (max_time, min_concentration) data_folder = os.path.join(base_output_dir, folder_name) amr_setup, num_procs = get_setup() # Setup up the post processing command python_compare_file = os.path.join(get_mushy_layer_dir(), 'test', 'run_chombo_compare.py') chombo_compare_analyse = 'python %s -f %s -a -v Porosity -e L2 -r True -n 8 -d %s \n \n' % (python_compare_file, data_folder, base_output_dir) make_figures = porous_hole_command(folder_name=folder_name) analysis_command = '%s\n\n%s" %s; exit;"' % (chombo_compare_analyse, matlab_command, make_figures) # Run extra_params = {'main.max_time': max_time, 'main.radius': hole_radius, 'bc.bulkConcentrationHiVal': [-1, min_concentration]} if plot_interval: extra_params['main.plot_interval'] = plot_interval run_test(data_folder, physical_problem, porous_mushy_hole_resolution_specific_params, amr_setup, num_procs, analysis_command, extra_params)
def test_uniform_porous_convection(argv): # Default vals: cfl = get_default_cfl() nz_uniform = 64 # don't do uniform mesh simulations by default nz_vm = 64 chi = 0.4 bc_accuracy = 2 u_del_u_method = 0 advection_method = 1 fixed_da = -1.0 fixed_ra = -1.0 try: opts, _ = getopt.getopt(argv, "n:v:c:p:b:u:a:d:r:") except getopt.GetoptError as err: print(str(err)) print( 'test_uniform_porous_convection.py -n<num uniform mesh grid points> -v<num variable mesh points>' ' -c<cfl> -p <chi> -b <BC accuracy> -u <u del u method> -a <advection method> ' '-d<fixed darcy> -r<fixed Ra>') sys.exit(2) for opt, arg in opts: if opt in "-n": nz_uniform = int(arg) elif opt in "-c": cfl = float(arg) elif opt in "-v": nz_vm = int(arg) elif opt in "-p": chi = float(arg) elif opt in "-b": bc_accuracy = int(arg) elif opt in "-u": u_del_u_method = int(arg) elif opt in "-a": advection_method = int(arg) elif opt in "-d": fixed_da = float(arg) elif opt in "-r": fixed_ra = float(arg) base_output_dir = get_base_output_dir() matlab_command = get_matlab_base_command() # Check we have the executables needed to run this test success = check_exec_exists( os.path.join(get_mushy_layer_dir(), 'execSubcycle'), 'mushyLayer') success = success and check_exec_exists( os.path.join(get_mushy_layer_dir(), 'setupNewRun'), 'setupnewrun') if not success: sys.exit(-1) print(Fore.GREEN + 'Setup tests for convection in a fixed uniform porous medium' + Style.RESET_ALL) physical_problem = 'convectionDB' # Nz_uniform = 128 # if Nz_vm <= 0: # Nz_vm = Nz_uniform #int(float(Nz_uniform) / 2) amr_setup = [] if nz_uniform > 0: amr_setup.append({ 'max_level': 0, 'ref_rat': 2, 'run_types': ['uniform'], 'Nzs': [int(nz_uniform / 2), nz_uniform, 2 * nz_uniform] }) if nz_vm > 0: these_nzs = [nz_vm, 2 * nz_vm, 4 * nz_vm] amr_setup.append({ 'max_level': 1, 'ref_rat': 2, 'run_types': ['variable'], 'Nzs': these_nzs }) num_procs = [1, 1, 1] # chi = 0.4 # Try and speed things up for now, should eventually make this criteria smaller # extra_params = {'main.steady_state': 1e-4} extra_params = { 'main.BCAccuracy': bc_accuracy, 'main.uDeluMethod': u_del_u_method, 'main.advectionMethod': advection_method, 'main.cfl': cfl, 'main.initial_cfl': cfl / 10 } base_data_folder = os.path.join(base_output_dir, 'ConvectionDB-cfl' + str(cfl)) da_ra_vals = [{ 'Da': 1e-6, 'RaT': [1e7, 1e8, 1e9], 'lebars': [1.08, 3.07, 12.9] }, { 'Da': 1e-2, 'RaT': [1e3, 1e4, 1e5, 5e5], 'lebars': [1.01, 1.41, 3.17, 5.24] }] if fixed_da > 0.0: if fixed_ra > 0.0: da_ra_vals = [{ 'Da': fixed_da, 'RaT': [fixed_ra], 'lebars': [float('NaN')] }] elif fixed_da == 1e-6: da_ra_vals = [{ 'Da': 1e-6, 'RaT': [1e7, 1e8, 1e9], 'lebars': [1.08, 3.07, 12.9] }] elif fixed_da == 1e-2: da_ra_vals = [{ 'Da': 1e-2, 'RaT': [1e3, 1e4, 1e5, 5e5], 'lebars': [1.01, 1.41, 3.17, 5.24] }] # [1.01, 1.41, 3.17, 5.24]; # [1.08, 3.07, 12.9]; all_job_ids = [] analysis_command = matlab_command + ' " ' ra_format = "%1.1e" da_format = "%1.1e" chi_format = "%1.1f" chi_str = chi_format % chi for da_ra in da_ra_vals: da = da_ra['Da'] da_str = da_format % da nu_lebars = [str(a) for a in da_ra['lebars']] # extra_params['main.max_time'] = 0.1 / float(Da) # extra_params['main.max_dt'] = ? for ra in da_ra['RaT']: extra_params['parameters.rayleighTemp'] = ra extra_params['main.plot_interval'] = -1 extra_params['main.plot_period'] = 0.05 extra_params['main.checkpoint_interval'] = 2000 # this is for testing purposes # extra_params['main.max_step'] = 10 if chi < 1.0: extra_params['parameters.darcy'] = da * pow(1 - chi, 2) / pow( chi, 3.0) else: extra_params['parameters.darcy'] = da extra_params['bc.porosityHiVal'] = str(chi) + ' ' + str( chi) # 0.4 0.4 extra_params['bc.porosityLoVal'] = str(chi) + ' ' + str(chi) # output_dir = 'chi' + str(chi) + '-Da' + str(Da) + '-Ra' + str(extra_params['parameters.rayleighTemp']) ra_str = ra_format % ra output_dir = "chi" + chi_str + "-Da" + da_str + "-Ra" + ra_str this_data_folder = os.path.join(base_data_folder, output_dir) job_ids = run_test(this_data_folder, physical_problem, uniform_porous_resolution_specific_params, amr_setup, num_procs, '', extra_params, restart_from_low_res=False) all_job_ids = all_job_ids + job_ids ra_str_vals = [ra_format % a for a in da_ra['RaT']] ra_str = '{\'' + '\',\''.join(ra_str_vals) + '\'}' analysis_command += ' compileNu(\'' + base_data_folder + '\', \'' \ + chi_str + '\', \'' + da_str + '\', ' + ra_str + ', ' \ + str(nz_uniform) + ', ' + str(nz_vm) + ', [' + ','.join(nu_lebars) + ']);' # Now do analysis analysis_command = analysis_command + ' exit; " ' run_analysis_name = 'runAnalysis.sh' job_name = physical_problem + '-analysis' s = BatchJob(base_data_folder, job_name, '') s.set_dependency(all_job_ids) s.set_custom_command(analysis_command) # s.write_slurm_file(run_analysis_name) s.run_task(run_analysis_name) print(Fore.GREEN + 'Submitted analysis job \n' + Fore.RESET)
def test_hele_shaw_fixed_chill(argv): mushy_layer_base_dir = os.path.abspath(os.pardir) # params_file = mushyLayerBaseDir + '/params/convergenceTest/FixedChill.parameters' params_file = mushy_layer_base_dir + '/params/convergenceTest/FixedChill.parameters' # Defaults default_params = read_inputs(params_file) extra_params = { 'main.max_time': float(default_params['main.max_time']), 'parameters.rayleighComp': float(default_params['parameters.rayleighComp']), 'parameters.darcy': float(default_params['parameters.darcy']), 'parameters.compositionRatio': float(default_params['parameters.compositionRatio']), 'parameters.nonDimReluctance': float(default_params['parameters.nonDimReluctance']), 'parameters.prandtl': float(default_params['parameters.prandtl']) } do_amr = True # Pr = 10.0 # fix this for now periodic = False try: opts, _ = getopt.getopt(argv, "t:R:D:C:P:N:A") except getopt.GetoptError as err: print(str(err)) print( 'testHeleShawFixedChill.py -t<max time> -R<Compositional Rayleigh Number> -D<Darcy number> ' '-C<Composition Ratio> -A<do amr> -P<true(1)/false(0) do plot files> -N<non dimensional reluctance>' ) sys.exit(2) for opt, arg in opts: if opt in "-t": extra_params['main.max_time'] = float(arg) elif opt in "-R": extra_params['parameters.rayleighComp'] = float(arg) elif opt in "-D": extra_params['parameters.darcy'] = float(arg) elif opt in "-C": extra_params['parameters.compositionRatio'] = float(arg) elif opt in "-N": extra_params['parameters.nonDimReluctance'] = float(arg) elif opt in "-P": do_plot_files = bool(int(arg)) print('Do plot files: ' + str(do_plot_files) + ', arg = ' + str(arg)) if not do_plot_files: extra_params['main.plot_interval'] = -1 elif opt in "-A": do_amr = True base_output_dir = get_base_output_dir() print(Fore.GREEN + 'Setup tests for fixed chill in a Hele-Shaw cell' + Style.RESET_ALL) physical_problem = 'FixedChill' folder_name = "FixedChill-t%1.1e-Ra%.0e-Da%1.1e-C%1.2f-Rel%1.1e" % ( extra_params['main.max_time'], extra_params['parameters.rayleighComp'], extra_params['parameters.darcy'], extra_params['parameters.compositionRatio'], extra_params['parameters.nonDimReluctance']) if periodic: folder_name = folder_name + '-periodic' data_folder = os.path.join(base_output_dir, folder_name) analysis_command = get_matlab_base_command( ) + ' "%s; exit;"' % fixed_chill_command(folder_name + '-0') single_run = True if single_run: num_proc = 1 default_params['concise_run_name'] = folder_name default_params = add_params(default_params, extra_params) # Overwrite default params with any extra params we've specified default_params = add_params(default_params, extra_params) allow_restarts = False s = BatchJob('', default_params['concise_run_name'], '', num_proc) s.set_post_process(analysis_command) ml_run = MushyLayerRunSimple(base_output_dir, num_proc, default_params, s, allow_restarts, get_executable_name()) ml_run.single_run(folder_name) else: # Nz_uniform = 256 # Nz_amr_2 = int(float(Nz_uniform) / 2) # Nz_amr_4 = int(float(Nz_uniform) / 4) # amr_setup = [{'max_level': 0, 'ref_rat': 1, 'run_types': ['uniform'], 'Nzs': [Nz_uniform]}, # {'max_level': 1, 'ref_rat': 2, 'run_types': ['amr'], 'Nzs': [Nz_amr_2]}, # {'max_level': 2, 'ref_rat': 2, 'run_types': ['amr'], 'Nzs': [Nz_amr_4]}, # {'max_level': 1, 'ref_rat': 4, 'run_types': ['amr'], 'Nzs': [Nz_amr_4]}] # While testing: nz_uniform = [64] # amr_setup = [{'max_level': 0, 'ref_rat': 1, 'run_types': ['uniform'], 'Nzs': Nz_uniform}, # {'max_level': 1, 'ref_rat': 2, 'run_types': ['amr'], 'Nzs': [64]}] amr_setup = [{ 'max_level': 0, 'ref_rat': 1, 'run_types': ['uniform'], 'Nzs': nz_uniform }] if do_amr: amr_setup.append({ 'max_level': 1, 'ref_rat': 2, 'run_types': ['amr'], 'Nzs': nz_uniform }) amr_setup.append({ 'max_level': 2, 'ref_rat': 2, 'run_types': ['amr'], 'Nzs': nz_uniform }) num_procs = [1] # Needs to be as long as the longest Nzs run_test(data_folder, physical_problem, hele_shaw_resolution_specific_params, amr_setup, num_procs, analysis_command, extra_params, 0)
def testPorousMushyHole(argv): # Defaults: max_time = 1.5e-4 hole_radius = 0.04 try: opts, args = getopt.getopt(argv, "t:h:") except getopt.GetoptError as err: print(str(err)) print('testPorousMushyHole.py -t<max time> -h<hole radius=0.02>') sys.exit(2) for opt, arg in opts: if opt in "-t": max_time = float(arg) elif opt in "-h": hole_radius = float(arg) base_output_dir = get_base_output_dir() matlab_command = get_matlab_base_command() print(Fore.GREEN + 'Setup tests for porous mushy hole' + Style.RESET_ALL) physicalProblem = 'PorousMushyHole' # dataFolder = os.path.join(base_output_dir, 'PorousMushyHole-t' + str(max_time) + '-hole' + str(hole_radius) ) minC = -5.0 # default -5 dataFolder = os.path.join(base_output_dir, 'PorousMushyHole-t%s-minC%s' % (max_time, minC)) Nz_uniform = [16, 32, 64, 128, 256, 512] AMRSetup = [{'max_level': 0, 'ref_rat': 1, 'run_types': ['uniform'], 'Nzs': Nz_uniform}, {'max_level': 1, 'ref_rat': 2, 'run_types': ['amr'], 'Nzs': [16, 32, 64, 128]}, {'max_level': 2, 'ref_rat': 2, 'run_types': ['amr'], 'Nzs': [8, 16, 32, 64]}, {'max_level': 1, 'ref_rat': 4, 'run_types': ['amr'], 'Nzs': [8, 16, 32, 64]}] # While testing: # Nz_uniform = [16, 32, 64] # AMRSetup = [{'max_level': 0, 'ref_rat': 1, 'run_types': ['uniform'], 'Nzs': Nz_uniform}] # Nzs = [16, 32, 64] #num_procs = [1, 1, 1, 4, 4, 4] # Needs to be as long as the longest Nzs num_procs = [1] * len(Nz_uniform) # Setup up the post processing command # figureName = os.path.join(dataFolder, 'noFlow.pdf') uniform_prefix = 'Uniform-' + physicalProblem + '-' python_compare_file = os.path.join(get_mushy_layer_dir(), 'test', 'run_chombo_compare.py') chombo_compare_analyse ='python %s -f %s -a -v Porosity -e L2 -r True -n 8 \n \n' % (python_compare_file, dataFolder) # make_figures = 'Fig7PorousHole(\'' + dataFolder + '\', \'' + dataFolder + '\')' make_figures = porous_hole_command() #analyse_in_matlab = 'analyseVariablePorosityTest(\'' + dataFolder + '\', [' + ','.join([str(a) for a in Nz_uniform]) + '],' \ # 'true, true, \'' + uniform_prefix + '\', \'Porosity\', \'L2\');' analysis_command = chombo_compare_analyse + '\n\n' + \ matlab_command + ' " %s; exit;"' % make_figures # Run extra_params = {'main.max_time':max_time, 'main.radius': hole_radius, 'bc.bulkConcentrationHiVal' : [-1, minC]} runTest(dataFolder, physicalProblem, porous_mushy_hole_resolution_specific_params, AMRSetup, num_procs, analysis_command, extra_params)