Draft: 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 in SessionReader to a separate subclass, then add constructors and functions to populate session and mesh objects programmatically.
Implementation
The main changes are:
-
SessionReader
class renamed toSession
. - Several
SessionReader
member functions split up/rejigged in order to separate out XML-parsing from population of member variables. - Xml-parsing functionality from
SessionReader
moved to theSessionXmlReader
class, which inherits fromSession
. -
Session
constructors chained to reduce duplicate code. - New
Session
constructor added that performs initialisation based on various STL container arguments. e.g. astd::map<std::string,std::string>
for solver settings. - New
MeshGraphProgrammatic
class added. This is a subclass ofMeshGraphXml
, rather thanMeshGraph
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. - 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 !1375 (comment 20057). A description of the original implementation is retained below:
Previous implementation
- New SessionConfigurable class (subclass of SessionReader)
- Several SessionReader member functions split up/rejigged in order to separate XML-parsing from population of member variables
- SessionReader constructors chained to reduce duplicate code
- New MeshGraphProgrammatic class (subclass of MeshGraph)
- 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 #295 (closed).
Checklist
-
Functions and classes, or changes to them, are documented. -
User guide/documentation is updated. -
Changelog is updated. -
Suitable tests added for new functionality. -
Contributed code is correctly formatted. (See the contributing guidelines). -
License added to any new files. -
No extraneous files have been added (e.g. compiler output or test data files).