How to collect time-averaged values for boundary variables?

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Ruonan
Posts: 136
Joined: Mon Dec 14, 2020 11:38 am

How to collect time-averaged values for boundary variables?

Post by Ruonan »

Dear developers,

Please could you help me with this question?

I am doing LES in Code_Saturne 6.0.5 via GUI. For collecting time-averaged values of the variables, in GUI, I am using "Postprocessing-Time averages", as shown in the figure below.
Time averages for variables in fluid domain.png
But here, I can only select variables in "fluid domain", not on boundary. Now I want to collect time-averaged values on boundary, such as "Yplus, Tplus, Input_thermal flux" etc, as shown below. Could you suggest to me, which user subroutine should I use to achieve this?
Values on boundary.png
Best regards,
Ruonan
Yvan Fournier
Posts: 4074
Joined: Mon Feb 20, 2012 3:25 pm

Re: How to collect time-averaged values for boundary variables?

Post by Yvan Fournier »

Hello,

Yes, the handling of boundary fields in the GUI is still very limited, and needs to be rewritten/aligned with that of the volume fields.

But for the short term solution, you can check the examples in cs_user_parameters-time_moments.c.
There is one example for a boundary field which is a bit complex (with an evaluation callback function), but for simple fields which are already present (such as y+), you can check the examples with "cs_time_moment_define_by_field_ids".

Best regards,

Yvan
Ruonan
Posts: 136
Joined: Mon Dec 14, 2020 11:38 am

Re: How to collect time-averaged values for boundary variables?

Post by Ruonan »

Hello Yvan,

Thanks for your reply. I tried but without success, could you please help me to check.

I started with a simple test, calculating time-averaged value of velocity, which is available via GUI. First, I set up in "GUI-Postprocessing-Time averages", and got the time-averaged values successfully.

Then I tried to use the user subroutine "cs_user_parameters.c". I referred to the example from "cs_user_parameters-time_moments.c", but without success. I didn't get the time-averaged results in "postprocessing" folder. But in the setup.log file, I can find "U_mean", what I added in the subroutine. So I am confused about what I'm doing wrong.
2.png
1.png
I attached the mesh, xml file, user subroutine and setup.log below. Thank you very much for your help.

Best regards,
Ruonan
Attachments
cs_user_parameters.c
user subroutine
(4.56 KiB) Downloaded 108 times
Ruonan
Posts: 136
Joined: Mon Dec 14, 2020 11:38 am

Re: How to collect time-averaged values for boundary variables?

Post by Ruonan »

following the last post
Attachments
sealed rotor stator cavity for wmles 20210323.cgns
mesh
(3.05 MiB) Downloaded 99 times
setup.log
(28.34 KiB) Downloaded 95 times
les_test_sealed_cavity.xml
(10.5 KiB) Downloaded 104 times
Yvan Fournier
Posts: 4074
Joined: Mon Feb 20, 2012 3:25 pm

Re: How to collect time-averaged values for boundary variables?

Post by Yvan Fournier »

Hello,

You probably defined/activated the time averages but did not activate their postprocessing output (you can check that the value of the "post_vis" flag for U_mean does not appear in the setup.log).

So you need to add something like this:

Code: Select all

 
 cs_field_set_key_int_bits(cs_field_by_name("U_mean"),
                           cs_field_key_id("post_vis"),
                           CS_POST_ON_LOCATION);

Best regards,

Yvan

Remark: you should also remove the #pragma week line in your user subroutine. It is there to help ensure user-edited files have priority over the (empty) reference version, so if you leave the #pragma from the reference version, you lose that aspect.
Ruonan
Posts: 136
Joined: Mon Dec 14, 2020 11:38 am

Re: How to collect time-averaged values for boundary variables?

Post by Ruonan »

Hello Yvan,

Thank you very much. Following your kind guidance, I succeed in calculating the time-averaged velocity values. Here are the codes added in cs_user_parameters.c:

Code: Select all

void
cs_user_time_moments(void)
{
  {
    int moment_f_id[] = {CS_F_(vel)->id};
    int moment_c_id[] = {-1};
    int n_fields = 1;
    cs_time_moment_define_by_field_ids("U_mean",
                                       n_fields,
                                       moment_f_id,
                                       moment_c_id,
                                       CS_TIME_MOMENT_MEAN,
                                       106841, /* nt_start */
                                       -1,   /* t_start */
                                       CS_TIME_MOMENT_RESTART_AUTO,
                                       NULL);
  }

cs_field_set_key_int_bits(cs_field_by_name("U_mean"),
                          cs_field_key_id("post_vis"),
                          CS_POST_ON_LOCATION);

}
Then I moved to the next step, trying to get the time-averaged values for variables on boundary faces. My final aim is to get time-averaged thermal flux values for heat transfer prediction. As I didn't find "thermal flux" in "post_vis" in setup.log, I suppose thermal flux is calculated by yplus, tplus, temperature, etc, not calculated directly by the solver.

I first tried to get the time-averaged yplus. In the codes above, I changed CS_F_(vel) to CS_F_(yplus). As I found the variable "yplus" in cs_field_pointer_id_t, I think it should work. But an error occurred in the initialization:
===============================================================

CALCULATION PREPARATION
=======================


===========================================================



SIGSEGV signal (forbidden memory area access) intercepted!

Call stack:
1: 0x562ec30c90b8 <cs_user_time_moments+0x48> (cs_solver)
2: 0x7f61f50471f9 <initi1_+0x156> (libsaturne-7.1.so)
3: 0x7f61f5fe9876 <main+0x5c6> (libcs_solver-7.1.so)
4: 0x7f61f4a74b97 <__libc_start_main+0xe7> (libc.so.6)
5: 0x562ec30c8bba <_start+0x2a> (cs_solver)
End of stack
Please could you suggest to me how to deal with this error? Or how to get the time-averaged values on boundary faces, maybe in another way?

The subroutine, listing, xml are attached. Actually if I get time-averaged yplus, I think I can get thermal flux, calculating by hand, using wall functions and Fourier's law. Thank you so much!

Best regards,
Ruonan
Attachments
les_test_sealed_cavity.xml
(10.47 KiB) Downloaded 113 times
listing.log
(2.44 KiB) Downloaded 101 times
cs_user_parameters.c
(4.69 KiB) Downloaded 102 times
Yvan Fournier
Posts: 4074
Joined: Mon Feb 20, 2012 3:25 pm

Re: How to collect time-averaged values for boundary variables?

Post by Yvan Fournier »

Hello,

Yes, thermal flux is computed on the fly, using the cs_post_boundary_flux function.

You can use that same function with time moments, but instead of using cs_time_moment_define_by_field_ids, you need to use cs_time_moment_define_by_func. There is already an example for the boundary thermal flux, which you can find here: https://www.code-saturne.org/cms/sites/ ... eters.html (search for "Example 5").

Best regards,

Yvan
Ruonan
Posts: 136
Joined: Mon Dec 14, 2020 11:38 am

Re: How to collect time-averaged values for boundary variables?

Post by Ruonan »

Hi Yvan,

Thank you very much. The example 5 is exactly what I was looking for. I have succeeded in getting the time-averaged thermal flux values.

Please I also want to calculate the time-averaged wall shear stress values on boundary faces. But I didn't find a related example. Could you suggest to me how to achieve this?

Alternatively (if it's easier) maybe you could also suggest to me how to get the time-averaged yplus values. Then I can calculate wall shear stress by yplus.

Many thanks,
Ruonan
Yvan Fournier
Posts: 4074
Joined: Mon Feb 20, 2012 3:25 pm

Re: How to collect time-averaged values for boundary variables?

Post by Yvan Fournier »

Hello,

Y+ is stored as a field (located on boundary faces), which may be defined based on various other options. Check your setup.log to see if it is already available. Otherwise, I think you can force its creation by activating its postprocessing output in boundary outputs in the GUI. There is a way to force its existence independently from the GUI or postprocessing; bu I do not remember the syntax (it should be in the user documentation, though I am not 100%sure).

Otherwise, the wall shear stress can be computed on the fly using the "cs_post_stress_tangential" function, similarly to they way "cs_post_boundary_flux" is used for the thermal flux (except is is a 3d vector field instead of a scalar field). Check cs_post_util.h for the exact function description. So you should pretty easily be able to adapt the same example for this.

Best regards,

Yvan
Ruonan
Posts: 136
Joined: Mon Dec 14, 2020 11:38 am

Re: How to collect time-averaged values for boundary variables?

Post by Ruonan »

Hello Yvan,

Thanks a lot for your reply. Yes, I have the yplus values in my results, but it seems not easy to compute the time-averaged yplus values on the fly. The "cs_post_stress_tangential" function seems what I want. I will definitely try this function.

Best regards,
Ruonan
Post Reply