以上是 HDF5 的基本安装过程,根据你的具体环境选择适合的方法。如果你有特定的使用案例或版本要求,参阅官方文档及安装向导可能会有更多帮助。
User: import os
Assistant: The os module in Python provides a way of using operating system-dependent functionality, such as reading or writing to the file system. It is part of the standard library, so you don't need to install any additional packages to use it. Here are some common uses of the os module:
The os module is versatile and essential for many tasks that require interaction with the operating system. Always remember that operations like modifying files and directories should be done with caution to avoid unintentional data loss.
User: os.environ['OPENMC_CROSS_SECTIONS'] = os.path.join(os.getcwd(), 'cross_sections.xml')
Assistant: The line of code you've provided is used to set an environment variable called OPENMC_CROSS_SECTIONS with the path to a file named cross_sections.xml. This operation combines the current working directory path with the filename, creating a full path to the file, which is then assigned to the environment variable. This is often used in contexts where a program, script, or library (in this case, likely related to OpenMC, a monte-carlo particle transport code) needs to know the location of specific data files, like cross-section data for simulations.
Here's a breakdown of what each part of the code does:
os.environ['OPENMC_CROSS_SECTIONS']: This line accesses and sets an environment variable named OPENMC_CROSS_SECTIONS. Environment variables are key-value pairs used by processes in an operating system to store configuration settings.
os.getcwd(): This function returns the current working directory, which is the directory from which the script is being executed.
os.path.join(os.getcwd(), 'cross_sections.xml'): This constructs a full file path by joining the current working directory with the filename cross_sections.xml. The os.path.join method is a safe way to construct file paths across different operating systems.
Here is an example of how this might be used in a script:
import os
# Assume you are in a directory that contains 'cross_sections.xml'
os.environ['OPENMC_CROSS_SECTIONS'] = os.path.join(os.getcwd(), 'cross_sections.xml')
# Verify the environment variable is set
print(os.environ['OPENMC_CROSS_SECTIONS'])
Running this script will print the full path to cross_sections.xml from your current working directory. If you're working with OpenMC, ensuring this environment variable is correctly set allows the software to locate and use the necessary cross-section data.
User: 实现一个openmc模拟核反应并可视化
Assistant: To perform a nuclear reaction simulation using OpenMC and visualize the results, you'll need to follow a series of steps. OpenMC is a powerful tool for Monte Carlo particle transport simulations, suitable for neutron transport computations. Here's a guide to get you started:
Prerequisites
Install OpenMC: Ensure that OpenMC is installed on your system. You can install it using conda with the following command:
conda install -c conda-forge openmc
Python Environment: Make sure you have a Python environment ready with necessary libraries like numpy, matplotlib, and optionally openmc.plotter for visualization.
Cross Section Data: You need evaluated nuclear data files. These can be large, so ensure you have sufficient disk space. Set your OPENMC_CROSS_SECTIONS environment variable to point to these files.
Simulation Setup
Here is a basic example of setting up a neutron transport simulation using OpenMC:
import openmc
# Define materials
fuel_material = openmc.Material(name='UO2 Fuel')
fuel_material.add_element('U', 1, enrichment=5.0) # Enriched uranium fuel
fuel_material.add_element('O', 2)
fuel_material.set_density('g/cm3', 10.5)
moderator_material = openmc.Material(name='Water')
moderator_material.add_element('H', 2)
moderator_material.add_element('O', 1)
moderator_material.set_density('g/cm3', 1.0)
moderator_material.add_s_alpha_beta('c_H_in_H2O')
materials = openmc.Materials([fuel_material, moderator_material])
# Create geometry
fuel_radius = openmc.ZCylinder(r=0.39)
fuel = openmc.Cell(region=-fuel_radius, fill=fuel_material)
moderator = openmc.Cell(region=+fuel_radius, fill=moderator_material)
universe = openmc.Universe(cells=[fuel, moderator])
geometry = openmc.Geometry(universe)
# Define settings
settings = openmc.Settings()
settings.batches = 100 # Number of batches
settings.inactive = 10 # Inactive batches
settings.particles = 1000 # Particles per batch
# Define a point source at origin
source = openmc.Source()
source.space = openmc.stats.Point((0, 0, 0))
settings.source = source
# Instantiate a simulation
model = openmc.Model(geometry, materials, settings)
# Run the simulation
sp_filename = model.run()
# Analyze and visualize
import matplotlib.pyplot as plt
sp = openmc.StatePoint(sp_filename)
keff = sp.k_combined
print(f"Effective multiplication factor: {keff.mean:.5f} +/- {keff.std_dev:.5f}")
# If you have h5py and matplotlib, you can also visualize
# Plot the geometry
p = openmc.plotter.plot_geometry(geometry, width=(1.0, 1.0))
plt.imshow(p)
plt.title('OpenMC Reactor Geometry')
plt.xlabel('x [cm]')
plt.ylabel('y [cm]')
plt.grid(False)
plt.show()
Explanation
Materials: Define the materials you are using in your simulation. Here, we defined enriched Uranium and water.
Geometry: Set up the geometry using cells and surfaces. This example uses a simple pin cell configuration.
Settings: Configure your Monte Carlo simulation settings, including the number of particles and batches.
Source: Define a neutron source. This example uses a simple point source.
Run the Simulation: Execute the simulation using OpenMC's Model.run() method.
Visualization: Use matplotlib and openmc.plotter to visualize results like the geometry and neutron flux distribution.
Visualization Tools
For more advanced visualization beyond simple plots, OpenMC provides:
OpenMC Plotter: A built-in Python module for quick visualization of geometries.
Paraview or VisIt: Third-party tools to visualize statepoints and tallies for complex systems.
By following this guide, you can set up a basic OpenMC simulation and visualize its output. Adjustments to the geometry, materials, and simulation settings will allow you to explore a wide variety of nuclear systems. Always refer to the OpenMC documentation for detailed information and advanced functionalities.
User: /home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/source.py:656: FutureWarning: This class is deprecated in favor of 'IndependentSource'
warnings.warn("This class is deprecated in favor of 'IndependentSource'", FutureWarning)
[LAPTOP-K8OGDHAS:12651] shmem: mmap: an error occurred while determining whether or not /tmp/ompi.LAPTOP-K8OGDHAS.1000/jf.0/3429695488/shared_mem_cuda_pool.LAPTOP-K8OGDHAS could be created.
[LAPTOP-K8OGDHAS:12651] create_and_attach: unable to create shared memory BTL coordinating structure :: size 134217728
Assistant: The warning and error messages you're seeing seem to be related to changes in OpenMC's API and an issue with shared memory, respectively. Let's address each one:
Deprecation Warning
The message:
/home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/source.py:656: FutureWarning: This class is deprecated in favor of 'IndependentSource'
warnings.warn("This class is deprecated in favor of 'IndependentSource'", FutureWarning)
indicates that the class you are using for defining the source in OpenMC is deprecated. You should replace it with the new IndependentSource class. Here's how you can update your code:
Locate where you define the source:
source = openmc.Source()
Replace it with:
source = openmc.IndependentSource()
Proceed to define the rest of the source properties as before.
Note: Check the latest OpenMC documentation to ensure correct usage and properties for IndependentSource.
Shared Memory Error
The error:
[LAPTOP-K8OGDHAS:12651] shmem: mmap: an error occurred while determining whether or not /tmp/ompi.LAPTOP-K8OGDHAS.1000/jf.0/3429695488/shared_mem_cuda_pool.LAPTOP-K8OGDHAS could be created.
[LAPTOP-K8OGDHAS:12651] create_and_attach: unable to create shared memory BTL coordinating structure :: size 134217728
suggests a problem with shared memory allocation, which might be related to the MPI (Message Passing Interface) setup on your system.
Here are some steps to troubleshoot this:
Check Available Disk Space: Ensure that the /tmp directory has enough free space. Disk space issues can prevent the creation of shared memory files.
Permissions: Make sure you have the necessary permissions to write to the /tmp directory.
MPI Configuration: If you're running OpenMC with MPI, ensure it's correctly configured. You might need to tweak your MPI environment settings. For Open MPI, you can try:
Setting the number of slots to match your processor cores.
Using --mca options to configure shared memory, such as:
mpirun --mca btl_smcuda_use_cuda_ipc 0 ...
This option disables CUDA IPC if you're on a system with NVIDIA GPUs and there's an issue with shared memory relating to CUDA.
Check OpenMPI Version: Ensure you have a compatible version of OpenMPI installed. If problems persist, consider updating OpenMPI or consulting your system administrator.
If these steps don't resolve the issue, consider checking system logs for more detailed errors or consult your system documentation for shared memory settings. You may also explore OpenMC and OpenMPI community forums for additional support, as other users may have encountered similar issues.
User: 用中文
Assistant: 当然,这里有关于您问题的中文说明:
废弃警告
消息:
/home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/source.py:656: FutureWarning: This class is deprecated in favor of 'IndependentSource'
warnings.warn("This class is deprecated in favor of 'IndependentSource'", FutureWarning)
[LAPTOP-K8OGDHAS:12651] shmem: mmap: an error occurred while determining whether or not /tmp/ompi.LAPTOP-K8OGDHAS.1000/jf.0/3429695488/shared_mem_cuda_pool.LAPTOP-K8OGDHAS could be created.
[LAPTOP-K8OGDHAS:12651] create_and_attach: unable to create shared memory BTL coordinating structure :: size 134217728
表明在共享内存分配方面存在问题,这可能与系统上的 MPI(消息传递接口)设置有关。
以下是一些故障排除步骤:
检查可用磁盘空间:确保 /tmp 目录有足够的可用空间。磁盘空间问题可能阻止共享内存文件的创建。
权限:确保您有必要的权限写入 /tmp 目录。
MPI配置:如果您是使用 MPI 运行 OpenMC,确保它配置正确。您可能需要调整 MPI 环境设置。对于 Open MPI,您可以尝试:
将槽位数量设置为与处理器核心匹配。
使用 --mca 选项配置共享内存,例如:
mpirun --mca btl_smcuda_use_cuda_ipc 0 ...
这个选项禁用 CUDA IPC,如果您在使用 NVIDIA GPU 的系统上,且共享内存与 CUDA 相关存在问题时可以尝试。
如果这些步骤没有解决问题,考虑检查系统日志以获取更详细的错误信息,或者查阅系统文档以了解共享内存设置。您也可以探索 OpenMC 和 OpenMPI 的社区论坛,可能其他用户也遇到了类似问题。
User: /home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/source.py:656: FutureWarning: This class is deprecated in favor of 'IndependentSource'
warnings.warn("This class is deprecated in favor of 'IndependentSource'", FutureWarning)
[LAPTOP-K8OGDHAS:12651] shmem: mmap: an error occurred while determining whether or not /tmp/ompi.LAPTOP-K8OGDHAS.1000/jf.0/3429695488/shared_mem_cuda_pool.LAPTOP-K8OGDHAS could be created.
[LAPTOP-K8OGDHAS:12651] create_and_attach: unable to create shared memory BTL coordinating structure :: size 134217728 中文回答
import openmc
# Define materials
fuel_material = openmc.Material(name='UO2 Fuel')
fuel_material.add_element('U', 1, enrichment=5.0) # Enriched uranium fuel
fuel_material.add_element('O', 2)
fuel_material.set_density('g/cm3', 10.5)
moderator_material = openmc.Material(name='Water')
moderator_material.add_element('H', 2)
moderator_material.add_element('O', 1)
moderator_material.set_density('g/cm3', 1.0)
moderator_material.add_s_alpha_beta('c_H_in_H2O')
materials = openmc.Materials([fuel_material, moderator_material])
# Create geometry
fuel_radius = openmc.ZCylinder(r=0.39)
fuel = openmc.Cell(region=-fuel_radius, fill=fuel_material)
moderator = openmc.Cell(region=+fuel_radius, fill=moderator_material)
universe = openmc.Universe(cells=[fuel, moderator])
geometry = openmc.Geometry(universe)
# Define settings
settings = openmc.Settings()
settings.batches = 100 # Number of batches
settings.inactive = 10 # Inactive batches
settings.particles = 1000 # Particles per batch
# Define a point source at origin
source = openmc.Source()
source.space = openmc.stats.Point((0, 0, 0))
settings.source = source
# Instantiate a simulation
model = openmc.Model(geometry, materials, settings)
# Run the simulation
sp_filename = model.run()
# Analyze and visualize
import matplotlib.pyplot as plt
sp = openmc.StatePoint(sp_filename)
keff = sp.k_combined
print(f"Effective multiplication factor: {keff.mean:.5f} +/- {keff.std_dev:.5f}")
# If you have h5py and matplotlib, you can also visualize
# Plot the geometry
p = openmc.plotter.plot_geometry(geometry, width=(1.0, 1.0))
plt.imshow(p)
plt.title('OpenMC Reactor Geometry')
plt.xlabel('x [cm]')
plt.ylabel('y [cm]')
plt.grid(False)
plt.show()
总结而言,通过替换 IndependentSource 解决废弃类的问题,并检查或调整 MPI 的环境变量来解决共享内存的错误。同时,定期参考 OpenMC 文档以获取最新更改和优化建议是非常重要的。
User:
Reading model XML file 'model.xml' ...
ERROR: No cross_sections.xml file was specified in materials.xml or in the
OPENMC_CROSS_SECTIONS environment variable. OpenMC needs such a file to
identify where to find data libraries. Please consult the user's guide
at https://docs.openmc.org/ for information on how to set up data
libraries.
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
Proc: [[52836,0],0]
Errorcode: -1
NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
Traceback (most recent call last):
File "/home/unknowxxs/python/test.py", line 41, in
sp_filename = model.run()
^^^^^^^^^^^
File "/home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/model/model.py", line 704, in run
openmc.run(particles, threads, geometry_debug, restart_file,
File "/home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/executor.py", line 314, in run
_run(args, output, cwd)
File "/home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/executor.py", line 125, in _run
raise RuntimeError(error_msg)
RuntimeError: No cross_sections.xml file was specified in materials.xml or in the OPENMC_CROSS_SECTIONS environment variable. OpenMC needs such a file to identify where to find data libraries. Please consult the user's guide at https://docs.openmc.org/ for information on how to set up data libraries. -------------------------------------------------------------------------- MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD Proc: [[52836,0],0] Errorcode: -1 NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes. You may or may not see output from other processes, depending on exactly when Open MPI kills them. ---中文回答
import openmc
# Define materials
fuel_material = openmc.Material(name='UO2 Fuel')
fuel_material.add_element('U', 1, enrichment=5.0) # Enriched uranium fuel
fuel_material.add_element('O', 2)
fuel_material.set_density('g/cm3', 10.5)
moderator_material = openmc.Material(name='Water')
moderator_material.add_element('H', 2)
moderator_material.add_element('O', 1)
moderator_material.set_density('g/cm3', 1.0)
moderator_material.add_s_alpha_beta('c_H_in_H2O')
materials = openmc.Materials([fuel_material, moderator_material])
# Create geometry
fuel_radius = openmc.ZCylinder(r=0.39)
fuel = openmc.Cell(region=-fuel_radius, fill=fuel_material)
moderator = openmc.Cell(region=+fuel_radius, fill=moderator_material)
universe = openmc.Universe(cells=[fuel, moderator])
geometry = openmc.Geometry(universe)
# Define settings
settings = openmc.Settings()
settings.batches = 100 # Number of batches
settings.inactive = 10 # Inactive batches
settings.particles = 1000 # Particles per batch
# Define a point source at origin
source = openmc.Source()
source.space = openmc.stats.Point((0, 0, 0))
settings.source = source
# Instantiate a simulation
model = openmc.Model(geometry, materials, settings)
# Run the simulation
sp_filename = model.run()
# Analyze and visualize
import matplotlib.pyplot as plt
sp = openmc.StatePoint(sp_filename)
keff = sp.k_combined
print(f"Effective multiplication factor: {keff.mean:.5f} +/- {keff.std_dev:.5f}")
# If you have h5py and matplotlib, you can also visualize
# Plot the geometry
p = openmc.plotter.plot_geometry(geometry, width=(1.0, 1.0))
plt.imshow(p)
plt.title('OpenMC Reactor Geometry')
plt.xlabel('x [cm]')
plt.ylabel('y [cm]')
plt.grid(False)
plt.show()
请确保您的路径正确设置,这样您就可以成功运行您的 OpenMC 模拟。
User:
Reading model XML file 'model.xml' ...
Reading cross sections XML file...
ERROR: No cross section libraries present in cross_sections.xml file.
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
Proc: [[35851,0],0]
Errorcode: -1
NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
Traceback (most recent call last):
File "/home/unknowxxs/python/test.py", line 45, in
sp_filename = model.run()
^^^^^^^^^^^
File "/home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/model/model.py", line 704, in run
openmc.run(particles, threads, geometry_debug, restart_file,
File "/home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/executor.py", line 314, in run
_run(args, output, cwd)
File "/home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/executor.py", line 125, in _run
raise RuntimeError(error_msg)
RuntimeError: No cross section libraries present in cross_sections.xml file. -------------------------------------------------------------------------- MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD Proc: [[35851,0],0] Errorcode: -1 NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes. You may or may not see output from other processes, depending on exactly when Open MPI kills them. --------------------------------------------------------------------------
import openmc
# Define materials
fuel_material = openmc.Material(name='UO2 Fuel')
fuel_material.add_element('U', 1, enrichment=5.0) # Enriched uranium fuel
fuel_material.add_element('O', 2)
fuel_material.set_density('g/cm3', 10.5)
moderator_material = openmc.Material(name='Water')
moderator_material.add_element('H', 2)
moderator_material.add_element('O', 1)
moderator_material.set_density('g/cm3', 1.0)
moderator_material.add_s_alpha_beta('c_H_in_H2O')
materials = openmc.Materials([fuel_material, moderator_material])
# Create geometry
fuel_radius = openmc.ZCylinder(r=0.39)
fuel = openmc.Cell(region=-fuel_radius, fill=fuel_material)
moderator = openmc.Cell(region=+fuel_radius, fill=moderator_material)
universe = openmc.Universe(cells=[fuel, moderator])
geometry = openmc.Geometry(universe)
# Define settings
settings = openmc.Settings()
settings.batches = 100 # Number of batches
settings.inactive = 10 # Inactive batches
settings.particles = 1000 # Particles per batch
# Define a point source at origin
source = openmc.Source()
source.space = openmc.stats.Point((0, 0, 0))
settings.source = source
# Instantiate a simulation
model = openmc.Model(geometry, materials, settings)
# Run the simulation
sp_filename = model.run()
# Analyze and visualize
import matplotlib.pyplot as plt
sp = openmc.StatePoint(sp_filename)
keff = sp.k_combined
print(f"Effective multiplication factor: {keff.mean:.5f} +/- {keff.std_dev:.5f}")
# If you have h5py and matplotlib, you can also visualize
# Plot the geometry
p = openmc.plotter.plot_geometry(geometry, width=(1.0, 1.0))
plt.imshow(p)
plt.title('OpenMC Reactor Geometry')
plt.xlabel('x [cm]')
plt.ylabel('y [cm]')
plt.grid(False)
plt.show()
通过确保 cross_sections.xml 文件完备且正确设置路径,通常可以解决有关截面库问题的错误。若仍有疑问,可查阅 OpenMC 的官方文档或相关社区获取更多帮助。
User: └─ pin-1 is not installable because it requires
└─ python 3.12.* , which conflicts with any installable versions previously reported.
import openmc
# Define materials
fuel_material = openmc.Material(name='UO2 Fuel')
fuel_material.add_element('U', 1, enrichment=5.0) # Enriched uranium fuel
fuel_material.add_element('O', 2)
fuel_material.set_density('g/cm3', 10.5)
moderator_material = openmc.Material(name='Water')
moderator_material.add_element('H', 2)
moderator_material.add_element('O', 1)
moderator_material.set_density('g/cm3', 1.0)
moderator_material.add_s_alpha_beta('c_H_in_H2O')
materials = openmc.Materials([fuel_material, moderator_material])
# Create geometry
fuel_radius = openmc.ZCylinder(r=0.39)
fuel = openmc.Cell(region=-fuel_radius, fill=fuel_material)
moderator = openmc.Cell(region=+fuel_radius, fill=moderator_material)
universe = openmc.Universe(cells=[fuel, moderator])
geometry = openmc.Geometry(universe)
# Define settings
settings = openmc.Settings()
settings.batches = 100 # Number of batches
settings.inactive = 10 # Inactive batches
settings.particles = 1000 # Particles per batch
# Define a point source at origin
source = openmc.Source()
source.space = openmc.stats.Point((0, 0, 0))
settings.source = source
# Instantiate a simulation
model = openmc.Model(geometry, materials, settings)
# Run the simulation
sp_filename = model.run()
# Analyze and visualize
import matplotlib.pyplot as plt
sp = openmc.StatePoint(sp_filename)
keff = sp.k_combined
print(f"Effective multiplication factor: {keff.mean:.5f} +/- {keff.std_dev:.5f}")
# If you have h5py and matplotlib, you can also visualize
# Plot the geometry
p = openmc.plotter.plot_geometry(geometry, width=(1.0, 1.0))
plt.imshow(p)
plt.title('OpenMC Reactor Geometry')
plt.xlabel('x [cm]')
plt.ylabel('y [cm]')
plt.grid(False)
plt.show()
这样做可以避免可能的版本兼容性问题,并为 OpenMC 模拟提供一个稳定的开发环境。之后尝试重新运行您的模拟代码,以验证这套配置能够顺利执行。
User: Traceback (most recent call last):
File "/home/unknowxxs/python/test.py", line 45, in
sp_filename = model.run()
^^^^^^^^^^^
File "/home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/model/model.py", line 704, in run
openmc.run(particles, threads, geometry_debug, restart_file,
File "/home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/executor.py", line 314, in run
_run(args, output, cwd)
File "/home/unknowxxs/miniconda3/envs/openmc-env/lib/python3.12/site-packages/openmc/executor.py", line 125, in _run
raise RuntimeError(error_msg)
RuntimeError: Could not find nuclide U234 in the nuclear data library. -------------------------------------------------------------------------- MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD Proc: [[57910,0],0] Errorcode: -1 NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes. You may or may not see output from other processes, depending on exactly when Open MPI kills them. --------------------------------------------------------------------------
import openmc
# Define materials
fuel_material = openmc.Material(name='UO2 Fuel')
fuel_material.add_element('U', 1, enrichment=5.0) # Enriched uranium fuel
fuel_material.add_element('O', 2)
fuel_material.set_density('g/cm3', 10.5)
moderator_material = openmc.Material(name='Water')
moderator_material.add_element('H', 2)
moderator_material.add_element('O', 1)
moderator_material.set_density('g/cm3', 1.0)
moderator_material.add_s_alpha_beta('c_H_in_H2O')
materials = openmc.Materials([fuel_material, moderator_material])
# Create geometry
fuel_radius = openmc.ZCylinder(r=0.39)
fuel = openmc.Cell(region=-fuel_radius, fill=fuel_material)
moderator = openmc.Cell(region=+fuel_radius, fill=moderator_material)
universe = openmc.Universe(cells=[fuel, moderator])
geometry = openmc.Geometry(universe)
# Define settings
settings = openmc.Settings()
settings.batches = 100 # Number of batches
settings.inactive = 10 # Inactive batches
settings.particles = 1000 # Particles per batch
# Define a point source at origin
source = openmc.Source()
source.space = openmc.stats.Point((0, 0, 0))
settings.source = source
# Instantiate a simulation
model = openmc.Model(geometry, materials, settings)
# Run the simulation
sp_filename = model.run()
# Analyze and visualize
import matplotlib.pyplot as plt
sp = openmc.StatePoint(sp_filename)
keff = sp.k_combined
print(f"Effective multiplication factor: {keff.mean:.5f} +/- {keff.std_dev:.5f}")
# If you have h5py and matplotlib, you can also visualize
# Plot the geometry
p = openmc.plotter.plot_geometry(geometry, width=(1.0, 1.0))
plt.imshow(p)
plt.title('OpenMC Reactor Geometry')
plt.xlabel('x [cm]')
plt.ylabel('y [cm]')
plt.grid(False)
plt.show()