Class AbstractCumulativeEnergyCalculator

  • Direct Known Subclasses:
    SimpsonRuleCumulativeEnergyCalculator

    public abstract class AbstractCumulativeEnergyCalculator
    extends Object
    This abstract class is designed to be the base class of all algorithms that calculate cumulative energy consumptions based on power consumption samples (sampling points), i.e., in an integrator-like fashion. Usually, inheriting subclasses will implement certain numerical algorithms for integration of time series.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractCumulativeEnergyCalculator​(int powerSamplesNeeded, int energySamplesNeeded, int numberOfInitSteps)
      Initializes a new instance of the AbstractCumulativeEnergyCalculator class with the given properties.
      protected AbstractCumulativeEnergyCalculator​(int powerSamplesNeeded, int energySamplesNeeded, int numberOfInitSteps, javax.measure.Measurable<javax.measure.quantity.Duration> samplingPeriod, javax.measure.Measurable<javax.measure.quantity.Duration> initialOffset)
      Initializes a new instance of the AbstractCumulativeEnergyCalculator class with the given properties.
      protected AbstractCumulativeEnergyCalculator​(int powerSamplesNeeded, int energySamplesNeeded, int numberOfInitSteps, javax.measure.Measurable<javax.measure.quantity.Duration> samplingPeriod, javax.measure.Measurable<javax.measure.quantity.Duration> initialOffset, javax.measure.unit.Unit<javax.measure.quantity.Energy> resultUnit)
      Initializes a new instance of the AbstractCumulativeEnergyCalculator class with the given properties.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> calculateInitValue​(int initValueIndex)
      Method to be implemented by subclasses which contains the initialization steps.
      org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> calculateNext​(javax.measure.Measurable<javax.measure.quantity.Power> newPowerSample)
      Calculates the next energy sample, i.e., the next integration step is done.
      protected abstract org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> calculateNextInternal()
      Method to be implemented by subclasses containing the integration algorithm.
      protected int getCurrentlyStoredEnergySamplesCount()
      Gets the number of already calculated energy samples which are currently kept for integration.
      protected int getCurrentlyStoredPowerSamplesCount()
      Gets the number of power samples/sampling points which are currently kept for integration.
      static javax.measure.unit.Unit<javax.measure.quantity.Energy> getDefaultResultUnit()
      Gets the energy unit which is used by default.
      protected org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> getEnergySample​(int index)
      Gets the energy sample associated with the given index.
      Note, that index is related to previous integration steps, i.e.,: index = 0 denotes the energy sample calculated in the most recent integration step index = 1 denotes the energy sample calculated in the last but one step ... index = energySamplesNeeded - 1 denotes the least recent energy sample that is available
      org.jscience.physics.amount.Amount<javax.measure.quantity.Duration> getInitialOffset()
      Gets the initial offset.
      protected org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> getMostRecentEnergySample()
      Gets the energy sample that was calculated in the last integration step.
      protected org.jscience.physics.amount.Amount<javax.measure.quantity.Power> getMostRecentPowerSample()
      Gets the power sample that was used for the most recent integration step.
      protected org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> getOldestEnergySample()
      Gets the least recently calculated energy sample (expressed in terms of previous integration steps) which has to be kept for the next integration step.
      protected org.jscience.physics.amount.Amount<javax.measure.quantity.Power> getOldestPowerSample()
      Gets the least recently power sample (expressed in terms of previous integration steps) which has to be kept for the next integration step.
      protected org.jscience.physics.amount.Amount<javax.measure.quantity.Power> getPowerSample​(int index)
      Gets the stored power sample associated with the given index.
      Note, that index is related to previous integration steps, i.e.,: index = 0 denotes the power sample used in the most recent integration step index = 1 denotes the power sample used in the last but one step ... index = powerSamplesNeeded - 1 denotes the least recent power sample that is available
      javax.measure.unit.Unit<javax.measure.quantity.Energy> getResultUnit()
      Gets the unit in which the calculated energy samples are expressed.
      org.jscience.physics.amount.Amount<javax.measure.quantity.Duration> getSamplingPeriod()
      Gets the current sampling period, i.e, the temporal difference between two consecutive power samples.
      void reset()
      Resets the state of this instance.
      void setOffset​(javax.measure.Measurable<javax.measure.quantity.Duration> initialOffset)
      Sets the initial offset, i.e., the temporal offset of the first power sample.
      void setSamplingPeriod​(javax.measure.Measurable<javax.measure.quantity.Duration> samplingPeriod)
      Sets the sampling period, i.e., the temporal difference between the next consecutive power samples.
    • Constructor Detail

      • AbstractCumulativeEnergyCalculator

        protected AbstractCumulativeEnergyCalculator​(int powerSamplesNeeded,
                                                     int energySamplesNeeded,
                                                     int numberOfInitSteps,
                                                     javax.measure.Measurable<javax.measure.quantity.Duration> samplingPeriod,
                                                     javax.measure.Measurable<javax.measure.quantity.Duration> initialOffset,
                                                     javax.measure.unit.Unit<javax.measure.quantity.Energy> resultUnit)
        Initializes a new instance of the AbstractCumulativeEnergyCalculator class with the given properties.
        Parameters:
        powerSamplesNeeded - A nonnegative integer indicating the number of power samples required for the calculation of a new energy sample.
        energySamplesNeeded - A nonnegative integer indicating the number most recently calculated energy samples required for the calculation of a new one.
        numberOfInitSteps - A nonnegative integer indicating the number of initialization steps the implemented algorithm requires, i.e., the amount of the first energy samples that are potentially calculated in a different way.
        samplingPeriod - A Measurable denoting the sampling period, i.e., the temporal difference between two consecutive power samples.
        initialOffset - A Measurable denoting the temporal offset of the first power sample, i.e., the point in time it was taken.
        resultUnit - A Unit which defining the unit of the calculated energy samples.
        Throws:
        IllegalArgumentException - An IllegalArgumentException is thrown in one of the following cases:
        • powerSamplesNeeded, energySamplesNeeded or numberOfInitSteps are < 0
        • resultUnit is null
        • samplingPeriod does not represent a positive duration
        • initialOffset represents a negative duration
        See Also:
        AbstractCumulativeEnergyCalculator(int, int, int), AbstractCumulativeEnergyCalculator(int, int, int, Measurable, Measurable), getDefaultResultUnit()
      • AbstractCumulativeEnergyCalculator

        protected AbstractCumulativeEnergyCalculator​(int powerSamplesNeeded,
                                                     int energySamplesNeeded,
                                                     int numberOfInitSteps,
                                                     javax.measure.Measurable<javax.measure.quantity.Duration> samplingPeriod,
                                                     javax.measure.Measurable<javax.measure.quantity.Duration> initialOffset)
        Initializes a new instance of the AbstractCumulativeEnergyCalculator class with the given properties. The resulting energy samples are expressed using the default energy unit defined in this class.
        Parameters:
        powerSamplesNeeded - A nonnegative integer indicating the number of power samples required for the calculation of a new energy sample.
        energySamplesNeeded - A nonnegative integer indicating the number most recently calculated energy samples required for the calculation of a new one.
        numberOfInitSteps - A nonnegative integer indicating the number of initialization steps the implemented algorithm requires, i.e., the amount of the first energy samples that are potentially calculated in a different way.
        samplingPeriod - A Measurable denoting the sampling period, i.e., the temporal difference between two consecutive power samples.
        initialOffset - A Measurable denoting the temporal offset of the first power sample, i.e., the point in time it was taken.
        Throws:
        IllegalArgumentException - An IllegalArgumentException is thrown in one of the following cases:
        • powerSamplesNeeded, energySamplesNeeded or numberOfInitSteps are < 0
        • samplingPeriod does not represent a positive duration
        • initialOffset represents a negative duration
        See Also:
        AbstractCumulativeEnergyCalculator(int, int, int, Measurable, Measurable, Unit), AbstractCumulativeEnergyCalculator(int, int, int), getDefaultResultUnit()
      • AbstractCumulativeEnergyCalculator

        protected AbstractCumulativeEnergyCalculator​(int powerSamplesNeeded,
                                                     int energySamplesNeeded,
                                                     int numberOfInitSteps)
        Initializes a new instance of the AbstractCumulativeEnergyCalculator class with the given properties. The resulting energy samples are expressed using the default energy unit defined in this class. Additionally, a default sampling period of 10s and an initial offset of 0s is assumed.
        Parameters:
        powerSamplesNeeded - A nonnegative integer indicating the number of power samples required for the calculation of a new energy sample.
        energySamplesNeeded - A nonnegative integer indicating the number most recently calculated energy samples required for the calculation of a new one.
        numberOfInitSteps - A nonnegative integer indicating the number of initialization steps the implemented algorithm requires, i.e., the amount of the first energy samples that are potentially calculated in a different way.
        Throws:
        IllegalArgumentException - An IllegalArgumentException is thrown if powerSamplesNeeded, energySamplesNeeded or numberOfInitSteps are < 0
        See Also:
        getDefaultResultUnit(), AbstractCumulativeEnergyCalculator(int, int, int, Measurable, Measurable, Unit)
    • Method Detail

      • reset

        public void reset()
        Resets the state of this instance. In particular, the initial offset is set to 0s, the sampling period is set to default (10s) and all so far calculated energy samples are discarded. Additionally, all power samples kept for calculation are cleared.
      • setSamplingPeriod

        public void setSamplingPeriod​(javax.measure.Measurable<javax.measure.quantity.Duration> samplingPeriod)
        Sets the sampling period, i.e., the temporal difference between the next consecutive power samples. This might be useful if the sampling points are not equidistant.
        Parameters:
        samplingPeriod - A Measurable denoting the sampling period, i.e., the temporal difference between two consecutive power samples.
        Throws:
        IllegalArgumentException - In case the given duration is null or not positive
      • setOffset

        public void setOffset​(javax.measure.Measurable<javax.measure.quantity.Duration> initialOffset)
        Sets the initial offset, i.e., the temporal offset of the first power sample.
        Parameters:
        initialOffset - A Measurable denoting the temporal offset, i.e., the point in time it was taken.
        Throws:
        IllegalArgumentException - In case initialOffset is null or negative
      • getInitialOffset

        public org.jscience.physics.amount.Amount<javax.measure.quantity.Duration> getInitialOffset()
        Gets the initial offset.
        Returns:
        An Amount denoting the temporal offset of the first sampling point/power sample.
      • getSamplingPeriod

        public org.jscience.physics.amount.Amount<javax.measure.quantity.Duration> getSamplingPeriod()
        Gets the current sampling period, i.e, the temporal difference between two consecutive power samples.
        Returns:
        An Amount denoting the sampling period.
      • getResultUnit

        public javax.measure.unit.Unit<javax.measure.quantity.Energy> getResultUnit()
        Gets the unit in which the calculated energy samples are expressed.
        Returns:
        An Unit denoting an energy unit.
      • getDefaultResultUnit

        public static javax.measure.unit.Unit<javax.measure.quantity.Energy> getDefaultResultUnit()
        Gets the energy unit which is used by default.
        Returns:
        A Unit denoting Wh (watt-hours).
        See Also:
        PowerModelConstants.WATT_HOURS
      • calculateNext

        public final org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> calculateNext​(javax.measure.Measurable<javax.measure.quantity.Power> newPowerSample)
        Calculates the next energy sample, i.e., the next integration step is done.
        Parameters:
        newPowerSample - A Measurable holding the (most recent) power sample to be used for calculation.
        Returns:
        An Amount holding the calculated cumulative energy sample.
        Throws:
        IllegalArgumentException - In case the given power sample is null.
      • calculateNextInternal

        protected abstract org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> calculateNextInternal()
        Method to be implemented by subclasses containing the integration algorithm.
        Returns:
        The calculated energy sample.
      • calculateInitValue

        protected abstract org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> calculateInitValue​(int initValueIndex)
        Method to be implemented by subclasses which contains the initialization steps.
        Parameters:
        initValueIndex - The number of the init step.
        Returns:
        The energy sample calculated by the init step.
      • getCurrentlyStoredPowerSamplesCount

        protected int getCurrentlyStoredPowerSamplesCount()
        Gets the number of power samples/sampling points which are currently kept for integration.
        Returns:
        A value <= powerSamplesNeeded in case not all required init steps have been done yet,
        powerSamplesNeeded otherwise.
        See Also:
        #AbstractCumulativeEnergyCalculator(int, int, int, Amount, Amount, Unit)
      • getCurrentlyStoredEnergySamplesCount

        protected int getCurrentlyStoredEnergySamplesCount()
        Gets the number of already calculated energy samples which are currently kept for integration.
        Returns:
        A value <= energySamplesNeeded in case not all required init steps have been done yet,
        energySamplesNeeded otherwise.
        See Also:
        #AbstractCumulativeEnergyCalculator(int, int, int, Amount, Amount, Unit)
      • getOldestEnergySample

        protected org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> getOldestEnergySample()
        Gets the least recently calculated energy sample (expressed in terms of previous integration steps) which has to be kept for the next integration step.
        Returns:
        The energy sample that was calculated energySamplesNeeded steps before in case all init steps have been done, the least recent otherwise.
        See Also:
        getEnergySample(int)
      • getEnergySample

        protected org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> getEnergySample​(int index)
        Gets the energy sample associated with the given index.
        Note, that index is related to previous integration steps, i.e.,:
        • index = 0 denotes the energy sample calculated in the most recent integration step
        • index = 1 denotes the energy sample calculated in the last but one step
        • ...
        • index = energySamplesNeeded - 1 denotes the least recent energy sample that is available
        Parameters:
        index - An integer value as described above.
        Returns:
        The energy sample corresponding to the given index or null if none are available.
        Throws:
        IndexOutOfBoundsException - In case the given index is not within the range described above.
      • getOldestPowerSample

        protected org.jscience.physics.amount.Amount<javax.measure.quantity.Power> getOldestPowerSample()
        Gets the least recently power sample (expressed in terms of previous integration steps) which has to be kept for the next integration step.
        Returns:
        The power sample that was passed to #calculateNext(Amount) powerSamplesNeede steps before in case all init steps have been done, the least recent one otherwise.
        See Also:
        #calculateNext(Amount), getPowerSample(int)
      • getPowerSample

        protected org.jscience.physics.amount.Amount<javax.measure.quantity.Power> getPowerSample​(int index)
        Gets the stored power sample associated with the given index.
        Note, that index is related to previous integration steps, i.e.,:
        • index = 0 denotes the power sample used in the most recent integration step
        • index = 1 denotes the power sample used in the last but one step
        • ...
        • index = powerSamplesNeeded - 1 denotes the least recent power sample that is available
        Parameters:
        index - An integer value as described above.
        Returns:
        The power sample corresponding to the given index, or null if none are available.
        Throws:
        IndexOutOfBoundsException - In case the given index is not within the range described above.
      • getMostRecentPowerSample

        protected org.jscience.physics.amount.Amount<javax.measure.quantity.Power> getMostRecentPowerSample()
        Gets the power sample that was used for the most recent integration step.
        Returns:
        An Amount denoting the power sample used for the most recent integration step.
      • getMostRecentEnergySample

        protected org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> getMostRecentEnergySample()
        Gets the energy sample that was calculated in the last integration step.
        Returns:
        An Amount denoting the energy sample that was most recently calulated.