Git Product home page Git Product logo

micm's Introduction

MICM Chemistry

Model Independent Chemical Module. MICM can be used to configure and solve atmospheric chemistry systems.

GitHub Releases License Docker builds Windows Mac Ubuntu codecov DOI FAIR checklist badge

Copyright (C) 2018-2024 National Center for Atmospheric Research

Note MICM 3.x.x is part of a refactor and may include breaking changes across minor revision numbers and partially implemented features

Getting Started

Installing MICM locally

To build and install MICM locally, you must have CMake installed on your machine.

Open a terminal window, navigate to a folder where you would like the MICM files to exist, and run the following commands:

git clone https://github.com/NCAR/micm.git
cd micm
mkdir build
cd build
ccmake ..
sudo make install -j 8

To run the tests:

make test

If you would later like to uninstall MICM, you can run sudo make uninstall from the build/ directory.

Options

There are multiple options for running micm. You can use json to configure a solver, llvm to JIT-compile solvers on CPUs or cuda-based solvers to solve chemistry on GPUs. Please read our docs to learn how to enable these options.

Running a MICM Docker container

You must have Docker Desktop installed and running. With Docker Desktop running, open a terminal window. To build the latest MICM release, run the following command to start the MICM container:

docker run -it ghcr.io/ncar/micm:release bash

To build the latest pre-release version of MICM, instead run:

git clone https://github.com/NCAR/micm.git
cd micm
docker build -t micm -f docker/Dockerfile .
docker run -it micm bash

Inside the container, you can run the MICM tests from the /build/ folder:

cd /build/
make test

Using the MICM executable

A simple driver for MICM is built with the library and can be used to solve a chemical system for given initial conditions over one time step.

Just pass the driver the path to the folder containing a valid JSON mechanism configuration and the path to a CSV file holding the initial conditions.

Several example mechanisms and sets of conditions can be found in the /examples/configs/ folder.

You can use them like this:

micm examples/configs/chapman examples/configs/chapman/initial_conditions.csv

The output should be:

 time,          O,        O1D,         O2,         O3
    0,   0.00e+00,   0.00e+00,   7.50e-01,   8.10e-06
   60,   2.57e-12,   3.49e-22,   7.50e-01,   8.10e-06

Using the MICM API

The following example solves the fictitious chemical system:

foo       --k1--> 0.8 bar + 0.2 baz
foo + bar --k2--> baz

The k1 and k2 rate constants are for Arrhenius reactions. See the MICM documentation for details on the types of reactions available in MICM and how to configure them.

To solve this system save the following code in a file named foo_chem.cpp:

#include <iomanip>
#include <iostream>
#include <micm/process/arrhenius_rate_constant.hpp>
#include <micm/solver/rosenbrock.hpp>

using namespace micm;

int main(const int argc, const char *argv[])
{
  auto foo = Species{ "Foo" };
  auto bar = Species{ "Bar" };
  auto baz = Species{ "Baz" };

  Phase gas_phase{ std::vector<Species>{ foo, bar, baz } };

  System chemical_system{ SystemParameters{ .gas_phase_ = gas_phase } };

  Process r1 = Process::Create()
                   .SetReactants({ foo })
                   .SetProducts({ Yield(bar, 0.8), Yield(baz, 0.2) })
                   .SetRateConstant(ArrheniusRateConstant({ .A_ = 1.0e-3 }))
                   .SetPhase(gas_phase);

  Process r2 = Process::Create()
                   .SetReactants({ foo, bar })
                   .SetProducts({ Yield(baz, 1) })
                   .SetRateConstant(ArrheniusRateConstant({ .A_ = 1.0e-5, .C_ = 110.0 }))
                   .SetPhase(gas_phase);

  std::vector<Process> reactions{ r1, r2 };

  RosenbrockSolver<> solver{ chemical_system, reactions, RosenbrockSolverParameters::ThreeStageRosenbrockParameters() };

  State state = solver.GetState();

  state.conditions_[0].temperature_ = 287.45;  // K
  state.conditions_[0].pressure_ = 101319.9;   // Pa
  state.SetConcentration(foo, 20.0);           // mol m-3

  state.PrintHeader();
  for (int i = 0; i < 10; ++i)
  {
    auto result = solver.Solve(500.0, state);
    state.variables_ = result.result_;
    state.PrintState(i*500);
  }

  return 0;
}

To build and run the example using GNU (assuming the default install location):

g++ -o foo_chem foo_chem.cpp -I/usr/local/micm-3.3.1/include -std=c++20
./foo_chem

Output:

 time,        Bar,        Baz,        Foo
    0,   5.90e+00,   1.91e+00,   1.18e+01
  500,   9.05e+00,   3.32e+00,   6.79e+00
 1000,   1.07e+01,   4.21e+00,   3.83e+00
 1500,   1.17e+01,   4.74e+00,   2.14e+00
 2000,   1.22e+01,   5.04e+00,   1.19e+00
 2500,   1.24e+01,   5.21e+00,   6.58e-01
 3000,   1.26e+01,   5.31e+00,   3.64e-01
 3500,   1.27e+01,   5.36e+00,   2.01e-01
 4000,   1.27e+01,   5.39e+00,   1.11e-01
 4500,   1.28e+01,   5.41e+00,   6.13e-02

Citation

MICM is part of the MUSICA project and can be cited by reference to the MUSICA vision paper. The BibTeX entry below can be used to generate a citation for this.

@Article { acom.software.musica-vision,
    author = "Gabriele G. Pfister and Sebastian D. Eastham and Avelino F. Arellano and Bernard Aumont and Kelley C. Barsanti and Mary C. Barth and Andrew Conley and Nicholas A. Davis and Louisa K. Emmons and Jerome D. Fast and Arlene M. Fiore and Benjamin Gaubert and Steve Goldhaber and Claire Granier and Georg A. Grell and Marc Guevara and Daven K. Henze and Alma Hodzic and Xiaohong Liu and Daniel R. Marsh and John J. Orlando and John M. C. Plane and Lorenzo M. Polvani and Karen H. Rosenlof and Allison L. Steiner and Daniel J. Jacob and Guy P. Brasseur",
    title = "The Multi-Scale Infrastructure for Chemistry and Aerosols (MUSICA)",
    journal = "Bulletin of the American Meteorological Society",
    year = "2020",
    publisher = "American Meteorological Society",
    address = "Boston MA, USA",
    volume = "101",
    number = "10",
    doi = "10.1175/BAMS-D-19-0331.1",
    pages= "E1743 - E1760",
    url = "https://journals.ametsoc.org/view/journals/bams/101/10/bamsD190331.xml"
}

Community and contributions

We welcome contributions and feedback from anyone, everything from updating the content or appearance of the documentation to new and cutting edge science.

  • Collaboration

  • Code of conduct

    • Please read this through to you understand the expectations with how to interact with this project.
  • Contributor's guide

    • Before submiitting a PR, please thouroughly read this to you understand our expectations. We reserve the right to reject any PR not meeting our guidelines.

Documentation

Please see the MICM documentation for detailed installation and usage instructions.

License

Copyright (C) 2018-2024 National Center for Atmospheric Research

micm's People

Contributors

actions-user avatar aharonyk avatar andrewjconley avatar boulderdaze avatar cacraigucar avatar davidfillmore avatar dwfncar avatar fvitt avatar github-actions[bot] avatar k20shores avatar mattldawson avatar mwaxmonsky avatar qinatan avatar sjsprecious avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

micm's Issues

MICM cannot compile with nvhpc/23.0

It appears designated initializers are not supported by the nvhpc compiler:

[  5%] Building CXX object test/unit/process/CMakeFiles/test_troe_rate_constant.dir/test_troe_rate_constant.cpp.o
"/glade/derecho/scratch/sunjian/micm/test/unit/process/test_troe_rate_constant.cpp", line 12: error: class type not suitable for use with designators
    micm::TroeRateConstant troe{ micm::TroeRateConstantParameters{ .k0_A_ = 1.0, .kinf_A_ = 1.0 } };
                                                                                  ^

1 error detected in the compilation of "/glade/derecho/scratch/sunjian/micm/test/unit/process/test_troe_rate_constant.cpp".

Add a dockerfile that builds micm with the nvpc compiler and adds a test that runs automatically in github actions for this

Create a Vectorizable Sparse Matrix class

Following the pattern used by VectorMatrix for dense matrices, create a SparseVectorMatrix for sparse block-diagonal matrices whose elements are short vectors sized to optimized vectorization.

Adapt the LuDecompose class to use a SparseMatrixPolicy implemented by SparseMatrix and SparseVectorMatrix

Rosenbrock parameter updates

Should the three_stage_rosenbrock() function be a static class function that returns a RosenbrockSolverParameters object that could then be modified by a user before passing it to the RosenbrockSolver constructor?

(But, the N_ data member of RosenbrockSolverParameters should probably always be calculated based on the System.StateSize() and the number of grid cells, and shouldn't be editable by users.)

Issues about building MICM on Casper

I am trying to build MICM on Casper but encounter some issues. I need to manually revise the CMakeLists.txt file to resolve them:

  • The NETCDF_HOME env variable is not defined on Casper and thus the NETCDF module can not be found even if I have loaded it in my environment. The NETCDF env variable is defined on Casper and seems to work the same as NETCDF_HOME. Can we add it to the search path?

    $ENV{NETCDF_HOME}/include

  • The lib suffix in the search path should be changed to include. I am not sure why the container version still works since we are searching for header files here.

    $ENV{JSON_FORTRAN_HOME}/lib

Automate documentation builds

Automate documentation deployment to github.io using GH Actions. (Can follow the approach used for TUV-x) and include a link in the README

Update README

Update the MICM readme to include build and run instructions, contributions guidelines, and license information. (Can follow the structure of TUV-x

Mid-phase design refactor

Since the beginning of the project and the initial design, some parts of the system have evolved and we are now solving a different problem. Re-evaluate the codebase and ensure we are being consistent in our approach and still providing a flexible solver.

  • MICM started as a header only library. With the addition of the GPU code, some parts are being compiled as source file. Consider moving all inlined functions in the header files to corresponding source files to be consistent with the GPU code. An additional benefit is that MICM could then be compiled as an actual static or shared library and installed. Compile times should also go down for the tests since the tests will be linking against the library.
  • #126
  • The approaches applied to handle various underlying data structures for Matrix and SparseMatrix are different. We should figure out if we should choose one over the other, or leave them as they are.
  • #128
  • #129
  • To github actions, add a matrix test case for compilers and operating systems
  • NCAR/MUSICA-Performance-Comparison#1
  • Evaluate use of typename vs class in templates
  • Consider precompiled headers (#98) or modules. Since we use c++ 20, we should be able to use modules
  • Review use of templated class functions vs. templated classes
  • Make sure the use of conditional statements and ifdefs for GPU vs CPU code is removed or at least minimized.
  • Review the integration tests. Where we can, try to simplify the interface to the code as much as possible so that it's dead simple to make a solver and use it. (including, should UpdateState() just be called internally in Solve()?)
  • #131
  • Check whether we should add validation to builder classes
  • Remove the old version of micm and the regression tests so that there is no Fortran in this repository
  • Figure out how to actually set the c++ standard for different targets in cmake
  • Should we remove the test_ prefix from files, since they are already in the test/ folder?
  • #127

Cannot build MICM on Casper with nvhpc/22.5

Login to Casper

  • module load cmake/3.22.0 nvhpc/22.5

Build micm

  • cmake -DENABLE_REGESSION_TESTS=OFF -DENABLE_LOCAL_TESTS=OFF -DENABLE_CLANG_TIDY=OFF -DENABLE_JSON=OFF -DENABLE_HPC_TESTS=ON ..
  • make

You'll get this error. This error happens on Casper but not cheyenne with the same compiler, so it's a machine-specific thing.

[ 50%] Linking CXX executable ../../test_chapman_integration
cd /glade/u/home/kshores/micm/build/test/hpc_tests && /glade/u/apps/dav/opt/cmake/3.22.0/bin/cmake -E cmake_link_script CMakeFiles/test_chapman_integration.dir/link.txt --verbose=1
/glade/u/apps/dav/opt/ncarcompilers/0.5.0/nvhpc/22.5/nvc++ -fast -O3 -DNDEBUG CMakeFiles/test_chapman_integration.dir/chapman_integration.cpp.o -o ../../test_chapman_integration  -lstdc++ 
CMakeFiles/test_chapman_integration.dir/chapman_integration.cpp.o: In function `micm::RateConstant::~RateConstant()':
nvc++1EDrF6zXP_t6.ll:(.text+0x8a86): undefined reference to `operator delete(void*, unsigned long)'
CMakeFiles/test_chapman_integration.dir/chapman_integration.cpp.o: In function `micm::ArrheniusRateConstant::~ArrheniusRateConstant()':
nvc++1EDrF6zXP_t6.ll:(.text+0x8b86): undefined reference to `operator delete(void*, unsigned long)'
CMakeFiles/test_chapman_integration.dir/chapman_integration.cpp.o: In function `micm::PhotolysisRateConstant::~PhotolysisRateConstant()':
nvc++1EDrF6zXP_t6.ll:(.text+0x8d81): undefined reference to `operator delete(void*, unsigned long)'
CMakeFiles/test_chapman_integration.dir/chapman_integration.cpp.o: In function `micm::RosenbrockSolver::~RosenbrockSolver()':
nvc++1EDrF6zXP_t6.ll:(.text+0xc613): undefined reference to `operator delete(void*, unsigned long)'
make[2]: *** [test_chapman_integration] Error 2
make[2]: Leaving directory `/glade/u/home/kshores/micm/build'
make[1]: *** [test/hpc_tests/CMakeFiles/test_chapman_integration.dir/all] Error 2
make[1]: Leaving directory `/glade/u/home/kshores/micm/build'

It was fixed in this commit
18d79b5. Figure out why this is happening so that we don't need to define library functions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.