pmgbergen / porepy

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

Refactor constitutive_laws #1089

Open IvarStefansson opened 7 months ago

IvarStefansson commented 7 months ago

The module porepy/models/constitutive_laws.py currently contains 3.5k lines, motivating a refactoring. I suggest a two-level approach:

  1. Identifying if there is something which is not (primarily) a constitutive law. Such code should be moved elsewhere (e.g. to a discretization module).
  2. Designing a subdivision of what are constitutive laws (new package). Candidate designs are:
    • "type of physics" (mechanics, fluid flow). This might not work, as "coupled physics are coupled"...
    • mathematical structure (diffusion, advection).
    • material type (fluid, rock/solid...). Not everything fits this division - some laws are either agnostic to the material or defined for the compound porous medium.
    • More levels of the type constitutive_laws.name_of_quantity.NameOfLawInstance. E.g. stress.py containing classes like LinearElastic, PoroMechanical and ThermoPoroMechanical.
    • OTHER!

We should keep #943 in mind when designing the new structure and naming of modules/packages.

keileg commented 7 months ago

As a first step, we could identify parameters that may be classified as solid, fluid, and solid-fluid:

If we move these into separate files, my rough estimate is that this will take care of perhaps half the file. In addition, functionality relating to multiphase flow etc., that is coming up in the next few months, would enter fluid.py instead of constitutive laws.py (though this is rather a further argument for the refactoring).

For the remaining terms, looking only at class names, I would group these as relating to

So, perhaps a division diffusion, advection, 'stress-related' could work.

IvarStefansson commented 7 months ago

Are your "remaining terms" somehow classified as pertaining to discretization? And do you think it would make sense to put dimension reduction into the Geometry class?

keileg commented 7 months ago

Are your "remaining terms" somehow classified as pertaining to discretization?

It seems so, yes, but I have no firm opinions on this matter.

And do you think it would make sense to put dimension reduction into the Geometry class?

I had not thought of a geometry class, but yes, that makes sense.