Hello all,
I'm using CSv4.0.
I has a vey basic question i think. I would like to use the cs_user_postprocess.c instead of GUI. When I copy the source code cs_user_postprocess.c from /SRC/REFERENCE/ to /SRC, should I also looking for all the "local headers" in cs_user_postprocess.c and put it in the same repertory, i.e. /SRC? Is there another way simpler to use the souce code written in c++?
I hope that my question is clear.
Thanks in advance,
Best regard,
LE Hong Duc
How to add source code written in c++
Forum rules
Please read the forum usage recommendations before posting.
Please read the forum usage recommendations before posting.
Re: How to add source code written in c++
You just need to copy the .c file in the /SRC folder. The makefile ensures that all the headers will be found automatically and correctly. What you need to do is just modifier the .c file, unless you include new libraries.
The Code is written in C and Fortran. I am not sure that you can use c++ in a C code.
The Code is written in C and Fortran. I am not sure that you can use c++ in a C code.
Re: How to add source code written in c++
Has the status of C++ (or other languages) changed in recent years?
I see that it's possible to include a C++ file with suffix .cxx, for example, which the Python bits will recognize and on my setup get compiled by g++, but gcc will still be used as the linker and then crash.
Of course the missing part is just the C++ library, so one could test to show that there is no problem tying the two together, such as :
but there appears to be no corresponding option for adding libraries in the GUI or with the "code_saturne run" command.
I'm guessing that it could be possible to adjust the options with the initial ./configure command before compiling Code_Saturne at all, but while this is fine for small problems, could be difficult for dealing with existing configurations on clusters and such, I presume?
(Alternatively, of course there exist things to translate C++ into C code, but it would be nice to find a more natural solution if possible.)
I see that it's possible to include a C++ file with suffix .cxx, for example, which the Python bits will recognize and on my setup get compiled by g++, but gcc will still be used as the linker and then crash.
Of course the missing part is just the C++ library, so one could test to show that there is no problem tying the two together, such as :
Code: Select all
code_saturne compile --libs=-lstdc++
I'm guessing that it could be possible to adjust the options with the initial ./configure command before compiling Code_Saturne at all, but while this is fine for small problems, could be difficult for dealing with existing configurations on clusters and such, I presume?
(Alternatively, of course there exist things to translate C++ into C code, but it would be nice to find a more natural solution if possible.)
-
- Posts: 4080
- Joined: Mon Feb 20, 2012 3:25 pm
Re: How to add source code written in c++
Hello,
Actually the choice of the liner also depends on some optional libraries. For example, for a build using MED or another library requiring C++, the linker defaults to C++.
For other cases, you can try adding CS_LD=cxx or CS_LD=mpicxx to your configure line when installing. It should in theory do the trick.
To add things in cs_run, you can use the cs_user_scripts.py (copying it from DATA/REFERENCE to DATA to make activate it), and setting the domain.compile* fields (remove the "if domain.param == None" test).
Best regards,
Yvan
Actually the choice of the liner also depends on some optional libraries. For example, for a build using MED or another library requiring C++, the linker defaults to C++.
For other cases, you can try adding CS_LD=cxx or CS_LD=mpicxx to your configure line when installing. It should in theory do the trick.
To add things in cs_run, you can use the cs_user_scripts.py (copying it from DATA/REFERENCE to DATA to make activate it), and setting the domain.compile* fields (remove the "if domain.param == None" test).
Best regards,
Yvan
Re: How to add source code written in c++
Ah, interesting, thanks ! I can confirm that it works.
To say more precisely for those who may be interested, I was able to use C++ code without recompiling Code_Saturne -- first by using a ".cxx" suffix in the user routines in place of a ".c" suffix (for my test, cs_user_extra_operations.cxx), and copying cs_user_scripts.py as mentioned out of the REFERENCE folder into DATA/, then adding the line:
on line 161 of the script.
After that, the simulation runs without any problem, even from the GUI (though I didn't test it for anything terribly exotic yet ; one can always imagine ways to break the code...).
Presumably this is also the "correct" way if we would like to access existing libraries from the user routines?
To say more precisely for those who may be interested, I was able to use C++ code without recompiling Code_Saturne -- first by using a ".cxx" suffix in the user routines in place of a ".c" suffix (for my test, cs_user_extra_operations.cxx), and copying cs_user_scripts.py as mentioned out of the REFERENCE folder into DATA/, then adding the line:
Code: Select all
domain.compile_libs = '-lstdc++'
After that, the simulation runs without any problem, even from the GUI (though I didn't test it for anything terribly exotic yet ; one can always imagine ways to break the code...).
Presumably this is also the "correct" way if we would like to access existing libraries from the user routines?
-
- Posts: 4080
- Joined: Mon Feb 20, 2012 3:25 pm
Re: How to add source code written in c++
Hello,
Yes, this was designed so users can link to additional libraries (most commonly used for post-processing/data extraction but could also be used for fluid property libraries, advanced source term or boundary conditions, ...)
Best regards,
Yvan
Yes, this was designed so users can link to additional libraries (most commonly used for post-processing/data extraction but could also be used for fluid property libraries, advanced source term or boundary conditions, ...)
Best regards,
Yvan