Вы находитесь на странице: 1из 6

This article was published in ASHRAE Journal, August 2009.

Copyright 2009 American Society of Heating, Refrigerating and Air-Conditioning


Engineers, Inc. Posted at www.ashrae.org. This article may not be copied and/or distributed electronically or in paper form without permission
of ASHRAE. For more information about ASHRAE Journal, visit www.ashrae.org.

Using Excel for


Duct Calculations
User Defined Functions
By Thomas G. Lester, P.E., Life Member ASHRAE functions are, and how they can be used.
There are many fine books on Office/Ex-

E
ngineers have relied on tools such as cardboard duct calculators, cel that provide a comprehensive review
of Visual Basic for Applications. You
 log-log graphs and lengthy tables for information that was difficult to cal- will need to consult these references for
a complete understanding of the subject.
culate directly. With the spreadsheets that are available today, calculations can
Calculations
be made easily and placed into user-friendly functions. Building on the method Before writing the UDF procedure
for duct diameter, the calculations can
used in “Solving for Friction Factor,”1 this article presents user defined functions be done manually in a standard spread-
sheet. Here, it can more easily be tested,
(UDFs) that can be used as an alternative to the duct calculator. debugged and verified for accuracy. For
someone not familiar with the creation
The duct calculator typically is used The duct calculator also can be used process for UDFs, it is also easier to see
to find the duct diameter given flow to find the flow given the duct diameter what calculations are being executed.
and design pressure drop. When the and design pressure drop or find the pres- The spreadsheet procedure, under the
cardboard duct calculator was created, sure drop given flow and duct diameter. “Dia Air” tab, is then replicated as a
assumptions were made for the specific It also provides a graphical solution for UDF.
volume, viscosity and absolute roughness rectangular equivalents to the diameter. The procedure used to create these
of the duct material. These assumptions All of these functions are built into an functions is a form of iterative problem
can lead to significant error, particularly Microsoft Excel spreadsheet that can solving. In some cases, a solution of the
with the absolute roughness that varies be downloaded from www.ashrae.org/ Colebrook Equation is required. The
significantly between the duct materials ashraejournal/Lester_Duct_Calculator_
that commonly are used. The approach UDFs.xls. This article provides a brief About the Author
in this article uses actual values for these explanation of how the spreadsheet and Thomas G. Lester, P.E., is a retired senior me-
properties. UDFs were created, what user defined chanical engineer in Rochester, N.Y.

42 ASHRAE Journal a s h r a e . o r g August 2009


The Excel workbook discussed here
is available online at www.ashrae.org/
ashraejournal/Lester_Duct_Calculator_
UDFs.xls.

article, “Solving for Friction Factor,” was devel-


oped as an alternative solution for the Colebrook
Equation. In that article, a UDF named “fCalc”
was created to solve for the friction factor given
relative roughness and Reynolds number. This is
used to solve for friction factor in the new UDFs.
The same basic approach used in “fCalc” is used
as well.
While each case is unique, the general approach
follows five steps:
1. Determine the range over which the un-
known will be evaluated;
2. Perform a series of calculations where the
difference between the design value and the Figure 1: First table and plot in the spreadsheet.
actual value is calculated;
3. Visualize a plot of the difference (from Step 2) versus in Row 15. This tells us that a 2 in. (51 mm) diameter in
the unknown; Row 14 has a pressure drop greater than the design drop,
4. Find an initial value for the unknown and repeat Step 2 but in Row 15, where the diameter is 3 in. (76 mm), the
using a smaller increment; and opposite is true. We can conclude, therefore, that the true
5. Perform a series of calculations, starting with the value value for the diameter lies between 2 in. and 3 in. (51 mm
from Step 4, whereby an approximate slope of the plot is and 76 mm).
calculated and then projected to the axis of the unknown. Note that the plot of the difference (the blue line) crosses the
Our objective is to find the duct diameter that satisfies the zero difference (the red line) between diameters of 2.00 and
condition of flow and design pressure drop given the properi- 3.00. The plot is a graphical solution of the problem; albeit
ties of air (specific volume and viscosity) and duct material one that requires some refinement to accurately determine the
(absolute roughness). true value of diameter.
Step 1: Determine the range over which the unknown Step 4: Find an initial value for duct diameter, and repeat
will be evaluated. In the case of duct diameter, I chose a Step 2 using a smaller increment. Excel has a built-in function,
minimum diameter of 2 in. (51 mm) and a maximum diameter “Vlookup.” This will return a value from a table based on a desir-
of approximately 115 in. (2933 mm). (Note that in the actual able condition. In this example, Column A has been duplicated
UDF only the minimum diameter is important.) in Column K and a table was created in the range J14:K24. The
Step 2: Perform a series of calculations, starting with the “Vlookup” function is looking for the value, or as the function
minimum diameter where the difference between the design works, the last negative value in the first column of the table
pressure drop and the actual pressure drop is calculated. (Column J) and returns the corresponding value in Column
Figure 1 shows a portion of the spreadsheet where this first set K, in this case 2.00. With this information, a second series can
of calculations takes place. The diameter in Column A is being be created, starting with the value returned by the “Vlookup”
used in a series of trial and error calculation given fixed values and incrementing by 1.05. In the same manner, a new table and
of flow, design pressure drop, specific volume, viscosity and “Vlookup” will return a value that is within 5% of the true value.
absolute roughness. Each row, starting in Row 15, increments (In this case, the second “Vlookup” returns a value of 2.10.)
the diameter by a factor of 1.5. (A flow of 6 cfm [2.8 L/s] was Step 5: Perform a series of calculations, starting with the
used because the graphic scales best with such a value.) The value from Step 4, whereby an approximate slope is generated
actual pressure drop is calculated in Column H using the Darcy- at the value returned by the last “Vlookup.” The projected
Weisbach equation, converted to inches of water. Column J diameter (ProjDia) is calculated using simple triangulation. (The
shows the difference between the design pressure drop and the use of simple triangulation is made possible by knowing that
actual pressure drop. the value on the y axis is “0.”) Figure 2 shows this situation.
Step 3: Visualize a plot of the difference versus the The blue line is the difference plotted against the diameter.
unknown that is being solved for. The objective is to find The red line is the zero difference line.
the diameter that is within 50% of the true value. Note that The green line (the slope) was generated by pairing the
the difference is negative in Row 14 but changes to positive last value from “Vlookup” multiplied by 0.999 with a second

August 2009 ASHRAE Journal 43


point multiplied by 1.001. Figure 3 shows how this appears in
the spreadsheet. The first projected diameter is shown in Cell
M77. This value is then used in the same manner for the second
projection (shown in Cell M80). This is repeated for a third pro- Zero Difference
jection, resulting in a final solution, 2.1571 in. (55 mm) in Cell
M83. (Verification of this result is in the sample spreadsheet.)
As crude as this procedure may seem, it produces precise
results in three projections. High Difference
Notice the difference in Cell J83 is negative and in Cell J84
it is positive. We have reached the limits in accuracy for the
increments used here (meaning the 0.999 and 1.001 multipliers).
If greater accuracy is desired, finer increments must be used.
When writing this procedure as a user defined function, I’ve
used a “Do Loop Until,” ending the loop when I reach a nega- Low
tive difference for the first of the pair and a positive difference Difference

Diameter
Diameter

Projected
Diameter
for the second line of the pair.

High
Low
This spreadsheet was presented to show the calculation but is
good for only one point at a time. The calculation has been written
into a UDF named “AirDia,” which makes the procedure easy to Figure 2: In Step 5 the projected diameter is calculated using simple
use in a network of ducts with multiple points. The next section triangulation.
gives a brief explanation of UDFs, and how they can be used.
types of VBA macros: command macros (sometimes referred
Visual Basic for Applications (VBA) and Excel as keystroke macros) and user defined functions (sometimes
D54214asjl_805523
Visual 4/9/08 (VBA)
Basic for Applications 5:15 AM Page 1 in Excel.
is included referred to as function procedures). It is the user defined func-
Among the uses of VBA is the creation of macros. There are two tions that I will focus on.

CRITICAL CLEANING
DEMANDS GOODWAY.

HEAVY-DUTY TUBE CLEANERS


FOR FIRETUBE AND WATERTUBE BOILERS

• Firetube Boiler Cleaners • Watertube Boiler Cleaners


with Vacuum for Removing with Waterflush for Removing
Soot and Scale Scale and Hard Water Deposits
To find out more, call Goodway today ®

at 800-333-7467, or visit us online.

www.goodway.com Innovative Maintenance Solutions

www.info.hotims.com/25207-18 www.info.hotims.com/25207-19
44 A S H R A E J o u r n a l August 2009
Access to VBA has changed in Excel 2007. Under the “Of- Dim Darcy As Single
fice Button,” click on “Excel Options.” Under the “Popular
Tab,” “Top Options for Working with Excel,” check the Vel = CFM / (3.14159 * (Dia / 12) ^ 2 / 4)
“Show Developer Tab in the Ribbon.” Select the “Devel- RelRough = AbsRough * 12 / Dia
oper” tab and Visual Basic will appear in the left side of ReynoldsNum = Vel / 60 * (Dia / 12) / KineVisc
the options. In Excel 2003 and older versions, select Tools FF = fCalc(RelRough, ReynoldsNum)
> Macros >Visual Basic Editor. Either path takes you to the Darcy = (Vel / 60) ^ 2 / (2 * 32.174) * FF * 100 * 12 / Dia /
Visual Basic Editor. UDFs are created and/or edited in the (62.4 * SpVol) * 12
Modules section.
AirPD = Darcy
Viewing a User Defined Function
You do not need to view a UDF to use it. This section is provided End Function
for anyone wishing to look at the code used in creating the UDFs.
While UDFs follow the general format of Visual Basic pro- The first line uses the “Function” keyword, identifying the
gramming, they don’t necessarily contain any special program- procedure as a UDF. “AirPD” is the function name, followed
ming language. The sample spreadsheet includes five UDFs; by the “arguments” inside parentheses. These “arguments” are
the simplest is the procedure for calculating the pressure drop values to be used in the calculations.
in an airstream, “AirPD,” shown below: The “Dim Statements” are then used to establish variables
and the precision to be used. The “As Single” will apply a
Function AirPD(CFM, Dia, AbsRough, KineVisc, SpVol) single-precision floating point to a variable.
Calculation statements for velocity, relative roughness and
Dim Vel As Single Reynolds number follow. The calculation of friction factor (FF)
Dim RelRough As Single uses the procedure fCalc (Module11) that was introduced in
Dim ReynoldsNum As Single “Solving for Friction Factor.” The last calculation is the Darcy-
Dim FF As Single Weisbach formula with conversions to units of inches of water.

ELECTRONIC FLOWHOOD
FLOWHOOD
DIRECT DIGITAL READOUT 25-2500 CFM

AUTOMATICALLY CORRECTS FOR AIR DENSITY &


BACKPRESSURE
CHOICE OF METERS - AIR FLOW ONLY, OR AIR FLOW,
VELOCITY, PRESSURE & TEMPERATURE
OPTIONS INCLUDE: MEMORY, AVERAGE & SUM TO 2000
READINGS, SEQUENTIAL RECALL, AUTO-READ
REPAIR POLICY - TWO WEEK TURNAROUND OR LESS
CUSTOM TOPS MADE TO ORDER

Shortridge Instruments, Inc.


7855 East Redfield Road • Scottsdale, Arizona 85260
(480) 991-6744 FAX (480) 443-1267

www.info.hotims.com/25207-37 www.info.hotims.com/25207-29
August 2009 ASHRAE Journal 45
The statement “AirPD = Darcy” sets
the name of the UDF equal to the result-
ing calculation. The “End Function” key-
words indicate the end of the procedure.
In this case, all the statements are simple
mathematical computations. In fact, I use
only one Visual Basic procedure in any of
the UDFs presented: a “Do Loop Until.” I
use this to replicate the tables and also to Figure 3: Slope and projection triangles.
execute the slope and projection calcula-
tions. The calculations are identical to the spreadsheet. In the 3. The function dialog box appears, and then select “User
tables, I stop the incrementing as soon as a positive value is calcu- Defined” from the categories dropdown menu.
lated for the design pressure drop minus the actual pressure drop. 4. From the list of available functions, select “AirDia.”
5. Another dialog box opens with the “arguments” listed.
Using a Recorded UDF Enter relative references for flow and absolute rough-
There are five UDFs in the sample spreadsheet. ness and absolute references (using the F4 key after the
1. fCalc (RelRough, ReynoldsNum) (Module11). This UDF cell reference is entered) for the global inputs for design
solves for friction factor given relative roughness and static, kinematic viscosity and specific volume. (Global
Reynolds number. Note: fCalc must be imported to make references will apply to all duct sections.)
the other functions work properly because it is embedded 6. Once the “arguments” have been added, the results should
in the other functions. appear in the dialog box; click “ok” and the UDF will be
2. AirDia (CFM, DesignStatic, AbsRough, KineVisc, completed in Cell I22.
SpVol) (Module2). This UDF solves for duct diameter 7. The UDF can be copied to the range I23:I26.
given the arguments cfm, design static, absolute rough- 8. If the “arguments” have been entered correctly, I22:I26
ness, kinematic viscosity, and specific volume. should match D22:D26.
3. AirCap (Dia, DesignStatic, AbsRough, KineVisc, SpVol) For use in an existing spreadsheet, an Excel add-in can be
(Module1). This UDF solves for the flow (CFM) given created by saving the sample spreadsheet in .xla format. This
the stated arguments. is accomplished by performing a “Save As” and specifying
4. AirPD (CFM, Dia, AbsRough, KineVisc, SpVol) (Module5). “.xla” format. The saved add-in can be used as any other
This UDF solves for pressure drop given the stated arguments. Excel add-in.
5. WCalc (Height, EquivDia) (Module3). This UDF solves Alternatively, the modules could be exported from the sample
for the Huebscher equivalents for rectangular duct.2 spreadsheet and imported into an existing spreadsheet. While
When opening a spreadsheet that contains macros, Excel asks this requires some familiarity with the Visual Basic Editor, it
to “Enable Macros.” For the UDFs to execute, you must “Enable is relatively easy to export and import the modules. Within
Macros.” In Excel 2003 and older versions, a dialog box appears the editor, under the “File” menu, you will see the commands
when opening a spreadsheet with macros. This is less obvious in “Export File” and “Import File.” Highlight a module and then
Excel 2007, where only a “Security Warning” appears below the export it as a “.bas” file. The module can be imported into an
“ribbon” and an “Options” button appears. Click on “Options” existing spreadsheet. When all the modules have been added,
and select, “Enable this content.” Without “Enable Macros,” the save the spreadsheet and close it. Re-open the spreadsheet, “En-
spreadsheet will not perform any of the calculations described. able Macros,” and they will appear under the “User Defined”
UDFs work the same as the hundreds of built-in functions exist- category in the functions dialog box.
ing in Excel. Available functions are listed by categories. UDFs are
placed in a category named “User Defined,” which is automatically Conclusions
created whenever UDFs are created. In this category, all the UDFs Engineering tools such as the cardboard duct calculator per-
in “Add-ins,” as well as those created in the spreadsheet, are shown. form functions that easily can be performed directly in a spread-
If a new spreadsheet is created, the sample spreadsheet can sheet using user defined functions. By using the actual values
be used by deleting all of the worksheets that are not desired. for properties of air and duct material, it is possible to improve
When this is saved, all of the UDFs will be saved with it. the accuracy of the results. With practice and familiarity, these
The sample spreadsheet contains examples of the use of each calculations can be performed more efficiently using UDFs.
of these functions. Under the “Examples” tab, the procedure to
enter a UDF would be: References
1. Place the cursor in Cell I22 (or any blank cell). 1. Lester, T. 2003. “Solving for Friction Factor.” ASHRAE Journal
2. In Excel 2007, select the “Formulas” tab and then select 45(7):41 – 44.
“Insert Function” or from Excel 2003 or older, just click 2.  2005 ASHRAE Handbook—Fundamentals, Chapter 35, Duct
on the “fx” icon. Design, p. 35.9.

46 ASHRAE Journal a s h r a e . o r g August 2009


www.info.hotims.com/25207-27

Вам также может понравиться