hfoil 0.1.1 → 0.1.2
raw patch · 4 files changed
+105/−45 lines, 4 files
Files
- Numeric/HFoil/Drawing.hs +21/−14
- Numeric/HFoil/Flow.hs +25/−3
- Numeric/HFoil/Repl.hs +55/−22
- hfoil.cabal +4/−6
Numeric/HFoil/Drawing.hs view
@@ -8,6 +8,7 @@ , drawOnce , drawNormals , drawForces+ , drawKuttas ) where import Graphics.Gloss hiding(Vector,dim)@@ -73,6 +74,15 @@ where x = realToFrac $ (x' - min')/(max'-min') +drawKuttas :: (Real a, Storable a) => FlowSol a -> Picture+drawKuttas flow = pictures $ concatMap (\(k0,k1) -> [circ k0, circ k1]) kis+ where+ kis = solKuttaIndices flow+ (xs',ys') = unzip $ map fMidpoints $ (\(Foil els _) -> els) (solFoil flow)+ xs = join xs'+ ys = join ys'+ circ k = drawCircle yellow (xs @> k, ys @> k) 0.006+ drawForces :: FlowSol Double -> Picture drawForces flow = pictures $ map (\(xy0, xy1, cp) -> drawLine (colorFun minCp maxCp cp) [xy0, xy1]) $ zip3 xy0s xy1s (toList (solCps flow))@@ -108,14 +118,11 @@ f _ _ = error "uh oh (groupSomethingByFoil)" drawSolution :: FlowSol Double -> Picture-drawSolution flow = pictures $ [ drawText white (0.45, 0.8) 0.15 m0- , drawText white (0.45, 0.65) 0.15 m1- , drawText white (0.45, 0.5) 0.15 m2- , drawText white (0.45, 0.35) 0.15 m3- , drawForces flow- , drawColoredFoil colors foil+drawSolution flow = pictures $ onscreenText +++ [ drawColoredFoil colors foil , drawCircle white (fst $ solCenterPressure flow, snd $ solCenterPressure flow) 0.006 , drawCircle white (fst $ solCenterPressure flow, 0) 0.006+ , drawCircle green (0.25,0::Double) 0.006 ] ++ zipWith (\x y -> drawLineV red (x, y)) xs (takesV (map dim xs) (LA.scale cpScale cps)) -- cp graph where@@ -124,15 +131,15 @@ xs = map (fst . fMidpoints) elements --- ] ++ zipWith (\x y -> drawLine red (toList x, y)) xs (groupSomethingByFoil foil (toList (LA.scale cpScale cps))) -- cp graph--- +++ onscreenText = zipWith (\m y -> drawText white (0.45,y) 0.15 m) msgs+ $ take (length msgs) [0.8,0.65..]+ msgs = [ name+ , printf ("alpha: %.6f deg") ((solAlpha flow)*180/pi)+ , printf ("Cl: %.6f") (solCl flow)+ , printf ("Cd: %.6f") (solCd flow)+ , printf ("Cm: %.6f (c/4, 0)") (solCm flow)+ ] - [m0,m1,m2,m3] = [ name- , printf ("alpha: %.6f") ((solAlpha flow)*180/pi)- , printf ("Cl: %.6f") (solCl flow)- , printf ("Cd: %.6f") (solCd flow)- ]- colors = map (colorFun (minElement cps) (maxElement cps)) (toList cps)
Numeric/HFoil/Flow.hs view
@@ -19,9 +19,12 @@ , solVorticities :: [a] , solAlpha :: a , solForces :: (Vector a, Vector a)+ , solForce :: (a,a) , solCl :: a , solCd :: a+ , solCm :: a -- moment about (0,0.25) , solCenterPressure :: (a,a)+ , solKuttaIndices :: [(Int,Int)] } solveFlow :: (Num (Vector a), RealFloat a, Field a) => Foil a -> a -> FlowSol a@@ -32,9 +35,12 @@ , solVorticities = vorticities , solAlpha = alpha , solForces = (xForces, yForces)+ , solForce = (xf,yf) , solCl = cl , solCd = cd+ , solCm = cm , solCenterPressure = (xCp, yCp)+ , solKuttaIndices = kuttaIndices } where -- surface velocities@@ -56,14 +62,18 @@ cd = xf*(cos alpha) + yf*(sin alpha) cl = -xf*(sin alpha) + yf*(cos alpha)-+ + -- midpoints+ (xs,ys) = (\(x,y) -> (join x, join y)) $ unzip $ map fMidpoints elements+ -- centers of pressure (xCp, yCp) = ( (sumElements (xs*yForces)) / (sumElements yForces) , (sumElements (ys*xForces)) / (sumElements xForces) )- where- (xs,ys) = (\(x,y) -> (join x, join y)) $ unzip $ map fMidpoints elements + -- moment about cp and quarter chord+ cm = sumElements $ (mapVector (\z -> z - 0.25) xs)*yForces - ys*xForces+ kuttaIndices = ki 0 (map dim angles') where ki _ [] = []@@ -125,6 +135,18 @@ getSubRow i (j0,jf) mat = flatten $ subMatrix (i,j0) (1,jf-j0+1) mat +{- +calcuate 4 matrices which will be useful++mSL(i,j) = sin(qi - ij) * ln(rij+1/rij)+mCL(i,j) = cos(qi - ij) * ln(rij+1/rij)+mSB(i,j) = sin(qi - ij) * beta(i,j)+mCB(i,j) = cos(qi - ij) * beta(i,j)++where for i==j: ln(r/r) = 0+ beta = pi+are explicitly set+-} setupGeometries :: (RealFloat t, Storable t) => Vector t -> (Vector t, Vector t)
Numeric/HFoil/Repl.hs view
@@ -22,6 +22,17 @@ xSize = 800 ySize = 500 +data Config = Config { confForces :: Bool+ , confKuttas :: Bool+ , confNormals :: Bool+ }++defaultConfig :: Config+defaultConfig = Config { confForces = False+ , confKuttas = False+ , confNormals = False+ }+ run :: IO () run = do let naca0 = "2412"@@ -31,7 +42,8 @@ putStrLn "Welcome to hfoil\n" - _ <- forkIO $ runInputT defaultSettings (topLoop (\pics -> swapMVar mpics pics >>= (\_ -> return ())))+ _ <- forkIO $ runInputT defaultSettings+ $ topLoop (\pics -> swapMVar mpics pics >>= (\_ -> return ())) defaultConfig animateIO (InWindow@@ -41,52 +53,73 @@ black -- background color (\_ -> readMVar mpics >>= return . pictures) -- draw function -foilLoop :: ([Picture] -> IO ()) -> Foil Double -> InputT IO ()-foilLoop draw foil@(Foil _ name) = do+foilLoop :: ([Picture] -> IO ()) -> Config -> Foil Double -> InputT IO ()+foilLoop draw conf foil@(Foil _ name) = do minput <- getInputLine $ "\ESC[1;32m\STXhfoil."++name++">> \ESC[0m\STX" case minput of Nothing -> return () Just "quit" -> do outputStrLn "gloss won't let you quit :(\ntry ctrl-c or hit ESC in drawing window"- foilLoop draw foil+ foilLoop draw conf foil Just ('a':'l':'f':'a':' ':[]) -> do outputStrLn $ "unrecognized command"- foilLoop draw foil+ foilLoop draw conf foil Just ('a':'l':'f':'a':' ':alphaDeg) -> do let flow = solveFlow foil (pi/180*(read alphaDeg))- liftIO $ draw $ [drawSolution flow]- foilLoop draw foil+ forces = case (confForces conf) of+ True -> [drawForces flow]+ False -> []+ kuttas = case (confKuttas conf) of+ True -> [drawKuttas flow]+ False -> []+ normals = case (confNormals conf) of+ True -> [drawNormals (solFoil flow)]+ False -> []+ liftIO $ draw $ forces++kuttas++normals++[drawSolution flow]+ foilLoop draw conf foil+ Just ('f':'o':'r':'c':'e':'s':[]) -> do+ let newConf = conf {confForces = not (confForces conf)}+ outputStrLn $ "force drawing set to "++ show (not (confForces conf))+ foilLoop draw newConf foil+ Just ('k':'u':'t':'t':'a':'s':[]) -> do + let newConf = conf {confKuttas = not (confKuttas conf)}+ outputStrLn $ "kutta drawing set to "++ show (not (confKuttas conf))+ foilLoop draw newConf foil+ Just ('n':'o':'r':'m':'a':'l':'s':[]) -> do+ let newConf = conf {confNormals = not (confNormals conf)}+ outputStrLn $ "normals drawing set to "++ show (not (confNormals conf))+ foilLoop draw newConf foil Just "" -> return () Just input -> do outputStrLn $ "unrecognized command \"" ++ input ++ "\""- foilLoop draw foil+ foilLoop draw conf foil -topLoop :: ([Picture] -> IO ()) -> InputT IO ()-topLoop draw = do+topLoop :: ([Picture] -> IO ()) -> Config -> InputT IO ()+topLoop draw conf = do minput <- getInputLine "\ESC[1;32m\STXhfoil>> \ESC[0m\STX" case minput of Nothing -> return () Just "quit" -> do outputStrLn "gloss won't let you quit :(\ntry ctrl-c or hit ESC in drawing window"- topLoop draw- Just ('n':'a':'c':'a':' ':spec) -> do parseNaca draw spec- topLoop draw+ topLoop draw conf+ Just ('n':'a':'c':'a':' ':spec) -> do parseNaca draw conf spec+ topLoop draw conf Just ('l':'o':'a':'d':' ':name) -> do foil <- liftIO (loadFoil name) case foil of Left errMsg -> outputStrLn errMsg Right foil' -> do liftIO $ draw [drawFoil foil', drawNormals foil']- foilLoop draw foil'- topLoop draw+ foilLoop draw conf foil'+ topLoop draw conf Just ('u':'i':'u':'c':' ':name) -> do efoil <- liftIO (getUIUCFoil name) case efoil of Left errMsg -> outputStrLn errMsg Right foil -> do liftIO $ draw [drawFoil foil, drawNormals foil]- foilLoop draw foil- topLoop draw+ foilLoop draw conf foil+ topLoop draw conf - Just "" -> topLoop draw+ Just "" -> topLoop draw conf Just input -> do outputStrLn $ "unrecognized command \"" ++ input ++ "\""- topLoop draw+ topLoop draw conf -parseNaca :: ([Picture] -> IO ()) -> String -> InputT IO ()-parseNaca draw str +parseNaca :: ([Picture] -> IO ()) -> Config -> String -> InputT IO ()+parseNaca draw conf str | length str == 4 = do let foil = panelizeNaca4 (naca4 str :: Naca4 Double) nPanels liftIO $ draw [drawFoil foil, drawNormals foil]- foilLoop draw foil+ foilLoop draw conf foil | otherwise = do outputStrLn $ "Not 4 digits" return ()
hfoil.cabal view
@@ -1,5 +1,5 @@ Name: hfoil-Version: 0.1.1+Version: 0.1.2 Stability: Experimental Synopsis: Hess-Smith panel code for inviscid 2-d airfoil analysis License: BSD3@@ -21,15 +21,13 @@ . * Broken UIUC database integration (type \"uiuc [foilname]\") .-* Shameless xfoil ripoff for the relp/plotting+* Shameless xfoil ripoff for relp/plotting interface .-* Only works with development version of Gloss that's not yet on Hackage+* Only works with development version of Gloss that's not on Hackage yet . * Haskeline interface with tab-completion .-* And nothing else. .-. To get started, do cabal install or whatever, then run the \"hfoil\" binary. . Things to try: \"naca 2412\", \"alfa 4\", (hit enter before entering another airfoil), \"load [filename]\", \"uiuc e330\"@@ -78,4 +76,4 @@ source-repository head type: git location: git://github.com/ghorn/hfoil.git- tag: 0.1.1+ tag: 0.1.2