Skip to content

Commit

Permalink
Merge branch 'patch-90' into ci-overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
yardasol committed Dec 17, 2021
2 parents e72015a + 855f09f commit d418ae4
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions saltproc/depcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pyne import serpent
from abc import ABC, abstractmethod


class Depcode(ABC):
r"""Abstract class for interfacing with monte-carlo particle transport
codes. Contains information about input, output, geometry, and template
Expand Down Expand Up @@ -198,7 +199,7 @@ def __init__(self,
active_cycles,
inactive_cycles)

def change_sim_par(self, data):
def change_sim_par(self, template_data):
"""Finds simulation parameters (neutron population, cycles) in the
Serpent2 template file and change them to the parameters from the
SaltProc input file.
Expand All @@ -216,7 +217,7 @@ def change_sim_par(self, data):
"""
if self.npop and self.active_cycles and self.inactive_cycles:
sim_param = [s for s in data if s.startswith("set pop")]
sim_param = [s for s in template_data if s.startswith("set pop")]
if len(sim_param) > 1:
print('ERROR: Template file %s contains multiple lines with '
'simulation parameters:\n'
Expand All @@ -228,9 +229,9 @@ def change_sim_par(self, data):
return
args = 'set pop %i %i %i\n' % (self.npop, self.active_cycles,
self.inactive_cycles)
return [s.replace(sim_param[0], args) for s in data]
return [s.replace(sim_param[0], args) for s in template_data]

def create_iter_matfile(self, data):
def create_iter_matfile(self, template_data):
"""Finds ``include`` line with path to material file, copies content of
this file to iteration material file, changes path in ``include`` line
to newly created iteration material file.
Expand All @@ -247,7 +248,7 @@ def create_iter_matfile(self, data):
"""
data_dir = os.path.dirname(self.template_path)
include_str = [s for s in data if s.startswith("include ")]
include_str = [s for s in template_data if s.startswith("include ")]
if not include_str:
print('ERROR: Template file %s has no <include "material_file">'
' statements ' % (self.template_path))
Expand All @@ -271,7 +272,7 @@ def create_iter_matfile(self, data):
pass
# Create file with path for SaltProc rewritable iterative material file
shutil.copy2(abs_src_matfile, self.iter_matfile)
return [s.replace(src_file, self.iter_matfile) for s in data]
return [s.replace(src_file, self.iter_matfile) for s in template_data]

def get_nuc_name(self, nuc_code):
"""Returns nuclide name in human-readable notation: chemical symbol
Expand Down Expand Up @@ -361,7 +362,7 @@ def get_tra_or_dec(self, input_file):
map_dict.update({zzaaam: line[2]})
self.iso_map = map_dict

def insert_path_to_geometry(self, data):
def insert_path_to_geometry(self, template_data):
"""Inserts ``include <first_geometry_file>`` line on the 6th line of
Serpent2 input file.
Expand All @@ -372,14 +373,14 @@ def insert_path_to_geometry(self, data):
Returns
-------
input_data : list
template_data : list
List of strings containing modified path to geometry
in user's template file.
"""
data.insert(5, # Inserts on 6th line
'include \"' + str(self.geo_file[0]) + '\"\n')
return data
template_data.insert(5, # Inserts on 6th line
'include \"' + str(self.geo_file[0]) + '\"\n')
return template_data

def read_dep_comp(self, input_file, read_at_end=False):
"""Reads the Serpent2 `*_dep.m` file and returns a dictionary with
Expand Down Expand Up @@ -488,10 +489,14 @@ def read_depcode_template(self, template_path):
"""
file = open(template_path, 'r')
str_list = file.readlines()
return str_list
template_data = file.readlines()
return template_data

def replace_burnup_parameters(self, template_data, reactor, current_depstep_idx):
def replace_burnup_parameters(
self,
template_data,
reactor,
current_depstep_idx):
"""Adds or replaces the ``set power P dep daystep DEPSTEP`` line in
the Serpent2 input file. This line defines depletion history and power
levels with respect to the depletion step in the single run and
Expand All @@ -509,7 +514,7 @@ def replace_burnup_parameters(self, template_data, reactor, current_depstep_idx)
Returns
-------
input_data : list
template_data : list
List of strings containing modified in this function template file.
"""
Expand All @@ -521,16 +526,16 @@ def replace_burnup_parameters(self, template_data, reactor, current_depstep_idx)
else:
current_depstep = reactor.depl_hist[current_depstep_idx] - \
reactor.depl_hist[current_depstep_idx - 1]
for line in data:
for line in template_data:
if line.startswith('set power '):
line_idx = data.index(line)
del data[line_idx]

data.insert(line_idx, # Insert on 9th line
'set power %5.9E dep daystep %7.5E\n' %
(current_depstep_power,
current_depstep))
return data
line_idx = template_data.index(line)
del template_data[line_idx]

template_data.insert(line_idx, # Insert on 9th line
'set power %5.9E dep daystep %7.5E\n' %
(current_depstep_power,
current_depstep))
return template_data

def run_depcode(self, cores, nodes):
"""Runs Serpent2 as a subprocess with the given parameters.
Expand Down

0 comments on commit d418ae4

Please sign in to comment.