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 protected
AbstractCumulativeEnergyCalculator(int powerSamplesNeeded, int energySamplesNeeded, int numberOfInitSteps)
Initializes a new instance of theAbstractCumulativeEnergyCalculator
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 theAbstractCumulativeEnergyCalculator
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 theAbstractCumulativeEnergyCalculator
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 stepindex = 1
denotes the energy sample calculated in the last but one step ...index = energySamplesNeeded - 1
denotes 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 = 0
denotes the power sample used in the most recent integration stepindex = 1
denotes the power sample used in the last but one step ...index = powerSamplesNeeded - 1
denotes 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.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 theAbstractCumulativeEnergyCalculator
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
- AMeasurable
denoting the sampling period, i.e., the temporal difference between two consecutive power samples.initialOffset
- AMeasurable
denoting the temporal offset of the first power sample, i.e., the point in time it was taken.resultUnit
- AUnit
which defining the unit of the calculated energy samples.- Throws:
IllegalArgumentException
- AnIllegalArgumentException
is thrown in one of the following cases:powerSamplesNeeded
,energySamplesNeeded
ornumberOfInitSteps
are< 0
resultUnit
isnull
samplingPeriod
does not represent a positive durationinitialOffset
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 theAbstractCumulativeEnergyCalculator
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
- AMeasurable
denoting the sampling period, i.e., the temporal difference between two consecutive power samples.initialOffset
- AMeasurable
denoting the temporal offset of the first power sample, i.e., the point in time it was taken.- Throws:
IllegalArgumentException
- AnIllegalArgumentException
is thrown in one of the following cases:powerSamplesNeeded
,energySamplesNeeded
ornumberOfInitSteps
are< 0
samplingPeriod
does not represent a positive durationinitialOffset
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 theAbstractCumulativeEnergyCalculator
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 of10s
and an initial offset of0s
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
- AnIllegalArgumentException
is thrown ifpowerSamplesNeeded
,energySamplesNeeded
ornumberOfInitSteps
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 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
- AMeasurable
denoting the sampling period, i.e., the temporal difference between two consecutive power samples.- Throws:
IllegalArgumentException
- In case the given duration isnull
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
- AMeasurable
denoting the temporal offset, i.e., the point in time it was taken.- Throws:
IllegalArgumentException
- In caseinitialOffset
isnull
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
denotingWh
(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
- AMeasurable
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 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
<= 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 stepindex = 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 givenindex
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 stepindex = 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 givenindex
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.
-
-