This tutorial demonstrates how to use example codes in the libnucnet distribution examples/ directory.

Example 34: Merge a nuclear data xml file and a reaction data xml file to create a single network data xml file.

The example code is merge_net.c

One way to do this is to use xsltproc (which you should have installed as described in the compile tutorial). To do this, type:


xsltproc --stringparam reac_doc ../data_pub/example_reac.xml ../xsl_pub/merge_net.xsl ../data_pub/example_nuc.xml > ../data_pub/example_net.xml

It is also possible to use libnucnet routines themselves (including the use of XPath expressions). To create a network with only neutrons and protons and species with Z >= 26, type:


./merge_net ../data_pub/example_nuc.xml ../data_pub/example_reac.xml "[(a = 1) or (z >= 26)]" ex34_output_xpath.xml

The result is ex34_output_xpath.xml

Example 35: Create a nuclear reaction network from an input xml file and print the valid reactions (those between nuclei in the network) and the invalid reactions (those between nuclei not in the network).

The example code is print_valid_reactions.c

To run print_valid_reactions, type the following on the command line:


./print_valid_reactions ../data_pub/example_net.xml > ex35_output.txt

The result is ex35_output.txt

Example 36: Create a nuclear reaction network from input xml files and print the reaction Q values for the valid reactions.

The example code is print_Qvalues.c

To run print_Qvalues, type the following on the command line:


./print_Qvalues ../data_pub/example_nuc.xml ../data_pub/example_reac.xml > ex36_output.txt

The result is ex36_output.txt

Example 37: Create a latex table of the valid reactions in a network.

The example code is create_valid_reaction_latex_table.c

To run create_valid_reaction_latex_table, type the following on the command line:


./create_valid_reaction_latex_table ../data_pub/example_net.xml ex37_output.tex

The result is ex37_output.tex

Example 38: Create a nuclear reaction network from an input xml file and print the forward and reverse rates for all valid reactions at the input temperature.

The example code is print_forward_and_reverse_at_t9.c

To print out the forward and reverse rates at t9 = 1, type:


./print_forward_and_reverse_at_t9 ../data_pub/example_net.xml 1. > ex38_output.txt

The result is ex38_output.txt

To print out the forward and reverse rates at t9 = 1 but only for nuclei with atomic number less than or equal to 15 and for reactions that have h1 as a reaction, include XPath expressions:


./print_forward_and_reverse_at_t9 ../data_pub/example_net.xml 1. "[z <= 15]" "[reactant = 'h1']" > ex38_output_xpath.txt

The result is ex38_output_xpath.txt

Example 39: Create a nuclear reaction network from an input xml file and print the forward and reverse rates for a particular reaction (chosen by its string) at a variety of temperatures.

The example code is print_forward_and_reverse_by_string.c

Choose a particular reaction with a string. For example, try:


./print_forward_and_reverse_by_string ../data_pub/example_net.xml "c12 + he4 -> o16 + gamma" > ex39_output.txt

The result is ex39_output.txt

Example 40: Create a nuclear reaction network from an input xml file and print the forward and reverse rates for a particular reaction or set of reactions (chosen by an xpath expression) at a variety of temperatures.

The example code is print_forward_and_reverse_by_xpath.c

Choose a reaction or set of reactions with an xpath expression. For example, try:


./print_forward_and_reverse_by_xpath ../data_pub/example_net.xml "[reactant = 'ne21']" > ex40_output.txt

The result is ex40_output.txt

Example 41: Create a nuclear reaction network from an input xml file and check that the forward and reverse rates lie within lower and upper bounds for a given temperature range.

The example code is check_rates.c

To find the forward and reverse rates (for the network in the input file) that are less than 0 or greater than 1.e14 in the temperature range 1.e-3 to 10 billion Kelvins, type:


./check_rates ../data_pub/example_net.xml 1.e-3 10. 0. 1.e14 > ex41_output.txt

The result is ex41_output.txt

Example 42: Create a nuclear reaction network from an input xml file and print the forward and reverse rates at the input temperature and then double the rates and print them out again.

The example code is double_rates.c

To print and double the forward and reverse rates at t9 = 3, type:


./double_rates ../data_pub/example_net.xml 3. > ex42_output.txt

The result is ex42_output.txt

You can also select out certain reactions with an xpath expression. For example, try:


./double_rates ../data_pub/example_net.xml 3. "[product = 'mg25']" > ex42_output_xpath.txt

The result is ex42_output_xpath.txt

Example 43: Create a nuclear reaction network from an input xml file and for rates selected by an XPath expression, print out the forward and reverse rates, the forward screening factor, the reverse ratio correction, and the screened rates.

The example code is print_screened_rates.c

To print the correction factor and screened rates for reactions involving n15 as a reactant at t9 = 3, a mass density of 1.e8 g/cc, an electron-to-baryon ratio of 0.5, and a second moment of the abundances with respect to atomic number of 0.15, type:


./print_screened_rates ../data_pub/example_net.xml 3. 1.e8 0.5 0.15 "[reactant = 'n15']" > ex43_output.txt

The result is ex43_output.txt

Example 44: Merge a network xml file and an input mass fractions data xml file into a single libnucnet input xml file.

The example code is merge_full.c

One way to do this is to use xsltproc (which you should have installed during the compilation tutorial). To do so, type:


xsltproc --stringparam initial_mass_frac_doc ../data_pub/initial_mass_fractions_3d.xml ../xsl_pub/merge_full.xsl ../data_pub/example_net.xml > ../data_pub/example_3d.xml

You can alternatively use libnucnet routines. For example, type:


./merge_full ../data_pub/example_net.xml ../data_pub/initial_mass_fractions_single_zone.xml ../data_pub/example_single_zone.xml

You can use XPath. For example, to include only nuclei up to Z = 24, type:


./merge_full ../data_pub/example_net.xml ../data_pub/initial_mass_fractions_1d.xml "[z <= 24]" ../data_pub/example_1d.xml

You can also use XInclude with XPath. For example, to include only nuclei up to Z = 24 from included files, type:


./merge_full ../data_pub/example_net.xml ../data_pub/initial_mass_fractions_1d_include.xml "[z <= 24]" ../data_pub/example_1d_include.xml

Example 45: Merge a network xml file and an input mass fractions data xml file into a single libnucnet input xml file without building a tree.

The example code is merge_full_with_reader_and_writer.c

To do a basic merge (without indenting the output), type:


./merge_full_with_reader_and_writer ../data_pub/example_net.xml ../data_pub/initial_mass_fractions_single_zone.xml 0 ../data_pub/example_single_zone.xml

Since the example did not indent the xml, you can get a more readable output by pretty printing the file with xmllint. To do so, type:


xmllint --pretty 1 ../data_pub/example_single_zone.xml > ../data_pub/example_single_zone_pretty.xml

In performing the merge, you can use XPath. For example, to include only nuclei up to Z = 20 (non-indented ouput), type:


./merge_full_with_reader_and_writer ../data_pub/example_net.xml ../data_pub/initial_mass_fractions_1d.xml 0 ".//z[. <= 20]" ../data_pub/example_1d.xml

You can also use XInclude with XPath. For example, to include only nuclei up to Z = 20 from included files (indented output), type:


./merge_full_with_reader_and_writer ../data_pub/example_net.xml ../data_pub/initial_mass_fractions_1d_include.xml 1 ".//z[. <= 20]" ../data_pub/example_1d_include.xml

Example 46: Create a full libnucnet nuclear reaction network structure (nuclei plus reactions among them) from an input xml file print out data about the input zones, remove the zones, and add a zone.

The example code is create_zones.c

To run create_zones, type the following on the command line:


./create_zones ../data_pub/example_3d.xml > ex46_output.txt

The result is ex46_output.txt

Example 47: Create a full libnucnet structure (network plus zones) and print out data about the zones.

The example code is print_zone_data.c

To run print_zone_data, type the following on the command line:


./print_zone_data ../data_pub/example_3d.xml > ex47_output.txt

The result is ex47_output.txt

Example 48: Create a full libnucnet structure (network plus zones) and print out mass fractions for a zone chosen by its labels.

The example code is print_zone_mass_fractions_by_labels.c

To run print_zone_mass_fractions_by_labels, type the following on the command line:


./print_zone_mass_fractions_by_labels ../data_pub/example_net.xml ../data_pub/initial_mass_fractions_3d.xml x1 y1 z1 > ex48_output.txt

The result is ex48_output.txt

Example 49: Print out the abundances in a zone as a function of neutron number (or atomic number "z" or mass number "a").

The example code is print_zone_abundances_by_nucleon_number.c

To run print_zone_abundances_by_nucleon_number, type the following on the command line:


./print_zone_abundances_by_nucleon_number ../data_pub/example_nuc.xml ../data_pub/initial_mass_fractions_3d.xml x1 y1 z1 "n" > ex49_output.txt

The result is ex49_output.txt

Example 50: Create a full libnucnet structure (network plus zones) and print out the quantum abundances and chemical potentials (in Maxwell-Boltzmann statistics) at the input temperature and density for a zone chosen by its labels.

The example code is print_zone_quantum_abunds.c

To run print_zone_quantum_abunds, type the following on the command line:


./print_zone_quantum_abunds ../data_pub/example_nuc.xml ../data_pub/initial_mass_fractions_single_zone.xml 1 1.e5 0 0 0 > ex50_output.txt

The result is ex50_output.txt

Example 51: Create a full libnucnet structure (network plus zones) and print out mass fractions for a given species in all zones.

The example code is print_nuclide_mass_fractions_in_zones.c

To run print_nuclide_mass_fractions_in_zones, type the following on the command line:


./print_nuclide_mass_fractions_in_zones ../data_pub/example_nuc.xml ../data_pub/initial_mass_fractions_stooges.xml he4 > ex51_output.txt

The result is ex51_output.txt

Example 52: Create network views of valid reactions of various types, store them in a zone, and iterate the views in the zone to print out the number of reactions in each view.

The example code is print_views.c

To run print_views, type the following on the command line:


./print_views ../data_pub/example_net.xml > ex52_output.txt

The result is ex52_output.txt

Example 53: Create a zone mass fractions file from a Rauscher et al. (2002) stellar model data file.

The example code is star_read.c

To run star_read, type the following on the command line:


./star_read ../data_pub/star_read_nuc.xml ../data_pub/star_data.txt 1 ex53_output.xml

The result is ex53_output.xml

Example 54: Extract a subset of zones containing a subset of nuclei from the original zone xml file and dump to a new xml.

The example code is extract_zone_nuclide_subset.c

To run extract_zone_nuclide_subset, type the following on the command line:


./extract_zone_nuclide_subset ../data_pub/star_read_nuc.xml ../data_pub/s25a28d_expl.xml "[(@label1 >= '214' and @label1 <= '216') or @label1 = 'wind']" "[ z <= 30 ]" ex54_output.xml

The result is ex54_output.xml

More complicated xpath expressions are possible. For example to extract zones for which the the mass fraction of iron-60 is greater than 1.e-10 and include them in a file that includes only species with z < 30, type:


./extract_zone_nuclide_subset ../data_pub/star_read_nuc.xml ../data_pub/s25a28d_expl.xml "[mass_fractions/nuclide[@name='fe60' and x > 1.e-10]]" "[ z <= 30 ]" ex54_output_xpath2.xml

The result is ex54_output_xpath2.xml

Example 55: Average the abundances in the zones.

The example code is average_zones.c

To average the abundances in the zones by number (that is, by fractional contribution from each zone), type:


./average_zones ../data_pub/star_read_nuc.xml ../data_pub/s25a28d_expl.xml ../data_pub/average.txt number ex55_output.xml

The result is ex55_output.xml

It is also possible to average the abundances by zone mass (although for the present data file, the results will be the same as by number because all the zones have the same mass). To average by mass, type:


./average_zones ../data_pub/star_read_nuc.xml ../data_pub/s25a28d_expl.xml ../data_pub/average.txt mass ex55_output_mass.xml

The result is ex55_output_mass.xml

Example 56: Create a full libnucnet structure (network plus zones) and print out the the forward and reverse rates for the zone using detailed balance for the reverse rates (or not).

The example code is print_zone_rates.c

To print out the forward and reverse rates for the zone with labels 0, 0, 0 at t9 = 6 and mass density = 1.e9 g/cc using detailed balance, type:


./print_zone_rates ../data_pub/example_single_zone.xml 6. 1.e9 0 0 0 on > ex56_output.txt

The result is ex56_output.txt

To the zone rates but without computing the reverse rates, type:


./print_zone_rates ../data_pub/example_single_zone.xml 6. 1.e9 0 0 0 off > ex56_output_off.txt

The result is ex56_output_off.txt

Example 57: Create a full libnucnet structure (network plus zones) and print out the screening and correction factors for the reactions in a zone.

The example code is print_zone_screening.c

To print out the screening and reverse ratio correction factors for the zone with labels 0, 0, 0 at t9 = 1 and mass density = 1.e8 g/cc, type:


./print_zone_screening ../data_pub/example_single_zone.xml 1. 1.e8 0 0 0 > ex57_output.txt

The result is ex57_output.txt

Example 58: Create a full libnucnet structure (network plus zones) and generate the Jacobian matrix.

The example code is print_jacobian.c

To print out the Jacobian matrix for the abundances in the zone with labels 0, 0, 0 at t9 = 1 and mass density = 1000 g/cc, type:


./print_jacobian ../data_pub/example_single_zone.xml 0 0 0 1. 1.e3 ex58_output.txt

The result is ex58_output.txt

Example 59: Create a full libnucnet structure (network plus zones) and run a single-zone network calculation for the input temperature, density, and duration.

The example code is run_single_zone.c

Use a network of nuclei with Z <= 10 to compute the evolution of the abundances of species with initial abundances in the input file at an initial T9 = 10 and density of 1.e8 g/cc expanding with a density e-folding timescale of 0.1 seconds for 10 seconds, printing out the abundances every 20 time steps:


./run_single_zone ../data_pub/example_single_zone.xml 0 0 0 10. 1.e8 0.1 10. 20 "[z <= 10]" > ex59_output.txt

The result is ex59_output.txt

Example 60: Create a full libnucnet structure (network plus zones) and run a single-zone network calculation for the input temperature, density, and duration. Input XML read in without building a tree.

The example code is run_single_zone_with_reader.c

Use a network of nuclei with Z <= 10 to compute the evolution of the abundances of species with initial abundances in the input file at an initial T9 = 10 and density of 1.e8 g/cc expanding with a density e-folding timescale of 0.1 seconds for 10 seconds, printing out the abundances every 20 time steps:


./run_single_zone_with_reader ../data_pub/example_single_zone.xml 0 0 0 10. 1.e8 0.1 10. 20 ".//z[. <= 10]" > ex60_output.txt

The result is ex60_output.txt

Example 61: Run a single-zone network calculation for the input temperature, density, and duration but switch network to use only weak decays and neutron capture below T9 = 0.1.

The example code is run_switch_network.c

Use a network of nuclei with Z <= 10 to compute the evolution of the abundances of species with initial abundances in the input file at an initial T9 = 10 and density of 1.e8 g/cc expanding with a density e-folding timescale of 0.1 seconds for 10 seconds, printing out the abundances every 20 time steps and switching to a network only using weak decays and neutron captures below T9 = 0.1:


./run_switch_network ../data_pub/example_single_zone.xml 0 0 0 10. 1.e8 0.1 10. 20 "[z <= 10]" > ex61_output.txt

The result is ex61_output.txt

Example 62: Create a full libnucnet structure (network plus zones) and run a single-zone network calculation but with the forward and reverse rates for a particular reaction at all temperatures multipled by a constant factor.

The example code is run_mod_rate_single_zone.c

Use a network of nuclei with Z <= 10 to compute the evolution of the abundances of species with initial abundances in the input file at an initial T9 = 10 and density of 1.e8 g/cc expanding with a density e-folding timescale of 0.1 seconds for 10 seconds but with the forward and reverse rates for the reaction he4 + he4 + he4 -> c12 + gamma increased by a factor of 10 at all temperatures, printing out the abundances every 20 time steps:


./run_mod_rate_single_zone ../data_pub/example_single_zone.xml 10. 1.e8 0.1 10. 20 "he4 + he4 + he4 -> c12 + gamma" 10 "[z <= 10]" > ex62_output.txt

The result is ex62_output.txt

Example 63: Create a full libnucnet structure (network plus zones) and run a single-zone network calculation for the input temperature, density, and initial mass fractions from text files.

The example code is run_table_single_zone.c

Use a network of nuclei with Z <= 10 to compute the evolution of the abundances of species with initial abundances in an input file text file using a thermodynamics trajectory from an input text file evolving for 30 seconds and printing out the abundances every 20 time steps:


./run_table_single_zone ../data_pub/example_net.xml ../data_pub/zone_ascii.txt ../data_pub/mass_fractions.txt 30. 20 "[z <= 10]" > ex63_output.txt

The result is ex63_output.txt

Example 64: Create a full libnucnet structure (network plus zones) and run a multi-zone network calculation for the input conditions.

The example code is run_multi_zone.c

For a network of nuclei with Z <= 10, compute the evolution of the abundances of species in the three input zones for a duration of 100 seconds with a mixing time between zones of 0.01 seconds:


./run_multi_zone ../data_pub/example_1d.xml 0.01 100. 1 "[z <= 10]" > ex64_output.txt

The result is ex64_output.txt

To run without mixing, use a mixing timescale of zero:


./run_multi_zone ../data_pub/example_1d.xml 0. 100. 1 "[z <= 10]" > ex64_no_mixing_output.txt

The result is ex64_no_mixing_output.txt

To run with only mixing, use the mix_flag to set all zone temperatures to zero:


./run_multi_zone ../data_pub/example_1d_include.xml 0.1 100. 0 "[z <= 10]" > ex64_mixing_only_output.txt

The result is ex64_mixing_only_output.txt