Spaces:
Sleeping
Sleeping
File size: 13,949 Bytes
60cca7c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
"""
Calculation Method Interface for HVAC Load Calculator
This module defines the interface for calculation methods in the HVAC Load Calculator.
It provides a base class that all calculation methods should inherit from.
"""
from abc import ABC, abstractmethod
class CalculationMethod(ABC):
"""
Abstract base class for HVAC load calculation methods.
All calculation methods should inherit from this class and implement
the required methods.
"""
@property
@abstractmethod
def name(self):
"""
Get the name of the calculation method.
Returns:
str: Name of the calculation method
"""
pass
@property
@abstractmethod
def description(self):
"""
Get the description of the calculation method.
Returns:
str: Description of the calculation method
"""
pass
@property
@abstractmethod
def version(self):
"""
Get the version of the calculation method.
Returns:
str: Version of the calculation method
"""
pass
@abstractmethod
def calculate(self, input_data):
"""
Perform the calculation.
Args:
input_data (dict): Input data for the calculation
Returns:
dict: Calculation results
"""
pass
@abstractmethod
def get_input_schema(self):
"""
Get the input schema for the calculation method.
Returns:
dict: JSON schema for input validation
"""
pass
@abstractmethod
def get_output_schema(self):
"""
Get the output schema for the calculation method.
Returns:
dict: JSON schema for output validation
"""
pass
class ASHRAECoolingMethod(CalculationMethod):
"""
ASHRAE method for cooling load calculation.
"""
@property
def name(self):
return "ASHRAE Cooling Load Method"
@property
def description(self):
return "Calculates cooling loads using the ASHRAE method for residential buildings."
@property
def version(self):
return "1.0"
def calculate(self, input_data):
"""
Calculate cooling load using the ASHRAE method.
Args:
input_data (dict): Input data for the calculation
Returns:
dict: Calculation results
"""
from cooling_load import CoolingLoadCalculator
calculator = CoolingLoadCalculator()
# Extract input data
building_components = input_data.get('building_components', [])
windows = input_data.get('windows', [])
infiltration = input_data.get('infiltration', {})
internal_gains = input_data.get('internal_gains', {})
# Perform calculation
results = calculator.calculate_total_cooling_load(
building_components=building_components,
windows=windows,
infiltration=infiltration,
internal_gains=internal_gains
)
return results
def get_input_schema(self):
"""
Get the input schema for the ASHRAE cooling load method.
Returns:
dict: JSON schema for input validation
"""
return {
"type": "object",
"properties": {
"building_components": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"area": {"type": "number", "minimum": 0},
"u_value": {"type": "number", "minimum": 0},
"temp_diff": {"type": "number"}
},
"required": ["area", "u_value", "temp_diff"]
}
},
"windows": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"area": {"type": "number", "minimum": 0},
"u_value": {"type": "number", "minimum": 0},
"orientation": {"type": "string", "enum": ["north", "east", "south", "west", "horizontal"]},
"glass_type": {"type": "string"},
"shading": {"type": "string"},
"shade_factor": {"type": "number", "minimum": 0, "maximum": 1},
"temp_diff": {"type": "number"}
},
"required": ["area", "u_value", "orientation", "temp_diff"]
}
},
"infiltration": {
"type": "object",
"properties": {
"volume": {"type": "number", "minimum": 0},
"air_changes": {"type": "number", "minimum": 0},
"temp_diff": {"type": "number"}
},
"required": ["volume", "air_changes", "temp_diff"]
},
"internal_gains": {
"type": "object",
"properties": {
"num_people": {"type": "integer", "minimum": 0},
"has_kitchen": {"type": "boolean"},
"equipment_watts": {"type": "number", "minimum": 0}
},
"required": ["num_people"]
}
},
"required": ["building_components", "infiltration", "internal_gains"]
}
def get_output_schema(self):
"""
Get the output schema for the ASHRAE cooling load method.
Returns:
dict: JSON schema for output validation
"""
return {
"type": "object",
"properties": {
"conduction_gain": {"type": "number"},
"window_conduction_gain": {"type": "number"},
"window_solar_gain": {"type": "number"},
"infiltration_gain": {"type": "number"},
"internal_gain": {"type": "number"},
"sensible_load": {"type": "number"},
"latent_load": {"type": "number"},
"total_load": {"type": "number"}
},
"required": ["sensible_load", "latent_load", "total_load"]
}
class ASHRAEHeatingMethod(CalculationMethod):
"""
ASHRAE method for heating load calculation.
"""
@property
def name(self):
return "ASHRAE Heating Load Method"
@property
def description(self):
return "Calculates heating loads using the ASHRAE method for residential buildings."
@property
def version(self):
return "1.0"
def calculate(self, input_data):
"""
Calculate heating load using the ASHRAE method.
Args:
input_data (dict): Input data for the calculation
Returns:
dict: Calculation results
"""
from heating_load import HeatingLoadCalculator
calculator = HeatingLoadCalculator()
# Extract input data
building_components = input_data.get('building_components', [])
infiltration = input_data.get('infiltration', {})
# Perform calculation
results = calculator.calculate_total_heating_load(
building_components=building_components,
infiltration=infiltration
)
# Calculate annual heating requirement if location and occupancy data are provided
if 'location' in input_data and 'occupancy_type' in input_data:
location = input_data.get('location')
occupancy_type = input_data.get('occupancy_type')
base_temp = input_data.get('base_temp', 18)
annual_results = calculator.calculate_annual_heating_requirement(
results['total_load'],
location,
occupancy_type,
base_temp
)
# Combine results
results.update(annual_results)
return results
def get_input_schema(self):
"""
Get the input schema for the ASHRAE heating load method.
Returns:
dict: JSON schema for input validation
"""
return {
"type": "object",
"properties": {
"building_components": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"area": {"type": "number", "minimum": 0},
"u_value": {"type": "number", "minimum": 0},
"temp_diff": {"type": "number", "minimum": 0}
},
"required": ["area", "u_value", "temp_diff"]
}
},
"infiltration": {
"type": "object",
"properties": {
"volume": {"type": "number", "minimum": 0},
"air_changes": {"type": "number", "minimum": 0},
"temp_diff": {"type": "number", "minimum": 0}
},
"required": ["volume", "air_changes", "temp_diff"]
},
"location": {"type": "string"},
"occupancy_type": {"type": "string"},
"base_temp": {"type": "number"}
},
"required": ["building_components", "infiltration"]
}
def get_output_schema(self):
"""
Get the output schema for the ASHRAE heating load method.
Returns:
dict: JSON schema for output validation
"""
return {
"type": "object",
"properties": {
"component_losses": {
"type": "object",
"additionalProperties": {"type": "number"}
},
"total_conduction_loss": {"type": "number"},
"infiltration_loss": {"type": "number"},
"total_load": {"type": "number"},
"heating_degree_days": {"type": "number"},
"correction_factor": {"type": "number"},
"annual_energy_kwh": {"type": "number"},
"annual_energy_mj": {"type": "number"}
},
"required": ["total_load"]
}
class CalculationMethodRegistry:
"""
Registry for calculation methods.
This class maintains a registry of available calculation methods
and provides methods to access them.
"""
def __init__(self):
"""Initialize the registry."""
self._methods = {}
def register_method(self, method_id, method_class):
"""
Register a calculation method.
Args:
method_id (str): Unique identifier for the method
method_class (type): Class implementing the CalculationMethod interface
Returns:
bool: True if registration was successful, False otherwise
"""
if method_id in self._methods:
return False
if not issubclass(method_class, CalculationMethod):
return False
self._methods[method_id] = method_class
return True
def get_method(self, method_id):
"""
Get a calculation method by ID.
Args:
method_id (str): Unique identifier for the method
Returns:
CalculationMethod: Instance of the calculation method, or None if not found
"""
if method_id not in self._methods:
return None
return self._methods[method_id]()
def get_available_methods(self):
"""
Get a list of available calculation methods.
Returns:
list: List of dictionaries with method information
"""
methods = []
for method_id, method_class in self._methods.items():
method = method_class()
methods.append({
'id': method_id,
'name': method.name,
'description': method.description,
'version': method.version
})
return methods
# Create a global registry instance
registry = CalculationMethodRegistry()
# Register the built-in calculation methods
registry.register_method('ashrae_cooling', ASHRAECoolingMethod)
registry.register_method('ashrae_heating', ASHRAEHeatingMethod)
# Example of how to add a new calculation method
"""
class CustomCoolingMethod(CalculationMethod):
@property
def name(self):
return "Custom Cooling Method"
@property
def description(self):
return "A custom method for calculating cooling loads."
@property
def version(self):
return "1.0"
def calculate(self, input_data):
# Custom calculation logic
pass
def get_input_schema(self):
# Custom input schema
pass
def get_output_schema(self):
# Custom output schema
pass
# Register the custom method
registry.register_method('custom_cooling', CustomCoolingMethod)
"""
|