KrakenTools examples
Creating Serpent water compositions
Water composition material cards for Serpent can be generated using the krakentools.writeWaterComposition() method:
>>> help(krakentools.writeWaterComposition) writeWaterComposition(fresh_water_mass_density, boron_in_ppm_weight, temperature, fout=None, fname='./watercomp.txt', thermlibs=None) Writes water material card and optionally the therm-card for Serpent into a file for a specific state point (fresh water density + boron ppm) Arguments: fresh_water_mass_density {float} -- target mass density of non-borated water (positive number, g/cm3) boron_in_ppm_weight {float} -- boron concentration in ppm weight temperature {float} -- water temperature in Kelvin Keyword Arguments: fout {file handle} -- Handle to a pre-opened file into which the water composition will be written (default: {None}) fname {str} -- Optional name of file into which the water composition will be written (default: {"./watercomp.txt"}) thermlibs {[N*[str, float]]} -- A list of (thermal scattering library identifier)-(temperature) pairs (default: {None}) Raises: RuntimeError: If the target temperature is not bracketed by the thermal scattering libraries.
By default, the function writes the material card to a file ./watercomp.txt but a pre-opened file handle can be passed as fout keyword argument also. For example:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import krakentools # --- Open a file into which the composition will be written fout = open("./watercomp.txt","w") # --- Water density in g/cm3 (does not include boron) density = 1.0 # --- Boron content in ppm (weight) boron = 1000 # --- Water temperature in Kelvin (used for tmp card and naming of therm-card) temperature = 550 # --- Call the method to write the corresponding composition to the file krakentools.writeWaterComposition(density, boron, temperature, fout=fout) # --- Close the file fout.close()
will produce the following file:
mat cool_1000B_100D -1.00100 tmp 550 moder lw550K 1001 rgb 200 200 255 O-16.03c 3.323385e-01 O-17.03c 1.265963e-04 80170 6.829536e-04 H-1.03c 6.662196e-01 H-2.03c 7.662406e-05 B-10.03c 1.105860e-04 B-11.03c 4.451225e-04
The tmp and moder cards are automatically written based on the requested temperature, but as we provided no thermal scattering libraries, the therm card is not written. We could add a list of thermal scattering library identifiers and their corresponding temperatures, which would also append the correct therm card for the identifier specified in the moder card:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import krakentools # --- Set of thermal scattering libraries to use # [identifier, temperature (K)] myThermlibs = [["lwe7.00t", 294], ["lwe7.02t", 350], ["lwe7.04t", 400], ["lwe7.06t", 450], ["lwe7.08t", 500], ["lwe7.10t", 550], ["lwe7.12t", 600], ["lwe7.14t", 650], ["lwe7.18t", 800]] # --- Open a file into which the composition will be written fout = open("./watercomp.txt","w") # --- Water density in g/cm3 (does not include boron) density = 1.0 # --- Boron content in ppm (weight) boron = 1000 # --- Water temperature in Kelvin (used for tmp card and naming of therm-card) temperature = 550 # --- Call the method to write the corresponding composition to the file krakentools.writeWaterComposition(density, boron, temperature, fout=fout, thermlibs=myThermLibs) # --- Close the file fout.close()
would produce the file
mat cool_1000B_100D -1.00100 tmp 550 moder lw550K 1001 rgb 200 200 255 O-16.03c 3.323385e-01 O-17.03c 1.265963e-04 80180 6.829536e-04 H-1.03c 6.662196e-01 H-2.03c 7.662406e-05 B-10.03c 1.105860e-04 B-11.03c 4.451225e-04 therm lw550K lwe7.10t
This works even if the material temperature is between two library temperatures, in which case the therm card will use interpolation.