+ 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(EvalOutput(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(EvalOutput(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(EvalOutput(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("building.characteristics", "period.length"),
Ident= c("Op_en5397")
),
formula = function(dependencies, ...) {
inhabitants <- building.characteristics
inhabitants@output <- subset(inhabitants@output, Parameter=="Inhabitants")
hot.water.use <- building.characteristics
hot.water.use <- subset(hot.water.use@output, Parameter=="Hot water use")
#Hot water use (m3/a/building):
temp1 <- 45 * 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(EvalOutput(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 <- sun.heat.absorption.parameters
permeability.factor@output <- subset(permeability.factor@output, Parameter=="Permeability factor")
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 * frame.factor
#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(temp3)
}
)
oprint(EvalOutput(sun.heat.absorption))
| |