Loading SubKit/build/Section.py +8 −8 Original line number Diff line number Diff line """ Defines classes for creating axial sections and channels""" # Defines classes for creating axial sections and channels import collections import numpy as np Loading SubKit/utils/UnitConversions.py +42 −13 Original line number Diff line number Diff line Loading @@ -4,18 +4,8 @@ # # 2/3/19 """ A collection of unit conversion constants. Converts between English and metric. Conversion constant names are t_<from>_<to> where "from" is the unit being converted from and "to" is the unit being converted to. For example, multiplying by t_in_cm will convert a number from inches to cm. Multiplying it by t_cm_in will convert it from cm back to inches. Functions are also available for converting temperatures. """ t_in_cm = 2.54 # cm/in # Convert in to cm t_in_cm = 2.54 t_cm_m = 0.01 # cm/m t_in_m = t_in_cm*t_cm_m t_m_in = 1.0/t_in_m Loading Loading @@ -48,26 +38,65 @@ t_K_F = 1.8 t_bar_psi = 14.5038 def C2K(T): """ Converts Celsius to Kelvin Args: T (float) : Temperature """ return T+273.15 def K2R(T): """ Converts Kelvin to Rankine Args: T (float) : Temperature """ return C2R(K2C(T)) def C2R(T): """ Converts Celsius to Rankine Args: T (float) : Temperature """ return C2F(T)+460.0 def K2C(T): """ Converts Kelvin to Celsius Args: T (float) : Temperature """ return T-273.15 def F2C(T): """ Converts Fahrenheit to Celsius Args: T (float) : Temperature """ return (T-32.0)/t_K_F def C2F(T): """ Converts Celsius to Fahrenheit Args: T (float) : Temperature """ return T*1.8+32.0 def K2F(T): """ Converts Kelvin to Fahrenheit Args: T (float) : Temperature """ return K2C(T)*t_K_F+32.0 def F2K(T): return C2K(F2C(T)) """ Converts Fahrenheit to Kelvin Args: T (float) : Temperature """ return C2K(F2C(T)) SubKit/utils/gen_from_template.py 0 → 100644 +97 −0 Original line number Diff line number Diff line #! /usr/bin/env python import argparse import re def main(): parser = argparse.ArgumentParser(description=""" Reads a template file that contains labels and replaces those labels with values specified by the user. Can be used to create a set of input files from a template file, for example. Provide template file and legend file. See documentation for detailed instructions on setting up the template and legend files""", formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('template', type=str, help="The template file") parser.add_argument('legend', type=str, help='The legend file') args = parser.parse_args() # Read in the template file f = open(args.template, 'r') template = f.readlines() f.close() # Read in the legend file f = open(args.legend, 'r') legend = f.readlines() f.close() # Extract the key/values from the legend file keyval = {} firstline = True for line in legend: if line.strip(): if firstline: files = line.split() firstline = False else: splitline = line.split() keyval[splitline[0]] = splitline[1:] # Make sure there is a value for every file for key, value in keyval.iteritems(): if len(files) != len(value): print("Number of files read in: ", args.legend, ":", len(files)) print("Does not match number of values given for ", key, ":", len(value)) raise RuntimeError def getKeys(line): ''' Returns a list of keywords found in the line (can be zero) ''' regex = '<.+?>' return re.findall(regex, line) # Collect the list of keys found in the template file template_keys = [] for line in template: keywords = getKeys(line) for k in keywords: if k not in template_keys: template_keys.append(k) print("Keys found in template file:") print(template_keys) print("Keys defined in legend file:") print(keyval.keys()) # Make sure all the keys in the template file were defined in the legend file for key in template_keys: if key not in keyval: print("A keyword that was defined in the template file:", key) print("was not defined in the legend file:") print(keyval.keys()) raise RuntimeError # Replace all the keywords in the template file in a new list for i, file in enumerate(files): newlines = [] for line in template: keys = getKeys(line) if keys: splitline = line.split() for k in keys: replacement = keyval[k][i] splitline = [s.replace(k, replacement) for s in splitline] # Rejoin the line newlines.append(' '.join(splitline)+'\n') else: newlines.append(line) # Write the new lines to the new input deck f = open(file, 'w') for line in newlines: f.write(line) f.close() if __name__ == "__main__": main() doc/index.rst +3 −1 Original line number Diff line number Diff line Loading @@ -38,7 +38,8 @@ This documentation covers the following: will be necessary whether the user starts from the Python interface or the input interface. 3. Instructions for using the Python interface in scripting modethe classes and procedures the user. 4. Instructions for using input file mode. 5. Instructions for using CTF HDF5 file post processing tools. 5. Various utilities offered by SubKit. 6. Instructions for using CTF HDF5 file post processing tools. ************ Installation Loading Loading @@ -98,6 +99,7 @@ Table of Contents ctf_basics python_interface input_file.rst utils.rst post_process.rst Loading doc/python_interface.rst +0 −27 Original line number Diff line number Diff line Loading @@ -174,30 +174,3 @@ SubKit\.build.SquareLatticeLWR_Nodal module :undoc-members: :show-inheritance: ************************************ SubKit\.build.UnitConversions module ************************************ .. automodule:: SubKit.utils.UnitConversions :members: :undoc-members: :show-inheritance: ********************************* SubKit\.build.utils module ********************************* .. automodule:: SubKit.utils.utils :members: :undoc-members: :show-inheritance: ******************************* SubKit\.build.SaltProps module ******************************* .. automodule:: SubKit.utils.SaltProps :members: :undoc-members: :show-inheritance: Loading
SubKit/build/Section.py +8 −8 Original line number Diff line number Diff line """ Defines classes for creating axial sections and channels""" # Defines classes for creating axial sections and channels import collections import numpy as np Loading
SubKit/utils/UnitConversions.py +42 −13 Original line number Diff line number Diff line Loading @@ -4,18 +4,8 @@ # # 2/3/19 """ A collection of unit conversion constants. Converts between English and metric. Conversion constant names are t_<from>_<to> where "from" is the unit being converted from and "to" is the unit being converted to. For example, multiplying by t_in_cm will convert a number from inches to cm. Multiplying it by t_cm_in will convert it from cm back to inches. Functions are also available for converting temperatures. """ t_in_cm = 2.54 # cm/in # Convert in to cm t_in_cm = 2.54 t_cm_m = 0.01 # cm/m t_in_m = t_in_cm*t_cm_m t_m_in = 1.0/t_in_m Loading Loading @@ -48,26 +38,65 @@ t_K_F = 1.8 t_bar_psi = 14.5038 def C2K(T): """ Converts Celsius to Kelvin Args: T (float) : Temperature """ return T+273.15 def K2R(T): """ Converts Kelvin to Rankine Args: T (float) : Temperature """ return C2R(K2C(T)) def C2R(T): """ Converts Celsius to Rankine Args: T (float) : Temperature """ return C2F(T)+460.0 def K2C(T): """ Converts Kelvin to Celsius Args: T (float) : Temperature """ return T-273.15 def F2C(T): """ Converts Fahrenheit to Celsius Args: T (float) : Temperature """ return (T-32.0)/t_K_F def C2F(T): """ Converts Celsius to Fahrenheit Args: T (float) : Temperature """ return T*1.8+32.0 def K2F(T): """ Converts Kelvin to Fahrenheit Args: T (float) : Temperature """ return K2C(T)*t_K_F+32.0 def F2K(T): return C2K(F2C(T)) """ Converts Fahrenheit to Kelvin Args: T (float) : Temperature """ return C2K(F2C(T))
SubKit/utils/gen_from_template.py 0 → 100644 +97 −0 Original line number Diff line number Diff line #! /usr/bin/env python import argparse import re def main(): parser = argparse.ArgumentParser(description=""" Reads a template file that contains labels and replaces those labels with values specified by the user. Can be used to create a set of input files from a template file, for example. Provide template file and legend file. See documentation for detailed instructions on setting up the template and legend files""", formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('template', type=str, help="The template file") parser.add_argument('legend', type=str, help='The legend file') args = parser.parse_args() # Read in the template file f = open(args.template, 'r') template = f.readlines() f.close() # Read in the legend file f = open(args.legend, 'r') legend = f.readlines() f.close() # Extract the key/values from the legend file keyval = {} firstline = True for line in legend: if line.strip(): if firstline: files = line.split() firstline = False else: splitline = line.split() keyval[splitline[0]] = splitline[1:] # Make sure there is a value for every file for key, value in keyval.iteritems(): if len(files) != len(value): print("Number of files read in: ", args.legend, ":", len(files)) print("Does not match number of values given for ", key, ":", len(value)) raise RuntimeError def getKeys(line): ''' Returns a list of keywords found in the line (can be zero) ''' regex = '<.+?>' return re.findall(regex, line) # Collect the list of keys found in the template file template_keys = [] for line in template: keywords = getKeys(line) for k in keywords: if k not in template_keys: template_keys.append(k) print("Keys found in template file:") print(template_keys) print("Keys defined in legend file:") print(keyval.keys()) # Make sure all the keys in the template file were defined in the legend file for key in template_keys: if key not in keyval: print("A keyword that was defined in the template file:", key) print("was not defined in the legend file:") print(keyval.keys()) raise RuntimeError # Replace all the keywords in the template file in a new list for i, file in enumerate(files): newlines = [] for line in template: keys = getKeys(line) if keys: splitline = line.split() for k in keys: replacement = keyval[k][i] splitline = [s.replace(k, replacement) for s in splitline] # Rejoin the line newlines.append(' '.join(splitline)+'\n') else: newlines.append(line) # Write the new lines to the new input deck f = open(file, 'w') for line in newlines: f.write(line) f.close() if __name__ == "__main__": main()
doc/index.rst +3 −1 Original line number Diff line number Diff line Loading @@ -38,7 +38,8 @@ This documentation covers the following: will be necessary whether the user starts from the Python interface or the input interface. 3. Instructions for using the Python interface in scripting modethe classes and procedures the user. 4. Instructions for using input file mode. 5. Instructions for using CTF HDF5 file post processing tools. 5. Various utilities offered by SubKit. 6. Instructions for using CTF HDF5 file post processing tools. ************ Installation Loading Loading @@ -98,6 +99,7 @@ Table of Contents ctf_basics python_interface input_file.rst utils.rst post_process.rst Loading
doc/python_interface.rst +0 −27 Original line number Diff line number Diff line Loading @@ -174,30 +174,3 @@ SubKit\.build.SquareLatticeLWR_Nodal module :undoc-members: :show-inheritance: ************************************ SubKit\.build.UnitConversions module ************************************ .. automodule:: SubKit.utils.UnitConversions :members: :undoc-members: :show-inheritance: ********************************* SubKit\.build.utils module ********************************* .. automodule:: SubKit.utils.utils :members: :undoc-members: :show-inheritance: ******************************* SubKit\.build.SaltProps module ******************************* .. automodule:: SubKit.utils.SaltProps :members: :undoc-members: :show-inheritance: