Author Topic: Mechanical help...  (Read 10114 times)

0 Members and 1 Guest are viewing this topic.

Water Bear

  • Guest
Mechanical help...
« on: February 24, 2004, 03:24:18 PM »
Thanks to the good folks here at The Swamp I've worked up this duct calculator which makes conversions based on volume (cfm), velocity (fpm) and conversts to and from round ducts...it still needs some work to make it "pretty" but I've gone about as far as I know how...anyway I'll post it for input (I couldn't get it to calculate friction loss/100' duct) if anyone has suggestions please post, and if you can use it you're welcome to...thanx
Code: [Select]
(defun duct_calc (/)
;;;          volume  pressure   velocity
;;;  diam     rey_no fric_fac   width
;;;  depth     square friction   area_sqft
;;;  )

  (setq diam (getreal "\nEnter duct diameter:")
width (getreal "\nEnter duct width:")
depth (getreal "\nEnter duct depth:")
volume (getreal "\nEnter total CFM'S:")
velocity (getreal "\nEnter Velocity in FPM:")
)
  (cond
    ((and diam volume)
     (setq area_sqft (/ (* 0.7854 (expt diam 2.0)) 144.0)
  width     (* diam 0.914774703)
  depth     (* diam 0.914774703)
  velocity  (/ volume area_sqft)
  pressure  (expt (/ velocity 4005.00) 2)
  )
     (find_fric)
     )
    ((and diam velocity)
     (setq area_sqft (/ (* 0.7854 (expt diam 2.0)) 144.0)
  width     (* diam 0.914774703)
  depth     (* diam 0.914774703)
  volume    (* area_sqft velocity)
  pressure  (expt (/ velocity 4005.00) 2)
  )
     (find_fric)
     )
    ((and width depth volume)
     (setq area_sqft (* (/ (* width depth) 144.0) 0.914774703)
  square    (sqrt (* area_sqft 144.0))
  diam     (* 1.3
(exp
 (/ (log (/ (expt (* square square) 5.0)
    (expt (+ square square) 2.0)
    )
 )
    8.0
    )
 )
)
  velocity  (/ volume area_sqft)
  pressure  (expt (/ velocity 4005.00) 2)
  )
     (find_fric)
     )
    ((and width depth velocity)
     (setq area_sqft (* (/ (* width depth) 144.0) 0.914774703)
  square    (sqrt (* area_sqft 144.0))
  diam     (* 1.3
(exp
 (/ (log (/ (expt (* square square) 5.0)
    (expt (+ square square) 2.0)
    )
 )
    8.0
    )
 )
)
  volume    (* area_sqft velocity)
  pressure  (expt (/ velocity 4005.00) 2)
  )
     (find_fric)
     )
    ((and volume velocity)
     (setq area_sqft (/ (/ volume velocity) 0.914774703)
  square    (sqrt (* area_sqft 144.0))
  diam     (* 1.3
(exp
 (/ (log (/ (expt (* square square) 5.0)
    (expt (+ square square) 2.0)
    )
 )
    8.0
    )
 )
)

  width     (* diam 0.914774703)
  depth     (* diam 0.914774703)
  pressure  (expt (/ velocity 4005.00) 2)
  )
     (find_fric)
     )

   (t
      (cond
((if volume
  t
  )
(prompt
  "\nYou must enter diameter or Width x Depth or FPM..."
  )
)
((if velocity
  t
  )
(prompt
  "\nYou must enter a diameter or Width x Depth or CFM..."
  )
)
(t
(prompt "\nYou must indicate CFMs or FPM..")
)
)
      )
    )
  )


(defun find_fric ()
  (setq rey_no (* 0.075 diam velocity (/ 1.0 0.0432))
;<=need coefficient for viscosity of standard air in pounds/ft hr
fric_fac (/ 64.0 rey_no) ;<=only good if reynolds is less than 2000
friction (* fric_fac (/ 1200 diam) pressure)
) ;<==Darcy/Weisbach
  )

:D

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Mechanical help...
« Reply #1 on: February 24, 2004, 03:28:43 PM »
Cool. (I work in the mech field too.) Ill help help as much as i can when i get spare time. (I work in Microstation alot now, but i do still use Acad once and a while so this would be cool.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Mechanical help...
« Reply #2 on: February 24, 2004, 05:07:00 PM »
Excellent job there water bear
TheSwamp.org  (serving the CAD community since 2003)

Water Bear

  • Guest
Mechanical help...
« Reply #3 on: February 24, 2004, 05:17:47 PM »
Thanks for the kind words Mark. I, in turn, must thank CAB, and DParcon for their help... :D

SMadsen

  • Guest
Mechanical help...
« Reply #4 on: February 24, 2004, 05:37:30 PM »
Looks really great, Water Bear.

The factor 0.914774703, is that a workaround for not isolating one of the square sides in the formula that was discussed in the "you say you're pretty good at numbers...." thread?
Man, I gave up on that formula.

Water Bear

  • Guest
Mechanical help...
« Reply #5 on: February 24, 2004, 05:42:43 PM »
Yes, SMadsen, that's the one that had me pulling my hair out! lol

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Mechanical help...
« Reply #6 on: February 24, 2004, 06:53:00 PM »
Great job...

Some superficial stuff that is a personal preference.
You can create local functions to make the code more readable
and it localizes formula. So if you need to change a formula
it is in one place not many copies.

I added some window dressing and did a little filter on the inputs.
I'm still on the lower end of programing prowess so consider the
source.

CAB

Code: [Select]
;;; Duct calc returns the friction value

(defun duct_calc (/)
;;;             volume  pressure   velocity
;;;        diam        rey_no   fric_fac   width
;;;        depth        square   friction   area_sqft
;;;        )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;                      Local Functions                          
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
  ;;  given the area in square feet returns the diameter
  (defun area2dia (sf_area / square)
    (setq square (sqrt (* sf_area 144.0)))
    (* 1.3
       (exp
         (/ (log (/ (expt (* square square) 5.0)
                    (expt (+ square square) 2.0)
                 )
            )
            8.0
         )
       )
    )
  ) ; end defun

  ;;  given diameter returns the side dimension
  (defun dia2sq (dia)
    (* dia 0.914774703)
  )

  ;;  given the diameter returns the area in sq ft
  (defun dia2area (dia)
    (/ (* 0.7854 (expt dia 2.0)) 144.0)
  )

  ;;  given the sides returns the area in sq ft
  (defun rec2area (w d) ; retangle to area
    (* (/ (* w d) 144.0) 0.914774703)
  )

  ;;  given the diameter returns the area in sq ft
  (defun veloc2press (vel)
    (expt (/ vel 4005.00) 2)
  )

  ;;  calc friction
  (defun find_fric ()
    (setq rey_no   (* 0.075 diam velocity (/ 1.0 0.0432))
 ;<=need coefficient for viscosity of standard air in pounds/ft hr
          fric_fac (/ 64.0 rey_no)
 ;<=only good if reynolds is less than 2000
          friction (* fric_fac (/ 1200 diam) pressure)
    ) ;<==Darcy/Weisbach
  )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;;                    Start of Routine                            
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  (prompt "\nEnter known values. Press Enter if not known. ")
  (setq diam (getreal "\nEnter duct diameter: "))
  (if (null diam) ; skip if diameter entered
    (setq width (getreal "\nEnter duct width: ")
          depth (getreal "\nEnter duct depth: ")
    )
  )
  (setq volume   (getreal "\nEnter total CFM'S: ")
        velocity (getreal "\nEnter Velocity in FPM: ")
  )

  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                  Process user input                  
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (cond
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam volume)
     (setq area_sqft (dia2area diam)
           width     (dia2sq diam)
           depth     width
           velocity  (/ volume area_sqft)
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam velocity)
     (setq area_sqft (dia2area diam)
           width     (dia2sq diam)
           depth     width
           volume    (* area_sqft velocity)
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth volume)
     (setq area_sqft (rec2area width depth)
           diam      (area2dia area_sqft)
           velocity  (/ volume area_sqft)
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth velocity)
     (setq area_sqft (rec2area width depth)
           diam      (area2dia area_sqft)
           volume    (* area_sqft velocity)
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and volume velocity)
     (setq area_sqft (/ (/ volume velocity) 0.914774703)
           diam      (area2dia area_sqft)
           width     (dia2sq diam)
           depth     width
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    (t (alert "\nInsufficient data retry inputs..."))
  ) ; end cond stmt
) ; end defun
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Water Bear

  • Guest
Mechanical help...
« Reply #7 on: February 24, 2004, 07:26:42 PM »
Nice mop-up! Looks much cleaner! what do you think about a prompt for additional info, I had added this
Quote
(t
      (cond
   ((if volume
      t
      )
    (prompt
      "\nYou must enter diameter or Width x Depth or FPM..."
      )
    )
   ((if velocity
      t
      )
    (prompt
      "\nYou must enter a diameter or Width x Depth or CFM..."
      )
    )
   (t
    (prompt "\nYou must indicate CFMs or FPM..")
    )
   )
      )
instead of that last condition? and can we get it to switch to (textscr) and list all variables..

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Mechanical help...
« Reply #8 on: February 24, 2004, 07:52:45 PM »
How about this?

Code: [Select]
   (t
     (cond
       ((or volume velocity)
        (prompt
          "\nYou must enter diameter or Width x Depth or FPM..."
        )
       )
       (t
        (prompt "\nYou must indicate CFMs or FPM..")
       )
     )
    )



Code: [Select]
(defun c:test (/ friction)
  (while (null (setq friction (duct_calc))))
  (print friction)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Water Bear

  • Guest
Mechanical help...
« Reply #9 on: February 24, 2004, 08:43:08 PM »
Looks really good CAB putting it all together...how about  something like this at the end:
Code: [Select]
(defun duct_calc (/)
;;;             volume  pressure   velocity
;;;        diam        rey_no   fric_fac   width
;;;        depth        square   friction   area_sqft
;;;        )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;                      Local Functions                          
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
  ;;  given the area in square feet returns the diameter
  (defun area2dia (sf_area / square)
    (setq square (sqrt (* sf_area 144.0)))
    (* 1.3
       (exp
(/ (log (/ (expt (* square square) 5.0)
   (expt (+ square square) 2.0)
   )
)
   8.0
   )
)
       )
    ) ; end defun

  ;;  given diameter returns the side dimension
  (defun dia2sq (dia)
    (* dia 0.914774703)
    )

  ;;  given the diameter returns the area in sq ft
  (defun dia2area (dia)
    (/ (* 0.7854 (expt dia 2.0)) 144.0)
    )

  ;;  given the sides returns the area in sq ft
  (defun rec2area (w d) ; retangle to area
    (* (/ (* w d) 144.0) 0.914774703)
    )

  ;;  given the diameter returns the area in sq ft
  (defun veloc2press (vel)
    (expt (/ vel 4005.00) 2)
    )

  ;;  calc friction
  (defun find_fric ()
    (setq rey_no   (* 0.075 diam velocity (/ 1.0 0.0432))
;<=need coefficient for viscosity of standard air in pounds/ft hr
 fric_fac (/ 64.0 rey_no)
;<=only good if reynolds is less than 2000
 friction (* fric_fac (/ 1200 diam) pressure)
 ) ;<==Darcy/Weisbach
    )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;;                    Start of Routine                          
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  (prompt "\nEnter known values. Press Enter if not known. ")
  (setq diam (getreal "\nEnter duct diameter: "))
  (if (null diam) ; skip if diameter entered
    (setq width (getreal "\nEnter duct width: ")
 depth (getreal "\nEnter duct depth: ")
 )
    )
  (setq volume (getreal "\nEnter total CFM'S: ")
velocity (getreal "\nEnter Velocity in FPM: ")
)

  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;               Process character pressed                  
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (cond
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam volume)
     (setq area_sqft (dia2area diam)
  width     (dia2sq diam)
  depth     width
  velocity  (/ volume area_sqft)
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam velocity)
     (setq area_sqft (dia2area diam)
  width     (dia2sq diam)
  depth     width
  volume    (* area_sqft velocity)
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth volume)
     (setq area_sqft (rec2area width depth)
  diam     (area2dia area_sqft)
  velocity  (/ volume area_sqft)
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth velocity)
     (setq area_sqft (rec2area width depth)
  diam     (area2dia area_sqft)
  volume    (* area_sqft velocity)
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and volume velocity)
     (setq area_sqft (/ (/ volume velocity) 0.914774703)
  diam     (area2dia area_sqft)
  width     (dia2sq diam)
  depth     width
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    (t
     (cond
       ((or volume velocity)
(prompt
 "\nYou must enter diameter or Width x Depth..."
 )
)
       (t
(prompt "\nYou must indicate CFMs or FPM..")
)
       )
     )
    ) ; end cond stmt
  (textscr)
  (mapcar 'print
 (list diam volume width depth velocity friction)
 )
  (princ)
  )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Mechanical help...
« Reply #10 on: February 24, 2004, 10:27:52 PM »
Ok, add some more input filter and revised you print function.

Code: [Select]
;;; Duct calc returns the friction value

(defun duct_calc (/          friction   volume     pressure
                  velocity   diam       rey_no     fric_fac
                  width      depth      area_sqft
                 )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;                      Local Functions                          
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
  ;;  given the area in square feet returns the diameter
  (defun area2dia (sf_area / square)
    (setq square (sqrt (* sf_area 144.0)))
    (* 1.3
       (exp
         (/ (log (/ (expt (* square square) 5.0)
                    (expt (+ square square) 2.0)
                 )
            )
            8.0
         )
       )
    )
  ) ; end defun

  ;;  given diameter returns the side dimension
  (defun dia2sq (dia)
    (* dia 0.914774703)
  )

  ;;  given the diameter returns the area in sq ft
  (defun dia2area (dia)
    (/ (* 0.7854 (expt dia 2.0)) 144.0)
  )

  ;;  given the sides returns the area in sq ft
  (defun rec2area (w d) ; retangle to area
    (* (/ (* w d) 144.0) 0.914774703)
  )

  ;;  given the diameter returns the area in sq ft
  (defun veloc2press (vel)
    (expt (/ vel 4005.00) 2)
  )

  ;;  calc friction
  (defun find_fric ()
    (setq rey_no   (* 0.075 diam velocity (/ 1.0 0.0432))
 ;<=need coefficient for viscosity of standard air in pounds/ft hr
          fric_fac (/ 64.0 rey_no)
 ;<=only good if reynolds is less than 2000
          friction (* fric_fac (/ 1200 diam) pressure)
    ) ;<==Darcy/Weisbach
  )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;;                    Start of Routine                            
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-


 ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                    Get User Input                          
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (prompt "\nEnter known values. Press Enter if not known. ")
  (setq diam (getreal "\nEnter duct diameter: "))
  (if (null diam) ; skip if diameter entered
    (setq width (getreal "\nEnter duct width: ")
          depth (getreal "\nEnter duct depth: ")
    )
  )
  (setq volume (getreal "\nEnter total CFM'S: "))
  (if (null (and (or diam (and width depth)) volume))
    (setq velocity (getreal "\nEnter Velocity in FPM: "))
  )

  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                Process User Input                          
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (cond
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam volume)
     (setq area_sqft (dia2area diam)
           width     (dia2sq diam)
           depth     width
           velocity  (/ volume area_sqft)
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam velocity)
     (setq area_sqft (dia2area diam)
           width     (dia2sq diam)
           depth     width
           volume    (* area_sqft velocity)
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth volume)
     (setq area_sqft (rec2area width depth)
           diam      (area2dia area_sqft)
           velocity  (/ volume area_sqft)
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth velocity)
     (setq area_sqft (rec2area width depth)
           diam      (area2dia area_sqft)
           volume    (* area_sqft velocity)
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and volume velocity)
     (setq area_sqft (/ (/ volume velocity) 0.914774703)
           diam      (area2dia area_sqft)
           width     (dia2sq diam)
           depth     width
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    (t
     (cond
       ((or volume velocity)
        (prompt
          "\nYou must enter diameter or Width x Depth or FPM..."
        )
       )
       (t
        (prompt "\nYou must indicate CFMs or FPM..")
       )
     )
    )
  ) ; end cond stmt
  (textscr)
  (mapcar '(lambda (x) (prompt (strcat "\n" (car x) (rtos (cdr x) 2))))
          (list (cons "Diameter " diam)
                (cons "Width    " width)
                (cons "Depth    " depth)
                (cons "Volume   " volume)
                (cons "Velocity " velocity)
                (cons "Friction " friction)
          )
  )
  (princ)

) ; end defun



(defun c:test (/ friction)
  (while (null (setq friction (duct_calc))))
  (print friction)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Water Bear

  • Guest
Mechanical help...
« Reply #11 on: February 24, 2004, 10:47:57 PM »
Man! you aregood! And you've only been doing this for 3 months? :shock:
Now if I could only figure out the @#$% friction factor! The problem there is that  they use Colebrook's equation which "...cannot be explictly solved for the friction factor, so you must use iterative techniques. :twisted:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Mechanical help...
« Reply #12 on: February 24, 2004, 11:02:15 PM »
Thanks.


Quote
And you've only been doing this for 3 months


No, more like a year. 8)
Gettin started is the hard part.

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Water Bear

  • Guest
Mechanical help...
« Reply #13 on: February 24, 2004, 11:16:59 PM »
CAB, take a look at this one and give me your thoughts:

This is supposed to replace the formula I have for "fric_fac"

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Mechanical help...
« Reply #14 on: February 24, 2004, 11:32:52 PM »
That math is over my head :(

Is that the formula they talk about here?

Quote
Note: Friction losses have been calculated based on the Darcy equation.
The friction factor was determined by using a simplified formula by
Altshule/Tsal (see ASHRAE, 1997 Fundamentals, Chapter 32). The absolute
roughness factor of 0.0003 ft for the medium smooth roughness category
galvanized steel ductwork is used in the calculation.



One another subject,
Have you run across any software you would recommend for calculating and print a
Manual J form. Hillsborough County requires it for permit & although I use the
Energy Gauge software it doesn't print the Manual J.

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Water Bear

  • Guest
Mechanical help...
« Reply #15 on: February 24, 2004, 11:45:49 PM »
No I haven't seen any, but  I'll ask around the office.
Is there a formula with that excerpt?
The one I've got is from 1977 chapter 31 ! :roll: And they reference a computer algorthim which I have not been able to find:
H.F. Behls:Computerized Calculation of duct friction (U.S. Bureau of standards, Building Science Series 39, October 1971, p. 363

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Mechanical help...
« Reply #16 on: February 25, 2004, 12:08:06 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Water Bear

  • Guest
Mechanical help...
« Reply #17 on: February 25, 2004, 11:27:33 AM »
Good find CAB! that 37_444.html had the perfect equation...I did away with that Reynolds no. & Darcey equations (too theoretical!)
This one works just fine Pd = (0.109136 x q^1.9)/ d^5.02
Got a couple of hiccups though
*it computes the friction value correctly, but it does not display it correctly
*and the other is that if you enter a diameter and volume it computes everything properly, but if you use the square duct size you just got and the same volume , there is a discrepancy in the velocity--I think it has something to do with the computation of the area_sqft (there is a .91 difference when u convert back and forth from round to square)
*I could probably get rid of the pressure calc, it was needed for Reynold's
Code: [Select]
(defun duct_calc (/) ;     friction volume   pressure
;;;  velocity   diam rey_no   fric_fac
;;;  width     depth area_sqft
;;;  )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;                      Local Functions                          
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
  ;;  given the area in square feet returns the diameter
  (defun area2dia (sf_area / square)
    (setq square (sqrt (* sf_area 144.0)))
    (* 1.3
       (exp
(/ (log (/ (expt (* square square) 5.0)
   (expt (+ square square) 2.0)
   )
)
   8.0
   )
)
       )
    ) ; end defun

  ;;  given diameter returns the side dimension
  (defun dia2sq (dia)
    (* dia 0.914774703)
    )

  ;;  given the diameter returns the area in sq ft
  (defun dia2area (dia)
    (/ (* 0.7854 (expt dia 2.0)) 144.0)
    )

  ;;  given the sides returns the area in sq ft
  (defun rec2area (w d) ; retangle to area
    ;;(* (/ (* w d) 144.0) 0.914774703);<=changed
    (/ (* w d) 144.0)
    )

  ;;  given the diameter returns the area in sq ft
  (defun veloc2press (vel)
    (expt (/ vel 4005.00) 2)
    )

  ;;  calc friction
  (defun find_fric ()
    (setq friction (/ (* 0.109136 (expt volume 1.9)) (expt diam 5.02)))
    )


;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;;                    Start of Routine                          
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-


  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                    Get User Input                        
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (prompt "\nEnter known values. Press Enter if not known. ")
  (setq diam (getreal "\nEnter duct diameter: "))
  (if (null diam) ; skip if diameter entered
    (setq width (getreal "\nEnter duct width: ")
 depth (getreal "\nEnter duct depth: ")
 )
    )
  (setq volume (getreal "\nEnter total CFM'S: "))
  (if (null (and (or diam (and width depth)) volume))
    (setq velocity (getreal "\nEnter Velocity in FPM: "))
    )

  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                Process User Input                        
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (cond
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam volume)
     (setq area_sqft (dia2area diam)
  width     (dia2sq diam)
  depth     width
  velocity  (/ volume area_sqft)
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam velocity)
     (setq area_sqft (dia2area diam)
  width     (dia2sq diam)
  depth     width
  volume    (* area_sqft velocity)
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth volume)
     (setq area_sqft (rec2area width depth)
  diam     (area2dia area_sqft)
  velocity  (/ volume area_sqft);<==try multiplying area_sqft(0.914774703)
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth velocity)
     (setq area_sqft (rec2area width depth)
  diam     (area2dia area_sqft)
  volume    (* area_sqft velocity)
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and volume velocity)
     (setq area_sqft (/ (/ volume velocity) 0.914774703)
  diam     (area2dia area_sqft)
  width     (dia2sq diam)
  depth     width
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    (t
     (cond
       ((or volume velocity)
(prompt
 "\nYou must enter diameter or Width x Depth ..."
 )
)
       (t
(prompt "\nYou must indicate CFMs or FPM..")
)
       )
     )
    ) ; end cond stmt
  (textscr)
  (mapcar '(lambda (x) (prompt (strcat "\n" (car x) (rtos (cdr x) 2 3))))
 (list (cons "Diameter " diam)
(cons "Width    " width)
(cons "Depth    " depth)
(cons "Volume   " volume)
(cons "Velocity " velocity)
(cons "Friction " friction)
)
 )
  (princ)

  ) ; end defun



(defun c:test (/ friction)
  (while (null (setq friction (duct_calc))))
  (print friction)
  (princ)
  )

Water Bear

  • Guest
Mechanical help...
« Reply #18 on: February 25, 2004, 01:17:29 PM »
I corrected the friction display, although now it displays everything to 3 places :shock:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Mechanical help...
« Reply #19 on: February 25, 2004, 01:34:50 PM »
I revised the routine, bring the sledg hammer back.

Altered the
Code: [Select]
(rtos (cdr x) 2 8) to return 8 decimal points
Conversion from sq to rnd to sq works
Velocity is in error due to area formula.
the rnd duct area is ok for velocity but the sq area must be equevalent area.

This is what I came up with... :?


Code: [Select]
(defun duct_calc (/          friction   volume     pressure
                  velocity   diam       rey_no     fric_fac
                  width      depth      area_sqft
                 )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;                      Local Functions                            
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
  ;;  returns the square side dimension equivelant of rnd duct
  (defun rnd_to_sqr (dia ; dia of round duct
                     a ; side A of square duct
                     / loop fuzz b)
    (if (= (type a) 'int); make sure A is a REAL
      (setq a (* a 1.0))
    )
    (setq b    a ; B is target
          fuzz 0.001
          loop t
    )

    ;;  Returns Side B of square duct
    (while loop
      (setq dia2
             (* 1.3
                (exp (/ (log (/ (expt (* a b) 5) (expt (+ a b) 2))) 8))
             )
      )
      (if (equal dia2 dia fuzz)
        (setq loop nil) ; done
        (setq b (* b (/ dia dia2)))
      )
    )
    (princ)
    b
  ) ; end defun

  ;;  given the area in square feet returns the diameter
  (defun area2dia (sf_area / square)
    (setq square (sqrt (* sf_area 144.0)))
    (* 1.3
       (exp
         (/ (log (/ (expt (* square square) 5.0)
                    (expt (+ square square) 2.0)
                 )
            )
            8.0
         )
       )
    )
  ) ; end defun

  ;;  given diameter returns the side dimension
  (defun dia2sq (dia)
    ;;(* dia 0.914774703)
    ;;(*(sqrt area_sqft)12)
    (setq depth (* (sqrt area_sqft) 12)) ; CAB
    (rnd_to_sqr dia depth) ; CAB
  )

;;; given the diameter returns the area in sq ft
  (defun dia2area (dia)
    ;;(/ (* 0.7854 (expt dia 2.0)) 144.0)
    (/ (* pi (expt (/ dia 2.0) 2.0)) 144.0) ; CAB
  )

  ;;  given the sides returns the area in sq ft
  (defun rec2area (w d) ; retangle to area
    ;;(* (/ (* w d) 144.0) 0.914774703);<=changed
    (/ (* w d) 144.0)
  )

  ;;  given the diameter returns the area in sq ft
  (defun veloc2press (vel)
    (expt (/ vel 4005.00) 2)
  )

  ;;  calc friction
  (defun find_fric ()
    (setq friction (/ (* 0.109136 (expt volume 1.9)) (expt diam 5.02)))
  )


;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;;                    Start of Routine                            
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-


  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                    Get User Input                          
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (prompt "\nEnter known values. Press Enter if not known. ")
  (setq diam (getreal "\nEnter duct diameter: "))
  (if (null diam) ; skip if diameter entered
    (setq width (getreal "\nEnter duct width: ")
          depth (getreal "\nEnter duct depth: ")
    )
  )
  (setq volume (getreal "\nEnter total CFM'S: "))
  (if (null (and (or diam (and width depth)) volume))
    (setq velocity (getreal "\nEnter Velocity in FPM: "))
  )

  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                Process User Input                          
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (cond
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam volume)
     (setq area_sqft (dia2area diam)
           width     (dia2sq diam)
           ;;depth     width
           velocity  (/ volume area_sqft)
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam velocity)
     (setq area_sqft (dia2area diam)
           width     (dia2sq diam)
           ;;depth     width
           volume    (* area_sqft velocity)
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth volume)
     (setq area_sqft (rec2area width depth)
           diam      (area2dia area_sqft)
           ;;velocity  (/ volume area_sqft)dia2area
           velocity  (/ volume (dia2area diam))
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth velocity)
     (setq area_sqft (rec2area width depth)
           diam      (area2dia area_sqft)
           volume    (* area_sqft velocity)
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and volume velocity)
     (setq area_sqft (/ (/ volume velocity) 0.914774703)
           diam      (area2dia area_sqft)
           width     (dia2sq diam)
           ;;depth     width
           pressure  (veloc2press velocity)
     )
     (find_fric)
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    (t
     (cond
       ((or volume velocity)
        (prompt
          "\nYou must enter diameter or Width x Depth ..."
        )
       )
       (t
        (prompt "\nYou must indicate CFMs or FPM..")
       )
     )
    )
  ) ; end cond stmt
  (textscr)
  (mapcar '(lambda (x) (prompt (strcat "\n" (car x) (rtos (cdr x) 2 8))))
          (list (cons "Diameter " diam)
                (cons "Width    " width)
                (cons "Depth    " depth)
                (cons "Volume   " volume)
                (cons "Velocity " velocity)
                (cons "Friction " friction)
                (cons "Area     " area_sqft)
          )
  )
  (princ)
  friction ; return flag, nil if failed
) ; end defun



(defun c:test (/ friction)
  (while (null (setq friction (duct_calc))))
  (print friction)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Water Bear

  • Guest
Mechanical help...
« Reply #20 on: February 25, 2004, 02:00:59 PM »
Good one! ...and suppose that the only values we know are the volume and desired maximum friction?
Code: [Select]
(defun duct_calc (/     friction volume   pressure
 velocity   diam rey_no   fric_fac
 width     depth area_sqft
 )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;                      Local Functions                          
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
  ;;  returns the square side dimension equivelant of rnd duct
  (defun rnd_to_sqr (dia ; dia of round duct
    a ; side A of square duct
    / loop fuzz b)
    (if (= (type a) 'int) ; make sure A is a REAL
      (setq a (* a 1.0))
      )
    (setq b    a ; B is target
 fuzz 0.001
 loop t
 )

    ;;  Returns Side B of square duct
    (while loop
      (setq dia2
    (* 1.3
(exp (/ (log (/ (expt (* a b) 5) (expt (+ a b) 2))) 8))
)
   )
      (if (equal dia2 dia fuzz)
(setq loop nil) ; done
(setq b (* b (/ dia dia2)))
)
      )
    (princ)
    b
    ) ; end defun

  ;;  given the area in square feet returns the diameter
  (defun area2dia (sf_area / square)
    (setq square (sqrt (* sf_area 144.0)))
    (* 1.3
       (exp
(/ (log (/ (expt (* square square) 5.0)
   (expt (+ square square) 2.0)
   )
)
   8.0
   )
)
       )
    ) ; end defun

  ;;  given diameter returns the side dimension
  (defun dia2sq (dia)
    ;;(* dia 0.914774703)
    ;;(*(sqrt area_sqft)12)
    (setq depth (* (sqrt area_sqft) 12)) ; CAB
    (rnd_to_sqr dia depth) ; CAB
    )

;;; given the diameter returns the area in sq ft
  (defun dia2area (dia)
    ;;(/ (* 0.7854 (expt dia 2.0)) 144.0)
    (/ (* pi (expt (/ dia 2.0) 2.0)) 144.0) ; CAB
    )

  ;;  given the sides returns the area in sq ft
  (defun rec2area (w d) ; retangle to area
    ;;(* (/ (* w d) 144.0) 0.914774703);<=changed
    (/ (* w d) 144.0)
    )

  ;;  given the diameter returns the area in sq ft
  (defun veloc2press (vel)
    (expt (/ vel 4005.00) 2)
    )

  ;;  calc friction
  (defun find_fric ()
    (setq friction (/ (* 0.109136 (expt volume 1.9)) (expt diam 5.02)))
    )


;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;;                    Start of Routine                          
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-


  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                    Get User Input                        
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (prompt "\nEnter known values. Press Enter if not known. ")
  (setq diam (getreal "\nEnter duct diameter: "))
  (if (null diam) ; skip if diameter entered
    (setq width (getreal "\nEnter duct width: ")
 depth (getreal "\nEnter duct depth: ")
 )
    )
  (setq volume (getreal "\nEnter total CFM'S: ")
friction (getreal "\nEnter FRICTION value: ")
)
  (if (null (and (or diam (and width depth)) volume))
    (setq velocity (getreal "\nEnter Velocity in FPM: "))
    )

  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                Process User Input                        
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (cond
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and friction volume)
     (setq diam     (exp
      (/ (log (/ (* 0.109136 (expt volume 1.9)) friction)) 5.02)
      )
  area_sqft (dia2area diam)
  width     (dia2sq diam)
  depth     width
  velocity  (/ volume area_sqft)
  pressure  (veloc2press velocity)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam volume)
     (setq area_sqft (dia2area diam)
  width     (dia2sq diam)
  ;;depth     width
  velocity  (/ volume area_sqft)
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam velocity)
     (setq area_sqft (dia2area diam)
  width     (dia2sq diam)
  ;;depth     width
  volume    (* area_sqft velocity)
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth volume)
     (setq area_sqft (rec2area width depth)
  diam     (area2dia area_sqft)
  ;;velocity  (/ volume area_sqft)dia2area
  velocity  (/ volume (dia2area diam))
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth velocity)
     (setq area_sqft (rec2area width depth)
  diam     (area2dia area_sqft)
  volume    (* area_sqft velocity)
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and volume velocity)
     (setq area_sqft (/ (/ volume velocity) 0.914774703)
  diam     (area2dia area_sqft)
  width     (dia2sq diam)
  ;;depth     width
  pressure  (veloc2press velocity)
  )
     (find_fric)
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    (t
     (cond
       ((or volume velocity)
(prompt
 "\nYou must enter diameter or Width x Depth ..."
 )
)
       (t
(prompt "\nYou must indicate CFMs or FPM..")
)
       )
     )
    ) ; end cond stmt
  (textscr)
  (mapcar '(lambda (x)
    (prompt (strcat "\n" (car x) (rtos (cdr x) 2 8)))
    )
 (list (cons "Diameter " diam)
(cons "Width    " width)
(cons "Depth    " depth)
(cons "Volume   " volume)
(cons "Velocity " velocity)
(cons "Friction " friction)
(cons "Area     " area_sqft)
)
 )
  (princ)
  friction ; return flag, nil if failed
  ) ; end defun



(defun c:test (/ friction)
  (while (null (setq friction (duct_calc))))
  (print friction)
  (princ)
  )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Mechanical help...
« Reply #21 on: February 25, 2004, 02:19:13 PM »
Cleaned it up a bit.
Adjusted the input filter logic.

Code: [Select]
(defun duct_calc (/          friction   volume     pressure
                  velocity   diam       rey_no     fric_fac
                  width      depth      area_sqft
                 )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;                      Local Functions                            
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
  ;;  returns the square side dimension equivelant of rnd duct
  (defun rnd_to_sqr (dia ; dia of round duct
                     a ; side A of square duct
                     / loop fuzz b)
    (if (= (type a) 'int) ; make sure A is a REAL
      (setq a (* a 1.0))
    )
    (setq b    a ; B is target
          fuzz 0.001
          loop t
    )

    ;;  Returns Side B of square duct
    (while loop
      (setq dia2
             (* 1.3
                (exp (/ (log (/ (expt (* a b) 5) (expt (+ a b) 2))) 8))
             )
      )
      (if (equal dia2 dia fuzz)
        (setq loop nil) ; done
        (setq b (* b (/ dia dia2)))
      )
    )
    (princ)
    b
  ) ; end defun

  ;;  given the area in square feet returns the diameter
  (defun area2dia (sf_area / square)
    (setq square (sqrt (* sf_area 144.0)))
    (* 1.3
       (exp
         (/ (log (/ (expt (* square square) 5.0)
                    (expt (+ square square) 2.0)
                 )
            )
            8.0
         )
       )
    )
  ) ; end defun

  ;;  given diameter returns the side dimension
  (defun dia2sq (dia)
    ;;(* dia 0.914774703)
    ;;(*(sqrt area_sqft)12)
    (setq depth (* (sqrt area_sqft) 12)) ; CAB
    (rnd_to_sqr dia depth) ; CAB
  )

  ;; given the diameter returns the area in sq ft
  (defun dia2area (dia)
    ;;(/ (* 0.7854 (expt dia 2.0)) 144.0)
    (/ (* pi (expt (/ dia 2.0) 2.0)) 144.0) ; CAB
  )

  ;;  given the sides returns the area in sq ft
  (defun rec2area (w d) ; retangle to area
    ;;(* (/ (* w d) 144.0) 0.914774703);<=changed
    (/ (* w d) 144.0)
  )

  ;;  given the diameter returns the area in sq ft
  (defun veloc2press (vel)
    (expt (/ vel 4005.00) 2)
  )

  ;;  calc friction
  (defun find_fric ()
    (/ (* 0.109136 (expt volume 1.9)) (expt diam 5.02))
  )


;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;;                    Start of Routine                            
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-


  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                    Get User Input                          
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (prompt "\nEnter known values. Press Enter if not known. ")
  (setq diam (getreal "\nEnter duct diameter: "))
  (if (null diam) ; skip if diameter entered
    (setq width (getreal "\nEnter duct width: ")
          depth (getreal "\nEnter duct depth: ")
    )
  )
  (setq volume   (getreal "\nEnter total CFM'S: "))
  (if (null (and (or diam (and width depth)) volume))
    (setq friction (getreal "\nEnter FRICTION value: "))
  )
  (if (null (and (or diam (and width depth)) volume friction))
    (setq velocity (getreal "\nEnter Velocity in FPM: "))
  )

  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                Process User Input                          
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (cond
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and friction volume)
     (setq diam      (exp
                       (/ (log (/ (* 0.109136 (expt volume 1.9)) friction)) 5.02)
                     )
           area_sqft (dia2area diam)
           width     (dia2sq diam)
           velocity  (/ volume area_sqft)
           pressure  (veloc2press velocity)
     )
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam volume)
     (setq area_sqft (dia2area diam)
           width     (dia2sq diam)
           velocity  (/ volume area_sqft)
           pressure  (veloc2press velocity)
           friction  (find_fric)
     )
     
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam velocity)
     (setq area_sqft (dia2area diam)
           width     (dia2sq diam)
           volume    (* area_sqft velocity)
           pressure  (veloc2press velocity)
           friction  (find_fric)
     )
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth volume)
     (setq area_sqft (rec2area width depth)
           diam      (area2dia area_sqft)
           velocity  (/ volume (dia2area diam))
           pressure  (veloc2press velocity)
           friction  (find_fric)
     )
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth velocity)
     (setq area_sqft (rec2area width depth)
           diam      (area2dia area_sqft)
           volume    (* area_sqft velocity)
           pressure  (veloc2press velocity)
           friction  (find_fric)
     )
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and volume velocity)
     (setq area_sqft (/ (/ volume velocity) 0.914774703)
           diam      (area2dia area_sqft)
           width     (dia2sq diam)
           pressure  (veloc2press velocity)
           friction  (find_fric)
     )
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    (t
     (cond
       ((or volume velocity)
        (prompt
          "\nYou must enter diameter or Width x Depth ..."
        )
       )
       (t
        (prompt "\nYou must indicate CFMs or FPM..")
       )
     )
    )
  ) ; end cond stmt
  (textscr)
  (mapcar '(lambda (x)
             (prompt (strcat "\n" (car x) (rtos (cdr x) 2 8)))
           )
          (list (cons "Diameter " diam)
                (cons "Width    " width)
                (cons "Depth    " depth)
                (cons "Volume   " volume)
                (cons "Velocity " velocity)
                (cons "Friction " friction)
          )
  )
  (princ)
  friction ; return flag, nil if failed
) ; end defun



(defun c:test (/ friction)
  (while (null (setq friction (duct_calc))))
  (print friction)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Water Bear

  • Guest
Mechanical help...
« Reply #22 on: February 25, 2004, 02:31:08 PM »
Excellent stuff CAB! Now I've got something usable! The only thing I think I need is to make it loop while trying different square size combinations. Thanx, I really appreciate all your help... :D

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Mechanical help...
« Reply #23 on: February 25, 2004, 03:10:59 PM »
Any time...

Changed the print function to allow nil in case you pressed Enter to all prompts.

This TEST routine will loop until Escape or Enter to all.

Code: [Select]
(defun duct_calc (/          friction   volume     pressure
                  velocity   diam       rey_no     fric_fac
                  width      depth      area_sqft
                 )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;                      Local Functions                            
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
  ;;  returns the square side dimension equivelant of rnd duct
  (defun rnd_to_sqr (dia ; dia of round duct
                     a ; side A of square duct
                     / loop fuzz b)
    (if (= (type a) 'int) ; make sure A is a REAL
      (setq a (* a 1.0))
    )
    (setq b    a ; B is target
          fuzz 0.001
          loop t
    )

    ;;  Returns Side B of square duct
    (while loop
      (setq dia2
             (* 1.3
                (exp (/ (log (/ (expt (* a b) 5) (expt (+ a b) 2))) 8))
             )
      )
      (if (equal dia2 dia fuzz)
        (setq loop nil) ; done
        (setq b (* b (/ dia dia2)))
      )
    )
    (princ)
    b
  ) ; end defun

  ;;  given the area in square feet returns the diameter
  (defun area2dia (sf_area / square)
    (setq square (sqrt (* sf_area 144.0)))
    (* 1.3
       (exp
         (/ (log (/ (expt (* square square) 5.0)
                    (expt (+ square square) 2.0)
                 )
            )
            8.0
         )
       )
    )
  ) ; end defun

  ;;  given diameter returns the side dimension
  (defun dia2sq (dia)
    ;;(* dia 0.914774703)
    ;;(*(sqrt area_sqft)12)
    (setq depth (* (sqrt area_sqft) 12)) ; CAB
    (rnd_to_sqr dia depth) ; CAB
  )

  ;; given the diameter returns the area in sq ft
  (defun dia2area (dia)
    ;;(/ (* 0.7854 (expt dia 2.0)) 144.0)
    (/ (* pi (expt (/ dia 2.0) 2.0)) 144.0) ; CAB
  )

  ;;  given the sides returns the area in sq ft
  (defun rec2area (w d) ; retangle to area
    ;;(* (/ (* w d) 144.0) 0.914774703);<=changed
    (/ (* w d) 144.0)
  )

  ;;  given the diameter returns the area in sq ft
  (defun veloc2press (vel)
    (expt (/ vel 4005.00) 2)
  )

  ;;  calc friction
  (defun find_fric ()
    (/ (* 0.109136 (expt volume 1.9)) (expt diam 5.02))
  )


;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;;                    Start of Routine                            
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-


  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                    Get User Input                          
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (prompt "\nEnter known values. Press Enter if not known. ")
  (setq diam (getreal "\nEnter duct diameter: "))
  (if (null diam) ; skip if diameter entered
    (setq width (getreal "\nEnter duct width: ")
          depth (getreal "\nEnter duct depth: ")
    )
  )
  (setq volume (getreal "\nEnter total CFM'S: "))
  (if (null (and (or diam (and width depth)) volume))
    (setq friction (getreal "\nEnter FRICTION value: "))
  )
  (if (null (and (or diam (and width depth)) volume))
    (setq velocity (getreal "\nEnter Velocity in FPM: "))
  )

  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                Process User Input                          
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (cond
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and friction volume)
     (setq diam      (exp
                       (/ (log (/ (* 0.109136 (expt volume 1.9)) friction)) 5.02)
                     )
           area_sqft (dia2area diam)
           width     (dia2sq diam)
           velocity  (/ volume area_sqft)
           pressure  (veloc2press velocity)
     )
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam volume)
     (setq area_sqft (dia2area diam)
           width     (dia2sq diam)
           velocity  (/ volume area_sqft)
           pressure  (veloc2press velocity)
           friction  (find_fric)
     )

    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam velocity)
     (setq area_sqft (dia2area diam)
           width     (dia2sq diam)
           volume    (* area_sqft velocity)
           pressure  (veloc2press velocity)
           friction  (find_fric)
     )
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth volume)
     (setq area_sqft (rec2area width depth)
           diam      (area2dia area_sqft)
           velocity  (/ volume (dia2area diam))
           pressure  (veloc2press velocity)
           friction  (find_fric)
     )
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth velocity)
     (setq area_sqft (rec2area width depth)
           diam      (area2dia area_sqft)
           volume    (* area_sqft velocity)
           pressure  (veloc2press velocity)
           friction  (find_fric)
     )
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and volume velocity)
     (setq area_sqft (/ (/ volume velocity) 0.914774703)
           diam      (area2dia area_sqft)
           width     (dia2sq diam)
           pressure  (veloc2press velocity)
           friction  (find_fric)
     )
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    (t
     (cond
       ((or volume velocity)
        (prompt
          "\nYou must enter diameter or Width x Depth ..."
        )
       )
       (t
        (prompt "\nYou must indicate CFMs or FPM..")
       )
     )
    )
  ) ; end cond stmt
  (textscr)
  (mapcar '(lambda (x)
             (prompt (strcat "\n"
                             (car x)
                             (if (cdr x)
                               (rtos (cdr x) 2 8)
                               "X"
                             )
                     )
             )
           )
          (list (cons "Diameter " diam)
                (cons "Width    " width)
                (cons "Depth    " depth)
                (cons "Volume   " volume)
                (cons "Velocity " velocity)
                (cons "Friction " friction)
          )
  )
  (princ)
  friction ; return flag, nil if failed
) ; end defun



(defun c:test (/ friction)
  (while (setq friction (duct_calc)))
  (print friction)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Water Bear

  • Guest
Mechanical help...
« Reply #24 on: February 25, 2004, 04:30:51 PM »
added for known diameter and friction, compute volume, velocity and square
Code: [Select]
(defun duct_calc (/     friction volume   pressure
 velocity   diam rey_no   fric_fac
 width     depth area_sqft
 )

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;                      Local Functions                          
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
  ;;  returns the square side dimension equivelant of rnd duct
  (defun rnd_to_sqr (dia ; dia of round duct
    a ; side A of square duct
    / loop fuzz b)
    (if (= (type a) 'int) ; make sure A is a REAL
      (setq a (* a 1.0))
      )
    (setq b    a ; B is target
 fuzz 0.001
 loop t
 )

    ;;  Returns Side B of square duct
    (while loop
      (setq dia2
    (* 1.3
(exp (/ (log (/ (expt (* a b) 5) (expt (+ a b) 2))) 8))
)
   )
      (if (equal dia2 dia fuzz)
(setq loop nil) ; done
(setq b (* b (/ dia dia2)))
)
      )
    (princ)
    b
    ) ; end defun

  ;;  given the area in square feet returns the diameter
  (defun area2dia (sf_area / square)
    (setq square (sqrt (* sf_area 144.0)))
    (* 1.3
       (exp
(/ (log (/ (expt (* square square) 5.0)
   (expt (+ square square) 2.0)
   )
)
   8.0
   )
)
       )
    ) ; end defun

  ;;  given diameter returns the side dimension
  (defun dia2sq (dia)
    ;;(* dia 0.914774703)
    ;;(*(sqrt area_sqft)12)
    (setq depth (* (sqrt area_sqft) 12)) ; CAB
    (rnd_to_sqr dia depth) ; CAB
    )

  ;; given the diameter returns the area in sq ft
  (defun dia2area (dia)
    ;;(/ (* 0.7854 (expt dia 2.0)) 144.0)
    (/ (* pi (expt (/ dia 2.0) 2.0)) 144.0) ; CAB
    )

  ;;  given the sides returns the area in sq ft
  (defun rec2area (w d) ; retangle to area
    ;;(* (/ (* w d) 144.0) 0.914774703);<=changed
    (/ (* w d) 144.0)
    )

  ;;  given the diameter returns the area in sq ft
  (defun veloc2press (vel)
    (expt (/ vel 4005.00) 2)
    )

  ;;  calc friction
  (defun find_fric ()
    (/ (* 0.109136 (expt volume 1.9)) (expt diam 5.02))
    )


;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;;                    Start of Routine                          
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-


  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                    Get User Input                        
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (prompt "\nEnter known values. Press Enter if not known. ")
  (setq diam (getreal "\nEnter duct diameter: "))
  (if (null diam) ; skip if diameter entered
    (setq width (getreal "\nEnter duct width: ")
 depth (getreal "\nEnter duct depth: ")
 )
    )
  (setq volume (getreal "\nEnter total CFM'S: "))
  (if (null (and (or diam (and width depth)) volume))
    (setq friction (getreal "\nEnter FRICTION value: "))
    )
  (if (null (and (or diam (and width depth)) volume))
    (setq velocity (getreal "\nEnter Velocity in FPM: "))
    )

  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                Process User Input                        
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (cond
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and friction diam)
     (setq volume    (exp
      (/ (log (/ (* friction (expt diam 5.02)) 0.109136)) 1.9)
      )
  area_sqft (dia2area diam)
  width     (dia2sq diam)
  velocity  (/ volume area_sqft)
  pressure  (veloc2press velocity)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and friction volume)
     (setq diam     (exp
      (/ (log (/ (* 0.109136 (expt volume 1.9)) friction)) 5.02)
      )
  area_sqft (dia2area diam)
  width     (dia2sq diam)
  velocity  (/ volume area_sqft)
  pressure  (veloc2press velocity)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam volume)
     (setq area_sqft (dia2area diam)
  width     (dia2sq diam)
  velocity  (/ volume area_sqft)
  pressure  (veloc2press velocity)
  friction  (find_fric)
  )

     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam velocity)
     (setq area_sqft (dia2area diam)
  width     (dia2sq diam)
  volume    (* area_sqft velocity)
  pressure  (veloc2press velocity)
  friction  (find_fric)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth volume)
     (setq area_sqft (rec2area width depth)
  diam     (area2dia area_sqft)
  velocity  (/ volume (dia2area diam))
  pressure  (veloc2press velocity)
  friction  (find_fric)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth velocity)
     (setq area_sqft (rec2area width depth)
  diam     (area2dia area_sqft)
  volume    (* area_sqft velocity)
  pressure  (veloc2press velocity)
  friction  (find_fric)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and volume velocity)
     (setq area_sqft (/ (/ volume velocity) 0.914774703)
  diam     (area2dia area_sqft)
  width     (dia2sq diam)
  pressure  (veloc2press velocity)
  friction  (find_fric)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    (t
     (cond
       ((or volume velocity)
(prompt
 "\nYou must enter diameter or Width x Depth ..."
 )
)
       (t
(prompt "\nYou must indicate CFMs or FPM..")
)
       )
     )
    ) ; end cond stmt
  (textscr)
  (mapcar '(lambda (x)
    (prompt (strcat "\n"
    (car x)
    (if (cdr x)
      (rtos (cdr x) 2 8)
      "X"
      )
    )
    )
    )
 (list (cons "Diameter " diam)
(cons "Width    " width)
(cons "Depth    " depth)
(cons "Volume   " volume)
(cons "Velocity " velocity)
(cons "Friction " friction)
)
 )
  (princ)
  friction ; return flag, nil if failed
  ) ; end defun



(defun c:test (/ friction)
  (while (setq friction (duct_calc)))
  (print friction)
  (princ)
  )
Did I cover all possibilities?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Mechanical help...
« Reply #25 on: February 25, 2004, 04:51:23 PM »
All you need now is a DCL version. :D

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

DEVITG

  • Bull Frog
  • Posts: 479
Mechanical help...
« Reply #26 on: February 25, 2004, 05:03:19 PM »
Hi all you, you did a very good program in only two days. :lol:  :D

As a user of ductwork normally the duct are rectangular and often one side is keep constant , just as a matter to suit the space in the ceiling.
Guess you have a free space of 2' the  constant side must be less than 2'  
to allow the isolation and frame space.
Of course that when the side ratio is to big the constant side shall be changed.

Thanks againg..
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Water Bear

  • Guest
Mechanical help...
« Reply #27 on: February 25, 2004, 05:10:59 PM »
Whaaa! :shock:  :shock:

DEVITG

  • Bull Frog
  • Posts: 479
Mechanical help...
« Reply #28 on: February 25, 2004, 06:03:20 PM »
Water Bear, please apologize me.
I just try to express a wish as a user of duct work.

Normally I used a duct calculator rule , the same it had been used since 40 years or more back  from now.

This rule work on the same friction loos expresed on inch of water column by 100 ft  
Usually a fixed valued is used as per economic reazon and the allowable presure to be suited by the fan.
A normal value is set from 0.1 to 0.25 inch water column by 100'
This system allow an easy way to know the total pressure  loos of a system.
Hope you understand me , my english is poor , because I'm not in USA and it is my second language.
 :oops:  :oops:
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Water Bear

  • Guest
Mechanical help...
« Reply #29 on: February 26, 2004, 09:37:52 AM »
OK..I found inconsistencies when square duct sizes were input..corrected that new:
Code: [Select]
(defun duct_calc
       (/ friction volume velocity diam width depth area_sqft)

;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;                      Local Functions                          
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
  ;;  returns the square side dimension equivelant of rnd duct
  (defun rnd_to_sqr (dia ; dia of round duct
    a ; side A of square duct
    / loop fuzz b)
    (if (= (type a) 'int) ; make sure A is a REAL
      (setq a (* a 1.0))
      )
    (setq b    a ; B is target
 fuzz 0.001
 loop t
 )

    ;;  Returns Side B of square duct
    (while loop
      (setq dia2
    (* 1.3
(exp (/ (log (/ (expt (* a b) 5) (expt (+ a b) 2))) 8))
)
   )
      (if (equal dia2 dia fuzz)
(setq loop nil) ; done
(setq b (* b (/ dia dia2)))
)
      )
    (princ)
    b
    ) ; end defun

  ;;  given the area in square feet returns the diameter
  (defun area2dia (sf_area / square)
    (setq square (sqrt (* sf_area 144.0)))
    (* 1.3
       (exp
(/ (log (/ (expt (* square square) 5.0)
   (expt (+ square square) 2.0)
   )
)
   8.0
   )
)
       )
    ) ; end defun

  ;;  given diameter returns the side dimension
  (defun dia2sq (dia)
    ;;(* dia 0.914774703)
    ;;(*(sqrt area_sqft)12)
    (setq depth (* (sqrt area_sqft) 12)) ; CAB
    (rnd_to_sqr dia depth) ; CAB
    )

  ;; given the diameter returns the area in sq ft
  (defun dia2area (dia)
    ;;(/ (* 0.7854 (expt dia 2.0)) 144.0)
    (/ (* pi (expt (/ dia 2.0) 2.0)) 144.0) ; CAB
    )

  ;;given a square duct, make it round<=====added this
  (defun make_round (w d)
    (* 1.3
       (exp
(/ (log (/ (expt (* w d) 5.0)
   (expt (+ w d) 2.0)
   )
)
   8.0
   )
)
       )
    )

  ;;  given the diameter returns the area in sq ft
  (defun veloc2press (vel)
    (expt (/ vel 4005.00) 2)
    )

  ;;  calc friction
  (defun find_fric ()
    (/ (* 0.109136 (expt volume 1.9)) (expt diam 5.02))
    )


;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;;                    Start of Routine                          
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-


  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                    Get User Input                        
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (prompt "\nEnter known values. Press Enter if not known. ")
  (setq diam (getreal "\nEnter duct diameter: "))
  (if (null diam) ; skip if diameter entered
    (setq width (getreal "\nEnter duct width: ")
 depth (getreal "\nEnter duct depth: ")
 )
    )
  (setq volume (getreal "\nEnter total CFM'S: "))
  (if (null (and (or diam (and width depth)) volume))
    (setq friction (getreal "\nEnter FRICTION value: "))
    )
  (if (null (and (or diam (and width depth)) volume))
    (setq velocity (getreal "\nEnter Velocity in FPM: "))
    )

  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;                Process User Input                        
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  (cond
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and friction diam)
     (setq volume    (exp
      (/ (log (/ (* friction (expt diam 5.02)) 0.109136)) 1.9)
      )
  area_sqft (dia2area diam)
  width     (dia2sq diam)
  velocity  (/ volume area_sqft)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and friction volume)
     (setq diam     (exp
      (/ (log (/ (* 0.109136 (expt volume 1.9)) friction)) 5.02)
      )
  area_sqft (dia2area diam)
  width     (dia2sq diam)
  velocity  (/ volume area_sqft)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam volume)
     (setq area_sqft (dia2area diam)
  width     (dia2sq diam)
  velocity  (/ volume area_sqft)
  friction  (find_fric)
  )

     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and diam velocity)
     (setq area_sqft (dia2area diam)
  width     (dia2sq diam)
  volume    (* area_sqft velocity)
  friction  (find_fric)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth friction)
     (setq diam    (make_round width depth)
  volume   (exp
     (/ (log (/ (* friction (expt diam 5.02)) 0.109136))
1.9
)
     )
  velocity (/ volume (dia2area diam))
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth volume)
     (setq diam    (make_round width depth)
  velocity (/ volume (dia2area diam))
  friction (find_fric)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and width depth velocity)
     (setq diam    (make_round width depth)
  volume   (* (dia2area diam) velocity)
  friction (find_fric)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ((and volume velocity)
     (setq area_sqft (/ (/ volume velocity) 0.914774703)
  diam     (area2dia area_sqft)
  width     (dia2sq diam)
  friction  (find_fric)
  )
     )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    (t
     (cond
       ((or volume velocity)
(prompt
 "\nYou must enter diameter or Width x Depth ..."
 )
)
       (t
(prompt "\nYou must indicate CFMs or FPM..")
)
       )
     )
    ) ; end cond stmt
  (textscr)
  (mapcar '(lambda (x)
    (prompt (strcat "\n"
    (car x)
    (if (cdr x)
      (rtos (cdr x) 2 2)
      "X"
      )
    )
    )
    )
 (list (cons "Diameter " diam)
(cons "Width    " width)
(cons "Depth    " depth)
(cons "Volume   " volume)
(cons "Velocity " velocity)
(cons "Friction " friction)
)
 )
  (princ)
;friction ; return flag, nil if failed
  ) ; end defun



(defun c:test (/ friction)
  (while (setq friction (duct_calc)))
  (print friction)
  (princ)
  )