public enum RoomPressure { public static let description = """ Calculate return grille and duct sizing for room pressure balancing. """ public enum Mode: String, CaseIterable, Codable, Equatable, Sendable, Hashable { case knownAirflow case measuredPressure public var label: String { switch self { case .knownAirflow: return "Known Airflow" case .measuredPressure: return "Measured Pressure" } } } public enum Request: Codable, Equatable, Sendable, Hashable { case knownAirflow(KnownAirflow) case measuredPressure(MeasuredPressure) public struct KnownAirflow: Codable, Equatable, Sendable, Hashable { public let targetRoomPressure: Double public let doorWidth: Double public let doorHeight: Double public let doorUndercut: Double public let supplyAirflow: Double public let preferredGrilleHeight: CommonReturnGrilleHeight public init( targetRoomPressure: Double, doorWidth: Double, doorHeight: Double, doorUndercut: Double, supplyAirflow: Double, preferredGrilleHeight: RoomPressure.CommonReturnGrilleHeight ) { self.targetRoomPressure = targetRoomPressure self.doorWidth = doorWidth self.doorHeight = doorHeight self.doorUndercut = doorUndercut self.supplyAirflow = supplyAirflow self.preferredGrilleHeight = preferredGrilleHeight } } public struct MeasuredPressure: Codable, Equatable, Sendable, Hashable { public let measuredRoomPressure: Double // pascals. public let doorWidth: Double public let doorHeight: Double public let doorUndercut: Double public let preferredGrilleHeight: CommonReturnGrilleHeight public init( measuredRoomPressure: Double, doorWidth: Double, doorHeight: Double, doorUndercut: Double, preferredGrilleHeight: RoomPressure.CommonReturnGrilleHeight ) { self.measuredRoomPressure = measuredRoomPressure self.doorWidth = doorWidth self.doorHeight = doorHeight self.doorUndercut = doorUndercut self.preferredGrilleHeight = preferredGrilleHeight } } } public struct Response: Codable, Equatable, Sendable { public let mode: Mode public let grilleSize: GrilleSize public let ductSize: DuctSize public let calculatedAirflow: Double? public let warnings: [String] public init( mode: Mode, grilleSize: RoomPressure.Response.GrilleSize, ductSize: RoomPressure.Response.DuctSize, calculatedAirflow: Double? = nil, warnings: [String] ) { self.mode = mode self.grilleSize = grilleSize self.ductSize = ductSize self.calculatedAirflow = calculatedAirflow self.warnings = warnings } public struct DuctSize: Codable, Equatable, Sendable { public let diameter: Int public let velocity: Double public init(diameter: Int, velocity: Double) { self.diameter = diameter self.velocity = velocity } } public struct GrilleSize: Codable, Equatable, Sendable { public let width: Int public let height: Int public let area: Double public init(width: Int, height: Int, area: Double) { self.width = width self.height = height self.area = area } } } public enum CommonReturnGrilleHeight: Int, CaseIterable, Codable, Equatable, Sendable { case four = 4 case six = 6 case eight = 8 case ten = 10 case twelve = 12 case fourteen = 14 // case twenty = 20 public var label: String { "\(rawValue)\"" } } } #if DEBUG public extension RoomPressure.Response { static let mock = Self( mode: .knownAirflow, grilleSize: .init(width: 14, height: 8, area: 72), ductSize: .init(diameter: 10, velocity: 367), warnings: [ "Duct leakage area is significant - consider reducing gaps or increasing grille size." ] ) } #endif