Class SimpsonRuleCumulativeEnergyCalculator
- java.lang.Object
-
- de.fzi.power.interpreter.calculators.energy.AbstractCumulativeEnergyCalculator
-
- de.fzi.power.interpreter.calculators.energy.SimpsonRuleCumulativeEnergyCalculator
-
public class SimpsonRuleCumulativeEnergyCalculator extends AbstractCumulativeEnergyCalculator
This class contains an implementation of Simpson's rule for numerical integration given a series of sampling points and a sampling rate (more precisely, the temporal difference between two consecutive sampling points).
This implementation is tailored to calculating cumulative energy consumption based on power consumption samples. For details about Simpson's rule, cf.calculateNextInternal().- See Also:
AbstractCumulativeEnergyCalculator
-
-
Constructor Summary
Constructors Constructor Description SimpsonRuleCumulativeEnergyCalculator()Initializes a new instance of theSimpsonRuleCumulativeEnergyCalculatorclass.SimpsonRuleCumulativeEnergyCalculator(javax.measure.Measurable<javax.measure.quantity.Duration> samplingPeriod, javax.measure.Measurable<javax.measure.quantity.Duration> initialOffset)Initializes a new instance of theSimpsonRuleCumulativeEnergyCalculatorclass with given sampling period and initial offset.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.jscience.physics.amount.Amount<javax.measure.quantity.Energy>calculateInitValue(int initValueIndex)Method to be implemented by subclasses which contains the initialization steps.protected org.jscience.physics.amount.Amount<javax.measure.quantity.Energy>calculateNextInternal()Calculates the next energy sample, i.e., does the next integration step using Simpson's rule.
That is, for all energy samplesy[i]it holds:
y[i] = y[i-2] + weighting * (x[i] + 4 * x[i-1] + x[i-2])
wherex[i], x[i-1], x[i-2]are the most recent power samples
andweighting = samplingPeriod / 3.voidsetSamplingPeriod(javax.measure.Measurable<javax.measure.quantity.Duration> samplingPeriod)Sets the sampling period, i.e., the temporal difference between the next consecutive power samples.-
Methods inherited from class de.fzi.power.interpreter.calculators.energy.AbstractCumulativeEnergyCalculator
calculateNext, getCurrentlyStoredEnergySamplesCount, getCurrentlyStoredPowerSamplesCount, getDefaultResultUnit, getEnergySample, getInitialOffset, getMostRecentEnergySample, getMostRecentPowerSample, getOldestEnergySample, getOldestPowerSample, getPowerSample, getResultUnit, getSamplingPeriod, reset, setOffset
-
-
-
-
Constructor Detail
-
SimpsonRuleCumulativeEnergyCalculator
public SimpsonRuleCumulativeEnergyCalculator()
Initializes a new instance of theSimpsonRuleCumulativeEnergyCalculatorclass.
-
SimpsonRuleCumulativeEnergyCalculator
public SimpsonRuleCumulativeEnergyCalculator(javax.measure.Measurable<javax.measure.quantity.Duration> samplingPeriod, javax.measure.Measurable<javax.measure.quantity.Duration> initialOffset)Initializes a new instance of theSimpsonRuleCumulativeEnergyCalculatorclass with given sampling period and initial offset.- Parameters:
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:samplingPeriodisnullor does not represent a positive durationinitialOffsetisnullor represents a negative duration
- See Also:
SimpsonRuleCumulativeEnergyCalculator(),AbstractCumulativeEnergyCalculator.getDefaultResultUnit(),AbstractCumulativeEnergyCalculator.setOffset(Measurable),setSamplingPeriod(Measurable),AbstractCumulativeEnergyCalculator.getResultUnit()
-
-
Method Detail
-
setSamplingPeriod
public void setSamplingPeriod(javax.measure.Measurable<javax.measure.quantity.Duration> samplingPeriod)
Description copied from class:AbstractCumulativeEnergyCalculatorSets 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.- Overrides:
setSamplingPeriodin classAbstractCumulativeEnergyCalculator- Parameters:
samplingPeriod- AMeasurabledenoting the sampling period, i.e., the temporal difference between two consecutive power samples.
-
calculateNextInternal
protected org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> calculateNextInternal()
Calculates the next energy sample, i.e., does the next integration step using Simpson's rule.
That is, for all energy samplesy[i]it holds:
y[i] = y[i-2] + weighting * (x[i] + 4 * x[i-1] + x[i-2])
wherex[i], x[i-1], x[i-2]are the most recent power samples
andweighting = samplingPeriod / 3.- Specified by:
calculateNextInternalin classAbstractCumulativeEnergyCalculator- Returns:
- An
Amountdenoting the calculated energy sampley[i].
-
calculateInitValue
protected org.jscience.physics.amount.Amount<javax.measure.quantity.Energy> calculateInitValue(int initValueIndex)
Description copied from class:AbstractCumulativeEnergyCalculatorMethod to be implemented by subclasses which contains the initialization steps.- Specified by:
calculateInitValuein classAbstractCumulativeEnergyCalculator- Parameters:
initValueIndex- The number of the init step.- Returns:
- The energy sample calculated by the init step.
-
-