Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/df/#917-Refactor-Th…
Browse files Browse the repository at this point in the history
…ermalEnergyDemand' into df/#827_fix_hp_storage_refill
  • Loading branch information
danielfeismann committed Aug 21, 2024
2 parents b07c1f8 + ced3b55 commit 3696479
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- External simulation should provide information about next tick of MobSim [#776](https://github.com/ie3-institute/simona/issues/776)
- Reverted temporary workaround in `spotless.gradle` [#681](https://github.com/ie3-institute/simona/issues/681)
- Updated AUTHORS.md [#904](https://github.com/ie3-institute/simona/issues/904)
- Updated `Gradle` to version V8.10 [#829](https://github.com/ie3-institute/simona/issues/829)
- Updated AUTHORS.md [#905](https://github.com/ie3-institute/simona/issues/905)
- Prepare ThermalStorageTestData for Storage without storageVolumeLvlMin [#894](https://github.com/ie3-institute/simona/issues/894)

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
14 changes: 9 additions & 5 deletions src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import edu.ie3.datamodel.models.result.thermal.{
CylindricalStorageResult,
ThermalHouseResult,
}
import edu.ie3.simona.exceptions.InvalidParameterException
import edu.ie3.simona.exceptions.agent.InconsistentStateException
import edu.ie3.simona.model.thermal.ThermalGrid.{
ThermalEnergyDemand,
Expand Down Expand Up @@ -666,13 +667,12 @@ object ThermalGrid {

def hasRequiredDemand: Boolean = required > zeroMWH

def hasAdditionalDemand: Boolean = possible > required
def hasAdditionalDemand: Boolean = possible > zeroMWH
}
object ThermalEnergyDemand {

/** Builds a new instance of [[ThermalEnergyDemand]]. If the possible energy
* is less than the required energy, this is considered to be a bad state
* and the required energy is curtailed to the possible energy.
* is less than the required energy, this is considered to be a bad state.
* @param required
* The absolutely required energy to reach target state
* @param possible
Expand All @@ -684,8 +684,12 @@ object ThermalGrid {
required: Energy,
possible: Energy,
): ThermalEnergyDemand = {
if (possible < required)
new ThermalEnergyDemand(possible, possible)
if (
math.abs(possible.toKilowattHours) < math.abs(required.toKilowattHours)
)
throw new InvalidParameterException(
s"The possible amount of energy {$possible} is smaller than the required amount of energy {$required}. This is not supported."
)
else
new ThermalEnergyDemand(required, possible)
}
Expand Down
49 changes: 38 additions & 11 deletions src/test/scala/edu/ie3/simona/model/thermal/ThermalGridSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package edu.ie3.simona.model.thermal

import edu.ie3.simona.exceptions.InvalidParameterException
import edu.ie3.simona.model.thermal.ThermalGrid.ThermalEnergyDemand
import edu.ie3.simona.test.common.UnitSpec
import squants.energy.{MegawattHours, WattHours, Watts}
Expand All @@ -20,14 +21,22 @@ class ThermalGridSpec extends UnitSpec {

"Testing the thermal energy demand" when {
"instantiating it from given values" should {
"correct non-sensible input" in {
"throw exception for non-sensible input (positive)" in {
val possible = MegawattHours(40d)
val required = MegawattHours(42d)

val energyDemand = ThermalEnergyDemand(required, possible)
intercept[InvalidParameterException] {
ThermalEnergyDemand(required, possible)
}.getMessage shouldBe s"The possible amount of energy {$possible} is smaller than the required amount of energy {$required}. This is not supported."
}

energyDemand.required should approximate(possible)
energyDemand.possible should approximate(possible)
"throw exception for non-sensible input (negative)" in {
val possible = MegawattHours(-40d)
val required = MegawattHours(-42d)

intercept[InvalidParameterException] {
ThermalEnergyDemand(required, possible)
}.getMessage shouldBe s"The possible amount of energy {$possible} is smaller than the required amount of energy {$required}. This is not supported."
}

"set the correct values, if they are sensible" in {
Expand All @@ -51,22 +60,30 @@ class ThermalGridSpec extends UnitSpec {
}

"checking for required and additional demand" should {
"return proper information, if no required but additional demand is apparent" in {
"return proper information, if no required and no additional demand is apparent" in {
val required = MegawattHours(0d)
val possible = MegawattHours(45d)
val possible = MegawattHours(0d)

val energyDemand = ThermalEnergyDemand(required, possible)
energyDemand.hasRequiredDemand shouldBe false
energyDemand.hasAdditionalDemand shouldBe true
energyDemand.hasAdditionalDemand shouldBe false
}

"return proper information, if required but no additional demand is apparent" in {
val required = MegawattHours(45d)
"return proper information, if no required but additional demand is apparent" in {
val required = MegawattHours(0d)
val possible = MegawattHours(45d)

val energyDemand = ThermalEnergyDemand(required, possible)
energyDemand.hasRequiredDemand shouldBe true
energyDemand.hasAdditionalDemand shouldBe false
energyDemand.hasRequiredDemand shouldBe false
energyDemand.hasAdditionalDemand shouldBe true
}

"throw exception, if required demand is higher than possible demand" in {
val required = MegawattHours(1d)
val possible = MegawattHours(0d)
intercept[InvalidParameterException] {
ThermalEnergyDemand(required, possible)
}.getMessage shouldBe s"The possible amount of energy {$possible} is smaller than the required amount of energy {$required}. This is not supported."
}

"return proper information, if required and additional demand is apparent" in {
Expand All @@ -77,6 +94,16 @@ class ThermalGridSpec extends UnitSpec {
energyDemand.hasRequiredDemand shouldBe true
energyDemand.hasAdditionalDemand shouldBe true
}

// FIXME: Think about "negative demand", maybe add more cases as well
"return proper information, if no required but additional demand is apparent (negative)" in {
val required = MegawattHours(-10d)
val possible = MegawattHours(-45d)

val energyDemand = ThermalEnergyDemand(required, possible)
energyDemand.hasRequiredDemand shouldBe false
energyDemand.hasAdditionalDemand shouldBe true
}
}

"adding two demands" should {
Expand Down

0 comments on commit 3696479

Please sign in to comment.