Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read YAML using C++ newSolution in Python / access root level data #1129

Merged
merged 25 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6ce6bb8
[Python] Address unpythonic Species.fromYaml and Species.fromYamlFile
ischoegl Oct 23, 2021
a8f325c
[CI] Switch test_transport.py tests to h2o2.yaml
ischoegl Apr 15, 2021
e5b5292
[Solution] Avoid re-parsing of YAML input in C++
ischoegl Oct 23, 2021
897e655
[Python] Expose C++ YAML input data at root level
ischoegl Apr 16, 2021
c107167
[Solution] Add information on input data used for newSolution
ischoegl Oct 23, 2021
9c69c7d
[Solution] Skip non-standard YAML reaction fields in header
ischoegl Oct 24, 2021
6b3a4a5
[Transport] Simplify allocation of empty transport managers
ischoegl Oct 24, 2021
2a55c54
[Transport] Improve exception handling
ischoegl Oct 24, 2021
165cece
[Python] Build Solution from YAML input using C++ newSolution
ischoegl Oct 23, 2021
92f3f55
[UnitTests] Add tests for Solution.input_header
ischoegl Oct 23, 2021
c87e3b1
[UnitTests] Add googletests for transport model defaults
ischoegl Oct 24, 2021
5daa45b
[Solution] Fix logic for Solution::parameters
ischoegl Oct 24, 2021
ef4539b
[Python] Ensure C++ is aware of transport model changes
ischoegl Oct 24, 2021
3109c1a
[1D] Raise warning when transport model is implicitly set
ischoegl Oct 24, 2021
d354b57
[YamlWriter] Implement custom header information
ischoegl Oct 25, 2021
fe542a3
[Python] Make YAML header information customizable
ischoegl Oct 25, 2021
9bdc366
[Samples] Explicitly specify transport model in extract_submechanism.py
ischoegl Oct 24, 2021
f914571
[UnitTests] Add test for customized YamlWriter header
ischoegl Oct 25, 2021
863125b
[CI] Switch sundials runner to pytest
ischoegl Oct 25, 2021
13a42fa
Small fixes of docstrings and nomenclature
ischoegl Nov 24, 2021
401f69a
[Python] Remove local copies of shared_ptr in _SolutionBase
ischoegl Nov 25, 2021
f6b796a
[UnitTests] Fix failing test
ischoegl Nov 25, 2021
c845540
[Solution] Limit YAML header to fields preceding 'phases' entry
ischoegl Nov 25, 2021
46f43a8
[Transport] Remove 'NoTransport' class
ischoegl Nov 26, 2021
f51bd6d
[Transport] Update signature of new newTransport function
ischoegl Nov 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ jobs:
# use boost-cpp rather than boost from conda-forge
run: |
conda install -q sundials=${{ matrix.sundials-ver }} scons numpy ruamel.yaml \
cython boost-cpp fmt eigen yaml-cpp h5py pandas libgomp openblas
cython boost-cpp fmt eigen yaml-cpp h5py pandas libgomp openblas pytest
- name: Build Cantera
run: |
scons build extra_inc_dirs=$CONDA_PREFIX/include:$CONDA_PREFIX/include/eigen3 \
Expand Down
33 changes: 32 additions & 1 deletion include/cantera/base/Solution.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#define CT_SOLUTION_H

#include "cantera/base/ctexceptions.h"
#include "cantera/base/AnyMap.h"

namespace Cantera
{

class ThermoPhase;
class Kinetics;
class Transport;
class AnyMap;

//! A container class holding managers for all pieces defining a phase
class Solution : public std::enable_shared_from_this<Solution>
Expand Down Expand Up @@ -64,10 +64,22 @@ class Solution : public std::enable_shared_from_this<Solution>

AnyMap parameters(bool withInput=false) const;

//! Access input data associated with header definition
const AnyMap& header() const;
AnyMap& header();

//! Retrieve source used for object creation; usually an input file name
const std::string source() const;

//! Overwrite source (only required if object is not created using newSolution)
void setSource(const std::string& source);

protected:
shared_ptr<ThermoPhase> m_thermo; //!< ThermoPhase manager
shared_ptr<Kinetics> m_kinetics; //!< Kinetics manager
shared_ptr<Transport> m_transport; //!< Transport manager

AnyMap m_header; //!< Additional input fields; usually from a YAML input file
};

//! Create and initialize a new Solution manager from an input file
Expand All @@ -87,5 +99,24 @@ shared_ptr<Solution> newSolution(const std::string& infile,
const std::string& transport="",
const std::vector<shared_ptr<Solution>>& adjacent={});

//! Create and initialize a new Solution manager from AnyMap objects
/*!
* This constructor wraps newPhase(), newKinetics() and
* newTransportMgr() routines for initialization.
*
* @param phaseNode the node containing the phase definition (i.e. thermo model,
* list of species, and initial state)
* @param rootNode the root node of the tree containing the phase definition, which
* will be used as the default location from which to read species definitions.
* @param transport name of the transport model.
* @param adjacent vector containing adjacent solution objects.
* @returns an initialized Solution object.
*/
shared_ptr<Solution> newSolution(AnyMap& phaseNode,
const AnyMap& rootNode=AnyMap(),
const std::string& transport="",
const std::vector<shared_ptr<Solution>>& adjacent={});

}

#endif
7 changes: 7 additions & 0 deletions include/cantera/base/YamlWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define CT_YAMLWRITER_H

#include "cantera/base/ct_defs.h"
#include "cantera/base/AnyMap.h"
#include "cantera/base/Units.h"

namespace Cantera
Expand All @@ -23,6 +24,9 @@ class YamlWriter
public:
YamlWriter();

//! Include top-level information used in YAML header block
void setHeader(const AnyMap& header);

//! Include a phase definition for the specified Solution object
void addPhase(shared_ptr<Solution> soln);

Expand Down Expand Up @@ -66,6 +70,9 @@ class YamlWriter
void setUnitSystem(const UnitSystem& units=UnitSystem());

protected:
//! Top-level information used in YAML header block
AnyMap m_header;

std::vector<shared_ptr<Solution>> m_phases;

//! @see setPrecision()
Expand Down
9 changes: 9 additions & 0 deletions include/cantera/kinetics/KineticsFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ inline Kinetics* newKineticsMgr(const std::string& model)
return KineticsFactory::factory()->newKinetics(model);
}

/**
* Create a new Kinetics instance.
*/
inline shared_ptr<Kinetics> newKinetics(const std::string& model)
{
shared_ptr<Kinetics> kin(KineticsFactory::factory()->newKinetics(model));
return kin;
}

/*!
* Create a new kinetics manager, initialize it, and add reactions
*
Expand Down
11 changes: 11 additions & 0 deletions include/cantera/thermo/ThermoFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ inline ThermoPhase* newThermoPhase(const std::string& model)
return ThermoFactory::factory()->create(model);
}

//! Create a new ThermoPhase instance.
/*!
* @param model String to look up the model against
* @returns a shared pointer to a new ThermoPhase instance matching the model string.
*/
inline shared_ptr<ThermoPhase> newThermo(const std::string& model)
{
ThermoPhase* tptr = ThermoFactory::factory()->create(model);
return shared_ptr<ThermoPhase> (tptr);
}

//! Create a new ThermoPhase object and initializes it according to the XML tree
/*!
* This routine first looks up the identity of the model for the solution
Expand Down
Loading