-
Notifications
You must be signed in to change notification settings - Fork 16
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
Serpent material temps #178
Changes from 10 commits
32c02be
0f690a3
42a1253
5586a09
5f84d01
d0c5b55
df1c026
d51b204
f0e9b22
d206857
08d94a5
aa46951
0c17f30
35cdb8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,9 @@ class SerpentDepcode(Depcode): | |
Number of active cycles. | ||
inactive_cycles : int | ||
Number of inactive cycles. | ||
|
||
burnable_material_card_data : dict of str to tuple | ||
Dictionary containing burnable material cards | ||
and the index of the `vol` option. | ||
|
||
""" | ||
|
||
|
@@ -95,7 +97,7 @@ def get_neutron_settings(self, file_lines): | |
|
||
def create_runtime_matfile(self, file_lines): | ||
"""Creates the runtime material file tracking burnable materials | ||
ans inserts the path to this file in the Serpent2 runtime input file | ||
and inserts the path to this file in the Serpent2 runtime input file | ||
|
||
Parameters | ||
---------- | ||
|
@@ -108,6 +110,20 @@ def create_runtime_matfile(self, file_lines): | |
Serpent2 runtime input file with updated material file path. | ||
|
||
""" | ||
burnable_materials_path, absolute_path = self.get_burnable_materials_file(file_lines) | ||
|
||
# Create data directory | ||
Path.mkdir(Path(self.runtime_matfile).parents[0], exist_ok=True) | ||
|
||
# Get material cards | ||
flines = self.read_plaintext_file(absolute_path) | ||
self.get_burnable_material_card_data(flines) | ||
|
||
# Create file with path for SaltProc rewritable iterative material file | ||
shutil.copy2(absolute_path, self.runtime_matfile) | ||
return [line.replace(burnable_materials_path, self.runtime_matfile) for line in file_lines] | ||
|
||
def get_burnable_materials_file(self, file_lines): | ||
runtime_dir = Path(self.template_input_file_path).parents[0] | ||
include_card = [line for line in file_lines if line.startswith("include ")] | ||
if not include_card: | ||
|
@@ -124,12 +140,25 @@ def create_runtime_matfile(self, file_lines): | |
raise IOError('Template file ' | ||
f'{self.template_input_file_path} includes ' | ||
'no file with materials description') | ||
# Create data directory | ||
Path.mkdir(Path(self.runtime_matfile).parents[0], exist_ok=True) | ||
|
||
# Create file with path for SaltProc rewritable iterative material file | ||
shutil.copy2(absolute_path, self.runtime_matfile) | ||
return [line.replace(burnable_materials_path, self.runtime_matfile) for line in file_lines] | ||
return burnable_materials_path, absolute_path.resolve() | ||
|
||
def get_burnable_material_card_data(self, file_lines): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need a docstring for this function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
# Get data for matfile | ||
mat_cards = \ | ||
[line.split() for line in file_lines if line.startswith("mat ")] | ||
|
||
for card in mat_cards: | ||
if 'fix' not in card: | ||
raise IOError(f'"mat" card for burnable material "{card[1]}' | ||
'does not have a "fix" option. Burnable materials' | ||
'in SaltProc must include the "fix" option. See' | ||
'the serpent wiki for more information: ' | ||
'https://serpent.vtt.fi/mediawiki/index.php/Input_syntax_manual#mat') | ||
# Get volume indices | ||
card_volume_idx = [(card.index('vol') + 1) for card in mat_cards] | ||
mat_names = [card[1] for card in mat_cards] | ||
mat_data = zip(mat_cards, card_volume_idx)#, mat_extensions) | ||
self.burnable_material_card_data = dict(zip(mat_names, mat_data)) | ||
|
||
def convert_nuclide_code_to_name(self, nuc_code): | ||
"""Converts Serpent2 nuclide code to symbolic nuclide name. | ||
|
@@ -520,13 +549,17 @@ def update_depletable_materials(self, mats, dep_end_time): | |
f.write('%% Material compositions (after %f days)\n\n' | ||
% dep_end_time) | ||
nuc_code_map = self.map_nuclide_code_zam_to_serpent() | ||
if not(hasattr(self, 'burnable_material_card_data')): | ||
lines = self.read_plaintext_file(self.template_input_file_path) | ||
_, abs_src_matfile = self.get_burnable_materials_file(lines) | ||
file_lines = self.read_plaintext_file(abs_src_matfile) | ||
self.get_burnable_material_card_data(file_lines) | ||
for name, mat in mats.items(): | ||
f.write('mat %s %5.9E burn 1 fix %3s %4i vol %7.5E\n' % | ||
(name, | ||
-mat.density, | ||
'09c', | ||
mat.temp, | ||
mat.vol)) | ||
mat_card, card_volume_idx = self.burnable_material_card_data[name] | ||
mat_card[2] = str(-mat.density) | ||
mat_card[card_volume_idx] = "%7.5E" % mat.vol | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like a hardcoded value. Is this the case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No this is string formatting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what I was thinking. Just wanted to make sure it wasn't hard coding any values. |
||
f.write(" ".join(mat_card)) | ||
f.write("\n") | ||
for nuc_code, mass_fraction in mat.comp.items(): | ||
zam_code = pyname.zzaaam(nuc_code) | ||
f.write(' %9s %7.14E\n' % | ||
|
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.
Do you need a docstring for this function?
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.
If this is a private function, I will accept not having a docstring. Since users should never interact with it. In this case, the code is documentation. However, if it is a private function it should have a single underscore at the beginning of the method name.