How to add a new subroutine ?

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
zeph67
Posts: 52
Joined: Tue Oct 23, 2012 5:54 pm

How to add a new subroutine ?

Post by zeph67 »

Hello,

I'm wondering about a proper way to add an own subroutine, using just a few variables. It is a very simple routine, just performing a change in coordinates.

I tried adding a file containing it, I tried adding it in a cs_user_*.f90 file. None works.

So my question is just ; what is the proper way to perform it ?

Thanks a lot in advance.

PS : I'm talking about version 3.0.0
Yvan Fournier
Posts: 4081
Joined: Mon Feb 20, 2012 3:25 pm

Re: How to add a new subroutine ?

Post by Yvan Fournier »

Hello,

Normally, you should be able to add as many user subroutines as you want, but be careful where you call them from. For example, modifying coordinates after other geometric values have been computed and not updating them is a very bad idea.

What existing subroutine did you try to call your subroutine from ?

Regards,

Yvan
zeph67
Posts: 52
Joined: Tue Oct 23, 2012 5:54 pm

Re: How to add a new subroutine ?

Post by zeph67 »

I called the "new" routines from cs_user_initialization. But in fact I just encountered a stupid calling bug ; everything is fine now.

My routines don't modify coordinates (my first message, above, was clumsy) ; they just perform some frame-transformation for vectors and tensors. For instance, in cs_user_initialization, some of my starting data are expressed in a cylindrical frame, and I simply needed to "translate" them to the cartesian frame where Code_Saturne works.
I also intend to use these routines in cs_user_postprocess_var, in order to post-process e.g. velocities in the cylindrical frame, even though I could do this outside Code_Saturne, of course.

Thanks.
Yvan Fournier
Posts: 4081
Joined: Mon Feb 20, 2012 3:25 pm

Re: How to add a new subroutine ?

Post by Yvan Fournier »

Hello,

OK, great.

I forgot to mention that if you (or anyone else following this forum) ever need to define your own Fortran 95 modules, it is recommended to put them in a file named cs_user_modules.f90, because a file with that name will be compiled first, so that other files using those modules can be compiled correctly.

Regards,

Yvan
zeph67
Posts: 52
Joined: Tue Oct 23, 2012 5:54 pm

Re: How to add a new subroutine ?

Post by zeph67 »

Thanks for the suggestion.

I already use cs_user_modules.f90 but rather for common variable declarations and (de)allocations, which is its first purpose. Let's reckon that it is far more user-friendly (and readable) than the old RTUSER and ITUSER arrays.
Post Reply