-
Notifications
You must be signed in to change notification settings - Fork 41
Add 9-pebble DFEM k-eigenvalue tutorial #931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
liamncarlson
wants to merge
2
commits into
Open-Sn:main
Choose a base branch
from
liamncarlson:add-opensn-tutorial-lnc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,306 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "0292bb91-5e35-486f-b90e-39edc840ca87", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## OpenSn Tutoiral: 3D 9-Pebble BCC Lattice Cell\n", | ||
| "\n", | ||
| "This script performs a steady-state DFEM k-eigenvalue calculation for a nine-pebble geometry representing an infinite lattice. The corner pebbles are assigned homogenized multigroup cross sections that differ from those of the center pebble. The gap material consists of low-density helium. The unstructured tetrahedral mesh can be created using the jupyter notebook,\n", | ||
| "\n", | ||
| "opensn/doc/source/tutorials/lbs/9pebs/mesh/gmsh_9peb.ipynb\n", | ||
| "\n", | ||
| "\n", | ||
| "\n", | ||
| "This figure shows the nine-pebble mesh, with the helium gap material hidden for visual clarity. Each colored region corresponds to a distinct mesh subdomain or block, which can be assigned a specific cross-section representing the material properties for that region.\n", | ||
| "\n", | ||
| "The cell below begins by setting up MPI and importing all useful Python and OpenSn modules. An executable form of this script,\n", | ||
| "\n", | ||
| "opensn/doc/source/tutorials/lbs/9pebs/9_pebs_dfem_9grp.py\n", | ||
| "\n", | ||
| "is designed to be run in parallel using mpirun." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "4003a12b-7314-4ad3-8254-2234c160ab2e", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import os\n", | ||
| "import sys\n", | ||
| "import re\n", | ||
| "\n", | ||
| "# ---------------------------------------------------------\n", | ||
| "# MPI + OpenSn Python bindings setup\n", | ||
| "# ---------------------------------------------------------\n", | ||
| "if \"opensn_console\" not in globals():\n", | ||
| " from mpi4py import MPI\n", | ||
| " size = MPI.COMM_WORLD.size\n", | ||
| " rank = MPI.COMM_WORLD.rank\n", | ||
| "\n", | ||
| " # Add OpenSn Python module path (adjust if necessary)\n", | ||
| " sys.path.append(os.path.abspath(os.path.join(os.path.dirname(\"__file__\"), \"../../../../../\")))\n", | ||
| "\n", | ||
| " # Import OpenSn components\n", | ||
| " from pyopensn.aquad import GLCProductQuadrature3DXYZ\n", | ||
| " from pyopensn.solver import DiscreteOrdinatesSolver\n", | ||
| " from pyopensn.fieldfunc import FieldFunctionGridBased\n", | ||
| " from pyopensn.solver import NonLinearKEigen\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "99bd45b1-42db-447b-9823-490547c9c77d", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Load the 9-Pebble Mesh\n", | ||
| "\n", | ||
| "This step is important not only to load the mesh file, but also to partition it for parallel execution. Each mpi process will be assigned a subset or partition of the mesh. The partitioner (parmetis) uses this information to decide how to split the mesh for parallel computation. The image below shows an example where the 9-pebble domain is partitioned between 16 mpi tasks.\n", | ||
| "\n", | ||
| "\n", | ||
| "\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "51446690-1e17-40a3-8cf7-d75d3c6910c0", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "mesh_file = \"mesh/msh_meshes/9_peb.msh\"\n", | ||
| "\n", | ||
| "# Load mesh and partition it for parallel execution\n", | ||
| "meshgen = FromFileMeshGenerator(\n", | ||
| " filename=mesh_file,\n", | ||
| " partitioner=PETScGraphPartitioner(type='parmetis')\n", | ||
| ")\n", | ||
| "\n", | ||
| "grid = meshgen.Execute()\n", | ||
| "\n", | ||
| "# Export mesh to Paraview format for inspection\n", | ||
| "grid.ExportToPVTU(\"9pebs\")\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "a841ee56-dc91-4488-8ab5-823759b58520", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Load Multigroup Cross Sections\n", | ||
| "\n", | ||
| "Here, there are three cross section files corresponding to three separate materials, the corner pebbles, the center pebble, and the helium gap." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "6a3b0993-b3b9-421c-a624-cc4ed785fe94", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "xss = []\n", | ||
| "for m in range(3):\n", | ||
| " xss.append(MultiGroupXS())\n", | ||
| "\n", | ||
| "# Store cross section data as a list\n", | ||
| "xss[0].LoadFromOpenSn(\"xs_files/xs_p_1.xs\") # corner pebbles\n", | ||
| "xss[1].LoadFromOpenSn(\"xs_files/xs_p_5.xs\") # center pebble\n", | ||
| "xss[2].LoadFromOpenSn(\"xs_files/xs_50.xs\") # helium gap\n", | ||
| "\n", | ||
| "# Store the number of energy groups\n", | ||
| "num_groups = xss[0].num_groups\n", | ||
| "print(\"Number of energy groups:\", num_groups)\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "23a9b537-8283-4120-a2c7-c81c254e147a", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Map Cross Sections to Mesh Block IDs\n", | ||
| "\n", | ||
| "Assign XS to each mesh region based on block IDs. Note that a single material may be replicated across several block IDs." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "abb98609-7b2c-4ff7-9f8b-2380517b5e01", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "\n", | ||
| "xs_map = []\n", | ||
| "xs_map.append({\"block_ids\": [0, 1, 2, 3, 5, 6, 7, 8], \"xs\": xss[0]}) # corner pebbles\n", | ||
| "xs_map.append({\"block_ids\": [4], \"xs\": xss[1]}) # center pebble\n", | ||
| "xs_map.append({\"block_ids\": [9], \"xs\": xss[2]}) # coolant gap\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "28eaefad-0db2-416e-b767-71ec1ff4f9dc", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Angular Quadrature:\n", | ||
| "\n", | ||
| "Declare Gauss-Legendre Chebyshev product quadrature" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "59988bef-708d-4784-b659-47baffa54d8c", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "\n", | ||
| "# Choose S4 quadrature (can try S2 or S8)\n", | ||
| "pquad = GLCProductQuadrature3DXYZ(4, 8)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "fe4d9d6f-b0d4-46a8-9635-dd0c53153d0d", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Discrete Ordiantes (SN) Solver Setup:\n", | ||
| "\n", | ||
| "Configure solver with mesh, groups, quadrature, and material map which were all set up in the previous sections." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "f21b578a-3ef8-4865-beda-6a7a4d616c09", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "\n", | ||
| "phys = DiscreteOrdinatesSolver(\n", | ||
| " mesh=grid,\n", | ||
| " num_groups=num_groups,\n", | ||
| " groupsets=[\n", | ||
| " {\n", | ||
| " \"groups_from_to\": (0, num_groups - 1),\n", | ||
| " \"angular_quadrature\": pquad,\n", | ||
| " \"inner_linear_method\": \"petsc_gmres\",\n", | ||
| " \"l_max_its\": 10,\n", | ||
| " \"l_abs_tol\": 1.0e-7,\n", | ||
| " \"angle_aggregation_type\": \"single\",\n", | ||
| " \"angle_aggregation_num_subsets\": 1,\n", | ||
| " },\n", | ||
| " ],\n", | ||
| " xs_map=xs_map,\n", | ||
| " options={\n", | ||
| " \"boundary_conditions\": [\n", | ||
| " {\"name\": \"xmin\", \"type\": \"reflecting\"},\n", | ||
| " {\"name\": \"xmax\", \"type\": \"reflecting\"},\n", | ||
| " {\"name\": \"ymin\", \"type\": \"reflecting\"},\n", | ||
| " {\"name\": \"ymax\", \"type\": \"reflecting\"},\n", | ||
| " {\"name\": \"zmin\", \"type\": \"reflecting\"},\n", | ||
| " {\"name\": \"zmax\", \"type\": \"reflecting\"}\n", | ||
| " ],\n", | ||
| " \"scattering_order\": 2,\n", | ||
| " \"verbose_outer_iterations\": True,\n", | ||
| " \"verbose_inner_iterations\": True,\n", | ||
| " \"power_field_function_on\": True,\n", | ||
| " \"power_default_kappa\": 1.0,\n", | ||
| " \"power_normalization\": 2000.0,\n", | ||
| " \"save_angular_flux\": True,\n", | ||
| " },\n", | ||
| " sweep_type=\"CBC\",\n", | ||
| ")\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "789244d2-f913-4453-8eee-0c0c2734f291", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Nonlinear k-Eigenvalue Solver\n", | ||
| "\n", | ||
| "Initialize and run the criticality calculation." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "ff3d301d-746a-4871-a259-11a763858f59", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "\n", | ||
| "k_solver = NonLinearKEigen(\n", | ||
| " lbs_solver=phys,\n", | ||
| " nl_max_its=50,\n", | ||
| " nl_abs_tol=1.0e-10,\n", | ||
| " nl_rel_tol=1.0e-10,\n", | ||
| " l_max_its=20,\n", | ||
| " num_initial_power_iterations=2,\n", | ||
| ")\n", | ||
| "\n", | ||
| "k_solver.Initialize()\n", | ||
| "k_solver.Execute()\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "8bb2fc87-9482-4442-84fe-138bcde09296", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Export Scalar Flux to VTK\n", | ||
| "\n", | ||
| "This code exports the scalar flux field functions computed by the solver to VTK format for visualization and post-processing. By calling GetScalarFieldFunctionList, only the scalar flux fields are retrieved, omitting angular fluxes to reduce file size and simplify analysis. ExportMultipleToVTK then writes these fields to files with the specified basename, creating one or more VTK files suitable for ParaView or other visualization tools. This allows the user to inspect the spatial distribution of neutron flux throughout the nine-pebble geometry, verify solver results, and perform further analyses such as integrating flux to compute reaction rates or visualizing cross-section assignments across different mesh blocks." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "e9df8de5-e019-4823-a71e-b3fd8f4bf819", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "\n", | ||
| "fflist = phys.GetScalarFieldFunctionList(only_scalar_flux=True)\n", | ||
| "vtk_basename = \"9pebs_dfem_9grp_out\"\n", | ||
| "\n", | ||
| "FieldFunctionGridBased.ExportMultipleToVTK(fflist, vtk_basename)\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "ca7633e1-6f7d-479e-9ebc-78374b899886", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Exporting the scalar flux field to a VTK-compatible mesh enables detailed postprocessing and quantitative analysis in visualization tools such as ParaView. The image below shows the spatial distribution of thermal flux (group 7 of 9) in the nine-pebble problem.\n", | ||
| "\n", | ||
| "" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3 (ipykernel)", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.12.2" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
|
|
||
| KEigen | ||
| ======================= | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 1 | ||
|
|
||
| pincell_example | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't name your tutorial "pincell_example". Please update this to the file name (without .ipynb extension).