Class AbstractCumulativeEnergyCalculator
- java.lang.Object
-
- de.fzi.power.interpreter.calculators.energy.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 protectedAbstractCumulativeEnergyCalculator(int powerSamplesNeeded, int energySamplesNeeded, int numberOfInitSteps)Initializes a new instance of theAbstractCumulativeEnergyCalculatorclass with the given properties.protectedAbstractCumulativeEnergyCalculator(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 theAbstractCumulativeEnergyCalculatorclass with the given properties.protectedAbstractCumulativeEnergyCalculator(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 theAbstractCumulativeEnergyCalculatorclass 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 intgetCurrentlyStoredEnergySamplesCount()Gets the number of already calculated energy samples which are currently kept for integration.protected intgetCurrentlyStoredPowerSamplesCount()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 = 0denotes the energy sample calculated in the most recent integration stepindex = 1denotes the energy sample calculated in the last but one step ...index = energySamplesNeeded - 1denotes the least recent energy sample that is availableorg.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 = 0denotes the power sample used in the most recent integration stepindex = 1denotes the power sample used in the last but one step ...index = powerSamplesNeeded - 1denotes the least recent power sample that is availablejavax.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.voidreset()Resets the state of this instance.voidsetOffset(javax.measure.Measurable<javax.measure.quantity.Duration> initialOffset)Sets the initial offset, i.e., the temporal offset of the first power sample.voidsetSamplingPeriod(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 theAbstractCumulativeEnergyCalculatorclass 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- AMeasurabledenoting the sampling period, i.e., the temporal difference between two consecutive power samples.initialOffset- AMeasurabledenoting the temporal offset of the first power sample, i.e., the point in time it was taken.resultUnit- AUnitwhich defining the unit of the calculated energy samples.- Throws:
IllegalArgumentException- AnIllegalArgumentExceptionis thrown in one of the following cases:powerSamplesNeeded,energySamplesNeededornumberOfInitStepsare< 0resultUnitisnullsamplingPerioddoes not represent a positive durationinitialOffsetrepresents 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 theAbstractCumulativeEnergyCalculatorclass 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- AMeasurabledenoting the sampling period, i.e., the temporal difference between two consecutive power samples.initialOffset- AMeasurabledenoting the temporal offset of the first power sample, i.e., the point in time it was taken.- Throws:
IllegalArgumentException- AnIllegalArgumentExceptionis thrown in one of the following cases:powerSamplesNeeded,energySamplesNeededornumberOfInitStepsare< 0samplingPerioddoes not represent a positive durationinitialOffsetrepresents 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 theAbstractCumulativeEnergyCalculatorclass with the given properties. The resulting energy samples are expressed using the default energy unit defined in this class. Additionally, a default sampling period of10sand an initial offset of0sis 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- AnIllegalArgumentExceptionis thrown ifpowerSamplesNeeded,energySamplesNeededornumberOfInitStepsare< 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 to0s, 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- AMeasurabledenoting the sampling period, i.e., the temporal difference between two consecutive power samples.- Throws:
IllegalArgumentException- In case the given duration isnullor 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- AMeasurabledenoting the temporal offset, i.e., the point in time it was taken.- Throws:
IllegalArgumentException- In caseinitialOffsetisnullor negative
-
getInitialOffset
public org.jscience.physics.amount.Amount<javax.measure.quantity.Duration> getInitialOffset()
Gets the initial offset.- Returns:
- An
Amountdenoting 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
Amountdenoting 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
Unitdenoting 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
UnitdenotingWh(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- AMeasurableholding the (most recent) power sample to be used for calculation.- Returns:
- An
Amountholding the calculated cumulative energy sample. - Throws:
IllegalArgumentException- In case the given power sample isnull.
-
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
<= powerSamplesNeededin case not all required init steps have been done yet,
powerSamplesNeededotherwise. - 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
<= energySamplesNeededin case not all required init steps have been done yet,
energySamplesNeededotherwise. - 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
energySamplesNeededsteps 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 = 0denotes the energy sample calculated in the most recent integration stepindex = 1denotes the energy sample calculated in the last but one step- ...
index = energySamplesNeeded - 1denotes 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
nullif none are available. - Throws:
IndexOutOfBoundsException- In case the givenindexis 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)powerSamplesNeedesteps 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 = 0denotes the power sample used in the most recent integration stepindex = 1denotes the power sample used in the last but one step- ...
index = powerSamplesNeeded - 1denotes 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
nullif none are available. - Throws:
IndexOutOfBoundsException- In case the givenindexis 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
Amountdenoting 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
Amountdenoting the energy sample that was most recently calulated.
-
-