GridOPTICS / GridPACK

https://www.gridpack.org/
44 stars 22 forks source link

gridpack::NoPrint #126

Open abhyshr opened 1 year ago

abhyshr commented 1 year ago

No idea what this does. There is hardly any documentation about its intended usage. Seems to me like this is expendable if not used extensively.

huangrenke commented 1 year ago

No idea what this does. There is hardly any documentation about its intended usage. Seems to me like this is expendable if not used extensively.

Hi Shri, sorry I am not sure whether I messed up this issue #126 by closing it accidentally. I agree with your comments that "have a general "verbosity" level class that prints selective information depending on the verbosity level set. Verbosity level = 0 will print nothing and verbosity level = max_level will print all information." And we can also remove the usage of this class in the dsf_main.cpp, while I would suggest that we keep this class in GridPACK so in the python wrapper we can still easily call this function, otherwise the current existing code of reinforcement learning training will all not work, thanks.

abhyshr commented 1 year ago

Duly noted. The NoPrint class will not be removed till we put a better alternative for it. I have disabled it though (set status to false) for the dynamics simulation application.

abhyshr commented 1 year ago

Btw, are you using Gridpack or plan to use it in the future?

bjpalmer commented 1 year ago

As Renke mentioned, the NoPrint class was created to control the printing to standard out so that applications like HADREC would work properly. The idea was to create a singleton that provided a single point where printing could be turned on or off and also could be accessed anywhere in the code to check to see if printing is suppressed. Otherwise the printing status would need to be passed around to multiple different objects and applications. You should be able to control whether or not you want printing enabled at the application level, you could even provide it as a user option. However, I would not get rid of this class entirely, or at least replace it with something else that might suit your functional needs better.

abhyshr commented 1 year ago

Thanks, Bruce. How does it suppress the PETSc output? I cannot even view any PETSc vectors/matrices, i.e., if I extract the PETSc vector out of the Gridpack vector and call ‘VecView’ on it then it does not print it to stdout. Something is in the NoPrint class (perhaps some global variable that PETSc also uses) that redirects stdout.

bjpalmer commented 1 year ago

I think there is some PETSc parameter that you can set to suppress all output from PETSc. You may have to set NoPrint to true before calling the math initialization to get that to work properly. I'd need to dig into the code to know for sure.

bjpalmer commented 1 year ago

This is the code (in petsc_math.cpp) that turns off all printing

  bool no_print = gridpack::NoPrint::instance()->status();
  if (no_print)  {
    PETSC_STDOUT = fopen("/dev/null", "w");
    PETSC_STDERR = fopen("/dev/null", "w");
  }