Rabid Geek
  • Home
  • Bio
  • Applets
    • Graphing Calculator
    • Electric Fields
    • Fourier Series
    • Motion
    • Oscillations
    • Pendulum
    • Projectile Motion
    • Snell’s Law
    • Taylor Series
    • Waves
  • Projects
    • Android
    • Linux
      • Linux Web Camera Class
    • Mathematics
    • Other
      • Mesh Triangulation
  • Contact

Computational Fluid Dynamics written in Python

May18
2012
Leave a Comment Written by Gavin

Over the past number of weeks, I have been learning Finite Element Analysis to use for solving the Navier-Stokes equations of fluid dynamics.  Finite Element Analysis is used to solve partial differential equations over an unstructured grid.  Usually the grid is made up of triangles or quadrilaterals.   In my case, I used triangles since any mesh can be constructed from triangles.

Here are some results. The following is a simulation of Vortex Shedding of an incompressible fluid due to a circular obstacle. The simulation was written in Python using Numpy, Scipy, and Matplotlib and employs the pressure correction method.

Properties of the fluid:
Boundary Velocities:

    \[U(0,y) = U(5,y) =U(x,0) = U(x,3) =1.0\]

    \[Re = 500\]

Another video with the parameters slightly changed. This uses No-Slip boundary conditions on the top and bottom boundaries as well as a smaller fluid channel
Boundary Velocities:

    \[U(0,y) = U(5,y) = 1.0\]

    \[U(x,0) = U(x,1) = 0.0\]

    \[Re = 1000\]

I will release the Python code after I have cleaned it up a bit.

Posted in Math
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Delaunay Triangulation is fun!

Nov15
2011
1 Comment Written by Gavin

I’ve been trying to learn the Finite Element Method (FEM) for solving partial differential equations.  Turns out that I can’t do much with the FEM unless I have some kind of mesh, and generating a mesh is annoying.  So I looked into a way of generating one and came across Delaunay Triangulation.  The concept is quite easy and thought I’d try to implement it in C++.  Here is the output of the triangulation from a random set of points:

Triangular mesh generated from a random set of points

The code is posted on git hub.  Download it using the following commands (if you use git)

git clone git://github.com/rabidgeek/Mesh-Triangulation.git

Or if you prefer a downloadable link:
Download: zip

Posted in C++, Math
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Conky + Twitter

Sep29
2011
Leave a Comment Written by Gavin

I finally decided to get a Twitter account.  The first thing I wanted to do was interface it with my Conky script.  The Twitter API was a pain to use and there wasn’t much documentation on how to use it properly.  So I did some trickery and created a work around.

I found a command line interface for twitter called Twidge that was easy to set up and could easily read my Twitter friend’s feed and output it to the console.  This allowed me to pipe the output to a text file and then use a custom Python script to format the text the way I liked it.  The two lines that needed to be added to Conky are as follows:

{execi 1200 twidge lsrecent >  /home/commander/scripts/tweets.txt}{execi 1200 python /home/commander/scripts/tw.py /home/commander/scripts/tweets.txt}

The following is the tw.py python code that reads in the text file generated by Twidge and then reformats it to my choosing.  This code can be ignored if you just want to use the standard output that Twidge uses.  In which case the first line in the Conky script should not pipe the output to the text fiel.

#!/usr/bin/python
#filename: tw.py
import re
import sys
from time import strftime

def format(text, indent=2, width=70):
    """
    Format a text block.

    This function formats a block of text. The text is broken into
    tokens. (Whitespace is NOT preserved.) The tokens are reassembled
    at the specified level of indentation and line width.  A string is
    returned.

    Arguments:
        `text`   -- the string to be reformatted.
        `indent` -- the integer number of spaces to indent by.
        `width`  -- the maximum width of formatted text (including indent).
    """
    width = width - indent
    out = []
    stack = [word for word in text.replace("\n", " ").split(" ") if word]
    while stack:
        line = ""
        while stack:
            if len(line) + len(" " + stack[0]) > width: break
            if line: line += " "
            line += stack.pop(0)
        out.append(" "*indent + line)
    return "\n".join(out)

if len(sys.argv) != 2:
    print "Error: No input file"
    exit()

f=open(sys.argv[1], 'r')

df = f.read().split("\n")
strin = ""
name = ""
names = []
tweets = []
for l in df:
    match = re.search( "<(\w*)> *([\w\W]*)", l)
    if match:
         names.append(name)
         tweets.append(strin)
         name = match.group(1)
         strin = match.group(2)

    else:
         strin = strin + " " + l.strip()

# All the names are stored in an array called names, and the tweets in an array called tweets
# You cay customize the output the way you like. This method was the best for me

print "                                        TWITTER FEED"
print "                                        Last update: " + strftime("%H:%M:%S")
print "                                       ================================================="
for i in range(1,12):
    ff = format( tweets[i], 50, 100 )
    print "                                        " + names[i] + ":"
    print ff
    print ""

 

The final Conky output looks like (blurred for privacy):

Posted in Linux
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Video4Linux and Github

Aug14
2011
Leave a Comment Written by Gavin

Recently I decided to try using Github to save my code.  I’ve used Subversion for a little while and before that I never used any kind of code backup software.  So far I’m liking it, I have one project up on it.

I’ve been trying to experiment with Video4Linux.  I just bought a new web camera that is plug-n-play and works on linux.  So I tried to find some code that lets me get the webcamera data.  I found one example that is provided by Video4Linux so I modified it and encapsulated it into a C++ class file.  The class allows you to grab the webcam data in either YUV or RGB format, and then process the data however you want. I created an example that grabs the data and then prints out a series of bitmap images.

If you are using git, you can type the following to download the code.

git clone git://github.com/rabidgeek/linuxWebcam

Or if you do not use git and want a direct download, click the following

Download zip
Download tar

Posted in Uncategorized
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Applets are up

Aug10
2011
2 Comments Written by Gavin

If you didn’t know. I used to run www.physics-lab.net, but I stopped maintaining that site some time ago. I have now put most of the applets I had on that website on this website. So feel free to play with them. Use the above menu or the menu to the right to navigate to the different applets.

Posted in Uncategorized
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

New Theme

Aug10
2011
Written by Gavin

I think I finally settled on a new theme for my website, so I think this is official.

Also, here’s Schrodinger’s equation for no apparent reason.

(1)   \begin{equation*} \left ( -\frac{\hbar^2}{2m} \nabla^2 + V(\vec r) \right ) \psi(\vec r) = E \psi(\vec r)  \end{equation*}

Equation 1 is Schrodinger’s equation

Posted in Uncategorized
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Drupal Sucks

Aug09
2011
Written by Gavin

I tried Drupal, twice…it crashed both times. So I’m back to my faithful WordPress.

Posted in Uncategorized
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Pages

  • Bio
  • Applets
    • Graphing Calculator
    • Electric Fields
    • Fourier Series
    • Motion
    • Oscillations
    • Pendulum
    • Projectile Motion
    • Snell’s Law
    • Taylor Series
    • Waves
  • Projects
    • Android
    • Linux
      • Linux Web Camera Class
    • Mathematics
    • Other
      • Mesh Triangulation
  • Contact

My Links

  • My Github

Blogroll

  • Raspberry Pi

Categories

  • C++
  • Linux
  • Math
  • Uncategorized
© 2004 by Rabid Geek and Gavin Lobo. All rights reserved

EvoLve theme by Theme4Press  •  Powered by WordPress Rabid Geek