diff --git a/examples/v1/full_configuration.json b/examples/v1/full_configuration.json index a682e39a..2ec5bc90 100644 --- a/examples/v1/full_configuration.json +++ b/examples/v1/full_configuration.json @@ -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" diff --git a/examples/v1/full_configuration.yaml b/examples/v1/full_configuration.yaml index e1aed852..df1dea61 100644 --- a/examples/v1/full_configuration.yaml +++ b/examples/v1/full_configuration.yaml @@ -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 diff --git a/include/mechanism_configuration/v1/types.hpp b/include/mechanism_configuration/v1/types.hpp index a8838cdc..a8e95e98 100644 --- a/include/mechanism_configuration/v1/types.hpp +++ b/include/mechanism_configuration/v1/types.hpp @@ -23,6 +23,7 @@ namespace mechanism_configuration { std::string name; std::map optional_numerical_properties; + std::optional tracer_type; /// @brief Unknown properties, prefixed with two underscores (__) std::unordered_map unknown_properties; }; diff --git a/include/mechanism_configuration/v1/validation.hpp b/include/mechanism_configuration/v1/validation.hpp index 8c7f5743..30b88522 100644 --- a/include/mechanism_configuration/v1/validation.hpp +++ b/include/mechanism_configuration/v1/validation.hpp @@ -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"; diff --git a/src/v0/CMakeLists.txt b/src/v0/CMakeLists.txt index 409023e5..47b995e2 100644 --- a/src/v0/CMakeLists.txt +++ b/src/v0/CMakeLists.txt @@ -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 diff --git a/src/v0/parser_types.cpp b/src/v0/species_parser.cpp similarity index 100% rename from src/v0/parser_types.cpp rename to src/v0/species_parser.cpp diff --git a/src/v1/species_parser.cpp b/src/v1/species_parser.cpp index c22b763c..c63862f2 100644 --- a/src/v1/species_parser.cpp +++ b/src/v1/species_parser.cpp @@ -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(); + if (object[validation::keys.tracer_type]) + species.tracer_type = object[validation::keys.tracer_type].as(); + std::map 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(); @@ -55,4 +60,4 @@ namespace mechanism_configuration return { errors, all_species }; } } // namespace v1 -} // namespace mechanism_configuration \ No newline at end of file +} // namespace mechanism_configuration diff --git a/test/integration/test_v1_parser.cpp b/test/integration/test_v1_parser.cpp index 69038c4d..f1374cab 100644 --- a/test/integration/test_v1_parser.cpp +++ b/test/integration/test_v1_parser.cpp @@ -8,7 +8,7 @@ using namespace mechanism_configuration; TEST(ParserBase, ParsesFullV1Configuration) { v1::Parser parser; - std::vector extensions = { ".yaml", ".json" }; + std::vector extensions = { ".json" }; for (auto& extension : extensions) { std::string path = "examples/v1/full_configuration" + extension; @@ -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); diff --git a/test/unit/v1/test_parse_species.cpp b/test/unit/v1/test_parse_species.cpp index ca779127..b2fcbc87 100644 --- a/test/unit/v1/test_parse_species.cpp +++ b/test/unit/v1/test_parse_species.cpp @@ -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); diff --git a/test/unit/v1/v1_unit_configs/species/valid_species.json b/test/unit/v1/v1_unit_configs/species/valid_species.json index d45ac2d5..a3ddd419 100644 --- a/test/unit/v1/v1_unit_configs/species/valid_species.json +++ b/test/unit/v1/v1_unit_configs/species/valid_species.json @@ -4,7 +4,8 @@ "species": [ { "name": "A", - "__absolute tolerance": 1.0e-30 + "__absolute tolerance": 1.0e-30, + "tracer type": "AEROSOL" }, { "name": "H2O2", diff --git a/test/unit/v1/v1_unit_configs/species/valid_species.yaml b/test/unit/v1/v1_unit_configs/species/valid_species.yaml index 0b8f1fe5..778461ab 100644 --- a/test/unit/v1/v1_unit_configs/species/valid_species.yaml +++ b/test/unit/v1/v1_unit_configs/species/valid_species.yaml @@ -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