<jupyter_start><jupyter_text>Classes There are two material classes to use `mat_lib` and `mat_map`, they are both contained in `material.py`.<jupyter_code>from material import mat_lib, mat_map
from mesh import Cell, Mesh
import numpy as np<jupyter_output><empty_output><jupyter_text>1. [Cell Readme](Cell-Readme)1. [Cell API](Cell-API)1. [Material Readme](Material-Readme)1. [Material API Summary](Material-API)1. [Mesh Readme](Mesh-Readme)1. [Mesh API Summary](Mesh-API)  Cell Readme Initialize a cell using a tuple index, and a dictionary that contains mesh parameters required to create the cell.<jupyter_code>index = (1,1)
mesh_params = {'x_cell': 4,  #REQ: number of cells along the x-axis
               'y_cell': 4,  #OP: cells on y-axis (def to x_cell)
               'cell_length': 2.5 #REQ: cell length
              }
cell = Cell(index, mesh_params)<jupyter_output><empty_output><jupyter_text>Once initialized there are automatically calculated quantities accessed using function calls:<jupyter_code>cell.index() # Cell index
cell.global_idx() # Nodes
cell.length()
cell.area()<jupyter_output><empty_output><jupyter_text>If the cell is on a boundary, it will have a dictionary with the appropriate boundaries:<jupyter_code>index2 = (4,4)
cell2 = Cell(index2, mesh_params)
cell2.bounds()<jupyter_output><empty_output><jupyter_text>If it is _not_ on a boundary, the dictionary will be empty, allowing you to use this to determine if it is a boundary cell:<jupyter_code>for c in [cell, cell2]:     # cell is NOT a boundary, cell2 IS
    if c.bounds():
        print('cell at ' + str(c.index()) + ' is a boundary cell')
    if not c.bounds():
        print('cell at ' + str(c.index()) + ' is NOT a boundary cell')<jupyter_output>cell at (1, 1) is NOT a boundary cell
cell at (4, 4) is a boundary cell<jupyter_text>The bounds are `x_min`, `x_max`, `y_min`, and `y_max`. They are also set using the same `cell.bounds()` method:<jupyter_code>cell2.bounds('x_max', 'refl')
print cell2.bounds()<jupyter_output>{'y_max': None, 'x_max': 'refl'}<jupyter_text>Trying to set a bound that it doesn't have will result in a key error:<jupyter_code>cell2.bounds('x_min', 'refl')<jupyter_output><empty_output><jupyter_text>If a cell is defined by passing a material map `mat_map`, you can access the material properties using the same syntax as the `mat_map.get` function:<jupyter_code>file_loc = './tests/testData/materials/'
files = [file_loc + m for m in ['test_mat.xml', 'test_mat2.xml']]
lib = mat_lib(n_grps = 2, files = files)
layout = """1 1 1 1
            1 2 2 1
            1 2 2 1
            1 1 1 1"""
layout_dict = {'1':'test_mat2', '2': 'test_mat'}
mmap = mat_map(lib = lib, layout = layout, layout_dict = layout_dict, 
               x_max = 10, n=20)
index = (1,1)
mesh_params = {'x_cell': 4,  #REQ: number of cells along the x-axis
               'y_cell': 4,  #OP: cells on y-axis (def to x_cell)
               'cell_length': 2.5 #REQ: cell length
              }
cell = Cell(index, mesh_params, mat_map = mmap)<jupyter_output><empty_output><jupyter_text>**MAKE SURE THE DIMENSIONS OF THE MATERIAL MAP MATCH THE MESH PARAMETERS OR THEY WON'T LINE UP**<jupyter_code>print cell.get('sig_t')
print cell.get('id')<jupyter_output>[ 20.  30.]
test_mat<jupyter_text>Cell API Initialization:<jupyter_code>index = (1,1)
mesh_params = {'x_cell': 4,  #REQ: number of cells along the x-axis
               'y_cell': 4,  #OP: cells on y-axis (def to x_cell)
               'cell_length': 2.5 #REQ: cell length
              }
cell = Cell(index, mesh_params)<jupyter_output><empty_output><jupyter_text>Calculated Properties:<jupyter_code>print cell.global_idx()
print cell.length()
print cell.area()<jupyter_output>[6, 7, 11, 12]
2.5
6.25<jupyter_text>If on a boundary, `cell.bounds()` will return a dictionary with the boundaries or an empty dictionary.<jupyter_code>print cell.bounds()
index2 = (4,4)
boundary_cell = Cell(index2, mesh_params)
boundary_cell.bounds()<jupyter_output><empty_output><jupyter_text>Cell bounds are also set or called using the bounds function:<jupyter_code>boundary_cell.bounds('y_max', 'refl')
boundary_cell.bounds('x_max', 'vac')
print boundary_cell.bounds()
print boundary_cell.bounds('x_max')<jupyter_output>{'y_max': 'refl', 'x_max': 'vac'}
vac<jupyter_text>If you define a material map, material properties can be retrieved using `get`<jupyter_code>file_loc = './tests/testData/materials/'
files = [file_loc + m for m in ['test_mat.xml', 'test_mat2.xml']]
lib = mat_lib(n_grps = 2, files = files)
layout = """1 1 1 1
            1 2 2 1
            1 2 2 1
            1 1 1 1"""
layout_dict = {'1':'test_mat2', '2': 'test_mat'}
mmap = mat_map(lib = lib, layout = layout, layout_dict = layout_dict, 
               x_max = 10, n=20)
index = (1,1)
mesh_params = {'x_cell': 4,  #REQ: number of cells along the x-axis
               'y_cell': 4,  #OP: cells on y-axis (def to x_cell)
               'cell_length': 2.5 #REQ: cell length
              }
cell = Cell(index, mesh_params, mat_map = mmap)
cell.get('sig_t')<jupyter_output><empty_output><jupyter_text>Material Readme  Mat_lib `mat_lib` is the **Material Library**, and holds all the problem materials. This class should be used when info about a specific material, or all the materials is required. To initialize, it requires a list of all the desired material `xml` files, and the number of energy groups in the desired group structure, `n_grps`:<jupyter_code>file_loc = './tests/testData/materials/'
files = [file_loc + m for m in ['test_mat.xml', 'test_mat2.xml']]
lib = mat_lib(n_grps = 2, files = files)<jupyter_output><empty_output><jupyter_text>The library can also be intialized with only the number of groups, and then materials added using `mat_lib.add`, this is probably more useful if iterating through all the files in a directory. `n_grps` is always required at initialization.<jupyter_code>lib2 = mat_lib(n_grps = 2)
for f in files:
    lib2.add(f)<jupyter_output><empty_output><jupyter_text>Two utility functions return info about the materials, `ids` returns the material IDs and `props` shows all the properties that each material has, or the properties of a specific material id.<jupyter_code>lib.ids()
lib.props()
lib.props('test_mat')<jupyter_output><empty_output><jupyter_text>Number of groups can be accessed using two methods:<jupyter_code>lib.n_grps()
lib.get('n_grps')<jupyter_output><empty_output><jupyter_text>Accessing Data The main method to access data is `get`. This will either return:- A dictionary containing all the materials as keys, and the desired property as values **or**- The value of the property for a particular material.<jupyter_code># Get dictionary of all sig_t values:
lib.get('sig_t')
# Get values for a specific material:
lib.get('sig_t', mat_id = 'test_mat')<jupyter_output><empty_output><jupyter_text>Note this is identical to using:<jupyter_code>lib.get('sig_t')['test_mat']<jupyter_output><empty_output><jupyter_text>To get a property per steradian, use `get_per_str`:<jupyter_code>lib.get_per_str('sig_t', mat_id='test_mat')<jupyter_output><empty_output><jupyter_text>Other functions will return cell corrections and bd corrections using the same syntax:<jupyter_code>print lib.cell_correction_ua(np.array([[1.0, 1.0],[1.0,1.0]]))
print lib.bd_correction_ua(np.array([1.0, 1.0]))<jupyter_output>{'test_mat2': array([ 120.,  120.]), 'test_mat': array([ 70.,  70.])}
{'test_mat2': 120.0, 'test_mat': 70.0}<jupyter_text>MAT_MAP `mat_map` is a **material mapping** that takes the problem material layout and connects it to the materials contained in the material library. To make a mapping, it requires- `lib` A material library that contains all problem materials- `layout` A string showing the material layout of the problem, with different values meaning different materials. This must have a square number of values to map to the square problem.- `layout_dict` a dictionary connecting the strings used in the layout to the material ids in the library.- `x_max` maximum x-value of the problem.- `n` number of cells along each side of the problemOPTIONAL- `x_min`, `y_min` otherwise defaults to 0- `y_max` otherwise defaults to `x_max` The layout string uses any characters to represent different materials, you can use any characters or strings that you want. For example, to have one material surrounded by another. **Note:** The lower left of this array is the problem origin (0,0)<jupyter_code># Both of these are identical, 
# as any line breaks and extra spaces are removed. 
layout = """1 1 1 1
            1 2 2 1
            1 2 2 1
            1 1 1 1"""
layout2 = " 1 1 1 1 1 2 2 1 1 2 2 1 1 1 1 1"<jupyter_output><empty_output><jupyter_text>Next, the arbirary characters used (1 and 2 here) need to be linked back to materials in your material library. For example, we have two materials in ours:<jupyter_code>lib.ids()<jupyter_output><empty_output><jupyter_text>We link them using a dictionary, pairing the layout character with the material id:<jupyter_code>layout_dict = {'1':'test_mat2', '2': 'test_mat'}<jupyter_output><empty_output><jupyter_text>We can then make our mapping:<jupyter_code>mmap = mat_map(lib = lib, layout = layout, layout_dict = layout_dict, 
               x_max = 4, n=4)<jupyter_output><empty_output><jupyter_text>Now we can get material properties at any (x,y) value, or any cell index. Here, we get the name of the material, and the $\Sigma_t$ using x and y coordinates in a tuple:<jupyter_code>print mmap.get('id', (0.5, 0.5))
print mmap.get('sig_t', (0.5, 0.5))<jupyter_output>test_mat2
[ 10.  20.]<jupyter_text>As expected, that location returns the correct material and properties. Cell index can also be used:<jupyter_code>print mmap.get('id', 1)
print mmap.get('sig_t', 1)<jupyter_output>test_mat2
[ 10.  20.]<jupyter_text>Use the same names to get cell corrections:<jupyter_code>mmap.cell_correction_ua(np.array([[1.0, 1.0],[1.0,1.0]]), (0.5, 0.5))<jupyter_output><empty_output><jupyter_text>Material API This is a summary of all functions.  mat_lib<jupyter_code>file_loc = './tests/testData/materials/'
files = [file_loc + m for m in ['test_mat.xml', 'test_mat2.xml']]
# Initialize using list of files, set tr_scatt = True to transpose the
# scattering matrix.
lib = mat_lib(n_grps = 2, files = files) 

# Add new ones using add
lib2 = mat_lib(n_grps = 2)
for f in files:
    lib2.add(f)
# Get IDs of materials
lib.ids()
# Get Properties of materials
lib.props()
# Get number of groups
lib.n_grps()
lib.get('n_grps')
# Get properties of a specific material
lib.props('test_mat')
#Get properties of all materials
lib.get('sig_t')
#Get property of a specific material
lib.get('sig_t', mat_id = 'test_mat')
# Calculate corrections:
print lib.cell_correction_ua(np.array([[1.0, 1.0],[1.0,1.0]]))
print lib.bd_correction_ua(np.array([1.0, 1.0]))
# can also get for a specific material
lib.cell_correction_ua(np.array([[1.0, 1.0],[1.0,1.0]]), 
                             mat_id='test_mat')<jupyter_output><empty_output><jupyter_text>mat_map<jupyter_code># Create layout and layout dictionary
layout = """1 1 1 1
            1 2 2 1
            1 2 2 1
            1 1 1 1"""
layout_dict = {'1':'test_mat2', '2': 'test_mat'}

# Initialize
mmap = mat_map(lib = lib, layout = layout, layout_dict = layout_dict, 
               x_max = 4, n=4)
# Get values at locations, (x,y) or cell index k
print mmap.get('id', (0.5, 0.5))
print mmap.get('sig_t', (0.5, 0.5))
print mmap.get('id', 1)
print mmap.get('sig_t', 1)
# Get corrections at locations using the same syntax
mmap.cell_correction_ua(np.array([[1.0, 1.0],[1.0,1.0]]), (0.5, 0.5))
mmap.cell_correction_ua(np.array([[1.0, 1.0],[1.0,1.0]]), 1)<jupyter_output><empty_output><jupyter_text>Mesh Readme The `Mesh` class creates cells for a problem with a given number of cells per side and a total dimension. A mesh requires:- `mesh_cells` how many mesh cells per side of the domain- `domain_upper` the upper bound of the domain (lower assumed to be 0)- `mat_map` material mappingMake sure your `mat_map` dimensions match the `domain_upper`. Here we use 10 for both `x_max` and `domain upper`<jupyter_code>mmap = mat_map(lib = lib, layout = layout, layout_dict = layout_dict, 
               x_max = 10, n=4)
mesh_cells = 4
domain_upper = 10
mesh = Mesh(mesh_cells, domain_upper, mmap)<jupyter_output><empty_output><jupyter_text>Now we can access many properties of the mesh:<jupyter_code>print mesh.n_cell()
print mesh.n_node()
print mesh.x_cell()
print mesh.x_node()
print mesh.y_cell()
print mesh.y_node()
mesh.cell_length()<jupyter_output><empty_output><jupyter_text>and can get all the cells:<jupyter_code>mesh.cells()
for cell in mesh.cells():
    if cell.bounds():
        print 'Boundary cell ', cell.index(), cell.get('id'), cell.bounds()
    else:
        print 'Interior cell ', cell.index(), cell.get('id')<jupyter_output>Boundary cell  (0, 0) test_mat2 {'x_min': None, 'y_min': None}
Boundary cell  (0, 1) test_mat2 {'x_min': None}
Boundary cell  (0, 2) test_mat2 {'x_min': None}
Boundary cell  (0, 3) test_mat2 {'x_min': None, 'y_max': None}
Boundary cell  (1, 0) test_mat2 {'y_min': None}
Interior cell  (1, 1) test_mat
Interior cell  (1, 2) test_mat
Boundary cell  (1, 3) test_mat2 {'y_max': None}
Boundary cell  (2, 0) test_mat2 {'y_min': None}
Interior cell  (2, 1) test_mat
Interior cell  (2, 2) test_mat
Boundary cell  (2, 3) test_mat2 {'y_max': None}
Boundary cell  (3, 0) test_mat2 {'y_min': None, 'x_max': None}
Boundary cell  (3, 1) test_mat2 {'x_max': None}
Boundary cell  (3, 2) test_mat2 {'x_max': None}
Boundary cell  (3, 3) test_mat2 {'y_max': None, 'x_max': None}
{'fraction_non_alphanumeric': 0.12320223070149691, 'fraction_numerical': 0.026049310243616085, 'mean_word_length': 4.662235147486498, 'pattern_counts': {'":': 0, '<': 128, '<?xml version=': 0, '>': 128, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 9}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '34', 'dir': 'jupyter-structured-clean-dedup', 'id': '382397', 'license': 'MIT', 'n_tokens_mistral': 4936, 'n_tokens_neox': 4704, 'n_words': 1527, 'path': 'Class Readme.ipynb', 'repo_name': 'weixiong-zheng-berkeley/BART-lite', 'size': '13628'}