Skip to content

Commit 0dc0bd0

Browse files
authored
Merge pull request #247 from Zenmo/DoubleCompare
Double compare
2 parents 9ff3b0c + 1cc9aa5 commit 0dc0bd0

File tree

6 files changed

+51
-18
lines changed

6 files changed

+51
-18
lines changed

Zero_engine.alpx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,11 +1876,6 @@ EXCLUDE_PV => Use PV profile to preprocess gridnode profile to create a more acc
18761876
<Name><![CDATA[J_HeatingFunctionLibrary]]></Name>
18771877
<Folder>1762850578079</Folder>
18781878
</JavaClass>
1879-
<JavaClass>
1880-
<Id>1763570262548</Id>
1881-
<Name><![CDATA[J_GlobalParameters]]></Name>
1882-
<Folder>1764938574089</Folder>
1883-
</JavaClass>
18841879
<JavaClass>
18851880
<Id>1764337491572</Id>
18861881
<Name><![CDATA[I_ChargingRequest]]></Name>
@@ -1956,6 +1951,11 @@ EXCLUDE_PV => Use PV profile to preprocess gridnode profile to create a more acc
19561951
<Name><![CDATA[J_EAChargingSession]]></Name>
19571952
<Folder>1752677832758</Folder>
19581953
</JavaClass>
1954+
<JavaClass>
1955+
<Id>1770210283060</Id>
1956+
<Name><![CDATA[DoubleCompare]]></Name>
1957+
<Folder>1764938574089</Folder>
1958+
</JavaClass>
19591959
</JavaClasses>
19601960
<RequiredLibraryReference>
19611961
<LibraryName>com.anylogic.libraries.modules.markup_descriptors</LibraryName>

_alp/Agents/GridConnection/Code/Functions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
double f_connectionMetering(J_TimeVariables timeVariables,boolean isRapidRun)
3737
{/*ALCODESTART::1660212665961*/
38-
if ( abs(fm_currentConsumptionFlows_kW.get(OL_EnergyCarriers.HEAT) - fm_currentProductionFlows_kW.get(OL_EnergyCarriers.HEAT)) > 0.1 && p_parentNodeHeat == null ) {
38+
if ( DoubleCompare.greaterThanZero(abs(fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.HEAT))) && p_parentNodeHeat == null ) {
3939
//if (p_BuildingThermalAsset == null || !p_BuildingThermalAsset.hasHeatBuffer()) {
4040
traceln("heat consumption: %s kW", fm_currentConsumptionFlows_kW.get(OL_EnergyCarriers.HEAT));
4141
traceln("heat production: %s kW", fm_currentProductionFlows_kW.get(OL_EnergyCarriers.HEAT));
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.lang.Math;
2+
/**
3+
* DoubleCompare
4+
*/
5+
public class DoubleCompare {
6+
private final static int FLOATINGPOINTPRECISION = 10;
7+
private final static double EPSILON = 1e-10;
8+
9+
public static boolean equalsZero(double d) {
10+
//d = round(d);
11+
//return d == 0.0;
12+
13+
return Math.abs(d) < EPSILON;
14+
}
15+
16+
public static boolean lessThanZero(double d) {
17+
//d = round(d);
18+
//return d < 0.0;
19+
return d < -EPSILON;
20+
}
21+
22+
public static boolean greaterThanZero(double d) {
23+
//d = round(d);
24+
//return d > 0.0;
25+
return d > EPSILON;
26+
}
27+
28+
public static boolean equals(double a, double b) {
29+
30+
//a = round(a);
31+
//b = round(b);
32+
//return a == b;
33+
return Math.abs(a - b) < EPSILON;
34+
35+
}
36+
37+
//private static double round(double d) {
38+
//return Math.floor(d * Math.pow(10, FLOATINGPOINTPRECISION) + 0.5) / Math.pow(10, FLOATINGPOINTPRECISION);
39+
//}
40+
41+
}

_alp/Classes/Class.J_EABuilding.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public J_FlowPacket f_updateAllFlows(double powerFraction_fr, J_TimeVariables ti
7373

7474
@Override
7575
public void operate(double powerFraction_fr, J_TimeVariables timeVariables) {
76-
if (powerFraction_fr < 0) {
76+
77+
if (DoubleCompare.lessThanZero(powerFraction_fr)) {
7778
throw new RuntimeException("Cooling of the J_EABuilding is not yet supported.");
7879
}
79-
8080
double lossPower_kW = calculateLoss(); // Heat exchange with environment through convection
8181
double solarHeating_kW = solarHeating(); // Heat influx from sunlight
8282
this.energyUse_kW = lossPower_kW - solarHeating_kW;

_alp/Classes/Class.J_EAConversion.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ private void construct(I_AssetOwner owner, OL_EnergyAssetType energyAssetType, d
4343

4444
@Override
4545
public J_FlowPacket f_updateAllFlows(double powerFraction_fr, J_TimeVariables timeVariables) {
46-
powerFraction_fr = roundToDecimal(powerFraction_fr, J_GlobalParameters.floatingPointPrecision);
47-
if(powerFraction_fr < 0) {
46+
if(DoubleCompare.lessThanZero(powerFraction_fr)) {
4847
throw new RuntimeException("Impossible to operate conversion asset with negative powerfraction.");
4948
}
50-
else if ( powerFraction_fr == 0 ) {
49+
else if ( DoubleCompare.equalsZero(powerFraction_fr) ) {
5150
this.lastFlowsMap.clear();
5251
this.lastEnergyUse_kW = 0;
5352
J_FlowsMap flowsMapCopy = new J_FlowsMap();

_alp/Classes/Class.J_GlobalParameters.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)