Skip to content

Commit 195b24c

Browse files
committed
initial commit of dassh_power pathway to write pin total power distribution with no temperature sweep
1 parent 7f25a08 commit 195b24c

File tree

3 files changed

+95
-81
lines changed

3 files changed

+95
-81
lines changed

dassh/__main__.py

+65-3
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
# permissions and limitations under the License.
1515
########################################################################
1616
"""
17-
date: 2022-01-20
17+
date: 2022-12-19
1818
author: matz
19-
Main DASSH calculation procedure
19+
Main DASSH calculation procedures
2020
"""
2121
########################################################################
2222
import os
2323
import sys
24-
import dassh
24+
import numpy as np
2525
import argparse
2626
import cProfile
2727
import logging
28+
import dassh
2829
_log_info = 20 # logging levels must be int
2930

3031

@@ -279,5 +280,66 @@ def plot():
279280
dassh_logger.log(_log_info, 'DASSH_PLOT execution complete')
280281

281282

283+
def integrate_pin_power(args=None):
284+
"""Set up DASSH Reactor object, integrate pin power, and write to CSV"""
285+
# Get input file from command line arguments
286+
parser = argparse.ArgumentParser(description='Process DASSH cmd')
287+
parser.add_argument('inputfile',
288+
metavar='inputfile',
289+
help='The input file to run with DASSH')
290+
parser.add_argument('--save_reactor',
291+
action='store_true',
292+
help='Save DASSH Reactor object after sweep')
293+
args = parser.parse_args()
294+
295+
# Initiate logger
296+
print(dassh._ascii._ascii_title)
297+
in_path = os.path.split(args.inputfile)[0]
298+
dassh_logger = dassh.logged_class.init_root_logger(in_path, 'dassh_power')
299+
300+
# Pre-processing
301+
# Read input file and set up DASSH input object
302+
dassh_logger.log(_log_info, f'Reading input: {args.inputfile}')
303+
dassh_input = dassh.DASSHPower_Input(args.inputfile)
304+
305+
# Initialize the Reactor object
306+
reactor = dassh.Reactor(dassh_input, write_output=False)
307+
308+
# Generate pin power distributions
309+
dassh_logger.log(_log_info, 'Generating pin power distributions...')
310+
asm_ids = []
311+
n_pins = []
312+
integrated_pin_powers = []
313+
for a in reactor.assemblies:
314+
if a.has_rodded:
315+
asm_ids.append(a.id)
316+
n_pins.append(a.rodded.n_pin)
317+
integrated_pin_powers.append(
318+
dassh.power._integrate_pin_power(a.power))
319+
320+
# Save reactor if desired
321+
dassh_logger.log(_log_info, 'Saving data')
322+
if args.save_reactor:
323+
if sys.version_info < (3, 7):
324+
handlers = dassh_logger.handlers[:]
325+
for handler in handlers:
326+
handler.close()
327+
dassh_logger.removeHandler(handler)
328+
reactor.save()
329+
if sys.version_info < (3, 7):
330+
dassh_logger = dassh.logged_class.init_root_logger(
331+
os.path.split(dassh_logger._root_logfile_path)[0],
332+
'dassh', 'a+')
333+
334+
# Write distributions to CSV
335+
arr_to_write = np.zeros((max(n_pins) + 1, len(asm_ids)))
336+
arr_to_write[0] = asm_ids
337+
for col in range(arr_to_write.shape[1]):
338+
arr_to_write[1:(n_pins[col] + 1), col] = integrated_pin_powers[col]
339+
outpath = os.path.join(dassh_input.path, 'total_pin_power.csv')
340+
np.savetxt(outpath, arr_to_write, delimiter=',')
341+
dassh_logger.log(_log_info, 'DASSH_POWER execution complete')
342+
343+
282344
if __name__ == '__main__':
283345
main()

dassh/power.py

+27-76
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# permissions and limitations under the License.
1515
########################################################################
1616
"""
17-
date: 2022-03-16
17+
date: 2022-12-19
1818
author: matz
1919
Generate power distributions in assembly components based on neutron
2020
flux; object to assign to individual assemblies
@@ -1508,82 +1508,33 @@ def _integrate(pp_pins, pp_duct, pp_cool, n_terms):
15081508
return avg_power[:, 1] - avg_power[:, 0]
15091509

15101510

1511-
########################################################################
1511+
def _integrate_pin_power(asm_power):
1512+
"""Integrate the pin power distributions
15121513
1513-
# def renormalize(self, z, dz):
1514-
# """Need to normalize the power based on the discretization that
1515-
# DASSH will make during the sweep in order to accurately deliver
1516-
# the correct power
1517-
#
1518-
# Parameters
1519-
# ----------
1520-
# z : numpy.ndarray
1521-
# Absolute axial points (m)
1522-
# dz : numpy.ndarray
1523-
# Mesh step sizes (m)
1524-
#
1525-
# Returns
1526-
# -------
1527-
# numpy.ndarray
1528-
# Array of correction factors for each fine mesh interval
1529-
#
1530-
# """
1531-
# # Preprocess the axial mesh points
1532-
# z = z[1:] * 100 # m --> cm
1533-
# z = z - 0.5 * dz # get the axial mesh midpoints
1534-
# # Get the fine mesh intervals and the transformed z values for
1535-
# # each of the axial mesh points where power is evaluated.
1536-
# # kf = get_kfint2(self, z)
1537-
# # zm = transform_z2(self, kf, z)
1538-
# kf = self.get_kfint2(z)
1539-
# zm = self.transform_z2(kf, z)
1540-
# zm = np.expand_dims(zm, 1)
1541-
#
1542-
# # Raise those transformed z values to the monomial exponent
1543-
# z_exp = np.power(zm, np.arange(self.n_terms))
1544-
# z_exp = np.expand_dims(z_exp, 1)
1545-
#
1546-
# # Multiply the coefficients through and sum to get the total
1547-
# # power in each axial step: do this for pins, duct, and coolant
1548-
# mult_terms = self.pin_power[kf] * z_exp
1549-
# sum_terms = np.sum(mult_terms, axis=(1, 2))
1550-
# mult_terms = self.duct_power[kf] * z_exp
1551-
# sum_terms += np.sum(mult_terms, axis=(1, 2))
1552-
# mult_terms = self.coolant_power[kf] * z_exp
1553-
# sum_terms += np.sum(mult_terms, axis=(1, 2))
1554-
#
1555-
# # Dimension is equal to n_step x 1; equals total in each step
1556-
# sum_terms = sum_terms * 100 # W/cm --> W/m
1557-
#
1558-
# # Normalize each step linear power by step size
1559-
# dz_fint = self.z_finemesh[1:] - self.z_finemesh[:-1]
1560-
# dz_fint = dz_fint[kf] # cm
1561-
# sum_terms = sum_terms * dz / dz_fint # W/m * m / cm = W/cm
1562-
#
1563-
# # Determine the corrective factor in each kfint
1564-
# x = np.zeros(len(self.z_finemesh) - 1)
1565-
# for i in range(len(x)):
1566-
# # self.avg_power has units of W/cm; so does sum_terms
1567-
# x[i] = self.avg_power[i] / np.sum(sum_terms[kf == i])
1568-
# # x[i] = self.avg_power[i] * 100 / np.average(sum_terms[kf == i])
1569-
# return x
1514+
Parameters
1515+
----------
1516+
asm_power : DASSH AssemblyPower object
1517+
1518+
Returns
1519+
-------
1520+
numpy.ndarray
1521+
Total power in each pin
15701522
1523+
"""
1524+
z_bnds = np.array([-0.5, 0.5])
1525+
z_bnds = z_bnds.reshape(2, 1)
1526+
int_exponents = np.arange(1, asm_power.n_terms + 1)
1527+
z_int = np.power(z_bnds, int_exponents)
1528+
# Integrate in each region, evaluate at lower/upper bound
1529+
# shape is n_region x n_pin x 2 (upper/lower bound)
1530+
integrated = np.dot(asm_power.pin_power / int_exponents, z_int.T)
1531+
# Take the difference across the region
1532+
# shape is n_region x n_pin
1533+
diff_across_region = integrated[:, :, 1] - integrated[:, :, 0]
1534+
# multiply linear power by z-bounds and sum to get total power
1535+
# in each pin
1536+
dz_finemesh = asm_power.z_finemesh[1:] - asm_power.z_finemesh[:-1]
1537+
power_per_pin = np.dot(dz_finemesh, diff_across_region)
1538+
return power_per_pin
15711539

15721540
########################################################################
1573-
# Old
1574-
# def calculate_total_power(self):
1575-
# """Calculate the total power (W) produced by the assembly using
1576-
# the linear power (W/m) shape functions."""
1577-
#
1578-
# dz = [self.z_finemesh[k] - self.z_finemesh[k - 1]
1579-
# for k in range(1, len(self.z_finemesh))]
1580-
# p_total = 0.0
1581-
# for k in range(len(dz)):
1582-
# zc = self.z_finemesh[k] + dz[k] / 2 # center of mesh cell
1583-
# if k < self.k_bnds[0] or k >= self.k_bnds[1]:
1584-
# p_total += dz[k] * self.get_refl_power(zc)
1585-
# else:
1586-
# p_total += dz[k] * (np.sum(self.get_pin_power(zc))
1587-
# + np.sum(self.get_duct_power(zc))
1588-
# + np.sum(self.get_coolant_power(zc)))
1589-
# return p_total

setup.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# permissions and limitations under the License.
1515
########################################################################
1616
"""
17-
date: 2022-01-20
17+
date: 2022-12-16
1818
author: Milos Atz
1919
"""
2020
########################################################################
@@ -130,7 +130,8 @@ def check_dependencies():
130130
'Operating System :: MacOS'],
131131
entry_points={'console_scripts': [
132132
'dassh = dassh.__main__:main',
133-
'dassh_plot = dassh.__main__:plot']}
133+
'dassh_plot = dassh.__main__:plot',
134+
'dassh_power = dassh.__main__:integrate_pin_power']}
134135
)
135136

136137

0 commit comments

Comments
 (0)