Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Zero_engine.alpx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<AnyLogicWorkspace splitVersion="1"
WorkspaceVersion="1.9"
AnyLogicVersion="8.9.2.202410172112"
AnyLogicVersion="8.9.2.202410172101"
AlpVersion="8.9.2">
<Model>
<Id>1658477103134</Id>
Expand Down Expand Up @@ -1450,6 +1450,10 @@
<Id>1737025326025</Id>
<Name><![CDATA[J_LoadDurationCurves]]></Name>
</JavaClass>
<JavaClass>
<Id>1737633433233</Id>
<Name><![CDATA[J_EADieselTractor]]></Name>
</JavaClass>
</JavaClasses>
<RequiredLibraryReference>
<LibraryName>com.anylogic.libraries.modules.markup_descriptors</LibraryName>
Expand Down
2 changes: 1 addition & 1 deletion _alp/Agents/EnergyModel/Code/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ null, roundToDecimal( a.v_electricityImported_kWh-a.v_electricityExported_kWh, 2
int v_timeStepsElapsed_live = v_timeStepsElapsed;
v_timeStepsElapsed=0;

c_profiles.forEach(p -> p.updateValue(p_runStartTime_h));
c_profiles.forEach(p -> p.updateValue(p_runStartTime_h));
c_forecasts.forEach(p -> p.initializeForecast(p_runStartTime_h));
//c_forecasts.parallelStream().forEach(p -> p.initializeForecast(p_runStartTime_h));

Expand Down
7 changes: 4 additions & 3 deletions _alp/Agents/GridConnection/Code/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//p_parentNodeHeat = myParentNodeHeat;
}

if (p_ownerID!=null){
ConnectionOwner myParentConnectionOwner = findFirst(energyModel.pop_connectionOwners, p->p.p_actorID.equals(p_ownerID)) ;
if (p_owner!=null){
ConnectionOwner myParentConnectionOwner = p_owner; //findFirst(energyModel.pop_connectionOwners, p->p.p_actorID.equals(p_ownerID)) ;
if( myParentConnectionOwner instanceof ConnectionOwner) {
//p_ownerActor = myParentConnectionOwner;
l_ownerActor.connectTo(myParentConnectionOwner);
Expand Down Expand Up @@ -408,7 +408,6 @@ else if (j_ea instanceof J_EAConversionCurtailer || j_ea instanceof J_EAConversi
c_consumptionAssets.forEach(c -> c.f_updateAllFlows(0));
c_productionAssets.forEach(p -> p.f_updateAllFlows(0));
c_profileAssets.forEach(p -> p.f_updateAllFlows(energyModel.t_h));

/*ALCODEEND*/}

double f_resetStates()
Expand Down Expand Up @@ -1242,6 +1241,8 @@ else if (j_ea.energyAssetType == OL_EnergyAssetType.CHP) {
} else {
traceln( "Unrecognized profile type!");
}
} else if (j_ea instanceof J_EADieselTractor) {
c_profileAssets.add(j_ea);
} else {
traceln("Unrecognized energy asset %s in gridconnection %s", j_ea, this);
}
Expand Down
2 changes: 1 addition & 1 deletion _alp/Agents/GridConnection/Variables.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5875,7 +5875,7 @@
<ShowLabel>true</ShowLabel>
<Properties SaveInSnapshot="true" AccessType="public" StaticVariable="false">
<CollectionClass>ArrayList</CollectionClass>
<ElementClass>J_EAProfile</ElementClass>
<ElementClass>J_EA</ElementClass>
<ValueElementClass>String</ValueElementClass>
</Properties>
</Variable>
Expand Down
120 changes: 120 additions & 0 deletions _alp/Classes/Class.J_EADieselTractor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import java.util.*;

public class J_EADieselTractor extends J_EA implements Serializable {
final static double DIESEL_ENERGY_DENSITY_KWH_PER_L = 9.7;

final double[] dieselConsumptionPerWeek_L;
final double workDayStart_h = 6;
final double workDayEnd_h = 17;

/**
* @param parentAgent
* @param yearlyDieselConsumption_l diesel consumption of a single tractor for a whole year
* @param dieselConsumptionPerWeek profile of a year of diesel consumption.
* Usually expressed in L per ha per week for a specific crop or mix of crops.
* For our purpose the unit doesn't matter.
* @param timeStep_h
*/
public J_EADieselTractor(Agent parentAgent, double yearlyDieselConsumption_L, double[] dieselConsumptionPerWeek, double timeStep_h) {
if (parentAgent == null) {
throw new RuntimeException("Diesel tractor missing parent agent");
}

if (yearlyDieselConsumption_L <= 100.0) {
throw new RuntimeException(
String.format("Diesel tractor fuel usage conspicuously low: %d L", yearlyDieselConsumption_L)
);
}

if (dieselConsumptionPerWeek == null) {
throw new RuntimeException("Tractor diesel consumption profile is null");
}

if (dieselConsumptionPerWeek.length != 52) {
throw new RuntimeException(
String.format("Tractor diesel consumption profile has %d weeks instead of 52", dieselConsumptionPerWeek.length)
);
}

if (timeStep_h <= 0.0) {
throw new RuntimeException("Tractor timestep is off");
}

this.parentAgent = parentAgent;
this.dieselConsumptionPerWeek_L = calculateDieselConsumptionPerWeek_L(yearlyDieselConsumption_L, dieselConsumptionPerWeek);
this.timestep_h = timeStep_h;

this.activeConsumptionEnergyCarriers.add(OL_EnergyCarriers.DIESEL);
registerEnergyAsset();
}

@Override
public void f_updateAllFlows(double t_h) {
operate(t_h);
if (parentAgent instanceof GridConnection) {
((GridConnection)parentAgent).f_addFlows(flowsMap, this.energyUse_kW, this);
}
this.lastFlowsMap.cloneMap(this.flowsMap);
this.lastEnergyUse_kW = this.energyUse_kW;
this.clear();
}

@Override
public void operate(double t_h) {
if (!shouldWork(t_h)) {
this.flowsMap.clear();
return;
}

double currentPower_kW = currentPower_kW(t_h);

this.flowsMap.put(OL_EnergyCarriers.DIESEL, currentPower_kW);
this.energyUse_kW = currentPower_kW;
this.energyUsed_kWh += currentPower_kW * timestep_h;
}

private static double[] calculateDieselConsumptionPerWeek_L(double yearlyDieselConsumption_l, double[] weekProfile) {
var profileSum = Arrays.stream(weekProfile).sum();

return Arrays.stream(weekProfile)
.map(weekValue -> yearlyDieselConsumption_l * weekValue / profileSum)
.toArray();
}

private boolean shouldWork(double currentStep_h) {
return isWorkTime(currentStep_h) && isWorkDay();
}

private boolean isWorkTime(double currentStep_h) {
double timeOfDay = currentStep_h % 24;

return timeOfDay >= workDayStart_h && timeOfDay < workDayEnd_h;
}

private boolean isWorkDay() {
return ((GridConnection)parentAgent).energyModel.b_isWeekday;
}

private double workHoursPerWeek() {
return 5 * (workDayEnd_h - workDayStart_h);
}

private int workTimeStepsPerWeek() {
return roundToInt(workHoursPerWeek() / this.timestep_h);
}

private double currentPower_kW(double currentStep_h) {
int week = (int) Math.round(currentStep_h / (7 * 24));

double thisWeekDieselConsumption_L = this.dieselConsumptionPerWeek_L[week];
double thisWeekDieselConsumption_kWh = thisWeekDieselConsumption_L * DIESEL_ENERGY_DENSITY_KWH_PER_L;
double power_kW = thisWeekDieselConsumption_kWh / workHoursPerWeek();
return power_kW;
}

/**
* This number is here for model snapshot storing purpose<br>
* It needs to be changed when this class gets changed
*/
private static final long serialVersionUID = 1L;
}