Skip to content
Open
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
11 changes: 7 additions & 4 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 @@ -106,7 +109,7 @@
"CLOUD": { "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

}
},
{
Expand Down Expand Up @@ -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
13 changes: 6 additions & 7 deletions include/mechanism_configuration/types/aerosol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,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 +38,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 @@ -97,7 +96,7 @@ namespace mechanism_configuration::types
std::map<std::string, RateConstant> forward_rate_constants;
std::map<std::string, 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 +137,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
4 changes: 2 additions & 2 deletions src/detail/v1/aerosol/parsers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ 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": { ... } }.
Expand Down
12 changes: 6 additions & 6 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 Down Expand Up @@ -183,7 +183,7 @@ namespace mechanism_configuration::v1
if (object[keys::reverse_rate_constants])
reaction.reverse_rate_constants = ParseRateConstantMap(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 +225,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
10 changes: 5 additions & 5 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 Down Expand Up @@ -208,7 +208,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 Expand Up @@ -247,7 +247,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
4 changes: 2 additions & 2 deletions test/unit/test_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ TEST(ValidateAerosol, AcceptsValidProcessesAndConstraints)
reaction.solvent = "H2O";
reaction.reactants = { component("A") };
reaction.products = { component("A") };
reaction.rate_constants = { { "cloud", types::ArrheniusReferenceTemperature{} } }; // keyed by a declared representation
reaction.rate_constants = { { "cloud", types::Equilibrium{} } }; // keyed by a declared representation
m.aerosol->processes.push_back(reaction);

m.aerosol->constraints = { ValidEquilibrium() };
Expand Down Expand Up @@ -287,7 +287,7 @@ TEST(ValidateAerosol, DetectsRateConstantKeyedByUnknownRepresentation)
reaction.solvent = "H2O";
reaction.reactants = { component("A") };
reaction.products = { component("A") };
reaction.rate_constants = { { "not_a_representation", types::ArrheniusReferenceTemperature{} } };
reaction.rate_constants = { { "not_a_representation", types::Equilibrium{} } };
m.aerosol->processes = { reaction };

EXPECT_TRUE(HasCode(ValidateAerosolModel(m), ErrorCode::UnknownAerosolRepresentation));
Expand Down
Loading