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

Resolving static lifetime problems #674

Closed timspainNERSC closed 1 month ago

timspainNERSC commented 2 months ago

Resolving static lifetime problems

Fixes #614


Change Description

Deleted classes

Edited classes

ConfigMap

Changed the static const type constants to an enum.

Configurator

Made the static data into singletonoid functions. The data in question are:

The command line values were combined into a struct to avoid passing more than one return value. The pointer to the additional configuration was set to a nullptr initially, with null checks used when the pointer value is used.

Configured class template

Nothing depends on the keyMap template member variable being a template member variable. Redefine each key map as static (compilation unit localized) const std::map. Since many classes are configured, this affects many files. Only the source .cpp files are affected.

ConfiguredModule & Module

Changes to Module<>

Changes to ConfiguredModule

Miscellaneous other changes

FileCallbackCloser

Replaced the static std::list with a singleton function providing a std::list.

Iterator

Removed the static implementation of NullIterator.

MissingData

Replaced the static double missing data value with a singleton, inlined access function. The missing data value is created on first access, but still destroyed at the end of execution. This is fine, since it is a scalar double.

Removed the MissingData.cpp source file as it is no longer needed.

ModelComponent

ModelConfig

Moved the key specification to an .ipp file to avoid repeating the text in Model.cpp.

ParaGridIO

New classes

Finalizer


Test Description

Apart from deleted tests for deleted classes, all tests should still pass.

ModelComponent

Adds some test to ModelArray_test to check sizes around assignment operations.

Finalizer

There is a test for the new Finalizer class.


Documentation Impact

No changes to existing documentation. All classes should provided the same interfaces as previously.

TomMelt commented 1 month ago

Thanks @timspainNERSC , I have approved from my side. I left two conversations "unresolved" just so we can find them easily in the next team meeting and discuss. No outstanding issues. Thanks for addressing my comments

timspainNERSC commented 1 month ago

For the big picture of resource management, a possible pitfall which remains is that modules have to be manually registered for destruction via Module::finalize. That seems manageable but is there a reason why this should be done manually instead of automatically, e.g. on construction?

I thought that there were cases where registering the final methods at construction would not work. But I cannot identify any right now. This might be worth looking at in the (not to distant) future, but can be a separate issue.