public void inheritFrom(Dynamics src) { for (DerivedVariable dv : src.derivedVariables) { derivedVariables.add(dv.makeCopy()); } for (ConditionalDerivedVariable dv : src.conditionalDerivedVariables) { conditionalDerivedVariables.add(dv.makeCopy()); } for (StateVariable sv : src.stateVariables) { stateVariables.add(sv.makeCopy()); } for (TimeDerivative td : src.timeDerivatives) { timeDerivatives.add(td.makeCopy()); } for (KineticScheme ks : src.kineticSchemes) { kineticSchemes.add(ks.makeCopy()); } for (OnStart os : src.onStarts) { onStarts.add(os.makeCopy()); } for (OnEvent oe : src.onEvents) { onEvents.add(oe.makeCopy()); } for (OnCondition oc : src.onConditions) { onConditions.add(oc.makeCopy()); } for (Regime r : src.regimes) { regimes.add(r.makeCopy()); } }
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); } }
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; }
private void realResolve(Lems lems, Parser parser) throws ContentError, ParseError { if (lems.looseResolving()) { // then we expose anything with a name that matches the name of an exposure HashSet<String> expHS = new HashSet<String>(); for (Exposure exp : getComponentType().getExposures()) { expHS.add(exp.getName()); } for (StateVariable sv : stateVariables) { if (sv.exposure == null && expHS.contains(sv.name)) { sv.exposure = sv.name; E.shortWarning( "Implicitly exposing a state variable because its name matches an exposure: " + sv); } } for (DerivedVariable dv : derivedVariables) { if (dv.exposure == null && expHS.contains(dv.name)) { dv.exposure = dv.name; E.shortWarning( "Implicitly exposing a derived variable because its name matches an exposure: " + dv); } } for (ConditionalDerivedVariable dv : conditionalDerivedVariables) { if (dv.exposure == null && expHS.contains(dv.name)) { dv.exposure = dv.name; E.shortWarning( "Implicitly exposing a derived variable because its name matches an exposure: " + dv); } } } HashMap<String, Integer> exposedHM = new HashMap<String, Integer>(); for (Requirement req : getComponentType().getRequirements()) { p_requiredVars.add(new RequiredVar(req.getName(), req.getDimension())); } for (Exposure exp : getComponentType().getExposures()) { p_exposedVars.add(new ExposedVar(exp.getName(), exp.getDimension())); exposedHM.put(exp.getName(), 0); } checkMakeValHM(); addToMap(lems.getGlobals(), valHM); addToMap(lems.getConstantValueds(), valHM); for (DerivedVariable dvar : derivedVariables) { dvar.resolve(lems, lems.getDimensions(), r_type, valHM, parser); if (dvar.hasExposure()) { countExposure(dvar.getExposure(), exposedHM); } } for (ConditionalDerivedVariable dvar : conditionalDerivedVariables) { dvar.resolve(lems, lems.getDimensions(), r_type, valHM, parser); if (dvar.hasExposure()) { countExposure(dvar.getExposure(), exposedHM); } } for (StateVariable sv : stateVariables) { sv.resolve(r_type, lems.getDimensions()); if (sv.hasExposure()) { countExposure(sv.getExposure(), exposedHM); } } for (StateScalarField scf : stateScalarFields) { scf.resolve(r_type, lems.getDimensions()); } for (DerivedScalarField dcf : derivedScalarFields) { dcf.resolve(r_type, lems.getDimensions()); } for (DerivedPunctateField dpf : derivedPunctateFields) { dpf.resolve(r_type, lems.getDimensions()); } for (TimeDerivative sd : timeDerivatives) { sd.resolve(stateVariables, valHM, parser); } for (OnStart os : onStarts) { os.resolve(this, stateVariables, valHM, parser); } for (OnEvent oe : onEvents) { oe.resolve(this, stateVariables, valHM, parser); } for (OnCondition oc : onConditions) { oc.resolve(this, stateVariables, valHM, parser); } for (Regime reg : regimes) { reg.setBehavior(this); reg.resolve(stateVariables, lems, parser, exposedHM); } for (KineticScheme ks : kineticSchemes) { ks.resolve(r_type); } for (String enm : exposedHM.keySet()) { if (exposedHM.get(enm) == 0) { E.oneLineWarning( "No internal variable is linked to the exposure: " + enm + " for ComponentType " + getComponentType().getName()); } } }