Learn Computational Physics: Best Language & Packages for Computer Simulations

In summary: I mean I've read the wikipedia article and I'm making a list of books to buy). In summary, if you want to do graphics-based physics simulations in C++, you'll need a lot of experience with classes.
  • #1
SahinTC
19
0
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?
 
Physics news on Phys.org
  • #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..
 
  • #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.
 
  • #4
C++ or Fortran if you are going to 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 going to use will be based on what you know and feel comfortable with and if anyone else in your research group is going to 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.
 
  • #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 because its open src. but I like wildmagics organization.
 
  • #6
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.
 
  • #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.
 
  • #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?
 
  • #9
Assembly's the only real way to go. :)
 
  • #10
I've worked with 16-bit and 32-bit x86 assembly, and let me just say you deserve to be shot. :)
 
  • #11
You might wnat to look into IDL.
 
  • #12
SahinTC said:
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.
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.
 
  • #13
SahinTC said:
I've worked with 16-bit and 32-bit x86 assembly, and let me just say you deserve to be shot. :)
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.
 
  • #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 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:
  • #15
http://www.boost.org/libs/python/doc/
a C++ library which enables seamless interoperability between C++ and the Python programming language. The new version has been rewritten from the ground up, with a more convenient and flexible interface, and many new capabilities, including support for:
References and Pointers
Globally Registered Type Coercions
Automatic Cross-Module Type Conversions
Efficient Function Overloading
C++ to Python Exception Translation
Default Arguments
Keyword Arguments
Manipulating Python objects in C++
Exporting C++ Iterators as Python Iterators
Documentation Strings
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.
 

1. What is computational physics?

Computational physics is the use of computer algorithms and simulations to solve complex physical problems in areas such as mechanics, electromagnetism, thermodynamics, and quantum mechanics.

2. Why is computational physics important?

Computational physics allows us to model and understand physical systems that are too complex or expensive to study through traditional experiments. It also helps in making predictions and designing new technologies.

3. What is the best programming language for computational physics?

There is no single "best" programming language for computational physics, as different languages have their own strengths and weaknesses. However, some commonly used languages in this field include Python, C++, and Fortran.

4. What are some popular packages for computer simulations in computational physics?

Some popular packages for computer simulations in computational physics include Numpy, Scipy, and Matplotlib in Python, GSL (GNU Scientific Library) in C++, and LAPACK (Linear Algebra Package) in Fortran.

5. Is it necessary to have a physics background to learn computational physics?

Having a basic understanding of physics concepts is helpful but not necessary to learn computational physics. However, a strong background in mathematics and programming is essential for success in this field.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • STEM Academic Advising
Replies
3
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
10
Views
3K
  • Quantum Physics
Replies
1
Views
774
  • STEM Academic Advising
Replies
9
Views
1K
  • Other Physics Topics
Replies
5
Views
2K
  • STEM Career Guidance
Replies
3
Views
2K
  • Programming and Computer Science
Replies
11
Views
1K
  • STEM Career Guidance
Replies
22
Views
3K
Back
Top