CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Main CFD Forum (
-   -   java vs c++ (

zxaar December 1, 2004 03:56

java vs c++
i need little advice. i am currently writing a solver in C++ (visual studio), things are okey, but the problem comes if i have to add few things to GUI. to be truthful i am not able to understand much of visual studio (or MFC). verytime i get into some doubt i have to search hard to get the answer. On the other hand i have very good experience of java (swing etc). so i was wondering to shift my code from C++ to java. it will be little effort but will save lot of time for writing visualisation of results. but i fear that java will be infierier to c++ when it comes to scientific computations. so i wished to ask what do other people suggest on this.

Jim_Park December 1, 2004 09:41

Re: java vs c++
Really don't know either language. But, if Java is interpreted and c++ is compiled, wouldn't the c++ code run much faster? That'd be what you want for the CFD part.

At least one big CFX user I know uses CFX for his CFD solutions, then uses Tecplot for the visualization. Thinking in a similar pattern, have you considered using c++ for your number crunching (to get the solutions quickly), then visualizating the results in a separate Java code?

The experts will quickly tell you (and me!) what's wrong with this idea.

Good luck.

Jonas Holdeman December 1, 2004 12:44

Re: java vs c++
I agree that Java makes GUIs easy, and it is portable between operating systems. Any GUI using Visual C++ is not going to be easily portable to Linux. I think that there are toolkits that can be used for GUIs in C++ that are portable. You write to an interface, and the toolkit provides the support for the particular operating system. Perhaps someone else can comment on this. If you are not committed to tight integration of the GUI and computational modules, you could use Java in your GUI and write an intermediate file to be used as input to your comp module. (I started to do this for a mesh generator but never finished it. I hope to go back to this some time in the future).

For the computational module, you may want to use sparse matrix methods, certainly if you are interested in handling large problems. There are C++ linear algebra routines available from Netlib. I don't recall anything in Java, but it has been a year since I looked. If you are interested in CFD computation rather than computer programming, you could save a lot of time by avoiding translating to Java and debugging.

zxaar December 1, 2004 18:43

Re: java vs c++
there is one more possiblity that i am thinking, that is to call c++ from java, but as i am thinking the speed shall not be that different as i store the mesh in graph and use pointers to access data. so my solver is quite fast(at least in c++), but if the same apporach is used , that is the moevement with refrence or pointers the speed will be similar in java too. my biggest fear is of memory leaks if the data size increases, the solver shall be able to run two million cells (provided good hardware) without memory leaks. though i agree garbage collector of java is robust but i still doubt this.

abot debugging problems, the only type of problems i get are logical probs (very hard to debug), i usually do not get syntax errors. Now logical errors could not come as most of the code is already running (c++). it is just that i wanted that my solver should plot residual curve as fluent does and i found my self groping for answers.

Steve December 2, 2004 05:34

Re: java vs c++
Rumour has it that STAR-CCM+ consists of a java GUI wrapped around a C++ solver.

Maciej Matyka December 2, 2004 08:49

Re: java vs c++
"But, if Java is interpreted"

It is not interpreted. Maciej

Tom December 2, 2004 09:22

Re: java vs c++
Actually it is (or what was) known as a threaded interpreted language - just like the old Forth programming language; i.e. it is "compiled" into psuedo code which is then interpreted into true (machine dependent) machine code at run time by the Java Virtual Machine. That is the psuedo code is interpreted.

This is much faster than a normal interpreted language but much slower than a true compiled language.

Maciej Matyka December 2, 2004 09:43

Re: java vs c++
ok, you are right here. Maciej

zxaar December 2, 2004 18:39

Re: java vs c++
we wrote a network visualisation tool , that is to represent a network of large (very large say , 50 000 nodes or more) on screen, in java. and from that experience i can say java is not so slow as it seems. anyway i have found something called V or vide for gui, that is better (but still i am not able to compile it to run ), but this is small do not require visual studio and can be portable., very good tool

Angen December 2, 2004 22:48

Re: java vs c++
There is at least one C++ tolkit for portable graphic user interfaces (Windows, Unix/Linux, Mac). The name is "Qt" and it is developed by Troltech of Norway. They have comercial versions, which in my opinion are at moderate prices (compared to some Windows toolkits) and possiblly they still have a free toolkit for noncommercial use under Linux. I used this toolkit in Windows platform and I liked it a lot.


zxaar December 3, 2004 03:05

Re: java vs c++
i have found the answer to my riddle, i guess best for me to use opengl, and by using this i can draw residual plots while iterating ..on the other hand opengl has lot of things to show grid and results on screen, animate them, or print them. using that will be a saving of lot of time.

All times are GMT -4. The time now is 00:48.