Class TransferFunctionBlock

java.lang.Object
neqsim.util.NamedBaseClass
neqsim.process.controllerdevice.TransferFunctionBlock
All Implemented Interfaces:
Serializable, ControllerDeviceInterface, ProcessElementInterface, NamedInterface

public class TransferFunctionBlock extends NamedBaseClass implements ControllerDeviceInterface
Transfer function block for representing control dynamics in dynamic simulation. Supports first-order lag, lead-lag, pure dead time (transport delay), and second-order dynamics. These are the fundamental building blocks used in control system design and simulation.

The transfer function is represented in the Laplace domain as:

  • First-order lag: G(s) = K / (tau*s + 1)
  • Lead-lag: G(s) = K * (tauLead*s + 1) / (tauLag*s + 1)
  • Dead time: G(s) = K * exp(-theta*s)
  • Second-order: G(s) = K / (tau1*s + 1)(tau2*s + 1)

Example — lead-lag compensator for a feedforward signal:

TransferFunctionBlock leadLag =
    new TransferFunctionBlock("FF-comp", TransferFunctionBlock.Type.LEAD_LAG);
leadLag.setGain(1.0);
leadLag.setLeadTime(30.0); // 30 seconds lead
leadLag.setLagTime(120.0); // 120 seconds lag
leadLag.setTransmitter(flowTransmitter);
process.add(leadLag);
Version:
1.0
Author:
ESOL
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serialization version UID.
      See Also:
    • logger

      private static final org.apache.logging.log4j.Logger logger
      Logger object for class.
    • type

      private final TransferFunctionBlock.Type type
      Transfer function type.
    • gain

      private double gain
      Static gain K.
    • lagTime

      private double lagTime
      First time constant (tau for first-order, tauLag for lead-lag, tau1 for second-order) [s].
    • leadTime

      private double leadTime
      Lead time constant (tauLead for lead-lag) [s].
    • lagTime2

      private double lagTime2
      Second time constant (tau2 for second-order) [s].
    • deadTime

      private double deadTime
      Dead time (transport delay) theta [s].
    • inputBias

      private double inputBias
      Input bias (steady-state input value).
    • outputBias

      private double outputBias
      Output bias (steady-state output value).
    • state1

      private double state1
      State for first-order lag filter (or lag portion of lead-lag).
    • state2

      private double state2
      State for second time constant (second-order only).
    • deadTimeBuffer

      private double[] deadTimeBuffer
      Circular buffer for dead time implementation.
    • deadTimeWriteIndex

      private int deadTimeWriteIndex
      Write index for dead time buffer.
    • initialized

      private boolean initialized
      Flag indicating whether internal states have been initialized.
    • output

      private double output
      Current output value.
    • transmitter

      private MeasurementDeviceInterface transmitter
      Attached transmitter providing the input signal.
    • unit

      private String unit
      Engineering unit.
    • isActive

      private boolean isActive
      Whether block is active.
    • calcIdentifier

      protected UUID calcIdentifier
      UUID from last calculation.
  • Constructor Details

    • TransferFunctionBlock

      public TransferFunctionBlock(String name, TransferFunctionBlock.Type type)
      Constructor for TransferFunctionBlock.
      Parameters:
      name - identifier for this block
      type - the type of transfer function
  • Method Details

    • getType

      public TransferFunctionBlock.Type getType()
      Get the transfer function type.
      Returns:
      the type
    • setGain

      public void setGain(double gain)
      Set the static gain K.
      Parameters:
      gain - the gain value
    • getGain

      public double getGain()
      Get the static gain K.
      Returns:
      the gain
    • setLagTime

      public void setLagTime(double lagTime)
      Set the primary lag time constant [s]. For FIRST_ORDER_LAG this is tau. For LEAD_LAG this is tauLag. For SECOND_ORDER this is tau1.
      Parameters:
      lagTime - time constant in seconds (must be positive)
    • getLagTime

      public double getLagTime()
      Get the primary lag time constant [s].
      Returns:
      lag time in seconds
    • setLeadTime

      public void setLeadTime(double leadTime)
      Set the lead time constant for LEAD_LAG type [s].
      Parameters:
      leadTime - time constant in seconds (must be non-negative)
    • getLeadTime

      public double getLeadTime()
      Get the lead time constant [s].
      Returns:
      lead time in seconds
    • setLagTime2

      public void setLagTime2(double lagTime2)
      Set the second lag time constant for SECOND_ORDER type [s].
      Parameters:
      lagTime2 - time constant in seconds (must be positive)
    • getLagTime2

      public double getLagTime2()
      Get the second lag time constant [s].
      Returns:
      second lag time in seconds
    • setDeadTime

      public void setDeadTime(double deadTime)
      Set the dead time (transport delay) [s].
      Parameters:
      deadTime - delay in seconds (must be non-negative)
    • getDeadTime

      public double getDeadTime()
      Get the dead time [s].
      Returns:
      dead time in seconds
    • setInputBias

      public void setInputBias(double inputBias)
      Set the input bias (steady-state input around which the transfer function is linearized).
      Parameters:
      inputBias - the bias value
    • getInputBias

      public double getInputBias()
      Get the input bias.
      Returns:
      the input bias
    • setOutputBias

      public void setOutputBias(double outputBias)
      Set the output bias (steady-state output value).
      Parameters:
      outputBias - the bias value
    • getOutputBias

      public double getOutputBias()
      Get the output bias.
      Returns:
      the output bias
    • getOutput

      public double getOutput()
      Get the current output value.
      Returns:
      the output
    • reset

      public void reset()
      Reset internal states to initial conditions.
    • getMeasuredValue

      public double getMeasuredValue()

      getMeasuredValue.

      Specified by:
      getMeasuredValue in interface ControllerDeviceInterface
      Returns:
      a double
    • setControllerSetPoint

      public void setControllerSetPoint(double signal)

      setControllerSetPoint.

      Specified by:
      setControllerSetPoint in interface ControllerDeviceInterface
      Parameters:
      signal - a double
    • getControllerSetPoint

      public double getControllerSetPoint()

      getControllerSetPoint.

      Specified by:
      getControllerSetPoint in interface ControllerDeviceInterface
      Returns:
      current controller set point
    • getUnit

      public String getUnit()

      getUnit.

      Specified by:
      getUnit in interface ControllerDeviceInterface
      Returns:
      a String object
    • setUnit

      public void setUnit(String unit)

      setUnit.

      Specified by:
      setUnit in interface ControllerDeviceInterface
      Parameters:
      unit - a String object
    • setTransmitter

      public void setTransmitter(MeasurementDeviceInterface device)

      setTransmitter.

      Specified by:
      setTransmitter in interface ControllerDeviceInterface
      Parameters:
      device - a MeasurementDeviceInterface object
    • runTransient

      public void runTransient(double initResponse, double dt, UUID id)

      runTransient.

      Calculates controller output. Sets calc identifier UUID.
      Specified by:
      runTransient in interface ControllerDeviceInterface
      Parameters:
      initResponse - Init value for response calculation
      dt - Delta time [s]
      id - Calculation identifier
    • getResponse

      public double getResponse()

      getResponse.

      Specified by:
      getResponse in interface ControllerDeviceInterface
      Returns:
      a double
    • isReverseActing

      public boolean isReverseActing()

      isReverseActing.

      Specified by:
      isReverseActing in interface ControllerDeviceInterface
      Returns:
      a boolean
    • setReverseActing

      public void setReverseActing(boolean reverseActing)

      setReverseActing.

      Specified by:
      setReverseActing in interface ControllerDeviceInterface
      Parameters:
      reverseActing - a boolean
    • setControllerParameters

      public void setControllerParameters(double Kp, double Ti, double Td)

      Set PID tuning parameters.

      Specified by:
      setControllerParameters in interface ControllerDeviceInterface
      Parameters:
      Kp - Proportional gain
      Ti - Integral time in seconds
      Td - Derivative time in seconds
    • setActive

      public void setActive(boolean isActive)

      setActive.

      Set if controller is active
      Specified by:
      setActive in interface ControllerDeviceInterface
      Parameters:
      isActive - Set true to make controller active.
    • isActive

      public boolean isActive()

      isActive.

      Specifies if controller is active
      Specified by:
      isActive in interface ControllerDeviceInterface
      Returns:
      a boolean
    • initializeStates

      private void initializeStates(double u, double dt)
    • computeFirstOrderLag

      private double computeFirstOrderLag(double u, double dt)
      First-order lag: y(k) = alpha * y(k-1) + (1 - alpha) * K * u(k) where alpha = tau / (tau + dt).
      Parameters:
      u - the input signal value
      dt - the time step in seconds
      Returns:
      the filtered output value
    • computeLeadLag

      private double computeLeadLag(double u, double dt)
      Lead-lag: implemented as a first-order lag plus a derivative lead correction. Discretized as: y(k) = (tauLead/tauLag) * K * u(k) + (1 - tauLead/tauLag) * lagFiltered(K*u).
      Parameters:
      u - the input signal value
      dt - the time step in seconds
      Returns:
      the lead-lag filtered output value
    • computeDeadTime

      private double computeDeadTime(double u, double dt)
      Pure dead time: stores the input in a circular buffer and reads out the delayed value.
      Parameters:
      u - the input signal value
      dt - the time step in seconds
      Returns:
      the delayed output value
    • computeSecondOrder

      private double computeSecondOrder(double u, double dt)
      Second-order system: cascade of two first-order lags. G(s) = K / (tau1*s + 1)(tau2*s + 1)
      Parameters:
      u - the input signal value
      dt - the time step in seconds
      Returns:
      the second-order filtered output value
    • applyDeadTime

      private double applyDeadTime(double currentValue, double dt)
      Apply dead time via circular buffer.
      Parameters:
      currentValue - the current signal value to delay
      dt - the time step in seconds
      Returns:
      the delayed output value from the circular buffer