Skip to content

Commit

Permalink
First pass fix for solver deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
upibhalla committed Oct 3, 2020
1 parent b6b5da0 commit f87e947
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion builtins/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ void Function::setSolver( const Eref& e, ObjId newStoich )
e.id().path() << endl;
return;
}
if ( newStoich == ObjId( '/' ) ) { // Unsetting stoich.
if ( newStoich == ObjId() ) { // Unsetting stoich.
if ( stoich_ != 0 ) {
auto x = reinterpret_cast< Stoich* >( stoich_ );
x->notifyRemoveFunc( e );
Expand Down
8 changes: 8 additions & 0 deletions kinetics/Enz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ void Enz::setSolver( const Eref& e, ObjId stoich )
assert( cplxFinfo );
vector< Id > enzMols;
vector< Id > cplxMols;

if ( stoich == ObjId() ) { // Clear solver
if ( stoich_ )
stoich_->notifyRemoveEnz( e );
stoich_ = 0;
return;
}

bool isOK = true;
unsigned int numReactants;
numReactants = e.element()->getNeighbors( enzMols, enzFinfo );
Expand Down
7 changes: 7 additions & 0 deletions kinetics/MMenz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ void MMenz::setSolver( const Eref& e, ObjId solver )
assert( subFinfo );
assert( prdFinfo );

if ( solver == ObjId() ) { // Clear solver
if ( stoich_ )
stoich_->notifyRemoveMMenz( e );
stoich_ = 0;
return;
}

assert( solver.element()->cinfo()->isA( "Stoich" ) );
Stoich* stoichPtr = reinterpret_cast< Stoich* >( solver.data() );
if ( stoich_ == stoichPtr )
Expand Down
25 changes: 17 additions & 8 deletions kinetics/PoolBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,16 @@ unsigned int PoolBase::getSpecies( const Eref& e ) const
return 0;
}

void PoolBase::setSolvers( const Eref& e, ObjId ksolve, ObjId dsolve )
{
if ( ! ksolve.bad() ) {
string nm = ksolve.element()->cinfo()->name();
void PoolBase::setSolvers( const Eref& e, ObjId ks, ObjId ds )
{
if ( ks == ObjId() ) {
if ( ksolve_ )
ksolve_->notifyRemovePool( e );
ksolve_ = 0;
} else if ( ! ks.bad() ) {
string nm = ks.element()->cinfo()->name();
if ( nm == "Ksolve" || nm == "Gsolve" ) {
KsolveBase* k = reinterpret_cast< KsolveBase *>(ksolve.data() );
KsolveBase* k = reinterpret_cast< KsolveBase *>(ks.data() );
if ( k && k != ksolve_ ) {
if ( ksolve_ )
ksolve_->notifyRemovePool( e );
Expand All @@ -521,10 +525,15 @@ void PoolBase::setSolvers( const Eref& e, ObjId ksolve, ObjId dsolve )
}
}
}
if ( ! dsolve.bad() ) {
string nm = dsolve.element()->cinfo()->name();
if ( ds == ObjId() ) {
if ( dsolve_ ) {
dsolve_->notifyRemovePool( e );
}
dsolve_ = 0;
} else if ( ! ds.bad() ) {
string nm = ds.element()->cinfo()->name();
if ( nm == "Dsolve" ) {
KsolveBase* d = reinterpret_cast< KsolveBase *>(dsolve.data() );
KsolveBase* d = reinterpret_cast< KsolveBase *>(ds.data() );
if ( d && d != dsolve_ ) {
if ( dsolve_ )
dsolve_->notifyRemovePool( e );
Expand Down
2 changes: 1 addition & 1 deletion kinetics/Reac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void Reac::setSolver( const Eref& e, ObjId newStoich )
e.id().path() << endl;
return;
}
if ( newStoich == ObjId( '/' ) ) { // Unsetting stoich.
if ( newStoich == ObjId() ) { // Unsetting stoich.
if ( stoich_ != 0 )
stoich_->notifyRemoveReac( e );
stoich_ = 0;
Expand Down
29 changes: 11 additions & 18 deletions ksolve/Stoich.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,27 +1269,22 @@ void Stoich::zombifyModel(const Eref& e, const vector<Id>& elist)

void Stoich::unZombifyPools()
{
static const Cinfo* poolCinfo = Cinfo::find("Pool");
static const Cinfo* bufPoolCinfo = Cinfo::find("BufPool");
static ObjId root = ObjId();
unsigned int i;
for(i = 0; i < varPoolVec_.size(); ++i) {
Element* e = varPoolVec_[i].element();
if(!e || e->isDoomed())
continue;
}

for(i = 0; i < bufPoolVec_.size(); ++i) {
Element* e = bufPoolVec_[i].element();
if(!e || e->isDoomed())
continue;
for(auto i = varPoolVec_.begin(); i != varPoolVec_.end(); ++i) {
Element* e = i->element();
if(e && !e->isDoomed())
SetGet2< ObjId, ObjId >::set( *i, "setSolvers", root, root );
}
for(auto i = bufPoolVec_.begin(); i != bufPoolVec_.end(); ++i) {
Element* e = i->element();
if(e && !e->isDoomed())
SetGet2< ObjId, ObjId >::set( *i, "setSolvers", root, root );
}
}

void Stoich::unZombifyModel()
{
static const Cinfo* reacCinfo = Cinfo::find("Reac");
static const Cinfo* enzCinfo = Cinfo::find("Enz");
static const Cinfo* mmEnzCinfo = Cinfo::find("MMenz");
static const Cinfo* functionCinfo = Cinfo::find("Function");

unZombifyPools();
Expand All @@ -1309,7 +1304,6 @@ void Stoich::unZombifyModel()
Element* e = i->element();
if( e != 0 && e->cinfo()->isA( "EnzBase" ) ) {
SetGet1< ObjId >::set( *i, "setSolver", Id() ); // Clear stoich
// EnzBase::zombify(e, mmEnzCinfo, Id());
}
}

Expand All @@ -1319,15 +1313,14 @@ void Stoich::unZombifyModel()
Element* e = i->element();
if( e != 0 && e->cinfo()->isA( "EnzBase" ) ) {
SetGet1< ObjId >::set( *i, "setSolver", Id() ); // Clear stoich
// CplxEnzBase::zombify(e, enzCinfo, Id());
}
}

temp = poolFuncVec_;
temp.insert(temp.end(), incrementFuncVec_.begin(), incrementFuncVec_.end());
for(vector<Id>::iterator i = temp.begin(); i != temp.end(); ++i) {
Element* e = i->element();
if(e != 0 && e->cinfo() == functionCinfo) {
if(e != 0 && e->cinfo()->isA( "Function" ) ) {
SetGet1< ObjId >::set( *i, "setSolver", Id() );
}
if(e != 0 && e->getTick() == -2) {
Expand Down

0 comments on commit f87e947

Please sign in to comment.