Introduce aerosol chemistry validation and parser support#282
Introduce aerosol chemistry validation and parser support#282boulderdaze wants to merge 25 commits into
Conversation
Co-authored-by: Kyle Shores <kyle.shores44@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #282 +/- ##
=======================================
Coverage 31.57% 31.57%
=======================================
Files 4 4
Lines 19 19
=======================================
Hits 6 6
Misses 13 13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| { | ||
| namespace | ||
| { | ||
| Errors CheckArrheniusReferenceTemperatureSchema(const YAML::Node& object) |
There was a problem hiding this comment.
in the gas-phase parsing, we include this stuff directly in the parse function. Any reason we are doing it here?
There was a problem hiding this comment.
The one in the gas-phase parser for arrhenius includes A,B,C,D,E as well as the phase, reactants and products.
The aerosol model defines rate constant to calculate equilibrium rate constant in the form of arrhenius expression, but it only takes A, C values. This configuration calls micm::CalculateArrhenius in miam implementation, which is why it remains as arrhneinus struct in aerosol types.
On the other hand, henrys law constant uses a reference temperature, which uses van't hoff equation to calculate the rate constant. It depends on temperature difference. That's why the ArrheniusReferenceTemperature type was crated.
The direct answer to your question is that the required and optional keys should be different.
Errors CheckArrheniusSchema(const YAML::Node& object)
{
const std::vector<std::string_view> required_keys = { keys::A, keys::C };
const std::vector<std::string_view> optional_keys = { keys::type };
return CheckSchema(object, required_keys, optional_keys);
}There was a problem hiding this comment.
Ah, that wasn't my question. My question is why the schema checks are here and not in src/v1/aerosol_type_parsers.cpp. All of the gas phase checks have their schema checks include in the parsers.
K20shores
left a comment
There was a problem hiding this comment.
A couple of comments, but nothing that should hold up a merge. There's only one comment that wouldn't be addressed by a future issue anyway. If you like the way things look now, I'm happy to accept it
| { | ||
| std::string name; | ||
| std::optional<double> diffusion_coefficient; | ||
| std::optional<double> density; |
There was a problem hiding this comment.
do we know what this is? Is this just the molecular weight? If so, it's duplicated in the species
There was a problem hiding this comment.
It is the density of a species in a given phase, so it's expected to be different for solids, liquids, etc.
"name": "AQUEOUS",
"species": [
"SO2", "H2O2", "O3", "Hp", "OHm", "HSO3m", "SO3mm", "SO4mm", "SO2OOHm",
{ "name": "H2O", "density [kg m-3]": 997.0 }
]| // Aerosol cross-references are validated separately by ValidateAerosolModel, which works on the | ||
| // domain structs directly because it needs phase membership and optional-property values that | ||
| // this name-only view cannot carry. |
There was a problem hiding this comment.
The semantic input for an aerosol model doesn't yet exist. I suggest we do that as part of this PR, and then we can operate on the semantic inputs and share structural validation between in-code mechanisms and parsed mechanisms.
There was a problem hiding this comment.
This work requires to restructure *Def classes. Right now, they only store values in flat arrays without any information about relationships (which species belong to which phases or where the solvent is). I think the restrucuting work is outside the scope of this PR. As mentioned in the comments, we can track it separately in the issue:
| { | ||
| namespace | ||
| { | ||
| Errors CheckArrheniusReferenceTemperatureSchema(const YAML::Node& object) |
There was a problem hiding this comment.
Ah, that wasn't my question. My question is why the schema checks are here and not in src/v1/aerosol_type_parsers.cpp. All of the gas phase checks have their schema checks include in the parsers.
| return errors; | ||
| } | ||
|
|
||
| Errors CheckAerosolProcessesSchema(const YAML::Node& processes_list) |
There was a problem hiding this comment.
To me this reads like each of the types could be their own functions that we dispatch, similar to how we do for each different reaction type. Do you prefer this apporach?
| // Uses the same ValidateSemantics engine as ValidateGasModel, but with | ||
| // YAML-derived input so errors include source locations. |
There was a problem hiding this comment.
ValidateGasModel also includes line information because we have the semantic reference inputs, which I feel we should also add for aerosols
There was a problem hiding this comment.
The gas model can store them in a flat array without relationship information unlike aerosol.
| // pair 'aerosol representations' + 'aerosol processes'. The two modes may also coexist. | ||
| const bool has_reactions = static_cast<bool>(object[keys::reactions]); | ||
| const bool has_aerosol_representations = static_cast<bool>(object[keys::aerosol_representations]); | ||
| const bool has_aerosol_processes = static_cast<bool>(object[keys::aerosol_processes]); |
There was a problem hiding this comment.
We need to replicate these checks in src/validate.cpp so that in-code mechanisms also have this checked
This PR:
Mechanism#271Notes:
Validatefunction intoValidateGasModeland introduced a separateValidateAerosolModel.During aerosol validation, the relationship between phases and species(eg. condensed phase and species, gas phase and species, solvent, molecular weight, density ) cannot be expressed in the current
semantics::Inputbecause the required relationship information is lost during flattening. It does not preserve which species belongs to which phase.The intermediate type that I tried to introduced
AerosolProcessRefalso loses the structure by dropping the association between a specific species and its phase context.The current aerosol validation cannot preserve the error locations for the reasons above. This will be addressed in #284