Esempio n. 1
0
bool CSteadyStateTask::initialize(const OutputFlag & of,
                                  COutputHandler * pOutputHandler,
                                  std::ostream * pOstream)
{
  bool success = true;

  assert(mpProblem && mpMethod);

  CSteadyStateProblem* pProblem =
    dynamic_cast<CSteadyStateProblem *>(mpProblem);
  assert(pProblem);

  success &= pProblem->initialize();

  CSteadyStateMethod* pMethod =
    dynamic_cast<CSteadyStateMethod *>(mpMethod);
  assert(pMethod);

  success &= pMethod->initialize(pProblem);

  success &= pMethod->isValidProblem(mpProblem);

  success &= updateMatrices();

  mSteadyState = mpContainer->getState(true);

  success &= CCopasiTask::initialize(of, pOutputHandler, pOstream);

  return success;
}
Esempio n. 2
0
bool CSteadyStateTask::process(const bool & useInitialValues)
{
  if (useInitialValues)
    {
      mpProblem->getModel()->applyInitialValues();
    }

  *mpSteadyState = mpProblem->getModel()->getState();

  // A steady-state makes only sense in an autonomous model,
  // i.e., the time of the steady-state must not be changed
  // during simulation.
  C_FLOAT64 InitialTime = mpSteadyState->getTime();

  CSteadyStateMethod* pMethod =
    dynamic_cast<CSteadyStateMethod *>(mpMethod);
  assert(pMethod);

  CSteadyStateProblem* pProblem =
    dynamic_cast<CSteadyStateProblem *>(mpProblem);
  assert(pMethod);

  output(COutputInterface::BEFORE);

  //call the method
  mResult = pMethod->process(mpSteadyState,
                             mJacobianX,
                             mpCallBack);

  if (mResult == CSteadyStateMethod::notFound)
    restore();

  //update jacobian
  if (pProblem->isJacobianRequested() ||
      pProblem->isStabilityAnalysisRequested())
    {
      pMethod->doJacobian(mJacobian, mJacobianX);
    }

  //mpProblem->getModel()->setState(mpSteadyState);
  //mpProblem->getModel()->updateRates();

  //calculate eigenvalues
  if (pProblem->isStabilityAnalysisRequested())
    {
      mEigenValues.calcEigenValues(mJacobian);
      mEigenValuesX.calcEigenValues(mJacobianX);

      mEigenValues.stabilityAnalysis(pMethod->getStabilityResolution());
      mEigenValuesX.stabilityAnalysis(pMethod->getStabilityResolution());
    }

  // Reset the time.
  mpSteadyState->setTime(InitialTime);

  C_FLOAT64 * pTo;
  size_t i;

  // construct Eigenvalues of Jacobian
  CVector< C_FLOAT64 > vectorEigen_R = mEigenValues.getR();
  CVector< C_FLOAT64 > vectorEigen_I = mEigenValues.getI();

#ifdef DEBUG_UI
  C_INT32 size = vectorEigen_R.size() + vectorEigen_I.size();

  std::cout << "vectorEigen_R.size() = " << vectorEigen_R.size() << " + vectorEigen_I.size() = " << vectorEigen_I.size() << " == " << size << std::endl;
  std::cout << "size = " << mEigenvaluesXMatrix.size() << std::endl;
#endif
  assert(vectorEigen_R.size() == vectorEigen_I.size());

  pTo = mEigenvaluesMatrix.array();

  for (i = 0; i < vectorEigen_R.size(); ++i)
    {
      *pTo = vectorEigen_R[i]; ++pTo;
      *pTo = vectorEigen_I[i]; ++pTo;
    }

#ifdef DEBUG_UI
  std::cout << mEigenvaluesMatrix << std::endl;
#endif

  // construct Eigenvalues of Jacobian of reduced system
  CVector< C_FLOAT64 > vectorEigenX_R = mEigenValuesX.getR();
  CVector< C_FLOAT64 > vectorEigenX_I = mEigenValuesX.getI();

#ifdef DEBUG_UI
  C_INT32 sizeX = vectorEigenX_R.size() + vectorEigenX_I.size();

  std::cout << "vectorEigenX_R.size() = " << vectorEigenX_R.size() << " + vectorEigenX_I.size() = " << vectorEigenX_I.size() << " == " << sizeX << std::endl;
  std::cout << "size = " << mEigenvaluesXMatrix.size() << std::endl;
#endif

  assert(vectorEigenX_R.size() == vectorEigenX_I.size());

  pTo = mEigenvaluesXMatrix.array();

  for (i = 0; i < vectorEigenX_R.size(); ++i)
    {
      *pTo = vectorEigenX_R[i]; ++pTo;
      *pTo = vectorEigenX_I[i]; ++pTo;
    }

#ifdef DEBUG_UI
  std::cout << mEigenvaluesXMatrix << std::endl;
#endif

  output(COutputInterface::AFTER);

  return (mResult != CSteadyStateMethod::notFound);
}
Esempio n. 3
0
bool CSteadyStateTask::initialize(const OutputFlag & of,
                                  COutputHandler * pOutputHandler,
                                  std::ostream * pOstream)
{
  assert(mpProblem && mpMethod);

  if (!mpMethod->isValidProblem(mpProblem)) return false;

  bool success = true;

  if (!updateMatrices())
    return false;

  success &= CCopasiTask::initialize(of, pOutputHandler, pOstream);

  pdelete(mpSteadyState);
  mpSteadyState = new CState(mpProblem->getModel()->getInitialState());

  mCalculateReducedSystem = (mpProblem->getModel()->getNumDependentReactionMetabs() != 0);

#ifdef xxxx
  // init Jacobians
  size_t sizeX = mpSteadyState->getNumIndependent();
  mJacobianX.resize(sizeX, sizeX);
  size_t size = sizeX + mpSteadyState->getNumDependent();
  mJacobian.resize(size, size);

  //jacobian annotations
  CStateTemplate & StateTemplate = mpProblem->getModel()->getStateTemplate();

  mpJacobianAnn->resize();
  CModelEntity **ppEntities = StateTemplate.getEntities();
  const size_t * pUserOrder = StateTemplate.getUserOrder().array();
  const size_t * pUserOrderEnd = pUserOrder + StateTemplate.getUserOrder().size();

  pUserOrder++; // We skip the time which is the first.

  size_t i, imax = size;

  for (i = 0; i < imax && pUserOrder != pUserOrderEnd; pUserOrder++)
    {
      const CModelEntity::Status & Status = ppEntities[*pUserOrder]->getStatus();

      if (Status == CModelEntity::ODE ||
          (Status == CModelEntity::REACTIONS && ppEntities[*pUserOrder]->isUsed()))
        {
          mpJacobianAnn->setAnnotationCN(0 , i, ppEntities[*pUserOrder]->getCN());
          mpJacobianAnn->setAnnotationCN(1 , i, ppEntities[*pUserOrder]->getCN());

          i++;
        }
    }

  mpJacobianXAnn->resize();

  ppEntities = StateTemplate.beginIndependent();
  imax = sizeX;

  for (i = 0; i < imax; ++i, ++ppEntities)
    {
      mpJacobianXAnn->setAnnotationCN(0 , i, (*ppEntities)->getCN());
      mpJacobianXAnn->setAnnotationCN(1 , i, (*ppEntities)->getCN());
    }

#endif

  CSteadyStateProblem* pProblem =
    dynamic_cast<CSteadyStateProblem *>(mpProblem);
  assert(pProblem);

  success &= pProblem->initialize();

  CSteadyStateMethod* pMethod =
    dynamic_cast<CSteadyStateMethod *>(mpMethod);
  assert(pMethod);

  success &= pMethod->initialize(pProblem);

  return success;
}