Skip to content
Closed
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
13 changes: 11 additions & 2 deletions src/v0/photolysis_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ 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;
std::string name = object[keys::MUSICA_NAME].as<std::string>();

if (!reactants.empty())
if (reactants.empty())
{
// A photolysis reaction with no reactants is a pure production term --
// Music Box Interactive encodes emissions this way (as a photolysis so
// they can carry an irr product). Represent it as an emission, which has
// no reactant, so it is not silently dropped.
types::Emission emission = { .scaling_factor = scaling_factor, .products = products, .name = name };
mechanism.reactions.emission.push_back(emission);
}
else
{
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
};
Expand Down
9 changes: 9 additions & 0 deletions test/unit/v0/test_photolysis_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ 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 as an emission rather than dropped.
auto& emissions = mechanism.reactions.emission;
ASSERT_EQ(emissions.size(), 1);
EXPECT_EQ(emissions[0].name, "jemis");
ASSERT_EQ(emissions[0].products.size(), 1);
EXPECT_EQ(emissions[0].products[0].name, "foo");
EXPECT_EQ(emissions[0].products[0].coefficient, 1.0);
}
}

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
Loading