Skip to content

Commit

Permalink
Added a new J_EADieselTractor
Browse files Browse the repository at this point in the history
also added a collection to the GC canvas for these assets and updateAllFlows at operateFixedAssets
  • Loading branch information
Luc-Sol authored and Erikvv committed Jan 30, 2025
1 parent c23b968 commit 48b04ed
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Zero_engine.alpx
Original file line number Diff line number Diff line change
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
8 changes: 5 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,7 @@ 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));

c_tractorAssets.forEach(p -> p.f_updateAllFlows(energyModel.t_h));
/*ALCODEEND*/}

double f_resetStates()
Expand Down Expand Up @@ -1242,6 +1242,8 @@ else if (j_ea.energyAssetType == OL_EnergyAssetType.CHP) {
} else {
traceln( "Unrecognized profile type!");
}
} else if (j_ea instanceof J_EADieselTractor) {
c_tractorAssets.add(j_ea);
} else {
traceln("Unrecognized energy asset %s in gridconnection %s", j_ea, this);
}
Expand Down
18 changes: 18 additions & 0 deletions _alp/Agents/GridConnection/Variables.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6137,4 +6137,22 @@
<ValueElementClass>String</ValueElementClass>
</Properties>
</Variable>
<Variable Class="CollectionVariable">
<Id>1737642450668</Id>
<Name><![CDATA[c_tractorAssets]]></Name>
<X>600</X>
<Y>250</Y>
<Label>
<X>10</X>
<Y>0</Y>
</Label>
<PublicFlag>false</PublicFlag>
<PresentationFlag>true</PresentationFlag>
<ShowLabel>true</ShowLabel>
<Properties SaveInSnapshot="true" AccessType="public" StaticVariable="false">
<CollectionClass>ArrayList</CollectionClass>
<ElementClass>J_EA</ElementClass>
<ValueElementClass>String</ValueElementClass>
</Properties>
</Variable>
</Variables>
77 changes: 77 additions & 0 deletions _alp/Classes/Class.J_EADieselTractor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import java.util.*;

/**
* J_EADieselTractor
*/
public class J_EADieselTractor extends J_EA implements Serializable {
Double[] dieselConsumptionPerWeek;
Double yearlyDieselConsumption_l;

/**
* Default constructor
*/
public J_EADieselTractor() {
}

/**
* Constructor initializing the fields
*/
public J_EADieselTractor(Agent parentAgent, Double yearlyDieselConsumption_l, Double[] dieselConsumptionPerWeek, double timeStep_h) {
this.parentAgent = parentAgent;
this.yearlyDieselConsumption_l = yearlyDieselConsumption_l;
this.dieselConsumptionPerWeek = 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) {
double timeOfDay = t_h % 24;
if (timeOfDay < 6 || timeOfDay > 17) {
this.flowsMap.clear();
return;
}
if (parentAgent instanceof GridConnection) {
if (!((GridConnection)parentAgent).energyModel.b_isWeekday) {
this.flowsMap.clear();
return;
}
}
// TODO: Extract this calculation from operate and only do this once a week and store dieselPerTimeStep
int week = (int)(t_h / 168);
double weeklyDieselConsumption_l = this.dieselConsumptionPerWeek[week] / Arrays.stream(dieselConsumptionPerWeek).mapToDouble(f -> f.doubleValue()).sum() * this.yearlyDieselConsumption_l;
double weeklyDieselConsumption_kWh = weeklyDieselConsumption_l * 9.7;
int totalWorkTimeSteps = roundToInt(5 * (17 - 6) / this.timestep_h);
double dieselPerTimeStep_kW = weeklyDieselConsumption_l / totalWorkTimeSteps;

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


@Override
public String toString() {
return super.toString();
}

/**
* 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;

}

0 comments on commit 48b04ed

Please sign in to comment.