COPASI API  4.16.103
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CFindDimensions Class Reference

#include <CDimension.h>

Collaboration diagram for CFindDimensions:
Collaboration graph
[legend]

Public Member Functions

 CFindDimensions (const CFunction *function, bool d1, bool d2, bool d3, bool d4, bool d5)
 
void findDimensions (CDimension rootDim)
 
void findDimensions (bool isMulticompartment)
 
std::vector< std::string > findDimensionsBoth (const CModel *pModel)
 
const std::vector< CDimension > & getDimensions () const
 
void setChemicalEquation (const CChemEq *eq)
 
void setMolecularitiesForMassAction (const size_t &m1, const size_t &m2)
 
void setupDimensions ()
 
void setUseHeuristics (bool flag)
 

Private Member Functions

 CFindDimensions ()
 
void findDimension (size_t index)
 find dim for one parameter More...
 
CDimension findDimension (const CEvaluationNode *node, const CEvaluationNode *requestingNode=NULL)
 
void findDimensions ()
 find dim for all parameters More...
 
void findDimensionsMassAction ()
 

Private Attributes

bool mD1
 
bool mD2
 
bool mD3
 
bool mD4
 
bool mD5
 
std::vector< CDimensionmDimensions
 
C_FLOAT64 mM1
 
C_FLOAT64 mM2
 
const CFunctionmpFunction
 
CDimension mRootDimension
 
bool mUseHeuristics
 

Detailed Description

CFindDimensions class. The class tries to find the dimensions of the "PARAMETER" variable nodes in a function tree.

The function is specified in the constructor. After that the dimension of the root node has to be specified. This can be done with either of the two public findDimensions() methods. The result can be retrieved using the getDimensions() method.

Definition at line 107 of file CDimension.h.

Constructor & Destructor Documentation

CFindDimensions::CFindDimensions ( )
private
CFindDimensions::CFindDimensions ( const CFunction function,
bool  d1,
bool  d2,
bool  d3,
bool  d4,
bool  d5 
)

construct the class for a given function. d1,d2,d3, d4, d5 indicate if the base unit (for quantity, volume, time, area, length) is dimensionless

Definition at line 285 of file CDimension.cpp.

References setupDimensions().

286  : mpFunction(function),
287  mRootDimension(),
288  mUseHeuristics(false),
289  mM1(-1.0), mM2(-1.0),
290  mD1(d1), mD2(d2), mD3(d3), mD4(d4), mD5(d5)
291 {
292  setupDimensions();
293 }
CDimension mRootDimension
Definition: CDimension.h:165
C_FLOAT64 mM2
Definition: CDimension.h:169
const CFunction * mpFunction
Definition: CDimension.h:163
void setupDimensions()
Definition: CDimension.cpp:295
C_FLOAT64 mM1
Definition: CDimension.h:168

Member Function Documentation

void CFindDimensions::findDimension ( size_t  index)
private

find dim for one parameter

Definition at line 453 of file CDimension.cpp.

References CDimension::compare(), CEvaluationTree::getNodeList(), mDimensions, mpFunction, and CEvaluationNode::VARIABLE.

Referenced by findDimension(), and findDimensions().

454 {
455  if (!mpFunction) return;
456 
457  if (index >= mDimensions.size()) return;
458 
459  CDimension result;
460 
461  //find all variable nodes with given index
462  std::vector<const CEvaluationNode*> nodes;
463  const std::vector< CEvaluationNode * > & allnodes = mpFunction->getNodeList();
464  std::vector< CEvaluationNode * >::const_iterator it, itEnd = allnodes.end();
465 
466  for (it = allnodes.begin(); it != itEnd; ++it)
467  {
468  if ((*it)->getType() == CEvaluationNode::VARIABLE)
469  if (dynamic_cast<const CEvaluationNodeVariable*>(*it)->getIndex() == index)
470  {
471  nodes.push_back(*it);
472  }
473  }
474 
475  //find dimension for all nodes and compare results
476  std::vector<const CEvaluationNode * >::const_iterator it2, it2End = nodes.end();
477 
478  for (it2 = nodes.begin(); it2 != it2End; ++it2)
479  {
480  result = result.compare(findDimension(*it2));
481  }
482 
483  mDimensions[index] = result;
484 }
CDimension compare(const CDimension &rhs) const
Definition: CDimension.cpp:219
void findDimension(size_t index)
find dim for one parameter
Definition: CDimension.cpp:453
std::vector< CDimension > mDimensions
Definition: CDimension.h:164
const CFunction * mpFunction
Definition: CDimension.h:163
const std::vector< CEvaluationNode * > & getNodeList() const
CDimension CFindDimensions::findDimension ( const CEvaluationNode node,
const CEvaluationNode requestingNode = NULL 
)
private

Definition at line 486 of file CDimension.cpp.

References CDimension::compare(), CEvaluationNodeOperator::DIVIDE, fatalError, findDimension(), CEvaluationNodeVariable::getIndex(), CEvaluationNodeOperator::getLeft(), CCopasiNode< _Data >::getParent(), CEvaluationNodeOperator::getRight(), CEvaluationNode::getType(), CEvaluationNode::getValue(), mDimensions, CEvaluationNodeOperator::MINUS, mRootDimension, CEvaluationNodeOperator::MULTIPLY, mUseHeuristics, CEvaluationNodeOperator::PLUS, CDimension::setDimension(), and CDimension::setUnknown().

488 {
489  CDimension result;
490 
491  //variable node
492  const CEvaluationNodeVariable* varnode = dynamic_cast<const CEvaluationNodeVariable*>(node);
493 
494  if (varnode)
495  {
496  //is dim known?
497  if (!mDimensions[varnode->getIndex()].isUnknown())
498  result = mDimensions[varnode->getIndex()];
499 
500  else if (requestingNode) //do not try to evaluate dim recursively if asked by parent node
501  {
502  if (node->getParent())
503  result.setUnknown();
504  else //no parent
505  fatalError();
506  }
507  else // !requestingNode; method is called from outside, evaluate recursively
508  {
509  if (node->getParent())
510  {
511  const CEvaluationNode* parent = dynamic_cast<const CEvaluationNode*>(node->getParent());
512 
513  if (parent) result = findDimension(parent, node);
514  }
515  else //no parent, use root dimension
516  {
517  result = mRootDimension;
518  }
519  }
520  }
521 
522  //operator node
523  const CEvaluationNodeOperator* opnode = dynamic_cast<const CEvaluationNodeOperator*>(node);
524 
525  if (opnode)
526  {
527  assert(requestingNode); //should not be called from outside
528 
529  switch (opnode->getType() & 0x00FFFFFF)
530  {
533  {
534  CDimension r1, r2;
535 
536  if (requestingNode == node->getParent()) //called by parent
537  {
538  r1 = findDimension(opnode->getLeft(), node);
539  r2 = findDimension(opnode->getRight(), node);
540  }
541  else //called by one of the children
542  {
543  const CEvaluationNode* parent = dynamic_cast<const CEvaluationNode*>(node->getParent());
544 
545  if (parent) r1 = findDimension(parent, node);
546  else r1 = mRootDimension;
547 
548  if (requestingNode == opnode->getLeft())
549  r2 = findDimension(opnode->getRight(), node);
550 
551  if (requestingNode == opnode->getRight())
552  r2 = findDimension(opnode->getLeft(), node);
553  }
554 
555  //r1 and r2 are now the dimensions of the two nodes that are not the
556  //requesting node.
557  /*if (r1.isContradiction() || r2.isContradiction())
558  result.setContradiction();
559  else if (r1 == r2)
560  result = r1;
561  else if (r1.isUnknown())
562  result = r2;
563  else if (r2.isUnknown())
564  result =r1;
565  else
566  result.setContradiction();*/
567  result = r1.compare(r2);
568  }
569  break;
570 
572  {
573  CDimension r1, r2;
574 
575  if (requestingNode == node->getParent()) //called by parent
576  {
577  r1 = findDimension(opnode->getLeft(), node);
578  r2 = findDimension(opnode->getRight(), node);
579 
580  result = r1 + r2;
581  }
582  else //called by one of the children
583  {
584  //parent node
585  const CEvaluationNode* parent = dynamic_cast<const CEvaluationNode*>(node->getParent());
586 
587  if (parent) r1 = findDimension(parent, node);
588  else r1 = mRootDimension;
589 
590  //other child
591  if (requestingNode == opnode->getLeft())
592  r2 = findDimension(opnode->getRight(), node);
593 
594  if (requestingNode == opnode->getRight())
595  r2 = findDimension(opnode->getLeft(), node);
596 
597  result = r1 - r2;
598  }
599  }
600  break;
601 
603  {
604  CDimension r1, r2;
605 
606  if (requestingNode == node->getParent()) //called by parent
607  {
608  r1 = findDimension(opnode->getLeft(), node);
609  r2 = findDimension(opnode->getRight(), node);
610 
611  result = r1 - r2;
612  }
613  else //called by one of the children
614  {
615  //parent node
616  const CEvaluationNode* parent = dynamic_cast<const CEvaluationNode*>(node->getParent());
617 
618  if (parent) r1 = findDimension(parent, node);
619  else r1 = mRootDimension;
620 
621  //other child
622  if (requestingNode == opnode->getLeft())
623  {
624  r2 = findDimension(opnode->getRight(), node);
625  result = r1 + r2;
626  }
627 
628  if (requestingNode == opnode->getRight())
629  {
630  r2 = findDimension(opnode->getLeft(), node);
631  result = r2 - r1;
632  }
633  }
634  }
635  break;
636 
637  default:
638  break;
639  }
640  }
641 
642  //number node
643  const CEvaluationNodeNumber* numnode = dynamic_cast<const CEvaluationNodeNumber*>(node);
644 
645  if (numnode)
646  {
647  //heuristics!
648  if (mUseHeuristics && (numnode->getValue() == 1.0))
649  result.setDimension(0, 0, 0, 0, 0);
650  }
651 
652  return result;
653 }
CDimension compare(const CDimension &rhs) const
Definition: CDimension.cpp:219
const C_FLOAT64 & getValue() const
CDimension mRootDimension
Definition: CDimension.h:165
#define fatalError()
const Type & getType() const
void findDimension(size_t index)
find dim for one parameter
Definition: CDimension.cpp:453
std::vector< CDimension > mDimensions
Definition: CDimension.h:164
void setUnknown()
Definition: CDimension.cpp:28
CCopasiNode< Data > * getParent()
Definition: CCopasiNode.h:139
void setDimension(const C_FLOAT64 &d1, const C_FLOAT64 &d2, const C_FLOAT64 &d3, const C_FLOAT64 &d4, const C_FLOAT64 &d5)
Definition: CDimension.cpp:48
void CFindDimensions::findDimensions ( CDimension  rootDim)

find the dimensions from explicitly given root node dimension

Definition at line 340 of file CDimension.cpp.

References findDimensions(), and mRootDimension.

341 {
342  mRootDimension = rootDim;
343  findDimensions();
344 }
CDimension mRootDimension
Definition: CDimension.h:165
void findDimensions()
find dim for all parameters
Definition: CDimension.cpp:383
void CFindDimensions::findDimensions ( bool  isMulticompartment)

find the dimensions for a function that is used in a reaction the dimension of the root node depends on the number of compartments that are involved in the reaction

Definition at line 346 of file CDimension.cpp.

References findDimensions(), CDimension::fixDimensionless(), mD1, mD2, mD3, mD4, mD5, mRootDimension, and CDimension::setDimension().

347 {
348  if (isMulticompartment)
349  mRootDimension.setDimension(1, 0, -1, 0, 0); //amount of subs/time
350  else
351  mRootDimension.setDimension(1, -1, -1, 0, 0); //TODO !!! conc/time
352 
354 
355  findDimensions();
356 }
CDimension mRootDimension
Definition: CDimension.h:165
void fixDimensionless(bool d1, bool d2, bool d3, bool d4, bool d5)
Definition: CDimension.cpp:263
void findDimensions()
find dim for all parameters
Definition: CDimension.cpp:383
void setDimension(const C_FLOAT64 &d1, const C_FLOAT64 &d2, const C_FLOAT64 &d3, const C_FLOAT64 &d4, const C_FLOAT64 &d5)
Definition: CDimension.cpp:48
void CFindDimensions::findDimensions ( )
private

find dim for all parameters

Definition at line 383 of file CDimension.cpp.

References findDimension(), findDimensionsMassAction(), CFunction::getVariables(), mDimensions, mpFunction, and CFunctionParameters::size().

Referenced by findDimensions(), and findDimensionsBoth().

384 {
385  if (!mpFunction) return;
386 
387  if (dynamic_cast<const CMassAction*>(mpFunction))
388  {
390  return;
391  }
392 
393  size_t i, imax = mpFunction->getVariables().size();
394 
395  for (i = 0; i < imax; ++i)
396  if (mDimensions[i].isUnknown())
397  findDimension(i);
398 
399  for (i = 0; i < imax; ++i)
400  if (mDimensions[i].isUnknown())
401  findDimension(i);
402 
403  for (i = 0; i < imax; ++i)
404  if (mDimensions[i].isUnknown())
405  findDimension(i);
406 
407  //TODO: conistency check for known dimensions?
408 }
void findDimension(size_t index)
find dim for one parameter
Definition: CDimension.cpp:453
std::vector< CDimension > mDimensions
Definition: CDimension.h:164
const CFunction * mpFunction
Definition: CDimension.h:163
void findDimensionsMassAction()
Definition: CDimension.cpp:430
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
std::vector< std::string > CFindDimensions::findDimensionsBoth ( const CModel pModel)

find the dimensions for both a one-compartment and a multi-compartment reaction

Definition at line 358 of file CDimension.cpp.

References findDimensions(), mDimensions, and setupDimensions().

359 {
360  //first for single compartment
361  findDimensions(false);
362  std::vector<CDimension> store = mDimensions;
363 
364  //next for multiple compartments
365  setupDimensions();
366  findDimensions(true);
367 
368  //compare...
369  std::vector<std::string> ret;
370  std::vector<CDimension>::const_iterator it1, it2, it1end = store.end();
371 
372  for (it1 = store.begin(), it2 = mDimensions.begin(); it1 != it1end; ++it1, ++it2)
373  {
374  if (*it1 == *it2)
375  ret.push_back(it1->getDisplayString(pModel));
376  else
377  ret.push_back(it1->getDisplayString(pModel) + " or " + it2->getDisplayString(pModel));
378  }
379 
380  return ret;
381 }
std::vector< CDimension > mDimensions
Definition: CDimension.h:164
void setupDimensions()
Definition: CDimension.cpp:295
void findDimensions()
find dim for all parameters
Definition: CDimension.cpp:383
void CFindDimensions::findDimensionsMassAction ( )
private

determine dimensions for mass action kinetics chemical equation needs to be known

Definition at line 430 of file CDimension.cpp.

References CDimension::fixDimensionless(), mD1, mD2, mD3, mD4, mD5, mDimensions, mM1, mM2, mRootDimension, and CDimension::setDimension().

Referenced by findDimensions().

431 {
432  if (mM1 < 0) return;
433 
434  CDimension conc; conc.setDimension(1.0, -1.0, 0.0, 0, 0); //TODO!!!
435 
437  conc.fixDimensionless(mD1, mD2, mD3, mD4, mD5);
438 
439  if (mDimensions[0].isUnknown())
440  {
441  mDimensions[0] = mRootDimension - conc * mM1;
442  }
443 
444  if (mDimensions.size() == 2) return; //irreversible
445 
446  if (mDimensions[2].isUnknown())
447  {
448  mDimensions[2] = mRootDimension - conc * mM2;
449  }
450 }
CDimension mRootDimension
Definition: CDimension.h:165
void fixDimensionless(bool d1, bool d2, bool d3, bool d4, bool d5)
Definition: CDimension.cpp:263
C_FLOAT64 mM2
Definition: CDimension.h:169
std::vector< CDimension > mDimensions
Definition: CDimension.h:164
void setDimension(const C_FLOAT64 &d1, const C_FLOAT64 &d2, const C_FLOAT64 &d3, const C_FLOAT64 &d4, const C_FLOAT64 &d5)
Definition: CDimension.cpp:48
C_FLOAT64 mM1
Definition: CDimension.h:168
const std::vector< CDimension > & CFindDimensions::getDimensions ( ) const

Definition at line 335 of file CDimension.cpp.

References mDimensions.

336 {
337  return mDimensions;
338 }
std::vector< CDimension > mDimensions
Definition: CDimension.h:164
void CFindDimensions::setChemicalEquation ( const CChemEq eq)

tell about chemical equation. This is needed only for mass action kinetics. It is ignored otherwise.

Definition at line 410 of file CDimension.cpp.

References C_FLOAT64, CChemEq::getMolecularity(), mM1, mM2, CChemEq::PRODUCT, and CChemEq::SUBSTRATE.

411 {
412  //mpChemEq = eq;
413  if (!eq)
414  {
415  mM1 = 0.0; mM2 = 0.0;
416  return;
417  }
418 
421 }
C_FLOAT64 mM2
Definition: CDimension.h:169
#define C_FLOAT64
Definition: copasi.h:92
size_t getMolecularity(const MetaboliteRole role) const
Definition: CChemEq.cpp:210
C_FLOAT64 mM1
Definition: CDimension.h:168
void CFindDimensions::setMolecularitiesForMassAction ( const size_t &  m1,
const size_t &  m2 
)

Definition at line 423 of file CDimension.cpp.

References C_INVALID_INDEX, mM1, and mM2.

425 {
426  mM1 = (m1 != C_INVALID_INDEX) ? m1 : -1.0;
427  mM2 = (m2 != C_INVALID_INDEX) ? m2 : -1.0;
428 }
#define C_INVALID_INDEX
Definition: copasi.h:222
C_FLOAT64 mM2
Definition: CDimension.h:169
C_FLOAT64 mM1
Definition: CDimension.h:168
void CFindDimensions::setupDimensions ( )

initialize the known dimensions (from the parameter roles) and set the others to "unknown". This is called by the constructor.

Definition at line 295 of file CDimension.cpp.

References CFunction::getVariables(), mD1, mD2, mD3, mD4, mD5, mDimensions, CFunctionParameter::MODIFIER, mpFunction, CFunctionParameter::PRODUCT, CFunctionParameters::size(), CFunctionParameter::SUBSTRATE, CFunctionParameter::TIME, and CFunctionParameter::VOLUME.

Referenced by CFindDimensions(), and findDimensionsBoth().

296 {
297  if (!mpFunction) return;
298 
300 
301  size_t i, imax = mpFunction->getVariables().size();
302 
303  for (i = 0; i < imax; ++i)
304  {
305  switch (mpFunction->getVariables()[i]->getUsage())
306  {
310  mDimensions[i].setDimension(1, -1, 0, 0, 0); //concentration
311  break;
312 
314  mDimensions[i].setUnknown(); // TODO Dimension(0, 1, 0); //volume
315  break;
316 
318  mDimensions[i].setDimension(0, 0, 1, 0, 0); //time
319  break;
320 
321  default:
322  mDimensions[i].setUnknown();
323  break;
324  }
325 
326  mDimensions[i].fixDimensionless(mD1, mD2, mD3, mD4, mD5);
327  }
328 }
std::vector< CDimension > mDimensions
Definition: CDimension.h:164
const CFunction * mpFunction
Definition: CDimension.h:163
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
void CFindDimensions::setUseHeuristics ( bool  flag)

Member Data Documentation

bool CFindDimensions::mD1
private

Definition at line 171 of file CDimension.h.

Referenced by findDimensions(), findDimensionsMassAction(), and setupDimensions().

bool CFindDimensions::mD2
private

Definition at line 172 of file CDimension.h.

Referenced by findDimensions(), findDimensionsMassAction(), and setupDimensions().

bool CFindDimensions::mD3
private

Definition at line 173 of file CDimension.h.

Referenced by findDimensions(), findDimensionsMassAction(), and setupDimensions().

bool CFindDimensions::mD4
private

Definition at line 174 of file CDimension.h.

Referenced by findDimensions(), findDimensionsMassAction(), and setupDimensions().

bool CFindDimensions::mD5
private

Definition at line 175 of file CDimension.h.

Referenced by findDimensions(), findDimensionsMassAction(), and setupDimensions().

std::vector<CDimension> CFindDimensions::mDimensions
private
C_FLOAT64 CFindDimensions::mM1
private
C_FLOAT64 CFindDimensions::mM2
private
const CFunction* CFindDimensions::mpFunction
private

Definition at line 163 of file CDimension.h.

Referenced by findDimension(), findDimensions(), and setupDimensions().

CDimension CFindDimensions::mRootDimension
private

Definition at line 165 of file CDimension.h.

Referenced by findDimension(), findDimensions(), and findDimensionsMassAction().

bool CFindDimensions::mUseHeuristics
private

Definition at line 166 of file CDimension.h.

Referenced by findDimension(), and setUseHeuristics().


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