#A script which attempts to pull in all data, and create a data frame with the maximum revenue values for each facility, year and discount rate. The output can then be used to make figures and graphs library(tidyverse) library(parallel) library(lpSolve) #For solving discrete value maximization for the power plants TOTAL <- read_csv("Data/Raw_Data/Curie_Spent_Fuel_Site_Totals.csv") %>% mutate(OP_YEAR=year(Op_Date_Min),CLOSE_YEAR=year(Close_Date_Max))%>% select(Facility,Total_Assemblies,Total_Tons,OP_YEAR,CLOSE_YEAR) CV1 <- 1.3074*(10607030-1060703) #Data from Texas Report, converted from 2018 to Dec 2025 dollars CV2 <- 1.2874*(6984013-1117442) #Data from New Mexico Report, Converted from 2019 to Dec 2025 ###########Series of functions to calculate the gross consumer surplus from a CIFS for each facility, in each year from 1960 to 2082. #Function to find the net present revenue of a facility,given a discount rate, and the current year, and year the facility will close. This is the sum of discounted costs that WOULD have taken place if the facility was not built VALUE_ADD <- function(r,CURRENT_YEAR,CLOSE_YEAR){ Years_Until_Close <- max(CLOSE_YEAR-CURRENT_YEAR+1,0) VALUES <- (1+r)^-(1:10^4) if(Years_Until_Close==0){return(sum(VALUES))} else{return(sum(VALUES[-1:-Years_Until_Close]))} } #A function to extend the revenues calculations to the closure date of all of the facilities. VALUE_ADD_SINGLE_YEAR <- function(r,CURRENT_YEAR,CLOSE_YEARS){return(sapply(CLOSE_YEARS,function(x){VALUE_ADD(r,CURRENT_YEAR,x)}))} #A function to extend the calculation of the net present revenues of each facility to all years of interest. That is what is the NPV of building the facility in each year, for each facility. NPV_CALC <- function(r,DATA=TOTAL,YEARS=1960:2083){ Facility <- pull(DATA,Facility) RES <- cbind(Facility,do.call(cbind,lapply(YEARS,function(x){VALUE_ADD_SINGLE_YEAR(r,x,DATA$CLOSE_YEAR)}))) colnames(RES) <- c("Facility",YEARS) RES <- as_tibble(RES) %>% pivot_longer(cols=-Facility,names_to="Year",values_to="Revenue") %>% arrange(Year) %>% mutate(Year=parse_number(Year),Revenue=parse_number(Revenue),Discount=r) return(RES) } #A function which returns a list, of net present revenue calculation tables (facility by year) for a range of possible discount rates. This allows for the results to be quickly looked up, when we want to adjust the time value of money. These results combine costs savings to calculate NPV MULTI_DISCOUNT_RATE_NPV <- function(INCREMENT=0.005,DATA=TOTAL,YEARS=1960:2083,DOLLARS_SAVED_PER_YEAR){ NCORES <- detectCores()-1 RES <- mclapply(seq(0,1,by=INCREMENT),NPV_CALC,mc.cores = NCORES) RES <- do.call(rbind,RES) %>% mutate(Revenue=Revenue*DOLLARS_SAVED_PER_YEAR) return(RES) } TOTAL_VALUE_METRICS <- MULTI_DISCOUNT_RATE_NPV(INCREMENT=0.1,DOLLARS_SAVED_PER_YEAR=CV2) TOTAL_VALUE_METRICS <- TOTAL_VALUE_METRICS %>% filter(!(Facility %in% c("Palo Verde","Vogtle")))#These facilities always have a negative NPV by the end date 2083 TOTAL_VALUE_METRICS <- TOTAL_VALUE_METRICS %>% left_join(read_csv("Data/Raw_Data/Curie_Spent_Fuel_Site_Totals.csv")) %>% select(Year,Facility,Discount,Total_Tons,Revenue) #TBL <- TOTAL_VALUE_METRICS #DICOUNT=0.1 #CIFS_SIZE=1 #SHIPPING_COST <- 0 #YEAR=2026 #Function to find the maximum Revenue BUT it does not take dollars just relative savings MAX_REV <- function(YEAR,TBL,DISCOUNT,CIFS_SIZE,SHIPPING_COST=0){ TBL <- TBL %>% filter(Year==YEAR,Discount==DISCOUNT,Revenue/Total_Tons>SHIPPING_COST) REV <- TBL %>% pull(Revenue) VOL <- TBL %>% pull(Total_Tons) VOL RES <- lp(direction = "max", objective.in = REV, const.mat = matrix(VOL, nrow = 1),const.dir = "<=", const.rhs = CIFS_SIZE, all.bin = TRUE) return(RES[[11]]) } SHIPPING_COST_PER_TON <- 1.2874*26000 #Inflation adjusted from New Mexico Report #Unique values of discount rates used DISCOUNTS <- TOTAL_VALUE_METRICS$Discount %>% unique #Calculate all results for the start year to the end year. Discount rate, and capacities are fixed. YEARLY_RESULTS <- function(DATA,DISCOUNT,CAPACITY,SHIPPING_COSTS=0){ RES <- cbind(1960:2083,sapply(1960:2083, function(x){MAX_REV(YEAR=x,TBL=DATA,DISCOUNT,CAPACITY,SHIPPING_COSTS)})) %>% as_tibble colnames(RES) <- c("Year","Revenue") RES <- RES %>% mutate(Discount=DISCOUNT,Capacity=CAPACITY) return(RES) } #Calculate and individual facilities rate, for all discount rates, and all years FACILITY_RESULTS <- function(CAPACITY){do.call(rbind,lapply(DISCOUNTS,function(x){YEARLY_RESULTS(TOTAL_VALUE_METRICS,x,CAPACITY)}))} lapply(FACILITY_RESULTS() FACILITY_RESULTS(10^5) MAX_REV(YEAR=2020,TBL=TOTAL_VALUE_METRICS,DISCOUNT=0.1,CIFS_SIZE=100000,SHIPPING_COST_PER_TON ) dir.create("./Results",showWarnings=FALSE) saveRDS(TOTAL_VALUE_METRICS,"./Results/Storage_Values_by_Facility_and_Variable_Discounts.Rds")