コード例 #1
0
ファイル: TaskWidget.cpp プロジェクト: copasi/COPASI
bool TaskWidget::commonRunTask()
{
  // Initialize the task
  try
    {
      assert(mpDataModel != NULL);

      if (!mpTask->initialize(CCopasiTask::OUTPUT_UI, mpDataModel, NULL))
        throw CCopasiException(CCopasiMessage::peekLastMessage());
    }

  catch (CCopasiException & /*Exception*/)
    {
      if (CCopasiMessage::peekLastMessage().getNumber() != MCCopasiMessage + 1)
        {
          if (mProgressBar != NULL) mProgressBar->finish();

          CQMessageBox::critical(this, "Initialization Error",
                                 CCopasiMessage::getAllMessageText().c_str(),
                                 QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton);

          finishTask();
          return false;
        }
    }

  if (CCopasiMessage::getHighestSeverity() > CCopasiMessage::ERROR)
    {
      if (mProgressBar != NULL) mProgressBar->finish();

      CQMessageBox::critical(this, "Initialization Error",
                             CCopasiMessage::getAllMessageText().c_str(),
                             QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton);

      finishTask();
      return false;
    }

  if (CCopasiMessage::getHighestSeverity() > CCopasiMessage::COMMANDLINE)
    {
      C_INT Result =
        CQMessageBox::question(this, "Initialization Warning",
                               CCopasiMessage::getAllMessageText().c_str(),
                               QMessageBox::Ignore | QMessageBox::Abort, QMessageBox::Ignore);

      if (Result == QMessageBox::Abort)
        {
          finishTask();
          return false;
        }
    }

  CCopasiMessage::clearDeque();

  // Execute the task
  mpTaskThread->start();

  return true;
}
コード例 #2
0
ファイル: CLyapTask.cpp プロジェクト: jonasfoe/COPASI
bool CLyapTask::process(const bool & useInitialValues)
{
  if (useInitialValues)
    {
      mpContainer->applyInitialValues();
    }

  output(COutputInterface::BEFORE);

  //  bool flagProceed = true;
  mPercentage = 0;

  if (mpCallBack)
    {
      mpCallBack->setName("performing lyapunov exponent calculation...");
      C_FLOAT64 hundred = 100;
      mhProcess = mpCallBack->addItem("Completion",
                                      mPercentage,
                                      &hundred);
    }

  try
    {
      mpLyapMethod->calculate();
    }
  catch (CCopasiException & Exception)
    {
      //mpLyapProblem->getModel()->setState(*mpCurrentState);
      mpContainer->updateSimulatedValues(true);

      calculationsBeforeOutput();
      output(COutputInterface::DURING);

      if (mpCallBack) mpCallBack->finishItem(mhProcess);

      output(COutputInterface::AFTER);

      throw CCopasiException(Exception.getMessage());
    }

  if (mpCallBack) mpCallBack->finishItem(mhProcess);

  calculationsBeforeOutput();
  output(COutputInterface::AFTER);

  mResultAvailable = true;
  mResultHasDivergence = mpLyapProblem->divergenceRequested();
  mModelVariablesInResult = mpContainer->getState(true).size() - mpContainer->getCountFixedEventTargets() - 1;
  mNumExponentsCalculated = mpLyapProblem->getExponentNumber();

  return true;
}
コード例 #3
0
ファイル: CCrossSectionTask.cpp プロジェクト: PriKalra/COPASI
bool CCrossSectionTask::process(const bool & useInitialValues)
{
  processStart(useInitialValues);

  //this instructs the process queue to call back whenever an event is
  //executed
  mpCrossSectionProblem->getModel()->getMathModel()->getProcessQueue().setEventCallBack(this, &EventCallBack);

  mPreviousCrossingTime = std::numeric_limits< C_FLOAT64 >::quiet_NaN();
  mPeriod = std::numeric_limits< C_FLOAT64 >::quiet_NaN();
  mAveragePeriod = std::numeric_limits< C_FLOAT64 >::quiet_NaN();
  mLastPeriod = std::numeric_limits< C_FLOAT64 >::quiet_NaN();
  mPeriodicity = -1;
  mLastFreq = std::numeric_limits< C_FLOAT64 >::quiet_NaN();
  mFreq = std::numeric_limits< C_FLOAT64 >::quiet_NaN();
  mAverageFreq = std::numeric_limits< C_FLOAT64 >::quiet_NaN();

  C_FLOAT64 MaxDuration = mpCrossSectionProblem->getDuration();

  //the output starts only after "outputStartTime" has passed
  if (mpCrossSectionProblem->getFlagLimitOutTime())
    {
      mOutputStartTime = *mpCurrentTime + mpCrossSectionProblem->getOutputStartTime();
      MaxDuration += mpCrossSectionProblem->getOutputStartTime();
    }
  else
    {
      mOutputStartTime = *mpCurrentTime;
    }

  const C_FLOAT64 EndTime = *mpCurrentTime + MaxDuration;

  mStartTime = *mpCurrentTime;

  // It suffices to reach the end time within machine precision
  C_FLOAT64 CompareEndTime = mOutputStartTime - 100.0 * (fabs(EndTime) * std::numeric_limits< C_FLOAT64 >::epsilon() + std::numeric_limits< C_FLOAT64 >::min());

  if (mpCrossSectionProblem->getFlagLimitCrossings())
    mMaxNumCrossings = mpCrossSectionProblem->getCrossingsLimit();
  else
    mMaxNumCrossings = 0;

  if (mpCrossSectionProblem->getFlagLimitOutCrossings())
    mOutputStartNumCrossings = mpCrossSectionProblem->getOutCrossingsLimit();
  else
    mOutputStartNumCrossings = 0;

  output(COutputInterface::BEFORE);

  bool flagProceed = true;
  mProgressFactor = 100.0 / (MaxDuration + mpCrossSectionProblem->getOutputStartTime());
  mProgressValue = 0;

  if (mpCallBack != NULL)
    {
      mpCallBack->setName("performing simulation...");
      mProgressMax = 100.0;
      mhProgress = mpCallBack->addItem("Completion",
                                       mProgressValue,
                                       &mProgressMax);
    }

  mState = TRANSIENT;
  mStatesRingCounter = 0;

  mNumCrossings = 0;

  try
    {
      do
        {
          flagProceed &= processStep(EndTime);
        }
      while ((*mpCurrentTime < CompareEndTime) && flagProceed);
    }

  catch (int)
    {
      mpCrossSectionProblem->getModel()->setState(*mpCurrentState);
      mpCrossSectionProblem->getModel()->updateSimulatedValues(mUpdateMoieties);
      finish();
      CCopasiMessage(CCopasiMessage::EXCEPTION, MCTrajectoryMethod + 16);
    }

  catch (CCopasiException & Exception)
    {
      mpCrossSectionProblem->getModel()->setState(*mpCurrentState);
      mpCrossSectionProblem->getModel()->updateSimulatedValues(mUpdateMoieties);
      finish();
      throw CCopasiException(Exception.getMessage());
    }

  finish();

  return true;
}
コード例 #4
0
ファイル: CTSSATask.cpp プロジェクト: nabel/copasi-simple-api
bool CTSSATask::process(const bool & useInitialValues)
{
    //*****

    processStart(useInitialValues);

    //*****

    C_FLOAT64 StepSize = mpTSSAProblem->getStepSize();
    C_FLOAT64 NextTimeToReport;

    const C_FLOAT64 EndTime = *mpCurrentTime + mpTSSAProblem->getDuration();
    const C_FLOAT64 StartTime = *mpCurrentTime;

    C_FLOAT64 StepNumber = (mpTSSAProblem->getDuration()) / StepSize;

    bool (*LE)(const C_FLOAT64 &, const C_FLOAT64 &);
    bool (*L)(const C_FLOAT64 &, const C_FLOAT64 &);

    if (StepSize < 0.0)
    {
        LE = &tble;
        L = &tbl;
    }
    else
    {
        LE = &tfle;
        L = &tfl;
    }

    unsigned C_INT32 StepCounter = 1;

    C_FLOAT64 outputStartTime = mpTSSAProblem->getOutputStartTime();

    if (StepSize == 0.0 && mpTSSAProblem->getDuration() != 0.0)
    {
        CCopasiMessage(CCopasiMessage::ERROR, MCTSSAProblem + 1, StepSize);
        return false;
    }

    output(COutputInterface::BEFORE);

    bool flagProceed = true;
    C_FLOAT64 handlerFactor = 100.0 / mpTSSAProblem->getDuration();

    C_FLOAT64 Percentage = 0;
    unsigned C_INT32 hProcess;

    if (mpCallBack)
    {
        mpCallBack->setName("performing simulation...");
        C_FLOAT64 hundred = 100;
        hProcess = mpCallBack->addItem("Completion",
                                       CCopasiParameter::DOUBLE,
                                       &Percentage,
                                       &hundred);
    }

    if ((*LE)(outputStartTime, *mpCurrentTime)) output(COutputInterface::DURING);

    try
    {
        do
        {
            // This is numerically more stable then adding
            // mpTSSAProblem->getStepSize().
            NextTimeToReport =
                StartTime + (EndTime - StartTime) * StepCounter++ / StepNumber;

            flagProceed &= processStep(NextTimeToReport);

            if (mpCallBack)
            {
                Percentage = (*mpCurrentTime - StartTime) * handlerFactor;
                flagProceed &= mpCallBack->progressItem(hProcess);
            }

            if ((*LE)(outputStartTime, *mpCurrentTime))
            {
                output(COutputInterface::DURING);
            }
        }
        while ((*L)(*mpCurrentTime, EndTime) && flagProceed);
    }

    catch (int)
    {
        mpTSSAProblem->getModel()->setState(*mpCurrentState);
        mpTSSAProblem->getModel()->updateSimulatedValues(true);

        if ((*LE)(outputStartTime, *mpCurrentTime))
        {
            output(COutputInterface::DURING);
        }

        if (mpCallBack) mpCallBack->finishItem(hProcess);

        output(COutputInterface::AFTER);

        CCopasiMessage(CCopasiMessage::EXCEPTION, MCTSSAMethod + 4);
    }

    catch (CCopasiException Exception)
    {
        mpTSSAProblem->getModel()->setState(*mpCurrentState);
        mpTSSAProblem->getModel()->updateSimulatedValues(true);

        if ((*LE)(outputStartTime, *mpCurrentTime))
        {
            output(COutputInterface::DURING);
        }

        if (mpCallBack) mpCallBack->finishItem(hProcess);

        output(COutputInterface::AFTER);

        throw CCopasiException(Exception.getMessage());
    }

    if (mpCallBack) mpCallBack->finishItem(hProcess);

    output(COutputInterface::AFTER);

    return true;
}
コード例 #5
0
void CCopasiMessage::handler(const bool & /* _throw */)
{
  std::string Text = mText;

  switch (mType)
    {
    case RAW:
      mText = "";
      break;

    case TRACE:
      mText = ">TRACE ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case COMMANDLINE:
    case WARNING:
      mText = ">WARNING ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case ERROR:
      mText = ">ERROR ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case EXCEPTION:
      mText = ">EXCEPTION ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case RAW_FILTERED:
      mText = ">RAW(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case TRACE_FILTERED:
      mText = ">TRACE(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case COMMANDLINE_FILTERED:
      mText = ">COMMANDLINE(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case WARNING_FILTERED:
      mText = ">WARNING(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case ERROR_FILTERED:
      mText = ">ERROR(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case EXCEPTION_FILTERED:
      mText = ">EXCEPTION(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;
    }

  mText += Text;

  if (mType != RAW) lineBreak();

  // Remove the message: No more messages.
  if (mMessageDeque.size() == 1 &&
      mMessageDeque.back().getNumber() == MCCopasiMessage + 1)
    getLastMessage();

  mMessageDeque.push_back(*this);

  // All messages are printed to std::cerr
  if (COptions::compareValue("Verbose", true) &&
      mNumber != MCCopasiMessage + 1)
    {
      std::cerr << mText << std::endl;

#ifdef COPASI_DEBUG
      DebugFile << mText << std::endl;
#endif // COPASI_DEBUG
    }

  if (mType == EXCEPTION)
    throw CCopasiException(*this);
}
コード例 #6
0
ファイル: CTrajectoryTask.cpp プロジェクト: cpanchal/COPASI
bool CTrajectoryTask::process(const bool & useInitialValues)
{
  //*****

  processStart(useInitialValues);

  //*****

  //size_t FailCounter = 0;

  C_FLOAT64 Duration = mpTrajectoryProblem->getDuration();
  C_FLOAT64 StepSize = mpTrajectoryProblem->getStepSize();
  C_FLOAT64 StepNumber = fabs(Duration) / StepSize;

  if (isnan(StepNumber) || StepNumber < 1.0)
    StepNumber = 1.0;

  //the output starts only after "outputStartTime" has passed
  if (useInitialValues)
    mOutputStartTime = mpTrajectoryProblem->getOutputStartTime();
  else
    mOutputStartTime = *mpCurrentTime + mpTrajectoryProblem->getOutputStartTime();

  C_FLOAT64 NextTimeToReport;

  const C_FLOAT64 EndTime = *mpCurrentTime + Duration;
  const C_FLOAT64 StartTime = *mpCurrentTime;
  C_FLOAT64 CompareEndTime;

  if (StepSize < 0.0)
    {
      mpLessOrEqual = &ble;
      mpLess = &bl;

      // It suffices to reach the end time within machine precision
      CompareEndTime = EndTime + 100.0 * (fabs(EndTime) * std::numeric_limits< C_FLOAT64 >::epsilon() + std::numeric_limits< C_FLOAT64 >::min());
    }
  else
    {
      mpLessOrEqual = &fle;
      mpLess = &fl;

      // It suffices to reach the end time within machine precision
      CompareEndTime = EndTime - 100.0 * (fabs(EndTime) * std::numeric_limits< C_FLOAT64 >::epsilon() + std::numeric_limits< C_FLOAT64 >::min());
    }

  unsigned C_INT32 StepCounter = 1;

  if (StepSize == 0.0 && Duration != 0.0)
    {
      CCopasiMessage(CCopasiMessage::ERROR, MCTrajectoryProblem + 1, StepSize);
      return false;
    }

  output(COutputInterface::BEFORE);

  bool flagProceed = true;
  C_FLOAT64 handlerFactor = 100.0 / Duration;

  C_FLOAT64 Percentage = 0;
  size_t hProcess;

  if (mpCallBack != NULL && StepNumber > 1.0)
    {
      mpCallBack->setName("performing simulation...");
      C_FLOAT64 hundred = 100;
      hProcess = mpCallBack->addItem("Completion",
                                     Percentage,
                                     &hundred);
    }

  if ((*mpLessOrEqual)(mOutputStartTime, *mpCurrentTime)) output(COutputInterface::DURING);

  try
    {
      do
        {
          // This is numerically more stable then adding
          // mpTrajectoryProblem->getStepSize().
          NextTimeToReport =
            StartTime + (EndTime - StartTime) * StepCounter++ / StepNumber;

          flagProceed &= processStep(NextTimeToReport);

          if (mpCallBack != NULL && StepNumber > 1.0)
            {
              Percentage = (*mpCurrentTime - StartTime) * handlerFactor;
              flagProceed &= mpCallBack->progressItem(hProcess);
            }

          if ((*mpLessOrEqual)(mOutputStartTime, *mpCurrentTime))
            {
              output(COutputInterface::DURING);
            }
        }
      while ((*mpLess)(*mpCurrentTime, CompareEndTime) && flagProceed);
    }

  catch (int)
    {
      mpTrajectoryProblem->getModel()->setState(*mpCurrentState);
      mpTrajectoryProblem->getModel()->updateSimulatedValues(mUpdateMoieties);

      if ((*mpLessOrEqual)(mOutputStartTime, *mpCurrentTime))
        {
          output(COutputInterface::DURING);
        }

      if (mpCallBack != NULL && StepNumber > 1.0) mpCallBack->finishItem(hProcess);

      output(COutputInterface::AFTER);

      CCopasiMessage(CCopasiMessage::EXCEPTION, MCTrajectoryMethod + 16);
    }

  catch (CCopasiException & Exception)
    {
      mpTrajectoryProblem->getModel()->setState(*mpCurrentState);
      mpTrajectoryProblem->getModel()->updateSimulatedValues(mUpdateMoieties);

      if ((*mpLessOrEqual)(mOutputStartTime, *mpCurrentTime))
        {
          output(COutputInterface::DURING);
        }

      if (mpCallBack != NULL && StepNumber > 1.0) mpCallBack->finishItem(hProcess);

      output(COutputInterface::AFTER);

      throw CCopasiException(Exception.getMessage());
    }

  if (mpCallBack != NULL && StepNumber > 1.0) mpCallBack->finishItem(hProcess);

  output(COutputInterface::AFTER);

  return true;
}