Defined postprocess writer does not work

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
Mohammad
Posts: 114
Joined: Thu Oct 25, 2018 12:18 pm

Defined postprocess writer does not work

Post by Mohammad »

Hello,

I defined a new writer which I want it to write my desired fields, for example, I want it to only write the velocity field every 10 iterations.
In cs_user_postprocess.c and under cs_user_postprocess_writers() I added:

Code: Select all

  cs_post_define_writer(1,       /* writer_id */
                        "velocity_writer",                    /* writer name */
                        "my_field",             /* directory name */
                        "ensight",               /* format_name  EnSight Gold*/
                        "text",                           /* format_options */
                        FVM_WRITER_FIXED_MESH,
                        false,                        /* output_at_start */
                        false,                         /* output_at_end */
                        10,                           /* frequency_n */
                        -1.0);
Then, in the same file under cs_user_postprocess_values() I added these codes:

Code: Select all

    const cs_field_t *f = CS_F_(vel);
      cs_post_write_var(mesh_id,
                        1,  /* writer id filter */
                        "vel",                        /* var_name */
                        3,                              /* var_dim */
                        true,                           /* interlace, */
                        true,                           /* use_parent */
                        CS_POST_TYPE_cs_real_t,         /* var_type */
                        f->val,                         /* cel_vals */
                        NULL,                           /* i_face_vals */
                        NULL,                           /* b_face_vals */
                        ts);
But after running the code_saturne, it does not output anything!

I used call post_activate_writer(1, .true.) in cs_user_initialization.f90, too but didn't help.

Regards,
Mohammad
Last edited by Mohammad on Fri Dec 11, 2020 2:42 pm, edited 1 time in total.
Yvan Fournier
Posts: 4077
Joined: Mon Feb 20, 2012 3:25 pm

Re: Defined postprocess writer does not work

Post by Yvan Fournier »

Hello,

Did you define (or redefine) meshes to attach them to the new writer ? If not, you also need this step to fully define the writer/mesh combination.

Regards,

Yvan
Mohammad
Posts: 114
Joined: Thu Oct 25, 2018 12:18 pm

Re: Defined postprocess writer does not work

Post by Mohammad »

Hello,

Thanks a lot. The problem solved.
But the new writer, writes all of the fields just like the default writer. I want it to only write a few fields, and also I want the default writer to write all of the fields. I think it is related to CS_POST_WRITER_ALL_ASSOCIATED.
Is there anyway?

Regards,
Mohammad
Yvan Fournier
Posts: 4077
Joined: Mon Feb 20, 2012 3:25 pm

Re: Defined postprocess writer does not work

Post by Yvan Fournier »

Hello,

You need to set the "automatic variables output" argument to false in cs_post_define_*_mesh.

Regards,

Yvan
Mohammad
Posts: 114
Joined: Thu Oct 25, 2018 12:18 pm

Re: Defined postprocess writer does not work

Post by Mohammad »

Hello,

Thanks again!

I added the function to cs_user_postprocess.c as below, but still writes the main variables like pressure, mpi_rank_id, courantNb, turbvisc and, total_pressure.

Code: Select all

cs_user_postprocess_meshes(void)
{
  {
    const int writer_ids[] = {1};
    cs_post_define_volume_mesh(CS_POST_MESH_VOLUME,
                               "MESH_NAME",
                               "all[]",
                               false, /* if true, add group information if present */
                               false, /* automatic output of main variables  */
                               1,
                               writer_ids);
  }

  {
    cs_post_mesh_attach_writer(CS_POST_MESH_VOLUME, 1);
  }
}
Update:
The problem solved by using cs_post_get_free_mesh_id(); instead of CS_POST_MESH_VOLUME.
But I don't know why!

Regards,
Mohammad
Yvan Fournier
Posts: 4077
Joined: Mon Feb 20, 2012 3:25 pm

Re: Defined postprocess writer does not work

Post by Yvan Fournier »

Hello,

Actually, the main settings to determine whether each variable is written or not (post_vis field keyword, except for mpi_rank_id which currently has no parameter) refer to the main volume mesh, and the "automatic" determines whether an additional mesh should behave as the same "category" as a reference (main volume mesh, main boundary mesh, ...), so "automatic" is ignored for the main volume mesh. Sorry, I had forgotten about that...

Best regards,

Yvan
Mohammad
Posts: 114
Joined: Thu Oct 25, 2018 12:18 pm

Re: Defined postprocess writer does not work

Post by Mohammad »

Hello,

Thank you very much dear Yvan.

Best Regards,
Mohammad
Post Reply