Skip to content

Commit

Permalink
Merge pull request #40 from open-atmos/main-formatting
Browse files Browse the repository at this point in the history
Auto-format code changes
  • Loading branch information
K20shores authored Jan 23, 2024
2 parents 16b121c + 05e6278 commit 04476b2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
12 changes: 8 additions & 4 deletions include/open_atmos/mechanism_configuration/validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace open_atmos

// Aqueous Equilibrium
const std::string AqueousPhaseEquilibrium_key = "AQUEOUS_EQUILIBRIUM";
// also
// also
// aerosol phase
// aerosol-phase water
// A
Expand Down Expand Up @@ -245,7 +245,8 @@ namespace open_atmos

struct SimpolPhaseTransfer
{
const std::vector<std::string> required_keys{ keys.type, keys.gas_phase, keys.gas_phase_species, keys.aerosol_phase, keys.aerosol_phase_species, keys.B };
const std::vector<std::string> required_keys{ keys.type, keys.gas_phase, keys.gas_phase_species, keys.aerosol_phase, keys.aerosol_phase_species,
keys.B };
const std::vector<std::string> optional_keys{ keys.name };
} simpol_phase_transfer;

Expand All @@ -257,13 +258,16 @@ namespace open_atmos

struct HenrysLaw
{
const std::vector<std::string> required_keys{ keys.type, keys.gas_phase, keys.gas_phase_species, keys.aerosol_phase, keys.aerosol_phase_species, keys.aerosol_phase_water };
const std::vector<std::string> required_keys{
keys.type, keys.gas_phase, keys.gas_phase_species, keys.aerosol_phase, keys.aerosol_phase_species, keys.aerosol_phase_water
};
const std::vector<std::string> optional_keys{ keys.name };
} henrys_law;

struct AqueousEquilibrium
{
const std::vector<std::string> required_keys{ keys.type, keys.reactants, keys.products, keys.aerosol_phase, keys.aerosol_phase_water, keys.k_reverse };
const std::vector<std::string> required_keys{ keys.type, keys.reactants, keys.products,
keys.aerosol_phase, keys.aerosol_phase_water, keys.k_reverse };
const std::vector<std::string> optional_keys{ keys.name, keys.A, keys.C };
} aqueous_equilibrium;
} // namespace validation
Expand Down
5 changes: 2 additions & 3 deletions include/open_atmos/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

#pragma once

#include <array>
#include <optional>
#include <string>
#include <unordered_map>
#include <array>
#include <vector>
#include <optional>


namespace open_atmos
{
Expand Down
42 changes: 23 additions & 19 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,6 @@ namespace open_atmos
status = ConfigParseStatus::ReactionRequiresUnknownSpecies;
}


std::string aerosol_phase = object[validation::keys.aerosol_phase].get<std::string>();
auto it =
std::find_if(existing_phases.begin(), existing_phases.end(), [&aerosol_phase](const auto& phase) { return phase.name == aerosol_phase; });
Expand Down Expand Up @@ -1362,7 +1361,7 @@ namespace open_atmos
unknown_properties[key] = val;
}

std::vector<std::string> requested_species {gas_phase_species, aerosol_phase_species};
std::vector<std::string> requested_species{ gas_phase_species, aerosol_phase_species };
if (status == ConfigParseStatus::Success && RequiresUnknownSpecies(requested_species, existing_species))
{
status = ConfigParseStatus::ReactionRequiresUnknownSpecies;
Expand All @@ -1375,12 +1374,15 @@ namespace open_atmos
{
status = ConfigParseStatus::UnknownPhase;
}
else {
else
{
auto phase = *aerosol_it;
auto spec_it = std::find_if(phase.species.begin(), phase.species.end(), [&aerosol_phase_species](const std::string& species){
return species == aerosol_phase_species;
});
if (spec_it == phase.species.end()) {
auto spec_it = std::find_if(
phase.species.begin(),
phase.species.end(),
[&aerosol_phase_species](const std::string& species) { return species == aerosol_phase_species; });
if (spec_it == phase.species.end())
{
status = ConfigParseStatus::ReactionRequiresUnknownSpecies;
}
}
Expand All @@ -1392,18 +1394,21 @@ namespace open_atmos
{
status = ConfigParseStatus::UnknownPhase;
}
else {
else
{
auto phase = *gas_it;
auto spec_it = std::find_if(phase.species.begin(), phase.species.end(), [&gas_phase_species](const std::string& species){
return species == gas_phase_species;
});
if (spec_it == phase.species.end()) {
auto spec_it = std::find_if(
phase.species.begin(), phase.species.end(), [&gas_phase_species](const std::string& species) { return species == gas_phase_species; });
if (spec_it == phase.species.end())
{
status = ConfigParseStatus::ReactionRequiresUnknownSpecies;
}
}

if (object.contains(validation::keys.B) && object[validation::keys.B].is_array() && object[validation::keys.B].size() == 4) {
for(size_t i = 0; i < 4; ++i) {
if (object.contains(validation::keys.B) && object[validation::keys.B].is_array() && object[validation::keys.B].size() == 4)
{
for (size_t i = 0; i < 4; ++i)
{
simpol_phase_transfer.B[i] = object[validation::keys.B][i];
}
}
Expand All @@ -1423,10 +1428,8 @@ namespace open_atmos
/// @param existing_species A list of species configured in a mechanism
/// @param existing_phases A list of phases configured in a mechanism
/// @return A pair indicating parsing success and a struct of Condensed Phase Arrhenius parameters
std::pair<ConfigParseStatus, types::AqueousEquilibrium> ParseAqueousEquilibrium(
const json& object,
const std::vector<types::Species>& existing_species,
const std::vector<types::Phase>& existing_phases)
std::pair<ConfigParseStatus, types::AqueousEquilibrium>
ParseAqueousEquilibrium(const json& object, const std::vector<types::Species>& existing_species, const std::vector<types::Phase>& existing_phases)
{
ConfigParseStatus status = ConfigParseStatus::Success;
types::AqueousEquilibrium aqueous_equilibrium;
Expand Down Expand Up @@ -1565,7 +1568,8 @@ namespace open_atmos
std::string aerosol_phase = object[validation::keys.aerosol_phase].get<std::string>();

// check if aerosol phase exists
auto it = std::find_if(existing_phases.begin(), existing_phases.end(), [&aerosol_phase](const auto& phase) { return phase.name == aerosol_phase; });
auto it =
std::find_if(existing_phases.begin(), existing_phases.end(), [&aerosol_phase](const auto& phase) { return phase.name == aerosol_phase; });
if (status == ConfigParseStatus::Success && it == existing_phases.end())
{
status = ConfigParseStatus::UnknownPhase;
Expand Down
3 changes: 2 additions & 1 deletion test/unit/test_parse_simpol_phase_transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ TEST(JsonParser, SimpolPhaseTransferDetectsUnknownGasPhaseSpeciesNotInGasPhase)
TEST(JsonParser, SimpolPhaseTransferDetectsUnknownAerosolPhaseSpeciesNotInAerosolPhase)
{
JsonParser parser;
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/simpol_phase_transfer/missing_aerosol_phase_species_in_aerosol_phase.json"));
auto [status, mechanism] =
parser.Parse(std::string("unit_configs/reactions/simpol_phase_transfer/missing_aerosol_phase_species_in_aerosol_phase.json"));
EXPECT_EQ(status, ConfigParseStatus::ReactionRequiresUnknownSpecies);
}

0 comments on commit 04476b2

Please sign in to comment.