WIP: Cleans up ManualDClient and adds some more document strings.
Some checks failed
CI / Linux Tests (push) Failing after 7m3s
Some checks failed
CI / Linux Tests (push) Failing after 7m3s
This commit is contained in:
@@ -97,16 +97,16 @@ func roundSize(_ size: Double) throws -> Int {
|
||||
}
|
||||
}
|
||||
|
||||
func velocity(cfm: CFM, roundSize: Int) -> Int {
|
||||
func velocity(cfm: ManualDClient.CFM, roundSize: Int) -> Int {
|
||||
let cfm = Double(cfm.rawValue)
|
||||
let roundSize = Double(roundSize)
|
||||
let velocity = cfm / (pow(roundSize / 24, 2) * 3.14)
|
||||
return Int(round(velocity))
|
||||
}
|
||||
|
||||
func flexSize(_ cfm: CFM, _ frictionRate: DesignFrictionRate) throws -> Int {
|
||||
func flexSize(_ cfm: ManualDClient.CFM, _ frictionRate: Double) throws -> Int {
|
||||
let cfm = pow(Double(cfm.rawValue), 0.4)
|
||||
let fr = pow(frictionRate.rawValue / 1.76, 0.2)
|
||||
let fr = pow(frictionRate / 1.76, 0.2)
|
||||
let size = 0.55 * (cfm / fr)
|
||||
return try roundSize(size)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import Dependencies
|
||||
import DependenciesMacros
|
||||
import Logging
|
||||
import ManualDCore
|
||||
import Tagged
|
||||
|
||||
extension DependencyValues {
|
||||
/// Dependency that performs manual-d duct sizing calculations.
|
||||
@@ -16,38 +17,61 @@ extension DependencyValues {
|
||||
///
|
||||
@DependencyClient
|
||||
public struct ManualDClient: Sendable {
|
||||
public var ductSize: @Sendable (CFM, DesignFrictionRate) async throws -> DuctSizeResponse
|
||||
public var frictionRate: @Sendable (FrictionRateRequest) async throws -> FrictionRate
|
||||
public var rectangularSize: @Sendable (RoundSize, Height) async throws -> RectangularSizeResponse
|
||||
|
||||
/// Calculates the duct size for the given cfm and friction rate.
|
||||
public var ductSize: @Sendable (CFM, DesignFrictionRate) async throws -> DuctSize
|
||||
/// Calculates the design friction rate for the given request.
|
||||
public var frictionRate: @Sendable (FrictionRateRequest) async throws -> FrictionRate
|
||||
/// Calculates the equivalent rectangular size for the given round duct and rectangular height.
|
||||
public var rectangularSize: @Sendable (RoundSize, Height) async throws -> RectangularSize
|
||||
|
||||
/// Calculates the duct size for the given cfm and friction rate.
|
||||
///
|
||||
/// - Paramaters:
|
||||
/// - designCFM: The design cfm for the duct.
|
||||
/// - designFrictionRate: The design friction rate for the system.
|
||||
public func ductSize(
|
||||
cfm designCFM: Int,
|
||||
frictionRate designFrictionRate: Double
|
||||
) async throws -> DuctSizeResponse {
|
||||
) async throws -> DuctSize {
|
||||
try await ductSize(.init(rawValue: designCFM), .init(rawValue: designFrictionRate))
|
||||
}
|
||||
|
||||
/// Calculates the duct size for the given cfm and friction rate.
|
||||
///
|
||||
/// - Paramaters:
|
||||
/// - designCFM: The design cfm for the duct.
|
||||
/// - designFrictionRate: The design friction rate for the system.
|
||||
public func ductSize(
|
||||
cfm designCFM: Double,
|
||||
frictionRate designFrictionRate: Double
|
||||
) async throws -> DuctSizeResponse {
|
||||
) async throws -> DuctSize {
|
||||
try await ductSize(.init(rawValue: Int(designCFM)), .init(rawValue: designFrictionRate))
|
||||
}
|
||||
|
||||
/// Calculates the equivalent rectangular size for the given round duct and rectangular height.
|
||||
///
|
||||
/// - Paramaters:
|
||||
/// - roundSize: The round duct size.
|
||||
/// - height: The rectangular height of the duct.
|
||||
public func rectangularSize(
|
||||
round roundSize: RoundSize,
|
||||
height: Height
|
||||
) async throws -> RectangularSizeResponse {
|
||||
) async throws -> RectangularSize {
|
||||
try await rectangularSize(roundSize, height)
|
||||
}
|
||||
|
||||
/// Calculates the equivalent rectangular size for the given round duct and rectangular height.
|
||||
///
|
||||
/// - Paramaters:
|
||||
/// - roundSize: The round duct size.
|
||||
/// - height: The rectangular height of the duct.
|
||||
public func rectangularSize(
|
||||
round roundSize: Int,
|
||||
height: Int
|
||||
) async throws -> RectangularSizeResponse {
|
||||
) async throws -> RectangularSize {
|
||||
try await rectangularSize(.init(rawValue: roundSize), .init(rawValue: height))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension ManualDClient: TestDependencyKey {
|
||||
@@ -55,8 +79,20 @@ extension ManualDClient: TestDependencyKey {
|
||||
}
|
||||
|
||||
extension ManualDClient {
|
||||
/// A name space for tags used by the ManualDClient.
|
||||
public enum Tag {
|
||||
public enum CFM {}
|
||||
public enum DesignFrictionRate {}
|
||||
public enum Height {}
|
||||
public enum Round {}
|
||||
}
|
||||
|
||||
public struct DuctSizeResponse: Codable, Equatable, Sendable {
|
||||
public typealias CFM = Tagged<Tag.CFM, Int>
|
||||
public typealias DesignFrictionRate = Tagged<Tag.DesignFrictionRate, Double>
|
||||
public typealias Height = Tagged<Tag.Height, Int>
|
||||
public typealias RoundSize = Tagged<Tag.Round, Int>
|
||||
|
||||
public struct DuctSize: Codable, Equatable, Sendable {
|
||||
|
||||
public let calculatedSize: Double
|
||||
public let finalSize: Int
|
||||
@@ -80,55 +116,26 @@ extension ManualDClient {
|
||||
|
||||
public let externalStaticPressure: Double
|
||||
public let componentPressureLosses: [ComponentPressureLoss]
|
||||
public let totalEffectiveLength: Int
|
||||
public let totalEquivalentLength: Int
|
||||
|
||||
public init(
|
||||
externalStaticPressure: Double,
|
||||
componentPressureLosses: [ComponentPressureLoss],
|
||||
totalEffectiveLength: Int
|
||||
totalEquivalentLength: Int
|
||||
) {
|
||||
self.externalStaticPressure = externalStaticPressure
|
||||
self.componentPressureLosses = componentPressureLosses
|
||||
self.totalEffectiveLength = totalEffectiveLength
|
||||
self.totalEquivalentLength = totalEquivalentLength
|
||||
}
|
||||
}
|
||||
|
||||
public struct FrictionRateResponse: Codable, Equatable, Sendable {
|
||||
public struct RectangularSize: Codable, Equatable, Sendable {
|
||||
public let height: Int
|
||||
public let width: Int
|
||||
|
||||
public let availableStaticPressure: Double
|
||||
public let frictionRate: DesignFrictionRate
|
||||
|
||||
public init(availableStaticPressure: Double, frictionRate: DesignFrictionRate) {
|
||||
self.availableStaticPressure = availableStaticPressure
|
||||
self.frictionRate = frictionRate
|
||||
}
|
||||
}
|
||||
|
||||
// public struct RectangularSizeRequest: Codable, Equatable, Sendable {
|
||||
// public let roundSize: RoundSize
|
||||
// public let height: Height
|
||||
//
|
||||
// public init(round roundSize: RoundSize, height: Height) {
|
||||
// self.roundSize = roundSize
|
||||
// self.height = height
|
||||
// }
|
||||
//
|
||||
// public init(round roundSize: Int, height: Int) {
|
||||
// self.init(round: .init(rawValue: roundSize), height: .init(rawValue: height))
|
||||
// }
|
||||
// }
|
||||
|
||||
public struct RectangularSizeResponse: Codable, Equatable, Sendable {
|
||||
public let height: Height
|
||||
public let width: Width
|
||||
|
||||
public init(height: Height, width: Width) {
|
||||
public init(height: Int, width: Int) {
|
||||
self.height = height
|
||||
self.width = width
|
||||
}
|
||||
|
||||
public init(height: Int, width: Int) {
|
||||
self.init(height: .init(rawValue: height), width: .init(rawValue: width))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ extension ManualDClient: DependencyKey {
|
||||
let fr = pow(frictionRate.rawValue, 0.5)
|
||||
let ductulatorSize = pow(Double(cfm.rawValue) / (3.12 * fr), 0.38)
|
||||
let finalSize = try roundSize(ductulatorSize)
|
||||
let flexSize = try flexSize(cfm, frictionRate)
|
||||
let flexSize = try flexSize(cfm, frictionRate.rawValue)
|
||||
return .init(
|
||||
calculatedSize: ductulatorSize,
|
||||
finalSize: finalSize,
|
||||
@@ -21,16 +21,16 @@ extension ManualDClient: DependencyKey {
|
||||
},
|
||||
frictionRate: { request in
|
||||
// Ensure the total effective length is greater than 0.
|
||||
guard request.totalEffectiveLength > 0 else {
|
||||
guard request.totalEquivalentLength > 0 else {
|
||||
throw ManualDError(message: "Total Effective Length should be greater than 0.")
|
||||
}
|
||||
|
||||
let totalComponentLosses = request.componentPressureLosses.total
|
||||
let availableStaticPressure = request.externalStaticPressure - totalComponentLosses
|
||||
let frictionRate = availableStaticPressure * 100.0 / Double(request.totalEffectiveLength)
|
||||
let frictionRate = availableStaticPressure * 100.0 / Double(request.totalEquivalentLength)
|
||||
return .init(
|
||||
availableStaticPressure: availableStaticPressure,
|
||||
value: .init(rawValue: frictionRate)
|
||||
value: frictionRate
|
||||
)
|
||||
},
|
||||
// totalEquivalentLength: { request in
|
||||
@@ -42,8 +42,8 @@ extension ManualDClient: DependencyKey {
|
||||
rectangularSize: { round, height in
|
||||
let width = (Double.pi * (pow(Double(round.rawValue) / 2.0, 2.0))) / Double(height.rawValue)
|
||||
return .init(
|
||||
height: height,
|
||||
width: .init(rawValue: Int(width.rounded(.toNearestOrEven)))
|
||||
height: height.rawValue,
|
||||
width: Int(width.rounded(.toNearestOrEven))
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user