knitr::opts_chunk$set(echo = TRUE)
library(fbAntares)
library(manipulateWidget)
library(rAmCharts)
library(pipeR)
library(DT)

fbAntares`` allows to model flow-based domains into adequacy studies using the software Antares, with the following main functionalities:

1. Preparation of the input of an Antares study to include a modelling a flow-based in the CWE-AT area

2. Post-processing and visualisation of Antares’ results

This vignette describes the first set of functionnalities : the preparation of the inputs for the Antares study.

1 - Summary

#Convert domains from PTDF file, save the output in the directory "model1"
computeFB(PTDF = system.file("/input/ptdf/ptdfraw.csv", package = "fbAntares"), verbose = 1, nbFaces = 75, outputName = "D:/model1")

#Generate reports from the output of computeFB
domainesFB <- readRDS("D:/model1/domainesFB.rds")
for (day in domainesFB$idDayType) {
generateReportFb(dayType = day allFB = domainesFB)
}

# To check on the modelization results
getMaxImportExport(domainesFB)

#Set antares study path
antaresRead::setSimulationPath("D:/exemple_test", 0)

#Create flow-based time series considering their correlations with other inputs of an Antares Study, save the output in the directory "model1"
calendar <- system.file("calendar/calendar.txt", package = "fbAntares")
createFBTS(probabilityMatrix = probabilityMatrix, multiplier = multiplier,
calendar = calendar, firstDay = firstDay, outputPath = "D:/model1")


#Set setFlowbased directory path
setFlowbasedPath(path = "D:/model1")



#Run shiny application to visualize the results of the convertion
runAppError()

#Initialize the Antares study
initFlowBased(scenario = rep(1:200, times = 5))

2 - Projection of domains

a - Function presentation

The function computeFB() converts flow-based domains (e.g. historical flow-based domains of some "typical representative days") into an Antares model with fixed PTDF. It uses the main following parameters :

PTDF is a csv file with the following columns :

A PTDF file at this format can be automatically generated by using the function writeAllTypeDays of the package fbClust. One can also set the following optionnal arguments of the function :

To learn more, including tuning arguments for the optimization problem, see ?computeFB for more details.

The function creates a directory with the following files :

## Example of computeFB with cwe_at
computeFB(PTDF = system.file("/input/ptdf/ptdfraw.csv", package = "fbAntares"),
          reports = FALSE, areaName = "cwe_at", 
          hubDrop = list(NL = c("BE", "DE", "FR", "AT")),
          nbFaces = 75, dayType = 1,
          fixFaces = data.table(func = "min", zone = "BE"))

## Another example with more arguments and faces clustering only on most important hours
computeFB(PTDF = system.file("testdata/2019-07-18ptdfraw.csv",
                             package = "fbAntares"),
          reports = FALSE, areaName = "cwe_at", 
          hubDrop = list(NL = c("BE", "DE", "FR", "AT")),
          nbFaces = 75, dayType = 1, 
          clusteringHours = c(7:10, 17:19), nbLines = 50000,
          maxiter = 20, thresholdIndic = 95, 
          fixFaces = data.table(func = "min", zone = "BE"))

b - The using of the virtual area

Two different representations of flow-based can be used in Antares simulations. The historical one uses “real links” and translates the PTDF of the domain into a linear combination of exchanges. For example, PTDF of France will apply on the exchanges between France and Belgium and the exchanges between France and Germany. An alternative representation consists in creating a virtual area named zz_flowbased to which all areas are connected. In this case, this becomes the only link between each area and the other flow-based areas. It is a more pedagogic representation because it illustrates perfectly the fact that France exchanges electricity with the entire flow-based area at once and there is no differentiation between to exchanges with Belgium and those with Germany.

To use this alternative modelling, set to TRUE the parameter virtualFBarea in the function computeFB. The functions initFlowBased and the afterAntares funcitons will then adapt by themselves.

## Example of computeFB with cwe_at and virtual area
computeFB(PTDF = system.file("/input/ptdf/ptdfraw.csv", package = "fbAntares"),
          reports = FALSE, areaName = "cwe_at", 
          hubDrop = list(NL = c("BE", "DE", "FR", "AT")),
          nbFaces = 75, dayType = 1,
          fixFaces = data.table(func = "min", zone = "BE"),
          virtualFBarea = TRUE)

c - Validation of domains results

The function getMaxImportExport() returns a data.table and a csv if you want to. The result is the difference between the maximum of imports and exports between the modelized domain and the real domain for the different areas

#Generate reports from the output of computeFB
domainesFB <- readRDS(system.file("/input/model/antaresInput/domainesFB.RDS", package = "fbAntares"))

# To check on the modelization results
maxImportExport <- getMaxImportExport(domainesFB, writecsv = F)

# for a good visualisation in this vignette :
DT::datatable(maxImportExport, options = list(scrollX = TRUE))

3 - Creation of flow-based time series

a - Presentation of the function

The previous function - computeFB() - converts the typical flow-based days in a format suited for Antares.

The next step consists in defining, for each day of each Monte-Carlo year, which typical flow-based day will be used to bound the exchanges within the CWE-AT (or CWE) area. The function createFBTS() performs this task. Possible correlations between the flow-based shapes and external variables (e.g. load, wind power generation, solar generation) can be taken into account. Therefore, the function createFBTS() considers several inputs.

The main inputs of this function are :

An example of the use of createFBTS() is given below.

# build probabilityMatrix with the function getProbability() from the package
# fbClust
# select an antaresStudy with the function setSimulationPath() from the package antaresRead

# rename columns of the probability matrix

matProb <- setNamesProbabilityMatrix(probabilityMatrix, 
                                     c("FR_load", "DE_wind", "DE_solar"),
                                     c("fr@load", "de@wind", "de@solar"))

# set installed capacity for Wind (addition of onshore and offshore) and solar
multiplier <- data.frame(variable = c("fr@load", "de@wind", "de@solar"),
                         coef = c(1, 71900, 61900))

# set Calendar
firstDay <- identifyFirstDay(opts = antaresStudy)
calendar <- system.file("calendar/calendar.csv", package = "fbAntares")

# create ts.txt in D:/model1
ts <- createFBTS(opts = antaresStudy, probabilityMatrix = probabilityMatrix,
                 multiplier = multiplier, calendar = calendar,
                 firstDay = firstDay, outputPath = "D:/model1")

b - Validation of the results

getStatsFBts() gives detailed informations about the time series generated with the previous function createFBTS(). You just have to give in input the object ts generated with createFBTS(), a calendar with the csv format (like the one available in "/calendar/" in the package fbAntares) and an output ("summary", "yearbyyear" or "all")

ts <- fread(system.file("testdata/antaresInput/ts.txt", package = "fbAntares"), header = T)

statsFBts <- getStatsFBts(ts, calendar = system.file("calendar/calendar.txt", 
                                        package = "fbAntares"), output = "summary")

# for visualization in the vignette :
datatable(statsFBts, options = list(scrollX = TRUE))

4 - Set the flow-based model

Once the modeled flow-based domains have been created with computeFB() and createFBTS(), they can be loaded using the following function :

# Specify a repository
setFlowbasedPath(path = "C:/PATH/TO/INPUT")

The directory must contain :

5 - Visualization & reports

One can visualize the modeled flow-based domains, download the associated data or create a summary of the model accuracy in a html document using a shiny application with the function runAppError().

runAppError()
Drawing

plotFB() can also be used to plot one or more domains directly in R :

# For example, using the short model available in the package
library(fbAntares)
setFlowbasedPath(model = "antaresInput")
plotFB(hour = 5:6, dayType = 1, country1 = c("FR", "DE"),
       country2 = c("DE", "NL"), areaName = "cwe_at", export = T)

Reports in html format can also be generated within the shiny application. This solution can be use to facilitate the transmission and communication of the results. The function to generate html reports is generateReportFb()

Drawing

6 - Study initialization

This last step allows to prepare the inputs of an Antares study so as to include flow-based domains to bound CWE exchanges.

It is first necessary to select an antares study using setSimulationPath() function of the package antaresRead, and the flow-based model which will be set on this study must be specified with setFlowbasedPath().

The initialization of the study is then done with the function initFlowBased(). This function creates the inputs of the Antares study related to the flow-based modelling, with the appropriate binding constraints and virtual thermal plants.

The time-series of flow-based domains used for each Monte-Carlo years are desribed with the parameter scenarios. For instance, with scenario = rep(1:200, times = 5) (default value), up to 1000 Monte-Carlo years can be simulated with 5 blocks of, successively, time series 1 to 200. This "scenario building mode" is written in the file user/flowbased/scenario.txt of the Antares Study.

antaresRead::setSimulationPath("D:/exemple_test", 0)

# initialisation of flow-based study
initFlowBased(scenario = rep(1:200, times = 5))

7 - Run simulations

Once all these steps have been performed, the Antares study can be run as usual, for instance using the run simulation button of the software interface.



rte-antares-rpackage/fbAntares documentation built on June 1, 2022, 6:20 p.m.