Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ProfugusMC
ProfugusMC
Commits
f1c98e93
Commit
f1c98e93
authored
Oct 06, 2017
by
Hamilton, Steven P
Browse files
Updating check script to be python3 compatible.
parent
42edc4ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Profugus/Source/Scripts/check_profugus.py
View file @
f1c98e93
...
@@ -4,110 +4,110 @@ import numpy as np
...
@@ -4,110 +4,110 @@ import numpy as np
import
os.path
import
os.path
def
check_solution
(
path_to_results
):
def
check_solution
(
path_to_results
):
# Load reference flux
# Load reference flux
ref_flux_filename
=
os
.
path
.
join
(
path_to_results
,
'c5g7_3d_flux_ref.h5'
)
ref_flux_filename
=
os
.
path
.
join
(
path_to_results
,
'c5g7_3d_flux_ref.h5'
)
assert
os
.
path
.
isfile
(
ref_flux_filename
)
assert
os
.
path
.
isfile
(
ref_flux_filename
)
ref_flux_file
=
h5py
.
File
(
ref_flux_filename
,
'r'
)
ref_flux_file
=
h5py
.
File
(
ref_flux_filename
,
'r'
)
ref_flux
=
np
.
array
(
ref_flux_file
[
'flux_mean'
])
ref_flux
=
np
.
array
(
ref_flux_file
[
'flux_mean'
])
ref_flux_std
=
np
.
array
(
ref_flux_file
[
'flux_std_dev'
])
ref_flux_std
=
np
.
array
(
ref_flux_file
[
'flux_std_dev'
])
# Load reference k
# Load reference k
ref_k_filename
=
os
.
path
.
join
(
path_to_results
,
'c5g7_3d_output_ref.h5'
)
ref_k_filename
=
os
.
path
.
join
(
path_to_results
,
'c5g7_3d_output_ref.h5'
)
assert
os
.
path
.
isfile
(
ref_k_filename
)
assert
os
.
path
.
isfile
(
ref_k_filename
)
ref_k_file
=
h5py
.
File
(
ref_k_filename
,
'r'
)
ref_k_file
=
h5py
.
File
(
ref_k_filename
,
'r'
)
ref_k_dset
=
ref_k_file
[
'/keff/mean'
]
ref_k_dset
=
ref_k_file
[
'/keff/mean'
]
ref_k_var_dset
=
ref_k_file
[
'/keff/variance'
]
ref_k_var_dset
=
ref_k_file
[
'/keff/variance'
]
ref_k
=
ref_k_dset
[
0
]
ref_k
=
ref_k_dset
[
0
]
ref_k_std
=
np
.
sqrt
(
ref_k_var_dset
[
0
])
ref_k_std
=
np
.
sqrt
(
ref_k_var_dset
[
0
])
print
'
\n
Reference k = {0:.6f} +/- {1:.3e}'
.
format
(
ref_k
,
ref_k_std
)
print
(
'
\n
Reference k = {0:.6f} +/- {1:.3e}'
.
format
(
ref_k
,
ref_k_std
)
)
# Load flux file for comparison
# Load flux file for comparison
flux_filename
=
os
.
path
.
join
(
path_to_results
,
'c5g7_3d_flux.h5'
)
flux_filename
=
os
.
path
.
join
(
path_to_results
,
'c5g7_3d_flux.h5'
)
assert
os
.
path
.
isfile
(
flux_filename
)
assert
os
.
path
.
isfile
(
flux_filename
)
flux_file
=
h5py
.
File
(
flux_filename
,
'r'
)
flux_file
=
h5py
.
File
(
flux_filename
,
'r'
)
flux
=
np
.
array
(
flux_file
[
'flux_mean'
])
flux
=
np
.
array
(
flux_file
[
'flux_mean'
])
flux_std
=
np
.
array
(
flux_file
[
'flux_std_dev'
])
flux_std
=
np
.
array
(
flux_file
[
'flux_std_dev'
])
# Load k file for comparison
# Load k file for comparison
k_filename
=
os
.
path
.
join
(
path_to_results
,
'c5g7_3d_output.h5'
)
k_filename
=
os
.
path
.
join
(
path_to_results
,
'c5g7_3d_output.h5'
)
assert
os
.
path
.
isfile
(
k_filename
)
assert
os
.
path
.
isfile
(
k_filename
)
k_file
=
h5py
.
File
(
k_filename
,
'r'
)
k_file
=
h5py
.
File
(
k_filename
,
'r'
)
k_dset
=
k_file
[
'/keff/mean'
]
k_dset
=
k_file
[
'/keff/mean'
]
k_var_dset
=
k_file
[
'/keff/variance'
]
k_var_dset
=
k_file
[
'/keff/variance'
]
k
=
k_dset
[
0
]
k
=
k_dset
[
0
]
k_std
=
np
.
sqrt
(
k_var_dset
[
0
])
k_std
=
np
.
sqrt
(
k_var_dset
[
0
])
print
'New k = {0:.6f} +/- {1:.3e}'
.
format
(
k
,
k_std
)
print
(
'New k = {0:.6f} +/- {1:.3e}'
.
format
(
k
,
k_std
)
)
passes
=
True
passes
=
True
# Test to 4 standard deviations, should *almost* never fail
# Test to 4 standard deviations, should *almost* never fail
safety_factor
=
4
safety_factor
=
4
# Check k values
# Check k values
kdiff
=
np
.
abs
(
k
-
ref_k
)
kdiff
=
np
.
abs
(
k
-
ref_k
)
tol
=
safety_factor
*
np
.
sqrt
(
k_std
*
k_std
+
ref_k_std
*
ref_k_std
)
tol
=
safety_factor
*
np
.
sqrt
(
k_std
*
k_std
+
ref_k_std
*
ref_k_std
)
print
'Difference in k = {0:.2e} with tolerance of {1:.2e}'
.
format
(
kdiff
,
tol
)
print
(
'Difference in k = {0:.2e} with tolerance of {1:.2e}'
.
format
(
kdiff
,
tol
)
)
passes
=
kdiff
<
tol
passes
=
kdiff
<
tol
if
passes
:
if
passes
:
'Eigenvalue difference is acceptable'
'Eigenvalue difference is acceptable'
else
:
else
:
'Eigenvalue difference is outside expected tolerance'
'Eigenvalue difference is outside expected tolerance'
# Cycle-to-cycle correlations cause reported standard deviation to
# Cycle-to-cycle correlations cause reported standard deviation to
# be under-reported for tally values. Increase safety factor on flux
# be under-reported for tally values. Increase safety factor on flux
# checks to eliminate false positives.
# checks to eliminate false positives.
safety_factor
=
10
safety_factor
=
10
# Check flux
# Check flux
N
=
len
(
ref_flux
)
N
=
len
(
ref_flux
)
assert
N
==
len
(
ref_flux_std
)
assert
N
==
len
(
ref_flux_std
)
assert
N
==
len
(
flux
)
assert
N
==
len
(
flux
)
assert
N
==
len
(
flux_std
)
assert
N
==
len
(
flux_std
)
failed_indices
=
[]
failed_indices
=
[]
max_ratio
=
0.0
max_ratio
=
0.0
for
i
in
xrange
(
N
):
for
i
in
xrange
(
N
):
ref_val
=
ref_flux
[
i
]
ref_val
=
ref_flux
[
i
]
ref_std
=
ref_flux_std
[
i
]
ref_std
=
ref_flux_std
[
i
]
val
=
flux
[
i
]
val
=
flux
[
i
]
std
=
flux_std
[
i
]
std
=
flux_std
[
i
]
tol
=
safety_factor
*
np
.
sqrt
(
ref_std
*
ref_std
+
std
*
std
)
tol
=
safety_factor
*
np
.
sqrt
(
ref_std
*
ref_std
+
std
*
std
)
flux_diff
=
np
.
abs
(
val
-
ref_val
)
flux_diff
=
np
.
abs
(
val
-
ref_val
)
ratio
=
flux_diff
/
tol
ratio
=
flux_diff
/
tol
max_ratio
=
max
(
ratio
,
max_ratio
)
max_ratio
=
max
(
ratio
,
max_ratio
)
if
flux_diff
>
tol
:
if
flux_diff
>
tol
:
failed_indices
.
append
(
i
)
failed_indices
.
append
(
i
)
num_failed
=
len
(
failed_indices
)
num_failed
=
len
(
failed_indices
)
print
'
\n
Maximum relative error is {0:.3f} times tolerance'
.
format
(
max_ratio
)
print
(
'
\n
Maximum relative error is {0:.3f} times tolerance'
.
format
(
max_ratio
)
)
# Allow one outlier
# Allow one outlier
if
num_failed
>
1
:
if
num_failed
>
1
:
passes
=
False
passes
=
False
if
num_failed
>
0
:
if
num_failed
>
0
:
print
'
\n
The following flux values were outside of expected tolerance:'
print
(
'
\n
The following flux values were outside of expected tolerance:'
)
print
' Index Reference Value Difference Tolerance'
print
(
' Index Reference Value Difference Tolerance'
)
for
ind
in
failed_indices
:
for
ind
in
failed_indices
:
ref_val
=
ref_flux
[
ind
]
ref_val
=
ref_flux
[
ind
]
ref_std
=
ref_flux_std
[
ind
]
ref_std
=
ref_flux_std
[
ind
]
val
=
flux
[
ind
]
val
=
flux
[
ind
]
std
=
flux_std
[
ind
]
std
=
flux_std
[
ind
]
tol
=
safety_factor
*
np
.
sqrt
(
ref_std
*
ref_std
+
std
*
std
)
tol
=
safety_factor
*
np
.
sqrt
(
ref_std
*
ref_std
+
std
*
std
)
flux_diff
=
np
.
abs
(
val
-
ref_val
)
flux_diff
=
np
.
abs
(
val
-
ref_val
)
print
'{0:5} {1:.4e} {2:.4e} {3:.3e} {4:.3e}'
.
format
(
print
(
'{0:5} {1:.4e} {2:.4e} {3:.3e} {4:.3e}'
.
format
(
ind
,
ref_val
,
val
,
flux_diff
,
tol
)
ind
,
ref_val
,
val
,
flux_diff
,
tol
)
)
# Print pass/fail status
# Print pass/fail status
print
'
\n
'
,
print
(
'
\n
'
)
,
if
passes
:
if
passes
:
print
'Solution PASSED'
print
(
'Solution PASSED'
)
return
0
return
0
else
:
else
:
print
'Solution FAILED'
print
(
'Solution FAILED'
)
return
1
return
1
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment