Difference between revisions of "KrakenTools examples"

From Kraken Wiki
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
 
Water composition material cards for Serpent can be generated using the krakentools.writeWaterComposition() method:
 
Water composition material cards for Serpent can be generated using the krakentools.writeWaterComposition() method:
  
<div class="toccolours mw-collapsible mw-expanded" style="width:60em;">
+
<div class="toccolours mw-collapsible mw-expanded" style="width:70em;">
 
'''docstring for the krakentools.writeWaterComposition method'''
 
'''docstring for the krakentools.writeWaterComposition method'''
 
<div class="mw-collapsible-content">
 
<div class="mw-collapsible-content">
 
  >>> import krakentools
 
  >>> import krakentools
 
  >>> help(krakentools.writeWaterComposition)
 
  >>> help(krakentools.writeWaterComposition)
Help on function writeWaterComposition in module krakentools.utils:
+
  Help on function writeWaterComposition in module krakentools.utils:
 
+
writeWaterComposition(fresh_water_mass_density:float, boron_in_ppm_weight:float,
+
writeWaterComposition(fresh_water_mass_density:float, boron_in_ppm_weight:float,
temperature:float, fout:TextIO=None, fname:str='./watercomp.txt', thermlibs:Sequence[Tuple[str, float]]=[], mat_name:str='') -> None
+
  temperature:float, fout:TextIO=None, fname:str='./watercomp.txt', thermlibs:Sequence[Tuple[str, float]]=[], mat_name:str='') -> None
 
     Writes water material card and optionally the therm-card for Serpent into a file
 
     Writes water material card and optionally the therm-card for Serpent into a file
 
     for a specific state point (fresh water density + boron ppm)
 
     for a specific state point (fresh water density + boron ppm)

Latest revision as of 14:06, 30 July 2019

Creating Serpent water compositions

Water composition material cards for Serpent can be generated using the krakentools.writeWaterComposition() method:

docstring for the krakentools.writeWaterComposition method

>>> import krakentools
>>> help(krakentools.writeWaterComposition)
 Help on function writeWaterComposition in module krakentools.utils:

writeWaterComposition(fresh_water_mass_density:float, boron_in_ppm_weight:float,
 temperature:float, fout:TextIO=None, fname:str='./watercomp.txt', thermlibs:Sequence[Tuple[str, float]]=[], mat_name:str=) -> 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})
       mat_name {str} --
           Name for the created material (default: {""}, will be created based on state point)
   
   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:

test1.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import krakentools

# --- Open a file into which the composition will be written

fout = open("./some_name.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:

some_name.txt

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:

test2.py

#!/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("./some_other_name.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

some_other_name.txt

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.