@@ -174,6 +174,7 @@ removeVirtualAreas <- function(x, storageFlexibility = NULL, production = NULL,
174
174
connectedToHub <- linkList [, .(connectedToHub = all(connectedToVirtualArea )),
175
175
by = area ]
176
176
177
+
177
178
if (any(connectedToHub $ connectedToHub )) {
178
179
179
180
veryVirtualAreas <- connectedToHub [connectedToHub == TRUE ]$ area
@@ -408,7 +409,23 @@ removeVirtualAreas <- function(x, storageFlexibility = NULL, production = NULL,
408
409
if (! is.null(x $ districts ) && length(storageFlexibility ) > 0 ){
409
410
stoPumAreas <- x $ areas [, .(pumpingCapacity , storageCapacity ), by = c(" timeId" , " area" )]
410
411
stoPumDistricts <- .groupByDistrict(stoPumAreas , opts )
411
- x $ districts <- merge(x $ districts , stoPumDistricts , by = c(" timeId" , " district" ))
412
+
413
+ # the columns pumpingCapacity doesnt exist when we trade very virtual area
414
+ if (is.null(x $ districts $ pumpingCapacity )){
415
+ x $ districts <- merge(x $ districts , stoPumDistricts , by = c(" timeId" , " district" ))
416
+ }else {
417
+ # for simple virtual areas take into account the previous merge
418
+ x $ districts <- merge(x $ districts , stoPumDistricts , all.x = TRUE , by = c(" timeId" , " district" ))
419
+
420
+ x $ districts [, ' :=' (
421
+ pumpingCapacity = pumpingCapacity.x + pumpingCapacity.y ,
422
+ storageCapacity = storageCapacity.x + storageCapacity.y
423
+ )]
424
+
425
+ x $ districts [, c(" pumpingCapacity.x" , " pumpingCapacity.y" , " storageCapacity.x" , " storageCapacity.y"
426
+ ): = NULL ]
427
+
428
+ }
412
429
}
413
430
414
431
# Store in attributes the name of the virtuals nodes
0 commit comments