wire.py

Go to the documentation of this file.
00001 ##
00002 # 
00003 # Defines the Wire class, which is used to model various characteristics
00004 # of wire.
00005 # 
00006 # Copyright (C) 2002 GDS Software
00007 # 
00008 # This program is free software; you can redistribute it and/or
00009 # modify it under the terms of the GNU General Public License as
00010 # published by the Free Software Foundation; either version 2 of
00011 # the License, or (at your option) any later version.
00012 # 
00013 # This program is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 # GNU General Public License for more details.
00017 # 
00018 # You should have received a copy of the GNU General Public
00019 # License along with this program; if not, write to the Free
00020 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00021 # MA  02111-1307  USA
00022 # 
00023 # See http://www.gnu.org/licenses/licenses.html for more details.
00024 # 
00025 
00026 from math import pow, pi
00027 from util import SignificantFigures, SignMantissaExponent
00028 __version__ = "$Id: wire.py,v 1.5 2002/08/22 02:25:57 donp Exp $"
00029 
00030 #################### Classes ############################################
00031 
00032 ##
00033 # Utility class to deal with wire properties.  Internal calculations
00034 #     are done in SI units:  m for length, ohms for resistance, kg for mass, 
00035 #     K for temperature.  Utility functions are provided for unit conversions.
00036 #     
00037 class Wire:
00038     # The properties dictionary gives the following list of properties:
00039     #   Specific gravity
00040     #   Resistivity in 1e-6 ohm*cm
00041     #   Temperature coefficient of resistivity (1/K)
00042     # These numbers from CRC Handbook of Chemistry & Physics, 59th ed.
00043     properties = { 
00044         "aluminum"    : [  2.70,   2.824 , .0039  ],
00045         "copper"      : [  8.89,   1.7241, .00393 ],
00046         "brass"       : [  8.6 ,   7     , .002   ],
00047         "gold"        : [ 19.3 ,   2.44  , .0034  ],
00048         "iron"        : [  7.8 ,  10     , .005   ],
00049         "lead"        : [ 11.4 ,  22     , .0039  ],
00050         "magnesium"   : [  1.74,   4.6   , .004   ],
00051         "monel"       : [  8.9 ,  42     , .0020  ],
00052         "nichrome"    : [  8.2 , 100     , .0004  ],
00053         "nickel"      : [  8.9 ,   7.8   , .0033  ],
00054         "platinum"    : [ 21.4 ,  10     , .003   ],
00055         "silver"      : [ 10.5 ,   1.59  , .0038  ],
00056         "steel"       : [  7.7 ,  11     , .004   ],
00057         "tin"         : [  7.3 ,  11.5   , .0042  ],
00058         "zinc"        : [  7.1 ,   5.8   , .0037  ],
00059     }
00060 
00061     def __init__(self, diam_in_m = 0.0, length_in_m = 0.0):
00062         self.material    = "copper"
00063         self.SetMaterial(self.material)
00064         self.diam_in_m   = diam_in_m
00065         self.temp_in_K   = 20 + 273
00066         self.length_in_m = length_in_m
00067 
00068     def SetMaterial(self, material):
00069         if not self.properties.has_key(material):
00070             raise "'%s' is an unknown material" % material
00071         prop = self.properties[material]
00072         self.specific_gravity = prop[0]
00073         self.resistivity      = prop[1]/1e8  # Convert to ohm*m
00074         self.temp_coeff       = prop[2]
00075 
00076     ##
00077     # Returns a tuple containing the following elements:
00078     #             Resistance in ohms
00079     #             Length in m
00080     #             Mass in kg
00081     #             Diameter in m
00082     #             Resistivity in ohm*m at current temperature
00083     #             Specific gravity
00084     #             Temperature in K
00085     #             Material
00086     #         
00087     def GetProperties(self):
00088         area = pi * self.diam_in_m * self.diam_in_m / 4
00089         resistance = self.resistivity * self.length_in_m/area
00090         temp_corr  = 1 + self.temp_coeff * self.temp_in_K
00091         resistance = resistance * temp_corr
00092         mass = 1000 * self.specific_gravity * area * self.length_in_m
00093         return (             resistance,             self.length_in_m,             area,             mass,             self.diam_in_m,             self.resistivity * temp_corr,             self.specific_gravity,             self.temp_in_K,             self.material         )
00094 
00095     def GetPropertyNames(self):
00096         return (             "Resistance",             "Length in m",             "Area in m^2",             "Mass in kg",             "Diameter in m",             "Resistivity",             "Specific gravity",             "Temperature in K",             "Material"         )
00097 
00098     def SetLength(self, length_in_m):
00099         self.length_in_m = length_in_m
00100         if length_in_m < 0.0:
00101             raise "Length in m must be >= 0.0"
00102 
00103     def SetDiameter(self, diam_in_m):
00104         self.diam_in_m = diam_in_m
00105         if diam_in_m <= 0.0:
00106             raise "Diameter in m must be > 0.0"
00107 
00108     def SetTemperatureInK(self, temp_in_K):
00109         self.temp_in_K = temp_in_K
00110         if temp_in_K <= 0.0 or temp_in_K > (150 + 273):
00111             raise "'%s' is improper temperature" % `temp_in_K`
00112 
00113 #################### Utility functions ##################################
00114     
00115 ##
00116 # Returns the wire diameter in meters given the AWG gauge 
00117 #     number.
00118 #     
00119 def AWG_to_meters(n):
00120     if n < 0 or n > 40:
00121         raise "AWG argument out of range"
00122     return .0254*(.46/pow(92, (n+3.)/39))
00123 
00124 ##
00125 # Print a wire table in terms of AWG diameters for the indicated
00126 #     wire type.
00127 #     
00128 def WireTable(temp_deg_C, wire_material):
00129     ft_to_m = 0.3048
00130     m_to_mils = 39370
00131     kg_to_lbs = 2.2046
00132  
00133     print "Wire Table for %s at %d degrees C" % (wire_material, int(temp_deg_C))
00134     print ""
00135     print "AWG  Diam, mils    ft/lb    ohm/1000 ft"
00136     print "---  ----------   --------  -----------"
00137     w = Wire()
00138     w.SetMaterial("copper")
00139     w.SetTemperatureInK(temp_deg_C + 273)
00140     for gauge in xrange(0, 41, 2):
00141         w.SetLength(1 * ft_to_m)
00142         w.SetDiameter(AWG_to_meters(gauge))
00143         p = w.GetProperties()
00144         resistance  = p[0]
00145         mass        = p[3]
00146         print " %2d  %8.1f" % (gauge, w.diam_in_m * m_to_mils),
00147         ft_per_lb       = 1/(mass * kg_to_lbs)
00148         milliohm_per_ft = resistance * 1000.
00149         print " %10.2f  %11.4f" % (ft_per_lb, milliohm_per_ft)
00150 
00151 if __name__ == "__main__":
00152     WireTable(20, "copper")
00153 
00154 import sys
00155 sys.stderr.write("Warning:  wire.py does not seem to work correctly.\n" + "18 gauge wire has wrong resistance -- should be 6.5 milliohms/ft at 77 deg F.\n" + "R & H give rho for Cu at 20 deg C as 1.56e-8 ohm*m, so I've got bad\n" + "resistivity data.\n\n")
00156 
00157 ft_to_m = 0.3048
00158 m_to_mils = 39370
00159 kg_to_lbs = 2.2046
00160 w = Wire()
00161 w.SetMaterial("copper")
00162 w.SetTemperatureInK(20 + 273)
00163 gauge = 18
00164 w.SetLength(1 * ft_to_m)
00165 w.SetDiameter(AWG_to_meters(gauge))
00166 p = w.GetProperties()
00167 n = w.GetPropertyNames()
00168 
00169 for ix in xrange(len(n)):
00170     print n[ix], p[ix]
00171 
00172 resistance  = p[0]
00173 mass        = p[3]
00174 print " %2d  %8.1f" % (gauge, w.diam_in_m * m_to_mils),
00175 ft_per_lb       = 1/(mass * kg_to_lbs)
00176 milliohm_per_ft = resistance * 1000.
00177 print " %10.2f  %11.4f" % (ft_per_lb, milliohm_per_ft)
00178 
00179 

© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."

Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.

122,241 lines of code and growing...