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

Parse v0 mechanisms #265

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f40fb7a
roughing out structure to parse mechanisms into micm
K20shores Feb 26, 2025
cf62232
parsing species
K20shores Mar 5, 2025
838bb83
branched
K20shores Mar 5, 2025
e65b888
user defined
K20shores Mar 5, 2025
a26ca49
surface reactions
K20shores Mar 5, 2025
5ff5894
troe
K20shores Mar 5, 2025
9cec86f
reorganizing
K20shores Mar 5, 2025
ed08779
tunneling
K20shores Mar 5, 2025
fb75a06
converting ternary
K20shores Mar 5, 2025
6d13f9e
parsing v0
K20shores Mar 5, 2025
396a0cd
better test
K20shores Mar 5, 2025
110705e
serial build
K20shores Mar 5, 2025
52721d1
maybe python needs it as well
K20shores Mar 5, 2025
a5fcb9f
adding parsing files
K20shores Mar 5, 2025
bac6072
for some reason the long description was dropped from scikit learn???
K20shores Mar 5, 2025
f65901c
maybe this?
K20shores Mar 5, 2025
c069752
maybe I can remove the link?
K20shores Mar 5, 2025
442ec14
removing unnecessary test fixes
K20shores Mar 5, 2025
84b430b
adding more tests
K20shores Mar 6, 2025
aec11d7
adding more tests
K20shores Mar 6, 2025
4c11285
getting the tests to pass
K20shores Mar 7, 2025
d91ffa4
adding another file
K20shores Mar 7, 2025
cdaca17
using new musica error
K20shores Mar 7, 2025
d754562
deleting error in test
K20shores Mar 7, 2025
50426cc
removing null check
K20shores Mar 7, 2025
055287d
fixed one leak
K20shores Mar 7, 2025
9ed13b9
fixing the other memory leak?
K20shores Mar 7, 2025
29f600d
updating mech config tag
K20shores Mar 7, 2025
8333897
updating mech config tag
K20shores Mar 10, 2025
5a4d830
disabling python build of mech config
K20shores Mar 10, 2025
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
18 changes: 1 addition & 17 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
- run: pip install numpy --user

- name: Run Cmake
if: matrix.compiler.cpp != 'g++-13'
run: |
PYTHON_PATH=$(which python)
cmake -S . -B build \
Expand All @@ -49,23 +48,8 @@ jobs:
-D MUSICA_ENABLE_PYTHON_LIBRARY=ON \
-D Python3_EXECUTABLE=$PYTHON_PATH

- name: Run Cmake
if: matrix.compiler.cpp == 'g++-13'
run: |
PYTHON_PATH=$(which python)
# for some reason gcc 13 was having issues finding the correct osx sdk
# it seems it was a known issue: https://github.com/actions/runner-images/issues/9997
# for some reason, passing in an empty string for the osx sysroot fixed the issue
cmake -S . -B build \
-D CMAKE_CXX_FLAGS=-Wl,-ld_classic \
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-D MUSICA_GIT_TAG=${{ github.sha }} \
-D MUSICA_ENABLE_PYTHON_LIBRARY=ON \
-D Python3_EXECUTABLE=$PYTHON_PATH \
-D CMAKE_OSX_SYSROOT=""

- name: Build
run: cmake --build build --verbose --parallel 10
run: cmake --build build --verbose

- name: Run tests
run: |
Expand Down
4 changes: 3 additions & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ FetchContent_MakeAvailable(yaml-cpp)
# Mechanism Configuration

set_git_default(MECH_CONFIG_GIT_REPOSITORY https://github.com/open-atmos/MechanismConfiguration.git)
set_git_default(MECH_CONFIG_GIT_TAG 0835527)
set_git_default(MECH_CONFIG_GIT_TAG c379f9fa5164112d562a35f96718973acbc3e286)

FetchContent_Declare(mechanism_configuration
GIT_REPOSITORY ${MECH_CONFIG_GIT_REPOSITORY}
GIT_TAG ${MECH_CONFIG_GIT_TAG}
GIT_PROGRESS NOT ${FETCHCONTENT_QUIET}
)

set(OPEN_ATMOS_ENABLE_PYTHON_LIBRARY OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(mechanism_configuration)

################################################################################
Expand Down
3 changes: 2 additions & 1 deletion fortran/test/fetch_content_integration/test_micm_api.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ program test_micm_api
use musica_util, only: assert, error_t, mapping_t, string_t, find_mapping_index

#include "micm/util/error.hpp"
#include "musica/error.hpp"

#define ASSERT( expr ) call assert( expr, __FILE__, __LINE__ )
#define ASSERT_EQ( a, b ) call assert( a == b, __FILE__, __LINE__ )
Expand Down Expand Up @@ -166,7 +167,7 @@ subroutine test_api()
ASSERT( error%is_error( MICM_ERROR_CATEGORY_SPECIES, MICM_SPECIES_ERROR_CODE_PROPERTY_NOT_FOUND ) )
deallocate( micm )
micm => micm_t( "configs/invalid", solver_type, num_grid_cells, error )
ASSERT( error%is_error( MICM_ERROR_CATEGORY_CONFIGURATION, MICM_CONFIGURATION_ERROR_CODE_INVALID_FILE_PATH ) )
ASSERT( error%is_error( MUSICA_ERROR_CATEGORY, MUSICA_ERROR_CODE_CONFIG_PARSE_FAILED ) )
ASSERT( .not. associated( micm ) )

write(*,*) "[test micm fort api] Finished."
Expand Down
13 changes: 13 additions & 0 deletions include/musica/error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#if 0
// Copyright (C) 2023-2025 National Center for Atmospheric Research
// SPDX-License-Identifier: Apache-2.0
#endif

#define MUSICA_ERROR_CATEGORY "MUSICA Error"
#define MUSICA_ERROR_CODE_SPECIES_NOT_FOUND 1
#define MUSICA_ERROR_CODE_SOLVER_TYPE_NOT_FOUND 2
#define MUSICA_ERROR_CODE_MAPPING_NOT_FOUND 3
#define MUSICA_ERROR_CODE_PARSING_FAILED 4
#define MUSICA_ERROR_CODE_MAPPING_OPTIONS_UNDEFINED 5
#define MUSICA_ERROR_CODE_CONFIG_PARSE_FAILED 6
#define MUSICA_ERROR_CODE_VERSION_NOT_SUPPORTED 7
12 changes: 12 additions & 0 deletions include/musica/micm/chemistry.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <micm/process/process.hpp>
#include <micm/system/system.hpp>

namespace musica
{
struct Chemistry {
micm::System system;
std::vector<micm::Process> processes;
};
}
32 changes: 19 additions & 13 deletions include/musica/micm/micm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#pragma once

#include <musica/util.hpp>
#include <musica/micm/parse.hpp>
#include <musica/micm/chemistry.hpp>

#include <micm/configure/solver_config.hpp>
#include <micm/process/process_set.hpp>
Expand All @@ -31,7 +33,6 @@

namespace musica
{

class MICM;

#ifdef __cplusplus
Expand Down Expand Up @@ -169,25 +170,25 @@ namespace musica
class MICM
{
public:
/// @brief Create a Rosenbrock solver of vector-ordered matrix type by reading and parsing configuration file
/// @param config_path Path to configuration file or directory containing configuration file
/// @brief Create a Rosenbrock solver of vector-ordered matrix type using the provided chemistry configuration
/// @param chemistry Chemistry configuration
/// @param error Error struct to indicate success or failure
void CreateRosenbrock(const std::string &config_path, Error *error);
void CreateRosenbrock(const Chemistry &chemistry, Error *error);

/// @brief Create a Rosenbrock solver of standard-ordered matrix type by reading and parsing configuration file
/// @param config_path Path to configuration file or directory containing configuration file
/// @brief Create a Rosenbrock solver of standard-ordered matrix type using the provided chemistry configuration
/// @param chemistry Chemistry configuration
/// @param error Error struct to indicate success or failure
void CreateRosenbrockStandardOrder(const std::string &config_path, Error *error);
void CreateRosenbrockStandardOrder(const Chemistry &chemistry, Error *error);

/// @brief Create a BackwardEuler solver of vector-ordered matrix type by reading and parsing configuration file
/// @param config_path Path to configuration file or directory containing configuration file
/// @param chemistry Chemistry configuration
/// @param error Error struct to indicate success or failure
void CreateBackwardEuler(const std::string &config_path, Error *error);
void CreateBackwardEuler(const Chemistry &chemistry, Error *error);

/// @brief Create a BackwardEuler solver of standard-ordered matrix type by reading and parsing configuration file
/// @param config_path Path to configuration file or directory containing configuration file
/// @param chemistry Chemistry configuration
/// @param error Error struct to indicate success or failure
void CreateBackwardEulerStandardOrder(const std::string &config_path, Error *error);
void CreateBackwardEulerStandardOrder(const Chemistry &chemistry, Error *error);

/// @brief Solve the system
/// @param solver_state_pair A pair containing a pointer to a solver and a state for that solver (temporary fix)
Expand Down Expand Up @@ -223,6 +224,11 @@ namespace musica
{
num_grid_cells_ = num_grid_cells;
}

void SetChemistry(Chemistry chemistry)
{
chemistry_ = std::make_unique<Chemistry>(chemistry);
}

/// @brief Get a property for a chemical species
/// @param species_name Name of the species
Expand Down Expand Up @@ -275,14 +281,14 @@ namespace musica

private:
int num_grid_cells_;
std::unique_ptr<micm::SolverParameters> solver_parameters_;
std::unique_ptr<Chemistry> chemistry_;
};

template<class T>
inline T MICM::GetSpeciesProperty(const std::string &species_name, const std::string &property_name, Error *error)
{
*error = NoError();
for (const auto &species : solver_parameters_->system_.gas_phase_.species_)
for (const auto &species : chemistry_->system.gas_phase_.species_)
{
if (species.name_ == species_name)
{
Expand Down
19 changes: 19 additions & 0 deletions include/musica/micm/parse.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <musica/micm/chemistry.hpp>
#include <musica/micm/micm.hpp>
#include <musica/util.hpp>

#include <mechanism_configuration/parser.hpp>

namespace musica
{
Chemistry ReadConfiguration(const std::string& config_path, Error* error);
Chemistry ParserV0(const mechanism_configuration::ParserResult<>& result, Error* error);
Chemistry ParserV1(const mechanism_configuration::ParserResult<>& result, Error* error);

// Utility functions to check types and perform conversions
bool IsBool(const std::string& value);
bool IsInt(const std::string& value);
bool IsFloatingPoint(const std::string& value);
} // namespace musica
9 changes: 2 additions & 7 deletions include/musica/util.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@

// Copyright (C) 2023-2025 National Center for Atmospheric Research
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <cstddef>

#define MUSICA_ERROR_CATEGORY "MUSICA Error"
#define MUSICA_ERROR_CODE_SPECIES_NOT_FOUND 1
#define MUSICA_ERROR_CODE_SOLVER_TYPE_NOT_FOUND 2
#define MUSICA_ERROR_CODE_MAPPING_NOT_FOUND 3
#define MUSICA_ERROR_CODE_PARSING_FAILED 4
#define MUSICA_ERROR_CODE_MAPPING_OPTIONS_UNDEFINED 5
#include <musica/error.hpp>

#ifdef __cplusplus
#include <yaml-cpp/yaml.h>
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ name = "musica"
dynamic = ["version"]
readme = "README.md"
description = "MUSICA is a Python library for performing computational simulations in atmospheric chemistry."
long_description = "MUSICA (Multiscale Interface for Chemistry and Aerosols) is a powerful tool for modeling atmospheric chemistry processes. It provides a flexible interface for running simulations and analyzing results."
long_description_content_type = "text/plain"
authors = [
{ name = "Matthew Dawsom", email = "[email protected]" },
{ name = "Jiwon Gim", email = "[email protected]" },
Expand Down
14 changes: 12 additions & 2 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# we specify the sources by hand because sometimes musica builds with tuvx
# it is hard to guarantee there is a fortran compiler on windows
pybind11_add_module(musica_python
wrapper.cpp
${PROJECT_SOURCE_DIR}/src/micm/micm.cpp
${PROJECT_SOURCE_DIR}/src/micm/parse.cpp
${PROJECT_SOURCE_DIR}/src/micm/v0_parse.cpp
${PROJECT_SOURCE_DIR}/src/micm/v1_parse.cpp
${PROJECT_SOURCE_DIR}/src/component_versions.cpp
${PROJECT_SOURCE_DIR}/src/util.cpp
${CMAKE_BINARY_DIR}/version.cpp
)

target_link_libraries(musica_python PRIVATE yaml-cpp)
target_link_libraries(musica_python
PUBLIC
open_atmos::mechanism_configuration
PRIVATE
yaml-cpp
)

target_compile_features(musica_python PUBLIC cxx_std_20)

Expand Down Expand Up @@ -39,7 +49,7 @@ elseif(UNIX)
)
endif()

install(TARGETS musica_python yaml-cpp
install(TARGETS musica_python yaml-cpp mechanism_configuration
LIBRARY DESTINATION .
)

Expand Down
3 changes: 3 additions & 0 deletions src/micm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
target_sources(musica
PRIVATE
micm.cpp
parse.cpp
v0_parse.cpp
v1_parse.cpp
)

Loading
Loading