Preparations

Quit[];

SetDirectory[NotebookDirectory[]];

Needs["ReactionKinetics1`"];//AbsoluteTiming

Hydrogen combustion mechanisms

SetDirectory[NotebookDirectory[]<>"hydrogen"];

ClearAll[hdat,hdata];
hdat=Flatten[Import["names_hydrogen.txt","Table"]];
hdata=StringReplace[#,".dat"->""]&/@hdat

indices=Range[19];

TableForm[hdata,TableHeadings->{indices,None}]

ClearAll[hall];
hall=CHEMKINImport[#]["chemkinreactions"]&/@hdat;//AbsoluteTiming

ClearAll[hevery];
hevery=Transpose[{hall,DeleteAutocatalysis/@hall,hdata}];//AbsoluteTiming

TableForm[ReactionsData[#,ExternalSpecies->{"HV"}]["M","R","deficiency"]&/@hevery[[indices,2]],TableHeadings->{hevery[[indices,3]],{"M","R","deficiency"}}]

TableForm[ReactionsData[#,ExternalSpecies->"HV"]["species"]&/@hevery[[indices,2]],TableHeadings->{hevery[[indices,3]],{"list"," of ","species\n"}}]

TableForm[Table[hevery[[i,2]]/.x_Equilibrium->Sequence[],{i,19}],TableHeadings->{hevery[[indices,3]],None}]

hevery[[3,2]]/.x_Equilibrium->Sequence[]

Row[{ShowFHJGraph[#[[2]],DirectedEdges->True,VertexLabeling->All,PlotLabel->#[[3]],ImageSize->420],"   ",Column[Join[{"3rd body species deleted"},#[[2]]]],"   ",Column[Join[{"Orig. Mechanism"},#[[1]]]]}]&/@hevery[[indices]]//Timing

maxfhjcomponents=MaxFHJWeaklyConnectedComponents[hevery[[#,2]]]&/@indices;

maxfhjedges=Flatten[(First/@#)&/@maxfhjcomponents,1];

GraphPlot[First[#],VertexLabeling->True,DirectedEdges->True,ImageSize->350,PlotLabel->"Max weakly connected component of mech "<>ToString[hevery[[Last[#],3]]]<>"\n"]&/@Transpose[{maxfhjedges,indices}]

TableForm[tt=Table[TrueQ[(hevery[[i,2]]/."HV"->0)==(hevery[[j,2]]/."HV"->0)]/.{True->Style["TRUE",Bold]},{i,19},{j,19}],TableHeadings->{hdata,hdata}]

TableForm[Table[TrueQ[(hevery[[i,2]]/."HV"->0)==(hevery[[j,2]]/."HV"->0)]/.{True->Style["T",Bold,Red],False->Style["F",Bold,Blue]},{i,19},{j,19}],TableHeadings->{indices,indices}]

ag=(tt/.{Style["TRUE",Bold]->1,False->0})-IdentityMatrix[19];

AdjacencyGraph[ag,ImageSize->550,ImagePadding->60,VertexLabels->Thread[Rule[indices,Style[#,Bold,12]&/@hevery[[indices,3]]]]]

wc=ConnectedComponents[AdjacencyGraph[ag]]/.Thread[Rule[indices,hevery[[indices,3]]]];

TableForm[wc,TableHeadings->{Range[8],None}]

reducedindices=Sort[First/@ConnectedComponents[AdjacencyGraph[ag]]]

Column[Riffle[Row/@(Join[{Style[hevery[[#,3]],Bold,14],"\t"},VolpertIndexing[hevery[[#,2]],{"H2","O2"},Verbose->True,ExternalSpecies->{"HV"}]]&/@reducedindices),"\n\n"],2]

ShowVolpertGraph[hevery[[12,2]],PlotFunction->"LayeredGraphPlot",DirectedEdges->True,VertexLabeling->True,ImageSize->900,PlotLabel->Style["Volpert graph of "<>hevery[[12,3]],15,Bold,Black],EdgeLabeling->True,Numbered->True,Indexed->{"H2","O2"},MultiedgeStyle->True,PlotRangeClipping->True]

ShowVolpertGraph[hevery[[19,2]],MultiedgeStyle->True,DirectedEdges->True,VertexLabeling->True,PlotLabel->Style["Volpert graph of "<>hevery[[19,3]],15,Bold,Black],ImageSize->600]

ReversibleQ/@hevery[[reducedindices,2]]

db=Sort[DetailedBalanced[#],Total[Length/@(#1/.Equal->List)]<Total[Length/@(#2/.Equal->List)]&]&/@hevery[[Delete[reducedindices,3],2]]

TableForm[db,TableHeadings->{hevery[[Delete[reducedindices,3],3]]}]

TableForm[Table[Complement[ReactionsData[hevery[[i,2]],ExternalSpecies->"HV"]["fhjgraph"],ReactionsData[hevery[[j,2]],ExternalSpecies->"HV"]["fhjgraph"]],{i,reducedindices},{j,reducedindices}],TableHeadings->{hevery[[reducedindices,3]],hevery[[reducedindices,3]]}]

TableForm[Table[Length@Complement[ReactionsData[hevery[[i,2]],ExternalSpecies->"HV"]["fhjgraph"],ReactionsData[hevery[[j,2]],ExternalSpecies->"HV"]["fhjgraph"]],{i,reducedindices},{j,reducedindices}],TableHeadings->{hevery[[reducedindices,3]],hevery[[reducedindices,3]]}]

Carbon monoxide combustion mechanisms

SetDirectory[NotebookDirectory[]<>"CO"];

ClearAll[codat,codata];
codat=Flatten[Import["names_CO.txt","Table"]];
codata=StringReplace[#,".dat"->""]&/@codat

indices=Range[15];

TableForm[codata,TableHeadings->{indices,None}]

ClearAll[coall];
coall=CHEMKINImport[#]["chemkinreactions"]&/@codat;//AbsoluteTiming

ClearAll[coevery];
coevery=Transpose[{coall,DeleteAutocatalysis/@coall,codata}];//AbsoluteTiming

TableForm[ReactionsData[#,ExternalSpecies->"HV"]["M","R","deficiency"]&/@coevery[[indices,2]],TableHeadings->{coevery[[indices,3]],{"M","R","deficiency"}}]

TableForm[ReactionsData[#,ExternalSpecies->{"HV"}]["species"]&/@coevery[[indices,2]],TableHeadings->{coevery[[indices,3]],{"list"," of ","species\n"}}]

TableForm[Table[coevery[[i,2]]/.x_Equilibrium->Sequence[],{i,15}],TableHeadings->{coevery[[indices,3]],None}]

coevery[[2,2]]/.x_Equilibrium->Sequence[]

coevery[[6,2]]/.x_Equilibrium->Sequence[]

Row[{ShowFHJGraph[#[[2]],DirectedEdges->True,VertexLabeling->All,PlotLabel->#[[3]],ImageSize->420],"   ",Column[Join[{"3rd body species deleted"},#[[2]]]],"   ",Column[Join[{"Orig. Mechanism"},#[[1]]]]}]&/@coevery[[indices]]//Timing

maxfhjcomponents=MaxFHJWeaklyConnectedComponents[coevery[[#,2]]]&/@indices;

maxfhjedges=Flatten[(First/@#)&/@maxfhjcomponents,1];

GraphPlot[First[#],VertexLabeling->True,DirectedEdges->True,ImageSize->350,PlotLabel->"Max weakly connected component of mech "<>ToString[coevery[[Last[#],3]]]<>"\n"]&/@Transpose[{maxfhjedges,indices}]

TableForm[tt=Table[TrueQ[(coevery[[i,2]]/."HV"->0)==(coevery[[j,2]]/."HV"->0)]/.{True->Style["TRUE",Bold]},{i,15},{j,15}],TableHeadings->{codata,codata}]

TableForm[Table[TrueQ[(coevery[[i,2]]/."HV"->0)==(coevery[[j,2]]/."HV"->0)]/.{True->Style["T",Bold,Red],False->Style["F",Bold,Blue]},{i,15},{j,15}],TableHeadings->{indices,indices}]

ag=(tt/.{Style["TRUE",Bold]->1,False->0})-IdentityMatrix[15];

AdjacencyGraph[ag,ImageSize->1000,ImagePadding->50,VertexLabels->Thread[Rule[indices,Style[#,Bold,12]&/@coevery[[indices,3]]]]]

wc=ConnectedComponents[AdjacencyGraph[ag]]/.Thread[Rule[indices,coevery[[indices,3]]]];

TableForm[wc,TableHeadings->{Range[13],None}]

reducedindices=Sort[First/@ConnectedComponents[AdjacencyGraph[ag]]]

Column[Riffle[Row/@(Join[{Style[coevery[[#,3]],Bold,14],"\t"},VolpertIndexing[coevery[[#,2]],{"H2","O2","CO"},Verbose->True,ExternalSpecies->{"HV"}]]&/@reducedindices),"\n\n"],2]

ShowVolpertGraph[coevery[[15,2]],PlotFunction->"LayeredGraphPlot",DirectedEdges->True,VertexLabeling->True,ImageSize->900,PlotLabel->Style["Volpert graph of "<>coevery[[15,3]],15,Bold,Black],EdgeLabeling->True,Numbered->True,Indexed->{"H2","O2","CO"},MultiedgeStyle->True,PlotRangeClipping->True]

ShowVolpertGraph[coevery[[8,2]],MultiedgeStyle->True,DirectedEdges->True,VertexLabeling->True,PlotLabel->Style["Volpert graph of "<>coevery[[2,3]],15,Bold,Black],ImageSize->600]

ReversibleQ/@coevery[[reducedindices,2]]

db=Sort[DetailedBalanced[#],Total[Length/@(#1/.Equal->List)]<Total[Length/@(#2/.Equal->List)]&]&/@coevery[[Delete[reducedindices,{{2},{6}}],2]]

TableForm[db,TableHeadings->{coevery[[Delete[reducedindices,{{2},{6}}],3]]}]

TableForm[Table[Complement[ReactionsData[coevery[[i,2]],ExternalSpecies->"HV"]["fhjgraph"],ReactionsData[coevery[[j,2]],ExternalSpecies->"HV"]["fhjgraph"]],{i,reducedindices},{j,reducedindices}],TableHeadings->{coevery[[reducedindices,3]],coevery[[reducedindices,3]]}]

TableForm[Table[Length@Complement[ReactionsData[coevery[[i,2]],ExternalSpecies->{"HV"}]["fhjgraph"],ReactionsData[coevery[[j,2]],ExternalSpecies->"HV"]["fhjgraph"]],{i,reducedindices},{j,reducedindices}],TableHeadings->{coevery[[reducedindices,3]],coevery[[reducedindices,3]]}]

Methanol combustion mechanisms

SetDirectory[NotebookDirectory[]<>"methanol"];

ClearAll[mdata];
mdat=Flatten[Import["names_methanol.txt","Table"]];
mdata=StringReplace[#,".dat"->""]&/@mdat

indices=Range[5];

TableForm[mdata,TableHeadings->{indices,None}]

ClearAll[mall];
mall=CHEMKINImport[#]["chemkinreactions"]&/@mdat;//AbsoluteTiming

ClearAll[mevery];
mevery=Transpose[{mall,DeleteAutocatalysis/@mall,mdata}];//AbsoluteTiming

TableForm[ReactionsData[#]["M","R","deficiency"]&/@mevery[[indices,2]],TableHeadings->{mevery[[indices,3]],{"M","R","deficiency"}}]

TableForm[ReactionsData[#]["species"]&/@mevery[[indices,2]],TableHeadings->{mevery[[indices,3]],{"list"," of ","species\n"}}]

TableForm[Table[mevery[[i,2]]/.x_Equilibrium->Sequence[],{i,5}],TableHeadings->{mevery[[indices,3]],None}]

mevery[[1,2]]/.x_Equilibrium->Sequence[]

mevery[[-2,2]]/.x_Equilibrium->Sequence[]

Row[{ShowFHJGraph[#[[2]],DirectedEdges->True,VertexLabeling->All,PlotLabel->#[[3]],ImageSize->420],"   ",Column[Join[{"3rd body species deleted"},#[[2]]]],"   ",Column[Join[{"Orig. Mechanism"},#[[1]]]]}]&/@mevery[[indices]]//Timing

maxfhjcomponents=MaxFHJWeaklyConnectedComponents[mevery[[#,2]]]&/@indices;//AbsoluteTiming

maxfhjedges=Flatten[First/@#]&/@maxfhjcomponents;

GraphPlot[First[#],VertexLabeling->True,DirectedEdges->True,ImageSize->700,PlotLabel->"Max weakly connected component of mech "<>ToString[mevery[[Last[#],3]]]<>"\n"]&/@Transpose[{maxfhjedges,indices}]

TableForm[tt=Table[TrueQ[mevery[[i,2]]==mevery[[j,2]]]/.{True->Style["TRUE",Bold]},{i,5},{j,5}],TableHeadings->{mdata,mdata}]

ag=(tt/.{Style["TRUE",Bold]->1,False->0})-IdentityMatrix[5];

AdjacencyGraph[ag,ImageSize->550,ImagePadding->60,VertexLabels->Thread[Rule[indices,Style[#,Bold,12]&/@mevery[[indices,3]]]]]

reducedindices=Sort[First/@ConnectedComponents[AdjacencyGraph[ag]]]

Column[Riffle[Row/@(Join[{Style[mevery[[#,3]],Bold,14],"\t"},VolpertIndexing[mevery[[#,2]],{"CH2O"},Verbose->True]]&/@reducedindices),"\n\n"],2]

Column[Riffle[Row/@(Join[{Style[mevery[[#,3]],Bold,14],"\t"},VolpertIndexing[mevery[[#,2]],{"CH3OH","O2","N2"},Verbose->True]]&/@reducedindices),"\n\n"],2]

ShowVolpertGraph[mevery[[3,2]],PlotFunction->"LayeredGraphPlot",DirectedEdges->True,VertexLabeling->True,ImageSize->1000,PlotLabel->Style["Volpert graph of "<>mevery[[3,3]],15,Bold,Black],EdgeLabeling->True,Numbered->True,Indexed->{"CH3OH","O2","N2"},MultiedgeStyle->True,PlotRangeClipping->True]

ReversibleQ/@mevery[[reducedindices,2]]

db=Sort[DetailedBalanced[#],Total[Length/@(#1/.Equal->List)]<Total[Length/@(#2/.Equal->List)]&]&/@mevery[[Delete[reducedindices,{{1},{4}}],2]];//AbsoluteTiming

TableForm[db,TableHeadings->{mevery[[Delete[reducedindices,{{1},{4}}],3]]}]

TableForm[Table[Complement[ReactionsData[mevery[[i,2]]]["fhjgraph"],ReactionsData[mevery[[j,2]]]["fhjgraph"]],{i,reducedindices},{j,reducedindices}],TableHeadings->{mevery[[reducedindices,3]],mevery[[reducedindices,3]]}]

TableForm[Table[Length@Complement[ReactionsData[mevery[[i,2]]]["fhjgraph"],ReactionsData[mevery[[j,2]]]["fhjgraph"]],{i,reducedindices},{j,reducedindices}],TableHeadings->{mevery[[reducedindices,3]],mevery[[reducedindices,3]]}]