nextsimhub / nextsimdg

neXtSIM_DG : next generation sea-ice model with DG
https://nextsim-dg.readthedocs.io/en/latest/?badge=latest
Apache License 2.0
10 stars 13 forks source link

Dynamics switcher #477

Closed timspainNERSC closed 6 months ago

timspainNERSC commented 9 months ago

Dynamics switcher

Fixes #378


Change Description

This PR converts the structure of the code from the original code where the code for all rheologies is mixed in a single file.

The new structure is designed to allow new implementations to be written and included in nextSIM-DG. It also provides separation of all classes using continuous Galerkin (CG) arrays to hold velocity fields.

Modules

The dynamics are modularized so that the dynamics and rheology implementation can be configured at run time, allowing rapid replacement of the rheology mathematics. This modularization is only used in the modules held in the core part of the model. Within the dynamics subdirectory the code is not modularized, but the classes are part of a class hierarchy. The module implementations control the flow of data from the core of the model to the dynamics (and back) and determine which classes are called to act on this data.

Dynamics classes

DynamicsKernel

The new classes in the dynamics subdirectory are part of two class hierarchies. The first is based on the DynamicsKernel class. This is intended to encapsulate all of the dynamics calculations and data. any common data that is based on DG arrays is held here:

This class is abstract and should not be instantiated.

CGDynamicsKernel

The only current child class is the CGDynamicsKernel class, which defines everything which is common to dynamics classes which use CG velocity fields (currently all of them) and holds the arrays for this data:

The class also holds functions common to dynamics implementation using CG arrays, such as:

Again, the class is abstract and should not be instantiated.

VPCGDynamicsKernel

The implementation of CG-based dynamics for visco-plastic rheologies, a child of the CG dynamics kernel class. The update step is defined at this level, with only the stress update step to be defined by child classes. The main piece of code in this class is the momentum solver. The class also holds the parameters object for the VP calculation.

MEVPDynamicsKernel

This is a child class of the CG VP dynamics kernel. The only definition is that the MEVP stress update step class is to be used to calculate stress from strain. This class is the one instantiated by the MEVP dynamics implementation in the core code.

StressUpdateStep

A class that defines an interface to perform the calculation of stress from strain. By using a generic parameters class, the interface can be common between the MEVP, MEB and BBM rheologies that are the initial targets for nextSIM-DG.

MEVPStressUpdateStep

The child class of the stress update class that is instantiated do the MEVP stress calculation. Used by MEVPDynamicsKernel.


Test Description

Do the outputs of the dynamics benchmark and the yearlong run match for MEVP and BBM? As judged by a human.


Documentation Impact

In terms of user documentation, no impact. These changes should be transparent to the user.

Developer documentation should be added.

timspainNERSC commented 6 months ago

Removing the old dynamics source files causes the CI on Mac to fail, not even in the dynamics tests.

The files that have not been removed are