Skip to content

Instantly share code, notes, and snippets.

@pshriwise
pshriwise / gist:73c33d712da0a8f493e049dfb67a4f57
Created February 26, 2025 18:50
Mesh Material Raytracing Test Script
import os
import sys
import numpy as np
from scipy.spatial import Delaunay
from scipy.stats import qmc
import openmc
cube_corners = np.array([
[0, 0, 0],
@pshriwise
pshriwise / plane_test.py
Created November 18, 2024 22:32
Plots a plane and generates a Cubit file for an OpenMC general plane
import openmc
from openmc_cad_adapter import to_cubit_journal
import matplotlib.pyplot as plt
import numpy as np
# Define the coefficients of the plane
a, b, c, d = 1, 2, -3, 1
plane = openmc.Plane(a, b, c, d)
@pshriwise
pshriwise / openmc_tree.py
Last active November 1, 2024 20:26
Basic PyQT application for exploring an OpenMC model
#!python
import sys
from PySide6.QtWidgets import (
QApplication, QTabWidget, QVBoxLayout, QWidget, QTreeWidget, QTreeWidgetItem, QMessageBox
)
from PySide6.QtCore import Qt, QThread, Signal
import openmc
class LoadGeometryThread(QThread):
@pshriwise
pshriwise / geometry-examples.ipynb
Last active May 16, 2024 17:00
OpenMC CSG Geometry Examples
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pshriwise
pshriwise / new_dagmc_names.py
Created March 25, 2024 06:45
Convert old DAGMC group names that appear from MCNP imports to the current DAGMC naming format
#!python
for (group_name, group_id) in cubit.group_names_ids():
# ignore group "picked". It is always present by default and isn't
# relevant for DAGMC metadata
if group_name == 'picked':
continue
tokens = group_name.split('_')
properties = [f'{p}:{v}' for p, v in zip(tokens[::2], tokens[1::2])]
new_name = '/'.join(properties)
@pshriwise
pshriwise / compute_faceting_tolerance.py
Created January 26, 2024 04:36
Compute the faceting tolerance for a surface or all surfaces of a model
#!python
import numpy as np
import sys
# sys.path.append( r"C:\Program Files\Coreform Cubit 2023.11\bin")
# import cubit
def compute_tri_surf_dist_err(surface_id=None):
"""Compute the maximum distance between a surface's triangles the closest point on a surface."""
@pshriwise
pshriwise / random-sampling.ipynb
Created January 24, 2024 22:10
Test Notebook for NE506 Exercises
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pshriwise
pshriwise / export_slides_url.py
Last active January 16, 2025 21:55
Generate a URL for PDF export of a Google slide deck
from argparse import ArgumentParser
import sys
import os
args = ArgumentParser()
args.add_argument('document_id', help='Google Slides document ID')
args.add_argument('--output', help='Content in output',
choices=('html', 'iframe', 'link', 'pdf'), default='html')
args = args.parse_args()
@pshriwise
pshriwise / threaded_scaling.py
Last active March 13, 2025 05:09
A script for checking scaling of a DAGMC model.
import sys
from pathlib import Path
from matplotlib import pyplot as plt
import openmc
import numpy as np
def threaded_scaling(threads, model, openmc_exec='openmc', output_filename=None, particles_per_thread=10_000):
"""Run simulation with various threads and collect timing results
@pshriwise
pshriwise / groups_to_block_mats.py
Last active March 28, 2024 03:54
A code snippet for converting DAGMC Cubit groups to blocks and material assignments
import cubit
for (name, gid) in cubit.group_names_ids():
# skip the 'picked' group and other groups
# that aren't materials
if name == 'picked' or 'mat' not in name:
continue
mat = name.split('/')[0].split(':')[1]
if not mat: