pmgbergen / porepy

Python Simulation Tool for Fractured and Deformable Porous Media
GNU General Public License v3.0
251 stars 88 forks source link

Adaptivity of SolutionStatistics #1196

Closed IvarStefansson closed 5 months ago

IvarStefansson commented 5 months ago

Currently, the statistics object is set in SolutionStrategy.init(): self.nonlinear_solver_statistics = pp.SolverStatistics() The statistics to be stored are defined as class attributes. Thus, there is no support for expanding the set of attributes. I suggest changing to self.nonlinear_solver_statistics = self.params.get("nonlinear_solver_statistics", pp.SolverStatistics)(), allowing me to pass

class MySolverStatistics(pp.SolverStatistics):
   foo_error: field(default_factory=list)
   bar_attribute: field(default_factory=list)

   def log_error():
      super().log_error()
      self.foo_error.append(42)

and adding to bar_attribute in any other method with access to the model (e.g. when computing line search weights).

keileg commented 5 months ago

Makes sense to me.