Skip to content

Commit

Permalink
Merge pull request #53 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 16, 2025
2 parents dae56fd + f4874c0 commit 0a6d1ad
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 69 deletions.
2 changes: 1 addition & 1 deletion include/open_atmos/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ namespace open_atmos
static constexpr double boltzmann = 1.380649e-23; // J K^{-1}
static constexpr double avogadro = 6.02214076e23; // # mol^{-1}
static constexpr double R = boltzmann * avogadro; // J K^{-1} mol^{-1}
} // namespace constants
} // namespace constants
} // namespace open_atmos
14 changes: 8 additions & 6 deletions include/open_atmos/mechanism_configuration/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

#pragma once

#include <open_atmos/mechanism_configuration/parse_status.hpp>
#include <open_atmos/types.hpp>
#include <open_atmos/mechanism_configuration/validation.hpp>
#include <yaml-cpp/yaml.h>

#include <iostream>
#include <open_atmos/mechanism_configuration/parse_status.hpp>
#include <open_atmos/mechanism_configuration/validation.hpp>
#include <open_atmos/types.hpp>
#include <string>
#include <unordered_map>
#include <vector>
#include <yaml-cpp/yaml.h>

namespace open_atmos
{
Expand All @@ -34,10 +34,12 @@ namespace open_atmos

ConfigParseStatus
ValidateSchema(const YAML::Node& object, const std::vector<std::string>& required_keys, const std::vector<std::string>& optional_keys);

std::pair<ConfigParseStatus, std::vector<types::Species>> ParseSpecies(const YAML::Node& objects);

std::pair<ConfigParseStatus, std::vector<types::Phase>> ParsePhases(const YAML::Node& objects, const std::vector<types::Species> existing_species);
std::pair<ConfigParseStatus, std::vector<types::Phase>> ParsePhases(
const YAML::Node& objects,
const std::vector<types::Species> existing_species);

std::pair<ConfigParseStatus, types::ReactionComponent> ParseReactionComponent(const YAML::Node& object);

Expand Down
1 change: 0 additions & 1 deletion include/open_atmos/mechanism_configuration/validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ namespace open_atmos
// aerosol phase
// aerosol-phase water
// aerosol-phase species

};

struct Mechanism
Expand Down
2 changes: 1 addition & 1 deletion include/open_atmos/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#pragma once

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

namespace open_atmos
Expand Down
2 changes: 1 addition & 1 deletion src/aqueous_equilibrium_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <open_atmos/constants.hpp>
#include <open_atmos/mechanism_configuration/parser.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>
#include <open_atmos/mechanism_configuration/parser_types.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>

namespace open_atmos
{
Expand Down
2 changes: 1 addition & 1 deletion src/arrhenius_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <open_atmos/constants.hpp>
#include <open_atmos/mechanism_configuration/parser.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>
#include <open_atmos/mechanism_configuration/parser_types.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>

namespace open_atmos
{
Expand Down
95 changes: 47 additions & 48 deletions src/branched_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <open_atmos/constants.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>
#include <open_atmos/mechanism_configuration/parser.hpp>
#include <open_atmos/mechanism_configuration/parser_types.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>

namespace open_atmos
{
Expand All @@ -13,62 +13,61 @@ namespace open_atmos
const std::vector<types::Phase>& existing_phases,
open_atmos::types::Reactions& reactions)
{
ConfigParseStatus status = ConfigParseStatus::Success;
types::Branched branched;

status = ValidateSchema(object, validation::branched.required_keys, validation::branched.optional_keys);
if (status == ConfigParseStatus::Success)
{
auto alkoxy_products = ParseReactantsOrProducts(validation::keys.alkoxy_products, object, status);
auto nitrate_products = ParseReactantsOrProducts(validation::keys.nitrate_products, object, status);
auto reactants = ParseReactantsOrProducts(validation::keys.reactants, object, status);
ConfigParseStatus status = ConfigParseStatus::Success;
types::Branched branched;

branched.X = object[validation::keys.X].as<double>();
branched.Y = object[validation::keys.Y].as<double>();
branched.a0 = object[validation::keys.a0].as<double>();
branched.n = object[validation::keys.n].as<double>();
status = ValidateSchema(object, validation::branched.required_keys, validation::branched.optional_keys);
if (status == ConfigParseStatus::Success)
{
auto alkoxy_products = ParseReactantsOrProducts(validation::keys.alkoxy_products, object, status);
auto nitrate_products = ParseReactantsOrProducts(validation::keys.nitrate_products, object, status);
auto reactants = ParseReactantsOrProducts(validation::keys.reactants, object, status);

if (object[validation::keys.name])
{
branched.name = object[validation::keys.name].as<std::string>();
}
branched.X = object[validation::keys.X].as<double>();
branched.Y = object[validation::keys.Y].as<double>();
branched.a0 = object[validation::keys.a0].as<double>();
branched.n = object[validation::keys.n].as<double>();

std::vector<std::string> requested_species;
for (const auto& spec : nitrate_products)
{
requested_species.push_back(spec.species_name);
}
for (const auto& spec : alkoxy_products)
{
requested_species.push_back(spec.species_name);
}
for (const auto& spec : reactants)
{
requested_species.push_back(spec.species_name);
}
if (object[validation::keys.name])
{
branched.name = object[validation::keys.name].as<std::string>();
}

if (status == ConfigParseStatus::Success && RequiresUnknownSpecies(requested_species, existing_species))
{
status = ConfigParseStatus::ReactionRequiresUnknownSpecies;
}
std::vector<std::string> requested_species;
for (const auto& spec : nitrate_products)
{
requested_species.push_back(spec.species_name);
}
for (const auto& spec : alkoxy_products)
{
requested_species.push_back(spec.species_name);
}
for (const auto& spec : reactants)
{
requested_species.push_back(spec.species_name);
}

std::string gas_phase = object[validation::keys.gas_phase].as<std::string>();
auto it = std::find_if(existing_phases.begin(), existing_phases.end(), [&gas_phase](const auto& phase) { return phase.name == gas_phase; });
if (status == ConfigParseStatus::Success && it == existing_phases.end())
{
status = ConfigParseStatus::UnknownPhase;
}
if (status == ConfigParseStatus::Success && RequiresUnknownSpecies(requested_species, existing_species))
{
status = ConfigParseStatus::ReactionRequiresUnknownSpecies;
}

branched.gas_phase = gas_phase;
branched.nitrate_products = nitrate_products;
branched.alkoxy_products = alkoxy_products;
branched.reactants = reactants;
branched.unknown_properties = GetComments(object, validation::branched.required_keys, validation::branched.optional_keys);
reactions.branched.push_back(branched);
std::string gas_phase = object[validation::keys.gas_phase].as<std::string>();
auto it = std::find_if(existing_phases.begin(), existing_phases.end(), [&gas_phase](const auto& phase) { return phase.name == gas_phase; });
if (status == ConfigParseStatus::Success && it == existing_phases.end())
{
status = ConfigParseStatus::UnknownPhase;
}

return status;
branched.gas_phase = gas_phase;
branched.nitrate_products = nitrate_products;
branched.alkoxy_products = alkoxy_products;
branched.reactants = reactants;
branched.unknown_properties = GetComments(object, validation::branched.required_keys, validation::branched.optional_keys);
reactions.branched.push_back(branched);
}

return status;
}
} // namespace mechanism_configuration
} // namespace open_atmos
2 changes: 1 addition & 1 deletion src/condensed_phase_arrhenius_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <open_atmos/constants.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>
#include <open_atmos/mechanism_configuration/parser.hpp>
#include <open_atmos/mechanism_configuration/parser_types.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>

namespace open_atmos
{
Expand Down
2 changes: 1 addition & 1 deletion src/henrys_law_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <open_atmos/constants.hpp>
#include <open_atmos/mechanism_configuration/parser.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>
#include <open_atmos/mechanism_configuration/parser_types.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>

namespace open_atmos
{
Expand Down
4 changes: 2 additions & 2 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <yaml-cpp/yaml.h>

#include <open_atmos/constants.hpp>
#include <open_atmos/mechanism_configuration/validation.hpp>
#include <open_atmos/mechanism_configuration/version.hpp>
#include <open_atmos/mechanism_configuration/parser.hpp>
#include <open_atmos/mechanism_configuration/parser_types.hpp>
#include <open_atmos/mechanism_configuration/validation.hpp>
#include <open_atmos/mechanism_configuration/version.hpp>

namespace open_atmos
{
Expand Down
2 changes: 1 addition & 1 deletion src/troe_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <open_atmos/constants.hpp>
#include <open_atmos/mechanism_configuration/parser.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>
#include <open_atmos/mechanism_configuration/parser_types.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>

namespace open_atmos
{
Expand Down
6 changes: 3 additions & 3 deletions src/wet_deposition_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <open_atmos/constants.hpp>
#include <open_atmos/mechanism_configuration/parser.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>
#include <open_atmos/mechanism_configuration/parser_types.hpp>
#include <open_atmos/mechanism_configuration/utils.hpp>

namespace open_atmos
{
Expand Down Expand Up @@ -31,8 +31,8 @@ namespace open_atmos

std::string aerosol_phase = object[validation::keys.aerosol_phase].as<std::string>();

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_condensed_phase_photolysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ TEST(Parser, CondensedPhasePhotolysisDetectsWhenRequestedSpeciesAreNotInAerosolP
std::vector<std::string> extensions = { ".json", ".yaml" };
for (auto& extension : extensions)
{
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/condensed_phase_photolysis/species_not_in_aerosol_phase") + extension);
auto [status, mechanism] =
parser.Parse(std::string("unit_configs/reactions/condensed_phase_photolysis/species_not_in_aerosol_phase") + extension);
EXPECT_EQ(status, ConfigParseStatus::RequestedAerosolSpeciesNotIncludedInAerosolPhase);
}
}
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 @@ -78,7 +78,8 @@ TEST(Parser, SimpolPhaseTransferDetectsUnknownGasPhaseSpeciesNotInGasPhase)
std::vector<std::string> extensions = { ".json", ".yaml" };
for (auto& extension : extensions)
{
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/simpol_phase_transfer/missing_gas_phase_species_in_gas_phase") + extension);
auto [status, mechanism] =
parser.Parse(std::string("unit_configs/reactions/simpol_phase_transfer/missing_gas_phase_species_in_gas_phase") + extension);
EXPECT_EQ(status, ConfigParseStatus::ReactionRequiresUnknownSpecies);
}
}
Expand Down

0 comments on commit 0a6d1ad

Please sign in to comment.