Hi , I am trying to use the openmc.VolumeCalculation module on a simple test pin-cell geometry.
I get the following messages when I do compile the code :
Starting Monte Carlo volume calculation…
Traceback (most recent call last):
File “/home/gousset/OpenMC/vol/vol.py”, line 137, in
openmc.VolumeCalculation.export_to_xml([vol_calc])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object ‘VolumeCalculation’ has no attribute ‘export_to_xml’
I have been reading the documentation to fix the problem but I have a hard time finding it.
Here is my code:
import openmc
import random
from PIL import Image
import glob
import os
from datetime import datetime
Define materials
air = openmc.Material(name=“Air”)
air.add_nuclide(‘N14’, 0.79)
air.add_nuclide(‘O16’, 0.21)
air.set_density(‘g/cm3’, 0.0012)
uranium = openmc.Material(name=‘Enriched Uranium’)
uranium.add_nuclide(‘U235’, 0.05)
uranium.add_nuclide(‘U238’, 0.95)
uranium.set_density(‘g/cm3’, 18.95)
Cladding (e.g., Zircaloy)
cladding = openmc.Material(name=‘Zircaloy’)
cladding.add_element(‘Zr’, 1.0)
cladding.set_density(‘g/cm3’, 6.55)
Moderator (light water, H2O)
water = openmc.Material(name=‘Light Water’)
water.add_nuclide(‘H1’, 2.0)
water.add_nuclide(‘O16’, 1.0)
water.set_density(‘g/cm3’, 0.997) # at ~25°C
water.add_s_alpha_beta(‘c_H_in_H2O’) # thermal scattering treatment
Register all materials
materials = openmc.Materials([uranium, air, cladding, water])
materials.cross_sections = #TO ADD
materials.export_to_xml()
Define cylindrical surfaces (in cm)
fuel_radius = openmc.ZCylinder(r=2)
gap_radius = openmc.ZCylinder(r=4)
clad_radius = openmc.ZCylinder(r=6)
Half-length of the square
a = 10 # cm
Define a cubic region centered at (0, 0, 0)
square_region = +openmc.XPlane(x0=-a, boundary_type=‘vacuum’) & -openmc.XPlane(x0=a, boundary_type=‘vacuum’) &
+openmc.YPlane(y0=-a, boundary_type=‘vacuum’) & -openmc.YPlane(y0=a, boundary_type=‘vacuum’) &
+openmc.ZPlane(z0=-a, boundary_type=‘vacuum’) & -openmc.ZPlane(z0=a, boundary_type=‘vacuum’)
Define fuel pin geometry
fuel_region = -fuel_radius
gap_region = +fuel_radius & -gap_radius
clad_region = +gap_radius & -clad_radius
cylinder_region = +clad_radius
water_region = square_region | ~cylinder_region
Define cells
fuel_cell = openmc.Cell(region=fuel_region, fill=uranium)
gap_cell = openmc.Cell(region=gap_region, fill=air)
clad_cell = openmc.Cell(region=clad_region, fill=cladding)
water_cell = openmc.Cell(region=water_region, fill=water)
Define universes
root_universe = openmc.Universe(universe_id=0, name=‘root universe’)
pin_universe = openmc.Universe(universe_id=1, name=‘fuel pin’)
pin_universe.add_cells([fuel_cell, gap_cell, clad_cell, water_cell])
Define root cell containing the pin
root_cell = openmc.Cell(cell_id=0, name=‘root cell’, fill=pin_universe, region=square_region)
root_universe.add_cell(root_cell)
Build geometry
geometry = openmc.Geometry(root_universe)
geometry.export_to_xml()
Define material colors for plotting
material_colors = {
air: ‘white’,
uranium: ‘green’,
water: ‘blue’,
cladding: ‘gray’
}
Plot geometry (XY plane)
plot = openmc.Plot()
plot.basis = ‘xy’
plot.origin = [0, 0, 5]
plot.width = [40, 40]
plot.pixels = [4096, 4096]
plot.color_by = ‘material’
plot.colors = material_colors
plots = openmc.Plots([plot])
plots.export_to_xml()
Generate geometry image
openmc.plot_geometry()
Convert .ppm plots to .png without overwriting previous files
ppm_files = sorted(glob.glob(“.ppm"))
existing_pngs = glob.glob("plot_.png”)
existing_indices =
for filename in existing_pngs:
try:
index = int(os.path.splitext(filename)[0].split(‘_’)[1])
existing_indices.append(index)
except (IndexError, ValueError):
continue
next_index = max(existing_indices, default=0) + 1
for ppm_file in ppm_files:
img = Image.open(ppm_file)
png_file = f"plot_{next_index}.png"
img.save(png_file, “PNG”)
os.remove(ppm_file)
next_index += 1
print(“Geometry image conversion complete!”)
---------------------------------------------------
Monte Carlo Volume Calculation
---------------------------------------------------
print(“Starting Monte Carlo volume calculation…”)
Create VolumeCalculation object
vol_calc = openmc.VolumeCalculation(
domains=[fuel_cell, gap_cell, clad_cell, water_cell],
samples=1_000_000,
lower_left=(-a, -a, -a),
upper_right=(a, a, a)
)
Export volume calculation settings
openmc.VolumeCalculation.export_to_xml([vol_calc])
Minimal settings for OpenMC to run
settings = openmc.Settings()
settings.run_mode = ‘fixed source’
settings.batches = 1
settings.particles = 1
settings.export_to_xml()
Run volume calculation
openmc.calculate_volumes()
Load results
vol_calc.load_results()
Print estimated volumes
for domain, volume in zip(vol_calc.domains, vol_calc.volumes):
print(f"Estimated volume of cell ‘{domain.name}’: {volume:.4f} cm³")
Could you help me please?