Cantera  3.1.0a1
YamlWriter.h
Go to the documentation of this file.
1 //! @file YamlWriter.h Declaration for class Cantera::YamlWriter.
2 
3 // This file is part of Cantera. See License.txt in the top-level directory or
4 // at https://cantera.org/license.txt for license and copyright information.
5 
6 #ifndef CT_YAMLWRITER_H
7 #define CT_YAMLWRITER_H
8 
9 #include "cantera/base/ct_defs.h"
10 #include "cantera/base/AnyMap.h"
11 #include "cantera/base/Units.h"
12 
13 namespace Cantera
14 {
15 
16 class Solution;
17 class ThermoPhase;
18 class Kinetics;
19 class Transport;
20 
21 //! @defgroup serializeGroup Serialization
22 //! Classes and functions related to serialization of %Cantera objects
23 //! @ingroup ioGroup
24 
25 //! A class for generating full YAML input files from multiple data sources
26 //! @ingroup serializeGroup
28 {
29 public:
30  YamlWriter() = default;
31 
32  //! Include top-level information used in YAML header block
33  void setHeader(const AnyMap& header);
34 
35  //! Include a phase definition for the specified Solution object
36  void addPhase(shared_ptr<Solution> soln, bool includeAdjacent=true);
37 
38  //! Include a phase definition using the specified ThermoPhase, (optional)
39  //! Kinetics, and (optional) Transport objects
40  void addPhase(shared_ptr<ThermoPhase> thermo, shared_ptr<Kinetics> kin={},
41  shared_ptr<Transport> tran={});
42 
43  //! Return a YAML string that contains the definitions for the added phases,
44  //! species, and reactions
45  string toYamlString() const;
46 
47  //! Write the definitions for the added phases, species and reactions to
48  //! the specified file.
49  void toYamlFile(const string& filename) const;
50 
51  //! For output floating point values, set the maximum number of digits to
52  //! the right of the decimal point. The default is 15 digits.
53  void setPrecision(long int n) {
55  }
56 
57  //! By default user-defined data present in the input is preserved on
58  //! output. This method can be used to skip output of user-defined data
59  //! fields which are not directly used by Cantera.
60  void skipUserDefined(bool skip=true) {
61  m_skip_user_defined = skip;
62  }
63 
64  //! Set the units to be used in the output file. Dimensions not specified
65  //! will use Cantera's defaults.
66  //! @param units A map where keys are dimensions (mass, length, time,
67  //! quantity, pressure, energy, activation-energy) and the values are
68  //! corresponding units supported by the UnitSystem class.
69  void setUnits(const map<string, string>& units={});
70 
71  //! Set the units to be used in the output file. Dimensions not specified
72  //! will use Cantera's defaults.
73  //! @param units A UnitSystem object specifying dimensions (mass, length, time,
74  //! quantity, pressure, energy, activation-energy).
75  void setUnitSystem(const UnitSystem& units=UnitSystem());
76 
77 protected:
78  //! Top-level information used in YAML header block
80 
81  vector<shared_ptr<Solution>> m_phases;
82 
83  //! See setPrecision()
84  long int m_float_precision = 15;
85 
86  //! See skipUserDefined()
87  bool m_skip_user_defined = false;
88 
89  //! Top-level units directive for the output file. Defaults to Cantera's
90  //! native SI+kmol system.
92 };
93 
94 }
95 
96 #endif
Header for unit conversion utilities, which are used to translate user input from input files (See In...
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:427
Unit conversion utility.
Definition: Units.h:169
A class for generating full YAML input files from multiple data sources.
Definition: YamlWriter.h:28
bool m_skip_user_defined
See skipUserDefined()
Definition: YamlWriter.h:87
string toYamlString() const
Return a YAML string that contains the definitions for the added phases, species, and reactions.
Definition: YamlWriter.cpp:55
void setPrecision(long int n)
For output floating point values, set the maximum number of digits to the right of the decimal point.
Definition: YamlWriter.h:53
void setUnitSystem(const UnitSystem &units=UnitSystem())
Set the units to be used in the output file.
Definition: YamlWriter.cpp:201
long int m_float_precision
See setPrecision()
Definition: YamlWriter.h:84
void skipUserDefined(bool skip=true)
By default user-defined data present in the input is preserved on output.
Definition: YamlWriter.h:60
AnyMap m_header
Top-level information used in YAML header block.
Definition: YamlWriter.h:79
void setHeader(const AnyMap &header)
Include top-level information used in YAML header block.
Definition: YamlWriter.cpp:19
void addPhase(shared_ptr< Solution > soln, bool includeAdjacent=true)
Include a phase definition for the specified Solution object.
Definition: YamlWriter.cpp:23
UnitSystem m_output_units
Top-level units directive for the output file.
Definition: YamlWriter.h:91
void toYamlFile(const string &filename) const
Write the definitions for the added phases, species and reactions to the specified file.
Definition: YamlWriter.cpp:189
void setUnits(const map< string, string > &units={})
Set the units to be used in the output file.
Definition: YamlWriter.cpp:195
This file contains definitions of constants, types and terms that are used in internal routines and a...
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:564