+ Show code- Hide code
library(OpasnetUtils)
library(ggplot2)
#Data tables are converted into ovariables and stored
u.factor <- Ovariable(name= "u.factor", ddata = "Op_en5397", subset = "u.factor", getddata = FALSE)
surface.area <- Ovariable(name= "surface.area", ddata = "Op_en5397", subset = "surface.area", getddata = FALSE)
ventilation.rate <- Ovariable(name= "ventilation.rate", ddata = "Op_en5397", subset = "ventilation.rate", getddata = FALSE)
ventilation.heat.recovery <- Ovariable(name= "ventilation.heat.recovery", ddata = "Op_en5397", subset = "ventilation.heat.recovery", getddata = FALSE)
air.leak.factor <- Ovariable(name= "air.leak.factor", ddata = "Op_en5397", subset = "air.leak.factor", getddata = FALSE)
building.characteristics <- Ovariable(name= "building.characteristics", ddata = "Op_en5397", subset = "building.characteristics", getddata = FALSE)
total.floor.area <- Ovariable(name= "total.floor.area", ddata = "Op_en5397", subset = "total.floor.area", getddata = FALSE)
outdoor.temperature <- Ovariable(name= "outdoor.temperature", ddata = "Op_en5397", subset = "outdoor.temperature", getddata = FALSE)
residential.building.location <- Ovariable(name= "residential.building.location", ddata = "Op_en5397", subset = "residential.building.location", getddata = FALSE)
period.length <- Ovariable(name= "period.length", ddata = "Op_en5397", subset = "period.length", getddata = FALSE)
soil.temperature.difference <- Ovariable(name= "soil.temperature.difference", ddata = "Op_en5397", subset = "soil.temperature.difference", getddata = FALSE)
heating.season <- Ovariable(name= "heating.season", ddata = "Op_en5397", subset = "heating.season", getddata = FALSE)
sun.radiation.vertical.surface <- Ovariable(name= "sun.radiation.vertical.surface", ddata = "Op_en5397", subset = "sun.radiation.vertical.surface", getddata = FALSE)
window.direction <- Ovariable(name= "window.direction", ddata = "Op_en5397", subset = "window.direction", getddata = FALSE)
sun.heat.absorption.parameters <- Ovariable(name= "sun.heat.absorption.parameters", ddata = "Op_en5397", subset = "sun.heat.absorption.parameters", getddata = FALSE)
objects.store(u.factor, surface.area, ventilation.rate, ventilation.heat.recovery, air.leak.factor, building.characteristics, total.floor.area, outdoor.temperature, residential.building.location, period.length, soil.temperature.difference, heating.season, sun.radiation.vertical.surface, window.direction, sun.heat.absorption.parameters)
cat("Ovariablet tallennettu.\n")
#oprint(u.factor)
#oprint(surface.area)
#oprint(air.exchange)
#oprint(building.characteristics)
#oprint(outdoor.temperature)
#oprint(residential.building.location)
#oprint(ventilation.rate)
#Average monthly outdoor temperature for a residential building in Finland. Calculated based on monthly average temperatures and location of residential buildings in different parts of Finland
average.outdoor.temperature.month <- Ovariable(
name="average.outdoor.temperature.month",
dependencies = data.frame(
Name=c("outdoor.temperature", "residential.building.location"),
Ident= c("Op_en5397")
),
formula = function(dependencies, ...) {
out <- outdoor.temperature * residential.building.location
out <- out@output[ , c("Location", "Month", "Construction.year", "Result")]
out <- aggregate(out[,colnames(out)=='Result'],by=list(out$Month, out$Construction.year),FUN="sum", na.rm="TRUE")
names(out) <- c("Month","Construction.year", "Result")
#out <- aggregate(out[,colnames(out)=='Result'],by=list(out$Construction.year),FUN="mean",na.rm="TRUE")
#names(out) <- c("Construction.year", "Result")
return(out)
}
)
#oprint(EvalOutput(average.outdoor.temperature.month))
#Average annual outdoor temperature for a residential building in Finland. Calculated based on monthly average temperatures.
average.outdoor.temperature.year <- Ovariable(
name="average.outdoor.temperature.year",
dependencies = data.frame(
Name=c("outdoor.temperature", "residential.building.location"),
Ident= c("Op_en5397")
),
formula = function(dependencies, ...) {
#cat("Average outdoor temperature for a residential building in Finland. Calculated based on monthly average temperatures and location of residential buildings in different parts of Finland \n")
out <- outdoor.temperature * residential.building.location
#out@output <- out@output[ , c("Location", "Month", "Construction.year", "Result")]
#out@output <- aggregate(out@output[,4],by=list(out@output$Month, out@output$Construction.year),FUN="sum", na.rm="TRUE")
#names(out@output) <- c("Month","Construction.year", "average.outdoor.temperatureResult")
out <- out@output[ , c("Location", "Month", "Construction.year", "Result")]
out <- aggregate(out[,colnames(out)=='Result'],by=list(out$Month, out$Construction.year),FUN="sum", na.rm="TRUE")
names(out) <- c("Month","Construction.year", "Result")
out <- aggregate(out[,colnames(out)=='Result'],by=list(out$Construction.year),FUN="mean",na.rm="TRUE")
names(out) <- c("Construction.year", "Result")
return(out)
}
)
#oprint(average.outdoor.temperature.year)
cat("Total heat loss via heat conduction through outside walls, roof, ground floor, windows, and doors, kWh/month.\n")
conduction.heat.loss <- Ovariable(
name="conduction.heat.loss",
dependencies = data.frame(
Name=c("u.factor", "surface.area", "average.outdoor.temperature.month", "average.outdoor.temperature.year", "period.length", "soil.temperature.difference"),
Ident= c("Op_en5397")
),
formula = function(dependencies, ...) {
indoor.temperature <- 21
#Conduction heat loss for outside walls, roof, windows, and outer doors:
temp1 <- u.factor * surface.area * (indoor.temperature - average.outdoor.temperature.month) * period.length / 1000
temp1 <- subset(temp1@output, Surface=="Outside wall" | Surface=="Roof" | Surface=="Window" | Surface=="Outer door")
temp1 <- aggregate(temp1[,colnames(temp1)=='Result'],by=list(temp1$Construction.year, temp1$Surface, temp1$Month),FUN="sum",na.rm="TRUE")
names(temp1) <- c("Construction.year", "Surface", "Month", "Result")
#Conduction heat loss for ground floor:
temp2 <- u.factor * surface.area * (indoor.temperature - (average.outdoor.temperature.year + 5 + soil.temperature.difference)) * period.length / 1000
temp2 <- subset(temp2@output, Surface=="Ground floor")
temp2 <- aggregate(temp2[,colnames(temp2)=='Result'],by=list(temp2$Construction.year, temp2$Surface, temp2$Month),FUN="sum",na.rm="TRUE")
names(temp2) <- c("Construction.year", "Surface", "Month", "Result")
#Combination of all heat conduction routes into a single value (kWh/month):
out <- rbind(temp1, temp2)
out <- aggregate(out[,colnames(temp2)=='Result'],by=list(out$Construction.year, out$Month),FUN="sum",na.rm="TRUE")
names(out) <- c("Construction.year", "Month", "Result")
return(out)
}
)
oprint(conduction.heat.loss)
cat("Total heat loss via active air ventilation, kWh/month. \n")
ventilation.heat.loss <- Ovariable(
name="ventilation.heat.loss",
dependencies = data.frame(
Name=c("ventilation.rate", "ventilation.heat.recovery", "total.floor.area", "average.outdoor.temperature.month", "period.length"),
Ident= c("Op_en5397")
),
formula = function(dependencies, ...) {
indoor.temperature <- 21
#Building air removal rate (m3/s):
temp1 <- ventilation.rate * total.floor.area / 1000
#ventilation unit heat loss (W/K):
temp2 <- 1.2 * 1000 * temp1 * (1 - ventilation.heat.recovery)
#total heat loss (kWh/month):
out <- temp2 * (indoor.temperature - average.outdoor.temperature.month) * period.length / 1000
vars <- names(out@output) %in% c("Month", "Construction.year", "Result", "Source")
out <- out@output[vars]
return(out)
}
)
oprint(ventilation.heat.loss)
cat("Total heat loss via involuntary air leak, kWh/month.\n")
air.leak.heat.loss <- Ovariable(
name="air.leak.heat.loss",
dependencies = data.frame(
Name=c("air.leak.factor", "total.floor.area", "building.characteristics", "average.outdoor.temperature.month", "period.length"),
Ident= c("Op_en5397")
),
formula = function(dependencies, ...) {
indoor.temperature <- 21
building.characteristics@output <- subset(building.characteristics@output, Parameter=="Room height")
room.height <- building.characteristics
#Building air leak rate (m3/s):
temp1 <- air.leak.factor * total.floor.area * room.height / 3600
#air leak unit heat loss (W/K):
temp2 <- 1.2 * 1000 * temp1
#total heat loss (kWh/month):
out <- temp2 * (indoor.temperature - average.outdoor.temperature.month) * period.length / 1000
vars <- names(out@output) %in% c("Month", "Construction.year", "Result", "Source")
out <- out@output[vars]
return(out)
}
)
oprint(EvalOutput(air.leak.heat.loss))
cat("Total heat loss due to household water heating, kWh/month.\n")
household.water.heating <- Ovariable(
name="household.water.heating",
dependencies = data.frame(
Name=c("period.length"),
Ident= c("Op_en5397")
),
formula = function(dependencies, ...) {
building.characteristics <- opbase.data("Op_en5397.building_characteristics")
inhabitants <- Ovariable(name = "inhabitants")
inhabitants@output <- tidy(subset(building.characteristics, Parameter=="Inhabitants"), direction="long", objname="inhabitants")
inhabitants@output$Parameter <- NULL
hot.water.use <- Ovariable(name = "hot.water.use")
hot.water.use@output <- tidy(subset(building.characteristics, Parameter=="Hot water use"), direction="long", objname="hot.water.use")
hot.water.use@output$Parameter <- NULL
#Hot water use (m3/a/building):
temp1 <- hot.water.use * period.length / 24 * inhabitants / 1000
#total heat consumption (kWh/month):
out <- 1000 * 4.2 * temp1 * 50 / 3600
vars <- names(out@output) %in% c("Month", "Result", "Source")
out <- out@output[vars]
return(out)
}
)
oprint(household.water.heating)
sun.heat.absorption <- Ovariable(
name="sun.heat.absorption",
dependencies = data.frame(
Name=c("sun.radiation.vertical.surface", "window.direction", "surface.area", "sun.heat.absorption.parameters"),
Ident= c("Op_en5397")
),
formula = function(dependencies, ...) {
permeability.factor <- Ovariable(name = "permeability.factor")
permeability.factor@output <- subset(sun.heat.absorption.parameters@output, Parameter=="Permeability factor")
oprint(permeability.factor@output)
frame.factor <- sun.heat.absorption.parameters
frame.factor@output <- subset(frame.factor@output, Parameter=="Frame factor")
curtain.factor <- sun.heat.absorption.parameters
curtain.factor@output <- subset(curtain.factor@output, Parameter=="Curtain factor")
shading.factor <- sun.heat.absorption.parameters
shading.factor@output <- subset(shading.factor@output, Parameter=="Shading factor")
surface.area@output <- subset(surface.area@output, Surface=="Window")
#Sun radiation on windows (kWh/m2 per month):
temp1 <- surface.area * window.direction * sun.radiation.vertical.surface
#Sun heat absorption (kWh/month):
temp2 <- temp1 * permeability.factor
oprint(temp2)
#oprint(temp2)
#temp3 <- temp2 * curtain.factor
#oprint(temp3)
#temp4 <- temp3 * shading.factor
#oprint(temp4)
#out <- temp4 * 0.9 * permeability.factor
#vars <- names(out@output) %in% c("Month", "Result", "Source")
#out <- out@output[vars]
return(temp2)
}
)
oprint(EvalOutput(sun.heat.absorption))
| |