Skip to content
Merged
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
15 changes: 9 additions & 6 deletions examples/v1/cam_cloud_chemistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"aerosol processes": [
{
"__comment": "Henry's Law Equilibrium: SO2(g) <-> SO2(aq)",
"__note": "HLC = HLC_ref * exp(C*(1/T - 1/T0))",
"type": "HENRY_LAW_EQUILIBRIUM",
"gas phase": "gas",
"gas-phase species": "SO2",
Expand All @@ -62,6 +63,7 @@
},
{
"__comment": "Henry's Law Equilibrium: H2O2(g) <-> H2O2(aq)",
"__note": "HLC = HLC_ref * exp(C*(1/T - 1/T0))",
"type": "HENRY_LAW_EQUILIBRIUM",
"gas phase": "gas",
"gas-phase species": "H2O2",
Expand All @@ -76,6 +78,7 @@
},
{
"__comment": "Henry's Law Equilibrium: O3(g) <-> O3(aq)",
"__note": "HLC = HLC_ref * exp(C*(1/T - 1/T0))",
"type": "HENRY_LAW_EQUILIBRIUM",
"gas phase": "gas",
"gas-phase species": "O3",
Expand Down Expand Up @@ -103,10 +106,10 @@
{ "name": "H2O", "coefficient": 1 }
],
"forward rate constants": {
"CLOUD": { "type": "ARRHENIUS", "A": 3.184e8, "C": 4430.0 }
"type": "ARRHENIUS", "A": 3.184e8, "C": 4430.0
},
"equilibrium constant": {
"type": "ARRHENIUS_REFERENCE_TEMPERATURE", "A": 1725.0, "C [K]": 0.0, "T0 [K]": 298.15
"type": "EQUILIBRIUM", "A": 1725.0, "C [K]": 0.0, "T0 [K]": 298.15

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there docs for this in mechanism configuration? If so we should update them

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
},
{
Expand All @@ -123,7 +126,7 @@
{ "name": "SO4mm", "coefficient": 1 }
],
"rate constants": {
"CLOUD": { "type": "ARRHENIUS", "A": 1.333e8, "C": 4430.0}
"type": "ARRHENIUS", "A": 1.333e8, "C": 4430.0
}
},
{
Expand All @@ -140,7 +143,7 @@
],
"algebraic species": "OHm",
"equilibrium constant": {
"type": "ARRHENIUS_REFERENCE_TEMPERATURE", "A": 3.24e-18, "C [K]": 0.0, "T0 [K]": 298.15
"type": "EQUILIBRIUM", "A": 3.24e-18, "C [K]": 0.0, "T0 [K]": 298.15
}
},
{
Expand All @@ -157,7 +160,7 @@
],
"algebraic species": "HSO3m",
"equilibrium constant": {
"type": "ARRHENIUS_REFERENCE_TEMPERATURE", "A": 3.06e-4, "C [K]": 2090.0, "T0 [K]": 298.15
"type": "EQUILIBRIUM", "A": 3.06e-4, "C [K]": 2090.0, "T0 [K]": 298.15
}
},
{
Expand All @@ -174,7 +177,7 @@
{ "name": "SO3mm", "coefficient": 1 }
],
"equilibrium constant": {
"type": "ARRHENIUS_REFERENCE_TEMPERATURE", "A": 1.08e-9, "C [K]": 1120.0, "T0 [K]": 298.15
"type": "EQUILIBRIUM", "A": 1.08e-9, "C [K]": 1120.0, "T0 [K]": 298.15
}
},
{
Expand Down
1 change: 0 additions & 1 deletion include/mechanism_configuration/errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ namespace mechanism_configuration
ReactionRequiresUnknownSpecies,
UnknownSpecies,
UnknownPhase,
UnknownAerosolRepresentation,
RequestedSpeciesNotRegisteredInPhase,
TooManyReactionComponents,
InvalidVersion,
Expand Down
24 changes: 10 additions & 14 deletions include/mechanism_configuration/types/aerosol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <mechanism_configuration/types/reactions.hpp>

#include <functional>
#include <map>
#include <optional>
#include <string>
#include <variant>
Expand All @@ -19,18 +18,17 @@ namespace mechanism_configuration::types
// Rate constants
// ----------------------------------------

/// @brief Reference-temperature Arrhenius
/// @brief Equilibrium constant with reference-temperature Arrhenius form
/// f(T) = A * exp( C * (1/T0 - 1/T) ) (C = +Ea/R, positive)
struct ArrheniusReferenceTemperature
struct Equilibrium
{
double A; ///< Value at the reference temperature T0 [units vary by use]
double C = 0.0; ///< Temperature-dependence parameter [K] (C = +Ea/R)
double T0 = 298.15; ///< Reference temperature [K]
};

/// @brief Henry's law constant: HLC(T) = HLC_ref * exp( C * (1/T - 1/T0) )
/// Same as ArrheniusReferenceTemperature but with the
/// opposite temperature trend (solubility rises as T falls)
/// Same as Equilibrium but with the opposite temperature trend
struct HenryLawConstant
{
double HLC_ref; ///< Reference HLC at T0 [mol m-3 Pa-1]
Expand All @@ -39,7 +37,7 @@ namespace mechanism_configuration::types
};

/// @brief A reaction rate constant parsed from config.
using RateConstant = std::variant<Arrhenius, ArrheniusReferenceTemperature, std::function<double(double)>>;
using RateConstant = std::variant<Arrhenius, Equilibrium, std::function<double(double)>>;

// ----------------------------------------
// Representations
Expand Down Expand Up @@ -80,8 +78,7 @@ namespace mechanism_configuration::types
std::string solvent;
std::vector<ReactionComponent> reactants;
std::vector<ReactionComponent> products;
/// @brief Rate constant per aerosol representation; keys are representation names.
std::map<std::string, RateConstant> rate_constants;
RateConstant rate_constants;
std::optional<double> solvent_floor_;
std::optional<double> min_halflife_;
};
Expand All @@ -92,12 +89,11 @@ namespace mechanism_configuration::types
std::string solvent;
std::vector<ReactionComponent> reactants;
std::vector<ReactionComponent> products;
/// @brief Per-representation forward / reverse rate constants; keys are representation names.
/// Supply exactly two of {forward, reverse, equilibrium} per representation; the third is derived.
std::map<std::string, RateConstant> forward_rate_constants;
std::map<std::string, RateConstant> reverse_rate_constants;
/// @brief Supply exactly two of {forward, reverse, equilibrium}; the third is derived.
std::optional<RateConstant> forward_rate_constants;
std::optional<RateConstant> reverse_rate_constants;
/// @brief Shared, intrinsic equilibrium constant (NOT per representation).
std::optional<ArrheniusReferenceTemperature> equilibrium_constant;
std::optional<Equilibrium> equilibrium_constant;
std::optional<double> solvent_floor_;
};

Expand Down Expand Up @@ -138,7 +134,7 @@ namespace mechanism_configuration::types
std::string solvent;
std::vector<ReactionComponent> reactants;
std::vector<ReactionComponent> products;
ArrheniusReferenceTemperature equilibrium_constant;
Equilibrium equilibrium_constant;
std::optional<double> solvent_floor_;
};

Expand Down
2 changes: 1 addition & 1 deletion src/detail/v1/aerosol/keys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace mechanism_configuration::v1::keys
inline constexpr std::string_view equilibrium_constant = "equilibrium constant";
inline constexpr std::string_view reference_temperature = "T0 [K]";

inline constexpr std::string_view ArrheniusReferenceTemperature_key = "ARRHENIUS_REFERENCE_TEMPERATURE";
inline constexpr std::string_view Equilibrium_key = "EQUILIBRIUM";

inline constexpr std::string_view henry_law_constant = "Henry's law constant";
inline constexpr std::string_view HLC_ref = "HLC_ref [mol m-3 Pa-1]";
Expand Down
9 changes: 2 additions & 7 deletions src/detail/v1/aerosol/parsers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <yaml-cpp/yaml.h>

#include <map>
#include <string>
#include <vector>

Expand All @@ -21,19 +20,15 @@ namespace mechanism_configuration::v1
// ----------------------------------------

types::HenryLawConstant ParseHenryLawConstant(const YAML::Node& object);
types::ArrheniusReferenceTemperature ParseArrheniusReferenceTemperature(const YAML::Node& object);
types::Equilibrium ParseEquilibrium(const YAML::Node& object);

/// @brief Parses a bare Arrhenius rate-constant block (A, B, C, D, E).
types::Arrhenius ParseArrhenius(const YAML::Node& object);

/// @brief Parses one rate-constant block into the RateConstant variant, dispatching on its
/// inner `type` (ARRHENIUS -> Arrhenius, ARRHENIUS_REFERENCE_TEMPERATURE -> Arrhenius reference temperature).
/// inner `type` (ARRHENIUS -> Arrhenius, EQUILIBRIUM -> Equilibrium constant).
types::RateConstant ParseRateConstant(const YAML::Node& object);

/// @brief Parses a per-representation rate-constant map, e.g. { "CLOUD": { ... } }.
/// @return Map keyed by representation name to its rate constant.
std::map<std::string, types::RateConstant> ParseRateConstantMap(const YAML::Node& object);

// ----------------------------------------
// Representation parsers
// ----------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace mechanism_configuration
case ErrorCode::ReactionRequiresUnknownSpecies: return "ReactionRequiresUnknownSpecies";
case ErrorCode::UnknownSpecies: return "UnknownSpecies";
case ErrorCode::UnknownPhase: return "UnknownPhase";
case ErrorCode::UnknownAerosolRepresentation: return "UnknownAerosolRepresentation";
case ErrorCode::RequestedSpeciesNotRegisteredInPhase: return "RequestedSpeciesNotRegisteredInPhase";
case ErrorCode::TooManyReactionComponents: return "TooManyReactionComponents";
case ErrorCode::InvalidVersion: return "InvalidVersion";
Expand Down
32 changes: 9 additions & 23 deletions src/v1/aerosol/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace mechanism_configuration::v1
// Rate constants parser
// ----------------------------------------

types::ArrheniusReferenceTemperature ParseArrheniusReferenceTemperature(const YAML::Node& object)
types::Equilibrium ParseEquilibrium(const YAML::Node& object)
{
types::ArrheniusReferenceTemperature rate_constant;
types::Equilibrium rate_constant;

rate_constant.A = object[keys::A].as<double>();
if (object[keys::henry_law_C])
Expand Down Expand Up @@ -47,8 +47,8 @@ namespace mechanism_configuration::v1

types::RateConstant ParseRateConstant(const YAML::Node& object)
{
if (object[keys::type] && object[keys::type].as<std::string>() == keys::ArrheniusReferenceTemperature_key)
return ParseArrheniusReferenceTemperature(object);
if (object[keys::type] && object[keys::type].as<std::string>() == keys::Equilibrium_key)
return ParseEquilibrium(object);

// ARRHENIUS is the default when no (recognized) type is given.
return ParseArrhenius(object);
Expand All @@ -67,20 +67,6 @@ namespace mechanism_configuration::v1
return henry_law_constant;
}

std::map<std::string, types::RateConstant> ParseRateConstantMap(const YAML::Node& object)
{
std::map<std::string, types::RateConstant> rate_constants;

// Each key is an aerosol representation name (e.g. "CLOUD"); each value is a rate-constant
// block whose own `type` selects the RateConstant variant alternative.
for (const auto& entry : object)
{
rate_constants.emplace(entry.first.as<std::string>(), ParseRateConstant(entry.second));
}

return rate_constants;
}

// ----------------------------------------
// Representation parsers
// ----------------------------------------
Expand Down Expand Up @@ -162,7 +148,7 @@ namespace mechanism_configuration::v1
reaction.solvent = object[keys::solvent].as<std::string>();
reaction.reactants = ParseReactionComponents(object, keys::reactants);
reaction.products = ParseReactionComponents(object, keys::products);
reaction.rate_constants = ParseRateConstantMap(object[keys::rate_constants]);
reaction.rate_constants = ParseRateConstant(object[keys::rate_constants]);

return reaction;
}
Expand All @@ -179,11 +165,11 @@ namespace mechanism_configuration::v1
// Any two of {forward, reverse, equilibrium} may be supplied; the third is derived
// downstream, so each is parsed only when present.
if (object[keys::forward_rate_constants])
reaction.forward_rate_constants = ParseRateConstantMap(object[keys::forward_rate_constants]);
reaction.forward_rate_constants = ParseRateConstant(object[keys::forward_rate_constants]);
if (object[keys::reverse_rate_constants])
reaction.reverse_rate_constants = ParseRateConstantMap(object[keys::reverse_rate_constants]);
reaction.reverse_rate_constants = ParseRateConstant(object[keys::reverse_rate_constants]);
if (object[keys::equilibrium_constant])
reaction.equilibrium_constant = ParseArrheniusReferenceTemperature(object[keys::equilibrium_constant]);
reaction.equilibrium_constant = ParseEquilibrium(object[keys::equilibrium_constant]);

return reaction;
}
Expand Down Expand Up @@ -225,7 +211,7 @@ namespace mechanism_configuration::v1
equilibrium.solvent = object[keys::solvent].as<std::string>();
equilibrium.reactants = ParseReactionComponents(object, keys::reactants);
equilibrium.products = ParseReactionComponents(object, keys::products);
equilibrium.equilibrium_constant = ParseArrheniusReferenceTemperature(object[keys::equilibrium_constant]);
equilibrium.equilibrium_constant = ParseEquilibrium(object[keys::equilibrium_constant]);

return equilibrium;
}
Expand Down
28 changes: 8 additions & 20 deletions src/v1/aerosol/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace mechanism_configuration::v1
{
namespace
{
Errors CheckArrheniusReferenceTemperatureSchema(const YAML::Node& object)
Errors CheckEquilibriumSchema(const YAML::Node& object)
{
const std::vector<std::string_view> required_keys = { keys::A, keys::henry_law_C };
const std::vector<std::string_view> optional_keys = { keys::type, keys::reference_temperature };
Expand All @@ -37,8 +37,8 @@ namespace mechanism_configuration::v1

Errors CheckRateConstantSchema(const YAML::Node& object)
{
if (object[keys::type] && object[keys::type].as<std::string>() == keys::ArrheniusReferenceTemperature_key)
return CheckArrheniusReferenceTemperatureSchema(object);
if (object[keys::type] && object[keys::type].as<std::string>() == keys::Equilibrium_key)
return CheckEquilibriumSchema(object);
return CheckArrheniusSchema(object);
}

Expand All @@ -49,18 +49,6 @@ namespace mechanism_configuration::v1
return CheckSchema(object, required_keys, optional_keys);
}

// A per-representation rate-constant map. Each value is a typed rate-constant block.
Errors CheckRateConstantMapSchema(const YAML::Node& object)
{
Errors errors;
for (const auto& entry : object)
{
auto entry_errors = CheckRateConstantSchema(entry.second);
errors.insert(errors.end(), entry_errors.begin(), entry_errors.end());
}
return errors;
}

// Each linear-constraint term references a species in a phase with a coefficient.
Errors CheckLinearConstraintTermsSchema(const YAML::Node& object)
{
Expand Down Expand Up @@ -178,7 +166,7 @@ namespace mechanism_configuration::v1
}
if (object[keys::rate_constants])
{
auto e = CheckRateConstantMapSchema(object[keys::rate_constants]);
auto e = CheckRateConstantSchema(object[keys::rate_constants]);
nested_errors.insert(nested_errors.end(), e.begin(), e.end());
}
}
Expand All @@ -198,17 +186,17 @@ namespace mechanism_configuration::v1
}
if (object[keys::forward_rate_constants])
{
auto e = CheckRateConstantMapSchema(object[keys::forward_rate_constants]);
auto e = CheckRateConstantSchema(object[keys::forward_rate_constants]);
nested_errors.insert(nested_errors.end(), e.begin(), e.end());
}
if (object[keys::reverse_rate_constants])
{
auto e = CheckRateConstantMapSchema(object[keys::reverse_rate_constants]);
auto e = CheckRateConstantSchema(object[keys::reverse_rate_constants]);
nested_errors.insert(nested_errors.end(), e.begin(), e.end());
}
if (object[keys::equilibrium_constant])
{
auto e = CheckArrheniusReferenceTemperatureSchema(object[keys::equilibrium_constant]);
auto e = CheckEquilibriumSchema(object[keys::equilibrium_constant]);
nested_errors.insert(nested_errors.end(), e.begin(), e.end());
}
}
Expand Down Expand Up @@ -247,7 +235,7 @@ namespace mechanism_configuration::v1
}
if (object[keys::equilibrium_constant])
{
auto e = CheckArrheniusReferenceTemperatureSchema(object[keys::equilibrium_constant]);
auto e = CheckEquilibriumSchema(object[keys::equilibrium_constant]);
nested_errors.insert(nested_errors.end(), e.begin(), e.end());
}
}
Expand Down
Loading
Loading