diff --git a/src/perl/modules_targz/Binning-0.03.tar.gz b/src/perl/modules_targz/Binning-0.03.tar.gz index 86e0a90cb6ca354d90ddf4ce4094a5f3d9a12bba..b6e060d05f523474cbba91b49baa29eec0763a64 100644 Binary files a/src/perl/modules_targz/Binning-0.03.tar.gz and b/src/perl/modules_targz/Binning-0.03.tar.gz differ diff --git a/src/perl/modules_targz/Data-Serializer-RobJSON-0.05.tar.gz b/src/perl/modules_targz/Data-Serializer-RobJSON-0.05.tar.gz index e18051f942dc7f599492d9629bc7e2f80d66828c..f5a024c8c9beda5b23beffeddca9c411864cebe4 100644 Binary files a/src/perl/modules_targz/Data-Serializer-RobJSON-0.05.tar.gz and b/src/perl/modules_targz/Data-Serializer-RobJSON-0.05.tar.gz differ diff --git a/src/perl/modules_targz/Hash-RobMerge-0.14.tar.gz b/src/perl/modules_targz/Hash-RobMerge-0.14.tar.gz index 4b7db49ccef3626a3ea6cdc8f1acbdc3799247b7..8349ed868eb22d674bd881f97433c3279374108a 100644 Binary files a/src/perl/modules_targz/Hash-RobMerge-0.14.tar.gz and b/src/perl/modules_targz/Hash-RobMerge-0.14.tar.gz differ diff --git a/src/perl/modules_targz/Histogram-0.01.tar.gz b/src/perl/modules_targz/Histogram-0.01.tar.gz index 57a60630a25c5045e9aced5aaa12625aa4a7e5f4..7dd29c41e986ce30229bde7de3b89fb67f3ef359 100644 Binary files a/src/perl/modules_targz/Histogram-0.01.tar.gz and b/src/perl/modules_targz/Histogram-0.01.tar.gz differ diff --git a/src/perl/modules_targz/IMF-0.05.tar.gz b/src/perl/modules_targz/IMF-0.05.tar.gz index a21ca271fef0a643d984cb32a6a4d8622c74eb4f..7fdf591bdbcf698bfc36a7979f7b9a1568f3534d 100644 Binary files a/src/perl/modules_targz/IMF-0.05.tar.gz and b/src/perl/modules_targz/IMF-0.05.tar.gz differ diff --git a/src/perl/modules_targz/Maths_Double-0.01.tar.gz b/src/perl/modules_targz/Maths_Double-0.01.tar.gz index d48413dbab3350e75682a3025335ce1b6713ae89..cee57998a722d7bcf6cee4f91de9d09cd930df80 100644 Binary files a/src/perl/modules_targz/Maths_Double-0.01.tar.gz and b/src/perl/modules_targz/Maths_Double-0.01.tar.gz differ diff --git a/src/perl/modules_targz/binary_grid-v2.1.6.tar.gz b/src/perl/modules_targz/binary_grid-v2.1.6.tar.gz index 7118ff195338d1ba0c3fd8f2eca7461eb8022378..d27696f6c6d8f3df89cc93b6dfdd538963cac2d8 100644 Binary files a/src/perl/modules_targz/binary_grid-v2.1.6.tar.gz and b/src/perl/modules_targz/binary_grid-v2.1.6.tar.gz differ diff --git a/src/perl/modules_targz/binary_stars-0.05.tar.gz b/src/perl/modules_targz/binary_stars-0.05.tar.gz index e5a2d0262c86a6ff247e035128caf2fa32f1be1a..91223f6470ff0a1c0861f73cc300562b1ad76a3b 100644 Binary files a/src/perl/modules_targz/binary_stars-0.05.tar.gz and b/src/perl/modules_targz/binary_stars-0.05.tar.gz differ diff --git a/src/perl/modules_targz/cosmology-0.01.tar.gz b/src/perl/modules_targz/cosmology-0.01.tar.gz index 2d55249c96d697396f070202176aea19c8577bab..56949175cb74e8f772e1fc015bd9920107b1cd61 100644 Binary files a/src/perl/modules_targz/cosmology-0.01.tar.gz and b/src/perl/modules_targz/cosmology-0.01.tar.gz differ diff --git a/src/perl/modules_targz/distribution_functions-0.05.tar.gz b/src/perl/modules_targz/distribution_functions-0.05.tar.gz index 9b8b4cc988fac1a45fa1872a4fb68ad6d29ddad3..e7ce91f554666bcb06dbdf57cef1bcace575b98c 100644 Binary files a/src/perl/modules_targz/distribution_functions-0.05.tar.gz and b/src/perl/modules_targz/distribution_functions-0.05.tar.gz differ diff --git a/src/perl/modules_targz/rob_misc-0.16.tar.gz b/src/perl/modules_targz/rob_misc-0.16.tar.gz index 05088ecd69ccc80a0ba36bc34ab067c682cc7b8e..464397c25e0ebc4b53d05241a55ca173cb23c91b 100644 Binary files a/src/perl/modules_targz/rob_misc-0.16.tar.gz and b/src/perl/modules_targz/rob_misc-0.16.tar.gz differ diff --git a/src/perl/modules_targz/robqueue-0.05.tar.gz b/src/perl/modules_targz/robqueue-0.05.tar.gz index 04f3cba26c2db6ac09d03d1002c5d54cc80b1d57..bac9ff210f7186deb74103789e78e919078a8be9 100644 Binary files a/src/perl/modules_targz/robqueue-0.05.tar.gz and b/src/perl/modules_targz/robqueue-0.05.tar.gz differ diff --git a/src/perl/modules_targz/spacing_functions-0.02.tar.gz b/src/perl/modules_targz/spacing_functions-0.02.tar.gz index d6aa7232d7258c50217d9c56e90087f82c5f0194..816eb0900f2e67a6daad5a7111785d1264d3b7ff 100644 Binary files a/src/perl/modules_targz/spacing_functions-0.02.tar.gz and b/src/perl/modules_targz/spacing_functions-0.02.tar.gz differ diff --git a/src/perl/scripts2/runlist.pl b/src/perl/scripts2/runlist.pl new file mode 100755 index 0000000000000000000000000000000000000000..4eb169149fec728fb61167d7390070fe650dc9c2 --- /dev/null +++ b/src/perl/scripts2/runlist.pl @@ -0,0 +1,251 @@ +#!/usr/bin/env perl +use strict; # recommended +use 5.16.0; # recommended +use binary_grid2; # required +use binary_grid::C; # backend : C +use rob_misc qw/ncpus/; + +############################################################ +# +# Example script to demonstrate how to use the +# binary_grid2 module. +# +# For full documentation, please see binary_grid2.pdf +# in the doc/ directory of binary_c +# +############################################################ + +# number of computational threads to launch, usually one +# per CPU +my $nthreads = rob_misc::ncpus(); + +############################################################ +# Binary_c should output data that we can understand here. +# There are two ways to do this: +# +# 1) Put output statements, using Printf, in binary_c's +# log_every_timestep() function. This requires a rebuild +# of libbinary_c.so and a reinstall of the binary_grid module +# every time you change the Printf statement. +# +# +# 2) Put a list of hashes in the C_auto_logging grid option +# +# $population->set( +# C_auto_logging => { +# 'MY_STELLAR_DATA' => +# [ +# 'model.time', +# 'star[0].mass', +# 'model.probability', +# 'model.dt' +# ] +# }); +# +# where MY_STELLAR_DATA is the key of the hash {...} and is also +# the header matched in the parse_data function (below). The list [...] +# contains the names of the variables to be output, which are all +# assumed to be in stardata. +# +# This option does not require a rebuild of libbinary_c.so or a +# reinstall of binary_grid. +# +# +# 3) Put output statements, using Printf, into the C_logging_code +# grid option +# +# $population->set( C_logging_code => ' Printf("...\n"); '); +# +# You have access to the stardata variable, so you can +# output everything that is available to log_every_timestep(); +# +# This option does not require a rebuild of libbinary_c.so or a +# reinstall of binary_grid. +# +############################################################ +# make a new stellar population +my $population = binary_grid2->new( + # options can be given now ... + metallicity => 0.02, # mass fraction of "metals" + max_evolution_time => 15000, # Myr + nthreads=>$nthreads, # number of threads + ); + +# ... or options can be set manually later. +$population->set( + vb=>1, # turn on verbose logging (can be 0,1,2...) + return_array_refs=>1, # quicker data parsing mode + log_args=>1, + sort_args=>1, + save_args=>1, + log_args_dir=>'/tmp', + #log_dt_secs=>1, + C_auto_logging => { + 'MY_STELLAR_DATA' => + [ + 'model.time', + 'star[0].mass', + 'model.probability', + 'model.dt' + ] + }, + +## or enter more complicated code yourself: +# +# C_logging_code => ' +# Printf("MY_STELLAR_DATA %g %g %g %g\n", +# stardata->model.time, +# stardata->star[0].mass, +# stardata->model.probability, +# stardata->model.dt); +# ', + + ); + + +############################################################ +# run from a list of stars in a file : you must set the +# filename to be appropriate +$population->{_grid_options}->{flexigrid}->{'grid type'} = 'list'; +$population->{_grid_options}->{flexigrid}->{'list filename'} = '/tmp/s3'; + + +############################################################ +# scan command line arguments for extra options +$population->parse_args(); + +############################################################ +# link population to custom data parser function +$population->set( + parse_bse_function_pointer => \&main::parse_data + ); + +my %init = $population->initial_abundance_hash('Karakas2002',0.02); +my %isotope_hash = $population->isotope_hash(); +my @isotope_list = $population->isotope_list(); +my %nuclear_mass_hash = $population->nuclear_mass_hash(); +my @nuclear_mass_list = $population->nuclear_mass_list(); +my @sources = $population->source_list(); +my @ensemble = $population->ensemble_list(); + +# you can use Data::Dumper to see the contents +# of the above lists and hashes +if(0){ + print Data::Dumper->Dump([ + #\%init, + #\%isotope_hash, + #\@isotope_list, + #\%nuclear_mass_hash, + \@nuclear_mass_list, + #\@sources, + #\@ensemble + ]); +} + +# uncomment this to show version information +#print $population->evcode_version_string(); + +# uncomment this to show the evcode's default args list +#print join("\n",@{$population->evcode_args_list()}); + +# evolution the stellar population (this takes some time) +$population->evolve(); + +# output the data +output($population); + +# done : exit +exit; + +############################################################ +# subroutines +############################################################ + +sub parse_data +{ + my ($population, $results) = @_; + + my $progenitor = $population->progenitor(); + + # get initial mass and probability for the initial mass function + my $progenitor_initial_mass = + $progenitor->{m1} + $progenitor->{m2}; + my $progenitor_probability = $population->progenitor()->{prob}; + + # bin initial mass + my $binned_initial_mass = $population->rebin($progenitor_initial_mass,1.0); + + # initial mass function + $results->{initial_mass_function}->{$binned_initial_mass} += + $progenitor_probability; + + while(1) + { + # subsequent calls to tbse_line contain + # (references to) arrays of data + my $la = $population->tbse_line(); + + #print "DATA @$la\n"; + + # first element is the "header" line + my $header = shift @$la; + + # break out of the loop if this is 'fin' + last if ($header eq 'fin'); + + # check if $header matches one of your + # expected data lines, if so, act + if($header eq 'MY_STELLAR_DATA') + { + #print "GOT MY_STELLAR_DATA @$la\n"; + + # matched MY_STELLAR_DATA header + # + # get time, mass, probability etc. as specified above + # + # (note that $probability is possibly not the same as + # the progenitor's probability!) + my $time = $la->[0]; + my $mass = $la->[1]; + my $probability = $la->[2]; + my $timestep = $la->[3]; + + # bin mass to nearest 1.0 Msun + $mass = $population->rebin($mass, 1.0); + + # add up the mass distribution + $results->{mass_distribution}->{$mass} += $probability * $timestep; + } + } +} + +############################################################ + +sub output +{ + my ($population) = @_; + + # $results is a hash reference containing + # the results that were added up in parse_data() + my $results = $population->results; + + if(0) + { + # show results hash in full + print "############################################################\n"; + print Data::Dumper::Dumper($results); + print "############################################################\n"; + } + + # output the initial mass function + foreach my $mass (sort {$a<=>$b} keys %{$results->{initial_mass_function}}) + { + printf "IMF %g %g\n",$mass,$results->{initial_mass_function}->{$mass}; + } + + # output the mass distribution + foreach my $mass (sort {$a<=>$b} keys %{$results->{mass_distribution}}) + { + printf "MASS %g %g\n",$mass,$results->{mass_distribution}->{$mass}; + } +} diff --git a/src/perl/scripts2/template.pl b/src/perl/scripts2/template.pl index e5cf57e7d9793e84caf2f85390d4838141998669..4c6a4d789c89f564c86182890a2cfa55b8c26f6a 100755 --- a/src/perl/scripts2/template.pl +++ b/src/perl/scripts2/template.pl @@ -102,9 +102,6 @@ $population->set( ); -print Data::Dumper::Dumper($population->evcode_args_list()); -exit; - ############################################################ # scan command line arguments for extra options $population->parse_args();