Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Computational physics

  1. Oct 28, 2005 #1
    Perhaps this isn't in the right section, although I couldn't think of a better one. If I wanted to start working on computer simulations, what language and packages should I pursue? I know the blog highlighted Python, but after a point, it has its limits. I was thinking C++ or Java, as I already know how to program in both.

    What graphics packages are good for this and easy to learn?
  2. jcsd
  3. Oct 28, 2005 #2
    For really simple graphing of 2-D plots and simple syantax I would go with true basic. YOu can spend months trying to get graphics to work in c++.

    Most people code in fortran/ your favorite programming language, save the results and then plot them in a dedicated graphics program, ie pvwave/origin, not excel..
  4. Oct 28, 2005 #3
    The best bet is to write in Java (it's much cleaner than C++ although if your program requires utmost efficiency and speed of operation, then C++ might be a better alternative) and then save data to an output file. Use gnuplot or something like that to plot the data.
  5. Oct 28, 2005 #4
    C++ or Fortran if you are gonna be doing anything that involves some hardcore calculations- that is anything where you are crunching numbers for hours (or days maybe). Why? Much easier to optimize. Typically the language you are gonna use will be based on what you know and feel comfortable with and if anyone else in your research group is gonna have to use the program, you will have to use a language they use.

    For instance, in my research group, all the old codes are in FORTRAN 77 and all the older members of the groups still code in it. While the younger members code in Fortran 90. Unfortunately, there is no funding to update the old codes so it won't ever get done.

    So, unless you are just developing code for your own purposes, there will be other factors that will contribute which language you will use. But, really once you learn a programing language, you can quickly pick up other ones. You just have to learn the specific syntax- not that bad.
  6. Oct 28, 2005 #5
    depends on what you are doing...
    if you are doing purely numerical simulations My knoweldge is that people use
    fortran and for astrophys type sims theyre are packages out there in both fortran and C and they use particle methods...I think one of the pkgs is called Starlab.

    As for if your looking to do numerical simulatiosn with a 3D realtime graphics twist to it...to my knowledge fortran has no handle for this. and your best would be to
    either find a port for the numerical sims of fortran into C/C++ and use opengl
    ontop to display. Or just stick to C....
    There are pre coded numerical pacakges out there like LAPACK and opengl/sdl combo is a very easy way to start out with 3D graphics. Unless your only doing classical dynamics in which case i Suggest a precoded 3D engine like
    torque or halflife or ogre(its open src) or wildmagic....ogre is probably the best one cuz its open src. but I like wildmagics organization.
  7. Oct 28, 2005 #6


    User Avatar
    Science Advisor
    Gold Member

    You can get far with Python even, but after that latest fortran, C/C++ are the most used, Java gaining ground here and there (and in some applications performing quite admirably even efficiency wise). If would need to point a single language would say C++, the other stuff is tolerably easy to learn from thereon.
  8. Oct 28, 2005 #7
    It'd have to perform realtime simulations in 3D. Something as simple as a collision between two balls with variable coefficients of restitution to torque applied as a block slides off a table.
  9. Oct 29, 2005 #8
    Well, I have knowledge of C++, but no knowledge of the Win32 API. How big a leap would it be for me to go from that to programming, say, OGL graphics physics rendering?
  10. Oct 29, 2005 #9
    Assembly's the only real way to go. :)
  11. Oct 29, 2005 #10
    I've worked with 16-bit and 32-bit x86 assembly, and let me just say you deserve to be shot. :)
  12. Oct 31, 2005 #11
    You might wnat to look into IDL.
  13. Oct 31, 2005 #12


    User Avatar
    Gold Member

    I've done many physics simulations including Pool, reflections,ballistics,cloth... with C++. For the graphics I used OpenGL, it was very fast and easy - I was very happy with it. It took me about a month to learn OpenGL and I learned almost everything from NeHe's increadible site in gamedev. Look up NeHe in google to find the site.
    If you want to make good physics engines and simulations in C++ then you'll also need a lot of experience with classes.
  14. Oct 31, 2005 #13
    I'm learning 16-bit x86 assembly right now (and by extension, 32-bit assembly), and what I really like about it is that I have full control over what the machine is doing, not my compiler. In physics simulations especially, speed is a very important factor, and a human can often program something to be faster than a compiler can. For example, when a variable is declared temporarily in C, the compiler makes a location in memory and reads and writes to it. However, if you can get the same thing done using registers only, from what I understand, you can save a lot of time.
  15. Oct 31, 2005 #14
    sahinTC: you can use a precoded engine something like Magic or OGRE with ODE(opendynamics) Or newton's physics engine
    but if you choose to start from scratch i'd stay away from winAPI.

    www.sdllib.org[/url] or [PLAIN]www.libsdl.org(search [Broken] google for SDL) ...its got ports to both opengl and dx...in which case you'd prob. want OGL...
    the SDL tutorials are very easy to learn. and OPENGL itself is uber easy especially since your dealing iwth physics based rather than rendering-based.
    and for physics based code search for a researcher name Chris Hecker...his explanations maybe a bit raw(naive)...but its fairly easy if you already know classical mech. The plus is that his code examples are very sweet and well written. He's got a very sweet 3D block example...though ihave yet to replicate it because of some time scale error.
    Last edited by a moderator: May 2, 2017
  16. Nov 1, 2005 #15


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    This might be worth looking into if you want to use C++ for the computations and let VPython handle the realtime 3D-graphics. Certainly, you can use a fancier library or write your own OpenGL code (using, say, the NeHe site mentioned above). It depends on what is more important to you (computational physics or computer graphics) and how much time you have to invest in each component.

    One thing about Python/VPython that I like is that vector and matrix operations are implemented using the Numeric library, which helps process arrays quickly... not mention that Python is nicer to look at.

    My $0.02.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook