Skip to content

Draft: Changes to allow SessionReader (and MeshGraph) objects to be set up without XML files.

Owen Parry requested to merge oparry/nektar:feature/session-without-xml into master

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.
  2. Several SessionReader member functions split up/rejigged in order to separate out XML-parsing from population of member variables.
  3. Xml-parsing functionality from SessionReader moved to the SessionXmlReader class, which inherits from Session.
  4. Session constructors chained to reduce duplicate code.
  5. 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.
  6. New MeshGraphProgrammatic class added. This is a subclass of MeshGraphXml, 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.
  7. 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

  1. New SessionConfigurable class (subclass of SessionReader)
  2. Several SessionReader member functions split up/rejigged in order to separate XML-parsing from population of member variables
  3. SessionReader constructors chained to reduce duplicate code
  4. New MeshGraphProgrammatic class (subclass of MeshGraph)
  5. 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

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).
Edited by Owen Parry

Merge request reports