I need help debugging a simple model that I asked ChatGPT to make. I want a simple photon transport simulation to play with, so first I asked it just for some code that will plot a random geometry in both 2D and 3D side by side so I can start to visualize it. Couldn’t even get past the first step as ChatGPT and I can’t seem to figure out how to get it working. I’m just running this in a Jupyter Notebook on a Macbook Pro in a miniconda env with openmc installed:
import openmc
import matplotlib.pyplot as plt
# Define materials
water = openmc.Material(1, "h2o")
water.add_nuclide("H1", 2)
water.add_nuclide("O16", 1)
water.set_density("g/cm3", 1.0)
# Define geometry
sphere = openmc.Sphere(r=10, boundary_type="vacuum")
cell = openmc.Cell(fill=water, region=-sphere)
geom = openmc.Geometry([cell])
# Define source
point = openmc.stats.Point((0, 0, 0))
src = openmc.Source(space=point)
# Define tally
tally = openmc.Tally()
tally.filters = [openmc.CellFilter([cell])]
tally.scores = ["flux"]
# Create a model and set the geometry, source, and tallies
model = openmc.model.Model()
model.geometry = geom
model.source = src
model.tallies = [tally]
# Set up the simulation
settings = openmc.Settings()
settings.particles = 1000000
settings.run_mode = 'fixed source'
settings.source = src
# Run the simulation
model.run(particles=1000)
# Create a figure with a 3D plot and a 2D plot side by side
fig = plt.figure(figsize=(12, 6))
# Create a 3D plot
ax1 = fig.add_subplot(121, projection='3d')
openmc.plot_inline(model.geometry.plot(width=400), ax=ax1)
# Create a 2D plot
ax2 = fig.add_subplot(122)
openmc.plot_inline(tally.plot(0), ax=ax2)
# Show the plots
plt.show()
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
############### %%%%%%%%%%%%%%%%%%%%%%%%
################## %%%%%%%%%%%%%%%%%%%%%%%
################### %%%%%%%%%%%%%%%%%%%%%%%
#################### %%%%%%%%%%%%%%%%%%%%%%
##################### %%%%%%%%%%%%%%%%%%%%%
###################### %%%%%%%%%%%%%%%%%%%%
####################### %%%%%%%%%%%%%%%%%%
####################### %%%%%%%%%%%%%%%%%
###################### %%%%%%%%%%%%%%%%%
#################### %%%%%%%%%%%%%%%%%
################# %%%%%%%%%%%%%%%%%
############### %%%%%%%%%%%%%%%%
############ %%%%%%%%%%%%%%%
######## %%%%%%%%%%%%%%
%%%%%%%%%%%
| The OpenMC Monte Carlo Code
Copyright | 2011-2022 MIT, UChicago Argonne LLC, and contributors
License | https://docs.openmc.org/en/latest/license.html
Version | 0.13.2
Date/Time | 2023-02-22 17:02:00
MPI Processes | 1
OpenMP Threads | 8
Reading settings XML file...
ERROR: Need to specify number of particles.
application called MPI_Abort(MPI_COMM_WORLD, -1) - process 0
[unset]: write_line error; fd=-1 buf=:cmd=abort exitcode=-1
:
system msg for write_line failure : Bad file descriptor
/Users/sshahbazi/miniconda3/envs/openmc/lib/python3.11/site-packages/openmc/mixin.py:70: IDWarning: Another Material instance already exists with id=1.
warn(msg, IDWarning)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[41], line 37
34 settings.source = src
36 # Run the simulation
---> 37 model.run(particles=1000)
39 # Create a figure with a 3D plot and a 2D plot side by side
40 fig = plt.figure(figsize=(12, 6))
File ~/miniconda3/envs/openmc/lib/python3.11/site-packages/openmc/model/model.py:588, in Model.run(self, particles, threads, geometry_debug, restart_file, tracks, output, cwd, openmc_exec, mpi_args, event_based)
585 else:
586 # Then run via the command line
587 self.export_to_xml()
--> 588 openmc.run(particles, threads, geometry_debug, restart_file,
589 tracks, output, Path('.'), openmc_exec, mpi_args,
590 event_based)
592 # Get output directory and return the last statepoint written
593 if self.settings.output and 'path' in self.settings.output:
File ~/miniconda3/envs/openmc/lib/python3.11/site-packages/openmc/executor.py:280, in run(particles, threads, geometry_debug, restart_file, tracks, output, cwd, openmc_exec, mpi_args, event_based)
234 """Run an OpenMC simulation.
235
236 Parameters
(...)
272
273 """
275 args = _process_CLI_arguments(
276 volume=False, geometry_debug=geometry_debug, particles=particles,
277 restart_file=restart_file, threads=threads, tracks=tracks,
278 event_based=event_based, openmc_exec=openmc_exec, mpi_args=mpi_args)
--> 280 _run(args, output, cwd)
File ~/miniconda3/envs/openmc/lib/python3.11/site-packages/openmc/executor.py:118, in _run(args, output, cwd)
115 error_msg = 'OpenMC aborted unexpectedly.'
116 error_msg = ' '.join(error_msg.split())
--> 118 raise RuntimeError(error_msg)
RuntimeError: Need to specify number of particles. application called MPI_Abort(MPI_COMM_WORLD, -1) - process 0 [unset]: write_line error; fd=-1 buf=:cmd=abort exitcode=-1 : system msg for write_line failure : Bad file descriptor