mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
Fixed up CAPI notebook and added the link in documentation
This commit is contained in:
parent
0228ddba1d
commit
c8e1f6ee92
2 changed files with 90 additions and 127 deletions
|
|
@ -4,7 +4,9 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"This notebook shows how to use the OpenMC C/C++ API through the openmc.lib module. This module is particularly useful for multiphysics coupling because it allows you to update the density of materials and the temperatures of cells in memory, without stopping the simulation."
|
||||
"This notebook shows how to use the OpenMC C/C++ API through the openmc.lib module. This module is particularly useful for multiphysics coupling because it allows you to update the density of materials and the temperatures of cells in memory, without stopping the simulation.\n",
|
||||
"\n",
|
||||
"Warning: these bindings are still somewhat experimental and may be subject to change in future versions of OpenMC."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -55,26 +57,26 @@
|
|||
"uo2.add_element('O', 2.)\n",
|
||||
"material_list.append(uo2)\n",
|
||||
"\n",
|
||||
"helium = openmc.Material(material_id=2, name='Helium for gap') #gap\n",
|
||||
"helium = openmc.Material(material_id=2, name='Helium for gap')\n",
|
||||
"helium.set_density('g/cm3', 0.001598)\n",
|
||||
"helium.add_element('He', 2.4044e-4)\n",
|
||||
"material_list.append(helium)\n",
|
||||
"\n",
|
||||
"zircaloy = openmc.Material(material_id=3, name='Zircaloy 4')\n",
|
||||
"zircaloy.set_density('g/cm3', 6.55)\n",
|
||||
"zircaloy.add_element('Sn', 0.014 , 'wo')\n",
|
||||
"zircaloy.add_element('Sn', 0.014, 'wo')\n",
|
||||
"zircaloy.add_element('Fe', 0.00165, 'wo')\n",
|
||||
"zircaloy.add_element('Cr', 0.001 , 'wo')\n",
|
||||
"zircaloy.add_element('Cr', 0.001, 'wo')\n",
|
||||
"zircaloy.add_element('Zr', 0.98335, 'wo')\n",
|
||||
"material_list.append(zircaloy)\n",
|
||||
"\n",
|
||||
"for i in range(10):\n",
|
||||
"\twater = openmc.Material(material_id=4+i)\n",
|
||||
"\twater.set_density('g/cm3', 0.7)\n",
|
||||
"\twater.add_element('H', 2.0)\n",
|
||||
"\twater.add_element('O', 1.0)\n",
|
||||
"\twater.add_s_alpha_beta('c_H_in_H2O')\n",
|
||||
"\tmaterial_list.append(water)\n",
|
||||
"for i in range(4, 14):\n",
|
||||
" water = openmc.Material(material_id=i)\n",
|
||||
" water.set_density('g/cm3', 0.7)\n",
|
||||
" water.add_element('H', 2.0)\n",
|
||||
" water.add_element('O', 1.0)\n",
|
||||
" water.add_s_alpha_beta('c_H_in_H2O')\n",
|
||||
" material_list.append(water)\n",
|
||||
" \n",
|
||||
"materials_file = openmc.Materials(material_list)\n",
|
||||
"materials_file.export_to_xml()"
|
||||
|
|
@ -93,17 +95,16 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fuel_or = openmc.ZCylinder(x0=0, y0=0, r=0.39218)\n",
|
||||
"clad_ir = openmc.ZCylinder(x0=0, y0=0, r=0.40005)\n",
|
||||
"clad_or = openmc.ZCylinder(x0=0, y0=0, r=0.4572)\n",
|
||||
"left = openmc.XPlane(x0=-1.25984/2)\n",
|
||||
"right = openmc.XPlane(x0=1.25984/2)\n",
|
||||
"back = openmc.YPlane(y0=-1.25984/2)\n",
|
||||
"front = openmc.YPlane(y0=1.25984/2)\n",
|
||||
"pitch = 1.25984\n",
|
||||
"fuel_or = openmc.ZCylinder(r=0.39218)\n",
|
||||
"clad_ir = openmc.ZCylinder(r=0.40005)\n",
|
||||
"clad_or = openmc.ZCylinder(r=0.4572)\n",
|
||||
"left = openmc.XPlane(x0=-pitch/2)\n",
|
||||
"right = openmc.XPlane(x0=pitch/2)\n",
|
||||
"back = openmc.YPlane(y0=-pitch/2)\n",
|
||||
"front = openmc.YPlane(y0=pitch/2)\n",
|
||||
"z = [0., 30., 60., 90., 120., 150., 180., 210., 240., 270., 300.]\n",
|
||||
"z_list = []\n",
|
||||
"for i in range(len(z)):\n",
|
||||
"\tz_list.append(openmc.ZPlane(z0=z[i]))"
|
||||
"z_list = [openmc.ZPlane(z0=z_i) for z_i in z]"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -130,36 +131,31 @@
|
|||
"gap_list = []\n",
|
||||
"clad_list = []\n",
|
||||
"water_list = []\n",
|
||||
"for i in range(10):\n",
|
||||
"\tfuel_list.append(openmc.Cell())\n",
|
||||
"\tgap_list.append(openmc.Cell())\n",
|
||||
"\tclad_list.append(openmc.Cell())\n",
|
||||
"\twater_list.append(openmc.Cell())\n",
|
||||
"for i in range(1,11):\n",
|
||||
" fuel_list.append(openmc.Cell(cell_id=i))\n",
|
||||
" gap_list.append(openmc.Cell(cell_id=i+10))\n",
|
||||
" clad_list.append(openmc.Cell(cell_id=i+20))\n",
|
||||
" water_list.append(openmc.Cell(cell_id=i+30))\n",
|
||||
" \n",
|
||||
"j = 0\n",
|
||||
"for fuels in fuel_list:\n",
|
||||
"\tfuels.region = -fuel_or & +z_list[j] & -z_list[j+1]\n",
|
||||
"\tfuels.fill = uo2\n",
|
||||
"\tfuels.temperature = 900.\n",
|
||||
"\tj += 1\n",
|
||||
"j = 0\n",
|
||||
"for gaps in gap_list:\n",
|
||||
"\tgaps.region = +fuel_or & -clad_ir & +z_list[j] & -z_list[j+1]\n",
|
||||
"\tgaps.fill = helium\n",
|
||||
"\tgaps.temperature = 566.\n",
|
||||
"\tj += 1\n",
|
||||
"j = 0\n",
|
||||
"for clads in clad_list:\n",
|
||||
"\tclads.region = +clad_ir & -clad_or & +z_list[j] & -z_list[j+1]\n",
|
||||
"\tclads.fill = zircaloy\n",
|
||||
"\tclads.temperature = 566.\n",
|
||||
"\tj += 1\n",
|
||||
"j = 0\n",
|
||||
"for waters in water_list:\n",
|
||||
"\twaters.region = +clad_or & +left & -right & +back & -front & +z_list[j] & -z_list[j+1]\n",
|
||||
"\twaters.fill = material_list[j+3]\n",
|
||||
"\twater.temperature = 566.\n",
|
||||
"\tj += 1"
|
||||
"for j, fuels in enumerate(fuel_list):\n",
|
||||
" fuels.region = -fuel_or & +z_list[j] & -z_list[j+1]\n",
|
||||
" fuels.fill = uo2\n",
|
||||
" fuels.temperature = 800.\n",
|
||||
"\n",
|
||||
"for j, gaps in enumerate(gap_list):\n",
|
||||
" gaps.region = +fuel_or & -clad_ir & +z_list[j] & -z_list[j+1]\n",
|
||||
" gaps.fill = helium\n",
|
||||
" gaps.temperature = 700.\n",
|
||||
"\n",
|
||||
"for j, clads in enumerate(clad_list):\n",
|
||||
" clads.region = +clad_ir & -clad_or & +z_list[j] & -z_list[j+1]\n",
|
||||
" clads.fill = zircaloy\n",
|
||||
" clads.temperature = 600.\n",
|
||||
"\n",
|
||||
"for j, waters in enumerate(water_list):\n",
|
||||
" waters.region = +clad_or & +left & -right & +back & -front & +z_list[j] & -z_list[j+1]\n",
|
||||
" waters.fill = material_list[j+3]\n",
|
||||
" waters.temperature = 500."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -168,7 +164,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"root = openmc.Universe(universe_id=0, name='root universe')\n",
|
||||
"root = openmc.Universe(name='root universe')\n",
|
||||
"root.add_cells(fuel_list)\n",
|
||||
"root.add_cells(gap_list)\n",
|
||||
"root.add_cells(clad_list)\n",
|
||||
|
|
@ -234,14 +230,14 @@
|
|||
}
|
||||
],
|
||||
"source": [
|
||||
"root.plot(basis = 'yz', width = [2, 10], color_by = 'material', origin = [0., 0., 150.], pixels = [400, 400])"
|
||||
"root.plot(basis='yz', width=[2, 10], color_by='material', origin=[0., 0., 150.], pixels=[400, 400])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Settings: everything will be standard excpet for the temperature settings. Since we will be working with specified temperatures, you will need temperature dependent data. I typically use the endf data found here: https://openmc.org/official-data-libraries/\n",
|
||||
"Settings: everything will be standard except for the temperature settings. Since we will be working with specified temperatures, you will need temperature dependent data. I typically use the endf data found here: https://openmc.org/official-data-libraries/\n",
|
||||
"Make sure your cross sections environment variable is pointing to temperature-dependent data before using the following settings."
|
||||
]
|
||||
},
|
||||
|
|
@ -251,15 +247,15 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"lower_left = [-0.62992, -1.25984/2, 0]\n",
|
||||
"upper_right = [+0.62992, +1.25984/2, +365.76]\n",
|
||||
"lower_left = [-0.62992, -pitch/2, 0]\n",
|
||||
"upper_right = [+0.62992, +pitch/2, +300]\n",
|
||||
"uniform_dist = openmc.stats.Box(lower_left, upper_right, only_fissionable=True)\n",
|
||||
"\n",
|
||||
"settings_file = openmc.Settings()\n",
|
||||
"settings_file.batches = 100\n",
|
||||
"settings_file.inactive = 10\n",
|
||||
"settings_file.particles = 200\n",
|
||||
"settings_file.temperature = {'multipole': True, 'method': 'interpolation', 'range': [290,2500]}\n",
|
||||
"settings_file.temperature = {'multipole': True, 'method': 'interpolation', 'range': [290, 2500]}\n",
|
||||
"settings_file.source = openmc.source.Source(space=uniform_dist)\n",
|
||||
"settings_file.export_to_xml()"
|
||||
]
|
||||
|
|
@ -293,33 +289,10 @@
|
|||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0"
|
||||
]
|
||||
},
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()"
|
||||
"for _ in range(14):\n",
|
||||
" openmc.lib.next_batch()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -338,16 +311,16 @@
|
|||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[[ 7055776.55287918]\n",
|
||||
" [17094863.33665218]\n",
|
||||
" [11506453.28737884]\n",
|
||||
" [ 7928487.37318672]\n",
|
||||
" [ 6207272.97538636]\n",
|
||||
" [10543201.56141501]\n",
|
||||
" [14835050.99568053]\n",
|
||||
" [12634499.4021036 ]\n",
|
||||
" [ 8157771.53337996]\n",
|
||||
" [ 889335.96828464]]\n"
|
||||
"[[ 2223721.47896785]\n",
|
||||
" [11295743.41566435]\n",
|
||||
" [13759978.74467681]\n",
|
||||
" [ 9233589.77281075]\n",
|
||||
" [ 7989194.12896278]\n",
|
||||
" [ 5473333.88363707]\n",
|
||||
" [ 5016644.0905246 ]\n",
|
||||
" [ 8729254.15260335]\n",
|
||||
" [21998939.80880332]\n",
|
||||
" [13424679.19319787]]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
@ -360,7 +333,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now, let's make some changes to the temperatures. For this, we need to identify each cell by its index in the list of cells given to the geometry. We can use get_temperature() to compare the temperatures of the cells before and after the change. "
|
||||
"Now, let's make some changes to the temperatures. For this, we need to identify each cell by its id. We can use get_temperature() to compare the temperatures of the cells before and after the change. "
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -373,13 +346,25 @@
|
|||
"output_type": "stream",
|
||||
"text": [
|
||||
"fuel temperature is: \n",
|
||||
"566.0\n"
|
||||
"800.0\n",
|
||||
"gap temperature is: \n",
|
||||
"700.0\n",
|
||||
"clad temperature is: \n",
|
||||
"600.0\n",
|
||||
"water temperature is: \n",
|
||||
"500.00000000000006\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(\"fuel temperature is: \")\n",
|
||||
"print(openmc.lib.Cell(new=False, index=5).get_temperature())"
|
||||
"print(openmc.lib.cells[5].get_temperature())\n",
|
||||
"print(\"gap temperature is: \")\n",
|
||||
"print(openmc.lib.cells[15].get_temperature())\n",
|
||||
"print(\"clad temperature is: \")\n",
|
||||
"print(openmc.lib.cells[25].get_temperature())\n",
|
||||
"print(\"water temperature is: \")\n",
|
||||
"print(openmc.lib.cells[35].get_temperature())"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -388,9 +373,9 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"for i in range(10):\n",
|
||||
"for i in range(1, 11):\n",
|
||||
" temp = 900.0\n",
|
||||
" openmc.lib.Cell(new=False, index=i).set_temperature(temp)"
|
||||
" openmc.lib.cells[i].set_temperature(temp)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -416,7 +401,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Let's make a similar change for the water density. For this, we need to identify each material by its index in the list of materials given to openmc. "
|
||||
"Let's make a similar change for the water density. Again, we need to identify each material by its id."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -425,9 +410,9 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"for i in range(10):\n",
|
||||
"\tdensity = 0.65\n",
|
||||
"\topenmc.lib.Material(new=False, index=3+i).set_density(density, units='g/cm3')"
|
||||
"for i in range(4,14):\n",
|
||||
" density = 0.65\n",
|
||||
" openmc.lib.materials[i].set_density(density, units='g/cm3')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -441,33 +426,10 @@
|
|||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0"
|
||||
]
|
||||
},
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()\n",
|
||||
"openmc.lib.next_batch()"
|
||||
"for _ in range(14):\n",
|
||||
" openmc.lib.next_batch()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ General Usage
|
|||
post-processing
|
||||
pandas-dataframes
|
||||
tally-arithmetic
|
||||
CAPI
|
||||
expansion-filters
|
||||
search
|
||||
nuclear-data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue