Skip to content

Commit

Permalink
introduce DomesticHotWaterStorageResult
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfeismann committed Aug 26, 2024
1 parent 852fa78 commit 91bea33
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.ie3.datamodel.models.Entity;
import edu.ie3.datamodel.models.StandardUnits;
import edu.ie3.datamodel.models.result.thermal.CylindricalStorageResult;
import edu.ie3.datamodel.models.result.thermal.DomesticHotWaterStorageResult;
import edu.ie3.datamodel.models.result.thermal.ThermalHouseResult;
import edu.ie3.datamodel.models.result.thermal.ThermalUnitResult;
import java.time.ZonedDateTime;
Expand All @@ -28,7 +29,10 @@ public class ThermalResultFactory extends ModelResultFactory<ThermalUnitResult>
private static final String FILL_LEVEL = "fillLevel";

public ThermalResultFactory() {
super(ThermalHouseResult.class, CylindricalStorageResult.class);
super(
ThermalHouseResult.class,
CylindricalStorageResult.class,
DomesticHotWaterStorageResult.class);
}

/**
Expand All @@ -38,7 +42,11 @@ public ThermalResultFactory() {
* @param dateTimeFormatter parse date time strings
*/
public ThermalResultFactory(DateTimeFormatter dateTimeFormatter) {
super(dateTimeFormatter, ThermalHouseResult.class, CylindricalStorageResult.class);
super(
dateTimeFormatter,
ThermalHouseResult.class,
CylindricalStorageResult.class,
DomesticHotWaterStorageResult.class);
}

@Override
Expand Down Expand Up @@ -75,6 +83,14 @@ protected ThermalUnitResult buildModel(EntityData data) {

return new CylindricalStorageResult(
zdtTime, inputModelUuid, energyQuantity, qDotQuantity, fillLevelQuantity);
} else if (clazz.equals(DomesticHotWaterStorageResult.class)) {
ComparableQuantity<Energy> energyQuantity =
data.getQuantity(ENERGY, StandardUnits.ENERGY_RESULT);
ComparableQuantity<Dimensionless> fillLevelQuantity =
data.getQuantity(FILL_LEVEL, StandardUnits.FILL_LEVEL);

return new DomesticHotWaterStorageResult(
zdtTime, inputModelUuid, energyQuantity, qDotQuantity, fillLevelQuantity);
} else {
throw new FactoryException("Cannot process " + clazz.getSimpleName() + ".class.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import edu.ie3.datamodel.models.result.connector.Transformer3WResult;
import edu.ie3.datamodel.models.result.system.*;
import edu.ie3.datamodel.models.result.thermal.CylindricalStorageResult;
import edu.ie3.datamodel.models.result.thermal.DomesticHotWaterStorageResult;
import edu.ie3.datamodel.models.result.thermal.ThermalHouseResult;
import edu.ie3.datamodel.utils.Try;
import edu.ie3.datamodel.utils.Try.*;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class ResultEntityProcessor extends EntityProcessor<ResultEntity> {
NodeResult.class,
ThermalHouseResult.class,
CylindricalStorageResult.class,
DomesticHotWaterStorageResult.class,
EmResult.class,
FlexOptionsResult.class,
CongestionResult.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* © 2024. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.models.result.thermal;

import edu.ie3.datamodel.models.StandardUnits;
import java.time.ZonedDateTime;
import java.util.Objects;
import java.util.UUID;
import javax.measure.quantity.Dimensionless;
import javax.measure.quantity.Energy;
import javax.measure.quantity.Power;
import tech.units.indriya.ComparableQuantity;

/** Abstract class representing the common results of different types of thermal storages */
public abstract class AbstractThermalStorageResult extends ThermalStorageResult {
/** Fill level of the storage */
private ComparableQuantity<Dimensionless> fillLevel;

/**
* Constructs the result with
*
* @param time date and time when the result is produced
* @param inputModel uuid of the input model that produces the result
* @param energy Currently stored energy
* @param qDot Heat power flowing into (&gt; 0) or coming from (&lt; 0) the storage
* @param fillLevel Fill level of the storage
*/
public AbstractThermalStorageResult(
ZonedDateTime time,
UUID inputModel,
ComparableQuantity<Energy> energy,
ComparableQuantity<Power> qDot,
ComparableQuantity<Dimensionless> fillLevel) {
super(time, inputModel, energy, qDot);
this.fillLevel = fillLevel.to(StandardUnits.FILL_LEVEL);
}

public ComparableQuantity<Dimensionless> getFillLevel() {
return fillLevel;
}

public void setFillLevel(ComparableQuantity<Dimensionless> fillLevel) {
this.fillLevel = fillLevel.to(StandardUnits.FILL_LEVEL);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
AbstractThermalStorageResult that = (AbstractThermalStorageResult) o;
return fillLevel.equals(that.fillLevel);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), fillLevel);
}

@Override
public String toString() {
return getClass().getSimpleName()
+ "{"
+ "time="
+ getTime()
+ ", inputModel="
+ getInputModel()
+ ", qDot="
+ getqDot()
+ ", energy="
+ getEnergy()
+ ", fillLevel="
+ fillLevel
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,22 @@
*/
package edu.ie3.datamodel.models.result.thermal;

import edu.ie3.datamodel.models.StandardUnits;
import edu.ie3.datamodel.models.input.thermal.CylindricalStorageInput;
import java.time.ZonedDateTime;
import java.util.Objects;
import java.util.UUID;
import javax.measure.quantity.Dimensionless;
import javax.measure.quantity.Energy;
import javax.measure.quantity.Power;
import tech.units.indriya.ComparableQuantity;

/** Respresents the results of {@link CylindricalStorageInput} */
public class CylindricalStorageResult extends ThermalStorageResult {
/** Fill level of the storage */
private ComparableQuantity<Dimensionless> fillLevel;
/** Represents the results of Cylindrical Storage */
public class CylindricalStorageResult extends AbstractThermalStorageResult {

/**
* Constructs the result with
*
* @param time date and time when the result is produced
* @param inputModel uuid of the input model that produces the result
* @param energy Currently stored energy
* @param qDot Heat power flowing into (&gt; 0) or coming from (&lt; 0) the storage
* @param fillLevel Fill level of the storage
*/
public CylindricalStorageResult(
ZonedDateTime time,
UUID inputModel,
ComparableQuantity<Energy> energy,
ComparableQuantity<Power> qDot,
ComparableQuantity<Dimensionless> fillLevel) {
super(time, inputModel, energy, qDot);
this.fillLevel = fillLevel.to(StandardUnits.FILL_LEVEL);
}

public ComparableQuantity<Dimensionless> getFillLevel() {
return fillLevel;
}

public void setFillLevel(ComparableQuantity<Dimensionless> fillLevel) {
this.fillLevel = fillLevel.to(StandardUnits.FILL_LEVEL);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
CylindricalStorageResult that = (CylindricalStorageResult) o;
return fillLevel.equals(that.fillLevel);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), fillLevel);
}

@Override
public String toString() {
return "CylindricalStorageResult{"
+ "time="
+ getTime()
+ ", inputModel="
+ getInputModel()
+ ", qDot="
+ getqDot()
+ ", energy="
+ getEnergy()
+ ", fillLevel="
+ fillLevel
+ '}';
super(time, inputModel, energy, qDot, fillLevel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* © 2024. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.models.result.thermal;

import java.time.ZonedDateTime;
import java.util.UUID;
import javax.measure.quantity.Dimensionless;
import javax.measure.quantity.Energy;
import javax.measure.quantity.Power;
import tech.units.indriya.ComparableQuantity;

/** Represents the results of Domestic Hot Water Storage */
public class DomesticHotWaterStorageResult extends AbstractThermalStorageResult {

public DomesticHotWaterStorageResult(
ZonedDateTime time,
UUID inputModel,
ComparableQuantity<Energy> energy,
ComparableQuantity<Power> qDot,
ComparableQuantity<Dimensionless> fillLevel) {
super(time, inputModel, energy, qDot, fillLevel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import edu.ie3.datamodel.exceptions.FactoryException
import edu.ie3.datamodel.io.factory.EntityData
import edu.ie3.datamodel.models.StandardUnits
import edu.ie3.datamodel.models.result.thermal.CylindricalStorageResult
import edu.ie3.datamodel.models.result.thermal.DomesticHotWaterStorageResult
import edu.ie3.datamodel.models.result.thermal.ThermalHouseResult
import edu.ie3.datamodel.models.result.thermal.ThermalUnitResult
import edu.ie3.datamodel.utils.Try
Expand All @@ -23,7 +24,8 @@ class ThermalResultFactoryTest extends Specification implements FactoryTestHelpe
def resultFactory = new ThermalResultFactory()
def expectedClasses = [
ThermalHouseResult,
CylindricalStorageResult
CylindricalStorageResult,
DomesticHotWaterStorageResult
]

expect:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import edu.ie3.datamodel.models.result.connector.Transformer2WResult
import edu.ie3.datamodel.models.result.connector.Transformer3WResult
import edu.ie3.datamodel.models.result.system.*
import edu.ie3.datamodel.models.result.thermal.CylindricalStorageResult
import edu.ie3.datamodel.models.result.thermal.DomesticHotWaterStorageResult
import edu.ie3.datamodel.models.result.thermal.ThermalHouseResult
import edu.ie3.datamodel.models.timeseries.IntValue
import edu.ie3.datamodel.models.timeseries.TimeSeries
Expand Down Expand Up @@ -121,7 +122,8 @@ class ProcessorProviderTest extends Specification implements TimeSeriesTestData
NodeResult,
CongestionResult,
ThermalHouseResult,
CylindricalStorageResult
CylindricalStorageResult,
DomesticHotWaterStorageResult
]
// currently known processors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import edu.ie3.datamodel.models.result.connector.Transformer2WResult
import edu.ie3.datamodel.models.result.connector.Transformer3WResult
import edu.ie3.datamodel.models.result.system.*
import edu.ie3.datamodel.models.result.thermal.CylindricalStorageResult
import edu.ie3.datamodel.models.result.thermal.DomesticHotWaterStorageResult
import edu.ie3.util.quantities.PowerSystemUnits
import spock.lang.Shared
import spock.lang.Specification
Expand Down Expand Up @@ -252,6 +253,30 @@ class ResultEntityProcessorTest extends Specification {
validProcessedElement == expectedResults
}

def "A ResultEntityProcessor should serialize a DomesticHotWaterStorageResult correctly"() {
given:
def sysPartResProcessor = new ResultEntityProcessor(DomesticHotWaterStorageResult)

Quantity<Power> qDot = Quantities.getQuantity(2, StandardUnits.Q_DOT_RESULT)
Quantity<Energy> energy = Quantities.getQuantity(3, StandardUnits.ENERGY_RESULT)
Quantity<Dimensionless> fillLevel = Quantities.getQuantity(20, Units.PERCENT)

def validResult = new DomesticHotWaterStorageResult(ZonedDateTime.parse("2020-01-30T17:26:44Z"), inputModel, energy, qDot, fillLevel)

def expectedResults = [
energy : '3.0',
fillLevel : '20.0',
inputModel: '22bea5fc-2cb2-4c61-beb9-b476e0107f52',
qDot : '2.0',
time : '2020-01-30T17:26:44Z']

when:
def validProcessedElement = sysPartResProcessor.handleEntity(validResult)

then:
validProcessedElement == expectedResults
}

def "A ResultEntityProcessor should throw an EntityProcessorException when it receives an entity result that is not eligible"() {

given:
Expand All @@ -270,7 +295,7 @@ class ResultEntityProcessorTest extends Specification {

def "The list of eligible entity classes for a ResultEntityProcessor should be valid"() {
given:
int noOfElements = 20 // number of all currently implemented entity results
int noOfElements = 21 // number of all currently implemented entity results

expect:
ResultEntityProcessor.eligibleEntityClasses.size() == noOfElements
Expand Down

0 comments on commit 91bea33

Please sign in to comment.