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
4 changes: 2 additions & 2 deletions examples/v1/full_configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@
"name": "aitken",
"geometric mean diameter [m]": 2.6e-8,
"geometric standard deviation": 1.6,
"phase": "aqueous"
"phases": "aqueous"
},
{
"name": "accumulation",
"geometric mean diameter [m]": 1.1e-7,
"geometric standard deviation": 1.8,
"phase": "aqueous"
"phases": ["aqueous", "organic"]
}
]
}
Expand Down
9 changes: 7 additions & 2 deletions examples/v1/full_configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ phases:
species:
- B
- C

models:
- name: gas
type: GAS_PHASE
Expand All @@ -75,12 +76,16 @@ models:
- name: aitken
geometric mean diameter [m]: 2.6e-8
geometric standard deviation: 1.6
phase: aqueous
phases:
- aqueous

- name: accumulation
geometric mean diameter [m]: 1.1e-7
geometric standard deviation: 1.8
phase: aqueous
phases:
- aqueous
- cloud

reactions:
- type: HL_PHASE_TRANSFER
gas:
Expand Down
2 changes: 1 addition & 1 deletion include/mechanism_configuration/v1/model_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace mechanism_configuration
std::string name;
double geometric_mean_diameter;
double geometric_standard_deviation;
std::string phase;
std::vector<std::string> phases;
/// @brief Unknown properties, prefixed with two underscores (__)
std::unordered_map<std::string, std::string> unknown_properties;
};
Expand Down
2 changes: 1 addition & 1 deletion include/mechanism_configuration/v1/validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace mechanism_configuration
static constexpr const char* geometric_standard_deviation = "geometric standard deviation";
// also
// name
// phase
// phases

} // namespace validation
} // namespace v1
Expand Down
28 changes: 16 additions & 12 deletions src/v1/models/modal_model_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace mechanism_configuration
std::vector<std::string> optional_top_level_keys = { validation::name };

std::vector<std::string> required_second_level_keys = {
validation::name, validation::geometric_mean_diameter, validation::geometric_standard_deviation, validation::phase
validation::name, validation::geometric_mean_diameter, validation::geometric_standard_deviation, validation::phases
};
std::vector<std::string> optional_second_level_keys = {};

Expand Down Expand Up @@ -63,20 +63,24 @@ namespace mechanism_configuration
mode.name = mode_object[validation::name].as<std::string>();
mode.geometric_mean_diameter = mode_object[validation::geometric_mean_diameter].as<double>();
mode.geometric_standard_deviation = mode_object[validation::geometric_standard_deviation].as<double>();
mode.phases.reserve(mode_object[validation::phases].size());

// Check whether the phase for the mode is valid by comparing it to the initialized phases
std::string mode_phase = mode_object[validation::phase].as<std::string>();
auto it_found_phase =
std::find_if(existing_phases.begin(), existing_phases.end(), [&mode_phase](const auto& phase) { return phase.name == mode_phase; });
if (it_found_phase == existing_phases.end())
for (const auto& phase_object : mode_object[validation::phases])
{
std::string line = std::to_string(mode_object[validation::phase].Mark().line + 1);
std::string column = std::to_string(mode_object[validation::phase].Mark().column + 1);
errors.push_back({ ConfigParseStatus::UnknownPhase, line + ":" + column + ": Unknown phase: " + mode_phase });
}
else
{
mode.phase = mode_phase;
std::string mode_phase = phase_object.as<std::string>();
auto it_found_phase =
std::find_if(existing_phases.begin(), existing_phases.end(), [&mode_phase](const auto& phase) { return phase.name == mode_phase; });
if (it_found_phase == existing_phases.end())
{
std::string line = std::to_string(phase_object.Mark().line + 1);
std::string column = std::to_string(phase_object.Mark().column + 1);
errors.push_back({ ConfigParseStatus::UnknownPhase, line + ":" + column + ": Unknown phase: " + mode_phase });
}
else
{
mode.phases.emplace_back(mode_phase);
}
}

mode.unknown_properties = GetComments(mode_object);
Expand Down
9 changes: 7 additions & 2 deletions test/unit/v1/models/test_parse_modal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ TEST(ParserBase, CanParseValidModalModel)
{
v1::Parser parser;
std::vector<std::string> extensions = { ".json", ".yaml" };

for (auto& extension : extensions)
{
auto parsed = parser.Parse(std::string("v1_unit_configs/models/modal/valid") + extension);
EXPECT_TRUE(parsed);

v1::types::Mechanism mechanism = *parsed;

EXPECT_EQ(mechanism.models.modal_model.type, "MODAL");
Expand All @@ -20,14 +22,17 @@ TEST(ParserBase, CanParseValidModalModel)
EXPECT_EQ(mechanism.models.modal_model.modes[0].name, "aitken");
EXPECT_EQ(mechanism.models.modal_model.modes[0].geometric_mean_diameter, 2.6e-8);
EXPECT_EQ(mechanism.models.modal_model.modes[0].geometric_standard_deviation, 1.6);
EXPECT_EQ(mechanism.models.modal_model.modes[0].phase, "aqueous");
EXPECT_EQ(mechanism.models.modal_model.modes[0].phases.size(), 1);
EXPECT_EQ(mechanism.models.modal_model.modes[0].phases[0], "aqueous");
EXPECT_EQ(mechanism.models.modal_model.modes[0].unknown_properties.size(), 1);
EXPECT_EQ(mechanism.models.modal_model.modes[0].unknown_properties["__comment"], "Aitken mode");

EXPECT_EQ(mechanism.models.modal_model.modes[1].name, "accumulation");
EXPECT_EQ(mechanism.models.modal_model.modes[1].geometric_mean_diameter, 1.1e-7);
EXPECT_EQ(mechanism.models.modal_model.modes[1].geometric_standard_deviation, 1.8);
EXPECT_EQ(mechanism.models.modal_model.modes[1].phase, "aqueous");
EXPECT_EQ(mechanism.models.modal_model.modes[1].phases.size(), 2);
EXPECT_EQ(mechanism.models.modal_model.modes[1].phases[0], "aqueous");
EXPECT_EQ(mechanism.models.modal_model.modes[1].phases[1], "organic");
EXPECT_EQ(mechanism.models.modal_model.modes[1].unknown_properties.size(), 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@
{
"name": "aitken",
"geometric mean diameter [m]": 2.6e-8,
"phase": "aqueous",
"phases": ["aqueous"],
"__comment": "Aitken mode"
},
{
"name": "accumulation",
"geometric mean diameter [m]": 1.1e-7,
"phase": "aqueous"
"phases": ["aqueous"]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ models:
modes:
- name: aitken
geometric mean diameter [m]: 2.6e-8
phase: aqueous
phases:
- aqueous
__comment: Aitken mode

- name: accumulation
geometric mean diameter [m]: 1.1e-7
phase: aqueous
phases:
- aqueous

reactions:
- type: HL_PHASE_TRANSFER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
"name": "aitken",
"geometric mean diameter [m]": 2.6e-8,
"geometric standard deviation": 1.6,
"phase": "aqueous",
"phases": ["aqueous"],
"__comment": "Aitken mode"
},
{
"name": "accumulation",
"geometric mean diameter [m]": 1.1e-7,
"geometric standard deviation": 1.6,
"phase": "organic"
"phases": ["organic"]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ models:
- name: aitken
geometric mean diameter [m]: 2.6e-8
geometric standard deviation: 1.6
phase: aqueous
phases:
- aqueous
__comment: Aitken mode

- name: accumulation
geometric mean diameter [m]: 1.1e-7
geometric standard deviation: 1.6
phase: organic
phases:
- organic

reactions:
- type: HL_PHASE_TRANSFER
Expand Down
10 changes: 8 additions & 2 deletions test/unit/v1/v1_unit_configs/models/modal/valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
"O3",
"H2O2"
]
},
{
"name": "organic",
"species": [
"organic carbon"
]
}
],
"models": [
Expand All @@ -85,14 +91,14 @@
"name": "aitken",
"geometric mean diameter [m]": 2.6e-8,
"geometric standard deviation": 1.6,
"phase": "aqueous",
"phases": ["aqueous"],
"__comment": "Aitken mode"
},
{
"name": "accumulation",
"geometric mean diameter [m]": 1.1e-7,
"geometric standard deviation": 1.8,
"phase": "aqueous"
"phases": ["aqueous", "organic"]
}
]
}
Expand Down
11 changes: 9 additions & 2 deletions test/unit/v1/v1_unit_configs/models/modal/valid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ phases:
- O3
- H2O2

- name: organic
species:
- organic carbon

models:
- name: gas
type: GAS_PHASE
Expand All @@ -69,13 +73,16 @@ models:
- name: aitken
geometric mean diameter [m]: 2.6e-8
geometric standard deviation: 1.6
phase: aqueous
phases:
- aqueous
__comment: Aitken mode

- name: accumulation
geometric mean diameter [m]: 1.1e-7
geometric standard deviation: 1.8
phase: aqueous
phases:
- aqueous
- organic

reactions:
- type: HL_PHASE_TRANSFER
Expand Down
Loading