+ 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)
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)
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))
#Heat loss via heat conduction through outside walls, roof, ground floor, windows, and doors
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:
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))
#Heat loss via active air ventilation
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
out <- temp2 * (indoor.temperature - average.outdoor.temperature.month) * period.length / 1000
return(temp1)
}
)
oprint(EvalOutput(ventilation.heat.loss))
| |