Difference between revisions of "KrakenTools examples"

From Kraken Wiki
Jump to: navigation, search
(Created page with "== Creating Serpent water compositions == Water composition material cards for Serpent can be generated using the krakentools.writeWaterComposition() method: >>> help(krake...")
 
 
(3 intermediate revisions 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:70em;">
 +
'''docstring for the krakentools.writeWaterComposition method'''
 +
<div class="mw-collapsible-content">
 +
>>> import krakentools
 
  >>> help(krakentools.writeWaterComposition)
 
  >>> help(krakentools.writeWaterComposition)
 +
  Help on function writeWaterComposition in module krakentools.utils:
 
   
 
   
  writeWaterComposition(fresh_water_mass_density, boron_in_ppm_weight, temperature, fout=None, fname='./watercomp.txt', thermlibs=None)
+
  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
 
     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)
 
      
 
      
 
     Arguments:
 
     Arguments:
         fresh_water_mass_density {float} -- target mass density of non-borated water (positive number, g/cm3)
+
         fresh_water_mass_density {float} --
         boron_in_ppm_weight {float} -- boron concentration in ppm weight
+
            target mass density of non-borated water (positive number, g/cm3)
         temperature {float} -- water temperature in Kelvin
+
         boron_in_ppm_weight {float} --
 +
            boron concentration in ppm weight
 +
         temperature {float} --
 +
            water temperature in Kelvin
 
      
 
      
 
     Keyword Arguments:
 
     Keyword Arguments:
         fout {file handle} -- Handle to a pre-opened file into which the water
+
         fout {file handle} --
                              composition will be written (default: {None})
+
            Handle to a pre-opened file into which the water composition will be
         fname {str} -- Optional name of file into which the water composition
+
            written (default: {None})
                      will be written (default: {"./watercomp.txt"})
+
         fname {str} --
         thermlibs {[N*[str, float]]} -- A list of (thermal scattering library
+
            Optional name of file into which the water composition will be
                                        identifier)-(temperature) pairs
+
            written (default: {"./watercomp.txt"})
                                        (default: {None})
+
         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:
 
     Raises:
 
         RuntimeError: If the target temperature is not bracketed by the thermal scattering libraries.
 
         RuntimeError: If the target temperature is not bracketed by the thermal scattering libraries.
 +
</div>
 +
</div>
  
 
By default, the function writes the material card to a file <tt>./watercomp.txt</tt> but a pre-opened file handle can be passed as <tt>fout</tt> keyword argument also. For example:
 
By default, the function writes the material card to a file <tt>./watercomp.txt</tt> but a pre-opened file handle can be passed as <tt>fout</tt> keyword argument also. For example:
  
 +
<div class="toccolours mw-collapsible mw-expanded" style="width:60em;">
 +
'''test1.py'''
 +
<div class="mw-collapsible-content">
 
  #!/usr/bin/env python3
 
  #!/usr/bin/env python3
 
  # -*- coding: utf-8 -*-
 
  # -*- coding: utf-8 -*-
Line 35: Line 53:
 
  # --- Open a file into which the composition will be written
 
  # --- Open a file into which the composition will be written
 
   
 
   
  fout = open("./watercomp.txt","w")
+
  fout = open("./some_name.txt","w")
 
   
 
   
 
  # --- Water density in g/cm3 (does not include boron)
 
  # --- Water density in g/cm3 (does not include boron)
Line 56: Line 74:
 
   
 
   
 
  fout.close()
 
  fout.close()
 +
</div></div>
  
 
will produce the following file:
 
will produce the following file:
  
 +
<div class="toccolours mw-collapsible mw-expanded" style="width:60em;">
 +
'''some_name.txt'''
 +
<div class="mw-collapsible-content">
 
  mat cool_1000B_100D -1.00100 tmp 550
 
  mat cool_1000B_100D -1.00100 tmp 550
 
                             moder lw550K 1001
 
                             moder lw550K 1001
Line 69: Line 91:
 
  B-10.03c  1.105860e-04
 
  B-10.03c  1.105860e-04
 
  B-11.03c  4.451225e-04
 
  B-11.03c  4.451225e-04
 
+
</div></div>
 
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:
 
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:
  
 
+
<div class="toccolours mw-collapsible mw-expanded" style="width:60em;">
 +
'''test2.py'''
 +
<div class="mw-collapsible-content">
 
  #!/usr/bin/env python3
 
  #!/usr/bin/env python3
 
  # -*- coding: utf-8 -*-
 
  # -*- coding: utf-8 -*-
Line 93: Line 117:
 
  # --- Open a file into which the composition will be written
 
  # --- Open a file into which the composition will be written
 
   
 
   
  fout = open("./watercomp.txt","w")
+
  fout = open("./some_other_name.txt","w")
 
   
 
   
 
  # --- Water density in g/cm3 (does not include boron)
 
  # --- Water density in g/cm3 (does not include boron)
Line 114: Line 138:
 
   
 
   
 
  fout.close()
 
  fout.close()
 +
</div></div>
  
 
would produce the file
 
would produce the file
  
 +
<div class="toccolours mw-collapsible mw-expanded" style="width:60em;">
 +
'''some_other_name.txt'''
 +
<div class="mw-collapsible-content">
 
  mat cool_1000B_100D -1.00100 tmp 550
 
  mat cool_1000B_100D -1.00100 tmp 550
 
                             moder lw550K 1001
 
                             moder lw550K 1001
Line 129: Line 157:
 
   
 
   
 
  therm lw550K lwe7.10t
 
  therm lw550K lwe7.10t
 +
</div></div>
  
 
This works even if the material temperature is between two library temperatures, in which case the therm card will use interpolation.
 
This works even if the material temperature is between two library temperatures, in which case the therm card will use interpolation.

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.