Reference states#1696
Conversation
IvarStefansson
left a comment
There was a problem hiding this comment.
Main comment: Think about precendence for reference - time step - iteration
| """ | ||
| try: | ||
| value = data[pp.REFERENCE_SOLUTIONS][name].copy() | ||
| except KeyError as err: |
There was a problem hiding this comment.
Are we sure we want to have fallback?
There was a problem hiding this comment.
I would say no, I prefer to have the code crash on me. @jwboth what do you think?
There was a problem hiding this comment.
Update after a chat with @jwboth: A default value will make it possible to take the perturbations of general operators, without having to explicitly set a zero reference on all leaves (in the operator tree sense). This seems like a nice feature to have and will be useful for the initialization. The original implementation will not work, since under parsing this may lead to arithmetic operations with incompatible operands. The solution we ended up with for now is implemented below; this is not elegant and could have been less computationally expensive, but it should do the job for now.
There was a problem hiding this comment.
Which types of leaves will this be invoked for? I'm not certain I grasp all possible consequences of this.
| A copy of the values stored at the passed index. | ||
|
|
||
| """ | ||
| if reference: |
There was a problem hiding this comment.
I think this precedence makes sense. But we need to document the rules for previous time steps and iterates and references somewhere.
There was a problem hiding this comment.
Moved all get and set methods to a new module, will document at the module level there.
| - ReferenceOperator: The operator represents a reference value and will evaluate this | ||
| reference. | ||
|
|
||
| When combining the mixins, their behavior is prioritized as follows: |
There was a problem hiding this comment.
This list, which hopefully is complete, defines the prioritization logic of various operator states. Please review carefully and keep in mind when assessing the rest of the code.
| return Scalar(self.solid.porosity, "porosity") | ||
|
|
||
|
|
||
| class CompressibleRockPorosity(pp.PorePyModel): |
There was a problem hiding this comment.
@IvarStefansson I have not taken a stand on what to do with this class. My initial thought is, do we really need it, or is it 'nice to have'? If its main purpose is as a testing ground for initialization routines, there is information in that.
| @@ -0,0 +1,353 @@ | |||
| """This module contains helper functions for setting, getting and shifting values in the | |||
There was a problem hiding this comment.
This module is the new home for get and set methods (moved from ad_utils). I think that making a move was the right decision, whether this is the right placement is less clear.
|
I have done a partial re-implementation of this PR. Main points:
|
…ate module Also make these mixins to be added to operators
…operators These have been replaced with a more refined suite of tests
Proposed changes
This PR introduces an additional state of
VariableandTimeDependentDenseArrayfollowing the style ofprevious_iterationandprevious_time_step. These now also are able to hold reference values which can be obtained in AD operator form through call of the methodop.reference()for any AD operatorop, e.g.,model.pressure(subdomains).reference(). In addition, perturbations to reference states can be conventiently fetched byop.perturbation_from_reference(). If not set, reference values are 0. No optimization in terms of emtpy operators has been implemented but could be foreseen in near future.The API for setting values has been extended aiming at canonical extension of current workflows (
EquationSystem.set/get_variable_valuesandpp.set/get_solution_values). An additional keywordreferenceneeds to be set true.As an example (hopefully of actual value) is added utilizing perturbations from reference states: Porosity with mere rock compressibility simplifying standard two-way coupled poromechanics. It currently mainly serves for testing the potential integration of reference states in models.
NOTE: This PR does not integrate reference states in models and variables like currently proposed in #1686 (initialization). The aim is to base further work on initialization on the current PR.
Types of changes
What types of changes does this PR introduce to PorePy?
Put an
xin the boxes that apply.Checklist
Put an
xin the boxes that apply or explain briefly why the box is not relevant.pytestwas run with the--run-skippedflag.