Skip to content

Commit

Permalink
mostly parsed species
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Jan 11, 2024
1 parent b1d3f98 commit ad07e4f
Show file tree
Hide file tree
Showing 14 changed files with 477 additions and 85 deletions.
26 changes: 26 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
BasedOnStyle: Google
AlignAfterOpenBracket: 'AlwaysBreak'
AllowAllConstructorInitializersOnNextLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AlignConsecutiveMacros: 'true'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: 'None'
AllowShortIfStatementsOnASingleLine: 'Never'
AllowShortLoopsOnASingleLine: 'false'
BreakBeforeBraces: Allman
BinPackArguments: 'false'
BinPackParameters: 'false'
Cpp11BracedListStyle: 'false'
ColumnLimit: 150
IndentWidth: 2
IndentPPDirectives: AfterHash
NamespaceIndentation: All
PackConstructorInitializers: 'Never'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeCtorInitializerColon: 'true'
SpaceBeforeInheritanceColon: 'true'
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: 'true'
SpaceInEmptyBlock: true
Standard: 'Latest'
58 changes: 58 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Clang-Format

on:
push:
branches:
- main

jobs:
format:
name: Run Clang-Format
runs-on: ubuntu-latest

steps:
- name: Install Clang-Format
run: sudo apt-get update && sudo apt-get install clang-format

- name: Check out code, run clang format, push changes
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Format code
run: |
find include -type f \( -name '*.hpp' -o -name '*.h' \) -exec clang-format -i --style=file {} +
find src -type f \( -name '*.cu' -o -name '*.hpp' -o -name '*.h' -o -name '*.cpp' \) -exec clang-format -i --style=file {} +
find test -type f \( -name '*.hpp' -o -name '*.h' -o -name '*.cpp' \) ! -path 'test/tutorial/*' -exec clang-format -i --style=file {} +
- name: Check for changes
id: check-changes
run: |
git diff --exit-code
continue-on-error: true

- name: Commit and push changes
# a failue of this step means changes were detected
if: steps.check-changes.outcome != 'success'
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git commit -am "Auto-format code using Clang-Format" || echo "No changes to commit"
- name: Push changes to main-formatting branch
# a failue of this step means changes were detected
if: steps.check-changes.outcome != 'success'
run: |
git push origin HEAD:main-formatting
- name: Create Pull Request
# a failue of this step means changes were detected
if: steps.check-changes.outcome != 'success'
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Auto-format code using Clang-Format"
title: "Auto-format code changes"
body: "This is an automated pull request to apply code formatting using Clang-Format."
branch: "main-formatting"
57 changes: 23 additions & 34 deletions include/open_atmos/mechanism_configuration/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

#pragma once

#include <vector>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <unordered_map>
#include <nlohmann/json.hpp>
#include <open_atmos/types.hpp>
#include <string>
#include <unordered_map>
#include <utility>

#include <open_atmos/types.hpp>
#include <vector>

namespace open_atmos
{
Expand All @@ -26,44 +26,33 @@ namespace open_atmos
UnknownKey,
InvalidFilePath,
NoConfigFilesFound,
FilesSectionNotFound,
DataSectionNotFound,
InvalidSpecies,
InvalidMechanism,
ObjectTypeNotFound,
RequiredKeyNotFound,
ContainsNonStandardKey,
MutuallyExclusiveOption
MutuallyExclusiveOption,
InvalidVersion
};
std::string configParseStatusToString(const ConfigParseStatus &status);

struct Mechanism
{
std::vector<types::Species> species_arr_;
std::unordered_map<std::string, types::Phase> phases_;
};

class JsonReaderPolicy
class JsonParser
{
public:
/// @brief Parse configures
/// @param config_path Path to a the CAMP configuration directory or file
/// @return True for successful parsing
std::pair<ConfigParseStatus, Mechanism> Parse(const std::filesystem::path &config_path);
};
public:
/// @brief Reads a configuration from a json object
/// @param object a json object
/// @return A pair containing the parsing status and mechanism
std::pair<ConfigParseStatus, types::Mechanism> Parse(const nlohmann::json &object);

/// @brief Public interface to read and parse config
template <class ConfigTypePolicy = JsonReaderPolicy>
class ConfigurationReader : public ConfigTypePolicy
{
public:
/// @brief Reads and parses configures
/// @param config_dir Path to a the configuration directory
/// @return an enum indicating the success or failure of the parse
[[nodiscard]] std::pair<ConfigParseStatus, Mechanism> ReadAndParse(const std::filesystem::path &config_dir)
{
return this->Parse(config_dir);
}
/// @brief Reads a configuration from a file path
/// @param file_path A path to single json configuration
/// @return A pair containing the parsing status and mechanism
std::pair<ConfigParseStatus, types::Mechanism> Parse(const std::filesystem::path &file_path);

/// @brief Reads a configuration from a file path
/// @param file_path A path to single json configuration
/// @return A pair containing the parsing status and mechanism
std::pair<ConfigParseStatus, types::Mechanism> Parse(const std::string &file_path);
};
}
}
} // namespace mechanism_configuration
} // namespace open_atmos
71 changes: 71 additions & 0 deletions include/open_atmos/mechanism_configuration/validation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (C) 2023-2024 National Center for Atmospheric Research, University of Illinois at Urbana-Champaign
//
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <string>
#include <vector>

namespace open_atmos
{
namespace validation
{
struct Keys
{
const std::string version = "version";
const std::string name = "name";

// Configuration
const std::string species = "species";
const std::string phases = "phases";
const std::string reactions = "reactions";

// Species
const std::string tracer_type = "tracer type";
const std::string absolute_tolerance = "absolute tolerance";
const std::string diffusion_coefficient = "diffusion coefficient [m2 s-1]";
const std::string molecular_weight = "molecular weight [kg mol-1]";
const std::string henrys_law_constant_298 = "HLC(298K) [mol m-3 Pa-1]";
const std::string henrys_law_constant_exponential_factor = "HLC exponential factor [K]";
const std::string phase = "phase";
const std::string n_star = "N star";
const std::string density = "density [kg m-3]";
} keys;

// Initialize static const members of Keys

struct Configuration
{
const std::vector<std::string> required_keys{ keys.version, keys.species, keys.phases, keys.reactions };
const std::vector<std::string> optional_keys{ keys.name };
} configuration;

struct Species
{
const std::vector<std::string> required_keys{ keys.name };
const std::vector<std::string> optional_keys{ keys.tracer_type,
keys.absolute_tolerance,
keys.diffusion_coefficient,
keys.molecular_weight,
keys.phase,
keys.henrys_law_constant_298,
keys.henrys_law_constant_exponential_factor,
keys.n_star,
keys.density };
} species;

struct Phase
{
const std::vector<std::string> required_keys;
const std::vector<std::string> optional_keys;
} phase;

struct Mechanism
{
const std::vector<std::string> required_keys;
const std::vector<std::string> optional_keys;
} mechanism;

} // namespace validation
} // namespace open_atmos
2 changes: 1 addition & 1 deletion include/open_atmos/mechanism_configuration/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace open_atmos
extern "C" {
#endif

const char* getmechanism_configurationVersion()
const char* getVersionString()
{
return "1.0.0";
}
Expand Down
26 changes: 22 additions & 4 deletions include/open_atmos/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,32 @@

#pragma once

#include <string>
#include <unordered_map>

namespace open_atmos
{
namespace types
{
struct Species {
struct Species
{
std::string name;

std::map<std::string, double> optional_properties;

std::unordered_map<std::string, std::string> unknown_properties;
};

struct Phase {
struct Phase
{
};
}
}

struct Mechanism
{
std::string name; // optional
std::vector<types::Species> species;
std::unordered_map<std::string, types::Phase> phases;
};

} // namespace types
} // namespace open_atmos
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ target_include_directories(mechanism_configuration
$<INSTALL_INTERFACE:include>
)

target_link_libraries(mechanism_configuration PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(mechanism_configuration PUBLIC nlohmann_json::nlohmann_json)
Loading

0 comments on commit ad07e4f

Please sign in to comment.