From a16026e287cf703f4bf0c6e1e343f485cc2a76c2 Mon Sep 17 00:00:00 2001 From: GillisHommen Date: Wed, 31 Dec 2025 13:04:53 +0100 Subject: [PATCH 1/2] Split up engine initialisation, time/date vars are not in a separate function which is called before all agents are created. ActivityTrackerTrips now shifts trips according to day of week, to correctly account for lower milage during weekends. Loop live simulation now does not reset t_h and timeStepsElapsed to 0, they keep on counting up. This also means the data-display in the model will continue in the next year. --- _alp/Agents/EnergyModel/Code/Functions.java | 76 +++++++++---------- _alp/Agents/EnergyModel/Code/Functions.xml | 28 +++++-- _alp/Agents/EnergyModel/Variables.xml | 1 + _alp/Classes/Class.J_ActivityTracker.java | 2 +- .../Class.J_ActivityTrackerCooking.java | 5 +- .../Classes/Class.J_ActivityTrackerTrips.java | 50 +++++++----- 6 files changed, 96 insertions(+), 66 deletions(-) diff --git a/_alp/Agents/EnergyModel/Code/Functions.java b/_alp/Agents/EnergyModel/Code/Functions.java index 4a77f5e6..8257c2d3 100644 --- a/_alp/Agents/EnergyModel/Code/Functions.java +++ b/_alp/Agents/EnergyModel/Code/Functions.java @@ -42,7 +42,7 @@ b_isLastTimeStepOfDay = t_h % 24 == (24-p_timeStep_h); t_hourOfDay = t_h % 24; // Assumes modelrun starts at midnight. -c_profiles.forEach(p -> p.updateValue(t_h)); +c_profiles.forEach(p -> p.updateValue(t_h)); // //v_currentAmbientTemperature_degC = pp_ambientTemperature_degC.getCurrentValue(); //v_currentWindPowerNormalized_r = pp_windProduction_fr.getCurrentValue(); //v_currentSolarPowerNormalized_r = pp_PVProduction35DegSouth_fr.getCurrentValue(); @@ -589,44 +589,9 @@ ArrayList f_getActiveGridConnections() if (b_isInitialized) { throw new RuntimeException("Error: Engine was initalized a second time."); } -// Initialize time and date -//v_hourOfYearStart=hourOfYearPerMonth[getMonth()] + (getDayOfMonth()-1)*24; -t_h = p_runStartTime_h; - -Date startDate = date(); -p_year = startDate.getYear() + 1900; - -LocalDate localDate = LocalDate.of(p_year, 1, 1); -v_dayOfWeek1jan = DayOfWeek.from(localDate).getValue(); -p_startOfWinterWeek_h = roundToInt(24 * (p_winterWeekNumber * 7 + (8-v_dayOfWeek1jan)%7)); // Week 49 is winterweek. -p_startOfSummerWeek_h = roundToInt(24 * (p_summerWeekNumber * 7 + (8-v_dayOfWeek1jan)%7)); // Week 18 is summerweek. - - - -int monthIdx = 0; -while ( t_h > hourOfYearPerMonth[monthIdx] ) { - monthIdx++; - if (monthIdx==hourOfYearPerMonth.length){ - break; - } -} - -int dayOfMonth = 1+(int)((t_h - hourOfYearPerMonth[monthIdx])/24.0); -traceln("Day of month start: %s", dayOfMonth); -traceln("Month of year start: %s", monthIdx); -startDate.setMonth(monthIdx); -startDate.setDate(dayOfMonth); -startDate.setHours(0); -startDate.setMinutes(0); -traceln("Startdate: %s", startDate); -//startDate.set -getExperiment().getEngine().setStartDate(startDate); -//traceln("Day of the week on january 1st %s: %s, int value: %s", p_year, DayOfWeek.from(localDate).name(), v_dayOfWeek1jan); - // Initialize all agents in the correct order, creating all connections. What about setting initial values? And how about repeated simulations? - f_buildGridNodeTree(); c_gridConnections.forEach(GC -> GC.f_initialize()); @@ -1264,8 +1229,8 @@ Date f_getDate() double f_loopSimulation() {/*ALCODESTART::1758619562148*/ -v_timeStepsElapsed = 0; -f_clearAllLiveDatasets(); +//v_timeStepsElapsed = 0; +//f_clearAllLiveDatasets(); traceln("The simulation has been looped."); /*ALCODEEND*/} @@ -1377,3 +1342,38 @@ ArrayList f_getAllGridConnections() c_assetManagement.remove(assetManagement); /*ALCODEEND*/} +double f_initializeTimeDates() +{/*ALCODESTART::1767178014622*/ +// Initialize time and date +t_h = p_runStartTime_h; + +Date startDate = date(); +p_year = startDate.getYear() + 1900; + +LocalDate localDate = LocalDate.of(p_year, 1, 1); +v_dayOfWeek1jan = DayOfWeek.from(localDate).getValue(); +p_startOfWinterWeek_h = roundToInt(24 * (p_winterWeekNumber * 7 + (8-v_dayOfWeek1jan)%7)); // Week 49 is winterweek. +p_startOfSummerWeek_h = roundToInt(24 * (p_summerWeekNumber * 7 + (8-v_dayOfWeek1jan)%7)); // Week 18 is summerweek. + +int monthIdx = 0; +while ( t_h > hourOfYearPerMonth[monthIdx] ) { + monthIdx++; + if (monthIdx==hourOfYearPerMonth.length){ + break; + } +} + +int dayOfMonth = 1+(int)((t_h - hourOfYearPerMonth[monthIdx])/24.0); +traceln("Day of month start: %s", dayOfMonth); +traceln("Month of year start: %s", monthIdx); +startDate.setMonth(monthIdx); +startDate.setDate(dayOfMonth); +startDate.setHours(0); +startDate.setMinutes(0); +traceln("Startdate: %s", startDate); +//startDate.set +getExperiment().getEngine().setStartDate(startDate); + + +/*ALCODEEND*/} + diff --git a/_alp/Agents/EnergyModel/Code/Functions.xml b/_alp/Agents/EnergyModel/Code/Functions.xml index 4617ace4..6b1da69e 100644 --- a/_alp/Agents/EnergyModel/Code/Functions.xml +++ b/_alp/Agents/EnergyModel/Code/Functions.xml @@ -122,7 +122,7 @@ 1671636439933 730 - 113 + 133