Exemple #1
0
void CLsodaMethod::maskRoots(CVectorCore< C_FLOAT64 > & rootValues)
{
  const bool *pMask = mRootMask.array();
  const bool *pMaskEnd = pMask + mRootMask.size();
  C_FLOAT64 * pRoot = rootValues.array();

  for (; pMask != pMaskEnd; ++pMask, ++pRoot)
    {
      if (*pMask)
        {
          *pRoot = 1.0;
        }
    }
}
bool CTrajectoryMethodDsaLsodar::CPartition::rePartition(const CVectorCore< C_FLOAT64 > & state)
{
  // Modify the partition if species values move beyond the threshold
  const C_FLOAT64 * pValue = state.array() + mFirstReactionSpeciesIndex;
  const C_FLOAT64 * pValueEnd = pValue + mNumReactionSpecies;
  bool * pStochasticSpecies = mStochasticSpecies.array();

  bool PartitionChanged = false;

  size_t Index = 0;

  for (; pValue != pValueEnd; ++pValue, ++Index, ++pStochasticSpecies)
    {
      if (!*pStochasticSpecies && *pValue < mLowerThreshold)
        {
          *pStochasticSpecies = true;
          PartitionChanged = true;

          std::pair< speciesToReactionsMap::const_iterator, speciesToReactionsMap::const_iterator > Range
            = mSpeciesToReactions.equal_range(Index);

          for (; Range.first != Range.second; ++Range.first)
            {
              (*Range.first->second)++;
            }
        }
      else if (*pStochasticSpecies && *pValue > mUpperThreshold)
        {
          *pStochasticSpecies = false;
          PartitionChanged = true;

          std::pair< speciesToReactionsMap::const_iterator, speciesToReactionsMap::const_iterator > Range
            = mSpeciesToReactions.equal_range(Index);

          for (; Range.first != Range.second; ++Range.first)
            {
              (*Range.first->second)--;
            }
        }
    }

  if (!PartitionChanged)
    {
      return false;
    }

  PartitionChanged = false;

  // Reactions for which the count of species with low numbers is non zero
  // are treated stochastically.
  const size_t * pLow = mNumLowSpecies.array();
  const size_t * pLowEnd = pLow + mNumLowSpecies.size();
  const CMathReaction ** ppStochastic = mStochasticReactions.array();
  const CMathReaction ** ppDeterministic = mDeterministicReactions.array();
  mHasStochastic = false;
  mHasDeterministic = false;

  for (; pLow != pLowEnd; ++pLow, ++ppStochastic, ++ppDeterministic)
    {
      if (*pLow != 0)
        {
          mHasStochastic = true;

          if (*ppDeterministic != NULL)
            {
              PartitionChanged = true;
              *ppStochastic = *ppDeterministic;
              *ppDeterministic = NULL;
            }
        }
      else
        {
          mHasDeterministic = true;

          if (*ppStochastic != NULL)
            {
              PartitionChanged = true;
              *ppDeterministic = *ppStochastic;
              *ppStochastic = NULL;
            }
        }
    }

  if (PartitionChanged)
    {
      // determineStochasticSpecies();
    }

  return PartitionChanged;
}