Help with my first scientific computational project
Hi, I'm about to enter my third academic year as a Physics student and as part of this year I will be undertaking a project. The project I've chosen is based on the Gaia hypothesis and more specifically modeling Daisyworld. I will need to compute all the necessary equations and create a visualization of Albedo, daisy positions and Temperature of the model Earth. Once I have this sorted I would like to add in other variables such as plagues, different types of daisy and perhaps even predators/ herbivores to change the growth rates and patterns of the daisies.
Eventually I would like to achieve something like these with the display of the second .mpg but with the interface similar to that of the first java aplet:
http://zool33.uni-graz.at/schmickl/models/daisyworld.html
http://www.pik-potsdam.de/~bloh/mpeg/dw.mpg
I am a bit of a novice when it comes to programming but I'm a fast learner and have done well in my previous computing modules in my course (where basic fortran 90 was used). I rushed in and started learning c++ for this without really looking at other options but the more I look into it, it seems as if C/ Objective C might be the best language to use. Should I try and create a cocoa application for this? Also what is the best way to achieve some nice looking visual effects?
I really appreciate any help you can give on this topic.
thanks,
Jon



Re: Help with my first scientific computational project
Regarding your choice of Objective-C vs C++ ...
The advantage to Objective-C is that the dynamic design of methods makes using a great/easy framework like Cocoa an option, which drastically reduces the difficulty of writing your program's GUI.
The disadvantage to Objective-C is that calling a method has a significant speed-cost overhead versus C++ methods because it has to look up exactly what function to call for the message/selector given to it (flexibility at the slight cost to speed). That said, if your object won't be doing a massive amount of method calling, than this may not be a concern. An example of where it can matter would be if you would plan to call several methods per pixel in a huge image (I did this once), resulting in millions of method calls per image.
If you have an object that's supposed to just do a ton of math, and in doing so will use a ton of method calls, Objective-C will not perform as well as C++. I bring this up because I have no idea how computationally intensive your program will be.
But one option I don't think enough people realize is Objective-C++, which allows you to use both languages in the same source code files (file extension is ".mm"). You can't use C++ objects to call an Objective-C methods (and vice versa), but you can exchange data between the two types of objects using primitives like int, char, float, etc, or vanilla-C structs. Then you can get away with using C++ objects to do the intense math parts, and Objective-C for the parts that require flexibility (like the application's interface).
The disadvantage to Objective-C++ is that it makes compile-time slower (each .mm file is compiled twice), and there are sometimes occasional quirks you have to accommodate to keep the languages from conflicting by using extra preprocessor statements "#ifdef __cplusplus" or "#ifdef __OBJC__". (A very small price to pay for the mixing of two useful languages).
Using a C++ backend with an Objective-C frontend is a viable 3rd option. Not saying you should use it (or not), just throwing the idea out there.
RE: Help with my first scientific computational project
There are reasons for both c++ and objective-c.
c++ can get pretty technical with abstract base classes, classes derived from more than one base class (multiple inheritance), interleaving of virtual and non-virtual functions in the same scope. Most c++ implementations that I have seen do not go to the limits of c++ in design. Cool stuff though.
Objective-C is less technical and easier to use. Its method name (argument naming) syntax is easier to read than c++'s prefix notation. In summary (after not stating a theory or proof (I am allowed to do that right?)) Obj-C is the better language of the two.
If you learned fortran then I would suggest (rapidly proceeding to!) learning ANSI-C. After you get the hang of that then try a little Obj-C and C++ and see for yourself which direction you want to go in.
But, it sounds like for your project you may need mostly ANSI-C and OpenGL, which are both regular C. You may find some very specific library for your exact project that is written in either C++ or Obj-C and then that would probably determine which one you end up with. Or maybe not.
P.S. - method calling on C++ v.s. Obj-C : don't worry too much about it. Once you break inlining with virtual functions or method calls then a lot of optimizations go out the window anyways. Best to stick with regular ANSI-C in either language (c++ or obj-c) when doing heavy computes.
Re: Help with my first scientific computational project
My two cents, FWIW.
Follow the Model-View-Controller (M-V-C) philosophy and write your View and Controller in Objective-C++ and your Model in C++. Putting these together is not a problem in Xcode. C++ is especially good for scientific work because it has the STL (BLAS-compatible if you do it right) and you need not worry about vector and matrix math, etc. Also, use threads if possible, esp. for SIMD computations.
Michael P. McLaughlin
Sorry for the delay but I'd
Sorry for the delay but I'd just like to say thanks a lot for all the help. I've decided to do it in c/c++ to get the basic model working then eventually I'll get some kind of openGL working.
Thanks again,
Jon