Usage of cs_user_postprocess.c

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
konst
Posts: 30
Joined: Sun Sep 17, 2017 7:41 pm

Usage of cs_user_postprocess.c

Post by konst »

Good morning,
Could you help me with my problem. I am using Code_Saturne 5.2.
And I am trying to use cs_user_postprocess.c to define profiles.
It does not work even for very simple definition. I was adapting file EXAMPLES/cs_user_postprocess-profiles.c for my case. But it gives me error:

Code: Select all

cs_probe.c:573: Fatal error.

 Stop execution since the given cs_probe_set_t structure is empty.
 Please check your settings.
Here I put the main lines from my code:

Code: Select all

BEGIN_C_DECLS
void
cs_user_postprocess_writers(void)
{
  /* Set time plot file writer flush behavior defaults. */
  // /* ----------------------- */
    cs_post_define_writer(CS_POST_WRITER_PROFILES,  /* writer_id */
                        "",                       /* writer name */
                        "profiles",
                        "plot",                   /* format name */
                        "dat",                    /* format options */
                        FVM_WRITER_FIXED_MESH,
                        false,                    /* output_at_start */
                        true,                     /* output at end */
                        1,                       /* time step frequency */
                        -1.0);                    /* time value frequency */


}
void
cs_user_postprocess_probes(void)
{
    cs_coord_3_t  start = {0., 0.0, 0.0};
    cs_coord_3_t  end = {0., 4.0, 0.0};
    int  writer_ids[] = {CS_POST_WRITER_PROFILES};

    cs_probe_set_t  *pset =
       cs_probe_set_create_from_segment("Prof1", // name
                                       101,      // n_probes
                                       start,   // start coordinates
                                       end);    // end coordinates

    cs_probe_set_associate_writers(pset, 1, writer_ids);
}

void
cs_user_postprocess_values(const char            *mesh_name,
                           int                    mesh_id,
                           int                    cat_id,
                           cs_probe_set_t        *probes,
                           cs_lnum_t              n_cells,
                           cs_lnum_t              n_i_faces,
                           cs_lnum_t              n_b_faces,
                           cs_lnum_t              n_vertices,
                           const cs_lnum_t        cell_list[],
                           const cs_lnum_t        i_face_list[],
                           const cs_lnum_t        b_face_list[],
                           const cs_lnum_t        vertex_list[],
                           const cs_time_step_t  *ts)
{
  /* Output of k=1/2(R11+R22+R33) for the Rij-epsilon model
     ------------------------------------------------------ */
  if (cs_glob_turb_model->itytur == 3) {

    cs_real_t *s_cell;
    BFT_MALLOC(s_cell, n_cells, cs_real_t);

    if (cs_glob_turb_rans_model->irijco) {
      const cs_real_6_t *cvar_r = (const cs_real_6_t *)(CS_F_(rij)->val);
      for (cs_lnum_t i = 0; i < n_cells; i++) {
        cs_lnum_t cell_id = cell_list[i];
        s_cell[i] = 0.5* (  cvar_r[cell_id][0]
                          + cvar_r[cell_id][1]
                          + cvar_r[cell_id][2]);
      }
    }

    else {
      const cs_real_t *cvar_r11 = CS_F_(r11)->val;
      const cs_real_t *cvar_r22 = CS_F_(r22)->val;
      const cs_real_t *cvar_r33 = CS_F_(r33)->val;

      for (cs_lnum_t i = 0; i < n_cells; i++) {
        cs_lnum_t cell_id = cell_list[i];
        s_cell[i] = 0.5* (  cvar_r11[cell_id]
                          + cvar_r22[cell_id]
                          + cvar_r33[cell_id]);
      }
    }
    cs_post_write_probe_values(mesh_id,
                      CS_POST_WRITER_PROFILES,  /* writer id filter */
                      "turb energy",                  /* var_name */
                      1,                              /* var_dim */
                      CS_POST_TYPE_cs_real_t,         /* var_type */
                      0,                              /* parent location id */
                      NULL,                           /* default interpolation */
                      NULL,                           /* interpolation input */
                      s_cell,                         /* cel_vals */
                      ts);
    
    BFT_FREE(s_cell);
  }
}

void
cs_user_postprocess_activate(int     nt_max_abs,
                             int     nt_cur_abs,
                             double  t_cur_abs)
{

  if (nt_max_abs < 10) {
    int writer_id = CS_POST_WRITER_PROFILES;
    cs_post_activate_writer(writer_id, false);
  }
}
END_C_DECLS
In attached file you can find cs_user_postprocess.c.
Maybe I defined something in a wrong way?
Attachments
cs_user_postprocess_tmp1.c
(10.23 KiB) Downloaded 200 times
Yvan Fournier
Posts: 4080
Joined: Mon Feb 20, 2012 3:25 pm

Re: Usage of cs_user_postprocess.c

Post by Yvan Fournier »

Hello,

Judging by the error message, it would seem the given segment does not intersect the mesh.

Are you sure the segment coordinates match your mesh ?

Best regards,

Yvan
konst
Posts: 30
Joined: Sun Sep 17, 2017 7:41 pm

Re: Usage of cs_user_postprocess.c

Post by konst »

Thanks for answering,
I am pretty sure that coordinates ( (0.0, 0.0, 0.0) and (0.0, 4.0, 0.0)) is inside the mesh. My mesh size is x:[0; 0.5], y:[0; 4.0], z[0; 0.5].
box1Layer.med
(56.61 KiB) Downloaded 223 times
UPD: The same error when I trying to define some "bad" segment ( (10.0, 10.0, 10.0) and (10.0, 14.0, 10.0))
Yvan Fournier
Posts: 4080
Joined: Mon Feb 20, 2012 3:25 pm

Re: Usage of cs_user_postprocess.c

Post by Yvan Fournier »

Hello,

Since the segment seems to e just on the edge of the domain, it is possible that rounding issues come into play here. Could you test again with

Code: Select all

    cs_coord_3_t  start = {0.1e-6, 0.0, 0.0};
    cs_coord_3_t  end = {0.1e-6, 4.0, 0.0};
just to force the segment to be inside the mesh ?

Best regards,

Yvan
konst
Posts: 30
Joined: Sun Sep 17, 2017 7:41 pm

Re: Usage of cs_user_postprocess.c

Post by konst »

I've tried that values, and also these:

Code: Select all

    
    cs_coord_3_t  start = {0.1, 0.0, 0.1};
    cs_coord_3_t  end = {0.1, 1.1, 0.1};
but it does not help. Still same error:

Code: Select all

cs_probe.c:573: Fatal error.

 Stop execution since the given cs_probe_set_t structure is empty.
 Please check your settings.
My mesh is 1D maybe it could affect somehow?
Yvan Fournier
Posts: 4080
Joined: Mon Feb 20, 2012 3:25 pm

Re: Usage of cs_user_postprocess.c

Post by Yvan Fournier »

Hello,

Testing your mesh with development master (soon-to-be-released version 5.3) and an arbitrary setup, I reproduce your error, but only at the last time step. Output is correct at previous time steps.

The error is a bit subtle: in cs_user_postprocess_values you need to check the mesh_id, or simple add:

Code: Select all

if (probes == NULL) return;
at the beginning of that function. The crash occurs because the code tries to write your use data on the volume mesh, which is not of "probes" type.

I'll try to see how to add additional checks to avoid this sort of crash, but in the meantime this should work for you.

Regards,

Yvan
konst
Posts: 30
Joined: Sun Sep 17, 2017 7:41 pm

Re: Usage of cs_user_postprocess.c

Post by konst »

Thanks a lot, Yvan! That helps me :)

Best regards,
Konstantin
Post Reply