Skip to content
Snippets Groups Projects
Commit a5ba3a3d authored by David Hendriks's avatar David Hendriks
Browse files

added some tests

parent 3bc0755e
No related branches found
No related tags found
No related merge requests found
...@@ -61,32 +61,32 @@ test_pop.set( ...@@ -61,32 +61,32 @@ test_pop.set(
## Custom logging with bigger print statement: ## Custom logging with bigger print statement:
test_pop.set(M_1=100, M_2=1, metallicity=0.0002, orbital_period=500000000) # test_pop.set(M_1=100, M_2=1, metallicity=0.0002, orbital_period=500000000)
test_pop.set( # test_pop.set(
C_logging_code=""" # C_logging_code="""
if(stardata->star[0].stellar_type>=MS) # if(stardata->star[0].stellar_type>=MS)
{ # {
if (stardata->model.time < stardata->model.max_evolution_time) # if (stardata->model.time < stardata->model.max_evolution_time)
{ # {
Printf("DAVID_SCO %30.12e %g %g %g %g %d %d\\n", # Printf("DAVID_SCO %30.12e %g %g %g %g %d %d\\n",
// # //
stardata->model.time, // 1 # stardata->model.time, // 1
stardata->star[0].mass, //2 # stardata->star[0].mass, //2
stardata->previous_stardata->star[0].mass, //3 # stardata->previous_stardata->star[0].mass, //3
stardata->star[0].radius, //4 # stardata->star[0].radius, //4
stardata->previous_stardata->star[0].radius, //5 # stardata->previous_stardata->star[0].radius, //5
stardata->star[0].stellar_type, //6 # stardata->star[0].stellar_type, //6
stardata->previous_stardata->star[0].stellar_type //7 # stardata->previous_stardata->star[0].stellar_type //7
); # );
}; # };
/* Kill the simulation to save time */ # /* Kill the simulation to save time */
// stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm; # // stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm;
}; # };
""" # """
) # )
# test_pop.evolve_population() # test_pop.evolve_population()
...@@ -103,74 +103,73 @@ test_pop.set( ...@@ -103,74 +103,73 @@ test_pop.set(
################# Parse function ################# Parse function
## Testing some stuff out with giving a parse_function. ## Testing some stuff out with giving a parse_function.
test_pop.set( # test_pop.set(
C_logging_code=""" # C_logging_code="""
if(stardata->star[0].stellar_type>=NS) # if(stardata->star[0].stellar_type>=NS)
{ # {
if (stardata->model.time < stardata->model.max_evolution_time) # if (stardata->model.time < stardata->model.max_evolution_time)
{ # {
Printf("DAVID_SCO %30.12e %g %g %g %g %d %d\\n", # Printf("DAVID_SCO %30.12e %g %g %g %g %d %d\\n",
// # //
stardata->model.time, // 1 # stardata->model.time, // 1
stardata->star[0].mass, //2 # stardata->star[0].mass, //2
stardata->previous_stardata->star[0].mass, //3 # stardata->previous_stardata->star[0].mass, //3
stardata->star[0].radius, //4 # stardata->star[0].radius, //4
stardata->previous_stardata->star[0].radius, //5 # stardata->previous_stardata->star[0].radius, //5
stardata->star[0].stellar_type, //6 # stardata->star[0].stellar_type, //6
stardata->previous_stardata->star[0].stellar_type //7 # stardata->previous_stardata->star[0].stellar_type //7
); # );
}; # };
/* Kill the simulation to save time */ # /* Kill the simulation to save time */
stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm; # stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm;
}; # };
""" # """
) # )
# def output_lines(output):
def output_lines(output): # """
""" # Function that outputs the lines that were recieved from the binary_c run.
Function that outputs the lines that were recieved from the binary_c run. # """
""" # return output.splitlines()
return output.splitlines()
# def parse_function(self, output):
def parse_function(self, output): # # extract info from the population instance
# extract info from the population instance # # TODO: think about whether this is smart. Passing around this object might be an overkill
# TODO: think about whether this is smart. Passing around this object might be an overkill
# # Get some information from the
# Get some information from the # data_dir = self.custom_options['data_dir']
data_dir = self.custom_options['data_dir'] # base_filename = self.custom_options['base_filename']
base_filename = self.custom_options['base_filename'] # outfilename = os.path.join(data_dir, base_filename)
outfilename = os.path.join(data_dir, base_filename)
# # TODO: make population settings available in this function
# TODO: make population settings available in this function # for el in output_lines(output):
for el in output_lines(output): # headerline = el.split()[0]
headerline = el.split()[0]
# if (headerline=='DAVID_SCO'):
if (headerline=='DAVID_SCO'): # parameters = ['time', 'mass_1', 'prev_mass_1', 'radius_1', 'prev_radius_1', 'stellar_type_1', 'prev_stellar_type_1']
parameters = ['time', 'mass_1', 'prev_mass_1', 'radius_1', 'prev_radius_1', 'stellar_type_1', 'prev_stellar_type_1'] # values = el.split()[1:]
values = el.split()[1:] # seperator='\t'
seperator='\t'
# if not os.path.exists(outfilename):
if not os.path.exists(outfilename): # with open(outfilename, 'w') as f:
with open(outfilename, 'w') as f: # f.write(seperator.join(parameters)+'\n')
f.write(seperator.join(parameters)+'\n')
# with open(outfilename, 'a') as f:
with open(outfilename, 'a') as f: # f.write(seperator.join(values)+'\n')
f.write(seperator.join(values)+'\n')
# #test_pop.evolve_single(parse_function)
#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.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.evolve_single(parse_function) # test_pop.set(M_1=80)
test_pop.set(M_1=80) # test_pop.evolve_single(parse_function)
test_pop.evolve_single(parse_function) # test_pop.set(M_1=70)
test_pop.set(M_1=70) # test_pop.evolve_single(parse_function)
test_pop.evolve_single(parse_function) # test_pop.set(M_1=60)
test_pop.set(M_1=60) # test_pop.evolve_single(parse_function)
test_pop.evolve_single(parse_function)
################## ##################
## CHeck size of commands: ## CHeck size of commands:
...@@ -203,3 +202,34 @@ test_pop.evolve_single(parse_function) ...@@ -203,3 +202,34 @@ test_pop.evolve_single(parse_function)
# plt.savefig('sizes_for_commands.png') # plt.savefig('sizes_for_commands.png')
# plt.show() # 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment