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
4 changes: 2 additions & 2 deletions include/mechanism_configuration/types/reactions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ namespace mechanism_configuration::types
{
/// @brief Scaling factor to apply to user-provided rate constants
double scaling_factor{ 1.0 };
/// @brief A single reactant
ReactionComponent reactants;
/// @brief Reactants (at most one; empty for a pure production term, e.g. an emission)
std::vector<ReactionComponent> reactants;
/// @brief A list of products
std::vector<ReactionComponent> products;
/// @brief An identifier, optional, uniqueness not enforced
Expand Down
18 changes: 9 additions & 9 deletions src/v0/photolysis_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ namespace mechanism_configuration::v0
errors.insert(errors.end(), parse_error.begin(), parse_error.end());

double scaling_factor = object[keys::SCALING_FACTOR] ? object[keys::SCALING_FACTOR].as<double>() : 1.0;

if (!reactants.empty())
{
std::string name = object[keys::MUSICA_NAME].as<std::string>();
types::Photolysis user_defined = {
.scaling_factor = scaling_factor, .reactants = reactants[0], .products = products, .name = name
};
mechanism.reactions.photolysis.push_back(user_defined);
}
std::string name = object[keys::MUSICA_NAME].as<std::string>();

// Reactants may be empty: Music Box Interactive encodes emissions as a
// reactant-less photolysis (so they can carry an irr product). Keep the
// reaction rather than dropping it.
types::Photolysis user_defined = {
.scaling_factor = scaling_factor, .reactants = reactants, .products = products, .name = name
};
mechanism.reactions.photolysis.push_back(user_defined);
}

return errors;
Expand Down
2 changes: 1 addition & 1 deletion src/v1/reactions/photolysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace mechanism_configuration::v1
types::Photolysis photolysis;

photolysis.gas_phase = object[keys::gas_phase].as<std::string>();
photolysis.reactants = ParseReactionComponent(object, keys::reactants);
photolysis.reactants = ParseReactionComponents(object, keys::reactants);
photolysis.products = ParseReactionComponents(object, keys::products);
photolysis.unknown_properties = GetComments(object);

Expand Down
2 changes: 1 addition & 1 deletion src/validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ namespace mechanism_configuration
for (const auto& x : r.first_order_loss)
add("FIRST_ORDER_LOSS", x.gas_phase, Refs({ x.reactants }), Refs(x.products));
for (const auto& x : r.photolysis)
add("PHOTOLYSIS", x.gas_phase, Refs({ x.reactants }), Refs(x.products));
add("PHOTOLYSIS", x.gas_phase, Refs(x.reactants), Refs(x.products));
for (const auto& x : r.surface)
add("SURFACE", x.gas_phase, Refs({ x.gas_phase_species }), Refs(x.gas_phase_products));
for (const auto& x : r.branched)
Expand Down
16 changes: 13 additions & 3 deletions test/unit/v0/test_photolysis_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ TEST(PhotolysisConfig, ParseConfig)
Mechanism mechanism = *parsed;

auto& process_vector = mechanism.reactions.photolysis;
EXPECT_EQ(process_vector.size(), 2);
EXPECT_EQ(process_vector.size(), 3);

// first reaction
{
EXPECT_EQ(process_vector[0].reactants.name, "foo");
EXPECT_EQ(process_vector[0].reactants[0].name, "foo");
EXPECT_EQ(process_vector[0].products.size(), 2);
EXPECT_EQ(process_vector[0].products[0].name, "bar");
EXPECT_EQ(process_vector[0].products[0].coefficient, 1.0);
Expand All @@ -77,7 +77,7 @@ TEST(PhotolysisConfig, ParseConfig)

// second reaction
{
EXPECT_EQ(process_vector[1].reactants.name, "bar");
EXPECT_EQ(process_vector[1].reactants[0].name, "bar");
EXPECT_EQ(process_vector[1].products.size(), 2);
EXPECT_EQ(process_vector[1].products[0].name, "bar");
EXPECT_EQ(process_vector[1].products[0].coefficient, 0.5);
Expand All @@ -86,6 +86,16 @@ TEST(PhotolysisConfig, ParseConfig)
EXPECT_EQ(process_vector[1].name, "jbar");
EXPECT_EQ(process_vector[1].scaling_factor, 2.5);
}

// A photolysis reaction with no reactants (an emission encoded as photolysis)
// is kept, with an empty reactants list, rather than dropped.
{
EXPECT_EQ(process_vector[2].reactants.size(), 0);
ASSERT_EQ(process_vector[2].products.size(), 1);
EXPECT_EQ(process_vector[2].products[0].name, "foo");
EXPECT_EQ(process_vector[2].products[0].coefficient, 1.0);
EXPECT_EQ(process_vector[2].name, "jemis");
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/unit/v0/v0_unit_configs/photolysis/valid/reactions.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
},
"MUSICA name": "jbar",
"scaling factor": 2.5
},
{
"type": "PHOTOLYSIS",
"reactants": { },
"products": {
"foo": { "yield": 1.0 }
},
"MUSICA name": "jemis"
}
]
}
Expand Down
6 changes: 6 additions & 0 deletions test/unit/v0/v0_unit_configs/photolysis/valid/reactions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ camp-data:
bar: {}
scaling factor: 2.5
type: PHOTOLYSIS
- MUSICA name: jemis
products:
foo:
yield: 1.0
reactants: {}
type: PHOTOLYSIS
type: MECHANISM
8 changes: 4 additions & 4 deletions test/unit/v1/reactions/test_parse_photolysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ TEST(ParserBase, CanParseValidPhotolysisReaction)
EXPECT_EQ(mechanism.reactions.photolysis[0].gas_phase, "gas");
EXPECT_EQ(mechanism.reactions.photolysis[0].name, "my photolysis");
EXPECT_EQ(mechanism.reactions.photolysis[0].scaling_factor, 12.3);
EXPECT_EQ(mechanism.reactions.photolysis[0].reactants.name, "B");
EXPECT_EQ(mechanism.reactions.photolysis[0].reactants.coefficient, 1);
EXPECT_EQ(mechanism.reactions.photolysis[0].reactants[0].name, "B");
EXPECT_EQ(mechanism.reactions.photolysis[0].reactants[0].coefficient, 1);
EXPECT_EQ(mechanism.reactions.photolysis[0].products.size(), 1);
EXPECT_EQ(mechanism.reactions.photolysis[0].products[0].name, "C");
EXPECT_EQ(mechanism.reactions.photolysis[0].products[0].coefficient, 1);
Expand All @@ -34,8 +34,8 @@ TEST(ParserBase, CanParseValidPhotolysisReaction)

EXPECT_EQ(mechanism.reactions.photolysis[1].gas_phase, "gas");
EXPECT_EQ(mechanism.reactions.photolysis[1].scaling_factor, 1);
EXPECT_EQ(mechanism.reactions.photolysis[1].reactants.name, "B");
EXPECT_EQ(mechanism.reactions.photolysis[1].reactants.coefficient, 1.2);
EXPECT_EQ(mechanism.reactions.photolysis[1].reactants[0].name, "B");
EXPECT_EQ(mechanism.reactions.photolysis[1].reactants[0].coefficient, 1.2);
EXPECT_EQ(mechanism.reactions.photolysis[1].products.size(), 1);
EXPECT_EQ(mechanism.reactions.photolysis[1].products[0].name, "C");
EXPECT_EQ(mechanism.reactions.photolysis[1].products[0].coefficient, 0.2);
Expand Down
Loading