Skip to content

Commit d615ba1

Browse files
committed
Updates to allow error handling for failed mcnp runs without killing program.
1 parent 5b1fe5e commit d615ba1

8 files changed

Lines changed: 144 additions & 44 deletions

Code/Coeus_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
import sys
4040
sys.path.insert(0,os.path.abspath(os.getcwd())+'/Sampling')
4141

42+
#-------------------------------------------------------------------------------------------------------------#
4243

4344
def main(**kwargs):
4445

45-
#-------------------------------------------------------------------------------------------------------------#
4646
### Local Function definitions
4747

4848
# Print MCNP input Files

Code/Gnowee_Utilities.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -601,27 +601,33 @@ def Calc_Fitness(ids, pop, obj, min_fiss=0, max_w=1000):
601601
rundir=os.path.abspath(os.path.join(os.path.abspath(os.getcwd()),os.pardir))+"/Results/Population/"
602602

603603
for i in ids:
604+
tmp_fit=1E15
604605
index = next((c for c, parent in enumerate(pop) if parent.ident == i), -1)
605606
(tally,fissions,weight)=Read_MCNP_Output(rundir+str(i)+'/tmp/ETA.out', '24', '14')
606-
tally=to_NormDiff(tally)
607-
tmp_fit=RelativeLeastSquares(tally,obj)
608-
module_logger.debug("Parent ID # {} has fitness = {} from RLS".format(i,tmp_fit))
609-
610-
# Check constraints
611-
weight=weight/1000 # conversion to kg
612-
if fissions[0] == 0.0 and fissions[0] < min_fiss:
613-
module_logger.warning("WARNING: No fissions occured for the ETA design in parent #{}".format(i))
614-
tmp_fit+=1E15
615-
elif fissions[0] > 0 and fissions[0] < min_fiss:
616-
tmp_fit+= 0.1*(min_fiss/fissions[0]-1)
617-
elif fissions[0] > min_fiss:
618-
tmp_fit-= 0.01*(fissions[0]/min_fiss-1)
619-
module_logger.debug("fissions[0] = {} and min_fiss = {} ".format(fissions[0],min_fiss))
620-
module_logger.debug("Parent ID # {} has fitness = {} from RLS+fissions".format(i,tmp_fit))
607+
try:
608+
tally=to_NormDiff(tally)
609+
tmp_fit=RelativeLeastSquares(tally,obj)
610+
module_logger.debug("Parent ID # {} has fitness = {} from RLS".format(i,tmp_fit))
611+
612+
# Check constraints
613+
weight=weight/1000 # conversion to kg
614+
if fissions[0] == 0.0 and fissions[0] < min_fiss:
615+
module_logger.warning("WARNING: No fissions occured for the ETA design in parent #{}".format(i))
616+
tmp_fit+=1E15
617+
elif fissions[0] > 0 and fissions[0] < min_fiss:
618+
tmp_fit+= 0.1*(min_fiss/fissions[0]-1)
619+
elif fissions[0] > min_fiss:
620+
tmp_fit-= 0.01*(fissions[0]/min_fiss-1)
621+
module_logger.debug("fissions[0] = {} and min_fiss = {} ".format(fissions[0],min_fiss))
622+
module_logger.debug("Parent ID # {} has fitness = {} from RLS+fissions".format(i,tmp_fit))
623+
624+
if weight > max_w:
625+
tmp_fit+=1E15
626+
module_logger.info("Parent ID # {} has fitness = {} from RLS+fissions+weight".format(i,tmp_fit))
621627

622-
if weight > max_w:
623-
tmp_fit+=1E15
624-
module_logger.info("Parent ID # {} has fitness = {} from RLS+fissions+weight".format(i,tmp_fit))
628+
except:
629+
module_logger.info("WARNING: Parent ID # {} MCNP run failed.".format(i,tmp_fit))
630+
pass
625631

626632
# Save fitness
627633
pop[index].fit=tmp_fit

Code/MCNP_Utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ def Print_MCNP_Input(eta,geom,settings,mats,num,adv_print=True):
980980
inp_file.write("c Physics \n")
981981
inp_file.write("{}".format(settings.phys))
982982
inp_file.write("NPS {}\n".format(settings.nps))
983-
inp_file.write("RAND GEN=2 STRIDE=1529171\n".format(settings.nps))
983+
inp_file.write("RAND GEN=2 STRIDE=1529\n".format(settings.nps))
984984

985985
# Print Material Cards
986986
inp_file.write("c ****************************************************************************\n")

Code/Utilities.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def Run_Transport(lst,nps=[],code='mcnp6'):
509509
path=os.path.abspath(os.path.join(os.path.abspath(os.getcwd()), os.pardir))+"/Results/Population/"+str(i)+"/"
510510
sub.Popen("cp {} {}".format(path+"tmp/output/wwinp",path+"wwinp"),cwd=path,stdout=sub.PIPE,shell=True)
511511
sub.Popen("cp {} {}".format(path+"tmp/output/inp_edits.txt",path+"inp_edits.txt"), cwd=path,stdout=sub.PIPE,shell=True)
512-
sub.Popen("rm -rf {}tmp/*".format(path,i),cwd=path,stdout=sub.PIPE,shell=True)
512+
sub.Popen("rm -rf {}tmp/*".format(path,i),cwd=path,stderr=sub.STDOUT,stdout=sub.PIPE,shell=True)
513513

514514
module_logger.info('Total transport time was {} sec'.format(time.time() - start_time))
515515

@@ -611,6 +611,30 @@ def Build_Batch(lst,tasks,code,suf=""):
611611

612612
return fname
613613

614+
#-------------------------------------------------------------------------------------------------------------#
615+
def to_Norm(spectrum):
616+
"""
617+
Normalizes a MCNP tallied flux
618+
619+
Parameters
620+
==========
621+
spectrum : array
622+
The input flux spectrum
623+
624+
Optional
625+
========
626+
627+
Returns
628+
=======
629+
result : array
630+
The output normalized differential flux spectrum
631+
"""
632+
633+
flux=np.zeros(len(spectrum[:,0]))
634+
result=flux/np.sum(flux)
635+
636+
return result
637+
614638
#-------------------------------------------------------------------------------------------------------------#
615639
def to_NormDiff(spectrum):
616640
"""
@@ -639,25 +663,12 @@ def to_NormDiff(spectrum):
639663
# Calculate the differential flux
640664
diff[0]=(spectrum[0,1])/(spectrum[0,0])
641665
for i in range(1,len(spectrum[:,0])):
642-
diff[i]=(spectrum[i,1]+spectrum[i-1,1])/(spectrum[i,0]-spectrum[i-1,0])
643-
644-
# Calculate the integral of the differential flux using simpson's method
645-
intdiff[0]=0.5*spectrum[0,0]*diff[0]
646-
for i in range(1,len(spectrum[:,0])):
647-
intdiff[i]=0.5*(spectrum[i,0]-spectrum[i-1,0])*(diff[i]+diff[i-1])
666+
diff[i]=(spectrum[i,1])/(spectrum[i,0]-spectrum[i-1,0])
648667

649668
# Calculate the normalized differential flux
650-
integral=np.sum(intdiff)
651-
for i in range(0,len(spectrum[:,0])):
652-
normdiff[i]=diff[i]/integral
653-
654-
# Calculate the integral of the normalized differential flux using simpson's method
655-
result[0]=0.5*spectrum[0,0]*normdiff[0]
656-
for i in range(1,len(spectrum[:,0])):
657-
result[i]=0.5*(spectrum[i,0]-spectrum[i-1,0])*(normdiff[i]+normdiff[i-1])
669+
result=diff/np.sum(diff)
658670

659671
return result
660-
661672

662673
#-------------------------------------------------------------------------------------------------------------#
663674
def Uopt(c,d):
@@ -688,7 +699,7 @@ def Uopt(c,d):
688699
#-------------------------------------------------------------------------------------------------------------#
689700
def LeastSquares(c,d):
690701
"""
691-
Calculate the U-optimality
702+
Calculate the LeastSquares fit between two arrays
692703
693704
Parameters
694705
==========
@@ -706,7 +717,7 @@ def LeastSquares(c,d):
706717
The least-squares design based fitness
707718
"""
708719

709-
assert len(c)==len(d), "The length of the candidate and objective design must be equal in Uopt."
720+
assert len(c)==len(d), "The length of the candidate and objective design must be equal in LeastSquares."
710721

711722
return np.sum((d-c)**2)
712723

Code/WorkingTemp.ipynb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,50 @@
280280
" "
281281
]
282282
},
283+
{
284+
"cell_type": "code",
285+
"execution_count": 9,
286+
"metadata": {
287+
"collapsed": false
288+
},
289+
"outputs": [
290+
{
291+
"name": "stdout",
292+
"output_type": "stream",
293+
"text": [
294+
"2.2960312514\n"
295+
]
296+
}
297+
],
298+
"source": [
299+
"import numpy as np\n",
300+
"tally=np.array([7.25982E-07,5.20184E-08,5.79922E-08,8.65185E-08,7.74178E-08,1.00518E-07,9.05579E-08, 6.84944E-08,7.68031E-08,1.19829E-07,1.37603E-07,1.34688E-07,7.17418E-08,1.55737E-07,1.02621E-07, 5.98951E-07,4.16204E-07,4.80461E-07,7.74921E-07,6.96426E-07,3.03626E-07,2.48423E-07,1.16472E-07,2.03025E-07,1.80390E-07,2.21293E-07,1.77128E-07,1.26854E-07,1.68121E-08,8.70282E-08,7.81311E-08,3.20860E-08 ,9.61892E-09,4.57282E-08,2.56482E-08,1.65637E-08,1.85974E-08,1.84712E-08,2.07756E-08,2.32107E-08,7.91602E-09,7.37025E-08,8.14818E-08,2.89143E-09,6.85995E-11, 9.35566E-12])\n",
301+
"obj=np.array([4.066918E-13,2.825704E-11,7.962365E-10,7.373641E-09,2.404237E-08,1.185623E-07,4.099819E-07,1.204311E-06,4.002197E-06,2.135014E-05,1.563630E-04,6.279676E-04,5.722449E-04,2.080694E-03,2.725402E-03,1.179853E-02,1.589037E-02,3.674752E-02,4.712247E-02,7.091333E-02,4.365288E-02,4.831482E-02,2.674840E-02,4.052126E-02,3.298227E-02,6.017881E-02,5.755246E-02,6.032581E-02,1.847843E-02,1.261844E-01,4.444340E-02,2.998172E-02,1.113570E-02,3.622714E-02,9.127742E-03,5.905254E-03,3.046808E-03,1.812024E-03,1.438887E-03,1.387365E-03,6.852790E-04,6.874538E-03,1.843700E-02,5.523352E-02,6.085823E-02,9.803895E-03])\n",
302+
"\n",
303+
"import Utilities as util\n",
304+
"tmp_fit=util.RelativeLeastSquares(tally,obj)\n",
305+
"\n",
306+
"weight=1.687E6\n",
307+
"fissions=[0,0]\n",
308+
"\n",
309+
"min_fiss=0\n",
310+
"max_w=5000\n",
311+
"\n",
312+
"# Check constraints\n",
313+
"weight=weight/1000 # conversion to kg\n",
314+
"if fissions[0] == 0.0 and fissions[0] < min_fiss:\n",
315+
" tmp_fit+=1E15\n",
316+
"elif fissions[0] > 0 and fissions[0] < min_fiss:\n",
317+
" tmp_fit+= 0.1*(min_fiss/fissions[0]-1)\n",
318+
"elif fissions[0] > min_fiss:\n",
319+
" tmp_fit-= 0.01*(fissions[0]/min_fiss-1)\n",
320+
"\n",
321+
"if weight > max_w:\n",
322+
" tmp_fit+=1E15\n",
323+
" \n",
324+
"print tmp_fit"
325+
]
326+
},
283327
{
284328
"cell_type": "code",
285329
"execution_count": null,

Inputs/eta_constraints_BNCT.csv

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Minimum Fissions,0.0
2+
ETA Max Weight, 5000
3+
Source Strength,1.5E15
4+
/
5+
TCC to ETA Distance, 6.0
6+
Debris Shield Thickness,1e-5
7+
ETA Wall Thickness,10
8+
Snout Distance, 71
9+
ETA Back Cover Thickness, 10
10+
ETA to Snout Mount Thickness,1e-5
11+
ETA Face Radius, 49
12+
ETA Cone Outer Radius, 50
13+
ETA Cone Opening Angle, 5.71
14+
/
15+
Debris Shield Material,Stainless Steel 409
16+
ETA Structural Material,Aluminum alloy 6061-O
17+
ETA Void Fill Material,Vacuum
18+
Fissile Foil,HEU
19+
/
20+
NAS Thickness, 1e-5
21+
NAS Radius, 1e-5
22+
NAS Material,Aluminum alloy 6061-O
23+
/
24+
NAS Activation Foils, Zr, Ni, In, Al, Ta
25+
NAS Activation Foil Thickness,1e-5, 1e-5, 1e-5, 1e-5, 1e-5
26+
NAS Activation Foil Radius, 1e-5
27+
TOAD Follows Material, In
28+
/
29+
TOAD Material,Aluminum alloy 6061-O
30+
TOAD Activation Foils,Al,Au,Al,HEU,Al
31+
TOAD Activation Foil Thickness,1e-5,1e-5,1e-5,1e-5,1e-5
32+
TOAD Activation Foil Radius,1e-5
33+
/
34+
Holder Material,Aluminum alloy 6061-O
35+
Holder Fill Material, Pb
36+
Holder Wall Thickness,1e-5
37+
/
38+
Max Vertical Components,3
39+
Max Horizontal Components,7

Inputs/mcnp_settings.csv

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Physics:
2-
MODE n
3-
/
4-
NPS:
5-
1E6
6-
/
1+
Physics:
2+
MODE n
3+
/
4+
NPS:
5+
1E6
6+
/

Proposed Workflow.pptx

-2.59 KB
Binary file not shown.

0 commit comments

Comments
 (0)