Advanced question about time moments

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

Advanced question about time moments

Post by zeph67 »

Hi,

I'm using v6.0.6 and I used the examples provided in cs_user_parameters-time_moments.c .

It works fine but I would like to import a user-defined variable to calculate t_start, so I can make t_start a function of some constant parameters of the flow (e.g. a given number of transit times...)

I define "transit_time" in cs_user_modules.f90, and so I'd like to access it from the C function that computes time moments.
I checked the documentation, grep'd the sources and did not find anything fully satisfactory.

I thought of a couple of possibilities, among which defining a structure like vcopt, with various parameters inside it. But I did not find where/how vcopt is created, and thus could not follow its example.
Or there's probably a way of calling this transit_time that I define in the Fortran API, from a C function.

Could someone help me ? If I missed an example in the source code, any keyword would become.

Thanks in advance, best regards,
Christophe
Yvan Fournier
Posts: 4077
Joined: Mon Feb 20, 2012 3:25 pm

Re: Advanced question about time moments

Post by Yvan Fournier »

Hello,

To do this cleanly, it would be necessary to add a function so as to change the starting time of a time moment which has not started yet. Not complicated, but requires an addition to the code.

A simpler solution available in the current version is to use cs_time_moment_reset(). You can define a time moment starting at t0, the reset its starting time to the current time as long as you did not reach the computed starting time, and stop resetting it when you reach the desired time.

Actually, looking at the code, it seems it sis also possible to define a start time far in the future, and start the moment at the desired time, simply by calling cs_time_moment_reset at that time, but I am not sure, so you would need to check this behaves as desired.

Best regards,

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

Re: Advanced question about time moments

Post by zeph67 »

Thanks, but cs_time_moment_reset() requires the ID of the time moment that has to be reset. If I call it from a Fortran routine, I don't even know the syntax to call the moment number. Furthermore, I want to start all my moments at the same time.

Is there no way that I pass a Fortran "user-defined global variable" to the C API ? That would be the simplest to me, but I did not find any exemple of it in the documentation or in the sources.

At this stage, it seems simpler to me to create property fields, and compute the time moments myself, e.g. in caltri.f90 or in tridim.f90.

Thanks,
Christophe
Yvan Fournier
Posts: 4077
Joined: Mon Feb 20, 2012 3:25 pm

Re: Advanced question about time moments

Post by Yvan Fournier »

Hello,

In the "setup.log" file, you should find the moment ids for a given setup. So you can identify and use them if you do not otherwise change the number of moments. This is not a "clean" solution, as it is not robust relative to setup changes, so I would not otherwise recommend it, but it could be a "quick and dirty" solution.

If you want to start all moments at the same time, things are actually simpler, because you only need to know the number of moments, and loop on all of those (ids 0 to n-1).

To pass a "user-defined global" variable from Fortran to C, you can use iso_c_bindings. In this case, add "bind(c, name=...)' to the variable name (and also add a matching "extern <type> <name>" entry in the calling C file). There is a user example for get_user_module_rwork, but the same logci can be used for simple variable types. You can fin more examples on the web.

Regards,

Yvan
Post Reply