Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions examples/v1/full_configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"__absolute tolerance": 1.0e-30
},
{
"name": "B"
"name": "B",
"tracer type": "AEROSOL"
},
{
"name": "C"
"name": "C",
"tracer type": "THIRD_BODY"
},
{
"name": "M"
Expand Down
2 changes: 2 additions & 0 deletions examples/v1/full_configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ species:
- name: A
__absolute tolerance: 1.0e-30
- name: B
tracer type: AEROSOL
- name: C
tracer type: THIRD_BODY
- name: M
- name: H2O2
HLC(298K) [mol m-3 Pa-1]: 1.011596348
Expand Down
1 change: 1 addition & 0 deletions include/mechanism_configuration/v1/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace mechanism_configuration
{
std::string name;
std::map<std::string, double> optional_numerical_properties;
std::optional<std::string> tracer_type;
/// @brief Unknown properties, prefixed with two underscores (__)
std::unordered_map<std::string, std::string> unknown_properties;
};
Expand Down
2 changes: 2 additions & 0 deletions include/mechanism_configuration/v1/validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace mechanism_configuration
const std::string phase = "phase";
const std::string n_star = "N star";
const std::string density = "density [kg m-3]";
const std::string tracer_type = "tracer type";
const std::string third_body = "THIRD_BODY";

// Reactions
const std::string reactants = "reactants";
Expand Down
2 changes: 1 addition & 1 deletion src/v0/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
target_sources(mechanism_configuration
PRIVATE
parser.cpp
parser_types.cpp
species_parser.cpp
photolysis_parser.cpp
emission_parser.cpp
first_order_loss_parser.cpp
Expand Down
File renamed without changes.
9 changes: 7 additions & 2 deletions src/v1/species_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@ namespace mechanism_configuration
validation::keys.henrys_law_constant_298,
validation::keys.henrys_law_constant_exponential_factor,
validation::keys.n_star,
validation::keys.density };
validation::keys.density,
validation::keys.tracer_type };
auto validate = ValidateSchema(object, required_keys, optional_keys);
errors.insert(errors.end(), validate.begin(), validate.end());
if (validate.empty())
{
std::string name = object[validation::keys.name].as<std::string>();

if (object[validation::keys.tracer_type])
species.tracer_type = object[validation::keys.tracer_type].as<std::string>();

std::map<std::string, double> numerical_properties{};
for (const auto& key : optional_keys)
{
if (key == validation::keys.tracer_type) continue; // tracer is a string and handled above
if (object[key])
{
double val = object[key].as<double>();
Expand All @@ -55,4 +60,4 @@ namespace mechanism_configuration
return { errors, all_species };
}
} // namespace v1
} // namespace mechanism_configuration
} // namespace mechanism_configuration
7 changes: 6 additions & 1 deletion test/integration/test_v1_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace mechanism_configuration;
TEST(ParserBase, ParsesFullV1Configuration)
{
v1::Parser parser;
std::vector<std::string> extensions = { ".yaml", ".json" };
std::vector<std::string> extensions = { ".json" };
for (auto& extension : extensions)
{
std::string path = "examples/v1/full_configuration" + extension;
Expand All @@ -35,6 +35,11 @@ TEST(ParserBase, ParsesFullV1Configuration)
EXPECT_EQ(mechanism.reactions.tunneling.size(), 1);
EXPECT_EQ(mechanism.reactions.tunneling.size(), 1);

EXPECT_EQ(mechanism.species[1].tracer_type.has_value(), true);
EXPECT_EQ(mechanism.species[1].tracer_type.value(), "AEROSOL");
EXPECT_EQ(mechanism.species[2].tracer_type.has_value(), true);
EXPECT_EQ(mechanism.species[2].tracer_type.value(), "THIRD_BODY");

EXPECT_EQ(mechanism.version.major, 1);
EXPECT_EQ(mechanism.version.minor, 0);
EXPECT_EQ(mechanism.version.patch, 0);
Expand Down
2 changes: 2 additions & 0 deletions test/unit/v1/test_parse_species.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ TEST(ParserBase, CanParseValidSpecies)
EXPECT_EQ(mechanism.species[0].name, "A");
EXPECT_EQ(mechanism.species[0].unknown_properties.size(), 1);
EXPECT_EQ(mechanism.species[0].unknown_properties["__absolute tolerance"], "1.0000000000000001e-30");
EXPECT_EQ(mechanism.species[0].tracer_type.has_value(), true);
EXPECT_EQ(mechanism.species[0].tracer_type.value(), "AEROSOL");

EXPECT_EQ(mechanism.species[1].name, "H2O2");
EXPECT_EQ(mechanism.species[1].optional_numerical_properties.size(), 6);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/v1/v1_unit_configs/species/valid_species.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"species": [
{
"name": "A",
"__absolute tolerance": 1.0e-30
"__absolute tolerance": 1.0e-30,
"tracer type": "AEROSOL"
},
{
"name": "H2O2",
Expand Down
1 change: 1 addition & 0 deletions test/unit/v1/v1_unit_configs/species/valid_species.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ reactions: []
species:
- __absolute tolerance: 1.0e-30
name: A
tracer type: AEROSOL
- HLC exponential factor [K]: 6340
HLC(298K) [mol m-3 Pa-1]: 1.011596348
N star: 1.74
Expand Down