Program: 73087
Project: 73087
Buggy source:
/** 
 * Read data from output ports, set the input ports and invoke fmiDoStep() of the slave fmu. <p>Note that we get the outputs <b>before</b> invoking fmiDoStep() of the slave fmu so that we can get the data for time 0.  This is done so that FMUs can share initialization data if necessary.  For details, see the Section 3.4, Pseudo Code Example in the FMI-1.0 Co-simulation Specification at <a href="http://www.modelisar.com/specifications/FMI_for_CoSimulation_v1.0.pdf">http://www.modelisar.com/specifications/FMI_for_CoSimulation_v1.0.pdf</a>. For an explanation, see figure 4 of <br> Michael Wetter, "<a href="http://dx.doi.org/10.1080/19401493.2010.518631">Co-simulation of building energy and control systems with the Building Controls Virtual Test Bed</a>," Journal of Building Performance Simulation, Volume 4, Issue 3, 2011.
 * @exception IllegalActionException If there is no director.
 */
public void fire() throws IllegalActionException {
  super.fire();
  if (_debugging) {
    _debug("String_Node_Str");
  }
  _checkFmi();
  String modelIdentifier=_fmiModelDescription.modelIdentifier;
  Director director=getDirector();
  Time currentTime=director.getModelTime();
  int currentMicrostep=1;
  if (director instanceof SuperdenseTimeDirector) {
    currentMicrostep=((SuperdenseTimeDirector)director).getIndex();
  }
  int timeAdvance=currentTime.compareTo(_lastFireTime);
  if (timeAdvance > 0 || (timeAdvance == 0 && currentMicrostep > _lastFireMicrostep)) {
    double time=_lastFireTime.getDoubleValue();
    double stepSize=currentTime.subtract(_lastFireTime).getDoubleValue();
    if (_debugging) {
      _debug("String_Node_Str" + modelIdentifier + "String_Node_Str"+ time+ "String_Node_Str"+ stepSize+ "String_Node_Str");
    }
    _refinedStepSize=-1.0;
    int fmiFlag=((Integer)_fmiDoStep.invokeInt(new Object[]{_fmiComponent,time,stepSize,(byte)1})).intValue();
    if (fmiFlag == FMILibrary.FMIStatus.fmiDiscard) {
      _stepSizeRejected=true;
      if (_debugging) {
        _debug("String_Node_Str" + stepSize + "String_Node_Str"+ time);
      }
      if (_fmiGetRealStatus != null) {
        DoubleBuffer valueBuffer=DoubleBuffer.allocate(1);
        fmiFlag=((Integer)_fmiGetRealStatus.invokeInt(new Object[]{_fmiComponent,FMILibrary.FMIStatusKind.fmiLastSuccessfulTime,valueBuffer})).intValue();
        if (fmiFlag == FMILibrary.FMIStatus.fmiOK) {
          double lastSuccessfulTime=valueBuffer.get(0);
          if (lastSuccessfulTime >= time) {
            _refinedStepSize=lastSuccessfulTime - _lastCommitTime.getDoubleValue();
          }
        }
      }
    }
 else     if (fmiFlag != FMILibrary.FMIStatus.fmiOK) {
      throw new IllegalActionException(this,"String_Node_Str" + modelIdentifier + "String_Node_Str"+ time+ "String_Node_Str"+ stepSize+ "String_Node_Str"+ _fmiStatusDescription(fmiFlag));
    }
    if (_debugging) {
      _debug("String_Node_Str" + modelIdentifier + "String_Node_Str");
    }
  }
 else   if (timeAdvance < 0 || (timeAdvance == 0 && currentMicrostep < _lastFireMicrostep)) {
    double time=_lastCommitTime.getDoubleValue();
    double stepSize=currentTime.subtract(_lastCommitTime).getDoubleValue();
    if (_debugging) {
      _debug("String_Node_Str" + modelIdentifier + "String_Node_Str"+ time+ "String_Node_Str"+ stepSize+ "String_Node_Str");
    }
    int fmiFlag=((Integer)_fmiDoStep.invokeInt(new Object[]{_fmiComponent,time,stepSize,(byte)0})).intValue();
    if (fmiFlag != FMILibrary.FMIStatus.fmiOK) {
      throw new IllegalActionException(this,"String_Node_Str" + modelIdentifier + "String_Node_Str"+ time+ "String_Node_Str"+ stepSize+ "String_Node_Str"+ _fmiStatusDescription(fmiFlag));
    }
    if (_debugging) {
      _debug("String_Node_Str" + modelIdentifier + "String_Node_Str");
    }
  }
  _lastFireTime=currentTime;
  _lastFireMicrostep=currentMicrostep;
  for (  FMIScalarVariable scalarVariable : _fmiModelDescription.modelVariables) {
    if (scalarVariable.alias != null && scalarVariable.alias != Alias.noAlias) {
      continue;
    }
    if (scalarVariable.variability != FMIScalarVariable.Variability.parameter && scalarVariable.variability != FMIScalarVariable.Variability.constant && scalarVariable.causality == Causality.input) {
      TypedIOPort port=(TypedIOPort)getPort(scalarVariable.name);
      if (port != null) {
        if (port.isKnown(0)) {
          if (port.hasToken(0)) {
            Token token=port.get(0);
            _setScalarVariable(scalarVariable,token);
            if (_debugging) {
              _debug("String_Node_Str" + scalarVariable.name + "String_Node_Str"+ token);
            }
          }
 else {
            throw new IllegalActionException(this,"String_Node_Str" + scalarVariable.name + "String_Node_Str"+ "String_Node_Str");
          }
        }
      }
 else {
        throw new IllegalActionException(this,"String_Node_Str" + scalarVariable.name + "String_Node_Str");
      }
    }
  }
  for (  Output output : _getOutputs()) {
    TypedIOPort port=output.port;
    if (_skipIfKnown() && port.isKnown(0)) {
      continue;
    }
    boolean foundUnknownInputOnWhichOutputDepends=false;
    if (output.dependencies != null) {
      for (      TypedIOPort inputPort : output.dependencies) {
        if (!inputPort.isKnown(0)) {
          if (_debugging) {
            _debug("String_Node_Str" + "String_Node_Str" + port.getName() + "String_Node_Str"+ inputPort.getName()+ "String_Node_Str");
          }
          foundUnknownInputOnWhichOutputDepends=true;
          break;
        }
      }
    }
 else {
      List<TypedIOPort> inputPorts=inputPortList();
      for (      TypedIOPort inputPort : inputPorts) {
        if (inputPort.getWidth() < 0 || !inputPort.isKnown(0)) {
          foundUnknownInputOnWhichOutputDepends=true;
          break;
        }
      }
    }
    if (!foundUnknownInputOnWhichOutputDepends) {
      Token token=null;
      FMIScalarVariable scalarVariable=output.scalarVariable;
      if (scalarVariable.type instanceof FMIBooleanType) {
        boolean result=scalarVariable.getBoolean(_fmiComponent);
        token=new BooleanToken(result);
      }
 else       if (scalarVariable.type instanceof FMIIntegerType) {
        int result=scalarVariable.getInt(_fmiComponent);
        token=new IntToken(result);
      }
 else       if (scalarVariable.type instanceof FMIRealType) {
        double result=scalarVariable.getDouble(_fmiComponent);
        token=new DoubleToken(result);
      }
 else       if (scalarVariable.type instanceof FMIStringType) {
        String result=scalarVariable.getString(_fmiComponent);
        token=new StringToken(result);
      }
 else {
        throw new IllegalActionException("String_Node_Str" + scalarVariable.type + "String_Node_Str");
      }
      if (_debugging) {
        _debug("String_Node_Str" + scalarVariable.name + "String_Node_Str"+ token+ "String_Node_Str"+ currentTime+ "String_Node_Str"+ currentMicrostep);
      }
      port.send(0,token);
    }
  }
}

Fixed version (ground truth):
/** 
 * Read data from output ports, set the input ports and invoke fmiDoStep() of the slave fmu. <p>Note that we get the outputs <b>before</b> invoking fmiDoStep() of the slave fmu so that we can get the data for time 0.  This is done so that FMUs can share initialization data if necessary.  For details, see the Section 3.4, Pseudo Code Example in the FMI-1.0 Co-simulation Specification at <a href="http://www.modelisar.com/specifications/FMI_for_CoSimulation_v1.0.pdf">http://www.modelisar.com/specifications/FMI_for_CoSimulation_v1.0.pdf</a>. For an explanation, see figure 4 of <br> Michael Wetter, "<a href="http://dx.doi.org/10.1080/19401493.2010.518631">Co-simulation of building energy and control systems with the Building Controls Virtual Test Bed</a>," Journal of Building Performance Simulation, Volume 4, Issue 3, 2011.
 * @exception IllegalActionException If there is no director.
 */
public void fire() throws IllegalActionException {
  super.fire();
  if (_debugging) {
    _debug("String_Node_Str");
  }
  _checkFmi();
  String modelIdentifier=_fmiModelDescription.modelIdentifier;
  Director director=getDirector();
  Time currentTime=director.getModelTime();
  int currentMicrostep=1;
  if (director instanceof SuperdenseTimeDirector) {
    currentMicrostep=((SuperdenseTimeDirector)director).getIndex();
  }
  int timeAdvance=currentTime.compareTo(_lastFireTime);
  if (timeAdvance > 0 || (timeAdvance == 0 && currentMicrostep > _lastFireMicrostep)) {
    double time=_lastFireTime.getDoubleValue();
    double stepSize=currentTime.subtract(_lastFireTime).getDoubleValue();
    if (_debugging) {
      _debug("String_Node_Str" + modelIdentifier + "String_Node_Str"+ time+ "String_Node_Str"+ stepSize+ "String_Node_Str");
    }
    if (time >= 2.9) {
      Math.sin(3.14159);
    }
    _refinedStepSize=-1.0;
    int fmiFlag=((Integer)_fmiDoStep.invokeInt(new Object[]{_fmiComponent,time,stepSize,(byte)1})).intValue();
    if (fmiFlag == FMILibrary.FMIStatus.fmiDiscard) {
      _stepSizeRejected=true;
      if (_debugging) {
        _debug("String_Node_Str" + stepSize + "String_Node_Str"+ time);
      }
      if (_fmiGetRealStatus != null) {
        DoubleBuffer valueBuffer=DoubleBuffer.allocate(1);
        fmiFlag=((Integer)_fmiGetRealStatus.invokeInt(new Object[]{_fmiComponent,FMILibrary.FMIStatusKind.fmiLastSuccessfulTime,valueBuffer})).intValue();
        if (fmiFlag == FMILibrary.FMIStatus.fmiOK) {
          double lastSuccessfulTime=valueBuffer.get(0);
          if (lastSuccessfulTime >= _lastCommitTime.getDoubleValue()) {
            _refinedStepSize=lastSuccessfulTime - _lastCommitTime.getDoubleValue();
          }
        }
      }
    }
 else     if (fmiFlag != FMILibrary.FMIStatus.fmiOK) {
      throw new IllegalActionException(this,"String_Node_Str" + modelIdentifier + "String_Node_Str"+ time+ "String_Node_Str"+ stepSize+ "String_Node_Str"+ _fmiStatusDescription(fmiFlag));
    }
    if (_debugging) {
      _debug("String_Node_Str" + modelIdentifier + "String_Node_Str");
    }
  }
 else   if (timeAdvance < 0 || (timeAdvance == 0 && currentMicrostep < _lastFireMicrostep)) {
    double time=_lastCommitTime.getDoubleValue();
    double stepSize=currentTime.subtract(_lastCommitTime).getDoubleValue();
    if (_debugging) {
      _debug("String_Node_Str" + modelIdentifier + "String_Node_Str"+ time+ "String_Node_Str"+ stepSize+ "String_Node_Str");
    }
    int fmiFlag=((Integer)_fmiDoStep.invokeInt(new Object[]{_fmiComponent,time,stepSize,(byte)0})).intValue();
    if (fmiFlag != FMILibrary.FMIStatus.fmiOK) {
      throw new IllegalActionException(this,"String_Node_Str" + modelIdentifier + "String_Node_Str"+ time+ "String_Node_Str"+ stepSize+ "String_Node_Str"+ _fmiStatusDescription(fmiFlag));
    }
    if (_debugging) {
      _debug("String_Node_Str" + modelIdentifier + "String_Node_Str");
    }
  }
  _lastFireTime=currentTime;
  _lastFireMicrostep=currentMicrostep;
  for (  FMIScalarVariable scalarVariable : _fmiModelDescription.modelVariables) {
    if (scalarVariable.alias != null && scalarVariable.alias != Alias.noAlias) {
      continue;
    }
    if (scalarVariable.variability != FMIScalarVariable.Variability.parameter && scalarVariable.variability != FMIScalarVariable.Variability.constant && scalarVariable.causality == Causality.input) {
      TypedIOPort port=(TypedIOPort)getPort(scalarVariable.name);
      if (port != null) {
        if (port.isKnown(0)) {
          if (port.hasToken(0)) {
            Token token=port.get(0);
            _setScalarVariable(scalarVariable,token);
            if (_debugging) {
              _debug("String_Node_Str" + scalarVariable.name + "String_Node_Str"+ token);
            }
          }
 else {
            throw new IllegalActionException(this,"String_Node_Str" + scalarVariable.name + "String_Node_Str"+ "String_Node_Str");
          }
        }
      }
 else {
        throw new IllegalActionException(this,"String_Node_Str" + scalarVariable.name + "String_Node_Str");
      }
    }
  }
  for (  Output output : _getOutputs()) {
    TypedIOPort port=output.port;
    if (_skipIfKnown() && port.isKnown(0)) {
      continue;
    }
    boolean foundUnknownInputOnWhichOutputDepends=false;
    if (output.dependencies != null) {
      for (      TypedIOPort inputPort : output.dependencies) {
        if (!inputPort.isKnown(0)) {
          if (_debugging) {
            _debug("String_Node_Str" + "String_Node_Str" + port.getName() + "String_Node_Str"+ inputPort.getName()+ "String_Node_Str");
          }
          foundUnknownInputOnWhichOutputDepends=true;
          break;
        }
      }
    }
 else {
      List<TypedIOPort> inputPorts=inputPortList();
      for (      TypedIOPort inputPort : inputPorts) {
        if (inputPort.getWidth() < 0 || !inputPort.isKnown(0)) {
          foundUnknownInputOnWhichOutputDepends=true;
          break;
        }
      }
    }
    if (!foundUnknownInputOnWhichOutputDepends) {
      Token token=null;
      FMIScalarVariable scalarVariable=output.scalarVariable;
      if (scalarVariable.type instanceof FMIBooleanType) {
        boolean result=scalarVariable.getBoolean(_fmiComponent);
        token=new BooleanToken(result);
      }
 else       if (scalarVariable.type instanceof FMIIntegerType) {
        int result=scalarVariable.getInt(_fmiComponent);
        token=new IntToken(result);
      }
 else       if (scalarVariable.type instanceof FMIRealType) {
        double result=scalarVariable.getDouble(_fmiComponent);
        token=new DoubleToken(result);
      }
 else       if (scalarVariable.type instanceof FMIStringType) {
        String result=scalarVariable.getString(_fmiComponent);
        token=new StringToken(result);
      }
 else {
        throw new IllegalActionException("String_Node_Str" + scalarVariable.type + "String_Node_Str");
      }
      if (_debugging) {
        _debug("String_Node_Str" + scalarVariable.name + "String_Node_Str"+ token+ "String_Node_Str"+ currentTime+ "String_Node_Str"+ currentMicrostep);
      }
      port.send(0,token);
    }
  }
}