Real time residuals monitoring / convergence monitoring

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
mhassab

Real time residuals monitoring / convergence monitoring

Post by mhassab »

Hello All,

I was wondering if any of you got the chance to find a way to monitor the solver residuals in real time while the solver is running, monitoring of monitor points with iterations while solver is running. How do you monitor convergence while the solver is running.

Is there an add on to run to enable that ?

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

Re: Real time residuals monitoring / convergence monitoring

Post by Yvan Fournier »

Hello,

For residuals, I'm not sure about any other solution than parsing the "listing" file.

For probes, the output files are written as the computation progresses, but they might not always be "flushed" by default.

You can use the cs_user_parameters.f90 (usipse routine) to set the "tplflw" option, which determines the time plot flush frequency, in user-elapsed seconds (updating too often might slow down the the computation a bit).

To force flushing of the "listing" file, use the control_file (check the user guide for syntax).

We should add plots for residuals in the future, but I don't think its been done yet.

Regards,

Yvan
mhassab

Re: Real time residuals monitoring / convergence monitoring

Post by mhassab »

Yvan Fournier wrote:Hello,

For residuals, I'm not sure about any other solution than parsing the "listing" file.

For probes, the output files are written as the computation progresses, but they might not always be "flushed" by default.

You can use the cs_user_parameters.f90 (usipse routine) to set the "tplflw" option, which determines the time plot flush frequency, in user-elapsed seconds (updating too often might slow down the the computation a bit).

To force flushing of the "listing" file, use the control_file (check the user guide for syntax).

We should add plots for residuals in the future, but I don't think its been done yet.

Regards,

Yvan

I am using the GUI. I guess this is why those subroutines are not appearing in my cs_user_parameters.f90. Is it possible to provide or add aditional subroutine in cs_user_parameters.f90 to display the plots , will the code recognize other subroutines inside the fortan code? and how should it be added to run with the runcase batch file?

thanks,
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Real time residuals monitoring / convergence monitoring

Post by Yvan Fournier »

Hello,

To use cs_user_parameters.f90, simply copy it to the SRC folder of a study (you can copy the version in SRC/REFERENCES)..

But the reference cs_user_parameters.f90 contain examples for most frequently used optionsn ,ot for all possible options. For more rarely used options, only the documentation can help...)

In your case, I recommend searching for tplfmt both in the Doxygen documentation and in cs_user_parameters.f90. In the same "group" of options in the Docygen documentation, tou should find "tplflw", which you can set in cs_user_parameters.f90/usipes).

As a reminder to all users, when using both the GUI and user subroutines, GUI definitions are applied first, the the user subroutines are applied (so they take priority). Using this logic, I recommend using the GUI for every thing possible, and user subroutines only for the rest (this makes them simpler, and easier to verify).

Regards,

Yvan
mstorti
Posts: 4
Joined: Wed Jan 25, 2017 2:00 pm

Re: Real time residuals monitoring / convergence monitoring

Post by mstorti »

mhassab wrote: Fri Aug 21, 2015 2:42 pm Hello All,

I was wondering if any of you got the chance to find a way to monitor the solver residuals in real time while the solver is running, monitoring of monitor points with iterations while solver is running. How do you monitor convergence while the solver is running.

Is there an add on to run to enable that ?

Thanks,
Hi, this post is old but I think I find a solution and I leave it here for future reference. In C for each field you can extract a structure of type cs_solving_info_t that has the information that you see in the "INFORMATION ON CONVERGENCE" section in the "listing" log file. I put the code in the
cs_user_extra_operations() function and goes like this:

Code: Select all

 
cs_user_extra_operations(void) {
  int key_sinfo_id key_sinfo_id = cs_field_key_id("solving_info");
  cs_field_t *f = cs_field_by_name("velocity");
  cs_solving_info_t s;
  cs_field_get_key_struct(f, key_sinfo_id, &s);
  printf("velocity convergence nit %d, rhs %g, res %g, der %g, l2res %g\n",
         s.n_it,s.rhs_norm,s.res_norm,s.derive,s.l2residual);
  static int stop_step=-1;
  if (stop_step<0 && s.l2residual>0 && s.l2residual<1e-2) {
    // STOP at next step if we reach some threshold residual
    stop_step = cs_glob_time_step->nt_cur;
    cs_time_step_define_nt_max(stop_step+1);
  }
}
HTH, regards.
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Real time residuals monitoring / convergence monitoring

Post by Yvan Fournier »

Hello,

This info is normally also automatically logged in the residuals.csv file, which did not exist at the time if the original post but is present in current versions.

Best regards,

Yvan
Post Reply