CWorthy-ocean / C-Star

C-Star is a python package for setting up and running ocean model simulations, with a particular focus on marine carbon dioxide removal (mCDR) applications.
https://c-star.readthedocs.io
10 stars 4 forks source link

Refactor `AdditionalCode` to accommodate namelist modification #56

Open dafyddstephenson opened 1 month ago

dafyddstephenson commented 1 month ago

C-Star has to modify the ROMS primary namelist (typically called roms.in) in order to set basic parameters like run length and timestep.

The current strategy for this following PR #55 is to expect a "template" namelist containing placeholder strings to be replaced with actual parameter values by C-Star. When creating an AdditionalCode instance, C-Star adds any namelists to AdditionalCode.namelists but also copies any namelists with the suffix _TEMPLATE to a file without this suffix, adding this file to a separate attribute AdditionalCode.modified_namelists. Methods which then have to set namelist parameters use the modifiable copy, rather than the template.

Instead, we should separate AdditionalCode, in particular creating a Namelist class with:

If we design a sufficiently robust framework to handle the parsing and modifying, this potentially could be extended to cover source code modifications, including things like output frequency.

This would mean that instead of a single AdditionalCode instance describing a list of source code modifications and namelists associated with a Component, each namelist would have its own object, similarly to how InputDataset currently works. Component.input_dataset is a list of InputDataset objects, but Component.additional_code is a single AdditionalCode option.