Skip to content

Fix DMClone_Network

Aidan Hamilton requested to merge ahamilton/fix-DMClone_Network into main

This merge request is a work in progress to fix DMClone_Network.

Currently DMClone_Network is broken, as DMNetwork stores most of its information in DM_Network, including the sections and arrays for its dofs and components. Currently this is entirely shared with any clone.

The result is the clone has no means to change any components or dofs on the new network, and if we had the API to manipulate components after DMSetUp, it would change the information of the original as well. And technically right now, if you altered the data inside any component with a clone, it would also change the data for the original as it is shared.

The basic idea of the fix is to split DM_Network into a shared structure, that will be shared between clones, and everything else, that will be recreated and set to a default when cloning. The shared structure includes all topological components of the network, in particular everything to do with subnetworks, global indices and shared vertices. Notably the plex is not considered shared as it makes more sense in my view to simply clone that as well.

This requires only 1 API change, the addition of a function:

DMNetworkFinalizeComponents(DM)

which is responsible for setting up the internal sections for dofs and components as well as building the componentdataarray. This is intended to be called after adding all components to a network. This is needed as currently this is done in DMSetUp_Network, which at the DM level sets dm->setupcalled = PETSC_TRUE, which is inherited by clones. So we need an alternative way to set up this internal data as clones should be able to have completely different components than the original.

I have a basic "test" in src/dm/impls/network/tests/ that just checks if cloning can be called without errors and new components can be added. It seems to show everything working, but over course the test needs to be improved.

Let me know if the overall idea of this merge request is acceptable, then I can improve the test, as well as clean up the code/comments, and get this added to main.

Beyond just having a working clone, I want to implement createcoordinatedm for DMNetwork, as step in getting some generic visualization for DMNetwork implemented, and this requires clones to work for DMNetwork.

Edited by Aidan Hamilton

Merge request reports