Skip to content
Open
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
47 changes: 3 additions & 44 deletions _alp/Agents/EnergyModel/Code/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,6 @@
p_timeVariables.updateTimeVariables(v_timeStepsElapsed, p_timeParameters);

//// Store and reset model states
for (J_EA EA : c_energyAssets) {
EA.storeStatesAndReset();
}


for (GridConnection GC : c_gridConnections) {

if (GC.v_rapidRunData != null) {
Expand All @@ -255,21 +250,12 @@
GC.v_rapidRunData.connectionMetaData = GC.v_liveConnectionMetaData.getClone();
GC.v_rapidRunData.initializeAccumulators(GC.v_liveData.activeEnergyCarriers, GC.v_liveData.activeConsumptionEnergyCarriers, GC.v_liveData.activeProductionEnergyCarriers, GC.v_liveAssetsMetaData.activeAssetFlows); //f_initializeAccumulators();

GC.f_resetStates();
// f_resetStates resets the accumulators in rapidrundata, so must be after copying the previous run data
GC.f_resetStates(p_timeVariables);

GC.c_tripTrackers.forEach(tt->{
tt.storeStatesAndReset();
tt.setStartIndex(p_timeVariables, GC.f_getChargePoint());
//tt.prepareNextActivity(p_runStartTime_h*60, GC.f_getChargePoint());
});
if (GC instanceof GCHouse) {
if (((GCHouse)GC).p_cookingTracker != null) {
((GCHouse)GC).p_cookingTracker.storeStatesAndReset();
}
}
}
for (GridConnection GC : c_subGridConnections) {
GC.f_resetStates();
GC.f_resetStates(p_timeVariables);
}

for (GridNode GN : pop_gridNodes) {
Expand All @@ -285,19 +271,11 @@
if (b_storePreviousRapidRunData) {
EC.v_previousRunData = EC.v_rapidRunData;
}
/*EC.v_rapidRunData.assetsMetaData = EC.v_liveAssetsMetaData.getClone();
EC.v_rapidRunData.connectionMetaData = EC.v_liveConnectionMetaData.getClone();
if(EC.v_rapidRunData.getStoreTotalAssetFlows() == false){
EC.v_rapidRunData.setStoreTotalAssetFlows(true);
EC.v_rapidRunData.initializeAccumulators(p_runEndTime_h - p_runStartTime_h, p_timeStep_h, EC.v_liveData.activeEnergyCarriers, EC.v_liveData.activeConsumptionEnergyCarriers, EC.v_liveData.activeProductionEnergyCarriers, EC.v_liveAssetsMetaData.activeAssetFlows);
}*/
}
EC.v_rapidRunData = new J_RapidRunData(p_timeParameters, true);
EC.v_rapidRunData.assetsMetaData = EC.v_liveAssetsMetaData.getClone();
EC.v_rapidRunData.connectionMetaData = EC.v_liveConnectionMetaData.getClone();
//if(EC.v_rapidRunData.getStoreTotalAssetFlows() == false){
EC.v_rapidRunData.setStoreTotalAssetFlows(true);
//}
EC.v_rapidRunData.initializeAccumulators(EC.v_liveData.activeEnergyCarriers, EC.v_liveData.activeConsumptionEnergyCarriers, EC.v_liveData.activeProductionEnergyCarriers, EC.v_liveAssetsMetaData.activeAssetFlows);
EC.f_resetStates();

Expand Down Expand Up @@ -379,27 +357,8 @@
v_timeStepsElapsed = v_timeStepsElapsed_live;
p_timeVariables.updateTimeVariables(v_timeStepsElapsed, p_timeParameters);


for (J_EA EA : c_energyAssets) {
EA.restoreStates();
}

/*for (GridNode GN : pop_gridNodes) {
//Has no reset states
}*/

for (GridConnection GC : c_gridConnections) {
GC.f_resetStatesAfterRapidRun();
GC.c_tripTrackers.forEach(tt->{
tt.restoreStates();
//tt.prepareNextActivity((t_h-p_runStartTime_h)*60, GC.f_getChargePoint());
});
//GC.c_tripTrackers.forEach(tt->tt.prepareNextActivity((t_h-p_runStartTime_h)*60));
if (GC instanceof GCHouse) {
if (((GCHouse)GC).p_cookingTracker != null) {
((GCHouse)GC).p_cookingTracker.restoreStates();
}
}
}

v_isRapidRun = false;
Expand Down
32 changes: 23 additions & 9 deletions _alp/Agents/GridConnection/Code/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,34 +123,43 @@

/*ALCODEEND*/}

double f_resetStates()
double f_resetStates(J_TimeVariables timeVariables)
{/*ALCODESTART::1668983912731*/
fm_currentProductionFlows_kW.clear();
fm_currentConsumptionFlows_kW.clear();
fm_currentBalanceFlows_kW.clear();
fm_heatFromEnergyCarrier_kW.clear();
fm_consumptionForHeating_kW.clear();
//fm_currentAssetFlows_kW.clear(); // Why not this one??
//fm_currentAssetFlows_kW.clear(); // Why not this one?? (I'd have to check, but all these fm's are reset at calculateEnergyBalance, so they possibly could all be removed, ~Luc 20/03/26)

v_previousPowerElectricity_kW = 0;
v_previousPowerHeat_kW = 0;
//v_electricityPriceLowPassed_eurpkWh = 0;
//v_currentElectricityPriceConsumption_eurpkWh = 0;

v_rapidRunData.resetAccumulators(v_liveData.activeEnergyCarriers, v_liveData.activeConsumptionEnergyCarriers, v_liveData.activeProductionEnergyCarriers); //f_initializeAccumulators();

//Reset specific variables/collections in specific GC types (GCProduction, GConversion, etc.)
f_resetSpecificGCStates();

//Store states and reset EMS
// Reset other classes
if(p_energyManagement != null){
p_energyManagement.storeStatesAndReset();
}

//Store states and reset charge point
if(p_chargePoint != null){
p_chargePoint.storeStatesAndReset();
}

c_energyAssets.forEach(ea -> ea.storeStatesAndReset());

c_tripTrackers.forEach(tt -> {
tt.storeStatesAndReset();
tt.setStartIndex(timeVariables, f_getChargePoint());
}
);

if (p_cookingTracker != null) {
p_cookingTracker.storeStatesAndReset();
}
/*ALCODEEND*/}

double f_setOperatingSwitches()
Expand Down Expand Up @@ -321,25 +330,30 @@ else if(j_ea instanceof J_EAFlex j_eaFlex){

double f_resetSpecificGCStates()
{/*ALCODESTART::1717060111619*/

// to be overwritten by child GCs!
/*ALCODEEND*/}

double f_resetStatesAfterRapidRun()
{/*ALCODESTART::1717068094093*/
//Reset specificGC states after rapid run
f_resetSpecificGCStatesAfterRapidRun();

//Restore states in EMS
//Restore other classes
if(p_energyManagement != null){
p_energyManagement.restoreStates();
}

//Restore states in charge point
if(p_chargePoint != null){
p_chargePoint.restoreStates();
}

c_energyAssets.forEach(ea -> ea.restoreStates());

c_tripTrackers.forEach(tt-> tt.restoreStates());

if (p_cookingTracker != null) {
p_cookingTracker.restoreStates();
}
/*ALCODEEND*/}

double f_resetSpecificGCStatesAfterRapidRun()
Expand Down
5 changes: 5 additions & 0 deletions _alp/Agents/GridConnection/Code/Functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
<PublicFlag>false</PublicFlag>
<PresentationFlag>true</PresentationFlag>
<ShowLabel>true</ShowLabel>
<Parameter>
<Name><![CDATA[timeVariables]]></Name>
<Type><![CDATA[J_TimeVariables]]></Type>
</Parameter>
<Body xmlns:al="http://anylogic.com"/>
</Function>
<Function AccessType="default" StaticFunction="false">
Expand Down Expand Up @@ -238,6 +242,7 @@
<PublicFlag>false</PublicFlag>
<PresentationFlag>true</PresentationFlag>
<ShowLabel>true</ShowLabel>
<Body xmlns:al="http://anylogic.com"/>
</Function>
<Function AccessType="default" StaticFunction="false">
<ReturnModificator>VOID</ReturnModificator>
Expand Down
10 changes: 5 additions & 5 deletions _alp/Classes/Class.J_ActivityTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public abstract class J_ActivityTracker implements I_StoreStatesAndReset {
protected ArrayList<Double> endtimes_min = new ArrayList<>();
//private ArrayList<Double> eventMagnitude = new ArrayList<>();
public int nbActivities = 0;
public int v_eventIndex = 0;
protected int v_eventIndexStored =0;
public int eventIndex = 0;
protected int eventIndexStored =0;

/**
* Default constructor
Expand All @@ -37,12 +37,12 @@ public J_ActivityTracker(EnergyModel main, int rowIndex, double time_min) {
}

public void storeStatesAndReset() {
v_eventIndexStored = v_eventIndex;
v_eventIndex = 0;
eventIndexStored = eventIndex;
eventIndex = 0;
}

public void restoreStates() {
v_eventIndex = v_eventIndexStored;
eventIndex = eventIndexStored;
}


Expand Down
72 changes: 36 additions & 36 deletions _alp/Classes/Class.J_ActivityTrackerCooking.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public J_ActivityTrackerCooking(TextFile inputCookingActivities, int rowIndex, d
powerFractions_fr.add(ratio);
}

while ( starttimes_min.get(v_eventIndex) - time_min < 0) {
starttimes_min.set( v_eventIndex, starttimes_min.get(v_eventIndex) + 1440 ); // Source data is always just one day, repeating every day.
endtimes_min.set( v_eventIndex, endtimes_min.get(v_eventIndex) + 1440 ); // Source data is always just one day, repeating every day.
v_eventIndex++;
if ( v_eventIndex > starttimes_min.size() - 1 ) {
v_eventIndex = 0;
while ( starttimes_min.get(eventIndex) - time_min < 0) {
starttimes_min.set( eventIndex, starttimes_min.get(eventIndex) + 1440 ); // Source data is always just one day, repeating every day.
endtimes_min.set( eventIndex, endtimes_min.get(eventIndex) + 1440 ); // Source data is always just one day, repeating every day.
eventIndex++;
if ( eventIndex > starttimes_min.size() - 1 ) {
eventIndex = 0;
}
}

Expand All @@ -73,62 +73,62 @@ public J_ActivityTrackerCooking(TextFile inputCookingActivities, int rowIndex, d
public void manageActivities(J_TimeVariables timeVariables) {
double time_min = timeVariables.getAnyLogicTime_h() * 60;
//traceln("Cooking tracker current time: " + time_min);
//traceln("Event index: " + v_eventIndex);
//traceln("Event index: " + eventIndex);
//traceln("startTimes: " + starttimes_min);
//traceln("endTimes: " + endtimes_min);
//traceln("powerFractions_fr: " + powerFractions_fr);

if (cooking) {
if (time_min >= endtimes_min.get(v_eventIndex) ) { // end cooking session. Also check if a new one starts in this timestep!
if (time_min >= endtimes_min.get(eventIndex) ) { // end cooking session. Also check if a new one starts in this timestep!

//main.v_activeCookingSessions.decrementAndGet();
//traceln("End of cooking session, currently active cooking sessions %s", main.v_activeCookingSessions);
// factor to compensate for the fact that you might not be cooking for the entire timestep.
double fr = (time_min - this.endtimes_min.get(this.v_eventIndex)) / this.timeStep_min;
this.powerFraction_fr = fr * this.powerFractions_fr.get(this.v_eventIndex);
double fr = (time_min - this.endtimes_min.get(this.eventIndex)) / this.timeStep_min;
this.powerFraction_fr = fr * this.powerFractions_fr.get(this.eventIndex);

starttimes_min.set( v_eventIndex, starttimes_min.get(v_eventIndex) + 1440 );
endtimes_min.set( v_eventIndex, endtimes_min.get(v_eventIndex) + 1440 );
v_eventIndex++;
if ( v_eventIndex >= starttimes_min.size() ) {
v_eventIndex = 0;
starttimes_min.set( eventIndex, starttimes_min.get(eventIndex) + 1440 );
endtimes_min.set( eventIndex, endtimes_min.get(eventIndex) + 1440 );
eventIndex++;
if ( eventIndex >= starttimes_min.size() ) {
eventIndex = 0;
}
cooking=false;

if (time_min >= starttimes_min.get(v_eventIndex)) {
if (time_min >= starttimes_min.get(eventIndex)) {
// factor to compensate for the fact that you might not be cooking for the entire timestep.
fr = (time_min - this.starttimes_min.get(this.v_eventIndex)) / this.timeStep_min;
this.powerFraction_fr = fr * this.powerFractions_fr.get(this.v_eventIndex);
fr = (time_min - this.starttimes_min.get(this.eventIndex)) / this.timeStep_min;
this.powerFraction_fr = fr * this.powerFractions_fr.get(this.eventIndex);
//main.v_activeCookingSessions.incrementAndGet();
cooking=true;
traceln("Starting next cooking session in same timestep as previous session ended!! Rowindex %s, eventIndex %s\", rowIndex, v_eventIndex");
traceln("Starting next cooking session in same timestep as previous session ended!! Rowindex %s, eventIndex %s\", rowIndex, eventIndex");
}
}
else {
this.powerFraction_fr = this.starttimes_min.get(this.v_eventIndex);
this.powerFraction_fr = this.starttimes_min.get(this.eventIndex);
}
} else if (time_min >= starttimes_min.get(v_eventIndex) ) { // start cooking session. Also check if it ends within this timestep!
/*if (endtimes_min.get(v_eventIndex) - starttimes_min.get(v_eventIndex) > 100) {
traceln("Cooking event longer than 100 minutes!! Rowindex %s, eventIndex %s.", rowIndex, v_eventIndex);
} else if (time_min >= starttimes_min.get(eventIndex) ) { // start cooking session. Also check if it ends within this timestep!
/*if (endtimes_min.get(eventIndex) - starttimes_min.get(eventIndex) > 100) {
traceln("Cooking event longer than 100 minutes!! Rowindex %s, eventIndex %s.", rowIndex, eventIndex);
}*/

// factor to compensate for the fact that you might not be cooking for the entire timestep.
double fr = (time_min - this.starttimes_min.get(this.v_eventIndex)) / this.timeStep_min;
this.powerFraction_fr = fr * this.powerFractions_fr.get(this.v_eventIndex);
double fr = (time_min - this.starttimes_min.get(this.eventIndex)) / this.timeStep_min;
this.powerFraction_fr = fr * this.powerFractions_fr.get(this.eventIndex);
//main.v_activeCookingSessions.incrementAndGet();
cooking=true;
if (time_min >= endtimes_min.get(v_eventIndex) ) { // end cooking session in the same timestep? Still need to fix energy use for this case!!
if (time_min >= endtimes_min.get(eventIndex) ) { // end cooking session in the same timestep? Still need to fix energy use for this case!!

//main.v_activeCookingSessions.decrementAndGet();
//traceln("End of cooking session, currently active cooking sessions %s", main.v_activeCookingSessions);
fr = (this.endtimes_min.get(this.v_eventIndex) - this.starttimes_min.get(this.v_eventIndex)) / this.timeStep_min;
this.powerFraction_fr = fr * this.powerFractions_fr.get(this.v_eventIndex);
fr = (this.endtimes_min.get(this.eventIndex) - this.starttimes_min.get(this.eventIndex)) / this.timeStep_min;
this.powerFraction_fr = fr * this.powerFractions_fr.get(this.eventIndex);

starttimes_min.set( v_eventIndex, starttimes_min.get(v_eventIndex) + 1440 );
endtimes_min.set( v_eventIndex, endtimes_min.get(v_eventIndex) + 1440 );
v_eventIndex++;
if ( v_eventIndex >= starttimes_min.size() ) {
v_eventIndex = 0;
starttimes_min.set( eventIndex, starttimes_min.get(eventIndex) + 1440 );
endtimes_min.set( eventIndex, endtimes_min.get(eventIndex) + 1440 );
eventIndex++;
if ( eventIndex >= starttimes_min.size() ) {
eventIndex = 0;
}
cooking=false;
}
Expand All @@ -142,17 +142,17 @@ public void manageActivities(J_TimeVariables timeVariables) {

@Override
public void storeStatesAndReset() {
v_eventIndexStored = v_eventIndex;
eventIndexStored = eventIndex;
storedStarttimes_min = new ArrayList<>(starttimes_min);
storedEndtimes_min = new ArrayList<>(endtimes_min);
starttimes_min = new ArrayList<>(initalStarttimes_min);
endtimes_min = new ArrayList<>(initalEndtimes_min);
v_eventIndex = 0;
eventIndex = 0;
}

@Override
public void restoreStates() {
v_eventIndex = v_eventIndexStored;
eventIndex = eventIndexStored;
starttimes_min = new ArrayList<>(storedStarttimes_min);
endtimes_min = new ArrayList<>(storedEndtimes_min);
}
Expand Down
Loading
Loading