Skip to content

Commit

Permalink
start wet deposition
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Jan 19, 2024
1 parent 997be71 commit 027a7ed
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/open_atmos/mechanism_configuration/validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ namespace open_atmos
const std::string FirstOrderLoss_key = "FIRST_ORDER_LOSS";
// also scaling factor

// Wet Deposition
const std::string WetDeposition_key = "WET_DEPOSITION";
// also
// scaling factor
// aerosol phase
// gas phase

} keys;

struct Configuration
Expand Down Expand Up @@ -197,6 +204,12 @@ namespace open_atmos
const std::vector<std::string> optional_keys{ keys.name, keys.scaling_factor };
} first_order_loss;

struct WetDeposition
{
const std::vector<std::string> required_keys{ keys.gas_phase, keys.aerosol_phase, keys.type };
const std::vector<std::string> optional_keys{ keys.name, keys.scaling_factor };
} wet_deposition;

struct Mechanism
{
const std::vector<std::string> required_keys{};
Expand Down
15 changes: 15 additions & 0 deletions include/open_atmos/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ namespace open_atmos
std::unordered_map<std::string, std::string> unknown_properties;
};

struct WetDeposition
{
/// @brief Scaling factor to apply to user-provided rate constants
double scaling_factor_{ 1.0 };
/// @brief An identifier, optional, uniqueness not enforced
std::string name;
/// @brief An identifier indicating which gas phase this reaction takes place in
std::string gas_phase;
/// @brief An identifier indicating which aerosol phase this reaction takes place in
std::string aerosol_phase;
/// @brief Unknown properties, prefixed with two underscores (__)
std::unordered_map<std::string, std::string> unknown_properties;
};

struct Reactions
{
std::vector<types::Arrhenius> arrhenius;
Expand All @@ -234,6 +248,7 @@ namespace open_atmos
std::vector<types::Photolysis> photolysis;
std::vector<types::Emission> emission;
std::vector<types::FirstOrderLoss> first_order_loss;
std::vector<types::WetDeposition> wet_deposition;
};

struct Mechanism
Expand Down
10 changes: 10 additions & 0 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,16 @@ namespace open_atmos
}
reactions.first_order_loss.push_back(first_order_loss_parse.second);
}
else if (type == validation::keys.WetDeposition_key)
{
auto wet_deposition_parse = ParseWetDeposition(object, existing_species, existing_phases);
status = wet_deposition_parse.first;
if (status != ConfigParseStatus::Success)
{
break;
}
reactions.wet_deposition.push_back(wet_deposition_parse.second);
}
}

return { status, reactions };
Expand Down
1 change: 1 addition & 0 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ create_standard_test(NAME parse_species SOURCES test_parse_species.cpp)
create_standard_test(NAME parse_surface SOURCES test_parse_surface.cpp)
create_standard_test(NAME parse_troe SOURCES test_parse_troe.cpp)
create_standard_test(NAME parse_tunneling SOURCES test_parse_tunneling.cpp)
create_standard_test(NAME parse_wet_deposition SOURCES test_parse_wet_deposition.cpp)

################################################################################
# Copy test data
Expand Down
47 changes: 47 additions & 0 deletions test/unit/test_parse_wet_deposition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <gtest/gtest.h>

#include <open_atmos/mechanism_configuration/parser.hpp>

using namespace open_atmos::mechanism_configuration;

TEST(JsonParser, CanParseValidWetDepositionReaction)
{
JsonParser parser;
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/wet_deposition/valid.json"));
EXPECT_EQ(status, ConfigParseStatus::Success);

EXPECT_EQ(mechanism.reactions.wet_deposition.size(), 1);

EXPECT_EQ(mechanism.reactions.wet_deposition[0].name, "my arrhenius");
EXPECT_EQ(mechanism.reactions.wet_deposition[0].gas_phase, "gas");
EXPECT_EQ(mechanism.reactions.wet_deposition[0].unknown_properties.size(), 1);
EXPECT_EQ(mechanism.reactions.wet_deposition[0].unknown_properties["__solver_param"], "0.1");
}

TEST(JsonParser, WetDepositionDetectsUnknownSpecies)
{
JsonParser parser;
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/wet_deposition/unknown_species.json"));
EXPECT_EQ(status, ConfigParseStatus::ReactionRequiresUnknownSpecies);
}

TEST(JsonParser, WetDepositionDetectsMutuallyExclusiveOptions)
{
JsonParser parser;
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/wet_deposition/mutually_exclusive.json"));
EXPECT_EQ(status, ConfigParseStatus::MutuallyExclusiveOption);
}

TEST(JsonParser, WetDepositionDetectsBadReactionComponent)
{
JsonParser parser;
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/wet_deposition/bad_reaction_component.json"));
EXPECT_EQ(status, ConfigParseStatus::RequiredKeyNotFound);
}

TEST(JsonParser, WetDepositionDetectsUnknownPhase)
{
JsonParser parser;
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/wet_deposition/missing_phase.json"));
EXPECT_EQ(status, ConfigParseStatus::UnknownPhase);
}

0 comments on commit 027a7ed

Please sign in to comment.