Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove nlohman::json in favor of yaml-cpp since it parses both yaml and json #619

Closed
Tracked by #211
mattldawson opened this issue Aug 9, 2024 · 0 comments · Fixed by #649
Closed
Tracked by #211

Remove nlohman::json in favor of yaml-cpp since it parses both yaml and json #619

mattldawson opened this issue Aug 9, 2024 · 0 comments · Fixed by #649
Assignees
Labels
good first issue Good for newcomers

Comments

@mattldawson
Copy link
Collaborator

mattldawson commented Aug 9, 2024

The current MICM configuration parser wraps the nlohman::json library. Modify the parser and the CMake build scripts to use yaml-cpp library instead, which will allow for mechanisms in JSON or YAML.

Acceptance Criteria

  • nlohman::json library is no longer a dependency of MICM
  • The MICM configuration parser usesyaml-cpp for parsing configuration files
  • Include at least one test that reads a YAML configuration

Ideas

  • Files that may need editing:
    • cmake/dependencies.cmake
    • CMakeLists.txt
      • In here we define a variable called MICM_ENABLE_JSON, maybe change that to MICM_ENABLE_CONFIG_READER or something similar
    • src/CMakeLists.txt
    • include/micm/configure/solver_config.hpp
    • test/unit/CMakeLists.txt
    • Many things in test/unit/configure
    • There may be others, but this is likely enough to start
  • Possibly create a test in the configuration parser unit tests for a YAML configuration (the translation of an existing JSON configuration should be fairly easy in Python or an online converter
    TEST(SolverConfig, ReadAndParseSystemObject)
    {
    micm::SolverConfig solverConfig;
    // Read and parse the configure files
    EXPECT_NO_THROW(solverConfig.ReadAndParse("./unit_configs/small_mechanism/config.json"));
    // Get solver parameters ('System', the collection of 'Process')
    micm::SolverParameters solver_params = solverConfig.GetSolverParams();
    // Check 'gas_phase' in 'System'
    EXPECT_EQ(solver_params.system_.gas_phase_.species_.size(), 9);
    // Check 'phases' in 'System'
    EXPECT_EQ(solver_params.system_.phases_.size(), 0);
    // Check 'name' and 'properties' in 'Species'
    std::vector<std::pair<std::string, short>> species_name_and_num_properties = {
    std::make_pair("Ar", 1), std::make_pair("CO2", 1), std::make_pair("H2O", 1),
    std::make_pair("M", 0), std::make_pair("N2", 2), std::make_pair("O", 1),
    std::make_pair("O1D", 1), std::make_pair("O2", 1), std::make_pair("O3", 1)
    };
    short idx = 0;
    for (const auto& s : solver_params.system_.gas_phase_.species_)
    {
    EXPECT_EQ(s.name_, species_name_and_num_properties[idx].first);
    EXPECT_EQ(s.properties_double_.size(), species_name_and_num_properties[idx].second);
    idx++;
    }
    // check some specific properties
    EXPECT_EQ(solver_params.system_.gas_phase_.species_[4].GetProperty<double>("absolute tolerance"), 1.0e-12);
    EXPECT_EQ(solver_params.system_.gas_phase_.species_[4].GetProperty<double>("molecular weight [kg mol-1]"), 0.0280134);
    EXPECT_EQ(solver_params.system_.gas_phase_.species_[4].GetProperty<std::string>("__custom string property"), "foo");
    EXPECT_EQ(solver_params.system_.gas_phase_.species_[4].GetProperty<bool>("__custom bool property"), true);
    EXPECT_EQ(solver_params.system_.gas_phase_.species_[4].GetProperty<int>("__custom int property"), 12);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants