Skip to content

Commit

Permalink
Merge pull request #147 from AguaClara/fletch/miscFixes
Browse files Browse the repository at this point in the history
Fletch/misc fixes
  • Loading branch information
monroews authored Jan 9, 2019
2 parents 32e2643 + f3ee117 commit 14f8033
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 159 deletions.
4 changes: 2 additions & 2 deletions aguaclara/core/data/unit_definitions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ By: Sage Weber-Shirk

"""

NTU = 1.7 * (mg / L)
NTU = 1.47 * (mg / L)
dollar = [money] = USD
lempira = dollar * 0.0427 = HNL
lempira = dollar * 0.0427 = HNL
5 changes: 4 additions & 1 deletion aguaclara/core/drills.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def get_drill_bits_d_imperial():

def get_drill_bits_d_metric():
"""Return array of possible drill diameters in metric."""
return np.arange(0.5, 5.0, 0.1) * u.mm
return np.concatenate((np.arange(1.0, 10.0, 0.1),
np.arange(10.0, 18.0, 0.5),
np.arange(18.0, 36.0, 1.0),
np.arange(40.0, 55.0, 5.0))) * u.mm


DRILL_BITS_D_IMPERIAL = get_drill_bits_d_imperial()
Expand Down
2 changes: 1 addition & 1 deletion aguaclara/core/head_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,4 @@ def _get_orifice_type(orifice_l, orifice_id):

PIPE_EXIT_K_MINOR = 1

RM_GATE_VIN_K_MINOR = 25
RM_GATE_VIN_K_MINOR = 25
14 changes: 13 additions & 1 deletion aguaclara/core/physchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def density_water(temp):


@u.wraps(u.m**2/u.s, [u.degK], False)
def nu(temp):
def viscosity_kinematic(temp):
"""Return the kinematic viscosity of water at a given temperature.
If given units, the function will automatically convert to Kelvin.
Expand All @@ -96,6 +96,7 @@ def re_pipe(FlowRate, Diam, Nu):


@u.wraps(u.m, [u.m, u.m], False)
@ut.list_handler()
def radius_hydraulic(Width, DistCenter, openchannel):
"""Return the hydraulic radius.
Expand Down Expand Up @@ -141,6 +142,7 @@ def re_general(Vel, Area, PerimWetted, Nu):


@u.wraps(None, [u.m**3/u.s, u.m, u.m**2/u.s, u.m], False)
@ut.list_handler()
def fric(FlowRate, Diam, Nu, PipeRough):
"""Return the friction factor for pipe flow.
Expand All @@ -163,6 +165,7 @@ def fric(FlowRate, Diam, Nu, PipeRough):


@u.wraps(None, [u.m**3/u.s, u.m, u.m, u.m**2/u.s, u.m], False)
@ut.list_handler()
def fric_rect(FlowRate, Width, DistCenter, Nu, PipeRough, openchannel):
"""Return the friction factor for a rectangular channel."""
#Checking input validity - inputs not checked here are checked by
Expand All @@ -189,6 +192,7 @@ def fric_rect(FlowRate, Width, DistCenter, Nu, PipeRough, openchannel):


@u.wraps(None, [u.m**2, u.m, u.m/u.s, u.m**2/u.s, u.m], False)
@ut.list_handler()
def fric_general(Area, PerimWetted, Vel, Nu, PipeRough):
"""Return the friction factor for a general channel."""
#Checking input validity - inputs not checked here are checked by
Expand Down Expand Up @@ -356,6 +360,7 @@ def headloss_manifold(FlowRate, Diam, Length, KMinor, Nu, PipeRough, NumOutlets)


@u.wraps(u.m**3/u.s, [u.m, u.m], False)
@ut.list_handler()
def flow_orifice(Diam, Height, RatioVCOrifice):
"""Return the flow rate of the orifice."""
#Checking input validity
Expand All @@ -370,6 +375,7 @@ def flow_orifice(Diam, Height, RatioVCOrifice):

#Deviates from the MathCad at the 6th decimal place. Worth investigating or not?
@u.wraps(u.m**3/u.s, [u.m, u.m], False)
@ut.list_handler()
def flow_orifice_vert(Diam, Height, RatioVCOrifice):
"""Return the vertical flow rate of the orifice."""
#Checking input validity
Expand Down Expand Up @@ -458,6 +464,7 @@ def flow_swamee(Diam, HeadLossFric, Length, Nu, PipeRough):


@u.wraps(u.m**3/u.s, [u.m, u.m, u.m, u.m**2/u.s, u.m], False)
@ut.list_handler()
def flow_pipemajor(Diam, HeadLossFric, Length, Nu, PipeRough):
"""Return the flow rate with only major losses.
Expand Down Expand Up @@ -491,6 +498,7 @@ def flow_pipeminor(Diam, HeadLossExpans, KMinor):
# straight pipe that has both major and minor losses and might be either
# laminar or turbulent.
@u.wraps(u.m**3/u.s, (u.m, u.m, u.m, u.m**2/u.s, u.m), False)
@ut.list_handler()
def flow_pipe(Diam, HeadLoss, Length, Nu, PipeRough, KMinor):
"""Return the the flow in a straight pipe.
Expand Down Expand Up @@ -528,6 +536,7 @@ def flow_pipe(Diam, HeadLoss, Length, Nu, PipeRough, KMinor):
)
return FlowRate


@u.wraps(u.m, [u.m**3/u.s, u.m, u.m, u.m**2/u.s], False)
def diam_hagen(FlowRate, HeadLossFric, Length, Nu):
#Checking input validity
Expand Down Expand Up @@ -563,7 +572,9 @@ def diam_swamee(FlowRate, HeadLossFric, Length, Nu, PipeRough):
)
return 0.66 * (a+b)**0.04


@u.wraps(u.m, [u.m**3/u.s, u.m, u.m, u.m**2/u.s, u.m], False)
@ut.list_handler()
def diam_pipemajor(FlowRate, HeadLossFric, Length, Nu, PipeRough):
"""Return the pipe IDiam that would result in given major losses.
This function applies to both laminar and turbulent flow.
Expand Down Expand Up @@ -592,6 +603,7 @@ def diam_pipeminor(FlowRate, HeadLossExpans, KMinor):


@u.wraps(u.m, [u.m**3/u.s, u.m, u.m, u.m**2/u.s, u.m], False)
@ut.list_handler()
def diam_pipe(FlowRate, HeadLoss, Length, Nu, PipeRough, KMinor):
"""Return the pipe ID that would result in the given total head loss.
Expand Down
6 changes: 3 additions & 3 deletions aguaclara/core/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
unit_registry.default_format = '.4g'
pd.options.display.float_format = '{:,.4g}'.format

unit_registry.load_definitions(os.path.join(os.path.dirname(__file__),
"data", "unit_definitions.txt"))


def set_sig_figs(n: int):
"""Set the default number of significant figures used to print pint,
Expand All @@ -53,6 +56,3 @@ def set_sig_figs(n: int):
"""
unit_registry.default_format = '.' + str(n) + 'g'
pd.options.display.float_format = ('{:,.' + str(n) + '}').format

unit_registry.load_definitions(os.path.join(os.path.dirname(__file__),
"data", "unit_definitions.txt"))
9 changes: 4 additions & 5 deletions aguaclara/design/cdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#==============================================================================
# Functions for Coagulant Viscosities and Selecting Available Tube Diameters
#==============================================================================
from core.units import unit_registry as u


def _DiamTubeAvail(en_tube_series = True):
Expand All @@ -40,7 +39,7 @@ def viscosity_kinematic_alum(conc_alum, temp):
based on the effect on water and that there is no confounding effect from
the coagulant.
"""
nu = (1 + (4.255 * 10**-6) * conc_alum**2.289) * pc.nu(temp).magnitude
nu = (1 + (4.255 * 10**-6) * conc_alum**2.289) * pc.viscosity_kinematic(temp).magnitude
return nu


Expand All @@ -54,7 +53,7 @@ def viscosity_kinematic_pacl(conc_pacl, temp):
based on the effect on water and that there is no confounding effect from
the coagulant.
"""
nu = (1 + (2.383 * 10**-5) * conc_pacl**1.893) * pc.nu(temp).magnitude
nu = (1 + (2.383 * 10**-5) * conc_pacl**1.893) * pc.viscosity_kinematic(temp).magnitude
return nu


Expand All @@ -70,7 +69,7 @@ def viscosity_kinematic_chem(conc_chem, temp, en_chem):
if en_chem == 1:
nu = viscosity_kinematic_pacl(conc_chem, temp).magnitude
if en_chem not in [0,1]:
nu = pc.nu(temp).magnitude
nu = pc.viscosity_kinematic(temp).magnitude
return nu


Expand Down Expand Up @@ -490,4 +489,4 @@ def n_cdc_tube(FlowPlant, ConcDoseMax, ConcStock,
CHEM_LEVER_ARM_SPACE_L = 75 * u.cm
DIAM_TUBE_ENGLISH = [1, 2, 3 ,4 ,5 ,6, 7]*u.inch/16
DIAM_TUBE_METRIC = [2, 3, 4, 6, 8, 10]*u.mm
DIAM_FLT_VLV_ORIFICES_AVAIL = [0.093, 0.187, 0.25, 0.312]*u.inch
DIAM_FLT_VLV_ORIFICES_AVAIL = [0.093, 0.187, 0.25, 0.312]*u.inch
17 changes: 12 additions & 5 deletions aguaclara/design/floc.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ class Flocculator:
- URL to the flocculator 3D model in Onshape
"""

BAFFLE_K = 2.56
# Increased both to provide a safety margin on flocculator head loss and
# to simultaneously scale back on the actual collision potential we are
# trying to achieve.
# Originally calculated to be 2.3 from the equations:
# VC_BAFFLE_RATIO = con.VC_ORIFICE_RATIO**2
# K_MINOR_FLOC_BAFFLE = (1/VC_BAFFLE_RATIO - 1)**2
BAFFLE_K = 2.5
HL = 40 * u.cm
GT = 37000
END_WATER_H = 2 * u.m
Expand Down Expand Up @@ -133,7 +139,7 @@ def vel_grad_avg(self):
:rtype: float * 1 / second
"""
return ((con.GRAVITY * self.HL) /
(pc.nu(self.temp) * self.GT)).to(u.s ** -1)
(pc.viscosity_kinematic(self.temp) * self.GT)).to(u.s ** -1)

@property
def retention_time(self):
Expand Down Expand Up @@ -185,7 +191,7 @@ def w_min_hs_ratio(self):
"""
return ((self.HS_RATIO_MIN * self.q.to(u.m ** 3 / u.s) / self.END_WATER_H) *
(self.BAFFLE_K /
(2 * self.END_WATER_H * pc.nu(self.temp) * self.vel_grad_avg ** 2)) ** (1/3)
(2 * self.END_WATER_H * pc.viscosity_kinematic(self.temp) * self.vel_grad_avg ** 2)) ** (1/3)
).to(u.cm)

@property
Expand Down Expand Up @@ -247,7 +253,7 @@ def expansion_h_max(self):
exp_dist_max(20*u.L/u.s, 40*u.cm, 37000, 25*u.degC, 2*u.m)
0.375 meter
"""
return (((self.BAFFLE_K / (2 * pc.nu(self.temp) * (self.vel_grad_avg ** 2))) *
return (((self.BAFFLE_K / (2 * pc.viscosity_kinematic(self.temp) * (self.vel_grad_avg ** 2))) *
(self.q * self.HS_RATIO_MAX / self.channel_w) ** 3) ** (1/4)).to(u.m)

@property
Expand Down Expand Up @@ -277,7 +283,8 @@ def baffle_s(self):
"""

return ((self.BAFFLE_K /
(2 * self.expansion_h_max * (self.vel_grad_avg ** 2) * pc.nu(self.temp))) ** (1/3) *
(2 * self.expansion_h_max * (self.vel_grad_avg ** 2) *
pc.viscosity_kinematic(self.temp))) ** (1/3) *
self.q / ha.HUMAN_W_MIN).to(u.cm)

@property
Expand Down
12 changes: 6 additions & 6 deletions aguaclara/research/floc_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def pc_viscous(EnergyDis, Temp, Time, DiamTube,
""""""
return ((3/2)
* np.log10((2/3) * np.pi * FittingParam * Time
* np.sqrt(EnergyDis / (pc.nu(Temp).magnitude)
* np.sqrt(EnergyDis / (pc.viscosity_kinematic(Temp).magnitude)
)
* alpha(DiamTube, ConcClay, ConcAl, ConcNatOrgMat,
NatOrgMat, coag, material, RatioHeightDiameter)
Expand Down Expand Up @@ -429,7 +429,7 @@ def vel_term_floc(ConcAl, ConcClay, coag, material, DIM_FRACTAL,
"""Calculate floc terminal velocity."""
WaterDensity = pc.density_water(Temp).magnitude
return (((pc.gravity.magnitude * material.Diameter**2)
/ (18 * PHI_FLOC * pc.nu(Temp).magnitude)
/ (18 * PHI_FLOC * pc.viscosity_kinematic(Temp).magnitude)
)
* ((dens_floc_init(ConcAl, ConcClay, coag, material).magnitude
- WaterDensity
Expand All @@ -447,7 +447,7 @@ def diam_floc_vel_term(ConcAl, ConcClay, coag, material,
"""Calculate floc diamter as a function of terminal velocity."""
WaterDensity = pc.density_water(Temp).magnitude
return (material.Diameter * (((18 * VelTerm * PHI_FLOC
* pc.nu(Temp).magnitude
* pc.viscosity_kinematic(Temp).magnitude
)
/ (pc.gravity.magnitude * material.Diameter**2)
)
Expand All @@ -472,7 +472,7 @@ def time_col_laminar(EnergyDis, Temp, ConcAl, ConcClay, coag, material,
"""
return (((1/6) * ((6/np.pi)**(1/3))
* frac_vol_floc_initial(ConcAl, ConcClay, coag, material) ** (-2/3)
* (pc.nu(Temp).magnitude / EnergyDis) ** (1 / 2)
* (pc.viscosity_kinematic(Temp).magnitude / EnergyDis) ** (1 / 2)
* (DiamTarget / material.Diameter) ** (2*DIM_FRACTAL/3 - 2)
) # End of the numerator
/ (gamma_coag(ConcClay, ConcAl, coag, material, DiamTube,
Expand All @@ -498,7 +498,7 @@ def time_col_turbulent(EnergyDis, ConcAl, ConcClay, coag, material,
########### Kolmogorov and viscous length scales ###########
@u.wraps(u.m, [u.W/u.kg, u.degK], False)
def eta_kolmogorov(EnergyDis, Temp):
return ((pc.nu(Temp).magnitude ** 3) / EnergyDis) ** (1 / 4)
return ((pc.viscosity_kinematic(Temp).magnitude ** 3) / EnergyDis) ** (1 / 4)


@u.wraps(u.m, [u.W/u.kg, u.degK], False)
Expand Down Expand Up @@ -571,7 +571,7 @@ def g_straight(PlantFlow, IDTube):
@u.wraps(None, [u.m**3/u.s, u.m, u.degK], False)
def reynolds_rapid_mix(PlantFlow, IDTube, Temp):
return (4 * PlantFlow / (np.pi * IDTube
* pc.nu(Temp).magnitude))
* pc.viscosity_kinematic(Temp).magnitude))


@u.wraps(None, [u.m**3/u.s, u.m, u.m, u.degK], False)
Expand Down
2 changes: 1 addition & 1 deletion aguaclara/unit_process_design/ent_tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def drain_OD(q_plant, T, depth_end, SDR):
>>> from aguaclara.play import*
??
"""
nu = pc.nu(T)
nu = pc.viscosity_kinematic(T)
K_minor = con.PIPE_ENTRANCE_K_MINOR + con.PIPE_EXIT_K_MINOR + con.EL90_K_MINOR
drain_ID = pc.diam_pipe(q_plant, depth_end, depth_end, nu, mat.PVC_PIPE_ROUGH, K_minor)
drain_ND = pipe.SDR_available_ND(drain_ID, SDR)
Expand Down
Loading

0 comments on commit 14f8033

Please sign in to comment.