Skip to content
This repository was archived by the owner on Jun 7, 2024. It is now read-only.

Commit 99cda1c

Browse files
committed
Bug fix: NullPointerException for input files without seed mechanisms
This commit fixes the NPE that GRM found. The problem was that MRH assumed there would always be a seedMechanism instance, and therefore always a reactionSet() to extract and send to the ODESolver and CHEMKIN classes. Thanks Greg for finding this.
1 parent 62d1a55 commit 99cda1c

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

source/RMG/jing/rxnSys/ReactionModelGenerator.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,8 +1381,9 @@ public void modelGeneration() {
13811381
ReactionSystem rs = (ReactionSystem)reactionSystemList.get(i);
13821382
ReactionTime begin = (ReactionTime)beginList.get(i);
13831383
ReactionTime end = (ReactionTime)endList.get(i);
1384-
endList.set(i,rs.solveReactionSystem(begin, end, true, true, true, iterationNumber-1,seedMechanism.getReactionSet()));
1385-
Chemkin.writeChemkinInputFile(rs, seedMechanism.getReactionSet());
1384+
LinkedHashSet seedmechnonpdeprxns = extractSeedMechRxnsIfTheyExist();
1385+
endList.set(i,rs.solveReactionSystem(begin, end, true, true, true, iterationNumber-1,seedmechnonpdeprxns));
1386+
Chemkin.writeChemkinInputFile(rs, seedmechnonpdeprxns);
13861387
boolean terminated = rs.isReactionTerminated();
13871388
terminatedList.add(terminated);
13881389
if(!terminated)
@@ -1512,7 +1513,8 @@ public void modelGeneration() {
15121513
boolean conditionChanged = (Boolean)conditionChangedList.get(i);
15131514
ReactionTime begin = (ReactionTime)beginList.get(i);
15141515
ReactionTime end = (ReactionTime)endList.get(i);
1515-
endList.set(i,rs.solveReactionSystem(begin, end, false, reactionChanged, conditionChanged, iterationNumber-1,seedMechanism.getReactionSet()));
1516+
LinkedHashSet seedmechnonpdeprxns = extractSeedMechRxnsIfTheyExist();
1517+
endList.set(i,rs.solveReactionSystem(begin, end, false, reactionChanged, conditionChanged, iterationNumber-1,seedmechnonpdeprxns));
15161518
//end = reactionSystem.solveReactionSystem(begin, end, false, reactionChanged, conditionChanged, iterationNumber-1);
15171519
}
15181520
solverMin = solverMin + (System.currentTimeMillis()-startTime)/1000/60;
@@ -1522,7 +1524,8 @@ public void modelGeneration() {
15221524
// we over-write the chemkin file each time, so only the LAST reaction system is saved
15231525
// i.e. if you are using RATE for pdep, only the LAST pressure is used.
15241526
ReactionSystem rs = (ReactionSystem)reactionSystemList.get(i);
1525-
Chemkin.writeChemkinInputFile(rs,seedMechanism.getReactionSet());
1527+
LinkedHashSet seedmechnonpdeprxns = extractSeedMechRxnsIfTheyExist();
1528+
Chemkin.writeChemkinInputFile(rs,seedmechnonpdeprxns);
15261529
}
15271530
//9/1/09 gmagoon: if we are using QM, output a file with the CHEMKIN name, the RMG name, the (modified) InChI, and the (modified) InChIKey
15281531
if (ChemGraph.useQM){
@@ -1643,7 +1646,8 @@ public void modelGeneration() {
16431646
boolean conditionChanged = (Boolean)conditionChangedList.get(i);
16441647
ReactionTime begin = (ReactionTime)beginList.get(i);
16451648
ReactionTime end = (ReactionTime)endList.get(i);
1646-
endList.set(i,rs.solveReactionSystem(begin, end, false, reactionChanged, false, iterationNumber-1,seedMechanism.getReactionSet()));
1649+
LinkedHashSet seedmechnonpdeprxns = extractSeedMechRxnsIfTheyExist();
1650+
endList.set(i,rs.solveReactionSystem(begin, end, false, reactionChanged, false, iterationNumber-1,seedmechnonpdeprxns));
16471651
// end = reactionSystem.solveReactionSystem(begin, end, false, reactionChanged, false, iterationNumber-1);
16481652
}
16491653
solverMin = solverMin + (System.currentTimeMillis()-startTime)/1000/60;
@@ -1755,7 +1759,8 @@ public void modelGeneration() {
17551759
//terminated = false;
17561760
ReactionTime begin = (ReactionTime)beginList.get(i);
17571761
ReactionTime end = (ReactionTime)endList.get(i);
1758-
rs.solveReactionSystemwithSEN(begin, end, true, false, false, seedMechanism.getReactionSet());
1762+
LinkedHashSet seedmechnonpdeprxns = extractSeedMechRxnsIfTheyExist();
1763+
rs.solveReactionSystemwithSEN(begin, end, true, false, false, seedmechnonpdeprxns);
17591764
//reactionSystem.solveReactionSystemwithSEN(begin, end, true, false, false);
17601765
}
17611766

@@ -1764,7 +1769,8 @@ public void modelGeneration() {
17641769
// All of the reaction systems are the same, so just write the chemkin
17651770
// file for the first reaction system
17661771
ReactionSystem rs = (ReactionSystem)reactionSystemList.get(0);
1767-
Chemkin.writeChemkinInputFile(getReactionModel(),rs.getPresentStatus(),seedMechanism.getReactionSet());
1772+
LinkedHashSet seedmechnonpdeprxns = extractSeedMechRxnsIfTheyExist();
1773+
Chemkin.writeChemkinInputFile(getReactionModel(),rs.getPresentStatus(),seedmechnonpdeprxns);
17681774

17691775
//9/1/09 gmagoon: if we are using QM, output a file with the CHEMKIN name, the RMG name, the (modified) InChI, and the (modified) InChIKey
17701776
if (ChemGraph.useQM){
@@ -5209,6 +5215,12 @@ public boolean areTheNumberOfConcentrationsConsistent(int number) {
52095215
}
52105216
return true;
52115217
}
5218+
5219+
public LinkedHashSet extractSeedMechRxnsIfTheyExist() {
5220+
LinkedHashSet seedmechnonpdeprxns = new LinkedHashSet();
5221+
if (seedMechanism != null) seedmechnonpdeprxns = seedMechanism.getReactionSet();
5222+
return seedmechnonpdeprxns;
5223+
}
52125224
}
52135225
/*********************************************************************
52145226
File Path : RMG\RMG\jing\rxnSys\ReactionModelGenerator.java

0 commit comments

Comments
 (0)