示例#1
0
void NetworkModel::remove_reaction_rule(const ReactionRule& rr)
{
    reaction_rule_container_type::iterator
        i(std::find(reaction_rules_.begin(), reaction_rules_.end(), rr));
    if (i == reaction_rules_.end())
    {
        throw NotFound("reaction rule not found");
    }

    reaction_rule_container_type::size_type const
        idx(i - reaction_rules_.begin()), last_idx(reaction_rules_.size() - 1);
    reaction_rules_map_type::iterator
        j(reaction_rules_map_.find(rr.reactants()));
    if (j == reaction_rules_map_.end())
    {
        throw IllegalState("no corresponding map key found");
    }
    else if ((*j).second.erase(idx) == 0)
    {
        throw IllegalState("no corresponding map value found");
    }

    if (idx < last_idx)
    {
        reaction_rule_container_type::value_type const
            last_value(reaction_rules_[last_idx]);
        (*i) = last_value;
        j = reaction_rules_map_.find(last_value.reactants());
        if (j == reaction_rules_map_.end())
        {
            throw IllegalState("no corresponding map key for the last found");
        }
        else if ((*j).second.erase(last_idx) == 0)
        {
            throw IllegalState("no corresponding map value for the last found");
        }
        (*j).second.insert(idx);
    }

    reaction_rules_.pop_back();
    dirty_ = true;
}
示例#2
0
Real ODERatelawCppCallback::deriv_func(
        state_container_type const &reactants_state_array,
        state_container_type const &products_state_array, 
        Real const volume, Real const t,
        ODEReactionRule const &rr)
{
    if (!is_available())
    {
        throw IllegalState("Callback Function has not been registerd");
    }
    return this->func_(reactants_state_array, products_state_array, volume, t, rr);
}
示例#3
0
文件: Mesh.cpp 项目: kozo2/ecell4
Real3 MeshSurface::draw_position(boost::shared_ptr<RandomNumberGenerator>& rng) const
{
#ifdef HAVE_VTK
    vtkPolyData* polydata = reader_->GetOutput();
    std::vector<double> areas(polydata->GetNumberOfCells());
    for (vtkIdType i(0); i < polydata->GetNumberOfCells(); i++)
    {
        vtkCell* cell = polydata->GetCell(i);
        vtkTriangle* triangle = dynamic_cast<vtkTriangle*>(cell);
        double p0[3];
        double p1[3];
        double p2[3];
        triangle->GetPoints()->GetPoint(0, p0);
        triangle->GetPoints()->GetPoint(1, p1);
        triangle->GetPoints()->GetPoint(2, p2);
        const double area = vtkTriangle::TriangleArea(p0, p1, p2);
        // std::cout << "p0: " << p0[0] << " " << p0[1] << " " << p0[2] << std::endl;
        // std::cout << "p1: " << p1[0] << " " << p1[1] << " " << p1[2] << std::endl;
        // std::cout << "p2: " << p2[0] << " " << p2[1] << " " << p2[2] << std::endl;
        // std::cout << "area of triangle " << i << ": " << area << std::endl;
        areas[i] = area;
    }
    const double rnd = rng->uniform(0.0, std::accumulate(areas.begin(), areas.end(), 0.0));
    double totarea = 0.0;
    for (vtkIdType i(0); i < polydata->GetNumberOfCells(); i++)
    {
        totarea += areas[i];
        if (rnd < totarea)
        {
            vtkCell* cell = polydata->GetCell(i);
            vtkTriangle* triangle = dynamic_cast<vtkTriangle*>(cell);
            double p0[3];
            double p1[3];
            double p2[3];
            triangle->GetPoints()->GetPoint(0, p0);
            triangle->GetPoints()->GetPoint(1, p1);
            triangle->GetPoints()->GetPoint(2, p2);
            const Real3 P0(p0[0], p0[1], p0[2]);
            const Real3 P1(p1[0], p1[1], p1[2]);
            const Real3 P2(p2[0], p2[1], p2[2]);
            const Real p(rng->uniform(0.0, 1.0)), q(rng->uniform(0.0, 1.0 - p));
            return (((P1 - P0) * p + (P2 - P0) * q + P0) + shift_) * ratio_;
        }
    }
    throw IllegalState("Never reach here.");
#else
    throw NotImplemented("not implemented yet.");
#endif
}
示例#4
0
Real ODERatelawCythonCallback::deriv_func(
    state_container_type const &reactants_state_array,
    state_container_type const &products_state_array, 
    Real const volume, Real const t,
    ODEReactionRule const &rr)
{
    if (!is_available())
    {
        throw IllegalState("Callback Function has not been registerd");
    }
    ODEReactionRule rr_tempolrary(rr);
    return this->indirect_func_(
        this->python_func_, reactants_state_array, products_state_array, 
        volume, t, &rr_tempolrary);
}
示例#5
0
    void initialize()
    {
        boost::shared_ptr<Model> expanded(model_->expand(world_->list_species()));
        if (!expanded)
        {
            throw IllegalState("The model failed to be expanded.");
        }
        expanded_.swap(expanded); // use expanded_, but not model_

        const std::vector<Species> species(expanded_->list_species());
        for (std::vector<Species>::const_iterator
            i(species.begin()); i != species.end(); ++i)
        {
            if (!(*world_).has_species(*i))
            {
                (*world_).reserve_species(*i);
            }
        }
    }
示例#6
0
void NetworkModel::remove_reaction_rule(const ReactionRule& rr)
{
    reaction_rule_container_type::iterator
        i(std::find(reaction_rules_.begin(), reaction_rules_.end(), rr));
    if (i == reaction_rules_.end())
    {
        throw NotFound("reaction rule not found");
    }

    reaction_rule_container_type::size_type const
        idx(i - reaction_rules_.begin()), last_idx(reaction_rules_.size() - 1);
    if (rr.reactants().size() == 1)
    {
        first_order_reaction_rules_map_type::iterator
            j(first_order_reaction_rules_map_.find(rr.reactants()[0].serial()));
        if (j == first_order_reaction_rules_map_.end())
        {
            throw IllegalState("no corresponding map key found");
        }

        first_order_reaction_rules_map_type::mapped_type::iterator
            k(std::remove((*j).second.begin(), (*j).second.end(), idx));
        if (k == (*j).second.end())
        {
            throw IllegalState("no corresponding map value found");
        }
        else
        {
            (*j).second.erase(k, (*j).second.end());
        }
    }
    else if (rr.reactants().size() == 2)
    {
        second_order_reaction_rules_map_type::iterator
            j(second_order_reaction_rules_map_.find(std::make_pair(
                rr.reactants()[0].serial(), rr.reactants()[1].serial())));
        if (j == second_order_reaction_rules_map_.end())
        {
            throw IllegalState("no corresponding map key found");
        }

        second_order_reaction_rules_map_type::mapped_type::iterator
            k(std::remove((*j).second.begin(), (*j).second.end(), idx));
        if (k == (*j).second.end())
        {
            throw IllegalState("no corresponding map value found");
        }
        else
        {
            (*j).second.erase(k, (*j).second.end());
        }
    }

    if (idx < last_idx)
    {
        reaction_rule_container_type::value_type const
            last_value(reaction_rules_[last_idx]);
        (*i) = last_value;

        if (last_value.reactants().size() == 1)
        {
            first_order_reaction_rules_map_type::iterator
                j(first_order_reaction_rules_map_.find(
                    last_value.reactants()[0].serial()));
            if (j == first_order_reaction_rules_map_.end())
            {
                throw IllegalState("no corresponding map key for the last found");
            }

            first_order_reaction_rules_map_type::mapped_type::iterator
                k(std::remove((*j).second.begin(), (*j).second.end(), last_idx));
            if (k == (*j).second.end())
            {
                throw IllegalState("no corresponding map value found");
            }
            else
            {
                (*j).second.erase(k, (*j).second.end());
            }
            (*j).second.push_back(idx);
        }
        else if (last_value.reactants().size() == 2)
        {
            second_order_reaction_rules_map_type::iterator
                j(second_order_reaction_rules_map_.find(std::make_pair(
                    last_value.reactants()[0].serial(),
                    last_value.reactants()[1].serial())));
            if (j == second_order_reaction_rules_map_.end())
            {
                throw IllegalState("no corresponding map key for the last found");
            }
            second_order_reaction_rules_map_type::mapped_type::iterator
                k(std::remove((*j).second.begin(), (*j).second.end(), last_idx));
            if (k == (*j).second.end())
            {
                throw IllegalState("no corresponding map value found");
            }
            else
            {
                (*j).second.erase(k, (*j).second.end());
            }
            (*j).second.push_back(idx);
        }
    }

    reaction_rules_.pop_back();
}
示例#7
0
/* Parses a key, checks whether or not it is legal.
 * Returns
 * 1 if the key is illegal (a nested error message is printed)
 * , 0 if succesfull.
 */
static int ParseKey(
  LOOK_UP_KEY *k,  /* write-only key, if k->t == TEST_NOKEY
                   * then the end of file is reached
                   */
   CSF_VS vs)  /* value scale */
 {
      typedef enum STATE { STATE_START, STATE_LOWNUM, STATE_COMMA,
             STATE_HIGHNUM, STATE_HIGHTOKEN } STATE;
      STATE state = STATE_START;
      int t; /* token */
      long    startLineNr = LexGetLineNr();
  while(1)
  {
      t = LexGetToken();
      if (t >= 0 && LexGetLineNr() != startLineNr)
      {
        if (state == STATE_START) /* parsed empty line */
          startLineNr = LexGetLineNr();
        else
          t = LEX_EOL;
      }
      switch(state)
      {
    case STATE_START: switch(t) {
       case LEX_NUMBER:
      k->t = TEST_ONE;
          if (SetNumber(k, TRUE, vs))
            return 1;
          return 0;
           case '[' :
                 k->t = TEST_GE_INF;
                 state = STATE_LOWNUM;
                 break;
           case '<' :
                 k->t = TEST_GT_INF;
                 state = STATE_LOWNUM;
                 break;
           case 0   :
                 k->t = TEST_NOKEY;
                 return 0;
           default : return IllegalState(k,t,"$[<");
        } break;
        case STATE_LOWNUM:
     PRECOND(k->t == TEST_GE_INF || k->t == TEST_GT_INF);
         switch(t) {
       case LEX_NUMBER:
          if (SetNumber(k, TRUE, vs))
            return 1;
          state = STATE_COMMA;
          break;
       case ',':
      k->t = TEST_INF_INF;
          state = STATE_HIGHNUM;
          break;
           default : return IllegalState(k,t,"$,");
         } break;
        case STATE_COMMA:
          if (t != ',')
            return IllegalState(k,t,",");
          state = STATE_HIGHNUM;
          break;
        case STATE_HIGHNUM:
         POSTCOND(k->t==TEST_GE_INF||k->t==TEST_GT_INF ||k->t==TEST_INF_INF);
          switch(t) {
       case LEX_NUMBER:
          if (SetNumber(k, FALSE, vs))
            return 1;
          state = STATE_HIGHTOKEN;
          if (k->t != TEST_INF_INF && (k->l > k->h) )
          {
           k->t = TEST_ERROR; // pcrcalc/test69
           return RetErrorNested(1,"low value ('%g') of range larger than high value ('%g')", k->l,k->h);
          }
          break;
           case ']':
           case '>':
                 /* already set, by choosing
                  * intermediate states of k->t
                  */
                return 0;
           default : return IllegalState(k,t,"$]>");
          }break;
    case STATE_HIGHTOKEN:
         POSTCOND(k->t==TEST_GE_INF||k->t==TEST_GT_INF ||k->t==TEST_INF_INF);
         switch(t) {
           /* inc over enums, that's why particular order */
           case ']':
             k->t += 3;
             return 0;
           case '>':
             k->t += 6;
             return 0;
           default : return IllegalState(k,t,"]>");
         } break;
      } /* eoswitch state */
      } /* eowhile */
}