From a5ba3a3dfec8783072036181dad04ccec1f60969 Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Thu, 23 Jan 2020 16:47:01 +0000 Subject: [PATCH] added some tests --- tests/population/grid_tests.py | 218 +++++++++++++++++++-------------- 1 file changed, 124 insertions(+), 94 deletions(-) diff --git a/tests/population/grid_tests.py b/tests/population/grid_tests.py index 538ae76ba..f78b7d7af 100644 --- a/tests/population/grid_tests.py +++ b/tests/population/grid_tests.py @@ -61,32 +61,32 @@ test_pop.set( ## Custom logging with bigger print statement: -test_pop.set(M_1=100, M_2=1, metallicity=0.0002, orbital_period=500000000) -test_pop.set( - C_logging_code=""" - if(stardata->star[0].stellar_type>=MS) - { - if (stardata->model.time < stardata->model.max_evolution_time) - { - Printf("DAVID_SCO %30.12e %g %g %g %g %d %d\\n", - // - stardata->model.time, // 1 - - stardata->star[0].mass, //2 - stardata->previous_stardata->star[0].mass, //3 - - stardata->star[0].radius, //4 - stardata->previous_stardata->star[0].radius, //5 - - stardata->star[0].stellar_type, //6 - stardata->previous_stardata->star[0].stellar_type //7 - ); - }; - /* Kill the simulation to save time */ - // stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm; - }; -""" -) +# test_pop.set(M_1=100, M_2=1, metallicity=0.0002, orbital_period=500000000) +# test_pop.set( +# C_logging_code=""" +# if(stardata->star[0].stellar_type>=MS) +# { +# if (stardata->model.time < stardata->model.max_evolution_time) +# { +# Printf("DAVID_SCO %30.12e %g %g %g %g %d %d\\n", +# // +# stardata->model.time, // 1 + +# stardata->star[0].mass, //2 +# stardata->previous_stardata->star[0].mass, //3 + +# stardata->star[0].radius, //4 +# stardata->previous_stardata->star[0].radius, //5 + +# stardata->star[0].stellar_type, //6 +# stardata->previous_stardata->star[0].stellar_type //7 +# ); +# }; +# /* Kill the simulation to save time */ +# // stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm; +# }; +# """ +# ) # test_pop.evolve_population() @@ -103,74 +103,73 @@ test_pop.set( ################# Parse function ## Testing some stuff out with giving a parse_function. -test_pop.set( - C_logging_code=""" - if(stardata->star[0].stellar_type>=NS) - { - if (stardata->model.time < stardata->model.max_evolution_time) - { - Printf("DAVID_SCO %30.12e %g %g %g %g %d %d\\n", - // - stardata->model.time, // 1 - - stardata->star[0].mass, //2 - stardata->previous_stardata->star[0].mass, //3 - - stardata->star[0].radius, //4 - stardata->previous_stardata->star[0].radius, //5 - - stardata->star[0].stellar_type, //6 - stardata->previous_stardata->star[0].stellar_type //7 - ); - }; - /* Kill the simulation to save time */ - stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm; - }; -""" -) - - -def output_lines(output): - """ - Function that outputs the lines that were recieved from the binary_c run. - """ - return output.splitlines() - -def parse_function(self, output): - # extract info from the population instance - # TODO: think about whether this is smart. Passing around this object might be an overkill - - # Get some information from the - data_dir = self.custom_options['data_dir'] - base_filename = self.custom_options['base_filename'] - outfilename = os.path.join(data_dir, base_filename) - - # TODO: make population settings available in this function - for el in output_lines(output): - headerline = el.split()[0] - - if (headerline=='DAVID_SCO'): - parameters = ['time', 'mass_1', 'prev_mass_1', 'radius_1', 'prev_radius_1', 'stellar_type_1', 'prev_stellar_type_1'] - values = el.split()[1:] - seperator='\t' - - if not os.path.exists(outfilename): - with open(outfilename, 'w') as f: - f.write(seperator.join(parameters)+'\n') - - with open(outfilename, 'a') as f: - f.write(seperator.join(values)+'\n') - - -#test_pop.evolve_single(parse_function) -test_pop.set(M_1=90, data_dir=os.path.join(os.environ['BINARYC_DATA_ROOT'], 'testing_python'), base_filename='test_pop.dat') -test_pop.evolve_single(parse_function) -test_pop.set(M_1=80) -test_pop.evolve_single(parse_function) -test_pop.set(M_1=70) -test_pop.evolve_single(parse_function) -test_pop.set(M_1=60) -test_pop.evolve_single(parse_function) +# test_pop.set( +# C_logging_code=""" +# if(stardata->star[0].stellar_type>=NS) +# { +# if (stardata->model.time < stardata->model.max_evolution_time) +# { +# Printf("DAVID_SCO %30.12e %g %g %g %g %d %d\\n", +# // +# stardata->model.time, // 1 + +# stardata->star[0].mass, //2 +# stardata->previous_stardata->star[0].mass, //3 + +# stardata->star[0].radius, //4 +# stardata->previous_stardata->star[0].radius, //5 + +# stardata->star[0].stellar_type, //6 +# stardata->previous_stardata->star[0].stellar_type //7 +# ); +# }; +# /* Kill the simulation to save time */ +# stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm; +# }; +# """ +# ) + +# def output_lines(output): +# """ +# Function that outputs the lines that were recieved from the binary_c run. +# """ +# return output.splitlines() + +# def parse_function(self, output): +# # extract info from the population instance +# # TODO: think about whether this is smart. Passing around this object might be an overkill + +# # Get some information from the +# data_dir = self.custom_options['data_dir'] +# base_filename = self.custom_options['base_filename'] +# outfilename = os.path.join(data_dir, base_filename) + +# # TODO: make population settings available in this function +# for el in output_lines(output): +# headerline = el.split()[0] + +# if (headerline=='DAVID_SCO'): +# parameters = ['time', 'mass_1', 'prev_mass_1', 'radius_1', 'prev_radius_1', 'stellar_type_1', 'prev_stellar_type_1'] +# values = el.split()[1:] +# seperator='\t' + +# if not os.path.exists(outfilename): +# with open(outfilename, 'w') as f: +# f.write(seperator.join(parameters)+'\n') + +# with open(outfilename, 'a') as f: +# f.write(seperator.join(values)+'\n') + + +# #test_pop.evolve_single(parse_function) +# test_pop.set(M_1=90, data_dir=os.path.join(os.environ['BINARYC_DATA_ROOT'], 'testing_python'), base_filename='test_pop.dat') +# test_pop.evolve_single(parse_function) +# test_pop.set(M_1=80) +# test_pop.evolve_single(parse_function) +# test_pop.set(M_1=70) +# test_pop.evolve_single(parse_function) +# test_pop.set(M_1=60) +# test_pop.evolve_single(parse_function) ################## ## CHeck size of commands: @@ -203,3 +202,34 @@ test_pop.evolve_single(parse_function) # plt.savefig('sizes_for_commands.png') # plt.show() + + +### Grid generating test. +test_pop.add_grid_variable( + name='lnm1', + longname='log primary mass', + valuerange=[10, 20], + resolution='10', + spacingfunc='const()', + precode='m2=m1**2', + probdist='flat()', + dphasevol='', + parameter_name='M_1', + condition='', +) + +### Grid generating test. +test_pop.add_grid_variable( + name='period', + longname='period', + valuerange=['m1', 20], + resolution='10', + spacingfunc='const()', + precode='', + probdist='flat()', + parameter_name='orbital_period', + dphasevol='', + condition='', +) + +test_pop.generate_grid_code() \ No newline at end of file -- GitLab