Exemple #1
0
  public void checkEquations(HashMap<String, Dimensional> cdimHM) throws ContentError {

    HashMap<String, Dimensional> dimHM = new HashMap<String, Dimensional>();

    dimHM.putAll(cdimHM);

    for (RequiredVar rv : p_requiredVars) {
      dimHM.put(rv.getName(), rv.getDimensionality());
    }

    for (StateVariable sv : stateVariables) {
      dimHM.put(sv.getName(), sv.getDimensionality());
    }

    for (FinalParam fp : r_type.getFinalParams()) {
      dimHM.put(fp.getName(), fp.getDimensionality());
    }

    for (InstanceProperty ip : r_type.getInstancePropertys()) {
      dimHM.put(ip.getName(), ip.getDimensionality());
    }

    ExprDimensional tdim = new ExprDimensional();
    tdim.setT(1);
    dimHM.put("t", tdim);

    for (DerivedVariable dv : derivedVariables) {
      try {
        dimHM.put(dv.getName(), dv.getDimensionality(dimHM));
      } catch (ContentError ce) {
        E.error("Checking " + dv + " in " + r_type + " " + ce.getMessage());
      }
    }

    for (ConditionalDerivedVariable cdv : conditionalDerivedVariables) {
      try {
        dimHM.put(cdv.getName(), cdv.getDimensionality(dimHM));
      } catch (ContentError ce) {
        E.error("Checking " + cdv + " in " + r_type + " " + ce.getMessage());
      }
    }

    for (TimeDerivative td : timeDerivatives) {
      td.checkDimensions(dimHM);
    }
    for (PointResponse pr : onStarts) {
      pr.checkEquations(dimHM);
    }
    for (PointResponse pr : onEvents) {
      pr.checkEquations(dimHM);
    }
    for (OnCondition oc : onConditions) {
      oc.checkEquations(dimHM);
      oc.checkConditionDimensions(dimHM);
    }
  }
Exemple #2
0
  public StateType makeStateType(Component cpt, HashMap<String, Double> fixedHM)
      throws ContentError, ParseError {

    StateType ret = new StateType(cpt.getID(), cpt.getComponentType().getName());

    ret.setSimultaneous(simultaneous);

    for (ParamValue pv : cpt.getParamValues()) {
      String qn = pv.getName();
      double qv = pv.getDoubleValue();
      ret.addFixed(qn, qv);
      fixedHM.put(qn, qv);
    }

    for (RequiredVar rv : p_requiredVars) {
      ret.addIndependentVariable(rv.getName(), rv.getDimensionString());
    }

    for (ExposedVar ev : p_exposedVars) {
      ret.addExposedVariable(ev.getName(), ev.getDimensionString());
    }

    HashSet<StateVariable> varHS = new HashSet<StateVariable>();
    for (StateVariable sv : stateVariables) {
      varHS.add(sv);
      ret.addStateVariable(sv.getName(), sv.getDimensionString());
      if (sv.hasExposure()) {
        ret.addExposureMapping(sv.getName(), sv.getExposure().getName());
      }
    }

    for (InstanceProperty ip : cpt.getComponentType().getInstancePropertys()) {
      String pnm = ip.getName();
      ret.addExposureMapping(pnm, pnm);
      ret.addInstanceProperty(ip);
    }

    /*
    for (ExternalQuantity equan : externalQuantitys) {
     String qn = equan.getName();
     double qv = PathEvaluator.getValue(cpt, equan.getPath());
     ret.addFixed(qn, qv);
     fixedHM.put(qn, qv); // MUSTDO we don't need both of these:
     // either Ext quans shouldn't say they are fixed and we should use ret.addFixed, or it should
     // and use fixedHM.put.
    }
    */

    for (DerivedVariable dv : derivedVariables) {
      if (dv.hasExpression()) {

        DoubleEvaluator db = dv.getParseTree().makeFloatFixedEvaluator(fixedHM);

        ret.addExpressionDerived(dv.getName(), db, dv.getDimensionString());

      } else if (dv.hasSelection()) {
        ret.addPathDerived(
            dv.getName(),
            dv.getPath(),
            dv.getFunc(),
            dv.isRequired(),
            dv.getReduce(),
            dv.getDimensionString());

      } else {
        throw new ContentError("Derived variable needs as selection or an expression");
      }
      if (dv.hasExposure()) {
        ret.addExposureMapping(dv.getName(), dv.getExposure().getName());
      }
    }

    for (ConditionalDerivedVariable cdv : conditionalDerivedVariables) {
      DoubleEvaluator db = cdv.makeFloatFixedEvaluator(fixedHM);

      ret.addExpressionDerived(cdv.getName(), db, cdv.getDimensionString());

      if (cdv.hasExposure()) {
        ret.addExposureMapping(cdv.getName(), cdv.getExposure().getName());
      }
    }

    for (TimeDerivative sd : timeDerivatives) {
      StateVariable sv = sd.getStateVariable();
      varHS.remove(sv);

      ParseTree pt = sd.getParseTree();
      DoubleEvaluator db = pt.makeFloatFixedEvaluator(fixedHM);
      ret.addRate(sv.getName(), db, sd.getDimensionString());
    }

    for (OnStart os : onStarts) {
      ActionBlock ea = os.makeEventAction(fixedHM);
      ret.addInitialization(ea);
    }

    for (OnEvent oe : onEvents) {
      EventAction er = new EventAction(oe.getPortName());
      ActionBlock ea = oe.makeEventAction(fixedHM);
      er.setAction(ea);
      if (ea == null) {
        throw new ContentError("Null action block from OnEvent " + oe);
      }
      ret.addEventResponse(er);
    }
    if (regimes.size() > 0) {
      for (EventPort p : r_type.getEventPorts()) {
        if (p.isDirectionIn()) {
          if (onEvents.hasName(p.getName())) {
            // OK, the existing action will also send the event on to the active regime
          } else {
            EventAction er = new EventAction(p.getName());
            ret.addEventResponse(er);
          }
        }
      }
    }

    for (OnCondition oc : onConditions) {

      ParseTree pt = oc.getParseTree();
      BooleanEvaluator bb = pt.makeBooleanFixedEvaluator(fixedHM);

      ConditionAction cr = new ConditionAction(bb);
      ActionBlock ea = oc.makeEventAction(fixedHM);
      cr.setAction(ea);
      ret.addConditionResponse(cr);
    }

    for (KineticScheme ks : kineticSchemes) {
      ArrayList<Component> states = cpt.getChildrenAL(ks.getNodesName());
      ArrayList<Component> rates = cpt.getChildrenAL(ks.getEdgesName());

      KScheme scheme = ks.makeKScheme(states, rates);

      ret.addKScheme(scheme);
    }

    for (EventPort p : r_type.getEventPorts()) {
      if (p.isDirectionIn()) {
        ret.addInputPort(p.getName());
      }
      // TODO - also need output ports done the same way, in case send action is in a sub-regime
    }

    for (Regime reg : regimes) {
      ComponentRegime crb = reg.makeComponentRegime(ret, cpt, copyFixed(fixedHM));
      ret.addComponentRegime(crb);
    }

    // TODO - could do something with children of parent type here, but don't have to as they
    // come in again via the structure of the component itself.

    /*
    for (StateVariable sv : varHS) {
    // E.info("sv without derivative " + sv + " in mcb for " + cpt.getID() + " " + cpt.hashCode());
    }
    */

    ret.fix();
    return ret;
  }