amanzi / ats

Advanced Terrestrial Simulator (ATS) development
Other
47 stars 35 forks source link

Refactor ATS to use a single state #115

Closed ecoon closed 2 years ago

ecoon commented 2 years ago

This is to support Amanzi PR, amanzi/amanzi#640

Currently ATS uses 3, copy-constructed, identical states in all PKs: S_, S_inter_ and S_next_. Each has its own time, and correspond to the "old" time, an "intermediate" time for subcycling PKs, and the "new" time, respectively.

This is to be refactored to a single state model, where time tags are used to indicate "old", "intermediate", and "next." See discussions in the above PR. Each PK is assigned two tags, a tag_current_ and a tag_next_, and is expected to AdvanceTime() between those two tags. Note that subcycling PKs may be given intermediate tags that are NOT the defaults, e.g. Amanzi::Tags::CURRENT and Amanzi::Tags::NEXT, respectively.

To do this refactor is quite intrusive on ATS code. It requires:

In PKs:

  1. all S->RequireField(field_name); --> S->Require<CompositeVector,CompositeVectorSpace>(field_name, field_tag);
  2. all S->RequireFieldEvaluator(field_name) --> S->RequireEvaluator(field_name, field_tag);
  3. Direct control and new requires when a field is needed at the old time. Previously, this was gotten for free because Snext was copy-constructed from S_, so all evaluators existed in all states. Now, we have to require evaluators for both old and new times, and typically (for implicit time integration), the "old" evaluator is now a primary variable controlled by the PK. Furthermore, this field needs to be copied from new time --> old time on PK::CommitStep() and from new time --> old time on PK::FailStep().
  4. Other changes to the State and Evaluator interfaces need to be done (though most can be done via sed, but when a tag is required, this must be inserted).

In evaluators:

  1. Both my_keys (the variables calculated by that evaluator) and dependencies need tags.
  2. In Evaluate() and EvaluatePartialDerivatives(), calls to S->Get() need to be updated both in interface syntax and in adding a tag parameter.
  3. This is a great time to clean up code, making sure Keys::readKey() is used everywhere, there no hard-coded domains, and domain sets are used everywhere instead of magic "column" string searching.
  4. EnsureCompatibility() is being complete reworked to make it easier to overload this method and get it right. This method is now split into a bunch of "hooks" that are virtual, and most secondary evaluators only need to update the EnsureCompatibility_ToDeps_() hook, which passes CompositeVector structure (e.g. faces, cells, ndofs, mesh, etc) to its dependencies. See extensive developer documentation in https://github.com/amanzi/amanzi/blob/konstantin/state/src/state/evaluators/EvaluatorSecondaryMonotype.hh and please ask if you have questions!

In addition, code is generally being cleaned up, and after this PR is ready, the entire code will get run through clang-format to standardize styles!

ecoon commented 2 years ago

This work is being done on the branch: https://github.com/amanzi/ats/tree/konstantin/state

As of 78771dc the Richards and OverlandPressure PKs and associated evaluators were completed, with all tests in ats-regression-tests on a branch of the same name passing.

ecoon commented 2 years ago

@dasvyat Could you start to look at how Richards has changed, and see what you need to do for sediment transport and any other ATS PKs that you would need to update?

@jbeisman Could you start in on the energy PK and evaluators in src/pks/energy/constitutive_relations?

I will look at surface energy balance and MPCs, and whoever finishes first can take on transport.

I'd be happy to set up a meeting to walk through the main changes, as I think things are pretty stable now on both the Amanzi side and in the ATS flow PKs. If they would be helpful, I can send some emacs macros that do a lot of the heavy lifting with search-and-replace.

ecoon commented 2 years ago

PKs to do:

ecoon commented 2 years ago

this is done, or very nearly so. will be closed shortly