예제 #1
0
def headloss(req, roughness, internal_dimension):
    """Calculate velocity and headloss for selected dimension.

    :param req: request.get_json() flask's method to get json from user
    :param roughness: roughness of pipe in [mm]
    :param internal_dimension: internal dimension of pipe depends on nominal diameter
    """
    density = req['density']
    viscosity = req['viscosity']
    # pipe
    area = circular_pipe(internal_dimension, 'mm')
    length = req['length']
    llc = req.get('local_loss_coefficient', 0)
    # flow
    velocity = velocity_equation(req['flow'], req['flow_unit'], area)
    reynolds = reynolds_equation(velocity, internal_dimension, viscosity)
    # headloss
    headloss_unit = req.get('headloss_unit', 'Pa')
    dfc = darcy_friction_coefficient(reynolds, internal_dimension, roughness)
    loss = darcy_weisbach_equation(
        dfc, llc, length, unit_convertion(internal_dimension, 'mm', 'm', 'lenght'), density, velocity
    )
    return api_response(
        {
            'velocity': velocity,
            'velocity_unit': 'm/s',
            'headloss': unit_convertion(loss, 'Pa', headloss_unit, 'pressure'),
            'headloss_unit': headloss_unit,
        }
    )
예제 #2
0
def velocity_equation(flow, flow_unit, area):
    """Calculate average velocity.

    :param flow: volume flow rate
    :param flow_unit: flow unit e.g.: [m3/h], [m3/s]
    :param area: area of pipe's cross section [m2]"""
    try:
        volume_unit, time_unit = flow_unit.split('/')
        volume_convertion = unit_convertion(1, volume_unit, 'm3', 'volume')
        time_convertion = unit_convertion(1, time_unit, 's', 'time')
        return round_units((flow * volume_convertion / time_convertion) / area,
                           3)
    except (ValueError, TypeError):
        return 'Wrong volume flow rate!'
예제 #3
0
def circular_pipe(diameter, unit):
    """Circular area in [m2].
    :param diameter: value of internal diameter
    :param unit: unit of diameter e.g.: [mm] or [m]
    """
    converted_diameter = unit_convertion(diameter, unit, 'm', 'lenght')
    return round(math.pow(converted_diameter, 2) * math.pi / 4, 10)
예제 #4
0
def rectangular_dict(width, height, unit):
    """Rectangular area in [m2].

    :param width: duct width (A - dimension)
    :param height: duct height (B - dimension)
    :param unit: unit od dimensions e.g.: [mm] or [m]
    """
    conversion_value = math.pow(unit_convertion(1, unit, 'm', 'lenght'), 2)
    return round(width * height * conversion_value, 10)
예제 #5
0
 def wrapper(req, *args, **kwargs):
     if 'power' in req:
         power = unit_convertion(req['power'], req['power_unit'], 'W',
                                 'power')
         temperature_delta = abs(req['temperature_supply'] -
                                 req['temperature_return'])
         if not temperature_delta:
             return error_response(
                 400,
                 'Temperature supply and return can not have the same value.'
             )
         flow = power / (temperature_delta * req['density'] *
                         req['specific_heat'])
         req.update({'flow': flow, 'flow_unit': 'm3/s'})
     return func(*args, req=req, **kwargs)
예제 #6
0
def selecting_optimum_pipe_size(req):
    """Calculate velocity and headloss for every dimension.

    :param req: request.get_json() flask's method to get json from user
    """
    density = req['density']
    viscosity = req['viscosity']
    roughness = req.get('roughness', 1.5)
    results = []
    for nominal_diameter, internal_dimension in get_internal_diameters(req['material']):
        area = circular_pipe(internal_dimension, 'mm')
        velocity = velocity_equation(req['flow'], req['flow_unit'], area)
        reynolds = reynolds_equation(velocity, internal_dimension, viscosity)
        dfc = darcy_friction_coefficient(reynolds, internal_dimension, roughness)
        loss = darcy_weisbach_equation(
            dfc, 0, 1, unit_convertion(internal_dimension, 'mm', 'm', 'lenght'), density, velocity
        )
        results.append({'nominal_diameter': nominal_diameter, 'headloss': loss, 'velocity': velocity})
    return api_response({'headloss_unit': 'Pa/m', 'velocity_unit': 'm/s', 'results': results})
def test_unit_convertion_failed(value, unit_from, unit_to, data_type, expected_message):
    assert unit_convertion(value, unit_from, unit_to, data_type) == expected_message
def test_unit_convertion(value, unit_from, unit_to, data_type, expected_value):
    assert unit_convertion(value, unit_from, unit_to, data_type) == expected_value