Page 2 of 3

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

Posted: Wed Jun 02, 2021 8:53 pm
by Ruonan
Hello Yvan,

I tried to use the "cs_post_stress_tangential" function for calculating time-averaged wall shear stress on the fly. But unfortunately, without success.

The codes are shown below. When I compile them, some warnings occur but without error. I suppose there are some mistakes in the codes, but I cannot fine them. If you could check for me that will be much appreciated.

Code: Select all

static void
_boundary_shear_stress(const void  *input,
                       cs_real_3_t *vals)
{
  const int location_id = CS_MESH_LOCATION_BOUNDARY_FACES;
  const cs_lnum_t n_elts = cs_mesh_location_get_n_elts(location_id)[0];

  cs_post_stress_tangential(n_elts, NULL, vals);
}

void
cs_user_time_moments(void)
{
  {
    const char *sum_comp_name[] = {"shear_stress_mean", "shear_stress_variance"};
    cs_time_moment_type_t m_type[] = {CS_TIME_MOMENT_MEAN,
                                      CS_TIME_MOMENT_VARIANCE};

    for (int i = 0; i < 2; i++) {
      cs_time_moment_define_by_func(sum_comp_name[i],
                                    CS_MESH_LOCATION_BOUNDARY_FACES,
                                    3,                      /* field dimension */
                                    _boundary_shear_stress, /* data_func */
                                    NULL,                   /* data_input */
                                    NULL,                   /* w_data_func */
                                    NULL,                   /* w_data_input */
                                    m_type[i],
                                    106841,                      /* nt_start */
                                    -1,                     /* t_start */
                                    CS_TIME_MOMENT_RESTART_AUTO,
                                    NULL);
    }
  }

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

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

}
When I put the codes in the subroutine and ran the case, it crashed with the error shown below. I checked the setup.log file, the shear_stress_mean and shear_stress_variance, which I defined in the subroutine, seem included correctly in the "post_vis" and "Temporal moments" areas. So I don't know what caused the error.
** WALL DISTANCE
-------------

Min distance = 0.16443E-03 Max distance = 0.76789E-02

SIGSEGV signal (forbidden memory area access) intercepted!

Call stack:
1: 0x7f18bda14750 <cs_post_stress_tangential+0x120> (libsaturne-7.1.so)
2: 0x7f18bda55654 <cs_time_moment_update_all+0x6c4> (libsaturne-7.1.so)
3: 0x7f18bd94e087 <caltri_+0x1d74> (libsaturne-7.1.so)
4: 0x7f18bea2f8e0 <main+0x6f0> (libcs_solver-7.1.so)
5: 0x7f18bcd46b97 <__libc_start_main+0xe7> (libc.so.6)
6: 0x55b7f0e31fca <_start+0x2a> (cs_solver)
End of stack
The subroutine, xml, mesh and log files are attached. Thank you very much for helping me.

Best regards,
Ruonan

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

Posted: Wed Jun 02, 2021 8:54 pm
by Ruonan
Following the last post.

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

Posted: Thu Jun 03, 2021 4:25 pm
by Yvan Fournier
Hello,

The computation of the shear stress may require the activation of some intermediate arrays. This can be done in several ways, but the simplest one is to activate the postprocessing of the (instantaneous) boundary stress or shear stress using the GUI. Is this dne on your side ? If not, can you try again after activating this ?

Regards,

Yvan

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

Posted: Thu Jun 03, 2021 5:03 pm
by Ruonan
Hi Yvan,

Thanks for your reply. I double-checked, when I ran the case, I activated the stress options in the GUI, as shown in the figure below.
surface solution control.png
Also, I confirmed from other cases (which I can run smoothly), that when I ticked the stress boxes in the GUI, I can have the instantaneous shear stress values in the results. So I suppose the error isn't come from here?

Look forward to your further guidance.

Many thanks,
Ruonan

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

Posted: Fri Jun 04, 2021 12:27 am
by Yvan Fournier
Hello,

Running you code, I see that the "cs_post_stress_tangential" utility function does not handle "default" selections where when "b_face_ids" is NULL, it is assumed that matching values are implicitely "0, 1, 2, ... n_faces-1".

This is what causes the crash. So we should improve that function, but in the meantime, you can simply create a temporary b_face_ids array to pass to "cs_post_stress_tangential" instead of NULL.

Best regards,

Yvan

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

Posted: Sun Jun 06, 2021 6:43 pm
by Ruonan
Hello Yvan,

Thank you very much for pointing out the problem. I checked the examples related to time moment. In example 6, it writes "pass a simple call id as the input", which seems related to my problem. It seems something like "static char sum_comp_input ..." is needed. But due to my inexperience in programming, I cannot really understand the codes, and cannot get working codes by following this example.

Could you please suggest to me more details, on how to achieve you said in the last post: "create a temporary b_face_ids array to pass to 'cs_post_stress_tangential' instead of NULL" in the codes?

The subroutine is attached. Sorry for my inexperience.

Many thanks,
Ruonan

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

Posted: Mon Jun 07, 2021 8:20 pm
by Yvan Fournier
Hello,

I did a quick adaptation of your user file. This should be enough. I'll let you compare to the original file so you can learn for another time.

Best regards,

Yvan

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

Posted: Mon Jun 07, 2021 10:55 pm
by Ruonan
Hi Yvan,

Thank you so much for helping me. I can see your modification of the codes and learned from it. However, when I run the codes, it crashed with the same error as before.
SIGSEGV signal (forbidden memory area access) intercepted!

Call stack:
1: 0x7f3cc7ba0750 <cs_post_stress_tangential+0x120> (libsaturne-7.1.so)
2: 0x55b8811c2075 <+0x1075> (cs_solver)
3: 0x7f3cc7be1654 <cs_time_moment_update_all+0x6c4> (libsaturne-7.1.so)
4: 0x7f3cc7ada087 <caltri_+0x1d74> (libsaturne-7.1.so)
5: 0x7f3cc8bbb8e0 <main+0x6f0> (libcs_solver-7.1.so)
6: 0x7f3cc764fbf7 <__libc_start_main+0xe7> (libc.so.6)
7: 0x55b8811c1c0a <_start+0x2a> (cs_solver)
End of stack
Could you please try it on your side? The related files are attached. Sorry to bother you and thank you very much! Look forward to fixing this problem and getting time-averaged shear stress values calculated on the fly.

Best regards,
Ruonan

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

Posted: Mon Jun 07, 2021 11:00 pm
by Ruonan
The error message is in the log file. I use version 7.1-alpha from GitHub master. Thank you Yvan.

Best regards,
Ruonan

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

Posted: Tue Jun 08, 2021 12:51 am
by Yvan Fournier
Hello,

Sorry, I forgot to actually use the allocated array in place of NULL in the modified file...

The new attached version works (I tested it this time).

Best regards,

Yvan