Skip to content

Commit

Permalink
correcting emissions
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Jan 19, 2024
1 parent 8a308bc commit f852fcc
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion examples/full_configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
{
"type": "EMISSION",
"gas phase": "gas",
"reactants": [
"products": [
{
"species name": "B",
"coefficient": 1
Expand Down
2 changes: 1 addition & 1 deletion include/open_atmos/mechanism_configuration/validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace open_atmos

struct Emission
{
const std::vector<std::string> required_keys{ keys.reactants, keys.type, keys.gas_phase };
const std::vector<std::string> required_keys{ keys.products, keys.type, keys.gas_phase };
const std::vector<std::string> optional_keys{ keys.name, keys.scaling_factor };
} emission;

Expand Down
4 changes: 2 additions & 2 deletions include/open_atmos/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ namespace open_atmos
{
/// @brief Scaling factor to apply to user-provided rate constants
double scaling_factor_{ 1.0 };
/// @brief A list of reactants
std::vector<ReactionComponent> reactants;
/// @brief A list of products
std::vector<ReactionComponent> products;
/// @brief An identifier, optional, uniqueness not enforced
std::string name;
/// @brief An identifier indicating which gas phase this reaction takes place in
Expand Down
14 changes: 7 additions & 7 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,16 +886,16 @@ namespace open_atmos
status = ValidateSchema(object, validation::emission.required_keys, validation::emission.optional_keys);
if (status == ConfigParseStatus::Success)
{
std::vector<types::ReactionComponent> reactants{};
for (const auto& reactant : object[validation::keys.reactants])
std::vector<types::ReactionComponent> products{};
for (const auto& product : object[validation::keys.products])
{
auto reactant_parse = ParseReactionComponent(reactant);
status = reactant_parse.first;
auto product_parse = ParseReactionComponent(product);
status = product_parse.first;
if (status != ConfigParseStatus::Success)
{
break;
}
reactants.push_back(reactant_parse.second);
products.push_back(product_parse.second);
}

if (object.contains(validation::keys.scaling_factor))
Expand All @@ -918,7 +918,7 @@ namespace open_atmos
}

std::vector<std::string> requested_species;
for (const auto& spec : reactants)
for (const auto& spec : products)
{
requested_species.push_back(spec.species_name);
}
Expand All @@ -937,7 +937,7 @@ namespace open_atmos
}

emission.gas_phase = gas_phase;
emission.reactants = reactants;
emission.products = products;
emission.unknown_properties = unknown_properties;
}

Expand Down
12 changes: 6 additions & 6 deletions test/unit/test_parse_emission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ TEST(JsonParser, CanParseValidEmissionReaction)
EXPECT_EQ(mechanism.reactions.emission[0].gas_phase, "gas");
EXPECT_EQ(mechanism.reactions.emission[0].name, "my emission");
EXPECT_EQ(mechanism.reactions.emission[0].scaling_factor_, 12.3);
EXPECT_EQ(mechanism.reactions.emission[0].reactants.size(), 1);
EXPECT_EQ(mechanism.reactions.emission[0].reactants[0].species_name, "B");
EXPECT_EQ(mechanism.reactions.emission[0].reactants[0].coefficient, 1);
EXPECT_EQ(mechanism.reactions.emission[0].products.size(), 1);
EXPECT_EQ(mechanism.reactions.emission[0].products[0].species_name, "B");
EXPECT_EQ(mechanism.reactions.emission[0].products[0].coefficient, 1);
EXPECT_EQ(mechanism.reactions.emission[0].unknown_properties.size(), 1);
EXPECT_EQ(mechanism.reactions.emission[0].unknown_properties["__comment"], "\"Dr. Pepper outranks any other soda\"");

EXPECT_EQ(mechanism.reactions.emission[1].gas_phase, "gas");
EXPECT_EQ(mechanism.reactions.emission[1].scaling_factor_, 1);
EXPECT_EQ(mechanism.reactions.emission[1].reactants.size(), 1);
EXPECT_EQ(mechanism.reactions.emission[1].reactants[0].species_name, "B");
EXPECT_EQ(mechanism.reactions.emission[1].reactants[0].coefficient, 1);
EXPECT_EQ(mechanism.reactions.emission[1].products.size(), 1);
EXPECT_EQ(mechanism.reactions.emission[1].products[0].species_name, "B");
EXPECT_EQ(mechanism.reactions.emission[1].products[0].coefficient, 1);
}

TEST(JsonParser, EmissionDetectsUnknownSpecies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{
"type": "EMISSION",
"gas phase": "gas",
"reactants": [
"products": [
{
"Species name": "C"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"type": "EMISSION",
"gas phase": "gas",
"reactants": [
"products": [
{
"species name": "C"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{
"type": "EMISSION",
"gas phase": "gas",
"reactants": [
"products": [
{
"species name": "C"
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/unit_configs/reactions/emission/valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"type": "EMISSION",
"gas phase": "gas",
"reactants": [
"products": [
{
"species name": "B",
"coefficient": 1
Expand All @@ -47,7 +47,7 @@
{
"type": "EMISSION",
"gas phase": "gas",
"reactants": [
"products": [
{
"species name": "B"
}
Expand Down

0 comments on commit f852fcc

Please sign in to comment.