11from . import _moose as moose
22
3+
34def moosedeleteChemSolver (modelRoot ):
4- """
5- Delete solvers from Chemical Compartment
6- """
7- compts = moose .wildcardFind (modelRoot + '/##[ISA=ChemCompt]' )
8- for compt in compts :
9- if moose .exists (compt .path + '/stoich' ):
10- st = moose .element (compt .path + '/stoich' )
11- st_ksolve = st .ksolve
12- moose .delete (st )
13- if moose .exists ((st_ksolve ).path ):
14- moose .delete (st_ksolve )
15- print "Solver is deleted for modelpath " ,modelRoot
16-
17- def mooseaddChemSolver (modelRoot ,solver ):
18- """
19- Add the solvers to Chemical compartment
20- """
21- compt = moose .wildcardFind (modelRoot + '/##[ISA=ChemCompt]' )
22- if compt :
23- comptinfo = moose .Annotator (moose .element (compt [0 ]).path + '/info' )
24- previousSolver = comptinfo .solver
25- currentSolver = previousSolver
26- if solver == "Gillespie" :
27- currentSolver = "gssa"
28- elif solver == "Runge Kutta" :
29- currentSolver = "gsl"
30- elif solver == "Exponential Euler" :
31- currentSolver = "ee"
5+ """
6+ Delete solvers from Chemical Compartment
7+ """
8+ compts = moose .wildcardFind (modelRoot + '/##[ISA=ChemCompt]' )
9+ for compt in compts :
10+ if moose .exists (compt .path + '/stoich' ):
11+ st = moose .element (compt .path + '/stoich' )
12+ st_ksolve = st .ksolve
13+ moose .delete (st )
14+ if moose .exists ((st_ksolve ).path ):
15+ moose .delete (st_ksolve )
16+ print ("Solver is deleted for modelpath " , modelRoot )
17+
18+
19+ def mooseaddChemSolver (modelRoot , solver ):
20+ """
21+ Add the solvers to Chemical compartment
22+ """
23+ compt = moose .wildcardFind (modelRoot + '/##[ISA=ChemCompt]' )
24+ if compt :
25+ comptinfo = moose .Annotator (moose .element (compt [0 ]).path + '/info' )
26+ previousSolver = comptinfo .solver
27+ currentSolver = previousSolver
28+ if solver == "Gillespie" :
29+ currentSolver = "gssa"
30+ elif solver == "Runge Kutta" :
31+ currentSolver = "gsl"
32+ elif solver == "Exponential Euler" :
33+ currentSolver = "ee"
34+
35+ if previousSolver != currentSolver :
36+ # if previousSolver != currentSolver
37+ comptinfo .solver = currentSolver
38+ if (moose .exists (compt [0 ].path + '/stoich' )):
39+ # "A: and stoich exists then delete the stoich add solver"
40+ deleteSolver (modelRoot )
41+ setCompartmentSolver (modelRoot , currentSolver )
42+ return True
43+ else :
44+ # " B: stoich doesn't exists then addSolver, this is when object is deleted which delete's the solver "
45+ # " and solver is also changed, then add addsolver "
46+ setCompartmentSolver (modelRoot , currentSolver )
47+ return True
48+ else :
49+ if moose .exists (compt [0 ].path + '/stoich' ):
50+ # " stoich exist, doing nothing"
51+ return False
52+ else :
53+ # "but stoich doesn't exist,this is when object is deleted which deletes the solver
54+ # " but solver are not changed, then also call addSolver"
55+ setCompartmentSolver (modelRoot , currentSolver )
56+ return True
57+ return False
3258
33- if previousSolver != currentSolver :
34- # if previousSolver != currentSolver
35- comptinfo .solver = currentSolver
36- if (moose .exists (compt [0 ].path + '/stoich' )):
37- # "A: and stoich exists then delete the stoich add solver"
38- deleteSolver (modelRoot )
39- setCompartmentSolver (modelRoot ,currentSolver )
40- return True
41- else :
42- # " B: stoich doesn't exists then addSolver, this is when object is deleted which delete's the solver "
43- # " and solver is also changed, then add addsolver "
44- setCompartmentSolver (modelRoot ,currentSolver )
45- return True
46- else :
47- if moose .exists (compt [0 ].path + '/stoich' ):
48- # " stoich exist, doing nothing"
49- return False
50- else :
51- # "but stoich doesn't exist,this is when object is deleted which deletes the solver
52- # " but solver are not changed, then also call addSolver"
53- setCompartmentSolver (modelRoot ,currentSolver )
54- return True
55- return False
5659
57- def setCompartmentSolver (modelRoot ,solver ):
58- compts = moose .wildcardFind (modelRoot + '/##[ISA=ChemCompt]' )
59- for compt in compts :
60- if ( solver == 'gsl' ) or (solver == 'Runge Kutta' ):
61- ksolve = moose .Ksolve ( compt .path + '/ksolve' )
62- if ( solver == 'gssa' ) or (solver == 'Gillespie' ):
63- ksolve = moose .Gsolve ( compt .path + '/gsolve' )
64- if ( solver != 'ee' ):
65- stoich = moose .Stoich ( compt .path + '/stoich' )
66- stoich .compartment = compt
67- stoich .ksolve = ksolve
68- if moose .exists (compt .path ):
69- stoich .path = compt .path + "/##"
70- stoichList = moose .wildcardFind (modelRoot + '/##[ISA=Stoich]' )
71- if len ( stoichList ) == 2 :
72- stoichList [1 ].buildXreacs ( stoichList [0 ] )
73- if len ( stoichList ) == 3 :
74- stoichList [1 ].buildXreacs (stoichList [0 ])
75- stoichList [1 ].buildXreacs (stoichList [2 ])
60+ def setCompartmentSolver (modelRoot , solver ):
61+ compts = moose .wildcardFind (modelRoot + '/##[ISA=ChemCompt]' )
62+ for compt in compts :
63+ if (solver == 'gsl' ) or (solver == 'Runge Kutta' ):
64+ ksolve = moose .Ksolve (compt .path + '/ksolve' )
65+ if (solver == 'gssa' ) or (solver == 'Gillespie' ):
66+ ksolve = moose .Gsolve (compt .path + '/gsolve' )
67+ if (solver != 'ee' ):
68+ stoich = moose .Stoich (compt .path + '/stoich' )
69+ stoich .compartment = compt
70+ stoich .ksolve = ksolve
71+ if moose .exists (compt .path ):
72+ stoich .path = compt .path + "/##"
73+ stoichList = moose .wildcardFind (modelRoot + '/##[ISA=Stoich]' )
74+ if len (stoichList ) == 2 :
75+ stoichList [1 ].buildXreacs (stoichList [0 ])
76+ if len (stoichList ) == 3 :
77+ stoichList [1 ].buildXreacs (stoichList [0 ])
78+ stoichList [1 ].buildXreacs (stoichList [2 ])
7679
77- for i in stoichList :
78- i .filterXreacs ()
79- print " Solver is added to model path " ,modelRoot
80+ for i in stoichList :
81+ i .filterXreacs ()
82+ print ( " Solver is added to model path " , modelRoot )
0 commit comments