Skip to content
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

Merge the new tally structure #227

Merged
merged 39 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e4e88fd
start restructuring tally
ilhamv Jun 3, 2024
e3b6d45
start restructuring tally
ilhamv Jun 3, 2024
39a4203
make tally 3x1D
ilhamv Jun 3, 2024
39d4ca0
back in black
ilhamv Jun 3, 2024
0146115
fix mpi regression test
ilhamv Jun 3, 2024
9925071
fix numba
ilhamv Jun 3, 2024
d5b5455
rafactor tally and better tally support
ilhamv Jun 4, 2024
630a938
back in black
ilhamv Jun 4, 2024
2b45155
revise dd answer (reorganize hdf5 data)
ilhamv Jun 5, 2024
c89cd9d
refer tmax to input deck, not mcdc state
ilhamv Jun 6, 2024
5766606
fixing input errors for CE
ilhamv Jun 7, 2024
09782d6
resolve more conflict
ilhamv Jul 3, 2024
1a821dc
back in black
ilhamv Jul 3, 2024
0045221
fix unit test
ilhamv Jul 3, 2024
016baab
Decomposed mesh tallies when domain decomposition is active
alexandermote Jul 19, 2024
908c9af
Revised mesh tally decomposition
alexandermote Jul 22, 2024
fca1887
Fixed DD mesh indexing and recomposition
alexandermote Aug 12, 2024
be37bec
minor changes
ilhamv Aug 13, 2024
a0b7c2a
back in black
ilhamv Aug 13, 2024
0c65022
Merge pull request #212 from alexandermote/better_tally
ilhamv Aug 14, 2024
90033a2
Merge branch 'dev' into better_tally
ilhamv Aug 14, 2024
1b51de5
fix an overlooked conflict
ilhamv Aug 14, 2024
62f4dfb
missing PI constant in card.py
ilhamv Aug 14, 2024
8c214a4
fix slab_ce and source_file regression tests
ilhamv Aug 14, 2024
5ebb026
back in black
ilhamv Aug 14, 2024
2b3aabd
Added test for 3D domain/tally decomposition
alexandermote Aug 15, 2024
1ec806d
Merge branch 'better_tally' of https://github.com/alexandermote/MCDC …
alexandermote Aug 15, 2024
38a1ba3
Fixed tally reorganization for decomposed tallies
alexandermote Aug 15, 2024
6f22999
Bringing main.py up to date
alexandermote Aug 15, 2024
692fb68
Cleaning edit files
alexandermote Aug 15, 2024
f365013
Back in black
alexandermote Aug 15, 2024
db257f6
Merge branch 'better_tally' of https://github.com/alexandermote/MCDC …
alexandermote Aug 15, 2024
a2e96b9
explicit in checking the test name
ilhamv Aug 17, 2024
3a9517c
misnaming dd_slab_reed
ilhamv Aug 17, 2024
fae64cd
Merge pull request #230 from alexandermote/better_tally
ilhamv Aug 23, 2024
cd68f72
merge conflict resolved. next, fix the failing tests.
ilhamv Aug 27, 2024
829f1a6
revise azurv1 key
ilhamv Aug 27, 2024
89293d6
fix iqmc error. revise regression test. next, fix slab_ce
ilhamv Aug 27, 2024
8762146
fix ce energy indexing at mesh tall scoring; also revise slab_ce
ilhamv Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mcdc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
universe,
lattice,
source,
tally,
setting,
eigenmode,
implicit_capture,
Expand All @@ -26,6 +25,7 @@
make_particle_bank,
save_particle_bank,
)
import mcdc.tally
from mcdc.main import run, prepare

__version__ = importlib.metadata.version("mcdc")
55 changes: 52 additions & 3 deletions mcdc/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
BOOL_OR,
BOOL_NOT,
INF,
TINY,
PI,
)

# Get the global variable container
Expand All @@ -33,11 +33,17 @@ def __str__(self):


class NuclideCard(InputCard):
def __init__(self, G=1, J=0):
def __init__(self, G=1, J=0, name=None):
InputCard.__init__(self, "Nuclide")

# Continuous energy?
if name is not None:
G = 0
J = 0

# Set card data
self.ID = None
self.name = name
self.G = G
self.J = J
self.fissionable = False
Expand Down Expand Up @@ -161,6 +167,8 @@ def __init__(self):
self.nx = 0.0
self.ny = 0.0
self.nz = 0.0
self.N_tally = 0
self.tally_IDs = []

def _create_halfspace(self, positive):
region = RegionCard("halfspace")
Expand Down Expand Up @@ -331,6 +339,47 @@ def __init__(self):
self.white_y = 0.0
self.white_z = 0.0
self.group = np.array([1.0])
self.energy = np.array([[14e6, 14e6], [1.0, 1.0]])
self.energy = np.array([[1e6 - 1.0, 1e6 + 1.0], [1.0, 1.0]])
self.time = np.array([0.0, 0.0])
self.prob = 1.0


# ======================================================================================
# Tally cards
# ======================================================================================


class TallyCard(InputCard):
def __init__(self, type_):
InputCard.__init__(self, type_)

# Set card data
self.ID = None
self.scores = []
self.N_bin = 0

# Filters
self.t = np.array([-INF, INF])
self.mu = np.array([-1.0, 1.0])
self.azi = np.array([-PI, PI])
self.g = np.array([-INF, INF])


class MeshTallyCard(TallyCard):
def __init__(self):
TallyCard.__init__(self, "Mesh tally")

# Set card data
self.x = np.array([-INF, INF])
self.y = np.array([-INF, INF])
self.z = np.array([-INF, INF])
self.N_bin = 1


class SurfaceTallyCard(TallyCard):
def __init__(self, surface_ID):
TallyCard.__init__(self, "Surface tally")

# Set card data
self.surface_ID = surface_ID
self.N_bin = 1
16 changes: 16 additions & 0 deletions mcdc/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
import numba as nb


# Data index
TALLY = 0

# Tally bins
TALLY_SCORE = 0
TALLY_SUM = 1
TALLY_SUM_SQ = 2
TALLY_UQ_BATCH = 3
TALLY_UQ_BATCH_VAR = 4

# Tally scores
SCORE_FLUX = 0
SCORE_TOTAL = 1
SCORE_FISSION = 2
SCORE_NET_CURRENT = 3

# Boundary condition
BC_NONE = 0
BC_VACUUM = 1
Expand Down
15 changes: 2 additions & 13 deletions mcdc/global_.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,8 @@ def reset(self):
self.universes = [None] # Placeholder for the root universe
self.lattices = []
self.sources = []

self.tally = {
"tag": "Tally",
"tracklength": True,
"flux": False,
"density": False,
"fission": False,
"total": False,
"current": False,
"eddington": False,
"exit": False,
"mesh": make_card_mesh(),
}
self.mesh_tallies = []
self.surface_tallies = []

self.setting = {
"tag": "Setting",
Expand Down
93 changes: 11 additions & 82 deletions mcdc/input_.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import numpy as np
import scipy as sp

import mcdc.type_ as type_

from mcdc.card import (
NuclideCard,
MaterialCard,
Expand Down Expand Up @@ -39,6 +37,7 @@
TINY,
)
from mcdc.print_ import print_error
import mcdc.type_ as type_


def nuclide(
Expand Down Expand Up @@ -902,6 +901,16 @@ def source(**kw):
G = global_.input_deck.materials[0].G
group = np.ones(G)
card.group = group / np.sum(group)
# Default for CE
if global_.input_deck.setting["mode_CE"]:
# Normalize pdf
card.energy[1, :] = card.energy[1, :] / np.trapz(
card.energy[1, :], x=card.energy[0, :]
)
# Make cdf
card.energy[1, :] = sp.integrate.cumulative_trapezoid(
card.energy[1], x=card.energy[0], initial=0.0
)

# Set time
if time is not None:
Expand All @@ -917,82 +926,6 @@ def source(**kw):
return card


def tally(
scores,
x=np.array([-INF, INF]),
y=np.array([-INF, INF]),
z=np.array([-INF, INF]),
t=np.array([-INF, INF]),
mu=np.array([-1.0, 1.0]),
azi=np.array([-PI, PI]),
g=np.array([-INF, INF]),
E=np.array([0.0, INF]),
):
"""
Create a tally card to collect MC solutions.

Parameters
----------
scores : list of str
List of tally types (default ["tracklength"]).
x : array_like[float], optional
x-coordinates that demarcate tally bins (default numpy.ndarray([-INF, INF])).
y : array_like[float], optional
y-coordinates that demarcate tally bins (default numpy.ndarray([-INF, INF])).
z : array_like[float], optional
z-coordinates that demarcate tally bins (default numpy.ndarray([-INF, INF])).
t : array_like[float], optional
Times that demarcate tally bins (default numpy.ndarray([-INF, INF])).
mu : array_like[float], optional
Angles that demarcate axial angular tally bins (default numpy.ndarray([-1.0, 1.0])).
azi : array_like[float], optional
Angles that demarcate azimuthal angular tally bins (default numpy.ndarray([-1.0, 1.0])).
g : array_like[float], optional
Energies that demarcate energy tally bins (default numpy.ndarray([-INF, INF])).
E : array_like[float], optional
Continuous energy functionality, (default numpy.ndarray([0.0, INF])).

Returns
-------
dictionary
A tally card.
"""

# Get tally card
card = global_.input_deck.tally

# Set mesh
card["mesh"]["x"] = x
card["mesh"]["y"] = y
card["mesh"]["z"] = z
card["mesh"]["t"] = t
card["mesh"]["mu"] = mu
card["mesh"]["azi"] = azi

# Set energy group grid
if type(g) == type("string") and g == "all":
G = global_.input_deck.materials[0].G
card["mesh"]["g"] = np.linspace(0, G, G + 1) - 0.5
else:
card["mesh"]["g"] = g
if global_.input_deck.setting["mode_CE"]:
card["mesh"]["g"] = E

# Set score flags
for s in scores:
found = False
for score_name in type_.score_list:
if s.replace("-", "_") == score_name:
card["tracklength"] = True
card[score_name] = True
found = True
break
if not found:
print_error("Unknown tally score %s" % s)

return card


# ==============================================================================
# Setting
# ==============================================================================
Expand Down Expand Up @@ -1203,10 +1136,6 @@ def eigenmode(
else:
print_error("Unknown gyration radius type")

# Update tally card
card = global_.input_deck.tally
card["tracklength"] = True


# ==============================================================================
# Technique
Expand Down
18 changes: 18 additions & 0 deletions mcdc/iqmc/iqmc_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,24 @@ def iqmc_continuous_weight_reduction(P, distance, mcdc):
P["w"] = P["iqmc"]["w"].sum()


# =============================================================================
# Surface crossing
# =============================================================================


@toggle("iQMC")
def iqmc_surface_crossing(P, prog):
mcdc = adapt.device(prog)

# Implement BC
surface = mcdc["surfaces"][P["surface_ID"]]
geometry.surface_bc(P, surface)

# Need to check new cell later?
if P["alive"] and not surface["BC"] == BC_REFLECTIVE:
P["cell_ID"] = -1


# =============================================================================
# iQMC Source Operations
# =============================================================================
Expand Down
2 changes: 1 addition & 1 deletion mcdc/iqmc/iqmc_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def iqmc_step_particle(P, prog):

# Surface crossing
if event & EVENT_SURFACE_CROSSING:
kernel.surface_crossing(P, prog)
iqmc_kernel.iqmc_surface_crossing(P, prog)
if event & EVENT_DOMAIN_CROSSING:
if not (
mcdc["surfaces"][P["surface_ID"]]["BC"] == BC_REFLECTIVE
Expand Down
Loading
Loading