Nektar merge requestshttps://gitlab.nektar.info/nektar/nektar/-/merge_requests2024-01-26T14:17:12Zhttps://gitlab.nektar.info/nektar/nektar/-/merge_requests/1375Draft: Changes to allow SessionReader (and MeshGraph) objects to be set up wi...2024-01-26T14:17:12ZOwen ParryDraft: Changes to allow SessionReader (and MeshGraph) objects to be set up without XML files.# Issue/feature addressed
Simplify the running of Nektar solvers from external code by allowing programmatic set up of session and mesh objects, bypassing the usual XML file(s).
# Proposed solution
Extract the XML-parsing functionality ...# Issue/feature addressed
Simplify the running of Nektar solvers from external code by allowing programmatic set up of session and mesh objects, bypassing the usual XML file(s).
# Proposed solution
Extract the XML-parsing functionality in SessionReader to a separate subclass, then add constructors and functions to populate session and mesh objects programmatically.
# Implementation
The main changes are:
1. ``SessionReader`` class renamed to ``Session``.
1. Several ``SessionReader`` member functions split up/rejigged in order to separate out XML-parsing from population of member variables.
1. Xml-parsing functionality from ``SessionReader`` moved to the ``SessionXmlReader`` class, which inherits from ``Session``.
1. ``Session`` constructors chained to reduce duplicate code.
1. New ``Session`` constructor added that performs initialisation based on various STL container arguments. e.g. a ``std::map<std::string,std::string>`` for solver settings.
1. New ``MeshGraphProgrammatic`` class added. This is a subclass of ``MeshGraphXml``, rather than``MeshGraph`` in order to allow hybrid set ups, wherein parameters describing the expansion(s) are set programmatically, but the mesh itself is still read from XML.
1. Constructors of ``EquationSystem`` and its subclasses modified to allow pre-existing boundary conditions to be passed in, meaning they can be set up externally.
See library/Demos/LibUtilities/SessionWithoutXMLDemo.cpp for demos/tests of 1D and 2D problem set up.
N.B. The above implementation incorporates the approach described in the first bullet of https://gitlab.nektar.info/nektar/nektar/-/merge_requests/1375#note_20057.
A description of the original implementation is retained below:
---
### Previous implementation
1. New SessionConfigurable class (subclass of SessionReader)
1. Several SessionReader member functions split up/rejigged in order to separate XML-parsing from population of member variables
1. SessionReader constructors chained to reduce duplicate code
1. New MeshGraphProgrammatic class (subclass of MeshGraph)
1. Constructors of EquationSystem and its subclasses modified to allow pre-existing boundary conditions to be passed in, meaning they can be set up externally.
This approach seemed like the least disruptive way to change things for now; one downside is that SessionConfigurable inherits the XML doc and associated member functions. To mitigate that, I've overridden most (all?) of those functions to throw exceptions.
The intent is for external code to call SessionConfigurable::CreateInstance([variable_names, parameters, solver_info etc. in the form of STL containers]) . At least one part of the session is populated later (using SessionConfigurable::AddFunction), but that could be moved into the constructor too.
## Tests
- (Demos/LibUtilities/Tests/)SessionWithoutXMLDemo_Helmholtz1D - mimics the Helmholtz1D_8nodes test, buts sets up the session and mesh programmatically.
- (Demos/LibUtilities/Tests/)SessionWithoutXMLDemo_Helmholtz2D_modal_DG - mimics the Helmholtz2D_modal_DG test, buts sets up the session programmatically (the mesh is still read from xml).
# Notes
- clang-format changes handled in accordance with https://gitlab.nektar.info/nektar/nektar/-/issues/295.
# Checklist
- [ ] Functions and classes, or changes to them, are documented.
- [ ] User guide/documentation is updated.
- [ ] Changelog is updated.
- [x] Suitable tests added for new functionality.
- [x] Contributed code is correctly formatted. (See the [contributing guidelines](https://gitlab.nektar.info/nektar/nektar/-/blob/master/CONTRIBUTING.md#using-clang-format)).
- [x] License added to any new files.
- [x] No extraneous files have been added (e.g. compiler output or test data files).v5.6.0Dave MoxeyDave Moxey