COPASI API  4.16.103
Classes | Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
CMathEventN::CTrigger Class Reference

#include <CMathEvent.h>

Collaboration diagram for CMathEventN::CTrigger:
Collaboration graph
[legend]

Classes

class  CRoot
 

Public Member Functions

void allocate (const CEvent *pDataEvent, const CMathContainer &container)
 
void allocateDiscontinuous (const size_t &nRoots, const CMathContainer &container)
 
bool compile (CEvent *pDataEvent, CMathContainer &container)
 
void copy (const CTrigger &src, CMathContainer &container, const size_t &valueOffset, const size_t &objectOffset)
 
 CTrigger ()
 
const CVector< CRoot > & getRoots () const
 
void initialize (CMath::sPointers &pointers)
 
void setExpression (const std::string &infix, CMathContainer &container)
 
 ~CTrigger ()
 

Static Private Member Functions

static CEvaluationNodecompile (const CEvaluationNode *pNode, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
 
static CEvaluationNodecompileAND (const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
 
static CEvaluationNodecompileEQ (const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
 
static CEvaluationNodecompileFUNCTION (const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
 
static CEvaluationNodecompileLE (const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
 
static CEvaluationNodecompileNE (const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
 
static CEvaluationNodecompileNOT (const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
 
static CEvaluationNodecompileVARIABLE (const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
 
static size_t countRoots (const CEvaluationNode *pNode, const CMath::Variables< size_t > &variables)
 
static size_t countRootsDefault (const std::vector< size_t > &children)
 
static size_t countRootsEQ (const CEvaluationNode *pNode, const std::vector< size_t > &children)
 
static size_t countRootsFUNCTION (const CEvaluationNode *pNode, const std::vector< size_t > &children)
 
static size_t countRootsVARIABLE (const CEvaluationNode *pNode, const CMath::Variables< size_t > &variables)
 

Private Attributes

bool mDualAction
 
CMathObjectmpInitialTrigger
 
CMathObjectmpTrigger
 
CVector< CRootmRoots
 

Detailed Description

Definition at line 59 of file CMathEvent.h.

Constructor & Destructor Documentation

CMathEventN::CTrigger::CTrigger ( )

Default constructor

Definition at line 153 of file CMathEvent.cpp.

153  :
154  mpTrigger(NULL),
155  mpInitialTrigger(NULL),
156  mRoots(),
157  mDualAction(false)
158 {}
CVector< CRoot > mRoots
Definition: CMathEvent.h:202
CMathObject * mpInitialTrigger
Definition: CMathEvent.h:201
CMathObject * mpTrigger
Definition: CMathEvent.h:200
CMathEventN::CTrigger::~CTrigger ( )

Destructor

Definition at line 160 of file CMathEvent.cpp.

161 {}

Member Function Documentation

void CMathEventN::CTrigger::allocate ( const CEvent pDataEvent,
const CMathContainer container 
)

Definition at line 163 of file CMathEvent.cpp.

References CExpression::compile(), CEvaluationTree::compile(), CEvaluationTree::getRoot(), CEvent::getTriggerExpression(), CFunction::setInfix(), CExpression::setInfix(), and CExpression::setIsBoolean().

Referenced by CMathEventN::allocate().

165 {
166  // Determine the number of roots.
167  CMath::Variables< size_t > Variables;
168 
169  std::vector< CCopasiContainer * > Container;
170  Container.push_back(const_cast< CMathContainer * >(&container));
171 
172  CExpression Trigger("EventTrigger", &container);
173  Trigger.setIsBoolean(true);
174 
175  if (Trigger.setInfix(pDataEvent->getTriggerExpression()))
176  {
177  Trigger.compile(Container);
178  mRoots.resize(countRoots(Trigger.getRoot(), Variables));
179  }
180  else
181  {
182  CFunction TriggerFunction("EventTrigger", &container);
183 
184  if (TriggerFunction.setInfix(pDataEvent->getTriggerExpression()))
185  {
186  TriggerFunction.compile();
187  mRoots.resize(countRoots(TriggerFunction.getRoot(), Variables));
188  }
189  }
190 
191  return;
192 }
static size_t countRoots(const CEvaluationNode *pNode, const CMath::Variables< size_t > &variables)
Definition: CMathEvent.cpp:315
std::string getTriggerExpression() const
Definition: CEvent.cpp:524
CVector< CRoot > mRoots
Definition: CMathEvent.h:202
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
void CMathEventN::CTrigger::allocateDiscontinuous ( const size_t &  nRoots,
const CMathContainer container 
)

Definition at line 194 of file CMathEvent.cpp.

196 {
197  mRoots.resize(nRoots);
198 }
CVector< CRoot > mRoots
Definition: CMathEvent.h:202
bool CMathEventN::CTrigger::compile ( CEvent pDataEvent,
CMathContainer container 
)

Definition at line 247 of file CMathEvent.cpp.

References CExpression::compile(), CMathEventN::compile(), CEvaluationTree::getRoot(), CEvent::getTriggerExpression(), CExpression::setInfix(), and CExpression::setIsBoolean().

Referenced by CMathEventN::compile().

249 {
250  bool success = true;
251 
253 
254  std::vector< CCopasiContainer * > ListOfContainer;
255  ListOfContainer.push_back(&container);
256 
257  CExpression DataTrigger("DataTrigger", &container);
258  DataTrigger.setIsBoolean(true);
259 
260  if (pDataEvent != NULL)
261  {
262  DataTrigger.setInfix(pDataEvent->getTriggerExpression());
263  mDualAction = false;
264  }
265  else
266  {
267  DataTrigger.setInfix(mpTrigger->getExpressionPtr()->getInfix());
268  }
269 
270  success &= DataTrigger.compile();
271 
272  CEvaluationNode * pTriggerRoot = NULL;
273  CRoot * pRoot = mRoots.array();
274 
275  pTriggerRoot = compile(DataTrigger.getRoot(), Variables, pRoot, container);
276 
277  assert(pRoot == mRoots.array() + mRoots.size());
278 
279  CMathExpression * pTrigger = new CMathExpression("EventTrigger", container);
280  success &= static_cast< CEvaluationTree * >(pTrigger)->setRoot(pTriggerRoot);
281 
282  success &= mpTrigger->setExpressionPtr(pTrigger);
283 
284  return success;
285 }
const CMathExpression * getExpressionPtr() const
bool compile(CEvent *pDataEvent, CMathContainer &container)
Definition: CMathEvent.cpp:247
std::string getTriggerExpression() const
Definition: CEvent.cpp:524
CVector< CRoot > mRoots
Definition: CMathEvent.h:202
CMathObject * mpTrigger
Definition: CMathEvent.h:200
const std::string & getInfix() const
bool setExpressionPtr(CMathExpression *pMathExpression)
CEvaluationNode * CMathEventN::CTrigger::compile ( const CEvaluationNode pNode,
const CMath::Variables< CEvaluationNode * > &  variables,
CMathEventN::CTrigger::CRoot *&  pRoot,
CMathContainer container 
)
staticprivate

Definition at line 493 of file CMathEvent.cpp.

References CEvaluationNodeConstant::_NaN, CNodeIteratorMode::After, CEvaluationNodeLogical::AND, CEvaluationNodeVariable::ANY, CNodeIteratorMode::Before, C_INVALID_INDEX, CEvaluationNode::CALL, CEvaluationNode::CONSTANT, CNodeContextIterator< Node, Context >::context(), CMathContainer::copyBranch(), CEvaluationNode::copyNode(), CNodeContextIterator< Node, Context >::end(), CEvaluationNodeLogical::EQ, CEvaluationNodeCall::EXPRESSION, CEvaluationNodeConstant::FALSE, CEvaluationNodeCall::FUNCTION, CEvaluationNode::FUNCTION, CEvaluationNodeLogical::GE, CCopasiNode< _Data >::getData(), CEvaluationNodeVariable::getIndex(), CEvaluationNode::getType(), CEvaluationNodeLogical::GT, CEvaluationNode::isBoolean(), CEvaluationNodeLogical::LE, CEvaluationNode::LOGICAL, CEvaluationNodeLogical::LT, CEvaluationNodeLogical::NE, CNodeContextIterator< Node, Context >::next(), CEvaluationNodeFunction::NOT, CEvaluationNodeLogical::OR, CNodeContextIterator< Node, Context >::parentContextPtr(), CNodeContextIterator< Node, Context >::processingMode(), CNodeContextIterator< Node, Context >::setProcessingModes(), CNodeContextIterator< Node, Context >::skipChildren(), CEvaluationNodeConstant::TRUE, CEvaluationNode::type(), CEvaluationNode::VARIABLE, and CEvaluationNodeLogical::XOR.

497 {
498  CEvaluationNode * pNode = NULL;
499 
501  itNode.setProcessingModes(CNodeIteratorMode::Before | CNodeIteratorMode::After);
502 
503  while (itNode.next() != itNode.end())
504  {
505  if (*itNode == NULL)
506  {
507  continue;
508  }
509 
510  switch (itNode.processingMode())
511  {
513 
514  // Variables return always false we need to dig deeper.
515  if (CEvaluationNode::type(itNode->getType()) == CEvaluationNode::VARIABLE)
516  {
517  size_t Index =
518  static_cast< const CEvaluationNodeVariable * >(*itNode)->getIndex();
519 
520  if (Index != C_INVALID_INDEX &&
521  Index < variables.size() &&
522  variables[Index]->isBoolean())
523  {
524  continue;
525  }
526 
527  // We found a non boolean node which we simply copy.
528  itNode.skipChildren();
529 
530  // Since a variable may be referred to multiple times we need to copy it.
531  if (Index != C_INVALID_INDEX)
532  {
533  pNode = variables[Index]->copyBranch();
534  }
535  else
536  {
537  // Variables must not appear in mathematical expressions.
538  // We create an constant node with the variable name and value NaN.
539  pNode = new CEvaluationNodeConstant(CEvaluationNodeConstant::_NaN, itNode->getData());
540  }
541  }
542  else if (!itNode->isBoolean())
543  {
544  // We found a non boolean node which we simply copy.
545  itNode.skipChildren();
546  pNode = container.copyBranch(*itNode, variables, true);
547  }
548  else
549  {
550  continue;
551  }
552 
553  break;
554 
556 
557  // We do not need to check whether the root is boolean as non boolean nodes are
558  // already processed
559  switch ((int) itNode->getType())
560  {
564  pNode = compileAND(*itNode, itNode.context(), variables, pRoot, container);
565  break;
566 
568  pNode = compileEQ(*itNode, itNode.context(), variables, pRoot, container);
569  break;
570 
572  pNode = compileNE(*itNode, itNode.context(), variables, pRoot, container);
573  break;
574 
579  pNode = compileLE(*itNode, itNode.context(), variables, pRoot, container);
580  break;
581 
583  pNode = compileNOT(*itNode, itNode.context(), variables, pRoot, container);
584  break;
585 
588  pNode = compileFUNCTION(*itNode, itNode.context(), variables, pRoot, container);
589  break;
590 
592  pNode = compileVARIABLE(*itNode, itNode.context(), variables, pRoot, container);
593  break;
594 
597  default:
598  pNode = itNode->copyNode(itNode.context());
599  break;
600  }
601 
602  break;
603 
604  default:
605  // This will never happen
606  break;
607  }
608 
609  if (itNode.parentContextPtr() != NULL)
610  {
611  itNode.parentContextPtr()->push_back(pNode);
612  }
613  }
614 
615  return pNode;
616 }
static CEvaluationNode * compileVARIABLE(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:813
CEvaluationNode * copyNode(CEvaluationNode *child1, CEvaluationNode *child2) const
static CEvaluationNode * compileNE(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:693
static CEvaluationNode * compileAND(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:619
#define C_INVALID_INDEX
Definition: copasi.h:222
static CEvaluationNode * compileEQ(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:655
CEvaluationNode * copyBranch(const CEvaluationNode *pSrc, const bool &replaceDiscontinuousNodes)
static Type type(const Type &type)
static CEvaluationNode * compileLE(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:722
static CEvaluationNode * compileFUNCTION(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:789
static CEvaluationNode * compileNOT(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:774
CEvaluationNode * CMathEventN::CTrigger::compileAND ( const CEvaluationNode pNode,
const std::vector< CEvaluationNode * > &  children,
const CMath::Variables< CEvaluationNode * > &  variables,
CMathEventN::CTrigger::CRoot *&  pRoot,
CMathContainer container 
)
staticprivate

Definition at line 619 of file CMathEvent.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNodeLogical::AND, CEvaluationNode::getType(), CEvaluationNodeLogical::OR, CEvaluationNode::subType(), and CEvaluationNodeLogical::XOR.

624 {
625  CEvaluationNode * pNode = NULL;
626 
627  switch ((int) CEvaluationNode::subType(pTriggerNode->getType()))
628  {
631  break;
632 
635  break;
636 
639  break;
640 
641  default:
642  break;
643  }
644 
645  if (pNode != NULL)
646  {
647  pNode->addChild(children[0]);
648  pNode->addChild(children[1]);
649  }
650 
651  return pNode;
652 }
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
static Type subType(const Type &type)
CEvaluationNode * CMathEventN::CTrigger::compileEQ ( const CEvaluationNode pNode,
const std::vector< CEvaluationNode * > &  children,
const CMath::Variables< CEvaluationNode * > &  variables,
CMathEventN::CTrigger::CRoot *&  pRoot,
CMathContainer container 
)
staticprivate

Definition at line 655 of file CMathEvent.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNodeLogical::AND, CEvaluationNodeLogical::EQ, CEvaluationNodeLogical::GE, and CCopasiNode< _Data >::getChild().

660 {
661  CEvaluationNode * pNode = NULL;
662 
663  // Equality can be determined between Boolean and double values.
664  if (!static_cast< const CEvaluationNode * >(pTriggerNode->getChild())->isBoolean())
665  {
666  // We treat x EQ y as (x GE y) AND (y GE x)
668 
670  CEvaluationNode * pGELeft = compileLE(&GELeft, children, variables, pRoot, container);
671  pNode->addChild(pGELeft);
672 
673  // We need to duplicate and reverse the order for the right
674  std::vector< CEvaluationNode * > RightChildren;
675  RightChildren.push_back(children[1]->copyBranch());
676  RightChildren.push_back(children[0]->copyBranch());
677 
679  CEvaluationNode * pGERight = compileLE(&GERight, RightChildren, variables, pRoot, container);
680  pNode->addChild(pGERight);
681  }
682  else
683  {
685  pNode->addChild(children[0]);
686  pNode->addChild(children[1]);
687  }
688 
689  return pNode;
690 }
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
static CEvaluationNode * compileLE(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:722
CEvaluationNode * CMathEventN::CTrigger::compileFUNCTION ( const CEvaluationNode pNode,
const std::vector< CEvaluationNode * > &  children,
const CMath::Variables< CEvaluationNode * > &  variables,
CMathEventN::CTrigger::CRoot *&  pRoot,
CMathContainer container 
)
staticprivate

Definition at line 789 of file CMathEvent.cpp.

References CMathEventN::compile().

794 {
795  const CEvaluationNode * pCalledNode =
796  static_cast< const CEvaluationNodeCall * >(pTriggerNode)->getCalledTree()->getRoot();
797 
798  CEvaluationNode * pNode = compile(pCalledNode, children, pRoot, container);
799 
800  // We need to delete the children as the variables have been copied in place.
801  std::vector< CEvaluationNode * >::const_iterator it = children.begin();
802  std::vector< CEvaluationNode * >::const_iterator end = children.end();
803 
804  for (; it != end; ++it)
805  {
806  delete *it;
807  }
808 
809  return pNode;
810 }
bool compile(CEvent *pDataEvent, CMathContainer &container)
Definition: CMathEvent.cpp:247
CEvaluationNode * CMathEventN::CTrigger::compileLE ( const CEvaluationNode pNode,
const std::vector< CEvaluationNode * > &  children,
const CMath::Variables< CEvaluationNode * > &  variables,
CMathEventN::CTrigger::CRoot *&  pRoot,
CMathContainer container 
)
staticprivate

Definition at line 722 of file CMathEvent.cpp.

References CCopasiNode< _Data >::addChild(), CMathEventN::CTrigger::CRoot::compile(), CMathEventN::CTrigger::CRoot::createTriggerExpressionNode(), CEvaluationNodeLogical::GE, CEvaluationNode::getType(), CEvaluationNodeLogical::GT, CEvaluationNodeLogical::LE, CEvaluationNodeLogical::LT, CEvaluationNodeOperator::MINUS, and CEvaluationNode::subType().

727 {
728  CEvaluationNode * pNode = NULL;
729 
730  // We need to compile the root finding structure
731  // Create a root expression
733 
734  bool Equality = false;
735 
736  // We need to create a copy the left and right data nodes with the variables being replaced.
737  switch ((int) CEvaluationNode::subType(pTriggerNode->getType()))
738  {
740  pRootNode->addChild(children[1]);
741  pRootNode->addChild(children[0]);
742  Equality = true;
743  break;
744 
746  pRootNode->addChild(children[1]);
747  pRootNode->addChild(children[0]);
748  Equality = false;
749  break;
750 
752  pRootNode->addChild(children[0]);
753  pRootNode->addChild(children[1]);
754  Equality = true;
755  break;
756 
758  pRootNode->addChild(children[0]);
759  pRootNode->addChild(children[1]);
760  Equality = false;
761  break;
762  }
763 
764  pRoot->compile(pRootNode, Equality, container);
765  pNode = pRoot->createTriggerExpressionNode();
766  pRoot++;
767 
768  // We do not need to delete pRootNode as CRoot::compile takes car of it.
769 
770  return pNode;
771 }
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
bool compile(CEvaluationNode *pRootNode, const bool &equality, CMathContainer &container)
Definition: CMathEvent.cpp:121
static Type subType(const Type &type)
CEvaluationNode * createTriggerExpressionNode() const
Definition: CMathEvent.cpp:148
CEvaluationNode * CMathEventN::CTrigger::compileNE ( const CEvaluationNode pNode,
const std::vector< CEvaluationNode * > &  children,
const CMath::Variables< CEvaluationNode * > &  variables,
CMathEventN::CTrigger::CRoot *&  pRoot,
CMathContainer container 
)
staticprivate

Definition at line 693 of file CMathEvent.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNodeLogical::EQ, CEvaluationNodeFunction::NOT, and CCopasiNode< _Data >::removeChild().

698 {
699  CEvaluationNode * pNode = NULL;
700 
701  // We treat this as NOT and EQ.
702  // For this we create a modified copy of the current node.
703 
705 
707 
708  EqNode.addChild(children[0]);
709  EqNode.addChild(children[1]);
710 
711  CEvaluationNode * pEqNode = compileEQ(&EqNode, children, variables, pRoot, container);
712  pNotNode->addChild(pEqNode);
713 
714  // We need to remove the children since the ownership has been transferred to pEqNode.
715  EqNode.removeChild(children[0]);
716  EqNode.removeChild(children[1]);
717 
718  return pNode;
719 }
static CEvaluationNode * compileEQ(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:655
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CEvaluationNode * CMathEventN::CTrigger::compileNOT ( const CEvaluationNode pNode,
const std::vector< CEvaluationNode * > &  children,
const CMath::Variables< CEvaluationNode * > &  variables,
CMathEventN::CTrigger::CRoot *&  pRoot,
CMathContainer container 
)
staticprivate

Definition at line 774 of file CMathEvent.cpp.

References CCopasiNode< _Data >::addChild(), and CEvaluationNodeFunction::NOT.

779 {
780  CEvaluationNode * pNode = NULL;
781 
783  pNode->addChild(children[0]);
784 
785  return pNode;
786 }
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CEvaluationNode * CMathEventN::CTrigger::compileVARIABLE ( const CEvaluationNode pNode,
const std::vector< CEvaluationNode * > &  children,
const CMath::Variables< CEvaluationNode * > &  variables,
CMathEventN::CTrigger::CRoot *&  pRoot,
CMathContainer container 
)
staticprivate

Definition at line 813 of file CMathEvent.cpp.

References CEvaluationNodeConstant::_NaN, C_INVALID_INDEX, and CCopasiNode< _Data >::getData().

818 {
819  // We need to mimic the process in CMathContainer::copyBranch;
820  size_t Index =
821  static_cast< const CEvaluationNodeVariable * >(pTriggerNode)->getIndex();
822 
823  if (Index != C_INVALID_INDEX &&
824  Index < variables.size())
825  {
826  // Since a variable may be referred to multiple times we need to copy it.
827  return variables[Index]->copyBranch();
828  }
829  else
830  {
831  // Variables must not appear in mathematical expressions.
832  // We create a constant node with the variable name and value NaN.
833  return new CEvaluationNodeConstant(CEvaluationNodeConstant::_NaN, pTriggerNode->getData());
834  }
835 }
#define C_INVALID_INDEX
Definition: copasi.h:222
void CMathEventN::CTrigger::copy ( const CTrigger src,
CMathContainer container,
const size_t &  valueOffset,
const size_t &  objectOffset 
)

Copy an existing object

Parameters
constCTrigger & src
CMathContainer& container
constsize_t & valueOffset
constsize_t & objectOffset

Definition at line 226 of file CMathEvent.cpp.

References CMathEventN::CTrigger::CRoot::copy(), mDualAction, mpInitialTrigger, mpTrigger, and mRoots.

Referenced by CMathEventN::copy().

230 {
231  mpTrigger = src.mpTrigger + objectOffset;
232  mpInitialTrigger = src.mpInitialTrigger + objectOffset;
233 
234  mRoots.resize(src.mRoots.size());
235  CRoot * pRoot = mRoots.array();
236  CRoot * pRootEnd = pRoot + mRoots.size();
237  const CRoot * pRootSrc = src.mRoots.array();
238 
239  for (; pRoot != pRootEnd; ++pRoot, ++pRootSrc)
240  {
241  pRoot->copy(*pRootSrc, container, valueOffset, objectOffset);
242  }
243 
244  mDualAction = src.mDualAction;
245 }
CVector< CRoot > mRoots
Definition: CMathEvent.h:202
CMathObject * mpInitialTrigger
Definition: CMathEvent.h:201
CMathObject * mpTrigger
Definition: CMathEvent.h:200
size_t CMathEventN::CTrigger::countRoots ( const CEvaluationNode pNode,
const CMath::Variables< size_t > &  variables 
)
staticprivate

Definition at line 315 of file CMathEvent.cpp.

References CNodeIteratorMode::After, CEvaluationNodeVariable::ANY, CNodeIteratorMode::Before, CEvaluationNode::CALL, CNodeContextIterator< Node, Context >::context(), CNodeContextIterator< Node, Context >::end(), CEvaluationNodeLogical::EQ, CEvaluationNodeCall::EXPRESSION, CEvaluationNodeCall::FUNCTION, CEvaluationNodeLogical::GE, CEvaluationNode::getType(), CEvaluationNodeLogical::GT, CEvaluationNode::isBoolean(), CEvaluationNodeLogical::LE, CEvaluationNode::LOGICAL, CEvaluationNodeLogical::LT, CEvaluationNodeLogical::NE, CNodeContextIterator< Node, Context >::next(), CNodeContextIterator< Node, Context >::parentContextPtr(), CNodeContextIterator< Node, Context >::processingMode(), CNodeContextIterator< Node, Context >::setProcessingModes(), CNodeContextIterator< Node, Context >::skipChildren(), CEvaluationNode::subType(), CEvaluationNode::type(), and CEvaluationNode::VARIABLE.

317 {
318  size_t RootCount = 0;
319 
320  // TODO CRITICAL We only need to count in boolean functions see compile for details.
322  itNode.setProcessingModes(CNodeIteratorMode::Before | CNodeIteratorMode::After);
323 
324  while (itNode.next() != itNode.end())
325  {
326  if (*itNode == NULL)
327  {
328  continue;
329  }
330 
331  switch (itNode.processingMode())
332  {
334 
335  // Variables return always false we need to dig deeper.
336  if (CEvaluationNode::type(itNode->getType()) == CEvaluationNode::VARIABLE ||
337  itNode->isBoolean())
338  {
339  continue;
340  }
341 
342  // We found a non boolean node which does not create a root.
343  itNode.skipChildren();
344  RootCount = 0;
345 
346  break;
347 
349  {
350  // We do not need to check whether the root is boolean as non boolean nodes are
351  // already processed
352  const CEvaluationNode::Type & Type = itNode->getType();
353 
354  switch (CEvaluationNode::type(Type))
355  {
357 
358  switch ((int) CEvaluationNode::subType(Type))
359  {
362  RootCount = countRootsEQ(*itNode, itNode.context());
363  break;
364 
369  RootCount = 1;
370  break;
371 
372  default:
373  RootCount = countRootsDefault(itNode.context());
374  break;
375  }
376 
377  break;
378 
380 
381  switch ((int) CEvaluationNode::subType(Type))
382  {
385  RootCount = countRootsFUNCTION(*itNode, itNode.context());
386  break;
387 
388  default:
389  RootCount = countRootsDefault(itNode.context());
390  break;
391  }
392 
393  break;
394 
396 
397  switch ((int) CEvaluationNode::subType(Type))
398  {
400  RootCount = countRootsVARIABLE(*itNode, variables);
401  break;
402 
403  default:
404  RootCount = countRootsDefault(itNode.context());
405  break;
406  }
407 
408  break;
409 
410  default:
411  RootCount = countRootsDefault(itNode.context());
412  break;
413  }
414  }
415  break;
416 
417  default:
418  break;
419  }
420 
421  if (itNode.parentContextPtr() != NULL)
422  {
423  itNode.parentContextPtr()->push_back(RootCount);
424  }
425  }
426 
427  return RootCount;
428 }
static size_t countRootsVARIABLE(const CEvaluationNode *pNode, const CMath::Variables< size_t > &variables)
Definition: CMathEvent.cpp:478
static size_t countRootsFUNCTION(const CEvaluationNode *pNode, const std::vector< size_t > &children)
Definition: CMathEvent.cpp:466
static Type type(const Type &type)
static size_t countRootsDefault(const std::vector< size_t > &children)
Definition: CMathEvent.cpp:431
static Type subType(const Type &type)
static size_t countRootsEQ(const CEvaluationNode *pNode, const std::vector< size_t > &children)
Definition: CMathEvent.cpp:447
size_t CMathEventN::CTrigger::countRootsDefault ( const std::vector< size_t > &  children)
staticprivate

Definition at line 431 of file CMathEvent.cpp.

432 {
433  size_t RootCount = 0;
434 
435  std::vector< size_t >::const_iterator it = children.begin();
436  std::vector< size_t >::const_iterator end = children.end();
437 
438  for (; it != end; ++it)
439  {
440  RootCount += *it;
441  }
442 
443  return RootCount;
444 }
size_t CMathEventN::CTrigger::countRootsEQ ( const CEvaluationNode pNode,
const std::vector< size_t > &  children 
)
staticprivate

Definition at line 447 of file CMathEvent.cpp.

References CCopasiNode< _Data >::getChild().

449 {
450  size_t nRoots = children[0] + children[1];
451 
452  // Equality can be determined between Boolean and double values.
453  if (static_cast<const CEvaluationNode *>(pNode->getChild())->isBoolean())
454  {
455  nRoots = children[0] + children[1];
456  }
457  else
458  {
459  nRoots = 2;
460  }
461 
462  return nRoots;
463 }
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
size_t CMathEventN::CTrigger::countRootsFUNCTION ( const CEvaluationNode pNode,
const std::vector< size_t > &  children 
)
staticprivate

Definition at line 466 of file CMathEvent.cpp.

468 {
469  const CEvaluationNode * pTreeRoot =
470  static_cast< const CEvaluationNodeCall * >(pNode)->getCalledTree()->getRoot();
471 
472  size_t nRoots = countRoots(pTreeRoot, children);
473 
474  return nRoots;
475 }
static size_t countRoots(const CEvaluationNode *pNode, const CMath::Variables< size_t > &variables)
Definition: CMathEvent.cpp:315
size_t CMathEventN::CTrigger::countRootsVARIABLE ( const CEvaluationNode pNode,
const CMath::Variables< size_t > &  variables 
)
staticprivate

Definition at line 478 of file CMathEvent.cpp.

References C_INVALID_INDEX.

480 {
481  size_t Index =
482  static_cast< const CEvaluationNodeVariable * >(pNode)->getIndex();
483 
484  if (Index == C_INVALID_INDEX)
485  {
486  return 0;
487  }
488 
489  return variables[Index];
490 }
#define C_INVALID_INDEX
Definition: copasi.h:222
const CVector< CMathEventN::CTrigger::CRoot > & CMathEventN::CTrigger::getRoots ( ) const

Definition at line 287 of file CMathEvent.cpp.

Referenced by CMathContainer::allocate().

288 {
289  return mRoots;
290 }
CVector< CRoot > mRoots
Definition: CMathEvent.h:202
void CMathEventN::CTrigger::initialize ( CMath::sPointers pointers)

Definition at line 200 of file CMathEvent.cpp.

References CMath::Event, CMath::EventTrigger, CMathEventN::CTrigger::CRoot::initialize(), CMathObject::initialize(), CMath::sPointers::pEventTriggers, CMath::sPointers::pEventTriggersObject, CMath::sPointers::pInitialEventTriggers, CMath::sPointers::pInitialEventTriggersObject, and CMath::SimulationTypeUndefined.

Referenced by CMathEventN::initialize().

201 {
202  // Initialize trigger object.
203  mpTrigger = pointers.pEventTriggersObject;
204  *pointers.pEventTriggers = 1.0;
207  false, false, NULL);
208 
209  // Initialize initial trigger object.
211  *pointers.pInitialEventTriggers = 1.0;
214  false, true, NULL);
215 
216  // Initialize root object.
217  CRoot * pRoot = mRoots.array();
218  CRoot * pRootEnd = pRoot + mRoots.size();
219 
220  for (; pRoot != pRootEnd; ++pRoot)
221  {
222  pRoot->initialize(pointers);
223  }
224 }
CVector< CRoot > mRoots
Definition: CMathEvent.h:202
CMathObject * mpInitialTrigger
Definition: CMathEvent.h:201
C_FLOAT64 * pInitialEventTriggers
Definition: CMathEnum.h:96
CMathObject * pEventTriggersObject
Definition: CMathEnum.h:132
CMathObject * pInitialEventTriggersObject
Definition: CMathEnum.h:123
CMathObject * mpTrigger
Definition: CMathEvent.h:200
static void initialize(CMathObject *&pObject, C_FLOAT64 *&pValue, const CMath::ValueType &valueType, const CMath::EntityType &entityType, const CMath::SimulationType &simulationType, const bool &isIntensiveProperty, const bool &isInitialValue, const CCopasiObject *pDataObject)
Definition: CMathObject.cpp:23
C_FLOAT64 * pEventTriggers
Definition: CMathEnum.h:105
void CMathEventN::CTrigger::setExpression ( const std::string &  infix,
CMathContainer container 
)

Set the trigger expression

Parameters
conststd::string & infix
CMathContainer& container

Definition at line 292 of file CMathEvent.cpp.

References CMathEventN::compile(), CMathEventN::CTrigger::CRoot::mpRoot, and CMathEventN::CTrigger::CRoot::mpRootState.

Referenced by CMathEventN::setTriggerExpression().

294 {
295  assert(mpTrigger != NULL);
296 
297  mpTrigger->setExpression(infix, true, container);
298 
299  compile(NULL, container);
300 
301  std::cout << *mpTrigger;
302  std::cout << *mpInitialTrigger;
303 
304  CRoot * pRoot = mRoots.array();
305  CRoot * pRootEnd = pRoot + mRoots.size();
306 
307  for (; pRoot != pRootEnd; ++pRoot)
308  {
309  std::cout << *pRoot->mpRoot;
310  std::cout << *pRoot->mpRootState;
311  }
312 }
bool compile(CEvent *pDataEvent, CMathContainer &container)
Definition: CMathEvent.cpp:247
CVector< CRoot > mRoots
Definition: CMathEvent.h:202
CMathObject * mpInitialTrigger
Definition: CMathEvent.h:201
bool setExpression(const std::string &infix, const bool &isBoolean, CMathContainer &container)
CMathObject * mpTrigger
Definition: CMathEvent.h:200

Member Data Documentation

bool CMathEventN::CTrigger::mDualAction
private

Definition at line 203 of file CMathEvent.h.

Referenced by copy().

CMathObject* CMathEventN::CTrigger::mpInitialTrigger
private

Definition at line 201 of file CMathEvent.h.

Referenced by copy().

CMathObject* CMathEventN::CTrigger::mpTrigger
private

Definition at line 200 of file CMathEvent.h.

Referenced by copy().

CVector< CRoot > CMathEventN::CTrigger::mRoots
private

Definition at line 202 of file CMathEvent.h.

Referenced by copy().


The documentation for this class was generated from the following files: