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

Customizable data objects for ExtensibleRate #1417

Merged
merged 15 commits into from
Jan 21, 2023
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
74 changes: 37 additions & 37 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ jobs:
HDF5_LIBDIR: /usr/lib/x86_64-linux-gnu/hdf5/serial
HDF5_INCLUDEDIR: /usr/include/hdf5/serial
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
Expand All @@ -46,6 +46,7 @@ jobs:
sudo apt update
sudo apt install libboost-dev gfortran libopenmpi-dev libpython3-dev \
libblas-dev liblapack-dev libhdf5-dev
gcc --version
- name: Upgrade pip
run: python3 -m pip install -U pip setuptools wheel
- name: Install Python dependencies
Expand Down Expand Up @@ -77,12 +78,12 @@ jobs:
HDF5_LIBDIR: /usr/lib/x86_64-linux-gnu/hdf5/serial
HDF5_INCLUDEDIR: /usr/include/hdf5/serial
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8
architecture: x64
Expand Down Expand Up @@ -122,7 +123,7 @@ jobs:
# https://stackoverflow.com/q/38618885
- name: Configure git
run: /usr/local/bin/git config --global http.postBuffer 1048576000
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
Expand Down Expand Up @@ -176,19 +177,20 @@ jobs:
HDF5_LIBDIR: /usr/lib/x86_64-linux-gnu/hdf5/serial
HDF5_INCLUDEDIR: /usr/include/hdf5/serial
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
- name: Setup python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.8'
architecture: x64
- name: Install Apt dependencies
run: |
sudo apt update
sudo apt install libboost-dev gfortran liblapack-dev libblas-dev libsundials-dev libhdf5-dev
gcc --version
- name: Upgrade pip
run: python3 -m pip install -U pip setuptools wheel
- name: Install Python dependencies
Expand Down Expand Up @@ -227,19 +229,19 @@ jobs:
--exclude '.*ext.*' --exclude '(.+/)?_cantera\.cpp$' --exclude '^test.*' \
--xml coverage.xml --html-details htmlcoverage.html --txt
- name: Archive C++ coverage results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: cxx-coverage-report
path: htmlcoverage*
retention-days: 5
- name: Archive Python coverage results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: python-coverage-report
path: build/python-coverage*
retention-days: 5
- name: Archive .NET coverage results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: dotnet-coverage-report
path: interfaces/dotnet/coveragereport*
Expand All @@ -256,10 +258,10 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Check keywords
Expand All @@ -272,12 +274,12 @@ jobs:
env:
DEPLOY: ${{ github.event_name == 'push' && github.repository_owner == 'Cantera' && endsWith(github.ref, 'main') }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.8'
architecture: x64
Expand Down Expand Up @@ -308,7 +310,7 @@ jobs:
cd build
tar -czf docs.tar.gz docs
- name: Store archive of docs output
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
path: build/docs.tar.gz
name: docs
Expand Down Expand Up @@ -346,12 +348,12 @@ jobs:
HDF5_LIBDIR: /usr/lib/x86_64-linux-gnu/hdf5/serial
HDF5_INCLUDEDIR: /usr/include/hdf5/serial
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
Expand Down Expand Up @@ -390,7 +392,7 @@ jobs:
PYTHONWARNINGS: "error,ignore:warn_name_set_on_empty_Forward::pyparsing"
MPLBACKEND: Agg
- name: Save the results file for inspection
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
path: results.txt
retention-days: 2
Expand All @@ -413,7 +415,7 @@ jobs:
sundials-ver: [ 3, 4, 5.8, 6.4.1 ]
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
Expand Down Expand Up @@ -474,7 +476,7 @@ jobs:
python-version: ["3.8", "3.10", "3.11"]
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
Expand All @@ -483,10 +485,9 @@ jobs:
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
mamba-version: "*"
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: test
channels: conda-forge,defaults
channel-priority: true
- name: Install conda dependencies
# See https://github.com/conda-forge/boost-cpp-feedstock/issues/41 for why we
# use boost-cpp rather than boost from conda-forge
Expand Down Expand Up @@ -543,12 +544,12 @@ jobs:
python-version: ["3.8", "3.10", "3.11"]
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
- name: Set Up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
Expand All @@ -557,7 +558,7 @@ jobs:
python -m pip install -U pip setuptools wheel
python -m pip install '"scons<4.4.0"' pypiwin32 numpy ruamel.yaml cython pandas pytest pytest-github-actions-annotate-failures
- name: Restore Boost cache
uses: actions/cache@v2
uses: actions/cache@v3
id: cache-boost
with:
path: ${{env.BOOST_ROOT}}
Expand Down Expand Up @@ -605,12 +606,12 @@ jobs:
run: |
sudo apt-get install intel-oneapi-compiler-fortran intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic \
intel-oneapi-mpi intel-oneapi-mpi-devel intel-oneapi-mkl ninja-build libboost-dev libhdf5-dev
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8
architecture: x64
Expand Down Expand Up @@ -653,12 +654,12 @@ jobs:
run: |
sudo apt-get install intel-oneapi-compiler-fortran intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic \
intel-oneapi-mpi intel-oneapi-mpi-devel intel-oneapi-mkl ninja-build libboost-dev
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8
architecture: x64
Expand Down Expand Up @@ -686,12 +687,12 @@ jobs:
BOOST_ROOT: ${{github.workspace}}/3rdparty/boost
BOOST_URL: https://boostorg.jfrog.io/artifactory/main/release/1.78.0/source/boost_1_78_0.7z
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
with:
submodules: recursive
- name: Set Up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8
architecture: x64
Expand All @@ -700,7 +701,7 @@ jobs:
python -m pip install -U pip 'setuptools>=47.0.0,<48' wheel
python -m pip install scons pypiwin32 numpy ruamel.yaml cython h5py pandas pytest pytest-github-actions-annotate-failures
- name: Restore Boost cache
uses: actions/cache@v2
uses: actions/cache@v3
id: cache-boost
with:
path: ${{env.BOOST_ROOT}}
Expand Down Expand Up @@ -737,17 +738,16 @@ jobs:
needs: [ubuntu-multiple-pythons, macos-multiple-pythons, windows-2022]
timeout-minutes: 60
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout the repository
- name: Set up conda
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: "3.10"
mamba-version: "*"
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: test
channels: conda-forge,defaults
channel-priority: true
- name: Install Python dependencies
run: python3 -m pip install ruamel.yaml
- name: Install library dependencies with Conda (Windows)
Expand Down
5 changes: 5 additions & 0 deletions doc/sphinx/cython/kinetics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ StickingBlowersMaselRate
Auxiliary Reaction Data
-----------------------

ExtensibleRateData
^^^^^^^^^^^^^^^^^^
.. autoclass:: ExtensibleRateData
:no-undoc-members:

ThirdBody
^^^^^^^^^
.. autoclass:: ThirdBody
Expand Down
31 changes: 23 additions & 8 deletions include/cantera/base/Delegator.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ namespace Cantera
class Delegator
{
public:
//! Get the name of the user-defined class in the extension language
std::string delegatorName() const {
return m_delegatorName;
}

//! Set the name of the user-defined class in the extension language
void setDelegatorName(const std::string& delegatorName) {
m_delegatorName = delegatorName;
}

//! Set delegates for member functions with the signature `void()`.
void setDelegate(const std::string& name, const std::function<void()>& func,
const std::string& when)
Expand Down Expand Up @@ -215,7 +225,7 @@ class Delegator
throw NotImplementedError("Delegator::setDelegate",
"for function named '{}' with signature 'double(void*)'.", name);
}
*m_funcs_d_vp[name] = makeDelegate(func, when, m_base_d_vp[name]);
*m_funcs_d_vp[name] = makeDelegate(name, func, when, m_base_d_vp[name]);
}

//! Set delegates for member functions with the signature `string(size_t)`
Expand All @@ -228,7 +238,7 @@ class Delegator
"for function named '{}' with signature "
"'string(size_t)'.", name);
}
*m_funcs_s_sz[name] = makeDelegate(func, when, m_base_s_sz[name]);
*m_funcs_s_sz[name] = makeDelegate(name, func, when, m_base_s_sz[name]);
}

//! Set delegates for member functions with the signature `size_t(string)`
Expand All @@ -238,10 +248,10 @@ class Delegator
{
if (!m_funcs_sz_csr.count(name)) {
throw NotImplementedError("Delegator::setDelegate",
"for function named '{}' with signature "
"for function '{}' with signature "
"'size_t(const string&)'.", name);
}
*m_funcs_sz_csr[name] = makeDelegate(func, when, m_base_sz_csr[name]);
*m_funcs_sz_csr[name] = makeDelegate(name, func, when, m_base_sz_csr[name]);
}

void holdExternalHandle(const shared_ptr<ExternalHandle>& handle) {
Expand Down Expand Up @@ -382,6 +392,7 @@ class Delegator
//! Create a delegate for a function with a return value
template <typename ReturnType, class ... Args>
std::function<ReturnType(Args ...)> makeDelegate(
const std::string& name,
const std::function<int(ReturnType&, Args ...)>& func,
const std::string& when,
const std::function<ReturnType(Args ...)>& base)
Expand Down Expand Up @@ -413,20 +424,21 @@ class Delegator
}
};
} else if (when == "replace") {
return [base, func](Args ... args) {
return [base, name, func, this](Args ... args) {
ReturnType ret;
int has_ret = func(ret, args ...);
if (!has_ret) {
throw CanteraError("Lambda generated by Delegator::makeDelegate",
"Delegate for function of type '{}'\ndid not return a value",
demangle(typeid(base)));
"Method '{}' of class '{}' did not return a value of type '{}'.",
name, delegatorName(), demangle(typeid(ret)));
}
return ret;
};
} else {
throw CanteraError("Delegator::makeDelegate",
"For function named '{}':\n"
"'when' must be one of 'before', 'after', or 'replace';"
" not '{}", when);
" not '{}'", name, when);
}
}

Expand Down Expand Up @@ -486,6 +498,9 @@ class Delegator

//! Cleanup functions to be called from the destructor
std::list<shared_ptr<ExternalHandle>> m_handles;

//! Name of the class in the extension language
std::string m_delegatorName;
};

}
Expand Down
Loading