2.2. Built-in method for 1-group cross sections
Here, we use a built-in method to generate isotropic one-group cross sections.
To run the code, simply type: jupyter nbconvert --to python --execute <basename>.ipynb
.
To convert it to a python file (named <basename>.py
), simply type: jupyter nbconvert --to python <basename>.ipynb
[ ]:
import os
import sys
import numpy as np
sys.path.append("../../..")
from pyopensn.xs import MultiGroupXS
from pyopensn.context import UseColor, Finalize
UseColor(False)
2.2.1. Call built-in method
We use \(\Sigma_t=1.\) and
\[c=\frac{\Sigma_{S,0}}{\Sigma_t}=0.5\]
[ ]:
# load cross sections
xs_mat = MultiGroupXS()
xs_mat.CreateSimpleOneGroup(sigma_t=2.2, c=0.5)
2.2.2. Some cross-section data can be retrieved in Python
[ ]:
# Retrieve properties
ng = xs_mat.num_groups
sca_order = xs_mat.scattering_order
print("num_groups = ", ng)
print("scattering_order = ", sca_order)
# note cross sections are read-only objects of type <memoryview>
siga = xs_mat.sigma_a
print("type = ", type(siga))
# retrieve a numpy array
siga = np.array(xs_mat.sigma_a)
print("siga = ", siga)
# retrieve as list
sigt = list(xs_mat.sigma_t)
print("sigt = ", sigt)
2.2.3. Finalize (for Jupyter Notebook only)
In Python script mode, PyOpenSn automatically handles environment termination. However, this automatic finalization does not occur when running in a Jupyter notebook, so explicit finalization of the environment at the end of the notebook is required. Do not call the finalization in Python script mode, or in console mode.
Note that PyOpenSn’s finalization must be called before MPI’s finalization.
[ ]:
from IPython import get_ipython
def finalize_env():
Finalize()
MPI.Finalize()
ipython_instance = get_ipython()
if ipython_instance is not None:
ipython_instance.events.register("post_execute", finalize_env)