diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..13c2affa03 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,267 @@ +name: CI + +on: + pull_request: + branches: [ main ] + workflow_dispatch: + +env: + BUILDCACHE_ACCURACY: STRICT + BUILDCACHE_COMPRESS_FORMAT: ZSTD + BUILDCACHE_DEBUG: -1 + BUILDCACHE_LOG_FILE: "" + +jobs: + cpp_python: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - name: 'Windows static - C++/Python' + os: windows-latest + bindings_python: ON + build_shared: OFF + unit_tests: ON + set_path: $env:Path="C:\libxml2\bin;C:\zlib\bin;"+$env:Path + additional_cmake_options: -DLIBXML2_INCLUDE_DIR="C:\libxml2\include\libxml2" -DLIBXML2_LIBRARY="C:\libxml2\lib\libxml2.lib" -DZLIB_INCLUDE_DIR="C:\zlib\include" -DZLIB_LIBRARY="C:\zlib\lib\z_dll.lib" + - name: 'Windows shared - C++/Python' + os: windows-latest + bindings_python: ON + build_shared: ON + unit_tests: ON + set_path: $env:Path="C:\libxml2\bin;C:\zlib\bin;"+$env:Path + additional_cmake_options: -DLIBXML2_INCLUDE_DIR="C:\libxml2\include\libxml2" -DLIBXML2_LIBRARY="C:\libxml2\lib\libxml2.lib" -DZLIB_INCLUDE_DIR="C:\zlib\include" -DZLIB_LIBRARY="C:\zlib\lib\z_dll.lib" + - name: 'Linux static - C++ (build only)' + os: ubuntu-latest + bindings_python: OFF + build_shared: OFF + unit_tests: OFF + - name: 'Linux shared - C++/Python' + os: ubuntu-latest + bindings_python: ON + build_shared: ON + unit_tests: ON + - name: 'macOS static - C++ (Intel)' + os: macos-13 + bindings_python: OFF + build_shared: OFF + unit_tests: ON + - name: 'macOS shared - C++/Python (Intel)' + os: macos-13 + bindings_python: ON + build_shared: ON + unit_tests: ON + - name: 'macOS static - C++ (ARM)' + os: macos-latest + bindings_python: OFF + build_shared: OFF + unit_tests: ON + - name: 'macOS shared - C++/Python (ARM)' + os: macos-latest + bindings_python: ON + build_shared: ON + unit_tests: ON + steps: + - name: Check out libCellML + uses: actions/checkout@v4 + - name: Install Python (if needed) + if: ${{ matrix.bindings_python == 'ON' }} + uses: actions/setup-python@v5 + with: + python-version: '3.13' + - name: Install CMake and Ninja + uses: lukka/get-cmake@latest + - name: Install buildcache + uses: mikehardy/buildcache-action@v2 + with: + cache_key: ${{ matrix.os }}-${{ matrix.build_shared }} + - name: Configure MSVC (Windows only) + if: ${{ runner.os == 'Windows' }} + uses: ilammy/msvc-dev-cmd@v1 + - name: Install libxml2 (Windows only) + if: ${{ runner.os == 'Windows' }} + run: | + Invoke-WebRequest -UseBasicParsing https://github.com/cellml/gha/releases/download/gha/libxml2.zip -OutFile libxml2.zip + Expand-Archive -LiteralPath libxml2.zip -DestinationPath C:\ + - name: Install SWIG (macOS only and if needed) + if: ${{ runner.os == 'macOS' && matrix.bindings_python == 'ON' }} + run: | + brew install swig + - name: Install zlib (Windows only) + if: ${{ runner.os == 'Windows' }} + run: | + Invoke-WebRequest -UseBasicParsing https://github.com/cellml/gha/releases/download/gha/zlib.zip -OutFile zlib.zip + Expand-Archive -LiteralPath zlib.zip -DestinationPath C:\ + - name: Configure libCellML + run: | + mkdir build + cd build + ${{ matrix.set_path }} + cmake -G Ninja -DBINDINGS_PYTHON=${{ matrix.bindings_python }} -DBUILD_SHARED=${{ matrix.build_shared }} -DCOVERAGE=OFF -DLLVM_COVERAGE=OFF -DMEMCHECK=OFF -DUNIT_TESTS=${{ matrix.unit_tests }} ${{ matrix.additional_cmake_options }} .. + - name: Build libCellML + run: | + cd build + ninja + - name: Unit testing + if: ${{ matrix.unit_tests == 'ON' }} + run: | + cd build + ninja test + javascript: + name: JavaScript + runs-on: macos-latest + strategy: + fail-fast: false + env: + LIBCELLML_WASM_DIR: wasm + LIBXML2_VERSION: 2.9.10 + ZLIB_VERSION: 1.2.3 + steps: + - name: Check out libCellML + uses: actions/checkout@v4 + - name: Install CMake and Ninja + uses: lukka/get-cmake@latest + - name: Install buildcache + uses: mikehardy/buildcache-action@v2 + - name: Install Emscripten + run: | + brew install --overwrite emscripten + - name: Set up the build directory + run: | + mkdir build + - name: Build zlib + run: | + cd build + ZLIB_BUILD_DIR=zlib-wasm + git clone https://github.com/OpenCMISS-Dependencies/zlib.git -b v${ZLIB_VERSION} + mkdir ${ZLIB_BUILD_DIR} + emcmake cmake -G Ninja -S zlib -B ${ZLIB_BUILD_DIR} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/${LIBCELLML_WASM_DIR} -DBUILD_SHARED_LIBS=OFF + cmake --build ${ZLIB_BUILD_DIR} + cmake --install ${ZLIB_BUILD_DIR} + - name: Build libxml2 + run: | + cd build + LIBXML2_BUILD_DIR=libxml2-wasm + git clone https://github.com/OpenCMISS-Dependencies/libxml2.git -b v${LIBXML2_VERSION} + mkdir ${LIBXML2_BUILD_DIR} + emcmake cmake -G Ninja -S libxml2 -B ${LIBXML2_BUILD_DIR} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/${LIBCELLML_WASM_DIR} -DZLIB_DIR=~/${LIBCELLML_WASM_DIR}/lib/cmake/ZLIB-${ZLIB_VERSION} -DBUILD_SHARED_LIBS=OFF -DLIBXML2_WITH_ICONV=OFF -DLIBXML2_WITH_LZMA=OFF -DLIBXML2_WITH_PYTHON=OFF -DLIBXML2_WITH_TESTS=OFF -DLIBXML2_WITH_PROGRAMS=OFF + cmake --build ${LIBXML2_BUILD_DIR} + cmake --install ${LIBXML2_BUILD_DIR} + - name: Build libCellML + run: | + cd build + mkdir ${LIBCELLML_WASM_DIR} + emcmake cmake -G Ninja -S .. -B ${LIBCELLML_WASM_DIR} -DLibXml2_DIR=~/${LIBCELLML_WASM_DIR}/lib/cmake/libxml2-${LIBXML2_VERSION} -DBUILD_TYPE=Release + cmake --build ${LIBCELLML_WASM_DIR} + - name: Unit testing + run: | + cd build + cmake --build ${LIBCELLML_WASM_DIR} --target jest_test + code_formatting: + name: Code formatting + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Check out libCellML + uses: actions/checkout@v4 + - name: Install ClangFormat + run: | + sudo apt update + sudo apt install clang-format + - name: Install CMake and Ninja + uses: lukka/get-cmake@latest + - name: Configure libCellML + run: | + mkdir build + cd build + cmake -G Ninja .. + - name: Code formatting + run: | + cd build + ninja test_clang_format + coverage: + name: Code coverage + runs-on: macos-latest + strategy: + fail-fast: false + steps: + - name: Check out libCellML + uses: actions/checkout@v4 + - name: Install CMake and Ninja + uses: lukka/get-cmake@latest + - name: Install buildcache + uses: mikehardy/buildcache-action@v2 + - name: Install LLVM + run: | + brew install --overwrite llvm + echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.bash_profile + - name: Configure libCellML + run: | + mkdir build + cd build + cmake -G Ninja -DBINDINGS_PYTHON=OFF .. + - name: Code coverage + run: | + cd build + ninja llvm_coverage + if [ `ninja llvm_coverage | grep TOTAL | sed 's/ /\n/g' | grep "100.00%" | wc -l | sed 's/ //g'` -eq 4 ]; then exit 0; else exit 1; fi + memory_leaks: + name: Memory leaks + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Check out libCellML + uses: actions/checkout@v4 + - name: Install CMake and Ninja + uses: lukka/get-cmake@latest + - name: Install buildcache + uses: mikehardy/buildcache-action@v2 + - name: Install Valgrind + run: | + sudo apt update + sudo apt install valgrind + - name: Configure libCellML + run: | + mkdir build + cd build + cmake -G Ninja -DBINDINGS_PYTHON=OFF .. + - name: Memory leaks + run: | + cd build + ninja memcheck + documentation: + name: Documentation + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Check out libCellML + uses: actions/checkout@v4 + - name: Install CMake and Ninja + uses: lukka/get-cmake@latest + - name: Install buildcache + uses: mikehardy/buildcache-action@v2 + - name: Install dot + run: | + sudo apt update + sudo apt install graphviz + - name: Install Doxygen + run: | + sudo apt update + sudo apt install doxygen + - name: Install Sphinx + run: | + pip3 install sphinx + - name: Configure libCellML + run: | + mkdir build + cd build + cmake -G Ninja -DBINDINGS_PYTHON=OFF .. + - name: Documentation + run: | + cd build + ninja docs diff --git a/CMakeLists.txt b/CMakeLists.txt index d44995ad1a..693c1c637d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,8 +249,10 @@ if(CLANG_FORMAT_AVAILABLE) ${SOURCE_FILES} ${HEADER_FILES} ${CONFIG_FILES} - ${TESTS_HEADER_FILES} + ${DEBUG_SOURCE_FILES} + ${DEBUG_HEADER_FILES} ${TESTS_SOURCE_FILES} + ${TESTS_HEADER_FILES} ) set(CHECK_CODE_FORMATTING_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/cmake_command_check_code_formatting.cmake) diff --git a/cmake/common.cmake b/cmake/common.cmake index 6939ca93b9..214be6d699 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -313,3 +313,13 @@ function(redhat_based _RESULT) endif() set(${_RESULT} ${_REDHAT_BASED} PARENT_SCOPE) endfunction() + +function(apply_libxml2_settings _TARGET) + if(HAVE_LIBXML2_CONFIG) + target_link_libraries(${_TARGET} PUBLIC ${LIBXML2_TARGET_NAME}) + else() + target_include_directories(${_TARGET} PUBLIC ${LIBXML2_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS}) + target_link_libraries(${_TARGET} PUBLIC ${LIBXML2_LIBRARIES} ${ZLIB_LIBRARIES}) + target_compile_definitions(${_TARGET} PUBLIC ${LIBXML2_DEFINITIONS}) + endif() +endfunction() diff --git a/cmake/environmentchecks.cmake b/cmake/environmentchecks.cmake index 071e33682c..4a66b37fab 100644 --- a/cmake/environmentchecks.cmake +++ b/cmake/environmentchecks.cmake @@ -45,10 +45,11 @@ else () endif() find_program(CLANG_FORMAT_EXE NAMES ${PREFERRED_CLANG_FORMAT_NAMES} clang-format) find_program(CLANG_TIDY_EXE NAMES ${PREFERRED_CLANG_TIDY_NAMES} clang-tidy) + find_program(DOT_EXE NAMES ${PREFERRED_FIND_NAMES} dot) find_program(FIND_EXE NAMES ${PREFERRED_FIND_NAMES} find) find_program(GCOV_EXE NAMES ${PREFERRED_GCOV_NAMES} gcov) - find_program(LLVM_COV_EXE NAMES ${PREFERRED_LLVM_COV_NAMES} llvm-cov HINTS ${LLVM_BIN_DIR} /Library/Developer/CommandLineTools/usr/bin/) - find_program(LLVM_PROFDATA_EXE NAMES ${PREFERRED_LLVM_PROFDATA_NAMES} llvm-profdata HINTS ${LLVM_BIN_DIR} /Library/Developer/CommandLineTools/usr/bin/) + find_program(LLVM_COV_EXE NAMES ${PREFERRED_LLVM_COV_NAMES} llvm-cov HINTS ${LLVM_BIN_DIR} ENV PATH /Library/Developer/CommandLineTools/usr/bin/) + find_program(LLVM_PROFDATA_EXE NAMES ${PREFERRED_LLVM_PROFDATA_NAMES} llvm-profdata HINTS ${LLVM_BIN_DIR} ENV PATH /Library/Developer/CommandLineTools/usr/bin/) find_program(VALGRIND_EXE NAMES ${PREFERRED_VALGRIND_NAMES} valgrind) find_program(INSTALL_NAME_TOOL_EXE NAMES ${PREFERRED_INSTALL_NAME_TOOL_NAMES} install_name_tool) @@ -93,6 +94,7 @@ else () BUILDCACHE_EXE CLANG_TIDY_EXE CLANG_FORMAT_EXE + DOT_EXE FIND_EXE GCC_COVERAGE_COMPILER_FLAGS_OK GCOV_EXE diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 6795596e50..8498fc7b4a 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -49,7 +49,7 @@ if(SPHINX_FOUND) COMMENT "Building HTML documentation with Sphinx") endif() -if(DOXYGEN_FOUND) +if(DOXYGEN_FOUND AND DOT_EXE) set(DOXYGEN_DOCS_TARGET api_docs) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in.config ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) add_custom_target(${DOXYGEN_DOCS_TARGET} @@ -76,7 +76,7 @@ if(LIBCELLML_COVERAGE) COMMENT "Running coverage tests with html output") endif() -if(SPHINX_FOUND OR DOXYGEN_FOUND OR LIBCELLML_COVERAGE) +if(SPHINX_FOUND AND DOXYGEN_FOUND AND LIBCELLML_COVERAGE) add_custom_target(docs DEPENDS ${SPHINX_DOCS_TARGET} ${DOXYGEN_DOCS_TARGET} ${COVERAGE_DOCS_TARGET} ${DOXYGEN_API_XML_DOCS_TARGET} COMMENT "Generating documentation") @@ -86,4 +86,3 @@ if(SPHINX_FOUND OR DOXYGEN_FOUND OR LIBCELLML_COVERAGE) COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/_doctrees COMMENT "Cleaning documentation") endif() - diff --git a/docs/conf.in.py b/docs/conf.in.py index 1fad261573..b671f63111 100644 --- a/docs/conf.in.py +++ b/docs/conf.in.py @@ -47,42 +47,42 @@ # These are the shorthand for external links. Use them in the other pages as: # :shortcut:`Shortcut text ` NB space before < # Declare below as: -# 'shortcut': ('http://linkhere/%s',''), NB have to put the string insertion %s to make it work +# 'shortcut': ('http://linkhere/%s', None), NB have to put the string insertion %s to make it work extlinks = { # NB for deployment outside of the libcellml.org domain, you will need to include the root of the href for the # :api: shortcut here. This only works internally. - 'api': ('/documentation/latest/api/classlibcellml_1_1%s', ''), - 'buildbot': ('https://buildbot.net/%s',''), - 'cellml': ('https://www.cellml.org/%s',''), - 'cellml2spec': ('https://www.cellml.org/specifications/cellml_2.0%s', ''), - 'clang': ('https://clang.llvm.org/%s',''), - 'cmake': ('https://cmake.org/%s',''), - 'doxygen': ('http://www.doxygen.nl/%s',''), - 'forcescheduler': ('http://docs.buildbot.net/latest/developer/cls-forcesched.html%s',''), - 'gcc': ('https://gcc.gnu.org/%s',''), - 'gcovr': ('https://gcovr.com/%s',''), - 'git': ('https://git-scm.com/%s',''), - 'github': ('https://github.com/%s',''), - 'github_desktop': ('https://desktop.github.com/%s',''), - 'github_help': ('https://help.github.com%s',''), - 'github_rtd': ('https://github.com/rtfd/readthedocs.org/issues%s',''), - 'google_style_guide': ('https://google.github.io/styleguide/cppguide.html%s',''), - 'graphviz': ('http://graphviz.org%s',''), - 'htpasswd': ('https://httpd.apache.org/docs/current/programs/htpasswd.html%s',''), - 'libcellml_repo': ('https://github.com/cellml/libcellml/%s',''), - 'libcellml_buildbot': ('https://autotest.bioeng.auckland.ac.nz/buildbot/libcellml/#/builders%s',''), - 'libxml2': ('http://xmlsoft.org/%s',''), - 'mathml': ('https://www.w3.org/Math/%s',''), - 'msvs': ('https://visualstudio.microsoft.com%s',''), - 'opencmiss_libxml2_repo': ('https://github.com/OpenCMISS-Dependencies/libxml2/releases%s',''), - 'opencmiss_zlib_repo': ('https://github.com/OpenCMISS-Dependencies/zlib/releases%s',''), - 'python': ('https://www.python.org/%s',''), - 'sphinx': ('http://www.sphinx-doc.org/en/master/%s',''), - 'swig':('http://swig.org%s',''), - 'swigwin_download': ('https://sourceforge.net/projects/swig/files/swigwin/%s',''), - 'wikipedia': ('https://en.wikipedia.org/wiki%s',''), - 'xml': ('https://www.w3.org/XML/%s',''), - 'zlib': ('https://www.zlib.net/%s',''), + 'api': ('/documentation/latest/api/classlibcellml_1_1%s', None), + 'buildbot': ('https://buildbot.net/%s', None), + 'cellml': ('https://www.cellml.org/%s', None), + 'cellml2spec': ('https://www.cellml.org/specifications/cellml_2.0%s', None), + 'clang': ('https://clang.llvm.org/%s', None), + 'cmake': ('https://cmake.org/%s', None), + 'doxygen': ('http://www.doxygen.nl/%s', None), + 'forcescheduler': ('http://docs.buildbot.net/latest/developer/cls-forcesched.html%s', None), + 'gcc': ('https://gcc.gnu.org/%s', None), + 'gcovr': ('https://gcovr.com/%s', None), + 'git': ('https://git-scm.com/%s', None), + 'github': ('https://github.com/%s', None), + 'github_desktop': ('https://desktop.github.com/%s', None), + 'github_help': ('https://help.github.com%s', None), + 'github_rtd': ('https://github.com/rtfd/readthedocs.org/issues%s', None), + 'google_style_guide': ('https://google.github.io/styleguide/cppguide.html%s', None), + 'graphviz': ('http://graphviz.org%s', None), + 'htpasswd': ('https://httpd.apache.org/docs/current/programs/htpasswd.html%s', None), + 'libcellml_repo': ('https://github.com/cellml/libcellml/%s', None), + 'libcellml_buildbot': ('https://autotest.bioeng.auckland.ac.nz/buildbot/libcellml/#/builders%s', None), + 'libxml2': ('http://xmlsoft.org/%s', None), + 'mathml': ('https://www.w3.org/Math/%s', None), + 'msvs': ('https://visualstudio.microsoft.com%s', None), + 'opencmiss_libxml2_repo': ('https://github.com/OpenCMISS-Dependencies/libxml2/releases%s', None), + 'opencmiss_zlib_repo': ('https://github.com/OpenCMISS-Dependencies/zlib/releases%s', None), + 'python': ('https://www.python.org/%s', None), + 'sphinx': ('http://www.sphinx-doc.org/en/master/%s', None), + 'swig':('http://swig.org%s', None), + 'swigwin_download': ('https://sourceforge.net/projects/swig/files/swigwin/%s', None), + 'wikipedia': ('https://en.wikipedia.org/wiki%s', None), + 'xml': ('https://www.w3.org/XML/%s', None), + 'zlib': ('https://www.zlib.net/%s', None), } # The master toctree document. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 30a60d5bc6..ca1dde1d22 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,12 +49,15 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/entity.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enums.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generator.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/generatorinterpreter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generatorprofile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generatorprofiletools.cpp ${CMAKE_CURRENT_SOURCE_DIR}/importedentity.cpp ${CMAKE_CURRENT_SOURCE_DIR}/importer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/importsource.cpp ${CMAKE_CURRENT_SOURCE_DIR}/internaltypes.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/interpreter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/interpreterstatement.cpp ${CMAKE_CURRENT_SOURCE_DIR}/issue.cpp ${CMAKE_CURRENT_SOURCE_DIR}/logger.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mathmldtd.cpp @@ -94,6 +97,7 @@ set(GIT_API_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/importedentity.h ${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/importer.h ${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/importsource.h + ${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/interpreter.h ${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/issue.h ${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/logger.h ${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/model.h @@ -133,9 +137,15 @@ set(GIT_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/debug.h ${CMAKE_CURRENT_SOURCE_DIR}/entity_p.h ${CMAKE_CURRENT_SOURCE_DIR}/generator_p.h + ${CMAKE_CURRENT_SOURCE_DIR}/generatorinterpreter_p.h + ${CMAKE_CURRENT_SOURCE_DIR}/generatorinterpreter.h + ${CMAKE_CURRENT_SOURCE_DIR}/generatorprofile_p.h ${CMAKE_CURRENT_SOURCE_DIR}/generatorprofilesha1values.h ${CMAKE_CURRENT_SOURCE_DIR}/generatorprofiletools.h ${CMAKE_CURRENT_SOURCE_DIR}/internaltypes.h + ${CMAKE_CURRENT_SOURCE_DIR}/interpreter_p.h + ${CMAKE_CURRENT_SOURCE_DIR}/interpreterstatement_p.h + ${CMAKE_CURRENT_SOURCE_DIR}/interpreterstatement.h ${CMAKE_CURRENT_SOURCE_DIR}/issue_p.h ${CMAKE_CURRENT_SOURCE_DIR}/logger_p.h ${CMAKE_CURRENT_SOURCE_DIR}/mathmldtd.h @@ -193,13 +203,7 @@ else() target_include_directories(cellml PUBLIC ${ZLIB_INCLUDE_DIRS}) endif() -if(HAVE_LIBXML2_CONFIG) - target_link_libraries(cellml PUBLIC ${LIBXML2_TARGET_NAME}) -else() - target_include_directories(cellml PUBLIC ${LIBXML2_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS}) - target_link_libraries(cellml PUBLIC ${LIBXML2_LIBRARIES} ${ZLIB_LIBRARIES}) - target_compile_definitions(cellml PUBLIC ${LIBXML2_DEFINITIONS}) -endif() +apply_libxml2_settings(cellml) # Use target compile features to propagate features to consuming projects. target_compile_features(cellml PUBLIC cxx_std_17) @@ -231,6 +235,8 @@ target_include_directories(cellml_debug_utilities $ ) +apply_libxml2_settings(cellml_debug_utilities) + set_target_properties(cellml_debug_utilities PROPERTIES CXX_VISIBILITY_PRESET hidden DEBUG_POSTFIX d @@ -382,3 +388,6 @@ set(CONFIG_FILES ${LIBCELLML_VERSIONCONFIG_H_IN} PARENT_SCOPE ) + +set(DEBUG_SOURCE_FILES ${DEBUG_SOURCE_FILES} PARENT_SCOPE) +set(DEBUG_HEADER_FILES ${DEBUG_HEADER_FILES} PARENT_SCOPE) diff --git a/src/analyser.cpp b/src/analyser.cpp index 8b7c869481..0bb84b717e 100644 --- a/src/analyser.cpp +++ b/src/analyser.cpp @@ -24,85 +24,21 @@ limitations under the License. #include #include "libcellml/analyserequation.h" -#include "libcellml/analyserequationast.h" #include "libcellml/analyserexternalvariable.h" -#include "libcellml/analysermodel.h" -#include "libcellml/analyservariable.h" -#include "libcellml/component.h" -#include "libcellml/generator.h" #include "libcellml/generatorprofile.h" -#include "libcellml/model.h" -#include "libcellml/units.h" #include "libcellml/validator.h" -#include "libcellml/variable.h" +#include "analyser_p.h" #include "analyserequation_p.h" #include "analyserequationast_p.h" -#include "analysermodel_p.h" #include "analyservariable_p.h" -#include "anycellmlelement_p.h" #include "commonutils.h" #include "generator_p.h" -#include "issue_p.h" -#include "logger_p.h" -#include "utilities.h" -#include "xmldoc.h" +#include "generatorinterpreter_p.h" #include "xmlutils.h" -#include "libcellml/undefines.h" - namespace libcellml { -struct AnalyserInternalEquation; -struct AnalyserInternalVariable; - -using AnalyserInternalEquationWeakPtr = std::weak_ptr; -using AnalyserInternalEquationPtr = std::shared_ptr; -using AnalyserInternalVariablePtr = std::shared_ptr; - -using AnalyserInternalEquationWeakPtrs = std::vector; -using AnalyserInternalEquationPtrs = std::vector; -using AnalyserInternalVariablePtrs = std::vector; - -using AnalyserEquationPtrs = std::vector; -using AnalyserVariablePtrs = std::vector; -using AnalyserExternalVariablePtrs = std::vector; - -struct AnalyserInternalVariable -{ - enum struct Type - { - UNKNOWN, - SHOULD_BE_STATE, - INITIALISED, - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_TRUE_CONSTANT, - COMPUTED_VARIABLE_BASED_CONSTANT, - INITIALISED_ALGEBRAIC, - ALGEBRAIC, - OVERCONSTRAINED - }; - - size_t mIndex = MAX_SIZE_T; - Type mType = Type::UNKNOWN; - bool mIsExternal = false; - - VariablePtr mInitialisingVariable; - VariablePtr mVariable; - VariablePtrs mDependencies; - - static AnalyserInternalVariablePtr create(const VariablePtr &variable); - - void setVariable(const VariablePtr &variable, - bool checkInitialValue = true); - - void makeVoi(); - void makeState(); - void makeConstant(size_t &index); -}; - AnalyserInternalVariablePtr AnalyserInternalVariable::create(const VariablePtr &variable) { auto res = AnalyserInternalVariablePtr {new AnalyserInternalVariable {}}; @@ -149,68 +85,11 @@ void AnalyserInternalVariable::makeState() } } -void AnalyserInternalVariable::makeConstant(size_t &index) +void AnalyserInternalVariable::makeConstant() { - mIndex = ++index; mType = Type::CONSTANT; } -struct AnalyserInternalEquation -{ - enum struct Type - { - UNKNOWN, - TRUE_CONSTANT, - VARIABLE_BASED_CONSTANT, - ODE, - NLA, - ALGEBRAIC - }; - - Type mType = Type::UNKNOWN; - - VariablePtrs mDependencies; - - AnalyserEquationAstPtr mAst; - - ComponentPtr mComponent; - - AnalyserInternalVariablePtrs mVariables; - AnalyserInternalVariablePtrs mOdeVariables; - AnalyserInternalVariablePtrs mAllVariables; - AnalyserInternalVariablePtrs mUnknownVariables; - - size_t mNlaSystemIndex = MAX_SIZE_T; - AnalyserInternalEquationWeakPtrs mNlaSiblings; - - bool mComputedTrueConstant = true; - bool mComputedVariableBasedConstant = true; - - static AnalyserInternalEquationPtr create(const ComponentPtr &component); - static AnalyserInternalEquationPtr create(const AnalyserInternalVariablePtr &variable); - - void addVariable(const AnalyserInternalVariablePtr &variable); - void addOdeVariable(const AnalyserInternalVariablePtr &odeVariable); - - static bool isKnownVariable(const AnalyserInternalVariablePtr &variable); - static bool isKnownOdeVariable(const AnalyserInternalVariablePtr &odeVariable); - - static bool hasKnownVariables(const AnalyserInternalVariablePtrs &variables); - bool hasKnownVariables(); - - static bool isNonConstantVariable(const AnalyserInternalVariablePtr &variable); - - static bool hasNonConstantVariables(const AnalyserInternalVariablePtrs &variables); - bool hasNonConstantVariables(); - - bool variableOnLhsRhs(const AnalyserInternalVariablePtr &variable, - const AnalyserEquationAstPtr &astChild); - bool variableOnRhs(const AnalyserInternalVariablePtr &variable); - bool variableOnLhsOrRhs(const AnalyserInternalVariablePtr &variable); - - bool check(const AnalyserModelPtr &model, size_t &stateIndex, size_t &variableIndex, bool checkNlaSystems); -}; - AnalyserInternalEquationPtr AnalyserInternalEquation::create(const ComponentPtr &component) { auto res = AnalyserInternalEquationPtr {new AnalyserInternalEquation {}}; @@ -240,11 +119,11 @@ void AnalyserInternalEquation::addVariable(const AnalyserInternalVariablePtr &va } } -void AnalyserInternalEquation::addOdeVariable(const AnalyserInternalVariablePtr &odeVariable) +void AnalyserInternalEquation::addStateVariable(const AnalyserInternalVariablePtr &stateVariable) { - if (std::find(mOdeVariables.begin(), mOdeVariables.end(), odeVariable) == mOdeVariables.end()) { - mOdeVariables.push_back(odeVariable); - mAllVariables.push_back(odeVariable); + if (std::find(mStateVariables.begin(), mStateVariables.end(), stateVariable) == mStateVariables.end()) { + mStateVariables.push_back(stateVariable); + mAllVariables.push_back(stateVariable); } } @@ -253,9 +132,9 @@ bool AnalyserInternalEquation::isKnownVariable(const AnalyserInternalVariablePtr return variable->mType != AnalyserInternalVariable::Type::UNKNOWN; } -bool AnalyserInternalEquation::isKnownOdeVariable(const AnalyserInternalVariablePtr &odeVariable) +bool AnalyserInternalEquation::isKnownStateVariable(const AnalyserInternalVariablePtr &stateVariable) { - return odeVariable->mIndex != MAX_SIZE_T; + return stateVariable->mIsKnownStateVariable; } bool AnalyserInternalEquation::hasKnownVariables(const AnalyserInternalVariablePtrs &variables) @@ -267,7 +146,7 @@ bool AnalyserInternalEquation::hasKnownVariables(const AnalyserInternalVariableP bool AnalyserInternalEquation::hasKnownVariables() { - return hasKnownVariables(mVariables) || hasKnownVariables(mOdeVariables); + return hasKnownVariables(mVariables) || hasKnownVariables(mStateVariables); } bool AnalyserInternalEquation::isNonConstantVariable(const AnalyserInternalVariablePtr &variable) @@ -277,7 +156,7 @@ bool AnalyserInternalEquation::isNonConstantVariable(const AnalyserInternalVaria // know for sure that it's neither a state variable nor a variable // that is computed using an NLA system. - return variable->mIsExternal + return variable->mIsExternalVariable || ((variable->mType != AnalyserInternalVariable::Type::UNKNOWN) && (variable->mType != AnalyserInternalVariable::Type::INITIALISED) && (variable->mType != AnalyserInternalVariable::Type::COMPUTED_TRUE_CONSTANT) @@ -293,7 +172,7 @@ bool AnalyserInternalEquation::hasNonConstantVariables(const AnalyserInternalVar bool AnalyserInternalEquation::hasNonConstantVariables() { - return hasNonConstantVariables(mVariables) || hasNonConstantVariables(mOdeVariables); + return hasNonConstantVariables(mVariables) || hasNonConstantVariables(mStateVariables); } bool AnalyserInternalEquation::variableOnLhsRhs(const AnalyserInternalVariablePtr &variable, @@ -320,9 +199,7 @@ bool AnalyserInternalEquation::variableOnLhsOrRhs(const AnalyserInternalVariable || variableOnRhs(variable); } -bool AnalyserInternalEquation::check(const AnalyserModelPtr &model, - size_t &stateIndex, size_t &variableIndex, - bool checkNlaSystems) +bool AnalyserInternalEquation::check(const AnalyserModelPtr &model, bool checkNlaSystems) { // Nothing to check if the equation has a known type. @@ -330,13 +207,13 @@ bool AnalyserInternalEquation::check(const AnalyserModelPtr &model, return false; } - // Determine, from the (new) known (ODE) variables, whether the equation is + // Determine, from the (new) known (state) variables, whether the equation is // used to compute a true constant or a variable-based constant. mComputedTrueConstant = mComputedTrueConstant && !hasKnownVariables(); mComputedVariableBasedConstant = mComputedVariableBasedConstant && !hasNonConstantVariables(); - // Add, as a dependency, the variables used to compute the (new) known (ODE) + // Add, as a dependency, the variables used to compute the (new) known (state) // variables. for (const auto &variable : mVariables) { @@ -345,20 +222,20 @@ bool AnalyserInternalEquation::check(const AnalyserModelPtr &model, } } - // Stop tracking (new) known (ODE) variables. + // Stop tracking (new) known (state) variables. mVariables.erase(std::remove_if(mVariables.begin(), mVariables.end(), isKnownVariable), mVariables.end()); - mOdeVariables.erase(std::remove_if(mOdeVariables.begin(), mOdeVariables.end(), isKnownOdeVariable), mOdeVariables.end()); + mStateVariables.erase(std::remove_if(mStateVariables.begin(), mStateVariables.end(), isKnownStateVariable), mStateVariables.end()); - // If there is no (ODE) variable left then it means that the variables in + // If there is no (state) variable left then it means that the variables in // the equation are overconstrained unless one of them was initialised in // which case it will now be considered as an algebraic variable and this // equation as an NLA equation. - auto unknownVariablesOrOdeVariablesLeft = mVariables.size() + mOdeVariables.size(); + auto unknownVariablesOrStateVariablesLeft = mVariables.size() + mStateVariables.size(); AnalyserInternalVariablePtrs initialisedVariables; - if (checkNlaSystems && (unknownVariablesOrOdeVariablesLeft == 0)) { + if (checkNlaSystems && (unknownVariablesOrStateVariablesLeft == 0)) { for (const auto &variable : mAllVariables) { switch (variable->mType) { case AnalyserInternalVariable::Type::INITIALISED: @@ -388,7 +265,7 @@ bool AnalyserInternalEquation::check(const AnalyserModelPtr &model, } } - // If there is one (ODE) variable left (on its own on the LHS/RHS of the + // If there is one (state) variable left (on its own on the LHS/RHS of the // equation or in case we check for NLA systems) or some initialised // variables then update its variable (to be the corresponding one in the // component in which the equation is), as well as set its type (if it is @@ -396,9 +273,9 @@ bool AnalyserInternalEquation::check(const AnalyserModelPtr &model, // Finally, set the type and order of the equation, should everything have // gone as planned. - auto unknownVariableLeft = (unknownVariablesOrOdeVariablesLeft == 1) ? + auto unknownVariableLeft = (unknownVariablesOrStateVariablesLeft == 1) ? mVariables.empty() ? - mOdeVariables.front() : + mStateVariables.front() : mVariables.front() : nullptr; @@ -406,9 +283,9 @@ bool AnalyserInternalEquation::check(const AnalyserModelPtr &model, && (checkNlaSystems || variableOnLhsOrRhs(unknownVariableLeft))) || !initialisedVariables.empty()) { auto variables = mVariables.empty() ? - mOdeVariables.empty() ? + mStateVariables.empty() ? initialisedVariables : - mOdeVariables : + mStateVariables : mVariables; for (const auto &variable : variables) { @@ -435,9 +312,7 @@ bool AnalyserInternalEquation::check(const AnalyserModelPtr &model, case AnalyserInternalVariable::Type::COMPUTED_VARIABLE_BASED_CONSTANT: case AnalyserInternalVariable::Type::INITIALISED_ALGEBRAIC: case AnalyserInternalVariable::Type::ALGEBRAIC: - variable->mIndex = (variable->mType == AnalyserInternalVariable::Type::STATE) ? - ++stateIndex : - ++variableIndex; + variable->mIsKnownStateVariable = variable->mType == AnalyserInternalVariable::Type::STATE; mUnknownVariables.push_back(variable); @@ -495,139 +370,6 @@ bool AnalyserInternalEquation::check(const AnalyserModelPtr &model, return false; } -/** - * @brief The Analyser::AnalyserImpl class. - * - * The private implementation for the Analyser class. - */ -using UnitsMap = std::map; -using UnitsMaps = std::vector; -using UnitsMultipliers = std::vector; - -class Analyser::AnalyserImpl: public Logger::LoggerImpl -{ -public: - class PowerData - { - public: - bool mDimensionlessBase; - bool mExponentValueAvailable = true; - bool mExponentValueChangeable = false; - double mExponentValue; - AnalyserEquationAstPtr mExponentAst; - }; - - Analyser *mAnalyser = nullptr; - - AnalyserModelPtr mModel = AnalyserModel::AnalyserModelImpl::create(); - - AnalyserExternalVariablePtrs mExternalVariables; - - AnalyserInternalVariablePtrs mInternalVariables; - AnalyserInternalEquationPtrs mInternalEquations; - - GeneratorProfilePtr mGeneratorProfile = libcellml::GeneratorProfile::create(); - - std::map mStandardUnits; - std::map mCiCnUnits; - - AnalyserImpl(); - - AnalyserInternalVariablePtr internalVariable(const VariablePtr &variable); - - VariablePtr voiFirstOccurrence(const VariablePtr &variable, - const ComponentPtr &component); - - void analyseNode(const XmlNodePtr &node, AnalyserEquationAstPtr &ast, - const AnalyserEquationAstPtr &astParent, - const ComponentPtr &component, - const AnalyserInternalEquationPtr &equation); - void analyseComponent(const ComponentPtr &component); - void analyseComponentVariables(const ComponentPtr &component); - - void doEquivalentVariables(const VariablePtr &variable, - VariablePtrs &equivalentVariables) const; - VariablePtrs equivalentVariables(const VariablePtr &variable) const; - - void analyseEquationAst(const AnalyserEquationAstPtr &ast); - - void updateUnitsMapWithStandardUnit(const std::string &unitsName, - UnitsMap &unitsMap, - double unitsExponent); - void updateUnitsMap(const ModelPtr &model, const std::string &unitsName, - UnitsMap &unitsMap, bool userUnitsMap = false, - double unitsExponent = 1.0, - double unitsMultiplier = 0.0); - UnitsMap multiplyDivideUnitsMaps(const UnitsMap &firstUnitsMap, - const UnitsMap &secondUnitsMap, - bool multiply); - UnitsMaps multiplyDivideUnitsMaps(const UnitsMaps &firstUnitsMaps, - const UnitsMaps &secondUnitsMaps, - bool multiply = true); - UnitsMaps multiplyDivideUnitsMaps(const UnitsMaps &unitsMaps, - double factor, bool multiply); - double multiplyDivideUnitsMultipliers(double firstUnitsMultiplier, - double secondUnitsMultiplier, - bool multiply); - UnitsMultipliers multiplyDivideUnitsMultipliers(const UnitsMultipliers &firstUnitsMultipliers, - const UnitsMultipliers &secondUnitsMultipliers, - bool multiply = true); - UnitsMultipliers multiplyDivideUnitsMultipliers(double firstUnitsMultiplier, - const UnitsMultipliers &secondUnitsMultipliers, - bool multiply); - UnitsMultipliers powerRootUnitsMultipliers(const UnitsMultipliers &unitsMultipliers, - double factor, bool power); - bool areSameUnitsMaps(const UnitsMaps &firstUnitsMaps, - const UnitsMaps &secondUnitsMaps); - bool isDimensionlessUnitsMaps(const UnitsMaps &unitsMaps); - bool areSameUnitsMultipliers(const UnitsMultipliers &firstUnitsMultipliers, - const UnitsMultipliers &secondUnitsMultipliers); - void updateUnitsMultiplier(const ModelPtr &model, - const std::string &unitsName, - double &newUnitsMultiplier, - double unitsExponent = 1.0, - double unitsMultiplier = 0.0); - std::string componentName(const AnalyserEquationAstPtr &ast); - double powerValue(const AnalyserEquationAstPtr &ast, PowerData &powerData); - std::string expression(const AnalyserEquationAstPtr &ast, - bool includeHierarchy = true); - std::string expressionUnits(const UnitsMaps &unitsMaps, - const UnitsMultipliers &unitsMultipliers = {}); - std::string expressionUnits(const AnalyserEquationAstPtr &ast, - const UnitsMaps &unitsMaps, - const UnitsMaps &userUnitsMaps, - const UnitsMultipliers &unitsMultipliers); - void defaultUnitsMapsAndMultipliers(UnitsMaps &unitsMaps, - UnitsMaps &userUnitsMaps, - UnitsMultipliers &unitsMultipliers); - void analyseEquationUnits(const AnalyserEquationAstPtr &ast, - UnitsMaps &unitsMaps, UnitsMaps &userUnitsMaps, - UnitsMultipliers &unitsMultipliers, - std::string &issueDescription, PowerData &powerData); - - double scalingFactor(const VariablePtr &variable); - - void scaleAst(const AnalyserEquationAstPtr &ast, - const AnalyserEquationAstPtr &astParent, - double scalingFactor); - void scaleEquationAst(const AnalyserEquationAstPtr &ast); - - static bool isExternalVariable(const AnalyserInternalVariablePtr &variable); - - bool isStateRateBased(const AnalyserEquationPtr &equation, - AnalyserEquationPtrs &checkedEquations); - - void addInvalidVariableIssue(const AnalyserInternalVariablePtr &variable, - Issue::ReferenceRule referenceRule); - - void analyseModel(const ModelPtr &model); - - AnalyserExternalVariablePtrs::const_iterator findExternalVariable(const ModelPtr &model, - const std::string &componentName, - const std::string &variableName) const; - AnalyserExternalVariablePtrs::const_iterator findExternalVariable(const AnalyserExternalVariablePtr &externalVariable) const; -}; - Analyser::AnalyserImpl::AnalyserImpl() { // Customise our generator's profile. @@ -635,6 +377,8 @@ Analyser::AnalyserImpl::AnalyserImpl() mGeneratorProfile->setAbsoluteValueString("abs"); mGeneratorProfile->setNaturalLogarithmString("ln"); mGeneratorProfile->setCommonLogarithmString("log"); + mGeneratorProfile->setMinString("min"); + mGeneratorProfile->setMaxString("max"); mGeneratorProfile->setRemString("rem"); mGeneratorProfile->setAsinString("arcsin"); mGeneratorProfile->setAcosString("arccos"); @@ -945,30 +689,32 @@ void Analyser::AnalyserImpl::analyseNode(const XmlNodePtr &node, ast->mPimpl->populate(AnalyserEquationAst::Type::PIECEWISE, astParent); - analyseNode(mathmlChildNode(node, 0), ast->mPimpl->mOwnedLeftChild, ast, component, equation); + if (childCount >= 1) { + analyseNode(mathmlChildNode(node, 0), ast->mPimpl->mOwnedLeftChild, ast, component, equation); - if (childCount >= 2) { - AnalyserEquationAstPtr astRight; - AnalyserEquationAstPtr tempAst; + if (childCount >= 2) { + AnalyserEquationAstPtr astRight; + AnalyserEquationAstPtr tempAst; - analyseNode(mathmlChildNode(node, childCount - 1), astRight, nullptr, component, equation); + analyseNode(mathmlChildNode(node, childCount - 1), astRight, nullptr, component, equation); - for (auto i = childCount - 2; i > 0; --i) { - tempAst = AnalyserEquationAst::create(); + for (auto i = childCount - 2; i > 0; --i) { + tempAst = AnalyserEquationAst::create(); - tempAst->mPimpl->populate(AnalyserEquationAst::Type::PIECEWISE, astParent); + tempAst->mPimpl->populate(AnalyserEquationAst::Type::PIECEWISE, astParent); - analyseNode(mathmlChildNode(node, i), tempAst->mPimpl->mOwnedLeftChild, tempAst, component, equation); + analyseNode(mathmlChildNode(node, i), tempAst->mPimpl->mOwnedLeftChild, tempAst, component, equation); - astRight->mPimpl->mParent = tempAst; + astRight->mPimpl->mParent = tempAst; - tempAst->mPimpl->mOwnedRightChild = astRight; - astRight = tempAst; - } + tempAst->mPimpl->mOwnedRightChild = astRight; + astRight = tempAst; + } - astRight->mPimpl->mParent = ast; + astRight->mPimpl->mParent = ast; - ast->mPimpl->mOwnedRightChild = astRight; + ast->mPimpl->mOwnedRightChild = astRight; + } } } else if (node->isMathmlElement("piece")) { ast->mPimpl->populate(AnalyserEquationAst::Type::PIECE, astParent); @@ -991,11 +737,11 @@ void Analyser::AnalyserImpl::analyseNode(const XmlNodePtr &node, // something that is not allowed in CellML and will therefore be // reported when we validate the model. - // Have our equation track the (ODE) variable (by ODE variable, we mean + // Have our equation track the (state) variable (by state variable, we mean // a variable that is used in a "diff" element). if (node->parent()->firstChild()->isMathmlElement("diff")) { - equation->addOdeVariable(internalVariable(variable)); + equation->addStateVariable(internalVariable(variable)); } else if (!node->parent()->isMathmlElement("bvar")) { equation->addVariable(internalVariable(variable)); } @@ -1165,21 +911,19 @@ void Analyser::AnalyserImpl::analyseComponentVariables(const ComponentPtr &compo if ((variable != internalVariable->mVariable) && !variable->initialValue().empty()) { auto issue = Issue::IssueImpl::create(); - auto trackedVariableComponent = owningComponent(internalVariable->mVariable); issue->mPimpl->setDescription("Variable '" + variable->name() + "' in component '" + component->name() + "' and variable '" + internalVariable->mVariable->name() - + "' in component '" + trackedVariableComponent->name() + + "' in component '" + owningComponent(internalVariable->mVariable)->name() + "' are equivalent and cannot therefore both be initialised."); issue->mPimpl->setReferenceRule(Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_MORE_THAN_ONCE); issue->mPimpl->mItem->mPimpl->setVariable(variable); addIssue(issue); - } else if (!internalVariable->mVariable->initialValue().empty() - && !isCellMLReal(internalVariable->mVariable->initialValue())) { - auto initialisingComponent = owningComponent(internalVariable->mVariable); - auto initialisingVariable = initialisingComponent->variable(internalVariable->mVariable->initialValue()); + } else if (!variable->initialValue().empty() + && !isCellMLReal(variable->initialValue())) { + auto initialisingVariable = owningComponent(variable)->variable(variable->initialValue()); auto initialisingInternalVariable = Analyser::AnalyserImpl::internalVariable(initialisingVariable); if (initialisingInternalVariable->mType != AnalyserInternalVariable::Type::INITIALISED) { @@ -1187,12 +931,28 @@ void Analyser::AnalyserImpl::analyseComponentVariables(const ComponentPtr &compo issue->mPimpl->setDescription("Variable '" + variable->name() + "' in component '" + component->name() - + "' is initialised using variable '" + internalVariable->mVariable->initialValue() + + "' is initialised using variable '" + variable->initialValue() + "', which is not a constant."); issue->mPimpl->setReferenceRule(Issue::ReferenceRule::ANALYSER_VARIABLE_NON_CONSTANT_INITIALISATION); issue->mPimpl->mItem->mPimpl->setVariable(variable); addIssue(issue); + } else { + auto scalingFactor = Units::scalingFactor(variable->units(), initialisingVariable->units()); + + if (!areNearlyEqual(scalingFactor, 1.0)) { + auto issue = Issue::IssueImpl::create(); + + issue->mPimpl->setDescription("Variable '" + variable->name() + + "' in component '" + component->name() + + "' is initialised using variable '" + variable->initialValue() + + "' which has different units."); + issue->mPimpl->setLevel(Issue::Level::WARNING); + issue->mPimpl->setReferenceRule(Issue::ReferenceRule::ANALYSER_VARIABLE_NON_CONSTANT_INITIALISATION); + issue->mPimpl->mItem->mPimpl->setVariable(variable); + + addIssue(issue); + } } } } @@ -2483,7 +2243,7 @@ void Analyser::AnalyserImpl::scaleEquationAst(const AnalyserEquationAstPtr &ast) bool Analyser::AnalyserImpl::isExternalVariable(const AnalyserInternalVariablePtr &variable) { - return variable->mIsExternal; + return variable->mIsExternalVariable; } bool Analyser::AnalyserImpl::isStateRateBased(const AnalyserEquationPtr &equation, @@ -2502,8 +2262,7 @@ bool Analyser::AnalyserImpl::isStateRateBased(const AnalyserEquationPtr &equatio if ((dependency->type() == AnalyserEquation::Type::ODE) || ((dependency->type() == AnalyserEquation::Type::NLA) - && (dependency->variableCount() == 1) - && (dependency->variable(0)->type() == AnalyserVariable::Type::STATE)) + && (dependency->stateCount() == 1)) || isStateRateBased(dependency, checkedEquations)) { return true; } @@ -2604,8 +2363,8 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) primaryExternalVariables[internalVariable->mVariable].push_back(variable); - if (!internalVariable->mIsExternal) { - internalVariable->mIsExternal = true; + if (!internalVariable->mIsExternalVariable) { + internalVariable->mIsExternalVariable = true; for (const auto &dependency : externalVariable->dependencies()) { internalVariable->mDependencies.push_back(Analyser::AnalyserImpl::internalVariable(dependency)->mVariable); @@ -2686,9 +2445,9 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) + "' is"; description += hasPrimaryVariable ? " the" : - (equivalentVariableCount == 1) ? - " its corresponding" : - " their corresponding"; + ((equivalentVariableCount == 1) ? + " its corresponding" : + " their corresponding"); description += " primary variable and will therefore be the one used as an external variable."; referenceRule = Issue::ReferenceRule::ANALYSER_EXTERNAL_VARIABLE_USE_PRIMARY_VARIABLE; @@ -2732,7 +2491,7 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) // Detmerine whether some variables have been marked as external. auto hasExternalVariables = std::any_of(mInternalVariables.begin(), mInternalVariables.end(), [](const auto &iv) { - return iv->mIsExternal; + return iv->mIsExternalVariable; }); // Loop over our equations, checking which variables, if any, can be @@ -2747,8 +2506,6 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) // model invalid) that have been marked as external (rendering the // model valid). - auto stateIndex = MAX_SIZE_T; - auto variableIndex = MAX_SIZE_T; auto loopNumber = 1; bool relevantCheck; auto checkNlaSystems = false; @@ -2757,7 +2514,7 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) relevantCheck = false; for (const auto &internalEquation : mInternalEquations) { - relevantCheck = internalEquation->check(mModel, stateIndex, variableIndex, checkNlaSystems) + relevantCheck = internalEquation->check(mModel, checkNlaSystems) || relevantCheck; } @@ -2772,7 +2529,7 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) // marked as external and we go through the two loops one more time. for (const auto &internalVariable : mInternalVariables) { - if (internalVariable->mIsExternal + if (internalVariable->mIsExternalVariable && (internalVariable->mType == AnalyserInternalVariable::Type::UNKNOWN)) { internalVariable->mType = AnalyserInternalVariable::Type::INITIALISED; } @@ -2802,7 +2559,7 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) case AnalyserInternalVariable::Type::INITIALISED: // The variable is (still) initialised so it has to be a constant. - internalVariable->makeConstant(variableIndex); + internalVariable->makeConstant(); break; case AnalyserInternalVariable::Type::OVERCONSTRAINED: @@ -2856,7 +2613,7 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) if (internalEquation->mType == AnalyserInternalEquation::Type::NLA) { for (const auto &unknownVariable : internalEquation->mUnknownVariables) { - if (unknownVariable->mIsExternal + if (unknownVariable->mIsExternalVariable && (std::find(addedExternalVariables.begin(), addedExternalVariables.end(), unknownVariable) == addedExternalVariables.end())) { addedExternalVariables.push_back(unknownVariable); addedInternalEquations.push_back(AnalyserInternalEquation::create(unknownVariable)); @@ -3004,7 +2761,7 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) // have been marked as external return std::any_of(ie->mUnknownVariables.begin(), ie->mUnknownVariables.end(), [](const auto &uv) { - return !uv->mIsExternal; + return !uv->mIsExternalVariable; }); } @@ -3043,73 +2800,154 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) // in the API. std::map aie2aeMappings; - std::map v2aeMappings; for (const auto &internalEquation : mInternalEquations) { auto equation = AnalyserEquation::AnalyserEquationImpl::create(); aie2aeMappings.emplace(internalEquation, equation); - v2aeMappings.emplace(internalEquation->mUnknownVariables.front()->mVariable, equation); + } + + // Start making our internal equations available through our API. + // Note: start because we need to determine the type of our equations before we can make our internal variables + // available through our API. + + std::map aie2aetMappings; + + for (const auto &internalEquation : mInternalEquations) { + // Determine whether the equation is an external one. + + auto externalEquation = true; + + for (const auto &unknownVariable : internalEquation->mUnknownVariables) { + if (!unknownVariable->mIsExternalVariable) { + externalEquation = false; + + break; + } + } + + // Determine and keep track of the type of the equation. + + AnalyserEquation::Type type; + + if (externalEquation) { + type = AnalyserEquation::Type::EXTERNAL; + } else { + switch (internalEquation->mType) { + case AnalyserInternalEquation::Type::TRUE_CONSTANT: + type = AnalyserEquation::Type::TRUE_CONSTANT; + + break; + case AnalyserInternalEquation::Type::VARIABLE_BASED_CONSTANT: + type = AnalyserEquation::Type::VARIABLE_BASED_CONSTANT; + + break; + case AnalyserInternalEquation::Type::ODE: + type = AnalyserEquation::Type::ODE; + + break; + case AnalyserInternalEquation::Type::NLA: + type = AnalyserEquation::Type::NLA; + + break; + case AnalyserInternalEquation::Type::ALGEBRAIC: + type = AnalyserEquation::Type::ALGEBRAIC; + + break; + default: // AnalyserEquation::Type::UNKNOWN. + // The equation type is unknown, which means that it is a dummy + // equation for a true (i.e. non-computed) constant (so that it + // could have been marked as an external variable), so we skip + // it since the constant wasn't marked as an external variable. + + continue; + } + } + + aie2aetMappings.emplace(internalEquation, type); } // Make our internal variables available through our API. std::map aiv2avMappings; std::map v2avMappings; - - stateIndex = MAX_SIZE_T; - variableIndex = MAX_SIZE_T; + auto stateIndex = MAX_SIZE_T; + auto constantIndex = MAX_SIZE_T; + auto computedConstantIndex = MAX_SIZE_T; + auto algebraicIndex = MAX_SIZE_T; + auto externalIndex = MAX_SIZE_T; for (const auto &internalVariable : mInternalVariables) { // Determine the type of the variable. - AnalyserVariable::Type type; + AnalyserVariable::Type variableType; - if (internalVariable->mIsExternal) { - type = AnalyserVariable::Type::EXTERNAL; + if (internalVariable->mIsExternalVariable) { + variableType = AnalyserVariable::Type::EXTERNAL; } else { switch (internalVariable->mType) { case AnalyserInternalVariable::Type::STATE: - type = AnalyserVariable::Type::STATE; + variableType = AnalyserVariable::Type::STATE; break; case AnalyserInternalVariable::Type::CONSTANT: - type = AnalyserVariable::Type::CONSTANT; + variableType = AnalyserVariable::Type::CONSTANT; break; case AnalyserInternalVariable::Type::COMPUTED_TRUE_CONSTANT: case AnalyserInternalVariable::Type::COMPUTED_VARIABLE_BASED_CONSTANT: - type = AnalyserVariable::Type::COMPUTED_CONSTANT; + variableType = AnalyserVariable::Type::COMPUTED_CONSTANT; break; case AnalyserInternalVariable::Type::ALGEBRAIC: case AnalyserInternalVariable::Type::INITIALISED_ALGEBRAIC: - type = AnalyserVariable::Type::ALGEBRAIC; + variableType = AnalyserVariable::Type::ALGEBRAIC; break; - default: // AnalyserVariable::Type::VARIABLE_OF_INTEGRATION. + default: // AnalyserInternalVariable::Type::VARIABLE_OF_INTEGRATION. // This is the variable of integration, so skip it. continue; } } - // Populate and keep track of the state/variable. + // Retrieve the equations used to compute the variable. - auto variable = AnalyserVariable::AnalyserVariableImpl::create(); AnalyserEquationPtrs equations; + auto isNlaEquation = false; for (const auto &internalEquation : mInternalEquations) { if (std::find(internalEquation->mUnknownVariables.begin(), internalEquation->mUnknownVariables.end(), internalVariable) != internalEquation->mUnknownVariables.end()) { equations.push_back(aie2aeMappings[internalEquation]); + + if ((aie2aetMappings.find(internalEquation) != aie2aetMappings.end()) + && (aie2aetMappings[internalEquation] == AnalyserEquation::Type::NLA)) { + isNlaEquation = true; + } } } - variable->mPimpl->populate(type, - (type == AnalyserVariable::Type::STATE) ? + // Correct the type of the variable if it is a computed constant that is computed using an NLA equation. + + if ((variableType == AnalyserVariable::Type::COMPUTED_CONSTANT) && isNlaEquation) { + variableType = AnalyserVariable::Type::ALGEBRAIC; + } + + // Populate and keep track of the state/variable. + + auto variable = AnalyserVariable::AnalyserVariableImpl::create(); + + variable->mPimpl->populate(variableType, + (variableType == AnalyserVariable::Type::STATE) ? ++stateIndex : - ++variableIndex, - (type == AnalyserVariable::Type::EXTERNAL) ? + (variableType == AnalyserVariable::Type::CONSTANT) ? + ++constantIndex : + (variableType == AnalyserVariable::Type::COMPUTED_CONSTANT) ? + ++computedConstantIndex : + (variableType == AnalyserVariable::Type::ALGEBRAIC) ? + ++algebraicIndex : + ++externalIndex, + (variableType == AnalyserVariable::Type::EXTERNAL) ? nullptr : internalVariable->mInitialisingVariable, internalVariable->mVariable, @@ -3118,68 +2956,26 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) aiv2avMappings.emplace(internalVariable, variable); v2avMappings.emplace(internalVariable->mVariable, variable); - if (type == AnalyserVariable::Type::STATE) { + if (variableType == AnalyserVariable::Type::STATE) { mModel->mPimpl->mStates.push_back(variable); - } else { - mModel->mPimpl->mVariables.push_back(variable); + } else if (variableType == AnalyserVariable::Type::CONSTANT) { + mModel->mPimpl->mConstants.push_back(variable); + } else if (variableType == AnalyserVariable::Type::COMPUTED_CONSTANT) { + mModel->mPimpl->mComputedConstants.push_back(variable); + } else if (variableType == AnalyserVariable::Type::ALGEBRAIC) { + mModel->mPimpl->mAlgebraic.push_back(variable); + } else { // AnalyserVariable::Type::EXTERNAL. + mModel->mPimpl->mExternals.push_back(variable); } } - // Make our internal equations available through our API. + // Finish making our internal equations available through our API. for (const auto &internalEquation : mInternalEquations) { - // Determine all the variables computed by the equation, as well as - // whether the equation is an external one. - - AnalyserVariablePtrs variables; - auto externalEquation = true; - - for (const auto &unknownVariable : internalEquation->mUnknownVariables) { - auto variable = aiv2avMappings[unknownVariable]; + // Make sure that the type of the equation is known. - variables.push_back(variable); - - if (variable->type() != AnalyserVariable::Type::EXTERNAL) { - externalEquation = false; - } - } - - // Determine the type of the equation. - - AnalyserEquation::Type type; - - if (externalEquation) { - type = AnalyserEquation::Type::EXTERNAL; - } else { - switch (internalEquation->mType) { - case AnalyserInternalEquation::Type::TRUE_CONSTANT: - type = AnalyserEquation::Type::TRUE_CONSTANT; - - break; - case AnalyserInternalEquation::Type::VARIABLE_BASED_CONSTANT: - type = AnalyserEquation::Type::VARIABLE_BASED_CONSTANT; - - break; - case AnalyserInternalEquation::Type::ODE: - type = AnalyserEquation::Type::ODE; - - break; - case AnalyserInternalEquation::Type::NLA: - type = AnalyserEquation::Type::NLA; - - break; - case AnalyserInternalEquation::Type::ALGEBRAIC: - type = AnalyserEquation::Type::ALGEBRAIC; - - break; - default: // AnalyserEquation::Type::UNKNOWN. - // The equation type is unknown, which means that it is a dummy - // equation for a true (i.e. non-computed) constant (so that it - // could have been marked as an external variable), so we skip - // it since the constant wasn't marked as an external variable. - - continue; - } + if (aie2aetMappings.find(internalEquation) == aie2aetMappings.end()) { + continue; } // Scale our internal equation's AST to take into account the fact that @@ -3190,7 +2986,9 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) // Manipulate the equation, if needed. - switch (type) { + auto equationType = aie2aetMappings[internalEquation]; + + switch (equationType) { case AnalyserEquation::Type::NLA: // The equation is currently of the form LHS = RHS, but we want it // in the form LHS-RHS, so replace the equality element with a minus @@ -3219,7 +3017,7 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) VariablePtrs variableDependencies; - if (type == AnalyserEquation::Type::EXTERNAL) { + if (equationType == AnalyserEquation::Type::EXTERNAL) { for (const auto &unknownVariable : internalEquation->mUnknownVariables) { for (const auto &dependency : unknownVariable->mDependencies) { variableDependencies.push_back(dependency); @@ -3257,14 +3055,33 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) auto equation = aie2aeMappings[internalEquation]; - equation->mPimpl->populate(type, - (type == AnalyserEquation::Type::EXTERNAL) ? - nullptr : - internalEquation->mAst, - equationDependencies, - internalEquation->mNlaSystemIndex, - equationNlaSiblings, - variables); + equation->mPimpl->mType = equationType; + equation->mPimpl->mAst = (equationType == AnalyserEquation::Type::EXTERNAL) ? + nullptr : + internalEquation->mAst; + equation->mPimpl->mNlaSystemIndex = internalEquation->mNlaSystemIndex; + + for (const auto &unknownVariable : internalEquation->mUnknownVariables) { + // Keep track of the variable that the equation computes. + // Note: an unknown variable cannot be the variable of integration (since it cannot be computed) or a + // constant (snce it is not computed but set), so no need to check for those. + + auto variable = aiv2avMappings[unknownVariable]; + auto variableType = variable->type(); + + if (variableType == AnalyserVariable::Type::STATE) { + equation->mPimpl->mStates.push_back(variable); + } else if (variableType == AnalyserVariable::Type::COMPUTED_CONSTANT) { + equation->mPimpl->mComputedConstants.push_back(variable); + } else if (variableType == AnalyserVariable::Type::ALGEBRAIC) { + equation->mPimpl->mAlgebraic.push_back(variable); + } else { // AnalyserVariable::Type::EXTERNAL. + equation->mPimpl->mExternals.push_back(variable); + } + } + + std::copy(equationDependencies.begin(), equationDependencies.end(), back_inserter(equation->mPimpl->mDependencies)); + std::copy(equationNlaSiblings.begin(), equationNlaSiblings.end(), back_inserter(equation->mPimpl->mNlaSiblings)); mModel->mPimpl->mEquations.push_back(equation); } @@ -3290,16 +3107,10 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) } } -AnalyserExternalVariablePtrs::const_iterator Analyser::AnalyserImpl::findExternalVariable(const ModelPtr &model, - const std::string &componentName, - const std::string &variableName) const +AnalyserExternalVariablePtrs::const_iterator Analyser::AnalyserImpl::findExternalVariable(const VariablePtr &variable) const { return std::find_if(mExternalVariables.begin(), mExternalVariables.end(), [=](const auto &ev) { - auto variable = ev->variable(); - - return (owningModel(variable) == model) - && (owningComponent(variable)->name() == componentName) - && (variable->name() == variableName); + return ev->variable() == variable; }); } @@ -3387,6 +3198,19 @@ void Analyser::analyseModel(const ModelPtr &model) } } +bool Analyser::addExternalVariable(const VariablePtr &variable) +{ + for (const auto &externalVariable : pFunc()->mExternalVariables) { + if (externalVariable->variable() == variable) { + return false; + } + } + + pFunc()->mExternalVariables.push_back(AnalyserExternalVariable::create(variable)); + + return true; +} + bool Analyser::addExternalVariable(const AnalyserExternalVariablePtr &externalVariable) { if (std::find(pFunc()->mExternalVariables.begin(), pFunc()->mExternalVariables.end(), externalVariable) == pFunc()->mExternalVariables.end()) { @@ -3409,11 +3233,9 @@ bool Analyser::removeExternalVariable(size_t index) return false; } -bool Analyser::removeExternalVariable(const ModelPtr &model, - const std::string &componentName, - const std::string &variableName) +bool Analyser::removeExternalVariable(const VariablePtr &variable) { - auto result = pFunc()->findExternalVariable(model, componentName, variableName); + auto result = pFunc()->findExternalVariable(variable); if (result != pFunc()->mExternalVariables.end()) { pFunc()->mExternalVariables.erase(result); @@ -3442,11 +3264,9 @@ void Analyser::removeAllExternalVariables() pFunc()->mExternalVariables.clear(); } -bool Analyser::containsExternalVariable(const ModelPtr &model, - const std::string &componentName, - const std::string &variableName) const +bool Analyser::containsExternalVariable(const VariablePtr &variable) const { - return pFunc()->findExternalVariable(model, componentName, variableName) != pFunc()->mExternalVariables.end(); + return pFunc()->findExternalVariable(variable) != pFunc()->mExternalVariables.end(); } bool Analyser::containsExternalVariable(const AnalyserExternalVariablePtr &externalVariable) const @@ -3463,11 +3283,9 @@ AnalyserExternalVariablePtr Analyser::externalVariable(size_t index) const return nullptr; } -AnalyserExternalVariablePtr Analyser::externalVariable(const ModelPtr &model, - const std::string &componentName, - const std::string &variableName) const +AnalyserExternalVariablePtr Analyser::externalVariable(const VariablePtr &variable) const { - auto result = pFunc()->findExternalVariable(model, componentName, variableName); + auto result = pFunc()->findExternalVariable(variable); if (result != pFunc()->mExternalVariables.end()) { return *result; diff --git a/src/analyser_p.h b/src/analyser_p.h new file mode 100644 index 0000000000..97779631aa --- /dev/null +++ b/src/analyser_p.h @@ -0,0 +1,264 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// #include "libcellml/analyser.h" + +#include "analysermodel_p.h" +#include "internaltypes.h" +#include "issue_p.h" +#include "logger_p.h" +#include "utilities.h" + +namespace libcellml { + +struct AnalyserInternalEquation; +struct AnalyserInternalVariable; + +using AnalyserInternalEquationWeakPtr = std::weak_ptr; +using AnalyserInternalEquationPtr = std::shared_ptr; +using AnalyserInternalVariablePtr = std::shared_ptr; + +using AnalyserInternalEquationWeakPtrs = std::vector; +using AnalyserInternalEquationPtrs = std::vector; +using AnalyserInternalVariablePtrs = std::vector; + +using AnalyserEquationPtrs = std::vector; +using AnalyserVariablePtrs = std::vector; +using AnalyserExternalVariablePtrs = std::vector; + +struct AnalyserInternalVariable +{ + enum struct Type + { + UNKNOWN, + SHOULD_BE_STATE, + INITIALISED, + VARIABLE_OF_INTEGRATION, + STATE, + CONSTANT, + COMPUTED_TRUE_CONSTANT, + COMPUTED_VARIABLE_BASED_CONSTANT, + INITIALISED_ALGEBRAIC, + ALGEBRAIC, + OVERCONSTRAINED + }; + + Type mType = Type::UNKNOWN; + bool mIsKnownStateVariable = false; + bool mIsExternalVariable = false; + + VariablePtr mInitialisingVariable; + VariablePtr mVariable; + VariablePtrs mDependencies; + + static AnalyserInternalVariablePtr create(const VariablePtr &variable); + + void setVariable(const VariablePtr &variable, + bool checkInitialValue = true); + + void makeVoi(); + void makeState(); + void makeConstant(); +}; + +struct AnalyserInternalEquation +{ + enum struct Type + { + UNKNOWN, + TRUE_CONSTANT, + VARIABLE_BASED_CONSTANT, + ODE, + NLA, + ALGEBRAIC + }; + + Type mType = Type::UNKNOWN; + + VariablePtrs mDependencies; + + AnalyserEquationAstPtr mAst; + + ComponentPtr mComponent; + + AnalyserInternalVariablePtrs mVariables; + AnalyserInternalVariablePtrs mStateVariables; + AnalyserInternalVariablePtrs mAllVariables; + AnalyserInternalVariablePtrs mUnknownVariables; + + size_t mNlaSystemIndex = MAX_SIZE_T; + AnalyserInternalEquationWeakPtrs mNlaSiblings; + + bool mComputedTrueConstant = true; + bool mComputedVariableBasedConstant = true; + + static AnalyserInternalEquationPtr create(const ComponentPtr &component); + static AnalyserInternalEquationPtr create(const AnalyserInternalVariablePtr &variable); + + void addVariable(const AnalyserInternalVariablePtr &variable); + void addStateVariable(const AnalyserInternalVariablePtr &stateVariable); + + static bool isKnownVariable(const AnalyserInternalVariablePtr &variable); + static bool isKnownStateVariable(const AnalyserInternalVariablePtr &stateVariable); + + static bool hasKnownVariables(const AnalyserInternalVariablePtrs &variables); + bool hasKnownVariables(); + + static bool isNonConstantVariable(const AnalyserInternalVariablePtr &variable); + + static bool hasNonConstantVariables(const AnalyserInternalVariablePtrs &variables); + bool hasNonConstantVariables(); + + bool variableOnLhsRhs(const AnalyserInternalVariablePtr &variable, + const AnalyserEquationAstPtr &astChild); + bool variableOnRhs(const AnalyserInternalVariablePtr &variable); + bool variableOnLhsOrRhs(const AnalyserInternalVariablePtr &variable); + + bool check(const AnalyserModelPtr &model, bool checkNlaSystems); +}; + +/** + * @brief The Analyser::AnalyserImpl class. + * + * The private implementation for the Analyser class. + */ +using UnitsMap = std::map; +using UnitsMaps = std::vector; +using UnitsMultipliers = std::vector; + +class Analyser::AnalyserImpl: public Logger::LoggerImpl +{ +public: + class PowerData + { + public: + bool mDimensionlessBase; + bool mExponentValueAvailable = true; + bool mExponentValueChangeable = false; + double mExponentValue; + AnalyserEquationAstPtr mExponentAst; + }; + + Analyser *mAnalyser = nullptr; + + AnalyserModelPtr mModel = AnalyserModel::AnalyserModelImpl::create(); + + AnalyserExternalVariablePtrs mExternalVariables; + + AnalyserInternalVariablePtrs mInternalVariables; + AnalyserInternalEquationPtrs mInternalEquations; + + GeneratorProfilePtr mGeneratorProfile = libcellml::GeneratorProfile::create(); + + std::map mStandardUnits; + std::map mCiCnUnits; + + AnalyserImpl(); + + AnalyserInternalVariablePtr internalVariable(const VariablePtr &variable); + + VariablePtr voiFirstOccurrence(const VariablePtr &variable, + const ComponentPtr &component); + + void analyseNode(const XmlNodePtr &node, AnalyserEquationAstPtr &ast, + const AnalyserEquationAstPtr &astParent, + const ComponentPtr &component, + const AnalyserInternalEquationPtr &equation); + void analyseComponent(const ComponentPtr &component); + void analyseComponentVariables(const ComponentPtr &component); + + void doEquivalentVariables(const VariablePtr &variable, + VariablePtrs &equivalentVariables) const; + VariablePtrs equivalentVariables(const VariablePtr &variable) const; + + void analyseEquationAst(const AnalyserEquationAstPtr &ast); + + void updateUnitsMapWithStandardUnit(const std::string &unitsName, + UnitsMap &unitsMap, + double unitsExponent); + void updateUnitsMap(const ModelPtr &model, const std::string &unitsName, + UnitsMap &unitsMap, bool userUnitsMap = false, + double unitsExponent = 1.0, + double unitsMultiplier = 0.0); + UnitsMap multiplyDivideUnitsMaps(const UnitsMap &firstUnitsMap, + const UnitsMap &secondUnitsMap, + bool multiply); + UnitsMaps multiplyDivideUnitsMaps(const UnitsMaps &firstUnitsMaps, + const UnitsMaps &secondUnitsMaps, + bool multiply = true); + UnitsMaps multiplyDivideUnitsMaps(const UnitsMaps &unitsMaps, + double factor, bool multiply); + double multiplyDivideUnitsMultipliers(double firstUnitsMultiplier, + double secondUnitsMultiplier, + bool multiply); + UnitsMultipliers multiplyDivideUnitsMultipliers(const UnitsMultipliers &firstUnitsMultipliers, + const UnitsMultipliers &secondUnitsMultipliers, + bool multiply = true); + UnitsMultipliers multiplyDivideUnitsMultipliers(double firstUnitsMultiplier, + const UnitsMultipliers &secondUnitsMultipliers, + bool multiply); + UnitsMultipliers powerRootUnitsMultipliers(const UnitsMultipliers &unitsMultipliers, + double factor, bool power); + bool areSameUnitsMaps(const UnitsMaps &firstUnitsMaps, + const UnitsMaps &secondUnitsMaps); + bool isDimensionlessUnitsMaps(const UnitsMaps &unitsMaps); + bool areSameUnitsMultipliers(const UnitsMultipliers &firstUnitsMultipliers, + const UnitsMultipliers &secondUnitsMultipliers); + void updateUnitsMultiplier(const ModelPtr &model, + const std::string &unitsName, + double &newUnitsMultiplier, + double unitsExponent = 1.0, + double unitsMultiplier = 0.0); + std::string componentName(const AnalyserEquationAstPtr &ast); + double powerValue(const AnalyserEquationAstPtr &ast, PowerData &powerData); + std::string expression(const AnalyserEquationAstPtr &ast, + bool includeHierarchy = true); + std::string expressionUnits(const UnitsMaps &unitsMaps, + const UnitsMultipliers &unitsMultipliers = {}); + std::string expressionUnits(const AnalyserEquationAstPtr &ast, + const UnitsMaps &unitsMaps, + const UnitsMaps &userUnitsMaps, + const UnitsMultipliers &unitsMultipliers); + void defaultUnitsMapsAndMultipliers(UnitsMaps &unitsMaps, + UnitsMaps &userUnitsMaps, + UnitsMultipliers &unitsMultipliers); + void analyseEquationUnits(const AnalyserEquationAstPtr &ast, + UnitsMaps &unitsMaps, UnitsMaps &userUnitsMaps, + UnitsMultipliers &unitsMultipliers, + std::string &issueDescription, PowerData &powerData); + + double scalingFactor(const VariablePtr &variable); + + void scaleAst(const AnalyserEquationAstPtr &ast, + const AnalyserEquationAstPtr &astParent, + double scalingFactor); + void scaleEquationAst(const AnalyserEquationAstPtr &ast); + + static bool isExternalVariable(const AnalyserInternalVariablePtr &variable); + + bool isStateRateBased(const AnalyserEquationPtr &equation, + AnalyserEquationPtrs &checkedEquations); + + void addInvalidVariableIssue(const AnalyserInternalVariablePtr &variable, + Issue::ReferenceRule referenceRule); + + void analyseModel(const ModelPtr &model); + + AnalyserExternalVariablePtrs::const_iterator findExternalVariable(const VariablePtr &variable) const; + AnalyserExternalVariablePtrs::const_iterator findExternalVariable(const AnalyserExternalVariablePtr &externalVariable) const; +}; + +} // namespace libcellml diff --git a/src/analyserequation.cpp b/src/analyserequation.cpp index 228dd119e0..c559bfe64d 100644 --- a/src/analyserequation.cpp +++ b/src/analyserequation.cpp @@ -20,6 +20,7 @@ limitations under the License. #include #include "analyserequation_p.h" +#include "utilities.h" namespace libcellml { @@ -28,25 +29,9 @@ AnalyserEquationPtr AnalyserEquation::AnalyserEquationImpl::create() return std::shared_ptr {new AnalyserEquation {}}; } -void AnalyserEquation::AnalyserEquationImpl::populate(AnalyserEquation::Type type, - const AnalyserEquationAstPtr &ast, - const std::vector &dependencies, - size_t nlaSystemIndex, - const std::vector &nlaSiblings, - const std::vector &variables) -{ - mType = type; - mAst = ast; - mNlaSystemIndex = nlaSystemIndex; - - std::copy(dependencies.begin(), dependencies.end(), back_inserter(mDependencies)); - std::copy(nlaSiblings.begin(), nlaSiblings.end(), back_inserter(mNlaSiblings)); - std::copy(variables.begin(), variables.end(), back_inserter(mVariables)); -} - bool AnalyserEquation::AnalyserEquationImpl::isEmptyDependency(const AnalyserEquationWeakPtr &dependency) { - auto variables = dependency.lock()->variables(); + auto variables = libcellml::variables(dependency.lock()); if (std::any_of(variables.begin(), variables.end(), [](const auto &v) { return v != nullptr; })) { return false; @@ -153,23 +138,80 @@ bool AnalyserEquation::isStateRateBased() const return mPimpl->mIsStateRateBased; } -size_t AnalyserEquation::variableCount() const +size_t AnalyserEquation::stateCount() const +{ + return mPimpl->mStates.size(); +} + +std::vector AnalyserEquation::states() const +{ + return mPimpl->mStates; +} + +AnalyserVariablePtr AnalyserEquation::state(size_t index) const +{ + if (index >= mPimpl->mStates.size()) { + return {}; + } + + return mPimpl->mStates[index]; +} + +size_t AnalyserEquation::computedConstantCount() const +{ + return mPimpl->mComputedConstants.size(); +} + +std::vector AnalyserEquation::computedConstants() const +{ + return mPimpl->mComputedConstants; +} + +AnalyserVariablePtr AnalyserEquation::computedConstant(size_t index) const +{ + if (index >= mPimpl->mComputedConstants.size()) { + return {}; + } + + return mPimpl->mComputedConstants[index]; +} + +size_t AnalyserEquation::algebraicCount() const +{ + return mPimpl->mAlgebraic.size(); +} + +std::vector AnalyserEquation::algebraic() const +{ + return mPimpl->mAlgebraic; +} + +AnalyserVariablePtr AnalyserEquation::algebraic(size_t index) const +{ + if (index >= mPimpl->mAlgebraic.size()) { + return {}; + } + + return mPimpl->mAlgebraic[index]; +} + +size_t AnalyserEquation::externalCount() const { - return mPimpl->mVariables.size(); + return mPimpl->mExternals.size(); } -std::vector AnalyserEquation::variables() const +std::vector AnalyserEquation::externals() const { - return mPimpl->mVariables; + return mPimpl->mExternals; } -AnalyserVariablePtr AnalyserEquation::variable(size_t index) const +AnalyserVariablePtr AnalyserEquation::external(size_t index) const { - if (index >= mPimpl->mVariables.size()) { + if (index >= mPimpl->mExternals.size()) { return {}; } - return mPimpl->mVariables[index]; + return mPimpl->mExternals[index]; } } // namespace libcellml diff --git a/src/analyserequation_p.h b/src/analyserequation_p.h index 79d9fa63ad..a75f6faff8 100644 --- a/src/analyserequation_p.h +++ b/src/analyserequation_p.h @@ -31,20 +31,18 @@ struct AnalyserEquation::AnalyserEquationImpl { AnalyserEquation::Type mType = AnalyserEquation::Type::ALGEBRAIC; AnalyserEquationAstPtr mAst; - std::vector mDependencies; size_t mNlaSystemIndex; - std::vector mNlaSiblings; bool mIsStateRateBased = false; - std::vector mVariables; - static AnalyserEquationPtr create(); + std::vector mStates; + std::vector mComputedConstants; + std::vector mAlgebraic; + std::vector mExternals; - void populate(AnalyserEquation::Type type, - const AnalyserEquationAstPtr &ast, - const std::vector &dependencies, - size_t nlaSystemIndex, - const std::vector &nlaSiblings, - const std::vector &variables); + std::vector mDependencies; + std::vector mNlaSiblings; + + static AnalyserEquationPtr create(); static bool isEmptyDependency(const AnalyserEquationWeakPtr &dependency); diff --git a/src/analyserequationast.cpp b/src/analyserequationast.cpp index f543f766f1..ccb0a915a6 100644 --- a/src/analyserequationast.cpp +++ b/src/analyserequationast.cpp @@ -18,8 +18,6 @@ limitations under the License. #include "analyserequationast_p.h" -#include "libcellml/undefines.h" - namespace libcellml { void AnalyserEquationAst::AnalyserEquationAstImpl::populate(AnalyserEquationAst::Type type, diff --git a/src/analyserexternalvariable.cpp b/src/analyserexternalvariable.cpp index 41a9606ff9..b1910f8843 100644 --- a/src/analyserexternalvariable.cpp +++ b/src/analyserexternalvariable.cpp @@ -17,7 +17,6 @@ limitations under the License. #include "libcellml/analyserexternalvariable.h" #include "analyserexternalvariable_p.h" -#include "commonutils.h" #include "utilities.h" namespace libcellml { diff --git a/src/analysermodel.cpp b/src/analysermodel.cpp index 1931ca3893..9b783f1648 100644 --- a/src/analysermodel.cpp +++ b/src/analysermodel.cpp @@ -121,31 +121,112 @@ AnalyserVariablePtr AnalyserModel::state(size_t index) const return mPimpl->mStates[index]; } -size_t AnalyserModel::variableCount() const +size_t AnalyserModel::constantCount() const { if (!isValid()) { return 0; } - return mPimpl->mVariables.size(); + return mPimpl->mConstants.size(); } -std::vector AnalyserModel::variables() const +std::vector AnalyserModel::constants() const { if (!isValid()) { return {}; } - return mPimpl->mVariables; + return mPimpl->mConstants; } -AnalyserVariablePtr AnalyserModel::variable(size_t index) const +AnalyserVariablePtr AnalyserModel::constant(size_t index) const { - if (!isValid() || (index >= mPimpl->mVariables.size())) { + if (!isValid() || (index >= mPimpl->mConstants.size())) { return {}; } - return mPimpl->mVariables[index]; + return mPimpl->mConstants[index]; +} + +size_t AnalyserModel::computedConstantCount() const +{ + if (!isValid()) { + return 0; + } + + return mPimpl->mComputedConstants.size(); +} + +std::vector AnalyserModel::computedConstants() const +{ + if (!isValid()) { + return {}; + } + + return mPimpl->mComputedConstants; +} + +AnalyserVariablePtr AnalyserModel::computedConstant(size_t index) const +{ + if (!isValid() || (index >= mPimpl->mComputedConstants.size())) { + return {}; + } + + return mPimpl->mComputedConstants[index]; +} + +size_t AnalyserModel::algebraicCount() const +{ + if (!isValid()) { + return 0; + } + + return mPimpl->mAlgebraic.size(); +} + +std::vector AnalyserModel::algebraic() const +{ + if (!isValid()) { + return {}; + } + + return mPimpl->mAlgebraic; +} + +AnalyserVariablePtr AnalyserModel::algebraic(size_t index) const +{ + if (!isValid() || (index >= mPimpl->mAlgebraic.size())) { + return {}; + } + + return mPimpl->mAlgebraic[index]; +} + +size_t AnalyserModel::externalCount() const +{ + if (!isValid()) { + return 0; + } + + return mPimpl->mExternals.size(); +} + +std::vector AnalyserModel::externals() const +{ + if (!isValid()) { + return {}; + } + + return mPimpl->mExternals; +} + +AnalyserVariablePtr AnalyserModel::external(size_t index) const +{ + if (!isValid() || (index >= mPimpl->mExternals.size())) { + return {}; + } + + return mPimpl->mExternals[index]; } size_t AnalyserModel::equationCount() const diff --git a/src/analysermodel_p.h b/src/analysermodel_p.h index 2933e8a948..24cb80e580 100644 --- a/src/analysermodel_p.h +++ b/src/analysermodel_p.h @@ -34,8 +34,13 @@ struct AnalyserModel::AnalyserModelImpl bool mHasExternalVariables = false; AnalyserVariablePtr mVoi; + std::vector mStates; - std::vector mVariables; + std::vector mConstants; + std::vector mComputedConstants; + std::vector mAlgebraic; + std::vector mExternals; + std::vector mEquations; bool mNeedEqFunction = false; diff --git a/src/analyservariable.cpp b/src/analyservariable.cpp index 3c03d84734..bcda865b32 100644 --- a/src/analyservariable.cpp +++ b/src/analyservariable.cpp @@ -40,7 +40,6 @@ void AnalyserVariable::AnalyserVariableImpl::populate(AnalyserVariable::Type typ mIndex = index; mInitialisingVariable = initialisingVariable; mVariable = variable; - mComponent = owningComponent(mVariable); std::copy(equations.begin(), equations.end(), back_inserter(mEquations)); } diff --git a/src/analyservariable_p.h b/src/analyservariable_p.h index 98f0462a94..71a146da4c 100644 --- a/src/analyservariable_p.h +++ b/src/analyservariable_p.h @@ -33,7 +33,6 @@ struct AnalyserVariable::AnalyserVariableImpl size_t mIndex = 0; VariablePtr mInitialisingVariable; VariablePtr mVariable; - ComponentPtr mComponent; std::vector mEquations; static AnalyserVariablePtr create(); diff --git a/src/annotator.cpp b/src/annotator.cpp index 715997d9af..85d401b09c 100644 --- a/src/annotator.cpp +++ b/src/annotator.cpp @@ -29,7 +29,6 @@ limitations under the License. #include "libcellml/variable.h" #include "anycellmlelement_p.h" -#include "commonutils.h" #include "internaltypes.h" #include "issue_p.h" #include "logger_p.h" diff --git a/src/api/libcellml/analyser.h b/src/api/libcellml/analyser.h index 765c4a9946..eff53741e4 100644 --- a/src/api/libcellml/analyser.h +++ b/src/api/libcellml/analyser.h @@ -59,10 +59,23 @@ class LIBCELLML_EXPORT Analyser: public Logger void analyseModel(const ModelPtr &model); /** + * @brief Add a @ref VariablePtr as an external variable to this @ref Analyser. + * + * Add the given @ref VariablePtr as an external variable to this @ref Analyser, but only if it has not already been + * added. + * + * @param variable The @ref Variable to add as an external variable. + * + * @return @c true if the variable was added, @c false otherwise. + */ + bool addExternalVariable(const VariablePtr &variable); + + /** + * @overload + * * @brief Add an @ref AnalyserExternalVariable to this @ref Analyser. * - * Add the given @ref AnalyserExternalVariable to this @ref Analyser, but only - * if the given @ref AnalyserExternalVariable has not already been added. + * Add the given @ref AnalyserExternalVariable to this @ref Analyser, but only if it has not already been added. * * @param externalVariable The @ref AnalyserExternalVariable to add. * @@ -73,150 +86,107 @@ class LIBCELLML_EXPORT Analyser: public Logger /** * @brief Remove the @ref AnalyserExternalVariable at the given @p index. * - * Remove the @ref AnalyserExternalVariable with the given @p index. The - * @p index must be in the range [0, \#externalVariables). + * Remove the @ref AnalyserExternalVariable with the given @p index. The @p index must be in the range + * [0, \#externalVariables). * * @param index The index of the @ref AnalyserExternalVariable to remove. * - * @return @c true if the @ref AnalyserExternalVariable was removed, @c false - * otherwise. + * @return @c true if the @ref AnalyserExternalVariable was removed, @c false otherwise. */ bool removeExternalVariable(size_t index); /** * @overload * - * @brief Remove the @ref AnalyserExternalVariable with the given - * @p variableName in the @ref Component with the given @p componentName in - * the given @p model. + * @brief Remove the @ref AnalyserExternalVariable for the given @p variable. * - * Remove the @ref AnalyserExternalVariable found that matches the given - * @p variableName in the @ref Component with the given @p componentName in - * the given @p model. + * Remove the @ref AnalyserExternalVariable found that matches the given @p variable. * - * @param model The pointer to the @ref Model which contains the - * @ref AnalyserExternalVariable to remove. - * @param componentName The name of the @ref Component which contains the - * @ref AnalyserExternalVariable to remove. - * @param variableName The name of the @ref AnalyserExternalVariable to - * remove. + * @param variable The @ref Variable for which to remove the @ref AnalyserExternalVariable. * - * @return @c true if the @ref AnalyserExternalVariable was removed, @c false - * otherwise. + * @return @c true if the @ref AnalyserExternalVariable was removed, @c false otherwise. */ - bool removeExternalVariable(const ModelPtr &model, - const std::string &componentName, - const std::string &variableName); + bool removeExternalVariable(const VariablePtr &variable); /** * @overload * - * @brief Remove the @ref AnalyserExternalVariable with the given pointer. + * @brief Remove the @ref AnalyserExternalVariable for the given @p externalVariable. * - * Remove the @ref AnalyserExternalVariable with the pointer - * @p externalVariable. + * Remove the @ref AnalyserExternalVariable for the given @p externalVariable. * - * @param externalVariable The pointer to the @ref AnalyserExternalVariable to remove. + * @param externalVariable The @ref AnalyserExternalVariable to remove. * - * @return @c true if the @ref AnalyserExternalVariable was removed, @c false - * otherwise. + * @return @c true if the @ref AnalyserExternalVariable was removed, @c false otherwise. */ bool removeExternalVariable(const AnalyserExternalVariablePtr &externalVariable); /** - * @brief Remove all @ref AnalyserExternalVariable items from this - * @ref Analyser. + * @brief Remove all the @ref AnalyserExternalVariable items from this @ref Analyser. * - * Clear all @ref AnalyserExternalVariable items that have been added to this - * @ref Analyser. + * Remove all the @ref AnalyserExternalVariable items that were added to this @ref Analyser. */ void removeAllExternalVariables(); /** - * @brief Test to see if the @ref AnalyserExternalVariable with the given - * @p variableName in the @ref Component with the given @p componentName in - * the given @p model is contained within this @ref Analyser. - * - * Test to see if the @ref AnalyserExternalVariable with the the given - * @p variableName in the @ref Component with the given @p componentName in - * the given @p model is contained within this @ref Analyser. Return @c true - * if the @ref AnalyserExternalVariable is in the @ref Analyser and @c false + * @brief Test to see if an @ref AnalyserExternalVariable for the given @p variable is contained within this + * @ref Analyser. + * + * Test to see if an @ref AnalyserExternalVariable for the the given @p variable is contained within this + * @ref Analyser. Return @c true if an @ref AnalyserExternalVariable is in this @ref Analyser and @c false * otherwise. * - * @param model The pointer to the @ref Model which contains the - * @ref AnalyserExternalVariable to test. - * @param componentName The name of the @ref Component which contains the - * @ref AnalyserExternalVariable to test. - * @param variableName The name of the @ref AnalyserExternalVariable to test. + * @param variable The @ref Variable to test. * - * @return @c true if the @ref AnalyserExternalVariable is in this @ref Analyser - * and @c false otherwise. + * @return @c true if an @ref AnalyserExternalVariable is in this @ref Analyser, @c false otherwise. */ - bool containsExternalVariable(const ModelPtr &model, - const std::string &componentName, - const std::string &variableName) const; + bool containsExternalVariable(const VariablePtr &variable) const; /** * @overload * - * @brief Test to see if the @ref AnalyserExternalVariable with the given - * pointer is contained within this @ref Analyser. + * @brief Test to see if an @ref AnalyserExternalVariable for the given @p externalVariable is contained within this + * @ref Analyser. * - * Test to see if the @ref AnalyserExternalVariable with the given pointer is - * contained within this @ref Analyser. Return @c true if the - * @ref AnalyserExternalVariable is in the @ref Analyser and @c false otherwise. + * Test to see if an @ref AnalyserExternalVariable for the given @p externalVariable is contained within this + * @ref Analyser. Return @c true if an @ref AnalyserExternalVariable is in this @ref Analyser, @c false otherwise. * - * @param externalVariable The pointer to the @ref AnalyserExternalVariable to remove. + * @param externalVariable The @ref AnalyserExternalVariable to test. * - * @return @c true if the @ref AnalyserExternalVariable is in this @ref Analyser - * and @c false otherwise. + * @return @c true if an @ref AnalyserExternalVariable is in this @ref Analyser, @c false otherwise. */ bool containsExternalVariable(const AnalyserExternalVariablePtr &externalVariable) const; /** * @brief Get the @ref AnalyserExternalVariable at the given @p index. * - * Return a reference to the @ref AnalyserExternalVariable at the given - * @p index. The @p index must be in the range [0, \#externalVariables). + * Return the @ref AnalyserExternalVariable at the given @p index. The @p index must be in the range + * [0, \#externalVariables). * * @param index The index of the @ref AnalyserExternalVariable to return. * - * @return The @ref AnalyserExternalVariable at the given @p index on success, - * @c nullptr on failure. + * @return The @ref AnalyserExternalVariable at the given @p index on success, @c nullptr on failure. */ AnalyserExternalVariablePtr externalVariable(size_t index) const; /** * @overload * - * @brief Get the @ref AnalyserExternalVariable with the given @p name. + * @brief Get the @ref AnalyserExternalVariable for the given @p variable. * - * Return the @ref AnalyserExternalVariable with the given @p variableName in - * the @ref Component with the given @p componentName in the given @p model. - * If no such @ref AnalyserExternalVariable is contained within the - * @ref Analyser, a @c nullptr is returned. + * Return the @ref AnalyserExternalVariable for the given @p variable. If no such @ref AnalyserExternalVariable is + * contained within this @ref Analyser, a @c nullptr is returned. * - * @param model The pointer to the @ref Model which contains the - * @ref AnalyserExternalVariable to retrieve. - * @param componentName The name of the @ref Component which contains the - * @ref AnalyserExternalVariable to retrieve. - * @param variableName The name of the @ref AnalyserExternalVariable to - * retrieve. + * @param variable The @ref Variable for which to retrieve the @ref AnalyserExternalVariable. * - * @return The @ref AnalyserExternalVariable with the given @p variableName in - * the @ref Component with the given @p componentName in the given @p model on - * success, @c nullptr on failure. + * @return The @ref AnalyserExternalVariable for the given @p variable on success, @c nullptr on failure. */ - AnalyserExternalVariablePtr externalVariable(const ModelPtr &model, - const std::string &componentName, - const std::string &variableName) const; + AnalyserExternalVariablePtr externalVariable(const VariablePtr &variable) const; /** - * @brief Get the number of @ref AnalyserExternalVariable items in this - * @ref Analyser. + * @brief Get the number of @ref AnalyserExternalVariable items in this @ref Analyser. * - * Return the number of @ref AnalyserExternalVariable items the @ref Analyser - * contains. + * Return the number of @ref AnalyserExternalVariable items this @ref Analyser contains. * * @return The number of @ref AnalyserExternalVariable items. */ diff --git a/src/api/libcellml/analyserequation.h b/src/api/libcellml/analyserequation.h index d8a961e6ba..2e5f601b14 100644 --- a/src/api/libcellml/analyserequation.h +++ b/src/api/libcellml/analyserequation.h @@ -166,33 +166,120 @@ class LIBCELLML_EXPORT AnalyserEquation bool isStateRateBased() const; /** - * @brief Get the number of variables computed by this @ref AnalyserEquation. + * @brief Get the number of states computed by this @ref AnalyserEquation. * - * Return the number of variables computed by this @ref AnalyserEquation. + * Return the number of states computed by this @ref AnalyserEquation. * - * @return The number of variables. + * @return The number of states. */ - size_t variableCount() const; + size_t stateCount() const; /** - * @brief Get the variables computed by this @ref AnalyserEquation. + * @brief Get the states computed by this @ref AnalyserEquation. * - * Return the variables computed by this @ref AnalyserEquation. + * Return the states computed by this @ref AnalyserEquation. * - * @return The variables as a @c std::vector. + * @return The states as a @c std::vector. */ - std::vector variables() const; + std::vector states() const; /** - * @brief Get the variable, at @p index, computed by this @ref AnalyserEquation. + * @brief Get the state, at @p index, computed by this @ref AnalyserEquation. * - * Return the variable, at @p index, computed by this @ref AnalyserEquation. + * Return the state, at @p index, computed by this @ref AnalyserEquation. * - * @param index The index of the variable to return. + * @param index The index of the state to return. * - * @return The variable, at @p index, on success, @c nullptr on failure. + * @return The state, at @p index, on success, @c nullptr on failure. */ - AnalyserVariablePtr variable(size_t index) const; + AnalyserVariablePtr state(size_t index) const; + + /** + * @brief Get the number of computed constants computed by this @ref AnalyserEquation. + * + * Return the number of computed constants computed by this @ref AnalyserEquation. + * + * @return The number of computed constants. + */ + size_t computedConstantCount() const; + + /** + * @brief Get the computed constants computed by this @ref AnalyserEquation. + * + * Return the computed constants computed by this @ref AnalyserEquation. + * + * @return The computed constants as a @c std::vector. + */ + std::vector computedConstants() const; + + /** + * @brief Get the computed constant, at @p index, computed by this @ref AnalyserEquation. + * + * Return the computed constant, at @p index, computed by this @ref AnalyserEquation. + * + * @param index The index of the computed constant to return. + * + * @return The computed constant, at @p index, on success, @c nullptr on failure. + */ + AnalyserVariablePtr computedConstant(size_t index) const; + + /** + * @brief Get the number of algebraic variables computed by this @ref AnalyserEquation. + * + * Return the number of algebraic variables computed by this @ref AnalyserEquation. + * + * @return The number of algebraic variables. + */ + size_t algebraicCount() const; + + /** + * @brief Get the algebraic variables computed by this @ref AnalyserEquation. + * + * Return the algebraic variables computed by this @ref AnalyserEquation. + * + * @return The algebraic variables as a @c std::vector. + */ + std::vector algebraic() const; + + /** + * @brief Get the algebraic variable, at @p index, computed by this @ref AnalyserEquation. + * + * Return the algebraic variable, at @p index, computed by this @ref AnalyserEquation. + * + * @param index The index of the algebraic variable to return. + * + * @return The algebraic variable, at @p index, on success, @c nullptr on failure. + */ + AnalyserVariablePtr algebraic(size_t index) const; + + /** + * @brief Get the number of external variables computed by this @ref AnalyserEquation. + * + * Return the number of external variables computed by this @ref AnalyserEquation. + * + * @return The number of external variables. + */ + size_t externalCount() const; + + /** + * @brief Get the external variables computed by this @ref AnalyserEquation. + * + * Return the external variables computed by this @ref AnalyserEquation. + * + * @return The external variables as a @c std::vector. + */ + std::vector externals() const; + + /** + * @brief Get the external variable, at @p index, computed by this @ref AnalyserEquation. + * + * Return the external variable, at @p index, computed by this @ref AnalyserEquation. + * + * @param index The index of the external variable to return. + * + * @return The external variable, at @p index, on success, @c nullptr on failure. + */ + AnalyserVariablePtr external(size_t index) const; private: AnalyserEquation(); /**< Constructor, @private. */ diff --git a/src/api/libcellml/analysermodel.h b/src/api/libcellml/analysermodel.h index e6358dcb7e..f5d745d150 100644 --- a/src/api/libcellml/analysermodel.h +++ b/src/api/libcellml/analysermodel.h @@ -142,34 +142,124 @@ class LIBCELLML_EXPORT AnalyserModel AnalyserVariablePtr state(size_t index) const; /** - * @brief Get the number of variables. + * @brief Get the number of constants. * - * Return the number of variables in the @ref AnalyserModel. + * Return the number of constants in the @ref AnalyserModel. * - * @return The number of variables. + * @return The number of constants. */ - size_t variableCount() const; + size_t constantCount() const; /** - * @brief Get the variables. + * @brief Get the constants. * - * Return the variables in the @ref AnalyserModel. + * Return the constants in the @ref AnalyserModel. * - * @return The variables as a @c std::vector. + * @return The constants as a @c std::vector. */ - std::vector variables() const; + std::vector constants() const; /** - * @brief Get the variable at @p index. + * @brief Get the constant at @p index. * - * Return the variable at the index @p index for the @ref AnalyserModel. + * Return the constant at the index @p index for the @ref AnalyserModel. * - * @param index The index of the variable to return. + * @param index The index of the constant to return. * - * @return The variable at the given @p index on success, @c nullptr on + * @return The constant at the given @p index on success, @c nullptr on * failure. */ - AnalyserVariablePtr variable(size_t index) const; + AnalyserVariablePtr constant(size_t index) const; + + /** + * @brief Get the number of computed constants. + * + * Return the number of computed constants in the @ref AnalyserModel. + * + * @return The number of computed constants. + */ + size_t computedConstantCount() const; + + /** + * @brief Get the computed constants. + * + * Return the computed constants in the @ref AnalyserModel. + * + * @return The computed constants as a @c std::vector. + */ + std::vector computedConstants() const; + + /** + * @brief Get the computed constant at @p index. + * + * Return the computed constant at the index @p index for the @ref AnalyserModel. + * + * @param index The index of the computed constant to return. + * + * @return The computed constant at the given @p index on success, @c nullptr on + * failure. + */ + AnalyserVariablePtr computedConstant(size_t index) const; + + /** + * @brief Get the number of algebraic variables. + * + * Return the number of algebraic variables in the @ref AnalyserModel. + * + * @return The number of algebraic variables. + */ + size_t algebraicCount() const; + + /** + * @brief Get the algebraic variables. + * + * Return the algebraic variables in the @ref AnalyserModel. + * + * @return The algebraic variables as a @c std::vector. + */ + std::vector algebraic() const; + + /** + * @brief Get the algebraic variable at @p index. + * + * Return the algebraic variable at the index @p index for the @ref AnalyserModel. + * + * @param index The index of the algebraic variable to return. + * + * @return The algebraic variable at the given @p index on success, @c nullptr on + * failure. + */ + AnalyserVariablePtr algebraic(size_t index) const; + + /** + * @brief Get the number of external variables. + * + * Return the number of external variables in the @ref AnalyserModel. + * + * @return The number of external variables. + */ + size_t externalCount() const; + + /** + * @brief Get the external variables. + * + * Return the external variables in the @ref AnalyserModel. + * + * @return The external variables as a @c std::vector. + */ + std::vector externals() const; + + /** + * @brief Get the external variable at @p index. + * + * Return the external variable at the index @p index for the @ref AnalyserModel. + * + * @param index The index of the external variable to return. + * + * @return The external variable at the given @p index on success, @c nullptr on + * failure. + */ + AnalyserVariablePtr external(size_t index) const; /** * @brief Get the number of equations. diff --git a/src/api/libcellml/generator.h b/src/api/libcellml/generator.h index 85d5b71eb1..4bebebfd6d 100644 --- a/src/api/libcellml/generator.h +++ b/src/api/libcellml/generator.h @@ -111,13 +111,12 @@ class LIBCELLML_EXPORT Generator * Return the equation code for the given @ref AnalyserEquationAst using @ref GeneratorProfile. * * @param ast The @ref AnalyserEquationAst for which we want to generate some code. - * @param generatorProfile The @ref GeneratorProfile, if any, to use to generate the equation code. If no + * @param profile The @ref GeneratorProfile, if any, to use to generate the equation code. If no * @ref GeneratorProfile is provided then the default @ref GeneratorProfile is used. * * @return The equation code as a @c std::string. */ - static std::string equationCode(const AnalyserEquationAstPtr &ast, - const GeneratorProfilePtr &generatorProfile); + static std::string equationCode(const AnalyserEquationAstPtr &ast, const GeneratorProfilePtr &profile); /** * @brief Get the equation code for the given @ref AnalyserEquationAst using a default @ref GeneratorProfile. diff --git a/src/api/libcellml/generatorprofile.h b/src/api/libcellml/generatorprofile.h index 10335d24d8..8608cc8d8c 100644 --- a/src/api/libcellml/generatorprofile.h +++ b/src/api/libcellml/generatorprofile.h @@ -2462,218 +2462,196 @@ class LIBCELLML_EXPORT GeneratorProfile void setImplementationStateCountString(const std::string &implementationStateCountString); /** - * @brief Get the @c std::string for the interface of the variable count + * @brief Get the @c std::string for the interface of the constant count * constant. * - * Return the @c std::string for the interface of the variable count + * Return the @c std::string for the interface of the constant count * constant. * - * @return The @c std::string for the interface of the variable count + * @return The @c std::string for the interface of the constant count * constant. */ - std::string interfaceVariableCountString() const; + std::string interfaceConstantCountString() const; /** - * @brief Set the @c std::string for the interface of the variable count + * @brief Set the @c std::string for the interface of the constant count * constant. * - * Set the @c std::string for the interface of the variable count constant. + * Set the @c std::string for the interface of the constant count constant. * - * @param interfaceVariableCountString The @c std::string to use for the - * interface of the variable count constant. + * @param interfaceConstantCountString The @c std::string to use for the + * interface of the constant count constant. */ - void setInterfaceVariableCountString(const std::string &interfaceVariableCountString); + void setInterfaceConstantCountString(const std::string &interfaceConstantCountString); /** - * @brief Get the @c std::string for the implementation of the variable + * @brief Get the @c std::string for the implementation of the constant * count constant. * - * Return the @c std::string for the implementation of the variable count + * Return the @c std::string for the implementation of the constant count * constant. * - * @return The @c std::string for the implementation of the variable count + * @return The @c std::string for the implementation of the constant count * constant. */ - std::string implementationVariableCountString() const; + std::string implementationConstantCountString() const; /** - * @brief Set the @c std::string for the implementation of the variable + * @brief Set the @c std::string for the implementation of the constant * count constant. * - * Set the @c std::string for the implementation of the variable count - * constant. To be useful, the string should contain the [VARIABLE_COUNT] + * Set the @c std::string for the implementation of the constant count + * constant. To be useful, the string should contain the [CONSTANT_COUNT] * tag, which will be replaced with the number of states in the model. * - * @param implementationVariableCountString The @c std::string to use for - * the implementation of the variable count constant. + * @param implementationConstantCountString The @c std::string to use for + * the implementation of the constant count constant. */ - void setImplementationVariableCountString(const std::string &implementationVariableCountString); + void setImplementationConstantCountString(const std::string &implementationConstantCountString); /** - * @brief Get the @c std::string for the data structure for the variable - * type object. - * - * Return the @c std::string for the data structure for the variable type - * object. - * - * @param forDifferentialModel Whether the data structure is for a - * differential model, as opposed to an algebraic model. - * @param withExternalVariables Whether the data structure is for a model - * with external variables. - * - * @return The @c std::string for the data structure for the variable type - * object. - */ - std::string variableTypeObjectString(bool forDifferentialModel, - bool withExternalVariables) const; - - /** - * @brief Set the @c std::string for the data structure for the variable - * type object. - * - * Set the @c std::string for the data structure for the variable type - * object. - * - * @sa variableTypeObjectString - * - * @param forDifferentialModel Whether the data structure is for a - * differential model, as opposed to an algebraic model. - * @param withExternalVariables Whether the data structure is for a model - * with external variables. - * @param variableTypeObjectString The @c std::string to use for the data - * structure for the variable type object. - */ - void setVariableTypeObjectString(bool forDifferentialModel, - bool withExternalVariables, - const std::string &variableTypeObjectString); - - /** - * @brief Get the @c std::string for the name of the variable of integration - * variable type. + * @brief Get the @c std::string for the interface of the computed constant count + * constant. * - * Return the @c std::string for the name of the variable of integration - * variable type that is used in a differential model. + * Return the @c std::string for the interface of the computed constant count + * constant. * - * @return The @c std::string for the name of the variable of integration - * variable type. + * @return The @c std::string for the interface of the computed constant count + * constant. */ - std::string variableOfIntegrationVariableTypeString() const; + std::string interfaceComputedConstantCountString() const; /** - * @brief Set the @c std::string for the name of the variable of integration - * variable type. + * @brief Set the @c std::string for the interface of the computed constant count + * constant. * - * Set the @c std::string for the name of the variable of integration - * variable type that is used in a differential model. + * Set the @c std::string for the interface of the computed constant count constant. * - * @param variableOfIntegrationVariableTypeString The @c std::string to use - * for the name of the variable of integration variable type. + * @param interfaceComputedConstantCountString The @c std::string to use for the + * interface of the computed constant count constant. */ - void setVariableOfIntegrationVariableTypeString(const std::string &variableOfIntegrationVariableTypeString); + void setInterfaceComputedConstantCountString(const std::string &interfaceComputedConstantCountString); /** - * @brief Get the @c std::string for the name of the state variable type. + * @brief Get the @c std::string for the implementation of the computed constant + * count constant. * - * Return the @c std::string for the name of the state variable type that is - * used in a differential model. + * Return the @c std::string for the implementation of the computed constant count + * constant. * - * @return The @c std::string for the name of the state variable type. + * @return The @c std::string for the implementation of the computed constant count + * constant. */ - std::string stateVariableTypeString() const; + std::string implementationComputedConstantCountString() const; /** - * @brief Set the @c std::string for the name of the state variable type. + * @brief Set the @c std::string for the implementation of the computed constant + * count constant. * - * Set the @c std::string for the name of the state variable type that is - * used in a differential model. + * Set the @c std::string for the implementation of the computed constant count + * constant. To be useful, the string should contain the [COMPUTED_CONSTANT_COUNT] + * tag, which will be replaced with the number of states in the model. * - * @param stateTypeString The @c std::string to use for the name of the - * state variable type. + * @param implementationComputedConstantCountString The @c std::string to use for + * the implementation of the computed constant count constant. */ - void setStateVariableTypeString(const std::string &stateVariableTypeString); + void setImplementationComputedConstantCountString(const std::string &implementationComputedConstantCountString); /** - * @brief Get the @c std::string for the name of the constant variable type. + * @brief Get the @c std::string for the interface of the algebraic count + * constant. * - * Return the @c std::string for the name of the constant variable type. + * Return the @c std::string for the interface of the algebraic count + * constant. * - * @return The @c std::string for the name of the constant variable type. + * @return The @c std::string for the interface of the algebraic count + * constant. */ - std::string constantVariableTypeString() const; + std::string interfaceAlgebraicCountString() const; /** - * @brief Set the @c std::string for the name of the constant variable type. + * @brief Set the @c std::string for the interface of the algebraic count + * constant. * - * Set the @c std::string for the name of the constant variable type. + * Set the @c std::string for the interface of the algebraic count constant. * - * @param constantVariableTypeString The @c std::string to use for the name of the - * constant variable type. + * @param interfaceAlgebraicCountString The @c std::string to use for the + * interface of the algebraic count constant. */ - void setConstantVariableTypeString(const std::string &constantVariableTypeString); + void setInterfaceAlgebraicCountString(const std::string &interfaceAlgebraicCountString); /** - * @brief Get the @c std::string for the name of the computed constant - * variable type. + * @brief Get the @c std::string for the implementation of the algebraic + * count constant. * - * Return the @c std::string for the name of the computed constant variable - * type. + * Return the @c std::string for the implementation of the algebraic count + * constant. * - * @return The @c std::string for the name of the computed constant variable - * type. + * @return The @c std::string for the implementation of the algebraic count + * constant. */ - std::string computedConstantVariableTypeString() const; + std::string implementationAlgebraicCountString() const; /** - * @brief Set the @c std::string for the name of the computed constant - * variable type. + * @brief Set the @c std::string for the implementation of the algebraic + * count constant. * - * Set the @c std::string for the name of the computed constant variable - * type. + * Set the @c std::string for the implementation of the algebraic count + * constant. To be useful, the string should contain the [ALGEBRAIC_COUNT] + * tag, which will be replaced with the number of states in the model. * - * @param computedConstantVariableTypeString The @c std::string to use for the name of the - * computed constant variable type. + * @param implementationAlgebraicCountString The @c std::string to use for + * the implementation of the algebraic count constant. */ - void setComputedConstantVariableTypeString(const std::string &computedConstantVariableTypeString); + void setImplementationAlgebraicCountString(const std::string &implementationAlgebraicCountString); /** - * @brief Get the @c std::string for the name of the algebraic variable - * type. + * @brief Get the @c std::string for the interface of the external count + * constant. * - * Return the @c std::string for the name of the algebraic variable type. + * Return the @c std::string for the interface of the external count + * constant. * - * @return The @c std::string for the name of the algebraic variable type. + * @return The @c std::string for the interface of the external count + * constant. */ - std::string algebraicVariableTypeString() const; + std::string interfaceExternalCountString() const; /** - * @brief Set the @c std::string for the name of the algebraic variable - * type. + * @brief Set the @c std::string for the interface of the external count + * constant. * - * Set the @c std::string for the name of the algebraic variable type. + * Set the @c std::string for the interface of the external count constant. * - * @param algebraicVariableTypeString The @c std::string to use for the name of the - * algebraic variable type. + * @param interfaceExternalCountString The @c std::string to use for the + * interface of the external count constant. */ - void setAlgebraicVariableTypeString(const std::string &algebraicVariableTypeString); + void setInterfaceExternalCountString(const std::string &interfaceExternalCountString); /** - * @brief Get the @c std::string for the name of the external variable type. + * @brief Get the @c std::string for the implementation of the external + * count constant. * - * Return the @c std::string for the name of the external variable type. + * Return the @c std::string for the implementation of the external count + * constant. * - * @return The @c std::string for the name of the external variable type. + * @return The @c std::string for the implementation of the external count + * constant. */ - std::string externalVariableTypeString() const; + std::string implementationExternalCountString() const; /** - * @brief Set the @c std::string for the name of the external variable type. + * @brief Set the @c std::string for the implementation of the external + * count constant. * - * Set this @c std::string for the name of the external variable type. + * Set the @c std::string for the implementation of the external count + * constant. To be useful, the string should contain the [EXTERNAL_COUNT] + * tag, which will be replaced with the number of states in the model. * - * @param externalVariableTypeString The @c std::string to use for the name of the - * external variable type. + * @param implementationExternalCountString The @c std::string to use for + * the implementation of the external count constant. */ - void setExternalVariableTypeString(const std::string &externalVariableTypeString); + void setImplementationExternalCountString(const std::string &implementationExternalCountString); /** * @brief Get the @c std::string for the data structure for the variable @@ -2804,53 +2782,203 @@ class LIBCELLML_EXPORT GeneratorProfile /** * @brief Get the @c std::string for the interface of some information about - * the different variables. + * the different constants. * * Return the @c std::string for the interface of some information about the - * different variables. + * different constants. * * @return The @c std::string for the interface of some information about - * the different variables. + * the different constants. */ - std::string interfaceVariableInfoString() const; + std::string interfaceConstantInfoString() const; /** * @brief Set the @c std::string for the interface of some information about - * the different variables. + * the different constants. * * Set the @c std::string for the interface of some information about the - * different variables. + * different constants. * - * @param interfaceVariableInfoString The @c std::string to use for the - * interface of some information about the different variables. + * @param interfaceConstantInfoString The @c std::string to use for the + * interface of some information about the different constants. */ - void setInterfaceVariableInfoString(const std::string &interfaceVariableInfoString); + void setInterfaceConstantInfoString(const std::string &interfaceConstantInfoString); /** * @brief Get the @c std::string for the implementation of some information - * about the different variables. + * about the different constants. * * Return the @c std::string for the implementation of some information - * about the different variables. + * about the different constants. * * @return The @c std::string for the implementation of some information - * about the different variables. + * about the different constants. */ - std::string implementationVariableInfoString() const; + std::string implementationConstantInfoString() const; /** * @brief Set the @c std::string for the implementation of some information - * about the different variables. + * about the different constants. * * Set the @c std::string for the implementation of some information about - * the different variables. To be useful, the string should contain the - * [CODE] tag, which will be replaced with some information about the - * different variables. + * the different constants. To be useful, the string should contain the [CODE] + * tag, which will be replaced with some information about the different + * constants. + * + * @param implementationConstantInfoString The @c std::string to use for the + * implementation of some information about the different constants. + */ + void setImplementationConstantInfoString(const std::string &implementationConstantInfoString); + + /** + * @brief Get the @c std::string for the interface of some information about + * the different computed constants. + * + * Return the @c std::string for the interface of some information about the + * different computed constants. + * + * @return The @c std::string for the interface of some information about + * the different computed constants. + */ + std::string interfaceComputedConstantInfoString() const; + + /** + * @brief Set the @c std::string for the interface of some information about + * the different computed constants. + * + * Set the @c std::string for the interface of some information about the + * different computed constants. + * + * @param interfaceComputedConstantInfoString The @c std::string to use for the + * interface of some information about the different computed constants. + */ + void setInterfaceComputedConstantInfoString(const std::string &interfaceComputedConstantInfoString); + + /** + * @brief Get the @c std::string for the implementation of some information + * about the different computed constants. + * + * Return the @c std::string for the implementation of some information + * about the different computed constants. + * + * @return The @c std::string for the implementation of some information + * about the different computed constants. + */ + std::string implementationComputedConstantInfoString() const; + + /** + * @brief Set the @c std::string for the implementation of some information + * about the different computed constants. + * + * Set the @c std::string for the implementation of some information about + * the different computed constants. To be useful, the string should contain the [CODE] + * tag, which will be replaced with some information about the different + * computed constants. + * + * @param implementationComputedConstantInfoString The @c std::string to use for the + * implementation of some information about the different computed constants. + */ + void setImplementationComputedConstantInfoString(const std::string &implementationComputedConstantInfoString); + + /** + * @brief Get the @c std::string for the interface of some information about + * the different algebraic variables. + * + * Return the @c std::string for the interface of some information about the + * different algebraic variables. + * + * @return The @c std::string for the interface of some information about + * the different algebraic variables. + */ + std::string interfaceAlgebraicInfoString() const; + + /** + * @brief Set the @c std::string for the interface of some information about + * the different algebraic variables. + * + * Set the @c std::string for the interface of some information about the + * different algebraic variables. + * + * @param interfaceAlgebraicInfoString The @c std::string to use for the + * interface of some information about the different algebraic variables. + */ + void setInterfaceAlgebraicInfoString(const std::string &interfaceAlgebraicInfoString); + + /** + * @brief Get the @c std::string for the implementation of some information + * about the different algebraic variables. + * + * Return the @c std::string for the implementation of some information + * about the different algebraic variables. + * + * @return The @c std::string for the implementation of some information + * about the different algebraic variables. + */ + std::string implementationAlgebraicInfoString() const; + + /** + * @brief Set the @c std::string for the implementation of some information + * about the different algebraic variables. + * + * Set the @c std::string for the implementation of some information about + * the different algebraic variables. To be useful, the string should contain the [CODE] + * tag, which will be replaced with some information about the different + * algebraic variables. + * + * @param implementationAlgebraicInfoString The @c std::string to use for the + * implementation of some information about the different algebraic variables. + */ + void setImplementationAlgebraicInfoString(const std::string &implementationAlgebraicInfoString); + + /** + * @brief Get the @c std::string for the interface of some information about + * the different external variables. + * + * Return the @c std::string for the interface of some information about the + * different external variables. + * + * @return The @c std::string for the interface of some information about + * the different external variables. + */ + std::string interfaceExternalInfoString() const; + + /** + * @brief Set the @c std::string for the interface of some information about + * the different external variables. + * + * Set the @c std::string for the interface of some information about the + * different external variables. + * + * @param interfaceExternalInfoString The @c std::string to use for the + * interface of some information about the different external variables. + */ + void setInterfaceExternalInfoString(const std::string &interfaceExternalInfoString); + + /** + * @brief Get the @c std::string for the implementation of some information + * about the different external variables. + * + * Return the @c std::string for the implementation of some information + * about the different external variables. * - * @param implementationVariableInfoString The @c std::string to use for the - * implementation of some information about the different variables. + * @return The @c std::string for the implementation of some information + * about the different external variables. + */ + std::string implementationExternalInfoString() const; + + /** + * @brief Set the @c std::string for the implementation of some information + * about the different external variables. + * + * Set the @c std::string for the implementation of some information about + * the different external variables. To be useful, the string should contain the [CODE] + * tag, which will be replaced with some information about the different + * external variables. + * + * @param implementationExternalInfoString The @c std::string to use for the + * implementation of some information about the different external variables. */ - void setImplementationVariableInfoString(const std::string &implementationVariableInfoString); + void setImplementationExternalInfoString(const std::string &implementationExternalInfoString); /** * @brief Get the @c std::string for an entry in an array for some @@ -2938,23 +3066,80 @@ class LIBCELLML_EXPORT GeneratorProfile void setRatesArrayString(const std::string &ratesArrayString); /** - * @brief Get the @c std::string for the name of the variables array. + * @brief Get the @c std::string for the name of the constants array. + * + * Return the @c std::string for the name of the constants array. + * + * @return The @c std::string for the name of the constants array. + */ + std::string constantsArrayString() const; + + /** + * @brief Set the @c std::string for the name of the constants array. + * + * Set the @c std::string for the name of the constants array. + * + * @param constantsArrayString The @c std::string to use for the name of the + * constants array. + */ + void setConstantsArrayString(const std::string &constantsArrayString); + + /** + * @brief Get the @c std::string for the name of the computed constants array. + * + * Return the @c std::string for the name of the computed constants array. + * + * @return The @c std::string for the name of the computed constants array. + */ + std::string computedConstantsArrayString() const; + + /** + * @brief Set the @c std::string for the name of the computed constants array. + * + * Set the @c std::string for the name of the computed constants array. + * + * @param computedConstantsArrayString The @c std::string to use for the name of the + * computed constants array. + */ + void setComputedConstantsArrayString(const std::string &computedConstantsArrayString); + + /** + * @brief Get the @c std::string for the name of the algebraic array. + * + * Return the @c std::string for the name of the algebraic array. + * + * @return The @c std::string for the name of the algebraic array. + */ + std::string algebraicArrayString() const; + + /** + * @brief Set the @c std::string for the name of the algebraic array. + * + * Set the @c std::string for the name of the algebraic array. + * + * @param algebraicArrayString The @c std::string to use for the name of the + * algebraic array. + */ + void setAlgebraicArrayString(const std::string &algebraicArrayString); + + /** + * @brief Get the @c std::string for the name of the external array. * - * Return the @c std::string for the name of the variables array. + * Return the @c std::string for the name of the external array. * - * @return The @c std::string for the name of the variables array. + * @return The @c std::string for the name of the external array. */ - std::string variablesArrayString() const; + std::string externalArrayString() const; /** - * @brief Set the @c std::string for the name of the variables array. + * @brief Set the @c std::string for the name of the external array. * - * Set the @c std::string for the name of the variables array. + * Set the @c std::string for the name of the external array. * - * @param variablesArrayString The @c std::string to use for the name of the - * variables array. + * @param externalArrayString The @c std::string to use for the name of the + * external array. */ - void setVariablesArrayString(const std::string &variablesArrayString); + void setExternalArrayString(const std::string &externalArrayString); /** * @brief Get the @c std::string for the type definition of an external @@ -3027,11 +3212,14 @@ class LIBCELLML_EXPORT GeneratorProfile * @param forDifferentialModel Whether the call to the root finding * information object is for a differential model, as opposed to an * algebraic model. + * @param withExternalVariables Whether the call to the root finding + * information object is for a model with external variables. * * @return The @c std::string for the data structure for the root finding * information object. */ - std::string rootFindingInfoObjectString(bool forDifferentialModel) const; + std::string rootFindingInfoObjectString(bool forDifferentialModel, + bool withExternalVariables) const; /** * @brief Set the @c std::string for the data structure for the root finding @@ -3043,10 +3231,13 @@ class LIBCELLML_EXPORT GeneratorProfile * @param forDifferentialModel Whether the call to the root finding * information object is for a differential model, as opposed to an * algebraic model. + * @param withExternalVariables Whether the call to the root finding + * information object is for a model with external variables. * @param rootFindingInfoObjectString The @c std::string to use for the data * structure for the root finding information object. */ void setRootFindingInfoObjectString(bool forDifferentialModel, + bool withExternalVariables, const std::string &rootFindingInfoObjectString); /** @@ -3075,10 +3266,13 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the call to the find root method is * for a differential model, as opposed to an algebraic model. + * @param withExternalVariables Whether the call to the find root method is + * for a model with external variables. * * @return The @c std::string for the call to the find root method. */ - std::string findRootCallString(bool forDifferentialModel) const; + std::string findRootCallString(bool forDifferentialModel, + bool withExternalVariables) const; /** * @brief Set the @c std::string for the call to the find root method. @@ -3089,10 +3283,13 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the call to the find root method is * for a differential model, as opposed to an algebraic model. + * @param withExternalVariables Whether the call to the find root method is + * for a model with external variables. * @param findRootCallString The @c std::string to use for the call to the * find root method. */ void setFindRootCallString(bool forDifferentialModel, + bool withExternalVariables, const std::string &findRootCallString); /** @@ -3102,10 +3299,13 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the call to the find root method is * for a differential model, as opposed to an algebraic model. + * @param withExternalVariables Whether the call to the find root method is + * for a model with external variables. * * @return The @c std::string for the find root method. */ - std::string findRootMethodString(bool forDifferentialModel) const; + std::string findRootMethodString(bool forDifferentialModel, + bool withExternalVariables) const; /** * @brief Set the @c std::string for the find root method. @@ -3120,10 +3320,13 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the call to the find root method is * for a differential model, as opposed to an algebraic model. + * @param withExternalVariables Whether the call to the find root method is + * for a model with external variables. * @param findRootMethodString The @c std::string to use for the find root * method. */ void setFindRootMethodString(bool forDifferentialModel, + bool withExternalVariables, const std::string &findRootMethodString); /** @@ -3133,10 +3336,13 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the call to the NLA solve method is * for a differential model, as opposed to an algebraic model. + * @param withExternalVariables Whether the call to the NLA solve method is + * for a model with external variables. * * @return The @c std::string for the call to the NLA solve method. */ - std::string nlaSolveCallString(bool forDifferentialModel) const; + std::string nlaSolveCallString(bool forDifferentialModel, + bool withExternalVariables) const; /** * @brief Set the @c std::string for the call to the NLA solve method. @@ -3150,10 +3356,13 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the call to the NLA solve method is * for a differential model, as opposed to an algebraic model. + * @param withExternalVariables Whether the call to the NLA solve method is + * for a model with external variables. * @param nlaSolveCallString The @c std::string to use for the call to the * NLA solve method. */ void setNlaSolveCallString(bool forDifferentialModel, + bool withExternalVariables, const std::string &nlaSolveCallString); /** @@ -3163,10 +3372,13 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the call to the objective function * method is for a differential model, as opposed to an algebraic model. + * @param withExternalVariables Whether the call to the objective function + * method is for a model with external variables. * * @return The @c std::string for the objective function method. */ - std::string objectiveFunctionMethodString(bool forDifferentialModel) const; + std::string objectiveFunctionMethodString(bool forDifferentialModel, + bool withExternalVariables) const; /** * @brief Set the @c std::string for the objective function method. @@ -3178,10 +3390,13 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the call to the objective function * method is for a differential model, as opposed to an algebraic model. + * @param withExternalVariables Whether the call to the objective function + * method is for a model with external variables. * @param objectiveFunctionMethodString The @c std::string to use for the * objective function method. */ void setObjectiveFunctionMethodString(bool forDifferentialModel, + bool withExternalVariables, const std::string &objectiveFunctionMethodString); /** @@ -3281,49 +3496,180 @@ class LIBCELLML_EXPORT GeneratorProfile void setImplementationCreateStatesArrayMethodString(const std::string &implementationCreateStatesArrayMethodString); /** - * @brief Get the @c std::string for the interface to create variables + * @brief Get the @c std::string for the interface to create the constants + * array. + * + * Return the @c std::string for the interface to create the constants array. + * + * @return The @c std::string for the interface to create the constants array. + */ + std::string interfaceCreateConstantsArrayMethodString() const; + + /** + * @brief Set the @c std::string for the interface to create the constants + * array. + * + * Set the @c std::string for the interface to create the constants array. + * + * @param interfaceCreateConstantsArrayMethodString The @c std::string to use + * for the interface to create the constants array. + */ + void setInterfaceCreateConstantsArrayMethodString(const std::string &interfaceCreateConstantsArrayMethodString); + + /** + * @brief Get the @c std::string for the implementation to create the constants + * array. + * + * Return the @c std::string for the implementation to create the constants + * array. + * + * @return The @c std::string for the implementation to create the constants + * array. + */ + std::string implementationCreateConstantsArrayMethodString() const; + + /** + * @brief Set the @c std::string for the implementation to create the constants + * array. + * + * Set the @c std::string for the implementation to create the constants array. + * + * @param implementationCreateConstantsArrayMethodString The @c std::string to + * use for the implementation to create the constants array. + */ + void setImplementationCreateConstantsArrayMethodString(const std::string &implementationCreateConstantsArrayMethodString); + + /** + * @brief Get the @c std::string for the interface to create the computed constants + * array. + * + * Return the @c std::string for the interface to create the computed constants array. + * + * @return The @c std::string for the interface to create the computed constants array. + */ + std::string interfaceCreateComputedConstantsArrayMethodString() const; + + /** + * @brief Set the @c std::string for the interface to create the computed constants + * array. + * + * Set the @c std::string for the interface to create the computed constants array. + * + * @param interfaceCreateComputedConstantsArrayMethodString The @c std::string to use + * for the interface to create the computed constants array. + */ + void setInterfaceCreateComputedConstantsArrayMethodString(const std::string &interfaceCreateComputedConstantsArrayMethodString); + + /** + * @brief Get the @c std::string for the implementation to create the computed constants + * array. + * + * Return the @c std::string for the implementation to create the computed constants + * array. + * + * @return The @c std::string for the implementation to create the computed constants + * array. + */ + std::string implementationCreateComputedConstantsArrayMethodString() const; + + /** + * @brief Set the @c std::string for the implementation to create the computed constants + * array. + * + * Set the @c std::string for the implementation to create the computed constants array. + * + * @param implementationCreateComputedConstantsArrayMethodString The @c std::string to + * use for the implementation to create the computed constants array. + */ + void setImplementationCreateComputedConstantsArrayMethodString(const std::string &implementationCreateComputedConstantsArrayMethodString); + + /** + * @brief Get the @c std::string for the interface to create the algebraic variables + * array. + * + * Return the @c std::string for the interface to create the algebraic variables array. + * + * @return The @c std::string for the interface to create the algebraic variables array. + */ + std::string interfaceCreateAlgebraicArrayMethodString() const; + + /** + * @brief Set the @c std::string for the interface to create the algebraic variables * array. * - * Return the @c std::string for the interface to create variables array. + * Set the @c std::string for the interface to create the algebraic variables array. * - * @return The @c std::string for the interface to create variables array. + * @param interfaceCreateAlgebraicArrayMethodString The @c std::string to use + * for the interface to create the algebraic variables array. */ - std::string interfaceCreateVariablesArrayMethodString() const; + void setInterfaceCreateAlgebraicArrayMethodString(const std::string &interfaceCreateAlgebraicArrayMethodString); /** - * @brief Set the @c std::string for the interface to create variables + * @brief Get the @c std::string for the implementation to create the algebraic variables * array. * - * Set the @c std::string for the interface to create variables array. + * Return the @c std::string for the implementation to create the algebraic variables + * array. * - * @param interfaceCreateVariablesArrayMethodString The @c std::string to - * use for the interface to create variables array. + * @return The @c std::string for the implementation to create the algebraic variables + * array. */ - void setInterfaceCreateVariablesArrayMethodString(const std::string &interfaceCreateVariablesArrayMethodString); + std::string implementationCreateAlgebraicArrayMethodString() const; /** - * @brief Get the @c std::string for the implementation to create the - * variables array. + * @brief Set the @c std::string for the implementation to create the algebraic variables + * array. * - * Return the @c std::string for the implementation to create the variables + * Set the @c std::string for the implementation to create the algebraic variables array. + * + * @param implementationCreateAlgebraicArrayMethodString The @c std::string to + * use for the implementation to create the algebraic variables array. + */ + void setImplementationCreateAlgebraicArrayMethodString(const std::string &implementationCreateAlgebraicArrayMethodString); + + /** + * @brief Get the @c std::string for the interface to create the external variables * array. * - * @return The @c std::string for the implementation to create the variables + * Return the @c std::string for the interface to create the external variables array. + * + * @return The @c std::string for the interface to create the external variables array. + */ + std::string interfaceCreateExternalsArrayMethodString() const; + + /** + * @brief Set the @c std::string for the interface to create the external variables * array. + * + * Set the @c std::string for the interface to create the external variables array. + * + * @param interfaceCreateExternalsArrayMethodString The @c std::string to use + * for the interface to create the external variables array. */ - std::string implementationCreateVariablesArrayMethodString() const; + void setInterfaceCreateExternalsArrayMethodString(const std::string &interfaceCreateExternalsArrayMethodString); /** - * @brief Set the @c std::string for the implementation to create the - * variables array. + * @brief Get the @c std::string for the implementation to create the external variables + * array. + * + * Return the @c std::string for the implementation to create the external variables + * array. * - * Set the @c std::string for the implementation to create the variables + * @return The @c std::string for the implementation to create the external variables + * array. + */ + std::string implementationCreateExternalsArrayMethodString() const; + + /** + * @brief Set the @c std::string for the implementation to create the external variables * array. * - * @param implementationCreateVariablesArrayMethodString The @c std::string - * to use for the implementation to create the variables array. + * Set the @c std::string for the implementation to create the external variables array. + * + * @param implementationCreateExternalsArrayMethodString The @c std::string to + * use for the implementation to create the external variables array. */ - void setImplementationCreateVariablesArrayMethodString(const std::string &implementationCreateVariablesArrayMethodString); + void setImplementationCreateExternalsArrayMethodString(const std::string &implementationCreateExternalsArrayMethodString); /** * @brief Get the @c std::string for the interface to delete an array. @@ -3370,13 +3716,10 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the interface to initialise variables * is for a differential model, as opposed to an algebraic model. - * @param withExternalVariables Whether the interface to initialise - * variables is for a model with external variables. * * @return The @c std::string for the interface to initialise variables. */ - std::string interfaceInitialiseVariablesMethodString(bool forDifferentialModel, - bool withExternalVariables) const; + std::string interfaceInitialiseVariablesMethodString(bool forDifferentialModel) const; /** * @brief Set the @c std::string for the interface to initialise variables. @@ -3385,13 +3728,10 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the interface to initialise variables * is for a differential model, as opposed to an algebraic model. - * @param withExternalVariables Whether the interface to initialise - * variables is for a model with external variables. * @param interfaceInitialiseVariablesMethodString The @c std::string to use * for the interface to initialise variables. */ void setInterfaceInitialiseVariablesMethodString(bool forDifferentialModel, - bool withExternalVariables, const std::string &interfaceInitialiseVariablesMethodString); /** @@ -3402,14 +3742,11 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the implementation to initialise * variables is for a differential model, as opposed to an algebraic model. - * @param withExternalVariables Whether the implementation to initialise - * variables is for a model with external variables. * * @return The @c std::string for the implementation to initialise * variables. */ - std::string implementationInitialiseVariablesMethodString(bool forDifferentialModel, - bool withExternalVariables) const; + std::string implementationInitialiseVariablesMethodString(bool forDifferentialModel) const; /** * @brief Set the @c std::string for the implementation to initialise @@ -3421,13 +3758,10 @@ class LIBCELLML_EXPORT GeneratorProfile * * @param forDifferentialModel Whether the implementation to initialise * variables is for a differential model, as opposed to an algebraic model. - * @param withExternalVariables Whether the implementation to initialise - * variables is for a model with external variables. * @param implementationInitialiseVariablesMethodString The @c std::string * to use for the implementation to initialise variables. */ void setImplementationInitialiseVariablesMethodString(bool forDifferentialModel, - bool withExternalVariables, const std::string &implementationInitialiseVariablesMethodString); /** diff --git a/src/api/libcellml/interpreter.h b/src/api/libcellml/interpreter.h new file mode 100644 index 0000000000..a306f27ebe --- /dev/null +++ b/src/api/libcellml/interpreter.h @@ -0,0 +1,201 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#include "libcellml/exportdefinitions.h" +#include "libcellml/types.h" + +#include + +namespace libcellml { + +typedef double (*AlgebraicModelExternalVariable)(double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); +typedef double (*DifferentialModelExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +/** + * @brief The Interpreter class. + * + * The Interpreter class is for representing a CellML Interpreter. + * + * @warning The Interpreter class currently supports pure algebraic models and ODE models. NLA and DAE models are not + * currently supported and neither are models with external variables. + */ +class LIBCELLML_EXPORT Interpreter +{ +public: + ~Interpreter(); /**< Destructor, @private. */ + Interpreter(const Interpreter &rhs) = delete; /**< Copy constructor, @private. */ + Interpreter(Interpreter &&rhs) noexcept = delete; /**< Move constructor, @private. */ + Interpreter &operator=(Interpreter rhs) = delete; /**< Assignment operator, @private. */ + + /** + * @brief Create an @ref Interpreter object. + * + * Factory method to create an @ref Interpreter. Create an interpreter with:: + * + * @code + * auto interpreter = libcellml::Interpreter::create(); + * @endcode + * + * @return A smart pointer to an @ref Interpreter object. + */ + static InterpreterPtr create() noexcept; + + /** + * @brief Get the @ref AnalyserModel. + * + * Get the @ref AnalyserModel used by this @ref Interpreter. + * + * @return The @ref AnalyserModel used. + */ + AnalyserModelPtr model(); + + /** + * @brief Set the @ref AnalyserModel. + * + * Set the @ref AnalyserModel to be used by this @ref Interpreter. + * + * @param model The @ref AnalyserModel to set. + */ + void setModel(const AnalyserModelPtr &model); + + /** + * @brief Initialise the model's variables. + * + * Initialise the model's variables. This method is only relevant for algebraic models. + * + * @param constants The array of constants to use. + * @param computedConstants The array of computed constants to use. + * @param algebraic The array of algebraic variables to use. + */ + void initialiseVariables(double *constants, double *computedConstants, double *algebraic) const; + + /** + * @brief Initialise the model's variables. + * + * Initialise the model's variables. This method is only relevant for differential models. + * + * @param states The array of states to use. + * @param rates The array of rates to use. + * @param constants The array of constants to use. + * @param computedConstants The array of computed constants to use. + * @param algebraic The array of algebraic variables to use. + */ + void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) const; + + /** + * @brief Compute the model's computed constants. + * + * Compute the model's computed constants. + * + * @param constants The array of constants to use. + * @param computedConstants The array of computed constants to use. + */ + void computeComputedConstants(double *constants, double *computedConstants) const; + + /** + * @brief Compute the model's rates. + * + * Compute the model's rates. This method is only relevant for differential models. + * + * @param voi The value of the variable of integration. + * @param states The array of states. + * @param rates The array of rates to use. + * @param constants The array of constants to use. + * @param computedConstants The array of computed constants to use. + * @param algebraic The array of algebraic variables to use. + */ + void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) const; + + /** + * @brief Compute the model's rates. + * + * Compute the model's rates. This method is only relevant for differential models with external variables. + * + * @param voi The value of the variable of integration. + * @param states The array of states. + * @param rates The array of rates to use. + * @param constants The array of constants to use. + * @param computedConstants The array of computed constants to use. + * @param algebraic The array of algebraic variables to use. + * @param externals The array of external variables to use. + * @param externalVariable The external variable function to use. + */ + void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, DifferentialModelExternalVariable externalVariable) const; + + /** + * @brief Compute the model's variables. + * + * Compute the model's variables. This method is only relevant for algebraic models. + * + * @param constants The array of constants to use. + * @param computedConstants The array of computed constants to use. + * @param algebraic The array of algebraic variables to use. + */ + void computeVariables(double *constants, double *computedConstants, double *algebraic) const; + + /** + * @brief Compute the model's variables. + * + * Compute the model's variables. This method is only relevant for algebraic models with external variables. + * + * @param constants The array of constants to use. + * @param computedConstants The array of computed constants to use. + * @param algebraic The array of algebraic variables to use. + * @param externals The array of external variables to use. + * @param externalVariable The external variable function to use. + */ + void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, AlgebraicModelExternalVariable externalVariable) const; + + /** + * @brief Compute the model's variables. + * + * Compute the model's variables. This method is only relevant for differential models. + * + * @param voi The value of the variable of integration. + * @param states The array of states. + * @param rates The array of rates. + * @param constants The array of constants to use. + * @param computedConstants The array of computed constants to use. + * @param algebraic The array of algebraic variables to use. + */ + void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) const; + + /** + * @brief Compute the model's variables. + * + * Compute the model's variables. This method is only relevant for differential models with external variables. + * + * @param voi The value of the variable of integration. + * @param states The array of states. + * @param rates The array of rates. + * @param constants The array of constants to use. + * @param computedConstants The array of computed constants to use. + * @param algebraic The array of algebraic variables to use. + * @param externals The array of external variables to use. + * @param externalVariable The external variable function to use. + */ + void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, DifferentialModelExternalVariable externalVariable) const; + +private: + Interpreter(); /**< Constructor, @private. */ + + struct InterpreterImpl; + InterpreterImpl *mPimpl; /**< Private member to implementation pointer, @private. */ +}; + +} // namespace libcellml diff --git a/src/api/libcellml/module/libcellml b/src/api/libcellml/module/libcellml index 18940a3c27..7dfca862df 100644 --- a/src/api/libcellml/module/libcellml +++ b/src/api/libcellml/module/libcellml @@ -37,6 +37,7 @@ limitations under the License. #include "libcellml/generatorprofile.h" #include "libcellml/importer.h" #include "libcellml/importsource.h" +#include "libcellml/interpreter.h" #include "libcellml/issue.h" #include "libcellml/logger.h" #include "libcellml/model.h" diff --git a/src/api/libcellml/types.h b/src/api/libcellml/types.h index 48fb728564..73e54cf54c 100644 --- a/src/api/libcellml/types.h +++ b/src/api/libcellml/types.h @@ -50,6 +50,8 @@ class GeneratorProfile; /**< Forward declaration of GeneratorProfile class. */ using GeneratorProfilePtr = std::shared_ptr; /**< Type definition for shared generator variable pointer. */ class Importer; /**< Forward declaration of Importer class. */ using ImporterPtr = std::shared_ptr; /**< Type definition for shared importer pointer. */ +class Interpreter; /**< Forward declaration of Interpreter class. */ +using InterpreterPtr = std::shared_ptr; /**< Type definition for shared Interpreter pointer. */ class Issue; /**< Forward declaration of Issue class. */ using IssuePtr = std::shared_ptr; /**< Type definition for shared issue pointer. */ class Logger; /**< Forward declaration of Parser class. */ diff --git a/src/bindings/interface/analyser.i b/src/bindings/interface/analyser.i index 050cfd0999..8ae80be210 100644 --- a/src/bindings/interface/analyser.i +++ b/src/bindings/interface/analyser.i @@ -17,19 +17,16 @@ "Adds a variable as an external variable to this analyser."; %feature("docstring") libcellml::Analyser::removeExternalVariable -"Removes an external variable specified by 1) an index, 2) a :class:`Model` object, component name and variable -name, or 3) a :class:`Variable` object. Returns `True` on success."; +"Removes an external variable specified by 1) an index, 2) a :class:`Variable` object, or 3) an :class:`AnalyserExternalVariable` object. Returns `True` on success."; %feature("docstring") libcellml::Analyser::removeAllExternalVariables "Removes all external variables from this analyser."; %feature("docstring") libcellml::Analyser::containsExternalVariable -"Tests if an external variable, specified by 1) a :class:`Model` object, component name and variable name, or 2) -an :class:`AnalyserExternalVariable` object, is contained within this analyser."; +"Tests if an external variable, specified by 1) a :class:`Variable` object, or 2) an :class:`AnalyserExternalVariable` object, is contained within this analyser."; %feature("docstring") libcellml::Analyser::externalVariable -"Returns the external variable, specified by 1) an index, or 2) a :class:`Model` object, component name and -variable name."; +"Returns the external variable, specified by 1) an index, or 2) a :class:`Variable` object."; %feature("docstring") libcellml::Analyser::externalVariableCount "Returns the number of external variables this analyser contains."; diff --git a/src/bindings/interface/analyserequation.i b/src/bindings/interface/analyserequation.i index 208290c498..e75f49f9a4 100644 --- a/src/bindings/interface/analyserequation.i +++ b/src/bindings/interface/analyserequation.i @@ -43,14 +43,41 @@ %feature("docstring") libcellml::AnalyserEquation::isStateRateBased "Tests if this :class:`AnalyserEquation` object relies on states and/or rates."; -%feature("docstring") libcellml::AnalyserEquation::variableCount -"Returns the number of variables computed by this :class:`AnalyserEquation` object."; +%feature("docstring") libcellml::AnalyserEquation::stateCount +"Returns the number of states computed by this :class:`AnalyserEquation` object."; -%feature("docstring") libcellml::AnalyserEquation::variables -"Returns the variables computed by this :class:`AnalyserEquation` object."; +%feature("docstring") libcellml::AnalyserEquation::states +"Returns the states computed by this :class:`AnalyserEquation` object."; -%feature("docstring") libcellml::AnalyserEquation::variable -"Returns the variable, at the given index, computed by this :class:`AnalyserEquation` object."; +%feature("docstring") libcellml::AnalyserEquation::state +"Returns the state, at the given index, computed by this :class:`AnalyserEquation` object."; + +%feature("docstring") libcellml::AnalyserEquation::computedConstantCount +"Returns the number of computed constants computed by this :class:`AnalyserEquation` object."; + +%feature("docstring") libcellml::AnalyserEquation::computedConstants +"Returns the computed constants computed by this :class:`AnalyserEquation` object."; + +%feature("docstring") libcellml::AnalyserEquation::computedConstant +"Returns the computed constant, at the given index, computed by this :class:`AnalyserEquation` object."; + +%feature("docstring") libcellml::AnalyserEquation::algebraicCount +"Returns the number of algebraic variables computed by this :class:`AnalyserEquation` object."; + +%feature("docstring") libcellml::AnalyserEquation::algebraic +"Returns the algebraic variables computed by this :class:`AnalyserEquation` object."; + +%feature("docstring") libcellml::AnalyserEquation::algebraic +"Returns the algebraic variable, at the given index, computed by this :class:`AnalyserEquation` object."; + +%feature("docstring") libcellml::AnalyserEquation::externalCount +"Returns the number of external variables computed by this :class:`AnalyserEquation` object."; + +%feature("docstring") libcellml::AnalyserEquation::externals +"Returns the external variables computed by this :class:`AnalyserEquation` object."; + +%feature("docstring") libcellml::AnalyserEquation::external +"Returns the external variable, at the given index, computed by this :class:`AnalyserEquation` object."; %{ #include "libcellml/analyserequation.h" diff --git a/src/bindings/interface/analyserequationast.i b/src/bindings/interface/analyserequationast.i index 3d064c706f..d8d42695f6 100644 --- a/src/bindings/interface/analyserequationast.i +++ b/src/bindings/interface/analyserequationast.i @@ -53,6 +53,9 @@ "Swaps the left and right children of this :class:`AnalyserEquationAst` object."; %{ +#include +#include + #include "libcellml/analyserequationast.h" %} diff --git a/src/bindings/interface/analysermodel.i b/src/bindings/interface/analysermodel.i index 704d3e2f41..692a9d789a 100644 --- a/src/bindings/interface/analysermodel.i +++ b/src/bindings/interface/analysermodel.i @@ -34,14 +34,41 @@ %feature("docstring") libcellml::AnalyserModel::state "Returns the state, specified by index, contained by this :class:`AnalyserModel` object."; -%feature("docstring") libcellml::AnalyserModel::variableCount -"Returns the number of variables contained by this :class:`AnalyserModel` object."; +%feature("docstring") libcellml::AnalyserModel::constantCount +"Returns the number of constants contained by this :class:`AnalyserModel` object."; -%feature("docstring") libcellml::AnalyserModel::variables -"Returns the variables contained by this :class:`AnalyserModel` object."; +%feature("docstring") libcellml::AnalyserModel::constants +"Returns the constants contained by this :class:`AnalyserModel` object."; -%feature("docstring") libcellml::AnalyserModel::variable -"Returns the variable, specified by index, contained by this :class:`AnalyserModel` object."; +%feature("docstring") libcellml::AnalyserModel::constant +"Returns the constant, specified by index, contained by this :class:`AnalyserModel` object."; + +%feature("docstring") libcellml::AnalyserModel::computedConstantCount +"Returns the number of computed constants contained by this :class:`AnalyserModel` object."; + +%feature("docstring") libcellml::AnalyserModel::computedConstants +"Returns the computed constants contained by this :class:`AnalyserModel` object."; + +%feature("docstring") libcellml::AnalyserModel::computedConstant +"Returns the computed constant, specified by index, contained by this :class:`AnalyserModel` object."; + +%feature("docstring") libcellml::AnalyserModel::algebraicCount +"Returns the number of algebraic variables contained by this :class:`AnalyserModel` object."; + +%feature("docstring") libcellml::AnalyserModel::algebraic +"Returns the algebraic variables contained by this :class:`AnalyserModel` object."; + +%feature("docstring") libcellml::AnalyserModel::algebraic +"Returns the algebraic variable, specified by index, contained by this :class:`AnalyserModel` object."; + +%feature("docstring") libcellml::AnalyserModel::externalCount +"Returns the number of external variables contained by this :class:`AnalyserModel` object."; + +%feature("docstring") libcellml::AnalyserModel::externals +"Returns the external variables contained by this :class:`AnalyserModel` object."; + +%feature("docstring") libcellml::AnalyserModel::external +"Returns the external variable, specified by index, contained by this :class:`AnalyserModel` object."; %feature("docstring") libcellml::AnalyserModel::equationCount "Returns the number of equations contained by this :class:`AnalyserModel` object."; diff --git a/src/bindings/interface/generatorprofile.i b/src/bindings/interface/generatorprofile.i index 603ccd5b07..62cb5f26d6 100644 --- a/src/bindings/interface/generatorprofile.i +++ b/src/bindings/interface/generatorprofile.i @@ -611,15 +611,15 @@ "Returns the string for a comment."; %feature("docstring") libcellml::GeneratorProfile::setCommentString -"Sets the string for a comment. To be useful, the string should contain the tag, which will be replaced +"Sets the string for a comment. To be useful, the string should contain the [CODE] tag, which will be replaced with a (proper) comment."; %feature("docstring") libcellml::GeneratorProfile::originCommentString "Returns the string for an origin comment."; %feature("docstring") libcellml::GeneratorProfile::setOriginCommentString -"Sets the string for an origin comment. To be useful, the string should contain the and - tags, which will be replaced with a statement about the profile and the version of libCellML +"Sets the string for an origin comment. To be useful, the string should contain the [PROFILE_INFORMATION] and +[LIBCELLML_VERSION] tags, which will be replaced with a statement about the profile and the version of libCellML used respectively."; %feature("docstring") libcellml::GeneratorProfile::interfaceFileNameString @@ -675,69 +675,66 @@ used respectively."; %feature("docstring") libcellml::GeneratorProfile::setImplementationStateCountString "Sets the string for the implementation of the state count constant. To be useful, the string should contain the - tag, which will be replaced with the number of states in the model."; +[STATE_COUNT] tag, which will be replaced with the number of states in the model."; -%feature("docstring") libcellml::GeneratorProfile::interfaceVariableCountString -"Returns the string for the interface of the variable count constant."; +%feature("docstring") libcellml::GeneratorProfile::interfaceConstantCountString +"Returns the string for the interface of the constant count constant."; -%feature("docstring") libcellml::GeneratorProfile::setInterfaceVariableCountString -"Sets the string for the interface of the variable count constant."; +%feature("docstring") libcellml::GeneratorProfile::setInterfaceConstantCountString +"Sets the string for the interface of the constant count constant."; -%feature("docstring") libcellml::GeneratorProfile::implementationVariableCountString -"Returns the string for the implementation of the variable count constant."; +%feature("docstring") libcellml::GeneratorProfile::implementationConstantCountString +"Returns the string for the implementation of the constant count constant."; -%feature("docstring") libcellml::GeneratorProfile::setImplementationVariableCountString -"Sets the string for the implementation of the variable count constant. To be useful, the string should contain -the tag, which will be replaced with the number of states in the model."; +%feature("docstring") libcellml::GeneratorProfile::setImplementationConstantCountString +"Sets the string for the implementation of the constant count constant. To be useful, the string should contain +the [CONSTANT_COUNT] tag, which will be replaced with the number of states in the model."; -%feature("docstring") libcellml::GeneratorProfile::variableTypeObjectString -"Returns the string for the data structure for the variable type object."; +%feature("docstring") libcellml::GeneratorProfile::interfaceComputedConstantCountString +"Returns the string for the interface of the computed constant count constant."; -%feature("docstring") libcellml::GeneratorProfile::setVariableTypeObjectString -"Sets the string for the data structure for the variable type object."; +%feature("docstring") libcellml::GeneratorProfile::setInterfaceComputedConstantCountString +"Sets the string for the interface of the computed constant count constant."; -%feature("docstring") libcellml::GeneratorProfile::variableOfIntegrationVariableTypeString -"Returns the string for the name of the variable of integration variable type."; +%feature("docstring") libcellml::GeneratorProfile::implementationComputedConstantCountString +"Returns the string for the implementation of the computed constant count constant."; -%feature("docstring") libcellml::GeneratorProfile::setVariableOfIntegrationVariableTypeString -"Sets the string for the name of the variable of integration variable type."; +%feature("docstring") libcellml::GeneratorProfile::setImplementationComputedConstantCountString +"Sets the string for the implementation of the computed constant count constant. To be useful, the string should contain +the [COMPUTED_CONSTANT_COUNT] tag, which will be replaced with the number of states in the model."; -%feature("docstring") libcellml::GeneratorProfile::stateVariableTypeString -"Returns the string for the name of the state variable type."; +%feature("docstring") libcellml::GeneratorProfile::interfaceAlgebraicCountString +"Returns the string for the interface of the algebraic count constant."; -%feature("docstring") libcellml::GeneratorProfile::setStateVariableTypeString -"Sets the string for the name of the state variable type."; +%feature("docstring") libcellml::GeneratorProfile::setInterfaceAlgebraicCountString +"Sets the string for the interface of the algebraic count constant."; -%feature("docstring") libcellml::GeneratorProfile::constantVariableTypeString -"Returns the string for the name of the constant variable type."; +%feature("docstring") libcellml::GeneratorProfile::implementationAlgebraicCountString +"Returns the string for the implementation of the algebraic count constant."; -%feature("docstring") libcellml::GeneratorProfile::setConstantVariableTypeString -"Sets the string for the name of the constant variable type."; +%feature("docstring") libcellml::GeneratorProfile::setImplementationAlgebraicCountString +"Sets the string for the implementation of the algebraic count constant. To be useful, the string should contain +the [ALGEBRAIC_COUNT] tag, which will be replaced with the number of states in the model."; -%feature("docstring") libcellml::GeneratorProfile::computedConstantVariableTypeString -"Returns the string for the name of the computed constant variable type."; +%feature("docstring") libcellml::GeneratorProfile::interfaceExternalCountString +"Returns the string for the interface of the external count constant."; -%feature("docstring") libcellml::GeneratorProfile::setComputedConstantVariableTypeString -"Sets the string for the name of the computed constant variable type."; +%feature("docstring") libcellml::GeneratorProfile::setInterfaceExternalCountString +"Sets the string for the interface of the external count constant."; -%feature("docstring") libcellml::GeneratorProfile::algebraicVariableTypeString -"Returns the string for the name of the algebraic variable type."; +%feature("docstring") libcellml::GeneratorProfile::implementationExternalCountString +"Returns the string for the implementation of the external count constant."; -%feature("docstring") libcellml::GeneratorProfile::setAlgebraicVariableTypeString -"Sets the string for the name of the algebraic variable type."; - -%feature("docstring") libcellml::GeneratorProfile::externalVariableTypeString -"Returns the string for the name of the external variable type."; - -%feature("docstring") libcellml::GeneratorProfile::setExternalVariableTypeString -"Sets the string for the name of the external variable type."; +%feature("docstring") libcellml::GeneratorProfile::setImplementationExternalCountString +"Sets the string for the implementation of the external count constant. To be useful, the string should contain +the [EXTERNAL_COUNT] tag, which will be replaced with the number of states in the model."; %feature("docstring") libcellml::GeneratorProfile::variableInfoObjectString "Returns the string for the data structure for the variable information object."; %feature("docstring") libcellml::GeneratorProfile::setVariableInfoObjectString "Sets the string for the data structure for the variable information object. To be useful, the string should -contain the , and tags, which will be replaced with the maximum size of +contain the [NAME_SIZE], [UNITS_SIZE] and [COMPONENT_SIZE] tags, which will be replaced with the maximum size of a string for holding the name of a component, variable and units, respectively."; %feature("docstring") libcellml::GeneratorProfile::interfaceVoiInfoString @@ -751,7 +748,7 @@ a string for holding the name of a component, variable and units, respectively." %feature("docstring") libcellml::GeneratorProfile::setImplementationVoiInfoString "Sets the string for the implementation of some information about the variable of integration. To be useful, the -string should contain the tag, which will be replaced with some information about the variable of +string should contain the [CODE] tag, which will be replaced with some information about the variable of integration."; %feature("docstring") libcellml::GeneratorProfile::interfaceStateInfoString @@ -765,28 +762,66 @@ integration."; %feature("docstring") libcellml::GeneratorProfile::setImplementationStateInfoString "Sets the string for the implementation of some information about the different states. To be useful, the string -should contain the tag, which will be replaced with some information about the different states."; +should contain the [CODE] tag, which will be replaced with some information about the different states."; + +%feature("docstring") libcellml::GeneratorProfile::interfaceConstantInfoString +"Returns the string for the interface of some information about the different constants."; + +%feature("docstring") libcellml::GeneratorProfile::setInterfaceConstantInfoString +"Sets the string for the interface of some information about the different constants."; + +%feature("docstring") libcellml::GeneratorProfile::implementationConstantInfoString +"Returns the string for the implementation of some information about the different constants."; + +%feature("docstring") libcellml::GeneratorProfile::setImplementationConstantInfoString +"Sets the string for the implementation of some information about the different constants. To be useful, the string +should contain the [CODE] tag, which will be replaced with some information about the different constants."; + +%feature("docstring") libcellml::GeneratorProfile::interfaceComputedConstantInfoString +"Returns the string for the interface of some information about the different computed constants."; + +%feature("docstring") libcellml::GeneratorProfile::setInterfaceComputedConstantInfoString +"Sets the string for the interface of some information about the different computed constants."; -%feature("docstring") libcellml::GeneratorProfile::interfaceVariableInfoString -"Returns the string for the interface of some information about the different variables."; +%feature("docstring") libcellml::GeneratorProfile::implementationComputedConstantInfoString +"Returns the string for the implementation of some information about the different computed constants."; -%feature("docstring") libcellml::GeneratorProfile::setInterfaceVariableInfoString -"Sets the string for the interface of some information about the different variables."; +%feature("docstring") libcellml::GeneratorProfile::setImplementationComputedConstantInfoString +"Sets the string for the implementation of some information about the different computed constants. To be useful, the string +should contain the [CODE] tag, which will be replaced with some information about the different computed constants."; -%feature("docstring") libcellml::GeneratorProfile::implementationVariableInfoString -"Returns the string for the implementation of some information about the different variables."; +%feature("docstring") libcellml::GeneratorProfile::interfaceAlgebraicInfoString +"Returns the string for the interface of some information about the different algebraic variables."; -%feature("docstring") libcellml::GeneratorProfile::setImplementationVariableInfoString -"Sets the string for the implementation of some information about the different variables. To be useful, the -string should contain the tag, which will be replaced with some information about the different -variables."; +%feature("docstring") libcellml::GeneratorProfile::setInterfaceAlgebraicInfoString +"Sets the string for the interface of some information about the different algebraic variables."; + +%feature("docstring") libcellml::GeneratorProfile::implementationAlgebraicInfoString +"Returns the string for the implementation of some information about the different algebraic variables."; + +%feature("docstring") libcellml::GeneratorProfile::setImplementationAlgebraicInfoString +"Sets the string for the implementation of some information about the different algebraic variables. To be useful, the string +should contain the [CODE] tag, which will be replaced with some information about the different algebraic variables."; + +%feature("docstring") libcellml::GeneratorProfile::interfaceExternalInfoString +"Returns the string for the interface of some information about the different external variables."; + +%feature("docstring") libcellml::GeneratorProfile::setInterfaceExternalInfoString +"Sets the string for the interface of some information about the different external variables."; + +%feature("docstring") libcellml::GeneratorProfile::implementationExternalInfoString +"Returns the string for the implementation of some information about the different external variables."; + +%feature("docstring") libcellml::GeneratorProfile::setImplementationExternalInfoString +"Sets the string for the implementation of some information about the different external variables. To be useful, the string +should contain the [CODE] tag, which will be replaced with some information about the different external variables."; %feature("docstring") libcellml::GeneratorProfile::variableInfoEntryString "Returns the string for an entry in an array for some information about a variable."; %feature("docstring") libcellml::GeneratorProfile::setVariableInfoEntryString "Sets the string for an entry in an array for some information about a variable. To be useful, the string should -contain the , and tags, which will be replaced with the name of the component, name +contain the [COMPONENT], [NAME] and [UNITS] tags, which will be replaced with the name of the component, name and units of a variable respectively."; %feature("docstring") libcellml::GeneratorProfile::voiString @@ -807,11 +842,29 @@ and units of a variable respectively."; %feature("docstring") libcellml::GeneratorProfile::setRatesArrayString "Sets the string for the name of the rates array."; -%feature("docstring") libcellml::GeneratorProfile::variablesArrayString -"Returns the string for the name of the variables array."; +%feature("docstring") libcellml::GeneratorProfile::constantsArrayString +"Returns the string for the name of the constants array."; + +%feature("docstring") libcellml::GeneratorProfile::setConstantsArrayString +"Sets the string for the name of the constants array."; + +%feature("docstring") libcellml::GeneratorProfile::computedConstantsArrayString +"Returns the string for the name of the computed constants array."; -%feature("docstring") libcellml::GeneratorProfile::setVariablesArrayString -"Sets the string for the name of the variables array."; +%feature("docstring") libcellml::GeneratorProfile::setComputedConstantsArrayString +"Sets the string for the name of the computed constants array."; + +%feature("docstring") libcellml::GeneratorProfile::algebraicArrayString +"Returns the string for the name of the algebraic array."; + +%feature("docstring") libcellml::GeneratorProfile::setAlgebraicArrayString +"Sets the string for the name of the algebraic array."; + +%feature("docstring") libcellml::GeneratorProfile::externalArrayString +"Returns the string for the name of the external array."; + +%feature("docstring") libcellml::GeneratorProfile::setExternalArrayString +"Sets the string for the name of the external array."; %feature("docstring") libcellml::GeneratorProfile::externalVariableMethodTypeDefinitionString "Returns the string for the type definition of an external variable method."; @@ -874,14 +927,14 @@ and units of a variable respectively."; "Sets the string for the f array used in the objective function and find root methods."; %feature("docstring") libcellml::GeneratorProfile::setReturnCreatedArrayString -"Sets the string for returning a created array. To be useful, the string should contain the tag, +"Sets the string for returning a created array. To be useful, the string should contain the [ARRAY_SIZE] tag, which will be replaced with the size of the array to be created."; %feature("docstring") libcellml::GeneratorProfile::interfaceCreateStatesArrayMethodString "Returns the string for the interface to create the states array."; %feature("docstring") libcellml::GeneratorProfile::setInterfaceCreateStatesArrayMethodString -"Sets the string for the interface to create the states array. To be useful, the string should contain the +"Sets the string for the interface to create the states array. To be useful, the string should contain the [CODE] tag, which will be replaced with some code to create the states array."; %feature("docstring") libcellml::GeneratorProfile::implementationCreateStatesArrayMethodString @@ -889,21 +942,63 @@ tag, which will be replaced with some code to create the states array."; %feature("docstring") libcellml::GeneratorProfile::setImplementationCreateStatesArrayMethodString "Sets the string for the implementation to create the states array. To be useful, the string should contain the - tag, which will be replaced with some code to create the states array."; +[CODE] tag, which will be replaced with some code to create the states array."; + +%feature("docstring") libcellml::GeneratorProfile::interfaceCreateConstantsArrayMethodString +"Returns the string for the interface to create the constants array."; + +%feature("docstring") libcellml::GeneratorProfile::setInterfaceCreateConstantsArrayMethodString +"Sets the string for the interface to create the constants array. To be useful, the string should contain the [CODE] +tag, which will be replaced with some code to create the constants array."; + +%feature("docstring") libcellml::GeneratorProfile::implementationCreateConstantsArrayMethodString +"Returns the string for the implementation to create the constants array."; + +%feature("docstring") libcellml::GeneratorProfile::setImplementationCreateConstantsArrayMethodString +"Sets the string for the implementation to create the constants array. To be useful, the string should contain the +[CODE] tag, which will be replaced with some code to create the constants array."; + +%feature("docstring") libcellml::GeneratorProfile::interfaceCreateComputedConstantsArrayMethodString +"Returns the string for the interface to create the computed constants array."; + +%feature("docstring") libcellml::GeneratorProfile::setInterfaceCreateComputedConstantsArrayMethodString +"Sets the string for the interface to create the computed constants array. To be useful, the string should contain the [CODE] +tag, which will be replaced with some code to create the computed constants array."; + +%feature("docstring") libcellml::GeneratorProfile::implementationCreateComputedConstantsArrayMethodString +"Returns the string for the implementation to create the computed constants array."; + +%feature("docstring") libcellml::GeneratorProfile::setImplementationCreateComputedConstantsArrayMethodString +"Sets the string for the implementation to create the computed constants array. To be useful, the string should contain the +[CODE] tag, which will be replaced with some code to create the computed constants array."; + +%feature("docstring") libcellml::GeneratorProfile::interfaceCreateAlgebraicArrayMethodString +"Returns the string for the interface to create the algebraic array."; + +%feature("docstring") libcellml::GeneratorProfile::setInterfaceCreateAlgebraicArrayMethodString +"Sets the string for the interface to create the algebraic array. To be useful, the string should contain the [CODE] +tag, which will be replaced with some code to create the algebraic array."; + +%feature("docstring") libcellml::GeneratorProfile::implementationCreateAlgebraicArrayMethodString +"Returns the string for the implementation to create the algebraic array."; + +%feature("docstring") libcellml::GeneratorProfile::setImplementationCreateAlgebraicArrayMethodString +"Sets the string for the implementation to create the algebraic array. To be useful, the string should contain the +[CODE] tag, which will be replaced with some code to create the algebraic array."; -%feature("docstring") libcellml::GeneratorProfile::interfaceCreateVariablesArrayMethodString -"Returns the string for the interface to create variables array."; +%feature("docstring") libcellml::GeneratorProfile::interfaceCreateExternalsArrayMethodString +"Returns the string for the interface to create the externals array."; -%feature("docstring") libcellml::GeneratorProfile::setInterfaceCreateVariablesArrayMethodString -"Sets the string for the interface to create variables array. To be useful, the string should contain the -tag, which will be replaced with some code to create the variables array."; +%feature("docstring") libcellml::GeneratorProfile::setInterfaceCreateExternalsArrayMethodString +"Sets the string for the interface to create the externals array. To be useful, the string should contain the [CODE] +tag, which will be replaced with some code to create the externals array."; -%feature("docstring") libcellml::GeneratorProfile::implementationCreateVariablesArrayMethodString -"Returns the string for the implementation to create the variables array."; +%feature("docstring") libcellml::GeneratorProfile::implementationCreateExternalsArrayMethodString +"Returns the string for the implementation to create the externals array."; -%feature("docstring") libcellml::GeneratorProfile::setImplementationCreateVariablesArrayMethodString -"Sets the string for the implementation to create the variables array. To be useful, the string should contain the - tag, which will be replaced with some code to create the variables array."; +%feature("docstring") libcellml::GeneratorProfile::setImplementationCreateExternalsArrayMethodString +"Sets the string for the implementation to create the externals array. To be useful, the string should contain the +[CODE] tag, which will be replaced with some code to create the externals array."; %feature("docstring") libcellml::GeneratorProfile::interfaceDeleteArrayMethodString "Returns the string for the interface to delete an array."; diff --git a/src/bindings/interface/interpreter.i b/src/bindings/interface/interpreter.i new file mode 100644 index 0000000000..b22e74b3e4 --- /dev/null +++ b/src/bindings/interface/interpreter.i @@ -0,0 +1,46 @@ +%module(package="libcellml") interpreter + +#define LIBCELLML_EXPORT + +%{ +#define SWIG_FILE_WITH_INIT +#include "libcellml/interpreter.h" +%} + +%import "analysermodel.i" +%import "createconstructor.i" + +%feature("docstring") libcellml::Interpreter +"Creates a :class:`Interpreter` object."; + +%feature("docstring") libcellml::Interpreter::model +"Returns the model to interpret."; + +%feature("docstring") libcellml::Interpreter::setModel +"Sets the model to interpret."; + +%feature("docstring") libcellml::Interpreter::initialiseVariables +"Initialises the model's variables."; + +%feature("docstring") libcellml::Interpreter::computeComputedConstants +"Computes the model's computed constants."; + +%feature("docstring") libcellml::Interpreter::computeRates +"Computes the model's rates."; + +%feature("docstring") libcellml::Interpreter::computeVariables +"Computes the model's variables."; + +%init %{ +import_array(); +%} + +%apply (double* INPLACE_ARRAY1) {(double *array)} + +%pythoncode %{ +# libCellML generated wrapper code starts here. +%} + +%create_constructor(Interpreter) + +%include "libcellml/interpreter.h" diff --git a/src/bindings/interface/types.i b/src/bindings/interface/types.i index 01c6b8c17a..9cad37a58c 100644 --- a/src/bindings/interface/types.i +++ b/src/bindings/interface/types.i @@ -29,6 +29,7 @@ Provides support for shared pointers declared in types.h. %shared_ptr(libcellml::Importer) %shared_ptr(libcellml::ImportSource) %shared_ptr(libcellml::ImportedEntity) +%shared_ptr(libcellml::Interpreter) %shared_ptr(libcellml::Issue) %shared_ptr(libcellml::Logger) %shared_ptr(libcellml::Model) diff --git a/src/bindings/javascript/CMakeLists.txt b/src/bindings/javascript/CMakeLists.txt index 9fdd3e1791..2e60e7e28c 100644 --- a/src/bindings/javascript/CMakeLists.txt +++ b/src/bindings/javascript/CMakeLists.txt @@ -16,6 +16,8 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/importedentity.cpp ${CMAKE_CURRENT_SOURCE_DIR}/importer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/importsource.cpp + #---GRY--- TO BE UNCOMMENTED ONCE WE HAVE FIGURED OUT HOW TO PASS double *. + # ${CMAKE_CURRENT_SOURCE_DIR}/interpreter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/issue.cpp ${CMAKE_CURRENT_SOURCE_DIR}/logger.cpp ${CMAKE_CURRENT_SOURCE_DIR}/model.cpp diff --git a/src/bindings/javascript/analyser.cpp b/src/bindings/javascript/analyser.cpp index 99835a9f50..ce99fa6f79 100644 --- a/src/bindings/javascript/analyser.cpp +++ b/src/bindings/javascript/analyser.cpp @@ -25,17 +25,17 @@ EMSCRIPTEN_BINDINGS(libcellml_analyser) class_>("Analyser") .smart_ptr_constructor("Analyser", &libcellml::Analyser::create) .function("analyseModel", &libcellml::Analyser::analyseModel) - .function("addExternalVariable", &libcellml::Analyser::addExternalVariable) + .function("addExternalVariableByVariable", select_overload(&libcellml::Analyser::addExternalVariable)) + .function("addExternalVariableByExternalVariable", select_overload(&libcellml::Analyser::addExternalVariable)) .function("removeExternalVariableByIndex", select_overload(&libcellml::Analyser::removeExternalVariable)) - .function("removeExternalVariableByModel", select_overload(&libcellml::Analyser::removeExternalVariable)) + .function("removeExternalVariableByVariable", select_overload(&libcellml::Analyser::removeExternalVariable)) .function("removeExternalVariableByExternalVariable", select_overload(&libcellml::Analyser::removeExternalVariable)) .function("removeAllExternalVariables", &libcellml::Analyser::removeAllExternalVariables) - .function("containsExternalVariableByModel", select_overload(&libcellml::Analyser::containsExternalVariable)) + .function("containsExternalVariableByVariable", select_overload(&libcellml::Analyser::containsExternalVariable)) .function("containsExternalVariableByExternalVariable", select_overload(&libcellml::Analyser::containsExternalVariable)) .function("externalVariableByIndex", select_overload(&libcellml::Analyser::externalVariable)) - .function("externalVariableByModel", select_overload(&libcellml::Analyser::externalVariable)) + .function("externalVariableByVariable", select_overload(&libcellml::Analyser::externalVariable)) .function("externalVariableCount", &libcellml::Analyser::externalVariableCount) .function("model", &libcellml::Analyser::model) ; } - diff --git a/src/bindings/javascript/analyserequation.cpp b/src/bindings/javascript/analyserequation.cpp index d7579751f8..5f428b0405 100644 --- a/src/bindings/javascript/analyserequation.cpp +++ b/src/bindings/javascript/analyserequation.cpp @@ -45,9 +45,18 @@ EMSCRIPTEN_BINDINGS(libcellml_analyserequation) .function("nlaSiblings", &libcellml::AnalyserEquation::nlaSiblings) .function("nlaSibling", &libcellml::AnalyserEquation::nlaSibling) .function("isStateRateBased", &libcellml::AnalyserEquation::isStateRateBased) - .function("variableCount", &libcellml::AnalyserEquation::variableCount) - .function("variables", &libcellml::AnalyserEquation::variables) - .function("variable", &libcellml::AnalyserEquation::variable) + .function("stateCount", &libcellml::AnalyserEquation::stateCount) + .function("states", select_overload() const>(&libcellml::AnalyserEquation::states)) + .function("state", select_overload(&libcellml::AnalyserEquation::state)) + .function("computedConstantCount", &libcellml::AnalyserEquation::computedConstantCount) + .function("computedConstants", &libcellml::AnalyserEquation::computedConstants) + .function("computedConstant", &libcellml::AnalyserEquation::computedConstant) + .function("algebraicCount", &libcellml::AnalyserEquation::algebraicCount) + .function("algebraicVariables", select_overload() const>(&libcellml::AnalyserEquation::algebraic)) + .function("algebraicVariable", select_overload(&libcellml::AnalyserEquation::algebraic)) + .function("externalCount", &libcellml::AnalyserEquation::externalCount) + .function("externals", select_overload() const>(&libcellml::AnalyserEquation::externals)) + .function("external", select_overload(&libcellml::AnalyserEquation::external)) ; EM_ASM( diff --git a/src/bindings/javascript/analysermodel.cpp b/src/bindings/javascript/analysermodel.cpp index 87a74085f5..5182aa89bc 100644 --- a/src/bindings/javascript/analysermodel.cpp +++ b/src/bindings/javascript/analysermodel.cpp @@ -45,9 +45,18 @@ EMSCRIPTEN_BINDINGS(libcellml_analysermodel) .function("stateCount", &libcellml::AnalyserModel::stateCount) .function("states", &libcellml::AnalyserModel::states) .function("state", &libcellml::AnalyserModel::state) - .function("variableCount", &libcellml::AnalyserModel::variableCount) - .function("variables", &libcellml::AnalyserModel::variables) - .function("variable", &libcellml::AnalyserModel::variable) + .function("constantCount", &libcellml::AnalyserModel::constantCount) + .function("constants", &libcellml::AnalyserModel::constants) + .function("constant", &libcellml::AnalyserModel::constant) + .function("computedConstantCount", &libcellml::AnalyserModel::computedConstantCount) + .function("computedConstants", &libcellml::AnalyserModel::computedConstants) + .function("computedConstant", &libcellml::AnalyserModel::computedConstant) + .function("algebraicCount", &libcellml::AnalyserModel::algebraicCount) + .function("algebraicVariables", select_overload() const>(&libcellml::AnalyserModel::algebraic)) + .function("algebraicVariable", select_overload(&libcellml::AnalyserModel::algebraic)) + .function("externalCount", &libcellml::AnalyserModel::externalCount) + .function("externals", select_overload() const>(&libcellml::AnalyserModel::externals)) + .function("external", select_overload(&libcellml::AnalyserModel::external)) .function("equationCount", &libcellml::AnalyserModel::equationCount) .function("equations", &libcellml::AnalyserModel::equations) .function("equation", &libcellml::AnalyserModel::equation) diff --git a/src/bindings/javascript/generatorprofile.cpp b/src/bindings/javascript/generatorprofile.cpp index 41e4115fe0..e981e701ee 100644 --- a/src/bindings/javascript/generatorprofile.cpp +++ b/src/bindings/javascript/generatorprofile.cpp @@ -251,24 +251,22 @@ EMSCRIPTEN_BINDINGS(libcellml_generatorprofile) .function("setInterfaceStateCountString", &libcellml::GeneratorProfile::setInterfaceStateCountString) .function("implementationStateCountString", &libcellml::GeneratorProfile::implementationStateCountString) .function("setImplementationStateCountString", &libcellml::GeneratorProfile::setImplementationStateCountString) - .function("interfaceVariableCountString", &libcellml::GeneratorProfile::interfaceVariableCountString) - .function("setInterfaceVariableCountString", &libcellml::GeneratorProfile::setInterfaceVariableCountString) - .function("implementationVariableCountString", &libcellml::GeneratorProfile::implementationVariableCountString) - .function("setImplementationVariableCountString", &libcellml::GeneratorProfile::setImplementationVariableCountString) - .function("variableTypeObjectString", &libcellml::GeneratorProfile::variableTypeObjectString) - .function("setVariableTypeObjectString", &libcellml::GeneratorProfile::setVariableTypeObjectString) - .function("variableOfIntegrationVariableTypeString", &libcellml::GeneratorProfile::variableOfIntegrationVariableTypeString) - .function("setVariableOfIntegrationVariableTypeString", &libcellml::GeneratorProfile::setVariableOfIntegrationVariableTypeString) - .function("stateVariableTypeString", &libcellml::GeneratorProfile::stateVariableTypeString) - .function("setStateVariableTypeString", &libcellml::GeneratorProfile::setStateVariableTypeString) - .function("constantVariableTypeString", &libcellml::GeneratorProfile::constantVariableTypeString) - .function("setConstantVariableTypeString", &libcellml::GeneratorProfile::setConstantVariableTypeString) - .function("computedConstantVariableTypeString", &libcellml::GeneratorProfile::computedConstantVariableTypeString) - .function("setComputedConstantVariableTypeString", &libcellml::GeneratorProfile::setComputedConstantVariableTypeString) - .function("algebraicVariableTypeString", &libcellml::GeneratorProfile::algebraicVariableTypeString) - .function("setAlgebraicVariableTypeString", &libcellml::GeneratorProfile::setAlgebraicVariableTypeString) - .function("externalVariableTypeString", &libcellml::GeneratorProfile::externalVariableTypeString) - .function("setExternalVariableTypeString", &libcellml::GeneratorProfile::setExternalVariableTypeString) + .function("interfaceConstantCountString", &libcellml::GeneratorProfile::interfaceConstantCountString) + .function("setInterfaceConstantCountString", &libcellml::GeneratorProfile::setInterfaceConstantCountString) + .function("implementationConstantCountString", &libcellml::GeneratorProfile::implementationConstantCountString) + .function("setImplementationConstantCountString", &libcellml::GeneratorProfile::setImplementationConstantCountString) + .function("interfaceComputedConstantCountString", &libcellml::GeneratorProfile::interfaceComputedConstantCountString) + .function("setInterfaceComputedConstantCountString", &libcellml::GeneratorProfile::setInterfaceComputedConstantCountString) + .function("implementationComputedConstantCountString", &libcellml::GeneratorProfile::implementationComputedConstantCountString) + .function("setImplementationComputedConstantCountString", &libcellml::GeneratorProfile::setImplementationComputedConstantCountString) + .function("interfaceAlgebraicCountString", &libcellml::GeneratorProfile::interfaceAlgebraicCountString) + .function("setInterfaceAlgebraicCountString", &libcellml::GeneratorProfile::setInterfaceAlgebraicCountString) + .function("implementationAlgebraicCountString", &libcellml::GeneratorProfile::implementationAlgebraicCountString) + .function("setImplementationAlgebraicCountString", &libcellml::GeneratorProfile::setImplementationAlgebraicCountString) + .function("interfaceExternalCountString", &libcellml::GeneratorProfile::interfaceExternalCountString) + .function("setInterfaceExternalCountString", &libcellml::GeneratorProfile::setInterfaceExternalCountString) + .function("implementationExternalCountString", &libcellml::GeneratorProfile::implementationExternalCountString) + .function("setImplementationExternalCountString", &libcellml::GeneratorProfile::setImplementationExternalCountString) .function("variableInfoObjectString", &libcellml::GeneratorProfile::variableInfoObjectString) .function("setVariableInfoObjectString", &libcellml::GeneratorProfile::setVariableInfoObjectString) .function("interfaceVoiInfoString", &libcellml::GeneratorProfile::interfaceVoiInfoString) @@ -279,10 +277,22 @@ EMSCRIPTEN_BINDINGS(libcellml_generatorprofile) .function("setInterfaceStateInfoString", &libcellml::GeneratorProfile::setInterfaceStateInfoString) .function("implementationStateInfoString", &libcellml::GeneratorProfile::implementationStateInfoString) .function("setImplementationStateInfoString", &libcellml::GeneratorProfile::setImplementationStateInfoString) - .function("interfaceVariableInfoString", &libcellml::GeneratorProfile::interfaceVariableInfoString) - .function("setInterfaceVariableInfoString", &libcellml::GeneratorProfile::setInterfaceVariableInfoString) - .function("implementationVariableInfoString", &libcellml::GeneratorProfile::implementationVariableInfoString) - .function("setImplementationVariableInfoString", &libcellml::GeneratorProfile::setImplementationVariableInfoString) + .function("interfaceConstantInfoString", &libcellml::GeneratorProfile::interfaceConstantInfoString) + .function("setInterfaceConstantInfoString", &libcellml::GeneratorProfile::setInterfaceConstantInfoString) + .function("implementationConstantInfoString", &libcellml::GeneratorProfile::implementationConstantInfoString) + .function("setImplementationConstantInfoString", &libcellml::GeneratorProfile::setImplementationConstantInfoString) + .function("interfaceComputedConstantInfoString", &libcellml::GeneratorProfile::interfaceComputedConstantInfoString) + .function("setInterfaceComputedConstantInfoString", &libcellml::GeneratorProfile::setInterfaceComputedConstantInfoString) + .function("implementationComputedConstantInfoString", &libcellml::GeneratorProfile::implementationComputedConstantInfoString) + .function("setImplementationComputedConstantInfoString", &libcellml::GeneratorProfile::setImplementationComputedConstantInfoString) + .function("interfaceAlgebraicInfoString", &libcellml::GeneratorProfile::interfaceAlgebraicInfoString) + .function("setInterfaceAlgebraicInfoString", &libcellml::GeneratorProfile::setInterfaceAlgebraicInfoString) + .function("implementationAlgebraicInfoString", &libcellml::GeneratorProfile::implementationAlgebraicInfoString) + .function("setImplementationAlgebraicInfoString", &libcellml::GeneratorProfile::setImplementationAlgebraicInfoString) + .function("interfaceExternalInfoString", &libcellml::GeneratorProfile::interfaceExternalInfoString) + .function("setInterfaceExternalInfoString", &libcellml::GeneratorProfile::setInterfaceExternalInfoString) + .function("implementationExternalInfoString", &libcellml::GeneratorProfile::implementationExternalInfoString) + .function("setImplementationExternalInfoString", &libcellml::GeneratorProfile::setImplementationExternalInfoString) .function("variableInfoEntryString", &libcellml::GeneratorProfile::variableInfoEntryString) .function("setVariableInfoEntryString", &libcellml::GeneratorProfile::setVariableInfoEntryString) .function("voiString", &libcellml::GeneratorProfile::voiString) @@ -291,8 +301,14 @@ EMSCRIPTEN_BINDINGS(libcellml_generatorprofile) .function("setStatesArrayString", &libcellml::GeneratorProfile::setStatesArrayString) .function("ratesArrayString", &libcellml::GeneratorProfile::ratesArrayString) .function("setRatesArrayString", &libcellml::GeneratorProfile::setRatesArrayString) - .function("variablesArrayString", &libcellml::GeneratorProfile::variablesArrayString) - .function("setVariablesArrayString", &libcellml::GeneratorProfile::setVariablesArrayString) + .function("constantsArrayString", &libcellml::GeneratorProfile::constantsArrayString) + .function("setConstantsArrayString", &libcellml::GeneratorProfile::setConstantsArrayString) + .function("computedConstantsArrayString", &libcellml::GeneratorProfile::computedConstantsArrayString) + .function("setComputedConstantsArrayString", &libcellml::GeneratorProfile::setComputedConstantsArrayString) + .function("algebraicArrayString", &libcellml::GeneratorProfile::algebraicArrayString) + .function("setAlgebraicArrayString", &libcellml::GeneratorProfile::setAlgebraicArrayString) + .function("externalArrayString", &libcellml::GeneratorProfile::externalArrayString) + .function("setExternalArrayString", &libcellml::GeneratorProfile::setExternalArrayString) .function("externalVariableMethodTypeDefinitionString", &libcellml::GeneratorProfile::externalVariableMethodTypeDefinitionString) .function("setExternalVariableMethodTypeDefinitionString", &libcellml::GeneratorProfile::setExternalVariableMethodTypeDefinitionString) .function("externalVariableMethodCallString", &libcellml::GeneratorProfile::externalVariableMethodCallString) @@ -317,10 +333,22 @@ EMSCRIPTEN_BINDINGS(libcellml_generatorprofile) .function("setInterfaceCreateStatesArrayMethodString", &libcellml::GeneratorProfile::setInterfaceCreateStatesArrayMethodString) .function("implementationCreateStatesArrayMethodString", &libcellml::GeneratorProfile::implementationCreateStatesArrayMethodString) .function("setImplementationCreateStatesArrayMethodString", &libcellml::GeneratorProfile::setImplementationCreateStatesArrayMethodString) - .function("interfaceCreateVariablesArrayMethodString", &libcellml::GeneratorProfile::interfaceCreateVariablesArrayMethodString) - .function("setInterfaceCreateVariablesArrayMethodString", &libcellml::GeneratorProfile::setInterfaceCreateVariablesArrayMethodString) - .function("implementationCreateVariablesArrayMethodString", &libcellml::GeneratorProfile::implementationCreateVariablesArrayMethodString) - .function("setImplementationCreateVariablesArrayMethodString", &libcellml::GeneratorProfile::setImplementationCreateVariablesArrayMethodString) + .function("interfaceCreateConstantsArrayMethodString", &libcellml::GeneratorProfile::interfaceCreateConstantsArrayMethodString) + .function("setInterfaceCreateConstantsArrayMethodString", &libcellml::GeneratorProfile::setInterfaceCreateConstantsArrayMethodString) + .function("implementationCreateConstantsArrayMethodString", &libcellml::GeneratorProfile::implementationCreateConstantsArrayMethodString) + .function("setImplementationCreateConstantsArrayMethodString", &libcellml::GeneratorProfile::setImplementationCreateConstantsArrayMethodString) + .function("interfaceCreateComputedConstantsArrayMethodString", &libcellml::GeneratorProfile::interfaceCreateComputedConstantsArrayMethodString) + .function("setInterfaceCreateComputedConstantsArrayMethodString", &libcellml::GeneratorProfile::setInterfaceCreateComputedConstantsArrayMethodString) + .function("implementationCreateComputedConstantsArrayMethodString", &libcellml::GeneratorProfile::implementationCreateComputedConstantsArrayMethodString) + .function("setImplementationCreateComputedConstantsArrayMethodString", &libcellml::GeneratorProfile::setImplementationCreateComputedConstantsArrayMethodString) + .function("interfaceCreateAlgebraicArrayMethodString", &libcellml::GeneratorProfile::interfaceCreateAlgebraicArrayMethodString) + .function("setInterfaceCreateAlgebraicArrayMethodString", &libcellml::GeneratorProfile::setInterfaceCreateAlgebraicArrayMethodString) + .function("implementationCreateAlgebraicArrayMethodString", &libcellml::GeneratorProfile::implementationCreateAlgebraicArrayMethodString) + .function("setImplementationCreateAlgebraicArrayMethodString", &libcellml::GeneratorProfile::setImplementationCreateAlgebraicArrayMethodString) + .function("interfaceCreateExternalsArrayMethodString", &libcellml::GeneratorProfile::interfaceCreateExternalsArrayMethodString) + .function("setInterfaceCreateExternalsArrayMethodString", &libcellml::GeneratorProfile::setInterfaceCreateExternalsArrayMethodString) + .function("implementationCreateExternalsArrayMethodString", &libcellml::GeneratorProfile::implementationCreateExternalsArrayMethodString) + .function("setImplementationCreateExternalsArrayMethodString", &libcellml::GeneratorProfile::setImplementationCreateExternalsArrayMethodString) .function("interfaceDeleteArrayMethodString", &libcellml::GeneratorProfile::interfaceDeleteArrayMethodString) .function("setInterfaceDeleteArrayMethodString", &libcellml::GeneratorProfile::setInterfaceDeleteArrayMethodString) .function("implementationDeleteArrayMethodString", &libcellml::GeneratorProfile::implementationDeleteArrayMethodString) diff --git a/src/bindings/javascript/interpreter.cpp b/src/bindings/javascript/interpreter.cpp new file mode 100644 index 0000000000..1279ac32af --- /dev/null +++ b/src/bindings/javascript/interpreter.cpp @@ -0,0 +1,39 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include + +#include "libcellml/interpreter.h" + +using namespace emscripten; + +EMSCRIPTEN_BINDINGS(libcellml_interpreter) +{ + class_("Interpreter") + .smart_ptr_constructor("Interpreter", &libcellml::Interpreter::create) + .function("model", &libcellml::Interpreter::model) + .function("setModel", &libcellml::Interpreter::setModel) + .function("initialiseVariablesForAlgebraicModel", select_overload(&libcellml::Interpreter::initialiseVariables)) + .function("initialiseVariablesForDifferentialModel", select_overload(&libcellml::Interpreter::initialiseVariables)) + .function("computeComputedConstants", &libcellml::Interpreter::computeComputedConstants) + .function("computeRates", select_overload(&libcellml::Interpreter::computeRates)) + .function("computeRatesWithExternalVariables", select_overload(&libcellml::Interpreter::computeRates)) + .function("computeVariablesForAlgebraicModel", select_overload(&libcellml::Interpreter::computeVariables)) + .function("computeVariablesForAlgebraicModelWithExternalVariables", select_overload(&libcellml::Interpreter::computeVariables)) + .function("computeVariablesForDifferentialModel", select_overload(&libcellml::Interpreter::computeVariables)) + .function("computeVariablesForDifferentialModelWithExternalVariables", select_overload(&libcellml::Interpreter::computeVariables)) + ; +} diff --git a/src/bindings/javascript/types.cpp b/src/bindings/javascript/types.cpp index 647501563a..ad746d3360 100644 --- a/src/bindings/javascript/types.cpp +++ b/src/bindings/javascript/types.cpp @@ -22,6 +22,7 @@ using namespace emscripten; EMSCRIPTEN_BINDINGS(libcellml_types) { + register_vector("VectorDouble"); register_vector("VectorString"); register_vector("VectorAnyCellmlElementPtr"); register_vector("VectorVariablePtr"); diff --git a/src/bindings/python/CMakeLists.txt b/src/bindings/python/CMakeLists.txt index c98abd754f..81ea726840 100644 --- a/src/bindings/python/CMakeLists.txt +++ b/src/bindings/python/CMakeLists.txt @@ -31,6 +31,8 @@ set(SWIG_INTERFACE_SRCS ../interface/importer.i ../interface/importsource.i ../interface/importedentity.i + #---GRY--- TO BE UNCOMMENTED ONCE WE HAVE FIGURED OUT HOW TO PASS double *. + # ../interface/interpreter.i ../interface/issue.i ../interface/logger.i ../interface/model.i diff --git a/src/bindings/python/__init__.py b/src/bindings/python/__init__.py index d2ca733cfb..fc41f9f8ce 100644 --- a/src/bindings/python/__init__.py +++ b/src/bindings/python/__init__.py @@ -22,6 +22,7 @@ from libcellml.generatorprofile import GeneratorProfile from libcellml.importer import Importer from libcellml.importsource import ImportSource +from libcellml.interpreter import Interpreter from libcellml.issue import Issue from libcellml.model import Model from libcellml.parser import Parser diff --git a/src/commonutils.cpp b/src/commonutils.cpp index 412691ff77..e5581e9915 100644 --- a/src/commonutils.cpp +++ b/src/commonutils.cpp @@ -16,6 +16,9 @@ limitations under the License. #include "commonutils.h" +#include +#include + #include "libcellml/component.h" #include "libcellml/model.h" @@ -40,6 +43,54 @@ libcellml::ComponentPtr owningComponent(const libcellml::ParentedEntityConstPtr return std::dynamic_pointer_cast(entity->parent()); } +uint64_t ulpsDistance(double a, double b) +{ + static const auto max = std::numeric_limits::max(); + + // Max distance for NaN. + if (std::isnan(a) || std::isnan(b)) { + return max; + } + + // If one's infinite and they're not equal, max distance. + if (std::isinf(a) != std::isinf(b)) { + return max; + } + + static const int SIZE_OF_DOUBLE = sizeof(double); + + uint64_t ia; + uint64_t ib; + memcpy(&ia, &a, SIZE_OF_DOUBLE); + memcpy(&ib, &b, SIZE_OF_DOUBLE); + + // Return the absolute value of the distance in ULPs. + uint64_t distance = max; + if (ia < ib) { + distance = ib + ~ia + 1; + } else { + distance = ia + ~ib + 1; + } + return distance; +} + +bool areNearlyEqual(double a, double b) +{ + static const double fixedEpsilon = std::numeric_limits::epsilon(); + static const ptrdiff_t ulpsEpsilon = 1; + + if (fabs(a - b) <= fixedEpsilon) { + return true; + } + + // If they are not the same sign then return false. + if ((a < 0.0) != (b < 0.0)) { + return false; + } + + return ulpsDistance(a, b) <= ulpsEpsilon; +} + #ifndef TEST_UTILS } // namespace libcellml #endif diff --git a/src/commonutils.h b/src/commonutils.h index dc5ad20c00..66fff07a08 100644 --- a/src/commonutils.h +++ b/src/commonutils.h @@ -45,6 +45,23 @@ libcellml::ModelPtr TEST_EXPORT owningModel(const libcellml::ParentedEntityConst */ libcellml::ComponentPtr TEST_EXPORT owningComponent(const libcellml::ParentedEntityConstPtr &entity); +/** + * @brief Decide if two doubles are nearly equal. + * + * Test two doubles to determine if they are close enough + * to be considered equal. + * + * Uses a modified form of comparing floats: + * + * https://bitbashing.io/comparing-floats.html + * + * @param a A @c double to test. + * @param b A @c double to test. + * + * @return @c true if the given doubles are considered close, @c false otherwise. + */ +bool TEST_EXPORT areNearlyEqual(double a, double b); + #ifndef TEST_UTILS } // namespace libcellml diff --git a/src/component.cpp b/src/component.cpp index 207d731e6a..43be7989b9 100644 --- a/src/component.cpp +++ b/src/component.cpp @@ -27,7 +27,6 @@ limitations under the License. #include "libcellml/reset.h" #include "libcellml/variable.h" -#include "commonutils.h" #include "component_p.h" #include "reset_p.h" #include "utilities.h" diff --git a/src/debug.cpp b/src/debug.cpp index b78d788535..cae27b3f65 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -23,12 +23,16 @@ limitations under the License. #include "libcellml/component.h" #include "libcellml/generator.h" #include "libcellml/generatorprofile.h" +#include "libcellml/interpreter.h" #include "libcellml/model.h" #include "libcellml/variable.h" +#include "generatorinterpreter_p.h" +#include "utilities.h" + #include "libcellml/undefines.h" -#include "commonutils.h" +#include "interpreterstatement_debug.cpp" namespace libcellml { @@ -78,21 +82,52 @@ void printAnalyserModelEquations(const AnalyserModelPtr &model) Debug() << "\n---------------------------------------[API equation #" << ++eqnNb << "]"; if (eqn->ast() != nullptr) { - Debug() << "\n" << astAsCode(eqn->ast()); + Debug() << "\n" + << astAsCode(eqn->ast()); } else { Debug() << "\nNo equation"; } Debug() << "\nType: " << AnalyserEquation::typeAsString(eqn->type()); - if (eqn->variableCount() != 0) { - Debug() << "\nVariables:"; + if (eqn->stateCount() != 0) { + Debug() << "\nStates:"; - for (const auto &var : eqn->variables()) { + for (const auto &var : eqn->states()) { Debug() << " - " << var->variable()->name(); } } else { - Debug() << "\nNo variables"; + Debug() << "\nNo states"; + } + + if (eqn->computedConstantCount() != 0) { + Debug() << "\nComputed constants:"; + + for (const auto &var : eqn->computedConstants()) { + Debug() << " - " << var->variable()->name(); + } + } else { + Debug() << "\nNo computed constants"; + } + + if (eqn->algebraicCount() != 0) { + Debug() << "\nAlgebraic variables:"; + + for (const auto &var : eqn->algebraic()) { + Debug() << " - " << var->variable()->name(); + } + } else { + Debug() << "\nNo algebraic variables"; + } + + if (eqn->externalCount() != 0) { + Debug() << "\nExternal variables:"; + + for (const auto &var : eqn->externals()) { + Debug() << " - " << var->variable()->name(); + } + } else { + Debug() << "\nNo external variables"; } if (eqn->dependencyCount() != 0) { @@ -102,7 +137,7 @@ void printAnalyserModelEquations(const AnalyserModelPtr &model) if (dep->ast() != nullptr) { Debug() << " - " << astAsCode(dep->ast()); } else if (dep->type() == AnalyserEquation::Type::EXTERNAL) { - Debug() << " - External equation for '" << dep->variable(0)->variable()->name() << "'"; + Debug() << " - External equation for '" << dep->external(0)->variable()->name() << "'"; } else { Debug() << " - ??? [" << AnalyserEquation::typeAsString(dep->type()) << "]"; } @@ -119,7 +154,7 @@ void printAnalyserModelEquations(const AnalyserModelPtr &model) if (nlaSibling->ast() != nullptr) { Debug() << " - " << astAsCode(nlaSibling->ast()); } else if (nlaSibling->type() == AnalyserEquation::Type::EXTERNAL) { - Debug() << " - External equation for '" << nlaSibling->variable(0)->variable()->name() << "'"; + Debug() << " - External equation for '" << nlaSibling->external(0)->variable()->name() << "'"; } else { Debug() << " - ??? [" << AnalyserEquation::typeAsString(nlaSibling->type()) << "]"; } @@ -137,8 +172,8 @@ void printAnalyserModelVariables(const AnalyserModelPtr &model) { size_t varNb = 0; - for (const auto &var : model->variables()) { - Debug() << "\n---------------------------------------[API variable " << ++varNb << "]"; + for (const auto &var : variables(model)) { + Debug() << "\n---------------------------------------[API variable #" << ++varNb << "]"; Debug() << "\nName: " << var->variable()->name(); Debug() << "Type: " << AnalyserVariable::typeAsString(var->type()); @@ -149,7 +184,7 @@ void printAnalyserModelVariables(const AnalyserModelPtr &model) if (eqn->ast() != nullptr) { Debug() << " - " << astAsCode(eqn->ast()); } else if (eqn->type() == AnalyserEquation::Type::EXTERNAL) { - Debug() << " - External equation for '" << eqn->variable(0)->variable()->name() << "'"; + Debug() << " - External equation for '" << eqn->external(0)->variable()->name() << "'"; } else { Debug() << " - ??? [" << AnalyserEquation::typeAsString(eqn->type()) << "]"; } @@ -165,7 +200,6 @@ void printHistory(const History &history) for (const auto &h : history) { printHistoryEpoch(h); } - } void printHistoryEpoch(const HistoryEpochPtr &historyEpoch) @@ -205,7 +239,8 @@ void printEquivalenceMap(const EquivalenceMap &map) void printEquivalenceMapWithModelInfo(const EquivalenceMap &map, const ModelPtr &model) { for (const auto &iter : map) { - auto key = iter.first; Debug(false) << "key: "; + auto key = iter.first; + Debug(false) << "key: "; printStackWithModelInfo(key, model); auto vector = iter.second; for (const auto &vectorIt : vector) { @@ -308,7 +343,29 @@ std::string doPrintAstAsTree(AnalyserEquationAstTrunk *trunk) return res + trunk->mStr; } -std::string doPrintAstAsTree(const AnalyserEquationAstPtr &ast) +std::string ciValue(const AnalyserVariablePtr &analyserVariable, bool rate) +{ + std::string res = (analyserVariable->type() == AnalyserVariable::Type::STATE) ? + (rate ? + "rates" : + "states") : + ((analyserVariable->type() == AnalyserVariable::Type::CONSTANT) ? + "constants" : + ((analyserVariable->type() == AnalyserVariable::Type::COMPUTED_CONSTANT) ? + "computedConstants" : + ((analyserVariable->type() == AnalyserVariable::Type::ALGEBRAIC) ? + "algebraic" : + "externals"))); + auto variable = analyserVariable->variable(); + + res += "[" + std::to_string(analyserVariable->index()) + "] | " + + owningComponent(variable)->name() + " | " + + variable->name() + std::string(rate ? "'" : ""); + + return res; +} + +std::string doPrintAstAsTree(const AnalyserModelPtr &model, const AnalyserEquationAstPtr &ast) { std::string res; @@ -549,15 +606,11 @@ std::string doPrintAstAsTree(const AnalyserEquationAstPtr &ast) // Token elements. - case AnalyserEquationAst::Type::CI: { - auto astVariable = ast->variable(); - - if (astVariable != nullptr) { - res = astVariable->name(); - } + case AnalyserEquationAst::Type::CI: + res = ciValue(libcellml::analyserVariable(model, ast->variable()), + ast->parent()->type() == AnalyserEquationAst::Type::DIFF); break; - } case AnalyserEquationAst::Type::CN: res = ast->value(); @@ -609,7 +662,7 @@ std::string doPrintAstAsTree(const AnalyserEquationAstPtr &ast) return res; } -std::string doPrintAstAsTree(const AnalyserEquationAstPtr &ast, +std::string doPrintAstAsTree(const AnalyserModelPtr &model, const AnalyserEquationAstPtr &ast, AnalyserEquationAstTrunk *prevTrunk, bool isLeft) { if (ast == nullptr) { @@ -622,7 +675,7 @@ std::string doPrintAstAsTree(const AnalyserEquationAstPtr &ast, auto astLeftChild = ast->leftChild(); if (astLeftChild != nullptr) { - res += doPrintAstAsTree(astLeftChild, &trunk, true); + res += doPrintAstAsTree(model, astLeftChild, &trunk, true); } if (prevTrunk == nullptr) { @@ -635,7 +688,15 @@ std::string doPrintAstAsTree(const AnalyserEquationAstPtr &ast, prevTrunk->mStr = prevStr; } - res += doPrintAstAsTree(&trunk) + doPrintAstAsTree(ast) + "\n"; + auto astRightChild = ast->rightChild(); + + res += doPrintAstAsTree(&trunk); + + if (astLeftChild != nullptr) { + res += (astRightChild != nullptr) ? "┤" : "┘"; + } + + res += " " + doPrintAstAsTree(model, ast) + "\n"; if (prevTrunk != nullptr) { prevTrunk->mStr = prevStr; @@ -643,18 +704,16 @@ std::string doPrintAstAsTree(const AnalyserEquationAstPtr &ast, trunk.mStr = TRUNK; - auto astRightChild = ast->rightChild(); - if (astRightChild != nullptr) { - res += doPrintAstAsTree(astRightChild, &trunk, false); + res += doPrintAstAsTree(model, astRightChild, &trunk, false); } return res; } -void printAstAsTree(const AnalyserEquationAstPtr &ast) +void printAstAsTree(const AnalyserModelPtr &model, const AnalyserEquationAstPtr &ast) { - Debug() << doPrintAstAsTree(ast, nullptr, false); + Debug() << doPrintAstAsTree(model, ast, nullptr, false); } void printAstAsCode(const AnalyserEquationAstPtr &ast) @@ -662,6 +721,398 @@ void printAstAsCode(const AnalyserEquationAstPtr &ast) Debug() << astAsCode(ast); } +struct InterpreterStatementTrunk +{ + InterpreterStatementTrunk *mPrev; + std::string mStr; + + InterpreterStatementTrunk(InterpreterStatementTrunk *prev, + const std::string &str); +}; + +InterpreterStatementTrunk::InterpreterStatementTrunk(InterpreterStatementTrunk *prev, + const std::string &str) + : mPrev(prev) + , mStr(str) +{ +} + +std::string doPrintInterpreterStatement(InterpreterStatementTrunk *trunk) +{ + if (trunk == nullptr) { + return {}; + } + + auto res = doPrintInterpreterStatement(trunk->mPrev); + + if ((trunk->mPrev != nullptr) && (trunk->mPrev->mStr == SPACES) + && ((trunk->mStr == SPACES) || (trunk->mStr == TRUNK))) { + res += " "; + } + + return res + trunk->mStr; +} + +std::string doPrintInterpreterStatement(const InterpreterStatementPtr &interpreterStatement) +{ + std::string res; + + switch (interpreterStatement->type()) { + // Equality. + + case InterpreterStatement::Type::EQUALITY: + res = "EQUALITY"; + + break; + + // Relational and logical operators. + + case InterpreterStatement::Type::EQ: + res = "EQ"; + + break; + case InterpreterStatement::Type::NEQ: + res = "NEQ"; + + break; + case InterpreterStatement::Type::LT: + res = "LT"; + + break; + case InterpreterStatement::Type::LEQ: + res = "LEQ"; + + break; + case InterpreterStatement::Type::GT: + res = "GT"; + + break; + case InterpreterStatement::Type::GEQ: + res = "LEQ"; + + break; + case InterpreterStatement::Type::AND: + res = "AND"; + + break; + case InterpreterStatement::Type::OR: + res = "OR"; + + break; + case InterpreterStatement::Type::XOR: + res = "XOR"; + + break; + case InterpreterStatement::Type::NOT: + res = "NOT"; + + break; + + // Arithmetic operators. + + case InterpreterStatement::Type::PLUS: + res = "PLUS"; + + break; + case InterpreterStatement::Type::MINUS: + res = "MINUS"; + + break; + case InterpreterStatement::Type::TIMES: + res = "TIMES"; + + break; + case InterpreterStatement::Type::DIVIDE: + res = "DIVIDE"; + + break; + case InterpreterStatement::Type::POWER: + res = "POWER"; + + break; + case InterpreterStatement::Type::SQUARE_ROOT: + res = "SQUARE_ROOT"; + + break; + case InterpreterStatement::Type::SQUARE: + res = "SQUARE"; + + break; + case InterpreterStatement::Type::ABS: + res = "ABS"; + + break; + case InterpreterStatement::Type::EXP: + res = "EXP"; + + break; + case InterpreterStatement::Type::LN: + res = "LN"; + + break; + case InterpreterStatement::Type::LOG: + res = "LOG"; + + break; + case InterpreterStatement::Type::CEILING: + res = "CEILING"; + + break; + case InterpreterStatement::Type::FLOOR: + res = "FLOOR"; + + break; + case InterpreterStatement::Type::MIN: + res = "MIN"; + + break; + case InterpreterStatement::Type::MAX: + res = "MAX"; + + break; + case InterpreterStatement::Type::REM: + res = "REM"; + + break; + + // Trigonometric operators. + + case InterpreterStatement::Type::SIN: + res = "SIN"; + + break; + case InterpreterStatement::Type::COS: + res = "COS"; + + break; + case InterpreterStatement::Type::TAN: + res = "TAN"; + + break; + case InterpreterStatement::Type::SEC: + res = "SEC"; + + break; + case InterpreterStatement::Type::CSC: + res = "CSC"; + + break; + case InterpreterStatement::Type::COT: + res = "COT"; + + break; + case InterpreterStatement::Type::SINH: + res = "SINH"; + + break; + case InterpreterStatement::Type::COSH: + res = "COSH"; + + break; + case InterpreterStatement::Type::TANH: + res = "TANH"; + + break; + case InterpreterStatement::Type::SECH: + res = "SECH"; + + break; + case InterpreterStatement::Type::CSCH: + res = "CSCH"; + + break; + case InterpreterStatement::Type::COTH: + res = "COTH"; + + break; + case InterpreterStatement::Type::ASIN: + res = "ASIN"; + + break; + case InterpreterStatement::Type::ACOS: + res = "ACOS"; + + break; + case InterpreterStatement::Type::ATAN: + res = "ATAN"; + + break; + case InterpreterStatement::Type::ASEC: + res = "ASEC"; + + break; + case InterpreterStatement::Type::ACSC: + res = "ACSC"; + + break; + case InterpreterStatement::Type::ACOT: + res = "ACOT"; + + break; + case InterpreterStatement::Type::ASINH: + res = "ASINH"; + + break; + case InterpreterStatement::Type::ACOSH: + res = "ACOSH"; + + break; + case InterpreterStatement::Type::ATANH: + res = "ATANH"; + + break; + case InterpreterStatement::Type::ASECH: + res = "ASECH"; + + break; + case InterpreterStatement::Type::ACSCH: + res = "ACSCH"; + + break; + case InterpreterStatement::Type::ACOTH: + res = "ACOTH"; + + break; + + // Piecewise statement. + + case InterpreterStatement::Type::PIECEWISE: + res = "PIECEWISE"; + + break; + case InterpreterStatement::Type::PIECE: + res = "PIECE"; + + break; + + // Token elements. + + case InterpreterStatement::Type::VOI: + res = "VOI"; + + break; + case InterpreterStatement::Type::STATE: + case InterpreterStatement::Type::RATE: + case InterpreterStatement::Type::CONSTANT: + case InterpreterStatement::Type::COMPUTED_CONSTANT: + case InterpreterStatement::Type::ALGEBRAIC: + case InterpreterStatement::Type::EXTERNAL: + res = ciValue(interpreterStatement->variable(), + interpreterStatement->type() == InterpreterStatement::Type::RATE); + + break; + case InterpreterStatement::Type::NUMBER: + res = convertToString(interpreterStatement->value()); + + break; + + // Qualifier elements. + + case InterpreterStatement::Type::DEGREE: + res = "DEGREE"; + + break; + case InterpreterStatement::Type::LOGBASE: + res = "LOGBASE"; + + break; + case InterpreterStatement::Type::BVAR: + res = "BVAR"; + + break; + + // Constants. + + case InterpreterStatement::Type::TRUE: + res = "TRUE"; + + break; + case InterpreterStatement::Type::FALSE: + res = "FALSE"; + + break; + case InterpreterStatement::Type::E: + res = "E"; + + break; + case InterpreterStatement::Type::PI: + res = "PI"; + + break; + case InterpreterStatement::Type::INF: + res = "INF"; + + break; + case InterpreterStatement::Type::NAN: + res = "NAN"; + + break; + + // Miscellaneous. + + case InterpreterStatement::Type::EXTERNAL_VARIABLE_CALL: + res = "externalVariable(" + convertToString(interpreterStatement->index()) + ")"; + + break; + } + + return res; +} + +std::string doPrintInterpreterStatement(const InterpreterStatementPtr &interpreterStatement, + InterpreterStatementTrunk *prevTrunk, bool isLeft) +{ + if (interpreterStatement == nullptr) { + return {}; + } + + std::string res; + std::string prevStr = SPACES; + InterpreterStatementTrunk trunk(prevTrunk, prevStr); + auto astLeftChild = interpreterStatement->leftChild(); + + if (astLeftChild != nullptr) { + res += doPrintInterpreterStatement(astLeftChild, &trunk, true); + } + + if (prevTrunk == nullptr) { + trunk.mStr = "──"; + } else if (isLeft) { + trunk.mStr = "╭──"; + prevStr = TRUNK; + } else { + trunk.mStr = "╰──"; + prevTrunk->mStr = prevStr; + } + + auto astRightChild = interpreterStatement->rightChild(); + + res += doPrintInterpreterStatement(&trunk); + + if (astLeftChild != nullptr) { + res += (astRightChild != nullptr) ? "┤" : "┘"; + } + + res += " " + doPrintInterpreterStatement(interpreterStatement) + "\n"; + + if (prevTrunk != nullptr) { + prevTrunk->mStr = prevStr; + } + + trunk.mStr = TRUNK; + + if (astRightChild != nullptr) { + res += doPrintInterpreterStatement(astRightChild, &trunk, false); + } + + return res; +} + +void printInterpreterStatement(const InterpreterStatementPtr &interpreterStatement) +{ + Debug() << doPrintInterpreterStatement(interpreterStatement, nullptr, false); +} + void printImportLibrary(const ImportLibrary &importlibrary) { Debug() << " == Import library =="; diff --git a/src/debug.h b/src/debug.h index 0c6f861ad4..b14e5d8e2a 100644 --- a/src/debug.h +++ b/src/debug.h @@ -21,6 +21,10 @@ limitations under the License. #include "internaltypes.h" +#define DEBUG +#include "interpreterstatement.h" +#undef DEBUG + namespace libcellml { /** @@ -95,8 +99,9 @@ struct Debug void printAnalyserModelEquations(const AnalyserModelPtr &model); void printAnalyserModelVariables(const AnalyserModelPtr &model); -void printAstAsTree(const AnalyserEquationAstPtr &ast); +void printAstAsTree(const AnalyserModelPtr &model, const AnalyserEquationAstPtr &ast); void printAstAsCode(const AnalyserEquationAstPtr &ast); +void printInterpreterStatement(const InterpreterStatementPtr &interpreterStatement); void printComponentMap(const ComponentMap &map); void printConnectionMap(const ConnectionMap &map); void printEquivalenceMap(const EquivalenceMap &map); diff --git a/src/generator.cpp b/src/generator.cpp index a018a63449..b7ff781cc2 100644 --- a/src/generator.cpp +++ b/src/generator.cpp @@ -17,23 +17,14 @@ limitations under the License. #include "libcellml/generator.h" #include -#include -#include "libcellml/analyserequation.h" -#include "libcellml/analyserequationast.h" -#include "libcellml/analysermodel.h" #include "libcellml/analyservariable.h" -#include "libcellml/component.h" -#include "libcellml/units.h" #include "libcellml/version.h" -#include "commonutils.h" #include "generator_p.h" +#include "generatorinterpreter_p.h" #include "generatorprofilesha1values.h" #include "generatorprofiletools.h" -#include "utilities.h" - -#include "libcellml/undefines.h" namespace libcellml { @@ -42,184 +33,6 @@ void Generator::GeneratorImpl::reset() mCode = {}; } -bool Generator::GeneratorImpl::modelHasOdes() const -{ - switch (mModel->type()) { - case AnalyserModel::Type::ODE: - case AnalyserModel::Type::DAE: - return true; - default: - return false; - } -} - -bool Generator::GeneratorImpl::modelHasNlas() const -{ - switch (mModel->type()) { - case AnalyserModel::Type::NLA: - case AnalyserModel::Type::DAE: - return true; - default: - return false; - } -} - -AnalyserVariablePtr Generator::GeneratorImpl::analyserVariable(const VariablePtr &variable) const -{ - // Find and return the analyser variable associated with the given variable. - - AnalyserVariablePtr res; - auto modelVoi = mModel->voi(); - VariablePtr modelVoiVariable = (modelVoi != nullptr) ? modelVoi->variable() : nullptr; - - if ((modelVoiVariable != nullptr) - && mModel->areEquivalentVariables(variable, modelVoiVariable)) { - res = modelVoi; - } else { - for (const auto &modelState : mModel->states()) { - if (mModel->areEquivalentVariables(variable, modelState->variable())) { - res = modelState; - - break; - } - } - - if (res == nullptr) { - // Normally, we would have: - // - // for (const auto &modelVariable : mModel->variables()) { - // if (mModel->areEquivalentVariables(variable, modelVariable->variable())) { - // res = modelVariable; - // - // break; - // } - // } - // - // but we always have variables, so llvm-cov will complain that the - // false branch of our for loop is never reached. The below code is - // a bit more verbose but at least it makes llvm-cov happy. - - auto modelVariables = mModel->variables(); - auto modelVariable = modelVariables.begin(); - - do { - if (mModel->areEquivalentVariables(variable, (*modelVariable)->variable())) { - res = *modelVariable; - } else { - ++modelVariable; - } - } while (res == nullptr); - } - } - - return res; -} - -double Generator::GeneratorImpl::scalingFactor(const VariablePtr &variable) const -{ - // Return the scaling factor for the given variable. - - return Units::scalingFactor(variable->units(), analyserVariable(variable)->variable()->units()); -} - -bool Generator::GeneratorImpl::isNegativeNumber(const AnalyserEquationAstPtr &ast) const -{ - if (ast->type() == AnalyserEquationAst::Type::CN) { - double doubleValue; - - convertToDouble(ast->value(), doubleValue); - - return doubleValue < 0.0; - } - - return false; -} - -bool Generator::GeneratorImpl::isRelationalOperator(const AnalyserEquationAstPtr &ast) const -{ - switch (ast->type()) { - case AnalyserEquationAst::Type::EQ: - return mProfile->hasEqOperator(); - case AnalyserEquationAst::Type::NEQ: - return mProfile->hasNeqOperator(); - case AnalyserEquationAst::Type::LT: - return mProfile->hasLtOperator(); - case AnalyserEquationAst::Type::LEQ: - return mProfile->hasLeqOperator(); - case AnalyserEquationAst::Type::GT: - return mProfile->hasGtOperator(); - case AnalyserEquationAst::Type::GEQ: - return mProfile->hasGeqOperator(); - default: - return false; - } -} - -bool Generator::GeneratorImpl::isAndOperator(const AnalyserEquationAstPtr &ast) const -{ - return (ast->type() == AnalyserEquationAst::Type::AND) - && mProfile->hasAndOperator(); -} - -bool Generator::GeneratorImpl::isOrOperator(const AnalyserEquationAstPtr &ast) const -{ - return (ast->type() == AnalyserEquationAst::Type::OR) - && mProfile->hasOrOperator(); -} - -bool Generator::GeneratorImpl::isXorOperator(const AnalyserEquationAstPtr &ast) const -{ - return (ast->type() == AnalyserEquationAst::Type::XOR) - && mProfile->hasXorOperator(); -} - -bool Generator::GeneratorImpl::isLogicalOperator(const AnalyserEquationAstPtr &ast) const -{ - // Note: AnalyserEquationAst::Type::NOT is a unary logical operator, hence - // we don't include it here since this method is only used to - // determine whether parentheses should be added around some code. - - return isAndOperator(ast) || isOrOperator(ast) || isXorOperator(ast); -} - -bool Generator::GeneratorImpl::isPlusOperator(const AnalyserEquationAstPtr &ast) const -{ - return ast->type() == AnalyserEquationAst::Type::PLUS; -} - -bool Generator::GeneratorImpl::isMinusOperator(const AnalyserEquationAstPtr &ast) const -{ - return ast->type() == AnalyserEquationAst::Type::MINUS; -} - -bool Generator::GeneratorImpl::isTimesOperator(const AnalyserEquationAstPtr &ast) const -{ - return ast->type() == AnalyserEquationAst::Type::TIMES; -} - -bool Generator::GeneratorImpl::isDivideOperator(const AnalyserEquationAstPtr &ast) const -{ - return ast->type() == AnalyserEquationAst::Type::DIVIDE; -} - -bool Generator::GeneratorImpl::isPowerOperator(const AnalyserEquationAstPtr &ast) const -{ - return (ast->type() == AnalyserEquationAst::Type::POWER) - && mProfile->hasPowerOperator(); -} - -bool Generator::GeneratorImpl::isRootOperator(const AnalyserEquationAstPtr &ast) const -{ - return (ast->type() == AnalyserEquationAst::Type::ROOT) - && mProfile->hasPowerOperator(); -} - -bool Generator::GeneratorImpl::isPiecewiseStatement(const AnalyserEquationAstPtr &ast) const -{ - return (ast->type() == AnalyserEquationAst::Type::PIECEWISE) - && mProfile->hasConditionalOperator(); -} - void Generator::GeneratorImpl::updateVariableInfoSizes(size_t &componentSize, size_t &nameSize, size_t &unitsSize, @@ -245,11 +58,6 @@ bool Generator::GeneratorImpl::modifiedProfile() const sha1(profileContents) != PYTHON_GENERATOR_PROFILE_SHA1; } -std::string Generator::GeneratorImpl::newLineIfNeeded() -{ - return mCode.empty() ? "" : "\n"; -} - void Generator::GeneratorImpl::addOriginCommentCode() { if (!mProfile->commentString().empty() @@ -263,15 +71,16 @@ void Generator::GeneratorImpl::addOriginCommentCode() "Python"; profileInformation += " profile of"; - mCode += replace(mProfile->commentString(), - "[CODE]", replace(replace(mProfile->originCommentString(), "[PROFILE_INFORMATION]", profileInformation), "[LIBCELLML_VERSION]", versionString())); + mCode += newLineIfNeeded(mCode) + + replace(mProfile->commentString(), + "[CODE]", replace(replace(mProfile->originCommentString(), "[PROFILE_INFORMATION]", profileInformation), "[LIBCELLML_VERSION]", versionString())); } } void Generator::GeneratorImpl::addInterfaceHeaderCode() { if (!mProfile->interfaceHeaderString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->interfaceHeaderString(); } } @@ -285,7 +94,7 @@ void Generator::GeneratorImpl::addImplementationHeaderCode() if (!mProfile->implementationHeaderString().empty() && ((hasInterfaceFileName && !mProfile->interfaceFileNameString().empty()) || !hasInterfaceFileName)) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + replace(mProfile->implementationHeaderString(), "[INTERFACE_FILE_NAME]", mProfile->interfaceFileNameString()); } @@ -293,74 +102,86 @@ void Generator::GeneratorImpl::addImplementationHeaderCode() void Generator::GeneratorImpl::addVersionAndLibcellmlVersionCode(bool interface) { - std::string versionAndLibcellmlCode; + std::string code; if ((interface && !mProfile->interfaceVersionString().empty()) || (!interface && !mProfile->implementationVersionString().empty())) { if (interface) { - versionAndLibcellmlCode += mProfile->interfaceVersionString(); + code += mProfile->interfaceVersionString(); } else { if (modifiedProfile()) { static const std::regex regEx("([0-9]+\\.[0-9]+\\.[0-9]+)"); - versionAndLibcellmlCode += std::regex_replace(mProfile->implementationVersionString(), regEx, "$1.post0"); + code += std::regex_replace(mProfile->implementationVersionString(), regEx, "$1.post0"); } else { - versionAndLibcellmlCode += mProfile->implementationVersionString(); + code += mProfile->implementationVersionString(); } } } if ((interface && !mProfile->interfaceLibcellmlVersionString().empty()) || (!interface && !mProfile->implementationLibcellmlVersionString().empty())) { - versionAndLibcellmlCode += interface ? - mProfile->interfaceLibcellmlVersionString() : - replace(mProfile->implementationLibcellmlVersionString(), - "[LIBCELLML_VERSION]", versionString()); + code += interface ? + mProfile->interfaceLibcellmlVersionString() : + replace(mProfile->implementationLibcellmlVersionString(), + "[LIBCELLML_VERSION]", versionString()); } - if (!versionAndLibcellmlCode.empty()) { - mCode += "\n"; + if (!code.empty()) { + mCode += newLineIfNeeded(mCode) + + code; } - - mCode += versionAndLibcellmlCode; } void Generator::GeneratorImpl::addStateAndVariableCountCode(bool interface) { - std::string stateAndVariableCountCode; + std::string code; - if (modelHasOdes() + if (mModelHasOdes && ((interface && !mProfile->interfaceStateCountString().empty()) || (!interface && !mProfile->implementationStateCountString().empty()))) { - stateAndVariableCountCode += interface ? - mProfile->interfaceStateCountString() : - replace(mProfile->implementationStateCountString(), - "[STATE_COUNT]", std::to_string(mModel->stateCount())); + code += interface ? + mProfile->interfaceStateCountString() : + replace(mProfile->implementationStateCountString(), + "[STATE_COUNT]", std::to_string(mModel->stateCount())); } - if ((interface && !mProfile->interfaceVariableCountString().empty()) - || (!interface && !mProfile->implementationVariableCountString().empty())) { - stateAndVariableCountCode += interface ? - mProfile->interfaceVariableCountString() : - replace(mProfile->implementationVariableCountString(), - "[VARIABLE_COUNT]", std::to_string(mModel->variableCount())); + if ((interface && !mProfile->interfaceConstantCountString().empty()) + || (!interface && !mProfile->implementationConstantCountString().empty())) { + code += interface ? + mProfile->interfaceConstantCountString() : + replace(mProfile->implementationConstantCountString(), + "[CONSTANT_COUNT]", std::to_string(mModel->constantCount())); } - if (!stateAndVariableCountCode.empty()) { - mCode += "\n"; + if ((interface && !mProfile->interfaceComputedConstantCountString().empty()) + || (!interface && !mProfile->implementationComputedConstantCountString().empty())) { + code += interface ? + mProfile->interfaceComputedConstantCountString() : + replace(mProfile->implementationComputedConstantCountString(), + "[COMPUTED_CONSTANT_COUNT]", std::to_string(mModel->computedConstantCount())); } - mCode += stateAndVariableCountCode; -} + if ((interface && !mProfile->interfaceAlgebraicCountString().empty()) + || (!interface && !mProfile->implementationAlgebraicCountString().empty())) { + code += interface ? + mProfile->interfaceAlgebraicCountString() : + replace(mProfile->implementationAlgebraicCountString(), + "[ALGEBRAIC_COUNT]", std::to_string(mModel->algebraicCount())); + } -void Generator::GeneratorImpl::addVariableTypeObjectCode() -{ - auto variableTypeObjectString = mProfile->variableTypeObjectString(modelHasOdes(), - mModel->hasExternalVariables()); + if ((mModel->externalCount() != 0) + && ((interface && !mProfile->interfaceExternalCountString().empty()) + || (!interface && !mProfile->implementationExternalCountString().empty()))) { + code += interface ? + mProfile->interfaceExternalCountString() : + replace(mProfile->implementationExternalCountString(), + "[EXTERNAL_COUNT]", std::to_string(mModel->externalCount())); + } - if (!variableTypeObjectString.empty()) { - mCode += newLineIfNeeded() - + variableTypeObjectString; + if (!code.empty()) { + mCode += newLineIfNeeded(mCode) + + code; } } @@ -370,15 +191,7 @@ std::string Generator::GeneratorImpl::generateVariableInfoObjectCode(const std:: size_t nameSize = 0; size_t unitsSize = 0; - if (modelHasOdes()) { - updateVariableInfoSizes(componentSize, nameSize, unitsSize, mModel->voi()); - - for (const auto &state : mModel->states()) { - updateVariableInfoSizes(componentSize, nameSize, unitsSize, state); - } - } - - for (const auto &variable : mModel->variables()) { + for (const auto &variable : variables(mModel)) { updateVariableInfoSizes(componentSize, nameSize, unitsSize, variable); } @@ -391,154 +204,105 @@ std::string Generator::GeneratorImpl::generateVariableInfoObjectCode(const std:: void Generator::GeneratorImpl::addVariableInfoObjectCode() { if (!mProfile->variableInfoObjectString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + generateVariableInfoObjectCode(mProfile->variableInfoObjectString()); } } std::string Generator::GeneratorImpl::generateVariableInfoEntryCode(const std::string &name, const std::string &units, - const std::string &component, - const std::string &type) const + const std::string &component) const { - return replace(replace(replace(replace(mProfile->variableInfoEntryString(), - "[NAME]", name), - "[UNITS]", units), - "[COMPONENT]", component), - "[TYPE]", type); + return replace(replace(replace(mProfile->variableInfoEntryString(), + "[NAME]", name), + "[UNITS]", units), + "[COMPONENT]", component); } -void Generator::GeneratorImpl::addInterfaceVoiStateAndVariableInfoCode() +void Generator::GeneratorImpl::addInterfaceVariableInfoCode() { - std::string interfaceVoiStateAndVariableInfoCode; + std::string code; - if (modelHasOdes() + if (mModelHasOdes && !mProfile->interfaceVoiInfoString().empty()) { - interfaceVoiStateAndVariableInfoCode += mProfile->interfaceVoiInfoString(); + code += mProfile->interfaceVoiInfoString(); } - if (modelHasOdes() + if (mModelHasOdes && !mProfile->interfaceStateInfoString().empty()) { - interfaceVoiStateAndVariableInfoCode += mProfile->interfaceStateInfoString(); + code += mProfile->interfaceStateInfoString(); } - if (!mProfile->interfaceVariableInfoString().empty()) { - interfaceVoiStateAndVariableInfoCode += mProfile->interfaceVariableInfoString(); + if (!mProfile->interfaceConstantInfoString().empty()) { + code += mProfile->interfaceConstantInfoString(); } - if (!interfaceVoiStateAndVariableInfoCode.empty()) { - mCode += "\n"; + if (!mProfile->interfaceComputedConstantInfoString().empty()) { + code += mProfile->interfaceComputedConstantInfoString(); } - mCode += interfaceVoiStateAndVariableInfoCode; -} + if (!mProfile->interfaceAlgebraicInfoString().empty()) { + code += mProfile->interfaceAlgebraicInfoString(); + } -void Generator::GeneratorImpl::addImplementationVoiInfoCode() -{ - if (modelHasOdes() - && !mProfile->implementationVoiInfoString().empty() - && !mProfile->variableInfoEntryString().empty() - && !mProfile->variableOfIntegrationVariableTypeString().empty()) { - auto voiVariable = mModel->voi()->variable(); - auto name = voiVariable->name(); - auto units = voiVariable->units()->name(); - auto component = owningComponent(voiVariable)->name(); - auto type = mProfile->variableOfIntegrationVariableTypeString(); + if (mModel->hasExternalVariables() + && !mProfile->interfaceExternalInfoString().empty()) { + code += mProfile->interfaceExternalInfoString(); + } - mCode += newLineIfNeeded() - + replace(mProfile->implementationVoiInfoString(), - "[CODE]", generateVariableInfoEntryCode(name, units, component, type)); + if (!code.empty()) { + mCode += newLineIfNeeded(mCode) + + code; } } -void Generator::GeneratorImpl::addImplementationStateInfoCode() +void Generator::GeneratorImpl::doAddImplementationVariableInfoCode(const std::string &variableInfoString, + const std::vector &variables, + bool voiVariable) { - if (modelHasOdes() - && !mProfile->implementationStateInfoString().empty() + if (!variableInfoString.empty() && !mProfile->variableInfoEntryString().empty() - && !mProfile->stateVariableTypeString().empty() && !mProfile->arrayElementSeparatorString().empty()) { std::string infoElementsCode; - auto type = mProfile->stateVariableTypeString(); - for (const auto &state : mModel->states()) { + for (const auto &variable : variables) { if (!infoElementsCode.empty()) { infoElementsCode += mProfile->arrayElementSeparatorString() + "\n"; } - auto stateVariable = state->variable(); + auto variableVariable = variable->variable(); - infoElementsCode += mProfile->indentString() - + generateVariableInfoEntryCode(stateVariable->name(), - stateVariable->units()->name(), - owningComponent(stateVariable)->name(), - type); + infoElementsCode += (voiVariable ? "" : mProfile->indentString()) + + generateVariableInfoEntryCode(variableVariable->name(), + variableVariable->units()->name(), + owningComponent(variableVariable)->name()); } - infoElementsCode += "\n"; + if (!voiVariable && !infoElementsCode.empty()) { + infoElementsCode += "\n"; + } - mCode += newLineIfNeeded() - + replace(mProfile->implementationStateInfoString(), - "[CODE]", infoElementsCode); + mCode += newLineIfNeeded(mCode) + + replace(variableInfoString, "[CODE]", infoElementsCode); } } void Generator::GeneratorImpl::addImplementationVariableInfoCode() { - if (!mProfile->implementationVariableInfoString().empty() - && !mProfile->variableInfoEntryString().empty() - && !mProfile->arrayElementSeparatorString().empty() - && !mProfile->variableOfIntegrationVariableTypeString().empty() - && !mProfile->stateVariableTypeString().empty() - && !mProfile->constantVariableTypeString().empty() - && !mProfile->computedConstantVariableTypeString().empty() - && !mProfile->algebraicVariableTypeString().empty() - && !mProfile->externalVariableTypeString().empty()) { - std::string infoElementsCode; - - for (const auto &variable : mModel->variables()) { - if (!infoElementsCode.empty()) { - infoElementsCode += mProfile->arrayElementSeparatorString() + "\n"; - } - - std::string variableType; - - switch (variable->type()) { - case AnalyserVariable::Type::CONSTANT: - variableType = mProfile->constantVariableTypeString(); - - break; - case AnalyserVariable::Type::COMPUTED_CONSTANT: - variableType = mProfile->computedConstantVariableTypeString(); - - break; - case AnalyserVariable::Type::ALGEBRAIC: - variableType = mProfile->algebraicVariableTypeString(); - - break; - default: // AnalyserVariable::Type::EXTERNAL. - variableType = mProfile->externalVariableTypeString(); - - break; - } + if (mModelHasOdes) { + doAddImplementationVariableInfoCode(mProfile->implementationVoiInfoString(), {mModel->voi()}, true); + } - auto variableVariable = variable->variable(); + if (mModelHasOdes) { + doAddImplementationVariableInfoCode(mProfile->implementationStateInfoString(), mModel->states(), false); + } - infoElementsCode += mProfile->indentString() - + replace(replace(replace(replace(mProfile->variableInfoEntryString(), - "[NAME]", variableVariable->name()), - "[UNITS]", variableVariable->units()->name()), - "[COMPONENT]", owningComponent(variableVariable)->name()), - "[TYPE]", variableType); - } + doAddImplementationVariableInfoCode(mProfile->implementationConstantInfoString(), mModel->constants(), false); + doAddImplementationVariableInfoCode(mProfile->implementationComputedConstantInfoString(), mModel->computedConstants(), false); + doAddImplementationVariableInfoCode(mProfile->implementationAlgebraicInfoString(), mModel->algebraic(), false); - if (!infoElementsCode.empty()) { - infoElementsCode += "\n"; - } - - mCode += newLineIfNeeded() - + replace(mProfile->implementationVariableInfoString(), - "[CODE]", infoElementsCode); + if (mModel->hasExternalVariables()) { + doAddImplementationVariableInfoCode(mProfile->implementationExternalInfoString(), mModel->externals(), false); } } @@ -546,73 +310,73 @@ void Generator::GeneratorImpl::addArithmeticFunctionsCode() { if (mModel->needEqFunction() && !mProfile->hasEqOperator() && !mProfile->eqFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->eqFunctionString(); } if (mModel->needNeqFunction() && !mProfile->hasNeqOperator() && !mProfile->neqFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->neqFunctionString(); } if (mModel->needLtFunction() && !mProfile->hasLtOperator() && !mProfile->ltFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->ltFunctionString(); } if (mModel->needLeqFunction() && !mProfile->hasLeqOperator() && !mProfile->leqFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->leqFunctionString(); } if (mModel->needGtFunction() && !mProfile->hasGtOperator() && !mProfile->gtFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->gtFunctionString(); } if (mModel->needGeqFunction() && !mProfile->hasGeqOperator() && !mProfile->geqFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->geqFunctionString(); } if (mModel->needAndFunction() && !mProfile->hasAndOperator() && !mProfile->andFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->andFunctionString(); } if (mModel->needOrFunction() && !mProfile->hasOrOperator() && !mProfile->orFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->orFunctionString(); } if (mModel->needXorFunction() && !mProfile->hasXorOperator() && !mProfile->xorFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->xorFunctionString(); } if (mModel->needNotFunction() && !mProfile->hasNotOperator() && !mProfile->notFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->notFunctionString(); } if (mModel->needMinFunction() && !mProfile->minFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->minFunctionString(); } if (mModel->needMaxFunction() && !mProfile->maxFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->maxFunctionString(); } } @@ -621,1351 +385,217 @@ void Generator::GeneratorImpl::addTrigonometricFunctionsCode() { if (mModel->needSecFunction() && !mProfile->secFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->secFunctionString(); } if (mModel->needCscFunction() && !mProfile->cscFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->cscFunctionString(); } if (mModel->needCotFunction() && !mProfile->cotFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->cotFunctionString(); } if (mModel->needSechFunction() && !mProfile->sechFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->sechFunctionString(); } if (mModel->needCschFunction() && !mProfile->cschFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->cschFunctionString(); } if (mModel->needCothFunction() && !mProfile->cothFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->cothFunctionString(); } if (mModel->needAsecFunction() && !mProfile->asecFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->asecFunctionString(); } if (mModel->needAcscFunction() && !mProfile->acscFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->acscFunctionString(); } if (mModel->needAcotFunction() && !mProfile->acotFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->acotFunctionString(); } if (mModel->needAsechFunction() && !mProfile->asechFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->asechFunctionString(); } if (mModel->needAcschFunction() && !mProfile->acschFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->acschFunctionString(); } if (mModel->needAcothFunction() && !mProfile->acothFunctionString().empty()) { - mCode += newLineIfNeeded() + mCode += newLineIfNeeded(mCode) + mProfile->acothFunctionString(); } } void Generator::GeneratorImpl::addInterfaceCreateDeleteArrayMethodsCode() { - std::string interfaceCreateDeleteArraysCode; + std::string code; - if (modelHasOdes() + if (mModelHasOdes && !mProfile->interfaceCreateStatesArrayMethodString().empty()) { - interfaceCreateDeleteArraysCode += mProfile->interfaceCreateStatesArrayMethodString(); - } - - if (!mProfile->interfaceCreateVariablesArrayMethodString().empty()) { - interfaceCreateDeleteArraysCode += mProfile->interfaceCreateVariablesArrayMethodString(); - } - - if (!mProfile->interfaceDeleteArrayMethodString().empty()) { - interfaceCreateDeleteArraysCode += mProfile->interfaceDeleteArrayMethodString(); + code += mProfile->interfaceCreateStatesArrayMethodString(); } - if (!interfaceCreateDeleteArraysCode.empty()) { - mCode += "\n"; + if (!mProfile->interfaceCreateConstantsArrayMethodString().empty()) { + code += mProfile->interfaceCreateConstantsArrayMethodString(); } - mCode += interfaceCreateDeleteArraysCode; -} - -void Generator::GeneratorImpl::addExternalVariableMethodTypeDefinitionCode() -{ - if (mModel->hasExternalVariables()) { - auto externalVariableMethodTypeDefinitionString = mProfile->externalVariableMethodTypeDefinitionString(modelHasOdes()); - - if (!externalVariableMethodTypeDefinitionString.empty()) { - mCode += "\n" - + externalVariableMethodTypeDefinitionString; - } + if (!mProfile->interfaceCreateComputedConstantsArrayMethodString().empty()) { + code += mProfile->interfaceCreateComputedConstantsArrayMethodString(); } -} -void Generator::GeneratorImpl::addImplementationCreateStatesArrayMethodCode() -{ - if (modelHasOdes() - && !mProfile->implementationCreateStatesArrayMethodString().empty()) { - mCode += newLineIfNeeded() - + mProfile->implementationCreateStatesArrayMethodString(); + if (!mProfile->interfaceCreateAlgebraicArrayMethodString().empty()) { + code += mProfile->interfaceCreateAlgebraicArrayMethodString(); } -} -void Generator::GeneratorImpl::addImplementationCreateVariablesArrayMethodCode() -{ - if (!mProfile->implementationCreateVariablesArrayMethodString().empty()) { - mCode += newLineIfNeeded() - + mProfile->implementationCreateVariablesArrayMethodString(); + if (mModel->hasExternalVariables() + && !mProfile->interfaceCreateExternalsArrayMethodString().empty()) { + code += mProfile->interfaceCreateExternalsArrayMethodString(); } -} -void Generator::GeneratorImpl::addImplementationDeleteArrayMethodCode() -{ - if (!mProfile->implementationDeleteArrayMethodString().empty()) { - mCode += newLineIfNeeded() - + mProfile->implementationDeleteArrayMethodString(); - } -} - -void Generator::GeneratorImpl::addRootFindingInfoObjectCode() -{ - if (modelHasNlas() - && !mProfile->rootFindingInfoObjectString(modelHasOdes()).empty()) { - mCode += newLineIfNeeded() - + mProfile->rootFindingInfoObjectString(modelHasOdes()); + if (!mProfile->interfaceDeleteArrayMethodString().empty()) { + code += "\n" + + mProfile->interfaceDeleteArrayMethodString(); } -} -void Generator::GeneratorImpl::addExternNlaSolveMethodCode() -{ - if (modelHasNlas() - && !mProfile->externNlaSolveMethodString().empty()) { - mCode += newLineIfNeeded() - + mProfile->externNlaSolveMethodString(); + if (!code.empty()) { + mCode += newLineIfNeeded(mCode) + + code; } } -void Generator::GeneratorImpl::addNlaSystemsCode() +void Generator::GeneratorImpl::addImplementationCreateDeleteArrayMethodsCode() { - if (modelHasNlas() - && !mProfile->objectiveFunctionMethodString(modelHasOdes()).empty() - && !mProfile->findRootMethodString(modelHasOdes()).empty() - && !mProfile->nlaSolveCallString(modelHasOdes()).empty()) { - std::vector handledNlaEquations; - - for (const auto &equation : mModel->equations()) { - if ((equation->type() == AnalyserEquation::Type::NLA) - && (std::find(handledNlaEquations.begin(), handledNlaEquations.end(), equation) == handledNlaEquations.end())) { - std::string methodBody; - auto i = MAX_SIZE_T; - auto variables = equation->variables(); - auto variablesSize = variables.size(); - - for (i = 0; i < variablesSize; ++i) { - auto arrayString = (variables[i]->type() == AnalyserVariable::Type::STATE) ? - mProfile->ratesArrayString() : - mProfile->variablesArrayString(); - - methodBody += mProfile->indentString() - + arrayString + mProfile->openArrayString() + convertToString(variables[i]->index()) + mProfile->closeArrayString() - + mProfile->equalityString() - + mProfile->uArrayString() + mProfile->openArrayString() + convertToString(i) + mProfile->closeArrayString() - + mProfile->commandSeparatorString() + "\n"; - } - - methodBody += newLineIfNeeded(); - - i = MAX_SIZE_T; - - methodBody += mProfile->indentString() - + mProfile->fArrayString() + mProfile->openArrayString() + convertToString(++i) + mProfile->closeArrayString() - + mProfile->equalityString() - + generateCode(equation->ast()) - + mProfile->commandSeparatorString() + "\n"; - - handledNlaEquations.push_back(equation); - - for (const auto &nlaSibling : equation->nlaSiblings()) { - methodBody += mProfile->indentString() - + mProfile->fArrayString() + mProfile->openArrayString() + convertToString(++i) + mProfile->closeArrayString() - + mProfile->equalityString() - + generateCode(nlaSibling->ast()) - + mProfile->commandSeparatorString() + "\n"; - - handledNlaEquations.push_back(nlaSibling); - } - - mCode += newLineIfNeeded() - + replace(replace(mProfile->objectiveFunctionMethodString(modelHasOdes()), - "[INDEX]", convertToString(equation->nlaSystemIndex())), - "[CODE]", generateMethodBodyCode(methodBody)); - - methodBody = {}; - - for (i = 0; i < variablesSize; ++i) { - auto arrayString = (variables[i]->type() == AnalyserVariable::Type::STATE) ? - mProfile->ratesArrayString() : - mProfile->variablesArrayString(); - - methodBody += mProfile->indentString() - + mProfile->uArrayString() + mProfile->openArrayString() + convertToString(i) + mProfile->closeArrayString() - + mProfile->equalityString() - + arrayString + mProfile->openArrayString() + convertToString(variables[i]->index()) + mProfile->closeArrayString() - + mProfile->commandSeparatorString() + "\n"; - } - - methodBody += newLineIfNeeded() - + mProfile->indentString() - + replace(replace(mProfile->nlaSolveCallString(modelHasOdes()), - "[INDEX]", convertToString(equation->nlaSystemIndex())), - "[SIZE]", convertToString(equation->variableCount())); - - methodBody += newLineIfNeeded(); - - for (i = 0; i < variablesSize; ++i) { - auto arrayString = (variables[i]->type() == AnalyserVariable::Type::STATE) ? - mProfile->ratesArrayString() : - mProfile->variablesArrayString(); - - methodBody += mProfile->indentString() - + arrayString + mProfile->openArrayString() + convertToString(variables[i]->index()) + mProfile->closeArrayString() - + mProfile->equalityString() - + mProfile->uArrayString() + mProfile->openArrayString() + convertToString(i) + mProfile->closeArrayString() - + mProfile->commandSeparatorString() + "\n"; - } - - mCode += newLineIfNeeded() - + replace(replace(replace(mProfile->findRootMethodString(modelHasOdes()), - "[INDEX]", convertToString(equation->nlaSystemIndex())), - "[SIZE]", convertToString(variablesSize)), - "[CODE]", generateMethodBodyCode(methodBody)); - } - } - } -} - -std::string Generator::GeneratorImpl::generateMethodBodyCode(const std::string &methodBody) const -{ - return methodBody.empty() ? - mProfile->emptyMethodString().empty() ? - "" : - mProfile->indentString() + mProfile->emptyMethodString() : - methodBody; -} - -std::string generateDoubleCode(const std::string &value) -{ - if (value.find('.') != std::string::npos) { - return value; - } - - auto ePos = value.find('e'); - - if (ePos == std::string::npos) { - return value + ".0"; + if (mModelHasOdes + && !mProfile->implementationCreateStatesArrayMethodString().empty()) { + mCode += newLineIfNeeded(mCode) + + mProfile->implementationCreateStatesArrayMethodString(); } - return value.substr(0, ePos) + ".0" + value.substr(ePos); -} - -std::string Generator::GeneratorImpl::generateDoubleOrConstantVariableNameCode(const VariablePtr &variable) const -{ - if (isCellMLReal(variable->initialValue())) { - return generateDoubleCode(variable->initialValue()); + if (!mProfile->implementationCreateConstantsArrayMethodString().empty()) { + mCode += newLineIfNeeded(mCode) + + mProfile->implementationCreateConstantsArrayMethodString(); } - auto initValueVariable = owningComponent(variable)->variable(variable->initialValue()); - auto analyserInitialValueVariable = analyserVariable(initValueVariable); - - return mProfile->variablesArrayString() + mProfile->openArrayString() + convertToString(analyserInitialValueVariable->index()) + mProfile->closeArrayString(); -} - -std::string Generator::GeneratorImpl::generateVariableNameCode(const VariablePtr &variable, - bool state) const -{ - // Generate some code for a variable name, but only if we have a model. If - // we don't have a model, it means that we are using the generator from the - // analyser, in which case we just want to return the original name of the - // variable. - - if (mModel == nullptr) { - return variable->name(); + if (!mProfile->implementationCreateComputedConstantsArrayMethodString().empty()) { + mCode += newLineIfNeeded(mCode) + + mProfile->implementationCreateComputedConstantsArrayMethodString(); } - auto analyserVariable = Generator::GeneratorImpl::analyserVariable(variable); - - if (analyserVariable->type() == AnalyserVariable::Type::VARIABLE_OF_INTEGRATION) { - return mProfile->voiString(); + if (!mProfile->implementationCreateAlgebraicArrayMethodString().empty()) { + mCode += newLineIfNeeded(mCode) + + mProfile->implementationCreateAlgebraicArrayMethodString(); } - std::string arrayName; - - if (analyserVariable->type() == AnalyserVariable::Type::STATE) { - arrayName = state ? - mProfile->statesArrayString() : - mProfile->ratesArrayString(); - } else { - arrayName = mProfile->variablesArrayString(); + if (mModel->hasExternalVariables() + && !mProfile->implementationCreateExternalsArrayMethodString().empty()) { + mCode += newLineIfNeeded(mCode) + + mProfile->implementationCreateExternalsArrayMethodString(); } - return arrayName + mProfile->openArrayString() + convertToString(analyserVariable->index()) + mProfile->closeArrayString(); -} - -std::string Generator::GeneratorImpl::generateOperatorCode(const std::string &op, - const AnalyserEquationAstPtr &ast) const -{ - // Generate the code for the left and right branches of the given AST. - - std::string res; - auto astLeftChild = ast->leftChild(); - auto astRightChild = ast->rightChild(); - auto astLeftChildCode = generateCode(astLeftChild); - auto astRightChildCode = generateCode(astRightChild); - - // Determine whether parentheses should be added around the left and/or - // right piece of code, and this based on the precedence of the operators - // used in CellML, which are listed below from higher to lower precedence: - // 1. Parentheses [Left to right] - // 2. POWER (as an operator, not as a function, i.e. [Left to right] - // as in Matlab and not in C, for example) - // 3. Unary PLUS, Unary MINUS, NOT [Right to left] - // 4. TIMES, DIVIDE [Left to right] - // 5. PLUS, MINUS [Left to right] - // 6. LT, LEQ, GT, GEQ [Left to right] - // 7. EQ, NEQ [Left to right] - // 8. XOR (bitwise) [Left to right] - // 9. AND (logical) [Left to right] - // 10. OR (logical) [Left to right] - // 11. PIECEWISE (as an operator) [Right to left] - - if (isPlusOperator(ast)) { - if (isRelationalOperator(astLeftChild) - || isLogicalOperator(astLeftChild) - || isPiecewiseStatement(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - - if (isRelationalOperator(astRightChild) - || isLogicalOperator(astRightChild) - || isPiecewiseStatement(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } else if (isMinusOperator(ast)) { - if (isRelationalOperator(astLeftChild) - || isLogicalOperator(astLeftChild) - || isPiecewiseStatement(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - - if (isNegativeNumber(astRightChild) - || isRelationalOperator(astRightChild) - || isLogicalOperator(astRightChild) - || isMinusOperator(astRightChild) - || isPiecewiseStatement(astRightChild) - || (astRightChildCode.rfind(mProfile->minusString(), 0) == 0)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } else if (isPlusOperator(astRightChild)) { - if (astRightChild->rightChild() != nullptr) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } - } else if (isTimesOperator(ast)) { - if (isRelationalOperator(astLeftChild) - || isLogicalOperator(astLeftChild) - || isPiecewiseStatement(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } else if (isPlusOperator(astLeftChild) - || isMinusOperator(astLeftChild)) { - if (astLeftChild->rightChild() != nullptr) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - } - - if (isRelationalOperator(astRightChild) - || isLogicalOperator(astRightChild) - || isPiecewiseStatement(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } else if (isPlusOperator(astRightChild) - || isMinusOperator(astRightChild)) { - if (astRightChild->rightChild() != nullptr) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } - } else if (isDivideOperator(ast)) { - if (isRelationalOperator(astLeftChild) - || isLogicalOperator(astLeftChild) - || isPiecewiseStatement(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } else if (isPlusOperator(astLeftChild) - || isMinusOperator(astLeftChild)) { - if (astLeftChild->rightChild() != nullptr) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - } - - if (isRelationalOperator(astRightChild) - || isLogicalOperator(astRightChild) - || isTimesOperator(astRightChild) - || isDivideOperator(astRightChild) - || isPiecewiseStatement(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } else if (isPlusOperator(astRightChild) - || isMinusOperator(astRightChild)) { - if (astRightChild->rightChild() != nullptr) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } - } else if (isAndOperator(ast)) { - // Note: according to the precedence rules above, we only need to - // add parentheses around OR and PIECEWISE. However, it looks - // better/clearer to have some around some other operators - // (agreed, this is somewhat subjective). - - if (isRelationalOperator(astLeftChild) - || isOrOperator(astLeftChild) - || isXorOperator(astLeftChild) - || isPiecewiseStatement(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } else if (isPlusOperator(astLeftChild) - || isMinusOperator(astLeftChild)) { - if (astLeftChild->rightChild() != nullptr) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - } else if (isPowerOperator(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } else if (isRootOperator(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - - if (isRelationalOperator(astRightChild) - || isOrOperator(astRightChild) - || isXorOperator(astRightChild) - || isPiecewiseStatement(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } else if (isPlusOperator(astRightChild) - || isMinusOperator(astRightChild)) { - if (astRightChild->rightChild() != nullptr) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } else if (isPowerOperator(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } else if (isRootOperator(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } else if (isOrOperator(ast)) { - // Note: according to the precedence rules above, we only need to - // add parentheses around PIECEWISE. However, it looks - // better/clearer to have some around some other operators - // (agreed, this is somewhat subjective). - - if (isRelationalOperator(astLeftChild) - || isAndOperator(astLeftChild) - || isXorOperator(astLeftChild) - || isPiecewiseStatement(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } else if (isPlusOperator(astLeftChild) - || isMinusOperator(astLeftChild)) { - if (astLeftChild->rightChild() != nullptr) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - } else if (isPowerOperator(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } else if (isRootOperator(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - - if (isRelationalOperator(astRightChild) - || isAndOperator(astRightChild) - || isXorOperator(astRightChild) - || isPiecewiseStatement(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } else if (isPlusOperator(astRightChild) - || isMinusOperator(astRightChild)) { - if (astRightChild->rightChild() != nullptr) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } else if (isPowerOperator(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } else if (isRootOperator(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } else if (isXorOperator(ast)) { - // Note: according to the precedence rules above, we only need to - // add parentheses around AND, OR and PIECEWISE. However, it - // looks better/clearer to have some around some other - // operators (agreed, this is somewhat subjective). - - if (isRelationalOperator(astLeftChild) - || isAndOperator(astLeftChild) - || isOrOperator(astLeftChild) - || isPiecewiseStatement(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } else if (isPlusOperator(astLeftChild) - || isMinusOperator(astLeftChild)) { - if (astLeftChild->rightChild() != nullptr) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - } else if (isPowerOperator(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } else if (isRootOperator(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - - if (isRelationalOperator(astRightChild) - || isAndOperator(astRightChild) - || isOrOperator(astRightChild) - || isPiecewiseStatement(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } else if (isPlusOperator(astRightChild) - || isMinusOperator(astRightChild)) { - if (astRightChild->rightChild() != nullptr) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } else if (isPowerOperator(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } else if (isRootOperator(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } else if (isPowerOperator(ast)) { - if (isRelationalOperator(astLeftChild) - || isLogicalOperator(astLeftChild) - || isMinusOperator(astLeftChild) - || isTimesOperator(astLeftChild) - || isDivideOperator(astLeftChild) - || isPiecewiseStatement(astLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } else if (isPlusOperator(astLeftChild)) { - if (astLeftChild->rightChild() != nullptr) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - } - - if (isRelationalOperator(astRightChild) - || isLogicalOperator(astRightChild) - || isMinusOperator(astLeftChild) - || isTimesOperator(astRightChild) - || isDivideOperator(astRightChild) - || isPowerOperator(astRightChild) - || isRootOperator(astRightChild) - || isPiecewiseStatement(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } else if (isPlusOperator(astRightChild)) { - if (astRightChild->rightChild() != nullptr) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } - } else if (isRootOperator(ast)) { - if (isRelationalOperator(astRightChild) - || isLogicalOperator(astRightChild) - || isMinusOperator(astRightChild) - || isTimesOperator(astRightChild) - || isDivideOperator(astRightChild) - || isPiecewiseStatement(astRightChild)) { - astRightChildCode = "(" + astRightChildCode + ")"; - } else if (isPlusOperator(astRightChild)) { - if (astRightChild->rightChild() != nullptr) { - astRightChildCode = "(" + astRightChildCode + ")"; - } - } - - auto astLeftChildLeftChild = astLeftChild->leftChild(); - - if (isRelationalOperator(astLeftChildLeftChild) - || isLogicalOperator(astLeftChildLeftChild) - || isMinusOperator(astLeftChildLeftChild) - || isTimesOperator(astLeftChildLeftChild) - || isDivideOperator(astLeftChildLeftChild) - || isPowerOperator(astLeftChildLeftChild) - || isRootOperator(astLeftChildLeftChild) - || isPiecewiseStatement(astLeftChildLeftChild)) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } else if (isPlusOperator(astLeftChildLeftChild)) { - if (astLeftChildLeftChild->rightChild() != nullptr) { - astLeftChildCode = "(" + astLeftChildCode + ")"; - } - } - - return astRightChildCode + op + "(1.0/" + astLeftChildCode + ")"; - } - - return astLeftChildCode + op + astRightChildCode; -} - -std::string Generator::GeneratorImpl::generateMinusUnaryCode(const AnalyserEquationAstPtr &ast) const -{ - // Generate the code for the left branch of the given AST. - - auto astLeftChild = ast->leftChild(); - auto code = generateCode(astLeftChild); - - // Determine whether parentheses should be added around the left code. - - if (isRelationalOperator(astLeftChild) - || isLogicalOperator(astLeftChild) - || isPlusOperator(astLeftChild) - || isMinusOperator(astLeftChild) - || isPiecewiseStatement(astLeftChild)) { - code = "(" + code + ")"; + if (!mProfile->implementationDeleteArrayMethodString().empty()) { + mCode += newLineIfNeeded(mCode) + + mProfile->implementationDeleteArrayMethodString(); } - - return mProfile->minusString() + code; -} - -std::string Generator::GeneratorImpl::generateOneParameterFunctionCode(const std::string &function, - const AnalyserEquationAstPtr &ast) const -{ - return function + "(" + generateCode(ast->leftChild()) + ")"; -} - -std::string Generator::GeneratorImpl::generateTwoParameterFunctionCode(const std::string &function, - const AnalyserEquationAstPtr &ast) const -{ - return function + "(" + generateCode(ast->leftChild()) + ", " + generateCode(ast->rightChild()) + ")"; -} - -std::string Generator::GeneratorImpl::generatePiecewiseIfCode(const std::string &condition, - const std::string &value) const -{ - return replace(replace(mProfile->hasConditionalOperator() ? - mProfile->conditionalOperatorIfString() : - mProfile->piecewiseIfString(), - "[CONDITION]", condition), - "[IF_STATEMENT]", value); -} - -std::string Generator::GeneratorImpl::generatePiecewiseElseCode(const std::string &value) const -{ - return replace(mProfile->hasConditionalOperator() ? - mProfile->conditionalOperatorElseString() : - mProfile->piecewiseElseString(), - "[ELSE_STATEMENT]", value); } -std::string Generator::GeneratorImpl::generateCode(const AnalyserEquationAstPtr &ast) const +void Generator::GeneratorImpl::addExternalVariableMethodTypeDefinitionCode() { - // Generate the code for the given AST. - // Note: AnalyserEquationAst::Type::BVAR is only relevant when there is no - // model (in which case we want to generate something like dx/dt, as - // is in the case of the analyser when we want to mention an equation) - // since otherwise we don't need to generate any code for it (since we - // will, instead, want to generate something like rates[0]). - - std::string code; - - switch (ast->type()) { - case AnalyserEquationAst::Type::EQUALITY: - code = generateOperatorCode(mProfile->equalityString(), ast); - - break; - case AnalyserEquationAst::Type::EQ: - if (mProfile->hasEqOperator()) { - code = generateOperatorCode(mProfile->eqString(), ast); - } else { - code = generateTwoParameterFunctionCode(mProfile->eqString(), ast); - } - - break; - case AnalyserEquationAst::Type::NEQ: - if (mProfile->hasNeqOperator()) { - code = generateOperatorCode(mProfile->neqString(), ast); - } else { - code = generateTwoParameterFunctionCode(mProfile->neqString(), ast); - } - - break; - case AnalyserEquationAst::Type::LT: - if (mProfile->hasLtOperator()) { - code = generateOperatorCode(mProfile->ltString(), ast); - } else { - code = generateTwoParameterFunctionCode(mProfile->ltString(), ast); - } - - break; - case AnalyserEquationAst::Type::LEQ: - if (mProfile->hasLeqOperator()) { - code = generateOperatorCode(mProfile->leqString(), ast); - } else { - code = generateTwoParameterFunctionCode(mProfile->leqString(), ast); - } - - break; - case AnalyserEquationAst::Type::GT: - if (mProfile->hasGtOperator()) { - code = generateOperatorCode(mProfile->gtString(), ast); - } else { - code = generateTwoParameterFunctionCode(mProfile->gtString(), ast); - } - - break; - case AnalyserEquationAst::Type::GEQ: - if (mProfile->hasGeqOperator()) { - code = generateOperatorCode(mProfile->geqString(), ast); - } else { - code = generateTwoParameterFunctionCode(mProfile->geqString(), ast); - } - - break; - case AnalyserEquationAst::Type::AND: - if (mProfile->hasAndOperator()) { - code = generateOperatorCode(mProfile->andString(), ast); - } else { - code = generateTwoParameterFunctionCode(mProfile->andString(), ast); - } - - break; - case AnalyserEquationAst::Type::OR: - if (mProfile->hasOrOperator()) { - code = generateOperatorCode(mProfile->orString(), ast); - } else { - code = generateTwoParameterFunctionCode(mProfile->orString(), ast); - } - - break; - case AnalyserEquationAst::Type::XOR: - if (mProfile->hasXorOperator()) { - code = generateOperatorCode(mProfile->xorString(), ast); - } else { - code = generateTwoParameterFunctionCode(mProfile->xorString(), ast); - } - - break; - case AnalyserEquationAst::Type::NOT: - if (mProfile->hasNotOperator()) { - code = mProfile->notString() + generateCode(ast->leftChild()); - } else { - code = generateOneParameterFunctionCode(mProfile->notString(), ast); - } - - break; - case AnalyserEquationAst::Type::PLUS: - if (ast->rightChild() != nullptr) { - code = generateOperatorCode(mProfile->plusString(), ast); - } else { - code = generateCode(ast->leftChild()); - } - - break; - case AnalyserEquationAst::Type::MINUS: - if (ast->rightChild() != nullptr) { - code = generateOperatorCode(mProfile->minusString(), ast); - } else { - code = generateMinusUnaryCode(ast); - } - - break; - case AnalyserEquationAst::Type::TIMES: - code = generateOperatorCode(mProfile->timesString(), ast); - - break; - case AnalyserEquationAst::Type::DIVIDE: - code = generateOperatorCode(mProfile->divideString(), ast); - - break; - case AnalyserEquationAst::Type::POWER: { - auto stringValue = generateCode(ast->rightChild()); - double doubleValue; - auto validConversion = convertToDouble(stringValue, doubleValue); - - if (validConversion && areEqual(doubleValue, 0.5)) { - code = generateOneParameterFunctionCode(mProfile->squareRootString(), ast); - } else if (validConversion && areEqual(doubleValue, 2.0) - && !mProfile->squareString().empty()) { - code = generateOneParameterFunctionCode(mProfile->squareString(), ast); - } else { - code = mProfile->hasPowerOperator() ? - generateOperatorCode(mProfile->powerString(), ast) : - mProfile->powerString() + "(" + generateCode(ast->leftChild()) + ", " + stringValue + ")"; - } - } break; - case AnalyserEquationAst::Type::ROOT: { - auto astRightChild = ast->rightChild(); - - if (astRightChild != nullptr) { - auto astLeftChild = ast->leftChild(); - double doubleValue; - - if (convertToDouble(generateCode(astLeftChild), doubleValue) - && areEqual(doubleValue, 2.0)) { - code = mProfile->squareRootString() + "(" + generateCode(astRightChild) + ")"; - } else { - if (mProfile->hasPowerOperator()) { - code = generateOperatorCode(mProfile->powerString(), ast); - } else { - auto rootValueAst = AnalyserEquationAst::create(); - - rootValueAst->setType(AnalyserEquationAst::Type::DIVIDE); - rootValueAst->setParent(ast); - - auto leftChild = AnalyserEquationAst::create(); - - leftChild->setType(AnalyserEquationAst::Type::CN); - leftChild->setValue("1.0"); - leftChild->setParent(rootValueAst); - - rootValueAst->setLeftChild(leftChild); - rootValueAst->setRightChild(astLeftChild->leftChild()); - - code = mProfile->powerString() + "(" + generateCode(astRightChild) + ", " + generateOperatorCode(mProfile->divideString(), rootValueAst) + ")"; - } - } - } else { - code = generateOneParameterFunctionCode(mProfile->squareRootString(), ast); - } - } break; - case AnalyserEquationAst::Type::ABS: - code = generateOneParameterFunctionCode(mProfile->absoluteValueString(), ast); - - break; - case AnalyserEquationAst::Type::EXP: - code = generateOneParameterFunctionCode(mProfile->exponentialString(), ast); - - break; - case AnalyserEquationAst::Type::LN: - code = generateOneParameterFunctionCode(mProfile->naturalLogarithmString(), ast); - - break; - case AnalyserEquationAst::Type::LOG: { - auto astRightChild = ast->rightChild(); - - if (astRightChild != nullptr) { - auto stringValue = generateCode(ast->leftChild()); - double doubleValue; - - if (convertToDouble(stringValue, doubleValue) - && areEqual(doubleValue, 10.0)) { - code = mProfile->commonLogarithmString() + "(" + generateCode(astRightChild) + ")"; - } else { - code = mProfile->naturalLogarithmString() + "(" + generateCode(astRightChild) + ")/" + mProfile->naturalLogarithmString() + "(" + stringValue + ")"; - } - } else { - code = generateOneParameterFunctionCode(mProfile->commonLogarithmString(), ast); - } - } break; - case AnalyserEquationAst::Type::CEILING: - code = generateOneParameterFunctionCode(mProfile->ceilingString(), ast); - - break; - case AnalyserEquationAst::Type::FLOOR: - code = generateOneParameterFunctionCode(mProfile->floorString(), ast); - - break; - case AnalyserEquationAst::Type::MIN: - code = generateTwoParameterFunctionCode(mProfile->minString(), ast); - - break; - case AnalyserEquationAst::Type::MAX: - code = generateTwoParameterFunctionCode(mProfile->maxString(), ast); - - break; - case AnalyserEquationAst::Type::REM: - code = generateTwoParameterFunctionCode(mProfile->remString(), ast); - - break; - case AnalyserEquationAst::Type::DIFF: - if (mModel != nullptr) { - code = generateCode(ast->rightChild()); - } else { - code = "d" + generateCode(ast->rightChild()) + "/d" + generateCode(ast->leftChild()); - } - - break; - case AnalyserEquationAst::Type::SIN: - code = generateOneParameterFunctionCode(mProfile->sinString(), ast); - - break; - case AnalyserEquationAst::Type::COS: - code = generateOneParameterFunctionCode(mProfile->cosString(), ast); - - break; - case AnalyserEquationAst::Type::TAN: - code = generateOneParameterFunctionCode(mProfile->tanString(), ast); - - break; - case AnalyserEquationAst::Type::SEC: - code = generateOneParameterFunctionCode(mProfile->secString(), ast); - - break; - case AnalyserEquationAst::Type::CSC: - code = generateOneParameterFunctionCode(mProfile->cscString(), ast); - - break; - case AnalyserEquationAst::Type::COT: - code = generateOneParameterFunctionCode(mProfile->cotString(), ast); - - break; - case AnalyserEquationAst::Type::SINH: - code = generateOneParameterFunctionCode(mProfile->sinhString(), ast); - - break; - case AnalyserEquationAst::Type::COSH: - code = generateOneParameterFunctionCode(mProfile->coshString(), ast); - - break; - case AnalyserEquationAst::Type::TANH: - code = generateOneParameterFunctionCode(mProfile->tanhString(), ast); - - break; - case AnalyserEquationAst::Type::SECH: - code = generateOneParameterFunctionCode(mProfile->sechString(), ast); - - break; - case AnalyserEquationAst::Type::CSCH: - code = generateOneParameterFunctionCode(mProfile->cschString(), ast); - - break; - case AnalyserEquationAst::Type::COTH: - code = generateOneParameterFunctionCode(mProfile->cothString(), ast); - - break; - case AnalyserEquationAst::Type::ASIN: - code = generateOneParameterFunctionCode(mProfile->asinString(), ast); - - break; - case AnalyserEquationAst::Type::ACOS: - code = generateOneParameterFunctionCode(mProfile->acosString(), ast); - - break; - case AnalyserEquationAst::Type::ATAN: - code = generateOneParameterFunctionCode(mProfile->atanString(), ast); - - break; - case AnalyserEquationAst::Type::ASEC: - code = generateOneParameterFunctionCode(mProfile->asecString(), ast); - - break; - case AnalyserEquationAst::Type::ACSC: - code = generateOneParameterFunctionCode(mProfile->acscString(), ast); - - break; - case AnalyserEquationAst::Type::ACOT: - code = generateOneParameterFunctionCode(mProfile->acotString(), ast); - - break; - case AnalyserEquationAst::Type::ASINH: - code = generateOneParameterFunctionCode(mProfile->asinhString(), ast); - - break; - case AnalyserEquationAst::Type::ACOSH: - code = generateOneParameterFunctionCode(mProfile->acoshString(), ast); - - break; - case AnalyserEquationAst::Type::ATANH: - code = generateOneParameterFunctionCode(mProfile->atanhString(), ast); - - break; - case AnalyserEquationAst::Type::ASECH: - code = generateOneParameterFunctionCode(mProfile->asechString(), ast); - - break; - case AnalyserEquationAst::Type::ACSCH: - code = generateOneParameterFunctionCode(mProfile->acschString(), ast); - - break; - case AnalyserEquationAst::Type::ACOTH: - code = generateOneParameterFunctionCode(mProfile->acothString(), ast); - - break; - case AnalyserEquationAst::Type::PIECEWISE: { - auto astRightChild = ast->rightChild(); + if (mModel->hasExternalVariables()) { + auto externalVariableMethodTypeDefinitionString = mProfile->externalVariableMethodTypeDefinitionString(mModelHasOdes); - if (astRightChild != nullptr) { - if (astRightChild->type() == AnalyserEquationAst::Type::PIECE) { - code = generateCode(ast->leftChild()) + generatePiecewiseElseCode(generateCode(astRightChild) + generatePiecewiseElseCode(mProfile->nanString())); - } else { - code = generateCode(ast->leftChild()) + generatePiecewiseElseCode(generateCode(astRightChild)); - } - } else { - code = generateCode(ast->leftChild()) + generatePiecewiseElseCode(mProfile->nanString()); + if (!externalVariableMethodTypeDefinitionString.empty()) { + mCode += newLineIfNeeded(mCode) + + externalVariableMethodTypeDefinitionString; } - } break; - case AnalyserEquationAst::Type::PIECE: - code = generatePiecewiseIfCode(generateCode(ast->rightChild()), generateCode(ast->leftChild())); - - break; - case AnalyserEquationAst::Type::OTHERWISE: - code = generateCode(ast->leftChild()); - - break; - case AnalyserEquationAst::Type::CI: - code = generateVariableNameCode(ast->variable(), ast->parent()->type() != AnalyserEquationAst::Type::DIFF); - - break; - case AnalyserEquationAst::Type::CN: - code = generateDoubleCode(ast->value()); - - break; - case AnalyserEquationAst::Type::DEGREE: - case AnalyserEquationAst::Type::LOGBASE: - code = generateCode(ast->leftChild()); - - break; - case AnalyserEquationAst::Type::BVAR: - code = generateCode(ast->leftChild()); - - break; - case AnalyserEquationAst::Type::TRUE: - code = mProfile->trueString(); - - break; - case AnalyserEquationAst::Type::FALSE: - code = mProfile->falseString(); - - break; - case AnalyserEquationAst::Type::E: - code = mProfile->eString(); - - break; - case AnalyserEquationAst::Type::PI: - code = mProfile->piString(); - - break; - case AnalyserEquationAst::Type::INF: - code = mProfile->infString(); - - break; - default: // AnalyserEquationAst::Type::NAN. - code = mProfile->nanString(); - - break; - } - - return code; -} - -bool Generator::GeneratorImpl::isToBeComputedAgain(const AnalyserEquationPtr &equation) const -{ - // NLA and algebraic equations that are state/rate-based and external - // equations are to be computed again (in the computeVariables() method). - - switch (equation->type()) { - case AnalyserEquation::Type::NLA: - case AnalyserEquation::Type::ALGEBRAIC: - return equation->isStateRateBased(); - case AnalyserEquation::Type::EXTERNAL: - return true; - default: - return false; } } -bool Generator::GeneratorImpl::isSomeConstant(const AnalyserEquationPtr &equation, - bool includeComputedConstants) const -{ - auto type = equation->type(); - - return (type == AnalyserEquation::Type::TRUE_CONSTANT) - || (!includeComputedConstants && (type == AnalyserEquation::Type::VARIABLE_BASED_CONSTANT)); -} - -std::string Generator::GeneratorImpl::generateZeroInitialisationCode(const AnalyserVariablePtr &variable) const -{ - return mProfile->indentString() - + generateVariableNameCode(variable->variable(), false) - + mProfile->equalityString() - + "0.0" - + mProfile->commandSeparatorString() + "\n"; -} - -std::string Generator::GeneratorImpl::generateInitialisationCode(const AnalyserVariablePtr &variable) const +void Generator::GeneratorImpl::addRootFindingInfoObjectCode() { - auto initialisingVariable = variable->initialisingVariable(); - auto scalingFactor = Generator::GeneratorImpl::scalingFactor(initialisingVariable); - std::string scalingFactorCode; - - if (!areNearlyEqual(scalingFactor, 1.0)) { - scalingFactorCode = generateDoubleCode(convertToString(1.0 / scalingFactor)) + mProfile->timesString(); + if (mModelHasNlas + && !mProfile->rootFindingInfoObjectString(mModelHasOdes, mModel->hasExternalVariables()).empty()) { + mCode += newLineIfNeeded(mCode) + + mProfile->rootFindingInfoObjectString(mModelHasOdes, mModel->hasExternalVariables()); } - - return mProfile->indentString() - + generateVariableNameCode(variable->variable()) - + mProfile->equalityString() - + scalingFactorCode + generateDoubleOrConstantVariableNameCode(initialisingVariable) - + mProfile->commandSeparatorString() + "\n"; } -std::string Generator::GeneratorImpl::generateEquationCode(const AnalyserEquationPtr &equation, - std::vector &remainingEquations, - std::vector &equationsForDependencies, - bool includeComputedConstants) +void Generator::GeneratorImpl::addExternNlaSolveMethodCode() { - std::string res; - - if (std::find(remainingEquations.begin(), remainingEquations.end(), equation) != remainingEquations.end()) { - // Stop tracking the equation and its NLA siblings, if any. - // Note: we need to do this as soon as possible to avoid recursive - // calls, something that would happen if we were to do this at the - // end of this if statement. - - remainingEquations.erase(std::find(remainingEquations.begin(), remainingEquations.end(), equation)); - - for (const auto &nlaSibling : equation->nlaSiblings()) { - remainingEquations.erase(std::find(remainingEquations.begin(), remainingEquations.end(), nlaSibling)); - } - - // Generate any dependency that this equation may have. - - if (!isSomeConstant(equation, includeComputedConstants)) { - for (const auto &dependency : equation->dependencies()) { - if ((dependency->type() != AnalyserEquation::Type::ODE) - && !isSomeConstant(dependency, includeComputedConstants) - && (equationsForDependencies.empty() - || isToBeComputedAgain(dependency) - || (std::find(equationsForDependencies.begin(), equationsForDependencies.end(), dependency) != equationsForDependencies.end()))) { - res += generateEquationCode(dependency, remainingEquations, equationsForDependencies, includeComputedConstants); - } - } - } - - // Generate the equation code itself, based on the equation type. - - switch (equation->type()) { - case AnalyserEquation::Type::EXTERNAL: - for (const auto &variable : equation->variables()) { - res += mProfile->indentString() - + generateVariableNameCode(variable->variable()) - + mProfile->equalityString() - + replace(mProfile->externalVariableMethodCallString(modelHasOdes()), - "[INDEX]", convertToString(variable->index())) - + mProfile->commandSeparatorString() + "\n"; - } - - break; - case AnalyserEquation::Type::NLA: - if (!mProfile->findRootCallString(modelHasOdes()).empty()) { - res += mProfile->indentString() - + replace(mProfile->findRootCallString(modelHasOdes()), - "[INDEX]", convertToString(equation->nlaSystemIndex())); - } - - break; - default: - res += mProfile->indentString() + generateCode(equation->ast()) + mProfile->commandSeparatorString() + "\n"; - - break; - } + if (mModelHasNlas + && !mProfile->externNlaSolveMethodString().empty()) { + mCode += newLineIfNeeded(mCode) + + mProfile->externNlaSolveMethodString(); } - - return res; -} - -std::string Generator::GeneratorImpl::generateEquationCode(const AnalyserEquationPtr &equation, - std::vector &remainingEquations) -{ - std::vector dummyEquationsForComputeVariables; - - return generateEquationCode(equation, remainingEquations, dummyEquationsForComputeVariables, true); } void Generator::GeneratorImpl::addInterfaceComputeModelMethodsCode() { - auto interfaceInitialiseVariablesMethodString = mProfile->interfaceInitialiseVariablesMethodString(modelHasOdes(), - mModel->hasExternalVariables()); - std::string interfaceComputeModelMethodsCode; + auto interfaceInitialiseVariablesMethodString = mProfile->interfaceInitialiseVariablesMethodString(mModelHasOdes); + std::string code; if (!interfaceInitialiseVariablesMethodString.empty()) { - interfaceComputeModelMethodsCode += interfaceInitialiseVariablesMethodString; + code += interfaceInitialiseVariablesMethodString; } if (!mProfile->interfaceComputeComputedConstantsMethodString().empty()) { - interfaceComputeModelMethodsCode += mProfile->interfaceComputeComputedConstantsMethodString(); + code += mProfile->interfaceComputeComputedConstantsMethodString(); } auto interfaceComputeRatesMethodString = mProfile->interfaceComputeRatesMethodString(mModel->hasExternalVariables()); - if (modelHasOdes() + if (mModelHasOdes && !interfaceComputeRatesMethodString.empty()) { - interfaceComputeModelMethodsCode += interfaceComputeRatesMethodString; + code += interfaceComputeRatesMethodString; } - auto interfaceComputeVariablesMethodString = mProfile->interfaceComputeVariablesMethodString(modelHasOdes(), + auto interfaceComputeVariablesMethodString = mProfile->interfaceComputeVariablesMethodString(mModelHasOdes, mModel->hasExternalVariables()); if (!interfaceComputeVariablesMethodString.empty()) { - interfaceComputeModelMethodsCode += interfaceComputeVariablesMethodString; + code += interfaceComputeVariablesMethodString; } - if (!interfaceComputeModelMethodsCode.empty()) { - mCode += "\n"; + if (!code.empty()) { + mCode += newLineIfNeeded(mCode) + + code; } - - mCode += interfaceComputeModelMethodsCode; } -void Generator::GeneratorImpl::addImplementationInitialiseVariablesMethodCode(std::vector &remainingEquations) +void Generator::GeneratorImpl::addImplementationComputeModelMethodsCode() { - auto implementationInitialiseVariablesMethodString = mProfile->implementationInitialiseVariablesMethodString(modelHasOdes(), - mModel->hasExternalVariables()); - - if (!implementationInitialiseVariablesMethodString.empty()) { - // Initialise our constants and our algebraic variables that have an - // initial value. Also use an initial guess of zero for computed - // constants and algebraic variables computed using an NLA system. - // Note: a variable which is the only unknown in an equation, but which - // is not on its own on either the LHS or RHS of that equation - // (e.g., x = y+z with x and y known and z unknown) is (currently) - // to be computed using an NLA system for which we need an initial - // guess. We use an initial guess of zero, which is fine since - // such an NLA system has only one solution. - - std::string methodBody; - - for (const auto &variable : mModel->variables()) { - switch (variable->type()) { - case AnalyserVariable::Type::CONSTANT: - methodBody += generateInitialisationCode(variable); - - break; - case AnalyserVariable::Type::COMPUTED_CONSTANT: - case AnalyserVariable::Type::ALGEBRAIC: - if (variable->initialisingVariable() != nullptr) { - methodBody += generateInitialisationCode(variable); - } else if (variable->equation(0)->type() == AnalyserEquation::Type::NLA) { - methodBody += generateZeroInitialisationCode(variable); - } - - break; - default: // Other types we don't care about. - break; - } - } - - // Initialise our true constants. - - for (const auto &equation : mModel->equations()) { - if (equation->type() == AnalyserEquation::Type::TRUE_CONSTANT) { - methodBody += generateEquationCode(equation, remainingEquations); - } - } - - // Initialise our states. - - for (const auto &state : mModel->states()) { - methodBody += generateInitialisationCode(state); - } - - // Use an initial guess of zero for rates computed using an NLA system - // (see the note above). + auto generatorInterpreter = GeneratorInterpreter::create(mModel, mProfile, mCode); - for (const auto &state : mModel->states()) { - if (state->equation(0)->type() == AnalyserEquation::Type::NLA) { - methodBody += generateZeroInitialisationCode(state); - } - } - - // Initialise our external variables. - - if (mModel->hasExternalVariables()) { - auto equations = mModel->equations(); - std::vector remainingExternalEquations; - - std::copy_if(equations.begin(), equations.end(), - std::back_inserter(remainingExternalEquations), - [](const AnalyserEquationPtr &equation) { return equation->type() == AnalyserEquation::Type::EXTERNAL; }); - - for (const auto &equation : mModel->equations()) { - if (equation->type() == AnalyserEquation::Type::EXTERNAL) { - methodBody += generateEquationCode(equation, remainingExternalEquations); - } - } - } - - mCode += newLineIfNeeded() - + replace(implementationInitialiseVariablesMethodString, - "[CODE]", generateMethodBodyCode(methodBody)); - } -} - -void Generator::GeneratorImpl::addImplementationComputeComputedConstantsMethodCode(std::vector &remainingEquations) -{ - if (!mProfile->implementationComputeComputedConstantsMethodString().empty()) { - std::string methodBody; - - for (const auto &equation : mModel->equations()) { - if (equation->type() == AnalyserEquation::Type::VARIABLE_BASED_CONSTANT) { - methodBody += generateEquationCode(equation, remainingEquations); - } - } - - mCode += newLineIfNeeded() - + replace(mProfile->implementationComputeComputedConstantsMethodString(), - "[CODE]", generateMethodBodyCode(methodBody)); - } -} - -void Generator::GeneratorImpl::addImplementationComputeRatesMethodCode(std::vector &remainingEquations) -{ - auto implementationComputeRatesMethodString = mProfile->implementationComputeRatesMethodString(mModel->hasExternalVariables()); - - if (modelHasOdes() - && !implementationComputeRatesMethodString.empty()) { - std::string methodBody; - - for (const auto &equation : mModel->equations()) { - // A rate is computed either through an ODE equation or through an - // NLA equation in case the rate is not on its own on either the LHS - // or RHS of the equation. - - if ((equation->type() == AnalyserEquation::Type::ODE) - || ((equation->type() == AnalyserEquation::Type::NLA) - && (equation->variableCount() == 1) - && (equation->variable(0)->type() == AnalyserVariable::Type::STATE))) { - methodBody += generateEquationCode(equation, remainingEquations); - } - } - - mCode += newLineIfNeeded() - + replace(implementationComputeRatesMethodString, - "[CODE]", generateMethodBodyCode(methodBody)); - } -} - -void Generator::GeneratorImpl::addImplementationComputeVariablesMethodCode(std::vector &remainingEquations) -{ - auto implementationComputeVariablesMethodString = mProfile->implementationComputeVariablesMethodString(modelHasOdes(), - mModel->hasExternalVariables()); - - if (!implementationComputeVariablesMethodString.empty()) { - std::string methodBody; - auto equations = mModel->equations(); - std::vector newRemainingEquations {std::begin(equations), std::end(equations)}; - - for (const auto &equation : equations) { - if ((std::find(remainingEquations.begin(), remainingEquations.end(), equation) != remainingEquations.end()) - || isToBeComputedAgain(equation)) { - methodBody += generateEquationCode(equation, newRemainingEquations, remainingEquations, false); - } - } - - mCode += newLineIfNeeded() - + replace(implementationComputeVariablesMethodString, - "[CODE]", generateMethodBodyCode(methodBody)); - } + mCode = generatorInterpreter->code(); } Generator::Generator() @@ -2001,6 +631,8 @@ AnalyserModelPtr Generator::model() void Generator::setModel(const AnalyserModelPtr &model) { mPimpl->mModel = model; + mPimpl->mModelHasOdes = modelHasOdes(model); + mPimpl->mModelHasNlas = modelHasNlas(model); } std::string Generator::interfaceCode() const @@ -2034,13 +666,12 @@ std::string Generator::interfaceCode() const // Add code for the variable information related objects. - mPimpl->addVariableTypeObjectCode(); mPimpl->addVariableInfoObjectCode(); - // Add code for the interface of the information about the variable of - // integration, states and (other) variables. + // Add code for the interface of the information about the variable of integration, states, constants, computed + // constants, algebraic variables, and external variables. - mPimpl->addInterfaceVoiStateAndVariableInfoCode(); + mPimpl->addInterfaceVariableInfoCode(); // Add code for the interface to create and delete arrays. @@ -2089,15 +720,12 @@ std::string Generator::implementationCode() const // Add code for the variable information related objects. if (!mPimpl->mProfile->hasInterface()) { - mPimpl->addVariableTypeObjectCode(); mPimpl->addVariableInfoObjectCode(); } - // Add code for the implementation of the information about the variable of - // integration, states and (other) variables. + // Add code for the implementation of the information about the variable of integration, states, constants, computed + // constants, algebraic variables, and external variables. - mPimpl->addImplementationVoiInfoCode(); - mPimpl->addImplementationStateInfoCode(); mPimpl->addImplementationVariableInfoCode(); // Add code for the arithmetic and trigonometric functions. @@ -2107,55 +735,25 @@ std::string Generator::implementationCode() const // Add code for the implementation to create and delete arrays. - mPimpl->addImplementationCreateStatesArrayMethodCode(); - mPimpl->addImplementationCreateVariablesArrayMethodCode(); - mPimpl->addImplementationDeleteArrayMethodCode(); + mPimpl->addImplementationCreateDeleteArrayMethodsCode(); // Add code for the NLA solver. mPimpl->addRootFindingInfoObjectCode(); mPimpl->addExternNlaSolveMethodCode(); - mPimpl->addNlaSystemsCode(); - - // Add code for the implementation to initialise our variables. - - auto equations = mPimpl->mModel->equations(); - std::vector remainingEquations {std::begin(equations), std::end(equations)}; - - mPimpl->addImplementationInitialiseVariablesMethodCode(remainingEquations); - // Add code for the implementation to compute our computed constants. + // Add code for the implementation to compute the model. - mPimpl->addImplementationComputeComputedConstantsMethodCode(remainingEquations); - - // Add code for the implementation to compute our rates (and any variables - // on which they depend). - - mPimpl->addImplementationComputeRatesMethodCode(remainingEquations); - - // Add code for the implementation to compute our variables. - // Note: this method computes the remaining variables, i.e. the ones not - // needed to compute our rates, but also the variables that depend on - // the value of some states/rates and all the external variables. - // This method is typically called after having integrated a model, - // thus ensuring that variables that rely on the value of some - // states/rates are up to date. - - mPimpl->addImplementationComputeVariablesMethodCode(remainingEquations); + mPimpl->addImplementationComputeModelMethodsCode(); return mPimpl->mCode; } -std::string Generator::equationCode(const AnalyserEquationAstPtr &ast, - const GeneratorProfilePtr &generatorProfile) +std::string Generator::equationCode(const AnalyserEquationAstPtr &ast, const GeneratorProfilePtr &profile) { - GeneratorPtr generator = libcellml::Generator::create(); - - if (generatorProfile != nullptr) { - generator->setProfile(generatorProfile); - } + auto generatorInterpreter = GeneratorInterpreter::create(ast, profile); - return generator->mPimpl->generateCode(ast); + return generatorInterpreter->code(); } std::string Generator::equationCode(const AnalyserEquationAstPtr &ast) diff --git a/src/generator_p.h b/src/generator_p.h index 2ddb812e96..86dc616728 100644 --- a/src/generator_p.h +++ b/src/generator_p.h @@ -24,8 +24,6 @@ limitations under the License. namespace libcellml { -std::string generateDoubleCode(const std::string &value); - /** * @brief The Generator::GeneratorImpl struct. * @@ -34,43 +32,20 @@ std::string generateDoubleCode(const std::string &value); struct Generator::GeneratorImpl { AnalyserModelPtr mModel; - - std::string mCode; + bool mModelHasOdes = false; + bool mModelHasNlas = false; GeneratorProfilePtr mProfile = GeneratorProfile::create(); + std::string mCode; void reset(); - bool modelHasOdes() const; - bool modelHasNlas() const; - - AnalyserVariablePtr analyserVariable(const VariablePtr &variable) const; - - double scalingFactor(const VariablePtr &variable) const; - - bool isNegativeNumber(const AnalyserEquationAstPtr &ast) const; - - bool isRelationalOperator(const AnalyserEquationAstPtr &ast) const; - bool isAndOperator(const AnalyserEquationAstPtr &ast) const; - bool isOrOperator(const AnalyserEquationAstPtr &ast) const; - bool isXorOperator(const AnalyserEquationAstPtr &ast) const; - bool isLogicalOperator(const AnalyserEquationAstPtr &ast) const; - bool isPlusOperator(const AnalyserEquationAstPtr &ast) const; - bool isMinusOperator(const AnalyserEquationAstPtr &ast) const; - bool isTimesOperator(const AnalyserEquationAstPtr &ast) const; - bool isDivideOperator(const AnalyserEquationAstPtr &ast) const; - bool isPowerOperator(const AnalyserEquationAstPtr &ast) const; - bool isRootOperator(const AnalyserEquationAstPtr &ast) const; - bool isPiecewiseStatement(const AnalyserEquationAstPtr &ast) const; - void updateVariableInfoSizes(size_t &componentSize, size_t &nameSize, size_t &unitsSize, const AnalyserVariablePtr &variable) const; bool modifiedProfile() const; - std::string newLineIfNeeded(); - void addOriginCommentCode(); void addInterfaceHeaderCode(); @@ -80,71 +55,33 @@ struct Generator::GeneratorImpl void addStateAndVariableCountCode(bool interface = false); - void addVariableTypeObjectCode(); - std::string generateVariableInfoObjectCode(const std::string &objectString) const; void addVariableInfoObjectCode(); std::string generateVariableInfoEntryCode(const std::string &name, const std::string &units, - const std::string &component, - const std::string &type) const; + const std::string &component) const; + + void addInterfaceVariableInfoCode(); - void addInterfaceVoiStateAndVariableInfoCode(); - void addImplementationVoiInfoCode(); - void addImplementationStateInfoCode(); + void doAddImplementationVariableInfoCode(const std::string &variableInfoString, + const std::vector &variables, bool voiVariable); void addImplementationVariableInfoCode(); void addArithmeticFunctionsCode(); void addTrigonometricFunctionsCode(); void addInterfaceCreateDeleteArrayMethodsCode(); + void addImplementationCreateDeleteArrayMethodsCode(); + void addExternalVariableMethodTypeDefinitionCode(); - void addImplementationCreateStatesArrayMethodCode(); - void addImplementationCreateVariablesArrayMethodCode(); - void addImplementationDeleteArrayMethodCode(); void addRootFindingInfoObjectCode(); void addExternNlaSolveMethodCode(); - void addNlaSystemsCode(); - - std::string generateMethodBodyCode(const std::string &methodBody) const; - - std::string generateDoubleOrConstantVariableNameCode(const VariablePtr &variable) const; - std::string generateVariableNameCode(const VariablePtr &variable, - bool state = true) const; - - std::string generateOperatorCode(const std::string &op, - const AnalyserEquationAstPtr &ast) const; - std::string generateMinusUnaryCode(const AnalyserEquationAstPtr &ast) const; - std::string generateOneParameterFunctionCode(const std::string &function, - const AnalyserEquationAstPtr &ast) const; - std::string generateTwoParameterFunctionCode(const std::string &function, - const AnalyserEquationAstPtr &ast) const; - std::string generatePiecewiseIfCode(const std::string &condition, - const std::string &value) const; - std::string generatePiecewiseElseCode(const std::string &value) const; - std::string generateCode(const AnalyserEquationAstPtr &ast) const; - - bool isToBeComputedAgain(const AnalyserEquationPtr &equation) const; - bool isSomeConstant(const AnalyserEquationPtr &equation, - bool includeComputedConstants) const; - - std::string generateZeroInitialisationCode(const AnalyserVariablePtr &variable) const; - std::string generateInitialisationCode(const AnalyserVariablePtr &variable) const; - std::string generateEquationCode(const AnalyserEquationPtr &equation, - std::vector &remainingEquations, - std::vector &equationsForDependencies, - bool includeComputedConstants); - std::string generateEquationCode(const AnalyserEquationPtr &equation, - std::vector &remainingEquations); void addInterfaceComputeModelMethodsCode(); - void addImplementationInitialiseVariablesMethodCode(std::vector &remainingEquations); - void addImplementationComputeComputedConstantsMethodCode(std::vector &remainingEquations); - void addImplementationComputeRatesMethodCode(std::vector &remainingEquations); - void addImplementationComputeVariablesMethodCode(std::vector &remainingEquations); + void addImplementationComputeModelMethodsCode(); }; } // namespace libcellml diff --git a/src/generatorinterpreter.cpp b/src/generatorinterpreter.cpp new file mode 100644 index 0000000000..580737174d --- /dev/null +++ b/src/generatorinterpreter.cpp @@ -0,0 +1,1770 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include "generatorinterpreter.h" + +#include + +#include "libcellml/analyserequation.h" +#include "libcellml/analyserequationast.h" +#include "libcellml/analyservariable.h" + +#include "generatorinterpreter_p.h" +#include "interpreterstatement.h" +#include "interpreterstatement_p.h" +#include "utilities.h" + +#include "libcellml/undefines.h" + +namespace libcellml { + +GeneratorInterpreter::GeneratorInterpreterImpl::GeneratorInterpreterImpl(const AnalyserModelPtr &model, + const GeneratorProfilePtr &profile, + const std::string &code) +{ + initialise(model, profile, code); +} + +GeneratorInterpreter::GeneratorInterpreterImpl::GeneratorInterpreterImpl(const AnalyserModelPtr &model) +{ + initialise(model, mProfile, mCode); +} + +GeneratorInterpreter::GeneratorInterpreterImpl::GeneratorInterpreterImpl(const AnalyserEquationAstPtr &ast, + const GeneratorProfilePtr &profile) +{ + if (profile != nullptr) { + mProfile = profile; + } + + auto [code, dummyStatement] = generateCode(ast); + + mCode = code; +} + +void GeneratorInterpreter::GeneratorInterpreterImpl::initialise(const AnalyserModelPtr &model, + const GeneratorProfilePtr &profile, + const std::string &code) +{ + mModel = model; + mModelHasOdes = modelHasOdes(model); + mModelHasNlas = modelHasNlas(model); + mProfile = profile; + mCode = code; + + // Add code for solving the NLA systems. + + addNlaSystemsCode(); + + // Add code for the implementation to initialise our variables. + + auto equations = mModel->equations(); + std::vector remainingEquations {std::begin(equations), std::end(equations)}; + + initialiseVariables(remainingEquations); + + mInitialiseVariablesStatements = mStatements; + + // Add code for the implementation to compute our computed constants. + + mStatements.clear(); + + computeComputedConstants(remainingEquations); + + mComputeComputedConstantsStatements = mStatements; + + // Add code for the implementation to compute our rates (and any variables + // on which they depend). + + mStatements.clear(); + + computeRates(remainingEquations); + + mComputeRatesStatements = mStatements; + + // Add code for the implementation to compute our variables. + // Note: this method computes the remaining variables, i.e. the ones not needed to compute our rates, but also the + // variables that depend on the value of some states/rates and all the external variables. This method is + // typically called after having integrated a model, thus ensuring that variables that rely on the value of + // some states/rates are up to date. + + mStatements.clear(); + + computeVariables(remainingEquations); + + mComputeVariablesStatements = mStatements; +} + +bool modelHasOdes(const AnalyserModelPtr &model) +{ + switch (model->type()) { + case AnalyserModel::Type::ODE: + case AnalyserModel::Type::DAE: + return true; + default: + return false; + } +} + +bool modelHasNlas(const AnalyserModelPtr &model) +{ + switch (model->type()) { + case AnalyserModel::Type::NLA: + case AnalyserModel::Type::DAE: + return true; + default: + return false; + } +} + +AnalyserVariablePtr analyserVariable(const AnalyserModelPtr &model, const VariablePtr &variable) +{ + // Find and return the analyser variable associated with the given variable. + + AnalyserVariablePtr res; + auto modelVoi = model->voi(); + auto modelVoiVariable = (modelVoi != nullptr) ? modelVoi->variable() : nullptr; + + if ((modelVoiVariable != nullptr) + && model->areEquivalentVariables(variable, modelVoiVariable)) { + res = modelVoi; + } else { + // Normally, we would have something like: + // + // for (const auto &modelVariable : variables(model)) { + // if (model->areEquivalentVariables(variable, modelVariable->variable())) { + // res = modelVariable; + // + // break; + // } + // } + // + // but we always have variables, so llvm-cov will complain that the false branch of our for loop is never + // reached. The below code is a bit more verbose but at least it makes llvm-cov happy. + + auto modelVariables = variables(model); + auto modelVariable = modelVariables.begin(); + + do { + if (model->areEquivalentVariables(variable, (*modelVariable)->variable())) { + res = *modelVariable; + } else { + ++modelVariable; + } + } while (res == nullptr); + } + + return res; +} + +double GeneratorInterpreter::GeneratorInterpreterImpl::scalingFactor(const VariablePtr &variable) const +{ + // Return the scaling factor for the given variable, accounting for the fact that a constant may be initialised by + // another variable which initial value may be defined in a different component. + + auto analyserVariable = libcellml::analyserVariable(mModel, variable); + + if ((analyserVariable->type() == AnalyserVariable::Type::CONSTANT) + && !isCellMLReal(variable->initialValue())) { + auto initialValueVariable = owningComponent(variable)->variable(variable->initialValue()); + auto initialValueAnalyserVariable = libcellml::analyserVariable(mModel, initialValueVariable); + + if (owningComponent(variable) != owningComponent(initialValueAnalyserVariable->variable())) { + return Units::scalingFactor(initialValueVariable->units(), variable->units()); + } + } + + return Units::scalingFactor(analyserVariable->variable()->units(), variable->units()); +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isNegativeNumber(const AnalyserEquationAstPtr &ast) const +{ + if (ast->type() == AnalyserEquationAst::Type::CN) { + double doubleValue; + + convertToDouble(ast->value(), doubleValue); + + return doubleValue < 0.0; + } + + return false; +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isRelationalOperator(const AnalyserEquationAstPtr &ast) const +{ + switch (ast->type()) { + case AnalyserEquationAst::Type::EQ: + return mProfile->hasEqOperator(); + case AnalyserEquationAst::Type::NEQ: + return mProfile->hasNeqOperator(); + case AnalyserEquationAst::Type::LT: + return mProfile->hasLtOperator(); + case AnalyserEquationAst::Type::LEQ: + return mProfile->hasLeqOperator(); + case AnalyserEquationAst::Type::GT: + return mProfile->hasGtOperator(); + case AnalyserEquationAst::Type::GEQ: + return mProfile->hasGeqOperator(); + default: + return false; + } +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isAndOperator(const AnalyserEquationAstPtr &ast) const +{ + return (ast->type() == AnalyserEquationAst::Type::AND) + && mProfile->hasAndOperator(); +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isOrOperator(const AnalyserEquationAstPtr &ast) const +{ + return (ast->type() == AnalyserEquationAst::Type::OR) + && mProfile->hasOrOperator(); +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isXorOperator(const AnalyserEquationAstPtr &ast) const +{ + return (ast->type() == AnalyserEquationAst::Type::XOR) + && mProfile->hasXorOperator(); +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isLogicalOperator(const AnalyserEquationAstPtr &ast) const +{ + // Note: AnalyserEquationAst::Type::NOT is a unary logical operator, hence we don't include it here since this + // method is only used to determine whether parentheses should be added around some code. + + return isAndOperator(ast) || isOrOperator(ast) || isXorOperator(ast); +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isPlusOperator(const AnalyserEquationAstPtr &ast) const +{ + return ast->type() == AnalyserEquationAst::Type::PLUS; +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isMinusOperator(const AnalyserEquationAstPtr &ast) const +{ + return ast->type() == AnalyserEquationAst::Type::MINUS; +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isTimesOperator(const AnalyserEquationAstPtr &ast) const +{ + return ast->type() == AnalyserEquationAst::Type::TIMES; +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isDivideOperator(const AnalyserEquationAstPtr &ast) const +{ + return ast->type() == AnalyserEquationAst::Type::DIVIDE; +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isPowerOperator(const AnalyserEquationAstPtr &ast) const +{ + return (ast->type() == AnalyserEquationAst::Type::POWER) + && mProfile->hasPowerOperator(); +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isRootOperator(const AnalyserEquationAstPtr &ast) const +{ + return (ast->type() == AnalyserEquationAst::Type::ROOT) + && mProfile->hasPowerOperator(); +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isPiecewiseStatement(const AnalyserEquationAstPtr &ast) const +{ + return (ast->type() == AnalyserEquationAst::Type::PIECEWISE) + && mProfile->hasConditionalOperator(); +} + +std::string newLineIfNeeded(const std::string &code) +{ + return code.empty() ? "" : "\n"; +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generateMethodBodyCode(const std::string &methodBody) const +{ + return methodBody.empty() ? + (mProfile->emptyMethodString().empty() ? + "" : + mProfile->indentString() + mProfile->emptyMethodString()) : + methodBody; +} + +std::string generateDoubleCode(const std::string &value) +{ + if (value.find('.') != std::string::npos) { + return value; + } + + auto ePos = value.find('e'); + + if (ePos == std::string::npos) { + return value + ".0"; + } + + return value.substr(0, ePos) + ".0" + value.substr(ePos); +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generateVariableNameCode(const VariablePtr &variable, + bool rate) const +{ + // Generate some code for a variable name, but only if we have a model. If we don't have a model, it means that we + // are using the generator from the analyser, in which case we just want to return the original name of the + // variable. + + if (mModel == nullptr) { + return variable->name(); + } + + auto analyserVariable = libcellml::analyserVariable(mModel, variable); + + if (analyserVariable->type() == AnalyserVariable::Type::VARIABLE_OF_INTEGRATION) { + return mProfile->voiString(); + } + + std::string arrayName; + + if (analyserVariable->type() == AnalyserVariable::Type::STATE) { + arrayName = rate ? + mProfile->ratesArrayString() : + mProfile->statesArrayString(); + } else if (analyserVariable->type() == AnalyserVariable::Type::CONSTANT) { + arrayName = mProfile->constantsArrayString(); + } else if (analyserVariable->type() == AnalyserVariable::Type::COMPUTED_CONSTANT) { + arrayName = mProfile->computedConstantsArrayString(); + } else if (analyserVariable->type() == AnalyserVariable::Type::ALGEBRAIC) { + arrayName = mProfile->algebraicArrayString(); + } else { + arrayName = mProfile->externalArrayString(); + } + + return arrayName + mProfile->openArrayString() + convertToString(analyserVariable->index()) + mProfile->closeArrayString(); +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generateOperatorCode(const std::string &op, + const AnalyserEquationAstPtr &ast, + const InterpreterStatementPtr &statement) const +{ + // Generate the code for the left and right branches of the given AST. + + std::string res; + auto astLeftChild = ast->leftChild(); + auto astRightChild = ast->rightChild(); + auto [leftCode, leftStatement] = generateCode(astLeftChild); + auto [rightCode, rightStatement] = generateCode(astRightChild); + + if (statement != nullptr) { + statement->mPimpl->mLeftChild = leftStatement; + statement->mPimpl->mRightChild = rightStatement; + } + + // Determine whether parentheses should be added around the left and/or right piece of code, and this based on the + // precedence of the operators used in CellML, which are listed below from higher to lower precedence: + // 1. Parentheses [Left to right] + // 2. POWER (as an operator, not as a function, i.e. [Left to right] + // as in Matlab and not in C, for example) + // 3. Unary PLUS, Unary MINUS, NOT [Right to left] + // 4. TIMES, DIVIDE [Left to right] + // 5. PLUS, MINUS [Left to right] + // 6. LT, LEQ, GT, GEQ [Left to right] + // 7. EQ, NEQ [Left to right] + // 8. XOR (bitwise) [Left to right] + // 9. AND (logical) [Left to right] + // 10. OR (logical) [Left to right] + // 11. PIECEWISE (as an operator) [Right to left] + + if (isPlusOperator(ast)) { + if (isRelationalOperator(astLeftChild) + || isLogicalOperator(astLeftChild) + || isPiecewiseStatement(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } + + if (isRelationalOperator(astRightChild) + || isLogicalOperator(astRightChild) + || isPiecewiseStatement(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } + } else if (isMinusOperator(ast)) { + if (isRelationalOperator(astLeftChild) + || isLogicalOperator(astLeftChild) + || isPiecewiseStatement(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } + + if (isNegativeNumber(astRightChild) + || isRelationalOperator(astRightChild) + || isLogicalOperator(astRightChild) + || isMinusOperator(astRightChild) + || isPiecewiseStatement(astRightChild) + || (rightCode.rfind(mProfile->minusString(), 0) == 0)) { + rightCode = "(" + rightCode + ")"; + } else if (isPlusOperator(astRightChild)) { + if (astRightChild->rightChild() != nullptr) { + rightCode = "(" + rightCode + ")"; + } + } + } else if (isTimesOperator(ast)) { + if (isRelationalOperator(astLeftChild) + || isLogicalOperator(astLeftChild) + || isPiecewiseStatement(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } else if (isPlusOperator(astLeftChild) + || isMinusOperator(astLeftChild)) { + if (astLeftChild->rightChild() != nullptr) { + leftCode = "(" + leftCode + ")"; + } + } + + if (isRelationalOperator(astRightChild) + || isLogicalOperator(astRightChild) + || isPiecewiseStatement(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } else if (isPlusOperator(astRightChild) + || isMinusOperator(astRightChild)) { + if (astRightChild->rightChild() != nullptr) { + rightCode = "(" + rightCode + ")"; + } + } + } else if (isDivideOperator(ast)) { + if (isRelationalOperator(astLeftChild) + || isLogicalOperator(astLeftChild) + || isPiecewiseStatement(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } else if (isPlusOperator(astLeftChild) + || isMinusOperator(astLeftChild)) { + if (astLeftChild->rightChild() != nullptr) { + leftCode = "(" + leftCode + ")"; + } + } + + if (isRelationalOperator(astRightChild) + || isLogicalOperator(astRightChild) + || isTimesOperator(astRightChild) + || isDivideOperator(astRightChild) + || isPiecewiseStatement(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } else if (isPlusOperator(astRightChild) + || isMinusOperator(astRightChild)) { + if (astRightChild->rightChild() != nullptr) { + rightCode = "(" + rightCode + ")"; + } + } + } else if (isAndOperator(ast)) { + // Note: according to the precedence rules above, we only need to add parentheses around OR and PIECEWISE. + // However, it looks better/clearer to have some around some other operators (agreed, this is somewhat + // subjective). + + if (isRelationalOperator(astLeftChild) + || isOrOperator(astLeftChild) + || isXorOperator(astLeftChild) + || isPiecewiseStatement(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } else if (isPlusOperator(astLeftChild) + || isMinusOperator(astLeftChild)) { + if (astLeftChild->rightChild() != nullptr) { + leftCode = "(" + leftCode + ")"; + } + } else if (isPowerOperator(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } else if (isRootOperator(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } + + if (isRelationalOperator(astRightChild) + || isOrOperator(astRightChild) + || isXorOperator(astRightChild) + || isPiecewiseStatement(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } else if (isPlusOperator(astRightChild) + || isMinusOperator(astRightChild)) { + if (astRightChild->rightChild() != nullptr) { + rightCode = "(" + rightCode + ")"; + } + } else if (isPowerOperator(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } else if (isRootOperator(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } + } else if (isOrOperator(ast)) { + // Note: according to the precedence rules above, we only need to add parentheses around PIECEWISE. However, it + // looks better/clearer to have some around some other operators (agreed, this is somewhat subjective). + + if (isRelationalOperator(astLeftChild) + || isAndOperator(astLeftChild) + || isXorOperator(astLeftChild) + || isPiecewiseStatement(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } else if (isPlusOperator(astLeftChild) + || isMinusOperator(astLeftChild)) { + if (astLeftChild->rightChild() != nullptr) { + leftCode = "(" + leftCode + ")"; + } + } else if (isPowerOperator(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } else if (isRootOperator(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } + + if (isRelationalOperator(astRightChild) + || isAndOperator(astRightChild) + || isXorOperator(astRightChild) + || isPiecewiseStatement(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } else if (isPlusOperator(astRightChild) + || isMinusOperator(astRightChild)) { + if (astRightChild->rightChild() != nullptr) { + rightCode = "(" + rightCode + ")"; + } + } else if (isPowerOperator(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } else if (isRootOperator(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } + } else if (isXorOperator(ast)) { + // Note: according to the precedence rules above, we only need to add parentheses around AND, OR and PIECEWISE. + // However, it looks better/clearer to have some around some other operators (agreed, this is somewhat + // subjective). + + if (isRelationalOperator(astLeftChild) + || isAndOperator(astLeftChild) + || isOrOperator(astLeftChild) + || isPiecewiseStatement(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } else if (isPlusOperator(astLeftChild) + || isMinusOperator(astLeftChild)) { + if (astLeftChild->rightChild() != nullptr) { + leftCode = "(" + leftCode + ")"; + } + } else if (isPowerOperator(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } else if (isRootOperator(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } + + if (isRelationalOperator(astRightChild) + || isAndOperator(astRightChild) + || isOrOperator(astRightChild) + || isPiecewiseStatement(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } else if (isPlusOperator(astRightChild) + || isMinusOperator(astRightChild)) { + if (astRightChild->rightChild() != nullptr) { + rightCode = "(" + rightCode + ")"; + } + } else if (isPowerOperator(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } else if (isRootOperator(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } + } else if (isPowerOperator(ast)) { + if (isRelationalOperator(astLeftChild) + || isLogicalOperator(astLeftChild) + || isMinusOperator(astLeftChild) + || isTimesOperator(astLeftChild) + || isDivideOperator(astLeftChild) + || isPiecewiseStatement(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } else if (isPlusOperator(astLeftChild)) { + if (astLeftChild->rightChild() != nullptr) { + leftCode = "(" + leftCode + ")"; + } + } + + if (isRelationalOperator(astRightChild) + || isLogicalOperator(astRightChild) + || isMinusOperator(astLeftChild) + || isTimesOperator(astRightChild) + || isDivideOperator(astRightChild) + || isPowerOperator(astRightChild) + || isRootOperator(astRightChild) + || isPiecewiseStatement(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } else if (isPlusOperator(astRightChild)) { + if (astRightChild->rightChild() != nullptr) { + rightCode = "(" + rightCode + ")"; + } + } + } else if (isRootOperator(ast)) { + if (isRelationalOperator(astRightChild) + || isLogicalOperator(astRightChild) + || isMinusOperator(astRightChild) + || isTimesOperator(astRightChild) + || isDivideOperator(astRightChild) + || isPiecewiseStatement(astRightChild)) { + rightCode = "(" + rightCode + ")"; + } else if (isPlusOperator(astRightChild)) { + if (astRightChild->rightChild() != nullptr) { + rightCode = "(" + rightCode + ")"; + } + } + + auto astLeftChildLeftChild = astLeftChild->leftChild(); + + if (isRelationalOperator(astLeftChildLeftChild) + || isLogicalOperator(astLeftChildLeftChild) + || isMinusOperator(astLeftChildLeftChild) + || isTimesOperator(astLeftChildLeftChild) + || isDivideOperator(astLeftChildLeftChild) + || isPowerOperator(astLeftChildLeftChild) + || isRootOperator(astLeftChildLeftChild) + || isPiecewiseStatement(astLeftChildLeftChild)) { + leftCode = "(" + leftCode + ")"; + } else if (isPlusOperator(astLeftChildLeftChild)) { + if (astLeftChildLeftChild->rightChild() != nullptr) { + leftCode = "(" + leftCode + ")"; + } + } + + return rightCode + op + "(1.0/" + leftCode + ")"; + } + + return leftCode + op + rightCode; +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generateMinusUnaryCode(const AnalyserEquationAstPtr &ast, + const InterpreterStatementPtr &statement) const +{ + // Generate the code for the left branch of the given AST. + + auto astLeftChild = ast->leftChild(); + auto [leftCode, leftStatement] = generateCode(astLeftChild); + + statement->mPimpl->mLeftChild = leftStatement; + + // Determine whether parentheses should be added around the left code. + + if (isRelationalOperator(astLeftChild) + || isLogicalOperator(astLeftChild) + || isPlusOperator(astLeftChild) + || isMinusOperator(astLeftChild) + || isPiecewiseStatement(astLeftChild)) { + leftCode = "(" + leftCode + ")"; + } + + return mProfile->minusString() + leftCode; +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generateOneParameterFunctionCode(const std::string &function, + const AnalyserEquationAstPtr &ast, + const InterpreterStatementPtr &statement) const +{ + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + + if (statement != nullptr) { + statement->mPimpl->mLeftChild = leftStatement; + } + + return function + "(" + leftCode + ")"; +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generateTwoParameterFunctionCode(const std::string &function, + const AnalyserEquationAstPtr &ast, + const InterpreterStatementPtr &statement) const +{ + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + auto [rightCode, rightStatement] = generateCode(ast->rightChild()); + + if (statement != nullptr) { + statement->mPimpl->mLeftChild = leftStatement; + statement->mPimpl->mRightChild = rightStatement; + } + + return function + "(" + leftCode + ", " + rightCode + ")"; +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generatePiecewiseIfCode(const std::string &condition, + const std::string &value) const +{ + return replace(replace(mProfile->hasConditionalOperator() ? + mProfile->conditionalOperatorIfString() : + mProfile->piecewiseIfString(), + "[CONDITION]", condition), + "[IF_STATEMENT]", value); +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generatePiecewiseElseCode(const std::string &value) const +{ + return replace(mProfile->hasConditionalOperator() ? + mProfile->conditionalOperatorElseString() : + mProfile->piecewiseElseString(), + "[ELSE_STATEMENT]", value); +} + +std::tuple GeneratorInterpreter::GeneratorInterpreterImpl::generateCode(const AnalyserEquationAstPtr &ast) const +{ + // Make sure that we have an AST to work on. + + if (ast == nullptr) { + return {}; + } + + // Generate the code for the given AST. + // Note: AnalyserEquationAst::Type::BVAR is only relevant when there is no model (in which case we want to generate + // something like dx/dt, as is in the case of the analyser when we want to mention an equation) since + // otherwise we don't need to generate any code for it (since we will, instead, want to generate something + // like rates[0]). + + std::string code; + InterpreterStatementPtr statement; + + switch (ast->type()) { + case AnalyserEquationAst::Type::EQUALITY: + statement = InterpreterStatement::create(InterpreterStatement::Type::EQUALITY); + code = generateOperatorCode(mProfile->equalityString(), ast, statement); + + break; + case AnalyserEquationAst::Type::EQ: + if (mProfile->hasEqOperator()) { + statement = InterpreterStatement::create(InterpreterStatement::Type::EQ); + code = generateOperatorCode(mProfile->eqString(), ast, statement); + } else { + code = generateTwoParameterFunctionCode(mProfile->eqString(), ast); + } + + break; + case AnalyserEquationAst::Type::NEQ: + if (mProfile->hasNeqOperator()) { + statement = InterpreterStatement::create(InterpreterStatement::Type::NEQ); + code = generateOperatorCode(mProfile->neqString(), ast, statement); + } else { + code = generateTwoParameterFunctionCode(mProfile->neqString(), ast); + } + + break; + case AnalyserEquationAst::Type::LT: + if (mProfile->hasLtOperator()) { + statement = InterpreterStatement::create(InterpreterStatement::Type::LT); + code = generateOperatorCode(mProfile->ltString(), ast, statement); + } else { + code = generateTwoParameterFunctionCode(mProfile->ltString(), ast); + } + + break; + case AnalyserEquationAst::Type::LEQ: + if (mProfile->hasLeqOperator()) { + statement = InterpreterStatement::create(InterpreterStatement::Type::LEQ); + code = generateOperatorCode(mProfile->leqString(), ast, statement); + } else { + code = generateTwoParameterFunctionCode(mProfile->leqString(), ast); + } + + break; + case AnalyserEquationAst::Type::GT: + if (mProfile->hasGtOperator()) { + statement = InterpreterStatement::create(InterpreterStatement::Type::GT); + code = generateOperatorCode(mProfile->gtString(), ast, statement); + } else { + code = generateTwoParameterFunctionCode(mProfile->gtString(), ast); + } + + break; + case AnalyserEquationAst::Type::GEQ: + if (mProfile->hasGeqOperator()) { + statement = InterpreterStatement::create(InterpreterStatement::Type::GEQ); + code = generateOperatorCode(mProfile->geqString(), ast, statement); + } else { + code = generateTwoParameterFunctionCode(mProfile->geqString(), ast); + } + + break; + case AnalyserEquationAst::Type::AND: + if (mProfile->hasAndOperator()) { + statement = InterpreterStatement::create(InterpreterStatement::Type::AND); + code = generateOperatorCode(mProfile->andString(), ast, statement); + } else { + code = generateTwoParameterFunctionCode(mProfile->andString(), ast); + } + + break; + case AnalyserEquationAst::Type::OR: + if (mProfile->hasOrOperator()) { + statement = InterpreterStatement::create(InterpreterStatement::Type::OR); + code = generateOperatorCode(mProfile->orString(), ast, statement); + } else { + code = generateTwoParameterFunctionCode(mProfile->orString(), ast); + } + + break; + case AnalyserEquationAst::Type::XOR: + if (mProfile->hasXorOperator()) { + code = generateOperatorCode(mProfile->xorString(), ast); + } else { + statement = InterpreterStatement::create(InterpreterStatement::Type::XOR); + code = generateTwoParameterFunctionCode(mProfile->xorString(), ast, statement); + } + + break; + case AnalyserEquationAst::Type::NOT: + if (mProfile->hasNotOperator()) { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + + statement = InterpreterStatement::create(InterpreterStatement::Type::NOT, leftStatement); + code = mProfile->notString() + leftCode; + } else { + code = generateOneParameterFunctionCode(mProfile->notString(), ast); + } + + break; + case AnalyserEquationAst::Type::PLUS: + if (ast->rightChild() != nullptr) { + statement = InterpreterStatement::create(InterpreterStatement::Type::PLUS); + code = generateOperatorCode(mProfile->plusString(), ast, statement); + } else { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + + statement = leftStatement; + code = leftCode; + } + + break; + case AnalyserEquationAst::Type::MINUS: + statement = InterpreterStatement::create(InterpreterStatement::Type::MINUS); + + code = (ast->rightChild() != nullptr) ? + generateOperatorCode(mProfile->minusString(), ast, statement) : + generateMinusUnaryCode(ast, statement); + + break; + case AnalyserEquationAst::Type::TIMES: + statement = InterpreterStatement::create(InterpreterStatement::Type::TIMES); + code = generateOperatorCode(mProfile->timesString(), ast, statement); + + break; + case AnalyserEquationAst::Type::DIVIDE: + statement = InterpreterStatement::create(InterpreterStatement::Type::DIVIDE); + code = generateOperatorCode(mProfile->divideString(), ast, statement); + + break; + case AnalyserEquationAst::Type::POWER: { + auto [rightCode, rightStatement] = generateCode(ast->rightChild()); + double doubleValue; + auto validConversion = convertToDouble(rightCode, doubleValue); + + if (validConversion && areEqual(doubleValue, 0.5)) { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + + statement = InterpreterStatement::create(InterpreterStatement::Type::SQUARE_ROOT, + leftStatement); + code = mProfile->squareRootString() + "(" + leftCode + ")"; + } else if (validConversion && areEqual(doubleValue, 2.0) + && !mProfile->squareString().empty()) { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + + statement = InterpreterStatement::create(InterpreterStatement::Type::SQUARE, + leftStatement); + code = mProfile->squareString() + "(" + leftCode + ")"; + } else if (mProfile->hasPowerOperator()) { + code = generateOperatorCode(mProfile->powerString(), ast); + } else { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + + if (areEqual(doubleValue, 2.0)) { + // Note: we need to handle this case here since the default (C) generator profile doesn't have a square + // function (while it does have a square root function). + + statement = InterpreterStatement::create(InterpreterStatement::Type::SQUARE, + leftStatement); + } else { + statement = InterpreterStatement::create(InterpreterStatement::Type::POWER, + leftStatement, + rightStatement); + } + + code = mProfile->powerString() + "(" + leftCode + ", " + rightCode + ")"; + } + } break; + case AnalyserEquationAst::Type::ROOT: { + auto astRightChild = ast->rightChild(); + + if (astRightChild != nullptr) { + auto astLeftChild = ast->leftChild(); + auto [leftCode, leftStatement] = generateCode(astLeftChild); + double doubleValue; + auto validConversion = convertToDouble(leftCode, doubleValue); + + if (validConversion && areEqual(doubleValue, 2.0)) { + auto [rightCode, rightStatement] = generateCode(astRightChild); + + statement = InterpreterStatement::create(InterpreterStatement::Type::SQUARE_ROOT, + rightStatement); + code = mProfile->squareRootString() + "(" + rightCode + ")"; + } else if (validConversion && areEqual(doubleValue, 0.5) + && !mProfile->squareString().empty()) { + auto [rightCode, rightStatement] = generateCode(astRightChild); + + statement = InterpreterStatement::create(InterpreterStatement::Type::SQUARE, + rightStatement); + code = mProfile->squareString() + "(" + rightCode + ")"; + } else if (mProfile->hasPowerOperator()) { + code = generateOperatorCode(mProfile->powerString(), ast); + } else { + auto [rightCode, rightStatement] = generateCode(astRightChild); + auto inverseValueAst = AnalyserEquationAst::create(); + auto inverseValueStatement = InterpreterStatement::create(InterpreterStatement::Type::DIVIDE); + + inverseValueAst->setType(AnalyserEquationAst::Type::DIVIDE); + inverseValueAst->setParent(ast); + + auto inverseValueAstLeftChild = AnalyserEquationAst::create(); + + inverseValueAstLeftChild->setType(AnalyserEquationAst::Type::CN); + inverseValueAstLeftChild->setValue("1.0"); + inverseValueAstLeftChild->setParent(inverseValueAst); + + inverseValueAst->setLeftChild(inverseValueAstLeftChild); + inverseValueAst->setRightChild(astLeftChild->leftChild()); + + statement = InterpreterStatement::create(InterpreterStatement::Type::POWER, + rightStatement, + inverseValueStatement); + code = mProfile->powerString() + "(" + rightCode + ", " + generateOperatorCode(mProfile->divideString(), inverseValueAst, inverseValueStatement) + ")"; + } + } else { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + + statement = InterpreterStatement::create(InterpreterStatement::Type::SQUARE_ROOT, + leftStatement); + code = mProfile->squareRootString() + "(" + leftCode + ")"; + } + } break; + case AnalyserEquationAst::Type::ABS: + statement = InterpreterStatement::create(InterpreterStatement::Type::ABS); + code = generateOneParameterFunctionCode(mProfile->absoluteValueString(), ast, statement); + + break; + case AnalyserEquationAst::Type::EXP: + statement = InterpreterStatement::create(InterpreterStatement::Type::EXP); + code = generateOneParameterFunctionCode(mProfile->exponentialString(), ast, statement); + + break; + case AnalyserEquationAst::Type::LN: + statement = InterpreterStatement::create(InterpreterStatement::Type::LN); + code = generateOneParameterFunctionCode(mProfile->naturalLogarithmString(), ast, statement); + + break; + case AnalyserEquationAst::Type::LOG: { + auto astRightChild = ast->rightChild(); + + if (astRightChild != nullptr) { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + double doubleValue; + auto [rightCode, rightStatement] = generateCode(astRightChild); + + if (convertToDouble(leftCode, doubleValue) + && areEqual(doubleValue, 10.0)) { + statement = InterpreterStatement::create(InterpreterStatement::Type::LOG, + rightStatement); + code = mProfile->commonLogarithmString() + "(" + rightCode + ")"; + } else { + statement = InterpreterStatement::create(InterpreterStatement::Type::DIVIDE, + InterpreterStatement::create(InterpreterStatement::Type::LN, + rightStatement), + InterpreterStatement::create(InterpreterStatement::Type::LN, + leftStatement)); + code = mProfile->naturalLogarithmString() + "(" + rightCode + ")/" + mProfile->naturalLogarithmString() + "(" + leftCode + ")"; + } + } else { + statement = InterpreterStatement::create(InterpreterStatement::Type::LOG); + code = generateOneParameterFunctionCode(mProfile->commonLogarithmString(), ast, statement); + } + } break; + case AnalyserEquationAst::Type::CEILING: + statement = InterpreterStatement::create(InterpreterStatement::Type::CEILING); + code = generateOneParameterFunctionCode(mProfile->ceilingString(), ast, statement); + + break; + case AnalyserEquationAst::Type::FLOOR: + statement = InterpreterStatement::create(InterpreterStatement::Type::FLOOR); + code = generateOneParameterFunctionCode(mProfile->floorString(), ast, statement); + + break; + case AnalyserEquationAst::Type::MIN: + statement = InterpreterStatement::create(InterpreterStatement::Type::MIN); + code = generateTwoParameterFunctionCode(mProfile->minString(), ast, statement); + + break; + case AnalyserEquationAst::Type::MAX: + statement = InterpreterStatement::create(InterpreterStatement::Type::MAX); + code = generateTwoParameterFunctionCode(mProfile->maxString(), ast, statement); + + break; + case AnalyserEquationAst::Type::REM: + statement = InterpreterStatement::create(InterpreterStatement::Type::REM); + code = generateTwoParameterFunctionCode(mProfile->remString(), ast, statement); + + break; + case AnalyserEquationAst::Type::DIFF: + if (mModel != nullptr) { + auto [rightCode, rightStatement] = generateCode(ast->rightChild()); + + statement = rightStatement; + code = rightCode; + } else { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + auto [rightCode, rightStatement] = generateCode(ast->rightChild()); + + code = "d" + rightCode + "/d" + leftCode; + } + + break; + case AnalyserEquationAst::Type::SIN: + statement = InterpreterStatement::create(InterpreterStatement::Type::SIN); + code = generateOneParameterFunctionCode(mProfile->sinString(), ast, statement); + + break; + case AnalyserEquationAst::Type::COS: + statement = InterpreterStatement::create(InterpreterStatement::Type::COS); + code = generateOneParameterFunctionCode(mProfile->cosString(), ast, statement); + + break; + case AnalyserEquationAst::Type::TAN: + statement = InterpreterStatement::create(InterpreterStatement::Type::TAN); + code = generateOneParameterFunctionCode(mProfile->tanString(), ast, statement); + + break; + case AnalyserEquationAst::Type::SEC: + statement = InterpreterStatement::create(InterpreterStatement::Type::SEC); + code = generateOneParameterFunctionCode(mProfile->secString(), ast, statement); + + break; + case AnalyserEquationAst::Type::CSC: + statement = InterpreterStatement::create(InterpreterStatement::Type::CSC); + code = generateOneParameterFunctionCode(mProfile->cscString(), ast, statement); + + break; + case AnalyserEquationAst::Type::COT: + statement = InterpreterStatement::create(InterpreterStatement::Type::COT); + code = generateOneParameterFunctionCode(mProfile->cotString(), ast, statement); + + break; + case AnalyserEquationAst::Type::SINH: + statement = InterpreterStatement::create(InterpreterStatement::Type::SINH); + code = generateOneParameterFunctionCode(mProfile->sinhString(), ast, statement); + + break; + case AnalyserEquationAst::Type::COSH: + statement = InterpreterStatement::create(InterpreterStatement::Type::COSH); + code = generateOneParameterFunctionCode(mProfile->coshString(), ast, statement); + + break; + case AnalyserEquationAst::Type::TANH: + statement = InterpreterStatement::create(InterpreterStatement::Type::TANH); + code = generateOneParameterFunctionCode(mProfile->tanhString(), ast, statement); + + break; + case AnalyserEquationAst::Type::SECH: + statement = InterpreterStatement::create(InterpreterStatement::Type::SECH); + code = generateOneParameterFunctionCode(mProfile->sechString(), ast, statement); + + break; + case AnalyserEquationAst::Type::CSCH: + statement = InterpreterStatement::create(InterpreterStatement::Type::CSCH); + code = generateOneParameterFunctionCode(mProfile->cschString(), ast, statement); + + break; + case AnalyserEquationAst::Type::COTH: + statement = InterpreterStatement::create(InterpreterStatement::Type::COTH); + code = generateOneParameterFunctionCode(mProfile->cothString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ASIN: + statement = InterpreterStatement::create(InterpreterStatement::Type::ASIN); + code = generateOneParameterFunctionCode(mProfile->asinString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ACOS: + statement = InterpreterStatement::create(InterpreterStatement::Type::ACOS); + code = generateOneParameterFunctionCode(mProfile->acosString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ATAN: + statement = InterpreterStatement::create(InterpreterStatement::Type::ATAN); + code = generateOneParameterFunctionCode(mProfile->atanString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ASEC: + statement = InterpreterStatement::create(InterpreterStatement::Type::ASEC); + code = generateOneParameterFunctionCode(mProfile->asecString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ACSC: + statement = InterpreterStatement::create(InterpreterStatement::Type::ACSC); + code = generateOneParameterFunctionCode(mProfile->acscString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ACOT: + statement = InterpreterStatement::create(InterpreterStatement::Type::ACOT); + code = generateOneParameterFunctionCode(mProfile->acotString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ASINH: + statement = InterpreterStatement::create(InterpreterStatement::Type::ASINH); + code = generateOneParameterFunctionCode(mProfile->asinhString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ACOSH: + statement = InterpreterStatement::create(InterpreterStatement::Type::ACOSH); + code = generateOneParameterFunctionCode(mProfile->acoshString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ATANH: + statement = InterpreterStatement::create(InterpreterStatement::Type::ATANH); + code = generateOneParameterFunctionCode(mProfile->atanhString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ASECH: + statement = InterpreterStatement::create(InterpreterStatement::Type::ASECH); + code = generateOneParameterFunctionCode(mProfile->asechString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ACSCH: + statement = InterpreterStatement::create(InterpreterStatement::Type::ACSCH); + code = generateOneParameterFunctionCode(mProfile->acschString(), ast, statement); + + break; + case AnalyserEquationAst::Type::ACOTH: + statement = InterpreterStatement::create(InterpreterStatement::Type::ACOTH); + code = generateOneParameterFunctionCode(mProfile->acothString(), ast, statement); + + break; + case AnalyserEquationAst::Type::PIECEWISE: { + auto astLeftChild = ast->leftChild(); + auto astRightChild = ast->rightChild(); + auto [leftCode, leftStatement] = generateCode(astLeftChild); + auto [rightCode, rightStatement] = generateCode(astRightChild); + + if (astRightChild != nullptr) { + if (astRightChild->type() == AnalyserEquationAst::Type::PIECE) { + statement = InterpreterStatement::create(InterpreterStatement::Type::PIECEWISE, + leftStatement, + InterpreterStatement::create(InterpreterStatement::Type::PIECEWISE, + rightStatement, + InterpreterStatement::create(InterpreterStatement::Type::NAN))); + code = leftCode + generatePiecewiseElseCode(rightCode + generatePiecewiseElseCode(mProfile->nanString())); + } else { + statement = InterpreterStatement::create(InterpreterStatement::Type::PIECEWISE, + leftStatement, + rightStatement); + code = leftCode + generatePiecewiseElseCode(rightCode); + } + } else if (astLeftChild != nullptr) { + if (astLeftChild->type() == AnalyserEquationAst::Type::PIECE) { + statement = InterpreterStatement::create(InterpreterStatement::Type::PIECEWISE, + leftStatement, + InterpreterStatement::create(InterpreterStatement::Type::NAN)); + code = leftCode + generatePiecewiseElseCode(mProfile->nanString()); + } else { + statement = leftStatement; + code = leftCode; + } + } else { + statement = InterpreterStatement::create(InterpreterStatement::Type::NAN); + code = mProfile->nanString(); + } + } break; + case AnalyserEquationAst::Type::PIECE: { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + auto [rightCode, rightStatement] = generateCode(ast->rightChild()); + + statement = InterpreterStatement::create(InterpreterStatement::Type::PIECE, + leftStatement, + rightStatement); + code = generatePiecewiseIfCode(rightCode, leftCode); + } break; + case AnalyserEquationAst::Type::OTHERWISE: { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + + statement = leftStatement; + code = leftCode; + } break; + case AnalyserEquationAst::Type::CI: { + auto variable = ast->variable(); + bool rate = ast->parent()->type() == AnalyserEquationAst::Type::DIFF; + + if (mModel != nullptr) { + auto analyserVariable = libcellml::analyserVariable(mModel, variable); + + statement = (analyserVariable->type() == AnalyserVariable::Type::VARIABLE_OF_INTEGRATION) ? + InterpreterStatement::create(InterpreterStatement::Type::VOI) : + InterpreterStatement::create(analyserVariable, rate); + } + + code = generateVariableNameCode(variable, rate); + } break; + case AnalyserEquationAst::Type::CN: { + double doubleValue; + + convertToDouble(ast->value(), doubleValue); + + statement = InterpreterStatement::create(doubleValue); + code = generateDoubleCode(ast->value()); + } break; + case AnalyserEquationAst::Type::DEGREE: + case AnalyserEquationAst::Type::LOGBASE: { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + + statement = leftStatement; + code = leftCode; + } break; + case AnalyserEquationAst::Type::BVAR: { + auto [leftCode, leftStatement] = generateCode(ast->leftChild()); + + statement = leftStatement; + code = leftCode; + } break; + case AnalyserEquationAst::Type::TRUE: + statement = InterpreterStatement::create(InterpreterStatement::Type::TRUE); + code = mProfile->trueString(); + + break; + case AnalyserEquationAst::Type::FALSE: + statement = InterpreterStatement::create(InterpreterStatement::Type::FALSE); + code = mProfile->falseString(); + + break; + case AnalyserEquationAst::Type::E: + statement = InterpreterStatement::create(InterpreterStatement::Type::E); + code = mProfile->eString(); + + break; + case AnalyserEquationAst::Type::PI: + statement = InterpreterStatement::create(InterpreterStatement::Type::PI); + code = mProfile->piString(); + + break; + case AnalyserEquationAst::Type::INF: + statement = InterpreterStatement::create(InterpreterStatement::Type::INF); + code = mProfile->infString(); + + break; + default: // AnalyserEquationAst::Type::NAN. + statement = InterpreterStatement::create(InterpreterStatement::Type::NAN); + code = mProfile->nanString(); + + break; + } + + return {code, statement}; +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isToBeComputedAgain(const AnalyserEquationPtr &equation) const +{ + // NLA and algebraic equations that are state/rate-based and external equations are to be computed again (in the + // computeVariables() method). + + switch (equation->type()) { + case AnalyserEquation::Type::NLA: + case AnalyserEquation::Type::ALGEBRAIC: + return equation->isStateRateBased(); + case AnalyserEquation::Type::EXTERNAL: + return true; + default: + return false; + } +} + +bool GeneratorInterpreter::GeneratorInterpreterImpl::isSomeConstant(const AnalyserEquationPtr &equation, + bool includeComputedConstants) const +{ + auto type = equation->type(); + + return (type == AnalyserEquation::Type::TRUE_CONSTANT) + || (!includeComputedConstants && (type == AnalyserEquation::Type::VARIABLE_BASED_CONSTANT)); +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generateZeroInitialisationCode(const AnalyserVariablePtr &variable) +{ + bool rate = variable->type() == AnalyserVariable::Type::STATE; + + mStatements.push_back(InterpreterStatement::create(InterpreterStatement::Type::EQUALITY, + InterpreterStatement::create(variable, rate), + InterpreterStatement::create(0.0))); + + return mProfile->indentString() + + generateVariableNameCode(variable->variable(), rate) + + mProfile->equalityString() + + "0.0" + + mProfile->commandSeparatorString() + "\n"; +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generateInitialisationCode(const AnalyserVariablePtr &variable) +{ + // Determine whether the initialising variable has an initial value per se or if it is initialised by another + // variable. + + auto initialisingVariable = variable->initialisingVariable(); + InterpreterStatementPtr initialValueStatement; + std::string initialValueCode; + + if (isCellMLReal(initialisingVariable->initialValue())) { + double initialValue; + + convertToDouble(initialisingVariable->initialValue(), initialValue); + + initialValueStatement = InterpreterStatement::create(initialValue); + initialValueCode = generateDoubleCode(initialisingVariable->initialValue()); + } else { + auto initialValueVariable = owningComponent(initialisingVariable)->variable(initialisingVariable->initialValue()); + auto analyserInitialValueVariable = analyserVariable(mModel, initialValueVariable); + + initialValueStatement = InterpreterStatement::create(analyserInitialValueVariable); + initialValueCode = mProfile->constantsArrayString() + mProfile->openArrayString() + convertToString(analyserInitialValueVariable->index()) + mProfile->closeArrayString(); + } + + // Determine the scaling factor, if any. + + auto scalingFactor = GeneratorInterpreter::GeneratorInterpreterImpl::scalingFactor(initialisingVariable); + + if (!areNearlyEqual(scalingFactor, 1.0)) { + initialValueStatement = InterpreterStatement::create(InterpreterStatement::Type::TIMES, + InterpreterStatement::create(scalingFactor), + initialValueStatement); + initialValueCode = generateDoubleCode(convertToString(scalingFactor)) + mProfile->timesString() + initialValueCode; + } + + mStatements.push_back(InterpreterStatement::create(InterpreterStatement::Type::EQUALITY, + InterpreterStatement::create(variable), + initialValueStatement)); + + return mProfile->indentString() + + generateVariableNameCode(variable->variable()) + + mProfile->equalityString() + + initialValueCode + + mProfile->commandSeparatorString() + "\n"; +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generateEquationCode(const AnalyserEquationPtr &equation, + std::vector &remainingEquations, + std::vector &equationsForDependencies, + bool includeComputedConstants) +{ + std::string res; + + if (std::find(remainingEquations.begin(), remainingEquations.end(), equation) != remainingEquations.end()) { + // Stop tracking the equation and its NLA siblings, if any. + // Note: we need to do this as soon as possible to avoid recursive calls, something that would happen if we were + // to do this at the end of this if statement. + + remainingEquations.erase(std::find(remainingEquations.begin(), remainingEquations.end(), equation)); + + for (const auto &nlaSibling : equation->nlaSiblings()) { + remainingEquations.erase(std::find(remainingEquations.begin(), remainingEquations.end(), nlaSibling)); + } + + // Generate any dependency that this equation may have. + + if (!isSomeConstant(equation, includeComputedConstants)) { + for (const auto &dependency : equation->dependencies()) { + if ((dependency->type() != AnalyserEquation::Type::ODE) + && !isSomeConstant(dependency, includeComputedConstants) + && (equationsForDependencies.empty() + || isToBeComputedAgain(dependency) + || (std::find(equationsForDependencies.begin(), equationsForDependencies.end(), dependency) != equationsForDependencies.end()))) { + res += generateEquationCode(dependency, remainingEquations, equationsForDependencies, includeComputedConstants); + } + } + } + + // Generate the equation code itself, based on the equation type. + + switch (equation->type()) { + case AnalyserEquation::Type::EXTERNAL: + for (const auto &variable : variables(equation)) { + mStatements.push_back(InterpreterStatement::create(InterpreterStatement::Type::EQUALITY, + InterpreterStatement::create(variable), + InterpreterStatement::create(variable->index()))); + + res += mProfile->indentString() + + generateVariableNameCode(variable->variable()) + + mProfile->equalityString() + + replace(mProfile->externalVariableMethodCallString(mModelHasOdes), + "[INDEX]", convertToString(variable->index())) + + mProfile->commandSeparatorString() + "\n"; + } + + break; + case AnalyserEquation::Type::NLA: + if (!mProfile->findRootCallString(mModelHasOdes, mModel->hasExternalVariables()).empty()) { + res += mProfile->indentString() + + replace(mProfile->findRootCallString(mModelHasOdes, mModel->hasExternalVariables()), + "[INDEX]", convertToString(equation->nlaSystemIndex())); + } + + break; + default: + auto [code, statement] = generateCode(equation->ast()); + + mStatements.push_back(statement); + + res += mProfile->indentString() + code + mProfile->commandSeparatorString() + "\n"; + + break; + } + } + + return res; +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generateEquationCode(const AnalyserEquationPtr &equation, + std::vector &remainingEquations) +{ + std::vector dummyEquationsForComputeVariables; + + return generateEquationCode(equation, remainingEquations, dummyEquationsForComputeVariables, true); +} + +void GeneratorInterpreter::GeneratorInterpreterImpl::addNlaSystemsCode() +{ + if (mModelHasNlas + && !mProfile->objectiveFunctionMethodString(mModelHasOdes, mModel->hasExternalVariables()).empty() + && !mProfile->findRootMethodString(mModelHasOdes, mModel->hasExternalVariables()).empty() + && !mProfile->nlaSolveCallString(mModelHasOdes, mModel->hasExternalVariables()).empty()) { + // Note: only states and algebraic variables can be computed through an NLA system. Constants, computed + // constants, and external variables cannot, by definition, be computed through an NLA system. + + std::vector handledNlaEquations; + + for (const auto &equation : mModel->equations()) { + if ((equation->type() == AnalyserEquation::Type::NLA) + && (std::find(handledNlaEquations.begin(), handledNlaEquations.end(), equation) == handledNlaEquations.end())) { + std::string methodBody; + auto i = MAX_SIZE_T; + auto variables = libcellml::variables(equation); + + for (const auto &variable : variables) { + auto arrayString = (variable->type() == AnalyserVariable::Type::STATE) ? + mProfile->ratesArrayString() : + mProfile->algebraicArrayString(); + + methodBody += mProfile->indentString() + + arrayString + mProfile->openArrayString() + convertToString(variable->index()) + mProfile->closeArrayString() + + mProfile->equalityString() + + mProfile->uArrayString() + mProfile->openArrayString() + convertToString(++i) + mProfile->closeArrayString() + + mProfile->commandSeparatorString() + "\n"; + } + + methodBody += newLineIfNeeded(mCode); + + i = MAX_SIZE_T; + + auto [equationCode, equationStatement] = generateCode(equation->ast()); + + methodBody += mProfile->indentString() + + mProfile->fArrayString() + mProfile->openArrayString() + convertToString(++i) + mProfile->closeArrayString() + + mProfile->equalityString() + + equationCode + + mProfile->commandSeparatorString() + "\n"; + + handledNlaEquations.push_back(equation); + + for (const auto &nlaSibling : equation->nlaSiblings()) { + auto [nlaSiblingCode, nlaSiblingStatement] = generateCode(nlaSibling->ast()); + + methodBody += mProfile->indentString() + + mProfile->fArrayString() + mProfile->openArrayString() + convertToString(++i) + mProfile->closeArrayString() + + mProfile->equalityString() + + nlaSiblingCode + + mProfile->commandSeparatorString() + "\n"; + + handledNlaEquations.push_back(nlaSibling); + } + + mCode += newLineIfNeeded(mCode) + + replace(replace(mProfile->objectiveFunctionMethodString(mModelHasOdes, mModel->hasExternalVariables()), + "[INDEX]", convertToString(equation->nlaSystemIndex())), + "[CODE]", generateMethodBodyCode(methodBody)); + + methodBody = {}; + + i = MAX_SIZE_T; + + for (const auto &variable : variables) { + auto arrayString = (variable->type() == AnalyserVariable::Type::STATE) ? + mProfile->ratesArrayString() : + mProfile->algebraicArrayString(); + + methodBody += mProfile->indentString() + + mProfile->uArrayString() + mProfile->openArrayString() + convertToString(++i) + mProfile->closeArrayString() + + mProfile->equalityString() + + arrayString + mProfile->openArrayString() + convertToString(variable->index()) + mProfile->closeArrayString() + + mProfile->commandSeparatorString() + "\n"; + } + + auto variablesCount = variables.size(); + + methodBody += newLineIfNeeded(mCode) + + mProfile->indentString() + + replace(replace(mProfile->nlaSolveCallString(mModelHasOdes, mModel->hasExternalVariables()), + "[INDEX]", convertToString(equation->nlaSystemIndex())), + "[SIZE]", convertToString(variablesCount)); + + methodBody += newLineIfNeeded(mCode); + + i = MAX_SIZE_T; + + for (const auto &variable : variables) { + auto arrayString = (variable->type() == AnalyserVariable::Type::STATE) ? + mProfile->ratesArrayString() : + mProfile->algebraicArrayString(); + + methodBody += mProfile->indentString() + + arrayString + mProfile->openArrayString() + convertToString(variable->index()) + mProfile->closeArrayString() + + mProfile->equalityString() + + mProfile->uArrayString() + mProfile->openArrayString() + convertToString(++i) + mProfile->closeArrayString() + + mProfile->commandSeparatorString() + "\n"; + } + + mCode += newLineIfNeeded(mCode) + + replace(replace(replace(mProfile->findRootMethodString(mModelHasOdes, mModel->hasExternalVariables()), + "[INDEX]", convertToString(equation->nlaSystemIndex())), + "[SIZE]", convertToString(variablesCount)), + "[CODE]", generateMethodBodyCode(methodBody)); + } + } + } +} + +std::string GeneratorInterpreter::GeneratorInterpreterImpl::generateConstantInitialisationCode(const std::vector::iterator constant, + std::vector &remainingConstants) +{ + auto initialisingVariable = (*constant)->initialisingVariable(); + auto initialValue = initialisingVariable->initialValue(); + + if (!isCellMLReal(initialValue)) { + auto initialisingComponent = owningComponent(initialisingVariable); + auto crtConstant = std::find_if(remainingConstants.begin(), remainingConstants.end(), + [=](const AnalyserVariablePtr &av) -> bool { + return initialisingComponent->variable(initialValue) == av->variable(); + }); + + if (crtConstant != remainingConstants.end()) { + return generateConstantInitialisationCode(crtConstant, remainingConstants); + } + } + + auto code = generateInitialisationCode(*constant); + + remainingConstants.erase(constant); + + return code; +} + +void GeneratorInterpreter::GeneratorInterpreterImpl::initialiseVariables(std::vector &remainingEquations) +{ + auto implementationInitialiseVariablesMethodString = mProfile->implementationInitialiseVariablesMethodString(mModelHasOdes); + + if (!implementationInitialiseVariablesMethodString.empty()) { + // Initialise our states (after, if needed, initialising the constant on which it depends). + + std::string methodBody; + auto constants = mModel->constants(); + + for (const auto &state : mModel->states()) { + auto initialisingVariable = state->initialisingVariable(); + auto initialValue = initialisingVariable->initialValue(); + + if (!isCellMLReal(initialValue)) { + // The initial value references a constant. + + auto initialisingComponent = owningComponent(initialisingVariable); + auto constant = std::find_if(constants.begin(), constants.end(), + [=](const AnalyserVariablePtr &av) -> bool { + return initialisingComponent->variable(initialValue)->hasEquivalentVariable(av->variable()); + }); + + methodBody += generateConstantInitialisationCode(constant, constants); + } + + methodBody += generateInitialisationCode(state); + } + + // Use an initial guess of zero for rates computed using an NLA system (see the note below). + + for (const auto &state : mModel->states()) { + if (state->equation(0)->type() == AnalyserEquation::Type::NLA) { + methodBody += generateZeroInitialisationCode(state); + } + } + + // Initialise our (remaining) constants. + + while (!constants.empty()) { + methodBody += generateConstantInitialisationCode(constants.begin(), constants); + } + + // Initialise our computed constants that are initialised using an equation (e.g., x = 3 rather than x with an + // initial value of 3). + + auto equations = mModel->equations(); + + for (const auto &equation : equations) { + if (equation->type() == AnalyserEquation::Type::TRUE_CONSTANT) { + methodBody += generateEquationCode(equation, remainingEquations); + } + } + + // Initialise our algebraic variables that have an initial value. Also use an initial guess of zero for + // algebraic variables computed using an NLA system. + // Note: a variable which is the only unknown in an equation, but which is not on its own on either the LHS or + // RHS of that equation (e.g., x = y+z with x and y known and z unknown) is (currently) to be computed + // using an NLA system for which we need an initial guess. We use an initial guess of zero, which is fine + // since such an NLA system has only one solution. + + for (const auto &algebraic : mModel->algebraic()) { + if (algebraic->initialisingVariable() != nullptr) { + methodBody += generateInitialisationCode(algebraic); + } else if (algebraic->equation(0)->type() == AnalyserEquation::Type::NLA) { + methodBody += generateZeroInitialisationCode(algebraic); + } + } + + mCode += newLineIfNeeded(mCode) + + replace(implementationInitialiseVariablesMethodString, + "[CODE]", generateMethodBodyCode(methodBody)); + } +} + +void GeneratorInterpreter::GeneratorInterpreterImpl::computeComputedConstants(std::vector &remainingEquations) +{ + if (!mProfile->implementationComputeComputedConstantsMethodString().empty()) { + std::string methodBody; + + for (const auto &equation : mModel->equations()) { + if (equation->type() == AnalyserEquation::Type::VARIABLE_BASED_CONSTANT) { + methodBody += generateEquationCode(equation, remainingEquations); + } + } + + mCode += newLineIfNeeded(mCode) + + replace(mProfile->implementationComputeComputedConstantsMethodString(), + "[CODE]", generateMethodBodyCode(methodBody)); + } +} + +void GeneratorInterpreter::GeneratorInterpreterImpl::computeRates(std::vector &remainingEquations) +{ + auto implementationComputeRatesMethodString = mProfile->implementationComputeRatesMethodString(mModel->hasExternalVariables()); + + if (mModelHasOdes + && !implementationComputeRatesMethodString.empty()) { + std::string methodBody; + + for (const auto &equation : mModel->equations()) { + // A rate is computed either through an ODE equation or through an NLA equation in case the rate is not on + // its own on either the LHS or RHS of the equation. + + auto variables = libcellml::variables(equation); + + if ((equation->type() == AnalyserEquation::Type::ODE) + || ((equation->type() == AnalyserEquation::Type::NLA) + && (variables.size() == 1) + && (variables[0]->type() == AnalyserVariable::Type::STATE))) { + methodBody += generateEquationCode(equation, remainingEquations); + } + } + + mCode += newLineIfNeeded(mCode) + + replace(implementationComputeRatesMethodString, + "[CODE]", generateMethodBodyCode(methodBody)); + } +} + +void GeneratorInterpreter::GeneratorInterpreterImpl::computeVariables(std::vector &remainingEquations) +{ + auto implementationComputeVariablesMethodString = mProfile->implementationComputeVariablesMethodString(mModelHasOdes, + mModel->hasExternalVariables()); + + if (!implementationComputeVariablesMethodString.empty()) { + std::string methodBody; + auto equations = mModel->equations(); + std::vector newRemainingEquations {std::begin(equations), std::end(equations)}; + + for (const auto &equation : equations) { + if ((std::find(remainingEquations.begin(), remainingEquations.end(), equation) != remainingEquations.end()) + || isToBeComputedAgain(equation)) { + methodBody += generateEquationCode(equation, newRemainingEquations, remainingEquations, false); + } + } + + mCode += newLineIfNeeded(mCode) + + replace(implementationComputeVariablesMethodString, + "[CODE]", generateMethodBodyCode(methodBody)); + } +} + +GeneratorInterpreter::GeneratorInterpreter(const AnalyserModelPtr &model, const GeneratorProfilePtr &profile, + const std::string &code) + : mPimpl(new GeneratorInterpreterImpl(model, profile, code)) +{ +} + +GeneratorInterpreter::GeneratorInterpreter(const AnalyserModelPtr &model) + : mPimpl(new GeneratorInterpreterImpl(model)) +{ +} + +GeneratorInterpreter::GeneratorInterpreter(const AnalyserEquationAstPtr &ast, const GeneratorProfilePtr &profile) + : mPimpl(new GeneratorInterpreterImpl(ast, profile)) +{ +} + +GeneratorInterpreter::~GeneratorInterpreter() +{ + delete mPimpl; +} + +GeneratorInterpreterPtr GeneratorInterpreter::create(const AnalyserModelPtr &model, const GeneratorProfilePtr &profile, + const std::string &code) noexcept +{ + return std::shared_ptr {new GeneratorInterpreter {model, profile, code}}; +} + +GeneratorInterpreterPtr GeneratorInterpreter::create(const AnalyserModelPtr &model) noexcept +{ + return std::shared_ptr {new GeneratorInterpreter {model}}; +} + +GeneratorInterpreterPtr GeneratorInterpreter::create(const AnalyserEquationAstPtr &ast, + const GeneratorProfilePtr &profile) noexcept +{ + return std::shared_ptr {new GeneratorInterpreter {ast, profile}}; +} + +std::string GeneratorInterpreter::code() const +{ + return mPimpl->mCode; +} + +std::vector GeneratorInterpreter::initialiseVariablesStatements() const +{ + return mPimpl->mInitialiseVariablesStatements; +} + +std::vector GeneratorInterpreter::computeComputedConstantsStatements() const +{ + return mPimpl->mComputeComputedConstantsStatements; +} + +std::vector GeneratorInterpreter::computeRatesStatements() const +{ + return mPimpl->mComputeRatesStatements; +} + +std::vector GeneratorInterpreter::computeVariablesStatements() const +{ + return mPimpl->mComputeVariablesStatements; +} + +} // namespace libcellml diff --git a/src/generatorinterpreter.h b/src/generatorinterpreter.h new file mode 100644 index 0000000000..697ed1be35 --- /dev/null +++ b/src/generatorinterpreter.h @@ -0,0 +1,146 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#include "libcellml/analysermodel.h" + +#include "interpreterstatement.h" + +namespace libcellml { + +class GeneratorInterpreter; /**< Forward declaration of GeneratorInterpreter class. */ +using GeneratorInterpreterPtr = std::shared_ptr; /**< Type definition for shared GeneratorInterpreter pointer. */ + +/** + * @brief The GeneratorInterpreter class. + * + * The GeneratorInterpreter class is used by the Generator and Interpreter classes to generate the code to compute a + * model. + */ +class GeneratorInterpreter +{ +public: + ~GeneratorInterpreter(); /**< Destructor, @private. */ + GeneratorInterpreter(const GeneratorInterpreter &rhs) = delete; /**< Copy constructor, @private. */ + GeneratorInterpreter(GeneratorInterpreter &&rhs) noexcept = delete; /**< Move constructor, @private. */ + GeneratorInterpreter &operator=(GeneratorInterpreter rhs) = delete; /**< Assignment operator, @private. */ + + /** + * @brief Create an @ref GeneratorInterpreter object. + * + * Factory method to create an @ref GeneratorInterpreter. Create a generator-interpreter with:: + * + * @code + * auto interpreterStatement = libcellml::GeneratorInterpreter::create(model, profile, code); + * @endcode + * + * @param model The model for which we want to generate the code to compute. + * @param profile The profile to be used to generate the code to compute. + * @param code The code that has already been generated. + * + * @return A smart pointer to an @ref GeneratorInterpreter object. + */ + static GeneratorInterpreterPtr create(const AnalyserModelPtr &model, const GeneratorProfilePtr &profile, + const std::string &code) noexcept; + + /** + * @brief Create an @ref GeneratorInterpreter object. + * + * Factory method to create an @ref GeneratorInterpreter. Create a generator-interpreter with:: + * + * @code + * auto interpreterStatement = libcellml::GeneratorInterpreter::create(model); + * @endcode + * + * @param model The model for which we want to generate the code to compute. + * + * @return A smart pointer to an @ref GeneratorInterpreter object. + */ + static GeneratorInterpreterPtr create(const AnalyserModelPtr &model) noexcept; + + /** + * @brief Create an @ref GeneratorInterpreter object. + * + * Factory method to create an @ref GeneratorInterpreter. Create a generator-interpreter with:: + * + * @code + * auto interpreterStatement = libcellml::GeneratorInterpreter::create(profile); + * @endcode + * + * @param ast The AST for which we want to generate some code. + * @param profile The profile to be used to generate some code. + * + * @return A smart pointer to an @ref GeneratorInterpreter object. + */ + static GeneratorInterpreterPtr create(const AnalyserEquationAstPtr &ast, + const GeneratorProfilePtr &profile) noexcept; + + /** + * @brief Get the code to compute the model. + * + * Get the @c std::string code to compute the model. + * + * @return The @c std::string code to compute the model. + */ + std::string code() const; + + /** + * @brief Get the statements to initialise variables. + * + * Get the statements to initialise variables. + * + * @return The statements to initialise variables as a @c std::vector. + */ + std::vector initialiseVariablesStatements() const; + + /** + * @brief Get the statements to compute computed constants. + * + * Get the statements to compute computed constants. + * + * @return The statements to compute computed constants as a @c std::vector. + */ + std::vector computeComputedConstantsStatements() const; + + /** + * @brief Get the statements to compute rates. + * + * Get the statements to compute rates. This method is only relevant for ODE models. + * + * @return The statements to compute rates as a @c std::vector. + */ + std::vector computeRatesStatements() const; + + /** + * @brief Get the statements to compute variables. + * + * Get the statements to compute variables. + * + * @return The statements to compute variables as a @c std::vector. + */ + std::vector computeVariablesStatements() const; + +private: + GeneratorInterpreter(const AnalyserModelPtr &model, const GeneratorProfilePtr &profile, const std::string &code); /**< Constructor, @private. */ + GeneratorInterpreter(const AnalyserModelPtr &model); /**< Constructor, @private. */ + GeneratorInterpreter(const AnalyserEquationAstPtr &ast, const GeneratorProfilePtr &profile); /**< Constructor, @private. */ + + struct GeneratorInterpreterImpl; + GeneratorInterpreterImpl *mPimpl; /**< Private member to implementation pointer, @private. */ +}; + +} // namespace libcellml diff --git a/src/generatorinterpreter_p.h b/src/generatorinterpreter_p.h new file mode 100644 index 0000000000..894c60c69a --- /dev/null +++ b/src/generatorinterpreter_p.h @@ -0,0 +1,117 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#include "generatorinterpreter.h" + +#include "libcellml/generatorprofile.h" + +namespace libcellml { + +bool modelHasOdes(const AnalyserModelPtr &model); +bool modelHasNlas(const AnalyserModelPtr &model); + +AnalyserVariablePtr analyserVariable(const AnalyserModelPtr &model, const VariablePtr &variable); + +std::string newLineIfNeeded(const std::string &code); + +std::string generateDoubleCode(const std::string &value); + +/** + * @brief The GeneratorInterpreter::GeneratorInterpreterImpl struct. + * + * The private implementation for the GeneratorInterpreter class. + */ +struct GeneratorInterpreter::GeneratorInterpreterImpl +{ + AnalyserModelPtr mModel; + bool mModelHasOdes = false; + bool mModelHasNlas = false; + + GeneratorProfilePtr mProfile = GeneratorProfile::create(); + std::string mCode; + + InterpreterStatementPtrs mStatements; + InterpreterStatementPtrs mInitialiseVariablesStatements; + InterpreterStatementPtrs mComputeComputedConstantsStatements; + InterpreterStatementPtrs mComputeRatesStatements; + InterpreterStatementPtrs mComputeVariablesStatements; + + explicit GeneratorInterpreterImpl(const AnalyserModelPtr &model, const GeneratorProfilePtr &profile, + const std::string &code); + explicit GeneratorInterpreterImpl(const AnalyserModelPtr &model); + explicit GeneratorInterpreterImpl(const AnalyserEquationAstPtr &ast, const GeneratorProfilePtr &profile); + + void initialise(const AnalyserModelPtr &model, const GeneratorProfilePtr &profile, const std::string &code); + + double scalingFactor(const VariablePtr &variable) const; + + bool isNegativeNumber(const AnalyserEquationAstPtr &ast) const; + + bool isRelationalOperator(const AnalyserEquationAstPtr &ast) const; + bool isAndOperator(const AnalyserEquationAstPtr &ast) const; + bool isOrOperator(const AnalyserEquationAstPtr &ast) const; + bool isXorOperator(const AnalyserEquationAstPtr &ast) const; + bool isLogicalOperator(const AnalyserEquationAstPtr &ast) const; + bool isPlusOperator(const AnalyserEquationAstPtr &ast) const; + bool isMinusOperator(const AnalyserEquationAstPtr &ast) const; + bool isTimesOperator(const AnalyserEquationAstPtr &ast) const; + bool isDivideOperator(const AnalyserEquationAstPtr &ast) const; + bool isPowerOperator(const AnalyserEquationAstPtr &ast) const; + bool isRootOperator(const AnalyserEquationAstPtr &ast) const; + bool isPiecewiseStatement(const AnalyserEquationAstPtr &ast) const; + + std::string generateMethodBodyCode(const std::string &methodBody) const; + + std::string generateVariableNameCode(const VariablePtr &variable, + bool rate = false) const; + + std::string generateOperatorCode(const std::string &op, const AnalyserEquationAstPtr &ast, + const InterpreterStatementPtr &statement = nullptr) const; + std::string generateMinusUnaryCode(const AnalyserEquationAstPtr &ast, const InterpreterStatementPtr &statement) const; + std::string generateOneParameterFunctionCode(const std::string &function, const AnalyserEquationAstPtr &ast, + const InterpreterStatementPtr &statement = nullptr) const; + std::string generateTwoParameterFunctionCode(const std::string &function, const AnalyserEquationAstPtr &ast, + const InterpreterStatementPtr &statement = nullptr) const; + std::string generatePiecewiseIfCode(const std::string &condition, const std::string &value) const; + std::string generatePiecewiseElseCode(const std::string &value) const; + std::tuple generateCode(const AnalyserEquationAstPtr &ast) const; + + bool isToBeComputedAgain(const AnalyserEquationPtr &equation) const; + bool isSomeConstant(const AnalyserEquationPtr &equation, + bool includeComputedConstants) const; + + std::string generateZeroInitialisationCode(const AnalyserVariablePtr &variable); + std::string generateInitialisationCode(const AnalyserVariablePtr &variable); + std::string generateEquationCode(const AnalyserEquationPtr &equation, + std::vector &remainingEquations, + std::vector &equationsForDependencies, + bool includeComputedConstants); + std::string generateEquationCode(const AnalyserEquationPtr &equation, + std::vector &remainingEquations); + + void addNlaSystemsCode(); + + std::string generateConstantInitialisationCode(const std::vector::iterator constant, + std::vector &remainingConstants); + void initialiseVariables(std::vector &remainingEquations); + void computeComputedConstants(std::vector &remainingEquations); + void computeRates(std::vector &remainingEquations); + void computeVariables(std::vector &remainingEquations); +}; + +} // namespace libcellml diff --git a/src/generatorprofile.cpp b/src/generatorprofile.cpp index 1362bc3875..87843836fc 100644 --- a/src/generatorprofile.cpp +++ b/src/generatorprofile.cpp @@ -22,283 +22,11 @@ limitations under the License. #include +#include "generatorprofile_p.h" #include "utilities.h" namespace libcellml { -/** - * @brief The GeneratorProfile::GeneratorProfileImpl struct. - * - * The private implementation for the GeneratorProfile class. - */ -struct GeneratorProfile::GeneratorProfileImpl -{ - // Whether the profile is official. - - GeneratorProfile::Profile mProfile = Profile::C; - - // Whether the profile requires an interface to be generated. - - bool mHasInterface = true; - - // Equality. - - std::string mEqualityString; - - // Relational and logical operators. - - std::string mEqString; - std::string mNeqString; - std::string mLtString; - std::string mLeqString; - std::string mGtString; - std::string mGeqString; - std::string mAndString; - std::string mOrString; - std::string mXorString; - std::string mNotString; - - bool mHasEqOperator = true; - bool mHasNeqOperator = true; - bool mHasLtOperator = true; - bool mHasLeqOperator = true; - bool mHasGtOperator = true; - bool mHasGeqOperator = true; - bool mHasAndOperator = true; - bool mHasOrOperator = true; - bool mHasXorOperator = true; - bool mHasNotOperator = true; - - // Arithmetic operators. - - std::string mPlusString; - std::string mMinusString; - std::string mTimesString; - std::string mDivideString; - std::string mPowerString; - std::string mSquareRootString; - std::string mSquareString; - std::string mAbsoluteValueString; - std::string mExponentialString; - std::string mNaturalLogarithmString; - std::string mCommonLogarithmString; - std::string mCeilingString; - std::string mFloorString; - std::string mMinString; - std::string mMaxString; - std::string mRemString; - - bool mHasPowerOperator = false; - - // Trigonometric operators. - - std::string mSinString; - std::string mCosString; - std::string mTanString; - std::string mSecString; - std::string mCscString; - std::string mCotString; - std::string mSinhString; - std::string mCoshString; - std::string mTanhString; - std::string mSechString; - std::string mCschString; - std::string mCothString; - std::string mAsinString; - std::string mAcosString; - std::string mAtanString; - std::string mAsecString; - std::string mAcscString; - std::string mAcotString; - std::string mAsinhString; - std::string mAcoshString; - std::string mAtanhString; - std::string mAsechString; - std::string mAcschString; - std::string mAcothString; - - // Piecewise statement. - - std::string mConditionalOperatorIfString; - std::string mConditionalOperatorElseString; - std::string mPiecewiseIfString; - std::string mPiecewiseElseString; - - bool mHasConditionalOperator = true; - - // Constants. - - std::string mTrueString; - std::string mFalseString; - std::string mEString; - std::string mPiString; - std::string mInfString; - std::string mNanString; - - // Arithmetic functions. - - std::string mEqFunctionString; - std::string mNeqFunctionString; - std::string mLtFunctionString; - std::string mLeqFunctionString; - std::string mGtFunctionString; - std::string mGeqFunctionString; - std::string mAndFunctionString; - std::string mOrFunctionString; - std::string mXorFunctionString; - std::string mNotFunctionString; - std::string mMinFunctionString; - std::string mMaxFunctionString; - - // Trigonometric functions. - - std::string mSecFunctionString; - std::string mCscFunctionString; - std::string mCotFunctionString; - std::string mSechFunctionString; - std::string mCschFunctionString; - std::string mCothFunctionString; - std::string mAsecFunctionString; - std::string mAcscFunctionString; - std::string mAcotFunctionString; - std::string mAsechFunctionString; - std::string mAcschFunctionString; - std::string mAcothFunctionString; - - // Miscellaneous. - - std::string mCommentString; - std::string mOriginCommentString; - - std::string mInterfaceFileNameString; - - std::string mInterfaceHeaderString; - std::string mImplementationHeaderString; - - std::string mInterfaceVersionString; - std::string mImplementationVersionString; - - std::string mInterfaceLibcellmlVersionString; - std::string mImplementationLibcellmlVersionString; - - std::string mInterfaceStateCountString; - std::string mImplementationStateCountString; - - std::string mInterfaceVariableCountString; - std::string mImplementationVariableCountString; - - std::string mVariableTypeObjectFamWoevString; - std::string mVariableTypeObjectFamWevString; - std::string mVariableTypeObjectFdmWoevString; - std::string mVariableTypeObjectFdmWevString; - - std::string mVariableOfIntegrationVariableTypeString; - std::string mStateVariableTypeString; - std::string mConstantVariableTypeString; - std::string mComputedConstantVariableTypeString; - std::string mAlgebraicVariableTypeString; - std::string mExternalVariableTypeString; - - std::string mVariableInfoObjectString; - - std::string mInterfaceVoiInfoString; - std::string mImplementationVoiInfoString; - - std::string mInterfaceStateInfoString; - std::string mImplementationStateInfoString; - - std::string mInterfaceVariableInfoString; - std::string mImplementationVariableInfoString; - - std::string mVariableInfoEntryString; - - std::string mVoiString; - - std::string mStatesArrayString; - std::string mRatesArrayString; - std::string mVariablesArrayString; - - std::string mExternalVariableMethodTypeDefinitionFamString; - std::string mExternalVariableMethodTypeDefinitionFdmString; - - std::string mExternalVariableMethodCallFamString; - std::string mExternalVariableMethodCallFdmString; - - std::string mRootFindingInfoObjectFamString; - std::string mRootFindingInfoObjectFdmString; - std::string mExternNlaSolveMethodString; - std::string mFindRootCallFamString; - std::string mFindRootCallFdmString; - std::string mFindRootMethodFamString; - std::string mFindRootMethodFdmString; - std::string mNlaSolveCallFamString; - std::string mNlaSolveCallFdmString; - std::string mObjectiveFunctionMethodFamString; - std::string mObjectiveFunctionMethodFdmString; - std::string mUArrayString; - std::string mFArrayString; - - std::string mInterfaceCreateStatesArrayMethodString; - std::string mImplementationCreateStatesArrayMethodString; - - std::string mInterfaceCreateVariablesArrayMethodString; - std::string mImplementationCreateVariablesArrayMethodString; - - std::string mInterfaceDeleteArrayMethodString; - std::string mImplementationDeleteArrayMethodString; - - std::string mInterfaceInitialiseVariablesMethodFamWoevString; - std::string mImplementationInitialiseVariablesMethodFamWoevString; - - std::string mInterfaceInitialiseVariablesMethodFamWevString; - std::string mImplementationInitialiseVariablesMethodFamWevString; - - std::string mInterfaceInitialiseVariablesMethodFdmWoevString; - std::string mImplementationInitialiseVariablesMethodFdmWoevString; - - std::string mInterfaceInitialiseVariablesMethodFdmWevString; - std::string mImplementationInitialiseVariablesMethodFdmWevString; - - std::string mInterfaceComputeComputedConstantsMethodString; - std::string mImplementationComputeComputedConstantsMethodString; - - std::string mInterfaceComputeRatesMethodWoevString; - std::string mImplementationComputeRatesMethodWoevString; - - std::string mInterfaceComputeRatesMethodWevString; - std::string mImplementationComputeRatesMethodWevString; - - std::string mInterfaceComputeVariablesMethodFamWoevString; - std::string mImplementationComputeVariablesMethodFamWoevString; - - std::string mInterfaceComputeVariablesMethodFamWevString; - std::string mImplementationComputeVariablesMethodFamWevString; - - std::string mInterfaceComputeVariablesMethodFdmWoevString; - std::string mImplementationComputeVariablesMethodFdmWoevString; - - std::string mInterfaceComputeVariablesMethodFdmWevString; - std::string mImplementationComputeVariablesMethodFdmWevString; - - std::string mEmptyMethodString; - - std::string mIndentString; - - std::string mOpenArrayInitialiserString; - std::string mCloseArrayInitialiserString; - - std::string mOpenArrayString; - std::string mCloseArrayString; - - std::string mArrayElementSeparatorString; - - std::string mStringDelimiterString; - - std::string mCommandSeparatorString; - - void loadProfile(GeneratorProfile::Profile profile); -}; - void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profile profile) { mProfile = profile; @@ -351,8 +79,8 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi mCommonLogarithmString = "log10"; mCeilingString = "ceil"; mFloorString = "floor"; - mMinString = "min"; - mMaxString = "max"; + mMinString = "fmin"; + mMaxString = "fmax"; mRemString = "fmod"; mHasPowerOperator = false; @@ -395,7 +123,7 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi mTrueString = "1.0"; mFalseString = "0.0"; - mEString = convertToString(exp(1.0)); + mEString = convertToString(M_E); mPiString = convertToString(M_PI); mInfString = "INFINITY"; mNanString = "NAN"; @@ -415,14 +143,8 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi " return (x != 0.0) ^ (y != 0.0);\n" "}\n"; mNotFunctionString = ""; - mMinFunctionString = "double min(double x, double y)\n" - "{\n" - " return (x < y)?x:y;\n" - "}\n"; - mMaxFunctionString = "double max(double x, double y)\n" - "{\n" - " return (x > y)?x:y;\n" - "}\n"; + mMinFunctionString = ""; + mMaxFunctionString = ""; // Trigonometric functions. @@ -464,21 +186,15 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi "}\n"; mAsechFunctionString = "double asech(double x)\n" "{\n" - " double oneOverX = 1.0/x;\n" - "\n" - " return log(oneOverX+sqrt(oneOverX*oneOverX-1.0));\n" + " return acosh(1.0/x);\n" "}\n"; mAcschFunctionString = "double acsch(double x)\n" "{\n" - " double oneOverX = 1.0/x;\n" - "\n" - " return log(oneOverX+sqrt(oneOverX*oneOverX+1.0));\n" + " return asinh(1.0/x);\n" "}\n"; mAcothFunctionString = "double acoth(double x)\n" "{\n" - " double oneOverX = 1.0/x;\n" - "\n" - " return 0.5*log((1.0+oneOverX)/(1.0-oneOverX));\n" + " return atanh(1.0/x);\n" "}\n"; // Miscellaneous. @@ -497,7 +213,7 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi "#include \n"; mInterfaceVersionString = "extern const char VERSION[];\n"; - mImplementationVersionString = "const char VERSION[] = \"0.5.0\";\n"; + mImplementationVersionString = "const char VERSION[] = \"0.6.0\";\n"; mInterfaceLibcellmlVersionString = "extern const char LIBCELLML_VERSION[];\n"; mImplementationLibcellmlVersionString = "const char LIBCELLML_VERSION[] = \"[LIBCELLML_VERSION]\";\n"; @@ -505,48 +221,22 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi mInterfaceStateCountString = "extern const size_t STATE_COUNT;\n"; mImplementationStateCountString = "const size_t STATE_COUNT = [STATE_COUNT];\n"; - mInterfaceVariableCountString = "extern const size_t VARIABLE_COUNT;\n"; - mImplementationVariableCountString = "const size_t VARIABLE_COUNT = [VARIABLE_COUNT];\n"; - - mVariableTypeObjectFamWoevString = "typedef enum {\n" - " CONSTANT,\n" - " COMPUTED_CONSTANT,\n" - " ALGEBRAIC\n" - "} VariableType;\n"; - mVariableTypeObjectFamWevString = "typedef enum {\n" - " CONSTANT,\n" - " COMPUTED_CONSTANT,\n" - " ALGEBRAIC,\n" - " EXTERNAL\n" - "} VariableType;\n"; - mVariableTypeObjectFdmWoevString = "typedef enum {\n" - " VARIABLE_OF_INTEGRATION,\n" - " STATE,\n" - " CONSTANT,\n" - " COMPUTED_CONSTANT,\n" - " ALGEBRAIC\n" - "} VariableType;\n"; - mVariableTypeObjectFdmWevString = "typedef enum {\n" - " VARIABLE_OF_INTEGRATION,\n" - " STATE,\n" - " CONSTANT,\n" - " COMPUTED_CONSTANT,\n" - " ALGEBRAIC,\n" - " EXTERNAL\n" - "} VariableType;\n"; - - mVariableOfIntegrationVariableTypeString = "VARIABLE_OF_INTEGRATION"; - mStateVariableTypeString = "STATE"; - mConstantVariableTypeString = "CONSTANT"; - mComputedConstantVariableTypeString = "COMPUTED_CONSTANT"; - mAlgebraicVariableTypeString = "ALGEBRAIC"; - mExternalVariableTypeString = "EXTERNAL"; + mInterfaceConstantCountString = "extern const size_t CONSTANT_COUNT;\n"; + mImplementationConstantCountString = "const size_t CONSTANT_COUNT = [CONSTANT_COUNT];\n"; + + mInterfaceComputedConstantCountString = "extern const size_t COMPUTED_CONSTANT_COUNT;\n"; + mImplementationComputedConstantCountString = "const size_t COMPUTED_CONSTANT_COUNT = [COMPUTED_CONSTANT_COUNT];\n"; + + mInterfaceAlgebraicCountString = "extern const size_t ALGEBRAIC_COUNT;\n"; + mImplementationAlgebraicCountString = "const size_t ALGEBRAIC_COUNT = [ALGEBRAIC_COUNT];\n"; + + mInterfaceExternalCountString = "extern const size_t EXTERNAL_COUNT;\n"; + mImplementationExternalCountString = "const size_t EXTERNAL_COUNT = [EXTERNAL_COUNT];\n"; mVariableInfoObjectString = "typedef struct {\n" " char name[[NAME_SIZE]];\n" " char units[[UNITS_SIZE]];\n" " char component[[COMPONENT_SIZE]];\n" - " VariableType type;\n" "} VariableInfo;\n"; mInterfaceVoiInfoString = "extern const VariableInfo VOI_INFO;\n"; @@ -557,69 +247,155 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi "[CODE]" "};\n"; - mInterfaceVariableInfoString = "extern const VariableInfo VARIABLE_INFO[];\n"; - mImplementationVariableInfoString = "const VariableInfo VARIABLE_INFO[] = {\n" + mInterfaceConstantInfoString = "extern const VariableInfo CONSTANT_INFO[];\n"; + mImplementationConstantInfoString = "const VariableInfo CONSTANT_INFO[] = {\n" "[CODE]" "};\n"; - mVariableInfoEntryString = "{\"[NAME]\", \"[UNITS]\", \"[COMPONENT]\", [TYPE]}"; + mInterfaceComputedConstantInfoString = "extern const VariableInfo COMPUTED_CONSTANT_INFO[];\n"; + mImplementationComputedConstantInfoString = "const VariableInfo COMPUTED_CONSTANT_INFO[] = {\n" + "[CODE]" + "};\n"; + + mInterfaceAlgebraicInfoString = "extern const VariableInfo ALGEBRAIC_INFO[];\n"; + mImplementationAlgebraicInfoString = "const VariableInfo ALGEBRAIC_INFO[] = {\n" + "[CODE]" + "};\n"; + + mInterfaceExternalInfoString = "extern const VariableInfo EXTERNAL_INFO[];\n"; + mImplementationExternalInfoString = "const VariableInfo EXTERNAL_INFO[] = {\n" + "[CODE]" + "};\n"; + + mVariableInfoEntryString = "{\"[NAME]\", \"[UNITS]\", \"[COMPONENT]\"}"; mVoiString = "voi"; mStatesArrayString = "states"; mRatesArrayString = "rates"; - mVariablesArrayString = "variables"; - - mExternalVariableMethodTypeDefinitionFamString = "typedef double (* ExternalVariable)(double *variables, size_t index);\n"; - mExternalVariableMethodTypeDefinitionFdmString = "typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index);\n"; - - mExternalVariableMethodCallFamString = "externalVariable(variables, [INDEX])"; - mExternalVariableMethodCallFdmString = "externalVariable(voi, states, rates, variables, [INDEX])"; - - mRootFindingInfoObjectFamString = "typedef struct {\n" - " double *variables;\n" - "} RootFindingInfo;\n"; - mRootFindingInfoObjectFdmString = "typedef struct {\n" - " double voi;\n" - " double *states;\n" - " double *rates;\n" - " double *variables;\n" - "} RootFindingInfo;\n"; + mConstantsArrayString = "constants"; + mComputedConstantsArrayString = "computedConstants"; + mAlgebraicArrayString = "algebraic"; + mExternalArrayString = "externals"; + + mExternalVariableMethodTypeDefinitionFamString = "typedef double (* ExternalVariable)(double *constants, double *computedConstants, double *algebraic, double *externals, size_t index);\n"; + mExternalVariableMethodTypeDefinitionFdmString = "typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index);\n"; + + mExternalVariableMethodCallFamString = "externalVariable(constants, computedConstants, algebraic, externals, [INDEX])"; + mExternalVariableMethodCallFdmString = "externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, [INDEX])"; + + mRootFindingInfoObjectFamWoevString = "typedef struct {\n" + " double *constants;\n" + " double *computedConstants;\n" + " double *algebraic;\n" + "} RootFindingInfo;\n"; + mRootFindingInfoObjectFamWevString = "typedef struct {\n" + " double *constants;\n" + " double *computedConstants;\n" + " double *algebraic;\n" + " double *externals;\n" + "} RootFindingInfo;\n"; + mRootFindingInfoObjectFdmWoevString = "typedef struct {\n" + " double voi;\n" + " double *states;\n" + " double *rates;\n" + " double *constants;\n" + " double *computedConstants;\n" + " double *algebraic;\n" + "} RootFindingInfo;\n"; + mRootFindingInfoObjectFdmWevString = "typedef struct {\n" + " double voi;\n" + " double *states;\n" + " double *rates;\n" + " double *constants;\n" + " double *computedConstants;\n" + " double *algebraic;\n" + " double *externals;\n" + "} RootFindingInfo;\n"; + mExternNlaSolveMethodString = "extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *),\n" " double *u, size_t n, void *data);\n"; - mFindRootCallFamString = "findRoot[INDEX](variables);\n"; - mFindRootCallFdmString = "findRoot[INDEX](voi, states, rates, variables);\n"; - mFindRootMethodFamString = "void findRoot[INDEX](double *variables)\n" - "{\n" - " RootFindingInfo rfi = { variables };\n" - " double u[[SIZE]];\n" - "\n" - "[CODE]" - "}\n"; - mFindRootMethodFdmString = "void findRoot[INDEX](double voi, double *states, double *rates, double *variables)\n" - "{\n" - " RootFindingInfo rfi = { voi, states, rates, variables };\n" - " double u[[SIZE]];\n" - "\n" - "[CODE]" - "}\n"; - mNlaSolveCallFamString = "nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n"; - mNlaSolveCallFdmString = "nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n"; - mObjectiveFunctionMethodFamString = "void objectiveFunction[INDEX](double *u, double *f, void *data)\n" - "{\n" - " double *variables = ((RootFindingInfo *) data)->variables;\n" - "\n" - "[CODE]" - "}\n"; - mObjectiveFunctionMethodFdmString = "void objectiveFunction[INDEX](double *u, double *f, void *data)\n" - "{\n" - " double voi = ((RootFindingInfo *) data)->voi;\n" - " double *states = ((RootFindingInfo *) data)->states;\n" - " double *rates = ((RootFindingInfo *) data)->rates;\n" - " double *variables = ((RootFindingInfo *) data)->variables;\n" - "\n" - "[CODE]" - "}\n"; + + mFindRootCallFamWoevString = "findRoot[INDEX](constants, computedConstants, algebraic);\n"; + mFindRootCallFamWevString = "findRoot[INDEX](constants, computedConstants, algebraic, externals);\n"; + mFindRootCallFdmWoevString = "findRoot[INDEX](voi, states, rates, constants, computedConstants, algebraic);\n"; + mFindRootCallFdmWevString = "findRoot[INDEX](voi, states, rates, constants, computedConstants, algebraic, externals);\n"; + + mFindRootMethodFamWoevString = "void findRoot[INDEX](double *constants, double *computedConstants, double *algebraic)\n" + "{\n" + " RootFindingInfo rfi = { constants, computedConstants, algebraic };\n" + " double u[[SIZE]];\n" + "\n" + "[CODE]" + "}\n"; + mFindRootMethodFamWevString = "void findRoot[INDEX](double *constants, double *computedConstants, double *algebraic, double *externals)\n" + "{\n" + " RootFindingInfo rfi = { constants, computedConstants, algebraic, externals };\n" + " double u[[SIZE]];\n" + "\n" + "[CODE]" + "}\n"; + mFindRootMethodFdmWoevString = "void findRoot[INDEX](double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n" + "{\n" + " RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic };\n" + " double u[[SIZE]];\n" + "\n" + "[CODE]" + "}\n"; + mFindRootMethodFdmWevString = "void findRoot[INDEX](double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals)\n" + "{\n" + " RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals };\n" + " double u[[SIZE]];\n" + "\n" + "[CODE]" + "}\n"; + + mNlaSolveCallFamWoevString = "nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n"; + mNlaSolveCallFamWevString = "nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n"; + mNlaSolveCallFdmWoevString = "nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n"; + mNlaSolveCallFdmWevString = "nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n"; + + mObjectiveFunctionMethodFamWoevString = "void objectiveFunction[INDEX](double *u, double *f, void *data)\n" + "{\n" + " double *constants = ((RootFindingInfo *) data)->constants;\n" + " double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n" + " double *algebraic = ((RootFindingInfo *) data)->algebraic;\n" + "\n" + "[CODE]" + "}\n"; + mObjectiveFunctionMethodFamWevString = "void objectiveFunction[INDEX](double *u, double *f, void *data)\n" + "{\n" + " double *constants = ((RootFindingInfo *) data)->constants;\n" + " double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n" + " double *algebraic = ((RootFindingInfo *) data)->algebraic;\n" + " double *externals = ((RootFindingInfo *) data)->externals;\n" + "\n" + "[CODE]" + "}\n"; + mObjectiveFunctionMethodFdmWoevString = "void objectiveFunction[INDEX](double *u, double *f, void *data)\n" + "{\n" + " double voi = ((RootFindingInfo *) data)->voi;\n" + " double *states = ((RootFindingInfo *) data)->states;\n" + " double *rates = ((RootFindingInfo *) data)->rates;\n" + " double *constants = ((RootFindingInfo *) data)->constants;\n" + " double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n" + " double *algebraic = ((RootFindingInfo *) data)->algebraic;\n" + "\n" + "[CODE]" + "}\n"; + mObjectiveFunctionMethodFdmWevString = "void objectiveFunction[INDEX](double *u, double *f, void *data)\n" + "{\n" + " double voi = ((RootFindingInfo *) data)->voi;\n" + " double *states = ((RootFindingInfo *) data)->states;\n" + " double *rates = ((RootFindingInfo *) data)->rates;\n" + " double *constants = ((RootFindingInfo *) data)->constants;\n" + " double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n" + " double *algebraic = ((RootFindingInfo *) data)->algebraic;\n" + " double *externals = ((RootFindingInfo *) data)->externals;\n" + "\n" + "[CODE]" + "}\n"; + mUArrayString = "u"; mFArrayString = "f"; @@ -635,12 +411,48 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi " return res;\n" "}\n"; - mInterfaceCreateVariablesArrayMethodString = "double * createVariablesArray();\n"; - mImplementationCreateVariablesArrayMethodString = "double * createVariablesArray()\n" + mInterfaceCreateConstantsArrayMethodString = "double * createConstantsArray();\n"; + mImplementationCreateConstantsArrayMethodString = "double * createConstantsArray()\n" "{\n" - " double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double));\n" + " double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double));\n" "\n" - " for (size_t i = 0; i < VARIABLE_COUNT; ++i) {\n" + " for (size_t i = 0; i < CONSTANT_COUNT; ++i) {\n" + " res[i] = NAN;\n" + " }\n" + "\n" + " return res;\n" + "}\n"; + + mInterfaceCreateComputedConstantsArrayMethodString = "double * createComputedConstantsArray();\n"; + mImplementationCreateComputedConstantsArrayMethodString = "double * createComputedConstantsArray()\n" + "{\n" + " double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double));\n" + "\n" + " for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) {\n" + " res[i] = NAN;\n" + " }\n" + "\n" + " return res;\n" + "}\n"; + + mInterfaceCreateAlgebraicArrayMethodString = "double * createAlgebraicArray();\n"; + mImplementationCreateAlgebraicArrayMethodString = "double * createAlgebraicArray()\n" + "{\n" + " double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double));\n" + "\n" + " for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) {\n" + " res[i] = NAN;\n" + " }\n" + "\n" + " return res;\n" + "}\n"; + + mInterfaceCreateExternalsArrayMethodString = "double * createExternalsArray();\n"; + mImplementationCreateExternalsArrayMethodString = "double * createExternalsArray()\n" + "{\n" + " double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double));\n" + "\n" + " for (size_t i = 0; i < EXTERNAL_COUNT; ++i) {\n" " res[i] = NAN;\n" " }\n" "\n" @@ -653,66 +465,54 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi " free(array);\n" "}\n"; - mInterfaceInitialiseVariablesMethodFamWoevString = "void initialiseVariables(double *variables);\n"; - mImplementationInitialiseVariablesMethodFamWoevString = "void initialiseVariables(double *variables)\n" - "{\n" - "[CODE]" - "}\n"; - - mInterfaceInitialiseVariablesMethodFamWevString = "void initialiseVariables(double *variables, ExternalVariable externalVariable);\n"; - mImplementationInitialiseVariablesMethodFamWevString = "void initialiseVariables(double *variables, ExternalVariable externalVariable)\n" - "{\n" - "[CODE]" - "}\n"; - - mInterfaceInitialiseVariablesMethodFdmWoevString = "void initialiseVariables(double *states, double *rates, double *variables);\n"; - mImplementationInitialiseVariablesMethodFdmWoevString = "void initialiseVariables(double *states, double *rates, double *variables)\n" - "{\n" - "[CODE]" - "}\n"; - - mInterfaceInitialiseVariablesMethodFdmWevString = "void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable);\n"; - mImplementationInitialiseVariablesMethodFdmWevString = "void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable)\n" - "{\n" - "[CODE]" - "}\n"; - - mInterfaceComputeComputedConstantsMethodString = "void computeComputedConstants(double *variables);\n"; - mImplementationComputeComputedConstantsMethodString = "void computeComputedConstants(double *variables)\n" + mInterfaceInitialiseVariablesMethodFamString = "void initialiseVariables(double *constants, double *computedConstants, double *algebraic);\n"; + mImplementationInitialiseVariablesMethodFamString = "void initialiseVariables(double *constants, double *computedConstants, double *algebraic)\n" + "{\n" + "[CODE]" + "}\n"; + + mInterfaceInitialiseVariablesMethodFdmString = "void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic);\n"; + mImplementationInitialiseVariablesMethodFdmString = "void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n" + "{\n" + "[CODE]" + "}\n"; + + mInterfaceComputeComputedConstantsMethodString = "void computeComputedConstants(double *constants, double *computedConstants);\n"; + mImplementationComputeComputedConstantsMethodString = "void computeComputedConstants(double *constants, double *computedConstants)\n" "{\n" "[CODE]" "}\n"; - mInterfaceComputeRatesMethodWoevString = "void computeRates(double voi, double *states, double *rates, double *variables);\n"; - mImplementationComputeRatesMethodWoevString = "void computeRates(double voi, double *states, double *rates, double *variables)\n{\n" + mInterfaceComputeRatesMethodWoevString = "void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic);\n"; + mImplementationComputeRatesMethodWoevString = "void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n{\n" "[CODE]" "}\n"; - mInterfaceComputeRatesMethodWevString = "void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable);\n"; - mImplementationComputeRatesMethodWevString = "void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable)\n{\n" + mInterfaceComputeRatesMethodWevString = "void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable);\n"; + mImplementationComputeRatesMethodWevString = "void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable)\n{\n" "[CODE]" "}\n"; - mInterfaceComputeVariablesMethodFamWoevString = "void computeVariables(double *variables);\n"; - mImplementationComputeVariablesMethodFamWoevString = "void computeVariables(double *variables)\n" + mInterfaceComputeVariablesMethodFamWoevString = "void computeVariables(double *constants, double *computedConstants, double *algebraic);\n"; + mImplementationComputeVariablesMethodFamWoevString = "void computeVariables(double *constants, double *computedConstants, double *algebraic)\n" "{\n" "[CODE]" "}\n"; - mInterfaceComputeVariablesMethodFamWevString = "void computeVariables(double *variables, ExternalVariable externalVariable);\n"; - mImplementationComputeVariablesMethodFamWevString = "void computeVariables(double *variables, ExternalVariable externalVariable)\n" + mInterfaceComputeVariablesMethodFamWevString = "void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable);\n"; + mImplementationComputeVariablesMethodFamWevString = "void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable)\n" "{\n" "[CODE]" "}\n"; - mInterfaceComputeVariablesMethodFdmWoevString = "void computeVariables(double voi, double *states, double *rates, double *variables);\n"; - mImplementationComputeVariablesMethodFdmWoevString = "void computeVariables(double voi, double *states, double *rates, double *variables)\n" + mInterfaceComputeVariablesMethodFdmWoevString = "void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic);\n"; + mImplementationComputeVariablesMethodFdmWoevString = "void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n" "{\n" "[CODE]" "}\n"; - mInterfaceComputeVariablesMethodFdmWevString = "void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable);\n"; - mImplementationComputeVariablesMethodFdmWevString = "void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable)\n" + mInterfaceComputeVariablesMethodFdmWevString = "void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable);\n"; + mImplementationComputeVariablesMethodFdmWevString = "void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable)\n" "{\n" "[CODE]" "}\n"; @@ -824,7 +624,7 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi mTrueString = "1.0"; mFalseString = "0.0"; - mEString = convertToString(exp(1.0)); + mEString = convertToString(M_E); mPiString = convertToString(M_PI); mInfString = "inf"; mNanString = "nan"; @@ -899,19 +699,13 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi " return atan(1.0/x)\n"; mAsechFunctionString = "\n" "def asech(x):\n" - " one_over_x = 1.0/x\n" - "\n" - " return log(one_over_x+sqrt(one_over_x*one_over_x-1.0))\n"; + " return acosh(1.0/x)\n"; mAcschFunctionString = "\n" "def acsch(x):\n" - " one_over_x = 1.0/x\n" - "\n" - " return log(one_over_x+sqrt(one_over_x*one_over_x+1.0))\n"; + " return asinh(1.0/x)\n"; mAcothFunctionString = "\n" "def acoth(x):\n" - " one_over_x = 1.0/x\n" - "\n" - " return 0.5*log((1.0+one_over_x)/(1.0-one_over_x))\n"; + " return atanh(1.0/x)\n"; // Miscellaneous. @@ -926,7 +720,7 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi "\n"; mInterfaceVersionString = ""; - mImplementationVersionString = "__version__ = \"0.4.0\"\n"; + mImplementationVersionString = "__version__ = \"0.5.0\"\n"; mInterfaceLibcellmlVersionString = ""; mImplementationLibcellmlVersionString = "LIBCELLML_VERSION = \"[LIBCELLML_VERSION]\"\n"; @@ -934,46 +728,17 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi mInterfaceStateCountString = ""; mImplementationStateCountString = "STATE_COUNT = [STATE_COUNT]\n"; - mInterfaceVariableCountString = ""; - mImplementationVariableCountString = "VARIABLE_COUNT = [VARIABLE_COUNT]\n"; - - mVariableTypeObjectFamWoevString = "\n" - "class VariableType(Enum):\n" - " CONSTANT = 0\n" - " COMPUTED_CONSTANT = 1\n" - " ALGEBRAIC = 2\n" - "\n"; - mVariableTypeObjectFamWevString = "\n" - "class VariableType(Enum):\n" - " CONSTANT = 0\n" - " COMPUTED_CONSTANT = 1\n" - " ALGEBRAIC = 2\n" - " EXTERNAL = 3\n" - "\n"; - mVariableTypeObjectFdmWoevString = "\n" - "class VariableType(Enum):\n" - " VARIABLE_OF_INTEGRATION = 0\n" - " STATE = 1\n" - " CONSTANT = 2\n" - " COMPUTED_CONSTANT = 3\n" - " ALGEBRAIC = 4\n" - "\n"; - mVariableTypeObjectFdmWevString = "\n" - "class VariableType(Enum):\n" - " VARIABLE_OF_INTEGRATION = 0\n" - " STATE = 1\n" - " CONSTANT = 2\n" - " COMPUTED_CONSTANT = 3\n" - " ALGEBRAIC = 4\n" - " EXTERNAL = 5\n" - "\n"; - - mVariableOfIntegrationVariableTypeString = "VariableType.VARIABLE_OF_INTEGRATION"; - mStateVariableTypeString = "VariableType.STATE"; - mConstantVariableTypeString = "VariableType.CONSTANT"; - mComputedConstantVariableTypeString = "VariableType.COMPUTED_CONSTANT"; - mAlgebraicVariableTypeString = "VariableType.ALGEBRAIC"; - mExternalVariableTypeString = "VariableType.EXTERNAL"; + mInterfaceConstantCountString = ""; + mImplementationConstantCountString = "CONSTANT_COUNT = [CONSTANT_COUNT]\n"; + + mInterfaceComputedConstantCountString = ""; + mImplementationComputedConstantCountString = "COMPUTED_CONSTANT_COUNT = [COMPUTED_CONSTANT_COUNT]\n"; + + mInterfaceAlgebraicCountString = ""; + mImplementationAlgebraicCountString = "ALGEBRAIC_COUNT = [ALGEBRAIC_COUNT]\n"; + + mInterfaceExternalCountString = ""; + mImplementationExternalCountString = "EXTERNAL_COUNT = [EXTERNAL_COUNT]\n"; mVariableInfoObjectString = ""; @@ -985,57 +750,120 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi "[CODE]" "]\n"; - mInterfaceVariableInfoString = ""; - mImplementationVariableInfoString = "VARIABLE_INFO = [\n" + mInterfaceConstantInfoString = ""; + mImplementationConstantInfoString = "CONSTANT_INFO = [\n" "[CODE]" "]\n"; - mVariableInfoEntryString = "{\"name\": \"[NAME]\", \"units\": \"[UNITS]\", \"component\": \"[COMPONENT]\", \"type\": [TYPE]}"; + mInterfaceComputedConstantInfoString = ""; + mImplementationComputedConstantInfoString = "COMPUTED_CONSTANT_INFO = [\n" + "[CODE]" + "]\n"; + + mInterfaceAlgebraicInfoString = ""; + mImplementationAlgebraicInfoString = "ALGEBRAIC_INFO = [\n" + "[CODE]" + "]\n"; + + mInterfaceExternalInfoString = ""; + mImplementationExternalInfoString = "EXTERNAL_INFO = [\n" + "[CODE]" + "]\n"; + + mVariableInfoEntryString = "{\"name\": \"[NAME]\", \"units\": \"[UNITS]\", \"component\": \"[COMPONENT]\"}"; mVoiString = "voi"; mStatesArrayString = "states"; mRatesArrayString = "rates"; - mVariablesArrayString = "variables"; + mConstantsArrayString = "constants"; + mComputedConstantsArrayString = "computed_constants"; + mAlgebraicArrayString = "algebraic"; + mExternalArrayString = "externals"; mExternalVariableMethodTypeDefinitionFamString = ""; mExternalVariableMethodTypeDefinitionFdmString = ""; - mExternalVariableMethodCallFamString = "external_variable(variables, [INDEX])"; - mExternalVariableMethodCallFdmString = "external_variable(voi, states, rates, variables, [INDEX])"; + mExternalVariableMethodCallFamString = "external_variable(constants, computed_constants, algebraic, externals, [INDEX])"; + mExternalVariableMethodCallFdmString = "external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, [INDEX])"; + + mRootFindingInfoObjectFamWoevString = ""; + mRootFindingInfoObjectFamWevString = ""; + mRootFindingInfoObjectFdmWoevString = ""; + mRootFindingInfoObjectFdmWevString = ""; - mRootFindingInfoObjectFamString = ""; - mRootFindingInfoObjectFdmString = ""; mExternNlaSolveMethodString = "\n" "from nlasolver import nla_solve" "\n"; - mFindRootCallFamString = "find_root_[INDEX](variables)\n"; - mFindRootCallFdmString = "find_root_[INDEX](voi, states, rates, variables)\n"; - mFindRootMethodFamString = "\n" - "def find_root_[INDEX](variables):\n" - " u = [nan]*[SIZE]\n" - "\n" - "[CODE]"; - mFindRootMethodFdmString = "\n" - "def find_root_[INDEX](voi, states, rates, variables):\n" - " u = [nan]*[SIZE]\n" - "\n" - "[CODE]"; - mNlaSolveCallFamString = "u = nla_solve(objective_function_[INDEX], u, [SIZE], [variables])\n"; - mNlaSolveCallFdmString = "u = nla_solve(objective_function_[INDEX], u, [SIZE], [voi, states, rates, variables])\n"; - mObjectiveFunctionMethodFamString = "\n" - "def objective_function_[INDEX](u, f, data):\n" - " variables = data[0]\n" - "\n" - "[CODE]"; - mObjectiveFunctionMethodFdmString = "\n" - "def objective_function_[INDEX](u, f, data):\n" - " voi = data[0]\n" - " states = data[1]\n" - " rates = data[2]\n" - " variables = data[3]\n" - "\n" - "[CODE]"; + + mFindRootCallFamWoevString = "find_root_[INDEX](constants, computed_constants, algebraic)\n"; + mFindRootCallFamWevString = "find_root_[INDEX](constants, computed_constants, algebraic, externals)\n"; + mFindRootCallFdmWoevString = "find_root_[INDEX](voi, states, rates, constants, computed_constants, algebraic)\n"; + mFindRootCallFdmWevString = "find_root_[INDEX](voi, states, rates, constants, computed_constants, algebraic, externals)\n"; + + mFindRootMethodFamWoevString = "\n" + "def find_root_[INDEX](constants, computed_constants, algebraic):\n" + " u = [nan]*[SIZE]\n" + "\n" + "[CODE]"; + mFindRootMethodFamWevString = "\n" + "def find_root_[INDEX](constants, computed_constants, algebraic, externals):\n" + " u = [nan]*[SIZE]\n" + "\n" + "[CODE]"; + mFindRootMethodFdmWoevString = "\n" + "def find_root_[INDEX](voi, states, rates, constants, computed_constants, algebraic):\n" + " u = [nan]*[SIZE]\n" + "\n" + "[CODE]"; + mFindRootMethodFdmWevString = "\n" + "def find_root_[INDEX](voi, states, rates, constants, computed_constants, algebraic, externals):\n" + " u = [nan]*[SIZE]\n" + "\n" + "[CODE]"; + + mNlaSolveCallFamWoevString = "u = nla_solve(objective_function_[INDEX], u, [SIZE], [constants, computed_constants, algebraic])\n"; + mNlaSolveCallFamWevString = "u = nla_solve(objective_function_[INDEX], u, [SIZE], [constants, computed_constants, algebraic, externals])\n"; + mNlaSolveCallFdmWoevString = "u = nla_solve(objective_function_[INDEX], u, [SIZE], [voi, states, rates, constants, computed_constants, algebraic])\n"; + mNlaSolveCallFdmWevString = "u = nla_solve(objective_function_[INDEX], u, [SIZE], [voi, states, rates, constants, computed_constants, algebraic, externals])\n"; + + mObjectiveFunctionMethodFamWoevString = "\n" + "def objective_function_[INDEX](u, f, data):\n" + " constants = data[0]\n" + " computed_constants = data[1]\n" + " algebraic = data[2]\n" + "\n" + "[CODE]"; + mObjectiveFunctionMethodFamWevString = "\n" + "def objective_function_[INDEX](u, f, data):\n" + " constants = data[0]\n" + " computed_constants = data[1]\n" + " algebraic = data[2]\n" + " externals = data[3]\n" + "\n" + "[CODE]"; + mObjectiveFunctionMethodFdmWoevString = "\n" + "def objective_function_[INDEX](u, f, data):\n" + " voi = data[0]\n" + " states = data[1]\n" + " rates = data[2]\n" + " constants = data[3]\n" + " computed_constants = data[4]\n" + " algebraic = data[5]\n" + "\n" + "[CODE]"; + mObjectiveFunctionMethodFdmWevString = "\n" + "def objective_function_[INDEX](u, f, data):\n" + " voi = data[0]\n" + " states = data[1]\n" + " rates = data[2]\n" + " constants = data[3]\n" + " computed_constants = data[4]\n" + " algebraic = data[5]\n" + " externals = data[6]\n" + "\n" + "[CODE]"; + mUArrayString = "u"; mFArrayString = "f"; @@ -1044,67 +872,72 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi "def create_states_array():\n" " return [nan]*STATE_COUNT\n"; - mInterfaceCreateVariablesArrayMethodString = ""; - mImplementationCreateVariablesArrayMethodString = "\n" - "def create_variables_array():\n" - " return [nan]*VARIABLE_COUNT\n"; + mInterfaceCreateConstantsArrayMethodString = ""; + mImplementationCreateConstantsArrayMethodString = "\n" + "def create_constants_array():\n" + " return [nan]*CONSTANT_COUNT\n"; - mInterfaceDeleteArrayMethodString = ""; - mImplementationDeleteArrayMethodString = ""; + mInterfaceCreateComputedConstantsArrayMethodString = ""; + mImplementationCreateComputedConstantsArrayMethodString = "\n" + "def create_computed_constants_array():\n" + " return [nan]*COMPUTED_CONSTANT_COUNT\n"; - mInterfaceInitialiseVariablesMethodFamWoevString = ""; - mImplementationInitialiseVariablesMethodFamWoevString = "\n" - "def initialise_variables(variables):\n" - "[CODE]"; + mInterfaceCreateAlgebraicArrayMethodString = ""; + mImplementationCreateAlgebraicArrayMethodString = "\n" + "def create_algebraic_array():\n" + " return [nan]*ALGEBRAIC_COUNT\n"; - mInterfaceInitialiseVariablesMethodFamWevString = ""; - mImplementationInitialiseVariablesMethodFamWevString = "\n" - "def initialise_variables(variables, external_variable):\n" - "[CODE]"; + mInterfaceCreateExternalsArrayMethodString = ""; + mImplementationCreateExternalsArrayMethodString = "\n" + "def create_externals_array():\n" + " return [nan]*EXTERNAL_COUNT\n"; - mInterfaceInitialiseVariablesMethodFdmWoevString = ""; - mImplementationInitialiseVariablesMethodFdmWoevString = "\n" - "def initialise_variables(states, rates, variables):\n" - "[CODE]"; + mInterfaceDeleteArrayMethodString = ""; + mImplementationDeleteArrayMethodString = ""; - mInterfaceInitialiseVariablesMethodFdmWevString = ""; - mImplementationInitialiseVariablesMethodFdmWevString = "\n" - "def initialise_variables(voi, states, rates, variables, external_variable):\n" - "[CODE]"; + mInterfaceInitialiseVariablesMethodFamString = ""; + mImplementationInitialiseVariablesMethodFamString = "\n" + "def initialise_variables(constants, computed_constants, algebraic):\n" + "[CODE]"; + + mInterfaceInitialiseVariablesMethodFdmString = ""; + mImplementationInitialiseVariablesMethodFdmString = "\n" + "def initialise_variables(states, rates, constants, computed_constants, algebraic):\n" + "[CODE]"; mInterfaceComputeComputedConstantsMethodString = ""; mImplementationComputeComputedConstantsMethodString = "\n" - "def compute_computed_constants(variables):\n" + "def compute_computed_constants(constants, computed_constants):\n" "[CODE]"; mInterfaceComputeRatesMethodWoevString = ""; mImplementationComputeRatesMethodWoevString = "\n" - "def compute_rates(voi, states, rates, variables):\n" + "def compute_rates(voi, states, rates, constants, computed_constants, algebraic):\n" "[CODE]"; mInterfaceComputeRatesMethodWevString = ""; mImplementationComputeRatesMethodWevString = "\n" - "def compute_rates(voi, states, rates, variables, external_variable):\n" + "def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable):\n" "[CODE]"; mInterfaceComputeVariablesMethodFamWoevString = ""; mImplementationComputeVariablesMethodFamWoevString = "\n" - "def compute_variables(variables):\n" + "def compute_variables(constants, computed_constants, algebraic):\n" "[CODE]"; mInterfaceComputeVariablesMethodFamWevString = ""; mImplementationComputeVariablesMethodFamWevString = "\n" - "def compute_variables(variables, external_variable):\n" + "def compute_variables(constants, computed_constants, algebraic, externals, external_variable):\n" "[CODE]"; mInterfaceComputeVariablesMethodFdmWoevString = ""; mImplementationComputeVariablesMethodFdmWoevString = "\n" - "def compute_variables(voi, states, rates, variables):\n" + "def compute_variables(voi, states, rates, constants, computed_constants, algebraic):\n" "[CODE]"; mInterfaceComputeVariablesMethodFdmWevString = ""; mImplementationComputeVariablesMethodFdmWevString = "\n" - "def compute_variables(voi, states, rates, variables, external_variable):\n" + "def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable):\n" "[CODE]"; mEmptyMethodString = "pass\n"; @@ -2250,121 +2083,84 @@ void GeneratorProfile::setImplementationStateCountString(const std::string &impl mPimpl->mImplementationStateCountString = implementationStateCountString; } -std::string GeneratorProfile::interfaceVariableCountString() const -{ - return mPimpl->mInterfaceVariableCountString; -} - -void GeneratorProfile::setInterfaceVariableCountString(const std::string &interfaceVariableCountString) +std::string GeneratorProfile::interfaceConstantCountString() const { - mPimpl->mInterfaceVariableCountString = interfaceVariableCountString; + return mPimpl->mInterfaceConstantCountString; } -std::string GeneratorProfile::implementationVariableCountString() const +void GeneratorProfile::setInterfaceConstantCountString(const std::string &interfaceConstantCountString) { - return mPimpl->mImplementationVariableCountString; + mPimpl->mInterfaceConstantCountString = interfaceConstantCountString; } -void GeneratorProfile::setImplementationVariableCountString(const std::string &implementationVariableCountString) +std::string GeneratorProfile::implementationConstantCountString() const { - mPimpl->mImplementationVariableCountString = implementationVariableCountString; -} - -std::string GeneratorProfile::variableTypeObjectString(bool forDifferentialModel, - bool withExternalVariables) const -{ - if (forDifferentialModel) { - if (withExternalVariables) { - return mPimpl->mVariableTypeObjectFdmWevString; - } - - return mPimpl->mVariableTypeObjectFdmWoevString; - } - - if (withExternalVariables) { - return mPimpl->mVariableTypeObjectFamWevString; - } - - return mPimpl->mVariableTypeObjectFamWoevString; + return mPimpl->mImplementationConstantCountString; } -void GeneratorProfile::setVariableTypeObjectString(bool forDifferentialModel, - bool withExternalVariables, - const std::string &variableTypeObjectString) +void GeneratorProfile::setImplementationConstantCountString(const std::string &implementationConstantCountString) { - if (forDifferentialModel) { - if (withExternalVariables) { - mPimpl->mVariableTypeObjectFdmWevString = variableTypeObjectString; - } else { - mPimpl->mVariableTypeObjectFdmWoevString = variableTypeObjectString; - } - } else { - if (withExternalVariables) { - mPimpl->mVariableTypeObjectFamWevString = variableTypeObjectString; - } else { - mPimpl->mVariableTypeObjectFamWoevString = variableTypeObjectString; - } - } + mPimpl->mImplementationConstantCountString = implementationConstantCountString; } -std::string GeneratorProfile::variableOfIntegrationVariableTypeString() const +std::string GeneratorProfile::interfaceComputedConstantCountString() const { - return mPimpl->mVariableOfIntegrationVariableTypeString; + return mPimpl->mInterfaceComputedConstantCountString; } -void GeneratorProfile::setVariableOfIntegrationVariableTypeString(const std::string &variableOfIntegrationVariableTypeString) +void GeneratorProfile::setInterfaceComputedConstantCountString(const std::string &interfaceComputedConstantCountString) { - mPimpl->mVariableOfIntegrationVariableTypeString = variableOfIntegrationVariableTypeString; + mPimpl->mInterfaceComputedConstantCountString = interfaceComputedConstantCountString; } -std::string GeneratorProfile::stateVariableTypeString() const +std::string GeneratorProfile::implementationComputedConstantCountString() const { - return mPimpl->mStateVariableTypeString; + return mPimpl->mImplementationComputedConstantCountString; } -void GeneratorProfile::setStateVariableTypeString(const std::string &stateVariableTypeString) +void GeneratorProfile::setImplementationComputedConstantCountString(const std::string &implementationComputedConstantCountString) { - mPimpl->mStateVariableTypeString = stateVariableTypeString; + mPimpl->mImplementationComputedConstantCountString = implementationComputedConstantCountString; } -std::string GeneratorProfile::constantVariableTypeString() const +std::string GeneratorProfile::interfaceAlgebraicCountString() const { - return mPimpl->mConstantVariableTypeString; + return mPimpl->mInterfaceAlgebraicCountString; } -void GeneratorProfile::setConstantVariableTypeString(const std::string &constantVariableTypeString) +void GeneratorProfile::setInterfaceAlgebraicCountString(const std::string &interfaceAlgebraicCountString) { - mPimpl->mConstantVariableTypeString = constantVariableTypeString; + mPimpl->mInterfaceAlgebraicCountString = interfaceAlgebraicCountString; } -std::string GeneratorProfile::computedConstantVariableTypeString() const +std::string GeneratorProfile::implementationAlgebraicCountString() const { - return mPimpl->mComputedConstantVariableTypeString; + return mPimpl->mImplementationAlgebraicCountString; } -void GeneratorProfile::setComputedConstantVariableTypeString(const std::string &computedConstantVariableTypeString) +void GeneratorProfile::setImplementationAlgebraicCountString(const std::string &implementationAlgebraicCountString) { - mPimpl->mComputedConstantVariableTypeString = computedConstantVariableTypeString; + mPimpl->mImplementationAlgebraicCountString = implementationAlgebraicCountString; } -std::string GeneratorProfile::algebraicVariableTypeString() const +std::string GeneratorProfile::interfaceExternalCountString() const { - return mPimpl->mAlgebraicVariableTypeString; + return mPimpl->mInterfaceExternalCountString; } -void GeneratorProfile::setAlgebraicVariableTypeString(const std::string &algebraicVariableTypeString) +void GeneratorProfile::setInterfaceExternalCountString(const std::string &interfaceExternalCountString) { - mPimpl->mAlgebraicVariableTypeString = algebraicVariableTypeString; + mPimpl->mInterfaceExternalCountString = interfaceExternalCountString; } -std::string GeneratorProfile::externalVariableTypeString() const +std::string GeneratorProfile::implementationExternalCountString() const { - return mPimpl->mExternalVariableTypeString; + return mPimpl->mImplementationExternalCountString; } -void GeneratorProfile::setExternalVariableTypeString(const std::string &externalVariableTypeString) +void GeneratorProfile::setImplementationExternalCountString(const std::string &implementationExternalCountString) { - mPimpl->mExternalVariableTypeString = externalVariableTypeString; + mPimpl->mImplementationExternalCountString = implementationExternalCountString; } std::string GeneratorProfile::variableInfoObjectString() const @@ -2417,24 +2213,84 @@ void GeneratorProfile::setImplementationStateInfoString(const std::string &imple mPimpl->mImplementationStateInfoString = implementationStateInfoString; } -std::string GeneratorProfile::interfaceVariableInfoString() const +std::string GeneratorProfile::interfaceConstantInfoString() const +{ + return mPimpl->mInterfaceConstantInfoString; +} + +void GeneratorProfile::setInterfaceConstantInfoString(const std::string &interfaceConstantInfoString) +{ + mPimpl->mInterfaceConstantInfoString = interfaceConstantInfoString; +} + +std::string GeneratorProfile::implementationConstantInfoString() const +{ + return mPimpl->mImplementationConstantInfoString; +} + +void GeneratorProfile::setImplementationConstantInfoString(const std::string &implementationConstantInfoString) +{ + mPimpl->mImplementationConstantInfoString = implementationConstantInfoString; +} + +std::string GeneratorProfile::interfaceComputedConstantInfoString() const +{ + return mPimpl->mInterfaceComputedConstantInfoString; +} + +void GeneratorProfile::setInterfaceComputedConstantInfoString(const std::string &interfaceComputedConstantInfoString) +{ + mPimpl->mInterfaceComputedConstantInfoString = interfaceComputedConstantInfoString; +} + +std::string GeneratorProfile::implementationComputedConstantInfoString() const +{ + return mPimpl->mImplementationComputedConstantInfoString; +} + +void GeneratorProfile::setImplementationComputedConstantInfoString(const std::string &implementationComputedConstantInfoString) +{ + mPimpl->mImplementationComputedConstantInfoString = implementationComputedConstantInfoString; +} + +std::string GeneratorProfile::interfaceAlgebraicInfoString() const +{ + return mPimpl->mInterfaceAlgebraicInfoString; +} + +void GeneratorProfile::setInterfaceAlgebraicInfoString(const std::string &interfaceAlgebraicInfoString) +{ + mPimpl->mInterfaceAlgebraicInfoString = interfaceAlgebraicInfoString; +} + +std::string GeneratorProfile::implementationAlgebraicInfoString() const { - return mPimpl->mInterfaceVariableInfoString; + return mPimpl->mImplementationAlgebraicInfoString; } -void GeneratorProfile::setInterfaceVariableInfoString(const std::string &interfaceVariableInfoString) +void GeneratorProfile::setImplementationAlgebraicInfoString(const std::string &implementationAlgebraicInfoString) { - mPimpl->mInterfaceVariableInfoString = interfaceVariableInfoString; + mPimpl->mImplementationAlgebraicInfoString = implementationAlgebraicInfoString; } -std::string GeneratorProfile::implementationVariableInfoString() const +std::string GeneratorProfile::interfaceExternalInfoString() const { - return mPimpl->mImplementationVariableInfoString; + return mPimpl->mInterfaceExternalInfoString; } -void GeneratorProfile::setImplementationVariableInfoString(const std::string &implementationVariableInfoString) +void GeneratorProfile::setInterfaceExternalInfoString(const std::string &interfaceExternalInfoString) { - mPimpl->mImplementationVariableInfoString = implementationVariableInfoString; + mPimpl->mInterfaceExternalInfoString = interfaceExternalInfoString; +} + +std::string GeneratorProfile::implementationExternalInfoString() const +{ + return mPimpl->mImplementationExternalInfoString; +} + +void GeneratorProfile::setImplementationExternalInfoString(const std::string &implementationExternalInfoString) +{ + mPimpl->mImplementationExternalInfoString = implementationExternalInfoString; } std::string GeneratorProfile::variableInfoEntryString() const @@ -2477,14 +2333,44 @@ void GeneratorProfile::setRatesArrayString(const std::string &ratesArrayString) mPimpl->mRatesArrayString = ratesArrayString; } -std::string GeneratorProfile::variablesArrayString() const +std::string GeneratorProfile::constantsArrayString() const +{ + return mPimpl->mConstantsArrayString; +} + +void GeneratorProfile::setConstantsArrayString(const std::string &constantsArrayString) +{ + mPimpl->mConstantsArrayString = constantsArrayString; +} + +std::string GeneratorProfile::computedConstantsArrayString() const +{ + return mPimpl->mComputedConstantsArrayString; +} + +void GeneratorProfile::setComputedConstantsArrayString(const std::string &computedConstantsArrayString) +{ + mPimpl->mComputedConstantsArrayString = computedConstantsArrayString; +} + +std::string GeneratorProfile::algebraicArrayString() const +{ + return mPimpl->mAlgebraicArrayString; +} + +void GeneratorProfile::setAlgebraicArrayString(const std::string &algebraicArrayString) +{ + mPimpl->mAlgebraicArrayString = algebraicArrayString; +} + +std::string GeneratorProfile::externalArrayString() const { - return mPimpl->mVariablesArrayString; + return mPimpl->mExternalArrayString; } -void GeneratorProfile::setVariablesArrayString(const std::string &variablesArrayString) +void GeneratorProfile::setExternalArrayString(const std::string &externalArrayString) { - mPimpl->mVariablesArrayString = variablesArrayString; + mPimpl->mExternalArrayString = externalArrayString; } std::string GeneratorProfile::externalVariableMethodTypeDefinitionString(bool forDifferentialModel) const @@ -2525,22 +2411,40 @@ void GeneratorProfile::setExternalVariableMethodCallString(bool forDifferentialM } } -std::string GeneratorProfile::rootFindingInfoObjectString(bool forDifferentialModel) const +std::string GeneratorProfile::rootFindingInfoObjectString(bool forDifferentialModel, + bool withExternalVariables) const { if (forDifferentialModel) { - return mPimpl->mRootFindingInfoObjectFdmString; + if (withExternalVariables) { + return mPimpl->mRootFindingInfoObjectFdmWevString; + } + + return mPimpl->mRootFindingInfoObjectFdmWoevString; } - return mPimpl->mRootFindingInfoObjectFamString; + if (withExternalVariables) { + return mPimpl->mRootFindingInfoObjectFamWevString; + } + + return mPimpl->mRootFindingInfoObjectFamWoevString; } void GeneratorProfile::setRootFindingInfoObjectString(bool forDifferentialModel, + bool withExternalVariables, const std::string &rootFindingInfoObjectString) { if (forDifferentialModel) { - mPimpl->mRootFindingInfoObjectFdmString = rootFindingInfoObjectString; + if (withExternalVariables) { + mPimpl->mRootFindingInfoObjectFdmWevString = rootFindingInfoObjectString; + } else { + mPimpl->mRootFindingInfoObjectFdmWoevString = rootFindingInfoObjectString; + } } else { - mPimpl->mRootFindingInfoObjectFamString = rootFindingInfoObjectString; + if (withExternalVariables) { + mPimpl->mRootFindingInfoObjectFamWevString = rootFindingInfoObjectString; + } else { + mPimpl->mRootFindingInfoObjectFamWoevString = rootFindingInfoObjectString; + } } } @@ -2554,79 +2458,151 @@ void GeneratorProfile::setExternNlaSolveMethodString(const std::string &externNl mPimpl->mExternNlaSolveMethodString = externNlaSolveMethodString; } -std::string GeneratorProfile::findRootCallString(bool forDifferentialModel) const +std::string GeneratorProfile::findRootCallString(bool forDifferentialModel, + bool withExternalVariables) const { if (forDifferentialModel) { - return mPimpl->mFindRootCallFdmString; + if (withExternalVariables) { + return mPimpl->mFindRootCallFdmWevString; + } + + return mPimpl->mFindRootCallFdmWoevString; } - return mPimpl->mFindRootCallFamString; + if (withExternalVariables) { + return mPimpl->mFindRootCallFamWevString; + } + + return mPimpl->mFindRootCallFamWoevString; } void GeneratorProfile::setFindRootCallString(bool forDifferentialModel, + bool withExternalVariables, const std::string &findRootCallString) { if (forDifferentialModel) { - mPimpl->mFindRootCallFdmString = findRootCallString; + if (withExternalVariables) { + mPimpl->mFindRootCallFdmWevString = findRootCallString; + } else { + mPimpl->mFindRootCallFdmWoevString = findRootCallString; + } } else { - mPimpl->mFindRootCallFamString = findRootCallString; + if (withExternalVariables) { + mPimpl->mFindRootCallFamWevString = findRootCallString; + } else { + mPimpl->mFindRootCallFamWoevString = findRootCallString; + } } } -std::string GeneratorProfile::findRootMethodString(bool forDifferentialModel) const +std::string GeneratorProfile::findRootMethodString(bool forDifferentialModel, + bool withExternalVariables) const { if (forDifferentialModel) { - return mPimpl->mFindRootMethodFdmString; + if (withExternalVariables) { + return mPimpl->mFindRootMethodFdmWevString; + } + + return mPimpl->mFindRootMethodFdmWoevString; } - return mPimpl->mFindRootMethodFamString; + if (withExternalVariables) { + return mPimpl->mFindRootMethodFamWevString; + } + + return mPimpl->mFindRootMethodFamWoevString; } void GeneratorProfile::setFindRootMethodString(bool forDifferentialModel, + bool withExternalVariables, const std::string &findRootMethodString) { if (forDifferentialModel) { - mPimpl->mFindRootMethodFdmString = findRootMethodString; + if (withExternalVariables) { + mPimpl->mFindRootMethodFdmWevString = findRootMethodString; + } else { + mPimpl->mFindRootMethodFdmWoevString = findRootMethodString; + } } else { - mPimpl->mFindRootMethodFamString = findRootMethodString; + if (withExternalVariables) { + mPimpl->mFindRootMethodFamWevString = findRootMethodString; + } else { + mPimpl->mFindRootMethodFamWoevString = findRootMethodString; + } } } -std::string GeneratorProfile::nlaSolveCallString(bool forDifferentialModel) const +std::string GeneratorProfile::nlaSolveCallString(bool forDifferentialModel, + bool withExternalVariables) const { if (forDifferentialModel) { - return mPimpl->mNlaSolveCallFdmString; + if (withExternalVariables) { + return mPimpl->mNlaSolveCallFdmWevString; + } + + return mPimpl->mNlaSolveCallFdmWoevString; + } + + if (withExternalVariables) { + return mPimpl->mNlaSolveCallFamWevString; } - return mPimpl->mNlaSolveCallFamString; + return mPimpl->mNlaSolveCallFamWoevString; } void GeneratorProfile::setNlaSolveCallString(bool forDifferentialModel, + bool withExternalVariables, const std::string &nlaSolveCallString) { if (forDifferentialModel) { - mPimpl->mNlaSolveCallFdmString = nlaSolveCallString; + if (withExternalVariables) { + mPimpl->mNlaSolveCallFdmWevString = nlaSolveCallString; + } else { + mPimpl->mNlaSolveCallFdmWoevString = nlaSolveCallString; + } } else { - mPimpl->mNlaSolveCallFamString = nlaSolveCallString; + if (withExternalVariables) { + mPimpl->mNlaSolveCallFamWevString = nlaSolveCallString; + } else { + mPimpl->mNlaSolveCallFamWoevString = nlaSolveCallString; + } } } -std::string GeneratorProfile::objectiveFunctionMethodString(bool forDifferentialModel) const +std::string GeneratorProfile::objectiveFunctionMethodString(bool forDifferentialModel, + bool withExternalVariables) const { if (forDifferentialModel) { - return mPimpl->mObjectiveFunctionMethodFdmString; + if (withExternalVariables) { + return mPimpl->mObjectiveFunctionMethodFdmWevString; + } + + return mPimpl->mObjectiveFunctionMethodFdmWoevString; } - return mPimpl->mObjectiveFunctionMethodFamString; + if (withExternalVariables) { + return mPimpl->mObjectiveFunctionMethodFamWevString; + } + + return mPimpl->mObjectiveFunctionMethodFamWoevString; } void GeneratorProfile::setObjectiveFunctionMethodString(bool forDifferentialModel, + bool withExternalVariables, const std::string &objectiveFunctionMethodString) { if (forDifferentialModel) { - mPimpl->mObjectiveFunctionMethodFdmString = objectiveFunctionMethodString; + if (withExternalVariables) { + mPimpl->mObjectiveFunctionMethodFdmWevString = objectiveFunctionMethodString; + } else { + mPimpl->mObjectiveFunctionMethodFdmWoevString = objectiveFunctionMethodString; + } } else { - mPimpl->mObjectiveFunctionMethodFamString = objectiveFunctionMethodString; + if (withExternalVariables) { + mPimpl->mObjectiveFunctionMethodFamWevString = objectiveFunctionMethodString; + } else { + mPimpl->mObjectiveFunctionMethodFamWoevString = objectiveFunctionMethodString; + } } } @@ -2670,24 +2646,84 @@ void GeneratorProfile::setImplementationCreateStatesArrayMethodString(const std: mPimpl->mImplementationCreateStatesArrayMethodString = implementationCreateStatesArrayMethodString; } -std::string GeneratorProfile::interfaceCreateVariablesArrayMethodString() const +std::string GeneratorProfile::interfaceCreateConstantsArrayMethodString() const +{ + return mPimpl->mInterfaceCreateConstantsArrayMethodString; +} + +void GeneratorProfile::setInterfaceCreateConstantsArrayMethodString(const std::string &interfaceCreateConstantsArrayMethodString) +{ + mPimpl->mInterfaceCreateConstantsArrayMethodString = interfaceCreateConstantsArrayMethodString; +} + +std::string GeneratorProfile::implementationCreateConstantsArrayMethodString() const +{ + return mPimpl->mImplementationCreateConstantsArrayMethodString; +} + +void GeneratorProfile::setImplementationCreateConstantsArrayMethodString(const std::string &implementationCreateConstantsArrayMethodString) +{ + mPimpl->mImplementationCreateConstantsArrayMethodString = implementationCreateConstantsArrayMethodString; +} + +std::string GeneratorProfile::interfaceCreateComputedConstantsArrayMethodString() const +{ + return mPimpl->mInterfaceCreateComputedConstantsArrayMethodString; +} + +void GeneratorProfile::setInterfaceCreateComputedConstantsArrayMethodString(const std::string &interfaceCreateComputedConstantsArrayMethodString) +{ + mPimpl->mInterfaceCreateComputedConstantsArrayMethodString = interfaceCreateComputedConstantsArrayMethodString; +} + +std::string GeneratorProfile::implementationCreateComputedConstantsArrayMethodString() const +{ + return mPimpl->mImplementationCreateComputedConstantsArrayMethodString; +} + +void GeneratorProfile::setImplementationCreateComputedConstantsArrayMethodString(const std::string &implementationCreateComputedConstantsArrayMethodString) +{ + mPimpl->mImplementationCreateComputedConstantsArrayMethodString = implementationCreateComputedConstantsArrayMethodString; +} + +std::string GeneratorProfile::interfaceCreateAlgebraicArrayMethodString() const +{ + return mPimpl->mInterfaceCreateAlgebraicArrayMethodString; +} + +void GeneratorProfile::setInterfaceCreateAlgebraicArrayMethodString(const std::string &interfaceCreateAlgebraicArrayMethodString) +{ + mPimpl->mInterfaceCreateAlgebraicArrayMethodString = interfaceCreateAlgebraicArrayMethodString; +} + +std::string GeneratorProfile::implementationCreateAlgebraicArrayMethodString() const +{ + return mPimpl->mImplementationCreateAlgebraicArrayMethodString; +} + +void GeneratorProfile::setImplementationCreateAlgebraicArrayMethodString(const std::string &implementationCreateAlgebraicArrayMethodString) { - return mPimpl->mInterfaceCreateVariablesArrayMethodString; + mPimpl->mImplementationCreateAlgebraicArrayMethodString = implementationCreateAlgebraicArrayMethodString; } -void GeneratorProfile::setInterfaceCreateVariablesArrayMethodString(const std::string &interfaceCreateVariablesArrayMethodString) +std::string GeneratorProfile::interfaceCreateExternalsArrayMethodString() const { - mPimpl->mInterfaceCreateVariablesArrayMethodString = interfaceCreateVariablesArrayMethodString; + return mPimpl->mInterfaceCreateExternalsArrayMethodString; } -std::string GeneratorProfile::implementationCreateVariablesArrayMethodString() const +void GeneratorProfile::setInterfaceCreateExternalsArrayMethodString(const std::string &interfaceCreateExternalsArrayMethodString) { - return mPimpl->mImplementationCreateVariablesArrayMethodString; + mPimpl->mInterfaceCreateExternalsArrayMethodString = interfaceCreateExternalsArrayMethodString; } -void GeneratorProfile::setImplementationCreateVariablesArrayMethodString(const std::string &implementationCreateVariablesArrayMethodString) +std::string GeneratorProfile::implementationCreateExternalsArrayMethodString() const { - mPimpl->mImplementationCreateVariablesArrayMethodString = implementationCreateVariablesArrayMethodString; + return mPimpl->mImplementationCreateExternalsArrayMethodString; +} + +void GeneratorProfile::setImplementationCreateExternalsArrayMethodString(const std::string &implementationCreateExternalsArrayMethodString) +{ + mPimpl->mImplementationCreateExternalsArrayMethodString = implementationCreateExternalsArrayMethodString; } std::string GeneratorProfile::interfaceDeleteArrayMethodString() const @@ -2710,77 +2746,41 @@ void GeneratorProfile::setImplementationDeleteArrayMethodString(const std::strin mPimpl->mImplementationDeleteArrayMethodString = implementationDeleteArrayMethodString; } -std::string GeneratorProfile::interfaceInitialiseVariablesMethodString(bool forDifferentialModel, - bool withExternalVariables) const +std::string GeneratorProfile::interfaceInitialiseVariablesMethodString(bool forDifferentialModel) const { if (forDifferentialModel) { - if (withExternalVariables) { - return mPimpl->mInterfaceInitialiseVariablesMethodFdmWevString; - } - - return mPimpl->mInterfaceInitialiseVariablesMethodFdmWoevString; - } - - if (withExternalVariables) { - return mPimpl->mInterfaceInitialiseVariablesMethodFamWevString; + return mPimpl->mInterfaceInitialiseVariablesMethodFdmString; } - return mPimpl->mInterfaceInitialiseVariablesMethodFamWoevString; + return mPimpl->mInterfaceInitialiseVariablesMethodFamString; } void GeneratorProfile::setInterfaceInitialiseVariablesMethodString(bool forDifferentialModel, - bool withExternalVariables, const std::string &interfaceInitialiseVariablesMethodString) { if (forDifferentialModel) { - if (withExternalVariables) { - mPimpl->mInterfaceInitialiseVariablesMethodFdmWevString = interfaceInitialiseVariablesMethodString; - } else { - mPimpl->mInterfaceInitialiseVariablesMethodFdmWoevString = interfaceInitialiseVariablesMethodString; - } + mPimpl->mInterfaceInitialiseVariablesMethodFdmString = interfaceInitialiseVariablesMethodString; } else { - if (withExternalVariables) { - mPimpl->mInterfaceInitialiseVariablesMethodFamWevString = interfaceInitialiseVariablesMethodString; - } else { - mPimpl->mInterfaceInitialiseVariablesMethodFamWoevString = interfaceInitialiseVariablesMethodString; - } + mPimpl->mInterfaceInitialiseVariablesMethodFamString = interfaceInitialiseVariablesMethodString; } } -std::string GeneratorProfile::implementationInitialiseVariablesMethodString(bool forDifferentialModel, - bool withExternalVariables) const +std::string GeneratorProfile::implementationInitialiseVariablesMethodString(bool forDifferentialModel) const { if (forDifferentialModel) { - if (withExternalVariables) { - return mPimpl->mImplementationInitialiseVariablesMethodFdmWevString; - } - - return mPimpl->mImplementationInitialiseVariablesMethodFdmWoevString; + return mPimpl->mImplementationInitialiseVariablesMethodFdmString; } - if (withExternalVariables) { - return mPimpl->mImplementationInitialiseVariablesMethodFamWevString; - } - - return mPimpl->mImplementationInitialiseVariablesMethodFamWoevString; + return mPimpl->mImplementationInitialiseVariablesMethodFamString; } void GeneratorProfile::setImplementationInitialiseVariablesMethodString(bool forDifferentialModel, - bool withExternalVariables, const std::string &implementationInitialiseVariablesMethodString) { if (forDifferentialModel) { - if (withExternalVariables) { - mPimpl->mImplementationInitialiseVariablesMethodFdmWevString = implementationInitialiseVariablesMethodString; - } else { - mPimpl->mImplementationInitialiseVariablesMethodFdmWoevString = implementationInitialiseVariablesMethodString; - } + mPimpl->mImplementationInitialiseVariablesMethodFdmString = implementationInitialiseVariablesMethodString; } else { - if (withExternalVariables) { - mPimpl->mImplementationInitialiseVariablesMethodFamWevString = implementationInitialiseVariablesMethodString; - } else { - mPimpl->mImplementationInitialiseVariablesMethodFamWoevString = implementationInitialiseVariablesMethodString; - } + mPimpl->mImplementationInitialiseVariablesMethodFamString = implementationInitialiseVariablesMethodString; } } diff --git a/src/generatorprofile_p.h b/src/generatorprofile_p.h new file mode 100644 index 0000000000..0a44b83d04 --- /dev/null +++ b/src/generatorprofile_p.h @@ -0,0 +1,320 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include "libcellml/generatorprofile.h" + +namespace libcellml { + +/** + * @brief The GeneratorProfile::GeneratorProfileImpl struct. + * + * The private implementation for the GeneratorProfile class. + */ +struct GeneratorProfile::GeneratorProfileImpl +{ + // Whether the profile is official. + + GeneratorProfile::Profile mProfile = Profile::C; + + // Whether the profile requires an interface to be generated. + + bool mHasInterface = true; + + // Equality. + + std::string mEqualityString; + + // Relational and logical operators. + + std::string mEqString; + std::string mNeqString; + std::string mLtString; + std::string mLeqString; + std::string mGtString; + std::string mGeqString; + std::string mAndString; + std::string mOrString; + std::string mXorString; + std::string mNotString; + + bool mHasEqOperator = true; + bool mHasNeqOperator = true; + bool mHasLtOperator = true; + bool mHasLeqOperator = true; + bool mHasGtOperator = true; + bool mHasGeqOperator = true; + bool mHasAndOperator = true; + bool mHasOrOperator = true; + bool mHasXorOperator = true; + bool mHasNotOperator = true; + + // Arithmetic operators. + + std::string mPlusString; + std::string mMinusString; + std::string mTimesString; + std::string mDivideString; + std::string mPowerString; + std::string mSquareRootString; + std::string mSquareString; + std::string mAbsoluteValueString; + std::string mExponentialString; + std::string mNaturalLogarithmString; + std::string mCommonLogarithmString; + std::string mCeilingString; + std::string mFloorString; + std::string mMinString; + std::string mMaxString; + std::string mRemString; + + bool mHasPowerOperator = false; + + // Trigonometric operators. + + std::string mSinString; + std::string mCosString; + std::string mTanString; + std::string mSecString; + std::string mCscString; + std::string mCotString; + std::string mSinhString; + std::string mCoshString; + std::string mTanhString; + std::string mSechString; + std::string mCschString; + std::string mCothString; + std::string mAsinString; + std::string mAcosString; + std::string mAtanString; + std::string mAsecString; + std::string mAcscString; + std::string mAcotString; + std::string mAsinhString; + std::string mAcoshString; + std::string mAtanhString; + std::string mAsechString; + std::string mAcschString; + std::string mAcothString; + + // Piecewise statement. + + std::string mConditionalOperatorIfString; + std::string mConditionalOperatorElseString; + std::string mPiecewiseIfString; + std::string mPiecewiseElseString; + + bool mHasConditionalOperator = true; + + // Constants. + + std::string mTrueString; + std::string mFalseString; + std::string mEString; + std::string mPiString; + std::string mInfString; + std::string mNanString; + + // Arithmetic functions. + + std::string mEqFunctionString; + std::string mNeqFunctionString; + std::string mLtFunctionString; + std::string mLeqFunctionString; + std::string mGtFunctionString; + std::string mGeqFunctionString; + std::string mAndFunctionString; + std::string mOrFunctionString; + std::string mXorFunctionString; + std::string mNotFunctionString; + std::string mMinFunctionString; + std::string mMaxFunctionString; + + // Trigonometric functions. + + std::string mSecFunctionString; + std::string mCscFunctionString; + std::string mCotFunctionString; + std::string mSechFunctionString; + std::string mCschFunctionString; + std::string mCothFunctionString; + std::string mAsecFunctionString; + std::string mAcscFunctionString; + std::string mAcotFunctionString; + std::string mAsechFunctionString; + std::string mAcschFunctionString; + std::string mAcothFunctionString; + + // Miscellaneous. + + std::string mCommentString; + std::string mOriginCommentString; + + std::string mInterfaceFileNameString; + + std::string mInterfaceHeaderString; + std::string mImplementationHeaderString; + + std::string mInterfaceVersionString; + std::string mImplementationVersionString; + + std::string mInterfaceLibcellmlVersionString; + std::string mImplementationLibcellmlVersionString; + + std::string mInterfaceStateCountString; + std::string mImplementationStateCountString; + + std::string mInterfaceConstantCountString; + std::string mImplementationConstantCountString; + + std::string mInterfaceComputedConstantCountString; + std::string mImplementationComputedConstantCountString; + + std::string mInterfaceAlgebraicCountString; + std::string mImplementationAlgebraicCountString; + + std::string mInterfaceExternalCountString; + std::string mImplementationExternalCountString; + + std::string mVariableInfoObjectString; + + std::string mInterfaceVoiInfoString; + std::string mImplementationVoiInfoString; + + std::string mInterfaceStateInfoString; + std::string mImplementationStateInfoString; + + std::string mInterfaceConstantInfoString; + std::string mImplementationConstantInfoString; + + std::string mInterfaceComputedConstantInfoString; + std::string mImplementationComputedConstantInfoString; + + std::string mInterfaceAlgebraicInfoString; + std::string mImplementationAlgebraicInfoString; + + std::string mInterfaceExternalInfoString; + std::string mImplementationExternalInfoString; + + std::string mVariableInfoEntryString; + + std::string mVoiString; + + std::string mStatesArrayString; + std::string mRatesArrayString; + std::string mConstantsArrayString; + std::string mComputedConstantsArrayString; + std::string mAlgebraicArrayString; + std::string mExternalArrayString; + + std::string mExternalVariableMethodTypeDefinitionFamString; + std::string mExternalVariableMethodTypeDefinitionFdmString; + + std::string mExternalVariableMethodCallFamString; + std::string mExternalVariableMethodCallFdmString; + + std::string mRootFindingInfoObjectFamWoevString; + std::string mRootFindingInfoObjectFamWevString; + std::string mRootFindingInfoObjectFdmWoevString; + std::string mRootFindingInfoObjectFdmWevString; + + std::string mExternNlaSolveMethodString; + + std::string mFindRootCallFamWoevString; + std::string mFindRootCallFamWevString; + std::string mFindRootCallFdmWoevString; + std::string mFindRootCallFdmWevString; + + std::string mFindRootMethodFamWoevString; + std::string mFindRootMethodFamWevString; + std::string mFindRootMethodFdmWoevString; + std::string mFindRootMethodFdmWevString; + + std::string mNlaSolveCallFamWoevString; + std::string mNlaSolveCallFamWevString; + std::string mNlaSolveCallFdmWoevString; + std::string mNlaSolveCallFdmWevString; + + std::string mObjectiveFunctionMethodFamWoevString; + std::string mObjectiveFunctionMethodFamWevString; + std::string mObjectiveFunctionMethodFdmWoevString; + std::string mObjectiveFunctionMethodFdmWevString; + + std::string mUArrayString; + std::string mFArrayString; + + std::string mInterfaceCreateStatesArrayMethodString; + std::string mImplementationCreateStatesArrayMethodString; + + std::string mInterfaceCreateConstantsArrayMethodString; + std::string mImplementationCreateConstantsArrayMethodString; + + std::string mInterfaceCreateComputedConstantsArrayMethodString; + std::string mImplementationCreateComputedConstantsArrayMethodString; + + std::string mInterfaceCreateAlgebraicArrayMethodString; + std::string mImplementationCreateAlgebraicArrayMethodString; + + std::string mInterfaceCreateExternalsArrayMethodString; + std::string mImplementationCreateExternalsArrayMethodString; + + std::string mInterfaceDeleteArrayMethodString; + std::string mImplementationDeleteArrayMethodString; + + std::string mInterfaceInitialiseVariablesMethodFamString; + std::string mImplementationInitialiseVariablesMethodFamString; + + std::string mInterfaceInitialiseVariablesMethodFdmString; + std::string mImplementationInitialiseVariablesMethodFdmString; + + std::string mInterfaceComputeComputedConstantsMethodString; + std::string mImplementationComputeComputedConstantsMethodString; + + std::string mInterfaceComputeRatesMethodWoevString; + std::string mImplementationComputeRatesMethodWoevString; + + std::string mInterfaceComputeRatesMethodWevString; + std::string mImplementationComputeRatesMethodWevString; + + std::string mInterfaceComputeVariablesMethodFamWoevString; + std::string mInterfaceComputeVariablesMethodFamWevString; + std::string mInterfaceComputeVariablesMethodFdmWoevString; + std::string mInterfaceComputeVariablesMethodFdmWevString; + + std::string mImplementationComputeVariablesMethodFamWoevString; + std::string mImplementationComputeVariablesMethodFamWevString; + std::string mImplementationComputeVariablesMethodFdmWoevString; + std::string mImplementationComputeVariablesMethodFdmWevString; + + std::string mEmptyMethodString; + + std::string mIndentString; + + std::string mOpenArrayInitialiserString; + std::string mCloseArrayInitialiserString; + + std::string mOpenArrayString; + std::string mCloseArrayString; + + std::string mArrayElementSeparatorString; + + std::string mStringDelimiterString; + + std::string mCommandSeparatorString; + + void loadProfile(GeneratorProfile::Profile profile); +}; + +} // namespace libcellml diff --git a/src/generatorprofilesha1values.h b/src/generatorprofilesha1values.h index 9216e6171b..6e870864e1 100644 --- a/src/generatorprofilesha1values.h +++ b/src/generatorprofilesha1values.h @@ -24,7 +24,7 @@ namespace libcellml { * The content of this file is generated, do not edit this file directly. * See docs/dev_utilities.rst for further information. */ -static const char C_GENERATOR_PROFILE_SHA1[] = "1ac959303d5e8d6623cbe0979cb608ef48aff653"; -static const char PYTHON_GENERATOR_PROFILE_SHA1[] = "41f70a8d0486fdb3638b310814ebaa7d3ddd6771"; +static const char C_GENERATOR_PROFILE_SHA1[] = "e0be7345a3da30625ef6f2316ea4280323703566"; +static const char PYTHON_GENERATOR_PROFILE_SHA1[] = "dece9fc3241b5a84a4e1ab67972501af0e550b35"; } // namespace libcellml diff --git a/src/generatorprofiletools.cpp b/src/generatorprofiletools.cpp index 2dce65f310..9b4d0086d9 100644 --- a/src/generatorprofiletools.cpp +++ b/src/generatorprofiletools.cpp @@ -442,20 +442,17 @@ std::string generatorProfileAsString(const GeneratorProfilePtr &generatorProfile profileContents += generatorProfile->interfaceStateCountString() + generatorProfile->implementationStateCountString(); - profileContents += generatorProfile->interfaceVariableCountString() - + generatorProfile->implementationVariableCountString(); + profileContents += generatorProfile->interfaceConstantCountString() + + generatorProfile->implementationConstantCountString(); - profileContents += generatorProfile->variableTypeObjectString(false, false); - profileContents += generatorProfile->variableTypeObjectString(false, true); - profileContents += generatorProfile->variableTypeObjectString(true, false); - profileContents += generatorProfile->variableTypeObjectString(true, true); + profileContents += generatorProfile->interfaceComputedConstantCountString() + + generatorProfile->implementationComputedConstantCountString(); - profileContents += generatorProfile->variableOfIntegrationVariableTypeString() - + generatorProfile->stateVariableTypeString() - + generatorProfile->constantVariableTypeString() - + generatorProfile->computedConstantVariableTypeString() - + generatorProfile->algebraicVariableTypeString() - + generatorProfile->externalVariableTypeString(); + profileContents += generatorProfile->interfaceAlgebraicCountString() + + generatorProfile->implementationAlgebraicCountString(); + + profileContents += generatorProfile->interfaceExternalCountString() + + generatorProfile->implementationExternalCountString(); profileContents += generatorProfile->variableInfoObjectString(); @@ -465,8 +462,17 @@ std::string generatorProfileAsString(const GeneratorProfilePtr &generatorProfile profileContents += generatorProfile->interfaceStateInfoString() + generatorProfile->implementationStateInfoString(); - profileContents += generatorProfile->interfaceVariableInfoString() - + generatorProfile->implementationVariableInfoString(); + profileContents += generatorProfile->interfaceConstantInfoString() + + generatorProfile->implementationConstantInfoString(); + + profileContents += generatorProfile->interfaceComputedConstantInfoString() + + generatorProfile->implementationComputedConstantInfoString(); + + profileContents += generatorProfile->interfaceAlgebraicInfoString() + + generatorProfile->implementationAlgebraicInfoString(); + + profileContents += generatorProfile->interfaceExternalInfoString() + + generatorProfile->implementationExternalInfoString(); profileContents += generatorProfile->variableInfoEntryString(); @@ -474,7 +480,10 @@ std::string generatorProfileAsString(const GeneratorProfilePtr &generatorProfile profileContents += generatorProfile->statesArrayString() + generatorProfile->ratesArrayString() - + generatorProfile->variablesArrayString(); + + generatorProfile->constantsArrayString() + + generatorProfile->computedConstantsArrayString() + + generatorProfile->algebraicArrayString() + + generatorProfile->externalArrayString(); profileContents += generatorProfile->externalVariableMethodTypeDefinitionString(false) + generatorProfile->externalVariableMethodTypeDefinitionString(true); @@ -482,40 +491,53 @@ std::string generatorProfileAsString(const GeneratorProfilePtr &generatorProfile profileContents += generatorProfile->externalVariableMethodCallString(false) + generatorProfile->externalVariableMethodCallString(true); - profileContents += generatorProfile->rootFindingInfoObjectString(false) - + generatorProfile->rootFindingInfoObjectString(true) + profileContents += generatorProfile->rootFindingInfoObjectString(false, false) + + generatorProfile->rootFindingInfoObjectString(false, true) + + generatorProfile->rootFindingInfoObjectString(true, false) + + generatorProfile->rootFindingInfoObjectString(true, true) + generatorProfile->externNlaSolveMethodString() - + generatorProfile->findRootCallString(false) - + generatorProfile->findRootCallString(true) - + generatorProfile->findRootMethodString(false) - + generatorProfile->findRootMethodString(true) - + generatorProfile->nlaSolveCallString(false) - + generatorProfile->nlaSolveCallString(true) - + generatorProfile->objectiveFunctionMethodString(false) - + generatorProfile->objectiveFunctionMethodString(true) + + generatorProfile->findRootCallString(false, false) + + generatorProfile->findRootCallString(false, true) + + generatorProfile->findRootCallString(true, false) + + generatorProfile->findRootCallString(true, true) + + generatorProfile->findRootMethodString(false, false) + + generatorProfile->findRootMethodString(false, true) + + generatorProfile->findRootMethodString(true, false) + + generatorProfile->findRootMethodString(true, true) + + generatorProfile->nlaSolveCallString(false, false) + + generatorProfile->nlaSolveCallString(false, true) + + generatorProfile->nlaSolveCallString(true, false) + + generatorProfile->nlaSolveCallString(true, true) + + generatorProfile->objectiveFunctionMethodString(false, false) + + generatorProfile->objectiveFunctionMethodString(false, true) + + generatorProfile->objectiveFunctionMethodString(true, false) + + generatorProfile->objectiveFunctionMethodString(true, true) + generatorProfile->uArrayString() + generatorProfile->fArrayString(); profileContents += generatorProfile->interfaceCreateStatesArrayMethodString() + generatorProfile->implementationCreateStatesArrayMethodString(); - profileContents += generatorProfile->interfaceCreateVariablesArrayMethodString() - + generatorProfile->implementationCreateVariablesArrayMethodString(); + profileContents += generatorProfile->interfaceCreateConstantsArrayMethodString() + + generatorProfile->implementationCreateConstantsArrayMethodString(); - profileContents += generatorProfile->interfaceDeleteArrayMethodString() - + generatorProfile->implementationDeleteArrayMethodString(); + profileContents += generatorProfile->interfaceCreateComputedConstantsArrayMethodString() + + generatorProfile->implementationCreateComputedConstantsArrayMethodString(); + + profileContents += generatorProfile->interfaceCreateAlgebraicArrayMethodString() + + generatorProfile->implementationCreateAlgebraicArrayMethodString(); - profileContents += generatorProfile->interfaceInitialiseVariablesMethodString(false, false) - + generatorProfile->implementationInitialiseVariablesMethodString(false, false); + profileContents += generatorProfile->interfaceCreateExternalsArrayMethodString() + + generatorProfile->implementationCreateExternalsArrayMethodString(); - profileContents += generatorProfile->interfaceInitialiseVariablesMethodString(false, true) - + generatorProfile->implementationInitialiseVariablesMethodString(false, true); + profileContents += generatorProfile->interfaceDeleteArrayMethodString() + + generatorProfile->implementationDeleteArrayMethodString(); - profileContents += generatorProfile->interfaceInitialiseVariablesMethodString(true, false) - + generatorProfile->implementationInitialiseVariablesMethodString(true, false); + profileContents += generatorProfile->interfaceInitialiseVariablesMethodString(false) + + generatorProfile->implementationInitialiseVariablesMethodString(false); - profileContents += generatorProfile->interfaceInitialiseVariablesMethodString(true, true) - + generatorProfile->implementationInitialiseVariablesMethodString(true, true); + profileContents += generatorProfile->interfaceInitialiseVariablesMethodString(true) + + generatorProfile->implementationInitialiseVariablesMethodString(true); profileContents += generatorProfile->interfaceComputeComputedConstantsMethodString() + generatorProfile->implementationComputeComputedConstantsMethodString(); diff --git a/src/importer.cpp b/src/importer.cpp index 7e74657fa5..01092d3adc 100644 --- a/src/importer.cpp +++ b/src/importer.cpp @@ -32,7 +32,6 @@ limitations under the License. #include "libcellml/variable.h" #include "anycellmlelement_p.h" -#include "commonutils.h" #include "issue_p.h" #include "logger_p.h" #include "utilities.h" diff --git a/src/internaltypes.h b/src/internaltypes.h index 5acacd2134..a4e616168d 100644 --- a/src/internaltypes.h +++ b/src/internaltypes.h @@ -77,6 +77,10 @@ using UnitsConstPtr = std::shared_ptr; /**< Type definition for sha using ConnectionMap = std::map; /**< Type definition for a connection map.*/ using NamePairList = std::vector; /**< Type definition for a list of a pair of names. */ +class InterpreterStatement; /**< Forward declaration of InterpreterStatement class. */ +using InterpreterStatementPtr = std::shared_ptr; /**< Type definition for shared InterpreterStatement pointer. */ +using InterpreterStatementPtrs = std::vector; /**< Type definition for a list of shared InterpreterStatement pointers. */ + /** * @brief Class for defining an epoch in the history of a @ref Component or @ref Units. * diff --git a/src/interpreter.cpp b/src/interpreter.cpp new file mode 100644 index 0000000000..9841b9ffec --- /dev/null +++ b/src/interpreter.cpp @@ -0,0 +1,135 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include "libcellml/interpreter.h" + +#include "libcellml/analysermodel.h" + +#include "generatorinterpreter_p.h" +#include "interpreter_p.h" + +#include "libcellml/undefines.h" + +namespace libcellml { + +void Interpreter::InterpreterImpl::setModel(const AnalyserModelPtr &model) +{ + mModel = model; + + if (mModel != nullptr) { + auto generatorInterpreter = GeneratorInterpreter::create(mModel); + + mInitialiseVariablesStatements = generatorInterpreter->initialiseVariablesStatements(); + mComputeComputedConstantsStatements = generatorInterpreter->computeComputedConstantsStatements(); + mComputeRatesStatements = generatorInterpreter->computeRatesStatements(); + mComputeVariablesStatements = generatorInterpreter->computeVariablesStatements(); + } else { + mInitialiseVariablesStatements.clear(); + mComputeComputedConstantsStatements.clear(); + mComputeRatesStatements.clear(); + mComputeVariablesStatements.clear(); + } +} + +Interpreter::Interpreter() + : mPimpl(new InterpreterImpl()) +{ +} + +Interpreter::~Interpreter() +{ + delete mPimpl; +} + +InterpreterPtr Interpreter::create() noexcept +{ + return std::shared_ptr {new Interpreter {}}; +} + +AnalyserModelPtr Interpreter::model() +{ + return mPimpl->mModel; +} + +void Interpreter::setModel(const AnalyserModelPtr &model) +{ + mPimpl->setModel(model); +} + +void Interpreter::initialiseVariables(double *constants, double *computedConstants, double *algebraic) const +{ + for (const auto &statement : mPimpl->mInitialiseVariablesStatements) { + statement->evaluate(0.0, nullptr, nullptr, constants, computedConstants, algebraic, nullptr, nullptr, nullptr); + } +} + +void Interpreter::initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) const +{ + for (const auto &statement : mPimpl->mInitialiseVariablesStatements) { + statement->evaluate(0.0, states, rates, constants, computedConstants, algebraic, nullptr, nullptr, nullptr); + } +} + +void Interpreter::computeComputedConstants(double *constants, double *computedConstants) const +{ + for (const auto &statement : mPimpl->mComputeComputedConstantsStatements) { + statement->evaluate(0.0, nullptr, nullptr, constants, computedConstants, nullptr, nullptr, nullptr, nullptr); + } +} + +void Interpreter::computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) const +{ + for (const auto &statement : mPimpl->mComputeRatesStatements) { + statement->evaluate(voi, states, rates, constants, computedConstants, algebraic, nullptr, nullptr, nullptr); + } +} + +void Interpreter::computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, DifferentialModelExternalVariable externalVariable) const +{ + for (const auto &statement : mPimpl->mComputeRatesStatements) { + statement->evaluate(voi, states, rates, constants, computedConstants, algebraic, externals, nullptr, externalVariable); + } +} + +void Interpreter::computeVariables(double *constants, double *computedConstants, double *algebraic) const +{ + for (const auto &statement : mPimpl->mComputeVariablesStatements) { + statement->evaluate(0.0, nullptr, nullptr, constants, computedConstants, algebraic, nullptr, nullptr, nullptr); + } +} + +void Interpreter::computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, AlgebraicModelExternalVariable externalVariable) const +{ + for (const auto &statement : mPimpl->mComputeVariablesStatements) { + statement->evaluate(0.0, nullptr, nullptr, constants, computedConstants, algebraic, externals, externalVariable, nullptr); + } +} + +void Interpreter::computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) const +{ + for (const auto &statement : mPimpl->mComputeVariablesStatements) { + statement->evaluate(voi, states, rates, constants, computedConstants, algebraic, nullptr, nullptr, nullptr); + } +} + +void Interpreter::computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, DifferentialModelExternalVariable externalVariable) const +{ + for (const auto &statement : mPimpl->mComputeVariablesStatements) { + statement->evaluate(voi, states, rates, constants, computedConstants, algebraic, externals, nullptr, externalVariable); + } +} + +} // namespace libcellml diff --git a/src/interpreter_p.h b/src/interpreter_p.h new file mode 100644 index 0000000000..1f5083ad37 --- /dev/null +++ b/src/interpreter_p.h @@ -0,0 +1,42 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#include "libcellml/interpreter.h" + +#include "internaltypes.h" + +namespace libcellml { + +/** + * @brief The Interpreter::InterpreterImpl struct. + * + * The private implementation for the Interpreter class. + */ +struct Interpreter::InterpreterImpl +{ + AnalyserModelPtr mModel; + + std::vector mInitialiseVariablesStatements; + std::vector mComputeComputedConstantsStatements; + std::vector mComputeRatesStatements; + std::vector mComputeVariablesStatements; + + void setModel(const AnalyserModelPtr &model); +}; + +} // namespace libcellml diff --git a/src/interpreterstatement.cpp b/src/interpreterstatement.cpp new file mode 100644 index 0000000000..fcb609bd92 --- /dev/null +++ b/src/interpreterstatement.cpp @@ -0,0 +1,320 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#ifdef _WIN32 +# define _USE_MATH_DEFINES +#endif + +#include "interpreterstatement.h" + +#include + +#include "libcellml/interpreter.h" +#include "libcellml/variable.h" + +#include "commonutils.h" +#include "interpreterstatement_p.h" + +#include "libcellml/undefines.h" + +namespace libcellml { + +InterpreterStatement::InterpreterStatementImpl::InterpreterStatementImpl(Type type, + const InterpreterStatementPtr &leftChild, + const InterpreterStatementPtr &rightChild) + : mType(type) + , mLeftChild(leftChild) + , mRightChild(rightChild) +{ +} + +InterpreterStatement::InterpreterStatementImpl::InterpreterStatementImpl(const AnalyserVariablePtr &variable, + bool rate) + : mType((variable->type() == AnalyserVariable::Type::STATE) ? + (rate ? + Type::RATE : + Type::STATE) : + ((variable->type() == AnalyserVariable::Type::CONSTANT) ? + Type::CONSTANT : + ((variable->type() == AnalyserVariable::Type::COMPUTED_CONSTANT) ? + Type::COMPUTED_CONSTANT : + ((variable->type() == AnalyserVariable::Type::ALGEBRAIC) ? + Type::ALGEBRAIC : + Type::EXTERNAL)))) + , mVariable(variable) + , mIndex(variable->index()) +{ +} + +InterpreterStatement::InterpreterStatementImpl::InterpreterStatementImpl(double value) + : mType(Type::NUMBER) + , mValue(value) +{ +} + +InterpreterStatement::InterpreterStatementImpl::InterpreterStatementImpl(size_t index) + : mType(Type::EXTERNAL_VARIABLE_CALL) + , mIndex(index) +{ +} + +void InterpreterStatement::InterpreterStatementImpl::evaluate(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, AlgebraicModelExternalVariable algebraicModelExternalVariable, DifferentialModelExternalVariable differentialModelExternalVariable) const +{ + if (mLeftChild->mPimpl->mType == Type::STATE) { + states[mLeftChild->mPimpl->mIndex] = mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + } else if (mLeftChild->mPimpl->mType == Type::RATE) { + rates[mLeftChild->mPimpl->mIndex] = mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + } else if (mLeftChild->mPimpl->mType == Type::CONSTANT) { + constants[mLeftChild->mPimpl->mIndex] = mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + } else if (mLeftChild->mPimpl->mType == Type::COMPUTED_CONSTANT) { + computedConstants[mLeftChild->mPimpl->mIndex] = mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + } else if (mLeftChild->mPimpl->mType == Type::ALGEBRAIC) { + algebraic[mLeftChild->mPimpl->mIndex] = mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + } else { + externals[mLeftChild->mPimpl->mIndex] = mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + } +} + +double InterpreterStatement::InterpreterStatementImpl::evaluateToDouble(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, AlgebraicModelExternalVariable algebraicModelExternalVariable, DifferentialModelExternalVariable differentialModelExternalVariable) const +{ + switch (mType) { + // Relational and logical operators. + + case Type::EQ: + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) == mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::NEQ: + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) != mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::LT: + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) < mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::LEQ: + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) <= mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::GT: + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) > mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::GEQ: + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) >= mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::AND: + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) && mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::OR: + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) || mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::XOR: + return (mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) != 0.0) ^ (mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) != 0.0); + case Type::NOT: + return !mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + + // Arithmetic operators. + + case Type::PLUS: + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) + mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::MINUS: + if (mRightChild != nullptr) { + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) - mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + } + + return -mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::TIMES: + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) * mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::DIVIDE: + return mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) / mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + case Type::POWER: + return pow(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable), mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::SQUARE_ROOT: + return sqrt(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::SQUARE: { + auto x = mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); + + return x * x; + } + case Type::ABS: + return fabs(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::EXP: + return exp(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::LN: + return log(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::LOG: + return log10(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::CEILING: + return ceil(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::FLOOR: + return floor(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::MIN: + return fmin(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable), mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::MAX: + return fmax(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable), mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::REM: + return fmod(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable), mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + + // Trigonometric operators. + + case Type::SIN: + return sin(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::COS: + return cos(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::TAN: + return tan(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::SEC: + return 1.0 / cos(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::CSC: + return 1.0 / sin(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::COT: + return 1.0 / tan(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::SINH: + return sinh(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::COSH: + return cosh(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::TANH: + return tanh(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::SECH: + return 1.0 / cosh(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::CSCH: + return 1.0 / sinh(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::COTH: + return 1.0 / tanh(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ASIN: + return asin(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ACOS: + return acos(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ATAN: + return atan(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ASEC: + return acos(1.0 / mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ACSC: + return asin(1.0 / mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ACOT: + return atan(1.0 / mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ASINH: + return asinh(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ACOSH: + return acosh(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ATANH: + return atanh(mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ASECH: + return acosh(1.0 / mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ACSCH: + return asinh(1.0 / mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + case Type::ACOTH: + return atanh(1.0 / mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + + // Piecewise statement. + + case Type::PIECEWISE: { + return (mLeftChild->mPimpl->mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) ? + mLeftChild->mPimpl->mLeftChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable) : + mRightChild->mPimpl->evaluateToDouble(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable)); + } + + // Token elements. + + case Type::VOI: + return voi; + case Type::STATE: + return states[mIndex]; + case Type::RATE: + return rates[mIndex]; + case Type::CONSTANT: + return constants[mIndex]; + case Type::COMPUTED_CONSTANT: + return computedConstants[mIndex]; + case Type::ALGEBRAIC: + return algebraic[mIndex]; + case Type::EXTERNAL: + return externals[mIndex]; + case Type::NUMBER: + return mValue; + + // Constants. + + case Type::TRUE: + return 1.0; + case Type::FALSE: + return 0.0; + case Type::E: + return M_E; + case Type::PI: + return M_PI; + case Type::INF: { + static const auto INF = std::numeric_limits::infinity(); + + return INF; + } + case Type::NAN: { + static const auto NAN = std::numeric_limits::quiet_NaN(); + + return NAN; + } + default: // Type::EXTERNAL_VARIABLE_CALL: + if (algebraicModelExternalVariable != nullptr) { + return algebraicModelExternalVariable(constants, computedConstants, algebraic, externals, mIndex); + } + + return differentialModelExternalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, mIndex); + } +} + +InterpreterStatement::InterpreterStatement(Type type, + const InterpreterStatementPtr &leftChild, + const InterpreterStatementPtr &rightChild) + : mPimpl(new InterpreterStatementImpl(type, leftChild, rightChild)) +{ +} + +InterpreterStatement::InterpreterStatement(const AnalyserVariablePtr &variable, bool rate) + : mPimpl(new InterpreterStatementImpl(variable, rate)) +{ +} + +InterpreterStatement::InterpreterStatement(double value) + : mPimpl(new InterpreterStatementImpl(value)) +{ +} + +InterpreterStatement::InterpreterStatement(size_t index) + : mPimpl(new InterpreterStatementImpl(index)) +{ +} + +InterpreterStatement::~InterpreterStatement() +{ + delete mPimpl; +} + +InterpreterStatementPtr InterpreterStatement::create(Type type, + const InterpreterStatementPtr &leftChild, + const InterpreterStatementPtr &rightChild) noexcept +{ + return InterpreterStatementPtr {new InterpreterStatement {type, leftChild, rightChild}}; +} + +InterpreterStatementPtr InterpreterStatement::create(const AnalyserVariablePtr &variable, bool rate) noexcept +{ + return InterpreterStatementPtr {new InterpreterStatement {variable, rate}}; +} + +InterpreterStatementPtr InterpreterStatement::create(double value) noexcept +{ + return InterpreterStatementPtr {new InterpreterStatement {value}}; +} + +InterpreterStatementPtr InterpreterStatement::create(size_t index) noexcept +{ + return InterpreterStatementPtr {new InterpreterStatement {index}}; +} + +void InterpreterStatement::evaluate(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, AlgebraicModelExternalVariable algebraicModelExternalVariable, DifferentialModelExternalVariable differentialModelExternalVariable) const +{ + mPimpl->evaluate(voi, states, rates, constants, computedConstants, algebraic, externals, algebraicModelExternalVariable, differentialModelExternalVariable); +} + +} // namespace libcellml diff --git a/src/interpreterstatement.h b/src/interpreterstatement.h new file mode 100644 index 0000000000..8614db447a --- /dev/null +++ b/src/interpreterstatement.h @@ -0,0 +1,306 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#include + +#include "libcellml/analyservariable.h" +#include "libcellml/interpreter.h" + +#include "internaltypes.h" + +#include "libcellml/undefines.h" + +namespace libcellml { + +/** + * @brief The InterpreterStatement class. + * + * The InterpreterStatement class is for representing a CellML Interpreter Statement. + */ +class InterpreterStatement +{ + friend class GeneratorInterpreter; + +public: + /** + * @brief The type of a statement. + * + * The type of a statement, i.e. whether it is an equality type, a relational or a logical operator, an arithmetic + * operator, a calculus element, a trigonometric operator, a piecewise statement, a token element, a qualifier + * element, or a constant. + */ + enum class Type + { + // Equality. + + EQUALITY, /**< The equality operator. */ + + // Relational and logical operators. + + EQ, /**< The equal to operator. */ + NEQ, /**< The not equal to operator. */ + LT, /**< The less than operator. */ + LEQ, /**< The less than or equal to operator. */ + GT, /**< The greater than operator. */ + GEQ, /**< The greater than or equal to operator. */ + AND, /**< The and operator. */ + OR, /**< The or operator. */ + XOR, /**< The exclusive or operator. */ + NOT, /**< The not operator. */ + + // Arithmetic operators. + + PLUS, /**< The plus operator. */ + MINUS, /**< The minus operator. */ + TIMES, /**< The times operator. */ + DIVIDE, /**< The divide operator. */ + POWER, /**< The power operator. */ + SQUARE_ROOT, /**< The square root operator. */ + SQUARE, /**< The square operator. */ + ABS, /**< The absolute value function. */ + EXP, /**< The exponential function. */ + LN, /**< The natural logarithm function. */ + LOG, /**< The common logarithm function. */ + CEILING, /**< The ceiling function. */ + FLOOR, /**< The floor function. */ + MIN, /**< The minimum function. */ + MAX, /**< The maximum function. */ + REM, /**< The remainder function. */ + + // Trigonometric operators. + + SIN, /**< The sine function. */ + COS, /**< The cosine function. */ + TAN, /**< The tangent function. */ + SEC, /**< The secant function. */ + CSC, /**< The cosecant function. */ + COT, /**< The cotangent function. */ + SINH, /**< The hyperbolic sine function. */ + COSH, /**< The hyperbolic cosine function. */ + TANH, /**< The hyperbolic tangent function. */ + SECH, /**< The hyperbolic secant function. */ + CSCH, /**< The hyperbolic cosecant function. */ + COTH, /**< The hyperbolic cotangent function. */ + ASIN, /**< The arc sine function. */ + ACOS, /**< The arc cosine function. */ + ATAN, /**< The arc tangent function. */ + ASEC, /**< The arc secant function. */ + ACSC, /**< The arc cosecant function. */ + ACOT, /**< The arc cotangent function. */ + ASINH, /**< The arc hyperbolic sine function. */ + ACOSH, /**< The arc hyperbolic cosine function. */ + ATANH, /**< The arc hyperbolic tangent function. */ + ASECH, /**< The arc hyperbolic secant function. */ + ACSCH, /**< The arc hyperbolic cosecant function. */ + ACOTH, /**< The arc hyperbolic cotangent function. */ + + // Piecewise statement. + + PIECEWISE, /**< The "piecewise" statement. */ + PIECE, /**< The "piece" part of a "piecewise" statement. */ + + // Token elements. + + VOI, /**< The variable of integration. */ + STATE, /**< A state variable. */ + RATE, /**< A rate variable. */ + CONSTANT, /**< A constant. */ + COMPUTED_CONSTANT, /**< A computed constant. */ + ALGEBRAIC, /**< An algebraic variable. */ + EXTERNAL, /**< An external variable. */ + NUMBER, /**< A number. */ + + // Qualifier elements. + + DEGREE, /**< The degree of a root operator (it is only used when its value is not 2). */ + LOGBASE, /**< The base with respect to which the logarithm is taken. */ + BVAR, /**< The bound variable of a differential equation. */ + + // Constants. + + TRUE, /**< The "true" boolean. */ + FALSE, /**< The "false" boolean. */ + E, /**< Euler's number. */ + PI, /**< The π constant. */ + INF, /**< The infinity value. */ + NAN, /**< The not-a-number value. */ + + // Miscellaneous. + + EXTERNAL_VARIABLE_CALL /**< An external variable call. */ + }; + + ~InterpreterStatement(); /**< Destructor, @private. */ + InterpreterStatement(const InterpreterStatement &rhs) = delete; /**< Copy constructor, @private. */ + InterpreterStatement(InterpreterStatement &&rhs) noexcept = delete; /**< Move constructor, @private. */ + InterpreterStatement &operator=(InterpreterStatement rhs) = delete; /**< Assignment operator, @private. */ + + /** + * @brief Create an @ref InterpreterStatement object. + * + * Factory method to create an @ref InterpreterStatement for an element of the given type. Create such an + * interpreter statement with:: + * + * @code + * auto interpreterStatement = libcellml::InterpreterStatement::create(type, leftChild, rightChild); + * @endcode + * + * @param type The type of the statement. + * @param leftChild The left child of the statement. + * @param rightChild The right child of the statement. + * + * @return A smart pointer to an @ref InterpreterStatement object. + */ + static InterpreterStatementPtr create(Type type, + const InterpreterStatementPtr &leftChild = nullptr, + const InterpreterStatementPtr &rightChild = nullptr) noexcept; + + /** + * @brief Create an @ref InterpreterStatement object. + * + * Factory method to create an @ref InterpreterStatement for a CI element. Create such an interpreter statement + * with:: + * + * @code + * auto interpreterStatement = libcellml::InterpreterStatement::create(variable, rate); + * @endcode + * + * @param variable The variable associated with the CI element. + * @param rate Whether the variable is a rate. + * + * @return A smart pointer to an @ref InterpreterStatement object. + */ + static InterpreterStatementPtr create(const AnalyserVariablePtr &variable, bool rate = false) noexcept; + + /** + * @brief Create an @ref InterpreterStatement object. + * + * Factory method to create an @ref InterpreterStatement for a CN element. Create such an interpreter statement + * with:: + * + * @code + * auto interpreterStatement = libcellml::InterpreterStatement::create(value); + * @endcode + * + * @param value The value associated with the CN element. + * + * @return A smart pointer to an @ref InterpreterStatement object. + */ + static InterpreterStatementPtr create(double value) noexcept; + + /** + * @brief Create an @ref InterpreterStatement object. + * + * Factory method to create an @ref InterpreterStatement for an external variable. Create such an interpreter + * statement with:: + * + * @code + * auto interpreterStatement = libcellml::InterpreterStatement::create(index); + * @endcode + * + * @param index + * + * @return A smart pointer to an @ref InterpreterStatement object. + */ + static InterpreterStatementPtr create(size_t index) noexcept; + +#ifdef DEBUG + /** + * @brief Get the left child of the statement. + * + * Return the left child of the statement. + * + * @return The left child of the statement. + */ + InterpreterStatementPtr leftChild() const; + + /** + * @brief Get the right child of the statement. + * + * Return the right child of the statement. + * + * @return The right child of the statement. + */ + InterpreterStatementPtr rightChild() const; + + /** + * @brief Get the type of the statement. + * + * Return the type of the statement. + * + * @return The type of the statement. + */ + Type type() const; + + /** + * @brief Get the variable associated with the statement. + * + * Return the variable associated with the statement. + * + * @return The variable associated with the statement. + */ + AnalyserVariablePtr variable() const; + + /** + * @brief Get the index associated with the statement. + * + * Return the index associated with the statement. + * + * @return The index associated with the statement. + */ + size_t index() const; + + /** + * @brief Get the value associated with the statement. + * + * Return the value associated with the statement. + * + * @return The value associated with the statement. + */ + double value() const; +#endif + + /** + * @brief Evaluate the statement. + * + * Evaluate the statement using the given variable of integration and arrays of states, rates, and variables. + * + * @param voi The variable of integration. + * @param states The array of states. + * @param rates The array of rates. + * @param constants The array of constants. + * @param computedConstants The array of computed constants. + * @param algebraic The array of algebraic variables. + * @param externals The array of external variables. + * @param externalVariable The external variable method to use. + */ + void evaluate(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, AlgebraicModelExternalVariable algebraicModelExternalVariable, DifferentialModelExternalVariable differentialModelExternalVariable) const; + +private: + InterpreterStatement(Type type, + const InterpreterStatementPtr &leftChild, + const InterpreterStatementPtr &rightChild); /**< Constructor, @private. */ + InterpreterStatement(const AnalyserVariablePtr &variable, bool rate); /**< Constructor, @private. */ + InterpreterStatement(double value); /**< Constructor, @private. */ + InterpreterStatement(size_t index); /**< Constructor, @private. */ + + struct InterpreterStatementImpl; + InterpreterStatementImpl *mPimpl; /**< Private member to implementation pointer, @private. */ +}; + +} // namespace libcellml diff --git a/src/interpreterstatement_debug.cpp b/src/interpreterstatement_debug.cpp new file mode 100644 index 0000000000..058b9dfabc --- /dev/null +++ b/src/interpreterstatement_debug.cpp @@ -0,0 +1,51 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include "interpreterstatement_p.h" + +namespace libcellml { + +InterpreterStatementPtr InterpreterStatement::leftChild() const +{ + return mPimpl->mLeftChild; +} + +InterpreterStatementPtr InterpreterStatement::rightChild() const +{ + return mPimpl->mRightChild; +} + +InterpreterStatement::Type InterpreterStatement::type() const +{ + return mPimpl->mType; +} + +AnalyserVariablePtr InterpreterStatement::variable() const +{ + return mPimpl->mVariable; +} + +size_t InterpreterStatement::index() const +{ + return mPimpl->mIndex; +} + +double InterpreterStatement::value() const +{ + return mPimpl->mValue; +} + +} // namespace libcellml diff --git a/src/interpreterstatement_p.h b/src/interpreterstatement_p.h new file mode 100644 index 0000000000..978a2ea6de --- /dev/null +++ b/src/interpreterstatement_p.h @@ -0,0 +1,50 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#include "libcellml/analyservariable.h" + +#include + +namespace libcellml { + +/** + * @brief The InterpreterStatement::InterpreterStatementImpl struct. + * + * The private implementation for the InterpreterStatement class. + */ +struct InterpreterStatement::InterpreterStatementImpl +{ + InterpreterStatement::Type mType = Type::EQUALITY; + InterpreterStatementPtr mLeftChild; + InterpreterStatementPtr mRightChild; + AnalyserVariablePtr mVariable; + size_t mIndex = 0; + double mValue = std::numeric_limits::quiet_NaN(); + + explicit InterpreterStatementImpl(Type type, + const InterpreterStatementPtr &leftChild, + const InterpreterStatementPtr &rightChild); + explicit InterpreterStatementImpl(const AnalyserVariablePtr &variable, bool rate); + explicit InterpreterStatementImpl(double value); + explicit InterpreterStatementImpl(size_t index); + + void evaluate(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, AlgebraicModelExternalVariable algebraicModelExternalVariable, DifferentialModelExternalVariable differentialModelExternalVariable) const; + double evaluateToDouble(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, AlgebraicModelExternalVariable algebraicModelExternalVariable, DifferentialModelExternalVariable differentialModelExternalVariable) const; +}; + +} // namespace libcellml diff --git a/src/model.cpp b/src/model.cpp index 7f89305ded..a429333d03 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -30,7 +30,6 @@ limitations under the License. #include "libcellml/units.h" #include "libcellml/variable.h" -#include "commonutils.h" #include "component_p.h" #include "componententity_p.h" #include "internaltypes.h" diff --git a/src/printer.cpp b/src/printer.cpp index db5ca8727c..b4b1dfa4db 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -33,7 +33,6 @@ limitations under the License. #include "libcellml/variable.h" #include "anycellmlelement_p.h" -#include "commonutils.h" #include "internaltypes.h" #include "issue_p.h" #include "logger_p.h" diff --git a/src/units.cpp b/src/units.cpp index 87800cdd88..398c74486c 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -30,7 +30,6 @@ limitations under the License. #include #include -#include "commonutils.h" #include "units_p.h" #include "utilities.h" diff --git a/src/utilities.cpp b/src/utilities.cpp index 51cb29a65c..7e5fc772e5 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -26,6 +26,8 @@ limitations under the License. #include #include +#include "libcellml/analyserequation.h" +#include "libcellml/analysermodel.h" #include "libcellml/component.h" #include "libcellml/importsource.h" #include "libcellml/model.h" @@ -34,7 +36,6 @@ limitations under the License. #include "libcellml/units.h" #include "libcellml/variable.h" -#include "commonutils.h" #include "xmldoc.h" #include "xmlutils.h" @@ -267,54 +268,6 @@ bool areEqual(double a, double b) return convertToString(a + 0.0) == convertToString(b + 0.0); } -uint64_t ulpsDistance(double a, double b) -{ - static const auto max = std::numeric_limits::max(); - - // Max distance for NaN. - if (std::isnan(a) || std::isnan(b)) { - return max; - } - - // If one's infinite and they're not equal, max distance. - if (std::isinf(a) != std::isinf(b)) { - return max; - } - - static const int SIZE_OF_DOUBLE = sizeof(double); - - uint64_t ia; - uint64_t ib; - memcpy(&ia, &a, SIZE_OF_DOUBLE); - memcpy(&ib, &b, SIZE_OF_DOUBLE); - - // Return the absolute value of the distance in ULPs. - uint64_t distance = max; - if (ia < ib) { - distance = ib + ~ia + 1; - } else { - distance = ia + ~ib + 1; - } - return distance; -} - -bool areNearlyEqual(double a, double b) -{ - static const double fixedEpsilon = std::numeric_limits::epsilon(); - static const ptrdiff_t ulpsEpsilon = 1; - - if (fabs(a - b) <= fixedEpsilon) { - return true; - } - - // If they are not the same sign then return false. - if ((a < 0.0) != (b < 0.0)) { - return false; - } - - return ulpsDistance(a, b) <= ulpsEpsilon; -} - std::vector getImportedComponents(const ComponentEntityConstPtr &componentEntity) { std::vector importedComponents; @@ -1315,4 +1268,41 @@ XmlNodePtr mathmlChildNode(const XmlNodePtr &node, size_t index) return res; } +std::vector variables(const AnalyserModelPtr &model) +{ + std::vector res; + + if (model->voi() != nullptr) { + res.push_back(model->voi()); + } + + auto states = model->states(); + auto constants = model->constants(); + auto computedConstants = model->computedConstants(); + auto algebraic = model->algebraic(); + auto externals = model->externals(); + + res.insert(res.end(), states.begin(), states.end()); + res.insert(res.end(), constants.begin(), constants.end()); + res.insert(res.end(), computedConstants.begin(), computedConstants.end()); + res.insert(res.end(), algebraic.begin(), algebraic.end()); + res.insert(res.end(), externals.begin(), externals.end()); + + return res; +} + +std::vector variables(const AnalyserEquationPtr &equation) +{ + auto res = equation->states(); + auto computedConstants = equation->computedConstants(); + auto algebraic = equation->algebraic(); + auto externals = equation->externals(); + + res.insert(res.end(), computedConstants.begin(), computedConstants.end()); + res.insert(res.end(), algebraic.begin(), algebraic.end()); + res.insert(res.end(), externals.begin(), externals.end()); + + return res; +} + } // namespace libcellml diff --git a/src/utilities.h b/src/utilities.h index cf3830c81f..00d06ccd62 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -26,6 +26,7 @@ limitations under the License. #include "libcellml/types.h" #include "libcellml/variable.h" +#include "commonutils.h" #include "internaltypes.h" #include "xmldoc.h" @@ -332,23 +333,6 @@ bool isCellMLReal(const std::string &candidate); */ bool areEqual(double a, double b); -/** - * @brief Decide if two doubles are nearly equal. - * - * Test two doubles to determine if they are close enough - * to be considered equal. - * - * Uses a modified form of comparing floats: - * - * https://bitbashing.io/comparing-floats.html - * - * @param a A @c double to test. - * @param b A @c double to test. - * - * @return @c true if the given doubles are considered close, @c false otherwise. - */ -bool areNearlyEqual(double a, double b); - /** * @brief Compare strings to determine if they are equal. * @@ -870,4 +854,26 @@ size_t mathmlChildCount(const XmlNodePtr &node); */ XmlNodePtr mathmlChildNode(const XmlNodePtr &node, size_t index); +/** + * @brief Return the variables in the given model. + * + * Return the variables in the given model. + * + * @param model The model for which we want the variables. + * + * @return The variables in the given model. + */ +std::vector variables(const AnalyserModelPtr &model); + +/** + * @brief Return the variables in the given equation. + * + * Return the variables in the given equation. + * + * @param equation The equation for which we want the variables. + * + * @return The variables in the given equation. + */ +std::vector variables(const AnalyserEquationPtr &equation); + } // namespace libcellml diff --git a/src/validator.cpp b/src/validator.cpp index 10cf488738..19a0d80712 100644 --- a/src/validator.cpp +++ b/src/validator.cpp @@ -33,7 +33,6 @@ limitations under the License. #include "libcellml/variable.h" #include "anycellmlelement_p.h" -#include "commonutils.h" #include "issue_p.h" #include "logger_p.h" #include "namespaces.h" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cf64a66c27..1dbf26da87 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -191,6 +191,7 @@ if(LIBCELLML_LLVM_COVERAGE) add_custom_target(llvm_coverage_report COMMAND ${LLVM_COV_EXE} show $ -instr-profile=${DATA_PROFILE_FILENAME} -format=html -Xdemangler c++filt -Xdemangler -n -o coverage_report --show-expansions --show-branches=count + COMMAND echo "The coverage report can be found at ${CMAKE_CURRENT_BINARY_DIR}/${COVERAGE_REPORT_DIR}coverage_report/index.html." DEPENDS prepare_llvm_coverage WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Running LLVM coverage missing lines command") diff --git a/tests/analyser/analyser.cpp b/tests/analyser/analyser.cpp index c7e1678b95..59c6570959 100644 --- a/tests/analyser/analyser.cpp +++ b/tests/analyser/analyser.cpp @@ -398,7 +398,26 @@ TEST(Analyser, unsuitablyConstrained) EXPECT_EQ(libcellml::AnalyserModel::Type::UNSUITABLY_CONSTRAINED, analyser->model()->type()); } -TEST(Analyser, addSameExternalVariable) +TEST(Analyser, addSameExternalVariableAsVariable) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.cellml")); + + EXPECT_EQ(size_t(0), parser->issueCount()); + + auto analyser = libcellml::Analyser::create(); + auto variable = model->component("membrane")->variable("V"); + + analyser->addExternalVariable(variable); + + EXPECT_EQ(size_t(1), analyser->externalVariableCount()); + + analyser->addExternalVariable(variable); + + EXPECT_EQ(size_t(1), analyser->externalVariableCount()); +} + +TEST(Analyser, addSameExternalVariableAsExternalVariable) { auto parser = libcellml::Parser::create(); auto model = parser->parseModel(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.cellml")); @@ -434,8 +453,8 @@ TEST(Analyser, addExternalVariableFromDifferentModels) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("V"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(other_model->component("membrane")->variable("V"))); + analyser->addExternalVariable(model->component("membrane")->variable("V")); + analyser->addExternalVariable(other_model->component("membrane")->variable("V")); EXPECT_EQ(size_t(2), analyser->externalVariableCount()); @@ -463,7 +482,7 @@ TEST(Analyser, removeExternalVariableByIndex) EXPECT_FALSE(analyser->removeExternalVariable(0)); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("V"))); + analyser->addExternalVariable(model->component("membrane")->variable("V")); EXPECT_TRUE(analyser->removeExternalVariable(0)); EXPECT_FALSE(analyser->removeExternalVariable(1)); @@ -477,16 +496,16 @@ TEST(Analyser, removeExternalVariableByName) EXPECT_EQ(size_t(0), parser->issueCount()); auto analyser = libcellml::Analyser::create(); + auto variable = model->component("membrane")->variable("V"); - EXPECT_FALSE(analyser->removeExternalVariable(model, "membrane", "V")); + EXPECT_FALSE(analyser->removeExternalVariable(variable)); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("V"))); + analyser->addExternalVariable(variable); - EXPECT_FALSE(analyser->removeExternalVariable(nullptr, "membrane", "V")); - EXPECT_FALSE(analyser->removeExternalVariable(model, "X", "V")); - EXPECT_FALSE(analyser->removeExternalVariable(model, "membrane", "X")); - EXPECT_TRUE(analyser->removeExternalVariable(model, "membrane", "V")); - EXPECT_FALSE(analyser->removeExternalVariable(model, "membrane", "V")); + EXPECT_FALSE(analyser->removeExternalVariable(static_cast(nullptr))); + EXPECT_FALSE(analyser->removeExternalVariable(model->component("membrane")->variable("Cm"))); + EXPECT_TRUE(analyser->removeExternalVariable(variable)); + EXPECT_FALSE(analyser->removeExternalVariable(variable)); } TEST(Analyser, removeExternalVariableByPointer) @@ -503,7 +522,7 @@ TEST(Analyser, removeExternalVariableByPointer) analyser->addExternalVariable(externalVariable); - EXPECT_FALSE(analyser->removeExternalVariable(nullptr)); + EXPECT_FALSE(analyser->removeExternalVariable(static_cast(nullptr))); EXPECT_TRUE(analyser->removeExternalVariable(externalVariable)); EXPECT_FALSE(analyser->removeExternalVariable(externalVariable)); } @@ -517,9 +536,9 @@ TEST(Analyser, removeAllExternalVariables) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("V"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("sodium_channel")->variable("V"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("potassium_channel")->variable("V"))); + analyser->addExternalVariable(model->component("membrane")->variable("V")); + analyser->addExternalVariable(model->component("sodium_channel")->variable("V")); + analyser->addExternalVariable(model->component("potassium_channel")->variable("V")); EXPECT_EQ(size_t(3), analyser->externalVariableCount()); @@ -536,11 +555,13 @@ TEST(Analyser, containsExternalVariableByName) EXPECT_EQ(size_t(0), parser->issueCount()); auto analyser = libcellml::Analyser::create(); + auto variable = model->component("membrane")->variable("V"); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("V"))); + analyser->addExternalVariable(variable); - EXPECT_TRUE(analyser->containsExternalVariable(model, "membrane", "V")); - EXPECT_FALSE(analyser->containsExternalVariable(model, "membrane", "X")); + EXPECT_TRUE(analyser->containsExternalVariable(variable)); + EXPECT_FALSE(analyser->containsExternalVariable(static_cast(nullptr))); + EXPECT_FALSE(analyser->containsExternalVariable(model->component("membrane")->variable("Cm"))); } TEST(Analyser, containsExternalVariableByPointer) @@ -556,7 +577,7 @@ TEST(Analyser, containsExternalVariableByPointer) analyser->addExternalVariable(externalVariable); EXPECT_TRUE(analyser->containsExternalVariable(externalVariable)); - EXPECT_FALSE(analyser->containsExternalVariable(nullptr)); + EXPECT_FALSE(analyser->containsExternalVariable(static_cast(nullptr))); } TEST(Analyser, externalVariableByIndex) @@ -586,15 +607,17 @@ TEST(Analyser, externalVariableByName) EXPECT_EQ(size_t(0), parser->issueCount()); auto analyser = libcellml::Analyser::create(); + auto variable = model->component("membrane")->variable("V"); - EXPECT_EQ(nullptr, analyser->externalVariable(model, "membrane", "V")); + EXPECT_EQ(nullptr, analyser->externalVariable(variable)); auto externalVariable = libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("V")); analyser->addExternalVariable(externalVariable); - EXPECT_EQ(externalVariable, analyser->externalVariable(model, "membrane", "V")); - EXPECT_EQ(nullptr, analyser->externalVariable(model, "membrane", "X")); + EXPECT_EQ(externalVariable, analyser->externalVariable(variable)); + EXPECT_EQ(nullptr, analyser->externalVariable(static_cast(nullptr))); + EXPECT_EQ(nullptr, analyser->externalVariable(model->component("membrane")->variable("Cm"))); } TEST(Analyser, onePrimaryVoiExternalVariable) @@ -610,7 +633,7 @@ TEST(Analyser, onePrimaryVoiExternalVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("environment")->variable("time"))); + analyser->addExternalVariable(model->component("environment")->variable("time")); analyser->analyseModel(model); @@ -630,7 +653,7 @@ TEST(Analyser, oneNonPrimaryVoiExternalVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("time"))); + analyser->addExternalVariable(model->component("membrane")->variable("time")); analyser->analyseModel(model); @@ -650,8 +673,8 @@ TEST(Analyser, twoEquivalentVoiExternalVariablesIncludingPrimaryVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("environment")->variable("time"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("time"))); + analyser->addExternalVariable(model->component("environment")->variable("time")); + analyser->addExternalVariable(model->component("membrane")->variable("time")); analyser->analyseModel(model); @@ -676,8 +699,8 @@ TEST(Analyser, twoEquivalentVoiExternalVariablesNotIncludingPrimaryVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("time"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("sodium_channel")->variable("time"))); + analyser->addExternalVariable(model->component("membrane")->variable("time")); + analyser->addExternalVariable(model->component("sodium_channel")->variable("time")); analyser->analyseModel(model); @@ -702,9 +725,9 @@ TEST(Analyser, threeEquivalentVoiExternalVariablesIncludingPrimaryVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("environment")->variable("time"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("time"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("sodium_channel")->variable("time"))); + analyser->addExternalVariable(model->component("environment")->variable("time")); + analyser->addExternalVariable(model->component("membrane")->variable("time")); + analyser->addExternalVariable(model->component("sodium_channel")->variable("time")); analyser->analyseModel(model); @@ -729,9 +752,9 @@ TEST(Analyser, threeEquivalentVoiExternalVariablesNotIncludingPrimaryVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("time"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("sodium_channel")->variable("time"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("potassium_channel")->variable("time"))); + analyser->addExternalVariable(model->component("membrane")->variable("time")); + analyser->addExternalVariable(model->component("sodium_channel")->variable("time")); + analyser->addExternalVariable(model->component("potassium_channel")->variable("time")); analyser->analyseModel(model); @@ -752,7 +775,7 @@ TEST(Analyser, onePrimaryExternalVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("V"))); + analyser->addExternalVariable(model->component("membrane")->variable("V")); analyser->analyseModel(model); @@ -772,7 +795,7 @@ TEST(Analyser, oneNonPrimaryExternalVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("sodium_channel")->variable("V"))); + analyser->addExternalVariable(model->component("sodium_channel")->variable("V")); analyser->analyseModel(model); @@ -797,8 +820,8 @@ TEST(Analyser, twoEquivalentExternalVariablesIncludingPrimaryVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("V"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("sodium_channel")->variable("V"))); + analyser->addExternalVariable(model->component("membrane")->variable("V")); + analyser->addExternalVariable(model->component("sodium_channel")->variable("V")); analyser->analyseModel(model); @@ -823,8 +846,8 @@ TEST(Analyser, twoEquivalentExternalVariablesNotIncludingPrimaryVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("sodium_channel")->variable("V"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("potassium_channel")->variable("V"))); + analyser->addExternalVariable(model->component("sodium_channel")->variable("V")); + analyser->addExternalVariable(model->component("potassium_channel")->variable("V")); analyser->analyseModel(model); @@ -849,9 +872,9 @@ TEST(Analyser, threeEquivalentExternalVariablesIncludingPrimaryVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("V"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("sodium_channel")->variable("V"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("potassium_channel")->variable("V"))); + analyser->addExternalVariable(model->component("membrane")->variable("V")); + analyser->addExternalVariable(model->component("sodium_channel")->variable("V")); + analyser->addExternalVariable(model->component("potassium_channel")->variable("V")); analyser->analyseModel(model); @@ -876,9 +899,9 @@ TEST(Analyser, threeEquivalentExternalVariablesNotIncludingPrimaryVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("sodium_channel")->variable("V"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("potassium_channel")->variable("V"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("leakage_current")->variable("V"))); + analyser->addExternalVariable(model->component("sodium_channel")->variable("V")); + analyser->addExternalVariable(model->component("potassium_channel")->variable("V")); + analyser->addExternalVariable(model->component("leakage_current")->variable("V")); analyser->analyseModel(model); @@ -904,7 +927,7 @@ TEST(Analyser, algebraicSystemWithThreeLinkedUnknownsWithOneExternalVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("my_algebraic_system")->variable("x"))); + analyser->addExternalVariable(model->component("my_algebraic_system")->variable("x")); analyser->analyseModel(model); @@ -931,8 +954,8 @@ TEST(Analyser, algebraicSystemWithThreeLinkedUnknownsWithTwoExternalVariables) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("my_algebraic_system")->variable("x"))); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("my_algebraic_system")->variable("z"))); + analyser->addExternalVariable(model->component("my_algebraic_system")->variable("x")); + analyser->addExternalVariable(model->component("my_algebraic_system")->variable("z")); analyser->analyseModel(model); diff --git a/tests/bindings/javascript/CMakeLists.txt b/tests/bindings/javascript/CMakeLists.txt index 87176319b0..9f7056f8a9 100644 --- a/tests/bindings/javascript/CMakeLists.txt +++ b/tests/bindings/javascript/CMakeLists.txt @@ -27,6 +27,8 @@ set(TEST_SRCS generator.test.js generatorprofile.test.js importsource.test.js + #---GRY--- TO BE UNCOMMENTED ONCE WE HAVE BINDINGS FOR Interpreter. + # interpreter.test.js model.test.js namedentity.test.js parentedentity.test.js diff --git a/tests/bindings/javascript/analyser.test.js b/tests/bindings/javascript/analyser.test.js index c103c60b55..c9ce49f4ba 100644 --- a/tests/bindings/javascript/analyser.test.js +++ b/tests/bindings/javascript/analyser.test.js @@ -23,6 +23,7 @@ describe("Analyser tests", () => { let m let a let aev + let v beforeAll(async () => { libcellml = await libCellMLModule(); @@ -35,7 +36,7 @@ describe("Analyser tests", () => { a.analyseModel(m) expect(a.issueCount()).toBe(0) - const v = m.componentByIndex(0).variableByIndex(0) + v = m.componentByIndex(0).variableByIndex(0) aev = new libcellml.AnalyserExternalVariable(v) }); test("Checking Analyser.analyseModel.", () => { @@ -49,54 +50,57 @@ describe("Analyser tests", () => { expect(a.issueCount()).toBe(1) expect(a.issue(0).description()).toBe("Variable 'time' in component 'my_component' cannot be both a variable of integration and initialised.") }); - test("Checking Analyser.addExternalVariable.", () => { - expect(a.addExternalVariable(aev)).toBe(true) + test("Checking Analyser.addExternalVariableByVariable.", () => { + expect(a.addExternalVariableByVariable(v)).toBe(true) + }); + test("Checking Analyser.addExternalVariableByExternalVariable.", () => { + expect(a.addExternalVariableByExternalVariable(aev)).toBe(true) }); test("Checking Analyser.removeExternalVariableByIndex.", () => { - a.addExternalVariable(aev) + a.addExternalVariableByVariable(v) expect(a.externalVariableCount()).toBe(1) a.removeExternalVariableByIndex(0) expect(a.externalVariableCount()).toBe(0) }); - test("Checking Analyser.removeExternalVariableByModel.", () => { - a.addExternalVariable(aev) + test("Checking Analyser.removeExternalVariableByVariable.", () => { + a.addExternalVariableByVariable(v) expect(a.externalVariableCount()).toBe(1) - a.removeExternalVariableByModel(m, "component", "time") + a.removeExternalVariableByVariable(v) expect(a.externalVariableCount()).toBe(0) }); test("Checking Analyser.removeExternalVariableByExternalVariable.", () => { - a.addExternalVariable(aev) + a.addExternalVariableByExternalVariable(aev) expect(a.externalVariableCount()).toBe(1) a.removeExternalVariableByExternalVariable(aev) expect(a.externalVariableCount()).toBe(0) }); test("Checking Analyser.removeAllExternalVariables.", () => { - a.addExternalVariable(aev) + a.addExternalVariableByVariable(v) expect(a.externalVariableCount()).toBe(1) a.removeAllExternalVariables() expect(a.externalVariableCount()).toBe(0) }); - test("Checking Analyser.containsExternalVariableByModel.", () => { - expect(a.containsExternalVariableByModel(m, "component", "time")).toBe(false) - a.addExternalVariable(aev) - expect(a.containsExternalVariableByModel(m, "component", "time")).toBe(true) + test("Checking Analyser.containsExternalVariableByVariable.", () => { + expect(a.containsExternalVariableByVariable(v)).toBe(false) + a.addExternalVariableByVariable(v) + expect(a.containsExternalVariableByVariable(v)).toBe(true) }); test("Checking Analyser.containsExternalVariableByExternalVariable.", () => { expect(a.containsExternalVariableByExternalVariable(aev)).toBe(false) - a.addExternalVariable(aev) + a.addExternalVariableByExternalVariable(aev) expect(a.containsExternalVariableByExternalVariable(aev)).toBe(true) }); test("Checking Analyser.externalVariableByIndex.", () => { - a.addExternalVariable(aev) + a.addExternalVariableByExternalVariable(aev) expect(a.externalVariableByIndex(0)).toStrictEqual(aev) }); - test("Checking Analyser.externalVariableByModel.", () => { - a.addExternalVariable(aev) - expect(a.externalVariableByModel(m, "component", "time")).toStrictEqual(aev) + test("Checking Analyser.externalVariableByVariable.", () => { + a.addExternalVariableByExternalVariable(aev) + expect(a.externalVariableByVariable(v)).toStrictEqual(aev) }); test("Checking Analyser.externalVariableCount.", () => { expect(a.externalVariableCount()).toBe(0) - a.addExternalVariable(aev) + a.addExternalVariableByVariable(v) expect(a.externalVariableCount()).toBe(1) }); test("Checking Analyser.model.", () => { diff --git a/tests/bindings/javascript/analyserequation.test.js b/tests/bindings/javascript/analyserequation.test.js index 4f1a5cc317..8269268994 100644 --- a/tests/bindings/javascript/analyserequation.test.js +++ b/tests/bindings/javascript/analyserequation.test.js @@ -56,7 +56,7 @@ describe("Analyser Equation tests", () => { expect(eqn.dependencies().size()).toBe(0) }); test('Checking Analyser Equation dependency.', () => { - expect(eqn.dependency(0)).toBe(null) + expect(eqn.dependency(0)).toBeNull() }); test('Checking Analyser Equation nlaSystemIndex.', () => { expect(eqn.nlaSystemIndex()).toBe(4294967295) @@ -68,16 +68,34 @@ describe("Analyser Equation tests", () => { expect(eqn.nlaSiblings().size()).toBe(0) }); test('Checking Analyser Equation nlaSibling.', () => { - expect(eqn.nlaSibling(0)).toBe(null) + expect(eqn.nlaSibling(0)).toBeNull() }); - test('Checking Analyser Equation variableCount.', () => { - expect(eqn.variableCount()).toBe(1) + test('Checking Analyser Equation computedConstantCount.', () => { + expect(eqn.computedConstantCount()).toBe(0) }); - test('Checking Analyser Equation variables.', () => { - expect(eqn.variables().size()).toBe(1) + test('Checking Analyser Equation computedConstants.', () => { + expect(eqn.computedConstants().size()).toBe(0) }); - test('Checking Analyser Equation variable.', () => { - expect(eqn.variable(0).variable().name()).toBe("x") + test('Checking Analyser Equation computedConstant.', () => { + expect(eqn.computedConstant(0)).toBeNull() + }); + test('Checking Analyser Equation algebraicCount.', () => { + expect(eqn.algebraicCount()).toBe(0) + }); + test('Checking Analyser Equation algebraicVariables.', () => { + expect(eqn.algebraicVariables().size()).toBe(0) + }); + test('Checking Analyser Equation algebraicVariable.', () => { + expect(eqn.algebraicVariable(0)).toBeNull() + }); + test('Checking Analyser Equation externalCount.', () => { + expect(eqn.externalCount()).toBe(0) + }); + test('Checking Analyser Equation externals.', () => { + expect(eqn.externals().size()).toBe(0) + }); + test('Checking Analyser Equation external.', () => { + expect(eqn.external(0)).toBeNull() }); test('Checking Analyser Equation AST.', () => { expect(eqn.ast().value()).toBe("") diff --git a/tests/bindings/javascript/analysermodel.test.js b/tests/bindings/javascript/analysermodel.test.js index a84ad5e3d2..3fe868c7a7 100644 --- a/tests/bindings/javascript/analysermodel.test.js +++ b/tests/bindings/javascript/analysermodel.test.js @@ -61,10 +61,25 @@ describe("Analyser Model tests", () => { expect(am.states().size()).toBe(4) expect(am.state(2).variable().name()).toBe("m") }); - test('Checking Analyser Model variables related API.', () => { - expect(am.variableCount()).toBe(18) - expect(am.variables().size()).toBe(18) - expect(am.variable(2).variable().name()).toBe("i_K") + test('Checking Analyser Model constants related API.', () => { + expect(am.constantCount()).toBe(5) + expect(am.constants().size()).toBe(5) + expect(am.constant(2).variable().name()).toBe("g_L") + }); + test('Checking Analyser Model computed constants related API.', () => { + expect(am.computedConstantCount()).toBe(3) + expect(am.computedConstants().size()).toBe(3) + expect(am.computedConstant(2).variable().name()).toBe("E_K") + }); + test('Checking Analyser Model algebraic variables related API.', () => { + expect(am.algebraicCount()).toBe(10) + expect(am.algebraicVariables().size()).toBe(10) + expect(am.algebraicVariable(2).variable().name()).toBe("i_K") + }); + test('Checking Analyser Model external variables related API.', () => { + expect(am.externalCount()).toBe(0) + expect(am.externals().size()).toBe(0) + expect(am.external(0)).toBeNull() }); test('Checking Analyser Model need* API.', () => { expect(am.needEqFunction()).toBe(false) @@ -93,6 +108,6 @@ describe("Analyser Model tests", () => { expect(am.needAcothFunction()).toBe(false) }); test('Checking Analyser Model are equivalent variables.', () => { - expect(am.areEquivalentVariables(am.variable(2).variable(), am.variable(7).variable())).toBe(false) + expect(am.areEquivalentVariables(am.algebraicVariable(2).variable(), am.algebraicVariable(7).variable())).toBe(false) }); }) diff --git a/tests/bindings/javascript/analyservariable.test.js b/tests/bindings/javascript/analyservariable.test.js index 52b5ef7496..aa9cbb501f 100644 --- a/tests/bindings/javascript/analyservariable.test.js +++ b/tests/bindings/javascript/analyservariable.test.js @@ -37,35 +37,38 @@ describe("Analyser Variable tests", () => { am = a.model() - expect(am.variableCount()).toBe(18) + expect(am.constantCount()).toBe(5) + expect(am.computedConstantCount()).toBe(3) + expect(am.algebraicCount()).toBe(10) + expect(am.externalCount()).toBe(0) }); test('Checking Analyser Variable type.', () => { - const av = am.variable(0) + const av = am.algebraicVariable(0) expect(av.type().value).toBe(libcellml.AnalyserVariable.Type.ALGEBRAIC.value) expect(libcellml.AnalyserVariable.typeAsString(av.type())).toBe("algebraic") }); test('Checking Analyser Variable index.', () => { - const av = am.variable(7) + const av = am.algebraicVariable(7) expect(av.index()).toBe(7) }); test('Checking Analyser Variable initialising variable.', () => { - const av = am.variable(15) - expect(av.initialisingVariable().name()).toBe("g_K") + const av = am.constant(3) + expect(av.initialisingVariable().name()).toBe("g_Na") }); test('Checking Analyser Variable variable.', () => { - const av = am.variable(10) - expect(av.variable().name()).toBe("alpha_m") + const av = am.algebraicVariable(3) + expect(av.variable().name()).toBe("i_Na") }); test('Checking Analyser Equation equationCount.', () => { - const av = am.variable(14) + const av = am.computedConstant(1) expect(av.equationCount()).toBe(1) }); test('Checking Analyser Variable equations.', () => { - const av = am.variable(14) + const av = am.computedConstant(1) expect(av.equations().size()).toBe(1) }); test('Checking Analyser Variable equation.', () => { - const av = am.variable(14) + const av = am.computedConstant(1) expect(av.equation(0).type().value).toBe(libcellml.AnalyserEquation.Type.VARIABLE_BASED_CONSTANT.value) }); }) diff --git a/tests/bindings/javascript/generator.test.js b/tests/bindings/javascript/generator.test.js index 0fd13e18a5..802b479413 100644 --- a/tests/bindings/javascript/generator.test.js +++ b/tests/bindings/javascript/generator.test.js @@ -43,7 +43,7 @@ describe("Generator tests", () => { a.analyseModel(m) - expect(g.model()).toBe(null) + expect(g.model()).toBeNull() g.setModel(a.model()) @@ -62,10 +62,10 @@ describe("Generator tests", () => { g.setModel(a.model()) const interface_lines = g.interfaceCode().split('\n') - expect(interface_lines.length).toBe(40) + expect(interface_lines.length).toBe(38) const implementation_lines = g.implementationCode().split('\n') - expect(implementation_lines.length).toBe(67) + expect(implementation_lines.length).toBe(97) const equation_line_1 = libcellml.Generator.equationCode(a.model().equation(0).ast()) expect(equation_line_1.length).toBe(14) diff --git a/tests/bindings/javascript/generatorprofile.test.js b/tests/bindings/javascript/generatorprofile.test.js index be6ff9f397..e3c40bfe40 100644 --- a/tests/bindings/javascript/generatorprofile.test.js +++ b/tests/bindings/javascript/generatorprofile.test.js @@ -684,65 +684,53 @@ describe("GeneratorProfile tests", () => { x.setImplementationStateCountString("something") expect(x.implementationStateCountString()).toBe("something") }); - test("Checking GeneratorProfile.interfaceVariableCountString.", () => { + test("Checking GeneratorProfile.interfaceConstantCountString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setInterfaceVariableCountString("something") - expect(x.interfaceVariableCountString()).toBe("something") + x.setInterfaceConstantCountString("something") + expect(x.interfaceConstantCountString()).toBe("something") }); - test("Checking GeneratorProfile.implementationVariableCountString.", () => { + test("Checking GeneratorProfile.implementationConstantCountString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setImplementationVariableCountString("something") - expect(x.implementationVariableCountString()).toBe("something") + x.setImplementationConstantCountString("something") + expect(x.implementationConstantCountString()).toBe("something") }); - test("Checking GeneratorProfile.variableTypeObjectString.", () => { + test("Checking GeneratorProfile.interfaceComputedConstantCountString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setVariableTypeObjectString(false, false, "something") - expect(x.variableTypeObjectString(false, false)).toBe("something") - x.setVariableTypeObjectString(false, true, "something") - expect(x.variableTypeObjectString(false, true)).toBe("something") - x.setVariableTypeObjectString(true, false, "something") - expect(x.variableTypeObjectString(true, false)).toBe("something") - x.setVariableTypeObjectString(true, true, "something") - expect(x.variableTypeObjectString(true, true)).toBe("something") + x.setInterfaceComputedConstantCountString("something") + expect(x.interfaceComputedConstantCountString()).toBe("something") }); - test("Checking GeneratorProfile.variableOfIntegrationVariableTypeString.", () => { + test("Checking GeneratorProfile.implementationComputedConstantCountString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setVariableOfIntegrationVariableTypeString("something") - expect(x.variableOfIntegrationVariableTypeString()).toBe("something") + x.setImplementationComputedConstantCountString("something") + expect(x.implementationComputedConstantCountString()).toBe("something") }); - test("Checking GeneratorProfile.stateVariableTypeString.", () => { + test("Checking GeneratorProfile.interfaceAlgebraicCountString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setStateVariableTypeString("something") - expect(x.stateVariableTypeString()).toBe("something") + x.setInterfaceAlgebraicCountString("something") + expect(x.interfaceAlgebraicCountString()).toBe("something") }); - test("Checking GeneratorProfile.constantVariableTypeString.", () => { + test("Checking GeneratorProfile.implementationAlgebraicCountString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setConstantVariableTypeString("something") - expect(x.constantVariableTypeString()).toBe("something") + x.setImplementationAlgebraicCountString("something") + expect(x.implementationAlgebraicCountString()).toBe("something") }); - test("Checking GeneratorProfile.computedConstantVariableTypeString.", () => { + test("Checking GeneratorProfile.interfaceExternalCountString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setComputedConstantVariableTypeString("something") - expect(x.computedConstantVariableTypeString()).toBe("something") + x.setInterfaceExternalCountString("something") + expect(x.interfaceExternalCountString()).toBe("something") }); - test("Checking GeneratorProfile.algebraicVariableTypeString.", () => { + test("Checking GeneratorProfile.implementationExternalCountString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setAlgebraicVariableTypeString("something") - expect(x.algebraicVariableTypeString()).toBe("something") - }); - test("Checking GeneratorProfile.externalVariableTypeString.", () => { - const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - - x.setExternalVariableTypeString("something") - expect(x.externalVariableTypeString()).toBe("something") + x.setImplementationExternalCountString("something") + expect(x.implementationExternalCountString()).toBe("something") }); test("Checking GeneratorProfile.variableInfoObjectString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) @@ -774,17 +762,53 @@ describe("GeneratorProfile tests", () => { x.setImplementationStateInfoString("something") expect(x.implementationStateInfoString()).toBe("something") }); - test("Checking GeneratorProfile.interfaceVariableInfoString.", () => { + test("Checking GeneratorProfile.interfaceConstantInfoString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setInterfaceConstantInfoString("something") + expect(x.interfaceConstantInfoString()).toBe("something") + }); + test("Checking GeneratorProfile.implementationConstantInfoString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setImplementationConstantInfoString("something") + expect(x.implementationConstantInfoString()).toBe("something") + }); + test("Checking GeneratorProfile.interfaceComputedConstantInfoString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setInterfaceComputedConstantInfoString("something") + expect(x.interfaceComputedConstantInfoString()).toBe("something") + }); + test("Checking GeneratorProfile.implementationComputedConstantInfoString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setInterfaceVariableInfoString("something") - expect(x.interfaceVariableInfoString()).toBe("something") + x.setImplementationComputedConstantInfoString("something") + expect(x.implementationComputedConstantInfoString()).toBe("something") }); - test("Checking GeneratorProfile.implementationVariableInfoString.", () => { + test("Checking GeneratorProfile.interfaceAlgebraicInfoString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setImplementationVariableInfoString("something") - expect(x.implementationVariableInfoString()).toBe("something") + x.setInterfaceAlgebraicInfoString("something") + expect(x.interfaceAlgebraicInfoString()).toBe("something") + }); + test("Checking GeneratorProfile.implementationAlgebraicInfoString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setImplementationAlgebraicInfoString("something") + expect(x.implementationAlgebraicInfoString()).toBe("something") + }); + test("Checking GeneratorProfile.interfaceExternalInfoString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setInterfaceExternalInfoString("something") + expect(x.interfaceExternalInfoString()).toBe("something") + }); + test("Checking GeneratorProfile.implementationExternalInfoString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setImplementationExternalInfoString("something") + expect(x.implementationExternalInfoString()).toBe("something") }); test("Checking GeneratorProfile.variableInfoEntryString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) @@ -795,11 +819,17 @@ describe("GeneratorProfile tests", () => { test("Checking GeneratorProfile.rootFindingInfoObjectString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setRootFindingInfoObjectString(false, "something") - expect(x.rootFindingInfoObjectString(false)).toBe("something") + x.setRootFindingInfoObjectString(false, false, "something") + expect(x.rootFindingInfoObjectString(false, false)).toBe("something") + + x.setRootFindingInfoObjectString(false, true, "something") + expect(x.rootFindingInfoObjectString(false, true)).toBe("something") - x.setRootFindingInfoObjectString(true, "something") - expect(x.rootFindingInfoObjectString(true)).toBe("something") + x.setRootFindingInfoObjectString(true, false, "something") + expect(x.rootFindingInfoObjectString(true, false)).toBe("something") + + x.setRootFindingInfoObjectString(true, true, "something") + expect(x.rootFindingInfoObjectString(true, true)).toBe("something") }); test("Checking GeneratorProfile.externNlaSolveMethodString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) @@ -810,38 +840,62 @@ describe("GeneratorProfile tests", () => { test("Checking GeneratorProfile.findRootCallString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setFindRootCallString(false, "something") - expect(x.findRootCallString(false)).toBe("something") + x.setFindRootCallString(false, false, "something") + expect(x.findRootCallString(false, false)).toBe("something") + + x.setFindRootCallString(false, true, "something") + expect(x.findRootCallString(false, true)).toBe("something") - x.setFindRootCallString(true, "something") - expect(x.findRootCallString(true)).toBe("something") + x.setFindRootCallString(true, false, "something") + expect(x.findRootCallString(true, false)).toBe("something") + + x.setFindRootCallString(true, true, "something") + expect(x.findRootCallString(true, true)).toBe("something") }); test("Checking GeneratorProfile.findRootMethodString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setFindRootMethodString(false, "something") - expect(x.findRootMethodString(false)).toBe("something") + x.setFindRootMethodString(false, false, "something") + expect(x.findRootMethodString(false, false)).toBe("something") + + x.setFindRootMethodString(false, true, "something") + expect(x.findRootMethodString(false, true)).toBe("something") - x.setFindRootMethodString(true, "something") - expect(x.findRootMethodString(true)).toBe("something") + x.setFindRootMethodString(true, false, "something") + expect(x.findRootMethodString(true, false)).toBe("something") + + x.setFindRootMethodString(true, true, "something") + expect(x.findRootMethodString(true, true)).toBe("something") }); test("Checking GeneratorProfile.nlaSolveCallString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setNlaSolveCallString(false, "something") - expect(x.nlaSolveCallString(false)).toBe("something") + x.setNlaSolveCallString(false, false, "something") + expect(x.nlaSolveCallString(false, false)).toBe("something") + + x.setNlaSolveCallString(false, true, "something") + expect(x.nlaSolveCallString(false, true)).toBe("something") - x.setNlaSolveCallString(true, "something") - expect(x.nlaSolveCallString(true)).toBe("something") + x.setNlaSolveCallString(true, false, "something") + expect(x.nlaSolveCallString(true, false)).toBe("something") + + x.setNlaSolveCallString(true, true, "something") + expect(x.nlaSolveCallString(true, true)).toBe("something") }); test("Checking GeneratorProfile.objectiveFunctionMethodString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setObjectiveFunctionMethodString(false, "something") - expect(x.objectiveFunctionMethodString(false)).toBe("something") + x.setObjectiveFunctionMethodString(false, false, "something") + expect(x.objectiveFunctionMethodString(false, false)).toBe("something") + + x.setObjectiveFunctionMethodString(false, true, "something") + expect(x.objectiveFunctionMethodString(false, true)).toBe("something") + + x.setObjectiveFunctionMethodString(true, false, "something") + expect(x.objectiveFunctionMethodString(true, false)).toBe("something") - x.setObjectiveFunctionMethodString(true, "something") - expect(x.objectiveFunctionMethodString(true)).toBe("something") + x.setObjectiveFunctionMethodString(true, true, "something") + expect(x.objectiveFunctionMethodString(true, true)).toBe("something") }); test("Checking GeneratorProfile.uArrayString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) @@ -873,11 +927,29 @@ describe("GeneratorProfile tests", () => { x.setRatesArrayString("something") expect(x.ratesArrayString()).toBe("something") }); - test("Checking GeneratorProfile.variablesArrayString.", () => { + test("Checking GeneratorProfile.constantsArrayString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setVariablesArrayString("something") - expect(x.variablesArrayString()).toBe("something") + x.setConstantsArrayString("something") + expect(x.constantsArrayString()).toBe("something") + }); + test("Checking GeneratorProfile.computedConstantsArrayString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setComputedConstantsArrayString("something") + expect(x.computedConstantsArrayString()).toBe("something") + }); + test("Checking GeneratorProfile.algebraicArrayString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setAlgebraicArrayString("something") + expect(x.algebraicArrayString()).toBe("something") + }); + test("Checking GeneratorProfile.externalArrayString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setExternalArrayString("something") + expect(x.externalArrayString()).toBe("something") }); test("Checking GeneratorProfile.externalVariableMethodTypeDefinitionString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) @@ -909,17 +981,53 @@ describe("GeneratorProfile tests", () => { x.setImplementationCreateStatesArrayMethodString("something") expect(x.implementationCreateStatesArrayMethodString()).toBe("something") }); - test("Checking GeneratorProfile.interfaceCreateVariablesArrayMethodString.", () => { + test("Checking GeneratorProfile.interfaceCreateConstantsArrayMethodString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setInterfaceCreateConstantsArrayMethodString("something") + expect(x.interfaceCreateConstantsArrayMethodString()).toBe("something") + }); + test("Checking GeneratorProfile.implementationCreateConstantsArrayMethodString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setInterfaceCreateVariablesArrayMethodString("something") - expect(x.interfaceCreateVariablesArrayMethodString()).toBe("something") + x.setImplementationCreateConstantsArrayMethodString("something") + expect(x.implementationCreateConstantsArrayMethodString()).toBe("something") }); - test("Checking GeneratorProfile.implementationCreateVariablesArrayMethodString.", () => { + test("Checking GeneratorProfile.interfaceCreateComputedConstantsArrayMethodString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setImplementationCreateVariablesArrayMethodString("something") - expect(x.implementationCreateVariablesArrayMethodString()).toBe("something") + x.setInterfaceCreateComputedConstantsArrayMethodString("something") + expect(x.interfaceCreateComputedConstantsArrayMethodString()).toBe("something") + }); + test("Checking GeneratorProfile.implementationCreateComputedConstantsArrayMethodString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setImplementationCreateComputedConstantsArrayMethodString("something") + expect(x.implementationCreateComputedConstantsArrayMethodString()).toBe("something") + }); + test("Checking GeneratorProfile.interfaceCreateAlgebraicArrayMethodString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setInterfaceCreateAlgebraicArrayMethodString("something") + expect(x.interfaceCreateAlgebraicArrayMethodString()).toBe("something") + }); + test("Checking GeneratorProfile.implementationCreateAlgebraicArrayMethodString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setImplementationCreateAlgebraicArrayMethodString("something") + expect(x.implementationCreateAlgebraicArrayMethodString()).toBe("something") + }); + test("Checking GeneratorProfile.interfaceCreateExternalsArrayMethodString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setInterfaceCreateExternalsArrayMethodString("something") + expect(x.interfaceCreateExternalsArrayMethodString()).toBe("something") + }); + test("Checking GeneratorProfile.implementationCreateExternalsArrayMethodString.", () => { + const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) + + x.setImplementationCreateExternalsArrayMethodString("something") + expect(x.implementationCreateExternalsArrayMethodString()).toBe("something") }); test("Checking GeneratorProfile.interfaceDeleteArrayMethodString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) @@ -936,32 +1044,20 @@ describe("GeneratorProfile tests", () => { test("Checking GeneratorProfile.interfaceInitialiseVariablesMethodString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setInterfaceInitialiseVariablesMethodString(false, false, "something") - expect(x.interfaceInitialiseVariablesMethodString(false, false)).toBe("something") - - x.setInterfaceInitialiseVariablesMethodString(false, true, "something") - expect(x.interfaceInitialiseVariablesMethodString(false, true)).toBe("something") + x.setInterfaceInitialiseVariablesMethodString(false, "something") + expect(x.interfaceInitialiseVariablesMethodString(false)).toBe("something") - x.setInterfaceInitialiseVariablesMethodString(true, false, "something") - expect(x.interfaceInitialiseVariablesMethodString(true, false)).toBe("something") - - x.setInterfaceInitialiseVariablesMethodString(true, true, "something") - expect(x.interfaceInitialiseVariablesMethodString(true, true)).toBe("something") + x.setInterfaceInitialiseVariablesMethodString(true, "something") + expect(x.interfaceInitialiseVariablesMethodString(true)).toBe("something") }); test("Checking GeneratorProfile.implementationInitialiseVariablesMethodString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) - x.setImplementationInitialiseVariablesMethodString(false, false, "something") - expect(x.implementationInitialiseVariablesMethodString(false, false)).toBe("something") - - x.setImplementationInitialiseVariablesMethodString(false, true, "something") - expect(x.implementationInitialiseVariablesMethodString(false, true)).toBe("something") - - x.setImplementationInitialiseVariablesMethodString(true, false, "something") - expect(x.implementationInitialiseVariablesMethodString(true, false)).toBe("something") + x.setImplementationInitialiseVariablesMethodString(false, "something") + expect(x.implementationInitialiseVariablesMethodString(false)).toBe("something") - x.setImplementationInitialiseVariablesMethodString(true, true, "something") - expect(x.implementationInitialiseVariablesMethodString(true, true)).toBe("something") + x.setImplementationInitialiseVariablesMethodString(true, "something") + expect(x.implementationInitialiseVariablesMethodString(true)).toBe("something") }); test("Checking GeneratorProfile.interfaceComputeComputedConstantsMethodString.", () => { const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C) diff --git a/tests/bindings/javascript/importsource.test.js b/tests/bindings/javascript/importsource.test.js index e349be0880..f3b48c307a 100644 --- a/tests/bindings/javascript/importsource.test.js +++ b/tests/bindings/javascript/importsource.test.js @@ -34,7 +34,7 @@ describe("Import Source tests", () => { const iS = new libcellml.ImportSource() const m = new libcellml.Model() - expect(iS.model()).toBe(null) + expect(iS.model()).toBeNull() iS.setModel(m) diff --git a/tests/bindings/javascript/interpreter.test.js b/tests/bindings/javascript/interpreter.test.js new file mode 100644 index 0000000000..eb9421069f --- /dev/null +++ b/tests/bindings/javascript/interpreter.test.js @@ -0,0 +1,72 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +const loadLibCellML = require('libcellml.js/libcellml.common') +const { hhSquidAxon1952 } = require('./resources') + +let libcellml = null + +describe("Interpreter tests", () => { + beforeAll(async () => { + libcellml = await loadLibCellML() + }) + + function expectArray(expectedValues, values) { + expect(expectedValues.length).toBe(values.size()) + + for (let i = 0; i < expectedValues.length; ++i) { + if (Number.isNaN(expectedValues[i])) { + expect(Number.isNaN(values.get(i))).toBe(true) + } else { + expect(expectedValues[i]).toBeCloseTo(values.get(i)) + } + } + } + + test('Checking Interpreter model manipulation.', () => { + const i = new libcellml.Interpreter() + const p = new libcellml.Parser(true) + + m = p.parseModel(hhSquidAxon1952) + a = new libcellml.Analyser() + + a.analyseModel(m) + + expect(i.model()).toBe(null) + + i.setModel(a.model()) + + expect(i.model()).toBeDefined() + + expect(i.voi()).toBe(0.0) + + const NaN_x_4 = Array(4).fill(Number.NaN) + const NaN_x_18 = Array(18).fill(Number.NaN) + + expectArray(NaN_x_4, i.states()) + expectArray(NaN_x_4, i.rates()) + expectArray(NaN_x_18, i.variables()) + + i.initialiseVariables() + i.computeComputedConstants() + i.computeRates(0.0) + i.computeVariables(0.0) + + expectArray([0.0, 0.6, 0.05, 0.325], i.states()) + expectArray([0.60076875, -0.0004555239065400646, 0.012385538355398518, -0.0013415722863204596], i.rates()) + expectArray([0.0, 3.1839, -4.81966875, 1.035, 1.0, 0.0, -10.613, 0.3, -115.0, 120.0, 0.22356372458463003, 4.0, 0.07, 0.04742587317756678, 12.0, 36.0, 0.05819767068693265, 0.125], i.variables()) + }) +}) diff --git a/tests/bindings/javascript/reset.test.js b/tests/bindings/javascript/reset.test.js index ab70a879bc..72a905f3f6 100644 --- a/tests/bindings/javascript/reset.test.js +++ b/tests/bindings/javascript/reset.test.js @@ -41,7 +41,7 @@ describe("Reset tests", () => { const r = new libcellml.Reset() const v = new libcellml.Variable() - expect(r.variable()).toBe(null) + expect(r.variable()).toBeNull() r.setVariable(v) expect(r.variable()).toStrictEqual(v) @@ -50,7 +50,7 @@ describe("Reset tests", () => { const r = new libcellml.Reset() const v = new libcellml.Variable() - expect(r.testVariable()).toBe(null) + expect(r.testVariable()).toBeNull() r.setTestVariable(v) expect(r.testVariable()).toStrictEqual(v) diff --git a/tests/bindings/javascript/variable.test.js b/tests/bindings/javascript/variable.test.js index 9dbc06c2fb..a3d863b0da 100644 --- a/tests/bindings/javascript/variable.test.js +++ b/tests/bindings/javascript/variable.test.js @@ -70,7 +70,7 @@ describe("Variable tests", () => { const v = new libcellml.Variable("V") const u = new libcellml.Units("mV") - expect(v.units()).toBe(null) + expect(v.units()).toBeNull() v.setUnitsByName("A") @@ -82,7 +82,7 @@ describe("Variable tests", () => { v.removeUnits() - expect(v.units()).toBe(null) + expect(v.units()).toBeNull() v.delete() u.delete() diff --git a/tests/bindings/python/CMakeLists.txt b/tests/bindings/python/CMakeLists.txt index 16d776bc9a..5b2aeb3493 100644 --- a/tests/bindings/python/CMakeLists.txt +++ b/tests/bindings/python/CMakeLists.txt @@ -25,6 +25,8 @@ set(TEST_SRCS test_import_requirement.py test_import_source.py test_importer.py + #---GRY--- TO BE UNCOMMENTED ONCE WE HAVE BINDINGS FOR Interpreter. + # test_interpreter.py test_issue.py test_model.py test_parser.py diff --git a/tests/bindings/python/test_analyser.py b/tests/bindings/python/test_analyser.py index 654daf1a20..bcfc9bc2e3 100644 --- a/tests/bindings/python/test_analyser.py +++ b/tests/bindings/python/test_analyser.py @@ -82,10 +82,10 @@ def test_coverage(self): self.assertTrue(a.addExternalVariable(aev)) self.assertTrue(a.containsExternalVariable(aev)) - self.assertTrue(a.containsExternalVariable(m, c.name(), v0.name())) + self.assertTrue(a.containsExternalVariable(v0)) self.assertEqual(aev.variable().name(), a.externalVariable(0).variable().name()) - self.assertEqual(aev.variable().name(), a.externalVariable(m, c.name(), v0.name()).variable().name()) + self.assertEqual(aev.variable().name(), a.externalVariable(v0).variable().name()) v2 = c.variable(2) @@ -97,7 +97,7 @@ def test_coverage(self): self.assertTrue(a.removeExternalVariable(1)) self.assertTrue(a.removeExternalVariable(aev)) - self.assertTrue(a.removeExternalVariable(m, c.name(), v2.name())) + self.assertTrue(a.removeExternalVariable(v2)) a.removeAllExternalVariables() @@ -115,9 +115,15 @@ def test_coverage(self): self.assertIsNotNone(am.states()) self.assertIsNotNone(am.state(3)) - self.assertEqual(17, am.variableCount()) - self.assertIsNotNone(am.variables()) - self.assertIsNotNone(am.variable(3)) + self.assertEqual(5, am.constantCount()) + self.assertIsNotNone(am.constants()) + self.assertIsNotNone(am.constant(3)) + self.assertEqual(0, am.computedConstantCount()) + self.assertIsNotNone(am.computedConstants()) + self.assertIsNone(am.computedConstant(3)) + self.assertEqual(12, am.algebraicCount()) + self.assertIsNotNone(am.algebraic()) + self.assertIsNotNone(am.algebraic(3)) self.assertEqual(16, am.equationCount()) self.assertIsNotNone(am.equations()) @@ -152,17 +158,17 @@ def test_coverage(self): # Ensure coverage for AnalyserVariable. - av = am.variable(3) + av = am.algebraic(3) - self.assertEqual(AnalyserVariable.Type.CONSTANT, av.type()) - self.assertEqual("constant", AnalyserVariable.typeAsString(av.type())) - self.assertEqual("constant", AnalyserVariable_typeAsString(av.type())) + self.assertEqual(AnalyserVariable.Type.ALGEBRAIC, av.type()) + self.assertEqual("algebraic", AnalyserVariable.typeAsString(av.type())) + self.assertEqual("algebraic", AnalyserVariable_typeAsString(av.type())) self.assertEqual(3, av.index()) - self.assertIsNotNone(av.initialisingVariable()) + self.assertIsNone(av.initialisingVariable()) self.assertIsNotNone(av.variable()) self.assertEqual(1, av.equationCount()) self.assertIsNotNone(av.equations()) - self.assertIsNone(av.equation(0)) + self.assertIsNotNone(av.equation(0)) # Ensure coverage for AnalyserEquation. @@ -180,9 +186,15 @@ def test_coverage(self): self.assertIsNotNone(ae.nlaSiblings()) self.assertIsNone(ae.nlaSibling(0)) self.assertTrue(ae.isStateRateBased()) - self.assertEqual(1, ae.variableCount()) - self.assertIsNotNone(ae.variables()) - self.assertIsNotNone(ae.variable(0)) + self.assertEqual(0, ae.computedConstantCount()) + self.assertIsNotNone(ae.computedConstants()) + self.assertIsNone(ae.computedConstant(0)) + self.assertEqual(1, ae.algebraicCount()) + self.assertIsNotNone(ae.algebraic()) + self.assertIsNotNone(ae.algebraic(0)) + self.assertEqual(0, ae.externalCount()) + self.assertIsNotNone(ae.externals()) + self.assertIsNone(ae.external(0)) # Check Analyser Equation type with invalid values. diff --git a/tests/bindings/python/test_generator_profile.py b/tests/bindings/python/test_generator_profile.py index f91a0645a9..0c6e4ec6c4 100644 --- a/tests/bindings/python/test_generator_profile.py +++ b/tests/bindings/python/test_generator_profile.py @@ -162,7 +162,7 @@ def test_acoth_function_string(self): g = GeneratorProfile() self.assertEqual( - 'double acoth(double x)\n{\n double oneOverX = 1.0/x;\n\n return 0.5*log((1.0+oneOverX)/(1.0-oneOverX));\n}\n', + 'double acoth(double x)\n{\n return atanh(1.0/x);\n}\n', g.acothFunctionString()) g.setAcothFunctionString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.acothFunctionString()) @@ -200,7 +200,7 @@ def test_acsch_function_string(self): g = GeneratorProfile() self.assertEqual( - 'double acsch(double x)\n{\n double oneOverX = 1.0/x;\n\n return log(oneOverX+sqrt(oneOverX*oneOverX+1.0));\n}\n', + 'double acsch(double x)\n{\n return asinh(1.0/x);\n}\n', g.acschFunctionString()) g.setAcschFunctionString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.acschFunctionString()) @@ -214,24 +214,6 @@ def test_acsch_string(self): g.setAcschString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.acschString()) - def test_algebraic_variable_type_string(self): - from libcellml import GeneratorProfile - - g = GeneratorProfile() - - self.assertEqual('ALGEBRAIC', g.algebraicVariableTypeString()) - g.setAlgebraicVariableTypeString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.algebraicVariableTypeString()) - - def test_external_variable_type_string(self): - from libcellml import GeneratorProfile - - g = GeneratorProfile() - - self.assertEqual('EXTERNAL', g.externalVariableTypeString()) - g.setExternalVariableTypeString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.externalVariableTypeString()) - def test_and_function_string(self): from libcellml import GeneratorProfile @@ -283,7 +265,7 @@ def test_asech_function_string(self): g = GeneratorProfile() self.assertEqual( - 'double asech(double x)\n{\n double oneOverX = 1.0/x;\n\n return log(oneOverX+sqrt(oneOverX*oneOverX-1.0));\n}\n', + 'double asech(double x)\n{\n return acosh(1.0/x);\n}\n', g.asechFunctionString()) g.setAsechFunctionString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.asechFunctionString()) @@ -396,15 +378,6 @@ def test_common_logarithm_string(self): g.setCommonLogarithmString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.commonLogarithmString()) - def test_computed_constant_variable_type_string(self): - from libcellml import GeneratorProfile - - g = GeneratorProfile() - - self.assertEqual('COMPUTED_CONSTANT', g.computedConstantVariableTypeString()) - g.setComputedConstantVariableTypeString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.computedConstantVariableTypeString()) - def test_conditional_operator_else_string(self): from libcellml import GeneratorProfile @@ -423,33 +396,6 @@ def test_conditional_operator_if_string(self): g.setConditionalOperatorIfString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.conditionalOperatorIfString()) - def test_variable_of_integration_variable_type_string(self): - from libcellml import GeneratorProfile - - g = GeneratorProfile() - - self.assertEqual('VARIABLE_OF_INTEGRATION', g.variableOfIntegrationVariableTypeString()) - g.setVariableOfIntegrationVariableTypeString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.variableOfIntegrationVariableTypeString()) - - def test_state_variable_type_string(self): - from libcellml import GeneratorProfile - - g = GeneratorProfile() - - self.assertEqual('STATE', g.stateVariableTypeString()) - g.setStateVariableTypeString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.stateVariableTypeString()) - - def test_constant_variable_type_string(self): - from libcellml import GeneratorProfile - - g = GeneratorProfile() - - self.assertEqual('CONSTANT', g.constantVariableTypeString()) - g.setConstantVariableTypeString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.constantVariableTypeString()) - def test_cos_string(self): from libcellml import GeneratorProfile @@ -761,7 +707,7 @@ def test_implementation_compute_computed_constants_method_string(self): g = GeneratorProfile() - self.assertEqual('void computeComputedConstants(double *variables)\n{\n[CODE]}\n', + self.assertEqual('void computeComputedConstants(double *constants, double *computedConstants)\n{\n[CODE]}\n', g.implementationComputeComputedConstantsMethodString()) g.setImplementationComputeComputedConstantsMethodString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationComputeComputedConstantsMethodString()) @@ -772,13 +718,13 @@ def test_implementation_compute_rates_method_string(self): g = GeneratorProfile() self.assertEqual( - 'void computeRates(double voi, double *states, double *rates, double *variables)\n{\n[CODE]}\n', + 'void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n{\n[CODE]}\n', g.implementationComputeRatesMethodString(False)) g.setImplementationComputeRatesMethodString(False, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationComputeRatesMethodString(False)) self.assertEqual( - 'void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable)\n{\n[CODE]}\n', + 'void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable)\n{\n[CODE]}\n', g.implementationComputeRatesMethodString(True)) g.setImplementationComputeRatesMethodString(True, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationComputeRatesMethodString(True)) @@ -789,25 +735,25 @@ def test_implementation_compute_variables_method_string(self): g = GeneratorProfile() self.assertEqual( - 'void computeVariables(double *variables)\n{\n[CODE]}\n', + 'void computeVariables(double *constants, double *computedConstants, double *algebraic)\n{\n[CODE]}\n', g.implementationComputeVariablesMethodString(False, False)) g.setImplementationComputeVariablesMethodString(False, False, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationComputeVariablesMethodString(False, False)) self.assertEqual( - 'void computeVariables(double *variables, ExternalVariable externalVariable)\n{\n[CODE]}\n', + 'void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable)\n{\n[CODE]}\n', g.implementationComputeVariablesMethodString(False, True)) g.setImplementationComputeVariablesMethodString(False, True, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationComputeVariablesMethodString(False, True)) self.assertEqual( - 'void computeVariables(double voi, double *states, double *rates, double *variables)\n{\n[CODE]}\n', + 'void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n{\n[CODE]}\n', g.implementationComputeVariablesMethodString(True, False)) g.setImplementationComputeVariablesMethodString(True, False, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationComputeVariablesMethodString(True, False)) self.assertEqual( - 'void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable)\n{\n[CODE]}\n', + 'void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable)\n{\n[CODE]}\n', g.implementationComputeVariablesMethodString(True, True)) g.setImplementationComputeVariablesMethodString(True, True, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationComputeVariablesMethodString(True, True)) @@ -823,16 +769,49 @@ def test_implementation_create_states_array_method_string(self): g.setImplementationCreateStatesArrayMethodString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationCreateStatesArrayMethodString()) - def test_implementation_create_variables_array_method_string(self): + def test_implementation_create_constants_array_method_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual( + 'double * createConstantsArray()\n{\n double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double));\n\n for (size_t i = 0; i < CONSTANT_COUNT; ++i) {\n res[i] = NAN;\n }\n\n return res;\n}\n', + g.implementationCreateConstantsArrayMethodString()) + g.setImplementationCreateConstantsArrayMethodString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationCreateConstantsArrayMethodString()) + + def test_implementation_create_computed_constants_array_method_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual( + 'double * createComputedConstantsArray()\n{\n double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double));\n\n for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) {\n res[i] = NAN;\n }\n\n return res;\n}\n', + g.implementationCreateComputedConstantsArrayMethodString()) + g.setImplementationCreateComputedConstantsArrayMethodString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationCreateComputedConstantsArrayMethodString()) + + def test_implementation_create_algebraic_array_method_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() self.assertEqual( - 'double * createVariablesArray()\n{\n double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double));\n\n for (size_t i = 0; i < VARIABLE_COUNT; ++i) {\n res[i] = NAN;\n }\n\n return res;\n}\n', - g.implementationCreateVariablesArrayMethodString()) - g.setImplementationCreateVariablesArrayMethodString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationCreateVariablesArrayMethodString()) + 'double * createAlgebraicArray()\n{\n double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double));\n\n for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) {\n res[i] = NAN;\n }\n\n return res;\n}\n', + g.implementationCreateAlgebraicArrayMethodString()) + g.setImplementationCreateAlgebraicArrayMethodString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationCreateAlgebraicArrayMethodString()) + + def test_implementation_create_externals_array_method_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual( + 'double * createExternalsArray()\n{\n double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double));\n\n for (size_t i = 0; i < EXTERNAL_COUNT; ++i) {\n res[i] = NAN;\n }\n\n return res;\n}\n', + g.implementationCreateExternalsArrayMethodString()) + g.setImplementationCreateExternalsArrayMethodString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationCreateExternalsArrayMethodString()) def test_implementation_delete_array_method_string(self): from libcellml import GeneratorProfile @@ -859,25 +838,15 @@ def test_implementation_initialise_constants_method_string(self): g = GeneratorProfile() - self.assertEqual('void initialiseVariables(double *variables)\n{\n[CODE]}\n', - g.implementationInitialiseVariablesMethodString(False, False)) - g.setImplementationInitialiseVariablesMethodString(False, False, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationInitialiseVariablesMethodString(False, False)) - - self.assertEqual('void initialiseVariables(double *variables, ExternalVariable externalVariable)\n{\n[CODE]}\n', - g.implementationInitialiseVariablesMethodString(False, True)) - g.setImplementationInitialiseVariablesMethodString(False, True, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationInitialiseVariablesMethodString(False, True)) - - self.assertEqual('void initialiseVariables(double *states, double *rates, double *variables)\n{\n[CODE]}\n', - g.implementationInitialiseVariablesMethodString(True, False)) - g.setImplementationInitialiseVariablesMethodString(True, False, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationInitialiseVariablesMethodString(True, False)) + self.assertEqual('void initialiseVariables(double *constants, double *computedConstants, double *algebraic)\n{\n[CODE]}\n', + g.implementationInitialiseVariablesMethodString(False)) + g.setImplementationInitialiseVariablesMethodString(False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationInitialiseVariablesMethodString(False)) - self.assertEqual('void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable)\n{\n[CODE]}\n', - g.implementationInitialiseVariablesMethodString(True, True)) - g.setImplementationInitialiseVariablesMethodString(True, True, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationInitialiseVariablesMethodString(True, True)) + self.assertEqual('void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n{\n[CODE]}\n', + g.implementationInitialiseVariablesMethodString(True)) + g.setImplementationInitialiseVariablesMethodString(True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationInitialiseVariablesMethodString(True)) def test_implementation_libcellml_version_string(self): from libcellml import GeneratorProfile @@ -907,31 +876,84 @@ def test_implementation_state_info_string(self): g.setImplementationStateInfoString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationStateInfoString()) - def test_implementation_variable_count_string(self): + def test_implementation_constant_info_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('const VariableInfo CONSTANT_INFO[] = {\n[CODE]};\n', g.implementationConstantInfoString()) + g.setImplementationConstantInfoString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationConstantInfoString()) + + def test_implementation_computed_constant_info_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('const VariableInfo COMPUTED_CONSTANT_INFO[] = {\n[CODE]};\n', g.implementationComputedConstantInfoString()) + g.setImplementationComputedConstantInfoString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationComputedConstantInfoString()) + + def test_implementation_algebraic_info_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('const VariableInfo ALGEBRAIC_INFO[] = {\n[CODE]};\n', g.implementationAlgebraicInfoString()) + g.setImplementationAlgebraicInfoString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationAlgebraicInfoString()) + + def test_implementation_external_info_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('const VariableInfo EXTERNAL_INFO[] = {\n[CODE]};\n', g.implementationExternalInfoString()) + g.setImplementationExternalInfoString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationExternalInfoString()) + + def test_implementation_constant_count_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('const size_t CONSTANT_COUNT = [CONSTANT_COUNT];\n', g.implementationConstantCountString()) + g.setImplementationConstantCountString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationConstantCountString()) + + def test_implementation_computed_constant_count_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('const size_t COMPUTED_CONSTANT_COUNT = [COMPUTED_CONSTANT_COUNT];\n', g.implementationComputedConstantCountString()) + g.setImplementationComputedConstantCountString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationComputedConstantCountString()) + + def test_implementation_algebraic_count_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() - self.assertEqual('const size_t VARIABLE_COUNT = [VARIABLE_COUNT];\n', g.implementationVariableCountString()) - g.setImplementationVariableCountString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationVariableCountString()) + self.assertEqual('const size_t ALGEBRAIC_COUNT = [ALGEBRAIC_COUNT];\n', g.implementationAlgebraicCountString()) + g.setImplementationAlgebraicCountString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationAlgebraicCountString()) - def test_implementation_variable_info_string(self): + def test_implementation_external_count_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() - self.assertEqual('const VariableInfo VARIABLE_INFO[] = {\n[CODE]};\n', - g.implementationVariableInfoString()) - g.setImplementationVariableInfoString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationVariableInfoString()) + self.assertEqual('const size_t EXTERNAL_COUNT = [EXTERNAL_COUNT];\n', g.implementationExternalCountString()) + g.setImplementationExternalCountString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationExternalCountString()) def test_implementation_version_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() - self.assertEqual('const char VERSION[] = "0.5.0";\n', g.implementationVersionString()) + self.assertEqual('const char VERSION[] = "0.6.0";\n', g.implementationVersionString()) g.setImplementationVersionString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.implementationVersionString()) @@ -967,7 +989,7 @@ def test_interface_compute_computed_constants_method_string(self): g = GeneratorProfile() - self.assertEqual('void computeComputedConstants(double *variables);\n', + self.assertEqual('void computeComputedConstants(double *constants, double *computedConstants);\n', g.interfaceComputeComputedConstantsMethodString()) g.setInterfaceComputeComputedConstantsMethodString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceComputeComputedConstantsMethodString()) @@ -978,13 +1000,13 @@ def test_interface_compute_rates_method_string(self): g = GeneratorProfile() self.assertEqual( - 'void computeRates(double voi, double *states, double *rates, double *variables);\n', + 'void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic);\n', g.interfaceComputeRatesMethodString(False)) g.setInterfaceComputeRatesMethodString(False, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceComputeRatesMethodString(False)) self.assertEqual( - 'void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable);\n', + 'void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable);\n', g.interfaceComputeRatesMethodString(True)) g.setInterfaceComputeRatesMethodString(True, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceComputeRatesMethodString(True)) @@ -995,25 +1017,25 @@ def test_interface_compute_variables_method_string(self): g = GeneratorProfile() self.assertEqual( - 'void computeVariables(double *variables);\n', + 'void computeVariables(double *constants, double *computedConstants, double *algebraic);\n', g.interfaceComputeVariablesMethodString(False, False)) g.setInterfaceComputeVariablesMethodString(False, False, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceComputeVariablesMethodString(False, False)) self.assertEqual( - 'void computeVariables(double *variables, ExternalVariable externalVariable);\n', + 'void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable);\n', g.interfaceComputeVariablesMethodString(False, True)) g.setInterfaceComputeVariablesMethodString(False, True, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceComputeVariablesMethodString(False, True)) self.assertEqual( - 'void computeVariables(double voi, double *states, double *rates, double *variables);\n', + 'void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic);\n', g.interfaceComputeVariablesMethodString(True, False)) g.setInterfaceComputeVariablesMethodString(True, False, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceComputeVariablesMethodString(True, False)) self.assertEqual( - 'void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable);\n', + 'void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable);\n', g.interfaceComputeVariablesMethodString(True, True)) g.setInterfaceComputeVariablesMethodString(True, True, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceComputeVariablesMethodString(True, True)) @@ -1027,14 +1049,41 @@ def test_interface_create_states_array_method_string(self): g.setInterfaceCreateStatesArrayMethodString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceCreateStatesArrayMethodString()) - def test_interface_create_variables_array_method_string(self): + def test_interface_create_constants_array_method_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() - self.assertEqual('double * createVariablesArray();\n', g.interfaceCreateVariablesArrayMethodString()) - g.setInterfaceCreateVariablesArrayMethodString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceCreateVariablesArrayMethodString()) + self.assertEqual('double * createConstantsArray();\n', g.interfaceCreateConstantsArrayMethodString()) + g.setInterfaceCreateConstantsArrayMethodString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceCreateConstantsArrayMethodString()) + + def test_interface_create_computed_constants_array_method_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('double * createComputedConstantsArray();\n', g.interfaceCreateComputedConstantsArrayMethodString()) + g.setInterfaceCreateComputedConstantsArrayMethodString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceCreateComputedConstantsArrayMethodString()) + + def test_interface_create_algebraic_array_method_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('double * createAlgebraicArray();\n', g.interfaceCreateAlgebraicArrayMethodString()) + g.setInterfaceCreateAlgebraicArrayMethodString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceCreateAlgebraicArrayMethodString()) + + def test_interface_create_externals_array_method_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('double * createExternalsArray();\n', g.interfaceCreateExternalsArrayMethodString()) + g.setInterfaceCreateExternalsArrayMethodString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceCreateExternalsArrayMethodString()) def test_interface_delete_array_method_string(self): from libcellml import GeneratorProfile @@ -1068,25 +1117,15 @@ def test_interface_initialise_constants_method_string(self): g = GeneratorProfile() - self.assertEqual('void initialiseVariables(double *variables);\n', - g.interfaceInitialiseVariablesMethodString(False, False)) - g.setInterfaceInitialiseVariablesMethodString(False, False, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceInitialiseVariablesMethodString(False, False)) - - self.assertEqual('void initialiseVariables(double *variables, ExternalVariable externalVariable);\n', - g.interfaceInitialiseVariablesMethodString(False, True)) - g.setInterfaceInitialiseVariablesMethodString(False, True, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceInitialiseVariablesMethodString(False, True)) + self.assertEqual('void initialiseVariables(double *constants, double *computedConstants, double *algebraic);\n', + g.interfaceInitialiseVariablesMethodString(False)) + g.setInterfaceInitialiseVariablesMethodString(False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceInitialiseVariablesMethodString(False)) - self.assertEqual('void initialiseVariables(double *states, double *rates, double *variables);\n', - g.interfaceInitialiseVariablesMethodString(True, False)) - g.setInterfaceInitialiseVariablesMethodString(True, False, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceInitialiseVariablesMethodString(True, False)) - - self.assertEqual('void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable);\n', - g.interfaceInitialiseVariablesMethodString(True, True)) - g.setInterfaceInitialiseVariablesMethodString(True, True, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceInitialiseVariablesMethodString(True, True)) + self.assertEqual('void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic);\n', + g.interfaceInitialiseVariablesMethodString(True)) + g.setInterfaceInitialiseVariablesMethodString(True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceInitialiseVariablesMethodString(True)) def test_interface_libcellml_version_string(self): from libcellml import GeneratorProfile @@ -1115,23 +1154,77 @@ def test_interface_state_info_string(self): g.setInterfaceStateInfoString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceStateInfoString()) - def test_interface_variable_count_string(self): + def test_interface_constant_info_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('extern const VariableInfo CONSTANT_INFO[];\n', g.interfaceConstantInfoString()) + g.setInterfaceConstantInfoString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceConstantInfoString()) + + def test_interface_computed_constant_info_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('extern const VariableInfo COMPUTED_CONSTANT_INFO[];\n', g.interfaceComputedConstantInfoString()) + g.setInterfaceComputedConstantInfoString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceComputedConstantInfoString()) + + def test_interface_algebraic_info_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('extern const VariableInfo ALGEBRAIC_INFO[];\n', g.interfaceAlgebraicInfoString()) + g.setInterfaceAlgebraicInfoString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceAlgebraicInfoString()) + + def test_interface_external_info_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('extern const VariableInfo EXTERNAL_INFO[];\n', g.interfaceExternalInfoString()) + g.setInterfaceExternalInfoString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceExternalInfoString()) + + def test_interface_constant_count_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() - self.assertEqual('extern const size_t VARIABLE_COUNT;\n', g.interfaceVariableCountString()) - g.setInterfaceVariableCountString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceVariableCountString()) + self.assertEqual('extern const size_t CONSTANT_COUNT;\n', g.interfaceConstantCountString()) + g.setInterfaceConstantCountString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceConstantCountString()) - def test_interface_variable_info_string(self): + def test_interface_computed_constant_count_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() - self.assertEqual('extern const VariableInfo VARIABLE_INFO[];\n', g.interfaceVariableInfoString()) - g.setInterfaceVariableInfoString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceVariableInfoString()) + self.assertEqual('extern const size_t COMPUTED_CONSTANT_COUNT;\n', g.interfaceComputedConstantCountString()) + g.setInterfaceComputedConstantCountString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceComputedConstantCountString()) + + def test_interface_algebraic_count_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('extern const size_t ALGEBRAIC_COUNT;\n', g.interfaceAlgebraicCountString()) + g.setInterfaceAlgebraicCountString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceAlgebraicCountString()) + + def test_interface_external_count_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('extern const size_t EXTERNAL_COUNT;\n', g.interfaceExternalCountString()) + g.setInterfaceExternalCountString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.interfaceExternalCountString()) def test_interface_version_string(self): from libcellml import GeneratorProfile @@ -1192,7 +1285,7 @@ def test_max_function_string(self): g = GeneratorProfile() - self.assertEqual('double max(double x, double y)\n{\n return (x > y)?x:y;\n}\n', g.maxFunctionString()) + self.assertEqual('', g.maxFunctionString()) g.setMaxFunctionString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.maxFunctionString()) @@ -1201,7 +1294,7 @@ def test_max_string(self): g = GeneratorProfile() - self.assertEqual('max', g.maxString()) + self.assertEqual('fmax', g.maxString()) g.setMaxString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.maxString()) @@ -1210,7 +1303,7 @@ def test_min_function_string(self): g = GeneratorProfile() - self.assertEqual('double min(double x, double y)\n{\n return (x < y)?x:y;\n}\n', g.minFunctionString()) + self.assertEqual('', g.minFunctionString()) g.setMinFunctionString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.minFunctionString()) @@ -1219,7 +1312,7 @@ def test_min_string(self): g = GeneratorProfile() - self.assertEqual('min', g.minString()) + self.assertEqual('fmin', g.minString()) g.setMinString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.minString()) @@ -1527,7 +1620,7 @@ def test_variable_info_entry_string(self): g = GeneratorProfile() - self.assertEqual('{"[NAME]", "[UNITS]", "[COMPONENT]", [TYPE]}', g.variableInfoEntryString()) + self.assertEqual('{"[NAME]", "[UNITS]", "[COMPONENT]"}', g.variableInfoEntryString()) g.setVariableInfoEntryString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.variableInfoEntryString()) @@ -1537,48 +1630,46 @@ def test_variable_info_object_string(self): g = GeneratorProfile() self.assertEqual( - 'typedef struct {\n char name[[NAME_SIZE]];\n char units[[UNITS_SIZE]];\n char component[[COMPONENT_SIZE]];\n VariableType type;\n} VariableInfo;\n', + 'typedef struct {\n char name[[NAME_SIZE]];\n char units[[UNITS_SIZE]];\n char component[[COMPONENT_SIZE]];\n} VariableInfo;\n', g.variableInfoObjectString()) g.setVariableInfoObjectString(GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.variableInfoObjectString()) - def test_variable_type_object_string(self): + def test_constants_array_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() - self.assertEqual( - 'typedef enum {\n CONSTANT,\n COMPUTED_CONSTANT,\n ALGEBRAIC\n} VariableType;\n', - g.variableTypeObjectString(False, False)) - g.setVariableTypeObjectString(False, False, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.variableTypeObjectString(False, False)) + self.assertEqual('constants', g.constantsArrayString()) + g.setConstantsArrayString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.constantsArrayString()) - self.assertEqual( - 'typedef enum {\n CONSTANT,\n COMPUTED_CONSTANT,\n ALGEBRAIC,\n EXTERNAL\n} VariableType;\n', - g.variableTypeObjectString(False, True)) - g.setVariableTypeObjectString(False, True, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.variableTypeObjectString(False, True)) + def test_computed_constants_array_string(self): + from libcellml import GeneratorProfile - self.assertEqual( - 'typedef enum {\n VARIABLE_OF_INTEGRATION,\n STATE,\n CONSTANT,\n COMPUTED_CONSTANT,\n ALGEBRAIC\n} VariableType;\n', - g.variableTypeObjectString(True, False)) - g.setVariableTypeObjectString(True, False, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.variableTypeObjectString(True, False)) + g = GeneratorProfile() - self.assertEqual( - 'typedef enum {\n VARIABLE_OF_INTEGRATION,\n STATE,\n CONSTANT,\n COMPUTED_CONSTANT,\n ALGEBRAIC,\n EXTERNAL\n} VariableType;\n', - g.variableTypeObjectString(True, True)) - g.setVariableTypeObjectString(True, True, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.variableTypeObjectString(True, True)) + self.assertEqual('computedConstants', g.computedConstantsArrayString()) + g.setComputedConstantsArrayString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.computedConstantsArrayString()) - def test_variables_array_string(self): + def test_algebraic_array_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() - self.assertEqual('variables', g.variablesArrayString()) - g.setVariablesArrayString(GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.variablesArrayString()) + self.assertEqual('algebraic', g.algebraicArrayString()) + g.setAlgebraicArrayString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.algebraicArrayString()) + + def test_external_array_string(self): + from libcellml import GeneratorProfile + + g = GeneratorProfile() + + self.assertEqual('externals', g.externalArrayString()) + g.setExternalArrayString(GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.externalArrayString()) def test_external_variable_method_type_definition_string(self): from libcellml import GeneratorProfile @@ -1586,13 +1677,13 @@ def test_external_variable_method_type_definition_string(self): g = GeneratorProfile() self.assertEqual( - 'typedef double (* ExternalVariable)(double *variables, size_t index);\n', + 'typedef double (* ExternalVariable)(double *constants, double *computedConstants, double *algebraic, double *externals, size_t index);\n', g.externalVariableMethodTypeDefinitionString(False)) g.setExternalVariableMethodTypeDefinitionString(False, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.externalVariableMethodTypeDefinitionString(False)) self.assertEqual( - 'typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index);\n', + 'typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index);\n', g.externalVariableMethodTypeDefinitionString(True)) g.setExternalVariableMethodTypeDefinitionString(True, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.externalVariableMethodTypeDefinitionString(True)) @@ -1602,12 +1693,12 @@ def test_external_variable_method_call_string(self): g = GeneratorProfile() - self.assertEqual('externalVariable(variables, [INDEX])', + self.assertEqual('externalVariable(constants, computedConstants, algebraic, externals, [INDEX])', g.externalVariableMethodCallString(False)) g.setExternalVariableMethodCallString(False, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.externalVariableMethodCallString(False)) - self.assertEqual('externalVariable(voi, states, rates, variables, [INDEX])', + self.assertEqual('externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, [INDEX])', g.externalVariableMethodCallString(True)) g.setExternalVariableMethodCallString(True, GeneratorProfileTestCase.VALUE) self.assertEqual(GeneratorProfileTestCase.VALUE, g.externalVariableMethodCallString(True)) @@ -1617,13 +1708,21 @@ def test_root_finding_info_object_string(self): g = GeneratorProfile() - self.assertEqual('typedef struct {\n double *variables;\n} RootFindingInfo;\n', g.rootFindingInfoObjectString(False)) - g.setRootFindingInfoObjectString(False, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.rootFindingInfoObjectString(False)) + self.assertEqual('typedef struct {\n double *constants;\n double *computedConstants;\n double *algebraic;\n} RootFindingInfo;\n', g.rootFindingInfoObjectString(False, False)) + g.setRootFindingInfoObjectString(False, False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.rootFindingInfoObjectString(False, False)) + + self.assertEqual('typedef struct {\n double *constants;\n double *computedConstants;\n double *algebraic;\n double *externals;\n} RootFindingInfo;\n', g.rootFindingInfoObjectString(False, True)) + g.setRootFindingInfoObjectString(False, True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.rootFindingInfoObjectString(False, True)) - self.assertEqual('typedef struct {\n double voi;\n double *states;\n double *rates;\n double *variables;\n} RootFindingInfo;\n', g.rootFindingInfoObjectString(True)) - g.setRootFindingInfoObjectString(True, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.rootFindingInfoObjectString(True)) + self.assertEqual('typedef struct {\n double voi;\n double *states;\n double *rates;\n double *constants;\n double *computedConstants;\n double *algebraic;\n} RootFindingInfo;\n', g.rootFindingInfoObjectString(True, False)) + g.setRootFindingInfoObjectString(True, False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.rootFindingInfoObjectString(True, False)) + + self.assertEqual('typedef struct {\n double voi;\n double *states;\n double *rates;\n double *constants;\n double *computedConstants;\n double *algebraic;\n double *externals;\n} RootFindingInfo;\n', g.rootFindingInfoObjectString(True, True)) + g.setRootFindingInfoObjectString(True, True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.rootFindingInfoObjectString(True, True)) def test_extern_nla_solve_method_string(self): from libcellml import GeneratorProfile @@ -1639,52 +1738,84 @@ def test_find_root_call_string(self): g = GeneratorProfile() - self.assertEqual('findRoot[INDEX](variables);\n', g.findRootCallString(False)) - g.setFindRootCallString(False, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootCallString(False)) + self.assertEqual('findRoot[INDEX](constants, computedConstants, algebraic);\n', g.findRootCallString(False, False)) + g.setFindRootCallString(False, False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootCallString(False, False)) + + self.assertEqual('findRoot[INDEX](constants, computedConstants, algebraic, externals);\n', g.findRootCallString(False, True)) + g.setFindRootCallString(False, True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootCallString(False, True)) + + self.assertEqual('findRoot[INDEX](voi, states, rates, constants, computedConstants, algebraic);\n', g.findRootCallString(True, False)) + g.setFindRootCallString(True, False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootCallString(True, False)) - self.assertEqual('findRoot[INDEX](voi, states, rates, variables);\n', g.findRootCallString(True)) - g.setFindRootCallString(True, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootCallString(True)) + self.assertEqual('findRoot[INDEX](voi, states, rates, constants, computedConstants, algebraic, externals);\n', g.findRootCallString(True, True)) + g.setFindRootCallString(True, True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootCallString(True, True)) def test_find_root_method_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() - self.assertEqual('void findRoot[INDEX](double *variables)\n{\n RootFindingInfo rfi = { variables };\n double u[[SIZE]];\n\n[CODE]}\n', g.findRootMethodString(False)) - g.setFindRootMethodString(False, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootMethodString(False)) + self.assertEqual('void findRoot[INDEX](double *constants, double *computedConstants, double *algebraic)\n{\n RootFindingInfo rfi = { constants, computedConstants, algebraic };\n double u[[SIZE]];\n\n[CODE]}\n', g.findRootMethodString(False, False)) + g.setFindRootMethodString(False, False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootMethodString(False, False)) + + self.assertEqual('void findRoot[INDEX](double *constants, double *computedConstants, double *algebraic, double *externals)\n{\n RootFindingInfo rfi = { constants, computedConstants, algebraic, externals };\n double u[[SIZE]];\n\n[CODE]}\n', g.findRootMethodString(False, True)) + g.setFindRootMethodString(False, True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootMethodString(False, True)) + + self.assertEqual('void findRoot[INDEX](double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n{\n RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic };\n double u[[SIZE]];\n\n[CODE]}\n', g.findRootMethodString(True, False)) + g.setFindRootMethodString(True, False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootMethodString(True, False)) - self.assertEqual('void findRoot[INDEX](double voi, double *states, double *rates, double *variables)\n{\n RootFindingInfo rfi = { voi, states, rates, variables };\n double u[[SIZE]];\n\n[CODE]}\n', g.findRootMethodString(True)) - g.setFindRootMethodString(True, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootMethodString(True)) + self.assertEqual('void findRoot[INDEX](double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals)\n{\n RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals };\n double u[[SIZE]];\n\n[CODE]}\n', g.findRootMethodString(True, True)) + g.setFindRootMethodString(True, True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.findRootMethodString(True, True)) def test_nla_solve_call_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() - self.assertEqual('nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n', g.nlaSolveCallString(False)) - g.setNlaSolveCallString(False, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.nlaSolveCallString(False)) + self.assertEqual('nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n', g.nlaSolveCallString(False, False)) + g.setNlaSolveCallString(False, False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.nlaSolveCallString(False, False)) - self.assertEqual('nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n', g.nlaSolveCallString(True)) - g.setNlaSolveCallString(True, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.nlaSolveCallString(True)) + self.assertEqual('nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n', g.nlaSolveCallString(False, True)) + g.setNlaSolveCallString(False, True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.nlaSolveCallString(False, True)) + + self.assertEqual('nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n', g.nlaSolveCallString(True, False)) + g.setNlaSolveCallString(True, False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.nlaSolveCallString(True, False)) + + self.assertEqual('nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n', g.nlaSolveCallString(True, True)) + g.setNlaSolveCallString(True, True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.nlaSolveCallString(True, True)) def test_objective_function_method_string(self): from libcellml import GeneratorProfile g = GeneratorProfile() - self.assertEqual('void objectiveFunction[INDEX](double *u, double *f, void *data)\n{\n double *variables = ((RootFindingInfo *) data)->variables;\n\n[CODE]}\n', g.objectiveFunctionMethodString(False)) - g.setObjectiveFunctionMethodString(False, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.objectiveFunctionMethodString(False)) + self.assertEqual('void objectiveFunction[INDEX](double *u, double *f, void *data)\n{\n double *constants = ((RootFindingInfo *) data)->constants;\n double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n double *algebraic = ((RootFindingInfo *) data)->algebraic;\n\n[CODE]}\n', g.objectiveFunctionMethodString(False, False)) + g.setObjectiveFunctionMethodString(False, False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.objectiveFunctionMethodString(False, False)) + + self.assertEqual('void objectiveFunction[INDEX](double *u, double *f, void *data)\n{\n double *constants = ((RootFindingInfo *) data)->constants;\n double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n double *algebraic = ((RootFindingInfo *) data)->algebraic;\n double *externals = ((RootFindingInfo *) data)->externals;\n\n[CODE]}\n', g.objectiveFunctionMethodString(False, True)) + g.setObjectiveFunctionMethodString(False, True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.objectiveFunctionMethodString(False, True)) + + self.assertEqual('void objectiveFunction[INDEX](double *u, double *f, void *data)\n{\n double voi = ((RootFindingInfo *) data)->voi;\n double *states = ((RootFindingInfo *) data)->states;\n double *rates = ((RootFindingInfo *) data)->rates;\n double *constants = ((RootFindingInfo *) data)->constants;\n double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n double *algebraic = ((RootFindingInfo *) data)->algebraic;\n\n[CODE]}\n', g.objectiveFunctionMethodString(True, False)) + g.setObjectiveFunctionMethodString(True, False, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.objectiveFunctionMethodString(True, False)) - self.assertEqual('void objectiveFunction[INDEX](double *u, double *f, void *data)\n{\n double voi = ((RootFindingInfo *) data)->voi;\n double *states = ((RootFindingInfo *) data)->states;\n double *rates = ((RootFindingInfo *) data)->rates;\n double *variables = ((RootFindingInfo *) data)->variables;\n\n[CODE]}\n', g.objectiveFunctionMethodString(True)) - g.setObjectiveFunctionMethodString(True, GeneratorProfileTestCase.VALUE) - self.assertEqual(GeneratorProfileTestCase.VALUE, g.objectiveFunctionMethodString(True)) + self.assertEqual('void objectiveFunction[INDEX](double *u, double *f, void *data)\n{\n double voi = ((RootFindingInfo *) data)->voi;\n double *states = ((RootFindingInfo *) data)->states;\n double *rates = ((RootFindingInfo *) data)->rates;\n double *constants = ((RootFindingInfo *) data)->constants;\n double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n double *algebraic = ((RootFindingInfo *) data)->algebraic;\n double *externals = ((RootFindingInfo *) data)->externals;\n\n[CODE]}\n', g.objectiveFunctionMethodString(True, True)) + g.setObjectiveFunctionMethodString(True, True, GeneratorProfileTestCase.VALUE) + self.assertEqual(GeneratorProfileTestCase.VALUE, g.objectiveFunctionMethodString(True, True)) def test_u_array_string(self): from libcellml import GeneratorProfile diff --git a/tests/bindings/python/test_interpreter.py b/tests/bindings/python/test_interpreter.py new file mode 100644 index 0000000000..66b23dd787 --- /dev/null +++ b/tests/bindings/python/test_interpreter.py @@ -0,0 +1,65 @@ +# +# Tests the Interpreter class bindings +# +import numpy as np +import unittest + + +class InterpreterTestCase(unittest.TestCase): + + def test_create_destroy(self): + from libcellml import Interpreter + + x = Interpreter() + del x + + def assert_array_equal(self, expected_values, values): + self.assertEqual(len(expected_values), len(values)) + + for i in range(len(expected_values)): + if np.isnan(expected_values[i]): + self.assertTrue(np.isnan(values[i])) + else: + self.assertAlmostEqual(expected_values[i], values[i]) + + def test_hodgkin_huxley_squid_axon_model_1952(self): + from libcellml import Analyser + from libcellml import AnalyserModel + from libcellml import Interpreter + from libcellml import Parser + from test_resources import file_contents + + p = Parser() + m = p.parseModel(file_contents('generator/hodgkin_huxley_squid_axon_model_1952/model.cellml')) + a = Analyser() + + a.analyseModel(m) + + am = a.model() + + self.assertEqual(AnalyserModel.Type.ODE, am.type()) + + i = Interpreter() + + self.assertIsNone(i.model()) + + i.setModel(am) + + self.assertIsNotNone(i.model()) + + states = np.full(am.stateCount(), np.nan) + rates = np.full(am.stateCount(), np.nan) + variables = np.full(am.variableCount(), np.nan) + + i.initialiseVariables(states, rates, variables) + i.computeComputedConstants(variables) + i.computeRates(0.0, states, rates, variables) + i.computeVariables(0.0, states, rates, variables) + + self.assert_array_equal([0.0, 0.6, 0.05, 0.325], states) + self.assert_array_equal([0.60076875, -0.0004555239065400646, 0.012385538355398518, -0.0013415722863204596], rates) + self.assert_array_equal([0.0, 3.1839, -4.81966875, 1.035, 1.0, 0.0, -10.613, 0.3, -115.0, 120.0, 0.22356372458463003, 4.0, 0.07, 0.04742587317756678, 12.0, 36.0, 0.05819767068693265, 0.125], variables) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/clone/clone.cpp b/tests/clone/clone.cpp index f92ecd62f1..1b0b7a47b0 100644 --- a/tests/clone/clone.cpp +++ b/tests/clone/clone.cpp @@ -503,7 +503,7 @@ TEST(Clone, generateFromClonedModel) generator->setModel(analyser->model()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.c", generator->implementationCode()); libcellml::PrinterPtr p = libcellml::Printer::create(); diff --git a/tests/coverage/coverage.cpp b/tests/coverage/coverage.cpp index 0b1b24495f..f763591714 100644 --- a/tests/coverage/coverage.cpp +++ b/tests/coverage/coverage.cpp @@ -20,6 +20,11 @@ limitations under the License. #include +#include "libcellml/undefines.h" + +#include "../generator/generator.macros.h" +#include "../generator/generator.models.h" + /* * The tests in this file are here to catch any branches of code that * are not picked up by the main tests testing the API of the library @@ -452,9 +457,21 @@ TEST(Coverage, analyser) EXPECT_EQ(size_t(0), analyserModel->states().size()); EXPECT_EQ(nullptr, analyserModel->state(0)); - EXPECT_EQ(size_t(0), analyserModel->variableCount()); - EXPECT_EQ(size_t(0), analyserModel->variables().size()); - EXPECT_EQ(nullptr, analyserModel->variable(0)); + EXPECT_EQ(size_t(0), analyserModel->constantCount()); + EXPECT_EQ(size_t(0), analyserModel->constants().size()); + EXPECT_EQ(nullptr, analyserModel->constant(0)); + + EXPECT_EQ(size_t(0), analyserModel->computedConstantCount()); + EXPECT_EQ(size_t(0), analyserModel->computedConstants().size()); + EXPECT_EQ(nullptr, analyserModel->computedConstant(0)); + + EXPECT_EQ(size_t(0), analyserModel->algebraicCount()); + EXPECT_EQ(size_t(0), analyserModel->algebraic().size()); + EXPECT_EQ(nullptr, analyserModel->algebraic(0)); + + EXPECT_EQ(size_t(0), analyserModel->externalCount()); + EXPECT_EQ(size_t(0), analyserModel->externals().size()); + EXPECT_EQ(nullptr, analyserModel->external(0)); EXPECT_EQ(size_t(0), analyserModel->equationCount()); EXPECT_EQ(size_t(0), analyserModel->equations().size()); @@ -548,7 +565,7 @@ TEST(Coverage, analyserTypes) auto analyserModel = analyser->model(); EXPECT_EQ("algebraic", libcellml::AnalyserEquation::typeAsString(analyserModel->equation(0)->type())); - EXPECT_EQ("algebraic", libcellml::AnalyserVariable::typeAsString(analyserModel->variable(0)->type())); + EXPECT_EQ("algebraic", libcellml::AnalyserVariable::typeAsString(analyserModel->algebraic(0)->type())); } void checkAstTypeAsString(const libcellml::AnalyserEquationAstPtr &ast) @@ -572,6 +589,8 @@ TEST(Coverage, generator) auto analyser = libcellml::Analyser::create(); + analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("my_component")->variable("eqnPlus"))); + analyser->analyseModel(model); EXPECT_EQ(size_t(0), analyser->errorCount()); @@ -582,8 +601,11 @@ TEST(Coverage, generator) EXPECT_EQ("dae", libcellml::AnalyserModel::typeAsString(analyserModel->type())); EXPECT_EQ(size_t(1), analyserModel->stateCount()); - EXPECT_EQ(size_t(209), analyserModel->variableCount()); - EXPECT_EQ(size_t(203), analyserModel->equationCount()); + EXPECT_EQ(size_t(7), analyserModel->constantCount()); + EXPECT_EQ(size_t(207), analyserModel->computedConstantCount()); + EXPECT_EQ(size_t(5), analyserModel->algebraicCount()); + EXPECT_EQ(size_t(1), analyserModel->externalCount()); + EXPECT_EQ(size_t(214), analyserModel->equationCount()); EXPECT_NE(nullptr, analyserModel->voi()); EXPECT_EQ(size_t(0), analyserModel->voi()->equationCount()); @@ -593,42 +615,46 @@ TEST(Coverage, generator) EXPECT_NE(size_t(0), analyserModel->state(0)->equationCount()); EXPECT_NE(size_t(0), analyserModel->state(0)->equations().size()); EXPECT_NE(nullptr, analyserModel->state(0)->equation(0)); + EXPECT_NE(nullptr, analyserModel->state(0)->equation(0)->state(0)); EXPECT_EQ(nullptr, analyserModel->state(analyserModel->stateCount())); - EXPECT_NE(nullptr, analyserModel->variable(0)); - EXPECT_EQ(nullptr, analyserModel->variable(analyserModel->variableCount())); - EXPECT_NE(nullptr, analyserModel->equation(199)); - EXPECT_NE(size_t(0), analyserModel->equation(199)->dependencyCount()); - EXPECT_NE(size_t(0), analyserModel->equation(199)->dependencies().size()); - EXPECT_NE(nullptr, analyserModel->equation(199)->dependency(0)); - EXPECT_EQ(nullptr, analyserModel->equation(199)->dependency(analyserModel->equation(199)->dependencyCount())); - EXPECT_EQ(size_t(1), analyserModel->equation(199)->nlaSiblingCount()); - EXPECT_EQ(size_t(1), analyserModel->equation(199)->nlaSiblings().size()); - EXPECT_NE(nullptr, analyserModel->equation(199)->nlaSibling(0)); - EXPECT_EQ(nullptr, analyserModel->equation(199)->nlaSibling(analyserModel->equation(199)->nlaSiblingCount())); - EXPECT_NE(size_t(0), analyserModel->equation(199)->variableCount()); - EXPECT_NE(size_t(0), analyserModel->equation(199)->variables().size()); - EXPECT_NE(nullptr, analyserModel->equation(199)->variable(0)); - EXPECT_EQ(nullptr, analyserModel->equation(199)->variable(analyserModel->equation(199)->variableCount())); - EXPECT_EQ(nullptr, analyserModel->equation(analyserModel->equationCount())); + EXPECT_NE(nullptr, analyserModel->constant(0)); + EXPECT_EQ(nullptr, analyserModel->constant(analyserModel->constantCount())); + EXPECT_NE(nullptr, analyserModel->computedConstant(0)); + EXPECT_NE(nullptr, analyserModel->computedConstant(0)->equation(0)->computedConstant(0)); + EXPECT_EQ(nullptr, analyserModel->computedConstant(analyserModel->computedConstantCount())); + EXPECT_NE(nullptr, analyserModel->algebraic(0)); + EXPECT_NE(nullptr, analyserModel->algebraic(0)->equation(0)->algebraic(0)); + EXPECT_EQ(nullptr, analyserModel->algebraic(analyserModel->algebraicCount())); + EXPECT_NE(nullptr, analyserModel->external(0)); + EXPECT_NE(nullptr, analyserModel->external(0)->equation(0)->external(0)); + EXPECT_EQ(nullptr, analyserModel->external(analyserModel->algebraicCount())); + EXPECT_EQ(size_t(1), analyserModel->equation(0)->stateCount()); + EXPECT_EQ(size_t(1), analyserModel->equation(0)->states().size()); + EXPECT_NE(nullptr, analyserModel->equation(0)->state(0)); + EXPECT_EQ(nullptr, analyserModel->equation(0)->state(analyserModel->equation(0)->stateCount())); for (const auto &equation : analyserModel->equations()) { + equation->dependencyCount(); + equation->dependency(0); + equation->dependency(equation->dependencyCount()); + equation->nlaSiblingCount(); + equation->nlaSibling(0); + equation->nlaSibling(equation->nlaSiblingCount()); + equation->computedConstantCount(); + equation->computedConstant(0); + equation->computedConstant(equation->computedConstantCount()); + equation->algebraicCount(); + equation->algebraic(0); + equation->algebraic(equation->algebraicCount()); + equation->externalCount(); + equation->external(0); + equation->external(equation->externalCount()); + checkAstTypeAsString(equation->ast()); } auto generator = libcellml::Generator::create(); - EXPECT_EQ(nullptr, analyserModel->voi()->initialisingVariable()); - - for (size_t i = 0; i < analyserModel->stateCount(); ++i) { - EXPECT_NE(nullptr, analyserModel->state(i)->initialisingVariable()); - } - - for (size_t i = 0; i < analyserModel->variableCount(); ++i) { - if ((i == 1) || (i == 2) || (i == 6) || (i == 18) || (i == 179) || (i == 180) || (i == 182) || (i == 205) || (i == 206)) { - EXPECT_TRUE(analyserModel->variable(i)->initialisingVariable() != nullptr); - } - } - EXPECT_EQ(nullptr, generator->model()); EXPECT_EQ(EMPTY_STRING, generator->interfaceCode()); EXPECT_EQ(EMPTY_STRING, generator->implementationCode()); @@ -636,25 +662,19 @@ TEST(Coverage, generator) generator->setModel(analyserModel); EXPECT_EQ(analyserModel, generator->model()); - EXPECT_EQ(fileContents("coverage/generator/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("coverage/generator/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.c", generator->implementationCode()); auto profile = generator->profile(); - profile->setInterfaceCreateStatesArrayMethodString("double * createStatesVector();\n"); - profile->setImplementationCreateStatesArrayMethodString("double * createStatesVector()\n" - "{\n" - " double *res = (double *) malloc(STATE_COUNT*sizeof(double));\n" - "\n" - " for (size_t i = 0; i < STATE_COUNT; ++i) {\n" - " res[i] = NAN;\n" - " }\n" - "\n" - " return res;\n" - "}\n"); - - EXPECT_EQ(fileContents("coverage/generator/model.modified.profile.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("coverage/generator/model.modified.profile.c"), generator->implementationCode()); + profile->setXorString("XOR"); + profile->setXorFunctionString("double XOR(double x, double y)\n" + "{\n" + " return (x != 0.0) ^ (y != 0.0);\n" + "}\n"); + + EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.xor.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.xor.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(); @@ -683,19 +703,10 @@ TEST(Coverage, generator) profile->setImplementationStateCountString(""); - profile->setImplementationVariableCountString(""); - - profile->setVariableTypeObjectString(false, false, ""); - profile->setVariableTypeObjectString(false, true, ""); - profile->setVariableTypeObjectString(true, false, ""); - profile->setVariableTypeObjectString(true, true, ""); - - profile->setVariableOfIntegrationVariableTypeString(""); - profile->setStateVariableTypeString(""); - profile->setConstantVariableTypeString(""); - profile->setComputedConstantVariableTypeString(""); - profile->setAlgebraicVariableTypeString(""); - profile->setExternalVariableTypeString(""); + profile->setImplementationConstantCountString(""); + profile->setImplementationComputedConstantCountString(""); + profile->setImplementationAlgebraicCountString(""); + profile->setImplementationExternalCountString(""); profile->setVariableInfoObjectString(""); @@ -703,23 +714,38 @@ TEST(Coverage, generator) profile->setImplementationStateInfoString(""); - profile->setImplementationVariableInfoString(""); + profile->setImplementationConstantInfoString(""); + + profile->setImplementationComputedConstantInfoString(""); + + profile->setImplementationAlgebraicInfoString(""); + + profile->setImplementationExternalInfoString(""); profile->setVariableInfoEntryString(""); profile->setImplementationCreateStatesArrayMethodString(""); - profile->setImplementationCreateVariablesArrayMethodString(""); + profile->setImplementationCreateConstantsArrayMethodString(""); + + profile->setImplementationCreateComputedConstantsArrayMethodString(""); + + profile->setImplementationCreateAlgebraicArrayMethodString(""); + + profile->setImplementationCreateExternalsArrayMethodString(""); profile->setImplementationDeleteArrayMethodString(""); + profile->setImplementationInitialiseVariablesMethodString(false, ""); + profile->setImplementationInitialiseVariablesMethodString(true, ""); + profile->setImplementationComputeVariablesMethodString(false, false, ""); profile->setImplementationComputeVariablesMethodString(false, true, ""); profile->setImplementationComputeVariablesMethodString(true, false, ""); profile->setImplementationComputeVariablesMethodString(true, true, ""); EXPECT_EQ(EMPTY_STRING, generator->interfaceCode()); - EXPECT_EQ(fileContents("coverage/generator/model.out"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.out", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(); @@ -758,20 +784,17 @@ TEST(Coverage, generator) profile->setInterfaceStateCountString(""); profile->setImplementationStateCountString(""); - profile->setInterfaceVariableCountString(""); - profile->setImplementationVariableCountString(""); + profile->setInterfaceConstantCountString(""); + profile->setImplementationConstantCountString(""); + + profile->setInterfaceComputedConstantCountString(""); + profile->setImplementationComputedConstantCountString(""); - profile->setVariableTypeObjectString(false, false, ""); - profile->setVariableTypeObjectString(false, true, ""); - profile->setVariableTypeObjectString(true, false, ""); - profile->setVariableTypeObjectString(true, true, ""); + profile->setInterfaceAlgebraicCountString(""); + profile->setImplementationAlgebraicCountString(""); - profile->setVariableOfIntegrationVariableTypeString(""); - profile->setStateVariableTypeString(""); - profile->setConstantVariableTypeString(""); - profile->setComputedConstantVariableTypeString(""); - profile->setAlgebraicVariableTypeString(""); - profile->setExternalVariableTypeString(""); + profile->setInterfaceExternalCountString(""); + profile->setImplementationExternalCountString(""); profile->setVariableInfoObjectString(""); @@ -781,25 +804,35 @@ TEST(Coverage, generator) profile->setInterfaceStateInfoString(""); profile->setImplementationStateInfoString(""); - profile->setInterfaceVariableInfoString(""); - profile->setImplementationVariableInfoString(""); + profile->setInterfaceConstantInfoString(""); + profile->setImplementationConstantInfoString(""); + + profile->setInterfaceComputedConstantInfoString(""); + profile->setImplementationComputedConstantInfoString(""); + + profile->setInterfaceAlgebraicInfoString(""); + profile->setImplementationAlgebraicInfoString(""); + + profile->setInterfaceExternalInfoString(""); + profile->setImplementationExternalInfoString(""); profile->setVariableInfoEntryString(""); - EXPECT_EQ(fileContents("coverage/generator/model.interface.out"), generator->interfaceCode()); - EXPECT_EQ(fileContents("coverage/generator/model.implementation.out"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.interface.out", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.implementation.out", generator->implementationCode()); profile->setProfile(libcellml::GeneratorProfile::Profile::PYTHON); EXPECT_EQ(EMPTY_STRING, generator->interfaceCode()); - EXPECT_EQ(fileContents("coverage/generator/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.py", generator->implementationCode()); - profile->setImplementationCreateStatesArrayMethodString("\n" - "def create_states_vector():\n" - " return [nan]*STATE_COUNT\n"); + profile->setXorString("XOR_FUNC"); + profile->setXorFunctionString("\n" + "def XOR_FUNC(x, y):\n" + " return 1.0 if bool(x) ^ bool(y) else 0.0\n"); EXPECT_EQ(EMPTY_STRING, generator->interfaceCode()); - EXPECT_EQ(fileContents("coverage/generator/model.modified.profile.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.xor.py", generator->implementationCode()); // Coverage for the case where mProfile is equal to nullptr in Generator. @@ -836,13 +869,14 @@ TEST(Coverage, generator) profile->setImplementationComputeComputedConstantsMethodString(""); profile->setImplementationComputeRatesMethodString(true, ""); profile->setImplementationHeaderString("[INTERFACE_FILE_NAME]"); - profile->setImplementationInitialiseVariablesMethodString(true, true, ""); profile->setInterfaceFileNameString(""); profile->setInterfaceHeaderString(""); profile->setMaxFunctionString(""); profile->setMinFunctionString(""); - profile->setObjectiveFunctionMethodString(false, ""); - profile->setObjectiveFunctionMethodString(true, ""); + profile->setObjectiveFunctionMethodString(false, false, ""); + profile->setObjectiveFunctionMethodString(false, true, ""); + profile->setObjectiveFunctionMethodString(true, false, ""); + profile->setObjectiveFunctionMethodString(true, true, ""); profile->setSecFunctionString(""); profile->setSechFunctionString(""); profile->setVariableInfoEntryString(""); @@ -852,10 +886,14 @@ TEST(Coverage, generator) profile->setArrayElementSeparatorString(""); profile->setCommentString("xxx"); - profile->setFindRootMethodString(false, ""); - profile->setFindRootMethodString(true, ""); - profile->setObjectiveFunctionMethodString(false, "xxx"); - profile->setObjectiveFunctionMethodString(true, "xxx"); + profile->setFindRootMethodString(false, false, ""); + profile->setFindRootMethodString(false, true, ""); + profile->setFindRootMethodString(true, false, ""); + profile->setFindRootMethodString(true, true, ""); + profile->setObjectiveFunctionMethodString(false, false, "xxx"); + profile->setObjectiveFunctionMethodString(false, true, "xxx"); + profile->setObjectiveFunctionMethodString(true, false, "xxx"); + profile->setObjectiveFunctionMethodString(true, true, "xxx"); profile->setOriginCommentString(""); profile->setVariableInfoEntryString("xxx"); @@ -863,47 +901,60 @@ TEST(Coverage, generator) profile->setArrayElementSeparatorString("xxx"); profile->setExternNlaSolveMethodString(""); - profile->setFindRootMethodString(false, "xxx"); - profile->setFindRootMethodString(true, "xxx"); - profile->setFindRootCallString(false, ""); - profile->setFindRootCallString(true, ""); - profile->setNlaSolveCallString(false, ""); - profile->setNlaSolveCallString(true, ""); - profile->setVariableOfIntegrationVariableTypeString(""); + profile->setFindRootMethodString(false, false, "xxx"); + profile->setFindRootMethodString(false, true, "xxx"); + profile->setFindRootMethodString(true, false, "xxx"); + profile->setFindRootMethodString(true, true, "xxx"); + profile->setFindRootCallString(false, false, ""); + profile->setFindRootCallString(false, true, ""); + profile->setFindRootCallString(true, false, ""); + profile->setFindRootCallString(true, true, ""); + profile->setNlaSolveCallString(false, false, ""); + profile->setNlaSolveCallString(false, true, ""); + profile->setNlaSolveCallString(true, false, ""); + profile->setNlaSolveCallString(true, true, ""); generator->implementationCode(); - profile->setStateVariableTypeString(""); - profile->setVariableOfIntegrationVariableTypeString("xxx"); + profile->setHasXorOperator(false); + profile->setXorFunctionString(""); generator->implementationCode(); - profile->setConstantVariableTypeString(""); - profile->setStateVariableTypeString("xxx"); + libcellml::Generator::equationCode(analyser->model()->equation(0)->ast()); +} - generator->implementationCode(); +TEST(Coverage, interpreter) +{ + // Get an analyser model for our coverage model. - profile->setComputedConstantVariableTypeString(""); - profile->setConstantVariableTypeString("xxx"); + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("coverage/generator/model.cellml")); + auto analyser = libcellml::Analyser::create(); - generator->implementationCode(); + analyser->analyseModel(model); - profile->setComputedConstantVariableTypeString("xxx"); - profile->setAlgebraicVariableTypeString(""); + auto analyserModel = analyser->model(); - generator->implementationCode(); + // Test our coverage model, i.e. make sure that our interpreter can evaluate our coverage model and that it gives + // the same results as our compiled model. + // Note: the C file that we use to compile our model has its XOr function called XOR rather than xor since xor is a + // reserved keyword in C++. - profile->setAlgebraicVariableTypeString("xxx"); - profile->setExternalVariableTypeString(""); + //---GRY--- TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, coverage); + auto interpreter = libcellml::Interpreter::create(); - generator->implementationCode(); + // Make sure that Interpreter::model() works as expected. - profile->setHasXorOperator(false); - profile->setXorFunctionString(""); + EXPECT_EQ(nullptr, interpreter->model()); - generator->implementationCode(); + interpreter->setModel(analyserModel); - libcellml::Generator::equationCode(analyser->model()->equation(0)->ast()); + EXPECT_EQ(analyserModel, interpreter->model()); + + interpreter->setModel(nullptr); + + EXPECT_EQ(nullptr, interpreter->model()); } TEST(CoverageValidator, degreeElementWithOneSibling) diff --git a/tests/generator/generator.cpp b/tests/generator/generator.cpp index 2494fa8dcf..64848c492f 100644 --- a/tests/generator/generator.cpp +++ b/tests/generator/generator.cpp @@ -14,11 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ +#ifdef _WIN32 +# define _USE_MATH_DEFINES +#endif + #include "test_utils.h" #include "gtest/gtest.h" -#include +#include "libcellml/undefines.h" + +#include "generator.macros.h" +#include "generator.models.h" static const std::string EMPTY_STRING; @@ -58,14 +65,16 @@ TEST(Generator, algebraicEqnComputedVarOnRhs) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/algebraic_eqn_computed_var_on_rhs/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_eqn_computed_var_on_rhs/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_computed_var_on_rhs/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_computed_var_on_rhs/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_eqn_computed_var_on_rhs/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_computed_var_on_rhs/model.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL(analyserModel, algebraic_eqn_computed_var_on_rhs); } TEST(Generator, algebraicEqnComputedVarOnRhsWithComputedConstantAsExternalVariable) @@ -92,14 +101,16 @@ TEST(Generator, algebraicEqnComputedVarOnRhsWithComputedConstantAsExternalVariab profile->setInterfaceFileNameString("model.external.h"); - EXPECT_EQ(fileContents("generator/algebraic_eqn_computed_var_on_rhs/model.external.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_eqn_computed_var_on_rhs/model.external.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_computed_var_on_rhs/model.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_computed_var_on_rhs/model.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_eqn_computed_var_on_rhs/model.external.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_computed_var_on_rhs/model.external.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL_EXTERNAL(analyserModel, algebraic_eqn_computed_var_on_rhs_external); } TEST(Generator, algebraicEqnConstVarOnRhs) @@ -120,14 +131,16 @@ TEST(Generator, algebraicEqnConstVarOnRhs) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/algebraic_eqn_const_var_on_rhs/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_eqn_const_var_on_rhs/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_const_var_on_rhs/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_const_var_on_rhs/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_eqn_const_var_on_rhs/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_const_var_on_rhs/model.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL(analyserModel, algebraic_eqn_const_var_on_rhs); } TEST(Generator, algebraicEqnConstantOnRhs) @@ -148,14 +161,16 @@ TEST(Generator, algebraicEqnConstantOnRhs) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/algebraic_eqn_constant_on_rhs/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_eqn_constant_on_rhs/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_constant_on_rhs/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_constant_on_rhs/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_eqn_constant_on_rhs/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_constant_on_rhs/model.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL(analyserModel, algebraic_eqn_constant_on_rhs); } TEST(Generator, algebraicEqnDerivativeOnRhs) @@ -176,14 +191,16 @@ TEST(Generator, algebraicEqnDerivativeOnRhs) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/algebraic_eqn_derivative_on_rhs/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_eqn_derivative_on_rhs/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_derivative_on_rhs/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_derivative_on_rhs/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_eqn_derivative_on_rhs/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_derivative_on_rhs/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, algebraic_eqn_derivative_on_rhs); } TEST(Generator, algebraicEqnDerivativeOnRhsOneComponent) @@ -204,14 +221,16 @@ TEST(Generator, algebraicEqnDerivativeOnRhsOneComponent) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/algebraic_eqn_derivative_on_rhs_one_component/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_eqn_derivative_on_rhs_one_component/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_derivative_on_rhs_one_component/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_derivative_on_rhs_one_component/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_eqn_derivative_on_rhs_one_component/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_derivative_on_rhs_one_component/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, algebraic_eqn_derivative_on_rhs_one_component); } TEST(Generator, algebraicEqnStateVarOnRhs) @@ -232,14 +251,16 @@ TEST(Generator, algebraicEqnStateVarOnRhs) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/algebraic_eqn_state_var_on_rhs/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_eqn_state_var_on_rhs/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_state_var_on_rhs/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_state_var_on_rhs/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_eqn_state_var_on_rhs/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_state_var_on_rhs/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, algebraic_eqn_state_var_on_rhs); } TEST(Generator, algebraicEqnStateVarOnRhsOneComponent) @@ -260,14 +281,16 @@ TEST(Generator, algebraicEqnStateVarOnRhsOneComponent) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/algebraic_eqn_state_var_on_rhs_one_component/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_eqn_state_var_on_rhs_one_component/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_state_var_on_rhs_one_component/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_state_var_on_rhs_one_component/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_eqn_state_var_on_rhs_one_component/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_state_var_on_rhs_one_component/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, algebraic_eqn_state_var_on_rhs_one_component); } TEST(Generator, algebraicUnknownVarOnRhs) @@ -288,14 +311,16 @@ TEST(Generator, algebraicUnknownVarOnRhs) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/algebraic_unknown_var_on_rhs/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_unknown_var_on_rhs/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_unknown_var_on_rhs/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_unknown_var_on_rhs/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_unknown_var_on_rhs/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_unknown_var_on_rhs/model.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL(analyserModel, algebraic_unknown_var_on_rhs); } TEST(Generator, algebraicEqnWithOneNonIsolatedUnknown) @@ -316,14 +341,16 @@ TEST(Generator, algebraicEqnWithOneNonIsolatedUnknown) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/algebraic_eqn_with_one_non_isolated_unknown/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_eqn_with_one_non_isolated_unknown/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_with_one_non_isolated_unknown/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_with_one_non_isolated_unknown/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_eqn_with_one_non_isolated_unknown/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_with_one_non_isolated_unknown/model.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL(analyserModel, algebraic_eqn_with_one_non_isolated_unknown); } TEST(Generator, algebraicEqnWithOneNonIsolatedUnknownWithExternalVariable) @@ -335,7 +362,7 @@ TEST(Generator, algebraicEqnWithOneNonIsolatedUnknownWithExternalVariable) auto analyser = libcellml::Analyser::create(); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("my_algebraic_eqn")->variable("a"))); + analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("my_algebraic_eqn")->variable("c"))); analyser->analyseModel(model); @@ -350,14 +377,16 @@ TEST(Generator, algebraicEqnWithOneNonIsolatedUnknownWithExternalVariable) profile->setInterfaceFileNameString("model.external.h"); - EXPECT_EQ(fileContents("generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL_EXTERNAL(analyserModel, algebraic_eqn_with_one_non_isolated_unknown_external); } TEST(Generator, algebraicSystemWithThreeLinkedUnknowns) @@ -378,14 +407,16 @@ TEST(Generator, algebraicSystemWithThreeLinkedUnknowns) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/algebraic_system_with_three_linked_unknowns/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_system_with_three_linked_unknowns/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_three_linked_unknowns/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_three_linked_unknowns/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_system_with_three_linked_unknowns/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_three_linked_unknowns/model.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL(analyserModel, algebraic_system_with_three_linked_unknowns); } TEST(Generator, algebraicSystemWithThreeLinkedUnknownsWithThreeExternalVariables) @@ -412,16 +443,18 @@ TEST(Generator, algebraicSystemWithThreeLinkedUnknownsWithThreeExternalVariables auto profile = generator->profile(); - profile->setInterfaceFileNameString("model.three.externals.h"); + profile->setInterfaceFileNameString("model.external.h"); - EXPECT_EQ(fileContents("generator/algebraic_system_with_three_linked_unknowns/model.three.externals.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_system_with_three_linked_unknowns/model.three.externals.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_three_linked_unknowns/model.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_three_linked_unknowns/model.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_system_with_three_linked_unknowns/model.three.externals.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_three_linked_unknowns/model.external.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL_EXTERNAL(analyserModel, algebraic_system_with_three_linked_unknowns_external); } TEST(Generator, algebraicSystemWithVariousDependenciesOrdered) @@ -446,14 +479,16 @@ TEST(Generator, algebraicSystemWithVariousDependenciesOrdered) profile->setInterfaceFileNameString("model.ordered.h"); - EXPECT_EQ(fileContents("generator/algebraic_system_with_various_dependencies/model.ordered.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_system_with_various_dependencies/model.ordered.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_various_dependencies/model.ordered.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_various_dependencies/model.ordered.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_system_with_various_dependencies/model.ordered.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_various_dependencies/model.ordered.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL(analyserModel, algebraic_system_with_various_dependencies_ordered); } TEST(Generator, algebraicSystemWithVariousDependenciesNotOrdered) @@ -478,14 +513,16 @@ TEST(Generator, algebraicSystemWithVariousDependenciesNotOrdered) profile->setInterfaceFileNameString("model.not.ordered.h"); - EXPECT_EQ(fileContents("generator/algebraic_system_with_various_dependencies/model.not.ordered.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/algebraic_system_with_various_dependencies/model.not.ordered.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_various_dependencies/model.not.ordered.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_various_dependencies/model.not.ordered.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/algebraic_system_with_various_dependencies/model.not.ordered.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/algebraic_system_with_various_dependencies/model.not.ordered.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL(analyserModel, algebraic_system_with_various_dependencies_not_ordered); } TEST(Generator, odeComputedVarOnRhs) @@ -506,14 +543,16 @@ TEST(Generator, odeComputedVarOnRhs) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/ode_computed_var_on_rhs/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/ode_computed_var_on_rhs/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_computed_var_on_rhs/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_computed_var_on_rhs/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/ode_computed_var_on_rhs/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_computed_var_on_rhs/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, ode_computed_var_on_rhs); } TEST(Generator, odeComputedVarOnRhsOneComponent) @@ -534,14 +573,16 @@ TEST(Generator, odeComputedVarOnRhsOneComponent) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/ode_computed_var_on_rhs_one_component/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/ode_computed_var_on_rhs_one_component/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_computed_var_on_rhs_one_component/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_computed_var_on_rhs_one_component/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/ode_computed_var_on_rhs_one_component/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_computed_var_on_rhs_one_component/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, ode_computed_var_on_rhs_one_component); } TEST(Generator, odeConstVarOnRhs) @@ -562,14 +603,16 @@ TEST(Generator, odeConstVarOnRhs) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/ode_const_var_on_rhs/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/ode_const_var_on_rhs/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_const_var_on_rhs/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_const_var_on_rhs/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/ode_const_var_on_rhs/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_const_var_on_rhs/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, ode_const_var_on_rhs); } TEST(Generator, odeConstVarOnRhsOneComponent) @@ -590,14 +633,16 @@ TEST(Generator, odeConstVarOnRhsOneComponent) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/ode_const_var_on_rhs_one_component/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/ode_const_var_on_rhs_one_component/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_const_var_on_rhs_one_component/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_const_var_on_rhs_one_component/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/ode_const_var_on_rhs_one_component/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_const_var_on_rhs_one_component/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, ode_const_var_on_rhs_one_component); } TEST(Generator, odeConstantOnRhs) @@ -618,14 +663,16 @@ TEST(Generator, odeConstantOnRhs) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/ode_constant_on_rhs/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/ode_constant_on_rhs/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_constant_on_rhs/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_constant_on_rhs/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/ode_constant_on_rhs/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_constant_on_rhs/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, ode_constant_on_rhs); } TEST(Generator, odeConstantOnRhsOneComponent) @@ -646,14 +693,16 @@ TEST(Generator, odeConstantOnRhsOneComponent) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/ode_constant_on_rhs_one_component/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/ode_constant_on_rhs_one_component/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_constant_on_rhs_one_component/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_constant_on_rhs_one_component/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/ode_constant_on_rhs_one_component/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_constant_on_rhs_one_component/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, ode_constant_on_rhs_one_component); } TEST(Generator, odeMultipleDependentOdes) @@ -674,14 +723,16 @@ TEST(Generator, odeMultipleDependentOdes) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/ode_multiple_dependent_odes/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/ode_multiple_dependent_odes/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_multiple_dependent_odes/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_multiple_dependent_odes/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/ode_multiple_dependent_odes/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_multiple_dependent_odes/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, ode_multiple_dependent_odes); } TEST(Generator, odeMultipleDependentOdesOneComponent) @@ -702,14 +753,16 @@ TEST(Generator, odeMultipleDependentOdesOneComponent) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/ode_multiple_dependent_odes_one_component/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/ode_multiple_dependent_odes_one_component/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_multiple_dependent_odes_one_component/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_multiple_dependent_odes_one_component/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/ode_multiple_dependent_odes_one_component/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_multiple_dependent_odes_one_component/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, ode_multiple_dependent_odes_one_component); } TEST(Generator, odeMultipleOdesWithSameName) @@ -730,14 +783,16 @@ TEST(Generator, odeMultipleOdesWithSameName) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/ode_multiple_odes_with_same_name/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/ode_multiple_odes_with_same_name/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_multiple_odes_with_same_name/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_multiple_odes_with_same_name/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/ode_multiple_odes_with_same_name/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_multiple_odes_with_same_name/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, ode_multiple_odes_with_same_name); } TEST(Generator, odeUnknownVarOnRhs) @@ -758,14 +813,16 @@ TEST(Generator, odeUnknownVarOnRhs) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/ode_unknown_var_on_rhs/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/ode_unknown_var_on_rhs/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_unknown_var_on_rhs/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_unknown_var_on_rhs/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/ode_unknown_var_on_rhs/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_unknown_var_on_rhs/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, ode_unknown_var_on_rhs); } TEST(Generator, cellmlMappingsAndEncapsulations) @@ -786,14 +843,16 @@ TEST(Generator, cellmlMappingsAndEncapsulations) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/cellml_mappings_and_encapsulations/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/cellml_mappings_and_encapsulations/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_mappings_and_encapsulations/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_mappings_and_encapsulations/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cellml_mappings_and_encapsulations/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_mappings_and_encapsulations/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, cellml_mappings_and_encapsulations); } TEST(Generator, cellmlStateInitialisedUsingVariable) @@ -814,14 +873,16 @@ TEST(Generator, cellmlStateInitialisedUsingVariable) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/cellml_state_initialised_using_variable/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/cellml_state_initialised_using_variable/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_state_initialised_using_variable/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_state_initialised_using_variable/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cellml_state_initialised_using_variable/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_state_initialised_using_variable/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, cellml_state_initialised_using_variable); } TEST(Generator, cellmlUnitScalingVoiIndirect) @@ -842,14 +903,16 @@ TEST(Generator, cellmlUnitScalingVoiIndirect) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_voi_indirect/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_voi_indirect/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_voi_indirect/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_voi_indirect/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_voi_indirect/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_voi_indirect/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, cellml_unit_scaling_voi_indirect); } TEST(Generator, cellmlUnitScalingVoiDirect) @@ -870,14 +933,16 @@ TEST(Generator, cellmlUnitScalingVoiDirect) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_voi_direct/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_voi_direct/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_voi_direct/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_voi_direct/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_voi_direct/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_voi_direct/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, cellml_unit_scaling_voi_direct); } TEST(Generator, cellmlUnitScalingConstant) @@ -889,23 +954,30 @@ TEST(Generator, cellmlUnitScalingConstant) auto analyser = libcellml::Analyser::create(); + const std::vector expectedIssues = { + "Variable 'c_M' in component 'constants' is initialised using variable 'c' which has different units.", + "Variable 'oc_mM' in component 'other_constants' is initialised using variable 'c' which has different units.", + }; + analyser->analyseModel(model); - EXPECT_EQ(size_t(0), analyser->errorCount()); + EXPECT_EQ_ISSUES(expectedIssues, analyser); auto analyserModel = analyser->model(); auto generator = libcellml::Generator::create(); generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_constant/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_constant/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_constant/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_constant/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_constant/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_constant/model.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL(analyserModel, cellml_unit_scaling_constant); } TEST(Generator, cellmlUnitScalingState) @@ -926,14 +998,16 @@ TEST(Generator, cellmlUnitScalingState) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_state/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_state/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_state/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_state/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_state/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_state/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, cellml_unit_scaling_state); } TEST(Generator, cellmlUnitScalingStateInitialisedUsingConstant) @@ -954,14 +1028,16 @@ TEST(Generator, cellmlUnitScalingStateInitialisedUsingConstant) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_state_initialised_using_constant/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_state_initialised_using_constant/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_state_initialised_using_constant/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_state_initialised_using_constant/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_state_initialised_using_constant/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_state_initialised_using_constant/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, cellml_unit_scaling_state_initialised_using_constant); } TEST(Generator, cellmlUnitScalingStateInitialisedUsingVariable) @@ -982,14 +1058,16 @@ TEST(Generator, cellmlUnitScalingStateInitialisedUsingVariable) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_state_initialised_using_variable/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_state_initialised_using_variable/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_state_initialised_using_variable/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_state_initialised_using_variable/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_state_initialised_using_variable/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_state_initialised_using_variable/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, cellml_unit_scaling_state_initialised_using_variable); } TEST(Generator, cellmlUnitScalingRate) @@ -1010,14 +1088,16 @@ TEST(Generator, cellmlUnitScalingRate) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_rate/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_rate/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_rate/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_rate/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cellml_unit_scaling_rate/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unit_scaling_rate/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, cellml_unit_scaling_rate); } TEST(Generator, dependentEqns) @@ -1038,14 +1118,16 @@ TEST(Generator, dependentEqns) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/dependent_eqns/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/dependent_eqns/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/dependent_eqns/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/dependent_eqns/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/dependent_eqns/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/dependent_eqns/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, dependent_eqns); } TEST(Generator, cellGeometryModel) @@ -1066,14 +1148,16 @@ TEST(Generator, cellGeometryModel) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/cell_geometry_model/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/cell_geometry_model/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cell_geometry_model/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cell_geometry_model/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cell_geometry_model/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cell_geometry_model/model.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL(analyserModel, cell_geometry_model); } TEST(Generator, cellGeometryModelWithSomeConstantsAsExternalVariables) @@ -1101,14 +1185,16 @@ TEST(Generator, cellGeometryModelWithSomeConstantsAsExternalVariables) profile->setInterfaceFileNameString("model.external.h"); - EXPECT_EQ(fileContents("generator/cell_geometry_model/model.external.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/cell_geometry_model/model.external.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cell_geometry_model/model.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cell_geometry_model/model.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cell_geometry_model/model.external.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cell_geometry_model/model.external.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL_EXTERNAL(analyserModel, cell_geometry_model_external); } TEST(Generator, fabbriFantiniWildersSeveriHumanSanModel2017) @@ -1129,14 +1215,16 @@ TEST(Generator, fabbriFantiniWildersSeveriHumanSanModel2017) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, fabbri_fantini_wilders_severi_human_san_model_2017); } TEST(Generator, garnyKohlHunterBoyettNobleRabbitSanModel2003) @@ -1157,14 +1245,16 @@ TEST(Generator, garnyKohlHunterBoyettNobleRabbitSanModel2003) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, garny_kohl_hunter_boyett_noble_rabbit_san_model_2003); } TEST(Generator, hodgkinHuxleySquidAxonModel1952) @@ -1185,20 +1275,22 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, hodgkin_huxley_squid_axon_model_1952); } TEST(Generator, hodgkinHuxleySquidAxonModel1952UnknownVarsOnRhs) { auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model_unknown_vars_on_rhs.cellml")); + auto model = parser->parseModel(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.unknown.vars.on.rhs.cellml")); EXPECT_EQ(size_t(0), parser->issueCount()); @@ -1213,14 +1305,16 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952UnknownVarsOnRhs) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, hodgkin_huxley_squid_axon_model_1952); } TEST(Generator, hodgkinHuxleySquidAxonModel1952WithStateVariableAsExternalVariable) @@ -1248,16 +1342,18 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithStateVariableAsExternalVariab auto profile = generator->profile(); - profile->setInterfaceFileNameString("model.state.h"); + profile->setInterfaceFileNameString("model.state.external.h"); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.state.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.state.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.state.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, hodgkin_huxley_squid_axon_model_1952_state_external); } TEST(Generator, hodgkinHuxleySquidAxonModel1952WithStateVariablesAsExternalVariablesIncludingOneDependingOnTheOther) @@ -1292,16 +1388,18 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithStateVariablesAsExternalVaria auto profile = generator->profile(); - profile->setInterfaceFileNameString("model.dependent.state.h"); + profile->setInterfaceFileNameString("model.dependent.state.external.h"); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, hodgkin_huxley_squid_axon_model_1952_dependent_state_external); } TEST(Generator, hodgkinHuxleySquidAxonModel1952WithConstantAsExternalVariable) @@ -1329,16 +1427,18 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithConstantAsExternalVariable) auto profile = generator->profile(); - profile->setInterfaceFileNameString("model.constant.h"); + profile->setInterfaceFileNameString("model.constant.external.h"); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, hodgkin_huxley_squid_axon_model_1952_constant_external); } TEST(Generator, hodgkinHuxleySquidAxonModel1952WithConstantsAsExternalVariablesIncludingOneDependingOnTheOther) @@ -1372,16 +1472,18 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithConstantsAsExternalVariablesI auto profile = generator->profile(); - profile->setInterfaceFileNameString("model.dependent.constant.h"); + profile->setInterfaceFileNameString("model.dependent.constant.external.h"); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, hodgkin_huxley_squid_axon_model_1952_dependent_constant_external); } TEST(Generator, hodgkinHuxleySquidAxonModel1952WithComputedConstantAsExternalVariable) @@ -1409,16 +1511,18 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithComputedConstantAsExternalVar auto profile = generator->profile(); - profile->setInterfaceFileNameString("model.computed.constant.h"); + profile->setInterfaceFileNameString("model.computed.constant.external.h"); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, hodgkin_huxley_squid_axon_model_1952_computed_constant_external); } TEST(Generator, hodgkinHuxleySquidAxonModel1952WithComputedConstantsAsExternalVariablesIncludingOneDependingOnTheOther) @@ -1452,16 +1556,18 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithComputedConstantsAsExternalVa auto profile = generator->profile(); - profile->setInterfaceFileNameString("model.dependent.computed.constant.h"); + profile->setInterfaceFileNameString("model.dependent.computed.constant.external.h"); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, hodgkin_huxley_squid_axon_model_1952_dependent_computed_constant_external); } TEST(Generator, hodgkinHuxleySquidAxonModel1952WithAlgebraicVariableAsExternalVariable) @@ -1489,16 +1595,18 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithAlgebraicVariableAsExternalVa auto profile = generator->profile(); - profile->setInterfaceFileNameString("model.algebraic.h"); + profile->setInterfaceFileNameString("model.algebraic.external.h"); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, hodgkin_huxley_squid_axon_model_1952_algebraic_external); } TEST(Generator, hodgkinHuxleySquidAxonModel1952WithAlgebraicVariablesAsExternalVariablesIncludingOneDependingOnTheOther) @@ -1514,12 +1622,12 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithAlgebraicVariablesAsExternalV auto analyser = libcellml::Analyser::create(); auto potassium_channel_n_gate_beta_n = model->component("potassium_channel_n_gate")->variable("beta_n"); - auto membrane_i_Stime = libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("i_Stim")); + auto membrane_i_Stim = libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("i_Stim")); - membrane_i_Stime->addDependency(potassium_channel_n_gate_beta_n); + membrane_i_Stim->addDependency(potassium_channel_n_gate_beta_n); analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(potassium_channel_n_gate_beta_n)); - analyser->addExternalVariable(membrane_i_Stime); + analyser->addExternalVariable(membrane_i_Stim); analyser->analyseModel(model); @@ -1532,16 +1640,18 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithAlgebraicVariablesAsExternalV auto profile = generator->profile(); - profile->setInterfaceFileNameString("model.dependent.algebraic.h"); + profile->setInterfaceFileNameString("model.dependent.algebraic.external.h"); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, hodgkin_huxley_squid_axon_model_1952_dependent_algebraic_external); } TEST(Generator, hodgkinHuxleySquidAxonModel1952WithVariousExternalVariables) @@ -1584,17 +1694,19 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithVariousExternalVariables) profile->setInterfaceFileNameString("model.external.h"); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.external.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.external.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.external.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.external.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, hodgkin_huxley_squid_axon_model_1952_external); } -TEST(Generator, hodgkinHuxleySquidAxonModel1952Nla) +TEST(Generator, hodgkinHuxleySquidAxonModel195Dae) { // Same as the hodgkinHuxleySquidAxonModel1952 test, except that all the // algebraic equations are to be computed using NLA systems of one equation. @@ -1619,14 +1731,61 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952Nla) profile->setInterfaceFileNameString("model.dae.h"); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dae.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dae.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dae.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dae.c", generator->implementationCode()); + + profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); + + generator->setProfile(profile); + + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dae.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, hodgkin_huxley_squid_axon_model_1952_dae); +} + +TEST(Generator, hodgkinHuxleySquidAxonModel1952DaeWithVariousExternalVariables) +{ + // Same as hodgkinHuxleySquidAxonModel1952WithVariousExternalVariables but with the DAE version of the HH52 model. + + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dae.cellml")); + + EXPECT_EQ(size_t(0), parser->issueCount()); + + auto analyser = libcellml::Analyser::create(); + auto potassium_channel_n_gate_alpha_n = model->component("potassium_channel_n_gate")->variable("alpha_n"); + auto external_sodium_channel_i_Na = libcellml::AnalyserExternalVariable::create(model->component("sodium_channel")->variable("i_Na")); + + external_sodium_channel_i_Na->addDependency(potassium_channel_n_gate_alpha_n); + external_sodium_channel_i_Na->addDependency(model->component("sodium_channel_h_gate")->variable("h")); + + analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("V"))); + analyser->addExternalVariable(external_sodium_channel_i_Na); + analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(potassium_channel_n_gate_alpha_n)); + + analyser->analyseModel(model); + + EXPECT_EQ(size_t(0), analyser->errorCount()); + + auto analyserModel = analyser->model(); + auto generator = libcellml::Generator::create(); + + generator->setModel(analyserModel); + + auto profile = generator->profile(); + + profile->setInterfaceFileNameString("model.dae.external.h"); + + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.dae.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, hodgkin_huxley_squid_axon_model_1952_dae_external); } TEST(Generator, nobleModel1962) @@ -1647,14 +1806,16 @@ TEST(Generator, nobleModel1962) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/noble_model_1962/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/noble_model_1962/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/noble_model_1962/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/noble_model_1962/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/noble_model_1962/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/noble_model_1962/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, noble_model_1962); } TEST(Generator, robertsonOdeModel1966) @@ -1679,14 +1840,16 @@ TEST(Generator, robertsonOdeModel1966) profile->setInterfaceFileNameString("model.ode.h"); - EXPECT_EQ(fileContents("generator/robertson_model_1966/model.ode.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/robertson_model_1966/model.ode.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/robertson_model_1966/model.ode.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/robertson_model_1966/model.ode.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/robertson_model_1966/model.ode.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/robertson_model_1966/model.ode.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, robertson_model_1966_ode); } TEST(Generator, robertsonDaeModel1966) @@ -1711,14 +1874,16 @@ TEST(Generator, robertsonDaeModel1966) profile->setInterfaceFileNameString("model.dae.h"); - EXPECT_EQ(fileContents("generator/robertson_model_1966/model.dae.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/robertson_model_1966/model.dae.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/robertson_model_1966/model.dae.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/robertson_model_1966/model.dae.c", generator->implementationCode()); profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/robertson_model_1966/model.dae.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/robertson_model_1966/model.dae.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, robertson_model_1966_dae); } TEST(Generator, sineImports) @@ -1747,14 +1912,16 @@ TEST(Generator, sineImports) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/sine_model_imports/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/sine_model_imports/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/sine_model_imports/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/sine_model_imports/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/sine_model_imports/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/sine_model_imports/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, sine_model_imports); } TEST(Generator, analyserModelScopeTest) @@ -1778,8 +1945,10 @@ TEST(Generator, analyserModelScopeTest) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.c", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, hodgkin_huxley_squid_axon_model_1952); } TEST(Generator, daeModel) @@ -1800,14 +1969,16 @@ TEST(Generator, daeModel) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/dae_cellml_1_1_model/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/dae_cellml_1_1_model/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/dae_cellml_1_1_model/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/dae_cellml_1_1_model/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/dae_cellml_1_1_model/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/dae_cellml_1_1_model/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, dae_cellml_1_1_model); } TEST(Generator, variableInitialisedUsingAConstant) @@ -1828,14 +1999,16 @@ TEST(Generator, variableInitialisedUsingAConstant) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/variable_initialised_using_a_constant/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/variable_initialised_using_a_constant/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/variable_initialised_using_a_constant/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/variable_initialised_using_a_constant/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/variable_initialised_using_a_constant/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/variable_initialised_using_a_constant/model.py", generator->implementationCode()); + + TEST_DIFFERENTIAL_MODEL(analyserModel, variable_initialised_using_a_constant); } TEST(Generator, modelOutOfScope) @@ -1864,7 +2037,7 @@ TEST(Generator, modelOutOfScope) generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/ode_multiple_dependent_odes/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/ode_multiple_dependent_odes/model.py", generator->implementationCode()); } TEST(Generator, unknownVariableMarkedAsExternalVariable) @@ -1887,14 +2060,16 @@ TEST(Generator, unknownVariableMarkedAsExternalVariable) generator->setModel(analyserModel); - EXPECT_EQ(fileContents("generator/unknown_variable_as_external_variable/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/unknown_variable_as_external_variable/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/unknown_variable_as_external_variable/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/unknown_variable_as_external_variable/model.c", generator->implementationCode()); auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/unknown_variable_as_external_variable/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/unknown_variable_as_external_variable/model.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL_EXTERNAL(analyserModel, unknown_variable_as_external_variable); } TEST(Generator, modelWithComplexUnitsOutOfScope) @@ -1924,9 +2099,14 @@ TEST(Generator, modelWithComplexUnitsOutOfScope) generator->setModel(analyserModel); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_slc_example/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_slc_example/model.c", generator->implementationCode()); + auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); - EXPECT_EQ(fileContents("generator/cellml_slc_example/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_slc_example/model.py", generator->implementationCode()); + + TEST_ALGEBRAIC_MODEL(analyserModel, cellml_slc_example); } diff --git a/tests/generator/generator.macros.h b/tests/generator/generator.macros.h new file mode 100644 index 0000000000..d767cda462 --- /dev/null +++ b/tests/generator/generator.macros.h @@ -0,0 +1,233 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#include + +static const auto NAN = std::numeric_limits::quiet_NaN(); + +typedef struct +{ + char name[256]; + char units[256]; + char component[256]; +} VariableInfo; + +#define NLA_SOLVE_METHOD \ + void nlaSolve(void (*)(double *, double *, void *), double *, size_t, void *) \ + { \ + } + +#define ALGEBRAIC_MODEL_EXTERNAL_VARIABLE_METHOD \ + double externalVariable(double *, double *, double *, double *, size_t) \ + { \ + return 1.23; \ + } + +#define DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD \ + double externalVariable(double, double *, double *, double *, double *, double *, double *, size_t) \ + { \ + return 7.89; \ + } + +#define TEST_ALGEBRAIC_MODEL(analyserModel, model) \ + auto interpreter = libcellml::Interpreter::create(); \ +\ + interpreter->setModel(analyserModel); \ +\ + auto *constants = new double[analyserModel->constantCount()]; \ + auto *computedConstants = new double[analyserModel->computedConstantCount()]; \ + auto *algebraic = new double[analyserModel->algebraicCount()]; \ +\ + interpreter->initialiseVariables(constants, computedConstants, algebraic); \ + interpreter->computeComputedConstants(constants, computedConstants); \ + interpreter->computeVariables(constants, computedConstants, algebraic); \ +\ + auto *expectedConstantsData = model::createConstantsArray(); \ + auto *expectedComputedConstantsData = model::createComputedConstantsArray(); \ + auto *expectedAlgebraicData = model::createAlgebraicArray(); \ +\ + model::initialiseVariables(expectedConstantsData, expectedComputedConstantsData, expectedAlgebraicData); \ + model::computeComputedConstants(expectedConstantsData, expectedComputedConstantsData); \ + model::computeVariables(expectedConstantsData, expectedComputedConstantsData, expectedAlgebraicData); \ +\ + std::vector expectedConstants(expectedConstantsData, expectedConstantsData + model::CONSTANT_COUNT); \ + std::vector expectedComputedConstants(expectedComputedConstantsData, expectedComputedConstantsData + model::COMPUTED_CONSTANT_COUNT); \ + std::vector expectedAlgebraic(expectedAlgebraicData, expectedAlgebraicData + model::ALGEBRAIC_COUNT); \ +\ + expectEqualValues(expectedConstants, constants, analyserModel->constantCount()); \ + expectEqualValues(expectedComputedConstants, computedConstants, analyserModel->computedConstantCount()); \ + expectEqualValues(expectedAlgebraic, algebraic, analyserModel->algebraicCount()); \ +\ + delete[] expectedConstantsData; \ + delete[] expectedComputedConstantsData; \ + delete[] expectedAlgebraicData; \ +\ + delete[] constants; \ + delete[] computedConstants; \ + delete[] algebraic; + +#define TEST_ALGEBRAIC_MODEL_EXTERNAL(analyserModel, model) \ + auto interpreter = libcellml::Interpreter::create(); \ +\ + interpreter->setModel(analyserModel); \ +\ + auto *constants = new double[analyserModel->constantCount()]; \ + auto *computedConstants = new double[analyserModel->computedConstantCount()]; \ + auto *algebraic = new double[analyserModel->algebraicCount()]; \ + auto *externals = new double[analyserModel->externalCount()]; \ +\ + interpreter->initialiseVariables(constants, computedConstants, algebraic); \ + interpreter->computeComputedConstants(constants, computedConstants); \ + interpreter->computeVariables(constants, computedConstants, algebraic, externals, model::externalVariable); \ +\ + auto *expectedConstantsData = model::createConstantsArray(); \ + auto *expectedComputedConstantsData = model::createComputedConstantsArray(); \ + auto *expectedAlgebraicData = model::createAlgebraicArray(); \ + auto *expectedAlgebraicExternals = model::createExternalsArray(); \ +\ + model::initialiseVariables(expectedConstantsData, expectedComputedConstantsData, expectedAlgebraicData); \ + model::computeComputedConstants(expectedConstantsData, expectedComputedConstantsData); \ + model::computeVariables(expectedConstantsData, expectedComputedConstantsData, expectedAlgebraicData, expectedAlgebraicExternals, model::externalVariable); \ +\ + std::vector expectedConstants(expectedConstantsData, expectedConstantsData + model::CONSTANT_COUNT); \ + std::vector expectedComputedConstants(expectedComputedConstantsData, expectedComputedConstantsData + model::COMPUTED_CONSTANT_COUNT); \ + std::vector expectedAlgebraic(expectedAlgebraicData, expectedAlgebraicData + model::ALGEBRAIC_COUNT); \ + std::vector expectedExternals(expectedAlgebraicExternals, expectedAlgebraicExternals + model::EXTERNAL_COUNT); \ +\ + expectEqualValues(expectedConstants, constants, analyserModel->constantCount()); \ + expectEqualValues(expectedComputedConstants, computedConstants, analyserModel->computedConstantCount()); \ + expectEqualValues(expectedAlgebraic, algebraic, analyserModel->algebraicCount()); \ + expectEqualValues(expectedExternals, externals, analyserModel->externalCount()); \ +\ + delete[] expectedConstantsData; \ + delete[] expectedComputedConstantsData; \ + delete[] expectedAlgebraicData; \ + delete[] expectedAlgebraicExternals; \ +\ + delete[] constants; \ + delete[] computedConstants; \ + delete[] algebraic; \ + delete[] externals; + +#define TEST_DIFFERENTIAL_MODEL(analyserModel, model) \ + auto interpreter = libcellml::Interpreter::create(); \ +\ + interpreter->setModel(analyserModel); \ +\ + auto *states = new double[analyserModel->stateCount()]; \ + auto *rates = new double[analyserModel->stateCount()]; \ + auto *constants = new double[analyserModel->constantCount()]; \ + auto *computedConstants = new double[analyserModel->computedConstantCount()]; \ + auto *algebraic = new double[analyserModel->algebraicCount()]; \ +\ + interpreter->initialiseVariables(states, rates, constants, computedConstants, algebraic); \ + interpreter->computeComputedConstants(constants, computedConstants); \ + interpreter->computeRates(0.0, states, rates, constants, computedConstants, algebraic); \ + interpreter->computeVariables(0.0, states, rates, constants, computedConstants, algebraic); \ +\ + auto *expectedStatesData = model::createStatesArray(); \ + auto *expectedRatesData = model::createStatesArray(); \ + auto *expectedConstantsData = model::createConstantsArray(); \ + auto *expectedComputedConstantsData = model::createComputedConstantsArray(); \ + auto *expectedAlgebraicData = model::createAlgebraicArray(); \ +\ + model::initialiseVariables(expectedStatesData, expectedRatesData, expectedConstantsData, expectedComputedConstantsData, expectedAlgebraicData); \ + model::computeComputedConstants(expectedConstantsData, expectedComputedConstantsData); \ + model::computeRates(0.0, expectedStatesData, expectedRatesData, expectedConstantsData, expectedComputedConstantsData, expectedAlgebraicData); \ + model::computeVariables(0.0, expectedStatesData, expectedRatesData, expectedConstantsData, expectedComputedConstantsData, expectedAlgebraicData); \ +\ + std::vector expectedStates(expectedStatesData, expectedStatesData + model::STATE_COUNT); \ + std::vector expectedRates(expectedRatesData, expectedRatesData + model::STATE_COUNT); \ + std::vector expectedConstants(expectedConstantsData, expectedConstantsData + model::CONSTANT_COUNT); \ + std::vector expectedComputedConstants(expectedComputedConstantsData, expectedComputedConstantsData + model::COMPUTED_CONSTANT_COUNT); \ + std::vector expectedAlgebraic(expectedAlgebraicData, expectedAlgebraicData + model::ALGEBRAIC_COUNT); \ +\ + expectEqualValues(expectedStates, states, analyserModel->stateCount()); \ + expectEqualValues(expectedRates, rates, analyserModel->stateCount()); \ + expectEqualValues(expectedConstants, constants, analyserModel->constantCount()); \ + expectEqualValues(expectedComputedConstants, computedConstants, analyserModel->computedConstantCount()); \ + expectEqualValues(expectedAlgebraic, algebraic, analyserModel->algebraicCount()); \ +\ + delete[] expectedStatesData; \ + delete[] expectedRatesData; \ + delete[] expectedConstantsData; \ + delete[] expectedComputedConstantsData; \ + delete[] expectedAlgebraicData; \ +\ + delete[] states; \ + delete[] rates; \ + delete[] constants; \ + delete[] computedConstants; \ + delete[] algebraic; + +#define TEST_DIFFERENTIAL_MODEL_EXTERNAL(analyserModel, model) \ + auto interpreter = libcellml::Interpreter::create(); \ +\ + interpreter->setModel(analyserModel); \ +\ + auto *states = new double[analyserModel->stateCount()]; \ + auto *rates = new double[analyserModel->stateCount()]; \ + auto *constants = new double[analyserModel->constantCount()]; \ + auto *computedConstants = new double[analyserModel->computedConstantCount()]; \ + auto *algebraic = new double[analyserModel->algebraicCount()]; \ + auto *externals = new double[analyserModel->externalCount()]; \ +\ + interpreter->initialiseVariables(states, rates, constants, computedConstants, algebraic); \ + interpreter->computeComputedConstants(constants, computedConstants); \ + interpreter->computeRates(0.0, states, rates, constants, computedConstants, algebraic, externals, model::externalVariable); \ + interpreter->computeVariables(0.0, states, rates, constants, computedConstants, algebraic, externals, model::externalVariable); \ +\ + auto *expectedStatesData = model::createStatesArray(); \ + auto *expectedRatesData = model::createStatesArray(); \ + auto *expectedConstantsData = model::createConstantsArray(); \ + auto *expectedComputedConstantsData = model::createComputedConstantsArray(); \ + auto *expectedAlgebraicData = model::createAlgebraicArray(); \ + auto *expectedAlgebraicExternals = model::createExternalsArray(); \ +\ + model::initialiseVariables(expectedStatesData, expectedRatesData, expectedConstantsData, expectedComputedConstantsData, expectedAlgebraicData); \ + model::computeComputedConstants(expectedConstantsData, expectedComputedConstantsData); \ + model::computeRates(0.0, expectedStatesData, expectedRatesData, expectedConstantsData, expectedComputedConstantsData, expectedAlgebraicData, expectedAlgebraicExternals, model::externalVariable); \ + model::computeVariables(0.0, expectedStatesData, expectedRatesData, expectedConstantsData, expectedComputedConstantsData, expectedAlgebraicData, expectedAlgebraicExternals, model::externalVariable); \ +\ + std::vector expectedStates(expectedStatesData, expectedStatesData + model::STATE_COUNT); \ + std::vector expectedRates(expectedRatesData, expectedRatesData + model::STATE_COUNT); \ + std::vector expectedConstants(expectedConstantsData, expectedConstantsData + model::CONSTANT_COUNT); \ + std::vector expectedComputedConstants(expectedComputedConstantsData, expectedComputedConstantsData + model::COMPUTED_CONSTANT_COUNT); \ + std::vector expectedAlgebraic(expectedAlgebraicData, expectedAlgebraicData + model::ALGEBRAIC_COUNT); \ + std::vector expectedExternals(expectedAlgebraicExternals, expectedAlgebraicExternals + model::EXTERNAL_COUNT); \ +\ + expectEqualValues(expectedStates, states, analyserModel->stateCount()); \ + expectEqualValues(expectedRates, rates, analyserModel->stateCount()); \ + expectEqualValues(expectedConstants, constants, analyserModel->constantCount()); \ + expectEqualValues(expectedComputedConstants, computedConstants, analyserModel->computedConstantCount()); \ + expectEqualValues(expectedAlgebraic, algebraic, analyserModel->algebraicCount()); \ + expectEqualValues(expectedExternals, externals, analyserModel->externalCount()); \ +\ + delete[] expectedStatesData; \ + delete[] expectedRatesData; \ + delete[] expectedConstantsData; \ + delete[] expectedComputedConstantsData; \ + delete[] expectedAlgebraicData; \ + delete[] expectedAlgebraicExternals; \ +\ + delete[] states; \ + delete[] rates; \ + delete[] constants; \ + delete[] computedConstants; \ + delete[] algebraic; \ + delete[] externals; diff --git a/tests/generator/generator.models.h b/tests/generator/generator.models.h new file mode 100644 index 0000000000..3806fda97d --- /dev/null +++ b/tests/generator/generator.models.h @@ -0,0 +1,304 @@ +/* +Copyright libCellML Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#if defined(_MSC_VER) && !defined(__clang__) +# pragma warning(push) +# pragma warning(disable : 4100) +#elif defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-parameter" +#else +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunused-parameter" +# pragma clang diagnostic ignored "-Wunused-variable" +#endif + +namespace algebraic_eqn_computed_var_on_rhs { +#include "../resources/generator/algebraic_eqn_computed_var_on_rhs/model.c" +} // namespace algebraic_eqn_computed_var_on_rhs + +namespace algebraic_eqn_computed_var_on_rhs_external { +ALGEBRAIC_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.c" +} // namespace algebraic_eqn_computed_var_on_rhs_external + +namespace algebraic_eqn_const_var_on_rhs { +#include "../resources/generator/algebraic_eqn_const_var_on_rhs/model.c" +} // namespace algebraic_eqn_const_var_on_rhs + +namespace algebraic_eqn_constant_on_rhs { +#include "../resources/generator/algebraic_eqn_constant_on_rhs/model.c" +} // namespace algebraic_eqn_constant_on_rhs + +namespace algebraic_eqn_derivative_on_rhs { +#include "../resources/generator/algebraic_eqn_derivative_on_rhs/model.c" +} // namespace algebraic_eqn_derivative_on_rhs + +namespace algebraic_eqn_derivative_on_rhs_one_component { +#include "../resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.c" +} // namespace algebraic_eqn_derivative_on_rhs_one_component + +namespace algebraic_eqn_state_var_on_rhs { +#include "../resources/generator/algebraic_eqn_state_var_on_rhs/model.c" +} // namespace algebraic_eqn_state_var_on_rhs + +namespace algebraic_eqn_state_var_on_rhs_one_component { +#include "../resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.c" +} // namespace algebraic_eqn_state_var_on_rhs_one_component + +namespace algebraic_unknown_var_on_rhs { +#include "../resources/generator/algebraic_unknown_var_on_rhs/model.c" +} // namespace algebraic_unknown_var_on_rhs + +namespace algebraic_eqn_with_one_non_isolated_unknown { +NLA_SOLVE_METHOD +#include "../resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.c" +} // namespace algebraic_eqn_with_one_non_isolated_unknown + +namespace algebraic_eqn_with_one_non_isolated_unknown_external { +NLA_SOLVE_METHOD +ALGEBRAIC_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.c" +} // namespace algebraic_eqn_with_one_non_isolated_unknown_external + +namespace algebraic_system_with_three_linked_unknowns { +NLA_SOLVE_METHOD +#include "../resources/generator/algebraic_system_with_three_linked_unknowns/model.c" +} // namespace algebraic_system_with_three_linked_unknowns + +namespace algebraic_system_with_three_linked_unknowns_external { +ALGEBRAIC_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/algebraic_system_with_three_linked_unknowns/model.external.c" +} // namespace algebraic_system_with_three_linked_unknowns_external + +namespace algebraic_system_with_various_dependencies_ordered { +NLA_SOLVE_METHOD +#include "../resources/generator/algebraic_system_with_various_dependencies/model.ordered.c" +} // namespace algebraic_system_with_various_dependencies_ordered + +namespace algebraic_system_with_various_dependencies_not_ordered { +NLA_SOLVE_METHOD +#include "../resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.c" +} // namespace algebraic_system_with_various_dependencies_not_ordered + +namespace ode_computed_var_on_rhs { +#include "../resources/generator/ode_computed_var_on_rhs/model.c" +} // namespace ode_computed_var_on_rhs + +namespace ode_computed_var_on_rhs_one_component { +#include "../resources/generator/ode_computed_var_on_rhs_one_component/model.c" +} // namespace ode_computed_var_on_rhs_one_component + +namespace ode_const_var_on_rhs { +#include "../resources/generator/ode_const_var_on_rhs/model.c" +} // namespace ode_const_var_on_rhs + +namespace ode_const_var_on_rhs_one_component { +#include "../resources/generator/ode_const_var_on_rhs_one_component/model.c" +} // namespace ode_const_var_on_rhs_one_component + +namespace ode_constant_on_rhs { +#include "../resources/generator/ode_constant_on_rhs/model.c" +} // namespace ode_constant_on_rhs + +namespace ode_constant_on_rhs_one_component { +#include "../resources/generator/ode_constant_on_rhs_one_component/model.c" +} // namespace ode_constant_on_rhs_one_component + +namespace ode_multiple_dependent_odes { +#include "../resources/generator/ode_multiple_dependent_odes/model.c" +} // namespace ode_multiple_dependent_odes + +namespace ode_multiple_dependent_odes_one_component { +#include "../resources/generator/ode_multiple_dependent_odes_one_component/model.c" +} // namespace ode_multiple_dependent_odes_one_component + +namespace ode_multiple_odes_with_same_name { +#include "../resources/generator/ode_multiple_odes_with_same_name/model.c" +} // namespace ode_multiple_odes_with_same_name + +namespace ode_unknown_var_on_rhs { +#include "../resources/generator/ode_unknown_var_on_rhs/model.c" +} // namespace ode_unknown_var_on_rhs + +namespace cellml_mappings_and_encapsulations { +#include "../resources/generator/cellml_mappings_and_encapsulations/model.c" +} // namespace cellml_mappings_and_encapsulations + +namespace cellml_state_initialised_using_variable { +#include "../resources/generator/cellml_state_initialised_using_variable/model.c" +} // namespace cellml_state_initialised_using_variable + +namespace cellml_unit_scaling_voi_indirect { +#include "../resources/generator/cellml_unit_scaling_voi_indirect/model.c" +} // namespace cellml_unit_scaling_voi_indirect + +namespace cellml_unit_scaling_voi_direct { +#include "../resources/generator/cellml_unit_scaling_voi_direct/model.c" +} // namespace cellml_unit_scaling_voi_direct + +namespace cellml_unit_scaling_constant { +#include "../resources/generator/cellml_unit_scaling_constant/model.c" +} // namespace cellml_unit_scaling_constant + +namespace cellml_unit_scaling_state { +#include "../resources/generator/cellml_unit_scaling_state/model.c" +} // namespace cellml_unit_scaling_state + +namespace cellml_unit_scaling_state_initialised_using_constant { +#include "../resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.c" +} // namespace cellml_unit_scaling_state_initialised_using_constant + +namespace cellml_unit_scaling_state_initialised_using_variable { +#include "../resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.c" +} // namespace cellml_unit_scaling_state_initialised_using_variable + +namespace cellml_unit_scaling_rate { +#include "../resources/generator/cellml_unit_scaling_rate/model.c" +} // namespace cellml_unit_scaling_rate + +namespace dependent_eqns { +#include "../resources/generator/dependent_eqns/model.c" +} // namespace dependent_eqns + +namespace cell_geometry_model { +#include "../resources/generator/cell_geometry_model/model.c" +} // namespace cell_geometry_model + +namespace cell_geometry_model_external { +ALGEBRAIC_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/cell_geometry_model/model.external.c" +} // namespace cell_geometry_model_external + +namespace fabbri_fantini_wilders_severi_human_san_model_2017 { +#include "../resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.c" +} // namespace fabbri_fantini_wilders_severi_human_san_model_2017 + +namespace garny_kohl_hunter_boyett_noble_rabbit_san_model_2003 { +#include "../resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.c" +} // namespace garny_kohl_hunter_boyett_noble_rabbit_san_model_2003 + +namespace hodgkin_huxley_squid_axon_model_1952 { +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.c" +} // namespace hodgkin_huxley_squid_axon_model_1952 + +namespace hodgkin_huxley_squid_axon_model_1952_state_external { +DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.c" +} // namespace hodgkin_huxley_squid_axon_model_1952_state_external + +namespace hodgkin_huxley_squid_axon_model_1952_dependent_state_external { +DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.c" +} // namespace hodgkin_huxley_squid_axon_model_1952_dependent_state_external + +namespace hodgkin_huxley_squid_axon_model_1952_constant_external { +DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.c" +} // namespace hodgkin_huxley_squid_axon_model_1952_constant_external + +namespace hodgkin_huxley_squid_axon_model_1952_dependent_constant_external { +DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.c" +} // namespace hodgkin_huxley_squid_axon_model_1952_dependent_constant_external + +namespace hodgkin_huxley_squid_axon_model_1952_computed_constant_external { +DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.c" +} // namespace hodgkin_huxley_squid_axon_model_1952_computed_constant_external + +namespace hodgkin_huxley_squid_axon_model_1952_dependent_computed_constant_external { +DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.c" +} // namespace hodgkin_huxley_squid_axon_model_1952_dependent_computed_constant_external + +namespace hodgkin_huxley_squid_axon_model_1952_algebraic_external { +DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.c" +} // namespace hodgkin_huxley_squid_axon_model_1952_algebraic_external + +namespace hodgkin_huxley_squid_axon_model_1952_dependent_algebraic_external { +DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.c" +} // namespace hodgkin_huxley_squid_axon_model_1952_dependent_algebraic_external + +namespace hodgkin_huxley_squid_axon_model_1952_external { +DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.c" +} // namespace hodgkin_huxley_squid_axon_model_1952_external + +namespace hodgkin_huxley_squid_axon_model_1952_dae { +NLA_SOLVE_METHOD +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.c" +} // namespace hodgkin_huxley_squid_axon_model_1952_dae + +namespace hodgkin_huxley_squid_axon_model_1952_dae_external { +NLA_SOLVE_METHOD +DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.c" +} // namespace hodgkin_huxley_squid_axon_model_1952_dae_external + +namespace noble_model_1962 { +#include "../resources/generator/noble_model_1962/model.c" +} // namespace noble_model_1962 + +namespace robertson_model_1966_ode { +#include "../resources/generator/robertson_model_1966/model.ode.c" +} // namespace robertson_model_1966_ode + +namespace robertson_model_1966_dae { +NLA_SOLVE_METHOD +#include "../resources/generator/robertson_model_1966/model.dae.c" +} // namespace robertson_model_1966_dae + +namespace sine_model_imports { +#include "../resources/generator/sine_model_imports/model.c" +} // namespace sine_model_imports + +namespace dae_cellml_1_1_model { +NLA_SOLVE_METHOD +#include "../resources/generator/dae_cellml_1_1_model/model.c" +} // namespace dae_cellml_1_1_model + +namespace variable_initialised_using_a_constant { +NLA_SOLVE_METHOD +#include "../resources/generator/variable_initialised_using_a_constant/model.c" +} // namespace variable_initialised_using_a_constant + +namespace unknown_variable_as_external_variable { +ALGEBRAIC_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/generator/unknown_variable_as_external_variable/model.c" +} // namespace unknown_variable_as_external_variable + +namespace cellml_slc_example { +#include "../resources/generator/cellml_slc_example/model.c" +} // namespace cellml_slc_example + +namespace coverage { +NLA_SOLVE_METHOD +DIFFERENTIAL_MODEL_EXTERNAL_VARIABLE_METHOD +#include "../resources/coverage/generator/model.xor.c" +} // namespace coverage + +#if defined(_MSC_VER) && !defined(__clang__) +# pragma warning(pop) +#elif defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic pop +#else +# pragma clang diagnostic pop +#endif diff --git a/tests/generator/generatorprofile.cpp b/tests/generator/generatorprofile.cpp index 479b29d239..4339294f9e 100644 --- a/tests/generator/generatorprofile.cpp +++ b/tests/generator/generatorprofile.cpp @@ -88,8 +88,8 @@ TEST(GeneratorProfile, defaultArithmeticOperatorValues) EXPECT_EQ("log10", generatorProfile->commonLogarithmString()); EXPECT_EQ("ceil", generatorProfile->ceilingString()); EXPECT_EQ("floor", generatorProfile->floorString()); - EXPECT_EQ("min", generatorProfile->minString()); - EXPECT_EQ("max", generatorProfile->maxString()); + EXPECT_EQ("fmin", generatorProfile->minString()); + EXPECT_EQ("fmax", generatorProfile->maxString()); EXPECT_EQ("fmod", generatorProfile->remString()); EXPECT_EQ(false, generatorProfile->hasPowerOperator()); @@ -167,16 +167,8 @@ TEST(GeneratorProfile, defaultArithmeticFunctionValues) "}\n", generatorProfile->xorFunctionString()); EXPECT_EQ("", generatorProfile->notFunctionString()); - EXPECT_EQ("double min(double x, double y)\n" - "{\n" - " return (x < y)?x:y;\n" - "}\n", - generatorProfile->minFunctionString()); - EXPECT_EQ("double max(double x, double y)\n" - "{\n" - " return (x > y)?x:y;\n" - "}\n", - generatorProfile->maxFunctionString()); + EXPECT_EQ("", generatorProfile->minFunctionString()); + EXPECT_EQ("", generatorProfile->maxFunctionString()); } TEST(GeneratorProfile, defaultTrigonometricFunctionValues) @@ -230,23 +222,17 @@ TEST(GeneratorProfile, defaultTrigonometricFunctionValues) generatorProfile->acotFunctionString()); EXPECT_EQ("double asech(double x)\n" "{\n" - " double oneOverX = 1.0/x;\n" - "\n" - " return log(oneOverX+sqrt(oneOverX*oneOverX-1.0));\n" + " return acosh(1.0/x);\n" "}\n", generatorProfile->asechFunctionString()); EXPECT_EQ("double acsch(double x)\n" "{\n" - " double oneOverX = 1.0/x;\n" - "\n" - " return log(oneOverX+sqrt(oneOverX*oneOverX+1.0));\n" + " return asinh(1.0/x);\n" "}\n", generatorProfile->acschFunctionString()); EXPECT_EQ("double acoth(double x)\n" "{\n" - " double oneOverX = 1.0/x;\n" - "\n" - " return 0.5*log((1.0+oneOverX)/(1.0-oneOverX));\n" + " return atanh(1.0/x);\n" "}\n", generatorProfile->acothFunctionString()); } @@ -271,7 +257,7 @@ TEST(GeneratorProfile, defaultMiscellaneousValues) generatorProfile->implementationHeaderString()); EXPECT_EQ("extern const char VERSION[];\n", generatorProfile->interfaceVersionString()); - EXPECT_EQ("const char VERSION[] = \"0.5.0\";\n", generatorProfile->implementationVersionString()); + EXPECT_EQ("const char VERSION[] = \"0.6.0\";\n", generatorProfile->implementationVersionString()); EXPECT_EQ("extern const char LIBCELLML_VERSION[];\n", generatorProfile->interfaceLibcellmlVersionString()); EXPECT_EQ("const char LIBCELLML_VERSION[] = \"[LIBCELLML_VERSION]\";\n", generatorProfile->implementationLibcellmlVersionString()); @@ -279,52 +265,22 @@ TEST(GeneratorProfile, defaultMiscellaneousValues) EXPECT_EQ("extern const size_t STATE_COUNT;\n", generatorProfile->interfaceStateCountString()); EXPECT_EQ("const size_t STATE_COUNT = [STATE_COUNT];\n", generatorProfile->implementationStateCountString()); - EXPECT_EQ("extern const size_t VARIABLE_COUNT;\n", generatorProfile->interfaceVariableCountString()); - EXPECT_EQ("const size_t VARIABLE_COUNT = [VARIABLE_COUNT];\n", generatorProfile->implementationVariableCountString()); - - EXPECT_EQ("typedef enum {\n" - " CONSTANT,\n" - " COMPUTED_CONSTANT,\n" - " ALGEBRAIC\n" - "} VariableType;\n", - generatorProfile->variableTypeObjectString(false, false)); - EXPECT_EQ("typedef enum {\n" - " CONSTANT,\n" - " COMPUTED_CONSTANT,\n" - " ALGEBRAIC,\n" - " EXTERNAL\n" - "} VariableType;\n", - generatorProfile->variableTypeObjectString(false, true)); - EXPECT_EQ("typedef enum {\n" - " VARIABLE_OF_INTEGRATION,\n" - " STATE,\n" - " CONSTANT,\n" - " COMPUTED_CONSTANT,\n" - " ALGEBRAIC\n" - "} VariableType;\n", - generatorProfile->variableTypeObjectString(true, false)); - EXPECT_EQ("typedef enum {\n" - " VARIABLE_OF_INTEGRATION,\n" - " STATE,\n" - " CONSTANT,\n" - " COMPUTED_CONSTANT,\n" - " ALGEBRAIC,\n" - " EXTERNAL\n" - "} VariableType;\n", - generatorProfile->variableTypeObjectString(true, true)); - - EXPECT_EQ("VARIABLE_OF_INTEGRATION", generatorProfile->variableOfIntegrationVariableTypeString()); - EXPECT_EQ("STATE", generatorProfile->stateVariableTypeString()); - EXPECT_EQ("CONSTANT", generatorProfile->constantVariableTypeString()); - EXPECT_EQ("COMPUTED_CONSTANT", generatorProfile->computedConstantVariableTypeString()); - EXPECT_EQ("ALGEBRAIC", generatorProfile->algebraicVariableTypeString()); - EXPECT_EQ("EXTERNAL", generatorProfile->externalVariableTypeString()); + EXPECT_EQ("extern const size_t CONSTANT_COUNT;\n", generatorProfile->interfaceConstantCountString()); + EXPECT_EQ("const size_t CONSTANT_COUNT = [CONSTANT_COUNT];\n", generatorProfile->implementationConstantCountString()); + + EXPECT_EQ("extern const size_t COMPUTED_CONSTANT_COUNT;\n", generatorProfile->interfaceComputedConstantCountString()); + EXPECT_EQ("const size_t COMPUTED_CONSTANT_COUNT = [COMPUTED_CONSTANT_COUNT];\n", generatorProfile->implementationComputedConstantCountString()); + + EXPECT_EQ("extern const size_t ALGEBRAIC_COUNT;\n", generatorProfile->interfaceAlgebraicCountString()); + EXPECT_EQ("const size_t ALGEBRAIC_COUNT = [ALGEBRAIC_COUNT];\n", generatorProfile->implementationAlgebraicCountString()); + + EXPECT_EQ("extern const size_t EXTERNAL_COUNT;\n", generatorProfile->interfaceExternalCountString()); + EXPECT_EQ("const size_t EXTERNAL_COUNT = [EXTERNAL_COUNT];\n", generatorProfile->implementationExternalCountString()); EXPECT_EQ("typedef struct {\n" " char name[[NAME_SIZE]];\n" " char units[[UNITS_SIZE]];\n" " char component[[COMPONENT_SIZE]];\n" - " VariableType type;\n" "} VariableInfo;\n", generatorProfile->variableInfoObjectString()); @@ -337,205 +293,324 @@ TEST(GeneratorProfile, defaultMiscellaneousValues) "};\n", generatorProfile->implementationStateInfoString()); - EXPECT_EQ("extern const VariableInfo VARIABLE_INFO[];\n", generatorProfile->interfaceVariableInfoString()); - EXPECT_EQ("const VariableInfo VARIABLE_INFO[] = {\n" + EXPECT_EQ("extern const VariableInfo CONSTANT_INFO[];\n", generatorProfile->interfaceConstantInfoString()); + EXPECT_EQ("const VariableInfo CONSTANT_INFO[] = {\n" "[CODE]" "};\n", - generatorProfile->implementationVariableInfoString()); + generatorProfile->implementationConstantInfoString()); - EXPECT_EQ("{\"[NAME]\", \"[UNITS]\", \"[COMPONENT]\", [TYPE]}", generatorProfile->variableInfoEntryString()); + EXPECT_EQ("extern const VariableInfo COMPUTED_CONSTANT_INFO[];\n", generatorProfile->interfaceComputedConstantInfoString()); + EXPECT_EQ("const VariableInfo COMPUTED_CONSTANT_INFO[] = {\n" + "[CODE]" + "};\n", + generatorProfile->implementationComputedConstantInfoString()); + + EXPECT_EQ("extern const VariableInfo ALGEBRAIC_INFO[];\n", generatorProfile->interfaceAlgebraicInfoString()); + EXPECT_EQ("const VariableInfo ALGEBRAIC_INFO[] = {\n" + "[CODE]" + "};\n", + generatorProfile->implementationAlgebraicInfoString()); + + EXPECT_EQ("extern const VariableInfo EXTERNAL_INFO[];\n", generatorProfile->interfaceExternalInfoString()); + EXPECT_EQ("const VariableInfo EXTERNAL_INFO[] = {\n" + "[CODE]" + "};\n", + generatorProfile->implementationExternalInfoString()); + + EXPECT_EQ("{\"[NAME]\", \"[UNITS]\", \"[COMPONENT]\"}", generatorProfile->variableInfoEntryString()); EXPECT_EQ("voi", generatorProfile->voiString()); EXPECT_EQ("states", generatorProfile->statesArrayString()); EXPECT_EQ("rates", generatorProfile->ratesArrayString()); - EXPECT_EQ("variables", generatorProfile->variablesArrayString()); + EXPECT_EQ("constants", generatorProfile->constantsArrayString()); + EXPECT_EQ("computedConstants", generatorProfile->computedConstantsArrayString()); + EXPECT_EQ("algebraic", generatorProfile->algebraicArrayString()); + EXPECT_EQ("externals", generatorProfile->externalArrayString()); - EXPECT_EQ("typedef double (* ExternalVariable)(double *variables, size_t index);\n", generatorProfile->externalVariableMethodTypeDefinitionString(false)); - EXPECT_EQ("typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index);\n", generatorProfile->externalVariableMethodTypeDefinitionString(true)); + EXPECT_EQ("typedef double (* ExternalVariable)(double *constants, double *computedConstants, double *algebraic, double *externals, size_t index);\n", generatorProfile->externalVariableMethodTypeDefinitionString(false)); + EXPECT_EQ("typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index);\n", generatorProfile->externalVariableMethodTypeDefinitionString(true)); - EXPECT_EQ("externalVariable(variables, [INDEX])", generatorProfile->externalVariableMethodCallString(false)); - EXPECT_EQ("externalVariable(voi, states, rates, variables, [INDEX])", generatorProfile->externalVariableMethodCallString(true)); - - EXPECT_EQ("double * createStatesArray();\n", - generatorProfile->interfaceCreateStatesArrayMethodString()); - EXPECT_EQ("double * createStatesArray()\n" - "{\n" - " double *res = (double *) malloc(STATE_COUNT*sizeof(double));\n" - "\n" - " for (size_t i = 0; i < STATE_COUNT; ++i) {\n" - " res[i] = NAN;\n" - " }\n" - "\n" - " return res;\n" - "}\n", - generatorProfile->implementationCreateStatesArrayMethodString()); + EXPECT_EQ("externalVariable(constants, computedConstants, algebraic, externals, [INDEX])", generatorProfile->externalVariableMethodCallString(false)); + EXPECT_EQ("externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, [INDEX])", generatorProfile->externalVariableMethodCallString(true)); EXPECT_EQ("typedef struct {\n" - " double *variables;\n" + " double *constants;\n" + " double *computedConstants;\n" + " double *algebraic;\n" + "} RootFindingInfo;\n", + generatorProfile->rootFindingInfoObjectString(false, false)); + EXPECT_EQ("typedef struct {\n" + " double *constants;\n" + " double *computedConstants;\n" + " double *algebraic;\n" + " double *externals;\n" + "} RootFindingInfo;\n", + generatorProfile->rootFindingInfoObjectString(false, true)); + EXPECT_EQ("typedef struct {\n" + " double voi;\n" + " double *states;\n" + " double *rates;\n" + " double *constants;\n" + " double *computedConstants;\n" + " double *algebraic;\n" "} RootFindingInfo;\n", - generatorProfile->rootFindingInfoObjectString(false)); + generatorProfile->rootFindingInfoObjectString(true, false)); EXPECT_EQ("typedef struct {\n" " double voi;\n" " double *states;\n" " double *rates;\n" - " double *variables;\n" + " double *constants;\n" + " double *computedConstants;\n" + " double *algebraic;\n" + " double *externals;\n" "} RootFindingInfo;\n", - generatorProfile->rootFindingInfoObjectString(true)); + generatorProfile->rootFindingInfoObjectString(true, true)); EXPECT_EQ("extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *),\n" " double *u, size_t n, void *data);\n", generatorProfile->externNlaSolveMethodString()); - EXPECT_EQ("findRoot[INDEX](variables);\n", - generatorProfile->findRootCallString(false)); - EXPECT_EQ("findRoot[INDEX](voi, states, rates, variables);\n", - generatorProfile->findRootCallString(true)); - EXPECT_EQ("void findRoot[INDEX](double *variables)\n" + EXPECT_EQ("findRoot[INDEX](constants, computedConstants, algebraic);\n", + generatorProfile->findRootCallString(false, false)); + EXPECT_EQ("findRoot[INDEX](constants, computedConstants, algebraic, externals);\n", + generatorProfile->findRootCallString(false, true)); + EXPECT_EQ("findRoot[INDEX](voi, states, rates, constants, computedConstants, algebraic);\n", + generatorProfile->findRootCallString(true, false)); + EXPECT_EQ("findRoot[INDEX](voi, states, rates, constants, computedConstants, algebraic, externals);\n", + generatorProfile->findRootCallString(true, true)); + EXPECT_EQ("void findRoot[INDEX](double *constants, double *computedConstants, double *algebraic)\n" "{\n" - " RootFindingInfo rfi = { variables };\n" + " RootFindingInfo rfi = { constants, computedConstants, algebraic };\n" " double u[[SIZE]];\n" "\n" "[CODE]" "}\n", - generatorProfile->findRootMethodString(false)); - EXPECT_EQ("void findRoot[INDEX](double voi, double *states, double *rates, double *variables)\n" + generatorProfile->findRootMethodString(false, false)); + EXPECT_EQ("void findRoot[INDEX](double *constants, double *computedConstants, double *algebraic, double *externals)\n" "{\n" - " RootFindingInfo rfi = { voi, states, rates, variables };\n" + " RootFindingInfo rfi = { constants, computedConstants, algebraic, externals };\n" " double u[[SIZE]];\n" "\n" "[CODE]" "}\n", - generatorProfile->findRootMethodString(true)); + generatorProfile->findRootMethodString(false, true)); + EXPECT_EQ("void findRoot[INDEX](double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n" + "{\n" + " RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic };\n" + " double u[[SIZE]];\n" + "\n" + "[CODE]" + "}\n", + generatorProfile->findRootMethodString(true, false)); + EXPECT_EQ("void findRoot[INDEX](double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals)\n" + "{\n" + " RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals };\n" + " double u[[SIZE]];\n" + "\n" + "[CODE]" + "}\n", + generatorProfile->findRootMethodString(true, true)); + EXPECT_EQ("nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n", + generatorProfile->nlaSolveCallString(false, false)); EXPECT_EQ("nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n", - generatorProfile->nlaSolveCallString(false)); + generatorProfile->nlaSolveCallString(false, true)); EXPECT_EQ("nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n", - generatorProfile->nlaSolveCallString(true)); + generatorProfile->nlaSolveCallString(true, false)); + EXPECT_EQ("nlaSolve(objectiveFunction[INDEX], u, [SIZE], &rfi);\n", + generatorProfile->nlaSolveCallString(true, true)); + EXPECT_EQ("void objectiveFunction[INDEX](double *u, double *f, void *data)\n" + "{\n" + " double *constants = ((RootFindingInfo *) data)->constants;\n" + " double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n" + " double *algebraic = ((RootFindingInfo *) data)->algebraic;\n" + "\n" + "[CODE]" + "}\n", + generatorProfile->objectiveFunctionMethodString(false, false)); + EXPECT_EQ("void objectiveFunction[INDEX](double *u, double *f, void *data)\n" + "{\n" + " double *constants = ((RootFindingInfo *) data)->constants;\n" + " double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n" + " double *algebraic = ((RootFindingInfo *) data)->algebraic;\n" + " double *externals = ((RootFindingInfo *) data)->externals;\n" + "\n" + "[CODE]" + "}\n", + generatorProfile->objectiveFunctionMethodString(false, true)); EXPECT_EQ("void objectiveFunction[INDEX](double *u, double *f, void *data)\n" "{\n" - " double *variables = ((RootFindingInfo *) data)->variables;\n" + " double voi = ((RootFindingInfo *) data)->voi;\n" + " double *states = ((RootFindingInfo *) data)->states;\n" + " double *rates = ((RootFindingInfo *) data)->rates;\n" + " double *constants = ((RootFindingInfo *) data)->constants;\n" + " double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n" + " double *algebraic = ((RootFindingInfo *) data)->algebraic;\n" "\n" "[CODE]" "}\n", - generatorProfile->objectiveFunctionMethodString(false)); + generatorProfile->objectiveFunctionMethodString(true, false)); EXPECT_EQ("void objectiveFunction[INDEX](double *u, double *f, void *data)\n" "{\n" " double voi = ((RootFindingInfo *) data)->voi;\n" " double *states = ((RootFindingInfo *) data)->states;\n" " double *rates = ((RootFindingInfo *) data)->rates;\n" - " double *variables = ((RootFindingInfo *) data)->variables;\n" + " double *constants = ((RootFindingInfo *) data)->constants;\n" + " double *computedConstants = ((RootFindingInfo *) data)->computedConstants;\n" + " double *algebraic = ((RootFindingInfo *) data)->algebraic;\n" + " double *externals = ((RootFindingInfo *) data)->externals;\n" "\n" "[CODE]" "}\n", - generatorProfile->objectiveFunctionMethodString(true)); + generatorProfile->objectiveFunctionMethodString(true, true)); EXPECT_EQ("u", generatorProfile->uArrayString()); EXPECT_EQ("f", generatorProfile->fArrayString()); - EXPECT_EQ("double * createVariablesArray();\n", - generatorProfile->interfaceCreateVariablesArrayMethodString()); - EXPECT_EQ("double * createVariablesArray()\n" + EXPECT_EQ("double * createStatesArray();\n", + generatorProfile->interfaceCreateStatesArrayMethodString()); + EXPECT_EQ("double * createStatesArray()\n" "{\n" - " double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double));\n" + " double *res = (double *) malloc(STATE_COUNT*sizeof(double));\n" "\n" - " for (size_t i = 0; i < VARIABLE_COUNT; ++i) {\n" + " for (size_t i = 0; i < STATE_COUNT; ++i) {\n" " res[i] = NAN;\n" " }\n" "\n" " return res;\n" "}\n", - generatorProfile->implementationCreateVariablesArrayMethodString()); + generatorProfile->implementationCreateStatesArrayMethodString()); - EXPECT_EQ("void deleteArray(double *array);\n", - generatorProfile->interfaceDeleteArrayMethodString()); - EXPECT_EQ("void deleteArray(double *array)\n" + EXPECT_EQ("double * createConstantsArray();\n", + generatorProfile->interfaceCreateConstantsArrayMethodString()); + EXPECT_EQ("double * createConstantsArray()\n" "{\n" - " free(array);\n" + " double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double));\n" + "\n" + " for (size_t i = 0; i < CONSTANT_COUNT; ++i) {\n" + " res[i] = NAN;\n" + " }\n" + "\n" + " return res;\n" "}\n", - generatorProfile->implementationDeleteArrayMethodString()); + generatorProfile->implementationCreateConstantsArrayMethodString()); - EXPECT_EQ("void initialiseVariables(double *variables);\n", - generatorProfile->interfaceInitialiseVariablesMethodString(false, false)); - EXPECT_EQ("void initialiseVariables(double *variables)\n" + EXPECT_EQ("double * createComputedConstantsArray();\n", + generatorProfile->interfaceCreateComputedConstantsArrayMethodString()); + EXPECT_EQ("double * createComputedConstantsArray()\n" "{\n" - "[CODE]" + " double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double));\n" + "\n" + " for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) {\n" + " res[i] = NAN;\n" + " }\n" + "\n" + " return res;\n" "}\n", - generatorProfile->implementationInitialiseVariablesMethodString(false, false)); + generatorProfile->implementationCreateComputedConstantsArrayMethodString()); - EXPECT_EQ("void initialiseVariables(double *variables, ExternalVariable externalVariable);\n", - generatorProfile->interfaceInitialiseVariablesMethodString(false, true)); - EXPECT_EQ("void initialiseVariables(double *variables, ExternalVariable externalVariable)\n" + EXPECT_EQ("double * createAlgebraicArray();\n", + generatorProfile->interfaceCreateAlgebraicArrayMethodString()); + EXPECT_EQ("double * createAlgebraicArray()\n" "{\n" - "[CODE]" + " double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double));\n" + "\n" + " for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) {\n" + " res[i] = NAN;\n" + " }\n" + "\n" + " return res;\n" + "}\n", + generatorProfile->implementationCreateAlgebraicArrayMethodString()); + + EXPECT_EQ("double * createExternalsArray();\n", + generatorProfile->interfaceCreateExternalsArrayMethodString()); + EXPECT_EQ("double * createExternalsArray()\n" + "{\n" + " double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double));\n" + "\n" + " for (size_t i = 0; i < EXTERNAL_COUNT; ++i) {\n" + " res[i] = NAN;\n" + " }\n" + "\n" + " return res;\n" "}\n", - generatorProfile->implementationInitialiseVariablesMethodString(false, true)); + generatorProfile->implementationCreateExternalsArrayMethodString()); - EXPECT_EQ("void initialiseVariables(double *states, double *rates, double *variables);\n", - generatorProfile->interfaceInitialiseVariablesMethodString(true, false)); - EXPECT_EQ("void initialiseVariables(double *states, double *rates, double *variables)\n" + EXPECT_EQ("void deleteArray(double *array);\n", + generatorProfile->interfaceDeleteArrayMethodString()); + EXPECT_EQ("void deleteArray(double *array)\n" + "{\n" + " free(array);\n" + "}\n", + generatorProfile->implementationDeleteArrayMethodString()); + + EXPECT_EQ("void initialiseVariables(double *constants, double *computedConstants, double *algebraic);\n", + generatorProfile->interfaceInitialiseVariablesMethodString(false)); + EXPECT_EQ("void initialiseVariables(double *constants, double *computedConstants, double *algebraic)\n" "{\n" "[CODE]" "}\n", - generatorProfile->implementationInitialiseVariablesMethodString(true, false)); + generatorProfile->implementationInitialiseVariablesMethodString(false)); - EXPECT_EQ("void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable);\n", - generatorProfile->interfaceInitialiseVariablesMethodString(true, true)); - EXPECT_EQ("void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable)\n" + EXPECT_EQ("void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic);\n", + generatorProfile->interfaceInitialiseVariablesMethodString(true)); + EXPECT_EQ("void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n" "{\n" "[CODE]" "}\n", - generatorProfile->implementationInitialiseVariablesMethodString(true, true)); + generatorProfile->implementationInitialiseVariablesMethodString(true)); - EXPECT_EQ("void computeComputedConstants(double *variables);\n", + EXPECT_EQ("void computeComputedConstants(double *constants, double *computedConstants);\n", generatorProfile->interfaceComputeComputedConstantsMethodString()); - EXPECT_EQ("void computeComputedConstants(double *variables)\n" + EXPECT_EQ("void computeComputedConstants(double *constants, double *computedConstants)\n" "{\n" "[CODE]" "}\n", generatorProfile->implementationComputeComputedConstantsMethodString()); - EXPECT_EQ("void computeRates(double voi, double *states, double *rates, double *variables);\n", + EXPECT_EQ("void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic);\n", generatorProfile->interfaceComputeRatesMethodString(false)); - EXPECT_EQ("void computeRates(double voi, double *states, double *rates, double *variables)\n" + EXPECT_EQ("void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n" "{\n" "[CODE]" "}\n", generatorProfile->implementationComputeRatesMethodString(false)); - EXPECT_EQ("void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable);\n", + EXPECT_EQ("void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable);\n", generatorProfile->interfaceComputeRatesMethodString(true)); - EXPECT_EQ("void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable)\n" + EXPECT_EQ("void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable)\n" "{\n" "[CODE]" "}\n", generatorProfile->implementationComputeRatesMethodString(true)); - EXPECT_EQ("void computeVariables(double *variables);\n", + EXPECT_EQ("void computeVariables(double *constants, double *computedConstants, double *algebraic);\n", generatorProfile->interfaceComputeVariablesMethodString(false, false)); - EXPECT_EQ("void computeVariables(double *variables)\n" + EXPECT_EQ("void computeVariables(double *constants, double *computedConstants, double *algebraic)\n" "{\n" "[CODE]" "}\n", generatorProfile->implementationComputeVariablesMethodString(false, false)); - EXPECT_EQ("void computeVariables(double *variables, ExternalVariable externalVariable);\n", + EXPECT_EQ("void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable);\n", generatorProfile->interfaceComputeVariablesMethodString(false, true)); - EXPECT_EQ("void computeVariables(double *variables, ExternalVariable externalVariable)\n" + EXPECT_EQ("void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable)\n" "{\n" "[CODE]" "}\n", generatorProfile->implementationComputeVariablesMethodString(false, true)); - EXPECT_EQ("void computeVariables(double voi, double *states, double *rates, double *variables);\n", + EXPECT_EQ("void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic);\n", generatorProfile->interfaceComputeVariablesMethodString(true, false)); - EXPECT_EQ("void computeVariables(double voi, double *states, double *rates, double *variables)\n" + EXPECT_EQ("void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic)\n" "{\n" "[CODE]" "}\n", generatorProfile->implementationComputeVariablesMethodString(true, false)); - EXPECT_EQ("void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable);\n", + EXPECT_EQ("void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable);\n", generatorProfile->interfaceComputeVariablesMethodString(true, true)); - EXPECT_EQ("void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable)\n" + EXPECT_EQ("void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable)\n" "{\n" "[CODE]" "}\n", @@ -865,20 +940,17 @@ TEST(GeneratorProfile, miscellaneous) generatorProfile->setInterfaceStateCountString(value); generatorProfile->setImplementationStateCountString(value); - generatorProfile->setInterfaceVariableCountString(value); - generatorProfile->setImplementationVariableCountString(value); + generatorProfile->setInterfaceConstantCountString(value); + generatorProfile->setImplementationConstantCountString(value); - generatorProfile->setVariableTypeObjectString(false, false, value); - generatorProfile->setVariableTypeObjectString(false, true, value); - generatorProfile->setVariableTypeObjectString(true, false, value); - generatorProfile->setVariableTypeObjectString(true, true, value); + generatorProfile->setInterfaceComputedConstantCountString(value); + generatorProfile->setImplementationComputedConstantCountString(value); - generatorProfile->setVariableOfIntegrationVariableTypeString(value); - generatorProfile->setStateVariableTypeString(value); - generatorProfile->setConstantVariableTypeString(value); - generatorProfile->setComputedConstantVariableTypeString(value); - generatorProfile->setAlgebraicVariableTypeString(value); - generatorProfile->setExternalVariableTypeString(value); + generatorProfile->setInterfaceAlgebraicCountString(value); + generatorProfile->setImplementationAlgebraicCountString(value); + + generatorProfile->setInterfaceExternalCountString(value); + generatorProfile->setImplementationExternalCountString(value); generatorProfile->setVariableInfoObjectString(value); @@ -888,8 +960,17 @@ TEST(GeneratorProfile, miscellaneous) generatorProfile->setInterfaceStateInfoString(value); generatorProfile->setImplementationStateInfoString(value); - generatorProfile->setInterfaceVariableInfoString(value); - generatorProfile->setImplementationVariableInfoString(value); + generatorProfile->setInterfaceConstantInfoString(value); + generatorProfile->setImplementationConstantInfoString(value); + + generatorProfile->setInterfaceComputedConstantInfoString(value); + generatorProfile->setImplementationComputedConstantInfoString(value); + + generatorProfile->setInterfaceAlgebraicInfoString(value); + generatorProfile->setImplementationAlgebraicInfoString(value); + + generatorProfile->setInterfaceExternalInfoString(value); + generatorProfile->setImplementationExternalInfoString(value); generatorProfile->setVariableInfoEntryString(value); @@ -897,7 +978,10 @@ TEST(GeneratorProfile, miscellaneous) generatorProfile->setStatesArrayString(value); generatorProfile->setRatesArrayString(value); - generatorProfile->setVariablesArrayString(value); + generatorProfile->setConstantsArrayString(value); + generatorProfile->setComputedConstantsArrayString(value); + generatorProfile->setAlgebraicArrayString(value); + generatorProfile->setExternalArrayString(value); generatorProfile->setExternalVariableMethodTypeDefinitionString(false, value); generatorProfile->setExternalVariableMethodTypeDefinitionString(true, value); @@ -905,60 +989,77 @@ TEST(GeneratorProfile, miscellaneous) generatorProfile->setExternalVariableMethodCallString(false, value); generatorProfile->setExternalVariableMethodCallString(true, value); - generatorProfile->setInterfaceCreateStatesArrayMethodString(value); - generatorProfile->setImplementationCreateStatesArrayMethodString(value); + generatorProfile->setRootFindingInfoObjectString(false, false, value); + generatorProfile->setRootFindingInfoObjectString(false, true, value); + generatorProfile->setRootFindingInfoObjectString(true, false, value); + generatorProfile->setRootFindingInfoObjectString(true, true, value); - generatorProfile->setRootFindingInfoObjectString(false, value); - generatorProfile->setRootFindingInfoObjectString(true, value); generatorProfile->setExternNlaSolveMethodString(value); - generatorProfile->setFindRootCallString(false, value); - generatorProfile->setFindRootCallString(true, value); - generatorProfile->setFindRootMethodString(false, value); - generatorProfile->setFindRootMethodString(true, value); - generatorProfile->setNlaSolveCallString(false, value); - generatorProfile->setNlaSolveCallString(true, value); - generatorProfile->setObjectiveFunctionMethodString(false, value); - generatorProfile->setObjectiveFunctionMethodString(true, value); + + generatorProfile->setFindRootCallString(false, false, value); + generatorProfile->setFindRootCallString(false, true, value); + generatorProfile->setFindRootCallString(true, false, value); + generatorProfile->setFindRootCallString(true, true, value); + + generatorProfile->setFindRootMethodString(false, false, value); + generatorProfile->setFindRootMethodString(false, true, value); + generatorProfile->setFindRootMethodString(true, false, value); + generatorProfile->setFindRootMethodString(true, true, value); + + generatorProfile->setNlaSolveCallString(false, false, value); + generatorProfile->setNlaSolveCallString(false, true, value); + generatorProfile->setNlaSolveCallString(true, false, value); + generatorProfile->setNlaSolveCallString(true, true, value); + + generatorProfile->setObjectiveFunctionMethodString(false, false, value); + generatorProfile->setObjectiveFunctionMethodString(false, true, value); + generatorProfile->setObjectiveFunctionMethodString(true, false, value); + generatorProfile->setObjectiveFunctionMethodString(true, true, value); + generatorProfile->setUArrayString(value); generatorProfile->setFArrayString(value); - generatorProfile->setInterfaceCreateVariablesArrayMethodString(value); - generatorProfile->setImplementationCreateVariablesArrayMethodString(value); + generatorProfile->setInterfaceCreateStatesArrayMethodString(value); + generatorProfile->setImplementationCreateStatesArrayMethodString(value); + + generatorProfile->setInterfaceCreateConstantsArrayMethodString(value); + generatorProfile->setImplementationCreateConstantsArrayMethodString(value); - generatorProfile->setInterfaceDeleteArrayMethodString(value); - generatorProfile->setImplementationDeleteArrayMethodString(value); + generatorProfile->setInterfaceCreateComputedConstantsArrayMethodString(value); + generatorProfile->setImplementationCreateComputedConstantsArrayMethodString(value); + + generatorProfile->setInterfaceCreateAlgebraicArrayMethodString(value); + generatorProfile->setImplementationCreateAlgebraicArrayMethodString(value); - generatorProfile->setInterfaceInitialiseVariablesMethodString(false, false, value); - generatorProfile->setImplementationInitialiseVariablesMethodString(false, false, value); + generatorProfile->setInterfaceCreateExternalsArrayMethodString(value); + generatorProfile->setImplementationCreateExternalsArrayMethodString(value); - generatorProfile->setInterfaceInitialiseVariablesMethodString(false, true, value); - generatorProfile->setImplementationInitialiseVariablesMethodString(false, true, value); + generatorProfile->setInterfaceDeleteArrayMethodString(value); + generatorProfile->setImplementationDeleteArrayMethodString(value); - generatorProfile->setInterfaceInitialiseVariablesMethodString(true, false, value); - generatorProfile->setImplementationInitialiseVariablesMethodString(true, false, value); + generatorProfile->setInterfaceInitialiseVariablesMethodString(false, value); + generatorProfile->setInterfaceInitialiseVariablesMethodString(true, value); - generatorProfile->setInterfaceInitialiseVariablesMethodString(true, true, value); - generatorProfile->setImplementationInitialiseVariablesMethodString(true, true, value); + generatorProfile->setImplementationInitialiseVariablesMethodString(false, value); + generatorProfile->setImplementationInitialiseVariablesMethodString(true, value); generatorProfile->setInterfaceComputeComputedConstantsMethodString(value); generatorProfile->setImplementationComputeComputedConstantsMethodString(value); generatorProfile->setInterfaceComputeRatesMethodString(false, value); - generatorProfile->setImplementationComputeRatesMethodString(false, value); - generatorProfile->setInterfaceComputeRatesMethodString(true, value); + + generatorProfile->setImplementationComputeRatesMethodString(false, value); generatorProfile->setImplementationComputeRatesMethodString(true, value); generatorProfile->setInterfaceComputeVariablesMethodString(false, false, value); - generatorProfile->setImplementationComputeVariablesMethodString(false, false, value); - generatorProfile->setInterfaceComputeVariablesMethodString(false, true, value); - generatorProfile->setImplementationComputeVariablesMethodString(false, true, value); - generatorProfile->setInterfaceComputeVariablesMethodString(true, false, value); - generatorProfile->setImplementationComputeVariablesMethodString(true, false, value); - generatorProfile->setInterfaceComputeVariablesMethodString(true, true, value); + + generatorProfile->setImplementationComputeVariablesMethodString(false, false, value); + generatorProfile->setImplementationComputeVariablesMethodString(false, true, value); + generatorProfile->setImplementationComputeVariablesMethodString(true, false, value); generatorProfile->setImplementationComputeVariablesMethodString(true, true, value); generatorProfile->setEmptyMethodString(value); @@ -994,20 +1095,17 @@ TEST(GeneratorProfile, miscellaneous) EXPECT_EQ(value, generatorProfile->interfaceStateCountString()); EXPECT_EQ(value, generatorProfile->implementationStateCountString()); - EXPECT_EQ(value, generatorProfile->interfaceVariableCountString()); - EXPECT_EQ(value, generatorProfile->implementationVariableCountString()); + EXPECT_EQ(value, generatorProfile->interfaceConstantCountString()); + EXPECT_EQ(value, generatorProfile->implementationConstantCountString()); + + EXPECT_EQ(value, generatorProfile->interfaceComputedConstantCountString()); + EXPECT_EQ(value, generatorProfile->implementationComputedConstantCountString()); - EXPECT_EQ(value, generatorProfile->variableTypeObjectString(false, false)); - EXPECT_EQ(value, generatorProfile->variableTypeObjectString(false, true)); - EXPECT_EQ(value, generatorProfile->variableTypeObjectString(true, false)); - EXPECT_EQ(value, generatorProfile->variableTypeObjectString(true, true)); + EXPECT_EQ(value, generatorProfile->interfaceAlgebraicCountString()); + EXPECT_EQ(value, generatorProfile->implementationAlgebraicCountString()); - EXPECT_EQ(value, generatorProfile->variableOfIntegrationVariableTypeString()); - EXPECT_EQ(value, generatorProfile->stateVariableTypeString()); - EXPECT_EQ(value, generatorProfile->constantVariableTypeString()); - EXPECT_EQ(value, generatorProfile->computedConstantVariableTypeString()); - EXPECT_EQ(value, generatorProfile->algebraicVariableTypeString()); - EXPECT_EQ(value, generatorProfile->externalVariableTypeString()); + EXPECT_EQ(value, generatorProfile->interfaceExternalCountString()); + EXPECT_EQ(value, generatorProfile->implementationExternalCountString()); EXPECT_EQ(value, generatorProfile->variableInfoObjectString()); @@ -1017,8 +1115,17 @@ TEST(GeneratorProfile, miscellaneous) EXPECT_EQ(value, generatorProfile->interfaceStateInfoString()); EXPECT_EQ(value, generatorProfile->implementationStateInfoString()); - EXPECT_EQ(value, generatorProfile->interfaceVariableInfoString()); - EXPECT_EQ(value, generatorProfile->implementationVariableInfoString()); + EXPECT_EQ(value, generatorProfile->interfaceConstantInfoString()); + EXPECT_EQ(value, generatorProfile->implementationConstantInfoString()); + + EXPECT_EQ(value, generatorProfile->interfaceComputedConstantInfoString()); + EXPECT_EQ(value, generatorProfile->implementationComputedConstantInfoString()); + + EXPECT_EQ(value, generatorProfile->interfaceAlgebraicInfoString()); + EXPECT_EQ(value, generatorProfile->implementationAlgebraicInfoString()); + + EXPECT_EQ(value, generatorProfile->interfaceExternalInfoString()); + EXPECT_EQ(value, generatorProfile->implementationExternalInfoString()); EXPECT_EQ(value, generatorProfile->variableInfoEntryString()); @@ -1026,7 +1133,10 @@ TEST(GeneratorProfile, miscellaneous) EXPECT_EQ(value, generatorProfile->statesArrayString()); EXPECT_EQ(value, generatorProfile->ratesArrayString()); - EXPECT_EQ(value, generatorProfile->variablesArrayString()); + EXPECT_EQ(value, generatorProfile->constantsArrayString()); + EXPECT_EQ(value, generatorProfile->computedConstantsArrayString()); + EXPECT_EQ(value, generatorProfile->algebraicArrayString()); + EXPECT_EQ(value, generatorProfile->externalArrayString()); EXPECT_EQ(value, generatorProfile->externalVariableMethodTypeDefinitionString(false)); EXPECT_EQ(value, generatorProfile->externalVariableMethodTypeDefinitionString(true)); @@ -1034,40 +1144,59 @@ TEST(GeneratorProfile, miscellaneous) EXPECT_EQ(value, generatorProfile->externalVariableMethodCallString(false)); EXPECT_EQ(value, generatorProfile->externalVariableMethodCallString(true)); - EXPECT_EQ(value, generatorProfile->interfaceCreateStatesArrayMethodString()); - EXPECT_EQ(value, generatorProfile->implementationCreateStatesArrayMethodString()); + EXPECT_EQ(value, generatorProfile->rootFindingInfoObjectString(false, false)); + EXPECT_EQ(value, generatorProfile->rootFindingInfoObjectString(false, true)); + EXPECT_EQ(value, generatorProfile->rootFindingInfoObjectString(true, false)); + EXPECT_EQ(value, generatorProfile->rootFindingInfoObjectString(true, true)); - EXPECT_EQ(value, generatorProfile->rootFindingInfoObjectString(false)); - EXPECT_EQ(value, generatorProfile->rootFindingInfoObjectString(true)); EXPECT_EQ(value, generatorProfile->externNlaSolveMethodString()); - EXPECT_EQ(value, generatorProfile->findRootCallString(false)); - EXPECT_EQ(value, generatorProfile->findRootCallString(true)); - EXPECT_EQ(value, generatorProfile->findRootMethodString(false)); - EXPECT_EQ(value, generatorProfile->findRootMethodString(true)); - EXPECT_EQ(value, generatorProfile->nlaSolveCallString(false)); - EXPECT_EQ(value, generatorProfile->nlaSolveCallString(true)); - EXPECT_EQ(value, generatorProfile->objectiveFunctionMethodString(false)); - EXPECT_EQ(value, generatorProfile->objectiveFunctionMethodString(true)); + + EXPECT_EQ(value, generatorProfile->findRootCallString(false, false)); + EXPECT_EQ(value, generatorProfile->findRootCallString(false, true)); + EXPECT_EQ(value, generatorProfile->findRootCallString(true, false)); + EXPECT_EQ(value, generatorProfile->findRootCallString(true, true)); + + EXPECT_EQ(value, generatorProfile->findRootMethodString(false, false)); + EXPECT_EQ(value, generatorProfile->findRootMethodString(false, true)); + EXPECT_EQ(value, generatorProfile->findRootMethodString(true, false)); + EXPECT_EQ(value, generatorProfile->findRootMethodString(true, true)); + + EXPECT_EQ(value, generatorProfile->nlaSolveCallString(false, false)); + EXPECT_EQ(value, generatorProfile->nlaSolveCallString(false, true)); + EXPECT_EQ(value, generatorProfile->nlaSolveCallString(true, false)); + EXPECT_EQ(value, generatorProfile->nlaSolveCallString(true, true)); + + EXPECT_EQ(value, generatorProfile->objectiveFunctionMethodString(false, false)); + EXPECT_EQ(value, generatorProfile->objectiveFunctionMethodString(false, true)); + EXPECT_EQ(value, generatorProfile->objectiveFunctionMethodString(true, false)); + EXPECT_EQ(value, generatorProfile->objectiveFunctionMethodString(true, true)); + EXPECT_EQ(value, generatorProfile->uArrayString()); EXPECT_EQ(value, generatorProfile->fArrayString()); - EXPECT_EQ(value, generatorProfile->interfaceCreateVariablesArrayMethodString()); - EXPECT_EQ(value, generatorProfile->implementationCreateVariablesArrayMethodString()); + EXPECT_EQ(value, generatorProfile->interfaceCreateStatesArrayMethodString()); + EXPECT_EQ(value, generatorProfile->implementationCreateStatesArrayMethodString()); - EXPECT_EQ(value, generatorProfile->interfaceDeleteArrayMethodString()); - EXPECT_EQ(value, generatorProfile->implementationDeleteArrayMethodString()); + EXPECT_EQ(value, generatorProfile->interfaceCreateConstantsArrayMethodString()); + EXPECT_EQ(value, generatorProfile->implementationCreateConstantsArrayMethodString()); + + EXPECT_EQ(value, generatorProfile->interfaceCreateComputedConstantsArrayMethodString()); + EXPECT_EQ(value, generatorProfile->implementationCreateComputedConstantsArrayMethodString()); + + EXPECT_EQ(value, generatorProfile->interfaceCreateAlgebraicArrayMethodString()); + EXPECT_EQ(value, generatorProfile->implementationCreateAlgebraicArrayMethodString()); - EXPECT_EQ(value, generatorProfile->interfaceInitialiseVariablesMethodString(false, false)); - EXPECT_EQ(value, generatorProfile->implementationInitialiseVariablesMethodString(false, false)); + EXPECT_EQ(value, generatorProfile->interfaceCreateExternalsArrayMethodString()); + EXPECT_EQ(value, generatorProfile->implementationCreateExternalsArrayMethodString()); - EXPECT_EQ(value, generatorProfile->interfaceInitialiseVariablesMethodString(false, true)); - EXPECT_EQ(value, generatorProfile->implementationInitialiseVariablesMethodString(false, true)); + EXPECT_EQ(value, generatorProfile->interfaceDeleteArrayMethodString()); + EXPECT_EQ(value, generatorProfile->implementationDeleteArrayMethodString()); - EXPECT_EQ(value, generatorProfile->interfaceInitialiseVariablesMethodString(true, false)); - EXPECT_EQ(value, generatorProfile->implementationInitialiseVariablesMethodString(true, false)); + EXPECT_EQ(value, generatorProfile->interfaceInitialiseVariablesMethodString(false)); + EXPECT_EQ(value, generatorProfile->implementationInitialiseVariablesMethodString(false)); - EXPECT_EQ(value, generatorProfile->interfaceInitialiseVariablesMethodString(true, true)); - EXPECT_EQ(value, generatorProfile->implementationInitialiseVariablesMethodString(true, true)); + EXPECT_EQ(value, generatorProfile->interfaceInitialiseVariablesMethodString(true)); + EXPECT_EQ(value, generatorProfile->implementationInitialiseVariablesMethodString(true)); EXPECT_EQ(value, generatorProfile->interfaceComputeComputedConstantsMethodString()); EXPECT_EQ(value, generatorProfile->implementationComputeComputedConstantsMethodString()); diff --git a/tests/generator/tests.cmake b/tests/generator/tests.cmake index c5fee6f22c..af7f9a9ae9 100644 --- a/tests/generator/tests.cmake +++ b/tests/generator/tests.cmake @@ -7,3 +7,8 @@ set(${CURRENT_TEST}_SRCS ${CMAKE_CURRENT_LIST_DIR}/generator.cpp ${CMAKE_CURRENT_LIST_DIR}/generatorprofile.cpp ) + +set(${CURRENT_TEST}_HDRS + ${CMAKE_CURRENT_LIST_DIR}/generator.macros.h + ${CMAKE_CURRENT_LIST_DIR}/generator.models.h +) diff --git a/tests/importer/importer.cpp b/tests/importer/importer.cpp index 3f959e71af..3ebab5811e 100644 --- a/tests/importer/importer.cpp +++ b/tests/importer/importer.cpp @@ -334,9 +334,9 @@ TEST(Importer, accessImportedModelLibrary) auto point = importer->library(resourcePath("importer/diamond_point.cellml")); // Test that the library items are the same as those in the files. - EXPECT_EQ(fileContents("importer/diamond_left.cellml"), printer->printModel(left)); - EXPECT_EQ(fileContents("importer/diamond_right.cellml"), printer->printModel(right)); - EXPECT_EQ(fileContents("importer/diamond_point.cellml"), printer->printModel(point)); + EXPECT_EQ_FILE_CONTENTS("importer/diamond_left.cellml", printer->printModel(left)); + EXPECT_EQ_FILE_CONTENTS("importer/diamond_right.cellml", printer->printModel(right)); + EXPECT_EQ_FILE_CONTENTS("importer/diamond_point.cellml", printer->printModel(point)); } TEST(Importer, multipleModelResolution) diff --git a/tests/importer/model_flattening.cpp b/tests/importer/model_flattening.cpp index 80c218df3f..f28e84713f 100644 --- a/tests/importer/model_flattening.cpp +++ b/tests/importer/model_flattening.cpp @@ -734,15 +734,15 @@ TEST(ModelFlattening, hodgkinHuxleyDefinedUsingImports) generator->setModel(analyser->model()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.h"), generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.c"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.h", generator->interfaceCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.c", generator->implementationCode()); libcellml::GeneratorProfilePtr profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); generator->setProfile(profile); EXPECT_EQ("", generator->interfaceCode()); - EXPECT_EQ(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.py"), generator->implementationCode()); + EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.py", generator->implementationCode()); } TEST(ModelFlattening, importedComponentsWithConnectionsToChildren) diff --git a/tests/printer/printer.cpp b/tests/printer/printer.cpp index a55cf81ceb..74692e53d3 100644 --- a/tests/printer/printer.cpp +++ b/tests/printer/printer.cpp @@ -312,7 +312,7 @@ TEST(Printer, printModelWithTabs) libcellml::ModelPtr model = parser->parseModel(fileContents("printer/tabulated_model.cellml")); libcellml::PrinterPtr printer = libcellml::Printer::create(); - EXPECT_EQ(fileContents("printer/spaced_model.cellml"), printer->printModel(model)); + EXPECT_EQ_FILE_CONTENTS("printer/spaced_model.cellml", printer->printModel(model)); } TEST(Printer, printModelWithStandardUnitsAdded) diff --git a/tests/resources/coverage/generator/model.c b/tests/resources/coverage/generator/model.c index c537d069fa..dfefa277a5 100644 --- a/tests/resources/coverage/generator/model.c +++ b/tests/resources/coverage/generator/model.c @@ -5,243 +5,256 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 209; +const size_t CONSTANT_COUNT = 7; +const size_t COMPUTED_CONSTANT_COUNT = 207; +const size_t ALGEBRAIC_COUNT = 5; +const size_t EXTERNAL_COUNT = 1; -const VariableInfo VOI_INFO = {"t", "second", "my_component", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "my_component"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_component", STATE} + {"x", "dimensionless", "my_component"} }; -const VariableInfo VARIABLE_INFO[] = { - {"eqnEq", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"m", "dimensionless", "my_component", CONSTANT}, - {"n", "dimensionless", "my_component", CONSTANT}, - {"eqnEqCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnNeq", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnNeqCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"o", "dimensionless", "my_component", CONSTANT}, - {"eqnLt", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLtCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLeq", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLeqCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnGt", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnGtCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnGeq", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnGeqCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAnd", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"p", "dimensionless", "my_component", CONSTANT}, - {"eqnAndParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesLeftPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesLeftRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOr", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXor", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnNot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPlus", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPlusMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPlusParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPlusUnary", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinus", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusParenthesesPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusParenthesesPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusParenthesesDirectUnaryMinus", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusParenthesesIndirectUnaryMinus", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusUnary", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusUnaryParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerSqrt", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerSqr", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerCube", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerCi", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootSqrt", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootSqrtOther", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootCube", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootCi", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAbs", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnExp", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLn", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLog", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLog2", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLog10", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLogCi", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCeiling", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnFloor", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMin", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMax", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMaxMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRem", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnSin", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCos", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTan", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnSec", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCsc", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnSinh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCosh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTanh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnSech", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCsch", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoth", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArcsin", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccos", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArctan", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArcsec", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccsc", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArcsinh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccosh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArctanh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArcsech", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccsch", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccoth", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPiecewisePiece", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPiecewisePieceOtherwise", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPiecewisePiecePiecePiece", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"q", "dimensionless", "my_component", CONSTANT}, - {"r", "dimensionless", "my_component", CONSTANT}, - {"eqnPiecewisePiecePiecePieceOtherwise", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"s", "dimensionless", "my_component", CONSTANT}, - {"eqnWithPiecewise", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCnInteger", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCnDouble", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCnIntegerWithExponent", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCnDoubleWithExponent", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCi", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTrue", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnFalse", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnExponentiale", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPi", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnInfinity", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnNotanumber", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForPlusOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForMinusOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForTimesOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForDivideOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForAndOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForOrOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForXorOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForPowerOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForRootOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForMinusUnary", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnNlaVariable1", "dimensionless", "my_component", ALGEBRAIC}, - {"eqnNlaVariable2", "dimensionless", "my_component", ALGEBRAIC}, - {"eqnComputedConstant1", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnComputedConstant2", "dimensionless", "my_component", COMPUTED_CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"m", "dimensionless", "my_component"}, + {"n", "dimensionless", "my_component"}, + {"o", "dimensionless", "my_component"}, + {"p", "dimensionless", "my_component"}, + {"q", "dimensionless", "my_component"}, + {"r", "dimensionless", "my_component"}, + {"s", "dimensionless", "my_component"} }; -double xor(double x, double y) -{ - return (x != 0.0) ^ (y != 0.0); -} +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"eqnEq", "dimensionless", "my_component"}, + {"eqnEqCoverageParentheses", "dimensionless", "my_component"}, + {"eqnNeq", "dimensionless", "my_component"}, + {"eqnNeqCoverageParentheses", "dimensionless", "my_component"}, + {"eqnLt", "dimensionless", "my_component"}, + {"eqnLtCoverageParentheses", "dimensionless", "my_component"}, + {"eqnLeq", "dimensionless", "my_component"}, + {"eqnLeqCoverageParentheses", "dimensionless", "my_component"}, + {"eqnGt", "dimensionless", "my_component"}, + {"eqnGtCoverageParentheses", "dimensionless", "my_component"}, + {"eqnGeq", "dimensionless", "my_component"}, + {"eqnGeqCoverageParentheses", "dimensionless", "my_component"}, + {"eqnAnd", "dimensionless", "my_component"}, + {"eqnAndMultiple", "dimensionless", "my_component"}, + {"eqnAndParentheses", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftPower", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftRoot", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightPower", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightRoot", "dimensionless", "my_component"}, + {"eqnAndCoverageParentheses", "dimensionless", "my_component"}, + {"eqnOrParentheses", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftPower", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftRoot", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightPower", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightRoot", "dimensionless", "my_component"}, + {"eqnOrCoverageParentheses", "dimensionless", "my_component"}, + {"eqnXor", "dimensionless", "my_component"}, + {"eqnXorMultiple", "dimensionless", "my_component"}, + {"eqnXorParentheses", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftPower", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftRoot", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightPower", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightRoot", "dimensionless", "my_component"}, + {"eqnNot", "dimensionless", "my_component"}, + {"eqnPlusMultiple", "dimensionless", "my_component"}, + {"eqnPlusParentheses", "dimensionless", "my_component"}, + {"eqnPlusUnary", "dimensionless", "my_component"}, + {"eqnMinus", "dimensionless", "my_component"}, + {"eqnMinusParentheses", "dimensionless", "my_component"}, + {"eqnMinusParenthesesPlusWith", "dimensionless", "my_component"}, + {"eqnMinusParenthesesPlusWithout", "dimensionless", "my_component"}, + {"eqnMinusParenthesesDirectUnaryMinus", "dimensionless", "my_component"}, + {"eqnMinusParenthesesIndirectUnaryMinus", "dimensionless", "my_component"}, + {"eqnMinusUnary", "dimensionless", "my_component"}, + {"eqnMinusUnaryParentheses", "dimensionless", "my_component"}, + {"eqnTimes", "dimensionless", "my_component"}, + {"eqnTimesMultiple", "dimensionless", "my_component"}, + {"eqnTimesParentheses", "dimensionless", "my_component"}, + {"eqnTimesParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnTimesParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnTimesParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnTimesParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnTimesParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnTimesParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnTimesParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnTimesParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnDivide", "dimensionless", "my_component"}, + {"eqnDivideParentheses", "dimensionless", "my_component"}, + {"eqnDivideParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnDivideParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnDivideParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnDivideParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightTimes", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightDivide", "dimensionless", "my_component"}, + {"eqnPowerSqrt", "dimensionless", "my_component"}, + {"eqnPowerSqr", "dimensionless", "my_component"}, + {"eqnPowerCube", "dimensionless", "my_component"}, + {"eqnPowerCi", "dimensionless", "my_component"}, + {"eqnPowerParentheses", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftTimes", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftDivide", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightTimes", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightDivide", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightPower", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightRoot", "dimensionless", "my_component"}, + {"eqnRootSqrt", "dimensionless", "my_component"}, + {"eqnRootSqrtOther", "dimensionless", "my_component"}, + {"eqnRootSqr", "dimensionless", "my_component"}, + {"eqnRootCube", "dimensionless", "my_component"}, + {"eqnRootCi", "dimensionless", "my_component"}, + {"eqnRootParentheses", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftTimes", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftDivide", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightTimes", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightDivide", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightPower", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightRoot", "dimensionless", "my_component"}, + {"eqnAbs", "dimensionless", "my_component"}, + {"eqnExp", "dimensionless", "my_component"}, + {"eqnLn", "dimensionless", "my_component"}, + {"eqnLog", "dimensionless", "my_component"}, + {"eqnLog2", "dimensionless", "my_component"}, + {"eqnLog10", "dimensionless", "my_component"}, + {"eqnLogCi", "dimensionless", "my_component"}, + {"eqnCeiling", "dimensionless", "my_component"}, + {"eqnFloor", "dimensionless", "my_component"}, + {"eqnMin", "dimensionless", "my_component"}, + {"eqnMinMultiple", "dimensionless", "my_component"}, + {"eqnMax", "dimensionless", "my_component"}, + {"eqnMaxMultiple", "dimensionless", "my_component"}, + {"eqnRem", "dimensionless", "my_component"}, + {"eqnSin", "dimensionless", "my_component"}, + {"eqnCos", "dimensionless", "my_component"}, + {"eqnTan", "dimensionless", "my_component"}, + {"eqnSec", "dimensionless", "my_component"}, + {"eqnCsc", "dimensionless", "my_component"}, + {"eqnCot", "dimensionless", "my_component"}, + {"eqnSinh", "dimensionless", "my_component"}, + {"eqnCosh", "dimensionless", "my_component"}, + {"eqnTanh", "dimensionless", "my_component"}, + {"eqnSech", "dimensionless", "my_component"}, + {"eqnCsch", "dimensionless", "my_component"}, + {"eqnCoth", "dimensionless", "my_component"}, + {"eqnArcsin", "dimensionless", "my_component"}, + {"eqnArccos", "dimensionless", "my_component"}, + {"eqnArctan", "dimensionless", "my_component"}, + {"eqnArcsec", "dimensionless", "my_component"}, + {"eqnArccsc", "dimensionless", "my_component"}, + {"eqnArccot", "dimensionless", "my_component"}, + {"eqnArcsinh", "dimensionless", "my_component"}, + {"eqnArccosh", "dimensionless", "my_component"}, + {"eqnArctanh", "dimensionless", "my_component"}, + {"eqnArcsech", "dimensionless", "my_component"}, + {"eqnArccsch", "dimensionless", "my_component"}, + {"eqnArccoth", "dimensionless", "my_component"}, + {"eqnPiecewise", "dimensionless", "my_component"}, + {"eqnPiecewisePiece", "dimensionless", "my_component"}, + {"eqnPiecewisePiece2", "dimensionless", "my_component"}, + {"eqnPiecewiseOtherwise", "dimensionless", "my_component"}, + {"eqnPiecewisePieceOtherwise", "dimensionless", "my_component"}, + {"eqnPiecewisePiecePiecePiece", "dimensionless", "my_component"}, + {"eqnPiecewisePiecePiecePiece2", "dimensionless", "my_component"}, + {"eqnPiecewisePiecePiecePieceOtherwise", "dimensionless", "my_component"}, + {"eqnWithPiecewise", "dimensionless", "my_component"}, + {"eqnWithPiecewise2", "dimensionless", "my_component"}, + {"eqnCnInteger", "dimensionless", "my_component"}, + {"eqnCnDouble", "dimensionless", "my_component"}, + {"eqnCnIntegerWithExponent", "dimensionless", "my_component"}, + {"eqnCnDoubleWithExponent", "dimensionless", "my_component"}, + {"eqnCi", "dimensionless", "my_component"}, + {"eqnTrue", "dimensionless", "my_component"}, + {"eqnFalse", "dimensionless", "my_component"}, + {"eqnExponentiale", "dimensionless", "my_component"}, + {"eqnPi", "dimensionless", "my_component"}, + {"eqnInfinity", "dimensionless", "my_component"}, + {"eqnNotanumber", "dimensionless", "my_component"}, + {"eqnCoverageForPlusOperator", "dimensionless", "my_component"}, + {"eqnCoverageForPlusOperator2", "dimensionless", "my_component"}, + {"eqnCoverageForMinusOperator", "dimensionless", "my_component"}, + {"eqnCoverageForMinusOperator2", "dimensionless", "my_component"}, + {"eqnCoverageForTimesOperator", "dimensionless", "my_component"}, + {"eqnCoverageForTimesOperator2", "dimensionless", "my_component"}, + {"eqnCoverageForDivideOperator", "dimensionless", "my_component"}, + {"eqnCoverageForDivideOperator2", "dimensionless", "my_component"}, + {"eqnCoverageForAndOperator", "dimensionless", "my_component"}, + {"eqnCoverageForOrOperator", "dimensionless", "my_component"}, + {"eqnCoverageForXorOperator", "dimensionless", "my_component"}, + {"eqnCoverageForPowerOperator", "dimensionless", "my_component"}, + {"eqnCoverageForRootOperator", "dimensionless", "my_component"}, + {"eqnCoverageForMinusUnary", "dimensionless", "my_component"}, + {"eqnCoverageForMinusUnary2", "dimensionless", "my_component"}, + {"eqnComputedConstant1", "dimensionless", "my_component"}, + {"eqnComputedConstant2", "dimensionless", "my_component"} +}; -double min(double x, double y) -{ - return (x < y)?x:y; -} +const VariableInfo ALGEBRAIC_INFO[] = { + {"eqnOr", "dimensionless", "my_component"}, + {"eqnOrMultiple", "dimensionless", "my_component"}, + {"eqnXorCoverageParentheses", "dimensionless", "my_component"}, + {"eqnNlaVariable1", "dimensionless", "my_component"}, + {"eqnNlaVariable2", "dimensionless", "my_component"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"eqnPlus", "dimensionless", "my_component"} +}; -double max(double x, double y) +double xor(double x, double y) { - return (x > y)?x:y; + return (x != 0.0) ^ (y != 0.0); } double sec(double x) @@ -291,23 +304,17 @@ double acot(double x) double asech(double x) { - double oneOverX = 1.0/x; - - return log(oneOverX+sqrt(oneOverX*oneOverX-1.0)); + return acosh(1.0/x); } double acsch(double x) { - double oneOverX = 1.0/x; - - return log(oneOverX+sqrt(oneOverX*oneOverX+1.0)); + return asinh(1.0/x); } double acoth(double x) { - double oneOverX = 1.0/x; - - return 0.5*log((1.0+oneOverX)/(1.0-oneOverX)); + return atanh(1.0/x); } double * createStatesArray() @@ -321,11 +328,44 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { res[i] = NAN; } @@ -341,7 +381,10 @@ typedef struct { double voi; double *states; double *rates; - double *variables; + double *constants; + double *computedConstants; + double *algebraic; + double *externals; } RootFindingInfo; extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), @@ -352,253 +395,267 @@ void objectiveFunction0(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; - variables[205] = u[0]; - variables[206] = u[1]; + algebraic[3] = u[0]; + algebraic[4] = u[1]; - f[0] = variables[205]+variables[206]+states[0]-0.0; - f[1] = variables[205]-variables[206]-(variables[207]+variables[208]); + f[0] = algebraic[3]+algebraic[4]+states[0]-0.0; + f[1] = algebraic[3]-algebraic[4]-(computedConstants[205]+computedConstants[206]); } -void findRoot0(double voi, double *states, double *rates, double *variables) +void findRoot0(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[2]; - u[0] = variables[205]; - u[1] = variables[206]; + u[0] = algebraic[3]; + u[1] = algebraic[4]; nlaSolve(objectiveFunction0, u, 2, &rfi); - variables[205] = u[0]; - variables[206] = u[1]; + algebraic[3] = u[0]; + algebraic[4] = u[1]; } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[1] = 1.0; - variables[2] = 2.0; - variables[6] = 3.0; - variables[18] = 4.0; - variables[179] = 5.0; - variables[180] = 6.0; - variables[182] = 7.0; - variables[205] = 1.0; - variables[206] = 2.0; - variables[184] = 123.0; - variables[185] = 123.456789; - variables[186] = 123.0e99; - variables[187] = 123.456789e99; - variables[189] = 1.0; - variables[190] = 0.0; - variables[191] = 2.71828182845905; - variables[192] = 3.14159265358979; - variables[193] = INFINITY; - variables[194] = NAN; - variables[207] = 1.0; - variables[208] = 3.0; states[0] = 0.0; + constants[0] = 1.0; + constants[1] = 2.0; + constants[2] = 3.0; + constants[3] = 4.0; + constants[4] = 5.0; + constants[5] = 6.0; + constants[6] = 7.0; + computedConstants[169] = NAN; + computedConstants[179] = 123.0; + computedConstants[180] = 123.456789; + computedConstants[181] = 123.0e99; + computedConstants[182] = 123.456789e99; + computedConstants[184] = 1.0; + computedConstants[185] = 0.0; + computedConstants[186] = 2.71828182845905; + computedConstants[187] = 3.14159265358979; + computedConstants[188] = INFINITY; + computedConstants[189] = NAN; + computedConstants[205] = 1.0; + computedConstants[206] = 3.0; + algebraic[3] = 1.0; + algebraic[4] = 2.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[0] = variables[1] == variables[2]; - variables[3] = variables[1]/(variables[2] == variables[2]); - variables[4] = variables[1] != variables[2]; - variables[5] = variables[1]/(variables[2] != variables[6]); - variables[7] = variables[1] < variables[2]; - variables[8] = variables[1]/(variables[2] < variables[6]); - variables[9] = variables[1] <= variables[2]; - variables[10] = variables[1]/(variables[2] <= variables[6]); - variables[11] = variables[1] > variables[2]; - variables[12] = variables[1]/(variables[2] > variables[6]); - variables[13] = variables[1] >= variables[2]; - variables[14] = variables[1]/(variables[2] >= variables[6]); - variables[15] = variables[1] && variables[2]; - variables[16] = variables[1] && variables[2] && variables[6]; - variables[17] = (variables[1] < variables[2]) && (variables[6] > variables[18]); - variables[19] = (variables[1]+variables[2]) && (variables[6] > variables[18]); - variables[20] = variables[1] && (variables[2] > variables[6]); - variables[21] = (variables[1]-variables[2]) && (variables[6] > variables[18]); - variables[22] = -variables[1] && (variables[2] > variables[6]); - variables[23] = pow(variables[1], variables[2]) && (variables[6] > variables[18]); - variables[24] = pow(variables[1], 1.0/variables[2]) && (variables[6] > variables[18]); - variables[25] = (variables[1] < variables[2]) && (variables[6]+variables[18]); - variables[26] = (variables[1] < variables[2]) && variables[6]; - variables[27] = (variables[1] < variables[2]) && (variables[6]-variables[18]); - variables[28] = (variables[1] < variables[2]) && -variables[6]; - variables[29] = (variables[1] < variables[2]) && pow(variables[6], variables[18]); - variables[30] = (variables[1] < variables[2]) && pow(variables[6], 1.0/variables[18]); - variables[31] = variables[1]/(variables[2] && variables[6]); - variables[32] = variables[1] || variables[2]; - variables[33] = variables[1] || variables[2] || variables[6]; - variables[34] = (variables[1] < variables[2]) || (variables[6] > variables[18]); - variables[35] = (variables[1]+variables[2]) || (variables[6] > variables[18]); - variables[36] = variables[1] || (variables[2] > variables[6]); - variables[37] = (variables[1]-variables[2]) || (variables[6] > variables[18]); - variables[38] = -variables[1] || (variables[2] > variables[6]); - variables[39] = pow(variables[1], variables[2]) || (variables[6] > variables[18]); - variables[40] = pow(variables[1], 1.0/variables[2]) || (variables[6] > variables[18]); - variables[41] = (variables[1] < variables[2]) || (variables[6]+variables[18]); - variables[42] = (variables[1] < variables[2]) || variables[6]; - variables[43] = (variables[1] < variables[2]) || (variables[6]-variables[18]); - variables[44] = (variables[1] < variables[2]) || -variables[6]; - variables[45] = (variables[1] < variables[2]) || pow(variables[6], variables[18]); - variables[46] = (variables[1] < variables[2]) || pow(variables[6], 1.0/variables[18]); - variables[47] = variables[1]/(variables[2] || variables[6]); - variables[48] = xor(variables[1], variables[2]); - variables[49] = xor(variables[1], xor(variables[2], variables[6])); - variables[50] = xor(variables[1] < variables[2], variables[6] > variables[18]); - variables[51] = xor(variables[1]+variables[2], variables[6] > variables[18]); - variables[52] = xor(variables[1], variables[2] > variables[6]); - variables[53] = xor(variables[1]-variables[2], variables[6] > variables[18]); - variables[54] = xor(-variables[1], variables[2] > variables[6]); - variables[55] = xor(pow(variables[1], variables[2]), variables[6] > variables[18]); - variables[56] = xor(pow(variables[1], 1.0/variables[2]), variables[6] > variables[18]); - variables[57] = xor(variables[1] < variables[2], variables[6]+variables[18]); - variables[58] = xor(variables[1] < variables[2], variables[6]); - variables[59] = xor(variables[1] < variables[2], variables[6]-variables[18]); - variables[60] = xor(variables[1] < variables[2], -variables[6]); - variables[61] = xor(variables[1] < variables[2], pow(variables[6], variables[18])); - variables[62] = xor(variables[1] < variables[2], pow(variables[6], 1.0/variables[18])); - variables[63] = variables[1]/xor(variables[2], variables[6]); - variables[64] = !variables[1]; - variables[65] = variables[1]+variables[2]; - variables[66] = variables[1]+variables[2]+variables[6]; - variables[67] = (variables[1] < variables[2])+(variables[6] > variables[18]); - variables[68] = variables[1]; - variables[69] = variables[1]-variables[2]; - variables[70] = (variables[1] < variables[2])-(variables[6] > variables[18]); - variables[71] = (variables[1] < variables[2])-(variables[6]+variables[18]); - variables[72] = (variables[1] < variables[2])-variables[6]; - variables[73] = variables[1]-(-variables[2]); - variables[74] = variables[1]-(-variables[2]*variables[6]); - variables[75] = -variables[1]; - variables[76] = -(variables[1] < variables[2]); - variables[77] = variables[1]*variables[2]; - variables[78] = variables[1]*variables[2]*variables[6]; - variables[79] = (variables[1] < variables[2])*(variables[6] > variables[18]); - variables[80] = (variables[1]+variables[2])*(variables[6] > variables[18]); - variables[81] = variables[1]*(variables[2] > variables[6]); - variables[82] = (variables[1]-variables[2])*(variables[6] > variables[18]); - variables[83] = -variables[1]*(variables[2] > variables[6]); - variables[84] = (variables[1] < variables[2])*(variables[6]+variables[18]); - variables[85] = (variables[1] < variables[2])*variables[6]; - variables[86] = (variables[1] < variables[2])*(variables[6]-variables[18]); - variables[87] = (variables[1] < variables[2])*-variables[6]; - variables[88] = variables[1]/variables[2]; - variables[89] = (variables[1] < variables[2])/(variables[18] > variables[6]); - variables[90] = (variables[1]+variables[2])/(variables[18] > variables[6]); - variables[91] = variables[1]/(variables[6] > variables[2]); - variables[92] = (variables[1]-variables[2])/(variables[18] > variables[6]); - variables[93] = -variables[1]/(variables[6] > variables[2]); - variables[94] = (variables[1] < variables[2])/(variables[6]+variables[18]); - variables[95] = (variables[1] < variables[2])/variables[6]; - variables[96] = (variables[1] < variables[2])/(variables[6]-variables[18]); - variables[97] = (variables[1] < variables[2])/-variables[6]; - variables[98] = (variables[1] < variables[2])/(variables[6]*variables[18]); - variables[99] = (variables[1] < variables[2])/(variables[6]/variables[18]); - variables[100] = sqrt(variables[1]); - variables[101] = pow(variables[1], 2.0); - variables[102] = pow(variables[1], 3.0); - variables[103] = pow(variables[1], variables[2]); - variables[104] = pow(variables[1] <= variables[2], variables[6] >= variables[18]); - variables[105] = pow(variables[1]+variables[2], variables[6] >= variables[18]); - variables[106] = pow(variables[1], variables[2] >= variables[6]); - variables[107] = pow(variables[1]-variables[2], variables[6] >= variables[18]); - variables[108] = pow(-variables[1], variables[2] >= variables[6]); - variables[109] = pow(variables[1]*variables[2], variables[6] >= variables[18]); - variables[110] = pow(variables[1]/variables[2], variables[6] >= variables[18]); - variables[111] = pow(variables[1] <= variables[2], variables[6]+variables[18]); - variables[112] = pow(variables[1] <= variables[2], variables[6]); - variables[113] = pow(variables[1] <= variables[2], variables[6]-variables[18]); - variables[114] = pow(variables[1] <= variables[2], -variables[6]); - variables[115] = pow(variables[1] <= variables[2], variables[6]*variables[18]); - variables[116] = pow(variables[1] <= variables[2], variables[6]/variables[18]); - variables[117] = pow(variables[1] <= variables[2], pow(variables[6], variables[18])); - variables[118] = pow(variables[1] <= variables[2], pow(variables[6], 1.0/variables[18])); - variables[119] = sqrt(variables[1]); - variables[120] = sqrt(variables[1]); - variables[121] = pow(variables[1], 1.0/3.0); - variables[122] = pow(variables[1], 1.0/variables[2]); - variables[123] = pow(variables[1] < variables[2], 1.0/(variables[18] > variables[6])); - variables[124] = pow(variables[1]+variables[2], 1.0/(variables[18] > variables[6])); - variables[125] = pow(variables[1], 1.0/(variables[6] > variables[2])); - variables[126] = pow(variables[1]-variables[2], 1.0/(variables[18] > variables[6])); - variables[127] = pow(-variables[1], 1.0/(variables[6] > variables[2])); - variables[128] = pow(variables[1]*variables[2], 1.0/(variables[18] > variables[6])); - variables[129] = pow(variables[1]/variables[2], 1.0/(variables[18] > variables[6])); - variables[130] = pow(variables[1] < variables[2], 1.0/(variables[6]+variables[18])); - variables[131] = pow(variables[1] < variables[2], 1.0/variables[6]); - variables[132] = pow(variables[1] < variables[2], 1.0/(variables[6]-variables[18])); - variables[133] = pow(variables[1] < variables[2], 1.0/-variables[6]); - variables[134] = pow(variables[1] < variables[2], 1.0/(variables[6]*variables[18])); - variables[135] = pow(variables[1] < variables[2], 1.0/(variables[6]/variables[18])); - variables[136] = pow(variables[1] < variables[2], 1.0/pow(variables[6], variables[18])); - variables[137] = pow(variables[1] < variables[2], 1.0/pow(variables[6], 1.0/variables[18])); - variables[138] = fabs(variables[1]); - variables[139] = exp(variables[1]); - variables[140] = log(variables[1]); - variables[141] = log10(variables[1]); - variables[142] = log(variables[1])/log(2.0); - variables[143] = log10(variables[1]); - variables[144] = log(variables[1])/log(variables[2]); - variables[145] = ceil(variables[1]); - variables[146] = floor(variables[1]); - variables[147] = min(variables[1], variables[2]); - variables[148] = min(variables[1], min(variables[2], variables[6])); - variables[149] = max(variables[1], variables[2]); - variables[150] = max(variables[1], max(variables[2], variables[6])); - variables[151] = fmod(variables[1], variables[2]); - variables[152] = sin(variables[1]); - variables[153] = cos(variables[1]); - variables[154] = tan(variables[1]); - variables[155] = sec(variables[1]); - variables[156] = csc(variables[1]); - variables[157] = cot(variables[1]); - variables[158] = sinh(variables[1]); - variables[159] = cosh(variables[1]); - variables[160] = tanh(variables[1]); - variables[161] = sech(variables[1]); - variables[162] = csch(variables[1]); - variables[163] = coth(variables[1]); - variables[164] = asin(variables[1]); - variables[165] = acos(variables[1]); - variables[166] = atan(variables[1]); - variables[167] = asec(variables[1]); - variables[168] = acsc(variables[1]); - variables[169] = acot(variables[1]); - variables[170] = asinh(variables[1]); - variables[171] = acosh(variables[1]); - variables[172] = atanh(variables[1]/2.0); - variables[173] = asech(variables[1]); - variables[174] = acsch(variables[1]); - variables[175] = acoth(2.0*variables[1]); - variables[176] = (variables[1] > variables[2])?variables[1]:NAN; - variables[177] = (variables[1] > variables[2])?variables[1]:variables[6]; - variables[178] = (variables[1] > variables[2])?variables[1]:(variables[6] > variables[18])?variables[6]:(variables[179] > variables[180])?variables[179]:NAN; - variables[181] = (variables[1] > variables[2])?variables[1]:(variables[6] > variables[18])?variables[6]:(variables[179] > variables[180])?variables[179]:variables[182]; - variables[183] = 123.0+((variables[1] > variables[2])?variables[1]:NAN); - variables[188] = variables[1]; - variables[195] = (variables[1] && variables[2])+((variables[6] > variables[18])?variables[2]:NAN)+variables[179]+(variables[180] && variables[182]); - variables[196] = (variables[1] && variables[2])-(((variables[6] > variables[18])?variables[2]:NAN)-(variables[179]-((variables[6] > variables[18])?variables[2]:NAN)))-(variables[180] && variables[182]); - variables[197] = (variables[1] && variables[2])*((variables[6] > variables[18])?variables[2]:NAN)*variables[179]*((variables[6] > variables[18])?variables[2]:NAN)*(variables[180] && variables[182]); - variables[198] = (variables[1] && variables[2])/(((variables[6] > variables[18])?variables[2]:NAN)/(variables[179]/((variables[6] > variables[18])?variables[2]:NAN))); - variables[199] = (variables[1] || variables[2]) && xor(variables[1], variables[2]) && ((variables[6] > variables[18])?variables[2]:NAN) && variables[179] && ((variables[6] > variables[18])?variables[2]:NAN) && xor(variables[1], variables[2]) && (variables[1] || variables[2]); - variables[200] = (variables[1] && variables[2]) || xor(variables[1], variables[2]) || ((variables[6] > variables[18])?variables[2]:NAN) || variables[179] || ((variables[6] > variables[18])?variables[2]:NAN) || xor(variables[1], variables[2]) || (variables[1] && variables[2]); - variables[201] = xor(variables[1] && variables[2], xor(variables[1] || variables[2], xor((variables[6] > variables[18])?variables[2]:NAN, xor(xor(xor(variables[179], (variables[6] > variables[18])?variables[2]:NAN), variables[1] || variables[2]), variables[1] && variables[2])))); - variables[202] = pow(variables[1] && variables[2], pow((variables[6] > variables[18])?variables[2]:NAN, pow(pow(variables[179], (variables[6] > variables[18])?variables[2]:NAN), variables[1] && variables[2]))); - variables[203] = pow(pow(pow(variables[1] && variables[2], 1.0/pow((variables[6] > variables[18])?variables[2]:NAN, 1.0/variables[179])), 1.0/((variables[6] > variables[18])?variables[2]:NAN)), 1.0/(variables[1] && variables[2])); - variables[204] = -(variables[1] && variables[2])+-((variables[6] > variables[18])?variables[2]:NAN); + computedConstants[0] = constants[0] == constants[1]; + computedConstants[1] = constants[0]/(constants[1] == constants[1]); + computedConstants[2] = constants[0] != constants[1]; + computedConstants[3] = constants[0]/(constants[1] != constants[2]); + computedConstants[4] = constants[0] < constants[1]; + computedConstants[5] = constants[0]/(constants[1] < constants[2]); + computedConstants[6] = constants[0] <= constants[1]; + computedConstants[7] = constants[0]/(constants[1] <= constants[2]); + computedConstants[8] = constants[0] > constants[1]; + computedConstants[9] = constants[0]/(constants[2] > constants[1]); + computedConstants[10] = constants[0] >= constants[1]; + computedConstants[11] = constants[0]/(constants[2] >= constants[1]); + computedConstants[12] = constants[0] && constants[1]; + computedConstants[13] = constants[0] && constants[1] && constants[2]; + computedConstants[14] = (constants[0] < constants[1]) && (constants[2] > constants[3]); + computedConstants[15] = (constants[0]+constants[1]) && (constants[2] > constants[3]); + computedConstants[16] = constants[0] && (constants[1] > constants[2]); + computedConstants[17] = (constants[0]-constants[1]) && (constants[2] > constants[3]); + computedConstants[18] = -constants[0] && (constants[1] > constants[2]); + computedConstants[19] = pow(constants[0], constants[1]) && (constants[2] > constants[3]); + computedConstants[20] = pow(constants[0], 1.0/constants[1]) && (constants[2] > constants[3]); + computedConstants[21] = (constants[0] < constants[1]) && (constants[2]+constants[3]); + computedConstants[22] = (constants[0] < constants[1]) && constants[2]; + computedConstants[23] = (constants[0] < constants[1]) && (constants[2]-constants[3]); + computedConstants[24] = (constants[0] < constants[1]) && -constants[2]; + computedConstants[25] = (constants[0] < constants[1]) && pow(constants[2], constants[3]); + computedConstants[26] = (constants[0] < constants[1]) && pow(constants[2], 1.0/constants[3]); + computedConstants[27] = constants[0]/(constants[1] && constants[2]); + computedConstants[28] = (constants[0] < constants[1]) || (constants[2] > constants[3]); + computedConstants[29] = (constants[0]+constants[1]) || (constants[2] > constants[3]); + computedConstants[30] = constants[0] || (constants[1] > constants[2]); + computedConstants[31] = (constants[0]-constants[1]) || (constants[2] > constants[3]); + computedConstants[32] = -constants[0] || (constants[1] > constants[2]); + computedConstants[33] = pow(constants[0], constants[1]) || (constants[2] > constants[3]); + computedConstants[34] = pow(constants[0], 1.0/constants[1]) || (constants[2] > constants[3]); + computedConstants[35] = (constants[0] < constants[1]) || (constants[2]+constants[3]); + computedConstants[36] = (constants[0] < constants[1]) || constants[2]; + computedConstants[37] = (constants[0] < constants[1]) || (constants[2]-constants[3]); + computedConstants[38] = (constants[0] < constants[1]) || -constants[2]; + computedConstants[39] = (constants[0] < constants[1]) || pow(constants[2], constants[3]); + computedConstants[40] = (constants[0] < constants[1]) || pow(constants[2], 1.0/constants[3]); + computedConstants[41] = constants[0]/(constants[1] || constants[2]); + computedConstants[42] = xor(constants[0], constants[1]); + computedConstants[43] = xor(constants[0], xor(constants[1], constants[2])); + computedConstants[44] = xor(constants[0] < constants[1], constants[2] > constants[3]); + computedConstants[45] = xor(constants[0]+constants[1], constants[2] > constants[3]); + computedConstants[46] = xor(constants[0], constants[1] > constants[2]); + computedConstants[47] = xor(constants[0]-constants[1], constants[2] > constants[3]); + computedConstants[48] = xor(-constants[0], constants[1] > constants[2]); + computedConstants[49] = xor(pow(constants[0], constants[1]), constants[2] > constants[3]); + computedConstants[50] = xor(pow(constants[0], 1.0/constants[1]), constants[2] > constants[3]); + computedConstants[51] = xor(constants[0] < constants[1], constants[2]+constants[3]); + computedConstants[52] = xor(constants[0] < constants[1], constants[2]); + computedConstants[53] = xor(constants[0] < constants[1], constants[2]-constants[3]); + computedConstants[54] = xor(constants[0] < constants[1], -constants[2]); + computedConstants[55] = xor(constants[0] < constants[1], pow(constants[2], constants[3])); + computedConstants[56] = xor(constants[0] < constants[1], pow(constants[2], 1.0/constants[3])); + computedConstants[57] = !constants[0]; + computedConstants[58] = constants[0]+constants[1]+constants[2]; + computedConstants[59] = (constants[0] < constants[1])+(constants[2] > constants[3]); + computedConstants[60] = constants[0]; + computedConstants[61] = constants[0]-constants[1]; + computedConstants[62] = (constants[0] < constants[1])-(constants[2] > constants[3]); + computedConstants[63] = (constants[0] < constants[1])-(constants[2]+constants[3]); + computedConstants[64] = (constants[0] < constants[1])-constants[2]; + computedConstants[65] = constants[0]-(-constants[1]); + computedConstants[66] = constants[0]-(-constants[1]*constants[2]); + computedConstants[67] = -constants[0]; + computedConstants[68] = -(constants[0] < constants[1]); + computedConstants[69] = constants[0]*constants[1]; + computedConstants[70] = constants[0]*constants[1]*constants[2]; + computedConstants[71] = (constants[0] < constants[1])*(constants[2] > constants[3]); + computedConstants[72] = (constants[0]+constants[1])*(constants[2] > constants[3]); + computedConstants[73] = constants[0]*(constants[1] > constants[2]); + computedConstants[74] = (constants[0]-constants[1])*(constants[2] > constants[3]); + computedConstants[75] = -constants[0]*(constants[1] > constants[2]); + computedConstants[76] = (constants[0] < constants[1])*(constants[2]+constants[3]); + computedConstants[77] = (constants[0] < constants[1])*constants[2]; + computedConstants[78] = (constants[0] < constants[1])*(constants[2]-constants[3]); + computedConstants[79] = (constants[0] < constants[1])*-constants[2]; + computedConstants[80] = constants[0]/constants[1]; + computedConstants[81] = (constants[0] < constants[1])/(constants[3] > constants[2]); + computedConstants[82] = (constants[0]+constants[1])/(constants[3] > constants[2]); + computedConstants[83] = constants[0]/(constants[2] > constants[1]); + computedConstants[84] = (constants[0]-constants[1])/(constants[3] > constants[2]); + computedConstants[85] = -constants[0]/(constants[2] > constants[1]); + computedConstants[86] = (constants[0] < constants[1])/(constants[2]+constants[3]); + computedConstants[87] = (constants[0] < constants[1])/constants[2]; + computedConstants[88] = (constants[0] < constants[1])/(constants[2]-constants[3]); + computedConstants[89] = (constants[0] < constants[1])/-constants[2]; + computedConstants[90] = (constants[0] < constants[1])/(constants[2]*constants[3]); + computedConstants[91] = (constants[0] < constants[1])/(constants[2]/constants[3]); + computedConstants[92] = sqrt(constants[0]); + computedConstants[93] = pow(constants[0], 2.0); + computedConstants[94] = pow(constants[0], 3.0); + computedConstants[95] = pow(constants[0], constants[1]); + computedConstants[96] = pow(constants[0] <= constants[1], constants[2] >= constants[3]); + computedConstants[97] = pow(constants[0]+constants[1], constants[2] >= constants[3]); + computedConstants[98] = pow(constants[0], constants[1] >= constants[2]); + computedConstants[99] = pow(constants[0]-constants[1], constants[2] >= constants[3]); + computedConstants[100] = pow(-constants[0], constants[1] >= constants[2]); + computedConstants[101] = pow(constants[0]*constants[1], constants[2] >= constants[3]); + computedConstants[102] = pow(constants[0]/constants[1], constants[2] >= constants[3]); + computedConstants[103] = pow(constants[0] <= constants[1], constants[2]+constants[3]); + computedConstants[104] = pow(constants[0] <= constants[1], constants[2]); + computedConstants[105] = pow(constants[0] <= constants[1], constants[2]-constants[3]); + computedConstants[106] = pow(constants[0] <= constants[1], -constants[2]); + computedConstants[107] = pow(constants[0] <= constants[1], constants[2]*constants[3]); + computedConstants[108] = pow(constants[0] <= constants[1], constants[2]/constants[3]); + computedConstants[109] = pow(constants[0] <= constants[1], pow(constants[2], constants[3])); + computedConstants[110] = pow(constants[0] <= constants[1], pow(constants[2], 1.0/constants[3])); + computedConstants[111] = sqrt(constants[0]); + computedConstants[112] = sqrt(constants[0]); + computedConstants[113] = pow(constants[0], 1.0/0.5); + computedConstants[114] = pow(constants[0], 1.0/3.0); + computedConstants[115] = pow(constants[0], 1.0/constants[1]); + computedConstants[116] = pow(constants[0] < constants[1], 1.0/(constants[3] > constants[2])); + computedConstants[117] = pow(constants[0]+constants[1], 1.0/(constants[3] > constants[2])); + computedConstants[118] = pow(constants[0], 1.0/(constants[2] > constants[1])); + computedConstants[119] = pow(constants[0]-constants[1], 1.0/(constants[3] > constants[2])); + computedConstants[120] = pow(-constants[0], 1.0/(constants[2] > constants[1])); + computedConstants[121] = pow(constants[0]*constants[1], 1.0/(constants[3] > constants[2])); + computedConstants[122] = pow(constants[0]/constants[1], 1.0/(constants[3] > constants[2])); + computedConstants[123] = pow(constants[0] < constants[1], 1.0/(constants[2]+constants[3])); + computedConstants[124] = pow(constants[0] < constants[1], 1.0/constants[2]); + computedConstants[125] = pow(constants[0] < constants[1], 1.0/(constants[2]-constants[3])); + computedConstants[126] = pow(constants[0] < constants[1], 1.0/-constants[2]); + computedConstants[127] = pow(constants[0] < constants[1], 1.0/(constants[2]*constants[3])); + computedConstants[128] = pow(constants[0] < constants[1], 1.0/(constants[2]/constants[3])); + computedConstants[129] = pow(constants[0] < constants[1], 1.0/pow(constants[2], constants[3])); + computedConstants[130] = pow(constants[0] < constants[1], 1.0/pow(constants[2], 1.0/constants[3])); + computedConstants[131] = fabs(constants[0]); + computedConstants[132] = exp(constants[0]); + computedConstants[133] = log(constants[0]); + computedConstants[134] = log10(constants[0]); + computedConstants[135] = log(constants[0])/log(2.0); + computedConstants[136] = log10(constants[0]); + computedConstants[137] = log(constants[0])/log(constants[1]); + computedConstants[138] = ceil(constants[0]); + computedConstants[139] = floor(constants[0]); + computedConstants[140] = fmin(constants[0], constants[1]); + computedConstants[141] = fmin(constants[0], fmin(constants[1], constants[2])); + computedConstants[142] = fmax(constants[0], constants[1]); + computedConstants[143] = fmax(constants[0], fmax(constants[1], constants[2])); + computedConstants[144] = fmod(constants[0], constants[1]); + computedConstants[145] = sin(constants[0]); + computedConstants[146] = cos(constants[0]); + computedConstants[147] = tan(constants[0]); + computedConstants[148] = sec(constants[0]); + computedConstants[149] = csc(constants[0]); + computedConstants[150] = cot(constants[0]); + computedConstants[151] = sinh(constants[0]); + computedConstants[152] = cosh(constants[0]); + computedConstants[153] = tanh(constants[0]); + computedConstants[154] = sech(constants[0]); + computedConstants[155] = csch(constants[0]); + computedConstants[156] = coth(constants[0]); + computedConstants[157] = asin(constants[0]); + computedConstants[158] = acos(constants[0]); + computedConstants[159] = atan(constants[0]); + computedConstants[160] = asec(constants[0]); + computedConstants[161] = acsc(constants[0]); + computedConstants[162] = acot(constants[0]); + computedConstants[163] = asinh(constants[0]); + computedConstants[164] = acosh(constants[0]); + computedConstants[165] = atanh(constants[0]/2.0); + computedConstants[166] = asech(constants[0]); + computedConstants[167] = acsch(constants[0]); + computedConstants[168] = acoth(2.0*constants[0]); + computedConstants[170] = (constants[0] > constants[1])?constants[0]:NAN; + computedConstants[171] = (constants[0] < constants[1])?constants[0]:NAN; + computedConstants[172] = constants[0]; + computedConstants[173] = (constants[0] > constants[1])?constants[0]:constants[2]; + computedConstants[174] = (constants[0] > constants[1])?constants[0]:(constants[2] > constants[3])?constants[2]:(constants[4] > constants[5])?constants[4]:NAN; + computedConstants[175] = (constants[0] < constants[1])?constants[0]:(constants[2] > constants[3])?constants[2]:(constants[4] > constants[5])?constants[4]:NAN; + computedConstants[176] = (constants[0] > constants[1])?constants[0]:(constants[2] > constants[3])?constants[2]:(constants[4] > constants[5])?constants[4]:constants[6]; + computedConstants[177] = 123.0+((constants[0] > constants[1])?constants[0]:NAN); + computedConstants[178] = 123.0+((constants[0] < constants[1])?constants[0]:NAN); + computedConstants[183] = constants[0]; + computedConstants[190] = (constants[0] && constants[1])+((constants[2] > constants[3])?constants[1]:NAN)+constants[4]+(constants[5] && constants[6]); + computedConstants[191] = (constants[0] && constants[1])+((constants[2] < constants[3])?constants[1]:NAN)+constants[4]+(constants[5] && constants[6]); + computedConstants[192] = (constants[0] && constants[1])-(((constants[2] > constants[3])?constants[1]:NAN)-(constants[4]-((constants[2] > constants[3])?constants[1]:NAN)))-(constants[5] && constants[6]); + computedConstants[193] = (constants[0] && constants[1])-(((constants[2] < constants[3])?constants[1]:NAN)-(constants[4]-((constants[2] < constants[3])?constants[1]:NAN)))-(constants[5] && constants[6]); + computedConstants[194] = (constants[0] && constants[1])*((constants[2] > constants[3])?constants[1]:NAN)*constants[4]*((constants[2] > constants[3])?constants[1]:NAN)*(constants[5] && constants[6]); + computedConstants[195] = (constants[0] && constants[1])*((constants[2] < constants[3])?constants[1]:NAN)*constants[4]*((constants[2] < constants[3])?constants[1]:NAN)*(constants[5] && constants[6]); + computedConstants[196] = (constants[0] && constants[1])/(((constants[2] > constants[3])?constants[1]:NAN)/(constants[4]/((constants[2] > constants[3])?constants[1]:NAN))); + computedConstants[197] = (constants[0] && constants[1])/(((constants[2] < constants[3])?constants[1]:NAN)/(constants[4]/((constants[2] < constants[3])?constants[1]:NAN))); + computedConstants[198] = (constants[0] || constants[1]) && xor(constants[0], constants[1]) && ((constants[2] > constants[3])?constants[1]:NAN) && constants[4] && ((constants[2] > constants[3])?constants[1]:NAN) && xor(constants[0], constants[1]) && (constants[0] || constants[1]); + computedConstants[199] = (constants[0] && constants[1]) || xor(constants[0], constants[1]) || ((constants[2] > constants[3])?constants[1]:NAN) || constants[4] || ((constants[2] > constants[3])?constants[1]:NAN) || xor(constants[0], constants[1]) || (constants[0] && constants[1]); + computedConstants[200] = xor(constants[0] && constants[1], xor(constants[0] || constants[1], xor((constants[2] > constants[3])?constants[1]:NAN, xor(xor(xor(constants[4], (constants[2] > constants[3])?constants[1]:NAN), constants[0] || constants[1]), constants[0] && constants[1])))); + computedConstants[201] = pow(constants[0] && constants[1], pow((constants[2] > constants[3])?constants[1]:NAN, pow(pow(constants[4], (constants[2] > constants[3])?constants[1]:NAN), constants[0] && constants[1]))); + computedConstants[202] = pow(pow(pow(constants[0] && constants[1], 1.0/pow((constants[2] > constants[3])?constants[1]:NAN, 1.0/constants[4])), 1.0/((constants[2] > constants[3])?constants[1]:NAN)), 1.0/(constants[0] && constants[1])); + computedConstants[203] = -(constants[0] && constants[1])+-((constants[2] > constants[3])?constants[1]:NAN); + computedConstants[204] = -(constants[0] && constants[1])+-((constants[2] < constants[3])?constants[1]:NAN); } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { rates[0] = 1.0; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - findRoot0(voi, states, rates, variables); + algebraic[0] = states[0] || states[0]; + algebraic[1] = states[0] || states[0] || constants[0]; + algebraic[2] = constants[0]/xor(constants[1], states[0]); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); } diff --git a/tests/resources/coverage/generator/model.cellml b/tests/resources/coverage/generator/model.cellml index 6a2574eed1..9ea2a4e296 100644 --- a/tests/resources/coverage/generator/model.cellml +++ b/tests/resources/coverage/generator/model.cellml @@ -129,6 +129,7 @@ + @@ -184,11 +185,16 @@ + + + + + @@ -201,15 +207,20 @@ + + + + + @@ -349,8 +360,8 @@ m - n o + n @@ -373,8 +384,8 @@ m - n o + n @@ -640,8 +651,8 @@ eqnOr - m - n + x + x @@ -649,9 +660,9 @@ eqnOrMultiple + x + x m - n - o @@ -1139,7 +1150,7 @@ n - o + x @@ -1984,6 +1995,17 @@ m + + + eqnRootSqr + + + + 0.5 + + m + + eqnRootCube @@ -2685,6 +2707,11 @@ + + + eqnPiecewise + + eqnPiecewisePiece @@ -2699,6 +2726,29 @@ + + + eqnPiecewisePiece2 + + + m + + + m + n + + + + + + + eqnPiecewiseOtherwise + + + m + + + eqnPiecewisePieceOtherwise @@ -2746,6 +2796,36 @@ + + + eqnPiecewisePiecePiecePiece2 + + + m + + + m + n + + + + o + + + o + p + + + + q + + + q + r + + + + eqnPiecewisePiecePiecePieceOtherwise @@ -2799,6 +2879,24 @@ + + + eqnWithPiecewise2 + + + 123 + + + m + + + m + n + + + + + @@ -2920,6 +3018,40 @@ + + + eqnCoverageForPlusOperator2 + + + + + + + m + n + + + + + + n + + + o + p + + + + q + + + + + r + s + + + eqnCoverageForMinusOperator @@ -2967,6 +3099,53 @@ + + + eqnCoverageForMinusOperator2 + + + + + + + m + n + + + + + + n + + + o + p + + + + + + q + + + n + + + o + p + + + + + + + + + r + s + + + eqnCoverageForTimesOperator @@ -3014,6 +3193,53 @@ + + + eqnCoverageForTimesOperator2 + + + + + + + m + n + + + + + + n + + + o + p + + + + + + q + + + n + + + o + p + + + + + + + + + r + s + + + eqnCoverageForDivideOperator @@ -3053,6 +3279,45 @@ + + + eqnCoverageForDivideOperator2 + + + + + m + n + + + + + + n + + + o + p + + + + + + q + + + n + + + o + p + + + + + + + eqnCoverageForAndOperator @@ -3372,6 +3637,34 @@ + + + eqnCoverageForMinusUnary2 + + + + + + + m + n + + + + + + + n + + + o + p + + + + + + diff --git a/tests/resources/coverage/generator/model.h b/tests/resources/coverage/generator/model.h index 9d8e94184c..b3e210d0ef 100644 --- a/tests/resources/coverage/generator/model.h +++ b/tests/resources/coverage/generator/model.h @@ -8,32 +8,35 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; typedef struct { char name[38]; char units[14]; char component[13]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/coverage/generator/model.implementation.out b/tests/resources/coverage/generator/model.implementation.out index 6c85028643..3ba38209d5 100644 --- a/tests/resources/coverage/generator/model.implementation.out +++ b/tests/resources/coverage/generator/model.implementation.out @@ -5,16 +5,6 @@ double xor(double x, double y) return (x != 0.0) ^ (y != 0.0); } -double min(double x, double y) -{ - return (x < y)?x:y; -} - -double max(double x, double y) -{ - return (x > y)?x:y; -} - double sec(double x) { return 1.0/cos(x); @@ -62,23 +52,17 @@ double acot(double x) double asech(double x) { - double oneOverX = 1.0/x; - - return log(oneOverX+sqrt(oneOverX*oneOverX-1.0)); + return acosh(1.0/x); } double acsch(double x) { - double oneOverX = 1.0/x; - - return log(oneOverX+sqrt(oneOverX*oneOverX+1.0)); + return asinh(1.0/x); } double acoth(double x) { - double oneOverX = 1.0/x; - - return 0.5*log((1.0+oneOverX)/(1.0-oneOverX)); + return atanh(1.0/x); } double * createStatesArray() @@ -92,11 +76,44 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { res[i] = NAN; } @@ -112,7 +129,10 @@ typedef struct { double voi; double *states; double *rates; - double *variables; + double *constants; + double *computedConstants; + double *algebraic; + double *externals; } RootFindingInfo; extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), @@ -123,253 +143,267 @@ void objectiveFunction0(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; - variables[205] = u[0]; - variables[206] = u[1]; + algebraic[3] = u[0]; + algebraic[4] = u[1]; - f[0] = variables[205]+variables[206]+states[0]-0.0; - f[1] = variables[205]-variables[206]-(variables[207]+variables[208]); + f[0] = algebraic[3]+algebraic[4]+states[0]-0.0; + f[1] = algebraic[3]-algebraic[4]-(computedConstants[205]+computedConstants[206]); } -void findRoot0(double voi, double *states, double *rates, double *variables) +void findRoot0(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[2]; - u[0] = variables[205]; - u[1] = variables[206]; + u[0] = algebraic[3]; + u[1] = algebraic[4]; nlaSolve(objectiveFunction0, u, 2, &rfi); - variables[205] = u[0]; - variables[206] = u[1]; + algebraic[3] = u[0]; + algebraic[4] = u[1]; } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[1] = 1.0; - variables[2] = 2.0; - variables[6] = 3.0; - variables[18] = 4.0; - variables[179] = 5.0; - variables[180] = 6.0; - variables[182] = 7.0; - variables[205] = 1.0; - variables[206] = 2.0; - variables[184] = 123.0; - variables[185] = 123.456789; - variables[186] = 123.0e99; - variables[187] = 123.456789e99; - variables[189] = 1.0; - variables[190] = 0.0; - variables[191] = 2.71828182845905; - variables[192] = 3.14159265358979; - variables[193] = INFINITY; - variables[194] = NAN; - variables[207] = 1.0; - variables[208] = 3.0; states[0] = 0.0; + constants[0] = 1.0; + constants[1] = 2.0; + constants[2] = 3.0; + constants[3] = 4.0; + constants[4] = 5.0; + constants[5] = 6.0; + constants[6] = 7.0; + computedConstants[169] = NAN; + computedConstants[179] = 123.0; + computedConstants[180] = 123.456789; + computedConstants[181] = 123.0e99; + computedConstants[182] = 123.456789e99; + computedConstants[184] = 1.0; + computedConstants[185] = 0.0; + computedConstants[186] = 2.71828182845905; + computedConstants[187] = 3.14159265358979; + computedConstants[188] = INFINITY; + computedConstants[189] = NAN; + computedConstants[205] = 1.0; + computedConstants[206] = 3.0; + algebraic[3] = 1.0; + algebraic[4] = 2.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[0] = eq(variables[1], variables[2]); - variables[3] = variables[1]/eq(variables[2], variables[2]); - variables[4] = neq(variables[1], variables[2]); - variables[5] = variables[1]/neq(variables[2], variables[6]); - variables[7] = lt(variables[1], variables[2]); - variables[8] = variables[1]/lt(variables[2], variables[6]); - variables[9] = leq(variables[1], variables[2]); - variables[10] = variables[1]/leq(variables[2], variables[6]); - variables[11] = gt(variables[1], variables[2]); - variables[12] = variables[1]/gt(variables[2], variables[6]); - variables[13] = geq(variables[1], variables[2]); - variables[14] = variables[1]/geq(variables[2], variables[6]); - variables[15] = and(variables[1], variables[2]); - variables[16] = and(variables[1], and(variables[2], variables[6])); - variables[17] = and(lt(variables[1], variables[2]), gt(variables[6], variables[18])); - variables[19] = and(variables[1]+variables[2], gt(variables[6], variables[18])); - variables[20] = and(variables[1], gt(variables[2], variables[6])); - variables[21] = and(variables[1]-variables[2], gt(variables[6], variables[18])); - variables[22] = and(-variables[1], gt(variables[2], variables[6])); - variables[23] = and(pow(variables[1], variables[2]), gt(variables[6], variables[18])); - variables[24] = and(pow(variables[1], 1.0/variables[2]), gt(variables[6], variables[18])); - variables[25] = and(lt(variables[1], variables[2]), variables[6]+variables[18]); - variables[26] = and(lt(variables[1], variables[2]), variables[6]); - variables[27] = and(lt(variables[1], variables[2]), variables[6]-variables[18]); - variables[28] = and(lt(variables[1], variables[2]), -variables[6]); - variables[29] = and(lt(variables[1], variables[2]), pow(variables[6], variables[18])); - variables[30] = and(lt(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])); - variables[31] = variables[1]/and(variables[2], variables[6]); - variables[32] = or(variables[1], variables[2]); - variables[33] = or(variables[1], or(variables[2], variables[6])); - variables[34] = or(lt(variables[1], variables[2]), gt(variables[6], variables[18])); - variables[35] = or(variables[1]+variables[2], gt(variables[6], variables[18])); - variables[36] = or(variables[1], gt(variables[2], variables[6])); - variables[37] = or(variables[1]-variables[2], gt(variables[6], variables[18])); - variables[38] = or(-variables[1], gt(variables[2], variables[6])); - variables[39] = or(pow(variables[1], variables[2]), gt(variables[6], variables[18])); - variables[40] = or(pow(variables[1], 1.0/variables[2]), gt(variables[6], variables[18])); - variables[41] = or(lt(variables[1], variables[2]), variables[6]+variables[18]); - variables[42] = or(lt(variables[1], variables[2]), variables[6]); - variables[43] = or(lt(variables[1], variables[2]), variables[6]-variables[18]); - variables[44] = or(lt(variables[1], variables[2]), -variables[6]); - variables[45] = or(lt(variables[1], variables[2]), pow(variables[6], variables[18])); - variables[46] = or(lt(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])); - variables[47] = variables[1]/or(variables[2], variables[6]); - variables[48] = xor(variables[1], variables[2]); - variables[49] = xor(variables[1], xor(variables[2], variables[6])); - variables[50] = xor(lt(variables[1], variables[2]), gt(variables[6], variables[18])); - variables[51] = xor(variables[1]+variables[2], gt(variables[6], variables[18])); - variables[52] = xor(variables[1], gt(variables[2], variables[6])); - variables[53] = xor(variables[1]-variables[2], gt(variables[6], variables[18])); - variables[54] = xor(-variables[1], gt(variables[2], variables[6])); - variables[55] = xor(pow(variables[1], variables[2]), gt(variables[6], variables[18])); - variables[56] = xor(pow(variables[1], 1.0/variables[2]), gt(variables[6], variables[18])); - variables[57] = xor(lt(variables[1], variables[2]), variables[6]+variables[18]); - variables[58] = xor(lt(variables[1], variables[2]), variables[6]); - variables[59] = xor(lt(variables[1], variables[2]), variables[6]-variables[18]); - variables[60] = xor(lt(variables[1], variables[2]), -variables[6]); - variables[61] = xor(lt(variables[1], variables[2]), pow(variables[6], variables[18])); - variables[62] = xor(lt(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])); - variables[63] = variables[1]/xor(variables[2], variables[6]); - variables[64] = not(variables[1]); - variables[65] = variables[1]+variables[2]; - variables[66] = variables[1]+variables[2]+variables[6]; - variables[67] = lt(variables[1], variables[2])+gt(variables[6], variables[18]); - variables[68] = variables[1]; - variables[69] = variables[1]-variables[2]; - variables[70] = lt(variables[1], variables[2])-gt(variables[6], variables[18]); - variables[71] = lt(variables[1], variables[2])-(variables[6]+variables[18]); - variables[72] = lt(variables[1], variables[2])-variables[6]; - variables[73] = variables[1]-(-variables[2]); - variables[74] = variables[1]-(-variables[2]*variables[6]); - variables[75] = -variables[1]; - variables[76] = -lt(variables[1], variables[2]); - variables[77] = variables[1]*variables[2]; - variables[78] = variables[1]*variables[2]*variables[6]; - variables[79] = lt(variables[1], variables[2])*gt(variables[6], variables[18]); - variables[80] = (variables[1]+variables[2])*gt(variables[6], variables[18]); - variables[81] = variables[1]*gt(variables[2], variables[6]); - variables[82] = (variables[1]-variables[2])*gt(variables[6], variables[18]); - variables[83] = -variables[1]*gt(variables[2], variables[6]); - variables[84] = lt(variables[1], variables[2])*(variables[6]+variables[18]); - variables[85] = lt(variables[1], variables[2])*variables[6]; - variables[86] = lt(variables[1], variables[2])*(variables[6]-variables[18]); - variables[87] = lt(variables[1], variables[2])*-variables[6]; - variables[88] = variables[1]/variables[2]; - variables[89] = lt(variables[1], variables[2])/gt(variables[18], variables[6]); - variables[90] = (variables[1]+variables[2])/gt(variables[18], variables[6]); - variables[91] = variables[1]/gt(variables[6], variables[2]); - variables[92] = (variables[1]-variables[2])/gt(variables[18], variables[6]); - variables[93] = -variables[1]/gt(variables[6], variables[2]); - variables[94] = lt(variables[1], variables[2])/(variables[6]+variables[18]); - variables[95] = lt(variables[1], variables[2])/variables[6]; - variables[96] = lt(variables[1], variables[2])/(variables[6]-variables[18]); - variables[97] = lt(variables[1], variables[2])/-variables[6]; - variables[98] = lt(variables[1], variables[2])/(variables[6]*variables[18]); - variables[99] = lt(variables[1], variables[2])/(variables[6]/variables[18]); - variables[100] = sqrt(variables[1]); - variables[101] = pow(variables[1], 2.0); - variables[102] = pow(variables[1], 3.0); - variables[103] = pow(variables[1], variables[2]); - variables[104] = pow(leq(variables[1], variables[2]), geq(variables[6], variables[18])); - variables[105] = pow(variables[1]+variables[2], geq(variables[6], variables[18])); - variables[106] = pow(variables[1], geq(variables[2], variables[6])); - variables[107] = pow(variables[1]-variables[2], geq(variables[6], variables[18])); - variables[108] = pow(-variables[1], geq(variables[2], variables[6])); - variables[109] = pow(variables[1]*variables[2], geq(variables[6], variables[18])); - variables[110] = pow(variables[1]/variables[2], geq(variables[6], variables[18])); - variables[111] = pow(leq(variables[1], variables[2]), variables[6]+variables[18]); - variables[112] = pow(leq(variables[1], variables[2]), variables[6]); - variables[113] = pow(leq(variables[1], variables[2]), variables[6]-variables[18]); - variables[114] = pow(leq(variables[1], variables[2]), -variables[6]); - variables[115] = pow(leq(variables[1], variables[2]), variables[6]*variables[18]); - variables[116] = pow(leq(variables[1], variables[2]), variables[6]/variables[18]); - variables[117] = pow(leq(variables[1], variables[2]), pow(variables[6], variables[18])); - variables[118] = pow(leq(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])); - variables[119] = sqrt(variables[1]); - variables[120] = sqrt(variables[1]); - variables[121] = pow(variables[1], 1.0/3.0); - variables[122] = pow(variables[1], 1.0/variables[2]); - variables[123] = pow(lt(variables[1], variables[2]), 1.0/gt(variables[18], variables[6])); - variables[124] = pow(variables[1]+variables[2], 1.0/gt(variables[18], variables[6])); - variables[125] = pow(variables[1], 1.0/gt(variables[6], variables[2])); - variables[126] = pow(variables[1]-variables[2], 1.0/gt(variables[18], variables[6])); - variables[127] = pow(-variables[1], 1.0/gt(variables[6], variables[2])); - variables[128] = pow(variables[1]*variables[2], 1.0/gt(variables[18], variables[6])); - variables[129] = pow(variables[1]/variables[2], 1.0/gt(variables[18], variables[6])); - variables[130] = pow(lt(variables[1], variables[2]), 1.0/(variables[6]+variables[18])); - variables[131] = pow(lt(variables[1], variables[2]), 1.0/variables[6]); - variables[132] = pow(lt(variables[1], variables[2]), 1.0/(variables[6]-variables[18])); - variables[133] = pow(lt(variables[1], variables[2]), 1.0/-variables[6]); - variables[134] = pow(lt(variables[1], variables[2]), 1.0/(variables[6]*variables[18])); - variables[135] = pow(lt(variables[1], variables[2]), 1.0/(variables[6]/variables[18])); - variables[136] = pow(lt(variables[1], variables[2]), 1.0/pow(variables[6], variables[18])); - variables[137] = pow(lt(variables[1], variables[2]), 1.0/pow(variables[6], 1.0/variables[18])); - variables[138] = fabs(variables[1]); - variables[139] = exp(variables[1]); - variables[140] = log(variables[1]); - variables[141] = log10(variables[1]); - variables[142] = log(variables[1])/log(2.0); - variables[143] = log10(variables[1]); - variables[144] = log(variables[1])/log(variables[2]); - variables[145] = ceil(variables[1]); - variables[146] = floor(variables[1]); - variables[147] = min(variables[1], variables[2]); - variables[148] = min(variables[1], min(variables[2], variables[6])); - variables[149] = max(variables[1], variables[2]); - variables[150] = max(variables[1], max(variables[2], variables[6])); - variables[151] = fmod(variables[1], variables[2]); - variables[152] = sin(variables[1]); - variables[153] = cos(variables[1]); - variables[154] = tan(variables[1]); - variables[155] = sec(variables[1]); - variables[156] = csc(variables[1]); - variables[157] = cot(variables[1]); - variables[158] = sinh(variables[1]); - variables[159] = cosh(variables[1]); - variables[160] = tanh(variables[1]); - variables[161] = sech(variables[1]); - variables[162] = csch(variables[1]); - variables[163] = coth(variables[1]); - variables[164] = asin(variables[1]); - variables[165] = acos(variables[1]); - variables[166] = atan(variables[1]); - variables[167] = asec(variables[1]); - variables[168] = acsc(variables[1]); - variables[169] = acot(variables[1]); - variables[170] = asinh(variables[1]); - variables[171] = acosh(variables[1]); - variables[172] = atanh(variables[1]/2.0); - variables[173] = asech(variables[1]); - variables[174] = acsch(variables[1]); - variables[175] = acoth(2.0*variables[1]); - variables[176] = (gt(variables[1], variables[2]))?variables[1]:NAN; - variables[177] = (gt(variables[1], variables[2]))?variables[1]:variables[6]; - variables[178] = (gt(variables[1], variables[2]))?variables[1]:(gt(variables[6], variables[18]))?variables[6]:(gt(variables[179], variables[180]))?variables[179]:NAN; - variables[181] = (gt(variables[1], variables[2]))?variables[1]:(gt(variables[6], variables[18]))?variables[6]:(gt(variables[179], variables[180]))?variables[179]:variables[182]; - variables[183] = 123.0+((gt(variables[1], variables[2]))?variables[1]:NAN); - variables[188] = variables[1]; - variables[195] = and(variables[1], variables[2])+((gt(variables[6], variables[18]))?variables[2]:NAN)+variables[179]+and(variables[180], variables[182]); - variables[196] = and(variables[1], variables[2])-(((gt(variables[6], variables[18]))?variables[2]:NAN)-(variables[179]-((gt(variables[6], variables[18]))?variables[2]:NAN)))-and(variables[180], variables[182]); - variables[197] = and(variables[1], variables[2])*((gt(variables[6], variables[18]))?variables[2]:NAN)*variables[179]*((gt(variables[6], variables[18]))?variables[2]:NAN)*and(variables[180], variables[182]); - variables[198] = and(variables[1], variables[2])/(((gt(variables[6], variables[18]))?variables[2]:NAN)/(variables[179]/((gt(variables[6], variables[18]))?variables[2]:NAN))); - variables[199] = and(or(variables[1], variables[2]), and(xor(variables[1], variables[2]), and((gt(variables[6], variables[18]))?variables[2]:NAN, and(and(and(variables[179], (gt(variables[6], variables[18]))?variables[2]:NAN), xor(variables[1], variables[2])), or(variables[1], variables[2]))))); - variables[200] = or(and(variables[1], variables[2]), or(xor(variables[1], variables[2]), or((gt(variables[6], variables[18]))?variables[2]:NAN, or(or(or(variables[179], (gt(variables[6], variables[18]))?variables[2]:NAN), xor(variables[1], variables[2])), and(variables[1], variables[2]))))); - variables[201] = xor(and(variables[1], variables[2]), xor(or(variables[1], variables[2]), xor((gt(variables[6], variables[18]))?variables[2]:NAN, xor(xor(xor(variables[179], (gt(variables[6], variables[18]))?variables[2]:NAN), or(variables[1], variables[2])), and(variables[1], variables[2]))))); - variables[202] = pow(and(variables[1], variables[2]), pow((gt(variables[6], variables[18]))?variables[2]:NAN, pow(pow(variables[179], (gt(variables[6], variables[18]))?variables[2]:NAN), and(variables[1], variables[2])))); - variables[203] = pow(pow(pow(and(variables[1], variables[2]), 1.0/pow((gt(variables[6], variables[18]))?variables[2]:NAN, 1.0/variables[179])), 1.0/((gt(variables[6], variables[18]))?variables[2]:NAN)), 1.0/and(variables[1], variables[2])); - variables[204] = -and(variables[1], variables[2])+-((gt(variables[6], variables[18]))?variables[2]:NAN); + computedConstants[0] = eq(constants[0], constants[1]); + computedConstants[1] = constants[0]/eq(constants[1], constants[1]); + computedConstants[2] = neq(constants[0], constants[1]); + computedConstants[3] = constants[0]/neq(constants[1], constants[2]); + computedConstants[4] = lt(constants[0], constants[1]); + computedConstants[5] = constants[0]/lt(constants[1], constants[2]); + computedConstants[6] = leq(constants[0], constants[1]); + computedConstants[7] = constants[0]/leq(constants[1], constants[2]); + computedConstants[8] = gt(constants[0], constants[1]); + computedConstants[9] = constants[0]/gt(constants[2], constants[1]); + computedConstants[10] = geq(constants[0], constants[1]); + computedConstants[11] = constants[0]/geq(constants[2], constants[1]); + computedConstants[12] = and(constants[0], constants[1]); + computedConstants[13] = and(constants[0], and(constants[1], constants[2])); + computedConstants[14] = and(lt(constants[0], constants[1]), gt(constants[2], constants[3])); + computedConstants[15] = and(constants[0]+constants[1], gt(constants[2], constants[3])); + computedConstants[16] = and(constants[0], gt(constants[1], constants[2])); + computedConstants[17] = and(constants[0]-constants[1], gt(constants[2], constants[3])); + computedConstants[18] = and(-constants[0], gt(constants[1], constants[2])); + computedConstants[19] = and(pow(constants[0], constants[1]), gt(constants[2], constants[3])); + computedConstants[20] = and(pow(constants[0], 1.0/constants[1]), gt(constants[2], constants[3])); + computedConstants[21] = and(lt(constants[0], constants[1]), constants[2]+constants[3]); + computedConstants[22] = and(lt(constants[0], constants[1]), constants[2]); + computedConstants[23] = and(lt(constants[0], constants[1]), constants[2]-constants[3]); + computedConstants[24] = and(lt(constants[0], constants[1]), -constants[2]); + computedConstants[25] = and(lt(constants[0], constants[1]), pow(constants[2], constants[3])); + computedConstants[26] = and(lt(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])); + computedConstants[27] = constants[0]/and(constants[1], constants[2]); + computedConstants[28] = or(lt(constants[0], constants[1]), gt(constants[2], constants[3])); + computedConstants[29] = or(constants[0]+constants[1], gt(constants[2], constants[3])); + computedConstants[30] = or(constants[0], gt(constants[1], constants[2])); + computedConstants[31] = or(constants[0]-constants[1], gt(constants[2], constants[3])); + computedConstants[32] = or(-constants[0], gt(constants[1], constants[2])); + computedConstants[33] = or(pow(constants[0], constants[1]), gt(constants[2], constants[3])); + computedConstants[34] = or(pow(constants[0], 1.0/constants[1]), gt(constants[2], constants[3])); + computedConstants[35] = or(lt(constants[0], constants[1]), constants[2]+constants[3]); + computedConstants[36] = or(lt(constants[0], constants[1]), constants[2]); + computedConstants[37] = or(lt(constants[0], constants[1]), constants[2]-constants[3]); + computedConstants[38] = or(lt(constants[0], constants[1]), -constants[2]); + computedConstants[39] = or(lt(constants[0], constants[1]), pow(constants[2], constants[3])); + computedConstants[40] = or(lt(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])); + computedConstants[41] = constants[0]/or(constants[1], constants[2]); + computedConstants[42] = xor(constants[0], constants[1]); + computedConstants[43] = xor(constants[0], xor(constants[1], constants[2])); + computedConstants[44] = xor(lt(constants[0], constants[1]), gt(constants[2], constants[3])); + computedConstants[45] = xor(constants[0]+constants[1], gt(constants[2], constants[3])); + computedConstants[46] = xor(constants[0], gt(constants[1], constants[2])); + computedConstants[47] = xor(constants[0]-constants[1], gt(constants[2], constants[3])); + computedConstants[48] = xor(-constants[0], gt(constants[1], constants[2])); + computedConstants[49] = xor(pow(constants[0], constants[1]), gt(constants[2], constants[3])); + computedConstants[50] = xor(pow(constants[0], 1.0/constants[1]), gt(constants[2], constants[3])); + computedConstants[51] = xor(lt(constants[0], constants[1]), constants[2]+constants[3]); + computedConstants[52] = xor(lt(constants[0], constants[1]), constants[2]); + computedConstants[53] = xor(lt(constants[0], constants[1]), constants[2]-constants[3]); + computedConstants[54] = xor(lt(constants[0], constants[1]), -constants[2]); + computedConstants[55] = xor(lt(constants[0], constants[1]), pow(constants[2], constants[3])); + computedConstants[56] = xor(lt(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])); + computedConstants[57] = not(constants[0]); + computedConstants[58] = constants[0]+constants[1]+constants[2]; + computedConstants[59] = lt(constants[0], constants[1])+gt(constants[2], constants[3]); + computedConstants[60] = constants[0]; + computedConstants[61] = constants[0]-constants[1]; + computedConstants[62] = lt(constants[0], constants[1])-gt(constants[2], constants[3]); + computedConstants[63] = lt(constants[0], constants[1])-(constants[2]+constants[3]); + computedConstants[64] = lt(constants[0], constants[1])-constants[2]; + computedConstants[65] = constants[0]-(-constants[1]); + computedConstants[66] = constants[0]-(-constants[1]*constants[2]); + computedConstants[67] = -constants[0]; + computedConstants[68] = -lt(constants[0], constants[1]); + computedConstants[69] = constants[0]*constants[1]; + computedConstants[70] = constants[0]*constants[1]*constants[2]; + computedConstants[71] = lt(constants[0], constants[1])*gt(constants[2], constants[3]); + computedConstants[72] = (constants[0]+constants[1])*gt(constants[2], constants[3]); + computedConstants[73] = constants[0]*gt(constants[1], constants[2]); + computedConstants[74] = (constants[0]-constants[1])*gt(constants[2], constants[3]); + computedConstants[75] = -constants[0]*gt(constants[1], constants[2]); + computedConstants[76] = lt(constants[0], constants[1])*(constants[2]+constants[3]); + computedConstants[77] = lt(constants[0], constants[1])*constants[2]; + computedConstants[78] = lt(constants[0], constants[1])*(constants[2]-constants[3]); + computedConstants[79] = lt(constants[0], constants[1])*-constants[2]; + computedConstants[80] = constants[0]/constants[1]; + computedConstants[81] = lt(constants[0], constants[1])/gt(constants[3], constants[2]); + computedConstants[82] = (constants[0]+constants[1])/gt(constants[3], constants[2]); + computedConstants[83] = constants[0]/gt(constants[2], constants[1]); + computedConstants[84] = (constants[0]-constants[1])/gt(constants[3], constants[2]); + computedConstants[85] = -constants[0]/gt(constants[2], constants[1]); + computedConstants[86] = lt(constants[0], constants[1])/(constants[2]+constants[3]); + computedConstants[87] = lt(constants[0], constants[1])/constants[2]; + computedConstants[88] = lt(constants[0], constants[1])/(constants[2]-constants[3]); + computedConstants[89] = lt(constants[0], constants[1])/-constants[2]; + computedConstants[90] = lt(constants[0], constants[1])/(constants[2]*constants[3]); + computedConstants[91] = lt(constants[0], constants[1])/(constants[2]/constants[3]); + computedConstants[92] = sqrt(constants[0]); + computedConstants[93] = pow(constants[0], 2.0); + computedConstants[94] = pow(constants[0], 3.0); + computedConstants[95] = pow(constants[0], constants[1]); + computedConstants[96] = pow(leq(constants[0], constants[1]), geq(constants[2], constants[3])); + computedConstants[97] = pow(constants[0]+constants[1], geq(constants[2], constants[3])); + computedConstants[98] = pow(constants[0], geq(constants[1], constants[2])); + computedConstants[99] = pow(constants[0]-constants[1], geq(constants[2], constants[3])); + computedConstants[100] = pow(-constants[0], geq(constants[1], constants[2])); + computedConstants[101] = pow(constants[0]*constants[1], geq(constants[2], constants[3])); + computedConstants[102] = pow(constants[0]/constants[1], geq(constants[2], constants[3])); + computedConstants[103] = pow(leq(constants[0], constants[1]), constants[2]+constants[3]); + computedConstants[104] = pow(leq(constants[0], constants[1]), constants[2]); + computedConstants[105] = pow(leq(constants[0], constants[1]), constants[2]-constants[3]); + computedConstants[106] = pow(leq(constants[0], constants[1]), -constants[2]); + computedConstants[107] = pow(leq(constants[0], constants[1]), constants[2]*constants[3]); + computedConstants[108] = pow(leq(constants[0], constants[1]), constants[2]/constants[3]); + computedConstants[109] = pow(leq(constants[0], constants[1]), pow(constants[2], constants[3])); + computedConstants[110] = pow(leq(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])); + computedConstants[111] = sqrt(constants[0]); + computedConstants[112] = sqrt(constants[0]); + computedConstants[113] = pow(constants[0], 1.0/0.5); + computedConstants[114] = pow(constants[0], 1.0/3.0); + computedConstants[115] = pow(constants[0], 1.0/constants[1]); + computedConstants[116] = pow(lt(constants[0], constants[1]), 1.0/gt(constants[3], constants[2])); + computedConstants[117] = pow(constants[0]+constants[1], 1.0/gt(constants[3], constants[2])); + computedConstants[118] = pow(constants[0], 1.0/gt(constants[2], constants[1])); + computedConstants[119] = pow(constants[0]-constants[1], 1.0/gt(constants[3], constants[2])); + computedConstants[120] = pow(-constants[0], 1.0/gt(constants[2], constants[1])); + computedConstants[121] = pow(constants[0]*constants[1], 1.0/gt(constants[3], constants[2])); + computedConstants[122] = pow(constants[0]/constants[1], 1.0/gt(constants[3], constants[2])); + computedConstants[123] = pow(lt(constants[0], constants[1]), 1.0/(constants[2]+constants[3])); + computedConstants[124] = pow(lt(constants[0], constants[1]), 1.0/constants[2]); + computedConstants[125] = pow(lt(constants[0], constants[1]), 1.0/(constants[2]-constants[3])); + computedConstants[126] = pow(lt(constants[0], constants[1]), 1.0/-constants[2]); + computedConstants[127] = pow(lt(constants[0], constants[1]), 1.0/(constants[2]*constants[3])); + computedConstants[128] = pow(lt(constants[0], constants[1]), 1.0/(constants[2]/constants[3])); + computedConstants[129] = pow(lt(constants[0], constants[1]), 1.0/pow(constants[2], constants[3])); + computedConstants[130] = pow(lt(constants[0], constants[1]), 1.0/pow(constants[2], 1.0/constants[3])); + computedConstants[131] = fabs(constants[0]); + computedConstants[132] = exp(constants[0]); + computedConstants[133] = log(constants[0]); + computedConstants[134] = log10(constants[0]); + computedConstants[135] = log(constants[0])/log(2.0); + computedConstants[136] = log10(constants[0]); + computedConstants[137] = log(constants[0])/log(constants[1]); + computedConstants[138] = ceil(constants[0]); + computedConstants[139] = floor(constants[0]); + computedConstants[140] = fmin(constants[0], constants[1]); + computedConstants[141] = fmin(constants[0], fmin(constants[1], constants[2])); + computedConstants[142] = fmax(constants[0], constants[1]); + computedConstants[143] = fmax(constants[0], fmax(constants[1], constants[2])); + computedConstants[144] = fmod(constants[0], constants[1]); + computedConstants[145] = sin(constants[0]); + computedConstants[146] = cos(constants[0]); + computedConstants[147] = tan(constants[0]); + computedConstants[148] = sec(constants[0]); + computedConstants[149] = csc(constants[0]); + computedConstants[150] = cot(constants[0]); + computedConstants[151] = sinh(constants[0]); + computedConstants[152] = cosh(constants[0]); + computedConstants[153] = tanh(constants[0]); + computedConstants[154] = sech(constants[0]); + computedConstants[155] = csch(constants[0]); + computedConstants[156] = coth(constants[0]); + computedConstants[157] = asin(constants[0]); + computedConstants[158] = acos(constants[0]); + computedConstants[159] = atan(constants[0]); + computedConstants[160] = asec(constants[0]); + computedConstants[161] = acsc(constants[0]); + computedConstants[162] = acot(constants[0]); + computedConstants[163] = asinh(constants[0]); + computedConstants[164] = acosh(constants[0]); + computedConstants[165] = atanh(constants[0]/2.0); + computedConstants[166] = asech(constants[0]); + computedConstants[167] = acsch(constants[0]); + computedConstants[168] = acoth(2.0*constants[0]); + computedConstants[170] = (gt(constants[0], constants[1]))?constants[0]:NAN; + computedConstants[171] = (lt(constants[0], constants[1]))?constants[0]:NAN; + computedConstants[172] = constants[0]; + computedConstants[173] = (gt(constants[0], constants[1]))?constants[0]:constants[2]; + computedConstants[174] = (gt(constants[0], constants[1]))?constants[0]:(gt(constants[2], constants[3]))?constants[2]:(gt(constants[4], constants[5]))?constants[4]:NAN; + computedConstants[175] = (lt(constants[0], constants[1]))?constants[0]:(gt(constants[2], constants[3]))?constants[2]:(gt(constants[4], constants[5]))?constants[4]:NAN; + computedConstants[176] = (gt(constants[0], constants[1]))?constants[0]:(gt(constants[2], constants[3]))?constants[2]:(gt(constants[4], constants[5]))?constants[4]:constants[6]; + computedConstants[177] = 123.0+((gt(constants[0], constants[1]))?constants[0]:NAN); + computedConstants[178] = 123.0+((lt(constants[0], constants[1]))?constants[0]:NAN); + computedConstants[183] = constants[0]; + computedConstants[190] = and(constants[0], constants[1])+((gt(constants[2], constants[3]))?constants[1]:NAN)+constants[4]+and(constants[5], constants[6]); + computedConstants[191] = and(constants[0], constants[1])+((lt(constants[2], constants[3]))?constants[1]:NAN)+constants[4]+and(constants[5], constants[6]); + computedConstants[192] = and(constants[0], constants[1])-(((gt(constants[2], constants[3]))?constants[1]:NAN)-(constants[4]-((gt(constants[2], constants[3]))?constants[1]:NAN)))-and(constants[5], constants[6]); + computedConstants[193] = and(constants[0], constants[1])-(((lt(constants[2], constants[3]))?constants[1]:NAN)-(constants[4]-((lt(constants[2], constants[3]))?constants[1]:NAN)))-and(constants[5], constants[6]); + computedConstants[194] = and(constants[0], constants[1])*((gt(constants[2], constants[3]))?constants[1]:NAN)*constants[4]*((gt(constants[2], constants[3]))?constants[1]:NAN)*and(constants[5], constants[6]); + computedConstants[195] = and(constants[0], constants[1])*((lt(constants[2], constants[3]))?constants[1]:NAN)*constants[4]*((lt(constants[2], constants[3]))?constants[1]:NAN)*and(constants[5], constants[6]); + computedConstants[196] = and(constants[0], constants[1])/(((gt(constants[2], constants[3]))?constants[1]:NAN)/(constants[4]/((gt(constants[2], constants[3]))?constants[1]:NAN))); + computedConstants[197] = and(constants[0], constants[1])/(((lt(constants[2], constants[3]))?constants[1]:NAN)/(constants[4]/((lt(constants[2], constants[3]))?constants[1]:NAN))); + computedConstants[198] = and(or(constants[0], constants[1]), and(xor(constants[0], constants[1]), and((gt(constants[2], constants[3]))?constants[1]:NAN, and(and(and(constants[4], (gt(constants[2], constants[3]))?constants[1]:NAN), xor(constants[0], constants[1])), or(constants[0], constants[1]))))); + computedConstants[199] = or(and(constants[0], constants[1]), or(xor(constants[0], constants[1]), or((gt(constants[2], constants[3]))?constants[1]:NAN, or(or(or(constants[4], (gt(constants[2], constants[3]))?constants[1]:NAN), xor(constants[0], constants[1])), and(constants[0], constants[1]))))); + computedConstants[200] = xor(and(constants[0], constants[1]), xor(or(constants[0], constants[1]), xor((gt(constants[2], constants[3]))?constants[1]:NAN, xor(xor(xor(constants[4], (gt(constants[2], constants[3]))?constants[1]:NAN), or(constants[0], constants[1])), and(constants[0], constants[1]))))); + computedConstants[201] = pow(and(constants[0], constants[1]), pow((gt(constants[2], constants[3]))?constants[1]:NAN, pow(pow(constants[4], (gt(constants[2], constants[3]))?constants[1]:NAN), and(constants[0], constants[1])))); + computedConstants[202] = pow(pow(pow(and(constants[0], constants[1]), 1.0/pow((gt(constants[2], constants[3]))?constants[1]:NAN, 1.0/constants[4])), 1.0/((gt(constants[2], constants[3]))?constants[1]:NAN)), 1.0/and(constants[0], constants[1])); + computedConstants[203] = -and(constants[0], constants[1])+-((gt(constants[2], constants[3]))?constants[1]:NAN); + computedConstants[204] = -and(constants[0], constants[1])+-((lt(constants[2], constants[3]))?constants[1]:NAN); } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { rates[0] = 1.0; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - findRoot0(voi, states, rates, variables); + algebraic[0] = or(states[0], states[0]); + algebraic[1] = or(states[0], or(states[0], constants[0])); + algebraic[2] = constants[0]/xor(constants[1], states[0]); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); } diff --git a/tests/resources/coverage/generator/model.interface.out b/tests/resources/coverage/generator/model.interface.out index 17842c1d65..60f0b1f405 100644 --- a/tests/resources/coverage/generator/model.interface.out +++ b/tests/resources/coverage/generator/model.interface.out @@ -5,10 +5,16 @@ #include double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/coverage/generator/model.modified.profile.c b/tests/resources/coverage/generator/model.modified.profile.c deleted file mode 100644 index 88a4fede2b..0000000000 --- a/tests/resources/coverage/generator/model.modified.profile.c +++ /dev/null @@ -1,604 +0,0 @@ -/* The content of this file was generated using a modified C profile of libCellML 0.6.0. */ - -#include "model.h" - -#include -#include - -const char VERSION[] = "0.5.0.post0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 209; - -const VariableInfo VOI_INFO = {"t", "second", "my_component", VARIABLE_OF_INTEGRATION}; - -const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_component", STATE} -}; - -const VariableInfo VARIABLE_INFO[] = { - {"eqnEq", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"m", "dimensionless", "my_component", CONSTANT}, - {"n", "dimensionless", "my_component", CONSTANT}, - {"eqnEqCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnNeq", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnNeqCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"o", "dimensionless", "my_component", CONSTANT}, - {"eqnLt", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLtCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLeq", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLeqCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnGt", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnGtCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnGeq", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnGeqCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAnd", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"p", "dimensionless", "my_component", CONSTANT}, - {"eqnAndParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesLeftPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesLeftRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndParenthesesRightRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAndCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOr", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesLeftRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrParenthesesRightRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnOrCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXor", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesLeftRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorParenthesesRightRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnXorCoverageParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnNot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPlus", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPlusMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPlusParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPlusUnary", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinus", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusParenthesesPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusParenthesesPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusParenthesesDirectUnaryMinus", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusParenthesesIndirectUnaryMinus", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusUnary", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinusUnaryParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTimesParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnDivideParenthesesRightDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerSqrt", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerSqr", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerCube", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerCi", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesLeftDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPowerParenthesesRightRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootSqrt", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootSqrtOther", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootCube", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootCi", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParentheses", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesLeftDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightPlusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightPlusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightMinusWith", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightMinusWithout", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightTimes", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightDivide", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightPower", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRootParenthesesRightRoot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnAbs", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnExp", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLn", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLog", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLog2", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLog10", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnLogCi", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCeiling", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnFloor", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMin", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMinMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMax", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnMaxMultiple", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnRem", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnSin", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCos", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTan", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnSec", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCsc", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnSinh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCosh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTanh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnSech", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCsch", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoth", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArcsin", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccos", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArctan", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArcsec", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccsc", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccot", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArcsinh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccosh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArctanh", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArcsech", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccsch", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnArccoth", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPiecewisePiece", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPiecewisePieceOtherwise", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPiecewisePiecePiecePiece", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"q", "dimensionless", "my_component", CONSTANT}, - {"r", "dimensionless", "my_component", CONSTANT}, - {"eqnPiecewisePiecePiecePieceOtherwise", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"s", "dimensionless", "my_component", CONSTANT}, - {"eqnWithPiecewise", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCnInteger", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCnDouble", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCnIntegerWithExponent", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCnDoubleWithExponent", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCi", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnTrue", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnFalse", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnExponentiale", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnPi", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnInfinity", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnNotanumber", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForPlusOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForMinusOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForTimesOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForDivideOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForAndOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForOrOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForXorOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForPowerOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForRootOperator", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnCoverageForMinusUnary", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnNlaVariable1", "dimensionless", "my_component", ALGEBRAIC}, - {"eqnNlaVariable2", "dimensionless", "my_component", ALGEBRAIC}, - {"eqnComputedConstant1", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"eqnComputedConstant2", "dimensionless", "my_component", COMPUTED_CONSTANT} -}; - -double xor(double x, double y) -{ - return (x != 0.0) ^ (y != 0.0); -} - -double min(double x, double y) -{ - return (x < y)?x:y; -} - -double max(double x, double y) -{ - return (x > y)?x:y; -} - -double sec(double x) -{ - return 1.0/cos(x); -} - -double csc(double x) -{ - return 1.0/sin(x); -} - -double cot(double x) -{ - return 1.0/tan(x); -} - -double sech(double x) -{ - return 1.0/cosh(x); -} - -double csch(double x) -{ - return 1.0/sinh(x); -} - -double coth(double x) -{ - return 1.0/tanh(x); -} - -double asec(double x) -{ - return acos(1.0/x); -} - -double acsc(double x) -{ - return asin(1.0/x); -} - -double acot(double x) -{ - return atan(1.0/x); -} - -double asech(double x) -{ - double oneOverX = 1.0/x; - - return log(oneOverX+sqrt(oneOverX*oneOverX-1.0)); -} - -double acsch(double x) -{ - double oneOverX = 1.0/x; - - return log(oneOverX+sqrt(oneOverX*oneOverX+1.0)); -} - -double acoth(double x) -{ - double oneOverX = 1.0/x; - - return 0.5*log((1.0+oneOverX)/(1.0-oneOverX)); -} - -double * createStatesVector() -{ - double *res = (double *) malloc(STATE_COUNT*sizeof(double)); - - for (size_t i = 0; i < STATE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -typedef struct { - double voi; - double *states; - double *rates; - double *variables; -} RootFindingInfo; - -extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), - double *u, size_t n, void *data); - -void objectiveFunction0(double *u, double *f, void *data) -{ - double voi = ((RootFindingInfo *) data)->voi; - double *states = ((RootFindingInfo *) data)->states; - double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; - - variables[205] = u[0]; - variables[206] = u[1]; - - f[0] = variables[205]+variables[206]+states[0]-0.0; - f[1] = variables[205]-variables[206]-(variables[207]+variables[208]); -} - -void findRoot0(double voi, double *states, double *rates, double *variables) -{ - RootFindingInfo rfi = { voi, states, rates, variables }; - double u[2]; - - u[0] = variables[205]; - u[1] = variables[206]; - - nlaSolve(objectiveFunction0, u, 2, &rfi); - - variables[205] = u[0]; - variables[206] = u[1]; -} - -void initialiseVariables(double *states, double *rates, double *variables) -{ - variables[1] = 1.0; - variables[2] = 2.0; - variables[6] = 3.0; - variables[18] = 4.0; - variables[179] = 5.0; - variables[180] = 6.0; - variables[182] = 7.0; - variables[205] = 1.0; - variables[206] = 2.0; - variables[184] = 123.0; - variables[185] = 123.456789; - variables[186] = 123.0e99; - variables[187] = 123.456789e99; - variables[189] = 1.0; - variables[190] = 0.0; - variables[191] = 2.71828182845905; - variables[192] = 3.14159265358979; - variables[193] = INFINITY; - variables[194] = NAN; - variables[207] = 1.0; - variables[208] = 3.0; - states[0] = 0.0; -} - -void computeComputedConstants(double *variables) -{ - variables[0] = variables[1] == variables[2]; - variables[3] = variables[1]/(variables[2] == variables[2]); - variables[4] = variables[1] != variables[2]; - variables[5] = variables[1]/(variables[2] != variables[6]); - variables[7] = variables[1] < variables[2]; - variables[8] = variables[1]/(variables[2] < variables[6]); - variables[9] = variables[1] <= variables[2]; - variables[10] = variables[1]/(variables[2] <= variables[6]); - variables[11] = variables[1] > variables[2]; - variables[12] = variables[1]/(variables[2] > variables[6]); - variables[13] = variables[1] >= variables[2]; - variables[14] = variables[1]/(variables[2] >= variables[6]); - variables[15] = variables[1] && variables[2]; - variables[16] = variables[1] && variables[2] && variables[6]; - variables[17] = (variables[1] < variables[2]) && (variables[6] > variables[18]); - variables[19] = (variables[1]+variables[2]) && (variables[6] > variables[18]); - variables[20] = variables[1] && (variables[2] > variables[6]); - variables[21] = (variables[1]-variables[2]) && (variables[6] > variables[18]); - variables[22] = -variables[1] && (variables[2] > variables[6]); - variables[23] = pow(variables[1], variables[2]) && (variables[6] > variables[18]); - variables[24] = pow(variables[1], 1.0/variables[2]) && (variables[6] > variables[18]); - variables[25] = (variables[1] < variables[2]) && (variables[6]+variables[18]); - variables[26] = (variables[1] < variables[2]) && variables[6]; - variables[27] = (variables[1] < variables[2]) && (variables[6]-variables[18]); - variables[28] = (variables[1] < variables[2]) && -variables[6]; - variables[29] = (variables[1] < variables[2]) && pow(variables[6], variables[18]); - variables[30] = (variables[1] < variables[2]) && pow(variables[6], 1.0/variables[18]); - variables[31] = variables[1]/(variables[2] && variables[6]); - variables[32] = variables[1] || variables[2]; - variables[33] = variables[1] || variables[2] || variables[6]; - variables[34] = (variables[1] < variables[2]) || (variables[6] > variables[18]); - variables[35] = (variables[1]+variables[2]) || (variables[6] > variables[18]); - variables[36] = variables[1] || (variables[2] > variables[6]); - variables[37] = (variables[1]-variables[2]) || (variables[6] > variables[18]); - variables[38] = -variables[1] || (variables[2] > variables[6]); - variables[39] = pow(variables[1], variables[2]) || (variables[6] > variables[18]); - variables[40] = pow(variables[1], 1.0/variables[2]) || (variables[6] > variables[18]); - variables[41] = (variables[1] < variables[2]) || (variables[6]+variables[18]); - variables[42] = (variables[1] < variables[2]) || variables[6]; - variables[43] = (variables[1] < variables[2]) || (variables[6]-variables[18]); - variables[44] = (variables[1] < variables[2]) || -variables[6]; - variables[45] = (variables[1] < variables[2]) || pow(variables[6], variables[18]); - variables[46] = (variables[1] < variables[2]) || pow(variables[6], 1.0/variables[18]); - variables[47] = variables[1]/(variables[2] || variables[6]); - variables[48] = xor(variables[1], variables[2]); - variables[49] = xor(variables[1], xor(variables[2], variables[6])); - variables[50] = xor(variables[1] < variables[2], variables[6] > variables[18]); - variables[51] = xor(variables[1]+variables[2], variables[6] > variables[18]); - variables[52] = xor(variables[1], variables[2] > variables[6]); - variables[53] = xor(variables[1]-variables[2], variables[6] > variables[18]); - variables[54] = xor(-variables[1], variables[2] > variables[6]); - variables[55] = xor(pow(variables[1], variables[2]), variables[6] > variables[18]); - variables[56] = xor(pow(variables[1], 1.0/variables[2]), variables[6] > variables[18]); - variables[57] = xor(variables[1] < variables[2], variables[6]+variables[18]); - variables[58] = xor(variables[1] < variables[2], variables[6]); - variables[59] = xor(variables[1] < variables[2], variables[6]-variables[18]); - variables[60] = xor(variables[1] < variables[2], -variables[6]); - variables[61] = xor(variables[1] < variables[2], pow(variables[6], variables[18])); - variables[62] = xor(variables[1] < variables[2], pow(variables[6], 1.0/variables[18])); - variables[63] = variables[1]/xor(variables[2], variables[6]); - variables[64] = !variables[1]; - variables[65] = variables[1]+variables[2]; - variables[66] = variables[1]+variables[2]+variables[6]; - variables[67] = (variables[1] < variables[2])+(variables[6] > variables[18]); - variables[68] = variables[1]; - variables[69] = variables[1]-variables[2]; - variables[70] = (variables[1] < variables[2])-(variables[6] > variables[18]); - variables[71] = (variables[1] < variables[2])-(variables[6]+variables[18]); - variables[72] = (variables[1] < variables[2])-variables[6]; - variables[73] = variables[1]-(-variables[2]); - variables[74] = variables[1]-(-variables[2]*variables[6]); - variables[75] = -variables[1]; - variables[76] = -(variables[1] < variables[2]); - variables[77] = variables[1]*variables[2]; - variables[78] = variables[1]*variables[2]*variables[6]; - variables[79] = (variables[1] < variables[2])*(variables[6] > variables[18]); - variables[80] = (variables[1]+variables[2])*(variables[6] > variables[18]); - variables[81] = variables[1]*(variables[2] > variables[6]); - variables[82] = (variables[1]-variables[2])*(variables[6] > variables[18]); - variables[83] = -variables[1]*(variables[2] > variables[6]); - variables[84] = (variables[1] < variables[2])*(variables[6]+variables[18]); - variables[85] = (variables[1] < variables[2])*variables[6]; - variables[86] = (variables[1] < variables[2])*(variables[6]-variables[18]); - variables[87] = (variables[1] < variables[2])*-variables[6]; - variables[88] = variables[1]/variables[2]; - variables[89] = (variables[1] < variables[2])/(variables[18] > variables[6]); - variables[90] = (variables[1]+variables[2])/(variables[18] > variables[6]); - variables[91] = variables[1]/(variables[6] > variables[2]); - variables[92] = (variables[1]-variables[2])/(variables[18] > variables[6]); - variables[93] = -variables[1]/(variables[6] > variables[2]); - variables[94] = (variables[1] < variables[2])/(variables[6]+variables[18]); - variables[95] = (variables[1] < variables[2])/variables[6]; - variables[96] = (variables[1] < variables[2])/(variables[6]-variables[18]); - variables[97] = (variables[1] < variables[2])/-variables[6]; - variables[98] = (variables[1] < variables[2])/(variables[6]*variables[18]); - variables[99] = (variables[1] < variables[2])/(variables[6]/variables[18]); - variables[100] = sqrt(variables[1]); - variables[101] = pow(variables[1], 2.0); - variables[102] = pow(variables[1], 3.0); - variables[103] = pow(variables[1], variables[2]); - variables[104] = pow(variables[1] <= variables[2], variables[6] >= variables[18]); - variables[105] = pow(variables[1]+variables[2], variables[6] >= variables[18]); - variables[106] = pow(variables[1], variables[2] >= variables[6]); - variables[107] = pow(variables[1]-variables[2], variables[6] >= variables[18]); - variables[108] = pow(-variables[1], variables[2] >= variables[6]); - variables[109] = pow(variables[1]*variables[2], variables[6] >= variables[18]); - variables[110] = pow(variables[1]/variables[2], variables[6] >= variables[18]); - variables[111] = pow(variables[1] <= variables[2], variables[6]+variables[18]); - variables[112] = pow(variables[1] <= variables[2], variables[6]); - variables[113] = pow(variables[1] <= variables[2], variables[6]-variables[18]); - variables[114] = pow(variables[1] <= variables[2], -variables[6]); - variables[115] = pow(variables[1] <= variables[2], variables[6]*variables[18]); - variables[116] = pow(variables[1] <= variables[2], variables[6]/variables[18]); - variables[117] = pow(variables[1] <= variables[2], pow(variables[6], variables[18])); - variables[118] = pow(variables[1] <= variables[2], pow(variables[6], 1.0/variables[18])); - variables[119] = sqrt(variables[1]); - variables[120] = sqrt(variables[1]); - variables[121] = pow(variables[1], 1.0/3.0); - variables[122] = pow(variables[1], 1.0/variables[2]); - variables[123] = pow(variables[1] < variables[2], 1.0/(variables[18] > variables[6])); - variables[124] = pow(variables[1]+variables[2], 1.0/(variables[18] > variables[6])); - variables[125] = pow(variables[1], 1.0/(variables[6] > variables[2])); - variables[126] = pow(variables[1]-variables[2], 1.0/(variables[18] > variables[6])); - variables[127] = pow(-variables[1], 1.0/(variables[6] > variables[2])); - variables[128] = pow(variables[1]*variables[2], 1.0/(variables[18] > variables[6])); - variables[129] = pow(variables[1]/variables[2], 1.0/(variables[18] > variables[6])); - variables[130] = pow(variables[1] < variables[2], 1.0/(variables[6]+variables[18])); - variables[131] = pow(variables[1] < variables[2], 1.0/variables[6]); - variables[132] = pow(variables[1] < variables[2], 1.0/(variables[6]-variables[18])); - variables[133] = pow(variables[1] < variables[2], 1.0/-variables[6]); - variables[134] = pow(variables[1] < variables[2], 1.0/(variables[6]*variables[18])); - variables[135] = pow(variables[1] < variables[2], 1.0/(variables[6]/variables[18])); - variables[136] = pow(variables[1] < variables[2], 1.0/pow(variables[6], variables[18])); - variables[137] = pow(variables[1] < variables[2], 1.0/pow(variables[6], 1.0/variables[18])); - variables[138] = fabs(variables[1]); - variables[139] = exp(variables[1]); - variables[140] = log(variables[1]); - variables[141] = log10(variables[1]); - variables[142] = log(variables[1])/log(2.0); - variables[143] = log10(variables[1]); - variables[144] = log(variables[1])/log(variables[2]); - variables[145] = ceil(variables[1]); - variables[146] = floor(variables[1]); - variables[147] = min(variables[1], variables[2]); - variables[148] = min(variables[1], min(variables[2], variables[6])); - variables[149] = max(variables[1], variables[2]); - variables[150] = max(variables[1], max(variables[2], variables[6])); - variables[151] = fmod(variables[1], variables[2]); - variables[152] = sin(variables[1]); - variables[153] = cos(variables[1]); - variables[154] = tan(variables[1]); - variables[155] = sec(variables[1]); - variables[156] = csc(variables[1]); - variables[157] = cot(variables[1]); - variables[158] = sinh(variables[1]); - variables[159] = cosh(variables[1]); - variables[160] = tanh(variables[1]); - variables[161] = sech(variables[1]); - variables[162] = csch(variables[1]); - variables[163] = coth(variables[1]); - variables[164] = asin(variables[1]); - variables[165] = acos(variables[1]); - variables[166] = atan(variables[1]); - variables[167] = asec(variables[1]); - variables[168] = acsc(variables[1]); - variables[169] = acot(variables[1]); - variables[170] = asinh(variables[1]); - variables[171] = acosh(variables[1]); - variables[172] = atanh(variables[1]/2.0); - variables[173] = asech(variables[1]); - variables[174] = acsch(variables[1]); - variables[175] = acoth(2.0*variables[1]); - variables[176] = (variables[1] > variables[2])?variables[1]:NAN; - variables[177] = (variables[1] > variables[2])?variables[1]:variables[6]; - variables[178] = (variables[1] > variables[2])?variables[1]:(variables[6] > variables[18])?variables[6]:(variables[179] > variables[180])?variables[179]:NAN; - variables[181] = (variables[1] > variables[2])?variables[1]:(variables[6] > variables[18])?variables[6]:(variables[179] > variables[180])?variables[179]:variables[182]; - variables[183] = 123.0+((variables[1] > variables[2])?variables[1]:NAN); - variables[188] = variables[1]; - variables[195] = (variables[1] && variables[2])+((variables[6] > variables[18])?variables[2]:NAN)+variables[179]+(variables[180] && variables[182]); - variables[196] = (variables[1] && variables[2])-(((variables[6] > variables[18])?variables[2]:NAN)-(variables[179]-((variables[6] > variables[18])?variables[2]:NAN)))-(variables[180] && variables[182]); - variables[197] = (variables[1] && variables[2])*((variables[6] > variables[18])?variables[2]:NAN)*variables[179]*((variables[6] > variables[18])?variables[2]:NAN)*(variables[180] && variables[182]); - variables[198] = (variables[1] && variables[2])/(((variables[6] > variables[18])?variables[2]:NAN)/(variables[179]/((variables[6] > variables[18])?variables[2]:NAN))); - variables[199] = (variables[1] || variables[2]) && xor(variables[1], variables[2]) && ((variables[6] > variables[18])?variables[2]:NAN) && variables[179] && ((variables[6] > variables[18])?variables[2]:NAN) && xor(variables[1], variables[2]) && (variables[1] || variables[2]); - variables[200] = (variables[1] && variables[2]) || xor(variables[1], variables[2]) || ((variables[6] > variables[18])?variables[2]:NAN) || variables[179] || ((variables[6] > variables[18])?variables[2]:NAN) || xor(variables[1], variables[2]) || (variables[1] && variables[2]); - variables[201] = xor(variables[1] && variables[2], xor(variables[1] || variables[2], xor((variables[6] > variables[18])?variables[2]:NAN, xor(xor(xor(variables[179], (variables[6] > variables[18])?variables[2]:NAN), variables[1] || variables[2]), variables[1] && variables[2])))); - variables[202] = pow(variables[1] && variables[2], pow((variables[6] > variables[18])?variables[2]:NAN, pow(pow(variables[179], (variables[6] > variables[18])?variables[2]:NAN), variables[1] && variables[2]))); - variables[203] = pow(pow(pow(variables[1] && variables[2], 1.0/pow((variables[6] > variables[18])?variables[2]:NAN, 1.0/variables[179])), 1.0/((variables[6] > variables[18])?variables[2]:NAN)), 1.0/(variables[1] && variables[2])); - variables[204] = -(variables[1] && variables[2])+-((variables[6] > variables[18])?variables[2]:NAN); -} - -void computeRates(double voi, double *states, double *rates, double *variables) -{ - rates[0] = 1.0; -} - -void computeVariables(double voi, double *states, double *rates, double *variables) -{ - findRoot0(voi, states, rates, variables); -} diff --git a/tests/resources/coverage/generator/model.modified.profile.h b/tests/resources/coverage/generator/model.modified.profile.h deleted file mode 100644 index f6509bf327..0000000000 --- a/tests/resources/coverage/generator/model.modified.profile.h +++ /dev/null @@ -1,39 +0,0 @@ -/* The content of this file was generated using a modified C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; - -typedef struct { - char name[38]; - char units[14]; - char component[13]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VOI_INFO; -extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; - -double * createStatesVector(); -double * createVariablesArray(); -void deleteArray(double *array); - -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); diff --git a/tests/resources/coverage/generator/model.modified.profile.py b/tests/resources/coverage/generator/model.modified.profile.py deleted file mode 100644 index 49dc56a77c..0000000000 --- a/tests/resources/coverage/generator/model.modified.profile.py +++ /dev/null @@ -1,600 +0,0 @@ -# The content of this file was generated using a modified Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0.post0" -LIBCELLML_VERSION = "0.6.0" - -STATE_COUNT = 1 -VARIABLE_COUNT = 209 - - -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - - -VOI_INFO = {"name": "t", "units": "second", "component": "my_component", "type": VariableType.VARIABLE_OF_INTEGRATION} - -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_component", "type": VariableType.STATE} -] - -VARIABLE_INFO = [ - {"name": "eqnEq", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "m", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "n", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "eqnEqCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnNeq", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnNeqCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "o", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "eqnLt", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLtCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLeq", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLeqCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnGt", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnGtCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnGeq", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnGeqCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAnd", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "p", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "eqnAndParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesLeftPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesLeftRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOr", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXor", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnNot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPlus", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPlusMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPlusParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPlusUnary", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinus", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusParenthesesPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusParenthesesPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusParenthesesDirectUnaryMinus", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusParenthesesIndirectUnaryMinus", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusUnary", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusUnaryParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerSqrt", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerSqr", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerCube", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerCi", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootSqrt", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootSqrtOther", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootCube", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootCi", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAbs", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnExp", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLn", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLog", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLog2", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLog10", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLogCi", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCeiling", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnFloor", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMin", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMax", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMaxMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRem", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnSin", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCos", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTan", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnSec", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCsc", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnSinh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCosh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTanh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnSech", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCsch", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoth", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArcsin", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccos", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArctan", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArcsec", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccsc", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArcsinh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccosh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArctanh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArcsech", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccsch", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccoth", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPiecewisePiece", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPiecewisePieceOtherwise", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPiecewisePiecePiecePiece", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "q", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "r", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "eqnPiecewisePiecePiecePieceOtherwise", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "s", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "eqnWithPiecewise", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCnInteger", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCnDouble", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCnIntegerWithExponent", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCnDoubleWithExponent", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCi", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTrue", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnFalse", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnExponentiale", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPi", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnInfinity", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnNotanumber", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForPlusOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForMinusOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForTimesOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForDivideOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForAndOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForOrOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForXorOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForPowerOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForRootOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForMinusUnary", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnNlaVariable1", "units": "dimensionless", "component": "my_component", "type": VariableType.ALGEBRAIC}, - {"name": "eqnNlaVariable2", "units": "dimensionless", "component": "my_component", "type": VariableType.ALGEBRAIC}, - {"name": "eqnComputedConstant1", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnComputedConstant2", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT} -] - - -def eq_func(x, y): - return 1.0 if x == y else 0.0 - - -def neq_func(x, y): - return 1.0 if x != y else 0.0 - - -def lt_func(x, y): - return 1.0 if x < y else 0.0 - - -def leq_func(x, y): - return 1.0 if x <= y else 0.0 - - -def gt_func(x, y): - return 1.0 if x > y else 0.0 - - -def geq_func(x, y): - return 1.0 if x >= y else 0.0 - - -def and_func(x, y): - return 1.0 if bool(x) & bool(y) else 0.0 - - -def or_func(x, y): - return 1.0 if bool(x) | bool(y) else 0.0 - - -def xor_func(x, y): - return 1.0 if bool(x) ^ bool(y) else 0.0 - - -def not_func(x): - return 1.0 if not bool(x) else 0.0 - - -def min(x, y): - return x if x < y else y - - -def max(x, y): - return x if x > y else y - - -def sec(x): - return 1.0/cos(x) - - -def csc(x): - return 1.0/sin(x) - - -def cot(x): - return 1.0/tan(x) - - -def sech(x): - return 1.0/cosh(x) - - -def csch(x): - return 1.0/sinh(x) - - -def coth(x): - return 1.0/tanh(x) - - -def asec(x): - return acos(1.0/x) - - -def acsc(x): - return asin(1.0/x) - - -def acot(x): - return atan(1.0/x) - - -def asech(x): - one_over_x = 1.0/x - - return log(one_over_x+sqrt(one_over_x*one_over_x-1.0)) - - -def acsch(x): - one_over_x = 1.0/x - - return log(one_over_x+sqrt(one_over_x*one_over_x+1.0)) - - -def acoth(x): - one_over_x = 1.0/x - - return 0.5*log((1.0+one_over_x)/(1.0-one_over_x)) - - -def create_states_vector(): - return [nan]*STATE_COUNT - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -from nlasolver import nla_solve - - -def objective_function_0(u, f, data): - voi = data[0] - states = data[1] - rates = data[2] - variables = data[3] - - variables[205] = u[0] - variables[206] = u[1] - - f[0] = variables[205]+variables[206]+states[0]-0.0 - f[1] = variables[205]-variables[206]-(variables[207]+variables[208]) - - -def find_root_0(voi, states, rates, variables): - u = [nan]*2 - - u[0] = variables[205] - u[1] = variables[206] - - u = nla_solve(objective_function_0, u, 2, [voi, states, rates, variables]) - - variables[205] = u[0] - variables[206] = u[1] - - -def initialise_variables(states, rates, variables): - variables[1] = 1.0 - variables[2] = 2.0 - variables[6] = 3.0 - variables[18] = 4.0 - variables[179] = 5.0 - variables[180] = 6.0 - variables[182] = 7.0 - variables[205] = 1.0 - variables[206] = 2.0 - variables[184] = 123.0 - variables[185] = 123.456789 - variables[186] = 123.0e99 - variables[187] = 123.456789e99 - variables[189] = 1.0 - variables[190] = 0.0 - variables[191] = 2.71828182845905 - variables[192] = 3.14159265358979 - variables[193] = inf - variables[194] = nan - variables[207] = 1.0 - variables[208] = 3.0 - states[0] = 0.0 - - -def compute_computed_constants(variables): - variables[0] = eq_func(variables[1], variables[2]) - variables[3] = variables[1]/eq_func(variables[2], variables[2]) - variables[4] = neq_func(variables[1], variables[2]) - variables[5] = variables[1]/neq_func(variables[2], variables[6]) - variables[7] = lt_func(variables[1], variables[2]) - variables[8] = variables[1]/lt_func(variables[2], variables[6]) - variables[9] = leq_func(variables[1], variables[2]) - variables[10] = variables[1]/leq_func(variables[2], variables[6]) - variables[11] = gt_func(variables[1], variables[2]) - variables[12] = variables[1]/gt_func(variables[2], variables[6]) - variables[13] = geq_func(variables[1], variables[2]) - variables[14] = variables[1]/geq_func(variables[2], variables[6]) - variables[15] = and_func(variables[1], variables[2]) - variables[16] = and_func(variables[1], and_func(variables[2], variables[6])) - variables[17] = and_func(lt_func(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[19] = and_func(variables[1]+variables[2], gt_func(variables[6], variables[18])) - variables[20] = and_func(variables[1], gt_func(variables[2], variables[6])) - variables[21] = and_func(variables[1]-variables[2], gt_func(variables[6], variables[18])) - variables[22] = and_func(-variables[1], gt_func(variables[2], variables[6])) - variables[23] = and_func(pow(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[24] = and_func(pow(variables[1], 1.0/variables[2]), gt_func(variables[6], variables[18])) - variables[25] = and_func(lt_func(variables[1], variables[2]), variables[6]+variables[18]) - variables[26] = and_func(lt_func(variables[1], variables[2]), variables[6]) - variables[27] = and_func(lt_func(variables[1], variables[2]), variables[6]-variables[18]) - variables[28] = and_func(lt_func(variables[1], variables[2]), -variables[6]) - variables[29] = and_func(lt_func(variables[1], variables[2]), pow(variables[6], variables[18])) - variables[30] = and_func(lt_func(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])) - variables[31] = variables[1]/and_func(variables[2], variables[6]) - variables[32] = or_func(variables[1], variables[2]) - variables[33] = or_func(variables[1], or_func(variables[2], variables[6])) - variables[34] = or_func(lt_func(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[35] = or_func(variables[1]+variables[2], gt_func(variables[6], variables[18])) - variables[36] = or_func(variables[1], gt_func(variables[2], variables[6])) - variables[37] = or_func(variables[1]-variables[2], gt_func(variables[6], variables[18])) - variables[38] = or_func(-variables[1], gt_func(variables[2], variables[6])) - variables[39] = or_func(pow(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[40] = or_func(pow(variables[1], 1.0/variables[2]), gt_func(variables[6], variables[18])) - variables[41] = or_func(lt_func(variables[1], variables[2]), variables[6]+variables[18]) - variables[42] = or_func(lt_func(variables[1], variables[2]), variables[6]) - variables[43] = or_func(lt_func(variables[1], variables[2]), variables[6]-variables[18]) - variables[44] = or_func(lt_func(variables[1], variables[2]), -variables[6]) - variables[45] = or_func(lt_func(variables[1], variables[2]), pow(variables[6], variables[18])) - variables[46] = or_func(lt_func(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])) - variables[47] = variables[1]/or_func(variables[2], variables[6]) - variables[48] = xor_func(variables[1], variables[2]) - variables[49] = xor_func(variables[1], xor_func(variables[2], variables[6])) - variables[50] = xor_func(lt_func(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[51] = xor_func(variables[1]+variables[2], gt_func(variables[6], variables[18])) - variables[52] = xor_func(variables[1], gt_func(variables[2], variables[6])) - variables[53] = xor_func(variables[1]-variables[2], gt_func(variables[6], variables[18])) - variables[54] = xor_func(-variables[1], gt_func(variables[2], variables[6])) - variables[55] = xor_func(pow(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[56] = xor_func(pow(variables[1], 1.0/variables[2]), gt_func(variables[6], variables[18])) - variables[57] = xor_func(lt_func(variables[1], variables[2]), variables[6]+variables[18]) - variables[58] = xor_func(lt_func(variables[1], variables[2]), variables[6]) - variables[59] = xor_func(lt_func(variables[1], variables[2]), variables[6]-variables[18]) - variables[60] = xor_func(lt_func(variables[1], variables[2]), -variables[6]) - variables[61] = xor_func(lt_func(variables[1], variables[2]), pow(variables[6], variables[18])) - variables[62] = xor_func(lt_func(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])) - variables[63] = variables[1]/xor_func(variables[2], variables[6]) - variables[64] = not_func(variables[1]) - variables[65] = variables[1]+variables[2] - variables[66] = variables[1]+variables[2]+variables[6] - variables[67] = lt_func(variables[1], variables[2])+gt_func(variables[6], variables[18]) - variables[68] = variables[1] - variables[69] = variables[1]-variables[2] - variables[70] = lt_func(variables[1], variables[2])-gt_func(variables[6], variables[18]) - variables[71] = lt_func(variables[1], variables[2])-(variables[6]+variables[18]) - variables[72] = lt_func(variables[1], variables[2])-variables[6] - variables[73] = variables[1]-(-variables[2]) - variables[74] = variables[1]-(-variables[2]*variables[6]) - variables[75] = -variables[1] - variables[76] = -lt_func(variables[1], variables[2]) - variables[77] = variables[1]*variables[2] - variables[78] = variables[1]*variables[2]*variables[6] - variables[79] = lt_func(variables[1], variables[2])*gt_func(variables[6], variables[18]) - variables[80] = (variables[1]+variables[2])*gt_func(variables[6], variables[18]) - variables[81] = variables[1]*gt_func(variables[2], variables[6]) - variables[82] = (variables[1]-variables[2])*gt_func(variables[6], variables[18]) - variables[83] = -variables[1]*gt_func(variables[2], variables[6]) - variables[84] = lt_func(variables[1], variables[2])*(variables[6]+variables[18]) - variables[85] = lt_func(variables[1], variables[2])*variables[6] - variables[86] = lt_func(variables[1], variables[2])*(variables[6]-variables[18]) - variables[87] = lt_func(variables[1], variables[2])*-variables[6] - variables[88] = variables[1]/variables[2] - variables[89] = lt_func(variables[1], variables[2])/gt_func(variables[18], variables[6]) - variables[90] = (variables[1]+variables[2])/gt_func(variables[18], variables[6]) - variables[91] = variables[1]/gt_func(variables[6], variables[2]) - variables[92] = (variables[1]-variables[2])/gt_func(variables[18], variables[6]) - variables[93] = -variables[1]/gt_func(variables[6], variables[2]) - variables[94] = lt_func(variables[1], variables[2])/(variables[6]+variables[18]) - variables[95] = lt_func(variables[1], variables[2])/variables[6] - variables[96] = lt_func(variables[1], variables[2])/(variables[6]-variables[18]) - variables[97] = lt_func(variables[1], variables[2])/-variables[6] - variables[98] = lt_func(variables[1], variables[2])/(variables[6]*variables[18]) - variables[99] = lt_func(variables[1], variables[2])/(variables[6]/variables[18]) - variables[100] = sqrt(variables[1]) - variables[101] = pow(variables[1], 2.0) - variables[102] = pow(variables[1], 3.0) - variables[103] = pow(variables[1], variables[2]) - variables[104] = pow(leq_func(variables[1], variables[2]), geq_func(variables[6], variables[18])) - variables[105] = pow(variables[1]+variables[2], geq_func(variables[6], variables[18])) - variables[106] = pow(variables[1], geq_func(variables[2], variables[6])) - variables[107] = pow(variables[1]-variables[2], geq_func(variables[6], variables[18])) - variables[108] = pow(-variables[1], geq_func(variables[2], variables[6])) - variables[109] = pow(variables[1]*variables[2], geq_func(variables[6], variables[18])) - variables[110] = pow(variables[1]/variables[2], geq_func(variables[6], variables[18])) - variables[111] = pow(leq_func(variables[1], variables[2]), variables[6]+variables[18]) - variables[112] = pow(leq_func(variables[1], variables[2]), variables[6]) - variables[113] = pow(leq_func(variables[1], variables[2]), variables[6]-variables[18]) - variables[114] = pow(leq_func(variables[1], variables[2]), -variables[6]) - variables[115] = pow(leq_func(variables[1], variables[2]), variables[6]*variables[18]) - variables[116] = pow(leq_func(variables[1], variables[2]), variables[6]/variables[18]) - variables[117] = pow(leq_func(variables[1], variables[2]), pow(variables[6], variables[18])) - variables[118] = pow(leq_func(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])) - variables[119] = sqrt(variables[1]) - variables[120] = sqrt(variables[1]) - variables[121] = pow(variables[1], 1.0/3.0) - variables[122] = pow(variables[1], 1.0/variables[2]) - variables[123] = pow(lt_func(variables[1], variables[2]), 1.0/gt_func(variables[18], variables[6])) - variables[124] = pow(variables[1]+variables[2], 1.0/gt_func(variables[18], variables[6])) - variables[125] = pow(variables[1], 1.0/gt_func(variables[6], variables[2])) - variables[126] = pow(variables[1]-variables[2], 1.0/gt_func(variables[18], variables[6])) - variables[127] = pow(-variables[1], 1.0/gt_func(variables[6], variables[2])) - variables[128] = pow(variables[1]*variables[2], 1.0/gt_func(variables[18], variables[6])) - variables[129] = pow(variables[1]/variables[2], 1.0/gt_func(variables[18], variables[6])) - variables[130] = pow(lt_func(variables[1], variables[2]), 1.0/(variables[6]+variables[18])) - variables[131] = pow(lt_func(variables[1], variables[2]), 1.0/variables[6]) - variables[132] = pow(lt_func(variables[1], variables[2]), 1.0/(variables[6]-variables[18])) - variables[133] = pow(lt_func(variables[1], variables[2]), 1.0/-variables[6]) - variables[134] = pow(lt_func(variables[1], variables[2]), 1.0/(variables[6]*variables[18])) - variables[135] = pow(lt_func(variables[1], variables[2]), 1.0/(variables[6]/variables[18])) - variables[136] = pow(lt_func(variables[1], variables[2]), 1.0/pow(variables[6], variables[18])) - variables[137] = pow(lt_func(variables[1], variables[2]), 1.0/pow(variables[6], 1.0/variables[18])) - variables[138] = fabs(variables[1]) - variables[139] = exp(variables[1]) - variables[140] = log(variables[1]) - variables[141] = log10(variables[1]) - variables[142] = log(variables[1])/log(2.0) - variables[143] = log10(variables[1]) - variables[144] = log(variables[1])/log(variables[2]) - variables[145] = ceil(variables[1]) - variables[146] = floor(variables[1]) - variables[147] = min(variables[1], variables[2]) - variables[148] = min(variables[1], min(variables[2], variables[6])) - variables[149] = max(variables[1], variables[2]) - variables[150] = max(variables[1], max(variables[2], variables[6])) - variables[151] = fmod(variables[1], variables[2]) - variables[152] = sin(variables[1]) - variables[153] = cos(variables[1]) - variables[154] = tan(variables[1]) - variables[155] = sec(variables[1]) - variables[156] = csc(variables[1]) - variables[157] = cot(variables[1]) - variables[158] = sinh(variables[1]) - variables[159] = cosh(variables[1]) - variables[160] = tanh(variables[1]) - variables[161] = sech(variables[1]) - variables[162] = csch(variables[1]) - variables[163] = coth(variables[1]) - variables[164] = asin(variables[1]) - variables[165] = acos(variables[1]) - variables[166] = atan(variables[1]) - variables[167] = asec(variables[1]) - variables[168] = acsc(variables[1]) - variables[169] = acot(variables[1]) - variables[170] = asinh(variables[1]) - variables[171] = acosh(variables[1]) - variables[172] = atanh(variables[1]/2.0) - variables[173] = asech(variables[1]) - variables[174] = acsch(variables[1]) - variables[175] = acoth(2.0*variables[1]) - variables[176] = variables[1] if gt_func(variables[1], variables[2]) else nan - variables[177] = variables[1] if gt_func(variables[1], variables[2]) else variables[6] - variables[178] = variables[1] if gt_func(variables[1], variables[2]) else variables[6] if gt_func(variables[6], variables[18]) else variables[179] if gt_func(variables[179], variables[180]) else nan - variables[181] = variables[1] if gt_func(variables[1], variables[2]) else variables[6] if gt_func(variables[6], variables[18]) else variables[179] if gt_func(variables[179], variables[180]) else variables[182] - variables[183] = 123.0+(variables[1] if gt_func(variables[1], variables[2]) else nan) - variables[188] = variables[1] - variables[195] = and_func(variables[1], variables[2])+(variables[2] if gt_func(variables[6], variables[18]) else nan)+variables[179]+and_func(variables[180], variables[182]) - variables[196] = and_func(variables[1], variables[2])-((variables[2] if gt_func(variables[6], variables[18]) else nan)-(variables[179]-(variables[2] if gt_func(variables[6], variables[18]) else nan)))-and_func(variables[180], variables[182]) - variables[197] = and_func(variables[1], variables[2])*(variables[2] if gt_func(variables[6], variables[18]) else nan)*variables[179]*(variables[2] if gt_func(variables[6], variables[18]) else nan)*and_func(variables[180], variables[182]) - variables[198] = and_func(variables[1], variables[2])/((variables[2] if gt_func(variables[6], variables[18]) else nan)/(variables[179]/(variables[2] if gt_func(variables[6], variables[18]) else nan))) - variables[199] = and_func(or_func(variables[1], variables[2]), and_func(xor_func(variables[1], variables[2]), and_func(variables[2] if gt_func(variables[6], variables[18]) else nan, and_func(and_func(and_func(variables[179], variables[2] if gt_func(variables[6], variables[18]) else nan), xor_func(variables[1], variables[2])), or_func(variables[1], variables[2]))))) - variables[200] = or_func(and_func(variables[1], variables[2]), or_func(xor_func(variables[1], variables[2]), or_func(variables[2] if gt_func(variables[6], variables[18]) else nan, or_func(or_func(or_func(variables[179], variables[2] if gt_func(variables[6], variables[18]) else nan), xor_func(variables[1], variables[2])), and_func(variables[1], variables[2]))))) - variables[201] = xor_func(and_func(variables[1], variables[2]), xor_func(or_func(variables[1], variables[2]), xor_func(variables[2] if gt_func(variables[6], variables[18]) else nan, xor_func(xor_func(xor_func(variables[179], variables[2] if gt_func(variables[6], variables[18]) else nan), or_func(variables[1], variables[2])), and_func(variables[1], variables[2]))))) - variables[202] = pow(and_func(variables[1], variables[2]), pow(variables[2] if gt_func(variables[6], variables[18]) else nan, pow(pow(variables[179], variables[2] if gt_func(variables[6], variables[18]) else nan), and_func(variables[1], variables[2])))) - variables[203] = pow(pow(pow(and_func(variables[1], variables[2]), 1.0/pow(variables[2] if gt_func(variables[6], variables[18]) else nan, 1.0/variables[179])), 1.0/(variables[2] if gt_func(variables[6], variables[18]) else nan)), 1.0/and_func(variables[1], variables[2])) - variables[204] = -and_func(variables[1], variables[2])+-(variables[2] if gt_func(variables[6], variables[18]) else nan) - - -def compute_rates(voi, states, rates, variables): - rates[0] = 1.0 - - -def compute_variables(voi, states, rates, variables): - find_root_0(voi, states, rates, variables) diff --git a/tests/resources/coverage/generator/model.out b/tests/resources/coverage/generator/model.out index e46b733183..326fdee8d4 100644 --- a/tests/resources/coverage/generator/model.out +++ b/tests/resources/coverage/generator/model.out @@ -2,16 +2,6 @@ #include "customheaderfile.h" -double min(double x, double y) -{ - return (x < y)?x:y; -} - -double max(double x, double y) -{ - return (x > y)?x:y; -} - double sec(double x) { return 1.0/cos(x); @@ -59,30 +49,27 @@ double acot(double x) double asech(double x) { - double oneOverX = 1.0/x; - - return log(oneOverX+sqrt(oneOverX*oneOverX-1.0)); + return acosh(1.0/x); } double acsch(double x) { - double oneOverX = 1.0/x; - - return log(oneOverX+sqrt(oneOverX*oneOverX+1.0)); + return asinh(1.0/x); } double acoth(double x) { - double oneOverX = 1.0/x; - - return 0.5*log((1.0+oneOverX)/(1.0-oneOverX)); + return atanh(1.0/x); } typedef struct { double voi; double *states; double *rates; - double *variables; + double *constants; + double *computedConstants; + double *algebraic; + double *externals; } RootFindingInfo; extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), @@ -93,248 +80,231 @@ void objectiveFunction0(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; - variables[205] = u[0]; - variables[206] = u[1]; + algebraic[3] = u[0]; + algebraic[4] = u[1]; - f[0] = variables[205]+variables[206]+states[0]-0.0; - f[1] = variables[205]-variables[206]-(variables[207]+variables[208]); + f[0] = algebraic[3]+algebraic[4]+states[0]-0.0; + f[1] = algebraic[3]-algebraic[4]-(computedConstants[205]+computedConstants[206]); } -void findRoot0(double voi, double *states, double *rates, double *variables) +void findRoot0(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[2]; - u[0] = variables[205]; - u[1] = variables[206]; + u[0] = algebraic[3]; + u[1] = algebraic[4]; nlaSolve(objectiveFunction0, u, 2, &rfi); - variables[205] = u[0]; - variables[206] = u[1]; -} - -void initialiseVariables(double *states, double *rates, double *variables) -{ - variables[1] = 1.0; - variables[2] = 2.0; - variables[6] = 3.0; - variables[18] = 4.0; - variables[179] = 5.0; - variables[180] = 6.0; - variables[182] = 7.0; - variables[205] = 1.0; - variables[206] = 2.0; - variables[184] = 123.0; - variables[185] = 123.456789; - variables[186] = 123.0e99; - variables[187] = 123.456789e99; - variables[189] = 1.0; - variables[190] = 0.0; - variables[191] = 2.71828182845905; - variables[192] = 3.14159265358979; - variables[193] = INFINITY; - variables[194] = NAN; - variables[207] = 1.0; - variables[208] = 3.0; - states[0] = 0.0; + algebraic[3] = u[0]; + algebraic[4] = u[1]; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[0] = variables[1] == variables[2]; - variables[3] = variables[1]/(variables[2] == variables[2]); - variables[4] = variables[1] != variables[2]; - variables[5] = variables[1]/(variables[2] != variables[6]); - variables[7] = variables[1] < variables[2]; - variables[8] = variables[1]/(variables[2] < variables[6]); - variables[9] = variables[1] <= variables[2]; - variables[10] = variables[1]/(variables[2] <= variables[6]); - variables[11] = variables[1] > variables[2]; - variables[12] = variables[1]/(variables[2] > variables[6]); - variables[13] = variables[1] >= variables[2]; - variables[14] = variables[1]/(variables[2] >= variables[6]); - variables[15] = variables[1] && variables[2]; - variables[16] = variables[1] && variables[2] && variables[6]; - variables[17] = (variables[1] < variables[2]) && (variables[6] > variables[18]); - variables[19] = (variables[1]+variables[2]) && (variables[6] > variables[18]); - variables[20] = variables[1] && (variables[2] > variables[6]); - variables[21] = (variables[1]-variables[2]) && (variables[6] > variables[18]); - variables[22] = -variables[1] && (variables[2] > variables[6]); - variables[23] = (variables[1]^^variables[2]) && (variables[6] > variables[18]); - variables[24] = (variables[1]^^(1.0/variables[2])) && (variables[6] > variables[18]); - variables[25] = (variables[1] < variables[2]) && (variables[6]+variables[18]); - variables[26] = (variables[1] < variables[2]) && variables[6]; - variables[27] = (variables[1] < variables[2]) && (variables[6]-variables[18]); - variables[28] = (variables[1] < variables[2]) && -variables[6]; - variables[29] = (variables[1] < variables[2]) && (variables[6]^^variables[18]); - variables[30] = (variables[1] < variables[2]) && (variables[6]^^(1.0/variables[18])); - variables[31] = variables[1]/(variables[2] && variables[6]); - variables[32] = variables[1] || variables[2]; - variables[33] = variables[1] || variables[2] || variables[6]; - variables[34] = (variables[1] < variables[2]) || (variables[6] > variables[18]); - variables[35] = (variables[1]+variables[2]) || (variables[6] > variables[18]); - variables[36] = variables[1] || (variables[2] > variables[6]); - variables[37] = (variables[1]-variables[2]) || (variables[6] > variables[18]); - variables[38] = -variables[1] || (variables[2] > variables[6]); - variables[39] = (variables[1]^^variables[2]) || (variables[6] > variables[18]); - variables[40] = (variables[1]^^(1.0/variables[2])) || (variables[6] > variables[18]); - variables[41] = (variables[1] < variables[2]) || (variables[6]+variables[18]); - variables[42] = (variables[1] < variables[2]) || variables[6]; - variables[43] = (variables[1] < variables[2]) || (variables[6]-variables[18]); - variables[44] = (variables[1] < variables[2]) || -variables[6]; - variables[45] = (variables[1] < variables[2]) || (variables[6]^^variables[18]); - variables[46] = (variables[1] < variables[2]) || (variables[6]^^(1.0/variables[18])); - variables[47] = variables[1]/(variables[2] || variables[6]); - variables[48] = variables[1]^variables[2]; - variables[49] = variables[1]^variables[2]^variables[6]; - variables[50] = (variables[1] < variables[2])^(variables[6] > variables[18]); - variables[51] = (variables[1]+variables[2])^(variables[6] > variables[18]); - variables[52] = variables[1]^(variables[2] > variables[6]); - variables[53] = (variables[1]-variables[2])^(variables[6] > variables[18]); - variables[54] = -variables[1]^(variables[2] > variables[6]); - variables[55] = (variables[1]^^variables[2])^(variables[6] > variables[18]); - variables[56] = (variables[1]^^(1.0/variables[2]))^(variables[6] > variables[18]); - variables[57] = (variables[1] < variables[2])^(variables[6]+variables[18]); - variables[58] = (variables[1] < variables[2])^variables[6]; - variables[59] = (variables[1] < variables[2])^(variables[6]-variables[18]); - variables[60] = (variables[1] < variables[2])^-variables[6]; - variables[61] = (variables[1] < variables[2])^(variables[6]^^variables[18]); - variables[62] = (variables[1] < variables[2])^(variables[6]^^(1.0/variables[18])); - variables[63] = variables[1]/(variables[2]^variables[6]); - variables[64] = !variables[1]; - variables[65] = variables[1]+variables[2]; - variables[66] = variables[1]+variables[2]+variables[6]; - variables[67] = (variables[1] < variables[2])+(variables[6] > variables[18]); - variables[68] = variables[1]; - variables[69] = variables[1]-variables[2]; - variables[70] = (variables[1] < variables[2])-(variables[6] > variables[18]); - variables[71] = (variables[1] < variables[2])-(variables[6]+variables[18]); - variables[72] = (variables[1] < variables[2])-variables[6]; - variables[73] = variables[1]-(-variables[2]); - variables[74] = variables[1]-(-variables[2]*variables[6]); - variables[75] = -variables[1]; - variables[76] = -(variables[1] < variables[2]); - variables[77] = variables[1]*variables[2]; - variables[78] = variables[1]*variables[2]*variables[6]; - variables[79] = (variables[1] < variables[2])*(variables[6] > variables[18]); - variables[80] = (variables[1]+variables[2])*(variables[6] > variables[18]); - variables[81] = variables[1]*(variables[2] > variables[6]); - variables[82] = (variables[1]-variables[2])*(variables[6] > variables[18]); - variables[83] = -variables[1]*(variables[2] > variables[6]); - variables[84] = (variables[1] < variables[2])*(variables[6]+variables[18]); - variables[85] = (variables[1] < variables[2])*variables[6]; - variables[86] = (variables[1] < variables[2])*(variables[6]-variables[18]); - variables[87] = (variables[1] < variables[2])*-variables[6]; - variables[88] = variables[1]/variables[2]; - variables[89] = (variables[1] < variables[2])/(variables[18] > variables[6]); - variables[90] = (variables[1]+variables[2])/(variables[18] > variables[6]); - variables[91] = variables[1]/(variables[6] > variables[2]); - variables[92] = (variables[1]-variables[2])/(variables[18] > variables[6]); - variables[93] = -variables[1]/(variables[6] > variables[2]); - variables[94] = (variables[1] < variables[2])/(variables[6]+variables[18]); - variables[95] = (variables[1] < variables[2])/variables[6]; - variables[96] = (variables[1] < variables[2])/(variables[6]-variables[18]); - variables[97] = (variables[1] < variables[2])/-variables[6]; - variables[98] = (variables[1] < variables[2])/(variables[6]*variables[18]); - variables[99] = (variables[1] < variables[2])/(variables[6]/variables[18]); - variables[100] = sqrt(variables[1]); - variables[101] = sqr(variables[1]); - variables[102] = variables[1]^^3.0; - variables[103] = variables[1]^^variables[2]; - variables[104] = (variables[1] <= variables[2])^^(variables[6] >= variables[18]); - variables[105] = (variables[1]+variables[2])^^(variables[6] >= variables[18]); - variables[106] = variables[1]^^(variables[2] >= variables[6]); - variables[107] = (variables[1]-variables[2])^^(variables[6] >= variables[18]); - variables[108] = (-variables[1])^^(variables[2] >= variables[6]); - variables[109] = (variables[1]*variables[2])^^(variables[6] >= variables[18]); - variables[110] = (variables[1]/variables[2])^^(variables[6] >= variables[18]); - variables[111] = (variables[1] <= variables[2])^^(variables[6]+variables[18]); - variables[112] = (variables[1] <= variables[2])^^variables[6]; - variables[113] = (variables[1] <= variables[2])^^variables[6]-variables[18]; - variables[114] = (variables[1] <= variables[2])^^-variables[6]; - variables[115] = (variables[1] <= variables[2])^^(variables[6]*variables[18]); - variables[116] = (variables[1] <= variables[2])^^(variables[6]/variables[18]); - variables[117] = (variables[1] <= variables[2])^^(variables[6]^^variables[18]); - variables[118] = (variables[1] <= variables[2])^^(variables[6]^^(1.0/variables[18])); - variables[119] = sqrt(variables[1]); - variables[120] = sqrt(variables[1]); - variables[121] = variables[1]^^(1.0/3.0); - variables[122] = variables[1]^^(1.0/variables[2]); - variables[123] = (variables[1] < variables[2])^^(1.0/(variables[18] > variables[6])); - variables[124] = (variables[1]+variables[2])^^(1.0/(variables[18] > variables[6])); - variables[125] = variables[1]^^(1.0/(variables[6] > variables[2])); - variables[126] = (variables[1]-variables[2])^^(1.0/(variables[18] > variables[6])); - variables[127] = (-variables[1])^^(1.0/(variables[6] > variables[2])); - variables[128] = (variables[1]*variables[2])^^(1.0/(variables[18] > variables[6])); - variables[129] = (variables[1]/variables[2])^^(1.0/(variables[18] > variables[6])); - variables[130] = (variables[1] < variables[2])^^(1.0/(variables[6]+variables[18])); - variables[131] = (variables[1] < variables[2])^^(1.0/variables[6]); - variables[132] = (variables[1] < variables[2])^^(1.0/(variables[6]-variables[18])); - variables[133] = (variables[1] < variables[2])^^(1.0/(-variables[6])); - variables[134] = (variables[1] < variables[2])^^(1.0/(variables[6]*variables[18])); - variables[135] = (variables[1] < variables[2])^^(1.0/(variables[6]/variables[18])); - variables[136] = (variables[1] < variables[2])^^(1.0/(variables[6]^^variables[18])); - variables[137] = (variables[1] < variables[2])^^(1.0/(variables[6]^^(1.0/variables[18]))); - variables[138] = fabs(variables[1]); - variables[139] = exp(variables[1]); - variables[140] = log(variables[1]); - variables[141] = log10(variables[1]); - variables[142] = log(variables[1])/log(2.0); - variables[143] = log10(variables[1]); - variables[144] = log(variables[1])/log(variables[2]); - variables[145] = ceil(variables[1]); - variables[146] = floor(variables[1]); - variables[147] = min(variables[1], variables[2]); - variables[148] = min(variables[1], min(variables[2], variables[6])); - variables[149] = max(variables[1], variables[2]); - variables[150] = max(variables[1], max(variables[2], variables[6])); - variables[151] = fmod(variables[1], variables[2]); - variables[152] = sin(variables[1]); - variables[153] = cos(variables[1]); - variables[154] = tan(variables[1]); - variables[155] = sec(variables[1]); - variables[156] = csc(variables[1]); - variables[157] = cot(variables[1]); - variables[158] = sinh(variables[1]); - variables[159] = cosh(variables[1]); - variables[160] = tanh(variables[1]); - variables[161] = sech(variables[1]); - variables[162] = csch(variables[1]); - variables[163] = coth(variables[1]); - variables[164] = asin(variables[1]); - variables[165] = acos(variables[1]); - variables[166] = atan(variables[1]); - variables[167] = asec(variables[1]); - variables[168] = acsc(variables[1]); - variables[169] = acot(variables[1]); - variables[170] = asinh(variables[1]); - variables[171] = acosh(variables[1]); - variables[172] = atanh(variables[1]/2.0); - variables[173] = asech(variables[1]); - variables[174] = acsch(variables[1]); - variables[175] = acoth(2.0*variables[1]); - variables[176] = piecewise(variables[1] > variables[2], variables[1], NAN); - variables[177] = piecewise(variables[1] > variables[2], variables[1], variables[6]); - variables[178] = piecewise(variables[1] > variables[2], variables[1], piecewise(variables[6] > variables[18], variables[6], piecewise(variables[179] > variables[180], variables[179], NAN))); - variables[181] = piecewise(variables[1] > variables[2], variables[1], piecewise(variables[6] > variables[18], variables[6], piecewise(variables[179] > variables[180], variables[179], variables[182]))); - variables[183] = 123.0+piecewise(variables[1] > variables[2], variables[1], NAN); - variables[188] = variables[1]; - variables[195] = (variables[1] && variables[2])+piecewise(variables[6] > variables[18], variables[2], NAN)+variables[179]+(variables[180] && variables[182]); - variables[196] = (variables[1] && variables[2])-(piecewise(variables[6] > variables[18], variables[2], NAN)-(variables[179]-piecewise(variables[6] > variables[18], variables[2], NAN)))-(variables[180] && variables[182]); - variables[197] = (variables[1] && variables[2])*piecewise(variables[6] > variables[18], variables[2], NAN)*variables[179]*piecewise(variables[6] > variables[18], variables[2], NAN)*(variables[180] && variables[182]); - variables[198] = (variables[1] && variables[2])/(piecewise(variables[6] > variables[18], variables[2], NAN)/(variables[179]/piecewise(variables[6] > variables[18], variables[2], NAN))); - variables[199] = (variables[1] || variables[2]) && (variables[1]^variables[2]) && piecewise(variables[6] > variables[18], variables[2], NAN) && variables[179] && piecewise(variables[6] > variables[18], variables[2], NAN) && (variables[1]^variables[2]) && (variables[1] || variables[2]); - variables[200] = (variables[1] && variables[2]) || (variables[1]^variables[2]) || piecewise(variables[6] > variables[18], variables[2], NAN) || variables[179] || piecewise(variables[6] > variables[18], variables[2], NAN) || (variables[1]^variables[2]) || (variables[1] && variables[2]); - variables[201] = (variables[1] && variables[2])^(variables[1] || variables[2])^piecewise(variables[6] > variables[18], variables[2], NAN)^variables[179]^piecewise(variables[6] > variables[18], variables[2], NAN)^(variables[1] || variables[2])^(variables[1] && variables[2]); - variables[202] = (variables[1] && variables[2])^^(piecewise(variables[6] > variables[18], variables[2], NAN)^^(variables[179]^^piecewise(variables[6] > variables[18], variables[2], NAN)^^(variables[1] && variables[2]))); - variables[203] = (variables[1] && variables[2])^^(1.0/(piecewise(variables[6] > variables[18], variables[2], NAN)^^(1.0/variables[179])))^^(1.0/piecewise(variables[6] > variables[18], variables[2], NAN))^^(1.0/(variables[1] && variables[2])); - variables[204] = -(variables[1] && variables[2])+-piecewise(variables[6] > variables[18], variables[2], NAN); + computedConstants[0] = constants[0] == constants[1]; + computedConstants[1] = constants[0]/(constants[1] == constants[1]); + computedConstants[2] = constants[0] != constants[1]; + computedConstants[3] = constants[0]/(constants[1] != constants[2]); + computedConstants[4] = constants[0] < constants[1]; + computedConstants[5] = constants[0]/(constants[1] < constants[2]); + computedConstants[6] = constants[0] <= constants[1]; + computedConstants[7] = constants[0]/(constants[1] <= constants[2]); + computedConstants[8] = constants[0] > constants[1]; + computedConstants[9] = constants[0]/(constants[2] > constants[1]); + computedConstants[10] = constants[0] >= constants[1]; + computedConstants[11] = constants[0]/(constants[2] >= constants[1]); + computedConstants[12] = constants[0] && constants[1]; + computedConstants[13] = constants[0] && constants[1] && constants[2]; + computedConstants[14] = (constants[0] < constants[1]) && (constants[2] > constants[3]); + computedConstants[15] = (constants[0]+constants[1]) && (constants[2] > constants[3]); + computedConstants[16] = constants[0] && (constants[1] > constants[2]); + computedConstants[17] = (constants[0]-constants[1]) && (constants[2] > constants[3]); + computedConstants[18] = -constants[0] && (constants[1] > constants[2]); + computedConstants[19] = (constants[0]^^constants[1]) && (constants[2] > constants[3]); + computedConstants[20] = (constants[0]^^(1.0/constants[1])) && (constants[2] > constants[3]); + computedConstants[21] = (constants[0] < constants[1]) && (constants[2]+constants[3]); + computedConstants[22] = (constants[0] < constants[1]) && constants[2]; + computedConstants[23] = (constants[0] < constants[1]) && (constants[2]-constants[3]); + computedConstants[24] = (constants[0] < constants[1]) && -constants[2]; + computedConstants[25] = (constants[0] < constants[1]) && (constants[2]^^constants[3]); + computedConstants[26] = (constants[0] < constants[1]) && (constants[2]^^(1.0/constants[3])); + computedConstants[27] = constants[0]/(constants[1] && constants[2]); + computedConstants[28] = (constants[0] < constants[1]) || (constants[2] > constants[3]); + computedConstants[29] = (constants[0]+constants[1]) || (constants[2] > constants[3]); + computedConstants[30] = constants[0] || (constants[1] > constants[2]); + computedConstants[31] = (constants[0]-constants[1]) || (constants[2] > constants[3]); + computedConstants[32] = -constants[0] || (constants[1] > constants[2]); + computedConstants[33] = (constants[0]^^constants[1]) || (constants[2] > constants[3]); + computedConstants[34] = (constants[0]^^(1.0/constants[1])) || (constants[2] > constants[3]); + computedConstants[35] = (constants[0] < constants[1]) || (constants[2]+constants[3]); + computedConstants[36] = (constants[0] < constants[1]) || constants[2]; + computedConstants[37] = (constants[0] < constants[1]) || (constants[2]-constants[3]); + computedConstants[38] = (constants[0] < constants[1]) || -constants[2]; + computedConstants[39] = (constants[0] < constants[1]) || (constants[2]^^constants[3]); + computedConstants[40] = (constants[0] < constants[1]) || (constants[2]^^(1.0/constants[3])); + computedConstants[41] = constants[0]/(constants[1] || constants[2]); + computedConstants[42] = constants[0]^constants[1]; + computedConstants[43] = constants[0]^constants[1]^constants[2]; + computedConstants[44] = (constants[0] < constants[1])^(constants[2] > constants[3]); + computedConstants[45] = (constants[0]+constants[1])^(constants[2] > constants[3]); + computedConstants[46] = constants[0]^(constants[1] > constants[2]); + computedConstants[47] = (constants[0]-constants[1])^(constants[2] > constants[3]); + computedConstants[48] = -constants[0]^(constants[1] > constants[2]); + computedConstants[49] = (constants[0]^^constants[1])^(constants[2] > constants[3]); + computedConstants[50] = (constants[0]^^(1.0/constants[1]))^(constants[2] > constants[3]); + computedConstants[51] = (constants[0] < constants[1])^(constants[2]+constants[3]); + computedConstants[52] = (constants[0] < constants[1])^constants[2]; + computedConstants[53] = (constants[0] < constants[1])^(constants[2]-constants[3]); + computedConstants[54] = (constants[0] < constants[1])^-constants[2]; + computedConstants[55] = (constants[0] < constants[1])^(constants[2]^^constants[3]); + computedConstants[56] = (constants[0] < constants[1])^(constants[2]^^(1.0/constants[3])); + computedConstants[57] = !constants[0]; + computedConstants[58] = constants[0]+constants[1]+constants[2]; + computedConstants[59] = (constants[0] < constants[1])+(constants[2] > constants[3]); + computedConstants[60] = constants[0]; + computedConstants[61] = constants[0]-constants[1]; + computedConstants[62] = (constants[0] < constants[1])-(constants[2] > constants[3]); + computedConstants[63] = (constants[0] < constants[1])-(constants[2]+constants[3]); + computedConstants[64] = (constants[0] < constants[1])-constants[2]; + computedConstants[65] = constants[0]-(-constants[1]); + computedConstants[66] = constants[0]-(-constants[1]*constants[2]); + computedConstants[67] = -constants[0]; + computedConstants[68] = -(constants[0] < constants[1]); + computedConstants[69] = constants[0]*constants[1]; + computedConstants[70] = constants[0]*constants[1]*constants[2]; + computedConstants[71] = (constants[0] < constants[1])*(constants[2] > constants[3]); + computedConstants[72] = (constants[0]+constants[1])*(constants[2] > constants[3]); + computedConstants[73] = constants[0]*(constants[1] > constants[2]); + computedConstants[74] = (constants[0]-constants[1])*(constants[2] > constants[3]); + computedConstants[75] = -constants[0]*(constants[1] > constants[2]); + computedConstants[76] = (constants[0] < constants[1])*(constants[2]+constants[3]); + computedConstants[77] = (constants[0] < constants[1])*constants[2]; + computedConstants[78] = (constants[0] < constants[1])*(constants[2]-constants[3]); + computedConstants[79] = (constants[0] < constants[1])*-constants[2]; + computedConstants[80] = constants[0]/constants[1]; + computedConstants[81] = (constants[0] < constants[1])/(constants[3] > constants[2]); + computedConstants[82] = (constants[0]+constants[1])/(constants[3] > constants[2]); + computedConstants[83] = constants[0]/(constants[2] > constants[1]); + computedConstants[84] = (constants[0]-constants[1])/(constants[3] > constants[2]); + computedConstants[85] = -constants[0]/(constants[2] > constants[1]); + computedConstants[86] = (constants[0] < constants[1])/(constants[2]+constants[3]); + computedConstants[87] = (constants[0] < constants[1])/constants[2]; + computedConstants[88] = (constants[0] < constants[1])/(constants[2]-constants[3]); + computedConstants[89] = (constants[0] < constants[1])/-constants[2]; + computedConstants[90] = (constants[0] < constants[1])/(constants[2]*constants[3]); + computedConstants[91] = (constants[0] < constants[1])/(constants[2]/constants[3]); + computedConstants[92] = sqrt(constants[0]); + computedConstants[93] = sqr(constants[0]); + computedConstants[94] = constants[0]^^3.0; + computedConstants[95] = constants[0]^^constants[1]; + computedConstants[96] = (constants[0] <= constants[1])^^(constants[2] >= constants[3]); + computedConstants[97] = (constants[0]+constants[1])^^(constants[2] >= constants[3]); + computedConstants[98] = constants[0]^^(constants[1] >= constants[2]); + computedConstants[99] = (constants[0]-constants[1])^^(constants[2] >= constants[3]); + computedConstants[100] = (-constants[0])^^(constants[1] >= constants[2]); + computedConstants[101] = (constants[0]*constants[1])^^(constants[2] >= constants[3]); + computedConstants[102] = (constants[0]/constants[1])^^(constants[2] >= constants[3]); + computedConstants[103] = (constants[0] <= constants[1])^^(constants[2]+constants[3]); + computedConstants[104] = (constants[0] <= constants[1])^^constants[2]; + computedConstants[105] = (constants[0] <= constants[1])^^constants[2]-constants[3]; + computedConstants[106] = (constants[0] <= constants[1])^^-constants[2]; + computedConstants[107] = (constants[0] <= constants[1])^^(constants[2]*constants[3]); + computedConstants[108] = (constants[0] <= constants[1])^^(constants[2]/constants[3]); + computedConstants[109] = (constants[0] <= constants[1])^^(constants[2]^^constants[3]); + computedConstants[110] = (constants[0] <= constants[1])^^(constants[2]^^(1.0/constants[3])); + computedConstants[111] = sqrt(constants[0]); + computedConstants[112] = sqrt(constants[0]); + computedConstants[113] = sqr(constants[0]); + computedConstants[114] = constants[0]^^(1.0/3.0); + computedConstants[115] = constants[0]^^(1.0/constants[1]); + computedConstants[116] = (constants[0] < constants[1])^^(1.0/(constants[3] > constants[2])); + computedConstants[117] = (constants[0]+constants[1])^^(1.0/(constants[3] > constants[2])); + computedConstants[118] = constants[0]^^(1.0/(constants[2] > constants[1])); + computedConstants[119] = (constants[0]-constants[1])^^(1.0/(constants[3] > constants[2])); + computedConstants[120] = (-constants[0])^^(1.0/(constants[2] > constants[1])); + computedConstants[121] = (constants[0]*constants[1])^^(1.0/(constants[3] > constants[2])); + computedConstants[122] = (constants[0]/constants[1])^^(1.0/(constants[3] > constants[2])); + computedConstants[123] = (constants[0] < constants[1])^^(1.0/(constants[2]+constants[3])); + computedConstants[124] = (constants[0] < constants[1])^^(1.0/constants[2]); + computedConstants[125] = (constants[0] < constants[1])^^(1.0/(constants[2]-constants[3])); + computedConstants[126] = (constants[0] < constants[1])^^(1.0/(-constants[2])); + computedConstants[127] = (constants[0] < constants[1])^^(1.0/(constants[2]*constants[3])); + computedConstants[128] = (constants[0] < constants[1])^^(1.0/(constants[2]/constants[3])); + computedConstants[129] = (constants[0] < constants[1])^^(1.0/(constants[2]^^constants[3])); + computedConstants[130] = (constants[0] < constants[1])^^(1.0/(constants[2]^^(1.0/constants[3]))); + computedConstants[131] = fabs(constants[0]); + computedConstants[132] = exp(constants[0]); + computedConstants[133] = log(constants[0]); + computedConstants[134] = log10(constants[0]); + computedConstants[135] = log(constants[0])/log(2.0); + computedConstants[136] = log10(constants[0]); + computedConstants[137] = log(constants[0])/log(constants[1]); + computedConstants[138] = ceil(constants[0]); + computedConstants[139] = floor(constants[0]); + computedConstants[140] = fmin(constants[0], constants[1]); + computedConstants[141] = fmin(constants[0], fmin(constants[1], constants[2])); + computedConstants[142] = fmax(constants[0], constants[1]); + computedConstants[143] = fmax(constants[0], fmax(constants[1], constants[2])); + computedConstants[144] = fmod(constants[0], constants[1]); + computedConstants[145] = sin(constants[0]); + computedConstants[146] = cos(constants[0]); + computedConstants[147] = tan(constants[0]); + computedConstants[148] = sec(constants[0]); + computedConstants[149] = csc(constants[0]); + computedConstants[150] = cot(constants[0]); + computedConstants[151] = sinh(constants[0]); + computedConstants[152] = cosh(constants[0]); + computedConstants[153] = tanh(constants[0]); + computedConstants[154] = sech(constants[0]); + computedConstants[155] = csch(constants[0]); + computedConstants[156] = coth(constants[0]); + computedConstants[157] = asin(constants[0]); + computedConstants[158] = acos(constants[0]); + computedConstants[159] = atan(constants[0]); + computedConstants[160] = asec(constants[0]); + computedConstants[161] = acsc(constants[0]); + computedConstants[162] = acot(constants[0]); + computedConstants[163] = asinh(constants[0]); + computedConstants[164] = acosh(constants[0]); + computedConstants[165] = atanh(constants[0]/2.0); + computedConstants[166] = asech(constants[0]); + computedConstants[167] = acsch(constants[0]); + computedConstants[168] = acoth(2.0*constants[0]); + computedConstants[170] = piecewise(constants[0] > constants[1], constants[0], NAN); + computedConstants[171] = piecewise(constants[0] < constants[1], constants[0], NAN); + computedConstants[172] = constants[0]; + computedConstants[173] = piecewise(constants[0] > constants[1], constants[0], constants[2]); + computedConstants[174] = piecewise(constants[0] > constants[1], constants[0], piecewise(constants[2] > constants[3], constants[2], piecewise(constants[4] > constants[5], constants[4], NAN))); + computedConstants[175] = piecewise(constants[0] < constants[1], constants[0], piecewise(constants[2] > constants[3], constants[2], piecewise(constants[4] > constants[5], constants[4], NAN))); + computedConstants[176] = piecewise(constants[0] > constants[1], constants[0], piecewise(constants[2] > constants[3], constants[2], piecewise(constants[4] > constants[5], constants[4], constants[6]))); + computedConstants[177] = 123.0+piecewise(constants[0] > constants[1], constants[0], NAN); + computedConstants[178] = 123.0+piecewise(constants[0] < constants[1], constants[0], NAN); + computedConstants[183] = constants[0]; + computedConstants[190] = (constants[0] && constants[1])+piecewise(constants[2] > constants[3], constants[1], NAN)+constants[4]+(constants[5] && constants[6]); + computedConstants[191] = (constants[0] && constants[1])+piecewise(constants[2] < constants[3], constants[1], NAN)+constants[4]+(constants[5] && constants[6]); + computedConstants[192] = (constants[0] && constants[1])-(piecewise(constants[2] > constants[3], constants[1], NAN)-(constants[4]-piecewise(constants[2] > constants[3], constants[1], NAN)))-(constants[5] && constants[6]); + computedConstants[193] = (constants[0] && constants[1])-(piecewise(constants[2] < constants[3], constants[1], NAN)-(constants[4]-piecewise(constants[2] < constants[3], constants[1], NAN)))-(constants[5] && constants[6]); + computedConstants[194] = (constants[0] && constants[1])*piecewise(constants[2] > constants[3], constants[1], NAN)*constants[4]*piecewise(constants[2] > constants[3], constants[1], NAN)*(constants[5] && constants[6]); + computedConstants[195] = (constants[0] && constants[1])*piecewise(constants[2] < constants[3], constants[1], NAN)*constants[4]*piecewise(constants[2] < constants[3], constants[1], NAN)*(constants[5] && constants[6]); + computedConstants[196] = (constants[0] && constants[1])/(piecewise(constants[2] > constants[3], constants[1], NAN)/(constants[4]/piecewise(constants[2] > constants[3], constants[1], NAN))); + computedConstants[197] = (constants[0] && constants[1])/(piecewise(constants[2] < constants[3], constants[1], NAN)/(constants[4]/piecewise(constants[2] < constants[3], constants[1], NAN))); + computedConstants[198] = (constants[0] || constants[1]) && (constants[0]^constants[1]) && piecewise(constants[2] > constants[3], constants[1], NAN) && constants[4] && piecewise(constants[2] > constants[3], constants[1], NAN) && (constants[0]^constants[1]) && (constants[0] || constants[1]); + computedConstants[199] = (constants[0] && constants[1]) || (constants[0]^constants[1]) || piecewise(constants[2] > constants[3], constants[1], NAN) || constants[4] || piecewise(constants[2] > constants[3], constants[1], NAN) || (constants[0]^constants[1]) || (constants[0] && constants[1]); + computedConstants[200] = (constants[0] && constants[1])^(constants[0] || constants[1])^piecewise(constants[2] > constants[3], constants[1], NAN)^constants[4]^piecewise(constants[2] > constants[3], constants[1], NAN)^(constants[0] || constants[1])^(constants[0] && constants[1]); + computedConstants[201] = (constants[0] && constants[1])^^(piecewise(constants[2] > constants[3], constants[1], NAN)^^(constants[4]^^piecewise(constants[2] > constants[3], constants[1], NAN)^^(constants[0] && constants[1]))); + computedConstants[202] = (constants[0] && constants[1])^^(1.0/(piecewise(constants[2] > constants[3], constants[1], NAN)^^(1.0/constants[4])))^^(1.0/piecewise(constants[2] > constants[3], constants[1], NAN))^^(1.0/(constants[0] && constants[1])); + computedConstants[203] = -(constants[0] && constants[1])+-piecewise(constants[2] > constants[3], constants[1], NAN); + computedConstants[204] = -(constants[0] && constants[1])+-piecewise(constants[2] < constants[3], constants[1], NAN); } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { rates[0] = 1.0; } diff --git a/tests/resources/coverage/generator/model.py b/tests/resources/coverage/generator/model.py index e59b58a9aa..acff4123de 100644 --- a/tests/resources/coverage/generator/model.py +++ b/tests/resources/coverage/generator/model.py @@ -4,237 +4,251 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 209 +CONSTANT_COUNT = 7 +COMPUTED_CONSTANT_COUNT = 207 +ALGEBRAIC_COUNT = 5 +EXTERNAL_COUNT = 1 +VOI_INFO = {"name": "t", "units": "second", "component": "my_component"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_component"} +] +CONSTANT_INFO = [ + {"name": "m", "units": "dimensionless", "component": "my_component"}, + {"name": "n", "units": "dimensionless", "component": "my_component"}, + {"name": "o", "units": "dimensionless", "component": "my_component"}, + {"name": "p", "units": "dimensionless", "component": "my_component"}, + {"name": "q", "units": "dimensionless", "component": "my_component"}, + {"name": "r", "units": "dimensionless", "component": "my_component"}, + {"name": "s", "units": "dimensionless", "component": "my_component"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "my_component", "type": VariableType.VARIABLE_OF_INTEGRATION} +COMPUTED_CONSTANT_INFO = [ + {"name": "eqnEq", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnEqCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNeq", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNeqCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLt", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLtCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLeq", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLeqCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnGt", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnGtCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnGeq", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnGeqCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAnd", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXor", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPlusMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPlusParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPlusUnary", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinus", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusParenthesesPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusParenthesesPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusParenthesesDirectUnaryMinus", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusParenthesesIndirectUnaryMinus", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusUnary", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusUnaryParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerSqrt", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerSqr", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerCube", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerCi", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootSqrt", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootSqrtOther", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootSqr", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootCube", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootCi", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAbs", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnExp", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLn", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLog", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLog2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLog10", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLogCi", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCeiling", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnFloor", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMin", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMax", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMaxMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRem", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnSin", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCos", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTan", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnSec", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCsc", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnSinh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCosh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTanh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnSech", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCsch", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoth", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArcsin", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccos", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArctan", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArcsec", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccsc", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArcsinh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccosh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArctanh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArcsech", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccsch", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccoth", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewise", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePiece", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePiece2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewiseOtherwise", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePieceOtherwise", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePiecePiecePiece", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePiecePiecePiece2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePiecePiecePieceOtherwise", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnWithPiecewise", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnWithPiecewise2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCnInteger", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCnDouble", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCnIntegerWithExponent", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCnDoubleWithExponent", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCi", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTrue", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnFalse", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnExponentiale", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPi", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnInfinity", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNotanumber", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForPlusOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForPlusOperator2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForMinusOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForMinusOperator2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForTimesOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForTimesOperator2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForDivideOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForDivideOperator2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForAndOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForOrOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForXorOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForPowerOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForRootOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForMinusUnary", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForMinusUnary2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnComputedConstant1", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnComputedConstant2", "units": "dimensionless", "component": "my_component"} +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_component", "type": VariableType.STATE} +ALGEBRAIC_INFO = [ + {"name": "eqnOr", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNlaVariable1", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNlaVariable2", "units": "dimensionless", "component": "my_component"} ] -VARIABLE_INFO = [ - {"name": "eqnEq", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "m", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "n", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "eqnEqCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnNeq", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnNeqCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "o", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "eqnLt", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLtCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLeq", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLeqCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnGt", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnGtCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnGeq", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnGeqCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAnd", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "p", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "eqnAndParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesLeftPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesLeftRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndParenthesesRightRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAndCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOr", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesLeftRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrParenthesesRightRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnOrCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXor", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesLeftRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorParenthesesRightRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnXorCoverageParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnNot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPlus", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPlusMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPlusParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPlusUnary", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinus", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusParenthesesPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusParenthesesPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusParenthesesDirectUnaryMinus", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusParenthesesIndirectUnaryMinus", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusUnary", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinusUnaryParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTimesParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnDivideParenthesesRightDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerSqrt", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerSqr", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerCube", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerCi", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesLeftDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPowerParenthesesRightRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootSqrt", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootSqrtOther", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootCube", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootCi", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParentheses", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesLeftDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightTimes", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightDivide", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightPower", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRootParenthesesRightRoot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnAbs", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnExp", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLn", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLog", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLog2", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLog10", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnLogCi", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCeiling", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnFloor", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMin", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMinMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMax", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnMaxMultiple", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnRem", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnSin", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCos", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTan", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnSec", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCsc", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnSinh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCosh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTanh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnSech", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCsch", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoth", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArcsin", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccos", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArctan", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArcsec", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccsc", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccot", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArcsinh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccosh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArctanh", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArcsech", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccsch", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnArccoth", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPiecewisePiece", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPiecewisePieceOtherwise", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPiecewisePiecePiecePiece", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "q", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "r", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "eqnPiecewisePiecePiecePieceOtherwise", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "s", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT}, - {"name": "eqnWithPiecewise", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCnInteger", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCnDouble", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCnIntegerWithExponent", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCnDoubleWithExponent", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCi", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnTrue", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnFalse", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnExponentiale", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnPi", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnInfinity", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnNotanumber", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForPlusOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForMinusOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForTimesOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForDivideOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForAndOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForOrOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForXorOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForPowerOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForRootOperator", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnCoverageForMinusUnary", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnNlaVariable1", "units": "dimensionless", "component": "my_component", "type": VariableType.ALGEBRAIC}, - {"name": "eqnNlaVariable2", "units": "dimensionless", "component": "my_component", "type": VariableType.ALGEBRAIC}, - {"name": "eqnComputedConstant1", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "eqnComputedConstant2", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT} +EXTERNAL_INFO = [ + {"name": "eqnPlus", "units": "dimensionless", "component": "my_component"} ] @@ -323,29 +337,35 @@ def acot(x): def asech(x): - one_over_x = 1.0/x - - return log(one_over_x+sqrt(one_over_x*one_over_x-1.0)) + return acosh(1.0/x) def acsch(x): - one_over_x = 1.0/x - - return log(one_over_x+sqrt(one_over_x*one_over_x+1.0)) + return asinh(1.0/x) def acoth(x): - one_over_x = 1.0/x - - return 0.5*log((1.0+one_over_x)/(1.0-one_over_x)) + return atanh(1.0/x) def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT from nlasolver import nla_solve @@ -355,246 +375,260 @@ def objective_function_0(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] - variables[205] = u[0] - variables[206] = u[1] + algebraic[3] = u[0] + algebraic[4] = u[1] - f[0] = variables[205]+variables[206]+states[0]-0.0 - f[1] = variables[205]-variables[206]-(variables[207]+variables[208]) + f[0] = algebraic[3]+algebraic[4]+states[0]-0.0 + f[1] = algebraic[3]-algebraic[4]-(computed_constants[205]+computed_constants[206]) -def find_root_0(voi, states, rates, variables): +def find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*2 - u[0] = variables[205] - u[1] = variables[206] - - u = nla_solve(objective_function_0, u, 2, [voi, states, rates, variables]) - - variables[205] = u[0] - variables[206] = u[1] - - -def initialise_variables(states, rates, variables): - variables[1] = 1.0 - variables[2] = 2.0 - variables[6] = 3.0 - variables[18] = 4.0 - variables[179] = 5.0 - variables[180] = 6.0 - variables[182] = 7.0 - variables[205] = 1.0 - variables[206] = 2.0 - variables[184] = 123.0 - variables[185] = 123.456789 - variables[186] = 123.0e99 - variables[187] = 123.456789e99 - variables[189] = 1.0 - variables[190] = 0.0 - variables[191] = 2.71828182845905 - variables[192] = 3.14159265358979 - variables[193] = inf - variables[194] = nan - variables[207] = 1.0 - variables[208] = 3.0 - states[0] = 0.0 + u[0] = algebraic[3] + u[1] = algebraic[4] + + u = nla_solve(objective_function_0, u, 2, [voi, states, rates, constants, computed_constants, algebraic, externals]) + algebraic[3] = u[0] + algebraic[4] = u[1] -def compute_computed_constants(variables): - variables[0] = eq_func(variables[1], variables[2]) - variables[3] = variables[1]/eq_func(variables[2], variables[2]) - variables[4] = neq_func(variables[1], variables[2]) - variables[5] = variables[1]/neq_func(variables[2], variables[6]) - variables[7] = lt_func(variables[1], variables[2]) - variables[8] = variables[1]/lt_func(variables[2], variables[6]) - variables[9] = leq_func(variables[1], variables[2]) - variables[10] = variables[1]/leq_func(variables[2], variables[6]) - variables[11] = gt_func(variables[1], variables[2]) - variables[12] = variables[1]/gt_func(variables[2], variables[6]) - variables[13] = geq_func(variables[1], variables[2]) - variables[14] = variables[1]/geq_func(variables[2], variables[6]) - variables[15] = and_func(variables[1], variables[2]) - variables[16] = and_func(variables[1], and_func(variables[2], variables[6])) - variables[17] = and_func(lt_func(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[19] = and_func(variables[1]+variables[2], gt_func(variables[6], variables[18])) - variables[20] = and_func(variables[1], gt_func(variables[2], variables[6])) - variables[21] = and_func(variables[1]-variables[2], gt_func(variables[6], variables[18])) - variables[22] = and_func(-variables[1], gt_func(variables[2], variables[6])) - variables[23] = and_func(pow(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[24] = and_func(pow(variables[1], 1.0/variables[2]), gt_func(variables[6], variables[18])) - variables[25] = and_func(lt_func(variables[1], variables[2]), variables[6]+variables[18]) - variables[26] = and_func(lt_func(variables[1], variables[2]), variables[6]) - variables[27] = and_func(lt_func(variables[1], variables[2]), variables[6]-variables[18]) - variables[28] = and_func(lt_func(variables[1], variables[2]), -variables[6]) - variables[29] = and_func(lt_func(variables[1], variables[2]), pow(variables[6], variables[18])) - variables[30] = and_func(lt_func(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])) - variables[31] = variables[1]/and_func(variables[2], variables[6]) - variables[32] = or_func(variables[1], variables[2]) - variables[33] = or_func(variables[1], or_func(variables[2], variables[6])) - variables[34] = or_func(lt_func(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[35] = or_func(variables[1]+variables[2], gt_func(variables[6], variables[18])) - variables[36] = or_func(variables[1], gt_func(variables[2], variables[6])) - variables[37] = or_func(variables[1]-variables[2], gt_func(variables[6], variables[18])) - variables[38] = or_func(-variables[1], gt_func(variables[2], variables[6])) - variables[39] = or_func(pow(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[40] = or_func(pow(variables[1], 1.0/variables[2]), gt_func(variables[6], variables[18])) - variables[41] = or_func(lt_func(variables[1], variables[2]), variables[6]+variables[18]) - variables[42] = or_func(lt_func(variables[1], variables[2]), variables[6]) - variables[43] = or_func(lt_func(variables[1], variables[2]), variables[6]-variables[18]) - variables[44] = or_func(lt_func(variables[1], variables[2]), -variables[6]) - variables[45] = or_func(lt_func(variables[1], variables[2]), pow(variables[6], variables[18])) - variables[46] = or_func(lt_func(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])) - variables[47] = variables[1]/or_func(variables[2], variables[6]) - variables[48] = xor_func(variables[1], variables[2]) - variables[49] = xor_func(variables[1], xor_func(variables[2], variables[6])) - variables[50] = xor_func(lt_func(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[51] = xor_func(variables[1]+variables[2], gt_func(variables[6], variables[18])) - variables[52] = xor_func(variables[1], gt_func(variables[2], variables[6])) - variables[53] = xor_func(variables[1]-variables[2], gt_func(variables[6], variables[18])) - variables[54] = xor_func(-variables[1], gt_func(variables[2], variables[6])) - variables[55] = xor_func(pow(variables[1], variables[2]), gt_func(variables[6], variables[18])) - variables[56] = xor_func(pow(variables[1], 1.0/variables[2]), gt_func(variables[6], variables[18])) - variables[57] = xor_func(lt_func(variables[1], variables[2]), variables[6]+variables[18]) - variables[58] = xor_func(lt_func(variables[1], variables[2]), variables[6]) - variables[59] = xor_func(lt_func(variables[1], variables[2]), variables[6]-variables[18]) - variables[60] = xor_func(lt_func(variables[1], variables[2]), -variables[6]) - variables[61] = xor_func(lt_func(variables[1], variables[2]), pow(variables[6], variables[18])) - variables[62] = xor_func(lt_func(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])) - variables[63] = variables[1]/xor_func(variables[2], variables[6]) - variables[64] = not_func(variables[1]) - variables[65] = variables[1]+variables[2] - variables[66] = variables[1]+variables[2]+variables[6] - variables[67] = lt_func(variables[1], variables[2])+gt_func(variables[6], variables[18]) - variables[68] = variables[1] - variables[69] = variables[1]-variables[2] - variables[70] = lt_func(variables[1], variables[2])-gt_func(variables[6], variables[18]) - variables[71] = lt_func(variables[1], variables[2])-(variables[6]+variables[18]) - variables[72] = lt_func(variables[1], variables[2])-variables[6] - variables[73] = variables[1]-(-variables[2]) - variables[74] = variables[1]-(-variables[2]*variables[6]) - variables[75] = -variables[1] - variables[76] = -lt_func(variables[1], variables[2]) - variables[77] = variables[1]*variables[2] - variables[78] = variables[1]*variables[2]*variables[6] - variables[79] = lt_func(variables[1], variables[2])*gt_func(variables[6], variables[18]) - variables[80] = (variables[1]+variables[2])*gt_func(variables[6], variables[18]) - variables[81] = variables[1]*gt_func(variables[2], variables[6]) - variables[82] = (variables[1]-variables[2])*gt_func(variables[6], variables[18]) - variables[83] = -variables[1]*gt_func(variables[2], variables[6]) - variables[84] = lt_func(variables[1], variables[2])*(variables[6]+variables[18]) - variables[85] = lt_func(variables[1], variables[2])*variables[6] - variables[86] = lt_func(variables[1], variables[2])*(variables[6]-variables[18]) - variables[87] = lt_func(variables[1], variables[2])*-variables[6] - variables[88] = variables[1]/variables[2] - variables[89] = lt_func(variables[1], variables[2])/gt_func(variables[18], variables[6]) - variables[90] = (variables[1]+variables[2])/gt_func(variables[18], variables[6]) - variables[91] = variables[1]/gt_func(variables[6], variables[2]) - variables[92] = (variables[1]-variables[2])/gt_func(variables[18], variables[6]) - variables[93] = -variables[1]/gt_func(variables[6], variables[2]) - variables[94] = lt_func(variables[1], variables[2])/(variables[6]+variables[18]) - variables[95] = lt_func(variables[1], variables[2])/variables[6] - variables[96] = lt_func(variables[1], variables[2])/(variables[6]-variables[18]) - variables[97] = lt_func(variables[1], variables[2])/-variables[6] - variables[98] = lt_func(variables[1], variables[2])/(variables[6]*variables[18]) - variables[99] = lt_func(variables[1], variables[2])/(variables[6]/variables[18]) - variables[100] = sqrt(variables[1]) - variables[101] = pow(variables[1], 2.0) - variables[102] = pow(variables[1], 3.0) - variables[103] = pow(variables[1], variables[2]) - variables[104] = pow(leq_func(variables[1], variables[2]), geq_func(variables[6], variables[18])) - variables[105] = pow(variables[1]+variables[2], geq_func(variables[6], variables[18])) - variables[106] = pow(variables[1], geq_func(variables[2], variables[6])) - variables[107] = pow(variables[1]-variables[2], geq_func(variables[6], variables[18])) - variables[108] = pow(-variables[1], geq_func(variables[2], variables[6])) - variables[109] = pow(variables[1]*variables[2], geq_func(variables[6], variables[18])) - variables[110] = pow(variables[1]/variables[2], geq_func(variables[6], variables[18])) - variables[111] = pow(leq_func(variables[1], variables[2]), variables[6]+variables[18]) - variables[112] = pow(leq_func(variables[1], variables[2]), variables[6]) - variables[113] = pow(leq_func(variables[1], variables[2]), variables[6]-variables[18]) - variables[114] = pow(leq_func(variables[1], variables[2]), -variables[6]) - variables[115] = pow(leq_func(variables[1], variables[2]), variables[6]*variables[18]) - variables[116] = pow(leq_func(variables[1], variables[2]), variables[6]/variables[18]) - variables[117] = pow(leq_func(variables[1], variables[2]), pow(variables[6], variables[18])) - variables[118] = pow(leq_func(variables[1], variables[2]), pow(variables[6], 1.0/variables[18])) - variables[119] = sqrt(variables[1]) - variables[120] = sqrt(variables[1]) - variables[121] = pow(variables[1], 1.0/3.0) - variables[122] = pow(variables[1], 1.0/variables[2]) - variables[123] = pow(lt_func(variables[1], variables[2]), 1.0/gt_func(variables[18], variables[6])) - variables[124] = pow(variables[1]+variables[2], 1.0/gt_func(variables[18], variables[6])) - variables[125] = pow(variables[1], 1.0/gt_func(variables[6], variables[2])) - variables[126] = pow(variables[1]-variables[2], 1.0/gt_func(variables[18], variables[6])) - variables[127] = pow(-variables[1], 1.0/gt_func(variables[6], variables[2])) - variables[128] = pow(variables[1]*variables[2], 1.0/gt_func(variables[18], variables[6])) - variables[129] = pow(variables[1]/variables[2], 1.0/gt_func(variables[18], variables[6])) - variables[130] = pow(lt_func(variables[1], variables[2]), 1.0/(variables[6]+variables[18])) - variables[131] = pow(lt_func(variables[1], variables[2]), 1.0/variables[6]) - variables[132] = pow(lt_func(variables[1], variables[2]), 1.0/(variables[6]-variables[18])) - variables[133] = pow(lt_func(variables[1], variables[2]), 1.0/-variables[6]) - variables[134] = pow(lt_func(variables[1], variables[2]), 1.0/(variables[6]*variables[18])) - variables[135] = pow(lt_func(variables[1], variables[2]), 1.0/(variables[6]/variables[18])) - variables[136] = pow(lt_func(variables[1], variables[2]), 1.0/pow(variables[6], variables[18])) - variables[137] = pow(lt_func(variables[1], variables[2]), 1.0/pow(variables[6], 1.0/variables[18])) - variables[138] = fabs(variables[1]) - variables[139] = exp(variables[1]) - variables[140] = log(variables[1]) - variables[141] = log10(variables[1]) - variables[142] = log(variables[1])/log(2.0) - variables[143] = log10(variables[1]) - variables[144] = log(variables[1])/log(variables[2]) - variables[145] = ceil(variables[1]) - variables[146] = floor(variables[1]) - variables[147] = min(variables[1], variables[2]) - variables[148] = min(variables[1], min(variables[2], variables[6])) - variables[149] = max(variables[1], variables[2]) - variables[150] = max(variables[1], max(variables[2], variables[6])) - variables[151] = fmod(variables[1], variables[2]) - variables[152] = sin(variables[1]) - variables[153] = cos(variables[1]) - variables[154] = tan(variables[1]) - variables[155] = sec(variables[1]) - variables[156] = csc(variables[1]) - variables[157] = cot(variables[1]) - variables[158] = sinh(variables[1]) - variables[159] = cosh(variables[1]) - variables[160] = tanh(variables[1]) - variables[161] = sech(variables[1]) - variables[162] = csch(variables[1]) - variables[163] = coth(variables[1]) - variables[164] = asin(variables[1]) - variables[165] = acos(variables[1]) - variables[166] = atan(variables[1]) - variables[167] = asec(variables[1]) - variables[168] = acsc(variables[1]) - variables[169] = acot(variables[1]) - variables[170] = asinh(variables[1]) - variables[171] = acosh(variables[1]) - variables[172] = atanh(variables[1]/2.0) - variables[173] = asech(variables[1]) - variables[174] = acsch(variables[1]) - variables[175] = acoth(2.0*variables[1]) - variables[176] = variables[1] if gt_func(variables[1], variables[2]) else nan - variables[177] = variables[1] if gt_func(variables[1], variables[2]) else variables[6] - variables[178] = variables[1] if gt_func(variables[1], variables[2]) else variables[6] if gt_func(variables[6], variables[18]) else variables[179] if gt_func(variables[179], variables[180]) else nan - variables[181] = variables[1] if gt_func(variables[1], variables[2]) else variables[6] if gt_func(variables[6], variables[18]) else variables[179] if gt_func(variables[179], variables[180]) else variables[182] - variables[183] = 123.0+(variables[1] if gt_func(variables[1], variables[2]) else nan) - variables[188] = variables[1] - variables[195] = and_func(variables[1], variables[2])+(variables[2] if gt_func(variables[6], variables[18]) else nan)+variables[179]+and_func(variables[180], variables[182]) - variables[196] = and_func(variables[1], variables[2])-((variables[2] if gt_func(variables[6], variables[18]) else nan)-(variables[179]-(variables[2] if gt_func(variables[6], variables[18]) else nan)))-and_func(variables[180], variables[182]) - variables[197] = and_func(variables[1], variables[2])*(variables[2] if gt_func(variables[6], variables[18]) else nan)*variables[179]*(variables[2] if gt_func(variables[6], variables[18]) else nan)*and_func(variables[180], variables[182]) - variables[198] = and_func(variables[1], variables[2])/((variables[2] if gt_func(variables[6], variables[18]) else nan)/(variables[179]/(variables[2] if gt_func(variables[6], variables[18]) else nan))) - variables[199] = and_func(or_func(variables[1], variables[2]), and_func(xor_func(variables[1], variables[2]), and_func(variables[2] if gt_func(variables[6], variables[18]) else nan, and_func(and_func(and_func(variables[179], variables[2] if gt_func(variables[6], variables[18]) else nan), xor_func(variables[1], variables[2])), or_func(variables[1], variables[2]))))) - variables[200] = or_func(and_func(variables[1], variables[2]), or_func(xor_func(variables[1], variables[2]), or_func(variables[2] if gt_func(variables[6], variables[18]) else nan, or_func(or_func(or_func(variables[179], variables[2] if gt_func(variables[6], variables[18]) else nan), xor_func(variables[1], variables[2])), and_func(variables[1], variables[2]))))) - variables[201] = xor_func(and_func(variables[1], variables[2]), xor_func(or_func(variables[1], variables[2]), xor_func(variables[2] if gt_func(variables[6], variables[18]) else nan, xor_func(xor_func(xor_func(variables[179], variables[2] if gt_func(variables[6], variables[18]) else nan), or_func(variables[1], variables[2])), and_func(variables[1], variables[2]))))) - variables[202] = pow(and_func(variables[1], variables[2]), pow(variables[2] if gt_func(variables[6], variables[18]) else nan, pow(pow(variables[179], variables[2] if gt_func(variables[6], variables[18]) else nan), and_func(variables[1], variables[2])))) - variables[203] = pow(pow(pow(and_func(variables[1], variables[2]), 1.0/pow(variables[2] if gt_func(variables[6], variables[18]) else nan, 1.0/variables[179])), 1.0/(variables[2] if gt_func(variables[6], variables[18]) else nan)), 1.0/and_func(variables[1], variables[2])) - variables[204] = -and_func(variables[1], variables[2])+-(variables[2] if gt_func(variables[6], variables[18]) else nan) - - -def compute_rates(voi, states, rates, variables): + +def initialise_variables(states, rates, constants, computed_constants, algebraic): + states[0] = 0.0 + constants[0] = 1.0 + constants[1] = 2.0 + constants[2] = 3.0 + constants[3] = 4.0 + constants[4] = 5.0 + constants[5] = 6.0 + constants[6] = 7.0 + computed_constants[169] = nan + computed_constants[179] = 123.0 + computed_constants[180] = 123.456789 + computed_constants[181] = 123.0e99 + computed_constants[182] = 123.456789e99 + computed_constants[184] = 1.0 + computed_constants[185] = 0.0 + computed_constants[186] = 2.71828182845905 + computed_constants[187] = 3.14159265358979 + computed_constants[188] = inf + computed_constants[189] = nan + computed_constants[205] = 1.0 + computed_constants[206] = 3.0 + algebraic[3] = 1.0 + algebraic[4] = 2.0 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = eq_func(constants[0], constants[1]) + computed_constants[1] = constants[0]/eq_func(constants[1], constants[1]) + computed_constants[2] = neq_func(constants[0], constants[1]) + computed_constants[3] = constants[0]/neq_func(constants[1], constants[2]) + computed_constants[4] = lt_func(constants[0], constants[1]) + computed_constants[5] = constants[0]/lt_func(constants[1], constants[2]) + computed_constants[6] = leq_func(constants[0], constants[1]) + computed_constants[7] = constants[0]/leq_func(constants[1], constants[2]) + computed_constants[8] = gt_func(constants[0], constants[1]) + computed_constants[9] = constants[0]/gt_func(constants[2], constants[1]) + computed_constants[10] = geq_func(constants[0], constants[1]) + computed_constants[11] = constants[0]/geq_func(constants[2], constants[1]) + computed_constants[12] = and_func(constants[0], constants[1]) + computed_constants[13] = and_func(constants[0], and_func(constants[1], constants[2])) + computed_constants[14] = and_func(lt_func(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[15] = and_func(constants[0]+constants[1], gt_func(constants[2], constants[3])) + computed_constants[16] = and_func(constants[0], gt_func(constants[1], constants[2])) + computed_constants[17] = and_func(constants[0]-constants[1], gt_func(constants[2], constants[3])) + computed_constants[18] = and_func(-constants[0], gt_func(constants[1], constants[2])) + computed_constants[19] = and_func(pow(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[20] = and_func(pow(constants[0], 1.0/constants[1]), gt_func(constants[2], constants[3])) + computed_constants[21] = and_func(lt_func(constants[0], constants[1]), constants[2]+constants[3]) + computed_constants[22] = and_func(lt_func(constants[0], constants[1]), constants[2]) + computed_constants[23] = and_func(lt_func(constants[0], constants[1]), constants[2]-constants[3]) + computed_constants[24] = and_func(lt_func(constants[0], constants[1]), -constants[2]) + computed_constants[25] = and_func(lt_func(constants[0], constants[1]), pow(constants[2], constants[3])) + computed_constants[26] = and_func(lt_func(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])) + computed_constants[27] = constants[0]/and_func(constants[1], constants[2]) + computed_constants[28] = or_func(lt_func(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[29] = or_func(constants[0]+constants[1], gt_func(constants[2], constants[3])) + computed_constants[30] = or_func(constants[0], gt_func(constants[1], constants[2])) + computed_constants[31] = or_func(constants[0]-constants[1], gt_func(constants[2], constants[3])) + computed_constants[32] = or_func(-constants[0], gt_func(constants[1], constants[2])) + computed_constants[33] = or_func(pow(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[34] = or_func(pow(constants[0], 1.0/constants[1]), gt_func(constants[2], constants[3])) + computed_constants[35] = or_func(lt_func(constants[0], constants[1]), constants[2]+constants[3]) + computed_constants[36] = or_func(lt_func(constants[0], constants[1]), constants[2]) + computed_constants[37] = or_func(lt_func(constants[0], constants[1]), constants[2]-constants[3]) + computed_constants[38] = or_func(lt_func(constants[0], constants[1]), -constants[2]) + computed_constants[39] = or_func(lt_func(constants[0], constants[1]), pow(constants[2], constants[3])) + computed_constants[40] = or_func(lt_func(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])) + computed_constants[41] = constants[0]/or_func(constants[1], constants[2]) + computed_constants[42] = xor_func(constants[0], constants[1]) + computed_constants[43] = xor_func(constants[0], xor_func(constants[1], constants[2])) + computed_constants[44] = xor_func(lt_func(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[45] = xor_func(constants[0]+constants[1], gt_func(constants[2], constants[3])) + computed_constants[46] = xor_func(constants[0], gt_func(constants[1], constants[2])) + computed_constants[47] = xor_func(constants[0]-constants[1], gt_func(constants[2], constants[3])) + computed_constants[48] = xor_func(-constants[0], gt_func(constants[1], constants[2])) + computed_constants[49] = xor_func(pow(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[50] = xor_func(pow(constants[0], 1.0/constants[1]), gt_func(constants[2], constants[3])) + computed_constants[51] = xor_func(lt_func(constants[0], constants[1]), constants[2]+constants[3]) + computed_constants[52] = xor_func(lt_func(constants[0], constants[1]), constants[2]) + computed_constants[53] = xor_func(lt_func(constants[0], constants[1]), constants[2]-constants[3]) + computed_constants[54] = xor_func(lt_func(constants[0], constants[1]), -constants[2]) + computed_constants[55] = xor_func(lt_func(constants[0], constants[1]), pow(constants[2], constants[3])) + computed_constants[56] = xor_func(lt_func(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])) + computed_constants[57] = not_func(constants[0]) + computed_constants[58] = constants[0]+constants[1]+constants[2] + computed_constants[59] = lt_func(constants[0], constants[1])+gt_func(constants[2], constants[3]) + computed_constants[60] = constants[0] + computed_constants[61] = constants[0]-constants[1] + computed_constants[62] = lt_func(constants[0], constants[1])-gt_func(constants[2], constants[3]) + computed_constants[63] = lt_func(constants[0], constants[1])-(constants[2]+constants[3]) + computed_constants[64] = lt_func(constants[0], constants[1])-constants[2] + computed_constants[65] = constants[0]-(-constants[1]) + computed_constants[66] = constants[0]-(-constants[1]*constants[2]) + computed_constants[67] = -constants[0] + computed_constants[68] = -lt_func(constants[0], constants[1]) + computed_constants[69] = constants[0]*constants[1] + computed_constants[70] = constants[0]*constants[1]*constants[2] + computed_constants[71] = lt_func(constants[0], constants[1])*gt_func(constants[2], constants[3]) + computed_constants[72] = (constants[0]+constants[1])*gt_func(constants[2], constants[3]) + computed_constants[73] = constants[0]*gt_func(constants[1], constants[2]) + computed_constants[74] = (constants[0]-constants[1])*gt_func(constants[2], constants[3]) + computed_constants[75] = -constants[0]*gt_func(constants[1], constants[2]) + computed_constants[76] = lt_func(constants[0], constants[1])*(constants[2]+constants[3]) + computed_constants[77] = lt_func(constants[0], constants[1])*constants[2] + computed_constants[78] = lt_func(constants[0], constants[1])*(constants[2]-constants[3]) + computed_constants[79] = lt_func(constants[0], constants[1])*-constants[2] + computed_constants[80] = constants[0]/constants[1] + computed_constants[81] = lt_func(constants[0], constants[1])/gt_func(constants[3], constants[2]) + computed_constants[82] = (constants[0]+constants[1])/gt_func(constants[3], constants[2]) + computed_constants[83] = constants[0]/gt_func(constants[2], constants[1]) + computed_constants[84] = (constants[0]-constants[1])/gt_func(constants[3], constants[2]) + computed_constants[85] = -constants[0]/gt_func(constants[2], constants[1]) + computed_constants[86] = lt_func(constants[0], constants[1])/(constants[2]+constants[3]) + computed_constants[87] = lt_func(constants[0], constants[1])/constants[2] + computed_constants[88] = lt_func(constants[0], constants[1])/(constants[2]-constants[3]) + computed_constants[89] = lt_func(constants[0], constants[1])/-constants[2] + computed_constants[90] = lt_func(constants[0], constants[1])/(constants[2]*constants[3]) + computed_constants[91] = lt_func(constants[0], constants[1])/(constants[2]/constants[3]) + computed_constants[92] = sqrt(constants[0]) + computed_constants[93] = pow(constants[0], 2.0) + computed_constants[94] = pow(constants[0], 3.0) + computed_constants[95] = pow(constants[0], constants[1]) + computed_constants[96] = pow(leq_func(constants[0], constants[1]), geq_func(constants[2], constants[3])) + computed_constants[97] = pow(constants[0]+constants[1], geq_func(constants[2], constants[3])) + computed_constants[98] = pow(constants[0], geq_func(constants[1], constants[2])) + computed_constants[99] = pow(constants[0]-constants[1], geq_func(constants[2], constants[3])) + computed_constants[100] = pow(-constants[0], geq_func(constants[1], constants[2])) + computed_constants[101] = pow(constants[0]*constants[1], geq_func(constants[2], constants[3])) + computed_constants[102] = pow(constants[0]/constants[1], geq_func(constants[2], constants[3])) + computed_constants[103] = pow(leq_func(constants[0], constants[1]), constants[2]+constants[3]) + computed_constants[104] = pow(leq_func(constants[0], constants[1]), constants[2]) + computed_constants[105] = pow(leq_func(constants[0], constants[1]), constants[2]-constants[3]) + computed_constants[106] = pow(leq_func(constants[0], constants[1]), -constants[2]) + computed_constants[107] = pow(leq_func(constants[0], constants[1]), constants[2]*constants[3]) + computed_constants[108] = pow(leq_func(constants[0], constants[1]), constants[2]/constants[3]) + computed_constants[109] = pow(leq_func(constants[0], constants[1]), pow(constants[2], constants[3])) + computed_constants[110] = pow(leq_func(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])) + computed_constants[111] = sqrt(constants[0]) + computed_constants[112] = sqrt(constants[0]) + computed_constants[113] = pow(constants[0], 1.0/0.5) + computed_constants[114] = pow(constants[0], 1.0/3.0) + computed_constants[115] = pow(constants[0], 1.0/constants[1]) + computed_constants[116] = pow(lt_func(constants[0], constants[1]), 1.0/gt_func(constants[3], constants[2])) + computed_constants[117] = pow(constants[0]+constants[1], 1.0/gt_func(constants[3], constants[2])) + computed_constants[118] = pow(constants[0], 1.0/gt_func(constants[2], constants[1])) + computed_constants[119] = pow(constants[0]-constants[1], 1.0/gt_func(constants[3], constants[2])) + computed_constants[120] = pow(-constants[0], 1.0/gt_func(constants[2], constants[1])) + computed_constants[121] = pow(constants[0]*constants[1], 1.0/gt_func(constants[3], constants[2])) + computed_constants[122] = pow(constants[0]/constants[1], 1.0/gt_func(constants[3], constants[2])) + computed_constants[123] = pow(lt_func(constants[0], constants[1]), 1.0/(constants[2]+constants[3])) + computed_constants[124] = pow(lt_func(constants[0], constants[1]), 1.0/constants[2]) + computed_constants[125] = pow(lt_func(constants[0], constants[1]), 1.0/(constants[2]-constants[3])) + computed_constants[126] = pow(lt_func(constants[0], constants[1]), 1.0/-constants[2]) + computed_constants[127] = pow(lt_func(constants[0], constants[1]), 1.0/(constants[2]*constants[3])) + computed_constants[128] = pow(lt_func(constants[0], constants[1]), 1.0/(constants[2]/constants[3])) + computed_constants[129] = pow(lt_func(constants[0], constants[1]), 1.0/pow(constants[2], constants[3])) + computed_constants[130] = pow(lt_func(constants[0], constants[1]), 1.0/pow(constants[2], 1.0/constants[3])) + computed_constants[131] = fabs(constants[0]) + computed_constants[132] = exp(constants[0]) + computed_constants[133] = log(constants[0]) + computed_constants[134] = log10(constants[0]) + computed_constants[135] = log(constants[0])/log(2.0) + computed_constants[136] = log10(constants[0]) + computed_constants[137] = log(constants[0])/log(constants[1]) + computed_constants[138] = ceil(constants[0]) + computed_constants[139] = floor(constants[0]) + computed_constants[140] = min(constants[0], constants[1]) + computed_constants[141] = min(constants[0], min(constants[1], constants[2])) + computed_constants[142] = max(constants[0], constants[1]) + computed_constants[143] = max(constants[0], max(constants[1], constants[2])) + computed_constants[144] = fmod(constants[0], constants[1]) + computed_constants[145] = sin(constants[0]) + computed_constants[146] = cos(constants[0]) + computed_constants[147] = tan(constants[0]) + computed_constants[148] = sec(constants[0]) + computed_constants[149] = csc(constants[0]) + computed_constants[150] = cot(constants[0]) + computed_constants[151] = sinh(constants[0]) + computed_constants[152] = cosh(constants[0]) + computed_constants[153] = tanh(constants[0]) + computed_constants[154] = sech(constants[0]) + computed_constants[155] = csch(constants[0]) + computed_constants[156] = coth(constants[0]) + computed_constants[157] = asin(constants[0]) + computed_constants[158] = acos(constants[0]) + computed_constants[159] = atan(constants[0]) + computed_constants[160] = asec(constants[0]) + computed_constants[161] = acsc(constants[0]) + computed_constants[162] = acot(constants[0]) + computed_constants[163] = asinh(constants[0]) + computed_constants[164] = acosh(constants[0]) + computed_constants[165] = atanh(constants[0]/2.0) + computed_constants[166] = asech(constants[0]) + computed_constants[167] = acsch(constants[0]) + computed_constants[168] = acoth(2.0*constants[0]) + computed_constants[170] = constants[0] if gt_func(constants[0], constants[1]) else nan + computed_constants[171] = constants[0] if lt_func(constants[0], constants[1]) else nan + computed_constants[172] = constants[0] + computed_constants[173] = constants[0] if gt_func(constants[0], constants[1]) else constants[2] + computed_constants[174] = constants[0] if gt_func(constants[0], constants[1]) else constants[2] if gt_func(constants[2], constants[3]) else constants[4] if gt_func(constants[4], constants[5]) else nan + computed_constants[175] = constants[0] if lt_func(constants[0], constants[1]) else constants[2] if gt_func(constants[2], constants[3]) else constants[4] if gt_func(constants[4], constants[5]) else nan + computed_constants[176] = constants[0] if gt_func(constants[0], constants[1]) else constants[2] if gt_func(constants[2], constants[3]) else constants[4] if gt_func(constants[4], constants[5]) else constants[6] + computed_constants[177] = 123.0+(constants[0] if gt_func(constants[0], constants[1]) else nan) + computed_constants[178] = 123.0+(constants[0] if lt_func(constants[0], constants[1]) else nan) + computed_constants[183] = constants[0] + computed_constants[190] = and_func(constants[0], constants[1])+(constants[1] if gt_func(constants[2], constants[3]) else nan)+constants[4]+and_func(constants[5], constants[6]) + computed_constants[191] = and_func(constants[0], constants[1])+(constants[1] if lt_func(constants[2], constants[3]) else nan)+constants[4]+and_func(constants[5], constants[6]) + computed_constants[192] = and_func(constants[0], constants[1])-((constants[1] if gt_func(constants[2], constants[3]) else nan)-(constants[4]-(constants[1] if gt_func(constants[2], constants[3]) else nan)))-and_func(constants[5], constants[6]) + computed_constants[193] = and_func(constants[0], constants[1])-((constants[1] if lt_func(constants[2], constants[3]) else nan)-(constants[4]-(constants[1] if lt_func(constants[2], constants[3]) else nan)))-and_func(constants[5], constants[6]) + computed_constants[194] = and_func(constants[0], constants[1])*(constants[1] if gt_func(constants[2], constants[3]) else nan)*constants[4]*(constants[1] if gt_func(constants[2], constants[3]) else nan)*and_func(constants[5], constants[6]) + computed_constants[195] = and_func(constants[0], constants[1])*(constants[1] if lt_func(constants[2], constants[3]) else nan)*constants[4]*(constants[1] if lt_func(constants[2], constants[3]) else nan)*and_func(constants[5], constants[6]) + computed_constants[196] = and_func(constants[0], constants[1])/((constants[1] if gt_func(constants[2], constants[3]) else nan)/(constants[4]/(constants[1] if gt_func(constants[2], constants[3]) else nan))) + computed_constants[197] = and_func(constants[0], constants[1])/((constants[1] if lt_func(constants[2], constants[3]) else nan)/(constants[4]/(constants[1] if lt_func(constants[2], constants[3]) else nan))) + computed_constants[198] = and_func(or_func(constants[0], constants[1]), and_func(xor_func(constants[0], constants[1]), and_func(constants[1] if gt_func(constants[2], constants[3]) else nan, and_func(and_func(and_func(constants[4], constants[1] if gt_func(constants[2], constants[3]) else nan), xor_func(constants[0], constants[1])), or_func(constants[0], constants[1]))))) + computed_constants[199] = or_func(and_func(constants[0], constants[1]), or_func(xor_func(constants[0], constants[1]), or_func(constants[1] if gt_func(constants[2], constants[3]) else nan, or_func(or_func(or_func(constants[4], constants[1] if gt_func(constants[2], constants[3]) else nan), xor_func(constants[0], constants[1])), and_func(constants[0], constants[1]))))) + computed_constants[200] = xor_func(and_func(constants[0], constants[1]), xor_func(or_func(constants[0], constants[1]), xor_func(constants[1] if gt_func(constants[2], constants[3]) else nan, xor_func(xor_func(xor_func(constants[4], constants[1] if gt_func(constants[2], constants[3]) else nan), or_func(constants[0], constants[1])), and_func(constants[0], constants[1]))))) + computed_constants[201] = pow(and_func(constants[0], constants[1]), pow(constants[1] if gt_func(constants[2], constants[3]) else nan, pow(pow(constants[4], constants[1] if gt_func(constants[2], constants[3]) else nan), and_func(constants[0], constants[1])))) + computed_constants[202] = pow(pow(pow(and_func(constants[0], constants[1]), 1.0/pow(constants[1] if gt_func(constants[2], constants[3]) else nan, 1.0/constants[4])), 1.0/(constants[1] if gt_func(constants[2], constants[3]) else nan)), 1.0/and_func(constants[0], constants[1])) + computed_constants[203] = -and_func(constants[0], constants[1])+-(constants[1] if gt_func(constants[2], constants[3]) else nan) + computed_constants[204] = -and_func(constants[0], constants[1])+-(constants[1] if lt_func(constants[2], constants[3]) else nan) + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): rates[0] = 1.0 -def compute_variables(voi, states, rates, variables): - find_root_0(voi, states, rates, variables) +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[0] = or_func(states[0], states[0]) + algebraic[1] = or_func(states[0], or_func(states[0], constants[0])) + algebraic[2] = constants[0]/xor_func(constants[1], states[0]) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals) diff --git a/tests/resources/coverage/generator/model.xor.c b/tests/resources/coverage/generator/model.xor.c new file mode 100644 index 0000000000..9861b1a292 --- /dev/null +++ b/tests/resources/coverage/generator/model.xor.c @@ -0,0 +1,661 @@ +/* The content of this file was generated using a modified C profile of libCellML 0.6.0. */ + +#include "model.h" + +#include +#include + +const char VERSION[] = "0.6.0.post0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 7; +const size_t COMPUTED_CONSTANT_COUNT = 207; +const size_t ALGEBRAIC_COUNT = 5; +const size_t EXTERNAL_COUNT = 1; + +const VariableInfo VOI_INFO = {"t", "second", "my_component"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "my_component"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"m", "dimensionless", "my_component"}, + {"n", "dimensionless", "my_component"}, + {"o", "dimensionless", "my_component"}, + {"p", "dimensionless", "my_component"}, + {"q", "dimensionless", "my_component"}, + {"r", "dimensionless", "my_component"}, + {"s", "dimensionless", "my_component"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"eqnEq", "dimensionless", "my_component"}, + {"eqnEqCoverageParentheses", "dimensionless", "my_component"}, + {"eqnNeq", "dimensionless", "my_component"}, + {"eqnNeqCoverageParentheses", "dimensionless", "my_component"}, + {"eqnLt", "dimensionless", "my_component"}, + {"eqnLtCoverageParentheses", "dimensionless", "my_component"}, + {"eqnLeq", "dimensionless", "my_component"}, + {"eqnLeqCoverageParentheses", "dimensionless", "my_component"}, + {"eqnGt", "dimensionless", "my_component"}, + {"eqnGtCoverageParentheses", "dimensionless", "my_component"}, + {"eqnGeq", "dimensionless", "my_component"}, + {"eqnGeqCoverageParentheses", "dimensionless", "my_component"}, + {"eqnAnd", "dimensionless", "my_component"}, + {"eqnAndMultiple", "dimensionless", "my_component"}, + {"eqnAndParentheses", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftPower", "dimensionless", "my_component"}, + {"eqnAndParenthesesLeftRoot", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightPower", "dimensionless", "my_component"}, + {"eqnAndParenthesesRightRoot", "dimensionless", "my_component"}, + {"eqnAndCoverageParentheses", "dimensionless", "my_component"}, + {"eqnOrParentheses", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftPower", "dimensionless", "my_component"}, + {"eqnOrParenthesesLeftRoot", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightPower", "dimensionless", "my_component"}, + {"eqnOrParenthesesRightRoot", "dimensionless", "my_component"}, + {"eqnOrCoverageParentheses", "dimensionless", "my_component"}, + {"eqnXor", "dimensionless", "my_component"}, + {"eqnXorMultiple", "dimensionless", "my_component"}, + {"eqnXorParentheses", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftPower", "dimensionless", "my_component"}, + {"eqnXorParenthesesLeftRoot", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightPower", "dimensionless", "my_component"}, + {"eqnXorParenthesesRightRoot", "dimensionless", "my_component"}, + {"eqnNot", "dimensionless", "my_component"}, + {"eqnPlusMultiple", "dimensionless", "my_component"}, + {"eqnPlusParentheses", "dimensionless", "my_component"}, + {"eqnPlusUnary", "dimensionless", "my_component"}, + {"eqnMinus", "dimensionless", "my_component"}, + {"eqnMinusParentheses", "dimensionless", "my_component"}, + {"eqnMinusParenthesesPlusWith", "dimensionless", "my_component"}, + {"eqnMinusParenthesesPlusWithout", "dimensionless", "my_component"}, + {"eqnMinusParenthesesDirectUnaryMinus", "dimensionless", "my_component"}, + {"eqnMinusParenthesesIndirectUnaryMinus", "dimensionless", "my_component"}, + {"eqnMinusUnary", "dimensionless", "my_component"}, + {"eqnMinusUnaryParentheses", "dimensionless", "my_component"}, + {"eqnTimes", "dimensionless", "my_component"}, + {"eqnTimesMultiple", "dimensionless", "my_component"}, + {"eqnTimesParentheses", "dimensionless", "my_component"}, + {"eqnTimesParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnTimesParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnTimesParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnTimesParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnTimesParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnTimesParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnTimesParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnTimesParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnDivide", "dimensionless", "my_component"}, + {"eqnDivideParentheses", "dimensionless", "my_component"}, + {"eqnDivideParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnDivideParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnDivideParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnDivideParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightTimes", "dimensionless", "my_component"}, + {"eqnDivideParenthesesRightDivide", "dimensionless", "my_component"}, + {"eqnPowerSqrt", "dimensionless", "my_component"}, + {"eqnPowerSqr", "dimensionless", "my_component"}, + {"eqnPowerCube", "dimensionless", "my_component"}, + {"eqnPowerCi", "dimensionless", "my_component"}, + {"eqnPowerParentheses", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftTimes", "dimensionless", "my_component"}, + {"eqnPowerParenthesesLeftDivide", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightTimes", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightDivide", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightPower", "dimensionless", "my_component"}, + {"eqnPowerParenthesesRightRoot", "dimensionless", "my_component"}, + {"eqnRootSqrt", "dimensionless", "my_component"}, + {"eqnRootSqrtOther", "dimensionless", "my_component"}, + {"eqnRootSqr", "dimensionless", "my_component"}, + {"eqnRootCube", "dimensionless", "my_component"}, + {"eqnRootCi", "dimensionless", "my_component"}, + {"eqnRootParentheses", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftPlusWith", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftPlusWithout", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftMinusWith", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftMinusWithout", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftTimes", "dimensionless", "my_component"}, + {"eqnRootParenthesesLeftDivide", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightPlusWith", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightPlusWithout", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightMinusWith", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightMinusWithout", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightTimes", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightDivide", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightPower", "dimensionless", "my_component"}, + {"eqnRootParenthesesRightRoot", "dimensionless", "my_component"}, + {"eqnAbs", "dimensionless", "my_component"}, + {"eqnExp", "dimensionless", "my_component"}, + {"eqnLn", "dimensionless", "my_component"}, + {"eqnLog", "dimensionless", "my_component"}, + {"eqnLog2", "dimensionless", "my_component"}, + {"eqnLog10", "dimensionless", "my_component"}, + {"eqnLogCi", "dimensionless", "my_component"}, + {"eqnCeiling", "dimensionless", "my_component"}, + {"eqnFloor", "dimensionless", "my_component"}, + {"eqnMin", "dimensionless", "my_component"}, + {"eqnMinMultiple", "dimensionless", "my_component"}, + {"eqnMax", "dimensionless", "my_component"}, + {"eqnMaxMultiple", "dimensionless", "my_component"}, + {"eqnRem", "dimensionless", "my_component"}, + {"eqnSin", "dimensionless", "my_component"}, + {"eqnCos", "dimensionless", "my_component"}, + {"eqnTan", "dimensionless", "my_component"}, + {"eqnSec", "dimensionless", "my_component"}, + {"eqnCsc", "dimensionless", "my_component"}, + {"eqnCot", "dimensionless", "my_component"}, + {"eqnSinh", "dimensionless", "my_component"}, + {"eqnCosh", "dimensionless", "my_component"}, + {"eqnTanh", "dimensionless", "my_component"}, + {"eqnSech", "dimensionless", "my_component"}, + {"eqnCsch", "dimensionless", "my_component"}, + {"eqnCoth", "dimensionless", "my_component"}, + {"eqnArcsin", "dimensionless", "my_component"}, + {"eqnArccos", "dimensionless", "my_component"}, + {"eqnArctan", "dimensionless", "my_component"}, + {"eqnArcsec", "dimensionless", "my_component"}, + {"eqnArccsc", "dimensionless", "my_component"}, + {"eqnArccot", "dimensionless", "my_component"}, + {"eqnArcsinh", "dimensionless", "my_component"}, + {"eqnArccosh", "dimensionless", "my_component"}, + {"eqnArctanh", "dimensionless", "my_component"}, + {"eqnArcsech", "dimensionless", "my_component"}, + {"eqnArccsch", "dimensionless", "my_component"}, + {"eqnArccoth", "dimensionless", "my_component"}, + {"eqnPiecewise", "dimensionless", "my_component"}, + {"eqnPiecewisePiece", "dimensionless", "my_component"}, + {"eqnPiecewisePiece2", "dimensionless", "my_component"}, + {"eqnPiecewiseOtherwise", "dimensionless", "my_component"}, + {"eqnPiecewisePieceOtherwise", "dimensionless", "my_component"}, + {"eqnPiecewisePiecePiecePiece", "dimensionless", "my_component"}, + {"eqnPiecewisePiecePiecePiece2", "dimensionless", "my_component"}, + {"eqnPiecewisePiecePiecePieceOtherwise", "dimensionless", "my_component"}, + {"eqnWithPiecewise", "dimensionless", "my_component"}, + {"eqnWithPiecewise2", "dimensionless", "my_component"}, + {"eqnCnInteger", "dimensionless", "my_component"}, + {"eqnCnDouble", "dimensionless", "my_component"}, + {"eqnCnIntegerWithExponent", "dimensionless", "my_component"}, + {"eqnCnDoubleWithExponent", "dimensionless", "my_component"}, + {"eqnCi", "dimensionless", "my_component"}, + {"eqnTrue", "dimensionless", "my_component"}, + {"eqnFalse", "dimensionless", "my_component"}, + {"eqnExponentiale", "dimensionless", "my_component"}, + {"eqnPi", "dimensionless", "my_component"}, + {"eqnInfinity", "dimensionless", "my_component"}, + {"eqnNotanumber", "dimensionless", "my_component"}, + {"eqnCoverageForPlusOperator", "dimensionless", "my_component"}, + {"eqnCoverageForPlusOperator2", "dimensionless", "my_component"}, + {"eqnCoverageForMinusOperator", "dimensionless", "my_component"}, + {"eqnCoverageForMinusOperator2", "dimensionless", "my_component"}, + {"eqnCoverageForTimesOperator", "dimensionless", "my_component"}, + {"eqnCoverageForTimesOperator2", "dimensionless", "my_component"}, + {"eqnCoverageForDivideOperator", "dimensionless", "my_component"}, + {"eqnCoverageForDivideOperator2", "dimensionless", "my_component"}, + {"eqnCoverageForAndOperator", "dimensionless", "my_component"}, + {"eqnCoverageForOrOperator", "dimensionless", "my_component"}, + {"eqnCoverageForXorOperator", "dimensionless", "my_component"}, + {"eqnCoverageForPowerOperator", "dimensionless", "my_component"}, + {"eqnCoverageForRootOperator", "dimensionless", "my_component"}, + {"eqnCoverageForMinusUnary", "dimensionless", "my_component"}, + {"eqnCoverageForMinusUnary2", "dimensionless", "my_component"}, + {"eqnComputedConstant1", "dimensionless", "my_component"}, + {"eqnComputedConstant2", "dimensionless", "my_component"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"eqnOr", "dimensionless", "my_component"}, + {"eqnOrMultiple", "dimensionless", "my_component"}, + {"eqnXorCoverageParentheses", "dimensionless", "my_component"}, + {"eqnNlaVariable1", "dimensionless", "my_component"}, + {"eqnNlaVariable2", "dimensionless", "my_component"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"eqnPlus", "dimensionless", "my_component"} +}; + +double XOR(double x, double y) +{ + return (x != 0.0) ^ (y != 0.0); +} + +double sec(double x) +{ + return 1.0/cos(x); +} + +double csc(double x) +{ + return 1.0/sin(x); +} + +double cot(double x) +{ + return 1.0/tan(x); +} + +double sech(double x) +{ + return 1.0/cosh(x); +} + +double csch(double x) +{ + return 1.0/sinh(x); +} + +double coth(double x) +{ + return 1.0/tanh(x); +} + +double asec(double x) +{ + return acos(1.0/x); +} + +double acsc(double x) +{ + return asin(1.0/x); +} + +double acot(double x) +{ + return atan(1.0/x); +} + +double asech(double x) +{ + return acosh(1.0/x); +} + +double acsch(double x) +{ + return asinh(1.0/x); +} + +double acoth(double x) +{ + return atanh(1.0/x); +} + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +typedef struct { + double voi; + double *states; + double *rates; + double *constants; + double *computedConstants; + double *algebraic; + double *externals; +} RootFindingInfo; + +extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), + double *u, size_t n, void *data); + +void objectiveFunction0(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[3] = u[0]; + algebraic[4] = u[1]; + + f[0] = algebraic[3]+algebraic[4]+states[0]-0.0; + f[1] = algebraic[3]-algebraic[4]-(computedConstants[205]+computedConstants[206]); +} + +void findRoot0(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[2]; + + u[0] = algebraic[3]; + u[1] = algebraic[4]; + + nlaSolve(objectiveFunction0, u, 2, &rfi); + + algebraic[3] = u[0]; + algebraic[4] = u[1]; +} + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + states[0] = 0.0; + constants[0] = 1.0; + constants[1] = 2.0; + constants[2] = 3.0; + constants[3] = 4.0; + constants[4] = 5.0; + constants[5] = 6.0; + constants[6] = 7.0; + computedConstants[169] = NAN; + computedConstants[179] = 123.0; + computedConstants[180] = 123.456789; + computedConstants[181] = 123.0e99; + computedConstants[182] = 123.456789e99; + computedConstants[184] = 1.0; + computedConstants[185] = 0.0; + computedConstants[186] = 2.71828182845905; + computedConstants[187] = 3.14159265358979; + computedConstants[188] = INFINITY; + computedConstants[189] = NAN; + computedConstants[205] = 1.0; + computedConstants[206] = 3.0; + algebraic[3] = 1.0; + algebraic[4] = 2.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ + computedConstants[0] = constants[0] == constants[1]; + computedConstants[1] = constants[0]/(constants[1] == constants[1]); + computedConstants[2] = constants[0] != constants[1]; + computedConstants[3] = constants[0]/(constants[1] != constants[2]); + computedConstants[4] = constants[0] < constants[1]; + computedConstants[5] = constants[0]/(constants[1] < constants[2]); + computedConstants[6] = constants[0] <= constants[1]; + computedConstants[7] = constants[0]/(constants[1] <= constants[2]); + computedConstants[8] = constants[0] > constants[1]; + computedConstants[9] = constants[0]/(constants[2] > constants[1]); + computedConstants[10] = constants[0] >= constants[1]; + computedConstants[11] = constants[0]/(constants[2] >= constants[1]); + computedConstants[12] = constants[0] && constants[1]; + computedConstants[13] = constants[0] && constants[1] && constants[2]; + computedConstants[14] = (constants[0] < constants[1]) && (constants[2] > constants[3]); + computedConstants[15] = (constants[0]+constants[1]) && (constants[2] > constants[3]); + computedConstants[16] = constants[0] && (constants[1] > constants[2]); + computedConstants[17] = (constants[0]-constants[1]) && (constants[2] > constants[3]); + computedConstants[18] = -constants[0] && (constants[1] > constants[2]); + computedConstants[19] = pow(constants[0], constants[1]) && (constants[2] > constants[3]); + computedConstants[20] = pow(constants[0], 1.0/constants[1]) && (constants[2] > constants[3]); + computedConstants[21] = (constants[0] < constants[1]) && (constants[2]+constants[3]); + computedConstants[22] = (constants[0] < constants[1]) && constants[2]; + computedConstants[23] = (constants[0] < constants[1]) && (constants[2]-constants[3]); + computedConstants[24] = (constants[0] < constants[1]) && -constants[2]; + computedConstants[25] = (constants[0] < constants[1]) && pow(constants[2], constants[3]); + computedConstants[26] = (constants[0] < constants[1]) && pow(constants[2], 1.0/constants[3]); + computedConstants[27] = constants[0]/(constants[1] && constants[2]); + computedConstants[28] = (constants[0] < constants[1]) || (constants[2] > constants[3]); + computedConstants[29] = (constants[0]+constants[1]) || (constants[2] > constants[3]); + computedConstants[30] = constants[0] || (constants[1] > constants[2]); + computedConstants[31] = (constants[0]-constants[1]) || (constants[2] > constants[3]); + computedConstants[32] = -constants[0] || (constants[1] > constants[2]); + computedConstants[33] = pow(constants[0], constants[1]) || (constants[2] > constants[3]); + computedConstants[34] = pow(constants[0], 1.0/constants[1]) || (constants[2] > constants[3]); + computedConstants[35] = (constants[0] < constants[1]) || (constants[2]+constants[3]); + computedConstants[36] = (constants[0] < constants[1]) || constants[2]; + computedConstants[37] = (constants[0] < constants[1]) || (constants[2]-constants[3]); + computedConstants[38] = (constants[0] < constants[1]) || -constants[2]; + computedConstants[39] = (constants[0] < constants[1]) || pow(constants[2], constants[3]); + computedConstants[40] = (constants[0] < constants[1]) || pow(constants[2], 1.0/constants[3]); + computedConstants[41] = constants[0]/(constants[1] || constants[2]); + computedConstants[42] = XOR(constants[0], constants[1]); + computedConstants[43] = XOR(constants[0], XOR(constants[1], constants[2])); + computedConstants[44] = XOR(constants[0] < constants[1], constants[2] > constants[3]); + computedConstants[45] = XOR(constants[0]+constants[1], constants[2] > constants[3]); + computedConstants[46] = XOR(constants[0], constants[1] > constants[2]); + computedConstants[47] = XOR(constants[0]-constants[1], constants[2] > constants[3]); + computedConstants[48] = XOR(-constants[0], constants[1] > constants[2]); + computedConstants[49] = XOR(pow(constants[0], constants[1]), constants[2] > constants[3]); + computedConstants[50] = XOR(pow(constants[0], 1.0/constants[1]), constants[2] > constants[3]); + computedConstants[51] = XOR(constants[0] < constants[1], constants[2]+constants[3]); + computedConstants[52] = XOR(constants[0] < constants[1], constants[2]); + computedConstants[53] = XOR(constants[0] < constants[1], constants[2]-constants[3]); + computedConstants[54] = XOR(constants[0] < constants[1], -constants[2]); + computedConstants[55] = XOR(constants[0] < constants[1], pow(constants[2], constants[3])); + computedConstants[56] = XOR(constants[0] < constants[1], pow(constants[2], 1.0/constants[3])); + computedConstants[57] = !constants[0]; + computedConstants[58] = constants[0]+constants[1]+constants[2]; + computedConstants[59] = (constants[0] < constants[1])+(constants[2] > constants[3]); + computedConstants[60] = constants[0]; + computedConstants[61] = constants[0]-constants[1]; + computedConstants[62] = (constants[0] < constants[1])-(constants[2] > constants[3]); + computedConstants[63] = (constants[0] < constants[1])-(constants[2]+constants[3]); + computedConstants[64] = (constants[0] < constants[1])-constants[2]; + computedConstants[65] = constants[0]-(-constants[1]); + computedConstants[66] = constants[0]-(-constants[1]*constants[2]); + computedConstants[67] = -constants[0]; + computedConstants[68] = -(constants[0] < constants[1]); + computedConstants[69] = constants[0]*constants[1]; + computedConstants[70] = constants[0]*constants[1]*constants[2]; + computedConstants[71] = (constants[0] < constants[1])*(constants[2] > constants[3]); + computedConstants[72] = (constants[0]+constants[1])*(constants[2] > constants[3]); + computedConstants[73] = constants[0]*(constants[1] > constants[2]); + computedConstants[74] = (constants[0]-constants[1])*(constants[2] > constants[3]); + computedConstants[75] = -constants[0]*(constants[1] > constants[2]); + computedConstants[76] = (constants[0] < constants[1])*(constants[2]+constants[3]); + computedConstants[77] = (constants[0] < constants[1])*constants[2]; + computedConstants[78] = (constants[0] < constants[1])*(constants[2]-constants[3]); + computedConstants[79] = (constants[0] < constants[1])*-constants[2]; + computedConstants[80] = constants[0]/constants[1]; + computedConstants[81] = (constants[0] < constants[1])/(constants[3] > constants[2]); + computedConstants[82] = (constants[0]+constants[1])/(constants[3] > constants[2]); + computedConstants[83] = constants[0]/(constants[2] > constants[1]); + computedConstants[84] = (constants[0]-constants[1])/(constants[3] > constants[2]); + computedConstants[85] = -constants[0]/(constants[2] > constants[1]); + computedConstants[86] = (constants[0] < constants[1])/(constants[2]+constants[3]); + computedConstants[87] = (constants[0] < constants[1])/constants[2]; + computedConstants[88] = (constants[0] < constants[1])/(constants[2]-constants[3]); + computedConstants[89] = (constants[0] < constants[1])/-constants[2]; + computedConstants[90] = (constants[0] < constants[1])/(constants[2]*constants[3]); + computedConstants[91] = (constants[0] < constants[1])/(constants[2]/constants[3]); + computedConstants[92] = sqrt(constants[0]); + computedConstants[93] = pow(constants[0], 2.0); + computedConstants[94] = pow(constants[0], 3.0); + computedConstants[95] = pow(constants[0], constants[1]); + computedConstants[96] = pow(constants[0] <= constants[1], constants[2] >= constants[3]); + computedConstants[97] = pow(constants[0]+constants[1], constants[2] >= constants[3]); + computedConstants[98] = pow(constants[0], constants[1] >= constants[2]); + computedConstants[99] = pow(constants[0]-constants[1], constants[2] >= constants[3]); + computedConstants[100] = pow(-constants[0], constants[1] >= constants[2]); + computedConstants[101] = pow(constants[0]*constants[1], constants[2] >= constants[3]); + computedConstants[102] = pow(constants[0]/constants[1], constants[2] >= constants[3]); + computedConstants[103] = pow(constants[0] <= constants[1], constants[2]+constants[3]); + computedConstants[104] = pow(constants[0] <= constants[1], constants[2]); + computedConstants[105] = pow(constants[0] <= constants[1], constants[2]-constants[3]); + computedConstants[106] = pow(constants[0] <= constants[1], -constants[2]); + computedConstants[107] = pow(constants[0] <= constants[1], constants[2]*constants[3]); + computedConstants[108] = pow(constants[0] <= constants[1], constants[2]/constants[3]); + computedConstants[109] = pow(constants[0] <= constants[1], pow(constants[2], constants[3])); + computedConstants[110] = pow(constants[0] <= constants[1], pow(constants[2], 1.0/constants[3])); + computedConstants[111] = sqrt(constants[0]); + computedConstants[112] = sqrt(constants[0]); + computedConstants[113] = pow(constants[0], 1.0/0.5); + computedConstants[114] = pow(constants[0], 1.0/3.0); + computedConstants[115] = pow(constants[0], 1.0/constants[1]); + computedConstants[116] = pow(constants[0] < constants[1], 1.0/(constants[3] > constants[2])); + computedConstants[117] = pow(constants[0]+constants[1], 1.0/(constants[3] > constants[2])); + computedConstants[118] = pow(constants[0], 1.0/(constants[2] > constants[1])); + computedConstants[119] = pow(constants[0]-constants[1], 1.0/(constants[3] > constants[2])); + computedConstants[120] = pow(-constants[0], 1.0/(constants[2] > constants[1])); + computedConstants[121] = pow(constants[0]*constants[1], 1.0/(constants[3] > constants[2])); + computedConstants[122] = pow(constants[0]/constants[1], 1.0/(constants[3] > constants[2])); + computedConstants[123] = pow(constants[0] < constants[1], 1.0/(constants[2]+constants[3])); + computedConstants[124] = pow(constants[0] < constants[1], 1.0/constants[2]); + computedConstants[125] = pow(constants[0] < constants[1], 1.0/(constants[2]-constants[3])); + computedConstants[126] = pow(constants[0] < constants[1], 1.0/-constants[2]); + computedConstants[127] = pow(constants[0] < constants[1], 1.0/(constants[2]*constants[3])); + computedConstants[128] = pow(constants[0] < constants[1], 1.0/(constants[2]/constants[3])); + computedConstants[129] = pow(constants[0] < constants[1], 1.0/pow(constants[2], constants[3])); + computedConstants[130] = pow(constants[0] < constants[1], 1.0/pow(constants[2], 1.0/constants[3])); + computedConstants[131] = fabs(constants[0]); + computedConstants[132] = exp(constants[0]); + computedConstants[133] = log(constants[0]); + computedConstants[134] = log10(constants[0]); + computedConstants[135] = log(constants[0])/log(2.0); + computedConstants[136] = log10(constants[0]); + computedConstants[137] = log(constants[0])/log(constants[1]); + computedConstants[138] = ceil(constants[0]); + computedConstants[139] = floor(constants[0]); + computedConstants[140] = fmin(constants[0], constants[1]); + computedConstants[141] = fmin(constants[0], fmin(constants[1], constants[2])); + computedConstants[142] = fmax(constants[0], constants[1]); + computedConstants[143] = fmax(constants[0], fmax(constants[1], constants[2])); + computedConstants[144] = fmod(constants[0], constants[1]); + computedConstants[145] = sin(constants[0]); + computedConstants[146] = cos(constants[0]); + computedConstants[147] = tan(constants[0]); + computedConstants[148] = sec(constants[0]); + computedConstants[149] = csc(constants[0]); + computedConstants[150] = cot(constants[0]); + computedConstants[151] = sinh(constants[0]); + computedConstants[152] = cosh(constants[0]); + computedConstants[153] = tanh(constants[0]); + computedConstants[154] = sech(constants[0]); + computedConstants[155] = csch(constants[0]); + computedConstants[156] = coth(constants[0]); + computedConstants[157] = asin(constants[0]); + computedConstants[158] = acos(constants[0]); + computedConstants[159] = atan(constants[0]); + computedConstants[160] = asec(constants[0]); + computedConstants[161] = acsc(constants[0]); + computedConstants[162] = acot(constants[0]); + computedConstants[163] = asinh(constants[0]); + computedConstants[164] = acosh(constants[0]); + computedConstants[165] = atanh(constants[0]/2.0); + computedConstants[166] = asech(constants[0]); + computedConstants[167] = acsch(constants[0]); + computedConstants[168] = acoth(2.0*constants[0]); + computedConstants[170] = (constants[0] > constants[1])?constants[0]:NAN; + computedConstants[171] = (constants[0] < constants[1])?constants[0]:NAN; + computedConstants[172] = constants[0]; + computedConstants[173] = (constants[0] > constants[1])?constants[0]:constants[2]; + computedConstants[174] = (constants[0] > constants[1])?constants[0]:(constants[2] > constants[3])?constants[2]:(constants[4] > constants[5])?constants[4]:NAN; + computedConstants[175] = (constants[0] < constants[1])?constants[0]:(constants[2] > constants[3])?constants[2]:(constants[4] > constants[5])?constants[4]:NAN; + computedConstants[176] = (constants[0] > constants[1])?constants[0]:(constants[2] > constants[3])?constants[2]:(constants[4] > constants[5])?constants[4]:constants[6]; + computedConstants[177] = 123.0+((constants[0] > constants[1])?constants[0]:NAN); + computedConstants[178] = 123.0+((constants[0] < constants[1])?constants[0]:NAN); + computedConstants[183] = constants[0]; + computedConstants[190] = (constants[0] && constants[1])+((constants[2] > constants[3])?constants[1]:NAN)+constants[4]+(constants[5] && constants[6]); + computedConstants[191] = (constants[0] && constants[1])+((constants[2] < constants[3])?constants[1]:NAN)+constants[4]+(constants[5] && constants[6]); + computedConstants[192] = (constants[0] && constants[1])-(((constants[2] > constants[3])?constants[1]:NAN)-(constants[4]-((constants[2] > constants[3])?constants[1]:NAN)))-(constants[5] && constants[6]); + computedConstants[193] = (constants[0] && constants[1])-(((constants[2] < constants[3])?constants[1]:NAN)-(constants[4]-((constants[2] < constants[3])?constants[1]:NAN)))-(constants[5] && constants[6]); + computedConstants[194] = (constants[0] && constants[1])*((constants[2] > constants[3])?constants[1]:NAN)*constants[4]*((constants[2] > constants[3])?constants[1]:NAN)*(constants[5] && constants[6]); + computedConstants[195] = (constants[0] && constants[1])*((constants[2] < constants[3])?constants[1]:NAN)*constants[4]*((constants[2] < constants[3])?constants[1]:NAN)*(constants[5] && constants[6]); + computedConstants[196] = (constants[0] && constants[1])/(((constants[2] > constants[3])?constants[1]:NAN)/(constants[4]/((constants[2] > constants[3])?constants[1]:NAN))); + computedConstants[197] = (constants[0] && constants[1])/(((constants[2] < constants[3])?constants[1]:NAN)/(constants[4]/((constants[2] < constants[3])?constants[1]:NAN))); + computedConstants[198] = (constants[0] || constants[1]) && XOR(constants[0], constants[1]) && ((constants[2] > constants[3])?constants[1]:NAN) && constants[4] && ((constants[2] > constants[3])?constants[1]:NAN) && XOR(constants[0], constants[1]) && (constants[0] || constants[1]); + computedConstants[199] = (constants[0] && constants[1]) || XOR(constants[0], constants[1]) || ((constants[2] > constants[3])?constants[1]:NAN) || constants[4] || ((constants[2] > constants[3])?constants[1]:NAN) || XOR(constants[0], constants[1]) || (constants[0] && constants[1]); + computedConstants[200] = XOR(constants[0] && constants[1], XOR(constants[0] || constants[1], XOR((constants[2] > constants[3])?constants[1]:NAN, XOR(XOR(XOR(constants[4], (constants[2] > constants[3])?constants[1]:NAN), constants[0] || constants[1]), constants[0] && constants[1])))); + computedConstants[201] = pow(constants[0] && constants[1], pow((constants[2] > constants[3])?constants[1]:NAN, pow(pow(constants[4], (constants[2] > constants[3])?constants[1]:NAN), constants[0] && constants[1]))); + computedConstants[202] = pow(pow(pow(constants[0] && constants[1], 1.0/pow((constants[2] > constants[3])?constants[1]:NAN, 1.0/constants[4])), 1.0/((constants[2] > constants[3])?constants[1]:NAN)), 1.0/(constants[0] && constants[1])); + computedConstants[203] = -(constants[0] && constants[1])+-((constants[2] > constants[3])?constants[1]:NAN); + computedConstants[204] = -(constants[0] && constants[1])+-((constants[2] < constants[3])?constants[1]:NAN); +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + rates[0] = 1.0; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + algebraic[0] = states[0] || states[0]; + algebraic[1] = states[0] || states[0] || constants[0]; + algebraic[2] = constants[0]/XOR(constants[1], states[0]); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); +} diff --git a/tests/resources/coverage/generator/model.xor.h b/tests/resources/coverage/generator/model.xor.h new file mode 100644 index 0000000000..93d1cdae9d --- /dev/null +++ b/tests/resources/coverage/generator/model.xor.h @@ -0,0 +1,42 @@ +/* The content of this file was generated using a modified C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; + +typedef struct { + char name[38]; + char units[14]; + char component[13]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + +void deleteArray(double *array); + +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/coverage/generator/model.xor.py b/tests/resources/coverage/generator/model.xor.py new file mode 100644 index 0000000000..8fc5da945f --- /dev/null +++ b/tests/resources/coverage/generator/model.xor.py @@ -0,0 +1,634 @@ +# The content of this file was generated using a modified Python profile of libCellML 0.6.0. + +from enum import Enum +from math import * + + +__version__ = "0.5.0.post0" +LIBCELLML_VERSION = "0.6.0" + +STATE_COUNT = 1 +CONSTANT_COUNT = 7 +COMPUTED_CONSTANT_COUNT = 207 +ALGEBRAIC_COUNT = 5 +EXTERNAL_COUNT = 1 + +VOI_INFO = {"name": "t", "units": "second", "component": "my_component"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_component"} +] + +CONSTANT_INFO = [ + {"name": "m", "units": "dimensionless", "component": "my_component"}, + {"name": "n", "units": "dimensionless", "component": "my_component"}, + {"name": "o", "units": "dimensionless", "component": "my_component"}, + {"name": "p", "units": "dimensionless", "component": "my_component"}, + {"name": "q", "units": "dimensionless", "component": "my_component"}, + {"name": "r", "units": "dimensionless", "component": "my_component"}, + {"name": "s", "units": "dimensionless", "component": "my_component"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "eqnEq", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnEqCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNeq", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNeqCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLt", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLtCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLeq", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLeqCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnGt", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnGtCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnGeq", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnGeqCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAnd", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesLeftRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndParenthesesRightRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAndCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesLeftRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrParenthesesRightRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXor", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesLeftRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorParenthesesRightRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPlusMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPlusParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPlusUnary", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinus", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusParenthesesPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusParenthesesPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusParenthesesDirectUnaryMinus", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusParenthesesIndirectUnaryMinus", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusUnary", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinusUnaryParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTimesParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnDivideParenthesesRightDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerSqrt", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerSqr", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerCube", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerCi", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesLeftDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPowerParenthesesRightRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootSqrt", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootSqrtOther", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootSqr", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootCube", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootCi", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesLeftDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightPlusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightPlusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightMinusWith", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightMinusWithout", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightTimes", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightDivide", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightPower", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRootParenthesesRightRoot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnAbs", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnExp", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLn", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLog", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLog2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLog10", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnLogCi", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCeiling", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnFloor", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMin", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMinMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMax", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnMaxMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnRem", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnSin", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCos", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTan", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnSec", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCsc", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnSinh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCosh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTanh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnSech", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCsch", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoth", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArcsin", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccos", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArctan", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArcsec", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccsc", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccot", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArcsinh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccosh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArctanh", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArcsech", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccsch", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnArccoth", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewise", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePiece", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePiece2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewiseOtherwise", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePieceOtherwise", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePiecePiecePiece", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePiecePiecePiece2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPiecewisePiecePiecePieceOtherwise", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnWithPiecewise", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnWithPiecewise2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCnInteger", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCnDouble", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCnIntegerWithExponent", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCnDoubleWithExponent", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCi", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnTrue", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnFalse", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnExponentiale", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnPi", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnInfinity", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNotanumber", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForPlusOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForPlusOperator2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForMinusOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForMinusOperator2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForTimesOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForTimesOperator2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForDivideOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForDivideOperator2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForAndOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForOrOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForXorOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForPowerOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForRootOperator", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForMinusUnary", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnCoverageForMinusUnary2", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnComputedConstant1", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnComputedConstant2", "units": "dimensionless", "component": "my_component"} +] + +ALGEBRAIC_INFO = [ + {"name": "eqnOr", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnOrMultiple", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnXorCoverageParentheses", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNlaVariable1", "units": "dimensionless", "component": "my_component"}, + {"name": "eqnNlaVariable2", "units": "dimensionless", "component": "my_component"} +] + +EXTERNAL_INFO = [ + {"name": "eqnPlus", "units": "dimensionless", "component": "my_component"} +] + + +def eq_func(x, y): + return 1.0 if x == y else 0.0 + + +def neq_func(x, y): + return 1.0 if x != y else 0.0 + + +def lt_func(x, y): + return 1.0 if x < y else 0.0 + + +def leq_func(x, y): + return 1.0 if x <= y else 0.0 + + +def gt_func(x, y): + return 1.0 if x > y else 0.0 + + +def geq_func(x, y): + return 1.0 if x >= y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def or_func(x, y): + return 1.0 if bool(x) | bool(y) else 0.0 + + +def XOR_FUNC(x, y): + return 1.0 if bool(x) ^ bool(y) else 0.0 + + +def not_func(x): + return 1.0 if not bool(x) else 0.0 + + +def min(x, y): + return x if x < y else y + + +def max(x, y): + return x if x > y else y + + +def sec(x): + return 1.0/cos(x) + + +def csc(x): + return 1.0/sin(x) + + +def cot(x): + return 1.0/tan(x) + + +def sech(x): + return 1.0/cosh(x) + + +def csch(x): + return 1.0/sinh(x) + + +def coth(x): + return 1.0/tanh(x) + + +def asec(x): + return acos(1.0/x) + + +def acsc(x): + return asin(1.0/x) + + +def acot(x): + return atan(1.0/x) + + +def asech(x): + return acosh(1.0/x) + + +def acsch(x): + return asinh(1.0/x) + + +def acoth(x): + return atanh(1.0/x) + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +from nlasolver import nla_solve + + +def objective_function_0(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[3] = u[0] + algebraic[4] = u[1] + + f[0] = algebraic[3]+algebraic[4]+states[0]-0.0 + f[1] = algebraic[3]-algebraic[4]-(computed_constants[205]+computed_constants[206]) + + +def find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*2 + + u[0] = algebraic[3] + u[1] = algebraic[4] + + u = nla_solve(objective_function_0, u, 2, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[3] = u[0] + algebraic[4] = u[1] + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): + states[0] = 0.0 + constants[0] = 1.0 + constants[1] = 2.0 + constants[2] = 3.0 + constants[3] = 4.0 + constants[4] = 5.0 + constants[5] = 6.0 + constants[6] = 7.0 + computed_constants[169] = nan + computed_constants[179] = 123.0 + computed_constants[180] = 123.456789 + computed_constants[181] = 123.0e99 + computed_constants[182] = 123.456789e99 + computed_constants[184] = 1.0 + computed_constants[185] = 0.0 + computed_constants[186] = 2.71828182845905 + computed_constants[187] = 3.14159265358979 + computed_constants[188] = inf + computed_constants[189] = nan + computed_constants[205] = 1.0 + computed_constants[206] = 3.0 + algebraic[3] = 1.0 + algebraic[4] = 2.0 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = eq_func(constants[0], constants[1]) + computed_constants[1] = constants[0]/eq_func(constants[1], constants[1]) + computed_constants[2] = neq_func(constants[0], constants[1]) + computed_constants[3] = constants[0]/neq_func(constants[1], constants[2]) + computed_constants[4] = lt_func(constants[0], constants[1]) + computed_constants[5] = constants[0]/lt_func(constants[1], constants[2]) + computed_constants[6] = leq_func(constants[0], constants[1]) + computed_constants[7] = constants[0]/leq_func(constants[1], constants[2]) + computed_constants[8] = gt_func(constants[0], constants[1]) + computed_constants[9] = constants[0]/gt_func(constants[2], constants[1]) + computed_constants[10] = geq_func(constants[0], constants[1]) + computed_constants[11] = constants[0]/geq_func(constants[2], constants[1]) + computed_constants[12] = and_func(constants[0], constants[1]) + computed_constants[13] = and_func(constants[0], and_func(constants[1], constants[2])) + computed_constants[14] = and_func(lt_func(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[15] = and_func(constants[0]+constants[1], gt_func(constants[2], constants[3])) + computed_constants[16] = and_func(constants[0], gt_func(constants[1], constants[2])) + computed_constants[17] = and_func(constants[0]-constants[1], gt_func(constants[2], constants[3])) + computed_constants[18] = and_func(-constants[0], gt_func(constants[1], constants[2])) + computed_constants[19] = and_func(pow(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[20] = and_func(pow(constants[0], 1.0/constants[1]), gt_func(constants[2], constants[3])) + computed_constants[21] = and_func(lt_func(constants[0], constants[1]), constants[2]+constants[3]) + computed_constants[22] = and_func(lt_func(constants[0], constants[1]), constants[2]) + computed_constants[23] = and_func(lt_func(constants[0], constants[1]), constants[2]-constants[3]) + computed_constants[24] = and_func(lt_func(constants[0], constants[1]), -constants[2]) + computed_constants[25] = and_func(lt_func(constants[0], constants[1]), pow(constants[2], constants[3])) + computed_constants[26] = and_func(lt_func(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])) + computed_constants[27] = constants[0]/and_func(constants[1], constants[2]) + computed_constants[28] = or_func(lt_func(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[29] = or_func(constants[0]+constants[1], gt_func(constants[2], constants[3])) + computed_constants[30] = or_func(constants[0], gt_func(constants[1], constants[2])) + computed_constants[31] = or_func(constants[0]-constants[1], gt_func(constants[2], constants[3])) + computed_constants[32] = or_func(-constants[0], gt_func(constants[1], constants[2])) + computed_constants[33] = or_func(pow(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[34] = or_func(pow(constants[0], 1.0/constants[1]), gt_func(constants[2], constants[3])) + computed_constants[35] = or_func(lt_func(constants[0], constants[1]), constants[2]+constants[3]) + computed_constants[36] = or_func(lt_func(constants[0], constants[1]), constants[2]) + computed_constants[37] = or_func(lt_func(constants[0], constants[1]), constants[2]-constants[3]) + computed_constants[38] = or_func(lt_func(constants[0], constants[1]), -constants[2]) + computed_constants[39] = or_func(lt_func(constants[0], constants[1]), pow(constants[2], constants[3])) + computed_constants[40] = or_func(lt_func(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])) + computed_constants[41] = constants[0]/or_func(constants[1], constants[2]) + computed_constants[42] = XOR_FUNC(constants[0], constants[1]) + computed_constants[43] = XOR_FUNC(constants[0], XOR_FUNC(constants[1], constants[2])) + computed_constants[44] = XOR_FUNC(lt_func(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[45] = XOR_FUNC(constants[0]+constants[1], gt_func(constants[2], constants[3])) + computed_constants[46] = XOR_FUNC(constants[0], gt_func(constants[1], constants[2])) + computed_constants[47] = XOR_FUNC(constants[0]-constants[1], gt_func(constants[2], constants[3])) + computed_constants[48] = XOR_FUNC(-constants[0], gt_func(constants[1], constants[2])) + computed_constants[49] = XOR_FUNC(pow(constants[0], constants[1]), gt_func(constants[2], constants[3])) + computed_constants[50] = XOR_FUNC(pow(constants[0], 1.0/constants[1]), gt_func(constants[2], constants[3])) + computed_constants[51] = XOR_FUNC(lt_func(constants[0], constants[1]), constants[2]+constants[3]) + computed_constants[52] = XOR_FUNC(lt_func(constants[0], constants[1]), constants[2]) + computed_constants[53] = XOR_FUNC(lt_func(constants[0], constants[1]), constants[2]-constants[3]) + computed_constants[54] = XOR_FUNC(lt_func(constants[0], constants[1]), -constants[2]) + computed_constants[55] = XOR_FUNC(lt_func(constants[0], constants[1]), pow(constants[2], constants[3])) + computed_constants[56] = XOR_FUNC(lt_func(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])) + computed_constants[57] = not_func(constants[0]) + computed_constants[58] = constants[0]+constants[1]+constants[2] + computed_constants[59] = lt_func(constants[0], constants[1])+gt_func(constants[2], constants[3]) + computed_constants[60] = constants[0] + computed_constants[61] = constants[0]-constants[1] + computed_constants[62] = lt_func(constants[0], constants[1])-gt_func(constants[2], constants[3]) + computed_constants[63] = lt_func(constants[0], constants[1])-(constants[2]+constants[3]) + computed_constants[64] = lt_func(constants[0], constants[1])-constants[2] + computed_constants[65] = constants[0]-(-constants[1]) + computed_constants[66] = constants[0]-(-constants[1]*constants[2]) + computed_constants[67] = -constants[0] + computed_constants[68] = -lt_func(constants[0], constants[1]) + computed_constants[69] = constants[0]*constants[1] + computed_constants[70] = constants[0]*constants[1]*constants[2] + computed_constants[71] = lt_func(constants[0], constants[1])*gt_func(constants[2], constants[3]) + computed_constants[72] = (constants[0]+constants[1])*gt_func(constants[2], constants[3]) + computed_constants[73] = constants[0]*gt_func(constants[1], constants[2]) + computed_constants[74] = (constants[0]-constants[1])*gt_func(constants[2], constants[3]) + computed_constants[75] = -constants[0]*gt_func(constants[1], constants[2]) + computed_constants[76] = lt_func(constants[0], constants[1])*(constants[2]+constants[3]) + computed_constants[77] = lt_func(constants[0], constants[1])*constants[2] + computed_constants[78] = lt_func(constants[0], constants[1])*(constants[2]-constants[3]) + computed_constants[79] = lt_func(constants[0], constants[1])*-constants[2] + computed_constants[80] = constants[0]/constants[1] + computed_constants[81] = lt_func(constants[0], constants[1])/gt_func(constants[3], constants[2]) + computed_constants[82] = (constants[0]+constants[1])/gt_func(constants[3], constants[2]) + computed_constants[83] = constants[0]/gt_func(constants[2], constants[1]) + computed_constants[84] = (constants[0]-constants[1])/gt_func(constants[3], constants[2]) + computed_constants[85] = -constants[0]/gt_func(constants[2], constants[1]) + computed_constants[86] = lt_func(constants[0], constants[1])/(constants[2]+constants[3]) + computed_constants[87] = lt_func(constants[0], constants[1])/constants[2] + computed_constants[88] = lt_func(constants[0], constants[1])/(constants[2]-constants[3]) + computed_constants[89] = lt_func(constants[0], constants[1])/-constants[2] + computed_constants[90] = lt_func(constants[0], constants[1])/(constants[2]*constants[3]) + computed_constants[91] = lt_func(constants[0], constants[1])/(constants[2]/constants[3]) + computed_constants[92] = sqrt(constants[0]) + computed_constants[93] = pow(constants[0], 2.0) + computed_constants[94] = pow(constants[0], 3.0) + computed_constants[95] = pow(constants[0], constants[1]) + computed_constants[96] = pow(leq_func(constants[0], constants[1]), geq_func(constants[2], constants[3])) + computed_constants[97] = pow(constants[0]+constants[1], geq_func(constants[2], constants[3])) + computed_constants[98] = pow(constants[0], geq_func(constants[1], constants[2])) + computed_constants[99] = pow(constants[0]-constants[1], geq_func(constants[2], constants[3])) + computed_constants[100] = pow(-constants[0], geq_func(constants[1], constants[2])) + computed_constants[101] = pow(constants[0]*constants[1], geq_func(constants[2], constants[3])) + computed_constants[102] = pow(constants[0]/constants[1], geq_func(constants[2], constants[3])) + computed_constants[103] = pow(leq_func(constants[0], constants[1]), constants[2]+constants[3]) + computed_constants[104] = pow(leq_func(constants[0], constants[1]), constants[2]) + computed_constants[105] = pow(leq_func(constants[0], constants[1]), constants[2]-constants[3]) + computed_constants[106] = pow(leq_func(constants[0], constants[1]), -constants[2]) + computed_constants[107] = pow(leq_func(constants[0], constants[1]), constants[2]*constants[3]) + computed_constants[108] = pow(leq_func(constants[0], constants[1]), constants[2]/constants[3]) + computed_constants[109] = pow(leq_func(constants[0], constants[1]), pow(constants[2], constants[3])) + computed_constants[110] = pow(leq_func(constants[0], constants[1]), pow(constants[2], 1.0/constants[3])) + computed_constants[111] = sqrt(constants[0]) + computed_constants[112] = sqrt(constants[0]) + computed_constants[113] = pow(constants[0], 1.0/0.5) + computed_constants[114] = pow(constants[0], 1.0/3.0) + computed_constants[115] = pow(constants[0], 1.0/constants[1]) + computed_constants[116] = pow(lt_func(constants[0], constants[1]), 1.0/gt_func(constants[3], constants[2])) + computed_constants[117] = pow(constants[0]+constants[1], 1.0/gt_func(constants[3], constants[2])) + computed_constants[118] = pow(constants[0], 1.0/gt_func(constants[2], constants[1])) + computed_constants[119] = pow(constants[0]-constants[1], 1.0/gt_func(constants[3], constants[2])) + computed_constants[120] = pow(-constants[0], 1.0/gt_func(constants[2], constants[1])) + computed_constants[121] = pow(constants[0]*constants[1], 1.0/gt_func(constants[3], constants[2])) + computed_constants[122] = pow(constants[0]/constants[1], 1.0/gt_func(constants[3], constants[2])) + computed_constants[123] = pow(lt_func(constants[0], constants[1]), 1.0/(constants[2]+constants[3])) + computed_constants[124] = pow(lt_func(constants[0], constants[1]), 1.0/constants[2]) + computed_constants[125] = pow(lt_func(constants[0], constants[1]), 1.0/(constants[2]-constants[3])) + computed_constants[126] = pow(lt_func(constants[0], constants[1]), 1.0/-constants[2]) + computed_constants[127] = pow(lt_func(constants[0], constants[1]), 1.0/(constants[2]*constants[3])) + computed_constants[128] = pow(lt_func(constants[0], constants[1]), 1.0/(constants[2]/constants[3])) + computed_constants[129] = pow(lt_func(constants[0], constants[1]), 1.0/pow(constants[2], constants[3])) + computed_constants[130] = pow(lt_func(constants[0], constants[1]), 1.0/pow(constants[2], 1.0/constants[3])) + computed_constants[131] = fabs(constants[0]) + computed_constants[132] = exp(constants[0]) + computed_constants[133] = log(constants[0]) + computed_constants[134] = log10(constants[0]) + computed_constants[135] = log(constants[0])/log(2.0) + computed_constants[136] = log10(constants[0]) + computed_constants[137] = log(constants[0])/log(constants[1]) + computed_constants[138] = ceil(constants[0]) + computed_constants[139] = floor(constants[0]) + computed_constants[140] = min(constants[0], constants[1]) + computed_constants[141] = min(constants[0], min(constants[1], constants[2])) + computed_constants[142] = max(constants[0], constants[1]) + computed_constants[143] = max(constants[0], max(constants[1], constants[2])) + computed_constants[144] = fmod(constants[0], constants[1]) + computed_constants[145] = sin(constants[0]) + computed_constants[146] = cos(constants[0]) + computed_constants[147] = tan(constants[0]) + computed_constants[148] = sec(constants[0]) + computed_constants[149] = csc(constants[0]) + computed_constants[150] = cot(constants[0]) + computed_constants[151] = sinh(constants[0]) + computed_constants[152] = cosh(constants[0]) + computed_constants[153] = tanh(constants[0]) + computed_constants[154] = sech(constants[0]) + computed_constants[155] = csch(constants[0]) + computed_constants[156] = coth(constants[0]) + computed_constants[157] = asin(constants[0]) + computed_constants[158] = acos(constants[0]) + computed_constants[159] = atan(constants[0]) + computed_constants[160] = asec(constants[0]) + computed_constants[161] = acsc(constants[0]) + computed_constants[162] = acot(constants[0]) + computed_constants[163] = asinh(constants[0]) + computed_constants[164] = acosh(constants[0]) + computed_constants[165] = atanh(constants[0]/2.0) + computed_constants[166] = asech(constants[0]) + computed_constants[167] = acsch(constants[0]) + computed_constants[168] = acoth(2.0*constants[0]) + computed_constants[170] = constants[0] if gt_func(constants[0], constants[1]) else nan + computed_constants[171] = constants[0] if lt_func(constants[0], constants[1]) else nan + computed_constants[172] = constants[0] + computed_constants[173] = constants[0] if gt_func(constants[0], constants[1]) else constants[2] + computed_constants[174] = constants[0] if gt_func(constants[0], constants[1]) else constants[2] if gt_func(constants[2], constants[3]) else constants[4] if gt_func(constants[4], constants[5]) else nan + computed_constants[175] = constants[0] if lt_func(constants[0], constants[1]) else constants[2] if gt_func(constants[2], constants[3]) else constants[4] if gt_func(constants[4], constants[5]) else nan + computed_constants[176] = constants[0] if gt_func(constants[0], constants[1]) else constants[2] if gt_func(constants[2], constants[3]) else constants[4] if gt_func(constants[4], constants[5]) else constants[6] + computed_constants[177] = 123.0+(constants[0] if gt_func(constants[0], constants[1]) else nan) + computed_constants[178] = 123.0+(constants[0] if lt_func(constants[0], constants[1]) else nan) + computed_constants[183] = constants[0] + computed_constants[190] = and_func(constants[0], constants[1])+(constants[1] if gt_func(constants[2], constants[3]) else nan)+constants[4]+and_func(constants[5], constants[6]) + computed_constants[191] = and_func(constants[0], constants[1])+(constants[1] if lt_func(constants[2], constants[3]) else nan)+constants[4]+and_func(constants[5], constants[6]) + computed_constants[192] = and_func(constants[0], constants[1])-((constants[1] if gt_func(constants[2], constants[3]) else nan)-(constants[4]-(constants[1] if gt_func(constants[2], constants[3]) else nan)))-and_func(constants[5], constants[6]) + computed_constants[193] = and_func(constants[0], constants[1])-((constants[1] if lt_func(constants[2], constants[3]) else nan)-(constants[4]-(constants[1] if lt_func(constants[2], constants[3]) else nan)))-and_func(constants[5], constants[6]) + computed_constants[194] = and_func(constants[0], constants[1])*(constants[1] if gt_func(constants[2], constants[3]) else nan)*constants[4]*(constants[1] if gt_func(constants[2], constants[3]) else nan)*and_func(constants[5], constants[6]) + computed_constants[195] = and_func(constants[0], constants[1])*(constants[1] if lt_func(constants[2], constants[3]) else nan)*constants[4]*(constants[1] if lt_func(constants[2], constants[3]) else nan)*and_func(constants[5], constants[6]) + computed_constants[196] = and_func(constants[0], constants[1])/((constants[1] if gt_func(constants[2], constants[3]) else nan)/(constants[4]/(constants[1] if gt_func(constants[2], constants[3]) else nan))) + computed_constants[197] = and_func(constants[0], constants[1])/((constants[1] if lt_func(constants[2], constants[3]) else nan)/(constants[4]/(constants[1] if lt_func(constants[2], constants[3]) else nan))) + computed_constants[198] = and_func(or_func(constants[0], constants[1]), and_func(XOR_FUNC(constants[0], constants[1]), and_func(constants[1] if gt_func(constants[2], constants[3]) else nan, and_func(and_func(and_func(constants[4], constants[1] if gt_func(constants[2], constants[3]) else nan), XOR_FUNC(constants[0], constants[1])), or_func(constants[0], constants[1]))))) + computed_constants[199] = or_func(and_func(constants[0], constants[1]), or_func(XOR_FUNC(constants[0], constants[1]), or_func(constants[1] if gt_func(constants[2], constants[3]) else nan, or_func(or_func(or_func(constants[4], constants[1] if gt_func(constants[2], constants[3]) else nan), XOR_FUNC(constants[0], constants[1])), and_func(constants[0], constants[1]))))) + computed_constants[200] = XOR_FUNC(and_func(constants[0], constants[1]), XOR_FUNC(or_func(constants[0], constants[1]), XOR_FUNC(constants[1] if gt_func(constants[2], constants[3]) else nan, XOR_FUNC(XOR_FUNC(XOR_FUNC(constants[4], constants[1] if gt_func(constants[2], constants[3]) else nan), or_func(constants[0], constants[1])), and_func(constants[0], constants[1]))))) + computed_constants[201] = pow(and_func(constants[0], constants[1]), pow(constants[1] if gt_func(constants[2], constants[3]) else nan, pow(pow(constants[4], constants[1] if gt_func(constants[2], constants[3]) else nan), and_func(constants[0], constants[1])))) + computed_constants[202] = pow(pow(pow(and_func(constants[0], constants[1]), 1.0/pow(constants[1] if gt_func(constants[2], constants[3]) else nan, 1.0/constants[4])), 1.0/(constants[1] if gt_func(constants[2], constants[3]) else nan)), 1.0/and_func(constants[0], constants[1])) + computed_constants[203] = -and_func(constants[0], constants[1])+-(constants[1] if gt_func(constants[2], constants[3]) else nan) + computed_constants[204] = -and_func(constants[0], constants[1])+-(constants[1] if lt_func(constants[2], constants[3]) else nan) + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + rates[0] = 1.0 + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[0] = or_func(states[0], states[0]) + algebraic[1] = or_func(states[0], or_func(states[0], constants[0])) + algebraic[2] = constants[0]/XOR_FUNC(constants[1], states[0]) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals) diff --git a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.c b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.c index 680c6813df..efbca9b8c7 100644 --- a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.c +++ b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.c @@ -5,21 +5,51 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 2; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VARIABLE_INFO[] = { - {"x", "dimensionless", "my_algebraic_eqn", COMPUTED_CONSTANT}, - {"a", "dimensionless", "my_algebraic_eqn", COMPUTED_CONSTANT} +const VariableInfo CONSTANT_INFO[] = { }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"x", "dimensionless", "my_algebraic_eqn"}, + {"a", "dimensionless", "my_algebraic_eqn"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -31,16 +61,16 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *variables) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[1] = 1.0; + computedConstants[1] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[0] = variables[1]; + computedConstants[0] = computedConstants[1]; } -void computeVariables(double *variables) +void computeVariables(double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.c b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.c index c3f8a31edb..f8aa4b40f0 100644 --- a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.c +++ b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.c @@ -5,21 +5,66 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 1; +const size_t EXTERNAL_COUNT = 1; -const VariableInfo VARIABLE_INFO[] = { - {"x", "dimensionless", "my_algebraic_eqn", ALGEBRAIC}, - {"a", "dimensionless", "my_algebraic_eqn", EXTERNAL} +const VariableInfo CONSTANT_INFO[] = { }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"x", "dimensionless", "my_algebraic_eqn"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"a", "dimensionless", "my_algebraic_eqn"} +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { res[i] = NAN; } @@ -31,17 +76,16 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *variables, ExternalVariable externalVariable) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[1] = externalVariable(variables, 1); } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeVariables(double *variables, ExternalVariable externalVariable) +void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - variables[1] = externalVariable(variables, 1); - variables[0] = variables[1]; + externals[0] = externalVariable(constants, computedConstants, algebraic, externals, 0); + algebraic[0] = externals[0]; } diff --git a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.h b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.h index 1ad708919e..f190d5f59a 100644 --- a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.h +++ b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.h @@ -7,29 +7,31 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; typedef struct { char name[2]; char units[14]; char component[17]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); -double * createVariablesArray(); void deleteArray(double *array); -typedef double (* ExternalVariable)(double *variables, size_t index); +typedef double (* ExternalVariable)(double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); -void initialiseVariables(double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeVariables(double *variables, ExternalVariable externalVariable); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.py b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.py index 954dbf9e93..11024fde51 100644 --- a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.py +++ b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.external.py @@ -4,37 +4,53 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 1 +EXTERNAL_COUNT = 1 +CONSTANT_INFO = [ +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - EXTERNAL = 3 +COMPUTED_CONSTANT_INFO = [ +] +ALGEBRAIC_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_algebraic_eqn"} +] -VARIABLE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.ALGEBRAIC}, - {"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.EXTERNAL} +EXTERNAL_INFO = [ + {"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn"} ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT -def initialise_variables(variables, external_variable): - variables[1] = external_variable(variables, 1) +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +def initialise_variables(constants, computed_constants, algebraic): + pass -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_variables(variables, external_variable): - variables[1] = external_variable(variables, 1) - variables[0] = variables[1] +def compute_variables(constants, computed_constants, algebraic, externals, external_variable): + externals[0] = external_variable(constants, computed_constants, algebraic, externals, 0) + algebraic[0] = externals[0] diff --git a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.h b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.h index a4e571d3ad..cf528ba5a5 100644 --- a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.h +++ b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.h @@ -7,26 +7,26 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[17]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); -double * createVariablesArray(); void deleteArray(double *array); -void initialiseVariables(double *variables); -void computeComputedConstants(double *variables); -void computeVariables(double *variables); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.py b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.py index f69e3d0495..e207d4ba26 100644 --- a/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.py +++ b/tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.py @@ -4,35 +4,44 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 2 +ALGEBRAIC_COUNT = 0 +CONSTANT_INFO = [ +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - +COMPUTED_CONSTANT_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_algebraic_eqn"}, + {"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn"} +] -VARIABLE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.COMPUTED_CONSTANT} +ALGEBRAIC_INFO = [ ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(variables): - variables[1] = 1.0 +def initialise_variables(constants, computed_constants, algebraic): + computed_constants[1] = 1.0 -def compute_computed_constants(variables): - variables[0] = variables[1] +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = computed_constants[1] -def compute_variables(variables): +def compute_variables(constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.c b/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.c index 61548b6136..95bd7edc6f 100644 --- a/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.c +++ b/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.c @@ -5,21 +5,51 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VARIABLE_INFO[] = { - {"x", "dimensionless", "my_algebraic_eqn", COMPUTED_CONSTANT}, - {"a", "dimensionless", "my_algebraic_eqn", CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"a", "dimensionless", "my_algebraic_eqn"} }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"x", "dimensionless", "my_algebraic_eqn"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -31,16 +61,16 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *variables) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[1] = 1.0; + constants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[0] = variables[1]; + computedConstants[0] = constants[0]; } -void computeVariables(double *variables) +void computeVariables(double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.h b/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.h index a4e571d3ad..cf528ba5a5 100644 --- a/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.h +++ b/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.h @@ -7,26 +7,26 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[17]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); -double * createVariablesArray(); void deleteArray(double *array); -void initialiseVariables(double *variables); -void computeComputedConstants(double *variables); -void computeVariables(double *variables); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.py b/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.py index 2233a67e1f..910b78d087 100644 --- a/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.py +++ b/tests/resources/generator/algebraic_eqn_const_var_on_rhs/model.py @@ -4,35 +4,44 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 0 +CONSTANT_INFO = [ + {"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn"} +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - +COMPUTED_CONSTANT_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_algebraic_eqn"} +] -VARIABLE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.CONSTANT} +ALGEBRAIC_INFO = [ ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(variables): - variables[1] = 1.0 +def initialise_variables(constants, computed_constants, algebraic): + constants[0] = 1.0 -def compute_computed_constants(variables): - variables[0] = variables[1] +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[0] -def compute_variables(variables): +def compute_variables(constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.c b/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.c index 1f8b5acb40..235767fa8b 100644 --- a/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.c +++ b/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.c @@ -5,20 +5,50 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 1; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VARIABLE_INFO[] = { - {"x", "dimensionless", "my_component", COMPUTED_CONSTANT} +const VariableInfo CONSTANT_INFO[] = { }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"x", "dimensionless", "my_component"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -30,15 +60,15 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *variables) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; + computedConstants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeVariables(double *variables) +void computeVariables(double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.h b/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.h index 75dd2ed790..7c2e4a401e 100644 --- a/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.h +++ b/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.h @@ -7,26 +7,26 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[13]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); -double * createVariablesArray(); void deleteArray(double *array); -void initialiseVariables(double *variables); -void computeComputedConstants(double *variables); -void computeVariables(double *variables); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.py b/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.py index 5ac1d1e02a..388a8fcdf9 100644 --- a/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.py +++ b/tests/resources/generator/algebraic_eqn_constant_on_rhs/model.py @@ -4,34 +4,43 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 1 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 0 +CONSTANT_INFO = [ +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - +COMPUTED_CONSTANT_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_component"} +] -VARIABLE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT} +ALGEBRAIC_INFO = [ ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(variables): - variables[0] = 1.0 +def initialise_variables(constants, computed_constants, algebraic): + computed_constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_variables(variables): +def compute_variables(constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.c b/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.c index e23a8eba7a..ba5b624fbb 100644 --- a/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.c +++ b/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.c @@ -5,21 +5,29 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 1; -const VariableInfo VOI_INFO = {"t", "second", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "environment"}; const VariableInfo STATE_INFO[] = { - {"v", "dimensionless", "my_ode", STATE} + {"v", "dimensionless", "my_ode"} }; -const VariableInfo VARIABLE_INFO[] = { - {"a", "per_s", "my_ode", COMPUTED_CONSTANT}, - {"x", "per_s", "my_algebraic_eqn", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"a", "per_s", "my_ode"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"x", "per_s", "my_algebraic_eqn"} }; double * createStatesArray() @@ -33,11 +41,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -49,22 +79,22 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; states[0] = 1.0; + computedConstants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - rates[0] = variables[0]; + rates[0] = computedConstants[0]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[1] = rates[0]; + algebraic[0] = rates[0]; } diff --git a/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.h b/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.h index d63dc72a06..e96595b45d 100644 --- a/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.h +++ b/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[17]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.py b/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.py index fd4d449b36..cf08970aca 100644 --- a/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.py +++ b/tests/resources/generator/algebraic_eqn_derivative_on_rhs/model.py @@ -4,30 +4,29 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 1 +VOI_INFO = {"name": "t", "units": "second", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "v", "units": "dimensionless", "component": "my_ode"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "v", "units": "dimensionless", "component": "my_ode", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ + {"name": "a", "units": "per_s", "component": "my_ode"} ] -VARIABLE_INFO = [ - {"name": "a", "units": "per_s", "component": "my_ode", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "x", "units": "per_s", "component": "my_algebraic_eqn", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "x", "units": "per_s", "component": "my_algebraic_eqn"} ] @@ -35,22 +34,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 1.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 + computed_constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - rates[0] = variables[0] +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + rates[0] = computed_constants[0] -def compute_variables(voi, states, rates, variables): - variables[1] = rates[0] +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[0] = rates[0] diff --git a/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.c b/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.c index 550702f11e..12cb9c0577 100644 --- a/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.c +++ b/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.c @@ -5,21 +5,29 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 1; -const VariableInfo VOI_INFO = {"t", "second", "my_component", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "my_component"}; const VariableInfo STATE_INFO[] = { - {"v", "dimensionless", "my_component", STATE} + {"v", "dimensionless", "my_component"} }; -const VariableInfo VARIABLE_INFO[] = { - {"a", "per_s", "my_component", COMPUTED_CONSTANT}, - {"x", "per_s", "my_component", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"a", "per_s", "my_component"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"x", "per_s", "my_component"} }; double * createStatesArray() @@ -33,11 +41,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -49,22 +79,22 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; states[0] = 1.0; + computedConstants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - rates[0] = variables[0]; + rates[0] = computedConstants[0]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[1] = rates[0]; + algebraic[0] = rates[0]; } diff --git a/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.h b/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.h index f1e1489ff9..d7cc1bd25d 100644 --- a/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.h +++ b/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[13]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.py b/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.py index f1ed0b42b6..8cb56321af 100644 --- a/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.py +++ b/tests/resources/generator/algebraic_eqn_derivative_on_rhs_one_component/model.py @@ -4,30 +4,29 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 1 +VOI_INFO = {"name": "t", "units": "second", "component": "my_component"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "v", "units": "dimensionless", "component": "my_component"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "my_component", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "v", "units": "dimensionless", "component": "my_component", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ + {"name": "a", "units": "per_s", "component": "my_component"} ] -VARIABLE_INFO = [ - {"name": "a", "units": "per_s", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "x", "units": "per_s", "component": "my_component", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "x", "units": "per_s", "component": "my_component"} ] @@ -35,22 +34,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 1.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 + computed_constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - rates[0] = variables[0] +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + rates[0] = computed_constants[0] -def compute_variables(voi, states, rates, variables): - variables[1] = rates[0] +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[0] = rates[0] diff --git a/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.c b/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.c index c9d8e5692f..b9a7636903 100644 --- a/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.c +++ b/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.c @@ -5,21 +5,29 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 1; -const VariableInfo VOI_INFO = {"t", "second", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "environment"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_ode", STATE} + {"x", "dimensionless", "my_ode"} }; -const VariableInfo VARIABLE_INFO[] = { - {"a", "per_s", "my_ode", COMPUTED_CONSTANT}, - {"xx", "dimensionless", "my_algebraic_eqn", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"a", "per_s", "my_ode"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"xx", "dimensionless", "my_algebraic_eqn"} }; double * createStatesArray() @@ -33,11 +41,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -49,22 +79,22 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; states[0] = 1.0; + computedConstants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - rates[0] = variables[0]; + rates[0] = computedConstants[0]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[1] = 2.0*states[0]; + algebraic[0] = 2.0*states[0]; } diff --git a/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.h b/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.h index cd16c62daf..6693d9766e 100644 --- a/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.h +++ b/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[3]; char units[14]; char component[17]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.py b/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.py index eef4ac0553..2a658dd544 100644 --- a/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.py +++ b/tests/resources/generator/algebraic_eqn_state_var_on_rhs/model.py @@ -4,30 +4,29 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 1 +VOI_INFO = {"name": "t", "units": "second", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_ode"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_ode", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ + {"name": "a", "units": "per_s", "component": "my_ode"} ] -VARIABLE_INFO = [ - {"name": "a", "units": "per_s", "component": "my_ode", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "xx", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "xx", "units": "dimensionless", "component": "my_algebraic_eqn"} ] @@ -35,22 +34,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 1.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 + computed_constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - rates[0] = variables[0] +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + rates[0] = computed_constants[0] -def compute_variables(voi, states, rates, variables): - variables[1] = 2.0*states[0] +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[0] = 2.0*states[0] diff --git a/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.c b/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.c index 33fc476974..c02457b4a9 100644 --- a/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.c +++ b/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.c @@ -5,21 +5,29 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 1; -const VariableInfo VOI_INFO = {"t", "second", "my_model", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "my_model"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_model", STATE} + {"x", "dimensionless", "my_model"} }; -const VariableInfo VARIABLE_INFO[] = { - {"a", "per_s", "my_model", COMPUTED_CONSTANT}, - {"xx", "dimensionless", "my_model", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"a", "per_s", "my_model"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"xx", "dimensionless", "my_model"} }; double * createStatesArray() @@ -33,11 +41,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -49,22 +79,22 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; states[0] = 1.0; + computedConstants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - rates[0] = variables[0]; + rates[0] = computedConstants[0]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[1] = 2.0*states[0]; + algebraic[0] = 2.0*states[0]; } diff --git a/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.h b/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.h index d82daff6a5..c84c15fdf3 100644 --- a/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.h +++ b/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[3]; char units[14]; char component[9]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.py b/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.py index d35535a821..9041732b3c 100644 --- a/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.py +++ b/tests/resources/generator/algebraic_eqn_state_var_on_rhs_one_component/model.py @@ -4,30 +4,29 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 1 +VOI_INFO = {"name": "t", "units": "second", "component": "my_model"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_model"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "my_model", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_model", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ + {"name": "a", "units": "per_s", "component": "my_model"} ] -VARIABLE_INFO = [ - {"name": "a", "units": "per_s", "component": "my_model", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "xx", "units": "dimensionless", "component": "my_model", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "xx", "units": "dimensionless", "component": "my_model"} ] @@ -35,22 +34,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 1.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 + computed_constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - rates[0] = variables[0] +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + rates[0] = computed_constants[0] -def compute_variables(voi, states, rates, variables): - variables[1] = 2.0*states[0] +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[0] = 2.0*states[0] diff --git a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.c b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.c index da6384a599..0e9046e7d5 100644 --- a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.c +++ b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.c @@ -5,23 +5,53 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 4; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 3; +const size_t ALGEBRAIC_COUNT = 1; -const VariableInfo VARIABLE_INFO[] = { - {"b", "dimensionless", "my_algebraic_eqn", COMPUTED_CONSTANT}, - {"c", "dimensionless", "my_algebraic_eqn", COMPUTED_CONSTANT}, - {"d", "dimensionless", "my_algebraic_eqn", COMPUTED_CONSTANT}, - {"a", "dimensionless", "my_algebraic_eqn", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"b", "dimensionless", "my_algebraic_eqn"}, + {"c", "dimensionless", "my_algebraic_eqn"}, + {"d", "dimensionless", "my_algebraic_eqn"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"a", "dimensionless", "my_algebraic_eqn"} +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -34,7 +64,9 @@ void deleteArray(double *array) } typedef struct { - double *variables; + double *constants; + double *computedConstants; + double *algebraic; } RootFindingInfo; extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), @@ -42,38 +74,40 @@ extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), void objectiveFunction0(double *u, double *f, void *data) { - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[3] = u[0]; + algebraic[0] = u[0]; - f[0] = variables[3]+variables[0]-(variables[1]+variables[2]); + f[0] = algebraic[0]+computedConstants[0]-(computedConstants[1]+computedConstants[2]); } -void findRoot0(double *variables) +void findRoot0(double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { variables }; + RootFindingInfo rfi = { constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[3]; + u[0] = algebraic[0]; nlaSolve(objectiveFunction0, u, 1, &rfi); - variables[3] = u[0]; + algebraic[0] = u[0]; } -void initialiseVariables(double *variables) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[3] = 1.0; - variables[0] = 3.0; - variables[1] = 5.0; - variables[2] = 7.0; + computedConstants[0] = 3.0; + computedConstants[1] = 5.0; + computedConstants[2] = 7.0; + algebraic[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeVariables(double *variables) +void computeVariables(double *constants, double *computedConstants, double *algebraic) { - findRoot0(variables); + findRoot0(constants, computedConstants, algebraic); } diff --git a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.c b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.c index 1ef331b07f..391747c0c1 100644 --- a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.c +++ b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.c @@ -5,23 +5,68 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 4; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 2; +const size_t ALGEBRAIC_COUNT = 1; +const size_t EXTERNAL_COUNT = 1; -const VariableInfo VARIABLE_INFO[] = { - {"b", "dimensionless", "my_algebraic_eqn", COMPUTED_CONSTANT}, - {"c", "dimensionless", "my_algebraic_eqn", COMPUTED_CONSTANT}, - {"d", "dimensionless", "my_algebraic_eqn", COMPUTED_CONSTANT}, - {"a", "dimensionless", "my_algebraic_eqn", EXTERNAL} +const VariableInfo CONSTANT_INFO[] = { }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"b", "dimensionless", "my_algebraic_eqn"}, + {"d", "dimensionless", "my_algebraic_eqn"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"a", "dimensionless", "my_algebraic_eqn"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"c", "dimensionless", "my_algebraic_eqn"} +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { res[i] = NAN; } @@ -33,19 +78,53 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *variables, ExternalVariable externalVariable) +typedef struct { + double *constants; + double *computedConstants; + double *algebraic; + double *externals; +} RootFindingInfo; + +extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), + double *u, size_t n, void *data); + +void objectiveFunction0(double *u, double *f, void *data) +{ + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[0] = u[0]; + + f[0] = algebraic[0]+computedConstants[0]-(externals[0]+computedConstants[1]); +} + +void findRoot0(double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[0]; + + nlaSolve(objectiveFunction0, u, 1, &rfi); + + algebraic[0] = u[0]; +} + +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[0] = 3.0; - variables[1] = 5.0; - variables[2] = 7.0; - variables[3] = externalVariable(variables, 3); + computedConstants[0] = 3.0; + computedConstants[1] = 7.0; + algebraic[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeVariables(double *variables, ExternalVariable externalVariable) +void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - variables[3] = externalVariable(variables, 3); + externals[0] = externalVariable(constants, computedConstants, algebraic, externals, 0); + findRoot0(constants, computedConstants, algebraic, externals); } diff --git a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.h b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.h index 1ad708919e..f190d5f59a 100644 --- a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.h +++ b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.h @@ -7,29 +7,31 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; typedef struct { char name[2]; char units[14]; char component[17]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); -double * createVariablesArray(); void deleteArray(double *array); -typedef double (* ExternalVariable)(double *variables, size_t index); +typedef double (* ExternalVariable)(double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); -void initialiseVariables(double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeVariables(double *variables, ExternalVariable externalVariable); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.py b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.py index b115e83971..bb6e8c0f03 100644 --- a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.py +++ b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.external.py @@ -4,41 +4,81 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 4 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 2 +ALGEBRAIC_COUNT = 1 +EXTERNAL_COUNT = 1 +CONSTANT_INFO = [ +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - EXTERNAL = 3 +COMPUTED_CONSTANT_INFO = [ + {"name": "b", "units": "dimensionless", "component": "my_algebraic_eqn"}, + {"name": "d", "units": "dimensionless", "component": "my_algebraic_eqn"} +] +ALGEBRAIC_INFO = [ + {"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn"} +] -VARIABLE_INFO = [ - {"name": "b", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "c", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "d", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.EXTERNAL} +EXTERNAL_INFO = [ + {"name": "c", "units": "dimensionless", "component": "my_algebraic_eqn"} ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +from nlasolver import nla_solve + + +def objective_function_0(u, f, data): + constants = data[0] + computed_constants = data[1] + algebraic = data[2] + externals = data[3] + + algebraic[0] = u[0] + + f[0] = algebraic[0]+computed_constants[0]-(externals[0]+computed_constants[1]) + + +def find_root_0(constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[0] + + u = nla_solve(objective_function_0, u, 1, [constants, computed_constants, algebraic, externals]) + + algebraic[0] = u[0] -def initialise_variables(variables, external_variable): - variables[0] = 3.0 - variables[1] = 5.0 - variables[2] = 7.0 - variables[3] = external_variable(variables, 3) +def initialise_variables(constants, computed_constants, algebraic): + computed_constants[0] = 3.0 + computed_constants[1] = 7.0 + algebraic[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_variables(variables, external_variable): - variables[3] = external_variable(variables, 3) +def compute_variables(constants, computed_constants, algebraic, externals, external_variable): + externals[0] = external_variable(constants, computed_constants, algebraic, externals, 0) + find_root_0(constants, computed_constants, algebraic, externals) diff --git a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.h b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.h index a4e571d3ad..cf528ba5a5 100644 --- a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.h +++ b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.h @@ -7,26 +7,26 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[17]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); -double * createVariablesArray(); void deleteArray(double *array); -void initialiseVariables(double *variables); -void computeComputedConstants(double *variables); -void computeVariables(double *variables); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.py b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.py index 475c6660ef..b5fba3c94e 100644 --- a/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.py +++ b/tests/resources/generator/algebraic_eqn_with_one_non_isolated_unknown/model.py @@ -4,61 +4,72 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 4 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 3 +ALGEBRAIC_COUNT = 1 +CONSTANT_INFO = [ +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - +COMPUTED_CONSTANT_INFO = [ + {"name": "b", "units": "dimensionless", "component": "my_algebraic_eqn"}, + {"name": "c", "units": "dimensionless", "component": "my_algebraic_eqn"}, + {"name": "d", "units": "dimensionless", "component": "my_algebraic_eqn"} +] -VARIABLE_INFO = [ - {"name": "b", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "c", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "d", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn"} ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT from nlasolver import nla_solve def objective_function_0(u, f, data): - variables = data[0] + constants = data[0] + computed_constants = data[1] + algebraic = data[2] - variables[3] = u[0] + algebraic[0] = u[0] - f[0] = variables[3]+variables[0]-(variables[1]+variables[2]) + f[0] = algebraic[0]+computed_constants[0]-(computed_constants[1]+computed_constants[2]) -def find_root_0(variables): +def find_root_0(constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[3] + u[0] = algebraic[0] - u = nla_solve(objective_function_0, u, 1, [variables]) + u = nla_solve(objective_function_0, u, 1, [constants, computed_constants, algebraic]) - variables[3] = u[0] + algebraic[0] = u[0] -def initialise_variables(variables): - variables[3] = 1.0 - variables[0] = 3.0 - variables[1] = 5.0 - variables[2] = 7.0 +def initialise_variables(constants, computed_constants, algebraic): + computed_constants[0] = 3.0 + computed_constants[1] = 5.0 + computed_constants[2] = 7.0 + algebraic[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_variables(variables): - find_root_0(variables) +def compute_variables(constants, computed_constants, algebraic): + find_root_0(constants, computed_constants, algebraic) diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.c b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.c index e8abab717c..29e90e9ea7 100644 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.c +++ b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.c @@ -5,22 +5,52 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 3; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 3; -const VariableInfo VARIABLE_INFO[] = { - {"x", "dimensionless", "my_algebraic_system", ALGEBRAIC}, - {"y", "dimensionless", "my_algebraic_system", ALGEBRAIC}, - {"z", "dimensionless", "my_algebraic_system", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"x", "dimensionless", "my_algebraic_system"}, + {"y", "dimensionless", "my_algebraic_system"}, + {"z", "dimensionless", "my_algebraic_system"} +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -33,7 +63,9 @@ void deleteArray(double *array) } typedef struct { - double *variables; + double *constants; + double *computedConstants; + double *algebraic; } RootFindingInfo; extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), @@ -41,45 +73,47 @@ extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), void objectiveFunction0(double *u, double *f, void *data) { - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[0] = u[0]; - variables[1] = u[1]; - variables[2] = u[2]; + algebraic[0] = u[0]; + algebraic[1] = u[1]; + algebraic[2] = u[2]; - f[0] = 2.0*variables[0]+variables[1]-2.0*variables[2]-(-1.0); - f[1] = 3.0*variables[0]-3.0*variables[1]-variables[2]-5.0; - f[2] = variables[0]-2.0*variables[1]+3.0*variables[2]-6.0; + f[0] = 2.0*algebraic[0]+algebraic[1]-2.0*algebraic[2]-(-1.0); + f[1] = 3.0*algebraic[0]-3.0*algebraic[1]-algebraic[2]-5.0; + f[2] = algebraic[0]-2.0*algebraic[1]+3.0*algebraic[2]-6.0; } -void findRoot0(double *variables) +void findRoot0(double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { variables }; + RootFindingInfo rfi = { constants, computedConstants, algebraic }; double u[3]; - u[0] = variables[0]; - u[1] = variables[1]; - u[2] = variables[2]; + u[0] = algebraic[0]; + u[1] = algebraic[1]; + u[2] = algebraic[2]; nlaSolve(objectiveFunction0, u, 3, &rfi); - variables[0] = u[0]; - variables[1] = u[1]; - variables[2] = u[2]; + algebraic[0] = u[0]; + algebraic[1] = u[1]; + algebraic[2] = u[2]; } -void initialiseVariables(double *variables) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; - variables[1] = 1.0; - variables[2] = 1.0; + algebraic[0] = 1.0; + algebraic[1] = 1.0; + algebraic[2] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeVariables(double *variables) +void computeVariables(double *constants, double *computedConstants, double *algebraic) { - findRoot0(variables); + findRoot0(constants, computedConstants, algebraic); } diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.external.c b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.external.c new file mode 100644 index 0000000000..4973adedc3 --- /dev/null +++ b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.external.c @@ -0,0 +1,93 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#include "model.external.h" + +#include +#include + +const char VERSION[] = "0.6.0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; +const size_t EXTERNAL_COUNT = 3; + +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"x", "dimensionless", "my_algebraic_system"}, + {"y", "dimensionless", "my_algebraic_system"}, + {"z", "dimensionless", "my_algebraic_system"} +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) +{ +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ +} + +void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + externals[0] = externalVariable(constants, computedConstants, algebraic, externals, 0); + externals[1] = externalVariable(constants, computedConstants, algebraic, externals, 1); + externals[2] = externalVariable(constants, computedConstants, algebraic, externals, 2); +} diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.external.h b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.external.h new file mode 100644 index 0000000000..cf20925070 --- /dev/null +++ b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.external.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; + +typedef struct { + char name[2]; + char units[14]; + char component[20]; +} VariableInfo; + +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + +void deleteArray(double *array); + +typedef double (* ExternalVariable)(double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.external.py b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.external.py new file mode 100644 index 0000000000..eabc3752c5 --- /dev/null +++ b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.external.py @@ -0,0 +1,58 @@ +# The content of this file was generated using the Python profile of libCellML 0.6.0. + +from enum import Enum +from math import * + + +__version__ = "0.5.0" +LIBCELLML_VERSION = "0.6.0" + +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +EXTERNAL_COUNT = 3 + +CONSTANT_INFO = [ +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_INFO = [ +] + +EXTERNAL_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_algebraic_system"}, + {"name": "y", "units": "dimensionless", "component": "my_algebraic_system"}, + {"name": "z", "units": "dimensionless", "component": "my_algebraic_system"} +] + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +def initialise_variables(constants, computed_constants, algebraic): + pass + + +def compute_computed_constants(constants, computed_constants): + pass + + +def compute_variables(constants, computed_constants, algebraic, externals, external_variable): + externals[0] = external_variable(constants, computed_constants, algebraic, externals, 0) + externals[1] = external_variable(constants, computed_constants, algebraic, externals, 1) + externals[2] = external_variable(constants, computed_constants, algebraic, externals, 2) diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.h b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.h index 32daa7677a..48125c5a3f 100644 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.h +++ b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.h @@ -7,26 +7,26 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[20]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); -double * createVariablesArray(); void deleteArray(double *array); -void initialiseVariables(double *variables); -void computeComputedConstants(double *variables); -void computeVariables(double *variables); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.one.external.c b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.one.external.c deleted file mode 100644 index f63ffdd07e..0000000000 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.one.external.c +++ /dev/null @@ -1,83 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#include "model.one.external.h" - -#include -#include - -const char VERSION[] = "0.5.0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t VARIABLE_COUNT = 3; - -const VariableInfo VARIABLE_INFO[] = { - {"x", "dimensionless", "my_algebraic_system", EXTERNAL}, - {"y", "dimensionless", "my_algebraic_system", ALGEBRAIC}, - {"z", "dimensionless", "my_algebraic_system", ALGEBRAIC} -}; - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -typedef struct { - double *variables; -} RootFindingInfo; - -extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), - double *u, size_t n, void *data); - -void objectiveFunction0(double *u, double *f, void *data) -{ - double *variables = ((RootFindingInfo *) data)->variables; - - variables[1] = u[0]; - variables[2] = u[1]; - - f[0] = 2.0*variables[0]+variables[1]-2.0*variables[2]-(-1.0); - f[1] = 3.0*variables[0]-3.0*variables[1]-variables[2]-5.0; - f[2] = variables[0]-2.0*variables[1]+3.0*variables[2]-6.0; -} - -void findRoot0(double *variables) -{ - RootFindingInfo rfi = { variables }; - double u[2]; - - u[0] = variables[1]; - u[1] = variables[2]; - - nlaSolve(objectiveFunction0, u, 2, &rfi); - - variables[1] = u[0]; - variables[2] = u[1]; -} - -void initialiseVariables(double *variables, ExternalVariable externalVariable) -{ - variables[1] = 1.0; - variables[2] = 1.0; - variables[0] = externalVariable(variables, 0); -} - -void computeComputedConstants(double *variables) -{ -} - -void computeVariables(double *variables, ExternalVariable externalVariable) -{ - variables[0] = externalVariable(variables, 0); - findRoot0(variables); -} diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.one.external.h b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.one.external.h deleted file mode 100644 index 603b8a7d53..0000000000 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.one.external.h +++ /dev/null @@ -1,35 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; - -typedef struct { - char name[2]; - char units[14]; - char component[20]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VARIABLE_INFO[]; - -double * createVariablesArray(); -void deleteArray(double *array); - -typedef double (* ExternalVariable)(double *variables, size_t index); - -void initialiseVariables(double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeVariables(double *variables, ExternalVariable externalVariable); diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.one.external.py b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.one.external.py deleted file mode 100644 index 6db5e1b426..0000000000 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.one.external.py +++ /dev/null @@ -1,69 +0,0 @@ -# The content of this file was generated using the Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0" -LIBCELLML_VERSION = "0.6.0" - -VARIABLE_COUNT = 3 - - -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - EXTERNAL = 3 - - -VARIABLE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.EXTERNAL}, - {"name": "y", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC}, - {"name": "z", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC} -] - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -from nlasolver import nla_solve - - -def objective_function_0(u, f, data): - variables = data[0] - - variables[1] = u[0] - variables[2] = u[1] - - f[0] = 2.0*variables[0]+variables[1]-2.0*variables[2]-(-1.0) - f[1] = 3.0*variables[0]-3.0*variables[1]-variables[2]-5.0 - f[2] = variables[0]-2.0*variables[1]+3.0*variables[2]-6.0 - - -def find_root_0(variables): - u = [nan]*2 - - u[0] = variables[1] - u[1] = variables[2] - - u = nla_solve(objective_function_0, u, 2, [variables]) - - variables[1] = u[0] - variables[2] = u[1] - - -def initialise_variables(variables, external_variable): - variables[1] = 1.0 - variables[2] = 1.0 - variables[0] = external_variable(variables, 0) - - -def compute_computed_constants(variables): - pass - - -def compute_variables(variables, external_variable): - variables[0] = external_variable(variables, 0) - find_root_0(variables) diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.py b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.py index faaea92712..dc1cd76f03 100644 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.py +++ b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.py @@ -4,67 +4,78 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 3 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 3 +CONSTANT_INFO = [ +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - +COMPUTED_CONSTANT_INFO = [ +] -VARIABLE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC}, - {"name": "y", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC}, - {"name": "z", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_algebraic_system"}, + {"name": "y", "units": "dimensionless", "component": "my_algebraic_system"}, + {"name": "z", "units": "dimensionless", "component": "my_algebraic_system"} ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT from nlasolver import nla_solve def objective_function_0(u, f, data): - variables = data[0] + constants = data[0] + computed_constants = data[1] + algebraic = data[2] - variables[0] = u[0] - variables[1] = u[1] - variables[2] = u[2] + algebraic[0] = u[0] + algebraic[1] = u[1] + algebraic[2] = u[2] - f[0] = 2.0*variables[0]+variables[1]-2.0*variables[2]-(-1.0) - f[1] = 3.0*variables[0]-3.0*variables[1]-variables[2]-5.0 - f[2] = variables[0]-2.0*variables[1]+3.0*variables[2]-6.0 + f[0] = 2.0*algebraic[0]+algebraic[1]-2.0*algebraic[2]-(-1.0) + f[1] = 3.0*algebraic[0]-3.0*algebraic[1]-algebraic[2]-5.0 + f[2] = algebraic[0]-2.0*algebraic[1]+3.0*algebraic[2]-6.0 -def find_root_0(variables): +def find_root_0(constants, computed_constants, algebraic): u = [nan]*3 - u[0] = variables[0] - u[1] = variables[1] - u[2] = variables[2] + u[0] = algebraic[0] + u[1] = algebraic[1] + u[2] = algebraic[2] - u = nla_solve(objective_function_0, u, 3, [variables]) + u = nla_solve(objective_function_0, u, 3, [constants, computed_constants, algebraic]) - variables[0] = u[0] - variables[1] = u[1] - variables[2] = u[2] + algebraic[0] = u[0] + algebraic[1] = u[1] + algebraic[2] = u[2] -def initialise_variables(variables): - variables[0] = 1.0 - variables[1] = 1.0 - variables[2] = 1.0 +def initialise_variables(constants, computed_constants, algebraic): + algebraic[0] = 1.0 + algebraic[1] = 1.0 + algebraic[2] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_variables(variables): - find_root_0(variables) +def compute_variables(constants, computed_constants, algebraic): + find_root_0(constants, computed_constants, algebraic) diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.three.externals.c b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.three.externals.c deleted file mode 100644 index c070cc18aa..0000000000 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.three.externals.c +++ /dev/null @@ -1,51 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#include "model.three.externals.h" - -#include -#include - -const char VERSION[] = "0.5.0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t VARIABLE_COUNT = 3; - -const VariableInfo VARIABLE_INFO[] = { - {"x", "dimensionless", "my_algebraic_system", EXTERNAL}, - {"y", "dimensionless", "my_algebraic_system", EXTERNAL}, - {"z", "dimensionless", "my_algebraic_system", EXTERNAL} -}; - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -void initialiseVariables(double *variables, ExternalVariable externalVariable) -{ - variables[0] = externalVariable(variables, 0); - variables[1] = externalVariable(variables, 1); - variables[2] = externalVariable(variables, 2); -} - -void computeComputedConstants(double *variables) -{ -} - -void computeVariables(double *variables, ExternalVariable externalVariable) -{ - variables[0] = externalVariable(variables, 0); - variables[1] = externalVariable(variables, 1); - variables[2] = externalVariable(variables, 2); -} diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.three.externals.h b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.three.externals.h deleted file mode 100644 index 603b8a7d53..0000000000 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.three.externals.h +++ /dev/null @@ -1,35 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; - -typedef struct { - char name[2]; - char units[14]; - char component[20]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VARIABLE_INFO[]; - -double * createVariablesArray(); -void deleteArray(double *array); - -typedef double (* ExternalVariable)(double *variables, size_t index); - -void initialiseVariables(double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeVariables(double *variables, ExternalVariable externalVariable); diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.three.externals.py b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.three.externals.py deleted file mode 100644 index f04da97fb8..0000000000 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.three.externals.py +++ /dev/null @@ -1,44 +0,0 @@ -# The content of this file was generated using the Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0" -LIBCELLML_VERSION = "0.6.0" - -VARIABLE_COUNT = 3 - - -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - EXTERNAL = 3 - - -VARIABLE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.EXTERNAL}, - {"name": "y", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.EXTERNAL}, - {"name": "z", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.EXTERNAL} -] - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -def initialise_variables(variables, external_variable): - variables[0] = external_variable(variables, 0) - variables[1] = external_variable(variables, 1) - variables[2] = external_variable(variables, 2) - - -def compute_computed_constants(variables): - pass - - -def compute_variables(variables, external_variable): - variables[0] = external_variable(variables, 0) - variables[1] = external_variable(variables, 1) - variables[2] = external_variable(variables, 2) diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.two.externals.c b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.two.externals.c deleted file mode 100644 index 36c73879c7..0000000000 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.two.externals.c +++ /dev/null @@ -1,123 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#include "model.two.externals.h" - -#include -#include - -const char VERSION[] = "0.5.0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t VARIABLE_COUNT = 3; - -const VariableInfo VARIABLE_INFO[] = { - {"x", "dimensionless", "my_algebraic_system", EXTERNAL}, - {"y", "dimensionless", "my_algebraic_system", ALGEBRAIC}, - {"z", "dimensionless", "my_algebraic_system", EXTERNAL} -}; - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -typedef struct { - double *variables; -} RootFindingInfo; - -extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), - double *u, size_t n, void *data); - -void objectiveFunction0(double *u, double *f, void *data) -{ - double *variables = ((RootFindingInfo *) data)->variables; - - variables[1] = u[0]; - - f[0] = 2.0*variables[0]+variables[1]-2.0*variables[2]-(-1.0); -} - -void findRoot0(double *variables) -{ - RootFindingInfo rfi = { variables }; - double u[1]; - - u[0] = variables[1]; - - nlaSolve(objectiveFunction0, u, 1, &rfi); - - variables[1] = u[0]; -} - -void objectiveFunction1(double *u, double *f, void *data) -{ - double *variables = ((RootFindingInfo *) data)->variables; - - variables[1] = u[0]; - - f[0] = 3.0*variables[0]-3.0*variables[1]-variables[2]-5.0; -} - -void findRoot1(double *variables) -{ - RootFindingInfo rfi = { variables }; - double u[1]; - - u[0] = variables[1]; - - nlaSolve(objectiveFunction1, u, 1, &rfi); - - variables[1] = u[0]; -} - -void objectiveFunction2(double *u, double *f, void *data) -{ - double *variables = ((RootFindingInfo *) data)->variables; - - variables[1] = u[0]; - - f[0] = variables[0]-2.0*variables[1]+3.0*variables[2]-6.0; -} - -void findRoot2(double *variables) -{ - RootFindingInfo rfi = { variables }; - double u[1]; - - u[0] = variables[1]; - - nlaSolve(objectiveFunction2, u, 1, &rfi); - - variables[1] = u[0]; -} - -void initialiseVariables(double *variables, ExternalVariable externalVariable) -{ - variables[1] = 1.0; - variables[0] = externalVariable(variables, 0); - variables[2] = externalVariable(variables, 2); -} - -void computeComputedConstants(double *variables) -{ -} - -void computeVariables(double *variables, ExternalVariable externalVariable) -{ - variables[0] = externalVariable(variables, 0); - variables[2] = externalVariable(variables, 2); - findRoot0(variables); - findRoot1(variables); - findRoot2(variables); -} diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.two.externals.h b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.two.externals.h deleted file mode 100644 index 603b8a7d53..0000000000 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.two.externals.h +++ /dev/null @@ -1,35 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; - -typedef struct { - char name[2]; - char units[14]; - char component[20]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VARIABLE_INFO[]; - -double * createVariablesArray(); -void deleteArray(double *array); - -typedef double (* ExternalVariable)(double *variables, size_t index); - -void initialiseVariables(double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeVariables(double *variables, ExternalVariable externalVariable); diff --git a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.two.externals.py b/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.two.externals.py deleted file mode 100644 index d3240ff893..0000000000 --- a/tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.two.externals.py +++ /dev/null @@ -1,103 +0,0 @@ -# The content of this file was generated using the Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0" -LIBCELLML_VERSION = "0.6.0" - -VARIABLE_COUNT = 3 - - -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - EXTERNAL = 3 - - -VARIABLE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.EXTERNAL}, - {"name": "y", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC}, - {"name": "z", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.EXTERNAL} -] - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -from nlasolver import nla_solve - - -def objective_function_0(u, f, data): - variables = data[0] - - variables[1] = u[0] - - f[0] = 2.0*variables[0]+variables[1]-2.0*variables[2]-(-1.0) - - -def find_root_0(variables): - u = [nan]*1 - - u[0] = variables[1] - - u = nla_solve(objective_function_0, u, 1, [variables]) - - variables[1] = u[0] - - -def objective_function_1(u, f, data): - variables = data[0] - - variables[1] = u[0] - - f[0] = 3.0*variables[0]-3.0*variables[1]-variables[2]-5.0 - - -def find_root_1(variables): - u = [nan]*1 - - u[0] = variables[1] - - u = nla_solve(objective_function_1, u, 1, [variables]) - - variables[1] = u[0] - - -def objective_function_2(u, f, data): - variables = data[0] - - variables[1] = u[0] - - f[0] = variables[0]-2.0*variables[1]+3.0*variables[2]-6.0 - - -def find_root_2(variables): - u = [nan]*1 - - u[0] = variables[1] - - u = nla_solve(objective_function_2, u, 1, [variables]) - - variables[1] = u[0] - - -def initialise_variables(variables, external_variable): - variables[1] = 1.0 - variables[0] = external_variable(variables, 0) - variables[2] = external_variable(variables, 2) - - -def compute_computed_constants(variables): - pass - - -def compute_variables(variables, external_variable): - variables[0] = external_variable(variables, 0) - variables[2] = external_variable(variables, 2) - find_root_0(variables) - find_root_1(variables) - find_root_2(variables) diff --git a/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.c b/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.c index d5c33adb68..f4f7372bc0 100644 --- a/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.c +++ b/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.c @@ -5,25 +5,55 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 6; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 3; -const VariableInfo VARIABLE_INFO[] = { - {"d", "dimensionless", "my_algebraic_system", ALGEBRAIC}, - {"b", "dimensionless", "my_algebraic_system", ALGEBRAIC}, - {"c", "dimensionless", "my_algebraic_system", ALGEBRAIC}, - {"a", "dimensionless", "my_algebraic_system", COMPUTED_CONSTANT}, - {"x", "dimensionless", "my_algebraic_system", CONSTANT}, - {"y", "dimensionless", "my_algebraic_system", CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"x", "dimensionless", "my_algebraic_system"}, + {"y", "dimensionless", "my_algebraic_system"} }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"a", "dimensionless", "my_algebraic_system"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"d", "dimensionless", "my_algebraic_system"}, + {"b", "dimensionless", "my_algebraic_system"}, + {"c", "dimensionless", "my_algebraic_system"} +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -36,7 +66,9 @@ void deleteArray(double *array) } typedef struct { - double *variables; + double *constants; + double *computedConstants; + double *algebraic; } RootFindingInfo; extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), @@ -44,44 +76,46 @@ extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), void objectiveFunction0(double *u, double *f, void *data) { - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[2] = u[0]; - variables[1] = u[1]; + algebraic[2] = u[0]; + algebraic[1] = u[1]; - f[0] = 3.0*variables[3]+2.0*variables[1]+variables[2]-57.0; - f[1] = variables[3]+3.0*variables[1]-variables[2]-19.0; + f[0] = 3.0*computedConstants[0]+2.0*algebraic[1]+algebraic[2]-57.0; + f[1] = computedConstants[0]+3.0*algebraic[1]-algebraic[2]-19.0; } -void findRoot0(double *variables) +void findRoot0(double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { variables }; + RootFindingInfo rfi = { constants, computedConstants, algebraic }; double u[2]; - u[0] = variables[2]; - u[1] = variables[1]; + u[0] = algebraic[2]; + u[1] = algebraic[1]; nlaSolve(objectiveFunction0, u, 2, &rfi); - variables[2] = u[0]; - variables[1] = u[1]; + algebraic[2] = u[0]; + algebraic[1] = u[1]; } -void initialiseVariables(double *variables) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[1] = 1.0; - variables[2] = 1.0; - variables[4] = 3.0; - variables[5] = 5.0; + constants[0] = 3.0; + constants[1] = 5.0; + algebraic[1] = 1.0; + algebraic[2] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[3] = 3.0*variables[4]+variables[5]; + computedConstants[0] = 3.0*constants[0]+constants[1]; } -void computeVariables(double *variables) +void computeVariables(double *constants, double *computedConstants, double *algebraic) { - findRoot0(variables); - variables[0] = variables[1]+variables[2]; + findRoot0(constants, computedConstants, algebraic); + algebraic[0] = algebraic[1]+algebraic[2]; } diff --git a/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.h b/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.h index 32daa7677a..48125c5a3f 100644 --- a/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.h +++ b/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.h @@ -7,26 +7,26 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[20]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); -double * createVariablesArray(); void deleteArray(double *array); -void initialiseVariables(double *variables); -void computeComputedConstants(double *variables); -void computeVariables(double *variables); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.py b/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.py index eb02b8a0b5..2b2b3aa211 100644 --- a/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.py +++ b/tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.py @@ -4,68 +4,79 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 6 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 3 +CONSTANT_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_algebraic_system"}, + {"name": "y", "units": "dimensionless", "component": "my_algebraic_system"} +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - +COMPUTED_CONSTANT_INFO = [ + {"name": "a", "units": "dimensionless", "component": "my_algebraic_system"} +] -VARIABLE_INFO = [ - {"name": "d", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC}, - {"name": "b", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC}, - {"name": "c", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC}, - {"name": "a", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "x", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.CONSTANT}, - {"name": "y", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.CONSTANT} +ALGEBRAIC_INFO = [ + {"name": "d", "units": "dimensionless", "component": "my_algebraic_system"}, + {"name": "b", "units": "dimensionless", "component": "my_algebraic_system"}, + {"name": "c", "units": "dimensionless", "component": "my_algebraic_system"} ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT from nlasolver import nla_solve def objective_function_0(u, f, data): - variables = data[0] + constants = data[0] + computed_constants = data[1] + algebraic = data[2] - variables[2] = u[0] - variables[1] = u[1] + algebraic[2] = u[0] + algebraic[1] = u[1] - f[0] = 3.0*variables[3]+2.0*variables[1]+variables[2]-57.0 - f[1] = variables[3]+3.0*variables[1]-variables[2]-19.0 + f[0] = 3.0*computed_constants[0]+2.0*algebraic[1]+algebraic[2]-57.0 + f[1] = computed_constants[0]+3.0*algebraic[1]-algebraic[2]-19.0 -def find_root_0(variables): +def find_root_0(constants, computed_constants, algebraic): u = [nan]*2 - u[0] = variables[2] - u[1] = variables[1] + u[0] = algebraic[2] + u[1] = algebraic[1] - u = nla_solve(objective_function_0, u, 2, [variables]) + u = nla_solve(objective_function_0, u, 2, [constants, computed_constants, algebraic]) - variables[2] = u[0] - variables[1] = u[1] + algebraic[2] = u[0] + algebraic[1] = u[1] -def initialise_variables(variables): - variables[1] = 1.0 - variables[2] = 1.0 - variables[4] = 3.0 - variables[5] = 5.0 +def initialise_variables(constants, computed_constants, algebraic): + constants[0] = 3.0 + constants[1] = 5.0 + algebraic[1] = 1.0 + algebraic[2] = 1.0 -def compute_computed_constants(variables): - variables[3] = 3.0*variables[4]+variables[5] +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = 3.0*constants[0]+constants[1] -def compute_variables(variables): - find_root_0(variables) - variables[0] = variables[1]+variables[2] +def compute_variables(constants, computed_constants, algebraic): + find_root_0(constants, computed_constants, algebraic) + algebraic[0] = algebraic[1]+algebraic[2] diff --git a/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.c b/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.c index d7efe17849..ddb9df2457 100644 --- a/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.c +++ b/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.c @@ -5,25 +5,55 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 6; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 3; -const VariableInfo VARIABLE_INFO[] = { - {"a", "dimensionless", "my_algebraic_system", COMPUTED_CONSTANT}, - {"x", "dimensionless", "my_algebraic_system", CONSTANT}, - {"y", "dimensionless", "my_algebraic_system", CONSTANT}, - {"c", "dimensionless", "my_algebraic_system", ALGEBRAIC}, - {"b", "dimensionless", "my_algebraic_system", ALGEBRAIC}, - {"d", "dimensionless", "my_algebraic_system", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { + {"x", "dimensionless", "my_algebraic_system"}, + {"y", "dimensionless", "my_algebraic_system"} }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"a", "dimensionless", "my_algebraic_system"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"c", "dimensionless", "my_algebraic_system"}, + {"b", "dimensionless", "my_algebraic_system"}, + {"d", "dimensionless", "my_algebraic_system"} +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -36,7 +66,9 @@ void deleteArray(double *array) } typedef struct { - double *variables; + double *constants; + double *computedConstants; + double *algebraic; } RootFindingInfo; extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), @@ -44,44 +76,46 @@ extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), void objectiveFunction0(double *u, double *f, void *data) { - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[3] = u[0]; - variables[4] = u[1]; + algebraic[0] = u[0]; + algebraic[1] = u[1]; - f[0] = 3.0*variables[0]+2.0*variables[4]+variables[3]-57.0; - f[1] = variables[0]+3.0*variables[4]-variables[3]-19.0; + f[0] = 3.0*computedConstants[0]+2.0*algebraic[1]+algebraic[0]-57.0; + f[1] = computedConstants[0]+3.0*algebraic[1]-algebraic[0]-19.0; } -void findRoot0(double *variables) +void findRoot0(double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { variables }; + RootFindingInfo rfi = { constants, computedConstants, algebraic }; double u[2]; - u[0] = variables[3]; - u[1] = variables[4]; + u[0] = algebraic[0]; + u[1] = algebraic[1]; nlaSolve(objectiveFunction0, u, 2, &rfi); - variables[3] = u[0]; - variables[4] = u[1]; + algebraic[0] = u[0]; + algebraic[1] = u[1]; } -void initialiseVariables(double *variables) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[1] = 3.0; - variables[2] = 5.0; - variables[3] = 1.0; - variables[4] = 1.0; + constants[0] = 3.0; + constants[1] = 5.0; + algebraic[0] = 1.0; + algebraic[1] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[0] = 3.0*variables[1]+variables[2]; + computedConstants[0] = 3.0*constants[0]+constants[1]; } -void computeVariables(double *variables) +void computeVariables(double *constants, double *computedConstants, double *algebraic) { - findRoot0(variables); - variables[5] = variables[4]+variables[3]; + findRoot0(constants, computedConstants, algebraic); + algebraic[2] = algebraic[1]+algebraic[0]; } diff --git a/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.h b/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.h index 32daa7677a..48125c5a3f 100644 --- a/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.h +++ b/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.h @@ -7,26 +7,26 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[20]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); -double * createVariablesArray(); void deleteArray(double *array); -void initialiseVariables(double *variables); -void computeComputedConstants(double *variables); -void computeVariables(double *variables); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.py b/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.py index a4ba68ec6f..46f741a829 100644 --- a/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.py +++ b/tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.py @@ -4,68 +4,79 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 6 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 3 +CONSTANT_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_algebraic_system"}, + {"name": "y", "units": "dimensionless", "component": "my_algebraic_system"} +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - +COMPUTED_CONSTANT_INFO = [ + {"name": "a", "units": "dimensionless", "component": "my_algebraic_system"} +] -VARIABLE_INFO = [ - {"name": "a", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "x", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.CONSTANT}, - {"name": "y", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.CONSTANT}, - {"name": "c", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC}, - {"name": "b", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC}, - {"name": "d", "units": "dimensionless", "component": "my_algebraic_system", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "c", "units": "dimensionless", "component": "my_algebraic_system"}, + {"name": "b", "units": "dimensionless", "component": "my_algebraic_system"}, + {"name": "d", "units": "dimensionless", "component": "my_algebraic_system"} ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT from nlasolver import nla_solve def objective_function_0(u, f, data): - variables = data[0] + constants = data[0] + computed_constants = data[1] + algebraic = data[2] - variables[3] = u[0] - variables[4] = u[1] + algebraic[0] = u[0] + algebraic[1] = u[1] - f[0] = 3.0*variables[0]+2.0*variables[4]+variables[3]-57.0 - f[1] = variables[0]+3.0*variables[4]-variables[3]-19.0 + f[0] = 3.0*computed_constants[0]+2.0*algebraic[1]+algebraic[0]-57.0 + f[1] = computed_constants[0]+3.0*algebraic[1]-algebraic[0]-19.0 -def find_root_0(variables): +def find_root_0(constants, computed_constants, algebraic): u = [nan]*2 - u[0] = variables[3] - u[1] = variables[4] + u[0] = algebraic[0] + u[1] = algebraic[1] - u = nla_solve(objective_function_0, u, 2, [variables]) + u = nla_solve(objective_function_0, u, 2, [constants, computed_constants, algebraic]) - variables[3] = u[0] - variables[4] = u[1] + algebraic[0] = u[0] + algebraic[1] = u[1] -def initialise_variables(variables): - variables[1] = 3.0 - variables[2] = 5.0 - variables[3] = 1.0 - variables[4] = 1.0 +def initialise_variables(constants, computed_constants, algebraic): + constants[0] = 3.0 + constants[1] = 5.0 + algebraic[0] = 1.0 + algebraic[1] = 1.0 -def compute_computed_constants(variables): - variables[0] = 3.0*variables[1]+variables[2] +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = 3.0*constants[0]+constants[1] -def compute_variables(variables): - find_root_0(variables) - variables[5] = variables[4]+variables[3] +def compute_variables(constants, computed_constants, algebraic): + find_root_0(constants, computed_constants, algebraic) + algebraic[2] = algebraic[1]+algebraic[0] diff --git a/tests/resources/generator/algebraic_unknown_var_on_rhs/model.c b/tests/resources/generator/algebraic_unknown_var_on_rhs/model.c index ded35a9b82..505d493e5a 100644 --- a/tests/resources/generator/algebraic_unknown_var_on_rhs/model.c +++ b/tests/resources/generator/algebraic_unknown_var_on_rhs/model.c @@ -5,21 +5,51 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 2; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VARIABLE_INFO[] = { - {"x", "dimensionless", "my_component", COMPUTED_CONSTANT}, - {"y", "dimensionless", "my_component", COMPUTED_CONSTANT} +const VariableInfo CONSTANT_INFO[] = { }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"x", "dimensionless", "my_component"}, + {"y", "dimensionless", "my_component"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -31,16 +61,16 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *variables) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; + computedConstants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[1] = variables[0]; + computedConstants[1] = computedConstants[0]; } -void computeVariables(double *variables) +void computeVariables(double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/algebraic_unknown_var_on_rhs/model.h b/tests/resources/generator/algebraic_unknown_var_on_rhs/model.h index 75dd2ed790..7c2e4a401e 100644 --- a/tests/resources/generator/algebraic_unknown_var_on_rhs/model.h +++ b/tests/resources/generator/algebraic_unknown_var_on_rhs/model.h @@ -7,26 +7,26 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[13]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); -double * createVariablesArray(); void deleteArray(double *array); -void initialiseVariables(double *variables); -void computeComputedConstants(double *variables); -void computeVariables(double *variables); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/algebraic_unknown_var_on_rhs/model.py b/tests/resources/generator/algebraic_unknown_var_on_rhs/model.py index 4d35b1e7c0..72512aed79 100644 --- a/tests/resources/generator/algebraic_unknown_var_on_rhs/model.py +++ b/tests/resources/generator/algebraic_unknown_var_on_rhs/model.py @@ -4,35 +4,44 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 2 +ALGEBRAIC_COUNT = 0 +CONSTANT_INFO = [ +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - +COMPUTED_CONSTANT_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_component"}, + {"name": "y", "units": "dimensionless", "component": "my_component"} +] -VARIABLE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "y", "units": "dimensionless", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT} +ALGEBRAIC_INFO = [ ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(variables): - variables[0] = 1.0 +def initialise_variables(constants, computed_constants, algebraic): + computed_constants[0] = 1.0 -def compute_computed_constants(variables): - variables[1] = variables[0] +def compute_computed_constants(constants, computed_constants): + computed_constants[1] = computed_constants[0] -def compute_variables(variables): +def compute_variables(constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/cell_geometry_model/model.c b/tests/resources/generator/cell_geometry_model/model.c index f061412060..0a2e36b91d 100644 --- a/tests/resources/generator/cell_geometry_model/model.c +++ b/tests/resources/generator/cell_geometry_model/model.c @@ -5,23 +5,53 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 4; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 2; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VARIABLE_INFO[] = { - {"vcell", "microlitre", "cell_geometry", COMPUTED_CONSTANT}, - {"L", "centimeter", "cell_geometry", CONSTANT}, - {"rad", "centimeter", "cell_geometry", CONSTANT}, - {"vss", "microlitre", "cell_geometry", COMPUTED_CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"L", "centimeter", "cell_geometry"}, + {"rad", "centimeter", "cell_geometry"} }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"vcell", "microlitre", "cell_geometry"}, + {"vss", "microlitre", "cell_geometry"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -33,18 +63,18 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *variables) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[1] = 0.01; - variables[2] = 0.0011; + constants[0] = 0.01; + constants[1] = 0.0011; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[0] = 1000.0*3.14*variables[2]*variables[2]*variables[1]; - variables[3] = 0.02*variables[0]; + computedConstants[0] = 1000.0*3.14*constants[1]*constants[1]*constants[0]; + computedConstants[1] = 0.02*computedConstants[0]; } -void computeVariables(double *variables) +void computeVariables(double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/cell_geometry_model/model.external.c b/tests/resources/generator/cell_geometry_model/model.external.c index 9542b6f88f..dd36cf034c 100644 --- a/tests/resources/generator/cell_geometry_model/model.external.c +++ b/tests/resources/generator/cell_geometry_model/model.external.c @@ -5,23 +5,68 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 4; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 2; +const size_t EXTERNAL_COUNT = 2; -const VariableInfo VARIABLE_INFO[] = { - {"vcell", "microlitre", "cell_geometry", ALGEBRAIC}, - {"L", "centimeter", "cell_geometry", EXTERNAL}, - {"rad", "centimeter", "cell_geometry", EXTERNAL}, - {"vss", "microlitre", "cell_geometry", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"vcell", "microlitre", "cell_geometry"}, + {"vss", "microlitre", "cell_geometry"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"L", "centimeter", "cell_geometry"}, + {"rad", "centimeter", "cell_geometry"} +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { res[i] = NAN; } @@ -33,20 +78,18 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *variables, ExternalVariable externalVariable) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[1] = externalVariable(variables, 1); - variables[2] = externalVariable(variables, 2); } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeVariables(double *variables, ExternalVariable externalVariable) +void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - variables[1] = externalVariable(variables, 1); - variables[2] = externalVariable(variables, 2); - variables[0] = 1000.0*3.14*variables[2]*variables[2]*variables[1]; - variables[3] = 0.02*variables[0]; + externals[0] = externalVariable(constants, computedConstants, algebraic, externals, 0); + externals[1] = externalVariable(constants, computedConstants, algebraic, externals, 1); + algebraic[0] = 1000.0*3.14*externals[1]*externals[1]*externals[0]; + algebraic[1] = 0.02*algebraic[0]; } diff --git a/tests/resources/generator/cell_geometry_model/model.external.h b/tests/resources/generator/cell_geometry_model/model.external.h index f9ebe340a0..a032661913 100644 --- a/tests/resources/generator/cell_geometry_model/model.external.h +++ b/tests/resources/generator/cell_geometry_model/model.external.h @@ -7,29 +7,31 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; typedef struct { char name[6]; char units[11]; char component[14]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); -double * createVariablesArray(); void deleteArray(double *array); -typedef double (* ExternalVariable)(double *variables, size_t index); +typedef double (* ExternalVariable)(double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); -void initialiseVariables(double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeVariables(double *variables, ExternalVariable externalVariable); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/cell_geometry_model/model.external.py b/tests/resources/generator/cell_geometry_model/model.external.py index 3f0e72f98a..90300c5e8c 100644 --- a/tests/resources/generator/cell_geometry_model/model.external.py +++ b/tests/resources/generator/cell_geometry_model/model.external.py @@ -4,42 +4,57 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 4 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 2 +EXTERNAL_COUNT = 2 +CONSTANT_INFO = [ +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - EXTERNAL = 3 +COMPUTED_CONSTANT_INFO = [ +] +ALGEBRAIC_INFO = [ + {"name": "vcell", "units": "microlitre", "component": "cell_geometry"}, + {"name": "vss", "units": "microlitre", "component": "cell_geometry"} +] -VARIABLE_INFO = [ - {"name": "vcell", "units": "microlitre", "component": "cell_geometry", "type": VariableType.ALGEBRAIC}, - {"name": "L", "units": "centimeter", "component": "cell_geometry", "type": VariableType.EXTERNAL}, - {"name": "rad", "units": "centimeter", "component": "cell_geometry", "type": VariableType.EXTERNAL}, - {"name": "vss", "units": "microlitre", "component": "cell_geometry", "type": VariableType.ALGEBRAIC} +EXTERNAL_INFO = [ + {"name": "L", "units": "centimeter", "component": "cell_geometry"}, + {"name": "rad", "units": "centimeter", "component": "cell_geometry"} ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT -def initialise_variables(variables, external_variable): - variables[1] = external_variable(variables, 1) - variables[2] = external_variable(variables, 2) +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +def initialise_variables(constants, computed_constants, algebraic): + pass -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_variables(variables, external_variable): - variables[1] = external_variable(variables, 1) - variables[2] = external_variable(variables, 2) - variables[0] = 1000.0*3.14*variables[2]*variables[2]*variables[1] - variables[3] = 0.02*variables[0] +def compute_variables(constants, computed_constants, algebraic, externals, external_variable): + externals[0] = external_variable(constants, computed_constants, algebraic, externals, 0) + externals[1] = external_variable(constants, computed_constants, algebraic, externals, 1) + algebraic[0] = 1000.0*3.14*externals[1]*externals[1]*externals[0] + algebraic[1] = 0.02*algebraic[0] diff --git a/tests/resources/generator/cell_geometry_model/model.h b/tests/resources/generator/cell_geometry_model/model.h index b47d6ae000..38ce9f6ced 100644 --- a/tests/resources/generator/cell_geometry_model/model.h +++ b/tests/resources/generator/cell_geometry_model/model.h @@ -7,26 +7,26 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[6]; char units[11]; char component[14]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); -double * createVariablesArray(); void deleteArray(double *array); -void initialiseVariables(double *variables); -void computeComputedConstants(double *variables); -void computeVariables(double *variables); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/cell_geometry_model/model.py b/tests/resources/generator/cell_geometry_model/model.py index 197a72fc2f..a729ad4fb0 100644 --- a/tests/resources/generator/cell_geometry_model/model.py +++ b/tests/resources/generator/cell_geometry_model/model.py @@ -4,39 +4,48 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 4 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 2 +ALGEBRAIC_COUNT = 0 +CONSTANT_INFO = [ + {"name": "L", "units": "centimeter", "component": "cell_geometry"}, + {"name": "rad", "units": "centimeter", "component": "cell_geometry"} +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - +COMPUTED_CONSTANT_INFO = [ + {"name": "vcell", "units": "microlitre", "component": "cell_geometry"}, + {"name": "vss", "units": "microlitre", "component": "cell_geometry"} +] -VARIABLE_INFO = [ - {"name": "vcell", "units": "microlitre", "component": "cell_geometry", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "L", "units": "centimeter", "component": "cell_geometry", "type": VariableType.CONSTANT}, - {"name": "rad", "units": "centimeter", "component": "cell_geometry", "type": VariableType.CONSTANT}, - {"name": "vss", "units": "microlitre", "component": "cell_geometry", "type": VariableType.COMPUTED_CONSTANT} +ALGEBRAIC_INFO = [ ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(variables): - variables[1] = 0.01 - variables[2] = 0.0011 +def initialise_variables(constants, computed_constants, algebraic): + constants[0] = 0.01 + constants[1] = 0.0011 -def compute_computed_constants(variables): - variables[0] = 1000.0*3.14*variables[2]*variables[2]*variables[1] - variables[3] = 0.02*variables[0] +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = 1000.0*3.14*constants[1]*constants[1]*constants[0] + computed_constants[1] = 0.02*computed_constants[0] -def compute_variables(variables): +def compute_variables(constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/cellml_mappings_and_encapsulations/model.c b/tests/resources/generator/cellml_mappings_and_encapsulations/model.c index 6a87540b96..1a9c8f6e1b 100644 --- a/tests/resources/generator/cellml_mappings_and_encapsulations/model.c +++ b/tests/resources/generator/cellml_mappings_and_encapsulations/model.c @@ -5,22 +5,30 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 2; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 2; -const VariableInfo VOI_INFO = {"t", "ms", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "ms", "environment"}; const VariableInfo STATE_INFO[] = { - {"y", "mM", "circle_y_implementation", STATE}, - {"x", "mM", "circle_x", STATE} + {"y", "mM", "circle_y_implementation"}, + {"x", "mM", "circle_x"} }; -const VariableInfo VARIABLE_INFO[] = { - {"local_complex_maths", "mM", "circle_sibling", ALGEBRAIC}, - {"two_x", "milli_mole", "circle_x_sibling", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"local_complex_maths", "mM", "circle_sibling"}, + {"two_x", "milli_mole", "circle_x_sibling"} }; double * createStatesArray() @@ -34,11 +42,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -50,24 +80,24 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { states[0] = 1.0; states[1] = 0.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[1] = -states[0]*1.0; rates[0] = states[1]*1.0; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = states[0]+5.0*states[0]/3.0+1.0*exp(states[0]/2.0); - variables[1] = 2.0*states[1]; + algebraic[0] = states[0]+5.0*states[0]/3.0+1.0*exp(states[0]/2.0); + algebraic[1] = 2.0*states[1]; } diff --git a/tests/resources/generator/cellml_mappings_and_encapsulations/model.h b/tests/resources/generator/cellml_mappings_and_encapsulations/model.h index 1960d79bbb..39af19927e 100644 --- a/tests/resources/generator/cellml_mappings_and_encapsulations/model.h +++ b/tests/resources/generator/cellml_mappings_and_encapsulations/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[20]; char units[11]; char component[24]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/cellml_mappings_and_encapsulations/model.py b/tests/resources/generator/cellml_mappings_and_encapsulations/model.py index 1ed0ddf5e1..e67e674fe0 100644 --- a/tests/resources/generator/cellml_mappings_and_encapsulations/model.py +++ b/tests/resources/generator/cellml_mappings_and_encapsulations/model.py @@ -4,31 +4,30 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 2 -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 2 +VOI_INFO = {"name": "t", "units": "ms", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "y", "units": "mM", "component": "circle_y_implementation"}, + {"name": "x", "units": "mM", "component": "circle_x"} +] -VOI_INFO = {"name": "t", "units": "ms", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "y", "units": "mM", "component": "circle_y_implementation", "type": VariableType.STATE}, - {"name": "x", "units": "mM", "component": "circle_x", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "local_complex_maths", "units": "mM", "component": "circle_sibling", "type": VariableType.ALGEBRAIC}, - {"name": "two_x", "units": "milli_mole", "component": "circle_x_sibling", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "local_complex_maths", "units": "mM", "component": "circle_sibling"}, + {"name": "two_x", "units": "milli_mole", "component": "circle_x_sibling"} ] @@ -36,24 +35,32 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 states[1] = 0.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[1] = -states[0]*1.0 rates[0] = states[1]*1.0 -def compute_variables(voi, states, rates, variables): - variables[0] = states[0]+5.0*states[0]/3.0+1.0*exp(states[0]/2.0) - variables[1] = 2.0*states[1] +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[0] = states[0]+5.0*states[0]/3.0+1.0*exp(states[0]/2.0) + algebraic[1] = 2.0*states[1] diff --git a/tests/resources/generator/cellml_slc_example/model.c b/tests/resources/generator/cellml_slc_example/model.c new file mode 100644 index 0000000000..1436a03f37 --- /dev/null +++ b/tests/resources/generator/cellml_slc_example/model.c @@ -0,0 +1,92 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#include "model.h" + +#include +#include + +const char VERSION[] = "0.6.0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t CONSTANT_COUNT = 9; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 0; + +const VariableInfo CONSTANT_INFO[] = { + {"E", "fmol", "SLC_template3_ss"}, + {"P_0", "per_fmol_sec4", "SLC_template3_ss"}, + {"q_Ao", "fmol", "SLC_template3_ss"}, + {"P_1", "per_fmol_sec4", "SLC_template3_ss"}, + {"q_Ai", "fmol", "SLC_template3_ss"}, + {"P_2", "per_fmol_sec3", "SLC_template3_ss"}, + {"P_5", "per_sec3", "SLC_template3_ss"}, + {"P_4", "per_fmol2_sec3", "SLC_template3_ss"}, + {"P_3", "per_fmol_sec3", "SLC_template3_ss"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"v", "fmol_per_sec", "SLC_template3_ss"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) +{ + constants[0] = 1.1; + constants[1] = 21262500.0; + constants[2] = 150.0; + constants[3] = 3402000.0; + constants[4] = 2.0; + constants[5] = 2902500.0; + constants[6] = 810000.0; + constants[7] = 247140.0; + constants[8] = 2902500.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ + computedConstants[0] = constants[0]*(constants[1]*constants[2]-constants[3]*constants[4])/(constants[5]*constants[4]+constants[8]*constants[2]+constants[7]*constants[4]*constants[2]+constants[6]); +} + +void computeVariables(double *constants, double *computedConstants, double *algebraic) +{ +} diff --git a/tests/resources/generator/cellml_slc_example/model.h b/tests/resources/generator/cellml_slc_example/model.h new file mode 100644 index 0000000000..661f80fa6f --- /dev/null +++ b/tests/resources/generator/cellml_slc_example/model.h @@ -0,0 +1,32 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; + +typedef struct { + char name[5]; + char units[15]; + char component[17]; +} VariableInfo; + +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + +void deleteArray(double *array); + +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/cellml_slc_example/model.py b/tests/resources/generator/cellml_slc_example/model.py index 308d1d3027..fd72de2b53 100644 --- a/tests/resources/generator/cellml_slc_example/model.py +++ b/tests/resources/generator/cellml_slc_example/model.py @@ -4,51 +4,60 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 10 +CONSTANT_COUNT = 9 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 0 + +CONSTANT_INFO = [ + {"name": "E", "units": "fmol", "component": "SLC_template3_ss"}, + {"name": "P_0", "units": "per_fmol_sec4", "component": "SLC_template3_ss"}, + {"name": "q_Ao", "units": "fmol", "component": "SLC_template3_ss"}, + {"name": "P_1", "units": "per_fmol_sec4", "component": "SLC_template3_ss"}, + {"name": "q_Ai", "units": "fmol", "component": "SLC_template3_ss"}, + {"name": "P_2", "units": "per_fmol_sec3", "component": "SLC_template3_ss"}, + {"name": "P_5", "units": "per_sec3", "component": "SLC_template3_ss"}, + {"name": "P_4", "units": "per_fmol2_sec3", "component": "SLC_template3_ss"}, + {"name": "P_3", "units": "per_fmol_sec3", "component": "SLC_template3_ss"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "v", "units": "fmol_per_sec", "component": "SLC_template3_ss"} +] +ALGEBRAIC_INFO = [ +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 +def create_constants_array(): + return [nan]*CONSTANT_COUNT -VARIABLE_INFO = [ - {"name": "v", "units": "fmol_per_sec", "component": "SLC_template3_ss", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "E", "units": "fmol", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_0", "units": "per_fmol_sec4", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "q_Ao", "units": "fmol", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_1", "units": "per_fmol_sec4", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "q_Ai", "units": "fmol", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_2", "units": "per_fmol_sec3", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_5", "units": "per_sec3", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_4", "units": "per_fmol2_sec3", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_3", "units": "per_fmol_sec3", "component": "SLC_template3_ss", "type": VariableType.CONSTANT} -] + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(variables): - variables[1] = 1.1 - variables[2] = 21262500.0 - variables[3] = 150.0 - variables[4] = 3402000.0 - variables[5] = 2.0 - variables[6] = 2902500.0 - variables[7] = 810000.0 - variables[8] = 247140.0 - variables[9] = 2902500.0 +def initialise_variables(constants, computed_constants, algebraic): + constants[0] = 1.1 + constants[1] = 21262500.0 + constants[2] = 150.0 + constants[3] = 3402000.0 + constants[4] = 2.0 + constants[5] = 2902500.0 + constants[6] = 810000.0 + constants[7] = 247140.0 + constants[8] = 2902500.0 -def compute_computed_constants(variables): - variables[0] = variables[1]*(variables[2]*variables[3]-variables[4]*variables[5])/(variables[6]*variables[5]+variables[9]*variables[3]+variables[8]*variables[5]*variables[3]+variables[7]) +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[0]*(constants[1]*constants[2]-constants[3]*constants[4])/(constants[5]*constants[4]+constants[8]*constants[2]+constants[7]*constants[4]*constants[2]+constants[6]) -def compute_variables(variables): +def compute_variables(constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/cellml_state_initialised_using_variable/model.c b/tests/resources/generator/cellml_state_initialised_using_variable/model.c index 04ae033a76..d40bbc2604 100644 --- a/tests/resources/generator/cellml_state_initialised_using_variable/model.c +++ b/tests/resources/generator/cellml_state_initialised_using_variable/model.c @@ -5,20 +5,28 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 1; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "ms", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "ms", "environment"}; const VariableInfo STATE_INFO[] = { - {"x", "mV", "main", STATE} + {"x", "mV", "main"} }; -const VariableInfo VARIABLE_INFO[] = { - {"k", "mV", "constants", CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"k", "mV", "constants"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -32,11 +40,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -48,21 +78,21 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 123.0; - states[0] = variables[0]; + constants[0] = 123.0; + states[0] = constants[0]; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 1.23; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/cellml_state_initialised_using_variable/model.h b/tests/resources/generator/cellml_state_initialised_using_variable/model.h index 6f4c3d11bf..6846fc5e5e 100644 --- a/tests/resources/generator/cellml_state_initialised_using_variable/model.h +++ b/tests/resources/generator/cellml_state_initialised_using_variable/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[3]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/cellml_state_initialised_using_variable/model.py b/tests/resources/generator/cellml_state_initialised_using_variable/model.py index c5c5a267db..7436bbb9a4 100644 --- a/tests/resources/generator/cellml_state_initialised_using_variable/model.py +++ b/tests/resources/generator/cellml_state_initialised_using_variable/model.py @@ -4,29 +4,28 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 1 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "ms", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "mV", "component": "main"} +] -VOI_INFO = {"name": "t", "units": "ms", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "k", "units": "mV", "component": "constants"} +] -STATE_INFO = [ - {"name": "x", "units": "mV", "component": "main", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "k", "units": "mV", "component": "constants", "type": VariableType.CONSTANT} +ALGEBRAIC_INFO = [ ] @@ -34,22 +33,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 123.0 - states[0] = variables[0] +def initialise_variables(states, rates, constants, computed_constants, algebraic): + constants[0] = 123.0 + states[0] = constants[0] -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 1.23 -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/cellml_unit_scaling_constant/model.c b/tests/resources/generator/cellml_unit_scaling_constant/model.c index 52452dab75..d8ffa9fc17 100644 --- a/tests/resources/generator/cellml_unit_scaling_constant/model.c +++ b/tests/resources/generator/cellml_unit_scaling_constant/model.c @@ -5,22 +5,68 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 3; +const size_t CONSTANT_COUNT = 9; +const size_t COMPUTED_CONSTANT_COUNT = 10; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VARIABLE_INFO[] = { - {"k", "mM", "constants", CONSTANT}, - {"x", "mM", "main", COMPUTED_CONSTANT}, - {"y", "M", "main", COMPUTED_CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"ind_c_mM", "mM", "constants"}, + {"c_mM", "mM", "constants"}, + {"c", "mM", "constants"}, + {"c_M", "M", "constants"}, + {"ind_c_M", "M", "constants"}, + {"ind_oc_mM", "mM", "other_constants"}, + {"oc_mM", "mM", "other_constants"}, + {"oc_M", "M", "other_constants"}, + {"ind_oc_M", "M", "other_constants"} }; -double * createVariablesArray() +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"comp_c_mM_mM", "mM", "main"}, + {"comp_c_mM_M", "M", "main"}, + {"comp_c_M_mM", "mM", "main"}, + {"comp_c_M_M", "M", "main"}, + {"comp_k_mM", "mM", "main"}, + {"comp_k_M", "M", "main"}, + {"comp_oc_mM_mM", "mM", "main"}, + {"comp_oc_mM_M", "M", "main"}, + {"comp_oc_M_mM", "mM", "main"}, + {"comp_oc_M_M", "M", "main"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { +}; + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -32,17 +78,33 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *variables) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[0] = 123.0; + constants[2] = 123.0; + constants[1] = constants[2]; + constants[0] = constants[1]; + constants[3] = constants[2]; + constants[4] = constants[3]; + constants[6] = 0.001*constants[2]; + constants[5] = constants[6]; + constants[7] = constants[2]; + constants[8] = constants[7]; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[1] = variables[0]+variables[0]; - variables[2] = 0.001*variables[0]+0.001*variables[0]; + computedConstants[0] = constants[1]+constants[0]; + computedConstants[1] = 0.001*constants[1]+0.001*constants[0]; + computedConstants[2] = 1000.0*constants[3]+1000.0*constants[4]; + computedConstants[3] = constants[3]+constants[4]; + computedConstants[4] = constants[2]+constants[2]; + computedConstants[5] = 0.001*constants[2]+0.001*constants[2]; + computedConstants[6] = constants[6]+constants[5]; + computedConstants[7] = 0.001*constants[6]+0.001*constants[5]; + computedConstants[8] = 1000.0*constants[7]+1000.0*constants[8]; + computedConstants[9] = constants[7]+constants[8]; } -void computeVariables(double *variables) +void computeVariables(double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/cellml_unit_scaling_constant/model.cellml b/tests/resources/generator/cellml_unit_scaling_constant/model.cellml index bc52f483e9..08556a82c5 100644 --- a/tests/resources/generator/cellml_unit_scaling_constant/model.cellml +++ b/tests/resources/generator/cellml_unit_scaling_constant/model.cellml @@ -1,8 +1,11 @@ - + @@ -14,36 +17,164 @@ - + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - x + comp_c_mM_mM + + + c_mM_mM + ind_c_mM_mM + + + + + comp_c_mM_M + + + c_mM_M + ind_c_mM_M + + + + + comp_c_M_mM - k_x - k_x + c_M_mM + ind_c_M_mM - y + comp_c_M_M - k_y - k_y + c_M_M + ind_c_M_M + + + + + comp_k_mM + + + k_mM + k_mM + + + + + comp_k_M + + + k_M + k_M + + + + + comp_oc_mM_mM + + + oc_mM_mM + ind_oc_mM_mM + + + + + comp_oc_mM_M + + + oc_mM_M + ind_oc_mM_M + + + + + comp_oc_M_mM + + + oc_M_mM + ind_oc_M_mM + + + + + comp_oc_M_M + + + oc_M_M + ind_oc_M_M - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/resources/generator/cellml_unit_scaling_constant/model.h b/tests/resources/generator/cellml_unit_scaling_constant/model.h index bf0869677b..4d4a9fab2b 100644 --- a/tests/resources/generator/cellml_unit_scaling_constant/model.h +++ b/tests/resources/generator/cellml_unit_scaling_constant/model.h @@ -7,26 +7,26 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { - char name[2]; + char name[14]; char units[3]; - char component[10]; - VariableType type; + char component[16]; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); -double * createVariablesArray(); void deleteArray(double *array); -void initialiseVariables(double *variables); -void computeComputedConstants(double *variables); -void computeVariables(double *variables); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/cellml_unit_scaling_constant/model.py b/tests/resources/generator/cellml_unit_scaling_constant/model.py index a99e9ff626..7949ad6de6 100644 --- a/tests/resources/generator/cellml_unit_scaling_constant/model.py +++ b/tests/resources/generator/cellml_unit_scaling_constant/model.py @@ -4,37 +4,78 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 3 +CONSTANT_COUNT = 9 +COMPUTED_CONSTANT_COUNT = 10 +ALGEBRAIC_COUNT = 0 + +CONSTANT_INFO = [ + {"name": "ind_c_mM", "units": "mM", "component": "constants"}, + {"name": "c_mM", "units": "mM", "component": "constants"}, + {"name": "c", "units": "mM", "component": "constants"}, + {"name": "c_M", "units": "M", "component": "constants"}, + {"name": "ind_c_M", "units": "M", "component": "constants"}, + {"name": "ind_oc_mM", "units": "mM", "component": "other_constants"}, + {"name": "oc_mM", "units": "mM", "component": "other_constants"}, + {"name": "oc_M", "units": "M", "component": "other_constants"}, + {"name": "ind_oc_M", "units": "M", "component": "other_constants"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "comp_c_mM_mM", "units": "mM", "component": "main"}, + {"name": "comp_c_mM_M", "units": "M", "component": "main"}, + {"name": "comp_c_M_mM", "units": "mM", "component": "main"}, + {"name": "comp_c_M_M", "units": "M", "component": "main"}, + {"name": "comp_k_mM", "units": "mM", "component": "main"}, + {"name": "comp_k_M", "units": "M", "component": "main"}, + {"name": "comp_oc_mM_mM", "units": "mM", "component": "main"}, + {"name": "comp_oc_mM_M", "units": "M", "component": "main"}, + {"name": "comp_oc_M_mM", "units": "mM", "component": "main"}, + {"name": "comp_oc_M_M", "units": "M", "component": "main"} +] +ALGEBRAIC_INFO = [ +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 +def create_constants_array(): + return [nan]*CONSTANT_COUNT -VARIABLE_INFO = [ - {"name": "k", "units": "mM", "component": "constants", "type": VariableType.CONSTANT}, - {"name": "x", "units": "mM", "component": "main", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "y", "units": "M", "component": "main", "type": VariableType.COMPUTED_CONSTANT} -] + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(variables): - variables[0] = 123.0 +def initialise_variables(constants, computed_constants, algebraic): + constants[2] = 123.0 + constants[1] = constants[2] + constants[0] = constants[1] + constants[3] = constants[2] + constants[4] = constants[3] + constants[6] = 0.001*constants[2] + constants[5] = constants[6] + constants[7] = constants[2] + constants[8] = constants[7] -def compute_computed_constants(variables): - variables[1] = variables[0]+variables[0] - variables[2] = 0.001*variables[0]+0.001*variables[0] +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[1]+constants[0] + computed_constants[1] = 0.001*constants[1]+0.001*constants[0] + computed_constants[2] = 1000.0*constants[3]+1000.0*constants[4] + computed_constants[3] = constants[3]+constants[4] + computed_constants[4] = constants[2]+constants[2] + computed_constants[5] = 0.001*constants[2]+0.001*constants[2] + computed_constants[6] = constants[6]+constants[5] + computed_constants[7] = 0.001*constants[6]+0.001*constants[5] + computed_constants[8] = 1000.0*constants[7]+1000.0*constants[8] + computed_constants[9] = constants[7]+constants[8] -def compute_variables(variables): +def compute_variables(constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/cellml_unit_scaling_rate/model.c b/tests/resources/generator/cellml_unit_scaling_rate/model.c index 83fb18139d..c3a30e5de9 100644 --- a/tests/resources/generator/cellml_unit_scaling_rate/model.c +++ b/tests/resources/generator/cellml_unit_scaling_rate/model.c @@ -5,21 +5,29 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 2; -const VariableInfo VOI_INFO = {"t", "ms", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "ms", "environment"}; const VariableInfo STATE_INFO[] = { - {"k", "mM", "states", STATE} + {"k", "mM", "states"} }; -const VariableInfo VARIABLE_INFO[] = { - {"x", "mM", "main", ALGEBRAIC}, - {"y", "M", "main", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"x", "mM", "main"}, + {"y", "M", "main"} }; double * createStatesArray() @@ -33,11 +41,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -49,22 +79,22 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { states[0] = 123.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 1.23; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1000.0*rates[0]+1000.0*rates[0]; - variables[1] = 1000.0*0.001*rates[0]+1000.0*0.001*rates[0]; + algebraic[0] = 1000.0*rates[0]+1000.0*rates[0]; + algebraic[1] = 1000.0*0.001*rates[0]+1000.0*0.001*rates[0]; } diff --git a/tests/resources/generator/cellml_unit_scaling_rate/model.h b/tests/resources/generator/cellml_unit_scaling_rate/model.h index 6f4c3d11bf..6846fc5e5e 100644 --- a/tests/resources/generator/cellml_unit_scaling_rate/model.h +++ b/tests/resources/generator/cellml_unit_scaling_rate/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[3]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/cellml_unit_scaling_rate/model.py b/tests/resources/generator/cellml_unit_scaling_rate/model.py index e7ba41b796..7670bea583 100644 --- a/tests/resources/generator/cellml_unit_scaling_rate/model.py +++ b/tests/resources/generator/cellml_unit_scaling_rate/model.py @@ -4,30 +4,29 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 2 +VOI_INFO = {"name": "t", "units": "ms", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "k", "units": "mM", "component": "states"} +] -VOI_INFO = {"name": "t", "units": "ms", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "k", "units": "mM", "component": "states", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "x", "units": "mM", "component": "main", "type": VariableType.ALGEBRAIC}, - {"name": "y", "units": "M", "component": "main", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "x", "units": "mM", "component": "main"}, + {"name": "y", "units": "M", "component": "main"} ] @@ -35,22 +34,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 123.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 1.23 -def compute_variables(voi, states, rates, variables): - variables[0] = 1000.0*rates[0]+1000.0*rates[0] - variables[1] = 1000.0*0.001*rates[0]+1000.0*0.001*rates[0] +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[0] = 1000.0*rates[0]+1000.0*rates[0] + algebraic[1] = 1000.0*0.001*rates[0]+1000.0*0.001*rates[0] diff --git a/tests/resources/generator/cellml_unit_scaling_state/model.c b/tests/resources/generator/cellml_unit_scaling_state/model.c index 2af3ce880f..f6df63b2f6 100644 --- a/tests/resources/generator/cellml_unit_scaling_state/model.c +++ b/tests/resources/generator/cellml_unit_scaling_state/model.c @@ -5,21 +5,29 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 2; -const VariableInfo VOI_INFO = {"t", "ms", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "ms", "environment"}; const VariableInfo STATE_INFO[] = { - {"k", "mM", "states", STATE} + {"k", "mM", "states"} }; -const VariableInfo VARIABLE_INFO[] = { - {"x", "mM", "main", ALGEBRAIC}, - {"y", "M", "main", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"x", "mM", "main"}, + {"y", "M", "main"} }; double * createStatesArray() @@ -33,11 +41,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -49,22 +79,22 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { states[0] = 123.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 1.23; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = states[0]+states[0]; - variables[1] = 0.001*states[0]+0.001*states[0]; + algebraic[0] = states[0]+states[0]; + algebraic[1] = 0.001*states[0]+0.001*states[0]; } diff --git a/tests/resources/generator/cellml_unit_scaling_state/model.h b/tests/resources/generator/cellml_unit_scaling_state/model.h index 6f4c3d11bf..6846fc5e5e 100644 --- a/tests/resources/generator/cellml_unit_scaling_state/model.h +++ b/tests/resources/generator/cellml_unit_scaling_state/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[3]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/cellml_unit_scaling_state/model.py b/tests/resources/generator/cellml_unit_scaling_state/model.py index c4c97bfe12..84d9b92830 100644 --- a/tests/resources/generator/cellml_unit_scaling_state/model.py +++ b/tests/resources/generator/cellml_unit_scaling_state/model.py @@ -4,30 +4,29 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 2 +VOI_INFO = {"name": "t", "units": "ms", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "k", "units": "mM", "component": "states"} +] -VOI_INFO = {"name": "t", "units": "ms", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "k", "units": "mM", "component": "states", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "x", "units": "mM", "component": "main", "type": VariableType.ALGEBRAIC}, - {"name": "y", "units": "M", "component": "main", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "x", "units": "mM", "component": "main"}, + {"name": "y", "units": "M", "component": "main"} ] @@ -35,22 +34,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 123.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 1.23 -def compute_variables(voi, states, rates, variables): - variables[0] = states[0]+states[0] - variables[1] = 0.001*states[0]+0.001*states[0] +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[0] = states[0]+states[0] + algebraic[1] = 0.001*states[0]+0.001*states[0] diff --git a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.c b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.c index 211ac7e6de..0b955b087e 100644 --- a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.c +++ b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.c @@ -5,20 +5,28 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 2; -const size_t VARIABLE_COUNT = 0; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "ms", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "ms", "environment"}; const VariableInfo STATE_INFO[] = { - {"k1", "mM", "main", STATE}, - {"k2", "M", "main", STATE} + {"k1", "mM", "main"}, + {"k2", "M", "main"} }; -const VariableInfo VARIABLE_INFO[] = { +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -32,11 +40,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -48,22 +78,22 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { states[0] = 123.0; states[1] = 0.001*789.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 1.23; rates[1] = 7.89; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.h b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.h index 6d6a6b11a3..9134e54166 100644 --- a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.h +++ b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[3]; char units[3]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.py b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.py index e267808bbc..8f4a5b9b3f 100644 --- a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.py +++ b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_constant/model.py @@ -4,29 +4,28 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 2 -VARIABLE_COUNT = 0 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "ms", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "k1", "units": "mM", "component": "main"}, + {"name": "k2", "units": "M", "component": "main"} +] -VOI_INFO = {"name": "t", "units": "ms", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "k1", "units": "mM", "component": "main", "type": VariableType.STATE}, - {"name": "k2", "units": "M", "component": "main", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ +ALGEBRAIC_INFO = [ ] @@ -34,23 +33,31 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 123.0 states[1] = 0.001*789.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 1.23 rates[1] = 7.89 -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.c b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.c index 3ada142a3b..ce8c344e70 100644 --- a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.c +++ b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.c @@ -5,22 +5,30 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 2; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "ms", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "ms", "environment"}; const VariableInfo STATE_INFO[] = { - {"k1", "mM", "main", STATE}, - {"k2", "M", "main", STATE} + {"k1", "mM", "main"}, + {"k2", "M", "main"} }; -const VariableInfo VARIABLE_INFO[] = { - {"k1_cst", "mM", "constants", CONSTANT}, - {"k2_cst", "mM", "constants", CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"k1_cst", "mM", "constants"}, + {"k2_cst", "mM", "constants"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -34,11 +42,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -50,24 +80,24 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 123.0; - variables[1] = 789.0; - states[0] = variables[0]; - states[1] = 0.001*variables[1]; + constants[0] = 123.0; + states[0] = constants[0]; + constants[1] = 789.0; + states[1] = 0.001*constants[1]; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 1.23; rates[1] = 7.89; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.h b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.h index b28167c371..11dfefb1e8 100644 --- a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.h +++ b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[7]; char units[3]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.py b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.py index 8b4004f24d..7cf4d54baa 100644 --- a/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.py +++ b/tests/resources/generator/cellml_unit_scaling_state_initialised_using_variable/model.py @@ -4,31 +4,30 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 2 -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "ms", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "k1", "units": "mM", "component": "main"}, + {"name": "k2", "units": "M", "component": "main"} +] -VOI_INFO = {"name": "t", "units": "ms", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "k1_cst", "units": "mM", "component": "constants"}, + {"name": "k2_cst", "units": "mM", "component": "constants"} +] -STATE_INFO = [ - {"name": "k1", "units": "mM", "component": "main", "type": VariableType.STATE}, - {"name": "k2", "units": "M", "component": "main", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "k1_cst", "units": "mM", "component": "constants", "type": VariableType.CONSTANT}, - {"name": "k2_cst", "units": "mM", "component": "constants", "type": VariableType.CONSTANT} +ALGEBRAIC_INFO = [ ] @@ -36,25 +35,33 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 123.0 - variables[1] = 789.0 - states[0] = variables[0] - states[1] = 0.001*variables[1] +def initialise_variables(states, rates, constants, computed_constants, algebraic): + constants[0] = 123.0 + states[0] = constants[0] + constants[1] = 789.0 + states[1] = 0.001*constants[1] -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 1.23 rates[1] = 7.89 -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/cellml_unit_scaling_voi_direct/model.c b/tests/resources/generator/cellml_unit_scaling_voi_direct/model.c index 1045dc0687..30da00b52b 100644 --- a/tests/resources/generator/cellml_unit_scaling_voi_direct/model.c +++ b/tests/resources/generator/cellml_unit_scaling_voi_direct/model.c @@ -5,20 +5,28 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 2; -const size_t VARIABLE_COUNT = 0; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "ms", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "ms", "environment"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "main", STATE}, - {"y", "dimensionless", "main", STATE} + {"x", "dimensionless", "main"}, + {"y", "dimensionless", "main"} }; -const VariableInfo VARIABLE_INFO[] = { +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -32,11 +40,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -48,22 +78,22 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { states[0] = 3.0; states[1] = 5.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = voi/1.0; rates[1] = 0.001*voi/1.0; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/cellml_unit_scaling_voi_direct/model.h b/tests/resources/generator/cellml_unit_scaling_voi_direct/model.h index 9303e63ae3..433b3e7910 100644 --- a/tests/resources/generator/cellml_unit_scaling_voi_direct/model.h +++ b/tests/resources/generator/cellml_unit_scaling_voi_direct/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/cellml_unit_scaling_voi_direct/model.py b/tests/resources/generator/cellml_unit_scaling_voi_direct/model.py index 3f60206736..861644f84b 100644 --- a/tests/resources/generator/cellml_unit_scaling_voi_direct/model.py +++ b/tests/resources/generator/cellml_unit_scaling_voi_direct/model.py @@ -4,29 +4,28 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 2 -VARIABLE_COUNT = 0 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "ms", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "main"}, + {"name": "y", "units": "dimensionless", "component": "main"} +] -VOI_INFO = {"name": "t", "units": "ms", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "main", "type": VariableType.STATE}, - {"name": "y", "units": "dimensionless", "component": "main", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ +ALGEBRAIC_INFO = [ ] @@ -34,23 +33,31 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 3.0 states[1] = 5.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = voi/1.0 rates[1] = 0.001*voi/1.0 -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.c b/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.c index 6e9c2fad29..fe68895c69 100644 --- a/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.c +++ b/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.c @@ -5,21 +5,29 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 3; -const size_t VARIABLE_COUNT = 0; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "environment"}; const VariableInfo STATE_INFO[] = { - {"x", "metre", "t_in_s", STATE}, - {"x", "metre", "t_in_ms", STATE}, - {"x", "metre", "t_in_ks", STATE} + {"x", "metre", "t_in_s"}, + {"x", "metre", "t_in_ms"}, + {"x", "metre", "t_in_ks"} }; -const VariableInfo VARIABLE_INFO[] = { +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -33,11 +41,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -49,24 +79,24 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { states[0] = 3.0; states[1] = 7.0; states[2] = 11.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 5.0; rates[1] = 1000.0*9.0; rates[2] = 0.001*13.0; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.h b/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.h index 6de3690637..1fe2b2ac23 100644 --- a/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.h +++ b/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[7]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.py b/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.py index 7005958e20..9e5354280c 100644 --- a/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.py +++ b/tests/resources/generator/cellml_unit_scaling_voi_indirect/model.py @@ -4,30 +4,29 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 3 -VARIABLE_COUNT = 0 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "metre", "component": "t_in_s"}, + {"name": "x", "units": "metre", "component": "t_in_ms"}, + {"name": "x", "units": "metre", "component": "t_in_ks"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "x", "units": "metre", "component": "t_in_s", "type": VariableType.STATE}, - {"name": "x", "units": "metre", "component": "t_in_ms", "type": VariableType.STATE}, - {"name": "x", "units": "metre", "component": "t_in_ks", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ +ALGEBRAIC_INFO = [ ] @@ -35,25 +34,33 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 3.0 states[1] = 7.0 states[2] = 11.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 5.0 rates[1] = 1000.0*9.0 rates[2] = 0.001*13.0 -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/dae_cellml_1_1_model/model.c b/tests/resources/generator/dae_cellml_1_1_model/model.c index b0da0480cf..f0b0480a83 100644 --- a/tests/resources/generator/dae_cellml_1_1_model/model.c +++ b/tests/resources/generator/dae_cellml_1_1_model/model.c @@ -5,30 +5,38 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 2; -const size_t VARIABLE_COUNT = 10; +const size_t CONSTANT_COUNT = 5; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 5; -const VariableInfo VOI_INFO = {"t", "second", "main", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "main"}; const VariableInfo STATE_INFO[] = { - {"q_1", "coulomb", "main", STATE}, - {"v_3", "C_per_s", "main", STATE} + {"q_1", "coulomb", "main"}, + {"v_3", "C_per_s", "main"} }; -const VariableInfo VARIABLE_INFO[] = { - {"v_1", "C_per_s", "main", ALGEBRAIC}, - {"v_in", "C_per_s", "main", CONSTANT}, - {"v_2", "C_per_s", "main", ALGEBRAIC}, - {"v_out", "C_per_s", "main", CONSTANT}, - {"u_1", "J_per_C", "main", ALGEBRAIC}, - {"u_2", "J_per_C", "main", ALGEBRAIC}, - {"u_3", "J_per_C", "main", ALGEBRAIC}, - {"C", "C2_per_J", "main", CONSTANT}, - {"R", "Js_per_C2", "main", CONSTANT}, - {"L", "Js2_per_C2", "main", CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"v_in", "C_per_s", "main"}, + {"v_out", "C_per_s", "main"}, + {"C", "C2_per_J", "main"}, + {"R", "Js_per_C2", "main"}, + {"L", "Js2_per_C2", "main"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"v_1", "C_per_s", "main"}, + {"v_2", "C_per_s", "main"}, + {"u_1", "J_per_C", "main"}, + {"u_2", "J_per_C", "main"}, + {"u_3", "J_per_C", "main"} }; double * createStatesArray() @@ -42,11 +50,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -62,7 +92,9 @@ typedef struct { double voi; double *states; double *rates; - double *variables; + double *constants; + double *computedConstants; + double *algebraic; } RootFindingInfo; extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), @@ -73,23 +105,25 @@ void objectiveFunction0(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[0] = u[0]; + algebraic[0] = u[0]; - f[0] = variables[1]-(variables[0]+variables[2]); + f[0] = constants[0]-(algebraic[0]+algebraic[1]); } -void findRoot0(double voi, double *states, double *rates, double *variables) +void findRoot0(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[0]; + u[0] = algebraic[0]; nlaSolve(objectiveFunction0, u, 1, &rfi); - variables[0] = u[0]; + algebraic[0] = u[0]; } void objectiveFunction1(double *u, double *f, void *data) @@ -97,58 +131,60 @@ void objectiveFunction1(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[6] = u[0]; + algebraic[4] = u[0]; - f[0] = variables[4]-(variables[5]+variables[6]); + f[0] = algebraic[2]-(algebraic[3]+algebraic[4]); } -void findRoot1(double voi, double *states, double *rates, double *variables) +void findRoot1(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[6]; + u[0] = algebraic[4]; nlaSolve(objectiveFunction1, u, 1, &rfi); - variables[6] = u[0]; + algebraic[4] = u[0]; } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 0.0; - variables[1] = 1.0; - variables[3] = 1.0; - variables[6] = 0.0; - variables[7] = 20.0; - variables[8] = 2.0; - variables[9] = 10.0; states[0] = 1.0; states[1] = 0.0; + constants[0] = 1.0; + constants[1] = 1.0; + constants[2] = 20.0; + constants[3] = 2.0; + constants[4] = 10.0; + algebraic[0] = 0.0; + algebraic[4] = 0.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[2] = states[1]+variables[3]; - findRoot0(voi, states, rates, variables); - rates[0] = variables[0]; - variables[4] = states[0]/variables[7]; - variables[5] = variables[8]*variables[2]; - findRoot1(voi, states, rates, variables); - rates[1] = variables[6]/variables[9]; + algebraic[1] = states[1]+constants[1]; + findRoot0(voi, states, rates, constants, computedConstants, algebraic); + rates[0] = algebraic[0]; + algebraic[2] = states[0]/constants[2]; + algebraic[3] = constants[3]*algebraic[1]; + findRoot1(voi, states, rates, constants, computedConstants, algebraic); + rates[1] = algebraic[4]/constants[4]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[2] = states[1]+variables[3]; - findRoot0(voi, states, rates, variables); - variables[4] = states[0]/variables[7]; - variables[5] = variables[8]*variables[2]; - findRoot1(voi, states, rates, variables); + algebraic[1] = states[1]+constants[1]; + findRoot0(voi, states, rates, constants, computedConstants, algebraic); + algebraic[2] = states[0]/constants[2]; + algebraic[3] = constants[3]*algebraic[1]; + findRoot1(voi, states, rates, constants, computedConstants, algebraic); } diff --git a/tests/resources/generator/dae_cellml_1_1_model/model.h b/tests/resources/generator/dae_cellml_1_1_model/model.h index 775b4fec29..7e7d90d531 100644 --- a/tests/resources/generator/dae_cellml_1_1_model/model.h +++ b/tests/resources/generator/dae_cellml_1_1_model/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[6]; char units[11]; char component[5]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/dae_cellml_1_1_model/model.py b/tests/resources/generator/dae_cellml_1_1_model/model.py index 0967f308a9..ad09db6bc1 100644 --- a/tests/resources/generator/dae_cellml_1_1_model/model.py +++ b/tests/resources/generator/dae_cellml_1_1_model/model.py @@ -4,39 +4,38 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 2 -VARIABLE_COUNT = 10 +CONSTANT_COUNT = 5 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 5 +VOI_INFO = {"name": "t", "units": "second", "component": "main"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "q_1", "units": "coulomb", "component": "main"}, + {"name": "v_3", "units": "C_per_s", "component": "main"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "main", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "v_in", "units": "C_per_s", "component": "main"}, + {"name": "v_out", "units": "C_per_s", "component": "main"}, + {"name": "C", "units": "C2_per_J", "component": "main"}, + {"name": "R", "units": "Js_per_C2", "component": "main"}, + {"name": "L", "units": "Js2_per_C2", "component": "main"} +] -STATE_INFO = [ - {"name": "q_1", "units": "coulomb", "component": "main", "type": VariableType.STATE}, - {"name": "v_3", "units": "C_per_s", "component": "main", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "v_1", "units": "C_per_s", "component": "main", "type": VariableType.ALGEBRAIC}, - {"name": "v_in", "units": "C_per_s", "component": "main", "type": VariableType.CONSTANT}, - {"name": "v_2", "units": "C_per_s", "component": "main", "type": VariableType.ALGEBRAIC}, - {"name": "v_out", "units": "C_per_s", "component": "main", "type": VariableType.CONSTANT}, - {"name": "u_1", "units": "J_per_C", "component": "main", "type": VariableType.ALGEBRAIC}, - {"name": "u_2", "units": "J_per_C", "component": "main", "type": VariableType.ALGEBRAIC}, - {"name": "u_3", "units": "J_per_C", "component": "main", "type": VariableType.ALGEBRAIC}, - {"name": "C", "units": "C2_per_J", "component": "main", "type": VariableType.CONSTANT}, - {"name": "R", "units": "Js_per_C2", "component": "main", "type": VariableType.CONSTANT}, - {"name": "L", "units": "Js2_per_C2", "component": "main", "type": VariableType.CONSTANT} +ALGEBRAIC_INFO = [ + {"name": "v_1", "units": "C_per_s", "component": "main"}, + {"name": "v_2", "units": "C_per_s", "component": "main"}, + {"name": "u_1", "units": "J_per_C", "component": "main"}, + {"name": "u_2", "units": "J_per_C", "component": "main"}, + {"name": "u_3", "units": "J_per_C", "component": "main"} ] @@ -44,8 +43,16 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT from nlasolver import nla_solve @@ -55,73 +62,77 @@ def objective_function_0(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[0] = u[0] + algebraic[0] = u[0] - f[0] = variables[1]-(variables[0]+variables[2]) + f[0] = constants[0]-(algebraic[0]+algebraic[1]) -def find_root_0(voi, states, rates, variables): +def find_root_0(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[0] + u[0] = algebraic[0] - u = nla_solve(objective_function_0, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_0, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[0] = u[0] + algebraic[0] = u[0] def objective_function_1(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[6] = u[0] + algebraic[4] = u[0] - f[0] = variables[4]-(variables[5]+variables[6]) + f[0] = algebraic[2]-(algebraic[3]+algebraic[4]) -def find_root_1(voi, states, rates, variables): +def find_root_1(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[6] + u[0] = algebraic[4] - u = nla_solve(objective_function_1, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_1, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[6] = u[0] + algebraic[4] = u[0] -def initialise_variables(states, rates, variables): - variables[0] = 0.0 - variables[1] = 1.0 - variables[3] = 1.0 - variables[6] = 0.0 - variables[7] = 20.0 - variables[8] = 2.0 - variables[9] = 10.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 states[1] = 0.0 + constants[0] = 1.0 + constants[1] = 1.0 + constants[2] = 20.0 + constants[3] = 2.0 + constants[4] = 10.0 + algebraic[0] = 0.0 + algebraic[4] = 0.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - variables[2] = states[1]+variables[3] - find_root_0(voi, states, rates, variables) - rates[0] = variables[0] - variables[4] = states[0]/variables[7] - variables[5] = variables[8]*variables[2] - find_root_1(voi, states, rates, variables) - rates[1] = variables[6]/variables[9] +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + algebraic[1] = states[1]+constants[1] + find_root_0(voi, states, rates, constants, computed_constants, algebraic) + rates[0] = algebraic[0] + algebraic[2] = states[0]/constants[2] + algebraic[3] = constants[3]*algebraic[1] + find_root_1(voi, states, rates, constants, computed_constants, algebraic) + rates[1] = algebraic[4]/constants[4] -def compute_variables(voi, states, rates, variables): - variables[2] = states[1]+variables[3] - find_root_0(voi, states, rates, variables) - variables[4] = states[0]/variables[7] - variables[5] = variables[8]*variables[2] - find_root_1(voi, states, rates, variables) +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[1] = states[1]+constants[1] + find_root_0(voi, states, rates, constants, computed_constants, algebraic) + algebraic[2] = states[0]/constants[2] + algebraic[3] = constants[3]*algebraic[1] + find_root_1(voi, states, rates, constants, computed_constants, algebraic) diff --git a/tests/resources/generator/dependent_eqns/model.c b/tests/resources/generator/dependent_eqns/model.c index 72e8b4dc61..044e54da27 100644 --- a/tests/resources/generator/dependent_eqns/model.c +++ b/tests/resources/generator/dependent_eqns/model.c @@ -5,21 +5,29 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 2; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 2; -const VariableInfo VOI_INFO = {"time", "second", "my_component", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"time", "second", "my_component"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_component", STATE} + {"x", "dimensionless", "my_component"} }; -const VariableInfo VARIABLE_INFO[] = { - {"a", "second", "my_component", ALGEBRAIC}, - {"b", "second", "my_component", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"a", "second", "my_component"}, + {"b", "second", "my_component"} }; double * createStatesArray() @@ -33,11 +41,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -49,22 +79,22 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { states[0] = 0.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 1.0; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[1] = 2.0*voi; - variables[0] = 3.0*variables[1]; + algebraic[1] = 2.0*voi; + algebraic[0] = 3.0*algebraic[1]; } diff --git a/tests/resources/generator/dependent_eqns/model.h b/tests/resources/generator/dependent_eqns/model.h index 54e3adf9e8..eba984bd3e 100644 --- a/tests/resources/generator/dependent_eqns/model.h +++ b/tests/resources/generator/dependent_eqns/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[5]; char units[14]; char component[13]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/dependent_eqns/model.py b/tests/resources/generator/dependent_eqns/model.py index 7bd1be7460..e1db2d5949 100644 --- a/tests/resources/generator/dependent_eqns/model.py +++ b/tests/resources/generator/dependent_eqns/model.py @@ -4,30 +4,29 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 2 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 2 +VOI_INFO = {"name": "time", "units": "second", "component": "my_component"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_component"} +] -VOI_INFO = {"name": "time", "units": "second", "component": "my_component", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_component", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "a", "units": "second", "component": "my_component", "type": VariableType.ALGEBRAIC}, - {"name": "b", "units": "second", "component": "my_component", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "a", "units": "second", "component": "my_component"}, + {"name": "b", "units": "second", "component": "my_component"} ] @@ -35,22 +34,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 0.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 1.0 -def compute_variables(voi, states, rates, variables): - variables[1] = 2.0*voi - variables[0] = 3.0*variables[1] +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[1] = 2.0*voi + algebraic[0] = 3.0*algebraic[1] diff --git a/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.c b/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.c index 5b2fdea1d7..ab1967fa54 100644 --- a/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.c +++ b/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.c @@ -5,268 +5,276 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 33; -const size_t VARIABLE_COUNT = 217; +const size_t CONSTANT_COUNT = 91; +const size_t COMPUTED_CONSTANT_COUNT = 25; +const size_t ALGEBRAIC_COUNT = 101; -const VariableInfo VOI_INFO = {"time", "second", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"time", "second", "environment"}; const VariableInfo STATE_INFO[] = { - {"Ca_sub", "millimolar", "Ca_dynamics", STATE}, - {"Nai_", "millimolar", "Nai_concentration", STATE}, - {"Ca_jsr", "millimolar", "Ca_dynamics", STATE}, - {"O", "dimensionless", "Ca_SR_release", STATE}, - {"R", "dimensionless", "Ca_SR_release", STATE}, - {"RI", "dimensionless", "Ca_SR_release", STATE}, - {"I", "dimensionless", "Ca_SR_release", STATE}, - {"Cai", "millimolar", "Ca_dynamics", STATE}, - {"Ca_nsr", "millimolar", "Ca_dynamics", STATE}, - {"fTC", "dimensionless", "Ca_buffering", STATE}, - {"fTMC", "dimensionless", "Ca_buffering", STATE}, - {"fTMM", "dimensionless", "Ca_buffering", STATE}, - {"fCMi", "dimensionless", "Ca_buffering", STATE}, - {"fCMs", "dimensionless", "Ca_buffering", STATE}, - {"fCQ", "dimensionless", "Ca_buffering", STATE}, - {"V_ode", "millivolt", "Membrane", STATE}, - {"y", "dimensionless", "i_f_y_gate", STATE}, - {"h", "dimensionless", "i_Na_h_gate", STATE}, - {"m", "dimensionless", "i_Na_m_gate", STATE}, - {"s_Kur", "dimensionless", "i_Kur_sKur_gate", STATE}, - {"r_Kur", "dimensionless", "i_Kur_rKur_gate", STATE}, - {"fCa", "dimensionless", "i_CaL_fCa_gate", STATE}, - {"fL", "dimensionless", "i_CaL_fL_gate", STATE}, - {"dL", "dimensionless", "i_CaL_dL_gate", STATE}, - {"fT", "dimensionless", "i_CaT_fT_gate", STATE}, - {"dT", "dimensionless", "i_CaT_dT_gate", STATE}, - {"r", "dimensionless", "i_to_r_gate", STATE}, - {"q", "dimensionless", "i_to_q_gate", STATE}, - {"piy", "dimensionless", "i_Kr_pi_gate", STATE}, - {"paF", "dimensionless", "i_Kr_pa_gate", STATE}, - {"paS", "dimensionless", "i_Kr_pa_gate", STATE}, - {"n", "dimensionless", "i_Ks_n_gate", STATE}, - {"a", "dimensionless", "i_KACh_a_gate", STATE} + {"Ca_sub", "millimolar", "Ca_dynamics"}, + {"Nai_", "millimolar", "Nai_concentration"}, + {"Ca_jsr", "millimolar", "Ca_dynamics"}, + {"O", "dimensionless", "Ca_SR_release"}, + {"R", "dimensionless", "Ca_SR_release"}, + {"RI", "dimensionless", "Ca_SR_release"}, + {"I", "dimensionless", "Ca_SR_release"}, + {"Cai", "millimolar", "Ca_dynamics"}, + {"Ca_nsr", "millimolar", "Ca_dynamics"}, + {"fTC", "dimensionless", "Ca_buffering"}, + {"fTMC", "dimensionless", "Ca_buffering"}, + {"fTMM", "dimensionless", "Ca_buffering"}, + {"fCMi", "dimensionless", "Ca_buffering"}, + {"fCMs", "dimensionless", "Ca_buffering"}, + {"fCQ", "dimensionless", "Ca_buffering"}, + {"V_ode", "millivolt", "Membrane"}, + {"y", "dimensionless", "i_f_y_gate"}, + {"h", "dimensionless", "i_Na_h_gate"}, + {"m", "dimensionless", "i_Na_m_gate"}, + {"s_Kur", "dimensionless", "i_Kur_sKur_gate"}, + {"r_Kur", "dimensionless", "i_Kur_rKur_gate"}, + {"fCa", "dimensionless", "i_CaL_fCa_gate"}, + {"fL", "dimensionless", "i_CaL_fL_gate"}, + {"dL", "dimensionless", "i_CaL_dL_gate"}, + {"fT", "dimensionless", "i_CaT_fT_gate"}, + {"dT", "dimensionless", "i_CaT_dT_gate"}, + {"r", "dimensionless", "i_to_r_gate"}, + {"q", "dimensionless", "i_to_q_gate"}, + {"piy", "dimensionless", "i_Kr_pi_gate"}, + {"paF", "dimensionless", "i_Kr_pa_gate"}, + {"paS", "dimensionless", "i_Kr_pa_gate"}, + {"n", "dimensionless", "i_Ks_n_gate"}, + {"a", "dimensionless", "i_KACh_a_gate"} }; -const VariableInfo VARIABLE_INFO[] = { - {"ACh", "millimolar", "Rate_modulation_experiments", CONSTANT}, - {"Iso_1_uM", "dimensionless", "Rate_modulation_experiments", CONSTANT}, - {"E_Na", "millivolt", "Ionic_values", ALGEBRAIC}, - {"RTONF", "millivolt", "Membrane", COMPUTED_CONSTANT}, - {"Nao", "millimolar", "Ionic_values", CONSTANT}, - {"Nai", "millimolar", "Nai_concentration", ALGEBRAIC}, - {"E_K", "millivolt", "Ionic_values", COMPUTED_CONSTANT}, - {"Ko", "millimolar", "Ionic_values", CONSTANT}, - {"Ki", "millimolar", "Ionic_values", CONSTANT}, - {"E_Ca", "millivolt", "Ionic_values", ALGEBRAIC}, - {"Cao", "millimolar", "Ionic_values", CONSTANT}, - {"Nai_clamp", "dimensionless", "Nai_concentration", CONSTANT}, - {"i_Na", "nanoA", "i_Na", ALGEBRAIC}, - {"i_NaCa", "nanoA", "i_NaCa", ALGEBRAIC}, - {"i_NaK", "nanoA", "i_NaK", ALGEBRAIC}, - {"i_siNa", "nanoA", "i_CaL", ALGEBRAIC}, - {"i_fNa", "nanoA", "i_f", ALGEBRAIC}, - {"F", "coulomb_per_mole", "Membrane", CONSTANT}, - {"V_i", "millimetre3", "Cell_parameters", COMPUTED_CONSTANT}, - {"V_sub", "millimetre3", "Cell_parameters", COMPUTED_CONSTANT}, - {"Iso_increase", "dimensionless", "i_NaK", COMPUTED_CONSTANT}, - {"V", "millivolt", "Membrane", ALGEBRAIC}, - {"Km_Nap", "millimolar", "i_NaK", CONSTANT}, - {"Km_Kp", "millimolar", "i_NaK", CONSTANT}, - {"i_NaK_max", "nanoA", "i_NaK", CONSTANT}, - {"blockade_NaCa", "dimensionless", "i_NaCa", CONSTANT}, - {"x2", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"k21", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"x1", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"k12", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"K_NaCa", "nanoA", "i_NaCa", CONSTANT}, - {"x4", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"x3", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"k41", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"k23", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"k34", "dimensionless", "i_NaCa", COMPUTED_CONSTANT}, - {"k43", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"k32", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"k14", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"K3ni", "millimolar", "i_NaCa", CONSTANT}, - {"Kci", "millimolar", "i_NaCa", CONSTANT}, - {"Qci", "dimensionless", "i_NaCa", CONSTANT}, - {"di", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"K1ni", "millimolar", "i_NaCa", CONSTANT}, - {"K2ni", "millimolar", "i_NaCa", CONSTANT}, - {"Qn", "dimensionless", "i_NaCa", CONSTANT}, - {"Kcni", "millimolar", "i_NaCa", CONSTANT}, - {"K3no", "millimolar", "i_NaCa", CONSTANT}, - {"Kco", "millimolar", "i_NaCa", CONSTANT}, - {"Qco", "dimensionless", "i_NaCa", CONSTANT}, - {"do", "dimensionless", "i_NaCa", ALGEBRAIC}, - {"K1no", "millimolar", "i_NaCa", CONSTANT}, - {"K2no", "millimolar", "i_NaCa", CONSTANT}, - {"j_SRCarel", "millimolar_per_second", "Ca_SR_release", ALGEBRAIC}, - {"ks", "per_second", "Ca_SR_release", CONSTANT}, - {"diff", "millimolar", "Ca_SR_release", ALGEBRAIC}, - {"kCaSR", "dimensionless", "Ca_SR_release", ALGEBRAIC}, - {"MaxSR", "dimensionless", "Ca_SR_release", CONSTANT}, - {"MinSR", "dimensionless", "Ca_SR_release", CONSTANT}, - {"EC50_SR", "millimolar", "Ca_SR_release", CONSTANT}, - {"HSR", "dimensionless", "Ca_SR_release", CONSTANT}, - {"koSRCa", "per_millimolar2_second", "Ca_SR_release", ALGEBRAIC}, - {"koCa", "per_millimolar2_second", "Ca_SR_release", CONSTANT}, - {"kiSRCa", "per_millimolar_second", "Ca_SR_release", ALGEBRAIC}, - {"kiCa", "per_millimolar_second", "Ca_SR_release", CONSTANT}, - {"kim", "per_second", "Ca_SR_release", CONSTANT}, - {"kom", "per_second", "Ca_SR_release", CONSTANT}, - {"P_tot", "dimensionless", "Ca_SR_release", ALGEBRAIC}, - {"b_up", "dimensionless", "Ca_intracellular_fluxes", COMPUTED_CONSTANT}, - {"P_up", "millimolar_per_second", "Ca_intracellular_fluxes", COMPUTED_CONSTANT}, - {"P_up_basal", "millimolar_per_second", "Ca_intracellular_fluxes", CONSTANT}, - {"j_Ca_dif", "millimolar_per_second", "Ca_intracellular_fluxes", ALGEBRAIC}, - {"tau_dif_Ca", "second", "Ca_intracellular_fluxes", CONSTANT}, - {"j_up", "millimolar_per_second", "Ca_intracellular_fluxes", ALGEBRAIC}, - {"K_up", "millimolar", "Ca_intracellular_fluxes", CONSTANT}, - {"slope_up", "millimolar", "Ca_intracellular_fluxes", CONSTANT}, - {"j_tr", "millimolar_per_second", "Ca_intracellular_fluxes", ALGEBRAIC}, - {"tau_tr", "second", "Ca_intracellular_fluxes", CONSTANT}, - {"delta_fTC", "per_second", "Ca_buffering", ALGEBRAIC}, - {"kf_TC", "per_millimolar_second", "Ca_buffering", CONSTANT}, - {"kb_TC", "per_second", "Ca_buffering", CONSTANT}, - {"delta_fTMC", "per_second", "Ca_buffering", ALGEBRAIC}, - {"kf_TMC", "per_millimolar_second", "Ca_buffering", CONSTANT}, - {"kb_TMC", "per_second", "Ca_buffering", CONSTANT}, - {"delta_fTMM", "per_second", "Ca_buffering", ALGEBRAIC}, - {"kf_TMM", "per_millimolar_second", "Ca_buffering", CONSTANT}, - {"Mgi", "millimolar", "Ca_buffering", CONSTANT}, - {"kb_TMM", "per_second", "Ca_buffering", CONSTANT}, - {"delta_fCMi", "per_second", "Ca_buffering", ALGEBRAIC}, - {"kf_CM", "per_millimolar_second", "Ca_buffering", CONSTANT}, - {"kb_CM", "per_second", "Ca_buffering", CONSTANT}, - {"delta_fCMs", "per_second", "Ca_buffering", ALGEBRAIC}, - {"delta_fCQ", "per_second", "Ca_buffering", ALGEBRAIC}, - {"kf_CQ", "per_millimolar_second", "Ca_buffering", CONSTANT}, - {"kb_CQ", "per_second", "Ca_buffering", CONSTANT}, - {"TC_tot", "millimolar", "Ca_buffering", CONSTANT}, - {"TMC_tot", "millimolar", "Ca_buffering", CONSTANT}, - {"CM_tot", "millimolar", "Ca_buffering", CONSTANT}, - {"CQ_tot", "millimolar", "Ca_buffering", CONSTANT}, - {"V_nsr", "millimetre3", "Cell_parameters", COMPUTED_CONSTANT}, - {"V_jsr", "millimetre3", "Cell_parameters", COMPUTED_CONSTANT}, - {"i_siCa", "nanoA", "i_CaL", ALGEBRAIC}, - {"i_CaT", "nanoA", "i_CaT", ALGEBRAIC}, - {"V_cell", "millimetre3", "Cell_parameters", COMPUTED_CONSTANT}, - {"L_cell", "micrometre", "Cell_parameters", CONSTANT}, - {"R_cell", "micrometre", "Cell_parameters", CONSTANT}, - {"L_sub", "micrometre", "Cell_parameters", CONSTANT}, - {"V_jsr_part", "dimensionless", "Cell_parameters", CONSTANT}, - {"V_i_part", "dimensionless", "Cell_parameters", CONSTANT}, - {"V_nsr_part", "dimensionless", "Cell_parameters", CONSTANT}, - {"i_tot", "nanoA", "Membrane", ALGEBRAIC}, - {"i_f", "nanoA", "i_f", ALGEBRAIC}, - {"i_Kur", "nanoA", "i_Kur", ALGEBRAIC}, - {"i_KACh", "nanoA", "i_KACh", ALGEBRAIC}, - {"i_CaL", "nanoA", "i_CaL", ALGEBRAIC}, - {"i_to", "nanoA", "i_to", ALGEBRAIC}, - {"i_Ks", "nanoA", "i_Ks", ALGEBRAIC}, - {"i_Kr", "nanoA", "i_Kr", ALGEBRAIC}, - {"C", "microF", "Membrane", CONSTANT}, - {"R", "joule_per_kilomole_kelvin", "Membrane", CONSTANT}, - {"T", "kelvin", "Membrane", CONSTANT}, - {"V_clamp", "millivolt", "Voltage_clamp", ALGEBRAIC}, - {"clamp_mode", "dimensionless", "Membrane", CONSTANT}, - {"V_test", "millivolt", "Voltage_clamp", CONSTANT}, - {"t_holding", "second", "Voltage_clamp", CONSTANT}, - {"t_test", "second", "Voltage_clamp", CONSTANT}, - {"V_holding", "millivolt", "Voltage_clamp", CONSTANT}, - {"G_f", "microS", "i_f", COMPUTED_CONSTANT}, - {"g_f", "microS", "i_f", CONSTANT}, - {"Km_f", "millimolar", "i_f", CONSTANT}, - {"G_f_K", "microS", "i_f", COMPUTED_CONSTANT}, - {"alpha", "dimensionless", "i_f", CONSTANT}, - {"G_f_Na", "microS", "i_f", COMPUTED_CONSTANT}, - {"g_f_Na", "microS", "i_f", COMPUTED_CONSTANT}, - {"g_f_K", "microS", "i_f", COMPUTED_CONSTANT}, - {"blockade", "dimensionless", "i_f", CONSTANT}, - {"i_fK", "nanoA", "i_f", ALGEBRAIC}, - {"ACh_shift", "millivolt", "i_f_y_gate", COMPUTED_CONSTANT}, - {"Iso_shift", "millivolt", "i_f_y_gate", COMPUTED_CONSTANT}, - {"tau_y", "second", "i_f_y_gate", ALGEBRAIC}, - {"y_infinity", "dimensionless", "i_f_y_gate", ALGEBRAIC}, - {"y_shift", "millivolt", "i_f_y_gate", CONSTANT}, - {"E_mh", "millivolt", "i_Na", ALGEBRAIC}, - {"i_Na_", "nanoA", "i_Na", ALGEBRAIC}, - {"g_Na", "microS", "i_Na", CONSTANT}, - {"i_Na_L", "nanoA", "i_Na", ALGEBRAIC}, - {"g_Na_L", "microS", "i_Na", CONSTANT}, - {"m_infinity", "dimensionless", "i_Na_m_gate", ALGEBRAIC}, - {"E0_m", "millivolt", "i_Na_m_gate", ALGEBRAIC}, - {"alpha_m", "per_second", "i_Na_m_gate", ALGEBRAIC}, - {"delta_m", "millivolt", "i_Na_m_gate", CONSTANT}, - {"beta_m", "per_second", "i_Na_m_gate", ALGEBRAIC}, - {"tau_m", "second", "i_Na_m_gate", ALGEBRAIC}, - {"h_infinity", "dimensionless", "i_Na_h_gate", ALGEBRAIC}, - {"alpha_h", "per_second", "i_Na_h_gate", ALGEBRAIC}, - {"beta_h", "per_second", "i_Na_h_gate", ALGEBRAIC}, - {"tau_h", "second", "i_Na_h_gate", ALGEBRAIC}, - {"g_Kur", "microS", "i_Kur", CONSTANT}, - {"r_Kur_infinity", "dimensionless", "i_Kur_rKur_gate", ALGEBRAIC}, - {"tau_r_Kur", "second", "i_Kur_rKur_gate", ALGEBRAIC}, - {"s_Kur_infinity", "dimensionless", "i_Kur_sKur_gate", ALGEBRAIC}, - {"tau_s_Kur", "second", "i_Kur_sKur_gate", ALGEBRAIC}, - {"Iso_increase", "dimensionless", "i_CaL", COMPUTED_CONSTANT}, - {"P_CaL", "nanoA_per_millimolar", "i_CaL", CONSTANT}, - {"i_siK", "nanoA", "i_CaL", ALGEBRAIC}, - {"ACh_block", "dimensionless", "i_CaL", COMPUTED_CONSTANT}, - {"Iso_shift_dL", "millivolt", "i_CaL_dL_gate", COMPUTED_CONSTANT}, - {"Iso_slope_dL", "dimensionless", "i_CaL_dL_gate", COMPUTED_CONSTANT}, - {"dL_infinity", "dimensionless", "i_CaL_dL_gate", ALGEBRAIC}, - {"V_dL", "millivolt", "i_CaL_dL_gate", CONSTANT}, - {"k_dL", "millivolt", "i_CaL_dL_gate", CONSTANT}, - {"tau_dL", "second", "i_CaL_dL_gate", ALGEBRAIC}, - {"alpha_dL", "per_second", "i_CaL_dL_gate", ALGEBRAIC}, - {"beta_dL", "per_second", "i_CaL_dL_gate", ALGEBRAIC}, - {"adVm", "millivolt", "i_CaL_dL_gate", ALGEBRAIC}, - {"bdVm", "millivolt", "i_CaL_dL_gate", ALGEBRAIC}, - {"fL_infinity", "dimensionless", "i_CaL_fL_gate", ALGEBRAIC}, - {"shift_fL", "millivolt", "i_CaL_fL_gate", CONSTANT}, - {"k_fL", "millivolt", "i_CaL_fL_gate", CONSTANT}, - {"tau_fL", "second", "i_CaL_fL_gate", ALGEBRAIC}, - {"fCa_infinity", "dimensionless", "i_CaL_fCa_gate", ALGEBRAIC}, - {"Km_fCa", "millimolar", "i_CaL_fCa_gate", CONSTANT}, - {"tau_fCa", "second", "i_CaL_fCa_gate", ALGEBRAIC}, - {"alpha_fCa", "per_second", "i_CaL_fCa_gate", CONSTANT}, - {"P_CaT", "nanoA_per_millimolar", "i_CaT", CONSTANT}, - {"dT_infinity", "dimensionless", "i_CaT_dT_gate", ALGEBRAIC}, - {"tau_dT", "second", "i_CaT_dT_gate", ALGEBRAIC}, - {"fT_infinity", "dimensionless", "i_CaT_fT_gate", ALGEBRAIC}, - {"tau_fT", "second", "i_CaT_fT_gate", ALGEBRAIC}, - {"offset_fT", "second", "i_CaT_fT_gate", CONSTANT}, - {"g_to", "microS", "i_to", CONSTANT}, - {"q_infinity", "dimensionless", "i_to_q_gate", ALGEBRAIC}, - {"tau_q", "second", "i_to_q_gate", ALGEBRAIC}, - {"r_infinity", "dimensionless", "i_to_r_gate", ALGEBRAIC}, - {"tau_r", "second", "i_to_r_gate", ALGEBRAIC}, - {"g_Kr", "microS", "i_Kr", CONSTANT}, - {"alfapaF", "per_second", "i_Kr_pa_gate", ALGEBRAIC}, - {"betapaF", "per_second", "i_Kr_pa_gate", ALGEBRAIC}, - {"pa_infinity", "dimensionless", "i_Kr_pa_gate", ALGEBRAIC}, - {"tau_paS", "second", "i_Kr_pa_gate", ALGEBRAIC}, - {"tau_paF", "second", "i_Kr_pa_gate", ALGEBRAIC}, - {"tau_pi", "second", "i_Kr_pi_gate", ALGEBRAIC}, - {"pi_infinity", "dimensionless", "i_Kr_pi_gate", ALGEBRAIC}, - {"g_Ks", "microS", "i_Ks", COMPUTED_CONSTANT}, - {"g_Ks_", "microS", "i_Ks", CONSTANT}, - {"E_Ks", "millivolt", "i_Ks", ALGEBRAIC}, - {"Iso_shift", "millivolt", "i_Ks_n_gate", COMPUTED_CONSTANT}, - {"n_infinity", "dimensionless", "i_Ks_n_gate", ALGEBRAIC}, - {"tau_n", "second", "i_Ks_n_gate", ALGEBRAIC}, - {"alpha_n", "per_second", "i_Ks_n_gate", ALGEBRAIC}, - {"beta_n", "per_second", "i_Ks_n_gate", ALGEBRAIC}, - {"ACh_on", "dimensionless", "i_KACh", CONSTANT}, - {"g_KACh", "microS", "i_KACh", CONSTANT}, - {"alpha_a", "per_second", "i_KACh_a_gate", COMPUTED_CONSTANT}, - {"beta_a", "per_second", "i_KACh_a_gate", ALGEBRAIC}, - {"a_infinity", "dimensionless", "i_KACh_a_gate", ALGEBRAIC}, - {"tau_a", "second", "i_KACh_a_gate", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { + {"ACh", "millimolar", "Rate_modulation_experiments"}, + {"Iso_1_uM", "dimensionless", "Rate_modulation_experiments"}, + {"Nao", "millimolar", "Ionic_values"}, + {"Ko", "millimolar", "Ionic_values"}, + {"Ki", "millimolar", "Ionic_values"}, + {"Cao", "millimolar", "Ionic_values"}, + {"Nai_clamp", "dimensionless", "Nai_concentration"}, + {"F", "coulomb_per_mole", "Membrane"}, + {"Km_Nap", "millimolar", "i_NaK"}, + {"Km_Kp", "millimolar", "i_NaK"}, + {"i_NaK_max", "nanoA", "i_NaK"}, + {"blockade_NaCa", "dimensionless", "i_NaCa"}, + {"K_NaCa", "nanoA", "i_NaCa"}, + {"K3ni", "millimolar", "i_NaCa"}, + {"Kci", "millimolar", "i_NaCa"}, + {"Qci", "dimensionless", "i_NaCa"}, + {"K1ni", "millimolar", "i_NaCa"}, + {"K2ni", "millimolar", "i_NaCa"}, + {"Qn", "dimensionless", "i_NaCa"}, + {"Kcni", "millimolar", "i_NaCa"}, + {"K3no", "millimolar", "i_NaCa"}, + {"Kco", "millimolar", "i_NaCa"}, + {"Qco", "dimensionless", "i_NaCa"}, + {"K1no", "millimolar", "i_NaCa"}, + {"K2no", "millimolar", "i_NaCa"}, + {"ks", "per_second", "Ca_SR_release"}, + {"MaxSR", "dimensionless", "Ca_SR_release"}, + {"MinSR", "dimensionless", "Ca_SR_release"}, + {"EC50_SR", "millimolar", "Ca_SR_release"}, + {"HSR", "dimensionless", "Ca_SR_release"}, + {"koCa", "per_millimolar2_second", "Ca_SR_release"}, + {"kiCa", "per_millimolar_second", "Ca_SR_release"}, + {"kim", "per_second", "Ca_SR_release"}, + {"kom", "per_second", "Ca_SR_release"}, + {"P_up_basal", "millimolar_per_second", "Ca_intracellular_fluxes"}, + {"tau_dif_Ca", "second", "Ca_intracellular_fluxes"}, + {"K_up", "millimolar", "Ca_intracellular_fluxes"}, + {"slope_up", "millimolar", "Ca_intracellular_fluxes"}, + {"tau_tr", "second", "Ca_intracellular_fluxes"}, + {"kf_TC", "per_millimolar_second", "Ca_buffering"}, + {"kb_TC", "per_second", "Ca_buffering"}, + {"kf_TMC", "per_millimolar_second", "Ca_buffering"}, + {"kb_TMC", "per_second", "Ca_buffering"}, + {"kf_TMM", "per_millimolar_second", "Ca_buffering"}, + {"Mgi", "millimolar", "Ca_buffering"}, + {"kb_TMM", "per_second", "Ca_buffering"}, + {"kf_CM", "per_millimolar_second", "Ca_buffering"}, + {"kb_CM", "per_second", "Ca_buffering"}, + {"kf_CQ", "per_millimolar_second", "Ca_buffering"}, + {"kb_CQ", "per_second", "Ca_buffering"}, + {"TC_tot", "millimolar", "Ca_buffering"}, + {"TMC_tot", "millimolar", "Ca_buffering"}, + {"CM_tot", "millimolar", "Ca_buffering"}, + {"CQ_tot", "millimolar", "Ca_buffering"}, + {"L_cell", "micrometre", "Cell_parameters"}, + {"R_cell", "micrometre", "Cell_parameters"}, + {"L_sub", "micrometre", "Cell_parameters"}, + {"V_jsr_part", "dimensionless", "Cell_parameters"}, + {"V_i_part", "dimensionless", "Cell_parameters"}, + {"V_nsr_part", "dimensionless", "Cell_parameters"}, + {"C", "microF", "Membrane"}, + {"R", "joule_per_kilomole_kelvin", "Membrane"}, + {"T", "kelvin", "Membrane"}, + {"clamp_mode", "dimensionless", "Membrane"}, + {"V_test", "millivolt", "Voltage_clamp"}, + {"t_holding", "second", "Voltage_clamp"}, + {"t_test", "second", "Voltage_clamp"}, + {"V_holding", "millivolt", "Voltage_clamp"}, + {"g_f", "microS", "i_f"}, + {"Km_f", "millimolar", "i_f"}, + {"alpha", "dimensionless", "i_f"}, + {"blockade", "dimensionless", "i_f"}, + {"y_shift", "millivolt", "i_f_y_gate"}, + {"g_Na", "microS", "i_Na"}, + {"g_Na_L", "microS", "i_Na"}, + {"delta_m", "millivolt", "i_Na_m_gate"}, + {"g_Kur", "microS", "i_Kur"}, + {"P_CaL", "nanoA_per_millimolar", "i_CaL"}, + {"V_dL", "millivolt", "i_CaL_dL_gate"}, + {"k_dL", "millivolt", "i_CaL_dL_gate"}, + {"shift_fL", "millivolt", "i_CaL_fL_gate"}, + {"k_fL", "millivolt", "i_CaL_fL_gate"}, + {"Km_fCa", "millimolar", "i_CaL_fCa_gate"}, + {"alpha_fCa", "per_second", "i_CaL_fCa_gate"}, + {"P_CaT", "nanoA_per_millimolar", "i_CaT"}, + {"offset_fT", "second", "i_CaT_fT_gate"}, + {"g_to", "microS", "i_to"}, + {"g_Kr", "microS", "i_Kr"}, + {"g_Ks_", "microS", "i_Ks"}, + {"ACh_on", "dimensionless", "i_KACh"}, + {"g_KACh", "microS", "i_KACh"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"RTONF", "millivolt", "Membrane"}, + {"E_K", "millivolt", "Ionic_values"}, + {"V_i", "millimetre3", "Cell_parameters"}, + {"V_sub", "millimetre3", "Cell_parameters"}, + {"Iso_increase", "dimensionless", "i_NaK"}, + {"k34", "dimensionless", "i_NaCa"}, + {"b_up", "dimensionless", "Ca_intracellular_fluxes"}, + {"P_up", "millimolar_per_second", "Ca_intracellular_fluxes"}, + {"V_nsr", "millimetre3", "Cell_parameters"}, + {"V_jsr", "millimetre3", "Cell_parameters"}, + {"V_cell", "millimetre3", "Cell_parameters"}, + {"G_f", "microS", "i_f"}, + {"G_f_K", "microS", "i_f"}, + {"G_f_Na", "microS", "i_f"}, + {"g_f_Na", "microS", "i_f"}, + {"g_f_K", "microS", "i_f"}, + {"ACh_shift", "millivolt", "i_f_y_gate"}, + {"Iso_shift", "millivolt", "i_f_y_gate"}, + {"Iso_increase", "dimensionless", "i_CaL"}, + {"ACh_block", "dimensionless", "i_CaL"}, + {"Iso_shift_dL", "millivolt", "i_CaL_dL_gate"}, + {"Iso_slope_dL", "dimensionless", "i_CaL_dL_gate"}, + {"g_Ks", "microS", "i_Ks"}, + {"Iso_shift", "millivolt", "i_Ks_n_gate"}, + {"alpha_a", "per_second", "i_KACh_a_gate"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"E_Na", "millivolt", "Ionic_values"}, + {"Nai", "millimolar", "Nai_concentration"}, + {"E_Ca", "millivolt", "Ionic_values"}, + {"i_Na", "nanoA", "i_Na"}, + {"i_NaCa", "nanoA", "i_NaCa"}, + {"i_NaK", "nanoA", "i_NaK"}, + {"i_siNa", "nanoA", "i_CaL"}, + {"i_fNa", "nanoA", "i_f"}, + {"V", "millivolt", "Membrane"}, + {"x2", "dimensionless", "i_NaCa"}, + {"k21", "dimensionless", "i_NaCa"}, + {"x1", "dimensionless", "i_NaCa"}, + {"k12", "dimensionless", "i_NaCa"}, + {"x4", "dimensionless", "i_NaCa"}, + {"x3", "dimensionless", "i_NaCa"}, + {"k41", "dimensionless", "i_NaCa"}, + {"k23", "dimensionless", "i_NaCa"}, + {"k43", "dimensionless", "i_NaCa"}, + {"k32", "dimensionless", "i_NaCa"}, + {"k14", "dimensionless", "i_NaCa"}, + {"di", "dimensionless", "i_NaCa"}, + {"do", "dimensionless", "i_NaCa"}, + {"j_SRCarel", "millimolar_per_second", "Ca_SR_release"}, + {"diff", "millimolar", "Ca_SR_release"}, + {"kCaSR", "dimensionless", "Ca_SR_release"}, + {"koSRCa", "per_millimolar2_second", "Ca_SR_release"}, + {"kiSRCa", "per_millimolar_second", "Ca_SR_release"}, + {"P_tot", "dimensionless", "Ca_SR_release"}, + {"j_Ca_dif", "millimolar_per_second", "Ca_intracellular_fluxes"}, + {"j_up", "millimolar_per_second", "Ca_intracellular_fluxes"}, + {"j_tr", "millimolar_per_second", "Ca_intracellular_fluxes"}, + {"delta_fTC", "per_second", "Ca_buffering"}, + {"delta_fTMC", "per_second", "Ca_buffering"}, + {"delta_fTMM", "per_second", "Ca_buffering"}, + {"delta_fCMi", "per_second", "Ca_buffering"}, + {"delta_fCMs", "per_second", "Ca_buffering"}, + {"delta_fCQ", "per_second", "Ca_buffering"}, + {"i_siCa", "nanoA", "i_CaL"}, + {"i_CaT", "nanoA", "i_CaT"}, + {"i_tot", "nanoA", "Membrane"}, + {"i_f", "nanoA", "i_f"}, + {"i_Kur", "nanoA", "i_Kur"}, + {"i_KACh", "nanoA", "i_KACh"}, + {"i_CaL", "nanoA", "i_CaL"}, + {"i_to", "nanoA", "i_to"}, + {"i_Ks", "nanoA", "i_Ks"}, + {"i_Kr", "nanoA", "i_Kr"}, + {"V_clamp", "millivolt", "Voltage_clamp"}, + {"i_fK", "nanoA", "i_f"}, + {"tau_y", "second", "i_f_y_gate"}, + {"y_infinity", "dimensionless", "i_f_y_gate"}, + {"E_mh", "millivolt", "i_Na"}, + {"i_Na_", "nanoA", "i_Na"}, + {"i_Na_L", "nanoA", "i_Na"}, + {"m_infinity", "dimensionless", "i_Na_m_gate"}, + {"E0_m", "millivolt", "i_Na_m_gate"}, + {"alpha_m", "per_second", "i_Na_m_gate"}, + {"beta_m", "per_second", "i_Na_m_gate"}, + {"tau_m", "second", "i_Na_m_gate"}, + {"h_infinity", "dimensionless", "i_Na_h_gate"}, + {"alpha_h", "per_second", "i_Na_h_gate"}, + {"beta_h", "per_second", "i_Na_h_gate"}, + {"tau_h", "second", "i_Na_h_gate"}, + {"r_Kur_infinity", "dimensionless", "i_Kur_rKur_gate"}, + {"tau_r_Kur", "second", "i_Kur_rKur_gate"}, + {"s_Kur_infinity", "dimensionless", "i_Kur_sKur_gate"}, + {"tau_s_Kur", "second", "i_Kur_sKur_gate"}, + {"i_siK", "nanoA", "i_CaL"}, + {"dL_infinity", "dimensionless", "i_CaL_dL_gate"}, + {"tau_dL", "second", "i_CaL_dL_gate"}, + {"alpha_dL", "per_second", "i_CaL_dL_gate"}, + {"beta_dL", "per_second", "i_CaL_dL_gate"}, + {"adVm", "millivolt", "i_CaL_dL_gate"}, + {"bdVm", "millivolt", "i_CaL_dL_gate"}, + {"fL_infinity", "dimensionless", "i_CaL_fL_gate"}, + {"tau_fL", "second", "i_CaL_fL_gate"}, + {"fCa_infinity", "dimensionless", "i_CaL_fCa_gate"}, + {"tau_fCa", "second", "i_CaL_fCa_gate"}, + {"dT_infinity", "dimensionless", "i_CaT_dT_gate"}, + {"tau_dT", "second", "i_CaT_dT_gate"}, + {"fT_infinity", "dimensionless", "i_CaT_fT_gate"}, + {"tau_fT", "second", "i_CaT_fT_gate"}, + {"q_infinity", "dimensionless", "i_to_q_gate"}, + {"tau_q", "second", "i_to_q_gate"}, + {"r_infinity", "dimensionless", "i_to_r_gate"}, + {"tau_r", "second", "i_to_r_gate"}, + {"alfapaF", "per_second", "i_Kr_pa_gate"}, + {"betapaF", "per_second", "i_Kr_pa_gate"}, + {"pa_infinity", "dimensionless", "i_Kr_pa_gate"}, + {"tau_paS", "second", "i_Kr_pa_gate"}, + {"tau_paF", "second", "i_Kr_pa_gate"}, + {"tau_pi", "second", "i_Kr_pi_gate"}, + {"pi_infinity", "dimensionless", "i_Kr_pi_gate"}, + {"E_Ks", "millivolt", "i_Ks"}, + {"n_infinity", "dimensionless", "i_Ks_n_gate"}, + {"tau_n", "second", "i_Ks_n_gate"}, + {"alpha_n", "per_second", "i_Ks_n_gate"}, + {"beta_n", "per_second", "i_Ks_n_gate"}, + {"beta_a", "per_second", "i_KACh_a_gate"}, + {"a_infinity", "dimensionless", "i_KACh_a_gate"}, + {"tau_a", "second", "i_KACh_a_gate"} }; double * createStatesArray() @@ -280,11 +288,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -296,99 +326,8 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 0.0; - variables[1] = 0.0; - variables[4] = 140.0; - variables[7] = 5.4; - variables[8] = 140.0; - variables[10] = 1.8; - variables[11] = 1.0; - variables[17] = 96485.3415; - variables[22] = 14.0; - variables[23] = 1.4; - variables[24] = 0.08105; - variables[25] = 0.0; - variables[30] = 3.343; - variables[39] = 26.44; - variables[40] = 0.0207; - variables[41] = 0.1369; - variables[43] = 395.3; - variables[44] = 2.289; - variables[45] = 0.4315; - variables[46] = 26.44; - variables[47] = 4.663; - variables[48] = 3.663; - variables[49] = 0.0; - variables[51] = 1628.0; - variables[52] = 561.4; - variables[54] = 148041085.1; - variables[57] = 15.0; - variables[58] = 1.0; - variables[59] = 0.45; - variables[60] = 2.5; - variables[62] = 10000.0; - variables[64] = 500.0; - variables[65] = 5.0; - variables[66] = 660.0; - variables[70] = 5.0; - variables[72] = 5.469e-5; - variables[74] = 0.000286113; - variables[75] = 5.0e-5; - variables[77] = 0.04; - variables[79] = 88800.0; - variables[80] = 446.0; - variables[82] = 227700.0; - variables[83] = 7.51; - variables[85] = 2277.0; - variables[86] = 2.5; - variables[87] = 751.0; - variables[89] = 1.642e6; - variables[90] = 542.0; - variables[93] = 175.4; - variables[94] = 445.0; - variables[95] = 0.031; - variables[96] = 0.062; - variables[97] = 0.045; - variables[98] = 10.0; - variables[104] = 67.0; - variables[105] = 3.9; - variables[106] = 0.02; - variables[107] = 0.0012; - variables[108] = 0.46; - variables[109] = 0.0116; - variables[118] = 5.7e-5; - variables[119] = 8314.472; - variables[120] = 310.0; - variables[122] = 0.0; - variables[123] = -35.0; - variables[124] = 0.5; - variables[125] = 0.5; - variables[126] = -45.0; - variables[128] = 0.00427; - variables[129] = 45.0; - variables[131] = 0.5927; - variables[135] = 0.0; - variables[141] = 0.0; - variables[144] = 0.0223; - variables[146] = 0.0; - variables[150] = 1.0e-5; - variables[157] = 0.1539e-3; - variables[163] = 0.4578; - variables[169] = -16.4508; - variables[170] = 4.3371; - variables[177] = 0.0; - variables[178] = 0.0; - variables[181] = 0.000338; - variables[183] = 0.0075; - variables[184] = 0.04132; - variables[189] = 0.0; - variables[190] = 3.5e-3; - variables[195] = 0.00424; - variables[204] = 0.00065; - variables[211] = 1.0; - variables[212] = 0.00345; states[0] = 6.226104e-5; states[1] = 5.0; states[2] = 0.409551; @@ -422,270 +361,361 @@ void initialiseVariables(double *states, double *rates, double *variables) states[30] = 0.283185; states[31] = 0.1162; states[32] = 0.00277; + constants[0] = 0.0; + constants[1] = 0.0; + constants[2] = 140.0; + constants[3] = 5.4; + constants[4] = 140.0; + constants[5] = 1.8; + constants[6] = 1.0; + constants[7] = 96485.3415; + constants[8] = 14.0; + constants[9] = 1.4; + constants[10] = 0.08105; + constants[11] = 0.0; + constants[12] = 3.343; + constants[13] = 26.44; + constants[14] = 0.0207; + constants[15] = 0.1369; + constants[16] = 395.3; + constants[17] = 2.289; + constants[18] = 0.4315; + constants[19] = 26.44; + constants[20] = 4.663; + constants[21] = 3.663; + constants[22] = 0.0; + constants[23] = 1628.0; + constants[24] = 561.4; + constants[25] = 148041085.1; + constants[26] = 15.0; + constants[27] = 1.0; + constants[28] = 0.45; + constants[29] = 2.5; + constants[30] = 10000.0; + constants[31] = 500.0; + constants[32] = 5.0; + constants[33] = 660.0; + constants[34] = 5.0; + constants[35] = 5.469e-5; + constants[36] = 0.000286113; + constants[37] = 5.0e-5; + constants[38] = 0.04; + constants[39] = 88800.0; + constants[40] = 446.0; + constants[41] = 227700.0; + constants[42] = 7.51; + constants[43] = 2277.0; + constants[44] = 2.5; + constants[45] = 751.0; + constants[46] = 1.642e6; + constants[47] = 542.0; + constants[48] = 175.4; + constants[49] = 445.0; + constants[50] = 0.031; + constants[51] = 0.062; + constants[52] = 0.045; + constants[53] = 10.0; + constants[54] = 67.0; + constants[55] = 3.9; + constants[56] = 0.02; + constants[57] = 0.0012; + constants[58] = 0.46; + constants[59] = 0.0116; + constants[60] = 5.7e-5; + constants[61] = 8314.472; + constants[62] = 310.0; + constants[63] = 0.0; + constants[64] = -35.0; + constants[65] = 0.5; + constants[66] = 0.5; + constants[67] = -45.0; + constants[68] = 0.00427; + constants[69] = 45.0; + constants[70] = 0.5927; + constants[71] = 0.0; + constants[72] = 0.0; + constants[73] = 0.0223; + constants[74] = 0.0; + constants[75] = 1.0e-5; + constants[76] = 0.1539e-3; + constants[77] = 0.4578; + constants[78] = -16.4508; + constants[79] = 4.3371; + constants[80] = 0.0; + constants[81] = 0.0; + constants[82] = 0.000338; + constants[83] = 0.0075; + constants[84] = 0.04132; + constants[85] = 0.0; + constants[86] = 3.5e-3; + constants[87] = 0.00424; + constants[88] = 0.00065; + constants[89] = 1.0; + constants[90] = 0.00345; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[3] = variables[119]*variables[120]/variables[17]; - variables[6] = variables[3]*log(variables[7]/variables[8]); - variables[20] = (variables[1] > 0.0)?1.2:1.0; - variables[35] = variables[4]/(variables[47]+variables[4]); - variables[68] = (variables[1] > 0.0)?-0.25:(variables[0] > 0.0)?0.7*variables[0]/(0.00009+variables[0]):0.0; - variables[69] = variables[70]*(1.0-variables[68]); - variables[103] = 0.000000001*3.14159265358979*pow(variables[105], 2.0)*variables[104]; - variables[19] = 0.000000001*2.0*3.14159265358979*variables[106]*(variables[105]-variables[106]/2.0)*variables[104]; - variables[100] = variables[107]*variables[103]; - variables[18] = variables[108]*variables[103]-variables[19]; - variables[99] = variables[109]*variables[103]; - variables[127] = variables[128]/(variables[7]/(variables[7]+variables[129])); - variables[130] = variables[127]/(variables[131]+1.0); - variables[132] = variables[131]*variables[130]; - variables[133] = variables[132]*variables[7]/(variables[7]+variables[129]); - variables[134] = variables[130]*variables[7]/(variables[7]+variables[129]); - variables[137] = (variables[0] > 0.0)?-1.0-9.898*pow(1.0*variables[0], 0.618)/(pow(1.0*variables[0], 0.618)+0.00122423):0.0; - variables[138] = (variables[1] > 0.0)?7.5:0.0; - variables[162] = (variables[1] > 0.0)?1.23:1.0; - variables[165] = 0.31*variables[0]/(variables[0]+0.00009); - variables[166] = (variables[1] > 0.0)?-8.0:0.0; - variables[167] = (variables[1] > 0.0)?-27.0:0.0; - variables[203] = (variables[1] > 0.0)?1.2*variables[204]:variables[204]; - variables[206] = (variables[1] > 0.0)?-14.0:0.0; - variables[213] = (3.5988-0.025641)/(1.0+0.0000012155/pow(1.0*variables[0], 1.6951))+0.025641; + computedConstants[0] = constants[61]*constants[62]/constants[7]; + computedConstants[1] = computedConstants[0]*log(constants[3]/constants[4]); + computedConstants[4] = (constants[1] > 0.0)?1.2:1.0; + computedConstants[5] = constants[2]/(constants[20]+constants[2]); + computedConstants[6] = (constants[1] > 0.0)?-0.25:(constants[0] > 0.0)?0.7*constants[0]/(0.00009+constants[0]):0.0; + computedConstants[7] = constants[34]*(1.0-computedConstants[6]); + computedConstants[10] = 0.000000001*3.14159265358979*pow(constants[55], 2.0)*constants[54]; + computedConstants[3] = 0.000000001*2.0*3.14159265358979*constants[56]*(constants[55]-constants[56]/2.0)*constants[54]; + computedConstants[9] = constants[57]*computedConstants[10]; + computedConstants[2] = constants[58]*computedConstants[10]-computedConstants[3]; + computedConstants[8] = constants[59]*computedConstants[10]; + computedConstants[11] = constants[68]/(constants[3]/(constants[3]+constants[69])); + computedConstants[12] = computedConstants[11]/(constants[70]+1.0); + computedConstants[13] = constants[70]*computedConstants[12]; + computedConstants[14] = computedConstants[13]*constants[3]/(constants[3]+constants[69]); + computedConstants[15] = computedConstants[12]*constants[3]/(constants[3]+constants[69]); + computedConstants[16] = (constants[0] > 0.0)?-1.0-9.898*pow(1.0*constants[0], 0.618)/(pow(1.0*constants[0], 0.618)+0.00122423):0.0; + computedConstants[17] = (constants[1] > 0.0)?7.5:0.0; + computedConstants[18] = (constants[1] > 0.0)?1.23:1.0; + computedConstants[19] = 0.31*constants[0]/(constants[0]+0.00009); + computedConstants[20] = (constants[1] > 0.0)?-8.0:0.0; + computedConstants[21] = (constants[1] > 0.0)?-27.0:0.0; + computedConstants[22] = (constants[1] > 0.0)?1.2*constants[88]:constants[88]; + computedConstants[23] = (constants[1] > 0.0)?-14.0:0.0; + computedConstants[24] = (3.5988-0.025641)/(1.0+0.0000012155/pow(1.0*constants[0], 1.6951))+0.025641; } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[5] = states[1]; - variables[142] = variables[3]*log((variables[4]+0.12*variables[7])/(variables[5]+0.12*variables[8])); - variables[121] = ((voi > variables[124]) && (voi < variables[124]+variables[125]))?variables[123]:variables[126]; - variables[21] = (variables[122] >= 1.0)?variables[121]:states[15]; - variables[143] = variables[144]*pow(states[18], 3.0)*states[17]*(variables[21]-variables[142]); - variables[145] = variables[146]*pow(states[18], 3.0)*(variables[21]-variables[142]); - variables[12] = variables[143]+variables[145]; - variables[15] = 0.0000185*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)/variables[3])))*(variables[5]-variables[4]*exp(-1.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21]; - variables[2] = variables[3]*log(variables[4]/variables[5]); - variables[16] = states[16]*variables[133]*(variables[21]-variables[2])*(1.0-variables[135]); - variables[14] = variables[20]*variables[24]*pow(1.0+pow(variables[23]/variables[7], 1.2), -1.0)*pow(1.0+pow(variables[22]/variables[5], 1.3), -1.0)*pow(1.0+exp(-(variables[21]-variables[2]+110.0)/20.0), -1.0); - variables[50] = 1.0+variables[10]/variables[48]*(1.0+exp(variables[49]*variables[21]/variables[3]))+variables[4]/variables[51]*(1.0+variables[4]/variables[52]*(1.0+variables[4]/variables[47])); - variables[27] = variables[10]/variables[48]*exp(variables[49]*variables[21]/variables[3])/variables[50]; - variables[42] = 1.0+states[0]/variables[40]*(1.0+exp(-variables[41]*variables[21]/variables[3])+variables[5]/variables[46])+variables[5]/variables[43]*(1.0+variables[5]/variables[44]*(1.0+variables[5]/variables[39])); - variables[29] = states[0]/variables[40]*exp(-variables[41]*variables[21]/variables[3])/variables[42]; - variables[36] = variables[5]/(variables[39]+variables[5]); - variables[37] = exp(variables[45]*variables[21]/(2.0*variables[3])); - variables[33] = exp(-variables[45]*variables[21]/(2.0*variables[3])); - variables[38] = variables[5]/variables[43]*variables[5]/variables[44]*(1.0+variables[5]/variables[39])*exp(variables[45]*variables[21]/(2.0*variables[3]))/variables[42]; - variables[26] = variables[37]*variables[36]*(variables[38]+variables[29])+variables[33]*variables[29]*(variables[35]+variables[37]); - variables[34] = variables[4]/variables[51]*variables[4]/variables[52]*(1.0+variables[4]/variables[47])*exp(-variables[45]*variables[21]/(2.0*variables[3]))/variables[50]; - variables[28] = variables[33]*variables[35]*(variables[34]+variables[27])+variables[27]*variables[37]*(variables[36]+variables[33]); - variables[31] = variables[34]*variables[35]*(variables[38]+variables[29])+variables[38]*variables[27]*(variables[35]+variables[37]); - variables[32] = variables[38]*variables[36]*(variables[34]+variables[27])+variables[29]*variables[34]*(variables[36]+variables[33]); - variables[13] = (1.0-variables[25])*variables[30]*(variables[26]*variables[27]-variables[28]*variables[29])/(variables[28]+variables[26]+variables[32]+variables[31]); - rates[1] = (1.0-variables[11])*-1.0*(variables[12]+variables[16]+variables[15]+3.0*variables[14]+3.0*variables[13])/(1.0*(variables[18]+variables[19])*variables[17]); - variables[56] = variables[57]-(variables[57]-variables[58])/(1.0+pow(variables[59]/states[2], variables[60])); - variables[63] = variables[64]*variables[56]; - variables[61] = variables[62]/variables[56]; - rates[4] = variables[65]*states[5]-variables[63]*states[0]*states[4]-(variables[61]*pow(states[0], 2.0)*states[4]-variables[66]*states[3]); - rates[3] = variables[61]*pow(states[0], 2.0)*states[4]-variables[66]*states[3]-(variables[63]*states[0]*states[3]-variables[65]*states[6]); - rates[6] = variables[63]*states[0]*states[3]-variables[65]*states[6]-(variables[66]*states[6]-variables[61]*pow(states[0], 2.0)*states[5]); - rates[5] = variables[66]*states[6]-variables[61]*pow(states[0], 2.0)*states[5]-(variables[65]*states[5]-variables[63]*states[0]*states[4]); - variables[78] = variables[79]*states[7]*(1.0-states[9])-variables[80]*states[9]; - rates[9] = variables[78]; - variables[81] = variables[82]*states[7]*(1.0-(states[10]+states[11]))-variables[83]*states[10]; - rates[10] = variables[81]; - variables[84] = variables[85]*variables[86]*(1.0-(states[10]+states[11]))-variables[87]*states[11]; - rates[11] = variables[84]; - variables[88] = variables[89]*states[7]*(1.0-states[12])-variables[90]*states[12]; - rates[12] = variables[88]; - variables[91] = variables[89]*states[0]*(1.0-states[13])-variables[90]*states[13]; - rates[13] = variables[91]; - variables[92] = variables[93]*states[2]*(1.0-states[14])-variables[94]*states[14]; - rates[14] = variables[92]; - variables[71] = (states[0]-states[7])/variables[72]; - variables[73] = variables[69]/(1.0+exp((-states[7]+variables[74])/variables[75])); - rates[7] = 1.0*(variables[71]*variables[19]-variables[73]*variables[99])/variables[18]-(variables[97]*variables[88]+variables[95]*variables[78]+variables[96]*variables[81]); - variables[53] = variables[54]*states[3]*(states[2]-states[0]); - variables[101] = 2.0*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)*2.0/variables[3])))*(states[0]-variables[10]*exp(-2.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21]; - variables[102] = 2.0*variables[184]*variables[21]/(variables[3]*(1.0-exp(-1.0*variables[21]*2.0/variables[3])))*(states[0]-variables[10]*exp(-2.0*variables[21]/variables[3]))*states[25]*states[24]; - rates[0] = variables[53]*variables[100]/variables[19]-((variables[101]+variables[102]-2.0*variables[13])/(2.0*variables[17]*variables[19])+variables[71]+variables[97]*variables[91]); - variables[76] = (states[8]-states[2])/variables[77]; - rates[8] = variables[73]-variables[76]*variables[100]/variables[99]; - rates[2] = variables[76]-(variables[53]+variables[98]*variables[92]); - variables[136] = states[16]*variables[134]*(variables[21]-variables[6])*(1.0-variables[135]); - variables[111] = variables[16]+variables[136]; - variables[112] = variables[157]*states[20]*states[19]*(variables[21]-variables[6]); - variables[113] = (variables[0] > 0.0)?variables[211]*variables[212]*(variables[21]-variables[6])*(1.0+exp((variables[21]+20.0)/20.0))*states[32]:0.0; - variables[164] = 0.000365*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)/variables[3])))*(variables[8]-variables[7]*exp(-1.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21]; - variables[114] = (variables[101]+variables[164]+variables[15])*(1.0-variables[165])*1.0*variables[162]; - variables[115] = variables[190]*(variables[21]-variables[6])*states[27]*states[26]; - variables[205] = variables[3]*log((variables[7]+0.12*variables[4])/(variables[8]+0.12*variables[5])); - variables[116] = variables[203]*(variables[21]-variables[205])*pow(states[31], 2.0); - variables[117] = variables[195]*(variables[21]-variables[6])*(0.9*states[29]+0.1*states[30])*states[28]; - variables[110] = variables[111]+variables[117]+variables[116]+variables[115]+variables[14]+variables[13]+variables[12]+variables[114]+variables[102]+variables[113]+variables[112]; - rates[15] = -variables[110]/variables[118]; - variables[140] = (variables[21] < -(80.0-variables[137]-variables[138]-variables[141]))?0.01329+0.99921/(1.0+exp((variables[21]+97.134-variables[137]-variables[138]-variables[141])/8.1752)):0.0002501*exp(-(variables[21]-variables[137]-variables[138]-variables[141])/12.861); - variables[139] = 1.0/(0.36*(variables[21]+148.8-variables[137]-variables[138])/(exp(0.066*(variables[21]+148.8-variables[137]-variables[138]))-1.0)+0.1*(variables[21]+87.3-variables[137]-variables[138])/(1.0-exp(-0.2*(variables[21]+87.3-variables[137]-variables[138]))))-0.054; - rates[16] = (variables[140]-states[16])/variables[139]; - variables[147] = 1.0/(1.0+exp(-(variables[21]+42.0504)/8.3106)); - variables[148] = variables[21]+41.0; - variables[149] = (fabs(variables[148]) < variables[150])?2000.0:200.0*variables[148]/(1.0-exp(-0.1*variables[148])); - variables[151] = 8000.0*exp(-0.056*(variables[21]+66.0)); - variables[152] = 1.0/(variables[149]+variables[151]); - rates[18] = (variables[147]-states[18])/variables[152]; - variables[153] = 1.0/(1.0+exp((variables[21]+69.804)/4.4565)); - variables[154] = 20.0*exp(-0.125*(variables[21]+75.0)); - variables[155] = 2000.0/(320.0*exp(-0.1*(variables[21]+75.0))+1.0); - variables[156] = 1.0/(variables[154]+variables[155]); - rates[17] = (variables[153]-states[17])/variables[156]; - variables[158] = 1.0/(1.0+exp((variables[21]+6.0)/-8.6)); - variables[159] = 0.009/(1.0+exp((variables[21]+5.0)/12.0))+0.0005; - rates[20] = (variables[158]-states[20])/variables[159]; - variables[160] = 1.0/(1.0+exp((variables[21]+7.5)/10.0)); - variables[161] = 0.59/(1.0+exp((variables[21]+60.0)/10.0))+3.05; - rates[19] = (variables[160]-states[19])/variables[161]; - variables[168] = 1.0/(1.0+exp(-(variables[21]-variables[169]-variables[166])/(variables[170]*(1.0+variables[167]/100.0)))); - variables[174] = (variables[21] == -41.8)?-41.80001:(variables[21] == 0.0)?0.0:(variables[21] == -6.8)?-6.80001:variables[21]; - variables[172] = -0.02839*(variables[174]+41.8)/(exp(-(variables[174]+41.8)/2.5)-1.0)-0.0849*(variables[174]+6.8)/(exp(-(variables[174]+6.8)/4.8)-1.0); - variables[175] = (variables[21] == -1.8)?-1.80001:variables[21]; - variables[173] = 0.01143*(variables[175]+1.8)/(exp((variables[175]+1.8)/2.5)-1.0); - variables[171] = 0.001/(variables[172]+variables[173]); - rates[23] = (variables[168]-states[23])/variables[171]; - variables[176] = 1.0/(1.0+exp((variables[21]+37.4+variables[177])/(5.3+variables[178]))); - variables[179] = 0.001*(44.3+230.0*exp(-pow((variables[21]+36.0)/10.0, 2.0))); - rates[22] = (variables[176]-states[22])/variables[179]; - variables[180] = variables[181]/(variables[181]+states[0]); - variables[182] = 0.001*variables[180]/variables[183]; - rates[21] = (variables[180]-states[21])/variables[182]; - variables[185] = 1.0/(1.0+exp(-(variables[21]+38.3)/5.5)); - variables[186] = 0.001/(1.068*exp((variables[21]+38.3)/30.0)+1.068*exp(-(variables[21]+38.3)/30.0)); - rates[25] = (variables[185]-states[25])/variables[186]; - variables[187] = 1.0/(1.0+exp((variables[21]+58.7)/3.8)); - variables[188] = 1.0/(16.67*exp(-(variables[21]+75.0)/83.3)+16.67*exp((variables[21]+75.0)/15.38))+variables[189]; - rates[24] = (variables[187]-states[24])/variables[188]; - variables[191] = 1.0/(1.0+exp((variables[21]+49.0)/13.0)); - variables[192] = 0.001*0.6*(65.17/(0.57*exp(-0.08*(variables[21]+44.0))+0.065*exp(0.1*(variables[21]+45.93)))+10.1); - rates[27] = (variables[191]-states[27])/variables[192]; - variables[193] = 1.0/(1.0+exp(-(variables[21]-19.3)/15.0)); - variables[194] = 0.001*0.66*1.4*(15.59/(1.037*exp(0.09*(variables[21]+30.61))+0.369*exp(-0.12*(variables[21]+23.84)))+2.98); - rates[26] = (variables[193]-states[26])/variables[194]; - variables[198] = 1.0/(1.0+exp(-(variables[21]+10.0144)/7.6607)); - variables[199] = 0.84655354/(4.2*exp(variables[21]/17.0)+0.15*exp(-variables[21]/21.6)); - rates[30] = (variables[198]-states[30])/variables[199]; - variables[200] = 1.0/(30.0*exp(variables[21]/10.0)+exp(-variables[21]/12.0)); - rates[29] = (variables[198]-states[29])/variables[200]; - variables[202] = 1.0/(1.0+exp((variables[21]+28.6)/17.1)); - variables[201] = 1.0/(100.0*exp(-variables[21]/54.645)+656.0*exp(variables[21]/106.157)); - rates[28] = (variables[202]-states[28])/variables[201]; - variables[207] = sqrt(1.0/(1.0+exp(-(variables[21]+0.6383-variables[206])/10.7071))); - variables[209] = 28.0/(1.0+exp(-(variables[21]-40.0-variables[206])/3.0)); - variables[210] = 1.0*exp(-(variables[21]-variables[206]-5.0)/25.0); - variables[208] = 1.0/(variables[209]+variables[210]); - rates[31] = (variables[207]-states[31])/variables[208]; - variables[214] = 10.0*exp(0.0133*(variables[21]+40.0)); - variables[215] = variables[213]/(variables[213]+variables[214]); - variables[216] = 1.0/(variables[213]+variables[214]); - rates[32] = (variables[215]-states[32])/variables[216]; + algebraic[1] = states[1]; + algebraic[51] = computedConstants[0]*log((constants[2]+0.12*constants[3])/(algebraic[1]+0.12*constants[4])); + algebraic[47] = ((voi > constants[65]) && (voi < constants[65]+constants[66]))?constants[64]:constants[67]; + algebraic[8] = (constants[63] >= 1.0)?algebraic[47]:states[15]; + algebraic[52] = constants[73]*pow(states[18], 3.0)*states[17]*(algebraic[8]-algebraic[51]); + algebraic[53] = constants[74]*pow(states[18], 3.0)*(algebraic[8]-algebraic[51]); + algebraic[3] = algebraic[52]+algebraic[53]; + algebraic[6] = 0.0000185*constants[77]*(algebraic[8]-0.0)/(computedConstants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)/computedConstants[0])))*(algebraic[1]-constants[2]*exp(-1.0*(algebraic[8]-0.0)/computedConstants[0]))*states[23]*states[22]*states[21]; + algebraic[0] = computedConstants[0]*log(constants[2]/algebraic[1]); + algebraic[7] = states[16]*computedConstants[14]*(algebraic[8]-algebraic[0])*(1.0-constants[71]); + algebraic[5] = computedConstants[4]*constants[10]*pow(1.0+pow(constants[9]/constants[3], 1.2), -1.0)*pow(1.0+pow(constants[8]/algebraic[1], 1.3), -1.0)*pow(1.0+exp(-(algebraic[8]-algebraic[0]+110.0)/20.0), -1.0); + algebraic[21] = 1.0+constants[5]/constants[21]*(1.0+exp(constants[22]*algebraic[8]/computedConstants[0]))+constants[2]/constants[23]*(1.0+constants[2]/constants[24]*(1.0+constants[2]/constants[20])); + algebraic[10] = constants[5]/constants[21]*exp(constants[22]*algebraic[8]/computedConstants[0])/algebraic[21]; + algebraic[20] = 1.0+states[0]/constants[14]*(1.0+exp(-constants[15]*algebraic[8]/computedConstants[0])+algebraic[1]/constants[19])+algebraic[1]/constants[16]*(1.0+algebraic[1]/constants[17]*(1.0+algebraic[1]/constants[13])); + algebraic[12] = states[0]/constants[14]*exp(-constants[15]*algebraic[8]/computedConstants[0])/algebraic[20]; + algebraic[17] = algebraic[1]/(constants[13]+algebraic[1]); + algebraic[18] = exp(constants[18]*algebraic[8]/(2.0*computedConstants[0])); + algebraic[15] = exp(-constants[18]*algebraic[8]/(2.0*computedConstants[0])); + algebraic[19] = algebraic[1]/constants[16]*algebraic[1]/constants[17]*(1.0+algebraic[1]/constants[13])*exp(constants[18]*algebraic[8]/(2.0*computedConstants[0]))/algebraic[20]; + algebraic[9] = algebraic[18]*algebraic[17]*(algebraic[19]+algebraic[12])+algebraic[15]*algebraic[12]*(computedConstants[5]+algebraic[18]); + algebraic[16] = constants[2]/constants[23]*constants[2]/constants[24]*(1.0+constants[2]/constants[20])*exp(-constants[18]*algebraic[8]/(2.0*computedConstants[0]))/algebraic[21]; + algebraic[11] = algebraic[15]*computedConstants[5]*(algebraic[16]+algebraic[10])+algebraic[10]*algebraic[18]*(algebraic[17]+algebraic[15]); + algebraic[13] = algebraic[16]*computedConstants[5]*(algebraic[19]+algebraic[12])+algebraic[19]*algebraic[10]*(computedConstants[5]+algebraic[18]); + algebraic[14] = algebraic[19]*algebraic[17]*(algebraic[16]+algebraic[10])+algebraic[12]*algebraic[16]*(algebraic[17]+algebraic[15]); + algebraic[4] = (1.0-constants[11])*constants[12]*(algebraic[9]*algebraic[10]-algebraic[11]*algebraic[12])/(algebraic[11]+algebraic[9]+algebraic[14]+algebraic[13]); + rates[1] = (1.0-constants[6])*-1.0*(algebraic[3]+algebraic[7]+algebraic[6]+3.0*algebraic[5]+3.0*algebraic[4])/(1.0*(computedConstants[2]+computedConstants[3])*constants[7]); + algebraic[24] = constants[26]-(constants[26]-constants[27])/(1.0+pow(constants[28]/states[2], constants[29])); + algebraic[26] = constants[31]*algebraic[24]; + algebraic[25] = constants[30]/algebraic[24]; + rates[4] = constants[32]*states[5]-algebraic[26]*states[0]*states[4]-(algebraic[25]*pow(states[0], 2.0)*states[4]-constants[33]*states[3]); + rates[3] = algebraic[25]*pow(states[0], 2.0)*states[4]-constants[33]*states[3]-(algebraic[26]*states[0]*states[3]-constants[32]*states[6]); + rates[6] = algebraic[26]*states[0]*states[3]-constants[32]*states[6]-(constants[33]*states[6]-algebraic[25]*pow(states[0], 2.0)*states[5]); + rates[5] = constants[33]*states[6]-algebraic[25]*pow(states[0], 2.0)*states[5]-(constants[32]*states[5]-algebraic[26]*states[0]*states[4]); + algebraic[31] = constants[39]*states[7]*(1.0-states[9])-constants[40]*states[9]; + rates[9] = algebraic[31]; + algebraic[32] = constants[41]*states[7]*(1.0-(states[10]+states[11]))-constants[42]*states[10]; + rates[10] = algebraic[32]; + algebraic[33] = constants[43]*constants[44]*(1.0-(states[10]+states[11]))-constants[45]*states[11]; + rates[11] = algebraic[33]; + algebraic[34] = constants[46]*states[7]*(1.0-states[12])-constants[47]*states[12]; + rates[12] = algebraic[34]; + algebraic[35] = constants[46]*states[0]*(1.0-states[13])-constants[47]*states[13]; + rates[13] = algebraic[35]; + algebraic[36] = constants[48]*states[2]*(1.0-states[14])-constants[49]*states[14]; + rates[14] = algebraic[36]; + algebraic[28] = (states[0]-states[7])/constants[35]; + algebraic[29] = computedConstants[7]/(1.0+exp((-states[7]+constants[36])/constants[37])); + rates[7] = 1.0*(algebraic[28]*computedConstants[3]-algebraic[29]*computedConstants[8])/computedConstants[2]-(constants[52]*algebraic[34]+constants[50]*algebraic[31]+constants[51]*algebraic[32]); + algebraic[22] = constants[25]*states[3]*(states[2]-states[0]); + algebraic[37] = 2.0*constants[77]*(algebraic[8]-0.0)/(computedConstants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)*2.0/computedConstants[0])))*(states[0]-constants[5]*exp(-2.0*(algebraic[8]-0.0)/computedConstants[0]))*states[23]*states[22]*states[21]; + algebraic[38] = 2.0*constants[84]*algebraic[8]/(computedConstants[0]*(1.0-exp(-1.0*algebraic[8]*2.0/computedConstants[0])))*(states[0]-constants[5]*exp(-2.0*algebraic[8]/computedConstants[0]))*states[25]*states[24]; + rates[0] = algebraic[22]*computedConstants[9]/computedConstants[3]-((algebraic[37]+algebraic[38]-2.0*algebraic[4])/(2.0*constants[7]*computedConstants[3])+algebraic[28]+constants[52]*algebraic[35]); + algebraic[30] = (states[8]-states[2])/constants[38]; + rates[8] = algebraic[29]-algebraic[30]*computedConstants[9]/computedConstants[8]; + rates[2] = algebraic[30]-(algebraic[22]+constants[53]*algebraic[36]); + algebraic[48] = states[16]*computedConstants[15]*(algebraic[8]-computedConstants[1])*(1.0-constants[71]); + algebraic[40] = algebraic[7]+algebraic[48]; + algebraic[41] = constants[76]*states[20]*states[19]*(algebraic[8]-computedConstants[1]); + algebraic[42] = (constants[0] > 0.0)?constants[89]*constants[90]*(algebraic[8]-computedConstants[1])*(1.0+exp((algebraic[8]+20.0)/20.0))*states[32]:0.0; + algebraic[67] = 0.000365*constants[77]*(algebraic[8]-0.0)/(computedConstants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)/computedConstants[0])))*(constants[4]-constants[3]*exp(-1.0*(algebraic[8]-0.0)/computedConstants[0]))*states[23]*states[22]*states[21]; + algebraic[43] = (algebraic[37]+algebraic[67]+algebraic[6])*(1.0-computedConstants[19])*1.0*computedConstants[18]; + algebraic[44] = constants[86]*(algebraic[8]-computedConstants[1])*states[27]*states[26]; + algebraic[93] = computedConstants[0]*log((constants[3]+0.12*constants[2])/(constants[4]+0.12*algebraic[1])); + algebraic[45] = computedConstants[22]*(algebraic[8]-algebraic[93])*pow(states[31], 2.0); + algebraic[46] = constants[87]*(algebraic[8]-computedConstants[1])*(0.9*states[29]+0.1*states[30])*states[28]; + algebraic[39] = algebraic[40]+algebraic[46]+algebraic[45]+algebraic[44]+algebraic[5]+algebraic[4]+algebraic[3]+algebraic[43]+algebraic[38]+algebraic[42]+algebraic[41]; + rates[15] = -algebraic[39]/constants[60]; + algebraic[50] = (algebraic[8] < -(80.0-computedConstants[16]-computedConstants[17]-constants[72]))?0.01329+0.99921/(1.0+exp((algebraic[8]+97.134-computedConstants[16]-computedConstants[17]-constants[72])/8.1752)):0.0002501*exp(-(algebraic[8]-computedConstants[16]-computedConstants[17]-constants[72])/12.861); + algebraic[49] = 1.0/(0.36*(algebraic[8]+148.8-computedConstants[16]-computedConstants[17])/(exp(0.066*(algebraic[8]+148.8-computedConstants[16]-computedConstants[17]))-1.0)+0.1*(algebraic[8]+87.3-computedConstants[16]-computedConstants[17])/(1.0-exp(-0.2*(algebraic[8]+87.3-computedConstants[16]-computedConstants[17]))))-0.054; + rates[16] = (algebraic[50]-states[16])/algebraic[49]; + algebraic[54] = 1.0/(1.0+exp(-(algebraic[8]+42.0504)/8.3106)); + algebraic[55] = algebraic[8]+41.0; + algebraic[56] = (fabs(algebraic[55]) < constants[75])?2000.0:200.0*algebraic[55]/(1.0-exp(-0.1*algebraic[55])); + algebraic[57] = 8000.0*exp(-0.056*(algebraic[8]+66.0)); + algebraic[58] = 1.0/(algebraic[56]+algebraic[57]); + rates[18] = (algebraic[54]-states[18])/algebraic[58]; + algebraic[59] = 1.0/(1.0+exp((algebraic[8]+69.804)/4.4565)); + algebraic[60] = 20.0*exp(-0.125*(algebraic[8]+75.0)); + algebraic[61] = 2000.0/(320.0*exp(-0.1*(algebraic[8]+75.0))+1.0); + algebraic[62] = 1.0/(algebraic[60]+algebraic[61]); + rates[17] = (algebraic[59]-states[17])/algebraic[62]; + algebraic[63] = 1.0/(1.0+exp((algebraic[8]+6.0)/-8.6)); + algebraic[64] = 0.009/(1.0+exp((algebraic[8]+5.0)/12.0))+0.0005; + rates[20] = (algebraic[63]-states[20])/algebraic[64]; + algebraic[65] = 1.0/(1.0+exp((algebraic[8]+7.5)/10.0)); + algebraic[66] = 0.59/(1.0+exp((algebraic[8]+60.0)/10.0))+3.05; + rates[19] = (algebraic[65]-states[19])/algebraic[66]; + algebraic[68] = 1.0/(1.0+exp(-(algebraic[8]-constants[78]-computedConstants[20])/(constants[79]*(1.0+computedConstants[21]/100.0)))); + algebraic[72] = (algebraic[8] == -41.8)?-41.80001:(algebraic[8] == 0.0)?0.0:(algebraic[8] == -6.8)?-6.80001:algebraic[8]; + algebraic[70] = -0.02839*(algebraic[72]+41.8)/(exp(-(algebraic[72]+41.8)/2.5)-1.0)-0.0849*(algebraic[72]+6.8)/(exp(-(algebraic[72]+6.8)/4.8)-1.0); + algebraic[73] = (algebraic[8] == -1.8)?-1.80001:algebraic[8]; + algebraic[71] = 0.01143*(algebraic[73]+1.8)/(exp((algebraic[73]+1.8)/2.5)-1.0); + algebraic[69] = 0.001/(algebraic[70]+algebraic[71]); + rates[23] = (algebraic[68]-states[23])/algebraic[69]; + algebraic[74] = 1.0/(1.0+exp((algebraic[8]+37.4+constants[80])/(5.3+constants[81]))); + algebraic[75] = 0.001*(44.3+230.0*exp(-pow((algebraic[8]+36.0)/10.0, 2.0))); + rates[22] = (algebraic[74]-states[22])/algebraic[75]; + algebraic[76] = constants[82]/(constants[82]+states[0]); + algebraic[77] = 0.001*algebraic[76]/constants[83]; + rates[21] = (algebraic[76]-states[21])/algebraic[77]; + algebraic[78] = 1.0/(1.0+exp(-(algebraic[8]+38.3)/5.5)); + algebraic[79] = 0.001/(1.068*exp((algebraic[8]+38.3)/30.0)+1.068*exp(-(algebraic[8]+38.3)/30.0)); + rates[25] = (algebraic[78]-states[25])/algebraic[79]; + algebraic[80] = 1.0/(1.0+exp((algebraic[8]+58.7)/3.8)); + algebraic[81] = 1.0/(16.67*exp(-(algebraic[8]+75.0)/83.3)+16.67*exp((algebraic[8]+75.0)/15.38))+constants[85]; + rates[24] = (algebraic[80]-states[24])/algebraic[81]; + algebraic[82] = 1.0/(1.0+exp((algebraic[8]+49.0)/13.0)); + algebraic[83] = 0.001*0.6*(65.17/(0.57*exp(-0.08*(algebraic[8]+44.0))+0.065*exp(0.1*(algebraic[8]+45.93)))+10.1); + rates[27] = (algebraic[82]-states[27])/algebraic[83]; + algebraic[84] = 1.0/(1.0+exp(-(algebraic[8]-19.3)/15.0)); + algebraic[85] = 0.001*0.66*1.4*(15.59/(1.037*exp(0.09*(algebraic[8]+30.61))+0.369*exp(-0.12*(algebraic[8]+23.84)))+2.98); + rates[26] = (algebraic[84]-states[26])/algebraic[85]; + algebraic[88] = 1.0/(1.0+exp(-(algebraic[8]+10.0144)/7.6607)); + algebraic[89] = 0.84655354/(4.2*exp(algebraic[8]/17.0)+0.15*exp(-algebraic[8]/21.6)); + rates[30] = (algebraic[88]-states[30])/algebraic[89]; + algebraic[90] = 1.0/(30.0*exp(algebraic[8]/10.0)+exp(-algebraic[8]/12.0)); + rates[29] = (algebraic[88]-states[29])/algebraic[90]; + algebraic[92] = 1.0/(1.0+exp((algebraic[8]+28.6)/17.1)); + algebraic[91] = 1.0/(100.0*exp(-algebraic[8]/54.645)+656.0*exp(algebraic[8]/106.157)); + rates[28] = (algebraic[92]-states[28])/algebraic[91]; + algebraic[94] = sqrt(1.0/(1.0+exp(-(algebraic[8]+0.6383-computedConstants[23])/10.7071))); + algebraic[96] = 28.0/(1.0+exp(-(algebraic[8]-40.0-computedConstants[23])/3.0)); + algebraic[97] = 1.0*exp(-(algebraic[8]-computedConstants[23]-5.0)/25.0); + algebraic[95] = 1.0/(algebraic[96]+algebraic[97]); + rates[31] = (algebraic[94]-states[31])/algebraic[95]; + algebraic[98] = 10.0*exp(0.0133*(algebraic[8]+40.0)); + algebraic[99] = computedConstants[24]/(computedConstants[24]+algebraic[98]); + algebraic[100] = 1.0/(computedConstants[24]+algebraic[98]); + rates[32] = (algebraic[99]-states[32])/algebraic[100]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[5] = states[1]; - variables[2] = variables[3]*log(variables[4]/variables[5]); - variables[9] = 0.5*variables[3]*log(variables[10]/states[0]); - variables[21] = (variables[122] >= 1.0)?variables[121]:states[15]; - variables[14] = variables[20]*variables[24]*pow(1.0+pow(variables[23]/variables[7], 1.2), -1.0)*pow(1.0+pow(variables[22]/variables[5], 1.3), -1.0)*pow(1.0+exp(-(variables[21]-variables[2]+110.0)/20.0), -1.0); - variables[50] = 1.0+variables[10]/variables[48]*(1.0+exp(variables[49]*variables[21]/variables[3]))+variables[4]/variables[51]*(1.0+variables[4]/variables[52]*(1.0+variables[4]/variables[47])); - variables[27] = variables[10]/variables[48]*exp(variables[49]*variables[21]/variables[3])/variables[50]; - variables[42] = 1.0+states[0]/variables[40]*(1.0+exp(-variables[41]*variables[21]/variables[3])+variables[5]/variables[46])+variables[5]/variables[43]*(1.0+variables[5]/variables[44]*(1.0+variables[5]/variables[39])); - variables[29] = states[0]/variables[40]*exp(-variables[41]*variables[21]/variables[3])/variables[42]; - variables[36] = variables[5]/(variables[39]+variables[5]); - variables[37] = exp(variables[45]*variables[21]/(2.0*variables[3])); - variables[33] = exp(-variables[45]*variables[21]/(2.0*variables[3])); - variables[38] = variables[5]/variables[43]*variables[5]/variables[44]*(1.0+variables[5]/variables[39])*exp(variables[45]*variables[21]/(2.0*variables[3]))/variables[42]; - variables[26] = variables[37]*variables[36]*(variables[38]+variables[29])+variables[33]*variables[29]*(variables[35]+variables[37]); - variables[34] = variables[4]/variables[51]*variables[4]/variables[52]*(1.0+variables[4]/variables[47])*exp(-variables[45]*variables[21]/(2.0*variables[3]))/variables[50]; - variables[28] = variables[33]*variables[35]*(variables[34]+variables[27])+variables[27]*variables[37]*(variables[36]+variables[33]); - variables[31] = variables[34]*variables[35]*(variables[38]+variables[29])+variables[38]*variables[27]*(variables[35]+variables[37]); - variables[32] = variables[38]*variables[36]*(variables[34]+variables[27])+variables[29]*variables[34]*(variables[36]+variables[33]); - variables[13] = (1.0-variables[25])*variables[30]*(variables[26]*variables[27]-variables[28]*variables[29])/(variables[28]+variables[26]+variables[32]+variables[31]); - variables[53] = variables[54]*states[3]*(states[2]-states[0]); - variables[55] = states[2]-states[0]; - variables[56] = variables[57]-(variables[57]-variables[58])/(1.0+pow(variables[59]/states[2], variables[60])); - variables[61] = variables[62]/variables[56]; - variables[63] = variables[64]*variables[56]; - variables[67] = states[4]+states[3]+states[6]+states[5]; - variables[71] = (states[0]-states[7])/variables[72]; - variables[73] = variables[69]/(1.0+exp((-states[7]+variables[74])/variables[75])); - variables[76] = (states[8]-states[2])/variables[77]; - variables[78] = variables[79]*states[7]*(1.0-states[9])-variables[80]*states[9]; - variables[81] = variables[82]*states[7]*(1.0-(states[10]+states[11]))-variables[83]*states[10]; - variables[84] = variables[85]*variables[86]*(1.0-(states[10]+states[11]))-variables[87]*states[11]; - variables[88] = variables[89]*states[7]*(1.0-states[12])-variables[90]*states[12]; - variables[91] = variables[89]*states[0]*(1.0-states[13])-variables[90]*states[13]; - variables[92] = variables[93]*states[2]*(1.0-states[14])-variables[94]*states[14]; - variables[16] = states[16]*variables[133]*(variables[21]-variables[2])*(1.0-variables[135]); - variables[136] = states[16]*variables[134]*(variables[21]-variables[6])*(1.0-variables[135]); - variables[111] = variables[16]+variables[136]; - variables[112] = variables[157]*states[20]*states[19]*(variables[21]-variables[6]); - variables[113] = (variables[0] > 0.0)?variables[211]*variables[212]*(variables[21]-variables[6])*(1.0+exp((variables[21]+20.0)/20.0))*states[32]:0.0; - variables[102] = 2.0*variables[184]*variables[21]/(variables[3]*(1.0-exp(-1.0*variables[21]*2.0/variables[3])))*(states[0]-variables[10]*exp(-2.0*variables[21]/variables[3]))*states[25]*states[24]; - variables[101] = 2.0*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)*2.0/variables[3])))*(states[0]-variables[10]*exp(-2.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21]; - variables[15] = 0.0000185*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)/variables[3])))*(variables[5]-variables[4]*exp(-1.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21]; - variables[164] = 0.000365*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)/variables[3])))*(variables[8]-variables[7]*exp(-1.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21]; - variables[114] = (variables[101]+variables[164]+variables[15])*(1.0-variables[165])*1.0*variables[162]; - variables[142] = variables[3]*log((variables[4]+0.12*variables[7])/(variables[5]+0.12*variables[8])); - variables[143] = variables[144]*pow(states[18], 3.0)*states[17]*(variables[21]-variables[142]); - variables[145] = variables[146]*pow(states[18], 3.0)*(variables[21]-variables[142]); - variables[12] = variables[143]+variables[145]; - variables[115] = variables[190]*(variables[21]-variables[6])*states[27]*states[26]; - variables[205] = variables[3]*log((variables[7]+0.12*variables[4])/(variables[8]+0.12*variables[5])); - variables[116] = variables[203]*(variables[21]-variables[205])*pow(states[31], 2.0); - variables[117] = variables[195]*(variables[21]-variables[6])*(0.9*states[29]+0.1*states[30])*states[28]; - variables[110] = variables[111]+variables[117]+variables[116]+variables[115]+variables[14]+variables[13]+variables[12]+variables[114]+variables[102]+variables[113]+variables[112]; - variables[139] = 1.0/(0.36*(variables[21]+148.8-variables[137]-variables[138])/(exp(0.066*(variables[21]+148.8-variables[137]-variables[138]))-1.0)+0.1*(variables[21]+87.3-variables[137]-variables[138])/(1.0-exp(-0.2*(variables[21]+87.3-variables[137]-variables[138]))))-0.054; - variables[140] = (variables[21] < -(80.0-variables[137]-variables[138]-variables[141]))?0.01329+0.99921/(1.0+exp((variables[21]+97.134-variables[137]-variables[138]-variables[141])/8.1752)):0.0002501*exp(-(variables[21]-variables[137]-variables[138]-variables[141])/12.861); - variables[147] = 1.0/(1.0+exp(-(variables[21]+42.0504)/8.3106)); - variables[148] = variables[21]+41.0; - variables[149] = (fabs(variables[148]) < variables[150])?2000.0:200.0*variables[148]/(1.0-exp(-0.1*variables[148])); - variables[151] = 8000.0*exp(-0.056*(variables[21]+66.0)); - variables[152] = 1.0/(variables[149]+variables[151]); - variables[153] = 1.0/(1.0+exp((variables[21]+69.804)/4.4565)); - variables[154] = 20.0*exp(-0.125*(variables[21]+75.0)); - variables[155] = 2000.0/(320.0*exp(-0.1*(variables[21]+75.0))+1.0); - variables[156] = 1.0/(variables[154]+variables[155]); - variables[158] = 1.0/(1.0+exp((variables[21]+6.0)/-8.6)); - variables[159] = 0.009/(1.0+exp((variables[21]+5.0)/12.0))+0.0005; - variables[160] = 1.0/(1.0+exp((variables[21]+7.5)/10.0)); - variables[161] = 0.59/(1.0+exp((variables[21]+60.0)/10.0))+3.05; - variables[168] = 1.0/(1.0+exp(-(variables[21]-variables[169]-variables[166])/(variables[170]*(1.0+variables[167]/100.0)))); - variables[174] = (variables[21] == -41.8)?-41.80001:(variables[21] == 0.0)?0.0:(variables[21] == -6.8)?-6.80001:variables[21]; - variables[172] = -0.02839*(variables[174]+41.8)/(exp(-(variables[174]+41.8)/2.5)-1.0)-0.0849*(variables[174]+6.8)/(exp(-(variables[174]+6.8)/4.8)-1.0); - variables[175] = (variables[21] == -1.8)?-1.80001:variables[21]; - variables[173] = 0.01143*(variables[175]+1.8)/(exp((variables[175]+1.8)/2.5)-1.0); - variables[171] = 0.001/(variables[172]+variables[173]); - variables[176] = 1.0/(1.0+exp((variables[21]+37.4+variables[177])/(5.3+variables[178]))); - variables[179] = 0.001*(44.3+230.0*exp(-pow((variables[21]+36.0)/10.0, 2.0))); - variables[180] = variables[181]/(variables[181]+states[0]); - variables[182] = 0.001*variables[180]/variables[183]; - variables[185] = 1.0/(1.0+exp(-(variables[21]+38.3)/5.5)); - variables[186] = 0.001/(1.068*exp((variables[21]+38.3)/30.0)+1.068*exp(-(variables[21]+38.3)/30.0)); - variables[187] = 1.0/(1.0+exp((variables[21]+58.7)/3.8)); - variables[188] = 1.0/(16.67*exp(-(variables[21]+75.0)/83.3)+16.67*exp((variables[21]+75.0)/15.38))+variables[189]; - variables[191] = 1.0/(1.0+exp((variables[21]+49.0)/13.0)); - variables[192] = 0.001*0.6*(65.17/(0.57*exp(-0.08*(variables[21]+44.0))+0.065*exp(0.1*(variables[21]+45.93)))+10.1); - variables[193] = 1.0/(1.0+exp(-(variables[21]-19.3)/15.0)); - variables[194] = 0.001*0.66*1.4*(15.59/(1.037*exp(0.09*(variables[21]+30.61))+0.369*exp(-0.12*(variables[21]+23.84)))+2.98); - variables[196] = 1.0/(1.0+exp(-(variables[21]+23.2)/6.6))/(0.84655354/(37.2*exp(variables[21]/11.9)+0.96*exp(-variables[21]/18.5))); - variables[197] = 4.0*((37.2*exp(variables[21]/15.9)+0.96*exp(-variables[21]/22.5))/0.84655354-1.0/(1.0+exp(-(variables[21]+23.2)/10.6))/(0.84655354/(37.2*exp(variables[21]/15.9)+0.96*exp(-variables[21]/22.5)))); - variables[198] = 1.0/(1.0+exp(-(variables[21]+10.0144)/7.6607)); - variables[199] = 0.84655354/(4.2*exp(variables[21]/17.0)+0.15*exp(-variables[21]/21.6)); - variables[200] = 1.0/(30.0*exp(variables[21]/10.0)+exp(-variables[21]/12.0)); - variables[201] = 1.0/(100.0*exp(-variables[21]/54.645)+656.0*exp(variables[21]/106.157)); - variables[202] = 1.0/(1.0+exp((variables[21]+28.6)/17.1)); - variables[207] = sqrt(1.0/(1.0+exp(-(variables[21]+0.6383-variables[206])/10.7071))); - variables[209] = 28.0/(1.0+exp(-(variables[21]-40.0-variables[206])/3.0)); - variables[210] = 1.0*exp(-(variables[21]-variables[206]-5.0)/25.0); - variables[208] = 1.0/(variables[209]+variables[210]); - variables[214] = 10.0*exp(0.0133*(variables[21]+40.0)); - variables[215] = variables[213]/(variables[213]+variables[214]); - variables[216] = 1.0/(variables[213]+variables[214]); + algebraic[1] = states[1]; + algebraic[0] = computedConstants[0]*log(constants[2]/algebraic[1]); + algebraic[2] = 0.5*computedConstants[0]*log(constants[5]/states[0]); + algebraic[8] = (constants[63] >= 1.0)?algebraic[47]:states[15]; + algebraic[5] = computedConstants[4]*constants[10]*pow(1.0+pow(constants[9]/constants[3], 1.2), -1.0)*pow(1.0+pow(constants[8]/algebraic[1], 1.3), -1.0)*pow(1.0+exp(-(algebraic[8]-algebraic[0]+110.0)/20.0), -1.0); + algebraic[21] = 1.0+constants[5]/constants[21]*(1.0+exp(constants[22]*algebraic[8]/computedConstants[0]))+constants[2]/constants[23]*(1.0+constants[2]/constants[24]*(1.0+constants[2]/constants[20])); + algebraic[10] = constants[5]/constants[21]*exp(constants[22]*algebraic[8]/computedConstants[0])/algebraic[21]; + algebraic[20] = 1.0+states[0]/constants[14]*(1.0+exp(-constants[15]*algebraic[8]/computedConstants[0])+algebraic[1]/constants[19])+algebraic[1]/constants[16]*(1.0+algebraic[1]/constants[17]*(1.0+algebraic[1]/constants[13])); + algebraic[12] = states[0]/constants[14]*exp(-constants[15]*algebraic[8]/computedConstants[0])/algebraic[20]; + algebraic[17] = algebraic[1]/(constants[13]+algebraic[1]); + algebraic[18] = exp(constants[18]*algebraic[8]/(2.0*computedConstants[0])); + algebraic[15] = exp(-constants[18]*algebraic[8]/(2.0*computedConstants[0])); + algebraic[19] = algebraic[1]/constants[16]*algebraic[1]/constants[17]*(1.0+algebraic[1]/constants[13])*exp(constants[18]*algebraic[8]/(2.0*computedConstants[0]))/algebraic[20]; + algebraic[9] = algebraic[18]*algebraic[17]*(algebraic[19]+algebraic[12])+algebraic[15]*algebraic[12]*(computedConstants[5]+algebraic[18]); + algebraic[16] = constants[2]/constants[23]*constants[2]/constants[24]*(1.0+constants[2]/constants[20])*exp(-constants[18]*algebraic[8]/(2.0*computedConstants[0]))/algebraic[21]; + algebraic[11] = algebraic[15]*computedConstants[5]*(algebraic[16]+algebraic[10])+algebraic[10]*algebraic[18]*(algebraic[17]+algebraic[15]); + algebraic[13] = algebraic[16]*computedConstants[5]*(algebraic[19]+algebraic[12])+algebraic[19]*algebraic[10]*(computedConstants[5]+algebraic[18]); + algebraic[14] = algebraic[19]*algebraic[17]*(algebraic[16]+algebraic[10])+algebraic[12]*algebraic[16]*(algebraic[17]+algebraic[15]); + algebraic[4] = (1.0-constants[11])*constants[12]*(algebraic[9]*algebraic[10]-algebraic[11]*algebraic[12])/(algebraic[11]+algebraic[9]+algebraic[14]+algebraic[13]); + algebraic[22] = constants[25]*states[3]*(states[2]-states[0]); + algebraic[23] = states[2]-states[0]; + algebraic[24] = constants[26]-(constants[26]-constants[27])/(1.0+pow(constants[28]/states[2], constants[29])); + algebraic[25] = constants[30]/algebraic[24]; + algebraic[26] = constants[31]*algebraic[24]; + algebraic[27] = states[4]+states[3]+states[6]+states[5]; + algebraic[28] = (states[0]-states[7])/constants[35]; + algebraic[29] = computedConstants[7]/(1.0+exp((-states[7]+constants[36])/constants[37])); + algebraic[30] = (states[8]-states[2])/constants[38]; + algebraic[31] = constants[39]*states[7]*(1.0-states[9])-constants[40]*states[9]; + algebraic[32] = constants[41]*states[7]*(1.0-(states[10]+states[11]))-constants[42]*states[10]; + algebraic[33] = constants[43]*constants[44]*(1.0-(states[10]+states[11]))-constants[45]*states[11]; + algebraic[34] = constants[46]*states[7]*(1.0-states[12])-constants[47]*states[12]; + algebraic[35] = constants[46]*states[0]*(1.0-states[13])-constants[47]*states[13]; + algebraic[36] = constants[48]*states[2]*(1.0-states[14])-constants[49]*states[14]; + algebraic[7] = states[16]*computedConstants[14]*(algebraic[8]-algebraic[0])*(1.0-constants[71]); + algebraic[48] = states[16]*computedConstants[15]*(algebraic[8]-computedConstants[1])*(1.0-constants[71]); + algebraic[40] = algebraic[7]+algebraic[48]; + algebraic[41] = constants[76]*states[20]*states[19]*(algebraic[8]-computedConstants[1]); + algebraic[42] = (constants[0] > 0.0)?constants[89]*constants[90]*(algebraic[8]-computedConstants[1])*(1.0+exp((algebraic[8]+20.0)/20.0))*states[32]:0.0; + algebraic[38] = 2.0*constants[84]*algebraic[8]/(computedConstants[0]*(1.0-exp(-1.0*algebraic[8]*2.0/computedConstants[0])))*(states[0]-constants[5]*exp(-2.0*algebraic[8]/computedConstants[0]))*states[25]*states[24]; + algebraic[37] = 2.0*constants[77]*(algebraic[8]-0.0)/(computedConstants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)*2.0/computedConstants[0])))*(states[0]-constants[5]*exp(-2.0*(algebraic[8]-0.0)/computedConstants[0]))*states[23]*states[22]*states[21]; + algebraic[6] = 0.0000185*constants[77]*(algebraic[8]-0.0)/(computedConstants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)/computedConstants[0])))*(algebraic[1]-constants[2]*exp(-1.0*(algebraic[8]-0.0)/computedConstants[0]))*states[23]*states[22]*states[21]; + algebraic[67] = 0.000365*constants[77]*(algebraic[8]-0.0)/(computedConstants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)/computedConstants[0])))*(constants[4]-constants[3]*exp(-1.0*(algebraic[8]-0.0)/computedConstants[0]))*states[23]*states[22]*states[21]; + algebraic[43] = (algebraic[37]+algebraic[67]+algebraic[6])*(1.0-computedConstants[19])*1.0*computedConstants[18]; + algebraic[51] = computedConstants[0]*log((constants[2]+0.12*constants[3])/(algebraic[1]+0.12*constants[4])); + algebraic[52] = constants[73]*pow(states[18], 3.0)*states[17]*(algebraic[8]-algebraic[51]); + algebraic[53] = constants[74]*pow(states[18], 3.0)*(algebraic[8]-algebraic[51]); + algebraic[3] = algebraic[52]+algebraic[53]; + algebraic[44] = constants[86]*(algebraic[8]-computedConstants[1])*states[27]*states[26]; + algebraic[93] = computedConstants[0]*log((constants[3]+0.12*constants[2])/(constants[4]+0.12*algebraic[1])); + algebraic[45] = computedConstants[22]*(algebraic[8]-algebraic[93])*pow(states[31], 2.0); + algebraic[46] = constants[87]*(algebraic[8]-computedConstants[1])*(0.9*states[29]+0.1*states[30])*states[28]; + algebraic[39] = algebraic[40]+algebraic[46]+algebraic[45]+algebraic[44]+algebraic[5]+algebraic[4]+algebraic[3]+algebraic[43]+algebraic[38]+algebraic[42]+algebraic[41]; + algebraic[49] = 1.0/(0.36*(algebraic[8]+148.8-computedConstants[16]-computedConstants[17])/(exp(0.066*(algebraic[8]+148.8-computedConstants[16]-computedConstants[17]))-1.0)+0.1*(algebraic[8]+87.3-computedConstants[16]-computedConstants[17])/(1.0-exp(-0.2*(algebraic[8]+87.3-computedConstants[16]-computedConstants[17]))))-0.054; + algebraic[50] = (algebraic[8] < -(80.0-computedConstants[16]-computedConstants[17]-constants[72]))?0.01329+0.99921/(1.0+exp((algebraic[8]+97.134-computedConstants[16]-computedConstants[17]-constants[72])/8.1752)):0.0002501*exp(-(algebraic[8]-computedConstants[16]-computedConstants[17]-constants[72])/12.861); + algebraic[54] = 1.0/(1.0+exp(-(algebraic[8]+42.0504)/8.3106)); + algebraic[55] = algebraic[8]+41.0; + algebraic[56] = (fabs(algebraic[55]) < constants[75])?2000.0:200.0*algebraic[55]/(1.0-exp(-0.1*algebraic[55])); + algebraic[57] = 8000.0*exp(-0.056*(algebraic[8]+66.0)); + algebraic[58] = 1.0/(algebraic[56]+algebraic[57]); + algebraic[59] = 1.0/(1.0+exp((algebraic[8]+69.804)/4.4565)); + algebraic[60] = 20.0*exp(-0.125*(algebraic[8]+75.0)); + algebraic[61] = 2000.0/(320.0*exp(-0.1*(algebraic[8]+75.0))+1.0); + algebraic[62] = 1.0/(algebraic[60]+algebraic[61]); + algebraic[63] = 1.0/(1.0+exp((algebraic[8]+6.0)/-8.6)); + algebraic[64] = 0.009/(1.0+exp((algebraic[8]+5.0)/12.0))+0.0005; + algebraic[65] = 1.0/(1.0+exp((algebraic[8]+7.5)/10.0)); + algebraic[66] = 0.59/(1.0+exp((algebraic[8]+60.0)/10.0))+3.05; + algebraic[68] = 1.0/(1.0+exp(-(algebraic[8]-constants[78]-computedConstants[20])/(constants[79]*(1.0+computedConstants[21]/100.0)))); + algebraic[72] = (algebraic[8] == -41.8)?-41.80001:(algebraic[8] == 0.0)?0.0:(algebraic[8] == -6.8)?-6.80001:algebraic[8]; + algebraic[70] = -0.02839*(algebraic[72]+41.8)/(exp(-(algebraic[72]+41.8)/2.5)-1.0)-0.0849*(algebraic[72]+6.8)/(exp(-(algebraic[72]+6.8)/4.8)-1.0); + algebraic[73] = (algebraic[8] == -1.8)?-1.80001:algebraic[8]; + algebraic[71] = 0.01143*(algebraic[73]+1.8)/(exp((algebraic[73]+1.8)/2.5)-1.0); + algebraic[69] = 0.001/(algebraic[70]+algebraic[71]); + algebraic[74] = 1.0/(1.0+exp((algebraic[8]+37.4+constants[80])/(5.3+constants[81]))); + algebraic[75] = 0.001*(44.3+230.0*exp(-pow((algebraic[8]+36.0)/10.0, 2.0))); + algebraic[76] = constants[82]/(constants[82]+states[0]); + algebraic[77] = 0.001*algebraic[76]/constants[83]; + algebraic[78] = 1.0/(1.0+exp(-(algebraic[8]+38.3)/5.5)); + algebraic[79] = 0.001/(1.068*exp((algebraic[8]+38.3)/30.0)+1.068*exp(-(algebraic[8]+38.3)/30.0)); + algebraic[80] = 1.0/(1.0+exp((algebraic[8]+58.7)/3.8)); + algebraic[81] = 1.0/(16.67*exp(-(algebraic[8]+75.0)/83.3)+16.67*exp((algebraic[8]+75.0)/15.38))+constants[85]; + algebraic[82] = 1.0/(1.0+exp((algebraic[8]+49.0)/13.0)); + algebraic[83] = 0.001*0.6*(65.17/(0.57*exp(-0.08*(algebraic[8]+44.0))+0.065*exp(0.1*(algebraic[8]+45.93)))+10.1); + algebraic[84] = 1.0/(1.0+exp(-(algebraic[8]-19.3)/15.0)); + algebraic[85] = 0.001*0.66*1.4*(15.59/(1.037*exp(0.09*(algebraic[8]+30.61))+0.369*exp(-0.12*(algebraic[8]+23.84)))+2.98); + algebraic[86] = 1.0/(1.0+exp(-(algebraic[8]+23.2)/6.6))/(0.84655354/(37.2*exp(algebraic[8]/11.9)+0.96*exp(-algebraic[8]/18.5))); + algebraic[87] = 4.0*((37.2*exp(algebraic[8]/15.9)+0.96*exp(-algebraic[8]/22.5))/0.84655354-1.0/(1.0+exp(-(algebraic[8]+23.2)/10.6))/(0.84655354/(37.2*exp(algebraic[8]/15.9)+0.96*exp(-algebraic[8]/22.5)))); + algebraic[88] = 1.0/(1.0+exp(-(algebraic[8]+10.0144)/7.6607)); + algebraic[89] = 0.84655354/(4.2*exp(algebraic[8]/17.0)+0.15*exp(-algebraic[8]/21.6)); + algebraic[90] = 1.0/(30.0*exp(algebraic[8]/10.0)+exp(-algebraic[8]/12.0)); + algebraic[91] = 1.0/(100.0*exp(-algebraic[8]/54.645)+656.0*exp(algebraic[8]/106.157)); + algebraic[92] = 1.0/(1.0+exp((algebraic[8]+28.6)/17.1)); + algebraic[94] = sqrt(1.0/(1.0+exp(-(algebraic[8]+0.6383-computedConstants[23])/10.7071))); + algebraic[96] = 28.0/(1.0+exp(-(algebraic[8]-40.0-computedConstants[23])/3.0)); + algebraic[97] = 1.0*exp(-(algebraic[8]-computedConstants[23]-5.0)/25.0); + algebraic[95] = 1.0/(algebraic[96]+algebraic[97]); + algebraic[98] = 10.0*exp(0.0133*(algebraic[8]+40.0)); + algebraic[99] = computedConstants[24]/(computedConstants[24]+algebraic[98]); + algebraic[100] = 1.0/(computedConstants[24]+algebraic[98]); } diff --git a/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.h b/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.h index 1e73f17e6a..e038543ea9 100644 --- a/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.h +++ b/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[15]; char units[26]; char component[28]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.py b/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.py index 2f1c730a91..6489ff4844 100644 --- a/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.py +++ b/tests/resources/generator/fabbri_fantini_wilders_severi_human_san_model_2017/model.py @@ -4,277 +4,276 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 33 -VARIABLE_COUNT = 217 +CONSTANT_COUNT = 91 +COMPUTED_CONSTANT_COUNT = 25 +ALGEBRAIC_COUNT = 101 +VOI_INFO = {"name": "time", "units": "second", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "Ca_sub", "units": "millimolar", "component": "Ca_dynamics"}, + {"name": "Nai_", "units": "millimolar", "component": "Nai_concentration"}, + {"name": "Ca_jsr", "units": "millimolar", "component": "Ca_dynamics"}, + {"name": "O", "units": "dimensionless", "component": "Ca_SR_release"}, + {"name": "R", "units": "dimensionless", "component": "Ca_SR_release"}, + {"name": "RI", "units": "dimensionless", "component": "Ca_SR_release"}, + {"name": "I", "units": "dimensionless", "component": "Ca_SR_release"}, + {"name": "Cai", "units": "millimolar", "component": "Ca_dynamics"}, + {"name": "Ca_nsr", "units": "millimolar", "component": "Ca_dynamics"}, + {"name": "fTC", "units": "dimensionless", "component": "Ca_buffering"}, + {"name": "fTMC", "units": "dimensionless", "component": "Ca_buffering"}, + {"name": "fTMM", "units": "dimensionless", "component": "Ca_buffering"}, + {"name": "fCMi", "units": "dimensionless", "component": "Ca_buffering"}, + {"name": "fCMs", "units": "dimensionless", "component": "Ca_buffering"}, + {"name": "fCQ", "units": "dimensionless", "component": "Ca_buffering"}, + {"name": "V_ode", "units": "millivolt", "component": "Membrane"}, + {"name": "y", "units": "dimensionless", "component": "i_f_y_gate"}, + {"name": "h", "units": "dimensionless", "component": "i_Na_h_gate"}, + {"name": "m", "units": "dimensionless", "component": "i_Na_m_gate"}, + {"name": "s_Kur", "units": "dimensionless", "component": "i_Kur_sKur_gate"}, + {"name": "r_Kur", "units": "dimensionless", "component": "i_Kur_rKur_gate"}, + {"name": "fCa", "units": "dimensionless", "component": "i_CaL_fCa_gate"}, + {"name": "fL", "units": "dimensionless", "component": "i_CaL_fL_gate"}, + {"name": "dL", "units": "dimensionless", "component": "i_CaL_dL_gate"}, + {"name": "fT", "units": "dimensionless", "component": "i_CaT_fT_gate"}, + {"name": "dT", "units": "dimensionless", "component": "i_CaT_dT_gate"}, + {"name": "r", "units": "dimensionless", "component": "i_to_r_gate"}, + {"name": "q", "units": "dimensionless", "component": "i_to_q_gate"}, + {"name": "piy", "units": "dimensionless", "component": "i_Kr_pi_gate"}, + {"name": "paF", "units": "dimensionless", "component": "i_Kr_pa_gate"}, + {"name": "paS", "units": "dimensionless", "component": "i_Kr_pa_gate"}, + {"name": "n", "units": "dimensionless", "component": "i_Ks_n_gate"}, + {"name": "a", "units": "dimensionless", "component": "i_KACh_a_gate"} +] -VOI_INFO = {"name": "time", "units": "second", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "ACh", "units": "millimolar", "component": "Rate_modulation_experiments"}, + {"name": "Iso_1_uM", "units": "dimensionless", "component": "Rate_modulation_experiments"}, + {"name": "Nao", "units": "millimolar", "component": "Ionic_values"}, + {"name": "Ko", "units": "millimolar", "component": "Ionic_values"}, + {"name": "Ki", "units": "millimolar", "component": "Ionic_values"}, + {"name": "Cao", "units": "millimolar", "component": "Ionic_values"}, + {"name": "Nai_clamp", "units": "dimensionless", "component": "Nai_concentration"}, + {"name": "F", "units": "coulomb_per_mole", "component": "Membrane"}, + {"name": "Km_Nap", "units": "millimolar", "component": "i_NaK"}, + {"name": "Km_Kp", "units": "millimolar", "component": "i_NaK"}, + {"name": "i_NaK_max", "units": "nanoA", "component": "i_NaK"}, + {"name": "blockade_NaCa", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "K_NaCa", "units": "nanoA", "component": "i_NaCa"}, + {"name": "K3ni", "units": "millimolar", "component": "i_NaCa"}, + {"name": "Kci", "units": "millimolar", "component": "i_NaCa"}, + {"name": "Qci", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "K1ni", "units": "millimolar", "component": "i_NaCa"}, + {"name": "K2ni", "units": "millimolar", "component": "i_NaCa"}, + {"name": "Qn", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "Kcni", "units": "millimolar", "component": "i_NaCa"}, + {"name": "K3no", "units": "millimolar", "component": "i_NaCa"}, + {"name": "Kco", "units": "millimolar", "component": "i_NaCa"}, + {"name": "Qco", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "K1no", "units": "millimolar", "component": "i_NaCa"}, + {"name": "K2no", "units": "millimolar", "component": "i_NaCa"}, + {"name": "ks", "units": "per_second", "component": "Ca_SR_release"}, + {"name": "MaxSR", "units": "dimensionless", "component": "Ca_SR_release"}, + {"name": "MinSR", "units": "dimensionless", "component": "Ca_SR_release"}, + {"name": "EC50_SR", "units": "millimolar", "component": "Ca_SR_release"}, + {"name": "HSR", "units": "dimensionless", "component": "Ca_SR_release"}, + {"name": "koCa", "units": "per_millimolar2_second", "component": "Ca_SR_release"}, + {"name": "kiCa", "units": "per_millimolar_second", "component": "Ca_SR_release"}, + {"name": "kim", "units": "per_second", "component": "Ca_SR_release"}, + {"name": "kom", "units": "per_second", "component": "Ca_SR_release"}, + {"name": "P_up_basal", "units": "millimolar_per_second", "component": "Ca_intracellular_fluxes"}, + {"name": "tau_dif_Ca", "units": "second", "component": "Ca_intracellular_fluxes"}, + {"name": "K_up", "units": "millimolar", "component": "Ca_intracellular_fluxes"}, + {"name": "slope_up", "units": "millimolar", "component": "Ca_intracellular_fluxes"}, + {"name": "tau_tr", "units": "second", "component": "Ca_intracellular_fluxes"}, + {"name": "kf_TC", "units": "per_millimolar_second", "component": "Ca_buffering"}, + {"name": "kb_TC", "units": "per_second", "component": "Ca_buffering"}, + {"name": "kf_TMC", "units": "per_millimolar_second", "component": "Ca_buffering"}, + {"name": "kb_TMC", "units": "per_second", "component": "Ca_buffering"}, + {"name": "kf_TMM", "units": "per_millimolar_second", "component": "Ca_buffering"}, + {"name": "Mgi", "units": "millimolar", "component": "Ca_buffering"}, + {"name": "kb_TMM", "units": "per_second", "component": "Ca_buffering"}, + {"name": "kf_CM", "units": "per_millimolar_second", "component": "Ca_buffering"}, + {"name": "kb_CM", "units": "per_second", "component": "Ca_buffering"}, + {"name": "kf_CQ", "units": "per_millimolar_second", "component": "Ca_buffering"}, + {"name": "kb_CQ", "units": "per_second", "component": "Ca_buffering"}, + {"name": "TC_tot", "units": "millimolar", "component": "Ca_buffering"}, + {"name": "TMC_tot", "units": "millimolar", "component": "Ca_buffering"}, + {"name": "CM_tot", "units": "millimolar", "component": "Ca_buffering"}, + {"name": "CQ_tot", "units": "millimolar", "component": "Ca_buffering"}, + {"name": "L_cell", "units": "micrometre", "component": "Cell_parameters"}, + {"name": "R_cell", "units": "micrometre", "component": "Cell_parameters"}, + {"name": "L_sub", "units": "micrometre", "component": "Cell_parameters"}, + {"name": "V_jsr_part", "units": "dimensionless", "component": "Cell_parameters"}, + {"name": "V_i_part", "units": "dimensionless", "component": "Cell_parameters"}, + {"name": "V_nsr_part", "units": "dimensionless", "component": "Cell_parameters"}, + {"name": "C", "units": "microF", "component": "Membrane"}, + {"name": "R", "units": "joule_per_kilomole_kelvin", "component": "Membrane"}, + {"name": "T", "units": "kelvin", "component": "Membrane"}, + {"name": "clamp_mode", "units": "dimensionless", "component": "Membrane"}, + {"name": "V_test", "units": "millivolt", "component": "Voltage_clamp"}, + {"name": "t_holding", "units": "second", "component": "Voltage_clamp"}, + {"name": "t_test", "units": "second", "component": "Voltage_clamp"}, + {"name": "V_holding", "units": "millivolt", "component": "Voltage_clamp"}, + {"name": "g_f", "units": "microS", "component": "i_f"}, + {"name": "Km_f", "units": "millimolar", "component": "i_f"}, + {"name": "alpha", "units": "dimensionless", "component": "i_f"}, + {"name": "blockade", "units": "dimensionless", "component": "i_f"}, + {"name": "y_shift", "units": "millivolt", "component": "i_f_y_gate"}, + {"name": "g_Na", "units": "microS", "component": "i_Na"}, + {"name": "g_Na_L", "units": "microS", "component": "i_Na"}, + {"name": "delta_m", "units": "millivolt", "component": "i_Na_m_gate"}, + {"name": "g_Kur", "units": "microS", "component": "i_Kur"}, + {"name": "P_CaL", "units": "nanoA_per_millimolar", "component": "i_CaL"}, + {"name": "V_dL", "units": "millivolt", "component": "i_CaL_dL_gate"}, + {"name": "k_dL", "units": "millivolt", "component": "i_CaL_dL_gate"}, + {"name": "shift_fL", "units": "millivolt", "component": "i_CaL_fL_gate"}, + {"name": "k_fL", "units": "millivolt", "component": "i_CaL_fL_gate"}, + {"name": "Km_fCa", "units": "millimolar", "component": "i_CaL_fCa_gate"}, + {"name": "alpha_fCa", "units": "per_second", "component": "i_CaL_fCa_gate"}, + {"name": "P_CaT", "units": "nanoA_per_millimolar", "component": "i_CaT"}, + {"name": "offset_fT", "units": "second", "component": "i_CaT_fT_gate"}, + {"name": "g_to", "units": "microS", "component": "i_to"}, + {"name": "g_Kr", "units": "microS", "component": "i_Kr"}, + {"name": "g_Ks_", "units": "microS", "component": "i_Ks"}, + {"name": "ACh_on", "units": "dimensionless", "component": "i_KACh"}, + {"name": "g_KACh", "units": "microS", "component": "i_KACh"} +] -STATE_INFO = [ - {"name": "Ca_sub", "units": "millimolar", "component": "Ca_dynamics", "type": VariableType.STATE}, - {"name": "Nai_", "units": "millimolar", "component": "Nai_concentration", "type": VariableType.STATE}, - {"name": "Ca_jsr", "units": "millimolar", "component": "Ca_dynamics", "type": VariableType.STATE}, - {"name": "O", "units": "dimensionless", "component": "Ca_SR_release", "type": VariableType.STATE}, - {"name": "R", "units": "dimensionless", "component": "Ca_SR_release", "type": VariableType.STATE}, - {"name": "RI", "units": "dimensionless", "component": "Ca_SR_release", "type": VariableType.STATE}, - {"name": "I", "units": "dimensionless", "component": "Ca_SR_release", "type": VariableType.STATE}, - {"name": "Cai", "units": "millimolar", "component": "Ca_dynamics", "type": VariableType.STATE}, - {"name": "Ca_nsr", "units": "millimolar", "component": "Ca_dynamics", "type": VariableType.STATE}, - {"name": "fTC", "units": "dimensionless", "component": "Ca_buffering", "type": VariableType.STATE}, - {"name": "fTMC", "units": "dimensionless", "component": "Ca_buffering", "type": VariableType.STATE}, - {"name": "fTMM", "units": "dimensionless", "component": "Ca_buffering", "type": VariableType.STATE}, - {"name": "fCMi", "units": "dimensionless", "component": "Ca_buffering", "type": VariableType.STATE}, - {"name": "fCMs", "units": "dimensionless", "component": "Ca_buffering", "type": VariableType.STATE}, - {"name": "fCQ", "units": "dimensionless", "component": "Ca_buffering", "type": VariableType.STATE}, - {"name": "V_ode", "units": "millivolt", "component": "Membrane", "type": VariableType.STATE}, - {"name": "y", "units": "dimensionless", "component": "i_f_y_gate", "type": VariableType.STATE}, - {"name": "h", "units": "dimensionless", "component": "i_Na_h_gate", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "i_Na_m_gate", "type": VariableType.STATE}, - {"name": "s_Kur", "units": "dimensionless", "component": "i_Kur_sKur_gate", "type": VariableType.STATE}, - {"name": "r_Kur", "units": "dimensionless", "component": "i_Kur_rKur_gate", "type": VariableType.STATE}, - {"name": "fCa", "units": "dimensionless", "component": "i_CaL_fCa_gate", "type": VariableType.STATE}, - {"name": "fL", "units": "dimensionless", "component": "i_CaL_fL_gate", "type": VariableType.STATE}, - {"name": "dL", "units": "dimensionless", "component": "i_CaL_dL_gate", "type": VariableType.STATE}, - {"name": "fT", "units": "dimensionless", "component": "i_CaT_fT_gate", "type": VariableType.STATE}, - {"name": "dT", "units": "dimensionless", "component": "i_CaT_dT_gate", "type": VariableType.STATE}, - {"name": "r", "units": "dimensionless", "component": "i_to_r_gate", "type": VariableType.STATE}, - {"name": "q", "units": "dimensionless", "component": "i_to_q_gate", "type": VariableType.STATE}, - {"name": "piy", "units": "dimensionless", "component": "i_Kr_pi_gate", "type": VariableType.STATE}, - {"name": "paF", "units": "dimensionless", "component": "i_Kr_pa_gate", "type": VariableType.STATE}, - {"name": "paS", "units": "dimensionless", "component": "i_Kr_pa_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "i_Ks_n_gate", "type": VariableType.STATE}, - {"name": "a", "units": "dimensionless", "component": "i_KACh_a_gate", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ + {"name": "RTONF", "units": "millivolt", "component": "Membrane"}, + {"name": "E_K", "units": "millivolt", "component": "Ionic_values"}, + {"name": "V_i", "units": "millimetre3", "component": "Cell_parameters"}, + {"name": "V_sub", "units": "millimetre3", "component": "Cell_parameters"}, + {"name": "Iso_increase", "units": "dimensionless", "component": "i_NaK"}, + {"name": "k34", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "b_up", "units": "dimensionless", "component": "Ca_intracellular_fluxes"}, + {"name": "P_up", "units": "millimolar_per_second", "component": "Ca_intracellular_fluxes"}, + {"name": "V_nsr", "units": "millimetre3", "component": "Cell_parameters"}, + {"name": "V_jsr", "units": "millimetre3", "component": "Cell_parameters"}, + {"name": "V_cell", "units": "millimetre3", "component": "Cell_parameters"}, + {"name": "G_f", "units": "microS", "component": "i_f"}, + {"name": "G_f_K", "units": "microS", "component": "i_f"}, + {"name": "G_f_Na", "units": "microS", "component": "i_f"}, + {"name": "g_f_Na", "units": "microS", "component": "i_f"}, + {"name": "g_f_K", "units": "microS", "component": "i_f"}, + {"name": "ACh_shift", "units": "millivolt", "component": "i_f_y_gate"}, + {"name": "Iso_shift", "units": "millivolt", "component": "i_f_y_gate"}, + {"name": "Iso_increase", "units": "dimensionless", "component": "i_CaL"}, + {"name": "ACh_block", "units": "dimensionless", "component": "i_CaL"}, + {"name": "Iso_shift_dL", "units": "millivolt", "component": "i_CaL_dL_gate"}, + {"name": "Iso_slope_dL", "units": "dimensionless", "component": "i_CaL_dL_gate"}, + {"name": "g_Ks", "units": "microS", "component": "i_Ks"}, + {"name": "Iso_shift", "units": "millivolt", "component": "i_Ks_n_gate"}, + {"name": "alpha_a", "units": "per_second", "component": "i_KACh_a_gate"} ] -VARIABLE_INFO = [ - {"name": "ACh", "units": "millimolar", "component": "Rate_modulation_experiments", "type": VariableType.CONSTANT}, - {"name": "Iso_1_uM", "units": "dimensionless", "component": "Rate_modulation_experiments", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "Ionic_values", "type": VariableType.ALGEBRAIC}, - {"name": "RTONF", "units": "millivolt", "component": "Membrane", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "Nao", "units": "millimolar", "component": "Ionic_values", "type": VariableType.CONSTANT}, - {"name": "Nai", "units": "millimolar", "component": "Nai_concentration", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "Ionic_values", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "Ko", "units": "millimolar", "component": "Ionic_values", "type": VariableType.CONSTANT}, - {"name": "Ki", "units": "millimolar", "component": "Ionic_values", "type": VariableType.CONSTANT}, - {"name": "E_Ca", "units": "millivolt", "component": "Ionic_values", "type": VariableType.ALGEBRAIC}, - {"name": "Cao", "units": "millimolar", "component": "Ionic_values", "type": VariableType.CONSTANT}, - {"name": "Nai_clamp", "units": "dimensionless", "component": "Nai_concentration", "type": VariableType.CONSTANT}, - {"name": "i_Na", "units": "nanoA", "component": "i_Na", "type": VariableType.ALGEBRAIC}, - {"name": "i_NaCa", "units": "nanoA", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "i_NaK", "units": "nanoA", "component": "i_NaK", "type": VariableType.ALGEBRAIC}, - {"name": "i_siNa", "units": "nanoA", "component": "i_CaL", "type": VariableType.ALGEBRAIC}, - {"name": "i_fNa", "units": "nanoA", "component": "i_f", "type": VariableType.ALGEBRAIC}, - {"name": "F", "units": "coulomb_per_mole", "component": "Membrane", "type": VariableType.CONSTANT}, - {"name": "V_i", "units": "millimetre3", "component": "Cell_parameters", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "V_sub", "units": "millimetre3", "component": "Cell_parameters", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "Iso_increase", "units": "dimensionless", "component": "i_NaK", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "V", "units": "millivolt", "component": "Membrane", "type": VariableType.ALGEBRAIC}, - {"name": "Km_Nap", "units": "millimolar", "component": "i_NaK", "type": VariableType.CONSTANT}, - {"name": "Km_Kp", "units": "millimolar", "component": "i_NaK", "type": VariableType.CONSTANT}, - {"name": "i_NaK_max", "units": "nanoA", "component": "i_NaK", "type": VariableType.CONSTANT}, - {"name": "blockade_NaCa", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "x2", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "k21", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "x1", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "k12", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "K_NaCa", "units": "nanoA", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "x4", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "x3", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "k41", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "k23", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "k34", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "k43", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "k32", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "k14", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "K3ni", "units": "millimolar", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "Kci", "units": "millimolar", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "Qci", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "di", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "K1ni", "units": "millimolar", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "K2ni", "units": "millimolar", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "Qn", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "Kcni", "units": "millimolar", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "K3no", "units": "millimolar", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "Kco", "units": "millimolar", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "Qco", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "do", "units": "dimensionless", "component": "i_NaCa", "type": VariableType.ALGEBRAIC}, - {"name": "K1no", "units": "millimolar", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "K2no", "units": "millimolar", "component": "i_NaCa", "type": VariableType.CONSTANT}, - {"name": "j_SRCarel", "units": "millimolar_per_second", "component": "Ca_SR_release", "type": VariableType.ALGEBRAIC}, - {"name": "ks", "units": "per_second", "component": "Ca_SR_release", "type": VariableType.CONSTANT}, - {"name": "diff", "units": "millimolar", "component": "Ca_SR_release", "type": VariableType.ALGEBRAIC}, - {"name": "kCaSR", "units": "dimensionless", "component": "Ca_SR_release", "type": VariableType.ALGEBRAIC}, - {"name": "MaxSR", "units": "dimensionless", "component": "Ca_SR_release", "type": VariableType.CONSTANT}, - {"name": "MinSR", "units": "dimensionless", "component": "Ca_SR_release", "type": VariableType.CONSTANT}, - {"name": "EC50_SR", "units": "millimolar", "component": "Ca_SR_release", "type": VariableType.CONSTANT}, - {"name": "HSR", "units": "dimensionless", "component": "Ca_SR_release", "type": VariableType.CONSTANT}, - {"name": "koSRCa", "units": "per_millimolar2_second", "component": "Ca_SR_release", "type": VariableType.ALGEBRAIC}, - {"name": "koCa", "units": "per_millimolar2_second", "component": "Ca_SR_release", "type": VariableType.CONSTANT}, - {"name": "kiSRCa", "units": "per_millimolar_second", "component": "Ca_SR_release", "type": VariableType.ALGEBRAIC}, - {"name": "kiCa", "units": "per_millimolar_second", "component": "Ca_SR_release", "type": VariableType.CONSTANT}, - {"name": "kim", "units": "per_second", "component": "Ca_SR_release", "type": VariableType.CONSTANT}, - {"name": "kom", "units": "per_second", "component": "Ca_SR_release", "type": VariableType.CONSTANT}, - {"name": "P_tot", "units": "dimensionless", "component": "Ca_SR_release", "type": VariableType.ALGEBRAIC}, - {"name": "b_up", "units": "dimensionless", "component": "Ca_intracellular_fluxes", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "P_up", "units": "millimolar_per_second", "component": "Ca_intracellular_fluxes", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "P_up_basal", "units": "millimolar_per_second", "component": "Ca_intracellular_fluxes", "type": VariableType.CONSTANT}, - {"name": "j_Ca_dif", "units": "millimolar_per_second", "component": "Ca_intracellular_fluxes", "type": VariableType.ALGEBRAIC}, - {"name": "tau_dif_Ca", "units": "second", "component": "Ca_intracellular_fluxes", "type": VariableType.CONSTANT}, - {"name": "j_up", "units": "millimolar_per_second", "component": "Ca_intracellular_fluxes", "type": VariableType.ALGEBRAIC}, - {"name": "K_up", "units": "millimolar", "component": "Ca_intracellular_fluxes", "type": VariableType.CONSTANT}, - {"name": "slope_up", "units": "millimolar", "component": "Ca_intracellular_fluxes", "type": VariableType.CONSTANT}, - {"name": "j_tr", "units": "millimolar_per_second", "component": "Ca_intracellular_fluxes", "type": VariableType.ALGEBRAIC}, - {"name": "tau_tr", "units": "second", "component": "Ca_intracellular_fluxes", "type": VariableType.CONSTANT}, - {"name": "delta_fTC", "units": "per_second", "component": "Ca_buffering", "type": VariableType.ALGEBRAIC}, - {"name": "kf_TC", "units": "per_millimolar_second", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "kb_TC", "units": "per_second", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "delta_fTMC", "units": "per_second", "component": "Ca_buffering", "type": VariableType.ALGEBRAIC}, - {"name": "kf_TMC", "units": "per_millimolar_second", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "kb_TMC", "units": "per_second", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "delta_fTMM", "units": "per_second", "component": "Ca_buffering", "type": VariableType.ALGEBRAIC}, - {"name": "kf_TMM", "units": "per_millimolar_second", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "Mgi", "units": "millimolar", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "kb_TMM", "units": "per_second", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "delta_fCMi", "units": "per_second", "component": "Ca_buffering", "type": VariableType.ALGEBRAIC}, - {"name": "kf_CM", "units": "per_millimolar_second", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "kb_CM", "units": "per_second", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "delta_fCMs", "units": "per_second", "component": "Ca_buffering", "type": VariableType.ALGEBRAIC}, - {"name": "delta_fCQ", "units": "per_second", "component": "Ca_buffering", "type": VariableType.ALGEBRAIC}, - {"name": "kf_CQ", "units": "per_millimolar_second", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "kb_CQ", "units": "per_second", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "TC_tot", "units": "millimolar", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "TMC_tot", "units": "millimolar", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "CM_tot", "units": "millimolar", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "CQ_tot", "units": "millimolar", "component": "Ca_buffering", "type": VariableType.CONSTANT}, - {"name": "V_nsr", "units": "millimetre3", "component": "Cell_parameters", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "V_jsr", "units": "millimetre3", "component": "Cell_parameters", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "i_siCa", "units": "nanoA", "component": "i_CaL", "type": VariableType.ALGEBRAIC}, - {"name": "i_CaT", "units": "nanoA", "component": "i_CaT", "type": VariableType.ALGEBRAIC}, - {"name": "V_cell", "units": "millimetre3", "component": "Cell_parameters", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "L_cell", "units": "micrometre", "component": "Cell_parameters", "type": VariableType.CONSTANT}, - {"name": "R_cell", "units": "micrometre", "component": "Cell_parameters", "type": VariableType.CONSTANT}, - {"name": "L_sub", "units": "micrometre", "component": "Cell_parameters", "type": VariableType.CONSTANT}, - {"name": "V_jsr_part", "units": "dimensionless", "component": "Cell_parameters", "type": VariableType.CONSTANT}, - {"name": "V_i_part", "units": "dimensionless", "component": "Cell_parameters", "type": VariableType.CONSTANT}, - {"name": "V_nsr_part", "units": "dimensionless", "component": "Cell_parameters", "type": VariableType.CONSTANT}, - {"name": "i_tot", "units": "nanoA", "component": "Membrane", "type": VariableType.ALGEBRAIC}, - {"name": "i_f", "units": "nanoA", "component": "i_f", "type": VariableType.ALGEBRAIC}, - {"name": "i_Kur", "units": "nanoA", "component": "i_Kur", "type": VariableType.ALGEBRAIC}, - {"name": "i_KACh", "units": "nanoA", "component": "i_KACh", "type": VariableType.ALGEBRAIC}, - {"name": "i_CaL", "units": "nanoA", "component": "i_CaL", "type": VariableType.ALGEBRAIC}, - {"name": "i_to", "units": "nanoA", "component": "i_to", "type": VariableType.ALGEBRAIC}, - {"name": "i_Ks", "units": "nanoA", "component": "i_Ks", "type": VariableType.ALGEBRAIC}, - {"name": "i_Kr", "units": "nanoA", "component": "i_Kr", "type": VariableType.ALGEBRAIC}, - {"name": "C", "units": "microF", "component": "Membrane", "type": VariableType.CONSTANT}, - {"name": "R", "units": "joule_per_kilomole_kelvin", "component": "Membrane", "type": VariableType.CONSTANT}, - {"name": "T", "units": "kelvin", "component": "Membrane", "type": VariableType.CONSTANT}, - {"name": "V_clamp", "units": "millivolt", "component": "Voltage_clamp", "type": VariableType.ALGEBRAIC}, - {"name": "clamp_mode", "units": "dimensionless", "component": "Membrane", "type": VariableType.CONSTANT}, - {"name": "V_test", "units": "millivolt", "component": "Voltage_clamp", "type": VariableType.CONSTANT}, - {"name": "t_holding", "units": "second", "component": "Voltage_clamp", "type": VariableType.CONSTANT}, - {"name": "t_test", "units": "second", "component": "Voltage_clamp", "type": VariableType.CONSTANT}, - {"name": "V_holding", "units": "millivolt", "component": "Voltage_clamp", "type": VariableType.CONSTANT}, - {"name": "G_f", "units": "microS", "component": "i_f", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_f", "units": "microS", "component": "i_f", "type": VariableType.CONSTANT}, - {"name": "Km_f", "units": "millimolar", "component": "i_f", "type": VariableType.CONSTANT}, - {"name": "G_f_K", "units": "microS", "component": "i_f", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "alpha", "units": "dimensionless", "component": "i_f", "type": VariableType.CONSTANT}, - {"name": "G_f_Na", "units": "microS", "component": "i_f", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_f_Na", "units": "microS", "component": "i_f", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_f_K", "units": "microS", "component": "i_f", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "blockade", "units": "dimensionless", "component": "i_f", "type": VariableType.CONSTANT}, - {"name": "i_fK", "units": "nanoA", "component": "i_f", "type": VariableType.ALGEBRAIC}, - {"name": "ACh_shift", "units": "millivolt", "component": "i_f_y_gate", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "Iso_shift", "units": "millivolt", "component": "i_f_y_gate", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "tau_y", "units": "second", "component": "i_f_y_gate", "type": VariableType.ALGEBRAIC}, - {"name": "y_infinity", "units": "dimensionless", "component": "i_f_y_gate", "type": VariableType.ALGEBRAIC}, - {"name": "y_shift", "units": "millivolt", "component": "i_f_y_gate", "type": VariableType.CONSTANT}, - {"name": "E_mh", "units": "millivolt", "component": "i_Na", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na_", "units": "nanoA", "component": "i_Na", "type": VariableType.ALGEBRAIC}, - {"name": "g_Na", "units": "microS", "component": "i_Na", "type": VariableType.CONSTANT}, - {"name": "i_Na_L", "units": "nanoA", "component": "i_Na", "type": VariableType.ALGEBRAIC}, - {"name": "g_Na_L", "units": "microS", "component": "i_Na", "type": VariableType.CONSTANT}, - {"name": "m_infinity", "units": "dimensionless", "component": "i_Na_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E0_m", "units": "millivolt", "component": "i_Na_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_m", "units": "per_second", "component": "i_Na_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "delta_m", "units": "millivolt", "component": "i_Na_m_gate", "type": VariableType.CONSTANT}, - {"name": "beta_m", "units": "per_second", "component": "i_Na_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_m", "units": "second", "component": "i_Na_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "h_infinity", "units": "dimensionless", "component": "i_Na_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_second", "component": "i_Na_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_second", "component": "i_Na_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_h", "units": "second", "component": "i_Na_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "g_Kur", "units": "microS", "component": "i_Kur", "type": VariableType.CONSTANT}, - {"name": "r_Kur_infinity", "units": "dimensionless", "component": "i_Kur_rKur_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_r_Kur", "units": "second", "component": "i_Kur_rKur_gate", "type": VariableType.ALGEBRAIC}, - {"name": "s_Kur_infinity", "units": "dimensionless", "component": "i_Kur_sKur_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_s_Kur", "units": "second", "component": "i_Kur_sKur_gate", "type": VariableType.ALGEBRAIC}, - {"name": "Iso_increase", "units": "dimensionless", "component": "i_CaL", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "P_CaL", "units": "nanoA_per_millimolar", "component": "i_CaL", "type": VariableType.CONSTANT}, - {"name": "i_siK", "units": "nanoA", "component": "i_CaL", "type": VariableType.ALGEBRAIC}, - {"name": "ACh_block", "units": "dimensionless", "component": "i_CaL", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "Iso_shift_dL", "units": "millivolt", "component": "i_CaL_dL_gate", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "Iso_slope_dL", "units": "dimensionless", "component": "i_CaL_dL_gate", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "dL_infinity", "units": "dimensionless", "component": "i_CaL_dL_gate", "type": VariableType.ALGEBRAIC}, - {"name": "V_dL", "units": "millivolt", "component": "i_CaL_dL_gate", "type": VariableType.CONSTANT}, - {"name": "k_dL", "units": "millivolt", "component": "i_CaL_dL_gate", "type": VariableType.CONSTANT}, - {"name": "tau_dL", "units": "second", "component": "i_CaL_dL_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_dL", "units": "per_second", "component": "i_CaL_dL_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_dL", "units": "per_second", "component": "i_CaL_dL_gate", "type": VariableType.ALGEBRAIC}, - {"name": "adVm", "units": "millivolt", "component": "i_CaL_dL_gate", "type": VariableType.ALGEBRAIC}, - {"name": "bdVm", "units": "millivolt", "component": "i_CaL_dL_gate", "type": VariableType.ALGEBRAIC}, - {"name": "fL_infinity", "units": "dimensionless", "component": "i_CaL_fL_gate", "type": VariableType.ALGEBRAIC}, - {"name": "shift_fL", "units": "millivolt", "component": "i_CaL_fL_gate", "type": VariableType.CONSTANT}, - {"name": "k_fL", "units": "millivolt", "component": "i_CaL_fL_gate", "type": VariableType.CONSTANT}, - {"name": "tau_fL", "units": "second", "component": "i_CaL_fL_gate", "type": VariableType.ALGEBRAIC}, - {"name": "fCa_infinity", "units": "dimensionless", "component": "i_CaL_fCa_gate", "type": VariableType.ALGEBRAIC}, - {"name": "Km_fCa", "units": "millimolar", "component": "i_CaL_fCa_gate", "type": VariableType.CONSTANT}, - {"name": "tau_fCa", "units": "second", "component": "i_CaL_fCa_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_fCa", "units": "per_second", "component": "i_CaL_fCa_gate", "type": VariableType.CONSTANT}, - {"name": "P_CaT", "units": "nanoA_per_millimolar", "component": "i_CaT", "type": VariableType.CONSTANT}, - {"name": "dT_infinity", "units": "dimensionless", "component": "i_CaT_dT_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_dT", "units": "second", "component": "i_CaT_dT_gate", "type": VariableType.ALGEBRAIC}, - {"name": "fT_infinity", "units": "dimensionless", "component": "i_CaT_fT_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_fT", "units": "second", "component": "i_CaT_fT_gate", "type": VariableType.ALGEBRAIC}, - {"name": "offset_fT", "units": "second", "component": "i_CaT_fT_gate", "type": VariableType.CONSTANT}, - {"name": "g_to", "units": "microS", "component": "i_to", "type": VariableType.CONSTANT}, - {"name": "q_infinity", "units": "dimensionless", "component": "i_to_q_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_q", "units": "second", "component": "i_to_q_gate", "type": VariableType.ALGEBRAIC}, - {"name": "r_infinity", "units": "dimensionless", "component": "i_to_r_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_r", "units": "second", "component": "i_to_r_gate", "type": VariableType.ALGEBRAIC}, - {"name": "g_Kr", "units": "microS", "component": "i_Kr", "type": VariableType.CONSTANT}, - {"name": "alfapaF", "units": "per_second", "component": "i_Kr_pa_gate", "type": VariableType.ALGEBRAIC}, - {"name": "betapaF", "units": "per_second", "component": "i_Kr_pa_gate", "type": VariableType.ALGEBRAIC}, - {"name": "pa_infinity", "units": "dimensionless", "component": "i_Kr_pa_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_paS", "units": "second", "component": "i_Kr_pa_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_paF", "units": "second", "component": "i_Kr_pa_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_pi", "units": "second", "component": "i_Kr_pi_gate", "type": VariableType.ALGEBRAIC}, - {"name": "pi_infinity", "units": "dimensionless", "component": "i_Kr_pi_gate", "type": VariableType.ALGEBRAIC}, - {"name": "g_Ks", "units": "microS", "component": "i_Ks", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Ks_", "units": "microS", "component": "i_Ks", "type": VariableType.CONSTANT}, - {"name": "E_Ks", "units": "millivolt", "component": "i_Ks", "type": VariableType.ALGEBRAIC}, - {"name": "Iso_shift", "units": "millivolt", "component": "i_Ks_n_gate", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "n_infinity", "units": "dimensionless", "component": "i_Ks_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_n", "units": "second", "component": "i_Ks_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_n", "units": "per_second", "component": "i_Ks_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_second", "component": "i_Ks_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "ACh_on", "units": "dimensionless", "component": "i_KACh", "type": VariableType.CONSTANT}, - {"name": "g_KACh", "units": "microS", "component": "i_KACh", "type": VariableType.CONSTANT}, - {"name": "alpha_a", "units": "per_second", "component": "i_KACh_a_gate", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "beta_a", "units": "per_second", "component": "i_KACh_a_gate", "type": VariableType.ALGEBRAIC}, - {"name": "a_infinity", "units": "dimensionless", "component": "i_KACh_a_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_a", "units": "second", "component": "i_KACh_a_gate", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "E_Na", "units": "millivolt", "component": "Ionic_values"}, + {"name": "Nai", "units": "millimolar", "component": "Nai_concentration"}, + {"name": "E_Ca", "units": "millivolt", "component": "Ionic_values"}, + {"name": "i_Na", "units": "nanoA", "component": "i_Na"}, + {"name": "i_NaCa", "units": "nanoA", "component": "i_NaCa"}, + {"name": "i_NaK", "units": "nanoA", "component": "i_NaK"}, + {"name": "i_siNa", "units": "nanoA", "component": "i_CaL"}, + {"name": "i_fNa", "units": "nanoA", "component": "i_f"}, + {"name": "V", "units": "millivolt", "component": "Membrane"}, + {"name": "x2", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "k21", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "x1", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "k12", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "x4", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "x3", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "k41", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "k23", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "k43", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "k32", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "k14", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "di", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "do", "units": "dimensionless", "component": "i_NaCa"}, + {"name": "j_SRCarel", "units": "millimolar_per_second", "component": "Ca_SR_release"}, + {"name": "diff", "units": "millimolar", "component": "Ca_SR_release"}, + {"name": "kCaSR", "units": "dimensionless", "component": "Ca_SR_release"}, + {"name": "koSRCa", "units": "per_millimolar2_second", "component": "Ca_SR_release"}, + {"name": "kiSRCa", "units": "per_millimolar_second", "component": "Ca_SR_release"}, + {"name": "P_tot", "units": "dimensionless", "component": "Ca_SR_release"}, + {"name": "j_Ca_dif", "units": "millimolar_per_second", "component": "Ca_intracellular_fluxes"}, + {"name": "j_up", "units": "millimolar_per_second", "component": "Ca_intracellular_fluxes"}, + {"name": "j_tr", "units": "millimolar_per_second", "component": "Ca_intracellular_fluxes"}, + {"name": "delta_fTC", "units": "per_second", "component": "Ca_buffering"}, + {"name": "delta_fTMC", "units": "per_second", "component": "Ca_buffering"}, + {"name": "delta_fTMM", "units": "per_second", "component": "Ca_buffering"}, + {"name": "delta_fCMi", "units": "per_second", "component": "Ca_buffering"}, + {"name": "delta_fCMs", "units": "per_second", "component": "Ca_buffering"}, + {"name": "delta_fCQ", "units": "per_second", "component": "Ca_buffering"}, + {"name": "i_siCa", "units": "nanoA", "component": "i_CaL"}, + {"name": "i_CaT", "units": "nanoA", "component": "i_CaT"}, + {"name": "i_tot", "units": "nanoA", "component": "Membrane"}, + {"name": "i_f", "units": "nanoA", "component": "i_f"}, + {"name": "i_Kur", "units": "nanoA", "component": "i_Kur"}, + {"name": "i_KACh", "units": "nanoA", "component": "i_KACh"}, + {"name": "i_CaL", "units": "nanoA", "component": "i_CaL"}, + {"name": "i_to", "units": "nanoA", "component": "i_to"}, + {"name": "i_Ks", "units": "nanoA", "component": "i_Ks"}, + {"name": "i_Kr", "units": "nanoA", "component": "i_Kr"}, + {"name": "V_clamp", "units": "millivolt", "component": "Voltage_clamp"}, + {"name": "i_fK", "units": "nanoA", "component": "i_f"}, + {"name": "tau_y", "units": "second", "component": "i_f_y_gate"}, + {"name": "y_infinity", "units": "dimensionless", "component": "i_f_y_gate"}, + {"name": "E_mh", "units": "millivolt", "component": "i_Na"}, + {"name": "i_Na_", "units": "nanoA", "component": "i_Na"}, + {"name": "i_Na_L", "units": "nanoA", "component": "i_Na"}, + {"name": "m_infinity", "units": "dimensionless", "component": "i_Na_m_gate"}, + {"name": "E0_m", "units": "millivolt", "component": "i_Na_m_gate"}, + {"name": "alpha_m", "units": "per_second", "component": "i_Na_m_gate"}, + {"name": "beta_m", "units": "per_second", "component": "i_Na_m_gate"}, + {"name": "tau_m", "units": "second", "component": "i_Na_m_gate"}, + {"name": "h_infinity", "units": "dimensionless", "component": "i_Na_h_gate"}, + {"name": "alpha_h", "units": "per_second", "component": "i_Na_h_gate"}, + {"name": "beta_h", "units": "per_second", "component": "i_Na_h_gate"}, + {"name": "tau_h", "units": "second", "component": "i_Na_h_gate"}, + {"name": "r_Kur_infinity", "units": "dimensionless", "component": "i_Kur_rKur_gate"}, + {"name": "tau_r_Kur", "units": "second", "component": "i_Kur_rKur_gate"}, + {"name": "s_Kur_infinity", "units": "dimensionless", "component": "i_Kur_sKur_gate"}, + {"name": "tau_s_Kur", "units": "second", "component": "i_Kur_sKur_gate"}, + {"name": "i_siK", "units": "nanoA", "component": "i_CaL"}, + {"name": "dL_infinity", "units": "dimensionless", "component": "i_CaL_dL_gate"}, + {"name": "tau_dL", "units": "second", "component": "i_CaL_dL_gate"}, + {"name": "alpha_dL", "units": "per_second", "component": "i_CaL_dL_gate"}, + {"name": "beta_dL", "units": "per_second", "component": "i_CaL_dL_gate"}, + {"name": "adVm", "units": "millivolt", "component": "i_CaL_dL_gate"}, + {"name": "bdVm", "units": "millivolt", "component": "i_CaL_dL_gate"}, + {"name": "fL_infinity", "units": "dimensionless", "component": "i_CaL_fL_gate"}, + {"name": "tau_fL", "units": "second", "component": "i_CaL_fL_gate"}, + {"name": "fCa_infinity", "units": "dimensionless", "component": "i_CaL_fCa_gate"}, + {"name": "tau_fCa", "units": "second", "component": "i_CaL_fCa_gate"}, + {"name": "dT_infinity", "units": "dimensionless", "component": "i_CaT_dT_gate"}, + {"name": "tau_dT", "units": "second", "component": "i_CaT_dT_gate"}, + {"name": "fT_infinity", "units": "dimensionless", "component": "i_CaT_fT_gate"}, + {"name": "tau_fT", "units": "second", "component": "i_CaT_fT_gate"}, + {"name": "q_infinity", "units": "dimensionless", "component": "i_to_q_gate"}, + {"name": "tau_q", "units": "second", "component": "i_to_q_gate"}, + {"name": "r_infinity", "units": "dimensionless", "component": "i_to_r_gate"}, + {"name": "tau_r", "units": "second", "component": "i_to_r_gate"}, + {"name": "alfapaF", "units": "per_second", "component": "i_Kr_pa_gate"}, + {"name": "betapaF", "units": "per_second", "component": "i_Kr_pa_gate"}, + {"name": "pa_infinity", "units": "dimensionless", "component": "i_Kr_pa_gate"}, + {"name": "tau_paS", "units": "second", "component": "i_Kr_pa_gate"}, + {"name": "tau_paF", "units": "second", "component": "i_Kr_pa_gate"}, + {"name": "tau_pi", "units": "second", "component": "i_Kr_pi_gate"}, + {"name": "pi_infinity", "units": "dimensionless", "component": "i_Kr_pi_gate"}, + {"name": "E_Ks", "units": "millivolt", "component": "i_Ks"}, + {"name": "n_infinity", "units": "dimensionless", "component": "i_Ks_n_gate"}, + {"name": "tau_n", "units": "second", "component": "i_Ks_n_gate"}, + {"name": "alpha_n", "units": "per_second", "component": "i_Ks_n_gate"}, + {"name": "beta_n", "units": "per_second", "component": "i_Ks_n_gate"}, + {"name": "beta_a", "units": "per_second", "component": "i_KACh_a_gate"}, + {"name": "a_infinity", "units": "dimensionless", "component": "i_KACh_a_gate"}, + {"name": "tau_a", "units": "second", "component": "i_KACh_a_gate"} ] @@ -302,102 +301,19 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -def initialise_variables(states, rates, variables): - variables[0] = 0.0 - variables[1] = 0.0 - variables[4] = 140.0 - variables[7] = 5.4 - variables[8] = 140.0 - variables[10] = 1.8 - variables[11] = 1.0 - variables[17] = 96485.3415 - variables[22] = 14.0 - variables[23] = 1.4 - variables[24] = 0.08105 - variables[25] = 0.0 - variables[30] = 3.343 - variables[39] = 26.44 - variables[40] = 0.0207 - variables[41] = 0.1369 - variables[43] = 395.3 - variables[44] = 2.289 - variables[45] = 0.4315 - variables[46] = 26.44 - variables[47] = 4.663 - variables[48] = 3.663 - variables[49] = 0.0 - variables[51] = 1628.0 - variables[52] = 561.4 - variables[54] = 148041085.1 - variables[57] = 15.0 - variables[58] = 1.0 - variables[59] = 0.45 - variables[60] = 2.5 - variables[62] = 10000.0 - variables[64] = 500.0 - variables[65] = 5.0 - variables[66] = 660.0 - variables[70] = 5.0 - variables[72] = 5.469e-5 - variables[74] = 0.000286113 - variables[75] = 5.0e-5 - variables[77] = 0.04 - variables[79] = 88800.0 - variables[80] = 446.0 - variables[82] = 227700.0 - variables[83] = 7.51 - variables[85] = 2277.0 - variables[86] = 2.5 - variables[87] = 751.0 - variables[89] = 1.642e6 - variables[90] = 542.0 - variables[93] = 175.4 - variables[94] = 445.0 - variables[95] = 0.031 - variables[96] = 0.062 - variables[97] = 0.045 - variables[98] = 10.0 - variables[104] = 67.0 - variables[105] = 3.9 - variables[106] = 0.02 - variables[107] = 0.0012 - variables[108] = 0.46 - variables[109] = 0.0116 - variables[118] = 5.7e-5 - variables[119] = 8314.472 - variables[120] = 310.0 - variables[122] = 0.0 - variables[123] = -35.0 - variables[124] = 0.5 - variables[125] = 0.5 - variables[126] = -45.0 - variables[128] = 0.00427 - variables[129] = 45.0 - variables[131] = 0.5927 - variables[135] = 0.0 - variables[141] = 0.0 - variables[144] = 0.0223 - variables[146] = 0.0 - variables[150] = 1.0e-5 - variables[157] = 0.1539e-3 - variables[163] = 0.4578 - variables[169] = -16.4508 - variables[170] = 4.3371 - variables[177] = 0.0 - variables[178] = 0.0 - variables[181] = 0.000338 - variables[183] = 0.0075 - variables[184] = 0.04132 - variables[189] = 0.0 - variables[190] = 3.5e-3 - variables[195] = 0.00424 - variables[204] = 0.00065 - variables[211] = 1.0 - variables[212] = 0.00345 +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 6.226104e-5 states[1] = 5.0 states[2] = 0.409551 @@ -431,266 +347,357 @@ def initialise_variables(states, rates, variables): states[30] = 0.283185 states[31] = 0.1162 states[32] = 0.00277 - - -def compute_computed_constants(variables): - variables[3] = variables[119]*variables[120]/variables[17] - variables[6] = variables[3]*log(variables[7]/variables[8]) - variables[20] = 1.2 if gt_func(variables[1], 0.0) else 1.0 - variables[35] = variables[4]/(variables[47]+variables[4]) - variables[68] = -0.25 if gt_func(variables[1], 0.0) else 0.7*variables[0]/(0.00009+variables[0]) if gt_func(variables[0], 0.0) else 0.0 - variables[69] = variables[70]*(1.0-variables[68]) - variables[103] = 0.000000001*3.14159265358979*pow(variables[105], 2.0)*variables[104] - variables[19] = 0.000000001*2.0*3.14159265358979*variables[106]*(variables[105]-variables[106]/2.0)*variables[104] - variables[100] = variables[107]*variables[103] - variables[18] = variables[108]*variables[103]-variables[19] - variables[99] = variables[109]*variables[103] - variables[127] = variables[128]/(variables[7]/(variables[7]+variables[129])) - variables[130] = variables[127]/(variables[131]+1.0) - variables[132] = variables[131]*variables[130] - variables[133] = variables[132]*variables[7]/(variables[7]+variables[129]) - variables[134] = variables[130]*variables[7]/(variables[7]+variables[129]) - variables[137] = -1.0-9.898*pow(1.0*variables[0], 0.618)/(pow(1.0*variables[0], 0.618)+0.00122423) if gt_func(variables[0], 0.0) else 0.0 - variables[138] = 7.5 if gt_func(variables[1], 0.0) else 0.0 - variables[162] = 1.23 if gt_func(variables[1], 0.0) else 1.0 - variables[165] = 0.31*variables[0]/(variables[0]+0.00009) - variables[166] = -8.0 if gt_func(variables[1], 0.0) else 0.0 - variables[167] = -27.0 if gt_func(variables[1], 0.0) else 0.0 - variables[203] = 1.2*variables[204] if gt_func(variables[1], 0.0) else variables[204] - variables[206] = -14.0 if gt_func(variables[1], 0.0) else 0.0 - variables[213] = (3.5988-0.025641)/(1.0+0.0000012155/pow(1.0*variables[0], 1.6951))+0.025641 - - -def compute_rates(voi, states, rates, variables): - variables[5] = states[1] - variables[142] = variables[3]*log((variables[4]+0.12*variables[7])/(variables[5]+0.12*variables[8])) - variables[121] = variables[123] if and_func(gt_func(voi, variables[124]), lt_func(voi, variables[124]+variables[125])) else variables[126] - variables[21] = variables[121] if geq_func(variables[122], 1.0) else states[15] - variables[143] = variables[144]*pow(states[18], 3.0)*states[17]*(variables[21]-variables[142]) - variables[145] = variables[146]*pow(states[18], 3.0)*(variables[21]-variables[142]) - variables[12] = variables[143]+variables[145] - variables[15] = 0.0000185*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)/variables[3])))*(variables[5]-variables[4]*exp(-1.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21] - variables[2] = variables[3]*log(variables[4]/variables[5]) - variables[16] = states[16]*variables[133]*(variables[21]-variables[2])*(1.0-variables[135]) - variables[14] = variables[20]*variables[24]*pow(1.0+pow(variables[23]/variables[7], 1.2), -1.0)*pow(1.0+pow(variables[22]/variables[5], 1.3), -1.0)*pow(1.0+exp(-(variables[21]-variables[2]+110.0)/20.0), -1.0) - variables[50] = 1.0+variables[10]/variables[48]*(1.0+exp(variables[49]*variables[21]/variables[3]))+variables[4]/variables[51]*(1.0+variables[4]/variables[52]*(1.0+variables[4]/variables[47])) - variables[27] = variables[10]/variables[48]*exp(variables[49]*variables[21]/variables[3])/variables[50] - variables[42] = 1.0+states[0]/variables[40]*(1.0+exp(-variables[41]*variables[21]/variables[3])+variables[5]/variables[46])+variables[5]/variables[43]*(1.0+variables[5]/variables[44]*(1.0+variables[5]/variables[39])) - variables[29] = states[0]/variables[40]*exp(-variables[41]*variables[21]/variables[3])/variables[42] - variables[36] = variables[5]/(variables[39]+variables[5]) - variables[37] = exp(variables[45]*variables[21]/(2.0*variables[3])) - variables[33] = exp(-variables[45]*variables[21]/(2.0*variables[3])) - variables[38] = variables[5]/variables[43]*variables[5]/variables[44]*(1.0+variables[5]/variables[39])*exp(variables[45]*variables[21]/(2.0*variables[3]))/variables[42] - variables[26] = variables[37]*variables[36]*(variables[38]+variables[29])+variables[33]*variables[29]*(variables[35]+variables[37]) - variables[34] = variables[4]/variables[51]*variables[4]/variables[52]*(1.0+variables[4]/variables[47])*exp(-variables[45]*variables[21]/(2.0*variables[3]))/variables[50] - variables[28] = variables[33]*variables[35]*(variables[34]+variables[27])+variables[27]*variables[37]*(variables[36]+variables[33]) - variables[31] = variables[34]*variables[35]*(variables[38]+variables[29])+variables[38]*variables[27]*(variables[35]+variables[37]) - variables[32] = variables[38]*variables[36]*(variables[34]+variables[27])+variables[29]*variables[34]*(variables[36]+variables[33]) - variables[13] = (1.0-variables[25])*variables[30]*(variables[26]*variables[27]-variables[28]*variables[29])/(variables[28]+variables[26]+variables[32]+variables[31]) - rates[1] = (1.0-variables[11])*-1.0*(variables[12]+variables[16]+variables[15]+3.0*variables[14]+3.0*variables[13])/(1.0*(variables[18]+variables[19])*variables[17]) - variables[56] = variables[57]-(variables[57]-variables[58])/(1.0+pow(variables[59]/states[2], variables[60])) - variables[63] = variables[64]*variables[56] - variables[61] = variables[62]/variables[56] - rates[4] = variables[65]*states[5]-variables[63]*states[0]*states[4]-(variables[61]*pow(states[0], 2.0)*states[4]-variables[66]*states[3]) - rates[3] = variables[61]*pow(states[0], 2.0)*states[4]-variables[66]*states[3]-(variables[63]*states[0]*states[3]-variables[65]*states[6]) - rates[6] = variables[63]*states[0]*states[3]-variables[65]*states[6]-(variables[66]*states[6]-variables[61]*pow(states[0], 2.0)*states[5]) - rates[5] = variables[66]*states[6]-variables[61]*pow(states[0], 2.0)*states[5]-(variables[65]*states[5]-variables[63]*states[0]*states[4]) - variables[78] = variables[79]*states[7]*(1.0-states[9])-variables[80]*states[9] - rates[9] = variables[78] - variables[81] = variables[82]*states[7]*(1.0-(states[10]+states[11]))-variables[83]*states[10] - rates[10] = variables[81] - variables[84] = variables[85]*variables[86]*(1.0-(states[10]+states[11]))-variables[87]*states[11] - rates[11] = variables[84] - variables[88] = variables[89]*states[7]*(1.0-states[12])-variables[90]*states[12] - rates[12] = variables[88] - variables[91] = variables[89]*states[0]*(1.0-states[13])-variables[90]*states[13] - rates[13] = variables[91] - variables[92] = variables[93]*states[2]*(1.0-states[14])-variables[94]*states[14] - rates[14] = variables[92] - variables[71] = (states[0]-states[7])/variables[72] - variables[73] = variables[69]/(1.0+exp((-states[7]+variables[74])/variables[75])) - rates[7] = 1.0*(variables[71]*variables[19]-variables[73]*variables[99])/variables[18]-(variables[97]*variables[88]+variables[95]*variables[78]+variables[96]*variables[81]) - variables[53] = variables[54]*states[3]*(states[2]-states[0]) - variables[101] = 2.0*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)*2.0/variables[3])))*(states[0]-variables[10]*exp(-2.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21] - variables[102] = 2.0*variables[184]*variables[21]/(variables[3]*(1.0-exp(-1.0*variables[21]*2.0/variables[3])))*(states[0]-variables[10]*exp(-2.0*variables[21]/variables[3]))*states[25]*states[24] - rates[0] = variables[53]*variables[100]/variables[19]-((variables[101]+variables[102]-2.0*variables[13])/(2.0*variables[17]*variables[19])+variables[71]+variables[97]*variables[91]) - variables[76] = (states[8]-states[2])/variables[77] - rates[8] = variables[73]-variables[76]*variables[100]/variables[99] - rates[2] = variables[76]-(variables[53]+variables[98]*variables[92]) - variables[136] = states[16]*variables[134]*(variables[21]-variables[6])*(1.0-variables[135]) - variables[111] = variables[16]+variables[136] - variables[112] = variables[157]*states[20]*states[19]*(variables[21]-variables[6]) - variables[113] = variables[211]*variables[212]*(variables[21]-variables[6])*(1.0+exp((variables[21]+20.0)/20.0))*states[32] if gt_func(variables[0], 0.0) else 0.0 - variables[164] = 0.000365*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)/variables[3])))*(variables[8]-variables[7]*exp(-1.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21] - variables[114] = (variables[101]+variables[164]+variables[15])*(1.0-variables[165])*1.0*variables[162] - variables[115] = variables[190]*(variables[21]-variables[6])*states[27]*states[26] - variables[205] = variables[3]*log((variables[7]+0.12*variables[4])/(variables[8]+0.12*variables[5])) - variables[116] = variables[203]*(variables[21]-variables[205])*pow(states[31], 2.0) - variables[117] = variables[195]*(variables[21]-variables[6])*(0.9*states[29]+0.1*states[30])*states[28] - variables[110] = variables[111]+variables[117]+variables[116]+variables[115]+variables[14]+variables[13]+variables[12]+variables[114]+variables[102]+variables[113]+variables[112] - rates[15] = -variables[110]/variables[118] - variables[140] = 0.01329+0.99921/(1.0+exp((variables[21]+97.134-variables[137]-variables[138]-variables[141])/8.1752)) if lt_func(variables[21], -(80.0-variables[137]-variables[138]-variables[141])) else 0.0002501*exp(-(variables[21]-variables[137]-variables[138]-variables[141])/12.861) - variables[139] = 1.0/(0.36*(variables[21]+148.8-variables[137]-variables[138])/(exp(0.066*(variables[21]+148.8-variables[137]-variables[138]))-1.0)+0.1*(variables[21]+87.3-variables[137]-variables[138])/(1.0-exp(-0.2*(variables[21]+87.3-variables[137]-variables[138]))))-0.054 - rates[16] = (variables[140]-states[16])/variables[139] - variables[147] = 1.0/(1.0+exp(-(variables[21]+42.0504)/8.3106)) - variables[148] = variables[21]+41.0 - variables[149] = 2000.0 if lt_func(fabs(variables[148]), variables[150]) else 200.0*variables[148]/(1.0-exp(-0.1*variables[148])) - variables[151] = 8000.0*exp(-0.056*(variables[21]+66.0)) - variables[152] = 1.0/(variables[149]+variables[151]) - rates[18] = (variables[147]-states[18])/variables[152] - variables[153] = 1.0/(1.0+exp((variables[21]+69.804)/4.4565)) - variables[154] = 20.0*exp(-0.125*(variables[21]+75.0)) - variables[155] = 2000.0/(320.0*exp(-0.1*(variables[21]+75.0))+1.0) - variables[156] = 1.0/(variables[154]+variables[155]) - rates[17] = (variables[153]-states[17])/variables[156] - variables[158] = 1.0/(1.0+exp((variables[21]+6.0)/-8.6)) - variables[159] = 0.009/(1.0+exp((variables[21]+5.0)/12.0))+0.0005 - rates[20] = (variables[158]-states[20])/variables[159] - variables[160] = 1.0/(1.0+exp((variables[21]+7.5)/10.0)) - variables[161] = 0.59/(1.0+exp((variables[21]+60.0)/10.0))+3.05 - rates[19] = (variables[160]-states[19])/variables[161] - variables[168] = 1.0/(1.0+exp(-(variables[21]-variables[169]-variables[166])/(variables[170]*(1.0+variables[167]/100.0)))) - variables[174] = -41.80001 if eq_func(variables[21], -41.8) else 0.0 if eq_func(variables[21], 0.0) else -6.80001 if eq_func(variables[21], -6.8) else variables[21] - variables[172] = -0.02839*(variables[174]+41.8)/(exp(-(variables[174]+41.8)/2.5)-1.0)-0.0849*(variables[174]+6.8)/(exp(-(variables[174]+6.8)/4.8)-1.0) - variables[175] = -1.80001 if eq_func(variables[21], -1.8) else variables[21] - variables[173] = 0.01143*(variables[175]+1.8)/(exp((variables[175]+1.8)/2.5)-1.0) - variables[171] = 0.001/(variables[172]+variables[173]) - rates[23] = (variables[168]-states[23])/variables[171] - variables[176] = 1.0/(1.0+exp((variables[21]+37.4+variables[177])/(5.3+variables[178]))) - variables[179] = 0.001*(44.3+230.0*exp(-pow((variables[21]+36.0)/10.0, 2.0))) - rates[22] = (variables[176]-states[22])/variables[179] - variables[180] = variables[181]/(variables[181]+states[0]) - variables[182] = 0.001*variables[180]/variables[183] - rates[21] = (variables[180]-states[21])/variables[182] - variables[185] = 1.0/(1.0+exp(-(variables[21]+38.3)/5.5)) - variables[186] = 0.001/(1.068*exp((variables[21]+38.3)/30.0)+1.068*exp(-(variables[21]+38.3)/30.0)) - rates[25] = (variables[185]-states[25])/variables[186] - variables[187] = 1.0/(1.0+exp((variables[21]+58.7)/3.8)) - variables[188] = 1.0/(16.67*exp(-(variables[21]+75.0)/83.3)+16.67*exp((variables[21]+75.0)/15.38))+variables[189] - rates[24] = (variables[187]-states[24])/variables[188] - variables[191] = 1.0/(1.0+exp((variables[21]+49.0)/13.0)) - variables[192] = 0.001*0.6*(65.17/(0.57*exp(-0.08*(variables[21]+44.0))+0.065*exp(0.1*(variables[21]+45.93)))+10.1) - rates[27] = (variables[191]-states[27])/variables[192] - variables[193] = 1.0/(1.0+exp(-(variables[21]-19.3)/15.0)) - variables[194] = 0.001*0.66*1.4*(15.59/(1.037*exp(0.09*(variables[21]+30.61))+0.369*exp(-0.12*(variables[21]+23.84)))+2.98) - rates[26] = (variables[193]-states[26])/variables[194] - variables[198] = 1.0/(1.0+exp(-(variables[21]+10.0144)/7.6607)) - variables[199] = 0.84655354/(4.2*exp(variables[21]/17.0)+0.15*exp(-variables[21]/21.6)) - rates[30] = (variables[198]-states[30])/variables[199] - variables[200] = 1.0/(30.0*exp(variables[21]/10.0)+exp(-variables[21]/12.0)) - rates[29] = (variables[198]-states[29])/variables[200] - variables[202] = 1.0/(1.0+exp((variables[21]+28.6)/17.1)) - variables[201] = 1.0/(100.0*exp(-variables[21]/54.645)+656.0*exp(variables[21]/106.157)) - rates[28] = (variables[202]-states[28])/variables[201] - variables[207] = sqrt(1.0/(1.0+exp(-(variables[21]+0.6383-variables[206])/10.7071))) - variables[209] = 28.0/(1.0+exp(-(variables[21]-40.0-variables[206])/3.0)) - variables[210] = 1.0*exp(-(variables[21]-variables[206]-5.0)/25.0) - variables[208] = 1.0/(variables[209]+variables[210]) - rates[31] = (variables[207]-states[31])/variables[208] - variables[214] = 10.0*exp(0.0133*(variables[21]+40.0)) - variables[215] = variables[213]/(variables[213]+variables[214]) - variables[216] = 1.0/(variables[213]+variables[214]) - rates[32] = (variables[215]-states[32])/variables[216] - - -def compute_variables(voi, states, rates, variables): - variables[5] = states[1] - variables[2] = variables[3]*log(variables[4]/variables[5]) - variables[9] = 0.5*variables[3]*log(variables[10]/states[0]) - variables[21] = variables[121] if geq_func(variables[122], 1.0) else states[15] - variables[14] = variables[20]*variables[24]*pow(1.0+pow(variables[23]/variables[7], 1.2), -1.0)*pow(1.0+pow(variables[22]/variables[5], 1.3), -1.0)*pow(1.0+exp(-(variables[21]-variables[2]+110.0)/20.0), -1.0) - variables[50] = 1.0+variables[10]/variables[48]*(1.0+exp(variables[49]*variables[21]/variables[3]))+variables[4]/variables[51]*(1.0+variables[4]/variables[52]*(1.0+variables[4]/variables[47])) - variables[27] = variables[10]/variables[48]*exp(variables[49]*variables[21]/variables[3])/variables[50] - variables[42] = 1.0+states[0]/variables[40]*(1.0+exp(-variables[41]*variables[21]/variables[3])+variables[5]/variables[46])+variables[5]/variables[43]*(1.0+variables[5]/variables[44]*(1.0+variables[5]/variables[39])) - variables[29] = states[0]/variables[40]*exp(-variables[41]*variables[21]/variables[3])/variables[42] - variables[36] = variables[5]/(variables[39]+variables[5]) - variables[37] = exp(variables[45]*variables[21]/(2.0*variables[3])) - variables[33] = exp(-variables[45]*variables[21]/(2.0*variables[3])) - variables[38] = variables[5]/variables[43]*variables[5]/variables[44]*(1.0+variables[5]/variables[39])*exp(variables[45]*variables[21]/(2.0*variables[3]))/variables[42] - variables[26] = variables[37]*variables[36]*(variables[38]+variables[29])+variables[33]*variables[29]*(variables[35]+variables[37]) - variables[34] = variables[4]/variables[51]*variables[4]/variables[52]*(1.0+variables[4]/variables[47])*exp(-variables[45]*variables[21]/(2.0*variables[3]))/variables[50] - variables[28] = variables[33]*variables[35]*(variables[34]+variables[27])+variables[27]*variables[37]*(variables[36]+variables[33]) - variables[31] = variables[34]*variables[35]*(variables[38]+variables[29])+variables[38]*variables[27]*(variables[35]+variables[37]) - variables[32] = variables[38]*variables[36]*(variables[34]+variables[27])+variables[29]*variables[34]*(variables[36]+variables[33]) - variables[13] = (1.0-variables[25])*variables[30]*(variables[26]*variables[27]-variables[28]*variables[29])/(variables[28]+variables[26]+variables[32]+variables[31]) - variables[53] = variables[54]*states[3]*(states[2]-states[0]) - variables[55] = states[2]-states[0] - variables[56] = variables[57]-(variables[57]-variables[58])/(1.0+pow(variables[59]/states[2], variables[60])) - variables[61] = variables[62]/variables[56] - variables[63] = variables[64]*variables[56] - variables[67] = states[4]+states[3]+states[6]+states[5] - variables[71] = (states[0]-states[7])/variables[72] - variables[73] = variables[69]/(1.0+exp((-states[7]+variables[74])/variables[75])) - variables[76] = (states[8]-states[2])/variables[77] - variables[78] = variables[79]*states[7]*(1.0-states[9])-variables[80]*states[9] - variables[81] = variables[82]*states[7]*(1.0-(states[10]+states[11]))-variables[83]*states[10] - variables[84] = variables[85]*variables[86]*(1.0-(states[10]+states[11]))-variables[87]*states[11] - variables[88] = variables[89]*states[7]*(1.0-states[12])-variables[90]*states[12] - variables[91] = variables[89]*states[0]*(1.0-states[13])-variables[90]*states[13] - variables[92] = variables[93]*states[2]*(1.0-states[14])-variables[94]*states[14] - variables[16] = states[16]*variables[133]*(variables[21]-variables[2])*(1.0-variables[135]) - variables[136] = states[16]*variables[134]*(variables[21]-variables[6])*(1.0-variables[135]) - variables[111] = variables[16]+variables[136] - variables[112] = variables[157]*states[20]*states[19]*(variables[21]-variables[6]) - variables[113] = variables[211]*variables[212]*(variables[21]-variables[6])*(1.0+exp((variables[21]+20.0)/20.0))*states[32] if gt_func(variables[0], 0.0) else 0.0 - variables[102] = 2.0*variables[184]*variables[21]/(variables[3]*(1.0-exp(-1.0*variables[21]*2.0/variables[3])))*(states[0]-variables[10]*exp(-2.0*variables[21]/variables[3]))*states[25]*states[24] - variables[101] = 2.0*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)*2.0/variables[3])))*(states[0]-variables[10]*exp(-2.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21] - variables[15] = 0.0000185*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)/variables[3])))*(variables[5]-variables[4]*exp(-1.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21] - variables[164] = 0.000365*variables[163]*(variables[21]-0.0)/(variables[3]*(1.0-exp(-1.0*(variables[21]-0.0)/variables[3])))*(variables[8]-variables[7]*exp(-1.0*(variables[21]-0.0)/variables[3]))*states[23]*states[22]*states[21] - variables[114] = (variables[101]+variables[164]+variables[15])*(1.0-variables[165])*1.0*variables[162] - variables[142] = variables[3]*log((variables[4]+0.12*variables[7])/(variables[5]+0.12*variables[8])) - variables[143] = variables[144]*pow(states[18], 3.0)*states[17]*(variables[21]-variables[142]) - variables[145] = variables[146]*pow(states[18], 3.0)*(variables[21]-variables[142]) - variables[12] = variables[143]+variables[145] - variables[115] = variables[190]*(variables[21]-variables[6])*states[27]*states[26] - variables[205] = variables[3]*log((variables[7]+0.12*variables[4])/(variables[8]+0.12*variables[5])) - variables[116] = variables[203]*(variables[21]-variables[205])*pow(states[31], 2.0) - variables[117] = variables[195]*(variables[21]-variables[6])*(0.9*states[29]+0.1*states[30])*states[28] - variables[110] = variables[111]+variables[117]+variables[116]+variables[115]+variables[14]+variables[13]+variables[12]+variables[114]+variables[102]+variables[113]+variables[112] - variables[139] = 1.0/(0.36*(variables[21]+148.8-variables[137]-variables[138])/(exp(0.066*(variables[21]+148.8-variables[137]-variables[138]))-1.0)+0.1*(variables[21]+87.3-variables[137]-variables[138])/(1.0-exp(-0.2*(variables[21]+87.3-variables[137]-variables[138]))))-0.054 - variables[140] = 0.01329+0.99921/(1.0+exp((variables[21]+97.134-variables[137]-variables[138]-variables[141])/8.1752)) if lt_func(variables[21], -(80.0-variables[137]-variables[138]-variables[141])) else 0.0002501*exp(-(variables[21]-variables[137]-variables[138]-variables[141])/12.861) - variables[147] = 1.0/(1.0+exp(-(variables[21]+42.0504)/8.3106)) - variables[148] = variables[21]+41.0 - variables[149] = 2000.0 if lt_func(fabs(variables[148]), variables[150]) else 200.0*variables[148]/(1.0-exp(-0.1*variables[148])) - variables[151] = 8000.0*exp(-0.056*(variables[21]+66.0)) - variables[152] = 1.0/(variables[149]+variables[151]) - variables[153] = 1.0/(1.0+exp((variables[21]+69.804)/4.4565)) - variables[154] = 20.0*exp(-0.125*(variables[21]+75.0)) - variables[155] = 2000.0/(320.0*exp(-0.1*(variables[21]+75.0))+1.0) - variables[156] = 1.0/(variables[154]+variables[155]) - variables[158] = 1.0/(1.0+exp((variables[21]+6.0)/-8.6)) - variables[159] = 0.009/(1.0+exp((variables[21]+5.0)/12.0))+0.0005 - variables[160] = 1.0/(1.0+exp((variables[21]+7.5)/10.0)) - variables[161] = 0.59/(1.0+exp((variables[21]+60.0)/10.0))+3.05 - variables[168] = 1.0/(1.0+exp(-(variables[21]-variables[169]-variables[166])/(variables[170]*(1.0+variables[167]/100.0)))) - variables[174] = -41.80001 if eq_func(variables[21], -41.8) else 0.0 if eq_func(variables[21], 0.0) else -6.80001 if eq_func(variables[21], -6.8) else variables[21] - variables[172] = -0.02839*(variables[174]+41.8)/(exp(-(variables[174]+41.8)/2.5)-1.0)-0.0849*(variables[174]+6.8)/(exp(-(variables[174]+6.8)/4.8)-1.0) - variables[175] = -1.80001 if eq_func(variables[21], -1.8) else variables[21] - variables[173] = 0.01143*(variables[175]+1.8)/(exp((variables[175]+1.8)/2.5)-1.0) - variables[171] = 0.001/(variables[172]+variables[173]) - variables[176] = 1.0/(1.0+exp((variables[21]+37.4+variables[177])/(5.3+variables[178]))) - variables[179] = 0.001*(44.3+230.0*exp(-pow((variables[21]+36.0)/10.0, 2.0))) - variables[180] = variables[181]/(variables[181]+states[0]) - variables[182] = 0.001*variables[180]/variables[183] - variables[185] = 1.0/(1.0+exp(-(variables[21]+38.3)/5.5)) - variables[186] = 0.001/(1.068*exp((variables[21]+38.3)/30.0)+1.068*exp(-(variables[21]+38.3)/30.0)) - variables[187] = 1.0/(1.0+exp((variables[21]+58.7)/3.8)) - variables[188] = 1.0/(16.67*exp(-(variables[21]+75.0)/83.3)+16.67*exp((variables[21]+75.0)/15.38))+variables[189] - variables[191] = 1.0/(1.0+exp((variables[21]+49.0)/13.0)) - variables[192] = 0.001*0.6*(65.17/(0.57*exp(-0.08*(variables[21]+44.0))+0.065*exp(0.1*(variables[21]+45.93)))+10.1) - variables[193] = 1.0/(1.0+exp(-(variables[21]-19.3)/15.0)) - variables[194] = 0.001*0.66*1.4*(15.59/(1.037*exp(0.09*(variables[21]+30.61))+0.369*exp(-0.12*(variables[21]+23.84)))+2.98) - variables[196] = 1.0/(1.0+exp(-(variables[21]+23.2)/6.6))/(0.84655354/(37.2*exp(variables[21]/11.9)+0.96*exp(-variables[21]/18.5))) - variables[197] = 4.0*((37.2*exp(variables[21]/15.9)+0.96*exp(-variables[21]/22.5))/0.84655354-1.0/(1.0+exp(-(variables[21]+23.2)/10.6))/(0.84655354/(37.2*exp(variables[21]/15.9)+0.96*exp(-variables[21]/22.5)))) - variables[198] = 1.0/(1.0+exp(-(variables[21]+10.0144)/7.6607)) - variables[199] = 0.84655354/(4.2*exp(variables[21]/17.0)+0.15*exp(-variables[21]/21.6)) - variables[200] = 1.0/(30.0*exp(variables[21]/10.0)+exp(-variables[21]/12.0)) - variables[201] = 1.0/(100.0*exp(-variables[21]/54.645)+656.0*exp(variables[21]/106.157)) - variables[202] = 1.0/(1.0+exp((variables[21]+28.6)/17.1)) - variables[207] = sqrt(1.0/(1.0+exp(-(variables[21]+0.6383-variables[206])/10.7071))) - variables[209] = 28.0/(1.0+exp(-(variables[21]-40.0-variables[206])/3.0)) - variables[210] = 1.0*exp(-(variables[21]-variables[206]-5.0)/25.0) - variables[208] = 1.0/(variables[209]+variables[210]) - variables[214] = 10.0*exp(0.0133*(variables[21]+40.0)) - variables[215] = variables[213]/(variables[213]+variables[214]) - variables[216] = 1.0/(variables[213]+variables[214]) + constants[0] = 0.0 + constants[1] = 0.0 + constants[2] = 140.0 + constants[3] = 5.4 + constants[4] = 140.0 + constants[5] = 1.8 + constants[6] = 1.0 + constants[7] = 96485.3415 + constants[8] = 14.0 + constants[9] = 1.4 + constants[10] = 0.08105 + constants[11] = 0.0 + constants[12] = 3.343 + constants[13] = 26.44 + constants[14] = 0.0207 + constants[15] = 0.1369 + constants[16] = 395.3 + constants[17] = 2.289 + constants[18] = 0.4315 + constants[19] = 26.44 + constants[20] = 4.663 + constants[21] = 3.663 + constants[22] = 0.0 + constants[23] = 1628.0 + constants[24] = 561.4 + constants[25] = 148041085.1 + constants[26] = 15.0 + constants[27] = 1.0 + constants[28] = 0.45 + constants[29] = 2.5 + constants[30] = 10000.0 + constants[31] = 500.0 + constants[32] = 5.0 + constants[33] = 660.0 + constants[34] = 5.0 + constants[35] = 5.469e-5 + constants[36] = 0.000286113 + constants[37] = 5.0e-5 + constants[38] = 0.04 + constants[39] = 88800.0 + constants[40] = 446.0 + constants[41] = 227700.0 + constants[42] = 7.51 + constants[43] = 2277.0 + constants[44] = 2.5 + constants[45] = 751.0 + constants[46] = 1.642e6 + constants[47] = 542.0 + constants[48] = 175.4 + constants[49] = 445.0 + constants[50] = 0.031 + constants[51] = 0.062 + constants[52] = 0.045 + constants[53] = 10.0 + constants[54] = 67.0 + constants[55] = 3.9 + constants[56] = 0.02 + constants[57] = 0.0012 + constants[58] = 0.46 + constants[59] = 0.0116 + constants[60] = 5.7e-5 + constants[61] = 8314.472 + constants[62] = 310.0 + constants[63] = 0.0 + constants[64] = -35.0 + constants[65] = 0.5 + constants[66] = 0.5 + constants[67] = -45.0 + constants[68] = 0.00427 + constants[69] = 45.0 + constants[70] = 0.5927 + constants[71] = 0.0 + constants[72] = 0.0 + constants[73] = 0.0223 + constants[74] = 0.0 + constants[75] = 1.0e-5 + constants[76] = 0.1539e-3 + constants[77] = 0.4578 + constants[78] = -16.4508 + constants[79] = 4.3371 + constants[80] = 0.0 + constants[81] = 0.0 + constants[82] = 0.000338 + constants[83] = 0.0075 + constants[84] = 0.04132 + constants[85] = 0.0 + constants[86] = 3.5e-3 + constants[87] = 0.00424 + constants[88] = 0.00065 + constants[89] = 1.0 + constants[90] = 0.00345 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[61]*constants[62]/constants[7] + computed_constants[1] = computed_constants[0]*log(constants[3]/constants[4]) + computed_constants[4] = 1.2 if gt_func(constants[1], 0.0) else 1.0 + computed_constants[5] = constants[2]/(constants[20]+constants[2]) + computed_constants[6] = -0.25 if gt_func(constants[1], 0.0) else 0.7*constants[0]/(0.00009+constants[0]) if gt_func(constants[0], 0.0) else 0.0 + computed_constants[7] = constants[34]*(1.0-computed_constants[6]) + computed_constants[10] = 0.000000001*3.14159265358979*pow(constants[55], 2.0)*constants[54] + computed_constants[3] = 0.000000001*2.0*3.14159265358979*constants[56]*(constants[55]-constants[56]/2.0)*constants[54] + computed_constants[9] = constants[57]*computed_constants[10] + computed_constants[2] = constants[58]*computed_constants[10]-computed_constants[3] + computed_constants[8] = constants[59]*computed_constants[10] + computed_constants[11] = constants[68]/(constants[3]/(constants[3]+constants[69])) + computed_constants[12] = computed_constants[11]/(constants[70]+1.0) + computed_constants[13] = constants[70]*computed_constants[12] + computed_constants[14] = computed_constants[13]*constants[3]/(constants[3]+constants[69]) + computed_constants[15] = computed_constants[12]*constants[3]/(constants[3]+constants[69]) + computed_constants[16] = -1.0-9.898*pow(1.0*constants[0], 0.618)/(pow(1.0*constants[0], 0.618)+0.00122423) if gt_func(constants[0], 0.0) else 0.0 + computed_constants[17] = 7.5 if gt_func(constants[1], 0.0) else 0.0 + computed_constants[18] = 1.23 if gt_func(constants[1], 0.0) else 1.0 + computed_constants[19] = 0.31*constants[0]/(constants[0]+0.00009) + computed_constants[20] = -8.0 if gt_func(constants[1], 0.0) else 0.0 + computed_constants[21] = -27.0 if gt_func(constants[1], 0.0) else 0.0 + computed_constants[22] = 1.2*constants[88] if gt_func(constants[1], 0.0) else constants[88] + computed_constants[23] = -14.0 if gt_func(constants[1], 0.0) else 0.0 + computed_constants[24] = (3.5988-0.025641)/(1.0+0.0000012155/pow(1.0*constants[0], 1.6951))+0.025641 + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + algebraic[1] = states[1] + algebraic[51] = computed_constants[0]*log((constants[2]+0.12*constants[3])/(algebraic[1]+0.12*constants[4])) + algebraic[47] = constants[64] if and_func(gt_func(voi, constants[65]), lt_func(voi, constants[65]+constants[66])) else constants[67] + algebraic[8] = algebraic[47] if geq_func(constants[63], 1.0) else states[15] + algebraic[52] = constants[73]*pow(states[18], 3.0)*states[17]*(algebraic[8]-algebraic[51]) + algebraic[53] = constants[74]*pow(states[18], 3.0)*(algebraic[8]-algebraic[51]) + algebraic[3] = algebraic[52]+algebraic[53] + algebraic[6] = 0.0000185*constants[77]*(algebraic[8]-0.0)/(computed_constants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)/computed_constants[0])))*(algebraic[1]-constants[2]*exp(-1.0*(algebraic[8]-0.0)/computed_constants[0]))*states[23]*states[22]*states[21] + algebraic[0] = computed_constants[0]*log(constants[2]/algebraic[1]) + algebraic[7] = states[16]*computed_constants[14]*(algebraic[8]-algebraic[0])*(1.0-constants[71]) + algebraic[5] = computed_constants[4]*constants[10]*pow(1.0+pow(constants[9]/constants[3], 1.2), -1.0)*pow(1.0+pow(constants[8]/algebraic[1], 1.3), -1.0)*pow(1.0+exp(-(algebraic[8]-algebraic[0]+110.0)/20.0), -1.0) + algebraic[21] = 1.0+constants[5]/constants[21]*(1.0+exp(constants[22]*algebraic[8]/computed_constants[0]))+constants[2]/constants[23]*(1.0+constants[2]/constants[24]*(1.0+constants[2]/constants[20])) + algebraic[10] = constants[5]/constants[21]*exp(constants[22]*algebraic[8]/computed_constants[0])/algebraic[21] + algebraic[20] = 1.0+states[0]/constants[14]*(1.0+exp(-constants[15]*algebraic[8]/computed_constants[0])+algebraic[1]/constants[19])+algebraic[1]/constants[16]*(1.0+algebraic[1]/constants[17]*(1.0+algebraic[1]/constants[13])) + algebraic[12] = states[0]/constants[14]*exp(-constants[15]*algebraic[8]/computed_constants[0])/algebraic[20] + algebraic[17] = algebraic[1]/(constants[13]+algebraic[1]) + algebraic[18] = exp(constants[18]*algebraic[8]/(2.0*computed_constants[0])) + algebraic[15] = exp(-constants[18]*algebraic[8]/(2.0*computed_constants[0])) + algebraic[19] = algebraic[1]/constants[16]*algebraic[1]/constants[17]*(1.0+algebraic[1]/constants[13])*exp(constants[18]*algebraic[8]/(2.0*computed_constants[0]))/algebraic[20] + algebraic[9] = algebraic[18]*algebraic[17]*(algebraic[19]+algebraic[12])+algebraic[15]*algebraic[12]*(computed_constants[5]+algebraic[18]) + algebraic[16] = constants[2]/constants[23]*constants[2]/constants[24]*(1.0+constants[2]/constants[20])*exp(-constants[18]*algebraic[8]/(2.0*computed_constants[0]))/algebraic[21] + algebraic[11] = algebraic[15]*computed_constants[5]*(algebraic[16]+algebraic[10])+algebraic[10]*algebraic[18]*(algebraic[17]+algebraic[15]) + algebraic[13] = algebraic[16]*computed_constants[5]*(algebraic[19]+algebraic[12])+algebraic[19]*algebraic[10]*(computed_constants[5]+algebraic[18]) + algebraic[14] = algebraic[19]*algebraic[17]*(algebraic[16]+algebraic[10])+algebraic[12]*algebraic[16]*(algebraic[17]+algebraic[15]) + algebraic[4] = (1.0-constants[11])*constants[12]*(algebraic[9]*algebraic[10]-algebraic[11]*algebraic[12])/(algebraic[11]+algebraic[9]+algebraic[14]+algebraic[13]) + rates[1] = (1.0-constants[6])*-1.0*(algebraic[3]+algebraic[7]+algebraic[6]+3.0*algebraic[5]+3.0*algebraic[4])/(1.0*(computed_constants[2]+computed_constants[3])*constants[7]) + algebraic[24] = constants[26]-(constants[26]-constants[27])/(1.0+pow(constants[28]/states[2], constants[29])) + algebraic[26] = constants[31]*algebraic[24] + algebraic[25] = constants[30]/algebraic[24] + rates[4] = constants[32]*states[5]-algebraic[26]*states[0]*states[4]-(algebraic[25]*pow(states[0], 2.0)*states[4]-constants[33]*states[3]) + rates[3] = algebraic[25]*pow(states[0], 2.0)*states[4]-constants[33]*states[3]-(algebraic[26]*states[0]*states[3]-constants[32]*states[6]) + rates[6] = algebraic[26]*states[0]*states[3]-constants[32]*states[6]-(constants[33]*states[6]-algebraic[25]*pow(states[0], 2.0)*states[5]) + rates[5] = constants[33]*states[6]-algebraic[25]*pow(states[0], 2.0)*states[5]-(constants[32]*states[5]-algebraic[26]*states[0]*states[4]) + algebraic[31] = constants[39]*states[7]*(1.0-states[9])-constants[40]*states[9] + rates[9] = algebraic[31] + algebraic[32] = constants[41]*states[7]*(1.0-(states[10]+states[11]))-constants[42]*states[10] + rates[10] = algebraic[32] + algebraic[33] = constants[43]*constants[44]*(1.0-(states[10]+states[11]))-constants[45]*states[11] + rates[11] = algebraic[33] + algebraic[34] = constants[46]*states[7]*(1.0-states[12])-constants[47]*states[12] + rates[12] = algebraic[34] + algebraic[35] = constants[46]*states[0]*(1.0-states[13])-constants[47]*states[13] + rates[13] = algebraic[35] + algebraic[36] = constants[48]*states[2]*(1.0-states[14])-constants[49]*states[14] + rates[14] = algebraic[36] + algebraic[28] = (states[0]-states[7])/constants[35] + algebraic[29] = computed_constants[7]/(1.0+exp((-states[7]+constants[36])/constants[37])) + rates[7] = 1.0*(algebraic[28]*computed_constants[3]-algebraic[29]*computed_constants[8])/computed_constants[2]-(constants[52]*algebraic[34]+constants[50]*algebraic[31]+constants[51]*algebraic[32]) + algebraic[22] = constants[25]*states[3]*(states[2]-states[0]) + algebraic[37] = 2.0*constants[77]*(algebraic[8]-0.0)/(computed_constants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)*2.0/computed_constants[0])))*(states[0]-constants[5]*exp(-2.0*(algebraic[8]-0.0)/computed_constants[0]))*states[23]*states[22]*states[21] + algebraic[38] = 2.0*constants[84]*algebraic[8]/(computed_constants[0]*(1.0-exp(-1.0*algebraic[8]*2.0/computed_constants[0])))*(states[0]-constants[5]*exp(-2.0*algebraic[8]/computed_constants[0]))*states[25]*states[24] + rates[0] = algebraic[22]*computed_constants[9]/computed_constants[3]-((algebraic[37]+algebraic[38]-2.0*algebraic[4])/(2.0*constants[7]*computed_constants[3])+algebraic[28]+constants[52]*algebraic[35]) + algebraic[30] = (states[8]-states[2])/constants[38] + rates[8] = algebraic[29]-algebraic[30]*computed_constants[9]/computed_constants[8] + rates[2] = algebraic[30]-(algebraic[22]+constants[53]*algebraic[36]) + algebraic[48] = states[16]*computed_constants[15]*(algebraic[8]-computed_constants[1])*(1.0-constants[71]) + algebraic[40] = algebraic[7]+algebraic[48] + algebraic[41] = constants[76]*states[20]*states[19]*(algebraic[8]-computed_constants[1]) + algebraic[42] = constants[89]*constants[90]*(algebraic[8]-computed_constants[1])*(1.0+exp((algebraic[8]+20.0)/20.0))*states[32] if gt_func(constants[0], 0.0) else 0.0 + algebraic[67] = 0.000365*constants[77]*(algebraic[8]-0.0)/(computed_constants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)/computed_constants[0])))*(constants[4]-constants[3]*exp(-1.0*(algebraic[8]-0.0)/computed_constants[0]))*states[23]*states[22]*states[21] + algebraic[43] = (algebraic[37]+algebraic[67]+algebraic[6])*(1.0-computed_constants[19])*1.0*computed_constants[18] + algebraic[44] = constants[86]*(algebraic[8]-computed_constants[1])*states[27]*states[26] + algebraic[93] = computed_constants[0]*log((constants[3]+0.12*constants[2])/(constants[4]+0.12*algebraic[1])) + algebraic[45] = computed_constants[22]*(algebraic[8]-algebraic[93])*pow(states[31], 2.0) + algebraic[46] = constants[87]*(algebraic[8]-computed_constants[1])*(0.9*states[29]+0.1*states[30])*states[28] + algebraic[39] = algebraic[40]+algebraic[46]+algebraic[45]+algebraic[44]+algebraic[5]+algebraic[4]+algebraic[3]+algebraic[43]+algebraic[38]+algebraic[42]+algebraic[41] + rates[15] = -algebraic[39]/constants[60] + algebraic[50] = 0.01329+0.99921/(1.0+exp((algebraic[8]+97.134-computed_constants[16]-computed_constants[17]-constants[72])/8.1752)) if lt_func(algebraic[8], -(80.0-computed_constants[16]-computed_constants[17]-constants[72])) else 0.0002501*exp(-(algebraic[8]-computed_constants[16]-computed_constants[17]-constants[72])/12.861) + algebraic[49] = 1.0/(0.36*(algebraic[8]+148.8-computed_constants[16]-computed_constants[17])/(exp(0.066*(algebraic[8]+148.8-computed_constants[16]-computed_constants[17]))-1.0)+0.1*(algebraic[8]+87.3-computed_constants[16]-computed_constants[17])/(1.0-exp(-0.2*(algebraic[8]+87.3-computed_constants[16]-computed_constants[17]))))-0.054 + rates[16] = (algebraic[50]-states[16])/algebraic[49] + algebraic[54] = 1.0/(1.0+exp(-(algebraic[8]+42.0504)/8.3106)) + algebraic[55] = algebraic[8]+41.0 + algebraic[56] = 2000.0 if lt_func(fabs(algebraic[55]), constants[75]) else 200.0*algebraic[55]/(1.0-exp(-0.1*algebraic[55])) + algebraic[57] = 8000.0*exp(-0.056*(algebraic[8]+66.0)) + algebraic[58] = 1.0/(algebraic[56]+algebraic[57]) + rates[18] = (algebraic[54]-states[18])/algebraic[58] + algebraic[59] = 1.0/(1.0+exp((algebraic[8]+69.804)/4.4565)) + algebraic[60] = 20.0*exp(-0.125*(algebraic[8]+75.0)) + algebraic[61] = 2000.0/(320.0*exp(-0.1*(algebraic[8]+75.0))+1.0) + algebraic[62] = 1.0/(algebraic[60]+algebraic[61]) + rates[17] = (algebraic[59]-states[17])/algebraic[62] + algebraic[63] = 1.0/(1.0+exp((algebraic[8]+6.0)/-8.6)) + algebraic[64] = 0.009/(1.0+exp((algebraic[8]+5.0)/12.0))+0.0005 + rates[20] = (algebraic[63]-states[20])/algebraic[64] + algebraic[65] = 1.0/(1.0+exp((algebraic[8]+7.5)/10.0)) + algebraic[66] = 0.59/(1.0+exp((algebraic[8]+60.0)/10.0))+3.05 + rates[19] = (algebraic[65]-states[19])/algebraic[66] + algebraic[68] = 1.0/(1.0+exp(-(algebraic[8]-constants[78]-computed_constants[20])/(constants[79]*(1.0+computed_constants[21]/100.0)))) + algebraic[72] = -41.80001 if eq_func(algebraic[8], -41.8) else 0.0 if eq_func(algebraic[8], 0.0) else -6.80001 if eq_func(algebraic[8], -6.8) else algebraic[8] + algebraic[70] = -0.02839*(algebraic[72]+41.8)/(exp(-(algebraic[72]+41.8)/2.5)-1.0)-0.0849*(algebraic[72]+6.8)/(exp(-(algebraic[72]+6.8)/4.8)-1.0) + algebraic[73] = -1.80001 if eq_func(algebraic[8], -1.8) else algebraic[8] + algebraic[71] = 0.01143*(algebraic[73]+1.8)/(exp((algebraic[73]+1.8)/2.5)-1.0) + algebraic[69] = 0.001/(algebraic[70]+algebraic[71]) + rates[23] = (algebraic[68]-states[23])/algebraic[69] + algebraic[74] = 1.0/(1.0+exp((algebraic[8]+37.4+constants[80])/(5.3+constants[81]))) + algebraic[75] = 0.001*(44.3+230.0*exp(-pow((algebraic[8]+36.0)/10.0, 2.0))) + rates[22] = (algebraic[74]-states[22])/algebraic[75] + algebraic[76] = constants[82]/(constants[82]+states[0]) + algebraic[77] = 0.001*algebraic[76]/constants[83] + rates[21] = (algebraic[76]-states[21])/algebraic[77] + algebraic[78] = 1.0/(1.0+exp(-(algebraic[8]+38.3)/5.5)) + algebraic[79] = 0.001/(1.068*exp((algebraic[8]+38.3)/30.0)+1.068*exp(-(algebraic[8]+38.3)/30.0)) + rates[25] = (algebraic[78]-states[25])/algebraic[79] + algebraic[80] = 1.0/(1.0+exp((algebraic[8]+58.7)/3.8)) + algebraic[81] = 1.0/(16.67*exp(-(algebraic[8]+75.0)/83.3)+16.67*exp((algebraic[8]+75.0)/15.38))+constants[85] + rates[24] = (algebraic[80]-states[24])/algebraic[81] + algebraic[82] = 1.0/(1.0+exp((algebraic[8]+49.0)/13.0)) + algebraic[83] = 0.001*0.6*(65.17/(0.57*exp(-0.08*(algebraic[8]+44.0))+0.065*exp(0.1*(algebraic[8]+45.93)))+10.1) + rates[27] = (algebraic[82]-states[27])/algebraic[83] + algebraic[84] = 1.0/(1.0+exp(-(algebraic[8]-19.3)/15.0)) + algebraic[85] = 0.001*0.66*1.4*(15.59/(1.037*exp(0.09*(algebraic[8]+30.61))+0.369*exp(-0.12*(algebraic[8]+23.84)))+2.98) + rates[26] = (algebraic[84]-states[26])/algebraic[85] + algebraic[88] = 1.0/(1.0+exp(-(algebraic[8]+10.0144)/7.6607)) + algebraic[89] = 0.84655354/(4.2*exp(algebraic[8]/17.0)+0.15*exp(-algebraic[8]/21.6)) + rates[30] = (algebraic[88]-states[30])/algebraic[89] + algebraic[90] = 1.0/(30.0*exp(algebraic[8]/10.0)+exp(-algebraic[8]/12.0)) + rates[29] = (algebraic[88]-states[29])/algebraic[90] + algebraic[92] = 1.0/(1.0+exp((algebraic[8]+28.6)/17.1)) + algebraic[91] = 1.0/(100.0*exp(-algebraic[8]/54.645)+656.0*exp(algebraic[8]/106.157)) + rates[28] = (algebraic[92]-states[28])/algebraic[91] + algebraic[94] = sqrt(1.0/(1.0+exp(-(algebraic[8]+0.6383-computed_constants[23])/10.7071))) + algebraic[96] = 28.0/(1.0+exp(-(algebraic[8]-40.0-computed_constants[23])/3.0)) + algebraic[97] = 1.0*exp(-(algebraic[8]-computed_constants[23]-5.0)/25.0) + algebraic[95] = 1.0/(algebraic[96]+algebraic[97]) + rates[31] = (algebraic[94]-states[31])/algebraic[95] + algebraic[98] = 10.0*exp(0.0133*(algebraic[8]+40.0)) + algebraic[99] = computed_constants[24]/(computed_constants[24]+algebraic[98]) + algebraic[100] = 1.0/(computed_constants[24]+algebraic[98]) + rates[32] = (algebraic[99]-states[32])/algebraic[100] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[1] = states[1] + algebraic[0] = computed_constants[0]*log(constants[2]/algebraic[1]) + algebraic[2] = 0.5*computed_constants[0]*log(constants[5]/states[0]) + algebraic[8] = algebraic[47] if geq_func(constants[63], 1.0) else states[15] + algebraic[5] = computed_constants[4]*constants[10]*pow(1.0+pow(constants[9]/constants[3], 1.2), -1.0)*pow(1.0+pow(constants[8]/algebraic[1], 1.3), -1.0)*pow(1.0+exp(-(algebraic[8]-algebraic[0]+110.0)/20.0), -1.0) + algebraic[21] = 1.0+constants[5]/constants[21]*(1.0+exp(constants[22]*algebraic[8]/computed_constants[0]))+constants[2]/constants[23]*(1.0+constants[2]/constants[24]*(1.0+constants[2]/constants[20])) + algebraic[10] = constants[5]/constants[21]*exp(constants[22]*algebraic[8]/computed_constants[0])/algebraic[21] + algebraic[20] = 1.0+states[0]/constants[14]*(1.0+exp(-constants[15]*algebraic[8]/computed_constants[0])+algebraic[1]/constants[19])+algebraic[1]/constants[16]*(1.0+algebraic[1]/constants[17]*(1.0+algebraic[1]/constants[13])) + algebraic[12] = states[0]/constants[14]*exp(-constants[15]*algebraic[8]/computed_constants[0])/algebraic[20] + algebraic[17] = algebraic[1]/(constants[13]+algebraic[1]) + algebraic[18] = exp(constants[18]*algebraic[8]/(2.0*computed_constants[0])) + algebraic[15] = exp(-constants[18]*algebraic[8]/(2.0*computed_constants[0])) + algebraic[19] = algebraic[1]/constants[16]*algebraic[1]/constants[17]*(1.0+algebraic[1]/constants[13])*exp(constants[18]*algebraic[8]/(2.0*computed_constants[0]))/algebraic[20] + algebraic[9] = algebraic[18]*algebraic[17]*(algebraic[19]+algebraic[12])+algebraic[15]*algebraic[12]*(computed_constants[5]+algebraic[18]) + algebraic[16] = constants[2]/constants[23]*constants[2]/constants[24]*(1.0+constants[2]/constants[20])*exp(-constants[18]*algebraic[8]/(2.0*computed_constants[0]))/algebraic[21] + algebraic[11] = algebraic[15]*computed_constants[5]*(algebraic[16]+algebraic[10])+algebraic[10]*algebraic[18]*(algebraic[17]+algebraic[15]) + algebraic[13] = algebraic[16]*computed_constants[5]*(algebraic[19]+algebraic[12])+algebraic[19]*algebraic[10]*(computed_constants[5]+algebraic[18]) + algebraic[14] = algebraic[19]*algebraic[17]*(algebraic[16]+algebraic[10])+algebraic[12]*algebraic[16]*(algebraic[17]+algebraic[15]) + algebraic[4] = (1.0-constants[11])*constants[12]*(algebraic[9]*algebraic[10]-algebraic[11]*algebraic[12])/(algebraic[11]+algebraic[9]+algebraic[14]+algebraic[13]) + algebraic[22] = constants[25]*states[3]*(states[2]-states[0]) + algebraic[23] = states[2]-states[0] + algebraic[24] = constants[26]-(constants[26]-constants[27])/(1.0+pow(constants[28]/states[2], constants[29])) + algebraic[25] = constants[30]/algebraic[24] + algebraic[26] = constants[31]*algebraic[24] + algebraic[27] = states[4]+states[3]+states[6]+states[5] + algebraic[28] = (states[0]-states[7])/constants[35] + algebraic[29] = computed_constants[7]/(1.0+exp((-states[7]+constants[36])/constants[37])) + algebraic[30] = (states[8]-states[2])/constants[38] + algebraic[31] = constants[39]*states[7]*(1.0-states[9])-constants[40]*states[9] + algebraic[32] = constants[41]*states[7]*(1.0-(states[10]+states[11]))-constants[42]*states[10] + algebraic[33] = constants[43]*constants[44]*(1.0-(states[10]+states[11]))-constants[45]*states[11] + algebraic[34] = constants[46]*states[7]*(1.0-states[12])-constants[47]*states[12] + algebraic[35] = constants[46]*states[0]*(1.0-states[13])-constants[47]*states[13] + algebraic[36] = constants[48]*states[2]*(1.0-states[14])-constants[49]*states[14] + algebraic[7] = states[16]*computed_constants[14]*(algebraic[8]-algebraic[0])*(1.0-constants[71]) + algebraic[48] = states[16]*computed_constants[15]*(algebraic[8]-computed_constants[1])*(1.0-constants[71]) + algebraic[40] = algebraic[7]+algebraic[48] + algebraic[41] = constants[76]*states[20]*states[19]*(algebraic[8]-computed_constants[1]) + algebraic[42] = constants[89]*constants[90]*(algebraic[8]-computed_constants[1])*(1.0+exp((algebraic[8]+20.0)/20.0))*states[32] if gt_func(constants[0], 0.0) else 0.0 + algebraic[38] = 2.0*constants[84]*algebraic[8]/(computed_constants[0]*(1.0-exp(-1.0*algebraic[8]*2.0/computed_constants[0])))*(states[0]-constants[5]*exp(-2.0*algebraic[8]/computed_constants[0]))*states[25]*states[24] + algebraic[37] = 2.0*constants[77]*(algebraic[8]-0.0)/(computed_constants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)*2.0/computed_constants[0])))*(states[0]-constants[5]*exp(-2.0*(algebraic[8]-0.0)/computed_constants[0]))*states[23]*states[22]*states[21] + algebraic[6] = 0.0000185*constants[77]*(algebraic[8]-0.0)/(computed_constants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)/computed_constants[0])))*(algebraic[1]-constants[2]*exp(-1.0*(algebraic[8]-0.0)/computed_constants[0]))*states[23]*states[22]*states[21] + algebraic[67] = 0.000365*constants[77]*(algebraic[8]-0.0)/(computed_constants[0]*(1.0-exp(-1.0*(algebraic[8]-0.0)/computed_constants[0])))*(constants[4]-constants[3]*exp(-1.0*(algebraic[8]-0.0)/computed_constants[0]))*states[23]*states[22]*states[21] + algebraic[43] = (algebraic[37]+algebraic[67]+algebraic[6])*(1.0-computed_constants[19])*1.0*computed_constants[18] + algebraic[51] = computed_constants[0]*log((constants[2]+0.12*constants[3])/(algebraic[1]+0.12*constants[4])) + algebraic[52] = constants[73]*pow(states[18], 3.0)*states[17]*(algebraic[8]-algebraic[51]) + algebraic[53] = constants[74]*pow(states[18], 3.0)*(algebraic[8]-algebraic[51]) + algebraic[3] = algebraic[52]+algebraic[53] + algebraic[44] = constants[86]*(algebraic[8]-computed_constants[1])*states[27]*states[26] + algebraic[93] = computed_constants[0]*log((constants[3]+0.12*constants[2])/(constants[4]+0.12*algebraic[1])) + algebraic[45] = computed_constants[22]*(algebraic[8]-algebraic[93])*pow(states[31], 2.0) + algebraic[46] = constants[87]*(algebraic[8]-computed_constants[1])*(0.9*states[29]+0.1*states[30])*states[28] + algebraic[39] = algebraic[40]+algebraic[46]+algebraic[45]+algebraic[44]+algebraic[5]+algebraic[4]+algebraic[3]+algebraic[43]+algebraic[38]+algebraic[42]+algebraic[41] + algebraic[49] = 1.0/(0.36*(algebraic[8]+148.8-computed_constants[16]-computed_constants[17])/(exp(0.066*(algebraic[8]+148.8-computed_constants[16]-computed_constants[17]))-1.0)+0.1*(algebraic[8]+87.3-computed_constants[16]-computed_constants[17])/(1.0-exp(-0.2*(algebraic[8]+87.3-computed_constants[16]-computed_constants[17]))))-0.054 + algebraic[50] = 0.01329+0.99921/(1.0+exp((algebraic[8]+97.134-computed_constants[16]-computed_constants[17]-constants[72])/8.1752)) if lt_func(algebraic[8], -(80.0-computed_constants[16]-computed_constants[17]-constants[72])) else 0.0002501*exp(-(algebraic[8]-computed_constants[16]-computed_constants[17]-constants[72])/12.861) + algebraic[54] = 1.0/(1.0+exp(-(algebraic[8]+42.0504)/8.3106)) + algebraic[55] = algebraic[8]+41.0 + algebraic[56] = 2000.0 if lt_func(fabs(algebraic[55]), constants[75]) else 200.0*algebraic[55]/(1.0-exp(-0.1*algebraic[55])) + algebraic[57] = 8000.0*exp(-0.056*(algebraic[8]+66.0)) + algebraic[58] = 1.0/(algebraic[56]+algebraic[57]) + algebraic[59] = 1.0/(1.0+exp((algebraic[8]+69.804)/4.4565)) + algebraic[60] = 20.0*exp(-0.125*(algebraic[8]+75.0)) + algebraic[61] = 2000.0/(320.0*exp(-0.1*(algebraic[8]+75.0))+1.0) + algebraic[62] = 1.0/(algebraic[60]+algebraic[61]) + algebraic[63] = 1.0/(1.0+exp((algebraic[8]+6.0)/-8.6)) + algebraic[64] = 0.009/(1.0+exp((algebraic[8]+5.0)/12.0))+0.0005 + algebraic[65] = 1.0/(1.0+exp((algebraic[8]+7.5)/10.0)) + algebraic[66] = 0.59/(1.0+exp((algebraic[8]+60.0)/10.0))+3.05 + algebraic[68] = 1.0/(1.0+exp(-(algebraic[8]-constants[78]-computed_constants[20])/(constants[79]*(1.0+computed_constants[21]/100.0)))) + algebraic[72] = -41.80001 if eq_func(algebraic[8], -41.8) else 0.0 if eq_func(algebraic[8], 0.0) else -6.80001 if eq_func(algebraic[8], -6.8) else algebraic[8] + algebraic[70] = -0.02839*(algebraic[72]+41.8)/(exp(-(algebraic[72]+41.8)/2.5)-1.0)-0.0849*(algebraic[72]+6.8)/(exp(-(algebraic[72]+6.8)/4.8)-1.0) + algebraic[73] = -1.80001 if eq_func(algebraic[8], -1.8) else algebraic[8] + algebraic[71] = 0.01143*(algebraic[73]+1.8)/(exp((algebraic[73]+1.8)/2.5)-1.0) + algebraic[69] = 0.001/(algebraic[70]+algebraic[71]) + algebraic[74] = 1.0/(1.0+exp((algebraic[8]+37.4+constants[80])/(5.3+constants[81]))) + algebraic[75] = 0.001*(44.3+230.0*exp(-pow((algebraic[8]+36.0)/10.0, 2.0))) + algebraic[76] = constants[82]/(constants[82]+states[0]) + algebraic[77] = 0.001*algebraic[76]/constants[83] + algebraic[78] = 1.0/(1.0+exp(-(algebraic[8]+38.3)/5.5)) + algebraic[79] = 0.001/(1.068*exp((algebraic[8]+38.3)/30.0)+1.068*exp(-(algebraic[8]+38.3)/30.0)) + algebraic[80] = 1.0/(1.0+exp((algebraic[8]+58.7)/3.8)) + algebraic[81] = 1.0/(16.67*exp(-(algebraic[8]+75.0)/83.3)+16.67*exp((algebraic[8]+75.0)/15.38))+constants[85] + algebraic[82] = 1.0/(1.0+exp((algebraic[8]+49.0)/13.0)) + algebraic[83] = 0.001*0.6*(65.17/(0.57*exp(-0.08*(algebraic[8]+44.0))+0.065*exp(0.1*(algebraic[8]+45.93)))+10.1) + algebraic[84] = 1.0/(1.0+exp(-(algebraic[8]-19.3)/15.0)) + algebraic[85] = 0.001*0.66*1.4*(15.59/(1.037*exp(0.09*(algebraic[8]+30.61))+0.369*exp(-0.12*(algebraic[8]+23.84)))+2.98) + algebraic[86] = 1.0/(1.0+exp(-(algebraic[8]+23.2)/6.6))/(0.84655354/(37.2*exp(algebraic[8]/11.9)+0.96*exp(-algebraic[8]/18.5))) + algebraic[87] = 4.0*((37.2*exp(algebraic[8]/15.9)+0.96*exp(-algebraic[8]/22.5))/0.84655354-1.0/(1.0+exp(-(algebraic[8]+23.2)/10.6))/(0.84655354/(37.2*exp(algebraic[8]/15.9)+0.96*exp(-algebraic[8]/22.5)))) + algebraic[88] = 1.0/(1.0+exp(-(algebraic[8]+10.0144)/7.6607)) + algebraic[89] = 0.84655354/(4.2*exp(algebraic[8]/17.0)+0.15*exp(-algebraic[8]/21.6)) + algebraic[90] = 1.0/(30.0*exp(algebraic[8]/10.0)+exp(-algebraic[8]/12.0)) + algebraic[91] = 1.0/(100.0*exp(-algebraic[8]/54.645)+656.0*exp(algebraic[8]/106.157)) + algebraic[92] = 1.0/(1.0+exp((algebraic[8]+28.6)/17.1)) + algebraic[94] = sqrt(1.0/(1.0+exp(-(algebraic[8]+0.6383-computed_constants[23])/10.7071))) + algebraic[96] = 28.0/(1.0+exp(-(algebraic[8]-40.0-computed_constants[23])/3.0)) + algebraic[97] = 1.0*exp(-(algebraic[8]-computed_constants[23]-5.0)/25.0) + algebraic[95] = 1.0/(algebraic[96]+algebraic[97]) + algebraic[98] = 10.0*exp(0.0133*(algebraic[8]+40.0)) + algebraic[99] = computed_constants[24]/(computed_constants[24]+algebraic[98]) + algebraic[100] = 1.0/(computed_constants[24]+algebraic[98]) diff --git a/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.c b/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.c index d1c26aa57c..f194f0cb24 100644 --- a/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.c +++ b/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.c @@ -5,218 +5,226 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 15; -const size_t VARIABLE_COUNT = 185; +const size_t CONSTANT_COUNT = 110; +const size_t COMPUTED_CONSTANT_COUNT = 23; +const size_t ALGEBRAIC_COUNT = 52; -const VariableInfo VOI_INFO = {"time", "second", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"time", "second", "environment"}; const VariableInfo STATE_INFO[] = { - {"V", "millivolt", "membrane", STATE}, - {"m", "dimensionless", "sodium_current_m_gate", STATE}, - {"h1", "dimensionless", "sodium_current_h_gate", STATE}, - {"h2", "dimensionless", "sodium_current_h_gate", STATE}, - {"f_L", "dimensionless", "L_type_Ca_channel_f_gate", STATE}, - {"d_L", "dimensionless", "L_type_Ca_channel_d_gate", STATE}, - {"f_T", "dimensionless", "T_type_Ca_channel_f_gate", STATE}, - {"d_T", "dimensionless", "T_type_Ca_channel_d_gate", STATE}, - {"r", "dimensionless", "four_AP_sensitive_currents_r_gate", STATE}, - {"q", "dimensionless", "four_AP_sensitive_currents_q_gate", STATE}, - {"P_i", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_i_gate", STATE}, - {"P_af", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_af_gate", STATE}, - {"P_as", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_as_gate", STATE}, - {"xs", "dimensionless", "slow_delayed_rectifying_potassium_current_xs_gate", STATE}, - {"y", "dimensionless", "hyperpolarisation_activated_current_y_gate", STATE} + {"V", "millivolt", "membrane"}, + {"m", "dimensionless", "sodium_current_m_gate"}, + {"h1", "dimensionless", "sodium_current_h_gate"}, + {"h2", "dimensionless", "sodium_current_h_gate"}, + {"f_L", "dimensionless", "L_type_Ca_channel_f_gate"}, + {"d_L", "dimensionless", "L_type_Ca_channel_d_gate"}, + {"f_T", "dimensionless", "T_type_Ca_channel_f_gate"}, + {"d_T", "dimensionless", "T_type_Ca_channel_d_gate"}, + {"r", "dimensionless", "four_AP_sensitive_currents_r_gate"}, + {"q", "dimensionless", "four_AP_sensitive_currents_q_gate"}, + {"P_i", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_i_gate"}, + {"P_af", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_af_gate"}, + {"P_as", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_as_gate"}, + {"xs", "dimensionless", "slow_delayed_rectifying_potassium_current_xs_gate"}, + {"y", "dimensionless", "hyperpolarisation_activated_current_y_gate"} }; -const VariableInfo VARIABLE_INFO[] = { - {"FCell", "dimensionless", "membrane", COMPUTED_CONSTANT}, - {"dCell", "dimensionless", "membrane", CONSTANT}, - {"Version", "dimensionless", "membrane", CONSTANT}, - {"FCellConstant", "dimensionless", "membrane", CONSTANT}, - {"Cm", "microF", "membrane", COMPUTED_CONSTANT}, - {"CmCentre", "microF", "membrane", CONSTANT}, - {"CmPeriphery", "microF", "membrane", CONSTANT}, - {"i_Na", "nanoA", "sodium_current", ALGEBRAIC}, - {"i_Ca_p", "nanoA", "persistent_calcium_current", COMPUTED_CONSTANT}, - {"i_p", "nanoA", "sodium_potassium_pump", ALGEBRAIC}, - {"i_NaCa", "nanoA", "sodium_calcium_exchanger", ALGEBRAIC}, - {"i_b_K", "nanoA", "potassium_background_current", ALGEBRAIC}, - {"i_b_Ca", "nanoA", "calcium_background_current", ALGEBRAIC}, - {"i_b_Na", "nanoA", "sodium_background_current", ALGEBRAIC}, - {"i_f_K", "nanoA", "hyperpolarisation_activated_current", ALGEBRAIC}, - {"i_f_Na", "nanoA", "hyperpolarisation_activated_current", ALGEBRAIC}, - {"i_K_s", "nanoA", "slow_delayed_rectifying_potassium_current", ALGEBRAIC}, - {"i_K_r", "nanoA", "rapid_delayed_rectifying_potassium_current", ALGEBRAIC}, - {"i_sus", "nanoA", "four_AP_sensitive_currents", ALGEBRAIC}, - {"i_to", "nanoA", "four_AP_sensitive_currents", ALGEBRAIC}, - {"i_Ca_T", "nanoA", "T_type_Ca_channel", ALGEBRAIC}, - {"i_Ca_L", "nanoA", "L_type_Ca_channel", ALGEBRAIC}, - {"R", "millijoule_per_mole_kelvin", "membrane", CONSTANT}, - {"T", "kelvin", "membrane", CONSTANT}, - {"F", "coulomb_per_mole", "membrane", CONSTANT}, - {"g_b_Na", "microS", "sodium_background_current", COMPUTED_CONSTANT}, - {"g_b_Na_Centre_Published", "microS", "sodium_background_current", CONSTANT}, - {"g_b_Na_Periphery_Published", "microS", "sodium_background_current", CONSTANT}, - {"g_b_Na_Centre_1DCapable", "microS", "sodium_background_current", CONSTANT}, - {"g_b_Na_Periphery_1DCapable", "microS", "sodium_background_current", CONSTANT}, - {"g_b_Na_Centre_0DCapable", "microS", "sodium_background_current", CONSTANT}, - {"g_b_Na_Periphery_0DCapable", "microS", "sodium_background_current", CONSTANT}, - {"E_Na", "millivolt", "reversal_and_equilibrium_potentials", COMPUTED_CONSTANT}, - {"g_b_K", "microS", "potassium_background_current", COMPUTED_CONSTANT}, - {"g_b_K_Centre_Published", "microS", "potassium_background_current", CONSTANT}, - {"g_b_K_Periphery_Published", "microS", "potassium_background_current", CONSTANT}, - {"g_b_K_Centre_1DCapable", "microS", "potassium_background_current", CONSTANT}, - {"g_b_K_Periphery_1DCapable", "microS", "potassium_background_current", CONSTANT}, - {"g_b_K_Centre_0DCapable", "microS", "potassium_background_current", CONSTANT}, - {"g_b_K_Periphery_0DCapable", "microS", "potassium_background_current", CONSTANT}, - {"E_K", "millivolt", "reversal_and_equilibrium_potentials", COMPUTED_CONSTANT}, - {"g_b_Ca", "microS", "calcium_background_current", COMPUTED_CONSTANT}, - {"g_b_Ca_Centre_Published", "microS", "calcium_background_current", CONSTANT}, - {"g_b_Ca_Periphery_Published", "microS", "calcium_background_current", CONSTANT}, - {"g_b_Ca_Centre_1DCapable", "microS", "calcium_background_current", CONSTANT}, - {"g_b_Ca_Periphery_1DCapable", "microS", "calcium_background_current", CONSTANT}, - {"g_b_Ca_Centre_0DCapable", "microS", "calcium_background_current", CONSTANT}, - {"g_b_Ca_Periphery_0DCapable", "microS", "calcium_background_current", CONSTANT}, - {"E_Ca", "millivolt", "reversal_and_equilibrium_potentials", COMPUTED_CONSTANT}, - {"k_NaCa", "nanoA", "sodium_calcium_exchanger", COMPUTED_CONSTANT}, - {"k_NaCa_Centre_Published", "nanoA", "sodium_calcium_exchanger", CONSTANT}, - {"k_NaCa_Periphery_Published", "nanoA", "sodium_calcium_exchanger", CONSTANT}, - {"k_NaCa_Centre_1DCapable", "nanoA", "sodium_calcium_exchanger", CONSTANT}, - {"k_NaCa_Periphery_1DCapable", "nanoA", "sodium_calcium_exchanger", CONSTANT}, - {"k_NaCa_Centre_0DCapable", "nanoA", "sodium_calcium_exchanger", CONSTANT}, - {"k_NaCa_Periphery_0DCapable", "nanoA", "sodium_calcium_exchanger", CONSTANT}, - {"Na_i", "millimolar", "ionic_concentrations", CONSTANT}, - {"gamma_NaCa", "dimensionless", "sodium_calcium_exchanger", CONSTANT}, - {"Ca_o", "millimolar", "ionic_concentrations", CONSTANT}, - {"Na_o", "millimolar", "ionic_concentrations", CONSTANT}, - {"Ca_i", "millimolar", "ionic_concentrations", CONSTANT}, - {"d_NaCa", "dimensionless", "sodium_calcium_exchanger", CONSTANT}, - {"i_p_max", "nanoA", "sodium_potassium_pump", COMPUTED_CONSTANT}, - {"i_p_max_Centre_Published", "nanoA", "sodium_potassium_pump", CONSTANT}, - {"i_p_max_Periphery_Published", "nanoA", "sodium_potassium_pump", CONSTANT}, - {"i_p_max_Centre_1DCapable", "nanoA", "sodium_potassium_pump", CONSTANT}, - {"i_p_max_Periphery_1DCapable", "nanoA", "sodium_potassium_pump", CONSTANT}, - {"i_p_max_Centre_0DCapable", "nanoA", "sodium_potassium_pump", CONSTANT}, - {"i_p_max_Periphery_0DCapable", "nanoA", "sodium_potassium_pump", CONSTANT}, - {"K_o", "millimolar", "ionic_concentrations", CONSTANT}, - {"K_m_K", "millimolar", "sodium_potassium_pump", CONSTANT}, - {"K_m_Na", "millimolar", "sodium_potassium_pump", CONSTANT}, - {"i_Ca_p_max", "nanoA", "persistent_calcium_current", COMPUTED_CONSTANT}, - {"i_Ca_p_max_Centre_Published", "nanoA", "persistent_calcium_current", CONSTANT}, - {"i_Ca_p_max_Periphery_Published", "nanoA", "persistent_calcium_current", CONSTANT}, - {"i_Ca_p_max_Centre_1DCapable", "nanoA", "persistent_calcium_current", CONSTANT}, - {"i_Ca_p_max_Periphery_1DCapable", "nanoA", "persistent_calcium_current", CONSTANT}, - {"i_Ca_p_max_Centre_0DCapable", "nanoA", "persistent_calcium_current", CONSTANT}, - {"i_Ca_p_max_Periphery_0DCapable", "nanoA", "persistent_calcium_current", CONSTANT}, - {"K_i", "millimolar", "ionic_concentrations", CONSTANT}, - {"E_K_s", "millivolt", "reversal_and_equilibrium_potentials", COMPUTED_CONSTANT}, - {"g_Na", "microlitre_per_second", "sodium_current", COMPUTED_CONSTANT}, - {"g_Na_Centre_Published", "microlitre_per_second", "sodium_current", CONSTANT}, - {"g_Na_Periphery_Published", "microlitre_per_second", "sodium_current", CONSTANT}, - {"g_Na_Centre_1DCapable", "microlitre_per_second", "sodium_current", CONSTANT}, - {"g_Na_Periphery_1DCapable", "microlitre_per_second", "sodium_current", CONSTANT}, - {"g_Na_Centre_0DCapable", "microlitre_per_second", "sodium_current", CONSTANT}, - {"g_Na_Periphery_0DCapable", "microlitre_per_second", "sodium_current", CONSTANT}, - {"h", "dimensionless", "sodium_current_h_gate", ALGEBRAIC}, - {"m_infinity", "dimensionless", "sodium_current_m_gate", ALGEBRAIC}, - {"tau_m", "second", "sodium_current_m_gate", ALGEBRAIC}, - {"F_Na", "dimensionless", "sodium_current_h_gate", ALGEBRAIC}, - {"h1_infinity", "dimensionless", "sodium_current_h_gate", ALGEBRAIC}, - {"tau_h1", "second", "sodium_current_h_gate", ALGEBRAIC}, - {"h2_infinity", "dimensionless", "sodium_current_h_gate", ALGEBRAIC}, - {"tau_h2", "second", "sodium_current_h_gate", ALGEBRAIC}, - {"g_Ca_L", "microS", "L_type_Ca_channel", COMPUTED_CONSTANT}, - {"g_Ca_L_Centre_Published", "microS", "L_type_Ca_channel", CONSTANT}, - {"g_Ca_L_Periphery_Published", "microS", "L_type_Ca_channel", CONSTANT}, - {"g_Ca_L_Centre_1DCapable", "microS", "L_type_Ca_channel", CONSTANT}, - {"g_Ca_L_Periphery_1DCapable", "microS", "L_type_Ca_channel", CONSTANT}, - {"g_Ca_L_Centre_0DCapable", "microS", "L_type_Ca_channel", CONSTANT}, - {"g_Ca_L_Periphery_0DCapable", "microS", "L_type_Ca_channel", CONSTANT}, - {"E_Ca_L", "millivolt", "L_type_Ca_channel", CONSTANT}, - {"d_L_infinity", "dimensionless", "L_type_Ca_channel_d_gate", ALGEBRAIC}, - {"tau_d_L", "second", "L_type_Ca_channel_d_gate", ALGEBRAIC}, - {"alpha_d_L", "per_second", "L_type_Ca_channel_d_gate", ALGEBRAIC}, - {"beta_d_L", "per_second", "L_type_Ca_channel_d_gate", ALGEBRAIC}, - {"f_L_infinity", "dimensionless", "L_type_Ca_channel_f_gate", ALGEBRAIC}, - {"tau_f_L", "second", "L_type_Ca_channel_f_gate", ALGEBRAIC}, - {"alpha_f_L", "per_second", "L_type_Ca_channel_f_gate", ALGEBRAIC}, - {"beta_f_L", "per_second", "L_type_Ca_channel_f_gate", ALGEBRAIC}, - {"g_Ca_T", "microS", "T_type_Ca_channel", COMPUTED_CONSTANT}, - {"g_Ca_T_Centre_Published", "microS", "T_type_Ca_channel", CONSTANT}, - {"g_Ca_T_Periphery_Published", "microS", "T_type_Ca_channel", CONSTANT}, - {"g_Ca_T_Centre_1DCapable", "microS", "T_type_Ca_channel", CONSTANT}, - {"g_Ca_T_Periphery_1DCapable", "microS", "T_type_Ca_channel", CONSTANT}, - {"g_Ca_T_Centre_0DCapable", "microS", "T_type_Ca_channel", CONSTANT}, - {"g_Ca_T_Periphery_0DCapable", "microS", "T_type_Ca_channel", CONSTANT}, - {"E_Ca_T", "millivolt", "T_type_Ca_channel", CONSTANT}, - {"d_T_infinity", "dimensionless", "T_type_Ca_channel_d_gate", ALGEBRAIC}, - {"tau_d_T", "second", "T_type_Ca_channel_d_gate", ALGEBRAIC}, - {"alpha_d_T", "per_second", "T_type_Ca_channel_d_gate", ALGEBRAIC}, - {"beta_d_T", "per_second", "T_type_Ca_channel_d_gate", ALGEBRAIC}, - {"f_T_infinity", "dimensionless", "T_type_Ca_channel_f_gate", ALGEBRAIC}, - {"tau_f_T", "second", "T_type_Ca_channel_f_gate", ALGEBRAIC}, - {"alpha_f_T", "per_second", "T_type_Ca_channel_f_gate", ALGEBRAIC}, - {"beta_f_T", "per_second", "T_type_Ca_channel_f_gate", ALGEBRAIC}, - {"g_to", "microS", "four_AP_sensitive_currents", COMPUTED_CONSTANT}, - {"g_to_Centre_Published", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"g_to_Periphery_Published", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"g_to_Centre_1DCapable", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"g_to_Periphery_1DCapable", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"g_to_Centre_0DCapable", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"g_to_Periphery_0DCapable", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"g_sus", "microS", "four_AP_sensitive_currents", COMPUTED_CONSTANT}, - {"g_sus_Centre_Published", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"g_sus_Periphery_Published", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"g_sus_Centre_1DCapable", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"g_sus_Periphery_1DCapable", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"g_sus_Centre_0DCapable", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"g_sus_Periphery_0DCapable", "microS", "four_AP_sensitive_currents", CONSTANT}, - {"q_infinity", "dimensionless", "four_AP_sensitive_currents_q_gate", ALGEBRAIC}, - {"tau_q", "second", "four_AP_sensitive_currents_q_gate", ALGEBRAIC}, - {"r_infinity", "dimensionless", "four_AP_sensitive_currents_r_gate", ALGEBRAIC}, - {"tau_r", "second", "four_AP_sensitive_currents_r_gate", ALGEBRAIC}, - {"g_K_r", "microS", "rapid_delayed_rectifying_potassium_current", COMPUTED_CONSTANT}, - {"g_K_r_Centre_Published", "microS", "rapid_delayed_rectifying_potassium_current", CONSTANT}, - {"g_K_r_Periphery_Published", "microS", "rapid_delayed_rectifying_potassium_current", CONSTANT}, - {"g_K_r_Centre_1DCapable", "microS", "rapid_delayed_rectifying_potassium_current", CONSTANT}, - {"g_K_r_Periphery_1DCapable", "microS", "rapid_delayed_rectifying_potassium_current", CONSTANT}, - {"g_K_r_Centre_0DCapable", "microS", "rapid_delayed_rectifying_potassium_current", CONSTANT}, - {"g_K_r_Periphery_0DCapable", "microS", "rapid_delayed_rectifying_potassium_current", CONSTANT}, - {"P_a", "dimensionless", "rapid_delayed_rectifying_potassium_current", ALGEBRAIC}, - {"P_af_infinity", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_af_gate", ALGEBRAIC}, - {"tau_P_af", "second", "rapid_delayed_rectifying_potassium_current_P_af_gate", ALGEBRAIC}, - {"P_as_infinity", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_as_gate", ALGEBRAIC}, - {"tau_P_as", "second", "rapid_delayed_rectifying_potassium_current_P_as_gate", ALGEBRAIC}, - {"tau_P_i", "second", "rapid_delayed_rectifying_potassium_current_P_i_gate", COMPUTED_CONSTANT}, - {"P_i_infinity", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_i_gate", ALGEBRAIC}, - {"g_K_s", "microS", "slow_delayed_rectifying_potassium_current", COMPUTED_CONSTANT}, - {"g_K_s_Centre_Published", "microS", "slow_delayed_rectifying_potassium_current", CONSTANT}, - {"g_K_s_Periphery_Published", "microS", "slow_delayed_rectifying_potassium_current", CONSTANT}, - {"g_K_s_Centre_1DCapable", "microS", "slow_delayed_rectifying_potassium_current", CONSTANT}, - {"g_K_s_Periphery_1DCapable", "microS", "slow_delayed_rectifying_potassium_current", CONSTANT}, - {"g_K_s_Centre_0DCapable", "microS", "slow_delayed_rectifying_potassium_current", CONSTANT}, - {"g_K_s_Periphery_0DCapable", "microS", "slow_delayed_rectifying_potassium_current", CONSTANT}, - {"alpha_xs", "per_second", "slow_delayed_rectifying_potassium_current_xs_gate", ALGEBRAIC}, - {"beta_xs", "per_second", "slow_delayed_rectifying_potassium_current_xs_gate", ALGEBRAIC}, - {"g_f_Na", "microS", "hyperpolarisation_activated_current", COMPUTED_CONSTANT}, - {"g_f_Na_Centre_Published", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"g_f_Na_Periphery_Published", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"g_f_Na_Centre_1DCapable", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"g_f_Na_Periphery_1DCapable", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"g_f_Na_Centre_0DCapable", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"g_f_Na_Periphery_0DCapable", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"g_f_K", "microS", "hyperpolarisation_activated_current", COMPUTED_CONSTANT}, - {"g_f_K_Centre_Published", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"g_f_K_Periphery_Published", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"g_f_K_Centre_1DCapable", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"g_f_K_Periphery_1DCapable", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"g_f_K_Centre_0DCapable", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"g_f_K_Periphery_0DCapable", "microS", "hyperpolarisation_activated_current", CONSTANT}, - {"alpha_y", "per_second", "hyperpolarisation_activated_current_y_gate", ALGEBRAIC}, - {"beta_y", "per_second", "hyperpolarisation_activated_current_y_gate", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { + {"dCell", "dimensionless", "membrane"}, + {"Version", "dimensionless", "membrane"}, + {"FCellConstant", "dimensionless", "membrane"}, + {"CmCentre", "microF", "membrane"}, + {"CmPeriphery", "microF", "membrane"}, + {"R", "millijoule_per_mole_kelvin", "membrane"}, + {"T", "kelvin", "membrane"}, + {"F", "coulomb_per_mole", "membrane"}, + {"g_b_Na_Centre_Published", "microS", "sodium_background_current"}, + {"g_b_Na_Periphery_Published", "microS", "sodium_background_current"}, + {"g_b_Na_Centre_1DCapable", "microS", "sodium_background_current"}, + {"g_b_Na_Periphery_1DCapable", "microS", "sodium_background_current"}, + {"g_b_Na_Centre_0DCapable", "microS", "sodium_background_current"}, + {"g_b_Na_Periphery_0DCapable", "microS", "sodium_background_current"}, + {"g_b_K_Centre_Published", "microS", "potassium_background_current"}, + {"g_b_K_Periphery_Published", "microS", "potassium_background_current"}, + {"g_b_K_Centre_1DCapable", "microS", "potassium_background_current"}, + {"g_b_K_Periphery_1DCapable", "microS", "potassium_background_current"}, + {"g_b_K_Centre_0DCapable", "microS", "potassium_background_current"}, + {"g_b_K_Periphery_0DCapable", "microS", "potassium_background_current"}, + {"g_b_Ca_Centre_Published", "microS", "calcium_background_current"}, + {"g_b_Ca_Periphery_Published", "microS", "calcium_background_current"}, + {"g_b_Ca_Centre_1DCapable", "microS", "calcium_background_current"}, + {"g_b_Ca_Periphery_1DCapable", "microS", "calcium_background_current"}, + {"g_b_Ca_Centre_0DCapable", "microS", "calcium_background_current"}, + {"g_b_Ca_Periphery_0DCapable", "microS", "calcium_background_current"}, + {"k_NaCa_Centre_Published", "nanoA", "sodium_calcium_exchanger"}, + {"k_NaCa_Periphery_Published", "nanoA", "sodium_calcium_exchanger"}, + {"k_NaCa_Centre_1DCapable", "nanoA", "sodium_calcium_exchanger"}, + {"k_NaCa_Periphery_1DCapable", "nanoA", "sodium_calcium_exchanger"}, + {"k_NaCa_Centre_0DCapable", "nanoA", "sodium_calcium_exchanger"}, + {"k_NaCa_Periphery_0DCapable", "nanoA", "sodium_calcium_exchanger"}, + {"Na_i", "millimolar", "ionic_concentrations"}, + {"gamma_NaCa", "dimensionless", "sodium_calcium_exchanger"}, + {"Ca_o", "millimolar", "ionic_concentrations"}, + {"Na_o", "millimolar", "ionic_concentrations"}, + {"Ca_i", "millimolar", "ionic_concentrations"}, + {"d_NaCa", "dimensionless", "sodium_calcium_exchanger"}, + {"i_p_max_Centre_Published", "nanoA", "sodium_potassium_pump"}, + {"i_p_max_Periphery_Published", "nanoA", "sodium_potassium_pump"}, + {"i_p_max_Centre_1DCapable", "nanoA", "sodium_potassium_pump"}, + {"i_p_max_Periphery_1DCapable", "nanoA", "sodium_potassium_pump"}, + {"i_p_max_Centre_0DCapable", "nanoA", "sodium_potassium_pump"}, + {"i_p_max_Periphery_0DCapable", "nanoA", "sodium_potassium_pump"}, + {"K_o", "millimolar", "ionic_concentrations"}, + {"K_m_K", "millimolar", "sodium_potassium_pump"}, + {"K_m_Na", "millimolar", "sodium_potassium_pump"}, + {"i_Ca_p_max_Centre_Published", "nanoA", "persistent_calcium_current"}, + {"i_Ca_p_max_Periphery_Published", "nanoA", "persistent_calcium_current"}, + {"i_Ca_p_max_Centre_1DCapable", "nanoA", "persistent_calcium_current"}, + {"i_Ca_p_max_Periphery_1DCapable", "nanoA", "persistent_calcium_current"}, + {"i_Ca_p_max_Centre_0DCapable", "nanoA", "persistent_calcium_current"}, + {"i_Ca_p_max_Periphery_0DCapable", "nanoA", "persistent_calcium_current"}, + {"K_i", "millimolar", "ionic_concentrations"}, + {"g_Na_Centre_Published", "microlitre_per_second", "sodium_current"}, + {"g_Na_Periphery_Published", "microlitre_per_second", "sodium_current"}, + {"g_Na_Centre_1DCapable", "microlitre_per_second", "sodium_current"}, + {"g_Na_Periphery_1DCapable", "microlitre_per_second", "sodium_current"}, + {"g_Na_Centre_0DCapable", "microlitre_per_second", "sodium_current"}, + {"g_Na_Periphery_0DCapable", "microlitre_per_second", "sodium_current"}, + {"g_Ca_L_Centre_Published", "microS", "L_type_Ca_channel"}, + {"g_Ca_L_Periphery_Published", "microS", "L_type_Ca_channel"}, + {"g_Ca_L_Centre_1DCapable", "microS", "L_type_Ca_channel"}, + {"g_Ca_L_Periphery_1DCapable", "microS", "L_type_Ca_channel"}, + {"g_Ca_L_Centre_0DCapable", "microS", "L_type_Ca_channel"}, + {"g_Ca_L_Periphery_0DCapable", "microS", "L_type_Ca_channel"}, + {"E_Ca_L", "millivolt", "L_type_Ca_channel"}, + {"g_Ca_T_Centre_Published", "microS", "T_type_Ca_channel"}, + {"g_Ca_T_Periphery_Published", "microS", "T_type_Ca_channel"}, + {"g_Ca_T_Centre_1DCapable", "microS", "T_type_Ca_channel"}, + {"g_Ca_T_Periphery_1DCapable", "microS", "T_type_Ca_channel"}, + {"g_Ca_T_Centre_0DCapable", "microS", "T_type_Ca_channel"}, + {"g_Ca_T_Periphery_0DCapable", "microS", "T_type_Ca_channel"}, + {"E_Ca_T", "millivolt", "T_type_Ca_channel"}, + {"g_to_Centre_Published", "microS", "four_AP_sensitive_currents"}, + {"g_to_Periphery_Published", "microS", "four_AP_sensitive_currents"}, + {"g_to_Centre_1DCapable", "microS", "four_AP_sensitive_currents"}, + {"g_to_Periphery_1DCapable", "microS", "four_AP_sensitive_currents"}, + {"g_to_Centre_0DCapable", "microS", "four_AP_sensitive_currents"}, + {"g_to_Periphery_0DCapable", "microS", "four_AP_sensitive_currents"}, + {"g_sus_Centre_Published", "microS", "four_AP_sensitive_currents"}, + {"g_sus_Periphery_Published", "microS", "four_AP_sensitive_currents"}, + {"g_sus_Centre_1DCapable", "microS", "four_AP_sensitive_currents"}, + {"g_sus_Periphery_1DCapable", "microS", "four_AP_sensitive_currents"}, + {"g_sus_Centre_0DCapable", "microS", "four_AP_sensitive_currents"}, + {"g_sus_Periphery_0DCapable", "microS", "four_AP_sensitive_currents"}, + {"g_K_r_Centre_Published", "microS", "rapid_delayed_rectifying_potassium_current"}, + {"g_K_r_Periphery_Published", "microS", "rapid_delayed_rectifying_potassium_current"}, + {"g_K_r_Centre_1DCapable", "microS", "rapid_delayed_rectifying_potassium_current"}, + {"g_K_r_Periphery_1DCapable", "microS", "rapid_delayed_rectifying_potassium_current"}, + {"g_K_r_Centre_0DCapable", "microS", "rapid_delayed_rectifying_potassium_current"}, + {"g_K_r_Periphery_0DCapable", "microS", "rapid_delayed_rectifying_potassium_current"}, + {"g_K_s_Centre_Published", "microS", "slow_delayed_rectifying_potassium_current"}, + {"g_K_s_Periphery_Published", "microS", "slow_delayed_rectifying_potassium_current"}, + {"g_K_s_Centre_1DCapable", "microS", "slow_delayed_rectifying_potassium_current"}, + {"g_K_s_Periphery_1DCapable", "microS", "slow_delayed_rectifying_potassium_current"}, + {"g_K_s_Centre_0DCapable", "microS", "slow_delayed_rectifying_potassium_current"}, + {"g_K_s_Periphery_0DCapable", "microS", "slow_delayed_rectifying_potassium_current"}, + {"g_f_Na_Centre_Published", "microS", "hyperpolarisation_activated_current"}, + {"g_f_Na_Periphery_Published", "microS", "hyperpolarisation_activated_current"}, + {"g_f_Na_Centre_1DCapable", "microS", "hyperpolarisation_activated_current"}, + {"g_f_Na_Periphery_1DCapable", "microS", "hyperpolarisation_activated_current"}, + {"g_f_Na_Centre_0DCapable", "microS", "hyperpolarisation_activated_current"}, + {"g_f_Na_Periphery_0DCapable", "microS", "hyperpolarisation_activated_current"}, + {"g_f_K_Centre_Published", "microS", "hyperpolarisation_activated_current"}, + {"g_f_K_Periphery_Published", "microS", "hyperpolarisation_activated_current"}, + {"g_f_K_Centre_1DCapable", "microS", "hyperpolarisation_activated_current"}, + {"g_f_K_Periphery_1DCapable", "microS", "hyperpolarisation_activated_current"}, + {"g_f_K_Centre_0DCapable", "microS", "hyperpolarisation_activated_current"}, + {"g_f_K_Periphery_0DCapable", "microS", "hyperpolarisation_activated_current"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"FCell", "dimensionless", "membrane"}, + {"Cm", "microF", "membrane"}, + {"i_Ca_p", "nanoA", "persistent_calcium_current"}, + {"g_b_Na", "microS", "sodium_background_current"}, + {"E_Na", "millivolt", "reversal_and_equilibrium_potentials"}, + {"g_b_K", "microS", "potassium_background_current"}, + {"E_K", "millivolt", "reversal_and_equilibrium_potentials"}, + {"g_b_Ca", "microS", "calcium_background_current"}, + {"E_Ca", "millivolt", "reversal_and_equilibrium_potentials"}, + {"k_NaCa", "nanoA", "sodium_calcium_exchanger"}, + {"i_p_max", "nanoA", "sodium_potassium_pump"}, + {"i_Ca_p_max", "nanoA", "persistent_calcium_current"}, + {"E_K_s", "millivolt", "reversal_and_equilibrium_potentials"}, + {"g_Na", "microlitre_per_second", "sodium_current"}, + {"g_Ca_L", "microS", "L_type_Ca_channel"}, + {"g_Ca_T", "microS", "T_type_Ca_channel"}, + {"g_to", "microS", "four_AP_sensitive_currents"}, + {"g_sus", "microS", "four_AP_sensitive_currents"}, + {"g_K_r", "microS", "rapid_delayed_rectifying_potassium_current"}, + {"tau_P_i", "second", "rapid_delayed_rectifying_potassium_current_P_i_gate"}, + {"g_K_s", "microS", "slow_delayed_rectifying_potassium_current"}, + {"g_f_Na", "microS", "hyperpolarisation_activated_current"}, + {"g_f_K", "microS", "hyperpolarisation_activated_current"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Na", "nanoA", "sodium_current"}, + {"i_p", "nanoA", "sodium_potassium_pump"}, + {"i_NaCa", "nanoA", "sodium_calcium_exchanger"}, + {"i_b_K", "nanoA", "potassium_background_current"}, + {"i_b_Ca", "nanoA", "calcium_background_current"}, + {"i_b_Na", "nanoA", "sodium_background_current"}, + {"i_f_K", "nanoA", "hyperpolarisation_activated_current"}, + {"i_f_Na", "nanoA", "hyperpolarisation_activated_current"}, + {"i_K_s", "nanoA", "slow_delayed_rectifying_potassium_current"}, + {"i_K_r", "nanoA", "rapid_delayed_rectifying_potassium_current"}, + {"i_sus", "nanoA", "four_AP_sensitive_currents"}, + {"i_to", "nanoA", "four_AP_sensitive_currents"}, + {"i_Ca_T", "nanoA", "T_type_Ca_channel"}, + {"i_Ca_L", "nanoA", "L_type_Ca_channel"}, + {"h", "dimensionless", "sodium_current_h_gate"}, + {"m_infinity", "dimensionless", "sodium_current_m_gate"}, + {"tau_m", "second", "sodium_current_m_gate"}, + {"F_Na", "dimensionless", "sodium_current_h_gate"}, + {"h1_infinity", "dimensionless", "sodium_current_h_gate"}, + {"tau_h1", "second", "sodium_current_h_gate"}, + {"h2_infinity", "dimensionless", "sodium_current_h_gate"}, + {"tau_h2", "second", "sodium_current_h_gate"}, + {"d_L_infinity", "dimensionless", "L_type_Ca_channel_d_gate"}, + {"tau_d_L", "second", "L_type_Ca_channel_d_gate"}, + {"alpha_d_L", "per_second", "L_type_Ca_channel_d_gate"}, + {"beta_d_L", "per_second", "L_type_Ca_channel_d_gate"}, + {"f_L_infinity", "dimensionless", "L_type_Ca_channel_f_gate"}, + {"tau_f_L", "second", "L_type_Ca_channel_f_gate"}, + {"alpha_f_L", "per_second", "L_type_Ca_channel_f_gate"}, + {"beta_f_L", "per_second", "L_type_Ca_channel_f_gate"}, + {"d_T_infinity", "dimensionless", "T_type_Ca_channel_d_gate"}, + {"tau_d_T", "second", "T_type_Ca_channel_d_gate"}, + {"alpha_d_T", "per_second", "T_type_Ca_channel_d_gate"}, + {"beta_d_T", "per_second", "T_type_Ca_channel_d_gate"}, + {"f_T_infinity", "dimensionless", "T_type_Ca_channel_f_gate"}, + {"tau_f_T", "second", "T_type_Ca_channel_f_gate"}, + {"alpha_f_T", "per_second", "T_type_Ca_channel_f_gate"}, + {"beta_f_T", "per_second", "T_type_Ca_channel_f_gate"}, + {"q_infinity", "dimensionless", "four_AP_sensitive_currents_q_gate"}, + {"tau_q", "second", "four_AP_sensitive_currents_q_gate"}, + {"r_infinity", "dimensionless", "four_AP_sensitive_currents_r_gate"}, + {"tau_r", "second", "four_AP_sensitive_currents_r_gate"}, + {"P_a", "dimensionless", "rapid_delayed_rectifying_potassium_current"}, + {"P_af_infinity", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_af_gate"}, + {"tau_P_af", "second", "rapid_delayed_rectifying_potassium_current_P_af_gate"}, + {"P_as_infinity", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_as_gate"}, + {"tau_P_as", "second", "rapid_delayed_rectifying_potassium_current_P_as_gate"}, + {"P_i_infinity", "dimensionless", "rapid_delayed_rectifying_potassium_current_P_i_gate"}, + {"alpha_xs", "per_second", "slow_delayed_rectifying_potassium_current_xs_gate"}, + {"beta_xs", "per_second", "slow_delayed_rectifying_potassium_current_xs_gate"}, + {"alpha_y", "per_second", "hyperpolarisation_activated_current_y_gate"}, + {"beta_y", "per_second", "hyperpolarisation_activated_current_y_gate"} }; double * createStatesArray() @@ -230,11 +238,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -246,118 +276,8 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[1] = 0.0; - variables[2] = 1.0; - variables[3] = 1.0309347; - variables[5] = 2.0e-5; - variables[6] = 6.5e-5; - variables[22] = 8314.0; - variables[23] = 310.0; - variables[24] = 96845.0; - variables[26] = 5.8e-5; - variables[27] = 0.000189; - variables[28] = 5.8e-5; - variables[29] = 0.000189; - variables[30] = 5.81818e-5; - variables[31] = 0.0001888; - variables[34] = 2.52e-5; - variables[35] = 8.19e-5; - variables[36] = 2.52e-5; - variables[37] = 8.19e-5; - variables[38] = 2.523636e-5; - variables[39] = 8.1892e-5; - variables[42] = 1.32e-5; - variables[43] = 4.3e-5; - variables[44] = 1.323e-5; - variables[45] = 4.29e-5; - variables[46] = 1.3236e-5; - variables[47] = 4.2952e-5; - variables[50] = 2.7e-6; - variables[51] = 8.8e-6; - variables[52] = 2.8e-6; - variables[53] = 8.8e-6; - variables[54] = 2.7229e-6; - variables[55] = 8.83584e-6; - variables[56] = 8.0; - variables[57] = 0.5; - variables[58] = 2.0; - variables[59] = 140.0; - variables[60] = 0.0001; - variables[61] = 0.0001; - variables[63] = 0.0478; - variables[64] = 0.16; - variables[65] = 0.0478; - variables[66] = 0.16; - variables[67] = 0.04782545; - variables[68] = 0.1551936; - variables[69] = 5.4; - variables[70] = 0.621; - variables[71] = 5.64; - variables[73] = 0.0; - variables[74] = 0.0; - variables[75] = 0.0042; - variables[76] = 0.03339; - variables[77] = 0.0; - variables[78] = 0.0; - variables[79] = 140.0; - variables[82] = 0.0; - variables[83] = 1.2e-6; - variables[84] = 0.0; - variables[85] = 3.7e-7; - variables[86] = 0.0; - variables[87] = 1.204e-6; - variables[97] = 0.0058; - variables[98] = 0.0659; - variables[99] = 0.0082; - variables[100] = 0.0659; - variables[101] = 0.0057938; - variables[102] = 0.06588648; - variables[103] = 46.4; - variables[113] = 0.0043; - variables[114] = 0.0139; - variables[115] = 0.0021; - variables[116] = 0.00694; - variables[117] = 0.00427806; - variables[118] = 0.0138823; - variables[119] = 45.0; - variables[129] = 0.00491; - variables[130] = 0.03649; - variables[131] = 0.004905; - variables[132] = 0.0365; - variables[133] = 0.004905; - variables[134] = 0.036495; - variables[136] = 6.65e-5; - variables[137] = 0.0114; - variables[138] = 0.000266; - variables[139] = 0.0114; - variables[140] = 6.645504e-5; - variables[141] = 0.01138376; - variables[147] = 0.000797; - variables[148] = 0.016; - variables[149] = 0.000738; - variables[150] = 0.0208; - variables[151] = 0.00079704; - variables[152] = 0.016; - variables[161] = 0.000518; - variables[162] = 0.0104; - variables[163] = 0.000345; - variables[164] = 0.0104; - variables[165] = 0.0003445; - variables[166] = 0.0104; - variables[170] = 0.000548; - variables[171] = 0.0069; - variables[172] = 0.000437; - variables[173] = 0.0055; - variables[174] = 0.0005465; - variables[175] = 0.006875; - variables[177] = 0.000548; - variables[178] = 0.0069; - variables[179] = 0.000437; - variables[180] = 0.0055; - variables[181] = 0.0005465; - variables[182] = 0.006875; states[0] = -39.013558536; states[1] = 0.092361701692; states[2] = 0.015905380261; @@ -373,158 +293,268 @@ void initialiseVariables(double *states, double *rates, double *variables) states[12] = 0.46960956028; states[13] = 0.082293827208; states[14] = 0.03889291759; + constants[0] = 0.0; + constants[1] = 1.0; + constants[2] = 1.0309347; + constants[3] = 2.0e-5; + constants[4] = 6.5e-5; + constants[5] = 8314.0; + constants[6] = 310.0; + constants[7] = 96845.0; + constants[8] = 5.8e-5; + constants[9] = 0.000189; + constants[10] = 5.8e-5; + constants[11] = 0.000189; + constants[12] = 5.81818e-5; + constants[13] = 0.0001888; + constants[14] = 2.52e-5; + constants[15] = 8.19e-5; + constants[16] = 2.52e-5; + constants[17] = 8.19e-5; + constants[18] = 2.523636e-5; + constants[19] = 8.1892e-5; + constants[20] = 1.32e-5; + constants[21] = 4.3e-5; + constants[22] = 1.323e-5; + constants[23] = 4.29e-5; + constants[24] = 1.3236e-5; + constants[25] = 4.2952e-5; + constants[26] = 2.7e-6; + constants[27] = 8.8e-6; + constants[28] = 2.8e-6; + constants[29] = 8.8e-6; + constants[30] = 2.7229e-6; + constants[31] = 8.83584e-6; + constants[32] = 8.0; + constants[33] = 0.5; + constants[34] = 2.0; + constants[35] = 140.0; + constants[36] = 0.0001; + constants[37] = 0.0001; + constants[38] = 0.0478; + constants[39] = 0.16; + constants[40] = 0.0478; + constants[41] = 0.16; + constants[42] = 0.04782545; + constants[43] = 0.1551936; + constants[44] = 5.4; + constants[45] = 0.621; + constants[46] = 5.64; + constants[47] = 0.0; + constants[48] = 0.0; + constants[49] = 0.0042; + constants[50] = 0.03339; + constants[51] = 0.0; + constants[52] = 0.0; + constants[53] = 140.0; + constants[54] = 0.0; + constants[55] = 1.2e-6; + constants[56] = 0.0; + constants[57] = 3.7e-7; + constants[58] = 0.0; + constants[59] = 1.204e-6; + constants[60] = 0.0058; + constants[61] = 0.0659; + constants[62] = 0.0082; + constants[63] = 0.0659; + constants[64] = 0.0057938; + constants[65] = 0.06588648; + constants[66] = 46.4; + constants[67] = 0.0043; + constants[68] = 0.0139; + constants[69] = 0.0021; + constants[70] = 0.00694; + constants[71] = 0.00427806; + constants[72] = 0.0138823; + constants[73] = 45.0; + constants[74] = 0.00491; + constants[75] = 0.03649; + constants[76] = 0.004905; + constants[77] = 0.0365; + constants[78] = 0.004905; + constants[79] = 0.036495; + constants[80] = 6.65e-5; + constants[81] = 0.0114; + constants[82] = 0.000266; + constants[83] = 0.0114; + constants[84] = 6.645504e-5; + constants[85] = 0.01138376; + constants[86] = 0.000797; + constants[87] = 0.016; + constants[88] = 0.000738; + constants[89] = 0.0208; + constants[90] = 0.00079704; + constants[91] = 0.016; + constants[92] = 0.000518; + constants[93] = 0.0104; + constants[94] = 0.000345; + constants[95] = 0.0104; + constants[96] = 0.0003445; + constants[97] = 0.0104; + constants[98] = 0.000548; + constants[99] = 0.0069; + constants[100] = 0.000437; + constants[101] = 0.0055; + constants[102] = 0.0005465; + constants[103] = 0.006875; + constants[104] = 0.000548; + constants[105] = 0.0069; + constants[106] = 0.000437; + constants[107] = 0.0055; + constants[108] = 0.0005465; + constants[109] = 0.006875; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[0] = (variables[2] == 0.0)?1.07*(3.0*variables[1]-0.1)/(3.0*(1.0+0.7745*exp(-(3.0*variables[1]-2.05)/0.295))):(variables[2] == 1.0)?variables[3]*variables[1]/(1.0+0.7745*exp(-(3.0*variables[1]-2.05)/0.295)):1.07*29.0*variables[1]/(30.0*(1.0+0.7745*exp(-(29.0*variables[1]-24.5)/1.95))); - variables[4] = variables[5]+variables[0]*(variables[6]-variables[5]); - variables[25] = (variables[2] == 0.0)?variables[26]+variables[0]*(variables[27]-variables[26]):(variables[2] == 1.0)?variables[30]+variables[0]*(variables[31]-variables[30]):variables[28]+variables[0]*(variables[29]-variables[28]); - variables[33] = (variables[2] == 0.0)?variables[34]+variables[0]*(variables[35]-variables[34]):(variables[2] == 1.0)?variables[38]+variables[0]*(variables[39]-variables[38]):variables[36]+variables[0]*(variables[37]-variables[36]); - variables[41] = (variables[2] == 0.0)?variables[42]+variables[0]*(variables[43]-variables[42]):(variables[2] == 1.0)?variables[46]+variables[0]*(variables[47]-variables[46]):variables[44]+variables[0]*(variables[45]-variables[44]); - variables[49] = (variables[2] == 0.0)?variables[50]+variables[0]*(variables[51]-variables[50]):(variables[2] == 1.0)?variables[54]+variables[0]*(variables[55]-variables[54]):variables[52]+variables[0]*(variables[53]-variables[52]); - variables[62] = (variables[2] == 0.0)?variables[63]+variables[0]*(variables[64]-variables[63]):(variables[2] == 1.0)?variables[67]+variables[0]*(variables[68]-variables[67]):variables[65]+variables[0]*(variables[66]-variables[65]); - variables[72] = (variables[2] == 0.0)?variables[73]+variables[0]*(variables[74]-variables[73]):(variables[2] == 1.0)?variables[77]+variables[0]*(variables[78]-variables[77]):variables[75]+variables[0]*(variables[76]-variables[75]); - variables[8] = variables[72]*variables[60]/(variables[60]+0.0004); - variables[32] = variables[22]*variables[23]/variables[24]*log(variables[59]/variables[56]); - variables[40] = variables[22]*variables[23]/variables[24]*log(variables[69]/variables[79]); - variables[48] = variables[22]*variables[23]/(2.0*variables[24])*log(variables[58]/variables[60]); - variables[80] = (variables[2] == 0.0)?variables[22]*variables[23]/variables[24]*log((variables[69]+0.12*variables[59])/(variables[79]+0.12*variables[56])):variables[22]*variables[23]/variables[24]*log((variables[69]+0.03*variables[59])/(variables[79]+0.03*variables[56])); - variables[81] = (variables[2] == 0.0)?variables[82]+variables[0]*(variables[83]-variables[82]):(variables[2] == 1.0)?variables[86]+variables[0]*(variables[87]-variables[86]):variables[84]+variables[0]*(variables[85]-variables[84]); - variables[96] = (variables[2] == 0.0)?variables[97]+variables[0]*(variables[98]-variables[97]):(variables[2] == 1.0)?variables[101]+variables[0]*(variables[102]-variables[101]):variables[99]+variables[0]*(variables[100]-variables[99]); - variables[112] = (variables[2] == 0.0)?variables[113]+variables[0]*(variables[114]-variables[113]):(variables[2] == 1.0)?variables[117]+variables[0]*(variables[118]-variables[117]):variables[115]+variables[0]*(variables[116]-variables[115]); - variables[128] = (variables[2] == 0.0)?variables[129]+variables[0]*(variables[130]-variables[129]):(variables[2] == 1.0)?variables[133]+variables[0]*(variables[134]-variables[133]):variables[131]+variables[0]*(variables[132]-variables[131]); - variables[135] = (variables[2] == 0.0)?variables[136]+variables[0]*(variables[137]-variables[136]):(variables[2] == 1.0)?variables[140]+variables[0]*(variables[141]-variables[140]):variables[138]+variables[0]*(variables[139]-variables[138]); - variables[146] = (variables[2] == 0.0)?variables[147]+variables[0]*(variables[148]-variables[147]):(variables[2] == 1.0)?variables[151]+variables[0]*(variables[152]-variables[151]):variables[149]+variables[0]*(variables[150]-variables[149]); - variables[158] = (variables[2] == 0.0)?0.002:(variables[2] == 1.0)?0.002:0.006; - variables[160] = (variables[2] == 0.0)?variables[161]+variables[0]*(variables[162]-variables[161]):(variables[2] == 1.0)?variables[165]+variables[0]*(variables[166]-variables[165]):variables[163]+variables[0]*(variables[164]-variables[163]); - variables[169] = (variables[2] == 0.0)?variables[170]+variables[0]*(variables[171]-variables[170]):(variables[2] == 1.0)?variables[174]+variables[0]*(variables[175]-variables[174]):variables[172]+variables[0]*(variables[173]-variables[172]); - variables[176] = (variables[2] == 0.0)?variables[177]+variables[0]*(variables[178]-variables[177]):(variables[2] == 1.0)?variables[181]+variables[0]*(variables[182]-variables[181]):variables[179]+variables[0]*(variables[180]-variables[179]); + computedConstants[0] = (constants[1] == 0.0)?1.07*(3.0*constants[0]-0.1)/(3.0*(1.0+0.7745*exp(-(3.0*constants[0]-2.05)/0.295))):(constants[1] == 1.0)?constants[2]*constants[0]/(1.0+0.7745*exp(-(3.0*constants[0]-2.05)/0.295)):1.07*29.0*constants[0]/(30.0*(1.0+0.7745*exp(-(29.0*constants[0]-24.5)/1.95))); + computedConstants[1] = constants[3]+computedConstants[0]*(constants[4]-constants[3]); + computedConstants[3] = (constants[1] == 0.0)?constants[8]+computedConstants[0]*(constants[9]-constants[8]):(constants[1] == 1.0)?constants[12]+computedConstants[0]*(constants[13]-constants[12]):constants[10]+computedConstants[0]*(constants[11]-constants[10]); + computedConstants[5] = (constants[1] == 0.0)?constants[14]+computedConstants[0]*(constants[15]-constants[14]):(constants[1] == 1.0)?constants[18]+computedConstants[0]*(constants[19]-constants[18]):constants[16]+computedConstants[0]*(constants[17]-constants[16]); + computedConstants[7] = (constants[1] == 0.0)?constants[20]+computedConstants[0]*(constants[21]-constants[20]):(constants[1] == 1.0)?constants[24]+computedConstants[0]*(constants[25]-constants[24]):constants[22]+computedConstants[0]*(constants[23]-constants[22]); + computedConstants[9] = (constants[1] == 0.0)?constants[26]+computedConstants[0]*(constants[27]-constants[26]):(constants[1] == 1.0)?constants[30]+computedConstants[0]*(constants[31]-constants[30]):constants[28]+computedConstants[0]*(constants[29]-constants[28]); + computedConstants[10] = (constants[1] == 0.0)?constants[38]+computedConstants[0]*(constants[39]-constants[38]):(constants[1] == 1.0)?constants[42]+computedConstants[0]*(constants[43]-constants[42]):constants[40]+computedConstants[0]*(constants[41]-constants[40]); + computedConstants[11] = (constants[1] == 0.0)?constants[47]+computedConstants[0]*(constants[48]-constants[47]):(constants[1] == 1.0)?constants[51]+computedConstants[0]*(constants[52]-constants[51]):constants[49]+computedConstants[0]*(constants[50]-constants[49]); + computedConstants[2] = computedConstants[11]*constants[36]/(constants[36]+0.0004); + computedConstants[4] = constants[5]*constants[6]/constants[7]*log(constants[35]/constants[32]); + computedConstants[6] = constants[5]*constants[6]/constants[7]*log(constants[44]/constants[53]); + computedConstants[8] = constants[5]*constants[6]/(2.0*constants[7])*log(constants[34]/constants[36]); + computedConstants[12] = (constants[1] == 0.0)?constants[5]*constants[6]/constants[7]*log((constants[44]+0.12*constants[35])/(constants[53]+0.12*constants[32])):constants[5]*constants[6]/constants[7]*log((constants[44]+0.03*constants[35])/(constants[53]+0.03*constants[32])); + computedConstants[13] = (constants[1] == 0.0)?constants[54]+computedConstants[0]*(constants[55]-constants[54]):(constants[1] == 1.0)?constants[58]+computedConstants[0]*(constants[59]-constants[58]):constants[56]+computedConstants[0]*(constants[57]-constants[56]); + computedConstants[14] = (constants[1] == 0.0)?constants[60]+computedConstants[0]*(constants[61]-constants[60]):(constants[1] == 1.0)?constants[64]+computedConstants[0]*(constants[65]-constants[64]):constants[62]+computedConstants[0]*(constants[63]-constants[62]); + computedConstants[15] = (constants[1] == 0.0)?constants[67]+computedConstants[0]*(constants[68]-constants[67]):(constants[1] == 1.0)?constants[71]+computedConstants[0]*(constants[72]-constants[71]):constants[69]+computedConstants[0]*(constants[70]-constants[69]); + computedConstants[16] = (constants[1] == 0.0)?constants[74]+computedConstants[0]*(constants[75]-constants[74]):(constants[1] == 1.0)?constants[78]+computedConstants[0]*(constants[79]-constants[78]):constants[76]+computedConstants[0]*(constants[77]-constants[76]); + computedConstants[17] = (constants[1] == 0.0)?constants[80]+computedConstants[0]*(constants[81]-constants[80]):(constants[1] == 1.0)?constants[84]+computedConstants[0]*(constants[85]-constants[84]):constants[82]+computedConstants[0]*(constants[83]-constants[82]); + computedConstants[18] = (constants[1] == 0.0)?constants[86]+computedConstants[0]*(constants[87]-constants[86]):(constants[1] == 1.0)?constants[90]+computedConstants[0]*(constants[91]-constants[90]):constants[88]+computedConstants[0]*(constants[89]-constants[88]); + computedConstants[19] = (constants[1] == 0.0)?0.002:(constants[1] == 1.0)?0.002:0.006; + computedConstants[20] = (constants[1] == 0.0)?constants[92]+computedConstants[0]*(constants[93]-constants[92]):(constants[1] == 1.0)?constants[96]+computedConstants[0]*(constants[97]-constants[96]):constants[94]+computedConstants[0]*(constants[95]-constants[94]); + computedConstants[21] = (constants[1] == 0.0)?constants[98]+computedConstants[0]*(constants[99]-constants[98]):(constants[1] == 1.0)?constants[102]+computedConstants[0]*(constants[103]-constants[102]):constants[100]+computedConstants[0]*(constants[101]-constants[100]); + computedConstants[22] = (constants[1] == 0.0)?constants[104]+computedConstants[0]*(constants[105]-constants[104]):(constants[1] == 1.0)?constants[108]+computedConstants[0]*(constants[109]-constants[108]):constants[106]+computedConstants[0]*(constants[107]-constants[106]); } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[9] = variables[62]*pow(variables[56]/(variables[71]+variables[56]), 3.0)*pow(variables[69]/(variables[70]+variables[69]), 2.0)*1.6/(1.5+exp(-(states[0]+60.0)/40.0)); - variables[10] = (variables[2] == 0.0)?variables[49]*(pow(variables[56], 3.0)*variables[58]*exp(0.03743*states[0]*variables[57])-pow(variables[59], 3.0)*variables[60]*exp(0.0374*states[0]*(variables[57]-1.0)))/(1.0+variables[61]*(variables[60]*pow(variables[59], 3.0)+variables[58]*pow(variables[56], 3.0))):variables[49]*(pow(variables[56], 3.0)*variables[58]*exp(0.03743*states[0]*variables[57])-pow(variables[59], 3.0)*variables[60]*exp(0.03743*states[0]*(variables[57]-1.0)))/(1.0+variables[61]*(variables[60]*pow(variables[59], 3.0)+variables[58]*pow(variables[56], 3.0))); - variables[14] = (variables[2] != 2.0)?variables[176]*states[14]*(states[0]-variables[40]):variables[176]*states[14]*(states[0]+102.0); - variables[15] = (variables[2] != 2.0)?variables[169]*states[14]*(states[0]-variables[32]):variables[169]*states[14]*(states[0]-77.6); - variables[16] = variables[160]*pow(states[13], 2.0)*(states[0]-variables[80]); - variables[18] = variables[135]*states[8]*(states[0]-variables[40]); - variables[19] = variables[128]*states[9]*states[8]*(states[0]-variables[40]); - variables[20] = variables[112]*states[7]*states[6]*(states[0]-variables[119]); - variables[21] = variables[96]*(states[4]*states[5]+0.006/(1.0+exp(-(states[0]+14.1)/6.0)))*(states[0]-variables[103]); - variables[91] = (variables[2] == 0.0)?0.0952*exp(-0.063*(states[0]+34.4))/(1.0+1.66*exp(-0.225*(states[0]+63.7)))+0.0869:0.09518*exp(-0.06306*(states[0]+34.4))/(1.0+1.662*exp(-0.2251*(states[0]+63.7)))+0.08693; - variables[88] = (1.0-variables[91])*states[2]+variables[91]*states[3]; - variables[7] = variables[81]*pow(states[1], 3.0)*variables[88]*variables[59]*pow(variables[24], 2.0)/(variables[22]*variables[23])*(exp((states[0]-variables[32])*variables[24]/(variables[22]*variables[23]))-1.0)/(exp(states[0]*variables[24]/(variables[22]*variables[23]))-1.0)*states[0]; - variables[11] = variables[33]*(states[0]-variables[40]); - variables[12] = variables[41]*(states[0]-variables[48]); - variables[13] = variables[25]*(states[0]-variables[32]); - variables[153] = 0.6*states[11]+0.4*states[12]; - variables[17] = variables[146]*variables[153]*states[10]*(states[0]-variables[40]); - rates[0] = -1.0/variables[4]*(variables[7]+variables[21]+variables[20]+variables[19]+variables[18]+variables[17]+variables[16]+variables[15]+variables[14]+variables[13]+variables[12]+variables[11]+variables[10]+variables[9]+variables[8]); - variables[89] = (variables[2] == 0.0)?pow(1.0/(1.0+exp(-states[0]/5.46)), 1.0/3.0):pow(1.0/(1.0+exp(-(states[0]+30.32)/5.46)), 1.0/3.0); - variables[90] = (variables[2] == 0.0)?0.0006247/(0.832*exp(-0.335*(states[0]+56.7))+0.627*exp(0.082*(states[0]+65.01)))+4.0e-5:0.0006247/(0.8322166*exp(-0.33566*(states[0]+56.7062))+0.6274*exp(0.0823*(states[0]+65.0131)))+4.569e-5; - rates[1] = (variables[89]-states[1])/variables[90]; - variables[92] = 1.0/(1.0+exp((states[0]+66.1)/6.4)); - variables[93] = 3.717e-6*exp(-0.2815*(states[0]+17.11))/(1.0+0.003732*exp(-0.3426*(states[0]+37.76)))+0.0005977; - rates[2] = (variables[92]-states[2])/variables[93]; - variables[94] = variables[92]; - variables[95] = 3.186e-8*exp(-0.6219*(states[0]+18.8))/(1.0+7.189e-5*exp(-0.6683*(states[0]+34.07)))+0.003556; - rates[3] = (variables[94]-states[3])/variables[95]; - variables[104] = (variables[2] == 0.0)?1.0/(1.0+exp(-(states[0]+23.1)/6.0)):(variables[2] == 1.0)?1.0/(1.0+exp(-(states[0]+22.3+0.8*variables[0])/6.0)):1.0/(1.0+exp(-(states[0]+22.2)/6.0)); - variables[106] = (variables[2] == 0.0)?-28.38*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0):(variables[2] == 1.0)?-28.39*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0):-28.4*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0); - variables[107] = (variables[2] == 1.0)?11.43*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0):11.42*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0); - variables[105] = 2.0/(variables[106]+variables[107]); - rates[5] = (variables[104]-states[5])/variables[105]; - variables[108] = 1.0/(1.0+exp((states[0]+45.0)/5.0)); - variables[110] = (variables[2] == 1.0)?3.75*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0):3.12*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0); - variables[111] = (variables[2] == 1.0)?30.0/(1.0+exp(-(states[0]+28.0)/4.0)):25.0/(1.0+exp(-(states[0]+28.0)/4.0)); - variables[109] = (variables[2] == 1.0)?(1.2-0.2*variables[0])/(variables[110]+variables[111]):1.0/(variables[110]+variables[111]); - rates[4] = (variables[108]-states[4])/variables[109]; - variables[120] = 1.0/(1.0+exp(-(states[0]+37.0)/6.8)); - variables[122] = 1068.0*exp((states[0]+26.3)/30.0); - variables[123] = 1068.0*exp(-(states[0]+26.3)/30.0); - variables[121] = 1.0/(variables[122]+variables[123]); - rates[7] = (variables[120]-states[7])/variables[121]; - variables[124] = 1.0/(1.0+exp((states[0]+71.0)/9.0)); - variables[126] = (variables[2] == 1.0)?15.3*exp(-(states[0]+71.0+0.7*variables[0])/83.3):15.3*exp(-(states[0]+71.7)/83.3); - variables[127] = (variables[2] == 1.0)?15.0*exp((states[0]+71.0)/15.38):15.0*exp((states[0]+71.7)/15.38); - variables[125] = 1.0/(variables[126]+variables[127]); - rates[6] = (variables[124]-states[6])/variables[125]; - variables[142] = 1.0/(1.0+exp((states[0]+59.37)/13.1)); - variables[143] = (variables[2] == 0.0)?0.0101+0.06517/(0.57*exp(-0.08*(states[0]+49.0)))+2.4e-5*exp(0.1*(states[0]+50.93)):(variables[2] == 1.0)?0.001/3.0*(30.31+195.5/(0.5686*exp(-0.08161*(states[0]+39.0+10.0*variables[0]))+0.7174*exp((0.2719-0.1719*variables[0])*1.0*(states[0]+40.93+10.0*variables[0])))):0.0101+0.06517/(0.5686*exp(-0.08161*(states[0]+39.0))+0.7174*exp(0.2719*(states[0]+40.93))); - rates[9] = (variables[142]-states[9])/variables[143]; - variables[144] = 1.0/(1.0+exp(-(states[0]-10.93)/19.7)); - variables[145] = (variables[2] == 0.0)?0.001*(2.98+15.59/(1.037*exp(0.09*(states[0]+30.61))+0.369*exp(-0.12*(states[0]+23.84)))):(variables[2] == 1.0)?0.0025*(1.191+7.838/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))):0.001*(2.98+19.59/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))); - rates[8] = (variables[144]-states[8])/variables[145]; - variables[154] = (variables[2] != 2.0)?1.0/(1.0+exp(-(states[0]+14.2)/10.6)):1.0/(1.0+exp(-(states[0]+13.2)/10.6)); - variables[155] = (variables[2] != 2.0)?1.0/(37.2*exp((states[0]-9.0)/15.9)+0.96*exp(-(states[0]-9.0)/22.5)):1.0/(37.2*exp((states[0]-10.0)/15.9)+0.96*exp(-(states[0]-10.0)/22.5)); - rates[11] = (variables[154]-states[11])/variables[155]; - variables[156] = variables[154]; - variables[157] = (variables[2] != 2.0)?1.0/(4.2*exp((states[0]-9.0)/17.0)+0.15*exp(-(states[0]-9.0)/21.6)):1.0/(4.2*exp((states[0]-10.0)/17.0)+0.15*exp(-(states[0]-10.0)/21.6)); - rates[12] = (variables[156]-states[12])/variables[157]; - variables[159] = 1.0/(1.0+exp((states[0]+18.6)/10.1)); - rates[10] = (variables[159]-states[10])/variables[158]; - variables[167] = 14.0/(1.0+exp(-(states[0]-40.0)/9.0)); - variables[168] = 1.0*exp(-states[0]/45.0); - rates[13] = variables[167]*(1.0-states[13])-variables[168]*states[13]; - variables[183] = (variables[2] == 0.0)?1.0*exp(-(states[0]+78.91)/26.62):1.0*exp(-(states[0]+78.91)/26.63); - variables[184] = 1.0*exp((states[0]+75.13)/21.25); - rates[14] = variables[183]*(1.0-states[14])-variables[184]*states[14]; + algebraic[1] = computedConstants[10]*pow(constants[32]/(constants[46]+constants[32]), 3.0)*pow(constants[44]/(constants[45]+constants[44]), 2.0)*1.6/(1.5+exp(-(states[0]+60.0)/40.0)); + algebraic[2] = (constants[1] == 0.0)?computedConstants[9]*(pow(constants[32], 3.0)*constants[34]*exp(0.03743*states[0]*constants[33])-pow(constants[35], 3.0)*constants[36]*exp(0.0374*states[0]*(constants[33]-1.0)))/(1.0+constants[37]*(constants[36]*pow(constants[35], 3.0)+constants[34]*pow(constants[32], 3.0))):computedConstants[9]*(pow(constants[32], 3.0)*constants[34]*exp(0.03743*states[0]*constants[33])-pow(constants[35], 3.0)*constants[36]*exp(0.03743*states[0]*(constants[33]-1.0)))/(1.0+constants[37]*(constants[36]*pow(constants[35], 3.0)+constants[34]*pow(constants[32], 3.0))); + algebraic[6] = (constants[1] != 2.0)?computedConstants[22]*states[14]*(states[0]-computedConstants[6]):computedConstants[22]*states[14]*(states[0]+102.0); + algebraic[7] = (constants[1] != 2.0)?computedConstants[21]*states[14]*(states[0]-computedConstants[4]):computedConstants[21]*states[14]*(states[0]-77.6); + algebraic[8] = computedConstants[20]*pow(states[13], 2.0)*(states[0]-computedConstants[12]); + algebraic[10] = computedConstants[17]*states[8]*(states[0]-computedConstants[6]); + algebraic[11] = computedConstants[16]*states[9]*states[8]*(states[0]-computedConstants[6]); + algebraic[12] = computedConstants[15]*states[7]*states[6]*(states[0]-constants[73]); + algebraic[13] = computedConstants[14]*(states[4]*states[5]+0.006/(1.0+exp(-(states[0]+14.1)/6.0)))*(states[0]-constants[66]); + algebraic[17] = (constants[1] == 0.0)?0.0952*exp(-0.063*(states[0]+34.4))/(1.0+1.66*exp(-0.225*(states[0]+63.7)))+0.0869:0.09518*exp(-0.06306*(states[0]+34.4))/(1.0+1.662*exp(-0.2251*(states[0]+63.7)))+0.08693; + algebraic[14] = (1.0-algebraic[17])*states[2]+algebraic[17]*states[3]; + algebraic[0] = computedConstants[13]*pow(states[1], 3.0)*algebraic[14]*constants[35]*pow(constants[7], 2.0)/(constants[5]*constants[6])*(exp((states[0]-computedConstants[4])*constants[7]/(constants[5]*constants[6]))-1.0)/(exp(states[0]*constants[7]/(constants[5]*constants[6]))-1.0)*states[0]; + algebraic[3] = computedConstants[5]*(states[0]-computedConstants[6]); + algebraic[4] = computedConstants[7]*(states[0]-computedConstants[8]); + algebraic[5] = computedConstants[3]*(states[0]-computedConstants[4]); + algebraic[42] = 0.6*states[11]+0.4*states[12]; + algebraic[9] = computedConstants[18]*algebraic[42]*states[10]*(states[0]-computedConstants[6]); + rates[0] = -1.0/computedConstants[1]*(algebraic[0]+algebraic[13]+algebraic[12]+algebraic[11]+algebraic[10]+algebraic[9]+algebraic[8]+algebraic[7]+algebraic[6]+algebraic[5]+algebraic[4]+algebraic[3]+algebraic[2]+algebraic[1]+computedConstants[2]); + algebraic[15] = (constants[1] == 0.0)?pow(1.0/(1.0+exp(-states[0]/5.46)), 1.0/3.0):pow(1.0/(1.0+exp(-(states[0]+30.32)/5.46)), 1.0/3.0); + algebraic[16] = (constants[1] == 0.0)?0.0006247/(0.832*exp(-0.335*(states[0]+56.7))+0.627*exp(0.082*(states[0]+65.01)))+4.0e-5:0.0006247/(0.8322166*exp(-0.33566*(states[0]+56.7062))+0.6274*exp(0.0823*(states[0]+65.0131)))+4.569e-5; + rates[1] = (algebraic[15]-states[1])/algebraic[16]; + algebraic[18] = 1.0/(1.0+exp((states[0]+66.1)/6.4)); + algebraic[19] = 3.717e-6*exp(-0.2815*(states[0]+17.11))/(1.0+0.003732*exp(-0.3426*(states[0]+37.76)))+0.0005977; + rates[2] = (algebraic[18]-states[2])/algebraic[19]; + algebraic[20] = algebraic[18]; + algebraic[21] = 3.186e-8*exp(-0.6219*(states[0]+18.8))/(1.0+7.189e-5*exp(-0.6683*(states[0]+34.07)))+0.003556; + rates[3] = (algebraic[20]-states[3])/algebraic[21]; + algebraic[22] = (constants[1] == 0.0)?1.0/(1.0+exp(-(states[0]+23.1)/6.0)):(constants[1] == 1.0)?1.0/(1.0+exp(-(states[0]+22.3+0.8*computedConstants[0])/6.0)):1.0/(1.0+exp(-(states[0]+22.2)/6.0)); + algebraic[24] = (constants[1] == 0.0)?-28.38*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0):(constants[1] == 1.0)?-28.39*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0):-28.4*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0); + algebraic[25] = (constants[1] == 1.0)?11.43*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0):11.42*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0); + algebraic[23] = 2.0/(algebraic[24]+algebraic[25]); + rates[5] = (algebraic[22]-states[5])/algebraic[23]; + algebraic[26] = 1.0/(1.0+exp((states[0]+45.0)/5.0)); + algebraic[28] = (constants[1] == 1.0)?3.75*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0):3.12*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0); + algebraic[29] = (constants[1] == 1.0)?30.0/(1.0+exp(-(states[0]+28.0)/4.0)):25.0/(1.0+exp(-(states[0]+28.0)/4.0)); + algebraic[27] = (constants[1] == 1.0)?(1.2-0.2*computedConstants[0])/(algebraic[28]+algebraic[29]):1.0/(algebraic[28]+algebraic[29]); + rates[4] = (algebraic[26]-states[4])/algebraic[27]; + algebraic[30] = 1.0/(1.0+exp(-(states[0]+37.0)/6.8)); + algebraic[32] = 1068.0*exp((states[0]+26.3)/30.0); + algebraic[33] = 1068.0*exp(-(states[0]+26.3)/30.0); + algebraic[31] = 1.0/(algebraic[32]+algebraic[33]); + rates[7] = (algebraic[30]-states[7])/algebraic[31]; + algebraic[34] = 1.0/(1.0+exp((states[0]+71.0)/9.0)); + algebraic[36] = (constants[1] == 1.0)?15.3*exp(-(states[0]+71.0+0.7*computedConstants[0])/83.3):15.3*exp(-(states[0]+71.7)/83.3); + algebraic[37] = (constants[1] == 1.0)?15.0*exp((states[0]+71.0)/15.38):15.0*exp((states[0]+71.7)/15.38); + algebraic[35] = 1.0/(algebraic[36]+algebraic[37]); + rates[6] = (algebraic[34]-states[6])/algebraic[35]; + algebraic[38] = 1.0/(1.0+exp((states[0]+59.37)/13.1)); + algebraic[39] = (constants[1] == 0.0)?0.0101+0.06517/(0.57*exp(-0.08*(states[0]+49.0)))+2.4e-5*exp(0.1*(states[0]+50.93)):(constants[1] == 1.0)?0.001/3.0*(30.31+195.5/(0.5686*exp(-0.08161*(states[0]+39.0+10.0*computedConstants[0]))+0.7174*exp((0.2719-0.1719*computedConstants[0])*1.0*(states[0]+40.93+10.0*computedConstants[0])))):0.0101+0.06517/(0.5686*exp(-0.08161*(states[0]+39.0))+0.7174*exp(0.2719*(states[0]+40.93))); + rates[9] = (algebraic[38]-states[9])/algebraic[39]; + algebraic[40] = 1.0/(1.0+exp(-(states[0]-10.93)/19.7)); + algebraic[41] = (constants[1] == 0.0)?0.001*(2.98+15.59/(1.037*exp(0.09*(states[0]+30.61))+0.369*exp(-0.12*(states[0]+23.84)))):(constants[1] == 1.0)?0.0025*(1.191+7.838/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))):0.001*(2.98+19.59/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))); + rates[8] = (algebraic[40]-states[8])/algebraic[41]; + algebraic[43] = (constants[1] != 2.0)?1.0/(1.0+exp(-(states[0]+14.2)/10.6)):1.0/(1.0+exp(-(states[0]+13.2)/10.6)); + algebraic[44] = (constants[1] != 2.0)?1.0/(37.2*exp((states[0]-9.0)/15.9)+0.96*exp(-(states[0]-9.0)/22.5)):1.0/(37.2*exp((states[0]-10.0)/15.9)+0.96*exp(-(states[0]-10.0)/22.5)); + rates[11] = (algebraic[43]-states[11])/algebraic[44]; + algebraic[45] = algebraic[43]; + algebraic[46] = (constants[1] != 2.0)?1.0/(4.2*exp((states[0]-9.0)/17.0)+0.15*exp(-(states[0]-9.0)/21.6)):1.0/(4.2*exp((states[0]-10.0)/17.0)+0.15*exp(-(states[0]-10.0)/21.6)); + rates[12] = (algebraic[45]-states[12])/algebraic[46]; + algebraic[47] = 1.0/(1.0+exp((states[0]+18.6)/10.1)); + rates[10] = (algebraic[47]-states[10])/computedConstants[19]; + algebraic[48] = 14.0/(1.0+exp(-(states[0]-40.0)/9.0)); + algebraic[49] = 1.0*exp(-states[0]/45.0); + rates[13] = algebraic[48]*(1.0-states[13])-algebraic[49]*states[13]; + algebraic[50] = (constants[1] == 0.0)?1.0*exp(-(states[0]+78.91)/26.62):1.0*exp(-(states[0]+78.91)/26.63); + algebraic[51] = 1.0*exp((states[0]+75.13)/21.25); + rates[14] = algebraic[50]*(1.0-states[14])-algebraic[51]*states[14]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[13] = variables[25]*(states[0]-variables[32]); - variables[11] = variables[33]*(states[0]-variables[40]); - variables[12] = variables[41]*(states[0]-variables[48]); - variables[10] = (variables[2] == 0.0)?variables[49]*(pow(variables[56], 3.0)*variables[58]*exp(0.03743*states[0]*variables[57])-pow(variables[59], 3.0)*variables[60]*exp(0.0374*states[0]*(variables[57]-1.0)))/(1.0+variables[61]*(variables[60]*pow(variables[59], 3.0)+variables[58]*pow(variables[56], 3.0))):variables[49]*(pow(variables[56], 3.0)*variables[58]*exp(0.03743*states[0]*variables[57])-pow(variables[59], 3.0)*variables[60]*exp(0.03743*states[0]*(variables[57]-1.0)))/(1.0+variables[61]*(variables[60]*pow(variables[59], 3.0)+variables[58]*pow(variables[56], 3.0))); - variables[9] = variables[62]*pow(variables[56]/(variables[71]+variables[56]), 3.0)*pow(variables[69]/(variables[70]+variables[69]), 2.0)*1.6/(1.5+exp(-(states[0]+60.0)/40.0)); - variables[91] = (variables[2] == 0.0)?0.0952*exp(-0.063*(states[0]+34.4))/(1.0+1.66*exp(-0.225*(states[0]+63.7)))+0.0869:0.09518*exp(-0.06306*(states[0]+34.4))/(1.0+1.662*exp(-0.2251*(states[0]+63.7)))+0.08693; - variables[88] = (1.0-variables[91])*states[2]+variables[91]*states[3]; - variables[7] = variables[81]*pow(states[1], 3.0)*variables[88]*variables[59]*pow(variables[24], 2.0)/(variables[22]*variables[23])*(exp((states[0]-variables[32])*variables[24]/(variables[22]*variables[23]))-1.0)/(exp(states[0]*variables[24]/(variables[22]*variables[23]))-1.0)*states[0]; - variables[89] = (variables[2] == 0.0)?pow(1.0/(1.0+exp(-states[0]/5.46)), 1.0/3.0):pow(1.0/(1.0+exp(-(states[0]+30.32)/5.46)), 1.0/3.0); - variables[90] = (variables[2] == 0.0)?0.0006247/(0.832*exp(-0.335*(states[0]+56.7))+0.627*exp(0.082*(states[0]+65.01)))+4.0e-5:0.0006247/(0.8322166*exp(-0.33566*(states[0]+56.7062))+0.6274*exp(0.0823*(states[0]+65.0131)))+4.569e-5; - variables[92] = 1.0/(1.0+exp((states[0]+66.1)/6.4)); - variables[94] = variables[92]; - variables[93] = 3.717e-6*exp(-0.2815*(states[0]+17.11))/(1.0+0.003732*exp(-0.3426*(states[0]+37.76)))+0.0005977; - variables[95] = 3.186e-8*exp(-0.6219*(states[0]+18.8))/(1.0+7.189e-5*exp(-0.6683*(states[0]+34.07)))+0.003556; - variables[21] = variables[96]*(states[4]*states[5]+0.006/(1.0+exp(-(states[0]+14.1)/6.0)))*(states[0]-variables[103]); - variables[106] = (variables[2] == 0.0)?-28.38*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0):(variables[2] == 1.0)?-28.39*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0):-28.4*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0); - variables[107] = (variables[2] == 1.0)?11.43*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0):11.42*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0); - variables[105] = 2.0/(variables[106]+variables[107]); - variables[104] = (variables[2] == 0.0)?1.0/(1.0+exp(-(states[0]+23.1)/6.0)):(variables[2] == 1.0)?1.0/(1.0+exp(-(states[0]+22.3+0.8*variables[0])/6.0)):1.0/(1.0+exp(-(states[0]+22.2)/6.0)); - variables[110] = (variables[2] == 1.0)?3.75*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0):3.12*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0); - variables[111] = (variables[2] == 1.0)?30.0/(1.0+exp(-(states[0]+28.0)/4.0)):25.0/(1.0+exp(-(states[0]+28.0)/4.0)); - variables[109] = (variables[2] == 1.0)?(1.2-0.2*variables[0])/(variables[110]+variables[111]):1.0/(variables[110]+variables[111]); - variables[108] = 1.0/(1.0+exp((states[0]+45.0)/5.0)); - variables[20] = variables[112]*states[7]*states[6]*(states[0]-variables[119]); - variables[122] = 1068.0*exp((states[0]+26.3)/30.0); - variables[123] = 1068.0*exp(-(states[0]+26.3)/30.0); - variables[121] = 1.0/(variables[122]+variables[123]); - variables[120] = 1.0/(1.0+exp(-(states[0]+37.0)/6.8)); - variables[126] = (variables[2] == 1.0)?15.3*exp(-(states[0]+71.0+0.7*variables[0])/83.3):15.3*exp(-(states[0]+71.7)/83.3); - variables[127] = (variables[2] == 1.0)?15.0*exp((states[0]+71.0)/15.38):15.0*exp((states[0]+71.7)/15.38); - variables[125] = 1.0/(variables[126]+variables[127]); - variables[124] = 1.0/(1.0+exp((states[0]+71.0)/9.0)); - variables[19] = variables[128]*states[9]*states[8]*(states[0]-variables[40]); - variables[18] = variables[135]*states[8]*(states[0]-variables[40]); - variables[142] = 1.0/(1.0+exp((states[0]+59.37)/13.1)); - variables[143] = (variables[2] == 0.0)?0.0101+0.06517/(0.57*exp(-0.08*(states[0]+49.0)))+2.4e-5*exp(0.1*(states[0]+50.93)):(variables[2] == 1.0)?0.001/3.0*(30.31+195.5/(0.5686*exp(-0.08161*(states[0]+39.0+10.0*variables[0]))+0.7174*exp((0.2719-0.1719*variables[0])*1.0*(states[0]+40.93+10.0*variables[0])))):0.0101+0.06517/(0.5686*exp(-0.08161*(states[0]+39.0))+0.7174*exp(0.2719*(states[0]+40.93))); - variables[144] = 1.0/(1.0+exp(-(states[0]-10.93)/19.7)); - variables[145] = (variables[2] == 0.0)?0.001*(2.98+15.59/(1.037*exp(0.09*(states[0]+30.61))+0.369*exp(-0.12*(states[0]+23.84)))):(variables[2] == 1.0)?0.0025*(1.191+7.838/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))):0.001*(2.98+19.59/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))); - variables[153] = 0.6*states[11]+0.4*states[12]; - variables[17] = variables[146]*variables[153]*states[10]*(states[0]-variables[40]); - variables[154] = (variables[2] != 2.0)?1.0/(1.0+exp(-(states[0]+14.2)/10.6)):1.0/(1.0+exp(-(states[0]+13.2)/10.6)); - variables[155] = (variables[2] != 2.0)?1.0/(37.2*exp((states[0]-9.0)/15.9)+0.96*exp(-(states[0]-9.0)/22.5)):1.0/(37.2*exp((states[0]-10.0)/15.9)+0.96*exp(-(states[0]-10.0)/22.5)); - variables[156] = variables[154]; - variables[157] = (variables[2] != 2.0)?1.0/(4.2*exp((states[0]-9.0)/17.0)+0.15*exp(-(states[0]-9.0)/21.6)):1.0/(4.2*exp((states[0]-10.0)/17.0)+0.15*exp(-(states[0]-10.0)/21.6)); - variables[159] = 1.0/(1.0+exp((states[0]+18.6)/10.1)); - variables[16] = variables[160]*pow(states[13], 2.0)*(states[0]-variables[80]); - variables[167] = 14.0/(1.0+exp(-(states[0]-40.0)/9.0)); - variables[168] = 1.0*exp(-states[0]/45.0); - variables[15] = (variables[2] != 2.0)?variables[169]*states[14]*(states[0]-variables[32]):variables[169]*states[14]*(states[0]-77.6); - variables[14] = (variables[2] != 2.0)?variables[176]*states[14]*(states[0]-variables[40]):variables[176]*states[14]*(states[0]+102.0); - variables[183] = (variables[2] == 0.0)?1.0*exp(-(states[0]+78.91)/26.62):1.0*exp(-(states[0]+78.91)/26.63); - variables[184] = 1.0*exp((states[0]+75.13)/21.25); + algebraic[5] = computedConstants[3]*(states[0]-computedConstants[4]); + algebraic[3] = computedConstants[5]*(states[0]-computedConstants[6]); + algebraic[4] = computedConstants[7]*(states[0]-computedConstants[8]); + algebraic[2] = (constants[1] == 0.0)?computedConstants[9]*(pow(constants[32], 3.0)*constants[34]*exp(0.03743*states[0]*constants[33])-pow(constants[35], 3.0)*constants[36]*exp(0.0374*states[0]*(constants[33]-1.0)))/(1.0+constants[37]*(constants[36]*pow(constants[35], 3.0)+constants[34]*pow(constants[32], 3.0))):computedConstants[9]*(pow(constants[32], 3.0)*constants[34]*exp(0.03743*states[0]*constants[33])-pow(constants[35], 3.0)*constants[36]*exp(0.03743*states[0]*(constants[33]-1.0)))/(1.0+constants[37]*(constants[36]*pow(constants[35], 3.0)+constants[34]*pow(constants[32], 3.0))); + algebraic[1] = computedConstants[10]*pow(constants[32]/(constants[46]+constants[32]), 3.0)*pow(constants[44]/(constants[45]+constants[44]), 2.0)*1.6/(1.5+exp(-(states[0]+60.0)/40.0)); + algebraic[17] = (constants[1] == 0.0)?0.0952*exp(-0.063*(states[0]+34.4))/(1.0+1.66*exp(-0.225*(states[0]+63.7)))+0.0869:0.09518*exp(-0.06306*(states[0]+34.4))/(1.0+1.662*exp(-0.2251*(states[0]+63.7)))+0.08693; + algebraic[14] = (1.0-algebraic[17])*states[2]+algebraic[17]*states[3]; + algebraic[0] = computedConstants[13]*pow(states[1], 3.0)*algebraic[14]*constants[35]*pow(constants[7], 2.0)/(constants[5]*constants[6])*(exp((states[0]-computedConstants[4])*constants[7]/(constants[5]*constants[6]))-1.0)/(exp(states[0]*constants[7]/(constants[5]*constants[6]))-1.0)*states[0]; + algebraic[15] = (constants[1] == 0.0)?pow(1.0/(1.0+exp(-states[0]/5.46)), 1.0/3.0):pow(1.0/(1.0+exp(-(states[0]+30.32)/5.46)), 1.0/3.0); + algebraic[16] = (constants[1] == 0.0)?0.0006247/(0.832*exp(-0.335*(states[0]+56.7))+0.627*exp(0.082*(states[0]+65.01)))+4.0e-5:0.0006247/(0.8322166*exp(-0.33566*(states[0]+56.7062))+0.6274*exp(0.0823*(states[0]+65.0131)))+4.569e-5; + algebraic[18] = 1.0/(1.0+exp((states[0]+66.1)/6.4)); + algebraic[20] = algebraic[18]; + algebraic[19] = 3.717e-6*exp(-0.2815*(states[0]+17.11))/(1.0+0.003732*exp(-0.3426*(states[0]+37.76)))+0.0005977; + algebraic[21] = 3.186e-8*exp(-0.6219*(states[0]+18.8))/(1.0+7.189e-5*exp(-0.6683*(states[0]+34.07)))+0.003556; + algebraic[13] = computedConstants[14]*(states[4]*states[5]+0.006/(1.0+exp(-(states[0]+14.1)/6.0)))*(states[0]-constants[66]); + algebraic[24] = (constants[1] == 0.0)?-28.38*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0):(constants[1] == 1.0)?-28.39*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0):-28.4*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0); + algebraic[25] = (constants[1] == 1.0)?11.43*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0):11.42*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0); + algebraic[23] = 2.0/(algebraic[24]+algebraic[25]); + algebraic[22] = (constants[1] == 0.0)?1.0/(1.0+exp(-(states[0]+23.1)/6.0)):(constants[1] == 1.0)?1.0/(1.0+exp(-(states[0]+22.3+0.8*computedConstants[0])/6.0)):1.0/(1.0+exp(-(states[0]+22.2)/6.0)); + algebraic[28] = (constants[1] == 1.0)?3.75*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0):3.12*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0); + algebraic[29] = (constants[1] == 1.0)?30.0/(1.0+exp(-(states[0]+28.0)/4.0)):25.0/(1.0+exp(-(states[0]+28.0)/4.0)); + algebraic[27] = (constants[1] == 1.0)?(1.2-0.2*computedConstants[0])/(algebraic[28]+algebraic[29]):1.0/(algebraic[28]+algebraic[29]); + algebraic[26] = 1.0/(1.0+exp((states[0]+45.0)/5.0)); + algebraic[12] = computedConstants[15]*states[7]*states[6]*(states[0]-constants[73]); + algebraic[32] = 1068.0*exp((states[0]+26.3)/30.0); + algebraic[33] = 1068.0*exp(-(states[0]+26.3)/30.0); + algebraic[31] = 1.0/(algebraic[32]+algebraic[33]); + algebraic[30] = 1.0/(1.0+exp(-(states[0]+37.0)/6.8)); + algebraic[36] = (constants[1] == 1.0)?15.3*exp(-(states[0]+71.0+0.7*computedConstants[0])/83.3):15.3*exp(-(states[0]+71.7)/83.3); + algebraic[37] = (constants[1] == 1.0)?15.0*exp((states[0]+71.0)/15.38):15.0*exp((states[0]+71.7)/15.38); + algebraic[35] = 1.0/(algebraic[36]+algebraic[37]); + algebraic[34] = 1.0/(1.0+exp((states[0]+71.0)/9.0)); + algebraic[11] = computedConstants[16]*states[9]*states[8]*(states[0]-computedConstants[6]); + algebraic[10] = computedConstants[17]*states[8]*(states[0]-computedConstants[6]); + algebraic[38] = 1.0/(1.0+exp((states[0]+59.37)/13.1)); + algebraic[39] = (constants[1] == 0.0)?0.0101+0.06517/(0.57*exp(-0.08*(states[0]+49.0)))+2.4e-5*exp(0.1*(states[0]+50.93)):(constants[1] == 1.0)?0.001/3.0*(30.31+195.5/(0.5686*exp(-0.08161*(states[0]+39.0+10.0*computedConstants[0]))+0.7174*exp((0.2719-0.1719*computedConstants[0])*1.0*(states[0]+40.93+10.0*computedConstants[0])))):0.0101+0.06517/(0.5686*exp(-0.08161*(states[0]+39.0))+0.7174*exp(0.2719*(states[0]+40.93))); + algebraic[40] = 1.0/(1.0+exp(-(states[0]-10.93)/19.7)); + algebraic[41] = (constants[1] == 0.0)?0.001*(2.98+15.59/(1.037*exp(0.09*(states[0]+30.61))+0.369*exp(-0.12*(states[0]+23.84)))):(constants[1] == 1.0)?0.0025*(1.191+7.838/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))):0.001*(2.98+19.59/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))); + algebraic[42] = 0.6*states[11]+0.4*states[12]; + algebraic[9] = computedConstants[18]*algebraic[42]*states[10]*(states[0]-computedConstants[6]); + algebraic[43] = (constants[1] != 2.0)?1.0/(1.0+exp(-(states[0]+14.2)/10.6)):1.0/(1.0+exp(-(states[0]+13.2)/10.6)); + algebraic[44] = (constants[1] != 2.0)?1.0/(37.2*exp((states[0]-9.0)/15.9)+0.96*exp(-(states[0]-9.0)/22.5)):1.0/(37.2*exp((states[0]-10.0)/15.9)+0.96*exp(-(states[0]-10.0)/22.5)); + algebraic[45] = algebraic[43]; + algebraic[46] = (constants[1] != 2.0)?1.0/(4.2*exp((states[0]-9.0)/17.0)+0.15*exp(-(states[0]-9.0)/21.6)):1.0/(4.2*exp((states[0]-10.0)/17.0)+0.15*exp(-(states[0]-10.0)/21.6)); + algebraic[47] = 1.0/(1.0+exp((states[0]+18.6)/10.1)); + algebraic[8] = computedConstants[20]*pow(states[13], 2.0)*(states[0]-computedConstants[12]); + algebraic[48] = 14.0/(1.0+exp(-(states[0]-40.0)/9.0)); + algebraic[49] = 1.0*exp(-states[0]/45.0); + algebraic[7] = (constants[1] != 2.0)?computedConstants[21]*states[14]*(states[0]-computedConstants[4]):computedConstants[21]*states[14]*(states[0]-77.6); + algebraic[6] = (constants[1] != 2.0)?computedConstants[22]*states[14]*(states[0]-computedConstants[6]):computedConstants[22]*states[14]*(states[0]+102.0); + algebraic[50] = (constants[1] == 0.0)?1.0*exp(-(states[0]+78.91)/26.62):1.0*exp(-(states[0]+78.91)/26.63); + algebraic[51] = 1.0*exp((states[0]+75.13)/21.25); } diff --git a/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.h b/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.h index 79f9f5c87a..543be7bd12 100644 --- a/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.h +++ b/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[31]; char units[27]; char component[53]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.py b/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.py index f1add8b415..0095d973ec 100644 --- a/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.py +++ b/tests/resources/generator/garny_kohl_hunter_boyett_noble_rabbit_san_model_2003/model.py @@ -4,227 +4,226 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 15 -VARIABLE_COUNT = 185 +CONSTANT_COUNT = 110 +COMPUTED_CONSTANT_COUNT = 23 +ALGEBRAIC_COUNT = 52 +VOI_INFO = {"name": "time", "units": "second", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "m", "units": "dimensionless", "component": "sodium_current_m_gate"}, + {"name": "h1", "units": "dimensionless", "component": "sodium_current_h_gate"}, + {"name": "h2", "units": "dimensionless", "component": "sodium_current_h_gate"}, + {"name": "f_L", "units": "dimensionless", "component": "L_type_Ca_channel_f_gate"}, + {"name": "d_L", "units": "dimensionless", "component": "L_type_Ca_channel_d_gate"}, + {"name": "f_T", "units": "dimensionless", "component": "T_type_Ca_channel_f_gate"}, + {"name": "d_T", "units": "dimensionless", "component": "T_type_Ca_channel_d_gate"}, + {"name": "r", "units": "dimensionless", "component": "four_AP_sensitive_currents_r_gate"}, + {"name": "q", "units": "dimensionless", "component": "four_AP_sensitive_currents_q_gate"}, + {"name": "P_i", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_i_gate"}, + {"name": "P_af", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_af_gate"}, + {"name": "P_as", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_as_gate"}, + {"name": "xs", "units": "dimensionless", "component": "slow_delayed_rectifying_potassium_current_xs_gate"}, + {"name": "y", "units": "dimensionless", "component": "hyperpolarisation_activated_current_y_gate"} +] -VOI_INFO = {"name": "time", "units": "second", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "dCell", "units": "dimensionless", "component": "membrane"}, + {"name": "Version", "units": "dimensionless", "component": "membrane"}, + {"name": "FCellConstant", "units": "dimensionless", "component": "membrane"}, + {"name": "CmCentre", "units": "microF", "component": "membrane"}, + {"name": "CmPeriphery", "units": "microF", "component": "membrane"}, + {"name": "R", "units": "millijoule_per_mole_kelvin", "component": "membrane"}, + {"name": "T", "units": "kelvin", "component": "membrane"}, + {"name": "F", "units": "coulomb_per_mole", "component": "membrane"}, + {"name": "g_b_Na_Centre_Published", "units": "microS", "component": "sodium_background_current"}, + {"name": "g_b_Na_Periphery_Published", "units": "microS", "component": "sodium_background_current"}, + {"name": "g_b_Na_Centre_1DCapable", "units": "microS", "component": "sodium_background_current"}, + {"name": "g_b_Na_Periphery_1DCapable", "units": "microS", "component": "sodium_background_current"}, + {"name": "g_b_Na_Centre_0DCapable", "units": "microS", "component": "sodium_background_current"}, + {"name": "g_b_Na_Periphery_0DCapable", "units": "microS", "component": "sodium_background_current"}, + {"name": "g_b_K_Centre_Published", "units": "microS", "component": "potassium_background_current"}, + {"name": "g_b_K_Periphery_Published", "units": "microS", "component": "potassium_background_current"}, + {"name": "g_b_K_Centre_1DCapable", "units": "microS", "component": "potassium_background_current"}, + {"name": "g_b_K_Periphery_1DCapable", "units": "microS", "component": "potassium_background_current"}, + {"name": "g_b_K_Centre_0DCapable", "units": "microS", "component": "potassium_background_current"}, + {"name": "g_b_K_Periphery_0DCapable", "units": "microS", "component": "potassium_background_current"}, + {"name": "g_b_Ca_Centre_Published", "units": "microS", "component": "calcium_background_current"}, + {"name": "g_b_Ca_Periphery_Published", "units": "microS", "component": "calcium_background_current"}, + {"name": "g_b_Ca_Centre_1DCapable", "units": "microS", "component": "calcium_background_current"}, + {"name": "g_b_Ca_Periphery_1DCapable", "units": "microS", "component": "calcium_background_current"}, + {"name": "g_b_Ca_Centre_0DCapable", "units": "microS", "component": "calcium_background_current"}, + {"name": "g_b_Ca_Periphery_0DCapable", "units": "microS", "component": "calcium_background_current"}, + {"name": "k_NaCa_Centre_Published", "units": "nanoA", "component": "sodium_calcium_exchanger"}, + {"name": "k_NaCa_Periphery_Published", "units": "nanoA", "component": "sodium_calcium_exchanger"}, + {"name": "k_NaCa_Centre_1DCapable", "units": "nanoA", "component": "sodium_calcium_exchanger"}, + {"name": "k_NaCa_Periphery_1DCapable", "units": "nanoA", "component": "sodium_calcium_exchanger"}, + {"name": "k_NaCa_Centre_0DCapable", "units": "nanoA", "component": "sodium_calcium_exchanger"}, + {"name": "k_NaCa_Periphery_0DCapable", "units": "nanoA", "component": "sodium_calcium_exchanger"}, + {"name": "Na_i", "units": "millimolar", "component": "ionic_concentrations"}, + {"name": "gamma_NaCa", "units": "dimensionless", "component": "sodium_calcium_exchanger"}, + {"name": "Ca_o", "units": "millimolar", "component": "ionic_concentrations"}, + {"name": "Na_o", "units": "millimolar", "component": "ionic_concentrations"}, + {"name": "Ca_i", "units": "millimolar", "component": "ionic_concentrations"}, + {"name": "d_NaCa", "units": "dimensionless", "component": "sodium_calcium_exchanger"}, + {"name": "i_p_max_Centre_Published", "units": "nanoA", "component": "sodium_potassium_pump"}, + {"name": "i_p_max_Periphery_Published", "units": "nanoA", "component": "sodium_potassium_pump"}, + {"name": "i_p_max_Centre_1DCapable", "units": "nanoA", "component": "sodium_potassium_pump"}, + {"name": "i_p_max_Periphery_1DCapable", "units": "nanoA", "component": "sodium_potassium_pump"}, + {"name": "i_p_max_Centre_0DCapable", "units": "nanoA", "component": "sodium_potassium_pump"}, + {"name": "i_p_max_Periphery_0DCapable", "units": "nanoA", "component": "sodium_potassium_pump"}, + {"name": "K_o", "units": "millimolar", "component": "ionic_concentrations"}, + {"name": "K_m_K", "units": "millimolar", "component": "sodium_potassium_pump"}, + {"name": "K_m_Na", "units": "millimolar", "component": "sodium_potassium_pump"}, + {"name": "i_Ca_p_max_Centre_Published", "units": "nanoA", "component": "persistent_calcium_current"}, + {"name": "i_Ca_p_max_Periphery_Published", "units": "nanoA", "component": "persistent_calcium_current"}, + {"name": "i_Ca_p_max_Centre_1DCapable", "units": "nanoA", "component": "persistent_calcium_current"}, + {"name": "i_Ca_p_max_Periphery_1DCapable", "units": "nanoA", "component": "persistent_calcium_current"}, + {"name": "i_Ca_p_max_Centre_0DCapable", "units": "nanoA", "component": "persistent_calcium_current"}, + {"name": "i_Ca_p_max_Periphery_0DCapable", "units": "nanoA", "component": "persistent_calcium_current"}, + {"name": "K_i", "units": "millimolar", "component": "ionic_concentrations"}, + {"name": "g_Na_Centre_Published", "units": "microlitre_per_second", "component": "sodium_current"}, + {"name": "g_Na_Periphery_Published", "units": "microlitre_per_second", "component": "sodium_current"}, + {"name": "g_Na_Centre_1DCapable", "units": "microlitre_per_second", "component": "sodium_current"}, + {"name": "g_Na_Periphery_1DCapable", "units": "microlitre_per_second", "component": "sodium_current"}, + {"name": "g_Na_Centre_0DCapable", "units": "microlitre_per_second", "component": "sodium_current"}, + {"name": "g_Na_Periphery_0DCapable", "units": "microlitre_per_second", "component": "sodium_current"}, + {"name": "g_Ca_L_Centre_Published", "units": "microS", "component": "L_type_Ca_channel"}, + {"name": "g_Ca_L_Periphery_Published", "units": "microS", "component": "L_type_Ca_channel"}, + {"name": "g_Ca_L_Centre_1DCapable", "units": "microS", "component": "L_type_Ca_channel"}, + {"name": "g_Ca_L_Periphery_1DCapable", "units": "microS", "component": "L_type_Ca_channel"}, + {"name": "g_Ca_L_Centre_0DCapable", "units": "microS", "component": "L_type_Ca_channel"}, + {"name": "g_Ca_L_Periphery_0DCapable", "units": "microS", "component": "L_type_Ca_channel"}, + {"name": "E_Ca_L", "units": "millivolt", "component": "L_type_Ca_channel"}, + {"name": "g_Ca_T_Centre_Published", "units": "microS", "component": "T_type_Ca_channel"}, + {"name": "g_Ca_T_Periphery_Published", "units": "microS", "component": "T_type_Ca_channel"}, + {"name": "g_Ca_T_Centre_1DCapable", "units": "microS", "component": "T_type_Ca_channel"}, + {"name": "g_Ca_T_Periphery_1DCapable", "units": "microS", "component": "T_type_Ca_channel"}, + {"name": "g_Ca_T_Centre_0DCapable", "units": "microS", "component": "T_type_Ca_channel"}, + {"name": "g_Ca_T_Periphery_0DCapable", "units": "microS", "component": "T_type_Ca_channel"}, + {"name": "E_Ca_T", "units": "millivolt", "component": "T_type_Ca_channel"}, + {"name": "g_to_Centre_Published", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_to_Periphery_Published", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_to_Centre_1DCapable", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_to_Periphery_1DCapable", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_to_Centre_0DCapable", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_to_Periphery_0DCapable", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_sus_Centre_Published", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_sus_Periphery_Published", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_sus_Centre_1DCapable", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_sus_Periphery_1DCapable", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_sus_Centre_0DCapable", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_sus_Periphery_0DCapable", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_K_r_Centre_Published", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current"}, + {"name": "g_K_r_Periphery_Published", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current"}, + {"name": "g_K_r_Centre_1DCapable", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current"}, + {"name": "g_K_r_Periphery_1DCapable", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current"}, + {"name": "g_K_r_Centre_0DCapable", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current"}, + {"name": "g_K_r_Periphery_0DCapable", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current"}, + {"name": "g_K_s_Centre_Published", "units": "microS", "component": "slow_delayed_rectifying_potassium_current"}, + {"name": "g_K_s_Periphery_Published", "units": "microS", "component": "slow_delayed_rectifying_potassium_current"}, + {"name": "g_K_s_Centre_1DCapable", "units": "microS", "component": "slow_delayed_rectifying_potassium_current"}, + {"name": "g_K_s_Periphery_1DCapable", "units": "microS", "component": "slow_delayed_rectifying_potassium_current"}, + {"name": "g_K_s_Centre_0DCapable", "units": "microS", "component": "slow_delayed_rectifying_potassium_current"}, + {"name": "g_K_s_Periphery_0DCapable", "units": "microS", "component": "slow_delayed_rectifying_potassium_current"}, + {"name": "g_f_Na_Centre_Published", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_Na_Periphery_Published", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_Na_Centre_1DCapable", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_Na_Periphery_1DCapable", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_Na_Centre_0DCapable", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_Na_Periphery_0DCapable", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_K_Centre_Published", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_K_Periphery_Published", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_K_Centre_1DCapable", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_K_Periphery_1DCapable", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_K_Centre_0DCapable", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_K_Periphery_0DCapable", "units": "microS", "component": "hyperpolarisation_activated_current"} +] -STATE_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "sodium_current_m_gate", "type": VariableType.STATE}, - {"name": "h1", "units": "dimensionless", "component": "sodium_current_h_gate", "type": VariableType.STATE}, - {"name": "h2", "units": "dimensionless", "component": "sodium_current_h_gate", "type": VariableType.STATE}, - {"name": "f_L", "units": "dimensionless", "component": "L_type_Ca_channel_f_gate", "type": VariableType.STATE}, - {"name": "d_L", "units": "dimensionless", "component": "L_type_Ca_channel_d_gate", "type": VariableType.STATE}, - {"name": "f_T", "units": "dimensionless", "component": "T_type_Ca_channel_f_gate", "type": VariableType.STATE}, - {"name": "d_T", "units": "dimensionless", "component": "T_type_Ca_channel_d_gate", "type": VariableType.STATE}, - {"name": "r", "units": "dimensionless", "component": "four_AP_sensitive_currents_r_gate", "type": VariableType.STATE}, - {"name": "q", "units": "dimensionless", "component": "four_AP_sensitive_currents_q_gate", "type": VariableType.STATE}, - {"name": "P_i", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_i_gate", "type": VariableType.STATE}, - {"name": "P_af", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_af_gate", "type": VariableType.STATE}, - {"name": "P_as", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_as_gate", "type": VariableType.STATE}, - {"name": "xs", "units": "dimensionless", "component": "slow_delayed_rectifying_potassium_current_xs_gate", "type": VariableType.STATE}, - {"name": "y", "units": "dimensionless", "component": "hyperpolarisation_activated_current_y_gate", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ + {"name": "FCell", "units": "dimensionless", "component": "membrane"}, + {"name": "Cm", "units": "microF", "component": "membrane"}, + {"name": "i_Ca_p", "units": "nanoA", "component": "persistent_calcium_current"}, + {"name": "g_b_Na", "units": "microS", "component": "sodium_background_current"}, + {"name": "E_Na", "units": "millivolt", "component": "reversal_and_equilibrium_potentials"}, + {"name": "g_b_K", "units": "microS", "component": "potassium_background_current"}, + {"name": "E_K", "units": "millivolt", "component": "reversal_and_equilibrium_potentials"}, + {"name": "g_b_Ca", "units": "microS", "component": "calcium_background_current"}, + {"name": "E_Ca", "units": "millivolt", "component": "reversal_and_equilibrium_potentials"}, + {"name": "k_NaCa", "units": "nanoA", "component": "sodium_calcium_exchanger"}, + {"name": "i_p_max", "units": "nanoA", "component": "sodium_potassium_pump"}, + {"name": "i_Ca_p_max", "units": "nanoA", "component": "persistent_calcium_current"}, + {"name": "E_K_s", "units": "millivolt", "component": "reversal_and_equilibrium_potentials"}, + {"name": "g_Na", "units": "microlitre_per_second", "component": "sodium_current"}, + {"name": "g_Ca_L", "units": "microS", "component": "L_type_Ca_channel"}, + {"name": "g_Ca_T", "units": "microS", "component": "T_type_Ca_channel"}, + {"name": "g_to", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_sus", "units": "microS", "component": "four_AP_sensitive_currents"}, + {"name": "g_K_r", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current"}, + {"name": "tau_P_i", "units": "second", "component": "rapid_delayed_rectifying_potassium_current_P_i_gate"}, + {"name": "g_K_s", "units": "microS", "component": "slow_delayed_rectifying_potassium_current"}, + {"name": "g_f_Na", "units": "microS", "component": "hyperpolarisation_activated_current"}, + {"name": "g_f_K", "units": "microS", "component": "hyperpolarisation_activated_current"} ] -VARIABLE_INFO = [ - {"name": "FCell", "units": "dimensionless", "component": "membrane", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "dCell", "units": "dimensionless", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "Version", "units": "dimensionless", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "FCellConstant", "units": "dimensionless", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "Cm", "units": "microF", "component": "membrane", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "CmCentre", "units": "microF", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "CmPeriphery", "units": "microF", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "i_Na", "units": "nanoA", "component": "sodium_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_Ca_p", "units": "nanoA", "component": "persistent_calcium_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "i_p", "units": "nanoA", "component": "sodium_potassium_pump", "type": VariableType.ALGEBRAIC}, - {"name": "i_NaCa", "units": "nanoA", "component": "sodium_calcium_exchanger", "type": VariableType.ALGEBRAIC}, - {"name": "i_b_K", "units": "nanoA", "component": "potassium_background_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_b_Ca", "units": "nanoA", "component": "calcium_background_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_b_Na", "units": "nanoA", "component": "sodium_background_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_f_K", "units": "nanoA", "component": "hyperpolarisation_activated_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_f_Na", "units": "nanoA", "component": "hyperpolarisation_activated_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K_s", "units": "nanoA", "component": "slow_delayed_rectifying_potassium_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K_r", "units": "nanoA", "component": "rapid_delayed_rectifying_potassium_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_sus", "units": "nanoA", "component": "four_AP_sensitive_currents", "type": VariableType.ALGEBRAIC}, - {"name": "i_to", "units": "nanoA", "component": "four_AP_sensitive_currents", "type": VariableType.ALGEBRAIC}, - {"name": "i_Ca_T", "units": "nanoA", "component": "T_type_Ca_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Ca_L", "units": "nanoA", "component": "L_type_Ca_channel", "type": VariableType.ALGEBRAIC}, - {"name": "R", "units": "millijoule_per_mole_kelvin", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "T", "units": "kelvin", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "F", "units": "coulomb_per_mole", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "g_b_Na", "units": "microS", "component": "sodium_background_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_b_Na_Centre_Published", "units": "microS", "component": "sodium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_Na_Periphery_Published", "units": "microS", "component": "sodium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_Na_Centre_1DCapable", "units": "microS", "component": "sodium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_Na_Periphery_1DCapable", "units": "microS", "component": "sodium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_Na_Centre_0DCapable", "units": "microS", "component": "sodium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_Na_Periphery_0DCapable", "units": "microS", "component": "sodium_background_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "reversal_and_equilibrium_potentials", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_b_K", "units": "microS", "component": "potassium_background_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_b_K_Centre_Published", "units": "microS", "component": "potassium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_K_Periphery_Published", "units": "microS", "component": "potassium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_K_Centre_1DCapable", "units": "microS", "component": "potassium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_K_Periphery_1DCapable", "units": "microS", "component": "potassium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_K_Centre_0DCapable", "units": "microS", "component": "potassium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_K_Periphery_0DCapable", "units": "microS", "component": "potassium_background_current", "type": VariableType.CONSTANT}, - {"name": "E_K", "units": "millivolt", "component": "reversal_and_equilibrium_potentials", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_b_Ca", "units": "microS", "component": "calcium_background_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_b_Ca_Centre_Published", "units": "microS", "component": "calcium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_Ca_Periphery_Published", "units": "microS", "component": "calcium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_Ca_Centre_1DCapable", "units": "microS", "component": "calcium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_Ca_Periphery_1DCapable", "units": "microS", "component": "calcium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_Ca_Centre_0DCapable", "units": "microS", "component": "calcium_background_current", "type": VariableType.CONSTANT}, - {"name": "g_b_Ca_Periphery_0DCapable", "units": "microS", "component": "calcium_background_current", "type": VariableType.CONSTANT}, - {"name": "E_Ca", "units": "millivolt", "component": "reversal_and_equilibrium_potentials", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "k_NaCa", "units": "nanoA", "component": "sodium_calcium_exchanger", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "k_NaCa_Centre_Published", "units": "nanoA", "component": "sodium_calcium_exchanger", "type": VariableType.CONSTANT}, - {"name": "k_NaCa_Periphery_Published", "units": "nanoA", "component": "sodium_calcium_exchanger", "type": VariableType.CONSTANT}, - {"name": "k_NaCa_Centre_1DCapable", "units": "nanoA", "component": "sodium_calcium_exchanger", "type": VariableType.CONSTANT}, - {"name": "k_NaCa_Periphery_1DCapable", "units": "nanoA", "component": "sodium_calcium_exchanger", "type": VariableType.CONSTANT}, - {"name": "k_NaCa_Centre_0DCapable", "units": "nanoA", "component": "sodium_calcium_exchanger", "type": VariableType.CONSTANT}, - {"name": "k_NaCa_Periphery_0DCapable", "units": "nanoA", "component": "sodium_calcium_exchanger", "type": VariableType.CONSTANT}, - {"name": "Na_i", "units": "millimolar", "component": "ionic_concentrations", "type": VariableType.CONSTANT}, - {"name": "gamma_NaCa", "units": "dimensionless", "component": "sodium_calcium_exchanger", "type": VariableType.CONSTANT}, - {"name": "Ca_o", "units": "millimolar", "component": "ionic_concentrations", "type": VariableType.CONSTANT}, - {"name": "Na_o", "units": "millimolar", "component": "ionic_concentrations", "type": VariableType.CONSTANT}, - {"name": "Ca_i", "units": "millimolar", "component": "ionic_concentrations", "type": VariableType.CONSTANT}, - {"name": "d_NaCa", "units": "dimensionless", "component": "sodium_calcium_exchanger", "type": VariableType.CONSTANT}, - {"name": "i_p_max", "units": "nanoA", "component": "sodium_potassium_pump", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "i_p_max_Centre_Published", "units": "nanoA", "component": "sodium_potassium_pump", "type": VariableType.CONSTANT}, - {"name": "i_p_max_Periphery_Published", "units": "nanoA", "component": "sodium_potassium_pump", "type": VariableType.CONSTANT}, - {"name": "i_p_max_Centre_1DCapable", "units": "nanoA", "component": "sodium_potassium_pump", "type": VariableType.CONSTANT}, - {"name": "i_p_max_Periphery_1DCapable", "units": "nanoA", "component": "sodium_potassium_pump", "type": VariableType.CONSTANT}, - {"name": "i_p_max_Centre_0DCapable", "units": "nanoA", "component": "sodium_potassium_pump", "type": VariableType.CONSTANT}, - {"name": "i_p_max_Periphery_0DCapable", "units": "nanoA", "component": "sodium_potassium_pump", "type": VariableType.CONSTANT}, - {"name": "K_o", "units": "millimolar", "component": "ionic_concentrations", "type": VariableType.CONSTANT}, - {"name": "K_m_K", "units": "millimolar", "component": "sodium_potassium_pump", "type": VariableType.CONSTANT}, - {"name": "K_m_Na", "units": "millimolar", "component": "sodium_potassium_pump", "type": VariableType.CONSTANT}, - {"name": "i_Ca_p_max", "units": "nanoA", "component": "persistent_calcium_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "i_Ca_p_max_Centre_Published", "units": "nanoA", "component": "persistent_calcium_current", "type": VariableType.CONSTANT}, - {"name": "i_Ca_p_max_Periphery_Published", "units": "nanoA", "component": "persistent_calcium_current", "type": VariableType.CONSTANT}, - {"name": "i_Ca_p_max_Centre_1DCapable", "units": "nanoA", "component": "persistent_calcium_current", "type": VariableType.CONSTANT}, - {"name": "i_Ca_p_max_Periphery_1DCapable", "units": "nanoA", "component": "persistent_calcium_current", "type": VariableType.CONSTANT}, - {"name": "i_Ca_p_max_Centre_0DCapable", "units": "nanoA", "component": "persistent_calcium_current", "type": VariableType.CONSTANT}, - {"name": "i_Ca_p_max_Periphery_0DCapable", "units": "nanoA", "component": "persistent_calcium_current", "type": VariableType.CONSTANT}, - {"name": "K_i", "units": "millimolar", "component": "ionic_concentrations", "type": VariableType.CONSTANT}, - {"name": "E_K_s", "units": "millivolt", "component": "reversal_and_equilibrium_potentials", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na", "units": "microlitre_per_second", "component": "sodium_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na_Centre_Published", "units": "microlitre_per_second", "component": "sodium_current", "type": VariableType.CONSTANT}, - {"name": "g_Na_Periphery_Published", "units": "microlitre_per_second", "component": "sodium_current", "type": VariableType.CONSTANT}, - {"name": "g_Na_Centre_1DCapable", "units": "microlitre_per_second", "component": "sodium_current", "type": VariableType.CONSTANT}, - {"name": "g_Na_Periphery_1DCapable", "units": "microlitre_per_second", "component": "sodium_current", "type": VariableType.CONSTANT}, - {"name": "g_Na_Centre_0DCapable", "units": "microlitre_per_second", "component": "sodium_current", "type": VariableType.CONSTANT}, - {"name": "g_Na_Periphery_0DCapable", "units": "microlitre_per_second", "component": "sodium_current", "type": VariableType.CONSTANT}, - {"name": "h", "units": "dimensionless", "component": "sodium_current_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "m_infinity", "units": "dimensionless", "component": "sodium_current_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_m", "units": "second", "component": "sodium_current_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "F_Na", "units": "dimensionless", "component": "sodium_current_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "h1_infinity", "units": "dimensionless", "component": "sodium_current_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_h1", "units": "second", "component": "sodium_current_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "h2_infinity", "units": "dimensionless", "component": "sodium_current_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_h2", "units": "second", "component": "sodium_current_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "g_Ca_L", "units": "microS", "component": "L_type_Ca_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Ca_L_Centre_Published", "units": "microS", "component": "L_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "g_Ca_L_Periphery_Published", "units": "microS", "component": "L_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "g_Ca_L_Centre_1DCapable", "units": "microS", "component": "L_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "g_Ca_L_Periphery_1DCapable", "units": "microS", "component": "L_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "g_Ca_L_Centre_0DCapable", "units": "microS", "component": "L_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "g_Ca_L_Periphery_0DCapable", "units": "microS", "component": "L_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "E_Ca_L", "units": "millivolt", "component": "L_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "d_L_infinity", "units": "dimensionless", "component": "L_type_Ca_channel_d_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_d_L", "units": "second", "component": "L_type_Ca_channel_d_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_d_L", "units": "per_second", "component": "L_type_Ca_channel_d_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_d_L", "units": "per_second", "component": "L_type_Ca_channel_d_gate", "type": VariableType.ALGEBRAIC}, - {"name": "f_L_infinity", "units": "dimensionless", "component": "L_type_Ca_channel_f_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_f_L", "units": "second", "component": "L_type_Ca_channel_f_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_f_L", "units": "per_second", "component": "L_type_Ca_channel_f_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_f_L", "units": "per_second", "component": "L_type_Ca_channel_f_gate", "type": VariableType.ALGEBRAIC}, - {"name": "g_Ca_T", "units": "microS", "component": "T_type_Ca_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Ca_T_Centre_Published", "units": "microS", "component": "T_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "g_Ca_T_Periphery_Published", "units": "microS", "component": "T_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "g_Ca_T_Centre_1DCapable", "units": "microS", "component": "T_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "g_Ca_T_Periphery_1DCapable", "units": "microS", "component": "T_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "g_Ca_T_Centre_0DCapable", "units": "microS", "component": "T_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "g_Ca_T_Periphery_0DCapable", "units": "microS", "component": "T_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "E_Ca_T", "units": "millivolt", "component": "T_type_Ca_channel", "type": VariableType.CONSTANT}, - {"name": "d_T_infinity", "units": "dimensionless", "component": "T_type_Ca_channel_d_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_d_T", "units": "second", "component": "T_type_Ca_channel_d_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_d_T", "units": "per_second", "component": "T_type_Ca_channel_d_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_d_T", "units": "per_second", "component": "T_type_Ca_channel_d_gate", "type": VariableType.ALGEBRAIC}, - {"name": "f_T_infinity", "units": "dimensionless", "component": "T_type_Ca_channel_f_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_f_T", "units": "second", "component": "T_type_Ca_channel_f_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_f_T", "units": "per_second", "component": "T_type_Ca_channel_f_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_f_T", "units": "per_second", "component": "T_type_Ca_channel_f_gate", "type": VariableType.ALGEBRAIC}, - {"name": "g_to", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_to_Centre_Published", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "g_to_Periphery_Published", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "g_to_Centre_1DCapable", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "g_to_Periphery_1DCapable", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "g_to_Centre_0DCapable", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "g_to_Periphery_0DCapable", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "g_sus", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_sus_Centre_Published", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "g_sus_Periphery_Published", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "g_sus_Centre_1DCapable", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "g_sus_Periphery_1DCapable", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "g_sus_Centre_0DCapable", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "g_sus_Periphery_0DCapable", "units": "microS", "component": "four_AP_sensitive_currents", "type": VariableType.CONSTANT}, - {"name": "q_infinity", "units": "dimensionless", "component": "four_AP_sensitive_currents_q_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_q", "units": "second", "component": "four_AP_sensitive_currents_q_gate", "type": VariableType.ALGEBRAIC}, - {"name": "r_infinity", "units": "dimensionless", "component": "four_AP_sensitive_currents_r_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_r", "units": "second", "component": "four_AP_sensitive_currents_r_gate", "type": VariableType.ALGEBRAIC}, - {"name": "g_K_r", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K_r_Centre_Published", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "g_K_r_Periphery_Published", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "g_K_r_Centre_1DCapable", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "g_K_r_Periphery_1DCapable", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "g_K_r_Centre_0DCapable", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "g_K_r_Periphery_0DCapable", "units": "microS", "component": "rapid_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "P_a", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current", "type": VariableType.ALGEBRAIC}, - {"name": "P_af_infinity", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_af_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_P_af", "units": "second", "component": "rapid_delayed_rectifying_potassium_current_P_af_gate", "type": VariableType.ALGEBRAIC}, - {"name": "P_as_infinity", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_as_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_P_as", "units": "second", "component": "rapid_delayed_rectifying_potassium_current_P_as_gate", "type": VariableType.ALGEBRAIC}, - {"name": "tau_P_i", "units": "second", "component": "rapid_delayed_rectifying_potassium_current_P_i_gate", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "P_i_infinity", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_i_gate", "type": VariableType.ALGEBRAIC}, - {"name": "g_K_s", "units": "microS", "component": "slow_delayed_rectifying_potassium_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K_s_Centre_Published", "units": "microS", "component": "slow_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "g_K_s_Periphery_Published", "units": "microS", "component": "slow_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "g_K_s_Centre_1DCapable", "units": "microS", "component": "slow_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "g_K_s_Periphery_1DCapable", "units": "microS", "component": "slow_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "g_K_s_Centre_0DCapable", "units": "microS", "component": "slow_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "g_K_s_Periphery_0DCapable", "units": "microS", "component": "slow_delayed_rectifying_potassium_current", "type": VariableType.CONSTANT}, - {"name": "alpha_xs", "units": "per_second", "component": "slow_delayed_rectifying_potassium_current_xs_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_xs", "units": "per_second", "component": "slow_delayed_rectifying_potassium_current_xs_gate", "type": VariableType.ALGEBRAIC}, - {"name": "g_f_Na", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_f_Na_Centre_Published", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "g_f_Na_Periphery_Published", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "g_f_Na_Centre_1DCapable", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "g_f_Na_Periphery_1DCapable", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "g_f_Na_Centre_0DCapable", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "g_f_Na_Periphery_0DCapable", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "g_f_K", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_f_K_Centre_Published", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "g_f_K_Periphery_Published", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "g_f_K_Centre_1DCapable", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "g_f_K_Periphery_1DCapable", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "g_f_K_Centre_0DCapable", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "g_f_K_Periphery_0DCapable", "units": "microS", "component": "hyperpolarisation_activated_current", "type": VariableType.CONSTANT}, - {"name": "alpha_y", "units": "per_second", "component": "hyperpolarisation_activated_current_y_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_y", "units": "per_second", "component": "hyperpolarisation_activated_current_y_gate", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "i_Na", "units": "nanoA", "component": "sodium_current"}, + {"name": "i_p", "units": "nanoA", "component": "sodium_potassium_pump"}, + {"name": "i_NaCa", "units": "nanoA", "component": "sodium_calcium_exchanger"}, + {"name": "i_b_K", "units": "nanoA", "component": "potassium_background_current"}, + {"name": "i_b_Ca", "units": "nanoA", "component": "calcium_background_current"}, + {"name": "i_b_Na", "units": "nanoA", "component": "sodium_background_current"}, + {"name": "i_f_K", "units": "nanoA", "component": "hyperpolarisation_activated_current"}, + {"name": "i_f_Na", "units": "nanoA", "component": "hyperpolarisation_activated_current"}, + {"name": "i_K_s", "units": "nanoA", "component": "slow_delayed_rectifying_potassium_current"}, + {"name": "i_K_r", "units": "nanoA", "component": "rapid_delayed_rectifying_potassium_current"}, + {"name": "i_sus", "units": "nanoA", "component": "four_AP_sensitive_currents"}, + {"name": "i_to", "units": "nanoA", "component": "four_AP_sensitive_currents"}, + {"name": "i_Ca_T", "units": "nanoA", "component": "T_type_Ca_channel"}, + {"name": "i_Ca_L", "units": "nanoA", "component": "L_type_Ca_channel"}, + {"name": "h", "units": "dimensionless", "component": "sodium_current_h_gate"}, + {"name": "m_infinity", "units": "dimensionless", "component": "sodium_current_m_gate"}, + {"name": "tau_m", "units": "second", "component": "sodium_current_m_gate"}, + {"name": "F_Na", "units": "dimensionless", "component": "sodium_current_h_gate"}, + {"name": "h1_infinity", "units": "dimensionless", "component": "sodium_current_h_gate"}, + {"name": "tau_h1", "units": "second", "component": "sodium_current_h_gate"}, + {"name": "h2_infinity", "units": "dimensionless", "component": "sodium_current_h_gate"}, + {"name": "tau_h2", "units": "second", "component": "sodium_current_h_gate"}, + {"name": "d_L_infinity", "units": "dimensionless", "component": "L_type_Ca_channel_d_gate"}, + {"name": "tau_d_L", "units": "second", "component": "L_type_Ca_channel_d_gate"}, + {"name": "alpha_d_L", "units": "per_second", "component": "L_type_Ca_channel_d_gate"}, + {"name": "beta_d_L", "units": "per_second", "component": "L_type_Ca_channel_d_gate"}, + {"name": "f_L_infinity", "units": "dimensionless", "component": "L_type_Ca_channel_f_gate"}, + {"name": "tau_f_L", "units": "second", "component": "L_type_Ca_channel_f_gate"}, + {"name": "alpha_f_L", "units": "per_second", "component": "L_type_Ca_channel_f_gate"}, + {"name": "beta_f_L", "units": "per_second", "component": "L_type_Ca_channel_f_gate"}, + {"name": "d_T_infinity", "units": "dimensionless", "component": "T_type_Ca_channel_d_gate"}, + {"name": "tau_d_T", "units": "second", "component": "T_type_Ca_channel_d_gate"}, + {"name": "alpha_d_T", "units": "per_second", "component": "T_type_Ca_channel_d_gate"}, + {"name": "beta_d_T", "units": "per_second", "component": "T_type_Ca_channel_d_gate"}, + {"name": "f_T_infinity", "units": "dimensionless", "component": "T_type_Ca_channel_f_gate"}, + {"name": "tau_f_T", "units": "second", "component": "T_type_Ca_channel_f_gate"}, + {"name": "alpha_f_T", "units": "per_second", "component": "T_type_Ca_channel_f_gate"}, + {"name": "beta_f_T", "units": "per_second", "component": "T_type_Ca_channel_f_gate"}, + {"name": "q_infinity", "units": "dimensionless", "component": "four_AP_sensitive_currents_q_gate"}, + {"name": "tau_q", "units": "second", "component": "four_AP_sensitive_currents_q_gate"}, + {"name": "r_infinity", "units": "dimensionless", "component": "four_AP_sensitive_currents_r_gate"}, + {"name": "tau_r", "units": "second", "component": "four_AP_sensitive_currents_r_gate"}, + {"name": "P_a", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current"}, + {"name": "P_af_infinity", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_af_gate"}, + {"name": "tau_P_af", "units": "second", "component": "rapid_delayed_rectifying_potassium_current_P_af_gate"}, + {"name": "P_as_infinity", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_as_gate"}, + {"name": "tau_P_as", "units": "second", "component": "rapid_delayed_rectifying_potassium_current_P_as_gate"}, + {"name": "P_i_infinity", "units": "dimensionless", "component": "rapid_delayed_rectifying_potassium_current_P_i_gate"}, + {"name": "alpha_xs", "units": "per_second", "component": "slow_delayed_rectifying_potassium_current_xs_gate"}, + {"name": "beta_xs", "units": "per_second", "component": "slow_delayed_rectifying_potassium_current_xs_gate"}, + {"name": "alpha_y", "units": "per_second", "component": "hyperpolarisation_activated_current_y_gate"}, + {"name": "beta_y", "units": "per_second", "component": "hyperpolarisation_activated_current_y_gate"} ] @@ -240,121 +239,19 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[1] = 0.0 - variables[2] = 1.0 - variables[3] = 1.0309347 - variables[5] = 2.0e-5 - variables[6] = 6.5e-5 - variables[22] = 8314.0 - variables[23] = 310.0 - variables[24] = 96845.0 - variables[26] = 5.8e-5 - variables[27] = 0.000189 - variables[28] = 5.8e-5 - variables[29] = 0.000189 - variables[30] = 5.81818e-5 - variables[31] = 0.0001888 - variables[34] = 2.52e-5 - variables[35] = 8.19e-5 - variables[36] = 2.52e-5 - variables[37] = 8.19e-5 - variables[38] = 2.523636e-5 - variables[39] = 8.1892e-5 - variables[42] = 1.32e-5 - variables[43] = 4.3e-5 - variables[44] = 1.323e-5 - variables[45] = 4.29e-5 - variables[46] = 1.3236e-5 - variables[47] = 4.2952e-5 - variables[50] = 2.7e-6 - variables[51] = 8.8e-6 - variables[52] = 2.8e-6 - variables[53] = 8.8e-6 - variables[54] = 2.7229e-6 - variables[55] = 8.83584e-6 - variables[56] = 8.0 - variables[57] = 0.5 - variables[58] = 2.0 - variables[59] = 140.0 - variables[60] = 0.0001 - variables[61] = 0.0001 - variables[63] = 0.0478 - variables[64] = 0.16 - variables[65] = 0.0478 - variables[66] = 0.16 - variables[67] = 0.04782545 - variables[68] = 0.1551936 - variables[69] = 5.4 - variables[70] = 0.621 - variables[71] = 5.64 - variables[73] = 0.0 - variables[74] = 0.0 - variables[75] = 0.0042 - variables[76] = 0.03339 - variables[77] = 0.0 - variables[78] = 0.0 - variables[79] = 140.0 - variables[82] = 0.0 - variables[83] = 1.2e-6 - variables[84] = 0.0 - variables[85] = 3.7e-7 - variables[86] = 0.0 - variables[87] = 1.204e-6 - variables[97] = 0.0058 - variables[98] = 0.0659 - variables[99] = 0.0082 - variables[100] = 0.0659 - variables[101] = 0.0057938 - variables[102] = 0.06588648 - variables[103] = 46.4 - variables[113] = 0.0043 - variables[114] = 0.0139 - variables[115] = 0.0021 - variables[116] = 0.00694 - variables[117] = 0.00427806 - variables[118] = 0.0138823 - variables[119] = 45.0 - variables[129] = 0.00491 - variables[130] = 0.03649 - variables[131] = 0.004905 - variables[132] = 0.0365 - variables[133] = 0.004905 - variables[134] = 0.036495 - variables[136] = 6.65e-5 - variables[137] = 0.0114 - variables[138] = 0.000266 - variables[139] = 0.0114 - variables[140] = 6.645504e-5 - variables[141] = 0.01138376 - variables[147] = 0.000797 - variables[148] = 0.016 - variables[149] = 0.000738 - variables[150] = 0.0208 - variables[151] = 0.00079704 - variables[152] = 0.016 - variables[161] = 0.000518 - variables[162] = 0.0104 - variables[163] = 0.000345 - variables[164] = 0.0104 - variables[165] = 0.0003445 - variables[166] = 0.0104 - variables[170] = 0.000548 - variables[171] = 0.0069 - variables[172] = 0.000437 - variables[173] = 0.0055 - variables[174] = 0.0005465 - variables[175] = 0.006875 - variables[177] = 0.000548 - variables[178] = 0.0069 - variables[179] = 0.000437 - variables[180] = 0.0055 - variables[181] = 0.0005465 - variables[182] = 0.006875 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = -39.013558536 states[1] = 0.092361701692 states[2] = 0.015905380261 @@ -370,154 +267,264 @@ def initialise_variables(states, rates, variables): states[12] = 0.46960956028 states[13] = 0.082293827208 states[14] = 0.03889291759 + constants[0] = 0.0 + constants[1] = 1.0 + constants[2] = 1.0309347 + constants[3] = 2.0e-5 + constants[4] = 6.5e-5 + constants[5] = 8314.0 + constants[6] = 310.0 + constants[7] = 96845.0 + constants[8] = 5.8e-5 + constants[9] = 0.000189 + constants[10] = 5.8e-5 + constants[11] = 0.000189 + constants[12] = 5.81818e-5 + constants[13] = 0.0001888 + constants[14] = 2.52e-5 + constants[15] = 8.19e-5 + constants[16] = 2.52e-5 + constants[17] = 8.19e-5 + constants[18] = 2.523636e-5 + constants[19] = 8.1892e-5 + constants[20] = 1.32e-5 + constants[21] = 4.3e-5 + constants[22] = 1.323e-5 + constants[23] = 4.29e-5 + constants[24] = 1.3236e-5 + constants[25] = 4.2952e-5 + constants[26] = 2.7e-6 + constants[27] = 8.8e-6 + constants[28] = 2.8e-6 + constants[29] = 8.8e-6 + constants[30] = 2.7229e-6 + constants[31] = 8.83584e-6 + constants[32] = 8.0 + constants[33] = 0.5 + constants[34] = 2.0 + constants[35] = 140.0 + constants[36] = 0.0001 + constants[37] = 0.0001 + constants[38] = 0.0478 + constants[39] = 0.16 + constants[40] = 0.0478 + constants[41] = 0.16 + constants[42] = 0.04782545 + constants[43] = 0.1551936 + constants[44] = 5.4 + constants[45] = 0.621 + constants[46] = 5.64 + constants[47] = 0.0 + constants[48] = 0.0 + constants[49] = 0.0042 + constants[50] = 0.03339 + constants[51] = 0.0 + constants[52] = 0.0 + constants[53] = 140.0 + constants[54] = 0.0 + constants[55] = 1.2e-6 + constants[56] = 0.0 + constants[57] = 3.7e-7 + constants[58] = 0.0 + constants[59] = 1.204e-6 + constants[60] = 0.0058 + constants[61] = 0.0659 + constants[62] = 0.0082 + constants[63] = 0.0659 + constants[64] = 0.0057938 + constants[65] = 0.06588648 + constants[66] = 46.4 + constants[67] = 0.0043 + constants[68] = 0.0139 + constants[69] = 0.0021 + constants[70] = 0.00694 + constants[71] = 0.00427806 + constants[72] = 0.0138823 + constants[73] = 45.0 + constants[74] = 0.00491 + constants[75] = 0.03649 + constants[76] = 0.004905 + constants[77] = 0.0365 + constants[78] = 0.004905 + constants[79] = 0.036495 + constants[80] = 6.65e-5 + constants[81] = 0.0114 + constants[82] = 0.000266 + constants[83] = 0.0114 + constants[84] = 6.645504e-5 + constants[85] = 0.01138376 + constants[86] = 0.000797 + constants[87] = 0.016 + constants[88] = 0.000738 + constants[89] = 0.0208 + constants[90] = 0.00079704 + constants[91] = 0.016 + constants[92] = 0.000518 + constants[93] = 0.0104 + constants[94] = 0.000345 + constants[95] = 0.0104 + constants[96] = 0.0003445 + constants[97] = 0.0104 + constants[98] = 0.000548 + constants[99] = 0.0069 + constants[100] = 0.000437 + constants[101] = 0.0055 + constants[102] = 0.0005465 + constants[103] = 0.006875 + constants[104] = 0.000548 + constants[105] = 0.0069 + constants[106] = 0.000437 + constants[107] = 0.0055 + constants[108] = 0.0005465 + constants[109] = 0.006875 -def compute_computed_constants(variables): - variables[0] = 1.07*(3.0*variables[1]-0.1)/(3.0*(1.0+0.7745*exp(-(3.0*variables[1]-2.05)/0.295))) if eq_func(variables[2], 0.0) else variables[3]*variables[1]/(1.0+0.7745*exp(-(3.0*variables[1]-2.05)/0.295)) if eq_func(variables[2], 1.0) else 1.07*29.0*variables[1]/(30.0*(1.0+0.7745*exp(-(29.0*variables[1]-24.5)/1.95))) - variables[4] = variables[5]+variables[0]*(variables[6]-variables[5]) - variables[25] = variables[26]+variables[0]*(variables[27]-variables[26]) if eq_func(variables[2], 0.0) else variables[30]+variables[0]*(variables[31]-variables[30]) if eq_func(variables[2], 1.0) else variables[28]+variables[0]*(variables[29]-variables[28]) - variables[33] = variables[34]+variables[0]*(variables[35]-variables[34]) if eq_func(variables[2], 0.0) else variables[38]+variables[0]*(variables[39]-variables[38]) if eq_func(variables[2], 1.0) else variables[36]+variables[0]*(variables[37]-variables[36]) - variables[41] = variables[42]+variables[0]*(variables[43]-variables[42]) if eq_func(variables[2], 0.0) else variables[46]+variables[0]*(variables[47]-variables[46]) if eq_func(variables[2], 1.0) else variables[44]+variables[0]*(variables[45]-variables[44]) - variables[49] = variables[50]+variables[0]*(variables[51]-variables[50]) if eq_func(variables[2], 0.0) else variables[54]+variables[0]*(variables[55]-variables[54]) if eq_func(variables[2], 1.0) else variables[52]+variables[0]*(variables[53]-variables[52]) - variables[62] = variables[63]+variables[0]*(variables[64]-variables[63]) if eq_func(variables[2], 0.0) else variables[67]+variables[0]*(variables[68]-variables[67]) if eq_func(variables[2], 1.0) else variables[65]+variables[0]*(variables[66]-variables[65]) - variables[72] = variables[73]+variables[0]*(variables[74]-variables[73]) if eq_func(variables[2], 0.0) else variables[77]+variables[0]*(variables[78]-variables[77]) if eq_func(variables[2], 1.0) else variables[75]+variables[0]*(variables[76]-variables[75]) - variables[8] = variables[72]*variables[60]/(variables[60]+0.0004) - variables[32] = variables[22]*variables[23]/variables[24]*log(variables[59]/variables[56]) - variables[40] = variables[22]*variables[23]/variables[24]*log(variables[69]/variables[79]) - variables[48] = variables[22]*variables[23]/(2.0*variables[24])*log(variables[58]/variables[60]) - variables[80] = variables[22]*variables[23]/variables[24]*log((variables[69]+0.12*variables[59])/(variables[79]+0.12*variables[56])) if eq_func(variables[2], 0.0) else variables[22]*variables[23]/variables[24]*log((variables[69]+0.03*variables[59])/(variables[79]+0.03*variables[56])) - variables[81] = variables[82]+variables[0]*(variables[83]-variables[82]) if eq_func(variables[2], 0.0) else variables[86]+variables[0]*(variables[87]-variables[86]) if eq_func(variables[2], 1.0) else variables[84]+variables[0]*(variables[85]-variables[84]) - variables[96] = variables[97]+variables[0]*(variables[98]-variables[97]) if eq_func(variables[2], 0.0) else variables[101]+variables[0]*(variables[102]-variables[101]) if eq_func(variables[2], 1.0) else variables[99]+variables[0]*(variables[100]-variables[99]) - variables[112] = variables[113]+variables[0]*(variables[114]-variables[113]) if eq_func(variables[2], 0.0) else variables[117]+variables[0]*(variables[118]-variables[117]) if eq_func(variables[2], 1.0) else variables[115]+variables[0]*(variables[116]-variables[115]) - variables[128] = variables[129]+variables[0]*(variables[130]-variables[129]) if eq_func(variables[2], 0.0) else variables[133]+variables[0]*(variables[134]-variables[133]) if eq_func(variables[2], 1.0) else variables[131]+variables[0]*(variables[132]-variables[131]) - variables[135] = variables[136]+variables[0]*(variables[137]-variables[136]) if eq_func(variables[2], 0.0) else variables[140]+variables[0]*(variables[141]-variables[140]) if eq_func(variables[2], 1.0) else variables[138]+variables[0]*(variables[139]-variables[138]) - variables[146] = variables[147]+variables[0]*(variables[148]-variables[147]) if eq_func(variables[2], 0.0) else variables[151]+variables[0]*(variables[152]-variables[151]) if eq_func(variables[2], 1.0) else variables[149]+variables[0]*(variables[150]-variables[149]) - variables[158] = 0.002 if eq_func(variables[2], 0.0) else 0.002 if eq_func(variables[2], 1.0) else 0.006 - variables[160] = variables[161]+variables[0]*(variables[162]-variables[161]) if eq_func(variables[2], 0.0) else variables[165]+variables[0]*(variables[166]-variables[165]) if eq_func(variables[2], 1.0) else variables[163]+variables[0]*(variables[164]-variables[163]) - variables[169] = variables[170]+variables[0]*(variables[171]-variables[170]) if eq_func(variables[2], 0.0) else variables[174]+variables[0]*(variables[175]-variables[174]) if eq_func(variables[2], 1.0) else variables[172]+variables[0]*(variables[173]-variables[172]) - variables[176] = variables[177]+variables[0]*(variables[178]-variables[177]) if eq_func(variables[2], 0.0) else variables[181]+variables[0]*(variables[182]-variables[181]) if eq_func(variables[2], 1.0) else variables[179]+variables[0]*(variables[180]-variables[179]) +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = 1.07*(3.0*constants[0]-0.1)/(3.0*(1.0+0.7745*exp(-(3.0*constants[0]-2.05)/0.295))) if eq_func(constants[1], 0.0) else constants[2]*constants[0]/(1.0+0.7745*exp(-(3.0*constants[0]-2.05)/0.295)) if eq_func(constants[1], 1.0) else 1.07*29.0*constants[0]/(30.0*(1.0+0.7745*exp(-(29.0*constants[0]-24.5)/1.95))) + computed_constants[1] = constants[3]+computed_constants[0]*(constants[4]-constants[3]) + computed_constants[3] = constants[8]+computed_constants[0]*(constants[9]-constants[8]) if eq_func(constants[1], 0.0) else constants[12]+computed_constants[0]*(constants[13]-constants[12]) if eq_func(constants[1], 1.0) else constants[10]+computed_constants[0]*(constants[11]-constants[10]) + computed_constants[5] = constants[14]+computed_constants[0]*(constants[15]-constants[14]) if eq_func(constants[1], 0.0) else constants[18]+computed_constants[0]*(constants[19]-constants[18]) if eq_func(constants[1], 1.0) else constants[16]+computed_constants[0]*(constants[17]-constants[16]) + computed_constants[7] = constants[20]+computed_constants[0]*(constants[21]-constants[20]) if eq_func(constants[1], 0.0) else constants[24]+computed_constants[0]*(constants[25]-constants[24]) if eq_func(constants[1], 1.0) else constants[22]+computed_constants[0]*(constants[23]-constants[22]) + computed_constants[9] = constants[26]+computed_constants[0]*(constants[27]-constants[26]) if eq_func(constants[1], 0.0) else constants[30]+computed_constants[0]*(constants[31]-constants[30]) if eq_func(constants[1], 1.0) else constants[28]+computed_constants[0]*(constants[29]-constants[28]) + computed_constants[10] = constants[38]+computed_constants[0]*(constants[39]-constants[38]) if eq_func(constants[1], 0.0) else constants[42]+computed_constants[0]*(constants[43]-constants[42]) if eq_func(constants[1], 1.0) else constants[40]+computed_constants[0]*(constants[41]-constants[40]) + computed_constants[11] = constants[47]+computed_constants[0]*(constants[48]-constants[47]) if eq_func(constants[1], 0.0) else constants[51]+computed_constants[0]*(constants[52]-constants[51]) if eq_func(constants[1], 1.0) else constants[49]+computed_constants[0]*(constants[50]-constants[49]) + computed_constants[2] = computed_constants[11]*constants[36]/(constants[36]+0.0004) + computed_constants[4] = constants[5]*constants[6]/constants[7]*log(constants[35]/constants[32]) + computed_constants[6] = constants[5]*constants[6]/constants[7]*log(constants[44]/constants[53]) + computed_constants[8] = constants[5]*constants[6]/(2.0*constants[7])*log(constants[34]/constants[36]) + computed_constants[12] = constants[5]*constants[6]/constants[7]*log((constants[44]+0.12*constants[35])/(constants[53]+0.12*constants[32])) if eq_func(constants[1], 0.0) else constants[5]*constants[6]/constants[7]*log((constants[44]+0.03*constants[35])/(constants[53]+0.03*constants[32])) + computed_constants[13] = constants[54]+computed_constants[0]*(constants[55]-constants[54]) if eq_func(constants[1], 0.0) else constants[58]+computed_constants[0]*(constants[59]-constants[58]) if eq_func(constants[1], 1.0) else constants[56]+computed_constants[0]*(constants[57]-constants[56]) + computed_constants[14] = constants[60]+computed_constants[0]*(constants[61]-constants[60]) if eq_func(constants[1], 0.0) else constants[64]+computed_constants[0]*(constants[65]-constants[64]) if eq_func(constants[1], 1.0) else constants[62]+computed_constants[0]*(constants[63]-constants[62]) + computed_constants[15] = constants[67]+computed_constants[0]*(constants[68]-constants[67]) if eq_func(constants[1], 0.0) else constants[71]+computed_constants[0]*(constants[72]-constants[71]) if eq_func(constants[1], 1.0) else constants[69]+computed_constants[0]*(constants[70]-constants[69]) + computed_constants[16] = constants[74]+computed_constants[0]*(constants[75]-constants[74]) if eq_func(constants[1], 0.0) else constants[78]+computed_constants[0]*(constants[79]-constants[78]) if eq_func(constants[1], 1.0) else constants[76]+computed_constants[0]*(constants[77]-constants[76]) + computed_constants[17] = constants[80]+computed_constants[0]*(constants[81]-constants[80]) if eq_func(constants[1], 0.0) else constants[84]+computed_constants[0]*(constants[85]-constants[84]) if eq_func(constants[1], 1.0) else constants[82]+computed_constants[0]*(constants[83]-constants[82]) + computed_constants[18] = constants[86]+computed_constants[0]*(constants[87]-constants[86]) if eq_func(constants[1], 0.0) else constants[90]+computed_constants[0]*(constants[91]-constants[90]) if eq_func(constants[1], 1.0) else constants[88]+computed_constants[0]*(constants[89]-constants[88]) + computed_constants[19] = 0.002 if eq_func(constants[1], 0.0) else 0.002 if eq_func(constants[1], 1.0) else 0.006 + computed_constants[20] = constants[92]+computed_constants[0]*(constants[93]-constants[92]) if eq_func(constants[1], 0.0) else constants[96]+computed_constants[0]*(constants[97]-constants[96]) if eq_func(constants[1], 1.0) else constants[94]+computed_constants[0]*(constants[95]-constants[94]) + computed_constants[21] = constants[98]+computed_constants[0]*(constants[99]-constants[98]) if eq_func(constants[1], 0.0) else constants[102]+computed_constants[0]*(constants[103]-constants[102]) if eq_func(constants[1], 1.0) else constants[100]+computed_constants[0]*(constants[101]-constants[100]) + computed_constants[22] = constants[104]+computed_constants[0]*(constants[105]-constants[104]) if eq_func(constants[1], 0.0) else constants[108]+computed_constants[0]*(constants[109]-constants[108]) if eq_func(constants[1], 1.0) else constants[106]+computed_constants[0]*(constants[107]-constants[106]) -def compute_rates(voi, states, rates, variables): - variables[9] = variables[62]*pow(variables[56]/(variables[71]+variables[56]), 3.0)*pow(variables[69]/(variables[70]+variables[69]), 2.0)*1.6/(1.5+exp(-(states[0]+60.0)/40.0)) - variables[10] = variables[49]*(pow(variables[56], 3.0)*variables[58]*exp(0.03743*states[0]*variables[57])-pow(variables[59], 3.0)*variables[60]*exp(0.0374*states[0]*(variables[57]-1.0)))/(1.0+variables[61]*(variables[60]*pow(variables[59], 3.0)+variables[58]*pow(variables[56], 3.0))) if eq_func(variables[2], 0.0) else variables[49]*(pow(variables[56], 3.0)*variables[58]*exp(0.03743*states[0]*variables[57])-pow(variables[59], 3.0)*variables[60]*exp(0.03743*states[0]*(variables[57]-1.0)))/(1.0+variables[61]*(variables[60]*pow(variables[59], 3.0)+variables[58]*pow(variables[56], 3.0))) - variables[14] = variables[176]*states[14]*(states[0]-variables[40]) if neq_func(variables[2], 2.0) else variables[176]*states[14]*(states[0]+102.0) - variables[15] = variables[169]*states[14]*(states[0]-variables[32]) if neq_func(variables[2], 2.0) else variables[169]*states[14]*(states[0]-77.6) - variables[16] = variables[160]*pow(states[13], 2.0)*(states[0]-variables[80]) - variables[18] = variables[135]*states[8]*(states[0]-variables[40]) - variables[19] = variables[128]*states[9]*states[8]*(states[0]-variables[40]) - variables[20] = variables[112]*states[7]*states[6]*(states[0]-variables[119]) - variables[21] = variables[96]*(states[4]*states[5]+0.006/(1.0+exp(-(states[0]+14.1)/6.0)))*(states[0]-variables[103]) - variables[91] = 0.0952*exp(-0.063*(states[0]+34.4))/(1.0+1.66*exp(-0.225*(states[0]+63.7)))+0.0869 if eq_func(variables[2], 0.0) else 0.09518*exp(-0.06306*(states[0]+34.4))/(1.0+1.662*exp(-0.2251*(states[0]+63.7)))+0.08693 - variables[88] = (1.0-variables[91])*states[2]+variables[91]*states[3] - variables[7] = variables[81]*pow(states[1], 3.0)*variables[88]*variables[59]*pow(variables[24], 2.0)/(variables[22]*variables[23])*(exp((states[0]-variables[32])*variables[24]/(variables[22]*variables[23]))-1.0)/(exp(states[0]*variables[24]/(variables[22]*variables[23]))-1.0)*states[0] - variables[11] = variables[33]*(states[0]-variables[40]) - variables[12] = variables[41]*(states[0]-variables[48]) - variables[13] = variables[25]*(states[0]-variables[32]) - variables[153] = 0.6*states[11]+0.4*states[12] - variables[17] = variables[146]*variables[153]*states[10]*(states[0]-variables[40]) - rates[0] = -1.0/variables[4]*(variables[7]+variables[21]+variables[20]+variables[19]+variables[18]+variables[17]+variables[16]+variables[15]+variables[14]+variables[13]+variables[12]+variables[11]+variables[10]+variables[9]+variables[8]) - variables[89] = pow(1.0/(1.0+exp(-states[0]/5.46)), 1.0/3.0) if eq_func(variables[2], 0.0) else pow(1.0/(1.0+exp(-(states[0]+30.32)/5.46)), 1.0/3.0) - variables[90] = 0.0006247/(0.832*exp(-0.335*(states[0]+56.7))+0.627*exp(0.082*(states[0]+65.01)))+4.0e-5 if eq_func(variables[2], 0.0) else 0.0006247/(0.8322166*exp(-0.33566*(states[0]+56.7062))+0.6274*exp(0.0823*(states[0]+65.0131)))+4.569e-5 - rates[1] = (variables[89]-states[1])/variables[90] - variables[92] = 1.0/(1.0+exp((states[0]+66.1)/6.4)) - variables[93] = 3.717e-6*exp(-0.2815*(states[0]+17.11))/(1.0+0.003732*exp(-0.3426*(states[0]+37.76)))+0.0005977 - rates[2] = (variables[92]-states[2])/variables[93] - variables[94] = variables[92] - variables[95] = 3.186e-8*exp(-0.6219*(states[0]+18.8))/(1.0+7.189e-5*exp(-0.6683*(states[0]+34.07)))+0.003556 - rates[3] = (variables[94]-states[3])/variables[95] - variables[104] = 1.0/(1.0+exp(-(states[0]+23.1)/6.0)) if eq_func(variables[2], 0.0) else 1.0/(1.0+exp(-(states[0]+22.3+0.8*variables[0])/6.0)) if eq_func(variables[2], 1.0) else 1.0/(1.0+exp(-(states[0]+22.2)/6.0)) - variables[106] = -28.38*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) if eq_func(variables[2], 0.0) else -28.39*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) if eq_func(variables[2], 1.0) else -28.4*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) - variables[107] = 11.43*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0) if eq_func(variables[2], 1.0) else 11.42*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0) - variables[105] = 2.0/(variables[106]+variables[107]) - rates[5] = (variables[104]-states[5])/variables[105] - variables[108] = 1.0/(1.0+exp((states[0]+45.0)/5.0)) - variables[110] = 3.75*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0) if eq_func(variables[2], 1.0) else 3.12*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0) - variables[111] = 30.0/(1.0+exp(-(states[0]+28.0)/4.0)) if eq_func(variables[2], 1.0) else 25.0/(1.0+exp(-(states[0]+28.0)/4.0)) - variables[109] = (1.2-0.2*variables[0])/(variables[110]+variables[111]) if eq_func(variables[2], 1.0) else 1.0/(variables[110]+variables[111]) - rates[4] = (variables[108]-states[4])/variables[109] - variables[120] = 1.0/(1.0+exp(-(states[0]+37.0)/6.8)) - variables[122] = 1068.0*exp((states[0]+26.3)/30.0) - variables[123] = 1068.0*exp(-(states[0]+26.3)/30.0) - variables[121] = 1.0/(variables[122]+variables[123]) - rates[7] = (variables[120]-states[7])/variables[121] - variables[124] = 1.0/(1.0+exp((states[0]+71.0)/9.0)) - variables[126] = 15.3*exp(-(states[0]+71.0+0.7*variables[0])/83.3) if eq_func(variables[2], 1.0) else 15.3*exp(-(states[0]+71.7)/83.3) - variables[127] = 15.0*exp((states[0]+71.0)/15.38) if eq_func(variables[2], 1.0) else 15.0*exp((states[0]+71.7)/15.38) - variables[125] = 1.0/(variables[126]+variables[127]) - rates[6] = (variables[124]-states[6])/variables[125] - variables[142] = 1.0/(1.0+exp((states[0]+59.37)/13.1)) - variables[143] = 0.0101+0.06517/(0.57*exp(-0.08*(states[0]+49.0)))+2.4e-5*exp(0.1*(states[0]+50.93)) if eq_func(variables[2], 0.0) else 0.001/3.0*(30.31+195.5/(0.5686*exp(-0.08161*(states[0]+39.0+10.0*variables[0]))+0.7174*exp((0.2719-0.1719*variables[0])*1.0*(states[0]+40.93+10.0*variables[0])))) if eq_func(variables[2], 1.0) else 0.0101+0.06517/(0.5686*exp(-0.08161*(states[0]+39.0))+0.7174*exp(0.2719*(states[0]+40.93))) - rates[9] = (variables[142]-states[9])/variables[143] - variables[144] = 1.0/(1.0+exp(-(states[0]-10.93)/19.7)) - variables[145] = 0.001*(2.98+15.59/(1.037*exp(0.09*(states[0]+30.61))+0.369*exp(-0.12*(states[0]+23.84)))) if eq_func(variables[2], 0.0) else 0.0025*(1.191+7.838/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))) if eq_func(variables[2], 1.0) else 0.001*(2.98+19.59/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))) - rates[8] = (variables[144]-states[8])/variables[145] - variables[154] = 1.0/(1.0+exp(-(states[0]+14.2)/10.6)) if neq_func(variables[2], 2.0) else 1.0/(1.0+exp(-(states[0]+13.2)/10.6)) - variables[155] = 1.0/(37.2*exp((states[0]-9.0)/15.9)+0.96*exp(-(states[0]-9.0)/22.5)) if neq_func(variables[2], 2.0) else 1.0/(37.2*exp((states[0]-10.0)/15.9)+0.96*exp(-(states[0]-10.0)/22.5)) - rates[11] = (variables[154]-states[11])/variables[155] - variables[156] = variables[154] - variables[157] = 1.0/(4.2*exp((states[0]-9.0)/17.0)+0.15*exp(-(states[0]-9.0)/21.6)) if neq_func(variables[2], 2.0) else 1.0/(4.2*exp((states[0]-10.0)/17.0)+0.15*exp(-(states[0]-10.0)/21.6)) - rates[12] = (variables[156]-states[12])/variables[157] - variables[159] = 1.0/(1.0+exp((states[0]+18.6)/10.1)) - rates[10] = (variables[159]-states[10])/variables[158] - variables[167] = 14.0/(1.0+exp(-(states[0]-40.0)/9.0)) - variables[168] = 1.0*exp(-states[0]/45.0) - rates[13] = variables[167]*(1.0-states[13])-variables[168]*states[13] - variables[183] = 1.0*exp(-(states[0]+78.91)/26.62) if eq_func(variables[2], 0.0) else 1.0*exp(-(states[0]+78.91)/26.63) - variables[184] = 1.0*exp((states[0]+75.13)/21.25) - rates[14] = variables[183]*(1.0-states[14])-variables[184]*states[14] +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + algebraic[1] = computed_constants[10]*pow(constants[32]/(constants[46]+constants[32]), 3.0)*pow(constants[44]/(constants[45]+constants[44]), 2.0)*1.6/(1.5+exp(-(states[0]+60.0)/40.0)) + algebraic[2] = computed_constants[9]*(pow(constants[32], 3.0)*constants[34]*exp(0.03743*states[0]*constants[33])-pow(constants[35], 3.0)*constants[36]*exp(0.0374*states[0]*(constants[33]-1.0)))/(1.0+constants[37]*(constants[36]*pow(constants[35], 3.0)+constants[34]*pow(constants[32], 3.0))) if eq_func(constants[1], 0.0) else computed_constants[9]*(pow(constants[32], 3.0)*constants[34]*exp(0.03743*states[0]*constants[33])-pow(constants[35], 3.0)*constants[36]*exp(0.03743*states[0]*(constants[33]-1.0)))/(1.0+constants[37]*(constants[36]*pow(constants[35], 3.0)+constants[34]*pow(constants[32], 3.0))) + algebraic[6] = computed_constants[22]*states[14]*(states[0]-computed_constants[6]) if neq_func(constants[1], 2.0) else computed_constants[22]*states[14]*(states[0]+102.0) + algebraic[7] = computed_constants[21]*states[14]*(states[0]-computed_constants[4]) if neq_func(constants[1], 2.0) else computed_constants[21]*states[14]*(states[0]-77.6) + algebraic[8] = computed_constants[20]*pow(states[13], 2.0)*(states[0]-computed_constants[12]) + algebraic[10] = computed_constants[17]*states[8]*(states[0]-computed_constants[6]) + algebraic[11] = computed_constants[16]*states[9]*states[8]*(states[0]-computed_constants[6]) + algebraic[12] = computed_constants[15]*states[7]*states[6]*(states[0]-constants[73]) + algebraic[13] = computed_constants[14]*(states[4]*states[5]+0.006/(1.0+exp(-(states[0]+14.1)/6.0)))*(states[0]-constants[66]) + algebraic[17] = 0.0952*exp(-0.063*(states[0]+34.4))/(1.0+1.66*exp(-0.225*(states[0]+63.7)))+0.0869 if eq_func(constants[1], 0.0) else 0.09518*exp(-0.06306*(states[0]+34.4))/(1.0+1.662*exp(-0.2251*(states[0]+63.7)))+0.08693 + algebraic[14] = (1.0-algebraic[17])*states[2]+algebraic[17]*states[3] + algebraic[0] = computed_constants[13]*pow(states[1], 3.0)*algebraic[14]*constants[35]*pow(constants[7], 2.0)/(constants[5]*constants[6])*(exp((states[0]-computed_constants[4])*constants[7]/(constants[5]*constants[6]))-1.0)/(exp(states[0]*constants[7]/(constants[5]*constants[6]))-1.0)*states[0] + algebraic[3] = computed_constants[5]*(states[0]-computed_constants[6]) + algebraic[4] = computed_constants[7]*(states[0]-computed_constants[8]) + algebraic[5] = computed_constants[3]*(states[0]-computed_constants[4]) + algebraic[42] = 0.6*states[11]+0.4*states[12] + algebraic[9] = computed_constants[18]*algebraic[42]*states[10]*(states[0]-computed_constants[6]) + rates[0] = -1.0/computed_constants[1]*(algebraic[0]+algebraic[13]+algebraic[12]+algebraic[11]+algebraic[10]+algebraic[9]+algebraic[8]+algebraic[7]+algebraic[6]+algebraic[5]+algebraic[4]+algebraic[3]+algebraic[2]+algebraic[1]+computed_constants[2]) + algebraic[15] = pow(1.0/(1.0+exp(-states[0]/5.46)), 1.0/3.0) if eq_func(constants[1], 0.0) else pow(1.0/(1.0+exp(-(states[0]+30.32)/5.46)), 1.0/3.0) + algebraic[16] = 0.0006247/(0.832*exp(-0.335*(states[0]+56.7))+0.627*exp(0.082*(states[0]+65.01)))+4.0e-5 if eq_func(constants[1], 0.0) else 0.0006247/(0.8322166*exp(-0.33566*(states[0]+56.7062))+0.6274*exp(0.0823*(states[0]+65.0131)))+4.569e-5 + rates[1] = (algebraic[15]-states[1])/algebraic[16] + algebraic[18] = 1.0/(1.0+exp((states[0]+66.1)/6.4)) + algebraic[19] = 3.717e-6*exp(-0.2815*(states[0]+17.11))/(1.0+0.003732*exp(-0.3426*(states[0]+37.76)))+0.0005977 + rates[2] = (algebraic[18]-states[2])/algebraic[19] + algebraic[20] = algebraic[18] + algebraic[21] = 3.186e-8*exp(-0.6219*(states[0]+18.8))/(1.0+7.189e-5*exp(-0.6683*(states[0]+34.07)))+0.003556 + rates[3] = (algebraic[20]-states[3])/algebraic[21] + algebraic[22] = 1.0/(1.0+exp(-(states[0]+23.1)/6.0)) if eq_func(constants[1], 0.0) else 1.0/(1.0+exp(-(states[0]+22.3+0.8*computed_constants[0])/6.0)) if eq_func(constants[1], 1.0) else 1.0/(1.0+exp(-(states[0]+22.2)/6.0)) + algebraic[24] = -28.38*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) if eq_func(constants[1], 0.0) else -28.39*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) if eq_func(constants[1], 1.0) else -28.4*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) + algebraic[25] = 11.43*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0) if eq_func(constants[1], 1.0) else 11.42*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0) + algebraic[23] = 2.0/(algebraic[24]+algebraic[25]) + rates[5] = (algebraic[22]-states[5])/algebraic[23] + algebraic[26] = 1.0/(1.0+exp((states[0]+45.0)/5.0)) + algebraic[28] = 3.75*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0) if eq_func(constants[1], 1.0) else 3.12*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0) + algebraic[29] = 30.0/(1.0+exp(-(states[0]+28.0)/4.0)) if eq_func(constants[1], 1.0) else 25.0/(1.0+exp(-(states[0]+28.0)/4.0)) + algebraic[27] = (1.2-0.2*computed_constants[0])/(algebraic[28]+algebraic[29]) if eq_func(constants[1], 1.0) else 1.0/(algebraic[28]+algebraic[29]) + rates[4] = (algebraic[26]-states[4])/algebraic[27] + algebraic[30] = 1.0/(1.0+exp(-(states[0]+37.0)/6.8)) + algebraic[32] = 1068.0*exp((states[0]+26.3)/30.0) + algebraic[33] = 1068.0*exp(-(states[0]+26.3)/30.0) + algebraic[31] = 1.0/(algebraic[32]+algebraic[33]) + rates[7] = (algebraic[30]-states[7])/algebraic[31] + algebraic[34] = 1.0/(1.0+exp((states[0]+71.0)/9.0)) + algebraic[36] = 15.3*exp(-(states[0]+71.0+0.7*computed_constants[0])/83.3) if eq_func(constants[1], 1.0) else 15.3*exp(-(states[0]+71.7)/83.3) + algebraic[37] = 15.0*exp((states[0]+71.0)/15.38) if eq_func(constants[1], 1.0) else 15.0*exp((states[0]+71.7)/15.38) + algebraic[35] = 1.0/(algebraic[36]+algebraic[37]) + rates[6] = (algebraic[34]-states[6])/algebraic[35] + algebraic[38] = 1.0/(1.0+exp((states[0]+59.37)/13.1)) + algebraic[39] = 0.0101+0.06517/(0.57*exp(-0.08*(states[0]+49.0)))+2.4e-5*exp(0.1*(states[0]+50.93)) if eq_func(constants[1], 0.0) else 0.001/3.0*(30.31+195.5/(0.5686*exp(-0.08161*(states[0]+39.0+10.0*computed_constants[0]))+0.7174*exp((0.2719-0.1719*computed_constants[0])*1.0*(states[0]+40.93+10.0*computed_constants[0])))) if eq_func(constants[1], 1.0) else 0.0101+0.06517/(0.5686*exp(-0.08161*(states[0]+39.0))+0.7174*exp(0.2719*(states[0]+40.93))) + rates[9] = (algebraic[38]-states[9])/algebraic[39] + algebraic[40] = 1.0/(1.0+exp(-(states[0]-10.93)/19.7)) + algebraic[41] = 0.001*(2.98+15.59/(1.037*exp(0.09*(states[0]+30.61))+0.369*exp(-0.12*(states[0]+23.84)))) if eq_func(constants[1], 0.0) else 0.0025*(1.191+7.838/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))) if eq_func(constants[1], 1.0) else 0.001*(2.98+19.59/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))) + rates[8] = (algebraic[40]-states[8])/algebraic[41] + algebraic[43] = 1.0/(1.0+exp(-(states[0]+14.2)/10.6)) if neq_func(constants[1], 2.0) else 1.0/(1.0+exp(-(states[0]+13.2)/10.6)) + algebraic[44] = 1.0/(37.2*exp((states[0]-9.0)/15.9)+0.96*exp(-(states[0]-9.0)/22.5)) if neq_func(constants[1], 2.0) else 1.0/(37.2*exp((states[0]-10.0)/15.9)+0.96*exp(-(states[0]-10.0)/22.5)) + rates[11] = (algebraic[43]-states[11])/algebraic[44] + algebraic[45] = algebraic[43] + algebraic[46] = 1.0/(4.2*exp((states[0]-9.0)/17.0)+0.15*exp(-(states[0]-9.0)/21.6)) if neq_func(constants[1], 2.0) else 1.0/(4.2*exp((states[0]-10.0)/17.0)+0.15*exp(-(states[0]-10.0)/21.6)) + rates[12] = (algebraic[45]-states[12])/algebraic[46] + algebraic[47] = 1.0/(1.0+exp((states[0]+18.6)/10.1)) + rates[10] = (algebraic[47]-states[10])/computed_constants[19] + algebraic[48] = 14.0/(1.0+exp(-(states[0]-40.0)/9.0)) + algebraic[49] = 1.0*exp(-states[0]/45.0) + rates[13] = algebraic[48]*(1.0-states[13])-algebraic[49]*states[13] + algebraic[50] = 1.0*exp(-(states[0]+78.91)/26.62) if eq_func(constants[1], 0.0) else 1.0*exp(-(states[0]+78.91)/26.63) + algebraic[51] = 1.0*exp((states[0]+75.13)/21.25) + rates[14] = algebraic[50]*(1.0-states[14])-algebraic[51]*states[14] -def compute_variables(voi, states, rates, variables): - variables[13] = variables[25]*(states[0]-variables[32]) - variables[11] = variables[33]*(states[0]-variables[40]) - variables[12] = variables[41]*(states[0]-variables[48]) - variables[10] = variables[49]*(pow(variables[56], 3.0)*variables[58]*exp(0.03743*states[0]*variables[57])-pow(variables[59], 3.0)*variables[60]*exp(0.0374*states[0]*(variables[57]-1.0)))/(1.0+variables[61]*(variables[60]*pow(variables[59], 3.0)+variables[58]*pow(variables[56], 3.0))) if eq_func(variables[2], 0.0) else variables[49]*(pow(variables[56], 3.0)*variables[58]*exp(0.03743*states[0]*variables[57])-pow(variables[59], 3.0)*variables[60]*exp(0.03743*states[0]*(variables[57]-1.0)))/(1.0+variables[61]*(variables[60]*pow(variables[59], 3.0)+variables[58]*pow(variables[56], 3.0))) - variables[9] = variables[62]*pow(variables[56]/(variables[71]+variables[56]), 3.0)*pow(variables[69]/(variables[70]+variables[69]), 2.0)*1.6/(1.5+exp(-(states[0]+60.0)/40.0)) - variables[91] = 0.0952*exp(-0.063*(states[0]+34.4))/(1.0+1.66*exp(-0.225*(states[0]+63.7)))+0.0869 if eq_func(variables[2], 0.0) else 0.09518*exp(-0.06306*(states[0]+34.4))/(1.0+1.662*exp(-0.2251*(states[0]+63.7)))+0.08693 - variables[88] = (1.0-variables[91])*states[2]+variables[91]*states[3] - variables[7] = variables[81]*pow(states[1], 3.0)*variables[88]*variables[59]*pow(variables[24], 2.0)/(variables[22]*variables[23])*(exp((states[0]-variables[32])*variables[24]/(variables[22]*variables[23]))-1.0)/(exp(states[0]*variables[24]/(variables[22]*variables[23]))-1.0)*states[0] - variables[89] = pow(1.0/(1.0+exp(-states[0]/5.46)), 1.0/3.0) if eq_func(variables[2], 0.0) else pow(1.0/(1.0+exp(-(states[0]+30.32)/5.46)), 1.0/3.0) - variables[90] = 0.0006247/(0.832*exp(-0.335*(states[0]+56.7))+0.627*exp(0.082*(states[0]+65.01)))+4.0e-5 if eq_func(variables[2], 0.0) else 0.0006247/(0.8322166*exp(-0.33566*(states[0]+56.7062))+0.6274*exp(0.0823*(states[0]+65.0131)))+4.569e-5 - variables[92] = 1.0/(1.0+exp((states[0]+66.1)/6.4)) - variables[94] = variables[92] - variables[93] = 3.717e-6*exp(-0.2815*(states[0]+17.11))/(1.0+0.003732*exp(-0.3426*(states[0]+37.76)))+0.0005977 - variables[95] = 3.186e-8*exp(-0.6219*(states[0]+18.8))/(1.0+7.189e-5*exp(-0.6683*(states[0]+34.07)))+0.003556 - variables[21] = variables[96]*(states[4]*states[5]+0.006/(1.0+exp(-(states[0]+14.1)/6.0)))*(states[0]-variables[103]) - variables[106] = -28.38*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) if eq_func(variables[2], 0.0) else -28.39*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) if eq_func(variables[2], 1.0) else -28.4*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) - variables[107] = 11.43*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0) if eq_func(variables[2], 1.0) else 11.42*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0) - variables[105] = 2.0/(variables[106]+variables[107]) - variables[104] = 1.0/(1.0+exp(-(states[0]+23.1)/6.0)) if eq_func(variables[2], 0.0) else 1.0/(1.0+exp(-(states[0]+22.3+0.8*variables[0])/6.0)) if eq_func(variables[2], 1.0) else 1.0/(1.0+exp(-(states[0]+22.2)/6.0)) - variables[110] = 3.75*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0) if eq_func(variables[2], 1.0) else 3.12*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0) - variables[111] = 30.0/(1.0+exp(-(states[0]+28.0)/4.0)) if eq_func(variables[2], 1.0) else 25.0/(1.0+exp(-(states[0]+28.0)/4.0)) - variables[109] = (1.2-0.2*variables[0])/(variables[110]+variables[111]) if eq_func(variables[2], 1.0) else 1.0/(variables[110]+variables[111]) - variables[108] = 1.0/(1.0+exp((states[0]+45.0)/5.0)) - variables[20] = variables[112]*states[7]*states[6]*(states[0]-variables[119]) - variables[122] = 1068.0*exp((states[0]+26.3)/30.0) - variables[123] = 1068.0*exp(-(states[0]+26.3)/30.0) - variables[121] = 1.0/(variables[122]+variables[123]) - variables[120] = 1.0/(1.0+exp(-(states[0]+37.0)/6.8)) - variables[126] = 15.3*exp(-(states[0]+71.0+0.7*variables[0])/83.3) if eq_func(variables[2], 1.0) else 15.3*exp(-(states[0]+71.7)/83.3) - variables[127] = 15.0*exp((states[0]+71.0)/15.38) if eq_func(variables[2], 1.0) else 15.0*exp((states[0]+71.7)/15.38) - variables[125] = 1.0/(variables[126]+variables[127]) - variables[124] = 1.0/(1.0+exp((states[0]+71.0)/9.0)) - variables[19] = variables[128]*states[9]*states[8]*(states[0]-variables[40]) - variables[18] = variables[135]*states[8]*(states[0]-variables[40]) - variables[142] = 1.0/(1.0+exp((states[0]+59.37)/13.1)) - variables[143] = 0.0101+0.06517/(0.57*exp(-0.08*(states[0]+49.0)))+2.4e-5*exp(0.1*(states[0]+50.93)) if eq_func(variables[2], 0.0) else 0.001/3.0*(30.31+195.5/(0.5686*exp(-0.08161*(states[0]+39.0+10.0*variables[0]))+0.7174*exp((0.2719-0.1719*variables[0])*1.0*(states[0]+40.93+10.0*variables[0])))) if eq_func(variables[2], 1.0) else 0.0101+0.06517/(0.5686*exp(-0.08161*(states[0]+39.0))+0.7174*exp(0.2719*(states[0]+40.93))) - variables[144] = 1.0/(1.0+exp(-(states[0]-10.93)/19.7)) - variables[145] = 0.001*(2.98+15.59/(1.037*exp(0.09*(states[0]+30.61))+0.369*exp(-0.12*(states[0]+23.84)))) if eq_func(variables[2], 0.0) else 0.0025*(1.191+7.838/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))) if eq_func(variables[2], 1.0) else 0.001*(2.98+19.59/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))) - variables[153] = 0.6*states[11]+0.4*states[12] - variables[17] = variables[146]*variables[153]*states[10]*(states[0]-variables[40]) - variables[154] = 1.0/(1.0+exp(-(states[0]+14.2)/10.6)) if neq_func(variables[2], 2.0) else 1.0/(1.0+exp(-(states[0]+13.2)/10.6)) - variables[155] = 1.0/(37.2*exp((states[0]-9.0)/15.9)+0.96*exp(-(states[0]-9.0)/22.5)) if neq_func(variables[2], 2.0) else 1.0/(37.2*exp((states[0]-10.0)/15.9)+0.96*exp(-(states[0]-10.0)/22.5)) - variables[156] = variables[154] - variables[157] = 1.0/(4.2*exp((states[0]-9.0)/17.0)+0.15*exp(-(states[0]-9.0)/21.6)) if neq_func(variables[2], 2.0) else 1.0/(4.2*exp((states[0]-10.0)/17.0)+0.15*exp(-(states[0]-10.0)/21.6)) - variables[159] = 1.0/(1.0+exp((states[0]+18.6)/10.1)) - variables[16] = variables[160]*pow(states[13], 2.0)*(states[0]-variables[80]) - variables[167] = 14.0/(1.0+exp(-(states[0]-40.0)/9.0)) - variables[168] = 1.0*exp(-states[0]/45.0) - variables[15] = variables[169]*states[14]*(states[0]-variables[32]) if neq_func(variables[2], 2.0) else variables[169]*states[14]*(states[0]-77.6) - variables[14] = variables[176]*states[14]*(states[0]-variables[40]) if neq_func(variables[2], 2.0) else variables[176]*states[14]*(states[0]+102.0) - variables[183] = 1.0*exp(-(states[0]+78.91)/26.62) if eq_func(variables[2], 0.0) else 1.0*exp(-(states[0]+78.91)/26.63) - variables[184] = 1.0*exp((states[0]+75.13)/21.25) +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[5] = computed_constants[3]*(states[0]-computed_constants[4]) + algebraic[3] = computed_constants[5]*(states[0]-computed_constants[6]) + algebraic[4] = computed_constants[7]*(states[0]-computed_constants[8]) + algebraic[2] = computed_constants[9]*(pow(constants[32], 3.0)*constants[34]*exp(0.03743*states[0]*constants[33])-pow(constants[35], 3.0)*constants[36]*exp(0.0374*states[0]*(constants[33]-1.0)))/(1.0+constants[37]*(constants[36]*pow(constants[35], 3.0)+constants[34]*pow(constants[32], 3.0))) if eq_func(constants[1], 0.0) else computed_constants[9]*(pow(constants[32], 3.0)*constants[34]*exp(0.03743*states[0]*constants[33])-pow(constants[35], 3.0)*constants[36]*exp(0.03743*states[0]*(constants[33]-1.0)))/(1.0+constants[37]*(constants[36]*pow(constants[35], 3.0)+constants[34]*pow(constants[32], 3.0))) + algebraic[1] = computed_constants[10]*pow(constants[32]/(constants[46]+constants[32]), 3.0)*pow(constants[44]/(constants[45]+constants[44]), 2.0)*1.6/(1.5+exp(-(states[0]+60.0)/40.0)) + algebraic[17] = 0.0952*exp(-0.063*(states[0]+34.4))/(1.0+1.66*exp(-0.225*(states[0]+63.7)))+0.0869 if eq_func(constants[1], 0.0) else 0.09518*exp(-0.06306*(states[0]+34.4))/(1.0+1.662*exp(-0.2251*(states[0]+63.7)))+0.08693 + algebraic[14] = (1.0-algebraic[17])*states[2]+algebraic[17]*states[3] + algebraic[0] = computed_constants[13]*pow(states[1], 3.0)*algebraic[14]*constants[35]*pow(constants[7], 2.0)/(constants[5]*constants[6])*(exp((states[0]-computed_constants[4])*constants[7]/(constants[5]*constants[6]))-1.0)/(exp(states[0]*constants[7]/(constants[5]*constants[6]))-1.0)*states[0] + algebraic[15] = pow(1.0/(1.0+exp(-states[0]/5.46)), 1.0/3.0) if eq_func(constants[1], 0.0) else pow(1.0/(1.0+exp(-(states[0]+30.32)/5.46)), 1.0/3.0) + algebraic[16] = 0.0006247/(0.832*exp(-0.335*(states[0]+56.7))+0.627*exp(0.082*(states[0]+65.01)))+4.0e-5 if eq_func(constants[1], 0.0) else 0.0006247/(0.8322166*exp(-0.33566*(states[0]+56.7062))+0.6274*exp(0.0823*(states[0]+65.0131)))+4.569e-5 + algebraic[18] = 1.0/(1.0+exp((states[0]+66.1)/6.4)) + algebraic[20] = algebraic[18] + algebraic[19] = 3.717e-6*exp(-0.2815*(states[0]+17.11))/(1.0+0.003732*exp(-0.3426*(states[0]+37.76)))+0.0005977 + algebraic[21] = 3.186e-8*exp(-0.6219*(states[0]+18.8))/(1.0+7.189e-5*exp(-0.6683*(states[0]+34.07)))+0.003556 + algebraic[13] = computed_constants[14]*(states[4]*states[5]+0.006/(1.0+exp(-(states[0]+14.1)/6.0)))*(states[0]-constants[66]) + algebraic[24] = -28.38*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) if eq_func(constants[1], 0.0) else -28.39*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) if eq_func(constants[1], 1.0) else -28.4*(states[0]+35.0)/(exp(-(states[0]+35.0)/2.5)-1.0)-84.9*states[0]/(exp(-0.208*states[0])-1.0) + algebraic[25] = 11.43*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0) if eq_func(constants[1], 1.0) else 11.42*(states[0]-5.0)/(exp(0.4*(states[0]-5.0))-1.0) + algebraic[23] = 2.0/(algebraic[24]+algebraic[25]) + algebraic[22] = 1.0/(1.0+exp(-(states[0]+23.1)/6.0)) if eq_func(constants[1], 0.0) else 1.0/(1.0+exp(-(states[0]+22.3+0.8*computed_constants[0])/6.0)) if eq_func(constants[1], 1.0) else 1.0/(1.0+exp(-(states[0]+22.2)/6.0)) + algebraic[28] = 3.75*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0) if eq_func(constants[1], 1.0) else 3.12*(states[0]+28.0)/(exp((states[0]+28.0)/4.0)-1.0) + algebraic[29] = 30.0/(1.0+exp(-(states[0]+28.0)/4.0)) if eq_func(constants[1], 1.0) else 25.0/(1.0+exp(-(states[0]+28.0)/4.0)) + algebraic[27] = (1.2-0.2*computed_constants[0])/(algebraic[28]+algebraic[29]) if eq_func(constants[1], 1.0) else 1.0/(algebraic[28]+algebraic[29]) + algebraic[26] = 1.0/(1.0+exp((states[0]+45.0)/5.0)) + algebraic[12] = computed_constants[15]*states[7]*states[6]*(states[0]-constants[73]) + algebraic[32] = 1068.0*exp((states[0]+26.3)/30.0) + algebraic[33] = 1068.0*exp(-(states[0]+26.3)/30.0) + algebraic[31] = 1.0/(algebraic[32]+algebraic[33]) + algebraic[30] = 1.0/(1.0+exp(-(states[0]+37.0)/6.8)) + algebraic[36] = 15.3*exp(-(states[0]+71.0+0.7*computed_constants[0])/83.3) if eq_func(constants[1], 1.0) else 15.3*exp(-(states[0]+71.7)/83.3) + algebraic[37] = 15.0*exp((states[0]+71.0)/15.38) if eq_func(constants[1], 1.0) else 15.0*exp((states[0]+71.7)/15.38) + algebraic[35] = 1.0/(algebraic[36]+algebraic[37]) + algebraic[34] = 1.0/(1.0+exp((states[0]+71.0)/9.0)) + algebraic[11] = computed_constants[16]*states[9]*states[8]*(states[0]-computed_constants[6]) + algebraic[10] = computed_constants[17]*states[8]*(states[0]-computed_constants[6]) + algebraic[38] = 1.0/(1.0+exp((states[0]+59.37)/13.1)) + algebraic[39] = 0.0101+0.06517/(0.57*exp(-0.08*(states[0]+49.0)))+2.4e-5*exp(0.1*(states[0]+50.93)) if eq_func(constants[1], 0.0) else 0.001/3.0*(30.31+195.5/(0.5686*exp(-0.08161*(states[0]+39.0+10.0*computed_constants[0]))+0.7174*exp((0.2719-0.1719*computed_constants[0])*1.0*(states[0]+40.93+10.0*computed_constants[0])))) if eq_func(constants[1], 1.0) else 0.0101+0.06517/(0.5686*exp(-0.08161*(states[0]+39.0))+0.7174*exp(0.2719*(states[0]+40.93))) + algebraic[40] = 1.0/(1.0+exp(-(states[0]-10.93)/19.7)) + algebraic[41] = 0.001*(2.98+15.59/(1.037*exp(0.09*(states[0]+30.61))+0.369*exp(-0.12*(states[0]+23.84)))) if eq_func(constants[1], 0.0) else 0.0025*(1.191+7.838/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))) if eq_func(constants[1], 1.0) else 0.001*(2.98+19.59/(1.037*exp(0.09012*(states[0]+30.61))+0.369*exp(-0.119*(states[0]+23.84)))) + algebraic[42] = 0.6*states[11]+0.4*states[12] + algebraic[9] = computed_constants[18]*algebraic[42]*states[10]*(states[0]-computed_constants[6]) + algebraic[43] = 1.0/(1.0+exp(-(states[0]+14.2)/10.6)) if neq_func(constants[1], 2.0) else 1.0/(1.0+exp(-(states[0]+13.2)/10.6)) + algebraic[44] = 1.0/(37.2*exp((states[0]-9.0)/15.9)+0.96*exp(-(states[0]-9.0)/22.5)) if neq_func(constants[1], 2.0) else 1.0/(37.2*exp((states[0]-10.0)/15.9)+0.96*exp(-(states[0]-10.0)/22.5)) + algebraic[45] = algebraic[43] + algebraic[46] = 1.0/(4.2*exp((states[0]-9.0)/17.0)+0.15*exp(-(states[0]-9.0)/21.6)) if neq_func(constants[1], 2.0) else 1.0/(4.2*exp((states[0]-10.0)/17.0)+0.15*exp(-(states[0]-10.0)/21.6)) + algebraic[47] = 1.0/(1.0+exp((states[0]+18.6)/10.1)) + algebraic[8] = computed_constants[20]*pow(states[13], 2.0)*(states[0]-computed_constants[12]) + algebraic[48] = 14.0/(1.0+exp(-(states[0]-40.0)/9.0)) + algebraic[49] = 1.0*exp(-states[0]/45.0) + algebraic[7] = computed_constants[21]*states[14]*(states[0]-computed_constants[4]) if neq_func(constants[1], 2.0) else computed_constants[21]*states[14]*(states[0]-77.6) + algebraic[6] = computed_constants[22]*states[14]*(states[0]-computed_constants[6]) if neq_func(constants[1], 2.0) else computed_constants[22]*states[14]*(states[0]+102.0) + algebraic[50] = 1.0*exp(-(states[0]+78.91)/26.62) if eq_func(constants[1], 0.0) else 1.0*exp(-(states[0]+78.91)/26.63) + algebraic[51] = 1.0*exp((states[0]+75.13)/21.25) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.c deleted file mode 100644 index df19755f3d..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.c +++ /dev/null @@ -1,122 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#include "model.algebraic.h" - -#include -#include - -const char VERSION[] = "0.5.0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t STATE_COUNT = 4; -const size_t VARIABLE_COUNT = 18; - -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; - -const VariableInfo STATE_INFO[] = { - {"V", "millivolt", "membrane", STATE}, - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"m", "dimensionless", "sodium_channel_m_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} -}; - -const VariableInfo VARIABLE_INFO[] = { - {"i_Stim", "microA_per_cm2", "membrane", EXTERNAL}, - {"i_L", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"i_Na", "microA_per_cm2", "sodium_channel", ALGEBRAIC}, - {"Cm", "microF_per_cm2", "membrane", CONSTANT}, - {"E_R", "millivolt", "membrane", CONSTANT}, - {"E_L", "millivolt", "leakage_current", COMPUTED_CONSTANT}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", COMPUTED_CONSTANT}, - {"g_Na", "milliS_per_cm2", "sodium_channel", CONSTANT}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"E_K", "millivolt", "potassium_channel", COMPUTED_CONSTANT}, - {"g_K", "milliS_per_cm2", "potassium_channel", CONSTANT}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC} -}; - -double * createStatesArray() -{ - double *res = (double *) malloc(STATE_COUNT*sizeof(double)); - - for (size_t i = 0; i < STATE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[4] = 1.0; - variables[5] = 0.0; - variables[7] = 0.3; - variables[9] = 120.0; - variables[15] = 36.0; - states[0] = 0.0; - states[1] = 0.6; - states[2] = 0.05; - states[3] = 0.325; - variables[0] = externalVariable(voi, states, rates, variables, 0); -} - -void computeComputedConstants(double *variables) -{ - variables[6] = variables[5]-10.613; - variables[8] = variables[5]-115.0; - variables[14] = variables[5]+12.0; -} - -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[0] = externalVariable(voi, states, rates, variables, 0); - variables[1] = variables[7]*(states[0]-variables[6]); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4]; - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2]; - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1]; - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3]; -} - -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[0] = externalVariable(voi, states, rates, variables, 0); - variables[1] = variables[7]*(states[0]-variables[6]); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); -} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.c new file mode 100644 index 0000000000..0ff0c4489f --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.c @@ -0,0 +1,166 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#include "model.algebraic.external.h" + +#include +#include + +const char VERSION[] = "0.6.0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t STATE_COUNT = 4; +const size_t CONSTANT_COUNT = 5; +const size_t COMPUTED_CONSTANT_COUNT = 3; +const size_t ALGEBRAIC_COUNT = 9; +const size_t EXTERNAL_COUNT = 1; + +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; + +const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"m", "dimensionless", "sodium_channel_m_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"E_R", "millivolt", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, + {"E_K", "millivolt", "potassium_channel"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; + constants[0] = 1.0; + constants[1] = 0.0; + constants[2] = 0.3; + constants[3] = 120.0; + constants[4] = 36.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ + computedConstants[0] = constants[1]-10.613; + computedConstants[1] = constants[1]-115.0; + computedConstants[2] = constants[1]+12.0; +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[0] = constants[2]*(states[0]-computedConstants[0]); + algebraic[1] = constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[2] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1]); + rates[0] = -(-externals[0]+algebraic[2]+algebraic[1]+algebraic[0])/constants[0]; + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[4] = 4.0*exp(states[0]/18.0); + rates[2] = algebraic[3]*(1.0-states[2])-algebraic[4]*states[2]; + algebraic[5] = 0.07*exp(states[0]/20.0); + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = algebraic[5]*(1.0-states[1])-algebraic[6]*states[1]; + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[8] = 0.125*exp(states[0]/80.0); + rates[3] = algebraic[7]*(1.0-states[3])-algebraic[8]*states[3]; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[0] = constants[2]*(states[0]-computedConstants[0]); + algebraic[2] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1]); + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[4] = 4.0*exp(states[0]/18.0); + algebraic[5] = 0.07*exp(states[0]/20.0); + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + algebraic[1] = constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[8] = 0.125*exp(states[0]/80.0); +} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.h new file mode 100644 index 0000000000..a4fb541db7 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.h @@ -0,0 +1,42 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; + +typedef struct { + char name[8]; + char units[16]; + char component[25]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + +void deleteArray(double *array); + +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.py new file mode 100644 index 0000000000..4c2775f460 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.py @@ -0,0 +1,133 @@ +# The content of this file was generated using the Python profile of libCellML 0.6.0. + +from enum import Enum +from math import * + + +__version__ = "0.5.0" +LIBCELLML_VERSION = "0.6.0" + +STATE_COUNT = 4 +CONSTANT_COUNT = 5 +COMPUTED_CONSTANT_COUNT = 3 +ALGEBRAIC_COUNT = 9 +EXTERNAL_COUNT = 1 + +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} + +STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] + +CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} +] + +ALGEBRAIC_INFO = [ + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} +] + +EXTERNAL_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"} +] + + +def leq_func(x, y): + return 1.0 if x <= y else 0.0 + + +def geq_func(x, y): + return 1.0 if x >= y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 + constants[0] = 1.0 + constants[1] = 0.0 + constants[2] = 0.3 + constants[3] = 120.0 + constants[4] = 36.0 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[1]-10.613 + computed_constants[1] = constants[1]-115.0 + computed_constants[2] = constants[1]+12.0 + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[0] = constants[2]*(states[0]-computed_constants[0]) + algebraic[1] = constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[2] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1]) + rates[0] = -(-externals[0]+algebraic[2]+algebraic[1]+algebraic[0])/constants[0] + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[4] = 4.0*exp(states[0]/18.0) + rates[2] = algebraic[3]*(1.0-states[2])-algebraic[4]*states[2] + algebraic[5] = 0.07*exp(states[0]/20.0) + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = algebraic[5]*(1.0-states[1])-algebraic[6]*states[1] + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[8] = 0.125*exp(states[0]/80.0) + rates[3] = algebraic[7]*(1.0-states[3])-algebraic[8]*states[3] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[0] = constants[2]*(states[0]-computed_constants[0]) + algebraic[2] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1]) + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[4] = 4.0*exp(states[0]/18.0) + algebraic[5] = 0.07*exp(states[0]/20.0) + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + algebraic[1] = constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[8] = 0.125*exp(states[0]/80.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.h deleted file mode 100644 index 525f2c3c3f..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.h +++ /dev/null @@ -1,42 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; - -typedef struct { - char name[8]; - char units[16]; - char component[25]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VOI_INFO; -extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; - -double * createStatesArray(); -double * createVariablesArray(); -void deleteArray(double *array); - -typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index); - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.py deleted file mode 100644 index fde8fbafd3..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.py +++ /dev/null @@ -1,120 +0,0 @@ -# The content of this file was generated using the Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0" -LIBCELLML_VERSION = "0.6.0" - -STATE_COUNT = 4 -VARIABLE_COUNT = 18 - - -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - EXTERNAL = 5 - - -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} - -STATE_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.STATE}, - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} -] - -VARIABLE_INFO = [ - {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane", "type": VariableType.EXTERNAL}, - {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_R", "units": "millivolt", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "potassium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC} -] - - -def leq_func(x, y): - return 1.0 if x <= y else 0.0 - - -def geq_func(x, y): - return 1.0 if x >= y else 0.0 - - -def and_func(x, y): - return 1.0 if bool(x) & bool(y) else 0.0 - - -def create_states_array(): - return [nan]*STATE_COUNT - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -def initialise_variables(voi, states, rates, variables, external_variable): - variables[4] = 1.0 - variables[5] = 0.0 - variables[7] = 0.3 - variables[9] = 120.0 - variables[15] = 36.0 - states[0] = 0.0 - states[1] = 0.6 - states[2] = 0.05 - states[3] = 0.325 - variables[0] = external_variable(voi, states, rates, variables, 0) - - -def compute_computed_constants(variables): - variables[6] = variables[5]-10.613 - variables[8] = variables[5]-115.0 - variables[14] = variables[5]+12.0 - - -def compute_rates(voi, states, rates, variables, external_variable): - variables[0] = external_variable(voi, states, rates, variables, 0) - variables[1] = variables[7]*(states[0]-variables[6]) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4] - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2] - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1] - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3] - - -def compute_variables(voi, states, rates, variables, external_variable): - variables[0] = external_variable(voi, states, rates, variables, 0) - variables[1] = variables[7]*(states[0]-variables[6]) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.c index 240fb2a4d0..7299cfac6f 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.c @@ -5,40 +5,48 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 4; -const size_t VARIABLE_COUNT = 18; +const size_t CONSTANT_COUNT = 5; +const size_t COMPUTED_CONSTANT_COUNT = 3; +const size_t ALGEBRAIC_COUNT = 10; -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { - {"V", "millivolt", "membrane", STATE}, - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"m", "dimensionless", "sodium_channel_m_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} + {"V", "millivolt", "membrane"}, + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"m", "dimensionless", "sodium_channel_m_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} }; -const VariableInfo VARIABLE_INFO[] = { - {"i_Stim", "microA_per_cm2", "membrane", ALGEBRAIC}, - {"i_L", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"i_Na", "microA_per_cm2", "sodium_channel", ALGEBRAIC}, - {"Cm", "microF_per_cm2", "membrane", CONSTANT}, - {"E_R", "millivolt", "membrane", CONSTANT}, - {"E_L", "millivolt", "leakage_current", COMPUTED_CONSTANT}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", COMPUTED_CONSTANT}, - {"g_Na", "milliS_per_cm2", "sodium_channel", CONSTANT}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"E_K", "millivolt", "potassium_channel", COMPUTED_CONSTANT}, - {"g_K", "milliS_per_cm2", "potassium_channel", CONSTANT}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"E_R", "millivolt", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, + {"E_K", "millivolt", "potassium_channel"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"}, + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} }; double * createStatesArray() @@ -52,11 +60,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -68,53 +98,53 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[4] = 1.0; - variables[5] = 0.0; - variables[7] = 0.3; - variables[9] = 120.0; - variables[15] = 36.0; states[0] = 0.0; states[1] = 0.6; states[2] = 0.05; states[3] = 0.325; + constants[0] = 1.0; + constants[1] = 0.0; + constants[2] = 0.3; + constants[3] = 120.0; + constants[4] = 36.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[6] = variables[5]-10.613; - variables[8] = variables[5]-115.0; - variables[14] = variables[5]+12.0; + computedConstants[0] = constants[1]-10.613; + computedConstants[1] = constants[1]-115.0; + computedConstants[2] = constants[1]+12.0; } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; - variables[1] = variables[7]*(states[0]-variables[6]); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4]; - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2]; - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1]; - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3]; + algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + algebraic[1] = constants[2]*(states[0]-computedConstants[0]); + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[3] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1]); + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/constants[0]; + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[5] = 4.0*exp(states[0]/18.0); + rates[2] = algebraic[4]*(1.0-states[2])-algebraic[5]*states[2]; + algebraic[6] = 0.07*exp(states[0]/20.0); + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = algebraic[6]*(1.0-states[1])-algebraic[7]*states[1]; + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[9] = 0.125*exp(states[0]/80.0); + rates[3] = algebraic[8]*(1.0-states[3])-algebraic[9]*states[3]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[1] = variables[7]*(states[0]-variables[6]); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); + algebraic[1] = constants[2]*(states[0]-computedConstants[0]); + algebraic[3] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1]); + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[5] = 4.0*exp(states[0]/18.0); + algebraic[6] = 0.07*exp(states[0]/20.0); + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[9] = 0.125*exp(states[0]/80.0); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.c deleted file mode 100644 index 7536350ce3..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.c +++ /dev/null @@ -1,122 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#include "model.computed.constant.h" - -#include -#include - -const char VERSION[] = "0.5.0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t STATE_COUNT = 4; -const size_t VARIABLE_COUNT = 18; - -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; - -const VariableInfo STATE_INFO[] = { - {"V", "millivolt", "membrane", STATE}, - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"m", "dimensionless", "sodium_channel_m_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} -}; - -const VariableInfo VARIABLE_INFO[] = { - {"i_Stim", "microA_per_cm2", "membrane", ALGEBRAIC}, - {"i_L", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"i_Na", "microA_per_cm2", "sodium_channel", ALGEBRAIC}, - {"Cm", "microF_per_cm2", "membrane", CONSTANT}, - {"E_R", "millivolt", "membrane", CONSTANT}, - {"E_L", "millivolt", "leakage_current", EXTERNAL}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", COMPUTED_CONSTANT}, - {"g_Na", "milliS_per_cm2", "sodium_channel", CONSTANT}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"E_K", "millivolt", "potassium_channel", COMPUTED_CONSTANT}, - {"g_K", "milliS_per_cm2", "potassium_channel", CONSTANT}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC} -}; - -double * createStatesArray() -{ - double *res = (double *) malloc(STATE_COUNT*sizeof(double)); - - for (size_t i = 0; i < STATE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[4] = 1.0; - variables[5] = 0.0; - variables[7] = 0.3; - variables[9] = 120.0; - variables[15] = 36.0; - states[0] = 0.0; - states[1] = 0.6; - states[2] = 0.05; - states[3] = 0.325; - variables[6] = externalVariable(voi, states, rates, variables, 6); -} - -void computeComputedConstants(double *variables) -{ - variables[8] = variables[5]-115.0; - variables[14] = variables[5]+12.0; -} - -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; - variables[6] = externalVariable(voi, states, rates, variables, 6); - variables[1] = variables[7]*(states[0]-variables[6]); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4]; - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2]; - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1]; - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3]; -} - -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[6] = externalVariable(voi, states, rates, variables, 6); - variables[1] = variables[7]*(states[0]-variables[6]); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); -} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.c new file mode 100644 index 0000000000..5862270578 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.c @@ -0,0 +1,166 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#include "model.computed.constant.external.h" + +#include +#include + +const char VERSION[] = "0.6.0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t STATE_COUNT = 4; +const size_t CONSTANT_COUNT = 5; +const size_t COMPUTED_CONSTANT_COUNT = 2; +const size_t ALGEBRAIC_COUNT = 10; +const size_t EXTERNAL_COUNT = 1; + +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; + +const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"m", "dimensionless", "sodium_channel_m_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"E_R", "millivolt", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_Na", "millivolt", "sodium_channel"}, + {"E_K", "millivolt", "potassium_channel"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"}, + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"E_L", "millivolt", "leakage_current"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; + constants[0] = 1.0; + constants[1] = 0.0; + constants[2] = 0.3; + constants[3] = 120.0; + constants[4] = 36.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ + computedConstants[0] = constants[1]-115.0; + computedConstants[1] = constants[1]+12.0; +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[1] = constants[2]*(states[0]-externals[0]); + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[1]); + algebraic[3] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[0]); + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/constants[0]; + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[5] = 4.0*exp(states[0]/18.0); + rates[2] = algebraic[4]*(1.0-states[2])-algebraic[5]*states[2]; + algebraic[6] = 0.07*exp(states[0]/20.0); + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = algebraic[6]*(1.0-states[1])-algebraic[7]*states[1]; + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[9] = 0.125*exp(states[0]/80.0); + rates[3] = algebraic[8]*(1.0-states[3])-algebraic[9]*states[3]; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[1] = constants[2]*(states[0]-externals[0]); + algebraic[3] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[0]); + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[5] = 4.0*exp(states[0]/18.0); + algebraic[6] = 0.07*exp(states[0]/20.0); + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[1]); + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[9] = 0.125*exp(states[0]/80.0); +} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.h new file mode 100644 index 0000000000..a4fb541db7 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.h @@ -0,0 +1,42 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; + +typedef struct { + char name[8]; + char units[16]; + char component[25]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + +void deleteArray(double *array); + +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.py new file mode 100644 index 0000000000..014274da7b --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.py @@ -0,0 +1,133 @@ +# The content of this file was generated using the Python profile of libCellML 0.6.0. + +from enum import Enum +from math import * + + +__version__ = "0.5.0" +LIBCELLML_VERSION = "0.6.0" + +STATE_COUNT = 4 +CONSTANT_COUNT = 5 +COMPUTED_CONSTANT_COUNT = 2 +ALGEBRAIC_COUNT = 10 +EXTERNAL_COUNT = 1 + +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} + +STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] + +CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} +] + +ALGEBRAIC_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} +] + +EXTERNAL_INFO = [ + {"name": "E_L", "units": "millivolt", "component": "leakage_current"} +] + + +def leq_func(x, y): + return 1.0 if x <= y else 0.0 + + +def geq_func(x, y): + return 1.0 if x >= y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 + constants[0] = 1.0 + constants[1] = 0.0 + constants[2] = 0.3 + constants[3] = 120.0 + constants[4] = 36.0 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[1]-115.0 + computed_constants[1] = constants[1]+12.0 + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[1] = constants[2]*(states[0]-externals[0]) + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[1]) + algebraic[3] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[0]) + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/constants[0] + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[5] = 4.0*exp(states[0]/18.0) + rates[2] = algebraic[4]*(1.0-states[2])-algebraic[5]*states[2] + algebraic[6] = 0.07*exp(states[0]/20.0) + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = algebraic[6]*(1.0-states[1])-algebraic[7]*states[1] + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[9] = 0.125*exp(states[0]/80.0) + rates[3] = algebraic[8]*(1.0-states[3])-algebraic[9]*states[3] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[1] = constants[2]*(states[0]-externals[0]) + algebraic[3] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[0]) + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[5] = 4.0*exp(states[0]/18.0) + algebraic[6] = 0.07*exp(states[0]/20.0) + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[1]) + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[9] = 0.125*exp(states[0]/80.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.h deleted file mode 100644 index 525f2c3c3f..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.h +++ /dev/null @@ -1,42 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; - -typedef struct { - char name[8]; - char units[16]; - char component[25]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VOI_INFO; -extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; - -double * createStatesArray(); -double * createVariablesArray(); -void deleteArray(double *array); - -typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index); - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.py deleted file mode 100644 index df279af939..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.py +++ /dev/null @@ -1,120 +0,0 @@ -# The content of this file was generated using the Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0" -LIBCELLML_VERSION = "0.6.0" - -STATE_COUNT = 4 -VARIABLE_COUNT = 18 - - -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - EXTERNAL = 5 - - -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} - -STATE_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.STATE}, - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} -] - -VARIABLE_INFO = [ - {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane", "type": VariableType.ALGEBRAIC}, - {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_R", "units": "millivolt", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.EXTERNAL}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "potassium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC} -] - - -def leq_func(x, y): - return 1.0 if x <= y else 0.0 - - -def geq_func(x, y): - return 1.0 if x >= y else 0.0 - - -def and_func(x, y): - return 1.0 if bool(x) & bool(y) else 0.0 - - -def create_states_array(): - return [nan]*STATE_COUNT - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -def initialise_variables(voi, states, rates, variables, external_variable): - variables[4] = 1.0 - variables[5] = 0.0 - variables[7] = 0.3 - variables[9] = 120.0 - variables[15] = 36.0 - states[0] = 0.0 - states[1] = 0.6 - states[2] = 0.05 - states[3] = 0.325 - variables[6] = external_variable(voi, states, rates, variables, 6) - - -def compute_computed_constants(variables): - variables[8] = variables[5]-115.0 - variables[14] = variables[5]+12.0 - - -def compute_rates(voi, states, rates, variables, external_variable): - variables[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 - variables[6] = external_variable(voi, states, rates, variables, 6) - variables[1] = variables[7]*(states[0]-variables[6]) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4] - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2] - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1] - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3] - - -def compute_variables(voi, states, rates, variables, external_variable): - variables[6] = external_variable(voi, states, rates, variables, 6) - variables[1] = variables[7]*(states[0]-variables[6]) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.c deleted file mode 100644 index 5240505e05..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.c +++ /dev/null @@ -1,122 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#include "model.constant.h" - -#include -#include - -const char VERSION[] = "0.5.0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t STATE_COUNT = 4; -const size_t VARIABLE_COUNT = 18; - -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; - -const VariableInfo STATE_INFO[] = { - {"V", "millivolt", "membrane", STATE}, - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"m", "dimensionless", "sodium_channel_m_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} -}; - -const VariableInfo VARIABLE_INFO[] = { - {"i_Stim", "microA_per_cm2", "membrane", ALGEBRAIC}, - {"i_L", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"i_Na", "microA_per_cm2", "sodium_channel", ALGEBRAIC}, - {"Cm", "microF_per_cm2", "membrane", EXTERNAL}, - {"E_R", "millivolt", "membrane", CONSTANT}, - {"E_L", "millivolt", "leakage_current", COMPUTED_CONSTANT}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", COMPUTED_CONSTANT}, - {"g_Na", "milliS_per_cm2", "sodium_channel", CONSTANT}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"E_K", "millivolt", "potassium_channel", COMPUTED_CONSTANT}, - {"g_K", "milliS_per_cm2", "potassium_channel", CONSTANT}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC} -}; - -double * createStatesArray() -{ - double *res = (double *) malloc(STATE_COUNT*sizeof(double)); - - for (size_t i = 0; i < STATE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[5] = 0.0; - variables[7] = 0.3; - variables[9] = 120.0; - variables[15] = 36.0; - states[0] = 0.0; - states[1] = 0.6; - states[2] = 0.05; - states[3] = 0.325; - variables[4] = externalVariable(voi, states, rates, variables, 4); -} - -void computeComputedConstants(double *variables) -{ - variables[6] = variables[5]-10.613; - variables[8] = variables[5]-115.0; - variables[14] = variables[5]+12.0; -} - -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; - variables[4] = externalVariable(voi, states, rates, variables, 4); - variables[1] = variables[7]*(states[0]-variables[6]); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4]; - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2]; - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1]; - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3]; -} - -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[1] = variables[7]*(states[0]-variables[6]); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); - variables[4] = externalVariable(voi, states, rates, variables, 4); -} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.c new file mode 100644 index 0000000000..62631ccd62 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.c @@ -0,0 +1,166 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#include "model.constant.external.h" + +#include +#include + +const char VERSION[] = "0.6.0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t STATE_COUNT = 4; +const size_t CONSTANT_COUNT = 4; +const size_t COMPUTED_CONSTANT_COUNT = 3; +const size_t ALGEBRAIC_COUNT = 10; +const size_t EXTERNAL_COUNT = 1; + +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; + +const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"m", "dimensionless", "sodium_channel_m_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"E_R", "millivolt", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, + {"E_K", "millivolt", "potassium_channel"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"}, + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; + constants[0] = 0.0; + constants[1] = 0.3; + constants[2] = 120.0; + constants[3] = 36.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ + computedConstants[0] = constants[0]-10.613; + computedConstants[1] = constants[0]-115.0; + computedConstants[2] = constants[0]+12.0; +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[1] = constants[1]*(states[0]-computedConstants[0]); + algebraic[2] = constants[3]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[3] = constants[2]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1]); + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/externals[0]; + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[5] = 4.0*exp(states[0]/18.0); + rates[2] = algebraic[4]*(1.0-states[2])-algebraic[5]*states[2]; + algebraic[6] = 0.07*exp(states[0]/20.0); + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = algebraic[6]*(1.0-states[1])-algebraic[7]*states[1]; + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[9] = 0.125*exp(states[0]/80.0); + rates[3] = algebraic[8]*(1.0-states[3])-algebraic[9]*states[3]; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + algebraic[1] = constants[1]*(states[0]-computedConstants[0]); + algebraic[3] = constants[2]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1]); + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[5] = 4.0*exp(states[0]/18.0); + algebraic[6] = 0.07*exp(states[0]/20.0); + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + algebraic[2] = constants[3]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[9] = 0.125*exp(states[0]/80.0); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); +} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.h new file mode 100644 index 0000000000..a4fb541db7 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.h @@ -0,0 +1,42 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; + +typedef struct { + char name[8]; + char units[16]; + char component[25]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + +void deleteArray(double *array); + +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.py new file mode 100644 index 0000000000..04c0982b77 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.py @@ -0,0 +1,133 @@ +# The content of this file was generated using the Python profile of libCellML 0.6.0. + +from enum import Enum +from math import * + + +__version__ = "0.5.0" +LIBCELLML_VERSION = "0.6.0" + +STATE_COUNT = 4 +CONSTANT_COUNT = 4 +COMPUTED_CONSTANT_COUNT = 3 +ALGEBRAIC_COUNT = 10 +EXTERNAL_COUNT = 1 + +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} + +STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] + +CONSTANT_INFO = [ + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} +] + +ALGEBRAIC_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} +] + +EXTERNAL_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"} +] + + +def leq_func(x, y): + return 1.0 if x <= y else 0.0 + + +def geq_func(x, y): + return 1.0 if x >= y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 + constants[0] = 0.0 + constants[1] = 0.3 + constants[2] = 120.0 + constants[3] = 36.0 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[0]-10.613 + computed_constants[1] = constants[0]-115.0 + computed_constants[2] = constants[0]+12.0 + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[1] = constants[1]*(states[0]-computed_constants[0]) + algebraic[2] = constants[3]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[3] = constants[2]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1]) + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/externals[0] + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[5] = 4.0*exp(states[0]/18.0) + rates[2] = algebraic[4]*(1.0-states[2])-algebraic[5]*states[2] + algebraic[6] = 0.07*exp(states[0]/20.0) + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = algebraic[6]*(1.0-states[1])-algebraic[7]*states[1] + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[9] = 0.125*exp(states[0]/80.0) + rates[3] = algebraic[8]*(1.0-states[3])-algebraic[9]*states[3] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[1] = constants[1]*(states[0]-computed_constants[0]) + algebraic[3] = constants[2]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1]) + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[5] = 4.0*exp(states[0]/18.0) + algebraic[6] = 0.07*exp(states[0]/20.0) + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + algebraic[2] = constants[3]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[9] = 0.125*exp(states[0]/80.0) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.h deleted file mode 100644 index 525f2c3c3f..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.h +++ /dev/null @@ -1,42 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; - -typedef struct { - char name[8]; - char units[16]; - char component[25]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VOI_INFO; -extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; - -double * createStatesArray(); -double * createVariablesArray(); -void deleteArray(double *array); - -typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index); - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.py deleted file mode 100644 index cf9b0c99fe..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.constant.py +++ /dev/null @@ -1,120 +0,0 @@ -# The content of this file was generated using the Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0" -LIBCELLML_VERSION = "0.6.0" - -STATE_COUNT = 4 -VARIABLE_COUNT = 18 - - -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - EXTERNAL = 5 - - -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} - -STATE_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.STATE}, - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} -] - -VARIABLE_INFO = [ - {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane", "type": VariableType.ALGEBRAIC}, - {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.EXTERNAL}, - {"name": "E_R", "units": "millivolt", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "potassium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC} -] - - -def leq_func(x, y): - return 1.0 if x <= y else 0.0 - - -def geq_func(x, y): - return 1.0 if x >= y else 0.0 - - -def and_func(x, y): - return 1.0 if bool(x) & bool(y) else 0.0 - - -def create_states_array(): - return [nan]*STATE_COUNT - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -def initialise_variables(voi, states, rates, variables, external_variable): - variables[5] = 0.0 - variables[7] = 0.3 - variables[9] = 120.0 - variables[15] = 36.0 - states[0] = 0.0 - states[1] = 0.6 - states[2] = 0.05 - states[3] = 0.325 - variables[4] = external_variable(voi, states, rates, variables, 4) - - -def compute_computed_constants(variables): - variables[6] = variables[5]-10.613 - variables[8] = variables[5]-115.0 - variables[14] = variables[5]+12.0 - - -def compute_rates(voi, states, rates, variables, external_variable): - variables[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 - variables[4] = external_variable(voi, states, rates, variables, 4) - variables[1] = variables[7]*(states[0]-variables[6]) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4] - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2] - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1] - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3] - - -def compute_variables(voi, states, rates, variables, external_variable): - variables[1] = variables[7]*(states[0]-variables[6]) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) - variables[4] = external_variable(voi, states, rates, variables, 4) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.c index 94b0fde0e2..f2b6906537 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.c @@ -5,40 +5,48 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 4; -const size_t VARIABLE_COUNT = 18; +const size_t CONSTANT_COUNT = 5; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 13; -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { - {"V", "millivolt", "membrane", STATE}, - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"m", "dimensionless", "sodium_channel_m_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} + {"V", "millivolt", "membrane"}, + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"m", "dimensionless", "sodium_channel_m_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} }; -const VariableInfo VARIABLE_INFO[] = { - {"i_Stim", "microA_per_cm2", "membrane", ALGEBRAIC}, - {"i_L", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"i_Na", "microA_per_cm2", "sodium_channel", ALGEBRAIC}, - {"Cm", "microF_per_cm2", "membrane", CONSTANT}, - {"E_R", "millivolt", "membrane", CONSTANT}, - {"E_L", "millivolt", "leakage_current", COMPUTED_CONSTANT}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", COMPUTED_CONSTANT}, - {"g_Na", "milliS_per_cm2", "sodium_channel", CONSTANT}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"E_K", "millivolt", "potassium_channel", COMPUTED_CONSTANT}, - {"g_K", "milliS_per_cm2", "potassium_channel", CONSTANT}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"E_R", "millivolt", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"}, + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"E_K", "millivolt", "potassium_channel"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} }; double * createStatesArray() @@ -52,11 +60,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -72,7 +102,9 @@ typedef struct { double voi; double *states; double *rates; - double *variables; + double *constants; + double *computedConstants; + double *algebraic; } RootFindingInfo; extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), @@ -83,23 +115,25 @@ void objectiveFunction0(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[0] = u[0]; + algebraic[0] = u[0]; - f[0] = variables[0]-(((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0)-0.0; + f[0] = algebraic[0]-(((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0)-0.0; } -void findRoot0(double voi, double *states, double *rates, double *variables) +void findRoot0(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[0]; + u[0] = algebraic[0]; nlaSolve(objectiveFunction0, u, 1, &rfi); - variables[0] = u[0]; + algebraic[0] = u[0]; } void objectiveFunction1(double *u, double *f, void *data) @@ -107,16 +141,18 @@ void objectiveFunction1(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; rates[0] = u[0]; - f[0] = rates[0]-(-(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4])-0.0; + f[0] = rates[0]-(-(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/constants[0])-0.0; } -void findRoot1(double voi, double *states, double *rates, double *variables) +void findRoot1(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; u[0] = rates[0]; @@ -131,23 +167,25 @@ void objectiveFunction2(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[6] = u[0]; + algebraic[4] = u[0]; - f[0] = variables[6]-(variables[5]-10.613)-0.0; + f[0] = algebraic[4]-(constants[1]-10.613)-0.0; } -void findRoot2(double voi, double *states, double *rates, double *variables) +void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[6]; + u[0] = algebraic[4]; nlaSolve(objectiveFunction2, u, 1, &rfi); - variables[6] = u[0]; + algebraic[4] = u[0]; } void objectiveFunction3(double *u, double *f, void *data) @@ -155,23 +193,25 @@ void objectiveFunction3(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[1] = u[0]; + algebraic[1] = u[0]; - f[0] = variables[1]-variables[7]*(states[0]-variables[6])-0.0; + f[0] = algebraic[1]-constants[2]*(states[0]-algebraic[4])-0.0; } -void findRoot3(double voi, double *states, double *rates, double *variables) +void findRoot3(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[1]; + u[0] = algebraic[1]; nlaSolve(objectiveFunction3, u, 1, &rfi); - variables[1] = u[0]; + algebraic[1] = u[0]; } void objectiveFunction4(double *u, double *f, void *data) @@ -179,23 +219,25 @@ void objectiveFunction4(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[8] = u[0]; + algebraic[5] = u[0]; - f[0] = variables[8]-(variables[5]-115.0)-0.0; + f[0] = algebraic[5]-(constants[1]-115.0)-0.0; } -void findRoot4(double voi, double *states, double *rates, double *variables) +void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[8]; + u[0] = algebraic[5]; nlaSolve(objectiveFunction4, u, 1, &rfi); - variables[8] = u[0]; + algebraic[5] = u[0]; } void objectiveFunction5(double *u, double *f, void *data) @@ -203,23 +245,25 @@ void objectiveFunction5(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[3] = u[0]; + algebraic[3] = u[0]; - f[0] = variables[3]-variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8])-0.0; + f[0] = algebraic[3]-constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5])-0.0; } -void findRoot5(double voi, double *states, double *rates, double *variables) +void findRoot5(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[3]; + u[0] = algebraic[3]; nlaSolve(objectiveFunction5, u, 1, &rfi); - variables[3] = u[0]; + algebraic[3] = u[0]; } void objectiveFunction6(double *u, double *f, void *data) @@ -227,23 +271,25 @@ void objectiveFunction6(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[10] = u[0]; + algebraic[6] = u[0]; - f[0] = variables[10]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0; + f[0] = algebraic[6]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0; } -void findRoot6(double voi, double *states, double *rates, double *variables) +void findRoot6(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[10]; + u[0] = algebraic[6]; nlaSolve(objectiveFunction6, u, 1, &rfi); - variables[10] = u[0]; + algebraic[6] = u[0]; } void objectiveFunction7(double *u, double *f, void *data) @@ -251,23 +297,25 @@ void objectiveFunction7(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[11] = u[0]; + algebraic[7] = u[0]; - f[0] = variables[11]-4.0*exp(states[0]/18.0)-0.0; + f[0] = algebraic[7]-4.0*exp(states[0]/18.0)-0.0; } -void findRoot7(double voi, double *states, double *rates, double *variables) +void findRoot7(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[11]; + u[0] = algebraic[7]; nlaSolve(objectiveFunction7, u, 1, &rfi); - variables[11] = u[0]; + algebraic[7] = u[0]; } void objectiveFunction8(double *u, double *f, void *data) @@ -275,16 +323,18 @@ void objectiveFunction8(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; rates[2] = u[0]; - f[0] = rates[2]-(variables[10]*(1.0-states[2])-variables[11]*states[2])-0.0; + f[0] = rates[2]-(algebraic[6]*(1.0-states[2])-algebraic[7]*states[2])-0.0; } -void findRoot8(double voi, double *states, double *rates, double *variables) +void findRoot8(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; u[0] = rates[2]; @@ -299,23 +349,25 @@ void objectiveFunction9(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[12] = u[0]; + algebraic[8] = u[0]; - f[0] = variables[12]-0.07*exp(states[0]/20.0)-0.0; + f[0] = algebraic[8]-0.07*exp(states[0]/20.0)-0.0; } -void findRoot9(double voi, double *states, double *rates, double *variables) +void findRoot9(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[12]; + u[0] = algebraic[8]; nlaSolve(objectiveFunction9, u, 1, &rfi); - variables[12] = u[0]; + algebraic[8] = u[0]; } void objectiveFunction10(double *u, double *f, void *data) @@ -323,23 +375,25 @@ void objectiveFunction10(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[13] = u[0]; + algebraic[9] = u[0]; - f[0] = variables[13]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; + f[0] = algebraic[9]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; } -void findRoot10(double voi, double *states, double *rates, double *variables) +void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[13]; + u[0] = algebraic[9]; nlaSolve(objectiveFunction10, u, 1, &rfi); - variables[13] = u[0]; + algebraic[9] = u[0]; } void objectiveFunction11(double *u, double *f, void *data) @@ -347,16 +401,18 @@ void objectiveFunction11(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; rates[1] = u[0]; - f[0] = rates[1]-(variables[12]*(1.0-states[1])-variables[13]*states[1])-0.0; + f[0] = rates[1]-(algebraic[8]*(1.0-states[1])-algebraic[9]*states[1])-0.0; } -void findRoot11(double voi, double *states, double *rates, double *variables) +void findRoot11(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; u[0] = rates[1]; @@ -371,23 +427,25 @@ void objectiveFunction12(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[14] = u[0]; + algebraic[10] = u[0]; - f[0] = variables[14]-(variables[5]+12.0)-0.0; + f[0] = algebraic[10]-(constants[1]+12.0)-0.0; } -void findRoot12(double voi, double *states, double *rates, double *variables) +void findRoot12(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[14]; + u[0] = algebraic[10]; nlaSolve(objectiveFunction12, u, 1, &rfi); - variables[14] = u[0]; + algebraic[10] = u[0]; } void objectiveFunction13(double *u, double *f, void *data) @@ -395,23 +453,25 @@ void objectiveFunction13(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[2] = u[0]; + algebraic[2] = u[0]; - f[0] = variables[2]-variables[15]*pow(states[3], 4.0)*(states[0]-variables[14])-0.0; + f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-algebraic[10])-0.0; } -void findRoot13(double voi, double *states, double *rates, double *variables) +void findRoot13(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[2]; + u[0] = algebraic[2]; nlaSolve(objectiveFunction13, u, 1, &rfi); - variables[2] = u[0]; + algebraic[2] = u[0]; } void objectiveFunction14(double *u, double *f, void *data) @@ -419,23 +479,25 @@ void objectiveFunction14(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[16] = u[0]; + algebraic[11] = u[0]; - f[0] = variables[16]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; + f[0] = algebraic[11]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; } -void findRoot14(double voi, double *states, double *rates, double *variables) +void findRoot14(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[16]; + u[0] = algebraic[11]; nlaSolve(objectiveFunction14, u, 1, &rfi); - variables[16] = u[0]; + algebraic[11] = u[0]; } void objectiveFunction15(double *u, double *f, void *data) @@ -443,23 +505,25 @@ void objectiveFunction15(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[17] = u[0]; + algebraic[12] = u[0]; - f[0] = variables[17]-0.125*exp(states[0]/80.0)-0.0; + f[0] = algebraic[12]-0.125*exp(states[0]/80.0)-0.0; } -void findRoot15(double voi, double *states, double *rates, double *variables) +void findRoot15(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[17]; + u[0] = algebraic[12]; nlaSolve(objectiveFunction15, u, 1, &rfi); - variables[17] = u[0]; + algebraic[12] = u[0]; } void objectiveFunction16(double *u, double *f, void *data) @@ -467,16 +531,18 @@ void objectiveFunction16(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; rates[3] = u[0]; - f[0] = rates[3]-(variables[16]*(1.0-states[3])-variables[17]*states[3])-0.0; + f[0] = rates[3]-(algebraic[11]*(1.0-states[3])-algebraic[12]*states[3])-0.0; } -void findRoot16(double voi, double *states, double *rates, double *variables) +void findRoot16(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; u[0] = rates[3]; @@ -486,26 +552,8 @@ void findRoot16(double voi, double *states, double *rates, double *variables) rates[3] = u[0]; } -void initialiseVariables(double *states, double *rates, double *variables) -{ - variables[0] = 0.0; - variables[1] = 0.0; - variables[2] = 0.0; - variables[3] = 0.0; - variables[4] = 1.0; - variables[5] = 0.0; - variables[6] = 0.0; - variables[7] = 0.3; - variables[8] = 0.0; - variables[9] = 120.0; - variables[10] = 0.0; - variables[11] = 0.0; - variables[12] = 0.0; - variables[13] = 0.0; - variables[14] = 0.0; - variables[15] = 36.0; - variables[16] = 0.0; - variables[17] = 0.0; +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ states[0] = 0.0; states[1] = 0.6; states[2] = 0.05; @@ -514,50 +562,68 @@ void initialiseVariables(double *states, double *rates, double *variables) rates[1] = 0.0; rates[2] = 0.0; rates[3] = 0.0; -} - -void computeComputedConstants(double *variables) -{ -} - -void computeRates(double voi, double *states, double *rates, double *variables) -{ - findRoot0(voi, states, rates, variables); - findRoot2(voi, states, rates, variables); - findRoot3(voi, states, rates, variables); - findRoot14(voi, states, rates, variables); - findRoot15(voi, states, rates, variables); - findRoot16(voi, states, rates, variables); - findRoot12(voi, states, rates, variables); - findRoot13(voi, states, rates, variables); - findRoot9(voi, states, rates, variables); - findRoot10(voi, states, rates, variables); - findRoot11(voi, states, rates, variables); - findRoot6(voi, states, rates, variables); - findRoot7(voi, states, rates, variables); - findRoot8(voi, states, rates, variables); - findRoot4(voi, states, rates, variables); - findRoot5(voi, states, rates, variables); - findRoot1(voi, states, rates, variables); -} - -void computeVariables(double voi, double *states, double *rates, double *variables) -{ - findRoot0(voi, states, rates, variables); - findRoot2(voi, states, rates, variables); - findRoot3(voi, states, rates, variables); - findRoot14(voi, states, rates, variables); - findRoot15(voi, states, rates, variables); - findRoot16(voi, states, rates, variables); - findRoot12(voi, states, rates, variables); - findRoot13(voi, states, rates, variables); - findRoot9(voi, states, rates, variables); - findRoot10(voi, states, rates, variables); - findRoot11(voi, states, rates, variables); - findRoot6(voi, states, rates, variables); - findRoot7(voi, states, rates, variables); - findRoot8(voi, states, rates, variables); - findRoot4(voi, states, rates, variables); - findRoot5(voi, states, rates, variables); - findRoot1(voi, states, rates, variables); + constants[0] = 1.0; + constants[1] = 0.0; + constants[2] = 0.3; + constants[3] = 120.0; + constants[4] = 36.0; + algebraic[0] = 0.0; + algebraic[1] = 0.0; + algebraic[2] = 0.0; + algebraic[3] = 0.0; + algebraic[4] = 0.0; + algebraic[5] = 0.0; + algebraic[6] = 0.0; + algebraic[7] = 0.0; + algebraic[8] = 0.0; + algebraic[9] = 0.0; + algebraic[10] = 0.0; + algebraic[11] = 0.0; + algebraic[12] = 0.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + findRoot0(voi, states, rates, constants, computedConstants, algebraic); + findRoot2(voi, states, rates, constants, computedConstants, algebraic); + findRoot3(voi, states, rates, constants, computedConstants, algebraic); + findRoot14(voi, states, rates, constants, computedConstants, algebraic); + findRoot15(voi, states, rates, constants, computedConstants, algebraic); + findRoot16(voi, states, rates, constants, computedConstants, algebraic); + findRoot12(voi, states, rates, constants, computedConstants, algebraic); + findRoot13(voi, states, rates, constants, computedConstants, algebraic); + findRoot9(voi, states, rates, constants, computedConstants, algebraic); + findRoot10(voi, states, rates, constants, computedConstants, algebraic); + findRoot11(voi, states, rates, constants, computedConstants, algebraic); + findRoot6(voi, states, rates, constants, computedConstants, algebraic); + findRoot7(voi, states, rates, constants, computedConstants, algebraic); + findRoot8(voi, states, rates, constants, computedConstants, algebraic); + findRoot4(voi, states, rates, constants, computedConstants, algebraic); + findRoot5(voi, states, rates, constants, computedConstants, algebraic); + findRoot1(voi, states, rates, constants, computedConstants, algebraic); +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + findRoot0(voi, states, rates, constants, computedConstants, algebraic); + findRoot2(voi, states, rates, constants, computedConstants, algebraic); + findRoot3(voi, states, rates, constants, computedConstants, algebraic); + findRoot14(voi, states, rates, constants, computedConstants, algebraic); + findRoot15(voi, states, rates, constants, computedConstants, algebraic); + findRoot16(voi, states, rates, constants, computedConstants, algebraic); + findRoot12(voi, states, rates, constants, computedConstants, algebraic); + findRoot13(voi, states, rates, constants, computedConstants, algebraic); + findRoot9(voi, states, rates, constants, computedConstants, algebraic); + findRoot10(voi, states, rates, constants, computedConstants, algebraic); + findRoot11(voi, states, rates, constants, computedConstants, algebraic); + findRoot6(voi, states, rates, constants, computedConstants, algebraic); + findRoot7(voi, states, rates, constants, computedConstants, algebraic); + findRoot8(voi, states, rates, constants, computedConstants, algebraic); + findRoot4(voi, states, rates, constants, computedConstants, algebraic); + findRoot5(voi, states, rates, constants, computedConstants, algebraic); + findRoot1(voi, states, rates, constants, computedConstants, algebraic); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.c new file mode 100644 index 0000000000..4998481cb1 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.c @@ -0,0 +1,562 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#include "model.dae.external.h" + +#include +#include + +const char VERSION[] = "0.6.0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t STATE_COUNT = 3; +const size_t CONSTANT_COUNT = 5; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 11; +const size_t EXTERNAL_COUNT = 3; + +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; + +const VariableInfo STATE_INFO[] = { + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"m", "dimensionless", "sodium_channel_m_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"E_R", "millivolt", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"}, + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"E_K", "millivolt", "potassium_channel"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"V", "millivolt", "membrane"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +typedef struct { + double voi; + double *states; + double *rates; + double *constants; + double *computedConstants; + double *algebraic; + double *externals; +} RootFindingInfo; + +extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), + double *u, size_t n, void *data); + +void objectiveFunction0(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[0] = u[0]; + + f[0] = algebraic[0]-(((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0)-0.0; +} + +void findRoot0(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[0]; + + nlaSolve(objectiveFunction0, u, 1, &rfi); + + algebraic[0] = u[0]; +} + +void objectiveFunction2(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[3] = u[0]; + + f[0] = algebraic[3]-(constants[1]-10.613)-0.0; +} + +void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[3]; + + nlaSolve(objectiveFunction2, u, 1, &rfi); + + algebraic[3] = u[0]; +} + +void objectiveFunction3(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[1] = u[0]; + + f[0] = algebraic[1]-constants[2]*(externals[0]-algebraic[3])-0.0; +} + +void findRoot3(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[1]; + + nlaSolve(objectiveFunction3, u, 1, &rfi); + + algebraic[1] = u[0]; +} + +void objectiveFunction4(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[4] = u[0]; + + f[0] = algebraic[4]-(constants[1]-115.0)-0.0; +} + +void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[4]; + + nlaSolve(objectiveFunction4, u, 1, &rfi); + + algebraic[4] = u[0]; +} + +void objectiveFunction6(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[5] = u[0]; + + f[0] = algebraic[5]-0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0)-0.0; +} + +void findRoot6(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[5]; + + nlaSolve(objectiveFunction6, u, 1, &rfi); + + algebraic[5] = u[0]; +} + +void objectiveFunction7(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[6] = u[0]; + + f[0] = algebraic[6]-4.0*exp(externals[0]/18.0)-0.0; +} + +void findRoot7(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[6]; + + nlaSolve(objectiveFunction7, u, 1, &rfi); + + algebraic[6] = u[0]; +} + +void objectiveFunction8(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + rates[1] = u[0]; + + f[0] = rates[1]-(algebraic[5]*(1.0-states[1])-algebraic[6]*states[1])-0.0; +} + +void findRoot8(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = rates[1]; + + nlaSolve(objectiveFunction8, u, 1, &rfi); + + rates[1] = u[0]; +} + +void objectiveFunction9(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[7] = u[0]; + + f[0] = algebraic[7]-0.07*exp(externals[0]/20.0)-0.0; +} + +void findRoot9(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[7]; + + nlaSolve(objectiveFunction9, u, 1, &rfi); + + algebraic[7] = u[0]; +} + +void objectiveFunction10(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[8] = u[0]; + + f[0] = algebraic[8]-1.0/(exp((externals[0]+30.0)/10.0)+1.0)-0.0; +} + +void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[8]; + + nlaSolve(objectiveFunction10, u, 1, &rfi); + + algebraic[8] = u[0]; +} + +void objectiveFunction11(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + rates[0] = u[0]; + + f[0] = rates[0]-(algebraic[7]*(1.0-states[0])-algebraic[8]*states[0])-0.0; +} + +void findRoot11(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = rates[0]; + + nlaSolve(objectiveFunction11, u, 1, &rfi); + + rates[0] = u[0]; +} + +void objectiveFunction12(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[9] = u[0]; + + f[0] = algebraic[9]-(constants[1]+12.0)-0.0; +} + +void findRoot12(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[9]; + + nlaSolve(objectiveFunction12, u, 1, &rfi); + + algebraic[9] = u[0]; +} + +void objectiveFunction13(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[2] = u[0]; + + f[0] = algebraic[2]-constants[4]*pow(states[2], 4.0)*(externals[0]-algebraic[9])-0.0; +} + +void findRoot13(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[2]; + + nlaSolve(objectiveFunction13, u, 1, &rfi); + + algebraic[2] = u[0]; +} + +void objectiveFunction15(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[10] = u[0]; + + f[0] = algebraic[10]-0.125*exp(externals[0]/80.0)-0.0; +} + +void findRoot15(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[10]; + + nlaSolve(objectiveFunction15, u, 1, &rfi); + + algebraic[10] = u[0]; +} + +void objectiveFunction16(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + rates[2] = u[0]; + + f[0] = rates[2]-(externals[2]*(1.0-states[2])-algebraic[10]*states[2])-0.0; +} + +void findRoot16(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = rates[2]; + + nlaSolve(objectiveFunction16, u, 1, &rfi); + + rates[2] = u[0]; +} + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + states[0] = 0.6; + states[1] = 0.05; + states[2] = 0.325; + rates[0] = 0.0; + rates[1] = 0.0; + rates[2] = 0.0; + constants[0] = 1.0; + constants[1] = 0.0; + constants[2] = 0.3; + constants[3] = 120.0; + constants[4] = 36.0; + algebraic[0] = 0.0; + algebraic[1] = 0.0; + algebraic[2] = 0.0; + algebraic[3] = 0.0; + algebraic[4] = 0.0; + algebraic[5] = 0.0; + algebraic[6] = 0.0; + algebraic[7] = 0.0; + algebraic[8] = 0.0; + algebraic[9] = 0.0; + algebraic[10] = 0.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + findRoot6(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot7(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot8(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot9(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot10(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot11(voi, states, rates, constants, computedConstants, algebraic, externals); + externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); + findRoot15(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot16(voi, states, rates, constants, computedConstants, algebraic, externals); +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot2(voi, states, rates, constants, computedConstants, algebraic, externals); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + findRoot3(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot4(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); + externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); +} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.h new file mode 100644 index 0000000000..a4fb541db7 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.h @@ -0,0 +1,42 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; + +typedef struct { + char name[8]; + char units[16]; + char component[25]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + +void deleteArray(double *array); + +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.py new file mode 100644 index 0000000000..5ae1b2523f --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.external.py @@ -0,0 +1,478 @@ +# The content of this file was generated using the Python profile of libCellML 0.6.0. + +from enum import Enum +from math import * + + +__version__ = "0.5.0" +LIBCELLML_VERSION = "0.6.0" + +STATE_COUNT = 3 +CONSTANT_COUNT = 5 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 11 +EXTERNAL_COUNT = 3 + +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} + +STATE_INFO = [ + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] + +CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} +] + +EXTERNAL_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} +] + + +def leq_func(x, y): + return 1.0 if x <= y else 0.0 + + +def geq_func(x, y): + return 1.0 if x >= y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +from nlasolver import nla_solve + + +def objective_function_0(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[0] = u[0] + + f[0] = algebraic[0]-(-20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0)-0.0 + + +def find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[0] + + u = nla_solve(objective_function_0, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[0] = u[0] + + +def objective_function_2(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[3] = u[0] + + f[0] = algebraic[3]-(constants[1]-10.613)-0.0 + + +def find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[3] + + u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[3] = u[0] + + +def objective_function_3(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[1] = u[0] + + f[0] = algebraic[1]-constants[2]*(externals[0]-algebraic[3])-0.0 + + +def find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[1] + + u = nla_solve(objective_function_3, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[1] = u[0] + + +def objective_function_4(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[4] = u[0] + + f[0] = algebraic[4]-(constants[1]-115.0)-0.0 + + +def find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[4] + + u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[4] = u[0] + + +def objective_function_6(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[5] = u[0] + + f[0] = algebraic[5]-0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0)-0.0 + + +def find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[5] + + u = nla_solve(objective_function_6, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[5] = u[0] + + +def objective_function_7(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[6] = u[0] + + f[0] = algebraic[6]-4.0*exp(externals[0]/18.0)-0.0 + + +def find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[6] + + u = nla_solve(objective_function_7, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[6] = u[0] + + +def objective_function_8(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + rates[1] = u[0] + + f[0] = rates[1]-(algebraic[5]*(1.0-states[1])-algebraic[6]*states[1])-0.0 + + +def find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = rates[1] + + u = nla_solve(objective_function_8, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + rates[1] = u[0] + + +def objective_function_9(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[7] = u[0] + + f[0] = algebraic[7]-0.07*exp(externals[0]/20.0)-0.0 + + +def find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[7] + + u = nla_solve(objective_function_9, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[7] = u[0] + + +def objective_function_10(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[8] = u[0] + + f[0] = algebraic[8]-1.0/(exp((externals[0]+30.0)/10.0)+1.0)-0.0 + + +def find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[8] + + u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[8] = u[0] + + +def objective_function_11(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + rates[0] = u[0] + + f[0] = rates[0]-(algebraic[7]*(1.0-states[0])-algebraic[8]*states[0])-0.0 + + +def find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = rates[0] + + u = nla_solve(objective_function_11, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + rates[0] = u[0] + + +def objective_function_12(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[9] = u[0] + + f[0] = algebraic[9]-(constants[1]+12.0)-0.0 + + +def find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[9] + + u = nla_solve(objective_function_12, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[9] = u[0] + + +def objective_function_13(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[2] = u[0] + + f[0] = algebraic[2]-constants[4]*pow(states[2], 4.0)*(externals[0]-algebraic[9])-0.0 + + +def find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[2] + + u = nla_solve(objective_function_13, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[2] = u[0] + + +def objective_function_15(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[10] = u[0] + + f[0] = algebraic[10]-0.125*exp(externals[0]/80.0)-0.0 + + +def find_root_15(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[10] + + u = nla_solve(objective_function_15, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[10] = u[0] + + +def objective_function_16(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + rates[2] = u[0] + + f[0] = rates[2]-(externals[2]*(1.0-states[2])-algebraic[10]*states[2])-0.0 + + +def find_root_16(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = rates[2] + + u = nla_solve(objective_function_16, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + rates[2] = u[0] + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): + states[0] = 0.6 + states[1] = 0.05 + states[2] = 0.325 + rates[0] = 0.0 + rates[1] = 0.0 + rates[2] = 0.0 + constants[0] = 1.0 + constants[1] = 0.0 + constants[2] = 0.3 + constants[3] = 120.0 + constants[4] = 36.0 + algebraic[0] = 0.0 + algebraic[1] = 0.0 + algebraic[2] = 0.0 + algebraic[3] = 0.0 + algebraic[4] = 0.0 + algebraic[5] = 0.0 + algebraic[6] = 0.0 + algebraic[7] = 0.0 + algebraic[8] = 0.0 + algebraic[9] = 0.0 + algebraic[10] = 0.0 + + +def compute_computed_constants(constants, computed_constants): + pass + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals) + externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) + find_root_15(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_16(voi, states, rates, constants, computed_constants, algebraic, externals) + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) + externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.h index 921c36cfd1..5d3f4e744d 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.h +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[8]; char units[16]; char component[25]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.py index a78672ba52..b84631d5af 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.py @@ -4,49 +4,48 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 4 -VARIABLE_COUNT = 18 +CONSTANT_COUNT = 5 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 13 +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] -STATE_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.STATE}, - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane", "type": VariableType.ALGEBRAIC}, - {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_R", "units": "millivolt", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "potassium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} ] @@ -66,8 +65,16 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT from nlasolver import nla_solve @@ -77,40 +84,44 @@ def objective_function_0(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[0] = u[0] + algebraic[0] = u[0] - f[0] = variables[0]-(-20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0)-0.0 + f[0] = algebraic[0]-(-20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0)-0.0 -def find_root_0(voi, states, rates, variables): +def find_root_0(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[0] + u[0] = algebraic[0] - u = nla_solve(objective_function_0, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_0, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[0] = u[0] + algebraic[0] = u[0] def objective_function_1(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] rates[0] = u[0] - f[0] = rates[0]-(-(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4])-0.0 + f[0] = rates[0]-(-(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/constants[0])-0.0 -def find_root_1(voi, states, rates, variables): +def find_root_1(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 u[0] = rates[0] - u = nla_solve(objective_function_1, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_1, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) rates[0] = u[0] @@ -119,145 +130,159 @@ def objective_function_2(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[6] = u[0] + algebraic[4] = u[0] - f[0] = variables[6]-(variables[5]-10.613)-0.0 + f[0] = algebraic[4]-(constants[1]-10.613)-0.0 -def find_root_2(voi, states, rates, variables): +def find_root_2(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[6] + u[0] = algebraic[4] - u = nla_solve(objective_function_2, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[6] = u[0] + algebraic[4] = u[0] def objective_function_3(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[1] = u[0] + algebraic[1] = u[0] - f[0] = variables[1]-variables[7]*(states[0]-variables[6])-0.0 + f[0] = algebraic[1]-constants[2]*(states[0]-algebraic[4])-0.0 -def find_root_3(voi, states, rates, variables): +def find_root_3(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[1] + u[0] = algebraic[1] - u = nla_solve(objective_function_3, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_3, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[1] = u[0] + algebraic[1] = u[0] def objective_function_4(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[8] = u[0] + algebraic[5] = u[0] - f[0] = variables[8]-(variables[5]-115.0)-0.0 + f[0] = algebraic[5]-(constants[1]-115.0)-0.0 -def find_root_4(voi, states, rates, variables): +def find_root_4(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[8] + u[0] = algebraic[5] - u = nla_solve(objective_function_4, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[8] = u[0] + algebraic[5] = u[0] def objective_function_5(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[3] = u[0] + algebraic[3] = u[0] - f[0] = variables[3]-variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8])-0.0 + f[0] = algebraic[3]-constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5])-0.0 -def find_root_5(voi, states, rates, variables): +def find_root_5(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[3] + u[0] = algebraic[3] - u = nla_solve(objective_function_5, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_5, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[3] = u[0] + algebraic[3] = u[0] def objective_function_6(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[10] = u[0] + algebraic[6] = u[0] - f[0] = variables[10]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0 + f[0] = algebraic[6]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0 -def find_root_6(voi, states, rates, variables): +def find_root_6(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[10] + u[0] = algebraic[6] - u = nla_solve(objective_function_6, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_6, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[10] = u[0] + algebraic[6] = u[0] def objective_function_7(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[11] = u[0] + algebraic[7] = u[0] - f[0] = variables[11]-4.0*exp(states[0]/18.0)-0.0 + f[0] = algebraic[7]-4.0*exp(states[0]/18.0)-0.0 -def find_root_7(voi, states, rates, variables): +def find_root_7(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[11] + u[0] = algebraic[7] - u = nla_solve(objective_function_7, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_7, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[11] = u[0] + algebraic[7] = u[0] def objective_function_8(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] rates[2] = u[0] - f[0] = rates[2]-(variables[10]*(1.0-states[2])-variables[11]*states[2])-0.0 + f[0] = rates[2]-(algebraic[6]*(1.0-states[2])-algebraic[7]*states[2])-0.0 -def find_root_8(voi, states, rates, variables): +def find_root_8(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 u[0] = rates[2] - u = nla_solve(objective_function_8, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_8, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) rates[2] = u[0] @@ -266,61 +291,67 @@ def objective_function_9(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[12] = u[0] + algebraic[8] = u[0] - f[0] = variables[12]-0.07*exp(states[0]/20.0)-0.0 + f[0] = algebraic[8]-0.07*exp(states[0]/20.0)-0.0 -def find_root_9(voi, states, rates, variables): +def find_root_9(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[12] + u[0] = algebraic[8] - u = nla_solve(objective_function_9, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_9, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[12] = u[0] + algebraic[8] = u[0] def objective_function_10(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[13] = u[0] + algebraic[9] = u[0] - f[0] = variables[13]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 + f[0] = algebraic[9]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 -def find_root_10(voi, states, rates, variables): +def find_root_10(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[13] + u[0] = algebraic[9] - u = nla_solve(objective_function_10, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[13] = u[0] + algebraic[9] = u[0] def objective_function_11(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] rates[1] = u[0] - f[0] = rates[1]-(variables[12]*(1.0-states[1])-variables[13]*states[1])-0.0 + f[0] = rates[1]-(algebraic[8]*(1.0-states[1])-algebraic[9]*states[1])-0.0 -def find_root_11(voi, states, rates, variables): +def find_root_11(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 u[0] = rates[1] - u = nla_solve(objective_function_11, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_11, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) rates[1] = u[0] @@ -329,126 +360,118 @@ def objective_function_12(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[14] = u[0] + algebraic[10] = u[0] - f[0] = variables[14]-(variables[5]+12.0)-0.0 + f[0] = algebraic[10]-(constants[1]+12.0)-0.0 -def find_root_12(voi, states, rates, variables): +def find_root_12(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[14] + u[0] = algebraic[10] - u = nla_solve(objective_function_12, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_12, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[14] = u[0] + algebraic[10] = u[0] def objective_function_13(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[2] = u[0] + algebraic[2] = u[0] - f[0] = variables[2]-variables[15]*pow(states[3], 4.0)*(states[0]-variables[14])-0.0 + f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-algebraic[10])-0.0 -def find_root_13(voi, states, rates, variables): +def find_root_13(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[2] + u[0] = algebraic[2] - u = nla_solve(objective_function_13, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_13, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[2] = u[0] + algebraic[2] = u[0] def objective_function_14(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[16] = u[0] + algebraic[11] = u[0] - f[0] = variables[16]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 + f[0] = algebraic[11]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 -def find_root_14(voi, states, rates, variables): +def find_root_14(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[16] + u[0] = algebraic[11] - u = nla_solve(objective_function_14, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_14, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[16] = u[0] + algebraic[11] = u[0] def objective_function_15(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[17] = u[0] + algebraic[12] = u[0] - f[0] = variables[17]-0.125*exp(states[0]/80.0)-0.0 + f[0] = algebraic[12]-0.125*exp(states[0]/80.0)-0.0 -def find_root_15(voi, states, rates, variables): +def find_root_15(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[17] + u[0] = algebraic[12] - u = nla_solve(objective_function_15, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_15, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[17] = u[0] + algebraic[12] = u[0] def objective_function_16(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] rates[3] = u[0] - f[0] = rates[3]-(variables[16]*(1.0-states[3])-variables[17]*states[3])-0.0 + f[0] = rates[3]-(algebraic[11]*(1.0-states[3])-algebraic[12]*states[3])-0.0 -def find_root_16(voi, states, rates, variables): +def find_root_16(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 u[0] = rates[3] - u = nla_solve(objective_function_16, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_16, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) rates[3] = u[0] -def initialise_variables(states, rates, variables): - variables[0] = 0.0 - variables[1] = 0.0 - variables[2] = 0.0 - variables[3] = 0.0 - variables[4] = 1.0 - variables[5] = 0.0 - variables[6] = 0.0 - variables[7] = 0.3 - variables[8] = 0.0 - variables[9] = 120.0 - variables[10] = 0.0 - variables[11] = 0.0 - variables[12] = 0.0 - variables[13] = 0.0 - variables[14] = 0.0 - variables[15] = 36.0 - variables[16] = 0.0 - variables[17] = 0.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 0.0 states[1] = 0.6 states[2] = 0.05 @@ -457,47 +480,65 @@ def initialise_variables(states, rates, variables): rates[1] = 0.0 rates[2] = 0.0 rates[3] = 0.0 - - -def compute_computed_constants(variables): + constants[0] = 1.0 + constants[1] = 0.0 + constants[2] = 0.3 + constants[3] = 120.0 + constants[4] = 36.0 + algebraic[0] = 0.0 + algebraic[1] = 0.0 + algebraic[2] = 0.0 + algebraic[3] = 0.0 + algebraic[4] = 0.0 + algebraic[5] = 0.0 + algebraic[6] = 0.0 + algebraic[7] = 0.0 + algebraic[8] = 0.0 + algebraic[9] = 0.0 + algebraic[10] = 0.0 + algebraic[11] = 0.0 + algebraic[12] = 0.0 + + +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - find_root_0(voi, states, rates, variables) - find_root_2(voi, states, rates, variables) - find_root_3(voi, states, rates, variables) - find_root_14(voi, states, rates, variables) - find_root_15(voi, states, rates, variables) - find_root_16(voi, states, rates, variables) - find_root_12(voi, states, rates, variables) - find_root_13(voi, states, rates, variables) - find_root_9(voi, states, rates, variables) - find_root_10(voi, states, rates, variables) - find_root_11(voi, states, rates, variables) - find_root_6(voi, states, rates, variables) - find_root_7(voi, states, rates, variables) - find_root_8(voi, states, rates, variables) - find_root_4(voi, states, rates, variables) - find_root_5(voi, states, rates, variables) - find_root_1(voi, states, rates, variables) - - -def compute_variables(voi, states, rates, variables): - find_root_0(voi, states, rates, variables) - find_root_2(voi, states, rates, variables) - find_root_3(voi, states, rates, variables) - find_root_14(voi, states, rates, variables) - find_root_15(voi, states, rates, variables) - find_root_16(voi, states, rates, variables) - find_root_12(voi, states, rates, variables) - find_root_13(voi, states, rates, variables) - find_root_9(voi, states, rates, variables) - find_root_10(voi, states, rates, variables) - find_root_11(voi, states, rates, variables) - find_root_6(voi, states, rates, variables) - find_root_7(voi, states, rates, variables) - find_root_8(voi, states, rates, variables) - find_root_4(voi, states, rates, variables) - find_root_5(voi, states, rates, variables) - find_root_1(voi, states, rates, variables) +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + find_root_0(voi, states, rates, constants, computed_constants, algebraic) + find_root_2(voi, states, rates, constants, computed_constants, algebraic) + find_root_3(voi, states, rates, constants, computed_constants, algebraic) + find_root_14(voi, states, rates, constants, computed_constants, algebraic) + find_root_15(voi, states, rates, constants, computed_constants, algebraic) + find_root_16(voi, states, rates, constants, computed_constants, algebraic) + find_root_12(voi, states, rates, constants, computed_constants, algebraic) + find_root_13(voi, states, rates, constants, computed_constants, algebraic) + find_root_9(voi, states, rates, constants, computed_constants, algebraic) + find_root_10(voi, states, rates, constants, computed_constants, algebraic) + find_root_11(voi, states, rates, constants, computed_constants, algebraic) + find_root_6(voi, states, rates, constants, computed_constants, algebraic) + find_root_7(voi, states, rates, constants, computed_constants, algebraic) + find_root_8(voi, states, rates, constants, computed_constants, algebraic) + find_root_4(voi, states, rates, constants, computed_constants, algebraic) + find_root_5(voi, states, rates, constants, computed_constants, algebraic) + find_root_1(voi, states, rates, constants, computed_constants, algebraic) + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + find_root_0(voi, states, rates, constants, computed_constants, algebraic) + find_root_2(voi, states, rates, constants, computed_constants, algebraic) + find_root_3(voi, states, rates, constants, computed_constants, algebraic) + find_root_14(voi, states, rates, constants, computed_constants, algebraic) + find_root_15(voi, states, rates, constants, computed_constants, algebraic) + find_root_16(voi, states, rates, constants, computed_constants, algebraic) + find_root_12(voi, states, rates, constants, computed_constants, algebraic) + find_root_13(voi, states, rates, constants, computed_constants, algebraic) + find_root_9(voi, states, rates, constants, computed_constants, algebraic) + find_root_10(voi, states, rates, constants, computed_constants, algebraic) + find_root_11(voi, states, rates, constants, computed_constants, algebraic) + find_root_6(voi, states, rates, constants, computed_constants, algebraic) + find_root_7(voi, states, rates, constants, computed_constants, algebraic) + find_root_8(voi, states, rates, constants, computed_constants, algebraic) + find_root_4(voi, states, rates, constants, computed_constants, algebraic) + find_root_5(voi, states, rates, constants, computed_constants, algebraic) + find_root_1(voi, states, rates, constants, computed_constants, algebraic) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.c deleted file mode 100644 index 0140b35169..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.c +++ /dev/null @@ -1,123 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#include "model.dependent.algebraic.h" - -#include -#include - -const char VERSION[] = "0.5.0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t STATE_COUNT = 4; -const size_t VARIABLE_COUNT = 18; - -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; - -const VariableInfo STATE_INFO[] = { - {"V", "millivolt", "membrane", STATE}, - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"m", "dimensionless", "sodium_channel_m_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} -}; - -const VariableInfo VARIABLE_INFO[] = { - {"i_Stim", "microA_per_cm2", "membrane", EXTERNAL}, - {"i_L", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"i_Na", "microA_per_cm2", "sodium_channel", ALGEBRAIC}, - {"Cm", "microF_per_cm2", "membrane", CONSTANT}, - {"E_R", "millivolt", "membrane", CONSTANT}, - {"E_L", "millivolt", "leakage_current", COMPUTED_CONSTANT}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", COMPUTED_CONSTANT}, - {"g_Na", "milliS_per_cm2", "sodium_channel", CONSTANT}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"E_K", "millivolt", "potassium_channel", COMPUTED_CONSTANT}, - {"g_K", "milliS_per_cm2", "potassium_channel", CONSTANT}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", EXTERNAL} -}; - -double * createStatesArray() -{ - double *res = (double *) malloc(STATE_COUNT*sizeof(double)); - - for (size_t i = 0; i < STATE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[4] = 1.0; - variables[5] = 0.0; - variables[7] = 0.3; - variables[9] = 120.0; - variables[15] = 36.0; - states[0] = 0.0; - states[1] = 0.6; - states[2] = 0.05; - states[3] = 0.325; - variables[17] = externalVariable(voi, states, rates, variables, 17); - variables[0] = externalVariable(voi, states, rates, variables, 0); -} - -void computeComputedConstants(double *variables) -{ - variables[6] = variables[5]-10.613; - variables[8] = variables[5]-115.0; - variables[14] = variables[5]+12.0; -} - -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[17] = externalVariable(voi, states, rates, variables, 17); - variables[0] = externalVariable(voi, states, rates, variables, 0); - variables[1] = variables[7]*(states[0]-variables[6]); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4]; - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2]; - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1]; - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3]; -} - -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[17] = externalVariable(voi, states, rates, variables, 17); - variables[0] = externalVariable(voi, states, rates, variables, 0); - variables[1] = variables[7]*(states[0]-variables[6]); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); -} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.c new file mode 100644 index 0000000000..e357c309c0 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.c @@ -0,0 +1,166 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#include "model.dependent.algebraic.external.h" + +#include +#include + +const char VERSION[] = "0.6.0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t STATE_COUNT = 4; +const size_t CONSTANT_COUNT = 5; +const size_t COMPUTED_CONSTANT_COUNT = 3; +const size_t ALGEBRAIC_COUNT = 8; +const size_t EXTERNAL_COUNT = 2; + +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; + +const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"m", "dimensionless", "sodium_channel_m_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"E_R", "millivolt", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, + {"E_K", "millivolt", "potassium_channel"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; + constants[0] = 1.0; + constants[1] = 0.0; + constants[2] = 0.3; + constants[3] = 120.0; + constants[4] = 36.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ + computedConstants[0] = constants[1]-10.613; + computedConstants[1] = constants[1]-115.0; + computedConstants[2] = constants[1]+12.0; +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[0] = constants[2]*(states[0]-computedConstants[0]); + algebraic[1] = constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[2] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1]); + rates[0] = -(-externals[0]+algebraic[2]+algebraic[1]+algebraic[0])/constants[0]; + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[4] = 4.0*exp(states[0]/18.0); + rates[2] = algebraic[3]*(1.0-states[2])-algebraic[4]*states[2]; + algebraic[5] = 0.07*exp(states[0]/20.0); + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = algebraic[5]*(1.0-states[1])-algebraic[6]*states[1]; + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + rates[3] = algebraic[7]*(1.0-states[3])-externals[1]*states[3]; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[0] = constants[2]*(states[0]-computedConstants[0]); + algebraic[2] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1]); + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[4] = 4.0*exp(states[0]/18.0); + algebraic[5] = 0.07*exp(states[0]/20.0); + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + algebraic[1] = constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); +} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.h new file mode 100644 index 0000000000..a4fb541db7 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.h @@ -0,0 +1,42 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; + +typedef struct { + char name[8]; + char units[16]; + char component[25]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + +void deleteArray(double *array); + +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.py new file mode 100644 index 0000000000..5668afa225 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.py @@ -0,0 +1,133 @@ +# The content of this file was generated using the Python profile of libCellML 0.6.0. + +from enum import Enum +from math import * + + +__version__ = "0.5.0" +LIBCELLML_VERSION = "0.6.0" + +STATE_COUNT = 4 +CONSTANT_COUNT = 5 +COMPUTED_CONSTANT_COUNT = 3 +ALGEBRAIC_COUNT = 8 +EXTERNAL_COUNT = 2 + +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} + +STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] + +CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} +] + +ALGEBRAIC_INFO = [ + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} +] + +EXTERNAL_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} +] + + +def leq_func(x, y): + return 1.0 if x <= y else 0.0 + + +def geq_func(x, y): + return 1.0 if x >= y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 + constants[0] = 1.0 + constants[1] = 0.0 + constants[2] = 0.3 + constants[3] = 120.0 + constants[4] = 36.0 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[1]-10.613 + computed_constants[1] = constants[1]-115.0 + computed_constants[2] = constants[1]+12.0 + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[0] = constants[2]*(states[0]-computed_constants[0]) + algebraic[1] = constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[2] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1]) + rates[0] = -(-externals[0]+algebraic[2]+algebraic[1]+algebraic[0])/constants[0] + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[4] = 4.0*exp(states[0]/18.0) + rates[2] = algebraic[3]*(1.0-states[2])-algebraic[4]*states[2] + algebraic[5] = 0.07*exp(states[0]/20.0) + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = algebraic[5]*(1.0-states[1])-algebraic[6]*states[1] + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + rates[3] = algebraic[7]*(1.0-states[3])-externals[1]*states[3] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[0] = constants[2]*(states[0]-computed_constants[0]) + algebraic[2] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1]) + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[4] = 4.0*exp(states[0]/18.0) + algebraic[5] = 0.07*exp(states[0]/20.0) + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + algebraic[1] = constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.h deleted file mode 100644 index 525f2c3c3f..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.h +++ /dev/null @@ -1,42 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; - -typedef struct { - char name[8]; - char units[16]; - char component[25]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VOI_INFO; -extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; - -double * createStatesArray(); -double * createVariablesArray(); -void deleteArray(double *array); - -typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index); - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.py deleted file mode 100644 index 03e5c7c330..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.py +++ /dev/null @@ -1,121 +0,0 @@ -# The content of this file was generated using the Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0" -LIBCELLML_VERSION = "0.6.0" - -STATE_COUNT = 4 -VARIABLE_COUNT = 18 - - -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - EXTERNAL = 5 - - -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} - -STATE_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.STATE}, - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} -] - -VARIABLE_INFO = [ - {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane", "type": VariableType.EXTERNAL}, - {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_R", "units": "millivolt", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "potassium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.EXTERNAL} -] - - -def leq_func(x, y): - return 1.0 if x <= y else 0.0 - - -def geq_func(x, y): - return 1.0 if x >= y else 0.0 - - -def and_func(x, y): - return 1.0 if bool(x) & bool(y) else 0.0 - - -def create_states_array(): - return [nan]*STATE_COUNT - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -def initialise_variables(voi, states, rates, variables, external_variable): - variables[4] = 1.0 - variables[5] = 0.0 - variables[7] = 0.3 - variables[9] = 120.0 - variables[15] = 36.0 - states[0] = 0.0 - states[1] = 0.6 - states[2] = 0.05 - states[3] = 0.325 - variables[17] = external_variable(voi, states, rates, variables, 17) - variables[0] = external_variable(voi, states, rates, variables, 0) - - -def compute_computed_constants(variables): - variables[6] = variables[5]-10.613 - variables[8] = variables[5]-115.0 - variables[14] = variables[5]+12.0 - - -def compute_rates(voi, states, rates, variables, external_variable): - variables[17] = external_variable(voi, states, rates, variables, 17) - variables[0] = external_variable(voi, states, rates, variables, 0) - variables[1] = variables[7]*(states[0]-variables[6]) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4] - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2] - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1] - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3] - - -def compute_variables(voi, states, rates, variables, external_variable): - variables[17] = external_variable(voi, states, rates, variables, 17) - variables[0] = external_variable(voi, states, rates, variables, 0) - variables[1] = variables[7]*(states[0]-variables[6]) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.c deleted file mode 100644 index c74cf081bc..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.c +++ /dev/null @@ -1,126 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#include "model.dependent.computed.constant.h" - -#include -#include - -const char VERSION[] = "0.5.0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t STATE_COUNT = 4; -const size_t VARIABLE_COUNT = 18; - -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; - -const VariableInfo STATE_INFO[] = { - {"V", "millivolt", "membrane", STATE}, - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"m", "dimensionless", "sodium_channel_m_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} -}; - -const VariableInfo VARIABLE_INFO[] = { - {"i_Stim", "microA_per_cm2", "membrane", ALGEBRAIC}, - {"i_L", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"i_Na", "microA_per_cm2", "sodium_channel", ALGEBRAIC}, - {"Cm", "microF_per_cm2", "membrane", CONSTANT}, - {"E_R", "millivolt", "membrane", EXTERNAL}, - {"E_L", "millivolt", "leakage_current", ALGEBRAIC}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", ALGEBRAIC}, - {"g_Na", "milliS_per_cm2", "sodium_channel", CONSTANT}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"E_K", "millivolt", "potassium_channel", EXTERNAL}, - {"g_K", "milliS_per_cm2", "potassium_channel", CONSTANT}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC} -}; - -double * createStatesArray() -{ - double *res = (double *) malloc(STATE_COUNT*sizeof(double)); - - for (size_t i = 0; i < STATE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[4] = 1.0; - variables[7] = 0.3; - variables[9] = 120.0; - variables[15] = 36.0; - states[0] = 0.0; - states[1] = 0.6; - states[2] = 0.05; - states[3] = 0.325; - variables[14] = externalVariable(voi, states, rates, variables, 14); - variables[5] = externalVariable(voi, states, rates, variables, 5); -} - -void computeComputedConstants(double *variables) -{ -} - -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; - variables[14] = externalVariable(voi, states, rates, variables, 14); - variables[5] = externalVariable(voi, states, rates, variables, 5); - variables[6] = variables[5]-10.613; - variables[1] = variables[7]*(states[0]-variables[6]); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[8] = variables[5]-115.0; - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4]; - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2]; - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1]; - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3]; -} - -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[14] = externalVariable(voi, states, rates, variables, 14); - variables[5] = externalVariable(voi, states, rates, variables, 5); - variables[6] = variables[5]-10.613; - variables[1] = variables[7]*(states[0]-variables[6]); - variables[8] = variables[5]-115.0; - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); -} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.c new file mode 100644 index 0000000000..2948224f4d --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.c @@ -0,0 +1,169 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#include "model.dependent.computed.constant.external.h" + +#include +#include + +const char VERSION[] = "0.6.0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t STATE_COUNT = 4; +const size_t CONSTANT_COUNT = 4; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 12; +const size_t EXTERNAL_COUNT = 2; + +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; + +const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"m", "dimensionless", "sodium_channel_m_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"}, + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"E_R", "millivolt", "membrane"}, + {"E_K", "millivolt", "potassium_channel"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; + constants[0] = 1.0; + constants[1] = 0.3; + constants[2] = 120.0; + constants[3] = 36.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[4] = externals[0]-10.613; + algebraic[1] = constants[1]*(states[0]-algebraic[4]); + algebraic[2] = constants[3]*pow(states[3], 4.0)*(states[0]-externals[1]); + algebraic[5] = externals[0]-115.0; + algebraic[3] = constants[2]*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5]); + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/constants[0]; + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[7] = 4.0*exp(states[0]/18.0); + rates[2] = algebraic[6]*(1.0-states[2])-algebraic[7]*states[2]; + algebraic[8] = 0.07*exp(states[0]/20.0); + algebraic[9] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = algebraic[8]*(1.0-states[1])-algebraic[9]*states[1]; + algebraic[10] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[11] = 0.125*exp(states[0]/80.0); + rates[3] = algebraic[10]*(1.0-states[3])-algebraic[11]*states[3]; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[4] = externals[0]-10.613; + algebraic[1] = constants[1]*(states[0]-algebraic[4]); + algebraic[5] = externals[0]-115.0; + algebraic[3] = constants[2]*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5]); + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[7] = 4.0*exp(states[0]/18.0); + algebraic[8] = 0.07*exp(states[0]/20.0); + algebraic[9] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + algebraic[2] = constants[3]*pow(states[3], 4.0)*(states[0]-externals[1]); + algebraic[10] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[11] = 0.125*exp(states[0]/80.0); +} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.h new file mode 100644 index 0000000000..a4fb541db7 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.h @@ -0,0 +1,42 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; + +typedef struct { + char name[8]; + char units[16]; + char component[25]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + +void deleteArray(double *array); + +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.py new file mode 100644 index 0000000000..e4b964565c --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.py @@ -0,0 +1,137 @@ +# The content of this file was generated using the Python profile of libCellML 0.6.0. + +from enum import Enum +from math import * + + +__version__ = "0.5.0" +LIBCELLML_VERSION = "0.6.0" + +STATE_COUNT = 4 +CONSTANT_COUNT = 4 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 12 +EXTERNAL_COUNT = 2 + +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} + +STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] + +CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} +] + +EXTERNAL_INFO = [ + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} +] + + +def leq_func(x, y): + return 1.0 if x <= y else 0.0 + + +def geq_func(x, y): + return 1.0 if x >= y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 + constants[0] = 1.0 + constants[1] = 0.3 + constants[2] = 120.0 + constants[3] = 36.0 + + +def compute_computed_constants(constants, computed_constants): + pass + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[4] = externals[0]-10.613 + algebraic[1] = constants[1]*(states[0]-algebraic[4]) + algebraic[2] = constants[3]*pow(states[3], 4.0)*(states[0]-externals[1]) + algebraic[5] = externals[0]-115.0 + algebraic[3] = constants[2]*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5]) + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/constants[0] + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[7] = 4.0*exp(states[0]/18.0) + rates[2] = algebraic[6]*(1.0-states[2])-algebraic[7]*states[2] + algebraic[8] = 0.07*exp(states[0]/20.0) + algebraic[9] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = algebraic[8]*(1.0-states[1])-algebraic[9]*states[1] + algebraic[10] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[11] = 0.125*exp(states[0]/80.0) + rates[3] = algebraic[10]*(1.0-states[3])-algebraic[11]*states[3] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[4] = externals[0]-10.613 + algebraic[1] = constants[1]*(states[0]-algebraic[4]) + algebraic[5] = externals[0]-115.0 + algebraic[3] = constants[2]*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5]) + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[7] = 4.0*exp(states[0]/18.0) + algebraic[8] = 0.07*exp(states[0]/20.0) + algebraic[9] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + algebraic[2] = constants[3]*pow(states[3], 4.0)*(states[0]-externals[1]) + algebraic[10] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[11] = 0.125*exp(states[0]/80.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.h deleted file mode 100644 index 525f2c3c3f..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.h +++ /dev/null @@ -1,42 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; - -typedef struct { - char name[8]; - char units[16]; - char component[25]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VOI_INFO; -extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; - -double * createStatesArray(); -double * createVariablesArray(); -void deleteArray(double *array); - -typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index); - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.py deleted file mode 100644 index d6873e6275..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.py +++ /dev/null @@ -1,125 +0,0 @@ -# The content of this file was generated using the Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0" -LIBCELLML_VERSION = "0.6.0" - -STATE_COUNT = 4 -VARIABLE_COUNT = 18 - - -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - EXTERNAL = 5 - - -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} - -STATE_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.STATE}, - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} -] - -VARIABLE_INFO = [ - {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane", "type": VariableType.ALGEBRAIC}, - {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_R", "units": "millivolt", "component": "membrane", "type": VariableType.EXTERNAL}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "potassium_channel", "type": VariableType.EXTERNAL}, - {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC} -] - - -def leq_func(x, y): - return 1.0 if x <= y else 0.0 - - -def geq_func(x, y): - return 1.0 if x >= y else 0.0 - - -def and_func(x, y): - return 1.0 if bool(x) & bool(y) else 0.0 - - -def create_states_array(): - return [nan]*STATE_COUNT - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -def initialise_variables(voi, states, rates, variables, external_variable): - variables[4] = 1.0 - variables[7] = 0.3 - variables[9] = 120.0 - variables[15] = 36.0 - states[0] = 0.0 - states[1] = 0.6 - states[2] = 0.05 - states[3] = 0.325 - variables[14] = external_variable(voi, states, rates, variables, 14) - variables[5] = external_variable(voi, states, rates, variables, 5) - - -def compute_computed_constants(variables): - pass - - -def compute_rates(voi, states, rates, variables, external_variable): - variables[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 - variables[14] = external_variable(voi, states, rates, variables, 14) - variables[5] = external_variable(voi, states, rates, variables, 5) - variables[6] = variables[5]-10.613 - variables[1] = variables[7]*(states[0]-variables[6]) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[8] = variables[5]-115.0 - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4] - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2] - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1] - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3] - - -def compute_variables(voi, states, rates, variables, external_variable): - variables[14] = external_variable(voi, states, rates, variables, 14) - variables[5] = external_variable(voi, states, rates, variables, 5) - variables[6] = variables[5]-10.613 - variables[1] = variables[7]*(states[0]-variables[6]) - variables[8] = variables[5]-115.0 - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.c deleted file mode 100644 index a3ad4ba4ec..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.c +++ /dev/null @@ -1,124 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#include "model.dependent.constant.h" - -#include -#include - -const char VERSION[] = "0.5.0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t STATE_COUNT = 4; -const size_t VARIABLE_COUNT = 18; - -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; - -const VariableInfo STATE_INFO[] = { - {"V", "millivolt", "membrane", STATE}, - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"m", "dimensionless", "sodium_channel_m_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} -}; - -const VariableInfo VARIABLE_INFO[] = { - {"i_Stim", "microA_per_cm2", "membrane", ALGEBRAIC}, - {"i_L", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"i_Na", "microA_per_cm2", "sodium_channel", ALGEBRAIC}, - {"Cm", "microF_per_cm2", "membrane", EXTERNAL}, - {"E_R", "millivolt", "membrane", CONSTANT}, - {"E_L", "millivolt", "leakage_current", COMPUTED_CONSTANT}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", COMPUTED_CONSTANT}, - {"g_Na", "milliS_per_cm2", "sodium_channel", EXTERNAL}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"E_K", "millivolt", "potassium_channel", COMPUTED_CONSTANT}, - {"g_K", "milliS_per_cm2", "potassium_channel", CONSTANT}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC} -}; - -double * createStatesArray() -{ - double *res = (double *) malloc(STATE_COUNT*sizeof(double)); - - for (size_t i = 0; i < STATE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[5] = 0.0; - variables[7] = 0.3; - variables[15] = 36.0; - states[0] = 0.0; - states[1] = 0.6; - states[2] = 0.05; - states[3] = 0.325; - variables[9] = externalVariable(voi, states, rates, variables, 9); - variables[4] = externalVariable(voi, states, rates, variables, 4); -} - -void computeComputedConstants(double *variables) -{ - variables[6] = variables[5]-10.613; - variables[8] = variables[5]-115.0; - variables[14] = variables[5]+12.0; -} - -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; - variables[9] = externalVariable(voi, states, rates, variables, 9); - variables[4] = externalVariable(voi, states, rates, variables, 4); - variables[1] = variables[7]*(states[0]-variables[6]); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4]; - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2]; - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1]; - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3]; -} - -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[1] = variables[7]*(states[0]-variables[6]); - variables[9] = externalVariable(voi, states, rates, variables, 9); - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]); - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[11] = 4.0*exp(states[0]/18.0); - variables[12] = 0.07*exp(states[0]/20.0); - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]); - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[17] = 0.125*exp(states[0]/80.0); - variables[4] = externalVariable(voi, states, rates, variables, 4); -} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.c new file mode 100644 index 0000000000..55adde719b --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.c @@ -0,0 +1,167 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#include "model.dependent.constant.external.h" + +#include +#include + +const char VERSION[] = "0.6.0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t STATE_COUNT = 4; +const size_t CONSTANT_COUNT = 3; +const size_t COMPUTED_CONSTANT_COUNT = 3; +const size_t ALGEBRAIC_COUNT = 10; +const size_t EXTERNAL_COUNT = 2; + +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; + +const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"m", "dimensionless", "sodium_channel_m_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"E_R", "millivolt", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, + {"E_K", "millivolt", "potassium_channel"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"}, + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; + constants[0] = 0.0; + constants[1] = 0.3; + constants[2] = 36.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ + computedConstants[0] = constants[0]-10.613; + computedConstants[1] = constants[0]-115.0; + computedConstants[2] = constants[0]+12.0; +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[1] = constants[1]*(states[0]-computedConstants[0]); + algebraic[2] = constants[2]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[3] = externals[1]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1]); + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/externals[0]; + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[5] = 4.0*exp(states[0]/18.0); + rates[2] = algebraic[4]*(1.0-states[2])-algebraic[5]*states[2]; + algebraic[6] = 0.07*exp(states[0]/20.0); + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = algebraic[6]*(1.0-states[1])-algebraic[7]*states[1]; + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[9] = 0.125*exp(states[0]/80.0); + rates[3] = algebraic[8]*(1.0-states[3])-algebraic[9]*states[3]; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + algebraic[1] = constants[1]*(states[0]-computedConstants[0]); + externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); + algebraic[3] = externals[1]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1]); + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[5] = 4.0*exp(states[0]/18.0); + algebraic[6] = 0.07*exp(states[0]/20.0); + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + algebraic[2] = constants[2]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[9] = 0.125*exp(states[0]/80.0); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); +} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.h new file mode 100644 index 0000000000..a4fb541db7 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.h @@ -0,0 +1,42 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; + +typedef struct { + char name[8]; + char units[16]; + char component[25]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + +void deleteArray(double *array); + +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.py new file mode 100644 index 0000000000..3993b79e7f --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.py @@ -0,0 +1,134 @@ +# The content of this file was generated using the Python profile of libCellML 0.6.0. + +from enum import Enum +from math import * + + +__version__ = "0.5.0" +LIBCELLML_VERSION = "0.6.0" + +STATE_COUNT = 4 +CONSTANT_COUNT = 3 +COMPUTED_CONSTANT_COUNT = 3 +ALGEBRAIC_COUNT = 10 +EXTERNAL_COUNT = 2 + +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} + +STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] + +CONSTANT_INFO = [ + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} +] + +ALGEBRAIC_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} +] + +EXTERNAL_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"} +] + + +def leq_func(x, y): + return 1.0 if x <= y else 0.0 + + +def geq_func(x, y): + return 1.0 if x >= y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 + constants[0] = 0.0 + constants[1] = 0.3 + constants[2] = 36.0 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[0]-10.613 + computed_constants[1] = constants[0]-115.0 + computed_constants[2] = constants[0]+12.0 + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[1] = constants[1]*(states[0]-computed_constants[0]) + algebraic[2] = constants[2]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[3] = externals[1]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1]) + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/externals[0] + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[5] = 4.0*exp(states[0]/18.0) + rates[2] = algebraic[4]*(1.0-states[2])-algebraic[5]*states[2] + algebraic[6] = 0.07*exp(states[0]/20.0) + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = algebraic[6]*(1.0-states[1])-algebraic[7]*states[1] + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[9] = 0.125*exp(states[0]/80.0) + rates[3] = algebraic[8]*(1.0-states[3])-algebraic[9]*states[3] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[1] = constants[1]*(states[0]-computed_constants[0]) + externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) + algebraic[3] = externals[1]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1]) + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[5] = 4.0*exp(states[0]/18.0) + algebraic[6] = 0.07*exp(states[0]/20.0) + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + algebraic[2] = constants[2]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[9] = 0.125*exp(states[0]/80.0) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.h deleted file mode 100644 index 525f2c3c3f..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.h +++ /dev/null @@ -1,42 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; - -typedef struct { - char name[8]; - char units[16]; - char component[25]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VOI_INFO; -extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; - -double * createStatesArray(); -double * createVariablesArray(); -void deleteArray(double *array); - -typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index); - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.py deleted file mode 100644 index a3816969d7..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.py +++ /dev/null @@ -1,122 +0,0 @@ -# The content of this file was generated using the Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0" -LIBCELLML_VERSION = "0.6.0" - -STATE_COUNT = 4 -VARIABLE_COUNT = 18 - - -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - EXTERNAL = 5 - - -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} - -STATE_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.STATE}, - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} -] - -VARIABLE_INFO = [ - {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane", "type": VariableType.ALGEBRAIC}, - {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.EXTERNAL}, - {"name": "E_R", "units": "millivolt", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.EXTERNAL}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "potassium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC} -] - - -def leq_func(x, y): - return 1.0 if x <= y else 0.0 - - -def geq_func(x, y): - return 1.0 if x >= y else 0.0 - - -def and_func(x, y): - return 1.0 if bool(x) & bool(y) else 0.0 - - -def create_states_array(): - return [nan]*STATE_COUNT - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -def initialise_variables(voi, states, rates, variables, external_variable): - variables[5] = 0.0 - variables[7] = 0.3 - variables[15] = 36.0 - states[0] = 0.0 - states[1] = 0.6 - states[2] = 0.05 - states[3] = 0.325 - variables[9] = external_variable(voi, states, rates, variables, 9) - variables[4] = external_variable(voi, states, rates, variables, 4) - - -def compute_computed_constants(variables): - variables[6] = variables[5]-10.613 - variables[8] = variables[5]-115.0 - variables[14] = variables[5]+12.0 - - -def compute_rates(voi, states, rates, variables, external_variable): - variables[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 - variables[9] = external_variable(voi, states, rates, variables, 9) - variables[4] = external_variable(voi, states, rates, variables, 4) - variables[1] = variables[7]*(states[0]-variables[6]) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4] - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2] - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1] - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3] - - -def compute_variables(voi, states, rates, variables, external_variable): - variables[1] = variables[7]*(states[0]-variables[6]) - variables[9] = external_variable(voi, states, rates, variables, 9) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) - variables[4] = external_variable(voi, states, rates, variables, 4) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.c deleted file mode 100644 index 4aa8bde09a..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.c +++ /dev/null @@ -1,112 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#include "model.dependent.state.h" - -#include -#include - -const char VERSION[] = "0.5.0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t STATE_COUNT = 2; -const size_t VARIABLE_COUNT = 20; - -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; - -const VariableInfo STATE_INFO[] = { - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} -}; - -const VariableInfo VARIABLE_INFO[] = { - {"i_Stim", "microA_per_cm2", "membrane", ALGEBRAIC}, - {"V", "millivolt", "membrane", EXTERNAL}, - {"i_L", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"i_Na", "microA_per_cm2", "sodium_channel", ALGEBRAIC}, - {"Cm", "microF_per_cm2", "membrane", CONSTANT}, - {"E_R", "millivolt", "membrane", CONSTANT}, - {"E_L", "millivolt", "leakage_current", COMPUTED_CONSTANT}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", COMPUTED_CONSTANT}, - {"g_Na", "milliS_per_cm2", "sodium_channel", CONSTANT}, - {"m", "dimensionless", "sodium_channel_m_gate", EXTERNAL}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"E_K", "millivolt", "potassium_channel", COMPUTED_CONSTANT}, - {"g_K", "milliS_per_cm2", "potassium_channel", CONSTANT}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC} -}; - -double * createStatesArray() -{ - double *res = (double *) malloc(STATE_COUNT*sizeof(double)); - - for (size_t i = 0; i < STATE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[5] = 1.0; - variables[6] = 0.0; - variables[8] = 0.3; - variables[10] = 120.0; - variables[17] = 36.0; - states[0] = 0.6; - states[1] = 0.325; - variables[1] = externalVariable(voi, states, rates, variables, 1); - variables[11] = externalVariable(voi, states, rates, variables, 11); -} - -void computeComputedConstants(double *variables) -{ - variables[7] = variables[6]-10.613; - variables[9] = variables[6]-115.0; - variables[16] = variables[6]+12.0; -} - -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[1] = externalVariable(voi, states, rates, variables, 1); - variables[14] = 0.07*exp(variables[1]/20.0); - variables[15] = 1.0/(exp((variables[1]+30.0)/10.0)+1.0); - rates[0] = variables[14]*(1.0-states[0])-variables[15]*states[0]; - variables[18] = 0.01*(variables[1]+10.0)/(exp((variables[1]+10.0)/10.0)-1.0); - variables[19] = 0.125*exp(variables[1]/80.0); - rates[1] = variables[18]*(1.0-states[1])-variables[19]*states[1]; -} - -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; - variables[1] = externalVariable(voi, states, rates, variables, 1); - variables[2] = variables[8]*(variables[1]-variables[7]); - variables[11] = externalVariable(voi, states, rates, variables, 11); - variables[4] = variables[10]*pow(variables[11], 3.0)*states[0]*(variables[1]-variables[9]); - variables[12] = 0.1*(variables[1]+25.0)/(exp((variables[1]+25.0)/10.0)-1.0); - variables[13] = 4.0*exp(variables[1]/18.0); - variables[3] = variables[17]*pow(states[1], 4.0)*(variables[1]-variables[16]); -} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.c new file mode 100644 index 0000000000..b9bca59ba5 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.c @@ -0,0 +1,155 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#include "model.dependent.state.external.h" + +#include +#include + +const char VERSION[] = "0.6.0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t STATE_COUNT = 2; +const size_t CONSTANT_COUNT = 5; +const size_t COMPUTED_CONSTANT_COUNT = 3; +const size_t ALGEBRAIC_COUNT = 10; +const size_t EXTERNAL_COUNT = 2; + +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; + +const VariableInfo STATE_INFO[] = { + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"E_R", "millivolt", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, + {"E_K", "millivolt", "potassium_channel"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"}, + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"V", "millivolt", "membrane"}, + {"m", "dimensionless", "sodium_channel_m_gate"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + states[0] = 0.6; + states[1] = 0.325; + constants[0] = 1.0; + constants[1] = 0.0; + constants[2] = 0.3; + constants[3] = 120.0; + constants[4] = 36.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ + computedConstants[0] = constants[1]-10.613; + computedConstants[1] = constants[1]-115.0; + computedConstants[2] = constants[1]+12.0; +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[6] = 0.07*exp(externals[0]/20.0); + algebraic[7] = 1.0/(exp((externals[0]+30.0)/10.0)+1.0); + rates[0] = algebraic[6]*(1.0-states[0])-algebraic[7]*states[0]; + algebraic[8] = 0.01*(externals[0]+10.0)/(exp((externals[0]+10.0)/10.0)-1.0); + algebraic[9] = 0.125*exp(externals[0]/80.0); + rates[1] = algebraic[8]*(1.0-states[1])-algebraic[9]*states[1]; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[1] = constants[2]*(externals[0]-computedConstants[0]); + externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); + algebraic[3] = constants[3]*pow(externals[1], 3.0)*states[0]*(externals[0]-computedConstants[1]); + algebraic[4] = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0); + algebraic[5] = 4.0*exp(externals[0]/18.0); + algebraic[2] = constants[4]*pow(states[1], 4.0)*(externals[0]-computedConstants[2]); +} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.h new file mode 100644 index 0000000000..a4fb541db7 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.h @@ -0,0 +1,42 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; + +typedef struct { + char name[8]; + char units[16]; + char component[25]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + +void deleteArray(double *array); + +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.py new file mode 100644 index 0000000000..d7c683c17d --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.py @@ -0,0 +1,122 @@ +# The content of this file was generated using the Python profile of libCellML 0.6.0. + +from enum import Enum +from math import * + + +__version__ = "0.5.0" +LIBCELLML_VERSION = "0.6.0" + +STATE_COUNT = 2 +CONSTANT_COUNT = 5 +COMPUTED_CONSTANT_COUNT = 3 +ALGEBRAIC_COUNT = 10 +EXTERNAL_COUNT = 2 + +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} + +STATE_INFO = [ + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] + +CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} +] + +ALGEBRAIC_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} +] + +EXTERNAL_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"} +] + + +def leq_func(x, y): + return 1.0 if x <= y else 0.0 + + +def geq_func(x, y): + return 1.0 if x >= y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): + states[0] = 0.6 + states[1] = 0.325 + constants[0] = 1.0 + constants[1] = 0.0 + constants[2] = 0.3 + constants[3] = 120.0 + constants[4] = 36.0 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[1]-10.613 + computed_constants[1] = constants[1]-115.0 + computed_constants[2] = constants[1]+12.0 + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[6] = 0.07*exp(externals[0]/20.0) + algebraic[7] = 1.0/(exp((externals[0]+30.0)/10.0)+1.0) + rates[0] = algebraic[6]*(1.0-states[0])-algebraic[7]*states[0] + algebraic[8] = 0.01*(externals[0]+10.0)/(exp((externals[0]+10.0)/10.0)-1.0) + algebraic[9] = 0.125*exp(externals[0]/80.0) + rates[1] = algebraic[8]*(1.0-states[1])-algebraic[9]*states[1] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[1] = constants[2]*(externals[0]-computed_constants[0]) + externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) + algebraic[3] = constants[3]*pow(externals[1], 3.0)*states[0]*(externals[0]-computed_constants[1]) + algebraic[4] = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0) + algebraic[5] = 4.0*exp(externals[0]/18.0) + algebraic[2] = constants[4]*pow(states[1], 4.0)*(externals[0]-computed_constants[2]) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.h deleted file mode 100644 index 525f2c3c3f..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.h +++ /dev/null @@ -1,42 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; - -typedef struct { - char name[8]; - char units[16]; - char component[25]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VOI_INFO; -extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; - -double * createStatesArray(); -double * createVariablesArray(); -void deleteArray(double *array); - -typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index); - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.py deleted file mode 100644 index 507b2f58b5..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.py +++ /dev/null @@ -1,110 +0,0 @@ -# The content of this file was generated using the Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0" -LIBCELLML_VERSION = "0.6.0" - -STATE_COUNT = 2 -VARIABLE_COUNT = 20 - - -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - EXTERNAL = 5 - - -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} - -STATE_INFO = [ - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} -] - -VARIABLE_INFO = [ - {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane", "type": VariableType.ALGEBRAIC}, - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.EXTERNAL}, - {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_R", "units": "millivolt", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.EXTERNAL}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "potassium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC} -] - - -def leq_func(x, y): - return 1.0 if x <= y else 0.0 - - -def geq_func(x, y): - return 1.0 if x >= y else 0.0 - - -def and_func(x, y): - return 1.0 if bool(x) & bool(y) else 0.0 - - -def create_states_array(): - return [nan]*STATE_COUNT - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -def initialise_variables(voi, states, rates, variables, external_variable): - variables[5] = 1.0 - variables[6] = 0.0 - variables[8] = 0.3 - variables[10] = 120.0 - variables[17] = 36.0 - states[0] = 0.6 - states[1] = 0.325 - variables[1] = external_variable(voi, states, rates, variables, 1) - variables[11] = external_variable(voi, states, rates, variables, 11) - - -def compute_computed_constants(variables): - variables[7] = variables[6]-10.613 - variables[9] = variables[6]-115.0 - variables[16] = variables[6]+12.0 - - -def compute_rates(voi, states, rates, variables, external_variable): - variables[1] = external_variable(voi, states, rates, variables, 1) - variables[14] = 0.07*exp(variables[1]/20.0) - variables[15] = 1.0/(exp((variables[1]+30.0)/10.0)+1.0) - rates[0] = variables[14]*(1.0-states[0])-variables[15]*states[0] - variables[18] = 0.01*(variables[1]+10.0)/(exp((variables[1]+10.0)/10.0)-1.0) - variables[19] = 0.125*exp(variables[1]/80.0) - rates[1] = variables[18]*(1.0-states[1])-variables[19]*states[1] - - -def compute_variables(voi, states, rates, variables, external_variable): - variables[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 - variables[1] = external_variable(voi, states, rates, variables, 1) - variables[2] = variables[8]*(variables[1]-variables[7]) - variables[11] = external_variable(voi, states, rates, variables, 11) - variables[4] = variables[10]*pow(variables[11], 3.0)*states[0]*(variables[1]-variables[9]) - variables[12] = 0.1*(variables[1]+25.0)/(exp((variables[1]+25.0)/10.0)-1.0) - variables[13] = 4.0*exp(variables[1]/18.0) - variables[3] = variables[17]*pow(states[1], 4.0)*(variables[1]-variables[16]) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.c index 428d40b752..f76a9cfe46 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.c @@ -5,40 +5,52 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 3; -const size_t VARIABLE_COUNT = 19; +const size_t CONSTANT_COUNT = 5; +const size_t COMPUTED_CONSTANT_COUNT = 3; +const size_t ALGEBRAIC_COUNT = 8; +const size_t EXTERNAL_COUNT = 3; -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"m", "dimensionless", "sodium_channel_m_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"m", "dimensionless", "sodium_channel_m_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} }; -const VariableInfo VARIABLE_INFO[] = { - {"i_Stim", "microA_per_cm2", "membrane", ALGEBRAIC}, - {"V", "millivolt", "membrane", EXTERNAL}, - {"i_L", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"i_Na", "microA_per_cm2", "sodium_channel", EXTERNAL}, - {"Cm", "microF_per_cm2", "membrane", CONSTANT}, - {"E_R", "millivolt", "membrane", CONSTANT}, - {"E_L", "millivolt", "leakage_current", COMPUTED_CONSTANT}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", COMPUTED_CONSTANT}, - {"g_Na", "milliS_per_cm2", "sodium_channel", CONSTANT}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"E_K", "millivolt", "potassium_channel", COMPUTED_CONSTANT}, - {"g_K", "milliS_per_cm2", "potassium_channel", CONSTANT}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", EXTERNAL}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"E_R", "millivolt", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, + {"E_K", "millivolt", "potassium_channel"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"}, + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"V", "millivolt", "membrane"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"} }; double * createStatesArray() @@ -52,11 +64,44 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { res[i] = NAN; } @@ -68,48 +113,45 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[5] = 1.0; - variables[6] = 0.0; - variables[8] = 0.3; - variables[10] = 120.0; - variables[16] = 36.0; states[0] = 0.6; states[1] = 0.05; states[2] = 0.325; - variables[1] = externalVariable(voi, states, rates, variables, 1); - variables[17] = externalVariable(voi, states, rates, variables, 17); - variables[4] = externalVariable(voi, states, rates, variables, 4); + constants[0] = 1.0; + constants[1] = 0.0; + constants[2] = 0.3; + constants[3] = 120.0; + constants[4] = 36.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { - variables[7] = variables[6]-10.613; - variables[9] = variables[6]-115.0; - variables[15] = variables[6]+12.0; + computedConstants[0] = constants[1]-10.613; + computedConstants[1] = constants[1]-115.0; + computedConstants[2] = constants[1]+12.0; } -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - variables[1] = externalVariable(voi, states, rates, variables, 1); - variables[11] = 0.1*(variables[1]+25.0)/(exp((variables[1]+25.0)/10.0)-1.0); - variables[12] = 4.0*exp(variables[1]/18.0); - rates[1] = variables[11]*(1.0-states[1])-variables[12]*states[1]; - variables[13] = 0.07*exp(variables[1]/20.0); - variables[14] = 1.0/(exp((variables[1]+30.0)/10.0)+1.0); - rates[0] = variables[13]*(1.0-states[0])-variables[14]*states[0]; - variables[17] = externalVariable(voi, states, rates, variables, 17); - variables[18] = 0.125*exp(variables[1]/80.0); - rates[2] = variables[17]*(1.0-states[2])-variables[18]*states[2]; + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[3] = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0); + algebraic[4] = 4.0*exp(externals[0]/18.0); + rates[1] = algebraic[3]*(1.0-states[1])-algebraic[4]*states[1]; + algebraic[5] = 0.07*exp(externals[0]/20.0); + algebraic[6] = 1.0/(exp((externals[0]+30.0)/10.0)+1.0); + rates[0] = algebraic[5]*(1.0-states[0])-algebraic[6]*states[0]; + externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); + algebraic[7] = 0.125*exp(externals[0]/80.0); + rates[2] = externals[2]*(1.0-states[2])-algebraic[7]*states[2]; } -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - variables[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; - variables[1] = externalVariable(voi, states, rates, variables, 1); - variables[2] = variables[8]*(variables[1]-variables[7]); - variables[17] = externalVariable(voi, states, rates, variables, 17); - variables[4] = externalVariable(voi, states, rates, variables, 4); - variables[3] = variables[16]*pow(states[2], 4.0)*(variables[1]-variables[15]); + algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[1] = constants[2]*(externals[0]-computedConstants[0]); + externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); + externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); + algebraic[2] = constants[4]*pow(states[2], 4.0)*(externals[0]-computedConstants[2]); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.h index 525f2c3c3f..a4fb541db7 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.h +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.h @@ -8,35 +8,35 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; typedef struct { char name[8]; char units[16]; char component[25]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + void deleteArray(double *array); -typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index); +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.py index 60f658a6c1..c7ae5b5488 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.external.py @@ -4,50 +4,52 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 3 -VARIABLE_COUNT = 19 +CONSTANT_COUNT = 5 +COMPUTED_CONSTANT_COUNT = 3 +ALGEBRAIC_COUNT = 8 +EXTERNAL_COUNT = 3 +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - EXTERNAL = 5 +STATE_INFO = [ + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] +CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +COMPUTED_CONSTANT_INFO = [ + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} +] -STATE_INFO = [ - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} +ALGEBRAIC_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} ] -VARIABLE_INFO = [ - {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane", "type": VariableType.ALGEBRAIC}, - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.EXTERNAL}, - {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.EXTERNAL}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_R", "units": "millivolt", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "potassium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.EXTERNAL}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC} +EXTERNAL_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} ] @@ -67,47 +69,56 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT -def initialise_variables(voi, states, rates, variables, external_variable): - variables[5] = 1.0 - variables[6] = 0.0 - variables[8] = 0.3 - variables[10] = 120.0 - variables[16] = 36.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 0.6 states[1] = 0.05 states[2] = 0.325 - variables[1] = external_variable(voi, states, rates, variables, 1) - variables[17] = external_variable(voi, states, rates, variables, 17) - variables[4] = external_variable(voi, states, rates, variables, 4) - - -def compute_computed_constants(variables): - variables[7] = variables[6]-10.613 - variables[9] = variables[6]-115.0 - variables[15] = variables[6]+12.0 - - -def compute_rates(voi, states, rates, variables, external_variable): - variables[1] = external_variable(voi, states, rates, variables, 1) - variables[11] = 0.1*(variables[1]+25.0)/(exp((variables[1]+25.0)/10.0)-1.0) - variables[12] = 4.0*exp(variables[1]/18.0) - rates[1] = variables[11]*(1.0-states[1])-variables[12]*states[1] - variables[13] = 0.07*exp(variables[1]/20.0) - variables[14] = 1.0/(exp((variables[1]+30.0)/10.0)+1.0) - rates[0] = variables[13]*(1.0-states[0])-variables[14]*states[0] - variables[17] = external_variable(voi, states, rates, variables, 17) - variables[18] = 0.125*exp(variables[1]/80.0) - rates[2] = variables[17]*(1.0-states[2])-variables[18]*states[2] - - -def compute_variables(voi, states, rates, variables, external_variable): - variables[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 - variables[1] = external_variable(voi, states, rates, variables, 1) - variables[2] = variables[8]*(variables[1]-variables[7]) - variables[17] = external_variable(voi, states, rates, variables, 17) - variables[4] = external_variable(voi, states, rates, variables, 4) - variables[3] = variables[16]*pow(states[2], 4.0)*(variables[1]-variables[15]) + constants[0] = 1.0 + constants[1] = 0.0 + constants[2] = 0.3 + constants[3] = 120.0 + constants[4] = 36.0 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[1]-10.613 + computed_constants[1] = constants[1]-115.0 + computed_constants[2] = constants[1]+12.0 + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[3] = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0) + algebraic[4] = 4.0*exp(externals[0]/18.0) + rates[1] = algebraic[3]*(1.0-states[1])-algebraic[4]*states[1] + algebraic[5] = 0.07*exp(externals[0]/20.0) + algebraic[6] = 1.0/(exp((externals[0]+30.0)/10.0)+1.0) + rates[0] = algebraic[5]*(1.0-states[0])-algebraic[6]*states[0] + externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) + algebraic[7] = 0.125*exp(externals[0]/80.0) + rates[2] = externals[2]*(1.0-states[2])-algebraic[7]*states[2] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[1] = constants[2]*(externals[0]-computed_constants[0]) + externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) + externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) + algebraic[2] = constants[4]*pow(states[2], 4.0)*(externals[0]-computed_constants[2]) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.h index 921c36cfd1..5d3f4e744d 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.h +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[8]; char units[16]; char component[25]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.py index 7343f761af..ac70b2373a 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.py @@ -4,49 +4,48 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 4 -VARIABLE_COUNT = 18 +CONSTANT_COUNT = 5 +COMPUTED_CONSTANT_COUNT = 3 +ALGEBRAIC_COUNT = 10 +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] -STATE_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.STATE}, - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} ] -VARIABLE_INFO = [ - {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane", "type": VariableType.ALGEBRAIC}, - {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_R", "units": "millivolt", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "potassium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} ] @@ -66,52 +65,60 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT -def initialise_variables(states, rates, variables): - variables[4] = 1.0 - variables[5] = 0.0 - variables[7] = 0.3 - variables[9] = 120.0 - variables[15] = 36.0 + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 0.0 states[1] = 0.6 states[2] = 0.05 states[3] = 0.325 - - -def compute_computed_constants(variables): - variables[6] = variables[5]-10.613 - variables[8] = variables[5]-115.0 - variables[14] = variables[5]+12.0 - - -def compute_rates(voi, states, rates, variables): - variables[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 - variables[1] = variables[7]*(states[0]-variables[6]) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4] - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - rates[2] = variables[10]*(1.0-states[2])-variables[11]*states[2] - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - rates[1] = variables[12]*(1.0-states[1])-variables[13]*states[1] - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) - rates[3] = variables[16]*(1.0-states[3])-variables[17]*states[3] - - -def compute_variables(voi, states, rates, variables): - variables[1] = variables[7]*(states[0]-variables[6]) - variables[3] = variables[9]*pow(states[2], 3.0)*states[1]*(states[0]-variables[8]) - variables[10] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[11] = 4.0*exp(states[0]/18.0) - variables[12] = 0.07*exp(states[0]/20.0) - variables[13] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - variables[2] = variables[15]*pow(states[3], 4.0)*(states[0]-variables[14]) - variables[16] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[17] = 0.125*exp(states[0]/80.0) + constants[0] = 1.0 + constants[1] = 0.0 + constants[2] = 0.3 + constants[3] = 120.0 + constants[4] = 36.0 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[1]-10.613 + computed_constants[1] = constants[1]-115.0 + computed_constants[2] = constants[1]+12.0 + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + algebraic[1] = constants[2]*(states[0]-computed_constants[0]) + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[3] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1]) + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/constants[0] + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[5] = 4.0*exp(states[0]/18.0) + rates[2] = algebraic[4]*(1.0-states[2])-algebraic[5]*states[2] + algebraic[6] = 0.07*exp(states[0]/20.0) + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = algebraic[6]*(1.0-states[1])-algebraic[7]*states[1] + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[9] = 0.125*exp(states[0]/80.0) + rates[3] = algebraic[8]*(1.0-states[3])-algebraic[9]*states[3] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[1] = constants[2]*(states[0]-computed_constants[0]) + algebraic[3] = constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1]) + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[5] = 4.0*exp(states[0]/18.0) + algebraic[6] = 0.07*exp(states[0]/20.0) + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[9] = 0.125*exp(states[0]/80.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.c deleted file mode 100644 index 6e4ef64afa..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.c +++ /dev/null @@ -1,119 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#include "model.state.h" - -#include -#include - -const char VERSION[] = "0.5.0"; -const char LIBCELLML_VERSION[] = "0.6.0"; - -const size_t STATE_COUNT = 3; -const size_t VARIABLE_COUNT = 19; - -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; - -const VariableInfo STATE_INFO[] = { - {"V", "millivolt", "membrane", STATE}, - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} -}; - -const VariableInfo VARIABLE_INFO[] = { - {"i_Stim", "microA_per_cm2", "membrane", ALGEBRAIC}, - {"i_L", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"i_Na", "microA_per_cm2", "sodium_channel", ALGEBRAIC}, - {"Cm", "microF_per_cm2", "membrane", CONSTANT}, - {"E_R", "millivolt", "membrane", CONSTANT}, - {"E_L", "millivolt", "leakage_current", COMPUTED_CONSTANT}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", COMPUTED_CONSTANT}, - {"g_Na", "milliS_per_cm2", "sodium_channel", CONSTANT}, - {"m", "dimensionless", "sodium_channel_m_gate", EXTERNAL}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"E_K", "millivolt", "potassium_channel", COMPUTED_CONSTANT}, - {"g_K", "milliS_per_cm2", "potassium_channel", CONSTANT}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC} -}; - -double * createStatesArray() -{ - double *res = (double *) malloc(STATE_COUNT*sizeof(double)); - - for (size_t i = 0; i < STATE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -double * createVariablesArray() -{ - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); - - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { - res[i] = NAN; - } - - return res; -} - -void deleteArray(double *array) -{ - free(array); -} - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[4] = 1.0; - variables[5] = 0.0; - variables[7] = 0.3; - variables[9] = 120.0; - variables[16] = 36.0; - states[0] = 0.0; - states[1] = 0.6; - states[2] = 0.325; - variables[10] = externalVariable(voi, states, rates, variables, 10); -} - -void computeComputedConstants(double *variables) -{ - variables[6] = variables[5]-10.613; - variables[8] = variables[5]-115.0; - variables[15] = variables[5]+12.0; -} - -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; - variables[1] = variables[7]*(states[0]-variables[6]); - variables[2] = variables[16]*pow(states[2], 4.0)*(states[0]-variables[15]); - variables[10] = externalVariable(voi, states, rates, variables, 10); - variables[3] = variables[9]*pow(variables[10], 3.0)*states[1]*(states[0]-variables[8]); - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4]; - variables[13] = 0.07*exp(states[0]/20.0); - variables[14] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - rates[1] = variables[13]*(1.0-states[1])-variables[14]*states[1]; - variables[17] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[18] = 0.125*exp(states[0]/80.0); - rates[2] = variables[17]*(1.0-states[2])-variables[18]*states[2]; -} - -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable) -{ - variables[1] = variables[7]*(states[0]-variables[6]); - variables[10] = externalVariable(voi, states, rates, variables, 10); - variables[3] = variables[9]*pow(variables[10], 3.0)*states[1]*(states[0]-variables[8]); - variables[11] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); - variables[12] = 4.0*exp(states[0]/18.0); - variables[13] = 0.07*exp(states[0]/20.0); - variables[14] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); - variables[2] = variables[16]*pow(states[2], 4.0)*(states[0]-variables[15]); - variables[17] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); - variables[18] = 0.125*exp(states[0]/80.0); -} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.c new file mode 100644 index 0000000000..0e3ca00d59 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.c @@ -0,0 +1,163 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#include "model.state.external.h" + +#include +#include + +const char VERSION[] = "0.6.0"; +const char LIBCELLML_VERSION[] = "0.6.0"; + +const size_t STATE_COUNT = 3; +const size_t CONSTANT_COUNT = 5; +const size_t COMPUTED_CONSTANT_COUNT = 3; +const size_t ALGEBRAIC_COUNT = 10; +const size_t EXTERNAL_COUNT = 1; + +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; + +const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"E_R", "millivolt", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"g_K", "milliS_per_cm2", "potassium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, + {"E_K", "millivolt", "potassium_channel"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Stim", "microA_per_cm2", "membrane"}, + {"i_L", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"m", "dimensionless", "sodium_channel_m_gate"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() +{ + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); + + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.325; + constants[0] = 1.0; + constants[1] = 0.0; + constants[2] = 0.3; + constants[3] = 120.0; + constants[4] = 36.0; +} + +void computeComputedConstants(double *constants, double *computedConstants) +{ + computedConstants[0] = constants[1]-10.613; + computedConstants[1] = constants[1]-115.0; + computedConstants[2] = constants[1]+12.0; +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + algebraic[1] = constants[2]*(states[0]-computedConstants[0]); + algebraic[2] = constants[4]*pow(states[2], 4.0)*(states[0]-computedConstants[2]); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[3] = constants[3]*pow(externals[0], 3.0)*states[1]*(states[0]-computedConstants[1]); + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/constants[0]; + algebraic[6] = 0.07*exp(states[0]/20.0); + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = algebraic[6]*(1.0-states[1])-algebraic[7]*states[1]; + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[9] = 0.125*exp(states[0]/80.0); + rates[2] = algebraic[8]*(1.0-states[2])-algebraic[9]*states[2]; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) +{ + algebraic[1] = constants[2]*(states[0]-computedConstants[0]); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[3] = constants[3]*pow(externals[0], 3.0)*states[1]*(states[0]-computedConstants[1]); + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + algebraic[5] = 4.0*exp(states[0]/18.0); + algebraic[6] = 0.07*exp(states[0]/20.0); + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + algebraic[2] = constants[4]*pow(states[2], 4.0)*(states[0]-computedConstants[2]); + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[9] = 0.125*exp(states[0]/80.0); +} diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.h new file mode 100644 index 0000000000..a4fb541db7 --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.h @@ -0,0 +1,42 @@ +/* The content of this file was generated using the C profile of libCellML 0.6.0. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; + +typedef struct { + char name[8]; + char units[16]; + char component[25]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); + +void deleteArray(double *array); + +typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); + +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.py new file mode 100644 index 0000000000..bdf273310b --- /dev/null +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.py @@ -0,0 +1,130 @@ +# The content of this file was generated using the Python profile of libCellML 0.6.0. + +from enum import Enum +from math import * + + +__version__ = "0.5.0" +LIBCELLML_VERSION = "0.6.0" + +STATE_COUNT = 3 +CONSTANT_COUNT = 5 +COMPUTED_CONSTANT_COUNT = 3 +ALGEBRAIC_COUNT = 10 +EXTERNAL_COUNT = 1 + +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} + +STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] + +CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "E_R", "units": "millivolt", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} +] + +ALGEBRAIC_INFO = [ + {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, + {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} +] + +EXTERNAL_INFO = [ + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"} +] + + +def leq_func(x, y): + return 1.0 if x <= y else 0.0 + + +def geq_func(x, y): + return 1.0 if x >= y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT + + +def initialise_variables(states, rates, constants, computed_constants, algebraic): + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.325 + constants[0] = 1.0 + constants[1] = 0.0 + constants[2] = 0.3 + constants[3] = 120.0 + constants[4] = 36.0 + + +def compute_computed_constants(constants, computed_constants): + computed_constants[0] = constants[1]-10.613 + computed_constants[1] = constants[1]-115.0 + computed_constants[2] = constants[1]+12.0 + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + algebraic[1] = constants[2]*(states[0]-computed_constants[0]) + algebraic[2] = constants[4]*pow(states[2], 4.0)*(states[0]-computed_constants[2]) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[3] = constants[3]*pow(externals[0], 3.0)*states[1]*(states[0]-computed_constants[1]) + rates[0] = -(-algebraic[0]+algebraic[3]+algebraic[2]+algebraic[1])/constants[0] + algebraic[6] = 0.07*exp(states[0]/20.0) + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = algebraic[6]*(1.0-states[1])-algebraic[7]*states[1] + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[9] = 0.125*exp(states[0]/80.0) + rates[2] = algebraic[8]*(1.0-states[2])-algebraic[9]*states[2] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[1] = constants[2]*(states[0]-computed_constants[0]) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[3] = constants[3]*pow(externals[0], 3.0)*states[1]*(states[0]-computed_constants[1]) + algebraic[4] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + algebraic[5] = 4.0*exp(states[0]/18.0) + algebraic[6] = 0.07*exp(states[0]/20.0) + algebraic[7] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + algebraic[2] = constants[4]*pow(states[2], 4.0)*(states[0]-computed_constants[2]) + algebraic[8] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[9] = 0.125*exp(states[0]/80.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.h b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.h deleted file mode 100644 index 525f2c3c3f..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.h +++ /dev/null @@ -1,42 +0,0 @@ -/* The content of this file was generated using the C profile of libCellML 0.6.0. */ - -#pragma once - -#include - -extern const char VERSION[]; -extern const char LIBCELLML_VERSION[]; - -extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; - -typedef struct { - char name[8]; - char units[16]; - char component[25]; - VariableType type; -} VariableInfo; - -extern const VariableInfo VOI_INFO; -extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; - -double * createStatesArray(); -double * createVariablesArray(); -void deleteArray(double *array); - -typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index); - -void initialiseVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); -void computeVariables(double voi, double *states, double *rates, double *variables, ExternalVariable externalVariable); diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.py deleted file mode 100644 index ef66381cca..0000000000 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.state.py +++ /dev/null @@ -1,117 +0,0 @@ -# The content of this file was generated using the Python profile of libCellML 0.6.0. - -from enum import Enum -from math import * - - -__version__ = "0.4.0" -LIBCELLML_VERSION = "0.6.0" - -STATE_COUNT = 3 -VARIABLE_COUNT = 19 - - -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - EXTERNAL = 5 - - -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} - -STATE_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.STATE}, - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} -] - -VARIABLE_INFO = [ - {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane", "type": VariableType.ALGEBRAIC}, - {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_R", "units": "millivolt", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.EXTERNAL}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "E_K", "units": "millivolt", "component": "potassium_channel", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "g_K", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC} -] - - -def leq_func(x, y): - return 1.0 if x <= y else 0.0 - - -def geq_func(x, y): - return 1.0 if x >= y else 0.0 - - -def and_func(x, y): - return 1.0 if bool(x) & bool(y) else 0.0 - - -def create_states_array(): - return [nan]*STATE_COUNT - - -def create_variables_array(): - return [nan]*VARIABLE_COUNT - - -def initialise_variables(voi, states, rates, variables, external_variable): - variables[4] = 1.0 - variables[5] = 0.0 - variables[7] = 0.3 - variables[9] = 120.0 - variables[16] = 36.0 - states[0] = 0.0 - states[1] = 0.6 - states[2] = 0.325 - variables[10] = external_variable(voi, states, rates, variables, 10) - - -def compute_computed_constants(variables): - variables[6] = variables[5]-10.613 - variables[8] = variables[5]-115.0 - variables[15] = variables[5]+12.0 - - -def compute_rates(voi, states, rates, variables, external_variable): - variables[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 - variables[1] = variables[7]*(states[0]-variables[6]) - variables[2] = variables[16]*pow(states[2], 4.0)*(states[0]-variables[15]) - variables[10] = external_variable(voi, states, rates, variables, 10) - variables[3] = variables[9]*pow(variables[10], 3.0)*states[1]*(states[0]-variables[8]) - rates[0] = -(-variables[0]+variables[3]+variables[2]+variables[1])/variables[4] - variables[13] = 0.07*exp(states[0]/20.0) - variables[14] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - rates[1] = variables[13]*(1.0-states[1])-variables[14]*states[1] - variables[17] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[18] = 0.125*exp(states[0]/80.0) - rates[2] = variables[17]*(1.0-states[2])-variables[18]*states[2] - - -def compute_variables(voi, states, rates, variables, external_variable): - variables[1] = variables[7]*(states[0]-variables[6]) - variables[10] = external_variable(voi, states, rates, variables, 10) - variables[3] = variables[9]*pow(variables[10], 3.0)*states[1]*(states[0]-variables[8]) - variables[11] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) - variables[12] = 4.0*exp(states[0]/18.0) - variables[13] = 0.07*exp(states[0]/20.0) - variables[14] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) - variables[2] = variables[16]*pow(states[2], 4.0)*(states[0]-variables[15]) - variables[17] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) - variables[18] = 0.125*exp(states[0]/80.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model_unknown_vars_on_rhs.cellml b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.unknown.vars.on.rhs.cellml similarity index 100% rename from tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model_unknown_vars_on_rhs.cellml rename to tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.unknown.vars.on.rhs.cellml diff --git a/tests/resources/generator/noble_model_1962/model.c b/tests/resources/generator/noble_model_1962/model.c index 6b792560c5..765e28e848 100644 --- a/tests/resources/generator/noble_model_1962/model.c +++ b/tests/resources/generator/noble_model_1962/model.c @@ -5,39 +5,47 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 4; -const size_t VARIABLE_COUNT = 17; +const size_t CONSTANT_COUNT = 5; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 12; -const VariableInfo VOI_INFO = {"time", "millisecond", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { - {"V", "millivolt", "membrane", STATE}, - {"m", "dimensionless", "sodium_channel_m_gate", STATE}, - {"h", "dimensionless", "sodium_channel_h_gate", STATE}, - {"n", "dimensionless", "potassium_channel_n_gate", STATE} + {"V", "millivolt", "membrane"}, + {"m", "dimensionless", "sodium_channel_m_gate"}, + {"h", "dimensionless", "sodium_channel_h_gate"}, + {"n", "dimensionless", "potassium_channel_n_gate"} }; -const VariableInfo VARIABLE_INFO[] = { - {"i_Na", "microA_per_cm2", "sodium_channel", ALGEBRAIC}, - {"i_Leak", "microA_per_cm2", "leakage_current", ALGEBRAIC}, - {"i_K", "microA_per_cm2", "potassium_channel", ALGEBRAIC}, - {"Cm", "microF_per_cm2", "membrane", CONSTANT}, - {"g_L", "milliS_per_cm2", "leakage_current", CONSTANT}, - {"E_L", "millivolt", "leakage_current", CONSTANT}, - {"g_Na", "milliS_per_cm2", "sodium_channel", ALGEBRAIC}, - {"g_Na_max", "milliS_per_cm2", "sodium_channel", CONSTANT}, - {"E_Na", "millivolt", "sodium_channel", CONSTANT}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"beta_m", "per_millisecond", "sodium_channel_m_gate", ALGEBRAIC}, - {"alpha_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"beta_h", "per_millisecond", "sodium_channel_h_gate", ALGEBRAIC}, - {"g_K1", "milliS_per_cm2", "potassium_channel", ALGEBRAIC}, - {"g_K2", "milliS_per_cm2", "potassium_channel", ALGEBRAIC}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC}, - {"beta_n", "per_millisecond", "potassium_channel_n_gate", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"}, + {"g_L", "milliS_per_cm2", "leakage_current"}, + {"E_L", "millivolt", "leakage_current"}, + {"g_Na_max", "milliS_per_cm2", "sodium_channel"}, + {"E_Na", "millivolt", "sodium_channel"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"i_Leak", "microA_per_cm2", "leakage_current"}, + {"i_K", "microA_per_cm2", "potassium_channel"}, + {"g_Na", "milliS_per_cm2", "sodium_channel"}, + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, + {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, + {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"g_K1", "milliS_per_cm2", "potassium_channel"}, + {"g_K2", "milliS_per_cm2", "potassium_channel"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, + {"beta_n", "per_millisecond", "potassium_channel_n_gate"} }; double * createStatesArray() @@ -51,11 +59,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -67,55 +97,55 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[3] = 12.0; - variables[4] = 0.075; - variables[5] = -60.0; - variables[7] = 400.0; - variables[8] = 40.0; states[0] = -87.0; states[1] = 0.01; states[2] = 0.8; states[3] = 0.01; + constants[0] = 12.0; + constants[1] = 0.075; + constants[2] = -60.0; + constants[3] = 400.0; + constants[4] = 40.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[6] = pow(states[1], 3.0)*states[2]*variables[7]; - variables[0] = (variables[6]+0.14)*(states[0]-variables[8]); - variables[1] = variables[4]*(states[0]-variables[5]); - variables[13] = 1.2*exp((-states[0]-90.0)/50.0)+0.015*exp((states[0]+90.0)/60.0); - variables[14] = 1.2*pow(states[3], 4.0); - variables[2] = (variables[13]+variables[14])*(states[0]+100.0); - rates[0] = -(variables[0]+variables[2]+variables[1])/variables[3]; - variables[9] = 0.1*(-states[0]-48.0)/(exp((-states[0]-48.0)/15.0)-1.0); - variables[10] = 0.12*(states[0]+8.0)/(exp((states[0]+8.0)/5.0)-1.0); - rates[1] = variables[9]*(1.0-states[1])-variables[10]*states[1]; - variables[11] = 0.17*exp((-states[0]-90.0)/20.0); - variables[12] = 1.0/(1.0+exp((-states[0]-42.0)/10.0)); - rates[2] = variables[11]*(1.0-states[2])-variables[12]*states[2]; - variables[15] = 0.0001*(-states[0]-50.0)/(exp((-states[0]-50.0)/10.0)-1.0); - variables[16] = 0.002*exp((-states[0]-90.0)/80.0); - rates[3] = variables[15]*(1.0-states[3])-variables[16]*states[3]; + algebraic[3] = pow(states[1], 3.0)*states[2]*constants[3]; + algebraic[0] = (algebraic[3]+0.14)*(states[0]-constants[4]); + algebraic[1] = constants[1]*(states[0]-constants[2]); + algebraic[8] = 1.2*exp((-states[0]-90.0)/50.0)+0.015*exp((states[0]+90.0)/60.0); + algebraic[9] = 1.2*pow(states[3], 4.0); + algebraic[2] = (algebraic[8]+algebraic[9])*(states[0]+100.0); + rates[0] = -(algebraic[0]+algebraic[2]+algebraic[1])/constants[0]; + algebraic[4] = 0.1*(-states[0]-48.0)/(exp((-states[0]-48.0)/15.0)-1.0); + algebraic[5] = 0.12*(states[0]+8.0)/(exp((states[0]+8.0)/5.0)-1.0); + rates[1] = algebraic[4]*(1.0-states[1])-algebraic[5]*states[1]; + algebraic[6] = 0.17*exp((-states[0]-90.0)/20.0); + algebraic[7] = 1.0/(1.0+exp((-states[0]-42.0)/10.0)); + rates[2] = algebraic[6]*(1.0-states[2])-algebraic[7]*states[2]; + algebraic[10] = 0.0001*(-states[0]-50.0)/(exp((-states[0]-50.0)/10.0)-1.0); + algebraic[11] = 0.002*exp((-states[0]-90.0)/80.0); + rates[3] = algebraic[10]*(1.0-states[3])-algebraic[11]*states[3]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[1] = variables[4]*(states[0]-variables[5]); - variables[6] = pow(states[1], 3.0)*states[2]*variables[7]; - variables[0] = (variables[6]+0.14)*(states[0]-variables[8]); - variables[9] = 0.1*(-states[0]-48.0)/(exp((-states[0]-48.0)/15.0)-1.0); - variables[10] = 0.12*(states[0]+8.0)/(exp((states[0]+8.0)/5.0)-1.0); - variables[11] = 0.17*exp((-states[0]-90.0)/20.0); - variables[12] = 1.0/(1.0+exp((-states[0]-42.0)/10.0)); - variables[13] = 1.2*exp((-states[0]-90.0)/50.0)+0.015*exp((states[0]+90.0)/60.0); - variables[14] = 1.2*pow(states[3], 4.0); - variables[2] = (variables[13]+variables[14])*(states[0]+100.0); - variables[15] = 0.0001*(-states[0]-50.0)/(exp((-states[0]-50.0)/10.0)-1.0); - variables[16] = 0.002*exp((-states[0]-90.0)/80.0); + algebraic[1] = constants[1]*(states[0]-constants[2]); + algebraic[3] = pow(states[1], 3.0)*states[2]*constants[3]; + algebraic[0] = (algebraic[3]+0.14)*(states[0]-constants[4]); + algebraic[4] = 0.1*(-states[0]-48.0)/(exp((-states[0]-48.0)/15.0)-1.0); + algebraic[5] = 0.12*(states[0]+8.0)/(exp((states[0]+8.0)/5.0)-1.0); + algebraic[6] = 0.17*exp((-states[0]-90.0)/20.0); + algebraic[7] = 1.0/(1.0+exp((-states[0]-42.0)/10.0)); + algebraic[8] = 1.2*exp((-states[0]-90.0)/50.0)+0.015*exp((states[0]+90.0)/60.0); + algebraic[9] = 1.2*pow(states[3], 4.0); + algebraic[2] = (algebraic[8]+algebraic[9])*(states[0]+100.0); + algebraic[10] = 0.0001*(-states[0]-50.0)/(exp((-states[0]-50.0)/10.0)-1.0); + algebraic[11] = 0.002*exp((-states[0]-90.0)/80.0); } diff --git a/tests/resources/generator/noble_model_1962/model.h b/tests/resources/generator/noble_model_1962/model.h index 4b13ed1e79..9b357382c4 100644 --- a/tests/resources/generator/noble_model_1962/model.h +++ b/tests/resources/generator/noble_model_1962/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[9]; char units[16]; char component[25]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/noble_model_1962/model.py b/tests/resources/generator/noble_model_1962/model.py index ef5da0bc05..c2399e7bb8 100644 --- a/tests/resources/generator/noble_model_1962/model.py +++ b/tests/resources/generator/noble_model_1962/model.py @@ -4,48 +4,47 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 4 -VARIABLE_COUNT = 17 +CONSTANT_COUNT = 5 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 12 +VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, + {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, + {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, + {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} +] -VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"}, + {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "g_Na_max", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"} +] -STATE_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane", "type": VariableType.STATE}, - {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate", "type": VariableType.STATE}, - {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate", "type": VariableType.STATE}, - {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "i_Leak", "units": "microA_per_cm2", "component": "leakage_current", "type": VariableType.ALGEBRAIC}, - {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "Cm", "units": "microF_per_cm2", "component": "membrane", "type": VariableType.CONSTANT}, - {"name": "g_L", "units": "milliS_per_cm2", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "E_L", "units": "millivolt", "component": "leakage_current", "type": VariableType.CONSTANT}, - {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "g_Na_max", "units": "milliS_per_cm2", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel", "type": VariableType.CONSTANT}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate", "type": VariableType.ALGEBRAIC}, - {"name": "g_K1", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "g_K2", "units": "milliS_per_cm2", "component": "potassium_channel", "type": VariableType.ALGEBRAIC}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC}, - {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "i_Leak", "units": "microA_per_cm2", "component": "leakage_current"}, + {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "g_Na", "units": "milliS_per_cm2", "component": "sodium_channel"}, + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "g_K1", "units": "milliS_per_cm2", "component": "potassium_channel"}, + {"name": "g_K2", "units": "milliS_per_cm2", "component": "potassium_channel"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, + {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} ] @@ -53,55 +52,63 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[3] = 12.0 - variables[4] = 0.075 - variables[5] = -60.0 - variables[7] = 400.0 - variables[8] = 40.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = -87.0 states[1] = 0.01 states[2] = 0.8 states[3] = 0.01 + constants[0] = 12.0 + constants[1] = 0.075 + constants[2] = -60.0 + constants[3] = 400.0 + constants[4] = 40.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - variables[6] = pow(states[1], 3.0)*states[2]*variables[7] - variables[0] = (variables[6]+0.14)*(states[0]-variables[8]) - variables[1] = variables[4]*(states[0]-variables[5]) - variables[13] = 1.2*exp((-states[0]-90.0)/50.0)+0.015*exp((states[0]+90.0)/60.0) - variables[14] = 1.2*pow(states[3], 4.0) - variables[2] = (variables[13]+variables[14])*(states[0]+100.0) - rates[0] = -(variables[0]+variables[2]+variables[1])/variables[3] - variables[9] = 0.1*(-states[0]-48.0)/(exp((-states[0]-48.0)/15.0)-1.0) - variables[10] = 0.12*(states[0]+8.0)/(exp((states[0]+8.0)/5.0)-1.0) - rates[1] = variables[9]*(1.0-states[1])-variables[10]*states[1] - variables[11] = 0.17*exp((-states[0]-90.0)/20.0) - variables[12] = 1.0/(1.0+exp((-states[0]-42.0)/10.0)) - rates[2] = variables[11]*(1.0-states[2])-variables[12]*states[2] - variables[15] = 0.0001*(-states[0]-50.0)/(exp((-states[0]-50.0)/10.0)-1.0) - variables[16] = 0.002*exp((-states[0]-90.0)/80.0) - rates[3] = variables[15]*(1.0-states[3])-variables[16]*states[3] - - -def compute_variables(voi, states, rates, variables): - variables[1] = variables[4]*(states[0]-variables[5]) - variables[6] = pow(states[1], 3.0)*states[2]*variables[7] - variables[0] = (variables[6]+0.14)*(states[0]-variables[8]) - variables[9] = 0.1*(-states[0]-48.0)/(exp((-states[0]-48.0)/15.0)-1.0) - variables[10] = 0.12*(states[0]+8.0)/(exp((states[0]+8.0)/5.0)-1.0) - variables[11] = 0.17*exp((-states[0]-90.0)/20.0) - variables[12] = 1.0/(1.0+exp((-states[0]-42.0)/10.0)) - variables[13] = 1.2*exp((-states[0]-90.0)/50.0)+0.015*exp((states[0]+90.0)/60.0) - variables[14] = 1.2*pow(states[3], 4.0) - variables[2] = (variables[13]+variables[14])*(states[0]+100.0) - variables[15] = 0.0001*(-states[0]-50.0)/(exp((-states[0]-50.0)/10.0)-1.0) - variables[16] = 0.002*exp((-states[0]-90.0)/80.0) +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + algebraic[3] = pow(states[1], 3.0)*states[2]*constants[3] + algebraic[0] = (algebraic[3]+0.14)*(states[0]-constants[4]) + algebraic[1] = constants[1]*(states[0]-constants[2]) + algebraic[8] = 1.2*exp((-states[0]-90.0)/50.0)+0.015*exp((states[0]+90.0)/60.0) + algebraic[9] = 1.2*pow(states[3], 4.0) + algebraic[2] = (algebraic[8]+algebraic[9])*(states[0]+100.0) + rates[0] = -(algebraic[0]+algebraic[2]+algebraic[1])/constants[0] + algebraic[4] = 0.1*(-states[0]-48.0)/(exp((-states[0]-48.0)/15.0)-1.0) + algebraic[5] = 0.12*(states[0]+8.0)/(exp((states[0]+8.0)/5.0)-1.0) + rates[1] = algebraic[4]*(1.0-states[1])-algebraic[5]*states[1] + algebraic[6] = 0.17*exp((-states[0]-90.0)/20.0) + algebraic[7] = 1.0/(1.0+exp((-states[0]-42.0)/10.0)) + rates[2] = algebraic[6]*(1.0-states[2])-algebraic[7]*states[2] + algebraic[10] = 0.0001*(-states[0]-50.0)/(exp((-states[0]-50.0)/10.0)-1.0) + algebraic[11] = 0.002*exp((-states[0]-90.0)/80.0) + rates[3] = algebraic[10]*(1.0-states[3])-algebraic[11]*states[3] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[1] = constants[1]*(states[0]-constants[2]) + algebraic[3] = pow(states[1], 3.0)*states[2]*constants[3] + algebraic[0] = (algebraic[3]+0.14)*(states[0]-constants[4]) + algebraic[4] = 0.1*(-states[0]-48.0)/(exp((-states[0]-48.0)/15.0)-1.0) + algebraic[5] = 0.12*(states[0]+8.0)/(exp((states[0]+8.0)/5.0)-1.0) + algebraic[6] = 0.17*exp((-states[0]-90.0)/20.0) + algebraic[7] = 1.0/(1.0+exp((-states[0]-42.0)/10.0)) + algebraic[8] = 1.2*exp((-states[0]-90.0)/50.0)+0.015*exp((states[0]+90.0)/60.0) + algebraic[9] = 1.2*pow(states[3], 4.0) + algebraic[2] = (algebraic[8]+algebraic[9])*(states[0]+100.0) + algebraic[10] = 0.0001*(-states[0]-50.0)/(exp((-states[0]-50.0)/10.0)-1.0) + algebraic[11] = 0.002*exp((-states[0]-90.0)/80.0) diff --git a/tests/resources/generator/ode_computed_var_on_rhs/model.c b/tests/resources/generator/ode_computed_var_on_rhs/model.c index 7b1376fb2c..a762f51a40 100644 --- a/tests/resources/generator/ode_computed_var_on_rhs/model.c +++ b/tests/resources/generator/ode_computed_var_on_rhs/model.c @@ -5,20 +5,28 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 1; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "environment"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_ode", STATE} + {"x", "dimensionless", "my_ode"} }; -const VariableInfo VARIABLE_INFO[] = { - {"a", "per_s", "my_ode", COMPUTED_CONSTANT} +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"a", "per_s", "my_ode"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -32,11 +40,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -48,21 +78,21 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; states[0] = 1.0; + computedConstants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - rates[0] = variables[0]; + rates[0] = computedConstants[0]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/ode_computed_var_on_rhs/model.h b/tests/resources/generator/ode_computed_var_on_rhs/model.h index 9303e63ae3..433b3e7910 100644 --- a/tests/resources/generator/ode_computed_var_on_rhs/model.h +++ b/tests/resources/generator/ode_computed_var_on_rhs/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/ode_computed_var_on_rhs/model.py b/tests/resources/generator/ode_computed_var_on_rhs/model.py index 1bd57dc917..c496aec0a9 100644 --- a/tests/resources/generator/ode_computed_var_on_rhs/model.py +++ b/tests/resources/generator/ode_computed_var_on_rhs/model.py @@ -4,29 +4,28 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 1 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_ode"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_ode", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ + {"name": "a", "units": "per_s", "component": "my_ode"} ] -VARIABLE_INFO = [ - {"name": "a", "units": "per_s", "component": "my_ode", "type": VariableType.COMPUTED_CONSTANT} +ALGEBRAIC_INFO = [ ] @@ -34,22 +33,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 1.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 + computed_constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - rates[0] = variables[0] +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + rates[0] = computed_constants[0] -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.c b/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.c index d2ad4c72d1..1627952022 100644 --- a/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.c +++ b/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.c @@ -5,20 +5,28 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 1; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "my_component", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "my_component"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_component", STATE} + {"x", "dimensionless", "my_component"} }; -const VariableInfo VARIABLE_INFO[] = { - {"a", "per_s", "my_component", COMPUTED_CONSTANT} +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"a", "per_s", "my_component"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -32,11 +40,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -48,21 +78,21 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; states[0] = 1.0; + computedConstants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - rates[0] = variables[0]; + rates[0] = computedConstants[0]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.h b/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.h index f1e1489ff9..d7cc1bd25d 100644 --- a/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.h +++ b/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[13]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.py b/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.py index afaa321a42..49c5bf63ed 100644 --- a/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.py +++ b/tests/resources/generator/ode_computed_var_on_rhs_one_component/model.py @@ -4,29 +4,28 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 1 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "my_component"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_component"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "my_component", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_component", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ + {"name": "a", "units": "per_s", "component": "my_component"} ] -VARIABLE_INFO = [ - {"name": "a", "units": "per_s", "component": "my_component", "type": VariableType.COMPUTED_CONSTANT} +ALGEBRAIC_INFO = [ ] @@ -34,22 +33,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 1.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 + computed_constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - rates[0] = variables[0] +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + rates[0] = computed_constants[0] -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/ode_const_var_on_rhs/model.c b/tests/resources/generator/ode_const_var_on_rhs/model.c index 287c9cdeb8..d557fe504c 100644 --- a/tests/resources/generator/ode_const_var_on_rhs/model.c +++ b/tests/resources/generator/ode_const_var_on_rhs/model.c @@ -5,20 +5,28 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 1; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "environment"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_ode", STATE} + {"x", "dimensionless", "my_ode"} }; -const VariableInfo VARIABLE_INFO[] = { - {"a", "per_s", "my_ode", CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"a", "per_s", "my_ode"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -32,11 +40,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -48,21 +78,21 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; states[0] = 1.0; + constants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - rates[0] = variables[0]; + rates[0] = constants[0]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/ode_const_var_on_rhs/model.h b/tests/resources/generator/ode_const_var_on_rhs/model.h index 9303e63ae3..433b3e7910 100644 --- a/tests/resources/generator/ode_const_var_on_rhs/model.h +++ b/tests/resources/generator/ode_const_var_on_rhs/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/ode_const_var_on_rhs/model.py b/tests/resources/generator/ode_const_var_on_rhs/model.py index 23f8104b7d..3f7dad296d 100644 --- a/tests/resources/generator/ode_const_var_on_rhs/model.py +++ b/tests/resources/generator/ode_const_var_on_rhs/model.py @@ -4,29 +4,28 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 1 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_ode"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "a", "units": "per_s", "component": "my_ode"} +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_ode", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "a", "units": "per_s", "component": "my_ode", "type": VariableType.CONSTANT} +ALGEBRAIC_INFO = [ ] @@ -34,22 +33,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 1.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 + constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - rates[0] = variables[0] +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + rates[0] = constants[0] -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/ode_const_var_on_rhs_one_component/model.c b/tests/resources/generator/ode_const_var_on_rhs_one_component/model.c index a8ed6c8612..045bd2fe13 100644 --- a/tests/resources/generator/ode_const_var_on_rhs_one_component/model.c +++ b/tests/resources/generator/ode_const_var_on_rhs_one_component/model.c @@ -5,20 +5,28 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 1; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "my_component", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "my_component"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_component", STATE} + {"x", "dimensionless", "my_component"} }; -const VariableInfo VARIABLE_INFO[] = { - {"a", "per_s", "my_component", CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"a", "per_s", "my_component"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -32,11 +40,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -48,21 +78,21 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; states[0] = 1.0; + constants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - rates[0] = variables[0]; + rates[0] = constants[0]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/ode_const_var_on_rhs_one_component/model.h b/tests/resources/generator/ode_const_var_on_rhs_one_component/model.h index f1e1489ff9..d7cc1bd25d 100644 --- a/tests/resources/generator/ode_const_var_on_rhs_one_component/model.h +++ b/tests/resources/generator/ode_const_var_on_rhs_one_component/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[13]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/ode_const_var_on_rhs_one_component/model.py b/tests/resources/generator/ode_const_var_on_rhs_one_component/model.py index bf36d8955d..030cf39a1c 100644 --- a/tests/resources/generator/ode_const_var_on_rhs_one_component/model.py +++ b/tests/resources/generator/ode_const_var_on_rhs_one_component/model.py @@ -4,29 +4,28 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 1 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "my_component"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_component"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "my_component", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "a", "units": "per_s", "component": "my_component"} +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_component", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "a", "units": "per_s", "component": "my_component", "type": VariableType.CONSTANT} +ALGEBRAIC_INFO = [ ] @@ -34,22 +33,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 1.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 + constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - rates[0] = variables[0] +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + rates[0] = constants[0] -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/ode_constant_on_rhs/model.c b/tests/resources/generator/ode_constant_on_rhs/model.c index f48ec3fe3e..86c2e5c732 100644 --- a/tests/resources/generator/ode_constant_on_rhs/model.c +++ b/tests/resources/generator/ode_constant_on_rhs/model.c @@ -5,19 +5,27 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 0; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "environment"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_ode", STATE} + {"x", "dimensionless", "my_ode"} }; -const VariableInfo VARIABLE_INFO[] = { +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -31,11 +39,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -47,20 +77,20 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { states[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 1.0; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/ode_constant_on_rhs/model.h b/tests/resources/generator/ode_constant_on_rhs/model.h index 9303e63ae3..433b3e7910 100644 --- a/tests/resources/generator/ode_constant_on_rhs/model.h +++ b/tests/resources/generator/ode_constant_on_rhs/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/ode_constant_on_rhs/model.py b/tests/resources/generator/ode_constant_on_rhs/model.py index 60f1fa984b..b7f35ed5f1 100644 --- a/tests/resources/generator/ode_constant_on_rhs/model.py +++ b/tests/resources/generator/ode_constant_on_rhs/model.py @@ -4,28 +4,27 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 0 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_ode"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_ode", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ +ALGEBRAIC_INFO = [ ] @@ -33,21 +32,29 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 1.0 -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/ode_constant_on_rhs_one_component/model.c b/tests/resources/generator/ode_constant_on_rhs_one_component/model.c index c32855ef56..09fac8994d 100644 --- a/tests/resources/generator/ode_constant_on_rhs_one_component/model.c +++ b/tests/resources/generator/ode_constant_on_rhs_one_component/model.c @@ -5,19 +5,27 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 0; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "my_component", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "my_component"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_component", STATE} + {"x", "dimensionless", "my_component"} }; -const VariableInfo VARIABLE_INFO[] = { +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -31,11 +39,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -47,20 +77,20 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { states[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 1.0; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/ode_constant_on_rhs_one_component/model.h b/tests/resources/generator/ode_constant_on_rhs_one_component/model.h index f1e1489ff9..d7cc1bd25d 100644 --- a/tests/resources/generator/ode_constant_on_rhs_one_component/model.h +++ b/tests/resources/generator/ode_constant_on_rhs_one_component/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[13]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/ode_constant_on_rhs_one_component/model.py b/tests/resources/generator/ode_constant_on_rhs_one_component/model.py index 73500c1d1b..3ed87da382 100644 --- a/tests/resources/generator/ode_constant_on_rhs_one_component/model.py +++ b/tests/resources/generator/ode_constant_on_rhs_one_component/model.py @@ -4,28 +4,27 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 0 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "my_component"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_component"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "my_component", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_component", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ +ALGEBRAIC_INFO = [ ] @@ -33,21 +32,29 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 1.0 -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/ode_multiple_dependent_odes/model.c b/tests/resources/generator/ode_multiple_dependent_odes/model.c index 12adccd98d..75154a5783 100644 --- a/tests/resources/generator/ode_multiple_dependent_odes/model.c +++ b/tests/resources/generator/ode_multiple_dependent_odes/model.c @@ -5,21 +5,29 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 2; -const size_t VARIABLE_COUNT = 1; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "environment"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_x_ode", STATE}, - {"y", "dimensionless", "my_y_ode", STATE} + {"x", "dimensionless", "my_x_ode"}, + {"y", "dimensionless", "my_y_ode"} }; -const VariableInfo VARIABLE_INFO[] = { - {"epsilon", "dimensionless", "my_y_ode", CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"epsilon", "dimensionless", "my_y_ode"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -33,11 +41,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -49,23 +79,23 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; states[0] = -2.0; states[1] = 0.0; + constants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = states[1]*1.0; - rates[1] = (variables[0]*(1.0-pow(states[0], 2.0))*states[1]-states[0])*1.0; + rates[1] = (constants[0]*(1.0-pow(states[0], 2.0))*states[1]-states[0])*1.0; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/ode_multiple_dependent_odes/model.h b/tests/resources/generator/ode_multiple_dependent_odes/model.h index 5c96160229..dbf4e827d5 100644 --- a/tests/resources/generator/ode_multiple_dependent_odes/model.h +++ b/tests/resources/generator/ode_multiple_dependent_odes/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[8]; char units[14]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/ode_multiple_dependent_odes/model.py b/tests/resources/generator/ode_multiple_dependent_odes/model.py index 4dd2b1c245..19902c6a2c 100644 --- a/tests/resources/generator/ode_multiple_dependent_odes/model.py +++ b/tests/resources/generator/ode_multiple_dependent_odes/model.py @@ -4,30 +4,29 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 2 -VARIABLE_COUNT = 1 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_x_ode"}, + {"name": "y", "units": "dimensionless", "component": "my_y_ode"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "epsilon", "units": "dimensionless", "component": "my_y_ode"} +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_x_ode", "type": VariableType.STATE}, - {"name": "y", "units": "dimensionless", "component": "my_y_ode", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "epsilon", "units": "dimensionless", "component": "my_y_ode", "type": VariableType.CONSTANT} +ALGEBRAIC_INFO = [ ] @@ -35,24 +34,32 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 1.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = -2.0 states[1] = 0.0 + constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = states[1]*1.0 - rates[1] = (variables[0]*(1.0-pow(states[0], 2.0))*states[1]-states[0])*1.0 + rates[1] = (constants[0]*(1.0-pow(states[0], 2.0))*states[1]-states[0])*1.0 -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.c b/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.c index 2cd822deb2..a5273d217b 100644 --- a/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.c +++ b/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.c @@ -5,21 +5,29 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 2; -const size_t VARIABLE_COUNT = 1; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "my_component", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "my_component"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_component", STATE}, - {"y", "dimensionless", "my_component", STATE} + {"x", "dimensionless", "my_component"}, + {"y", "dimensionless", "my_component"} }; -const VariableInfo VARIABLE_INFO[] = { - {"epsilon", "dimensionless", "my_component", CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"epsilon", "dimensionless", "my_component"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -33,11 +41,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -49,23 +79,23 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; states[0] = -2.0; states[1] = 0.0; + constants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = states[1]*1.0; - rates[1] = (variables[0]*(1.0-pow(states[0], 2.0))*states[1]-states[0])*1.0; + rates[1] = (constants[0]*(1.0-pow(states[0], 2.0))*states[1]-states[0])*1.0; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.h b/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.h index 8bf456229c..7355bad967 100644 --- a/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.h +++ b/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[8]; char units[14]; char component[13]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.py b/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.py index db7ce3132f..80b63b125f 100644 --- a/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.py +++ b/tests/resources/generator/ode_multiple_dependent_odes_one_component/model.py @@ -4,30 +4,29 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 2 -VARIABLE_COUNT = 1 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "my_component"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_component"}, + {"name": "y", "units": "dimensionless", "component": "my_component"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "my_component", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "epsilon", "units": "dimensionless", "component": "my_component"} +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_component", "type": VariableType.STATE}, - {"name": "y", "units": "dimensionless", "component": "my_component", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "epsilon", "units": "dimensionless", "component": "my_component", "type": VariableType.CONSTANT} +ALGEBRAIC_INFO = [ ] @@ -35,24 +34,32 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 1.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = -2.0 states[1] = 0.0 + constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = states[1]*1.0 - rates[1] = (variables[0]*(1.0-pow(states[0], 2.0))*states[1]-states[0])*1.0 + rates[1] = (constants[0]*(1.0-pow(states[0], 2.0))*states[1]-states[0])*1.0 -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/ode_multiple_odes_with_same_name/model.c b/tests/resources/generator/ode_multiple_odes_with_same_name/model.c index 89b2f0269f..584a1bee6f 100644 --- a/tests/resources/generator/ode_multiple_odes_with_same_name/model.c +++ b/tests/resources/generator/ode_multiple_odes_with_same_name/model.c @@ -5,21 +5,29 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 2; -const size_t VARIABLE_COUNT = 1; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "environment"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_first_ode", STATE}, - {"x", "dimensionless", "my_second_ode", STATE} + {"x", "dimensionless", "my_first_ode"}, + {"x", "dimensionless", "my_second_ode"} }; -const VariableInfo VARIABLE_INFO[] = { - {"a", "per_s", "my_second_ode", CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"a", "per_s", "my_second_ode"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -33,11 +41,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -49,23 +79,23 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 1.0; states[0] = 1.0; states[1] = 1.0; + constants[0] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 1.0; - rates[1] = variables[0]; + rates[1] = constants[0]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/ode_multiple_odes_with_same_name/model.h b/tests/resources/generator/ode_multiple_odes_with_same_name/model.h index 5d4ca0716d..bc2c3012a9 100644 --- a/tests/resources/generator/ode_multiple_odes_with_same_name/model.h +++ b/tests/resources/generator/ode_multiple_odes_with_same_name/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[14]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/ode_multiple_odes_with_same_name/model.py b/tests/resources/generator/ode_multiple_odes_with_same_name/model.py index 6deb5b65f3..077f5046ef 100644 --- a/tests/resources/generator/ode_multiple_odes_with_same_name/model.py +++ b/tests/resources/generator/ode_multiple_odes_with_same_name/model.py @@ -4,30 +4,29 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 2 -VARIABLE_COUNT = 1 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_first_ode"}, + {"name": "x", "units": "dimensionless", "component": "my_second_ode"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "a", "units": "per_s", "component": "my_second_ode"} +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_first_ode", "type": VariableType.STATE}, - {"name": "x", "units": "dimensionless", "component": "my_second_ode", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "a", "units": "per_s", "component": "my_second_ode", "type": VariableType.CONSTANT} +ALGEBRAIC_INFO = [ ] @@ -35,24 +34,32 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 1.0 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 states[1] = 1.0 + constants[0] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 1.0 - rates[1] = variables[0] + rates[1] = constants[0] -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/ode_unknown_var_on_rhs/model.c b/tests/resources/generator/ode_unknown_var_on_rhs/model.c index e58fa77bf0..5525bdb321 100644 --- a/tests/resources/generator/ode_unknown_var_on_rhs/model.c +++ b/tests/resources/generator/ode_unknown_var_on_rhs/model.c @@ -5,20 +5,28 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 2; -const size_t VARIABLE_COUNT = 0; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "environment", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "environment"}; const VariableInfo STATE_INFO[] = { - {"x", "dimensionless", "my_ode", STATE}, - {"y", "dimensionless", "my_ode", STATE} + {"x", "dimensionless", "my_ode"}, + {"y", "dimensionless", "my_ode"} }; -const VariableInfo VARIABLE_INFO[] = { +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -32,11 +40,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -48,22 +78,22 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { states[0] = 1.0; states[1] = 1.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 1.0; rates[1] = states[0]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/ode_unknown_var_on_rhs/model.h b/tests/resources/generator/ode_unknown_var_on_rhs/model.h index 9303e63ae3..433b3e7910 100644 --- a/tests/resources/generator/ode_unknown_var_on_rhs/model.h +++ b/tests/resources/generator/ode_unknown_var_on_rhs/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[2]; char units[14]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/ode_unknown_var_on_rhs/model.py b/tests/resources/generator/ode_unknown_var_on_rhs/model.py index d9bd7aa2be..e00affc475 100644 --- a/tests/resources/generator/ode_unknown_var_on_rhs/model.py +++ b/tests/resources/generator/ode_unknown_var_on_rhs/model.py @@ -4,29 +4,28 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 2 -VARIABLE_COUNT = 0 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "environment"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "my_ode"}, + {"name": "y", "units": "dimensionless", "component": "my_ode"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "environment", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ +] -STATE_INFO = [ - {"name": "x", "units": "dimensionless", "component": "my_ode", "type": VariableType.STATE}, - {"name": "y", "units": "dimensionless", "component": "my_ode", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ +ALGEBRAIC_INFO = [ ] @@ -34,23 +33,31 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 states[1] = 1.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 1.0 rates[1] = states[0] -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/resources/generator/robertson_model_1966/model.dae.c b/tests/resources/generator/robertson_model_1966/model.dae.c index e2915de939..96a4a0e8b9 100644 --- a/tests/resources/generator/robertson_model_1966/model.dae.c +++ b/tests/resources/generator/robertson_model_1966/model.dae.c @@ -5,25 +5,33 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 2; -const size_t VARIABLE_COUNT = 5; +const size_t CONSTANT_COUNT = 3; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 2; -const VariableInfo VOI_INFO = {"t", "dimensionless", "main", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "dimensionless", "main"}; const VariableInfo STATE_INFO[] = { - {"y1", "dimensionless", "main", STATE}, - {"y2", "dimensionless", "main", STATE} + {"y1", "dimensionless", "main"}, + {"y2", "dimensionless", "main"} }; -const VariableInfo VARIABLE_INFO[] = { - {"k1", "dimensionless", "main", CONSTANT}, - {"k3", "dimensionless", "main", CONSTANT}, - {"y3", "dimensionless", "main", ALGEBRAIC}, - {"k2", "dimensionless", "main", CONSTANT}, - {"y2_scaled", "dimensionless", "main", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { + {"k1", "dimensionless", "main"}, + {"k3", "dimensionless", "main"}, + {"k2", "dimensionless", "main"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"y3", "dimensionless", "main"}, + {"y2_scaled", "dimensionless", "main"} }; double * createStatesArray() @@ -37,11 +45,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -57,7 +87,9 @@ typedef struct { double voi; double *states; double *rates; - double *variables; + double *constants; + double *computedConstants; + double *algebraic; } RootFindingInfo; extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), @@ -68,48 +100,50 @@ void objectiveFunction0(double *u, double *f, void *data) double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; double *rates = ((RootFindingInfo *) data)->rates; - double *variables = ((RootFindingInfo *) data)->variables; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; - variables[2] = u[0]; + algebraic[0] = u[0]; - f[0] = 1.0-(states[0]+states[1]+variables[2]); + f[0] = 1.0-(states[0]+states[1]+algebraic[0]); } -void findRoot0(double voi, double *states, double *rates, double *variables) +void findRoot0(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - RootFindingInfo rfi = { voi, states, rates, variables }; + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = variables[2]; + u[0] = algebraic[0]; nlaSolve(objectiveFunction0, u, 1, &rfi); - variables[2] = u[0]; + algebraic[0] = u[0]; } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 0.04; - variables[1] = 1.0e4; - variables[2] = 0.0; - variables[3] = 3.0e7; states[0] = 1.0; states[1] = 0.0; + constants[0] = 0.04; + constants[1] = 1.0e4; + constants[2] = 3.0e7; + algebraic[0] = 0.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - findRoot0(voi, states, rates, variables); - rates[0] = -variables[0]*states[0]+variables[1]*states[1]*variables[2]; - rates[1] = variables[0]*states[0]-variables[3]*pow(states[1], 2.0)-variables[1]*states[1]*variables[2]; + findRoot0(voi, states, rates, constants, computedConstants, algebraic); + rates[0] = -constants[0]*states[0]+constants[1]*states[1]*algebraic[0]; + rates[1] = constants[0]*states[0]-constants[2]*pow(states[1], 2.0)-constants[1]*states[1]*algebraic[0]; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - findRoot0(voi, states, rates, variables); - variables[4] = 10000.0*states[1]; + findRoot0(voi, states, rates, constants, computedConstants, algebraic); + algebraic[1] = 10000.0*states[1]; } diff --git a/tests/resources/generator/robertson_model_1966/model.dae.h b/tests/resources/generator/robertson_model_1966/model.dae.h index ccc12feaa7..c91d4d893e 100644 --- a/tests/resources/generator/robertson_model_1966/model.dae.h +++ b/tests/resources/generator/robertson_model_1966/model.dae.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[10]; char units[14]; char component[5]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/robertson_model_1966/model.dae.py b/tests/resources/generator/robertson_model_1966/model.dae.py index 8da11629b1..5b691f8f28 100644 --- a/tests/resources/generator/robertson_model_1966/model.dae.py +++ b/tests/resources/generator/robertson_model_1966/model.dae.py @@ -4,34 +4,33 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 2 -VARIABLE_COUNT = 5 +CONSTANT_COUNT = 3 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 2 +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "main"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "y1", "units": "dimensionless", "component": "main"}, + {"name": "y2", "units": "dimensionless", "component": "main"} +] -VOI_INFO = {"name": "t", "units": "dimensionless", "component": "main", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "k1", "units": "dimensionless", "component": "main"}, + {"name": "k3", "units": "dimensionless", "component": "main"}, + {"name": "k2", "units": "dimensionless", "component": "main"} +] -STATE_INFO = [ - {"name": "y1", "units": "dimensionless", "component": "main", "type": VariableType.STATE}, - {"name": "y2", "units": "dimensionless", "component": "main", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "k1", "units": "dimensionless", "component": "main", "type": VariableType.CONSTANT}, - {"name": "k3", "units": "dimensionless", "component": "main", "type": VariableType.CONSTANT}, - {"name": "y3", "units": "dimensionless", "component": "main", "type": VariableType.ALGEBRAIC}, - {"name": "k2", "units": "dimensionless", "component": "main", "type": VariableType.CONSTANT}, - {"name": "y2_scaled", "units": "dimensionless", "component": "main", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "y3", "units": "dimensionless", "component": "main"}, + {"name": "y2_scaled", "units": "dimensionless", "component": "main"} ] @@ -39,8 +38,16 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT from nlasolver import nla_solve @@ -50,42 +57,44 @@ def objective_function_0(u, f, data): voi = data[0] states = data[1] rates = data[2] - variables = data[3] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] - variables[2] = u[0] + algebraic[0] = u[0] - f[0] = 1.0-(states[0]+states[1]+variables[2]) + f[0] = 1.0-(states[0]+states[1]+algebraic[0]) -def find_root_0(voi, states, rates, variables): +def find_root_0(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = variables[2] + u[0] = algebraic[0] - u = nla_solve(objective_function_0, u, 1, [voi, states, rates, variables]) + u = nla_solve(objective_function_0, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - variables[2] = u[0] + algebraic[0] = u[0] -def initialise_variables(states, rates, variables): - variables[0] = 0.04 - variables[1] = 1.0e4 - variables[2] = 0.0 - variables[3] = 3.0e7 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 states[1] = 0.0 + constants[0] = 0.04 + constants[1] = 1.0e4 + constants[2] = 3.0e7 + algebraic[0] = 0.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - find_root_0(voi, states, rates, variables) - rates[0] = -variables[0]*states[0]+variables[1]*states[1]*variables[2] - rates[1] = variables[0]*states[0]-variables[3]*pow(states[1], 2.0)-variables[1]*states[1]*variables[2] +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + find_root_0(voi, states, rates, constants, computed_constants, algebraic) + rates[0] = -constants[0]*states[0]+constants[1]*states[1]*algebraic[0] + rates[1] = constants[0]*states[0]-constants[2]*pow(states[1], 2.0)-constants[1]*states[1]*algebraic[0] -def compute_variables(voi, states, rates, variables): - find_root_0(voi, states, rates, variables) - variables[4] = 10000.0*states[1] +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + find_root_0(voi, states, rates, constants, computed_constants, algebraic) + algebraic[1] = 10000.0*states[1] diff --git a/tests/resources/generator/robertson_model_1966/model.ode.c b/tests/resources/generator/robertson_model_1966/model.ode.c index d7f5a3811f..e89cd157a8 100644 --- a/tests/resources/generator/robertson_model_1966/model.ode.c +++ b/tests/resources/generator/robertson_model_1966/model.ode.c @@ -5,25 +5,33 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 3; -const size_t VARIABLE_COUNT = 4; +const size_t CONSTANT_COUNT = 3; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 1; -const VariableInfo VOI_INFO = {"t", "dimensionless", "main", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "dimensionless", "main"}; const VariableInfo STATE_INFO[] = { - {"y1", "dimensionless", "main", STATE}, - {"y3", "dimensionless", "main", STATE}, - {"y2", "dimensionless", "main", STATE} + {"y1", "dimensionless", "main"}, + {"y3", "dimensionless", "main"}, + {"y2", "dimensionless", "main"} }; -const VariableInfo VARIABLE_INFO[] = { - {"k1", "dimensionless", "main", CONSTANT}, - {"k3", "dimensionless", "main", CONSTANT}, - {"k2", "dimensionless", "main", CONSTANT}, - {"y2_scaled", "dimensionless", "main", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { + {"k1", "dimensionless", "main"}, + {"k3", "dimensionless", "main"}, + {"k2", "dimensionless", "main"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"y2_scaled", "dimensionless", "main"} }; double * createStatesArray() @@ -37,11 +45,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -53,28 +83,28 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 0.04; - variables[1] = 1.0e4; - variables[2] = 3.0e7; states[0] = 1.0; states[1] = 0.0; states[2] = 0.0; + constants[0] = 0.04; + constants[1] = 1.0e4; + constants[2] = 3.0e7; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - rates[0] = -variables[0]*states[0]+variables[1]*states[2]*states[1]; - rates[2] = variables[0]*states[0]-variables[2]*pow(states[2], 2.0)-variables[1]*states[2]*states[1]; - rates[1] = variables[2]*pow(states[2], 2.0); + rates[0] = -constants[0]*states[0]+constants[1]*states[2]*states[1]; + rates[2] = constants[0]*states[0]-constants[2]*pow(states[2], 2.0)-constants[1]*states[2]*states[1]; + rates[1] = constants[2]*pow(states[2], 2.0); } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[3] = 10000.0*states[2]; + algebraic[0] = 10000.0*states[2]; } diff --git a/tests/resources/generator/robertson_model_1966/model.ode.h b/tests/resources/generator/robertson_model_1966/model.ode.h index ccc12feaa7..c91d4d893e 100644 --- a/tests/resources/generator/robertson_model_1966/model.ode.h +++ b/tests/resources/generator/robertson_model_1966/model.ode.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[10]; char units[14]; char component[5]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/robertson_model_1966/model.ode.py b/tests/resources/generator/robertson_model_1966/model.ode.py index 55198cc41a..45a0bf3087 100644 --- a/tests/resources/generator/robertson_model_1966/model.ode.py +++ b/tests/resources/generator/robertson_model_1966/model.ode.py @@ -4,34 +4,33 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 3 -VARIABLE_COUNT = 4 +CONSTANT_COUNT = 3 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 1 +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "main"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "y1", "units": "dimensionless", "component": "main"}, + {"name": "y3", "units": "dimensionless", "component": "main"}, + {"name": "y2", "units": "dimensionless", "component": "main"} +] -VOI_INFO = {"name": "t", "units": "dimensionless", "component": "main", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "k1", "units": "dimensionless", "component": "main"}, + {"name": "k3", "units": "dimensionless", "component": "main"}, + {"name": "k2", "units": "dimensionless", "component": "main"} +] -STATE_INFO = [ - {"name": "y1", "units": "dimensionless", "component": "main", "type": VariableType.STATE}, - {"name": "y3", "units": "dimensionless", "component": "main", "type": VariableType.STATE}, - {"name": "y2", "units": "dimensionless", "component": "main", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "k1", "units": "dimensionless", "component": "main", "type": VariableType.CONSTANT}, - {"name": "k3", "units": "dimensionless", "component": "main", "type": VariableType.CONSTANT}, - {"name": "k2", "units": "dimensionless", "component": "main", "type": VariableType.CONSTANT}, - {"name": "y2_scaled", "units": "dimensionless", "component": "main", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "y2_scaled", "units": "dimensionless", "component": "main"} ] @@ -39,28 +38,36 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 0.04 - variables[1] = 1.0e4 - variables[2] = 3.0e7 +def initialise_variables(states, rates, constants, computed_constants, algebraic): states[0] = 1.0 states[1] = 0.0 states[2] = 0.0 + constants[0] = 0.04 + constants[1] = 1.0e4 + constants[2] = 3.0e7 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): - rates[0] = -variables[0]*states[0]+variables[1]*states[2]*states[1] - rates[2] = variables[0]*states[0]-variables[2]*pow(states[2], 2.0)-variables[1]*states[2]*states[1] - rates[1] = variables[2]*pow(states[2], 2.0) +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): + rates[0] = -constants[0]*states[0]+constants[1]*states[2]*states[1] + rates[2] = constants[0]*states[0]-constants[2]*pow(states[2], 2.0)-constants[1]*states[2]*states[1] + rates[1] = constants[2]*pow(states[2], 2.0) -def compute_variables(voi, states, rates, variables): - variables[3] = 10000.0*states[2] +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[0] = 10000.0*states[2] diff --git a/tests/resources/generator/sine_model_imports/model.c b/tests/resources/generator/sine_model_imports/model.c index f270736d59..c80782548d 100644 --- a/tests/resources/generator/sine_model_imports/model.c +++ b/tests/resources/generator/sine_model_imports/model.c @@ -5,29 +5,37 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 10; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 5; +const size_t ALGEBRAIC_COUNT = 3; -const VariableInfo VOI_INFO = {"x", "dimensionless", "main", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"x", "dimensionless", "main"}; const VariableInfo STATE_INFO[] = { - {"sin", "dimensionless", "deriv_approx_sin", STATE} + {"sin", "dimensionless", "deriv_approx_sin"} }; -const VariableInfo VARIABLE_INFO[] = { - {"sin", "dimensionless", "actual_sin", ALGEBRAIC}, - {"deriv_approx_initial_value", "dimensionless", "main", CONSTANT}, - {"sin", "dimensionless", "parabolic_approx_sin", ALGEBRAIC}, - {"C", "dimensionless", "main", CONSTANT}, - {"k2_oPi", "dimensionless", "parabolic_approx_sin", COMPUTED_CONSTANT}, - {"k2Pi", "dimensionless", "parabolic_approx_sin", COMPUTED_CONSTANT}, - {"kPi_2", "dimensionless", "parabolic_approx_sin", COMPUTED_CONSTANT}, - {"kPi", "dimensionless", "parabolic_approx_sin", COMPUTED_CONSTANT}, - {"kPi_32", "dimensionless", "parabolic_approx_sin", COMPUTED_CONSTANT}, - {"z", "dimensionless", "parabolic_approx_sin", ALGEBRAIC} +const VariableInfo CONSTANT_INFO[] = { + {"deriv_approx_initial_value", "dimensionless", "main"}, + {"C", "dimensionless", "main"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"k2_oPi", "dimensionless", "parabolic_approx_sin"}, + {"k2Pi", "dimensionless", "parabolic_approx_sin"}, + {"kPi_2", "dimensionless", "parabolic_approx_sin"}, + {"kPi", "dimensionless", "parabolic_approx_sin"}, + {"kPi_32", "dimensionless", "parabolic_approx_sin"} +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"sin", "dimensionless", "actual_sin"}, + {"sin", "dimensionless", "parabolic_approx_sin"}, + {"z", "dimensionless", "parabolic_approx_sin"} }; double * createStatesArray() @@ -41,11 +49,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -57,30 +87,30 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[1] = 0.0; - variables[3] = 0.75; - variables[4] = 2.0/3.14159265358979; - variables[5] = 2.0*3.14159265358979; - variables[6] = 3.14159265358979/2.0; - variables[7] = 3.14159265358979; - variables[8] = 3.0*3.14159265358979/2.0; - states[0] = variables[1]; + constants[0] = 0.0; + states[0] = constants[0]; + constants[1] = 0.75; + computedConstants[0] = 2.0/3.14159265358979; + computedConstants[1] = 2.0*3.14159265358979; + computedConstants[2] = 3.14159265358979/2.0; + computedConstants[3] = 3.14159265358979; + computedConstants[4] = 3.0*3.14159265358979/2.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = cos(voi); } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = sin(voi); - variables[9] = (voi < variables[6])?voi*variables[4]-0.5:(voi < variables[7])?(3.14159265358979-voi)*variables[4]-0.5:(voi < variables[8])?(voi-3.14159265358979)*variables[4]-0.5:(variables[5]-voi)*variables[4]-0.5; - variables[2] = (voi < variables[6])?-variables[9]*variables[9]+variables[3]+variables[9]:(voi < variables[7])?-variables[9]*variables[9]+variables[3]+variables[9]:(voi < variables[8])?variables[9]*variables[9]-variables[3]-variables[9]:variables[9]*variables[9]-variables[3]-variables[9]; + algebraic[0] = sin(voi); + algebraic[2] = (voi < computedConstants[2])?voi*computedConstants[0]-0.5:(voi < computedConstants[3])?(3.14159265358979-voi)*computedConstants[0]-0.5:(voi < computedConstants[4])?(voi-3.14159265358979)*computedConstants[0]-0.5:(computedConstants[1]-voi)*computedConstants[0]-0.5; + algebraic[1] = (voi < computedConstants[2])?-algebraic[2]*algebraic[2]+constants[1]+algebraic[2]:(voi < computedConstants[3])?-algebraic[2]*algebraic[2]+constants[1]+algebraic[2]:(voi < computedConstants[4])?algebraic[2]*algebraic[2]-constants[1]-algebraic[2]:algebraic[2]*algebraic[2]-constants[1]-algebraic[2]; } diff --git a/tests/resources/generator/sine_model_imports/model.h b/tests/resources/generator/sine_model_imports/model.h index 24b2fe3f0f..2e5d800dc3 100644 --- a/tests/resources/generator/sine_model_imports/model.h +++ b/tests/resources/generator/sine_model_imports/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[27]; char units[14]; char component[21]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/sine_model_imports/model.py b/tests/resources/generator/sine_model_imports/model.py index e14572eb25..eddef6f512 100644 --- a/tests/resources/generator/sine_model_imports/model.py +++ b/tests/resources/generator/sine_model_imports/model.py @@ -4,38 +4,37 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 10 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 5 +ALGEBRAIC_COUNT = 3 +VOI_INFO = {"name": "x", "units": "dimensionless", "component": "main"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "sin", "units": "dimensionless", "component": "deriv_approx_sin"} +] -VOI_INFO = {"name": "x", "units": "dimensionless", "component": "main", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "deriv_approx_initial_value", "units": "dimensionless", "component": "main"}, + {"name": "C", "units": "dimensionless", "component": "main"} +] -STATE_INFO = [ - {"name": "sin", "units": "dimensionless", "component": "deriv_approx_sin", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ + {"name": "k2_oPi", "units": "dimensionless", "component": "parabolic_approx_sin"}, + {"name": "k2Pi", "units": "dimensionless", "component": "parabolic_approx_sin"}, + {"name": "kPi_2", "units": "dimensionless", "component": "parabolic_approx_sin"}, + {"name": "kPi", "units": "dimensionless", "component": "parabolic_approx_sin"}, + {"name": "kPi_32", "units": "dimensionless", "component": "parabolic_approx_sin"} ] -VARIABLE_INFO = [ - {"name": "sin", "units": "dimensionless", "component": "actual_sin", "type": VariableType.ALGEBRAIC}, - {"name": "deriv_approx_initial_value", "units": "dimensionless", "component": "main", "type": VariableType.CONSTANT}, - {"name": "sin", "units": "dimensionless", "component": "parabolic_approx_sin", "type": VariableType.ALGEBRAIC}, - {"name": "C", "units": "dimensionless", "component": "main", "type": VariableType.CONSTANT}, - {"name": "k2_oPi", "units": "dimensionless", "component": "parabolic_approx_sin", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "k2Pi", "units": "dimensionless", "component": "parabolic_approx_sin", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "kPi_2", "units": "dimensionless", "component": "parabolic_approx_sin", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "kPi", "units": "dimensionless", "component": "parabolic_approx_sin", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "kPi_32", "units": "dimensionless", "component": "parabolic_approx_sin", "type": VariableType.COMPUTED_CONSTANT}, - {"name": "z", "units": "dimensionless", "component": "parabolic_approx_sin", "type": VariableType.ALGEBRAIC} +ALGEBRAIC_INFO = [ + {"name": "sin", "units": "dimensionless", "component": "actual_sin"}, + {"name": "sin", "units": "dimensionless", "component": "parabolic_approx_sin"}, + {"name": "z", "units": "dimensionless", "component": "parabolic_approx_sin"} ] @@ -47,30 +46,38 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[1] = 0.0 - variables[3] = 0.75 - variables[4] = 2.0/3.14159265358979 - variables[5] = 2.0*3.14159265358979 - variables[6] = 3.14159265358979/2.0 - variables[7] = 3.14159265358979 - variables[8] = 3.0*3.14159265358979/2.0 - states[0] = variables[1] +def initialise_variables(states, rates, constants, computed_constants, algebraic): + constants[0] = 0.0 + states[0] = constants[0] + constants[1] = 0.75 + computed_constants[0] = 2.0/3.14159265358979 + computed_constants[1] = 2.0*3.14159265358979 + computed_constants[2] = 3.14159265358979/2.0 + computed_constants[3] = 3.14159265358979 + computed_constants[4] = 3.0*3.14159265358979/2.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = cos(voi) -def compute_variables(voi, states, rates, variables): - variables[0] = sin(voi) - variables[9] = voi*variables[4]-0.5 if lt_func(voi, variables[6]) else (3.14159265358979-voi)*variables[4]-0.5 if lt_func(voi, variables[7]) else (voi-3.14159265358979)*variables[4]-0.5 if lt_func(voi, variables[8]) else (variables[5]-voi)*variables[4]-0.5 - variables[2] = -variables[9]*variables[9]+variables[3]+variables[9] if lt_func(voi, variables[6]) else -variables[9]*variables[9]+variables[3]+variables[9] if lt_func(voi, variables[7]) else variables[9]*variables[9]-variables[3]-variables[9] if lt_func(voi, variables[8]) else variables[9]*variables[9]-variables[3]-variables[9] +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): + algebraic[0] = sin(voi) + algebraic[2] = voi*computed_constants[0]-0.5 if lt_func(voi, computed_constants[2]) else (3.14159265358979-voi)*computed_constants[0]-0.5 if lt_func(voi, computed_constants[3]) else (voi-3.14159265358979)*computed_constants[0]-0.5 if lt_func(voi, computed_constants[4]) else (computed_constants[1]-voi)*computed_constants[0]-0.5 + algebraic[1] = -algebraic[2]*algebraic[2]+constants[1]+algebraic[2] if lt_func(voi, computed_constants[2]) else -algebraic[2]*algebraic[2]+constants[1]+algebraic[2] if lt_func(voi, computed_constants[3]) else algebraic[2]*algebraic[2]-constants[1]-algebraic[2] if lt_func(voi, computed_constants[4]) else algebraic[2]*algebraic[2]-constants[1]-algebraic[2] diff --git a/tests/resources/generator/unknown_variable_as_external_variable/model.c b/tests/resources/generator/unknown_variable_as_external_variable/model.c index b324146ae9..764132d596 100644 --- a/tests/resources/generator/unknown_variable_as_external_variable/model.c +++ b/tests/resources/generator/unknown_variable_as_external_variable/model.c @@ -5,29 +5,74 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; -const size_t VARIABLE_COUNT = 10; - -const VariableInfo VARIABLE_INFO[] = { - {"v", "fmol_per_sec", "SLC_template3_ss", ALGEBRAIC}, - {"E", "fmol", "SLC_template3_ss", CONSTANT}, - {"P_0", "per_fmol_sec4", "SLC_template3_ss", CONSTANT}, - {"q_Ao", "fmol", "SLC_template3_ss", CONSTANT}, - {"P_1", "per_fmol_sec4", "SLC_template3_ss", CONSTANT}, - {"q_Ai", "fmol", "SLC_template3_ss", CONSTANT}, - {"P_2", "per_fmol_sec3", "SLC_template3_ss", CONSTANT}, - {"P_5", "per_sec3", "SLC_template3_ss", CONSTANT}, - {"P_4", "per_fmol2_sec3", "SLC_template3_ss", CONSTANT}, - {"P_3", "per_fmol_sec3", "SLC_template3_ss", EXTERNAL} +const size_t CONSTANT_COUNT = 8; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 1; +const size_t EXTERNAL_COUNT = 1; + +const VariableInfo CONSTANT_INFO[] = { + {"E", "fmol", "SLC_template3_ss"}, + {"P_0", "per_fmol_sec4", "SLC_template3_ss"}, + {"q_Ao", "fmol", "SLC_template3_ss"}, + {"P_1", "per_fmol_sec4", "SLC_template3_ss"}, + {"q_Ai", "fmol", "SLC_template3_ss"}, + {"P_2", "per_fmol_sec3", "SLC_template3_ss"}, + {"P_5", "per_sec3", "SLC_template3_ss"}, + {"P_4", "per_fmol2_sec3", "SLC_template3_ss"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { + {"v", "fmol_per_sec", "SLC_template3_ss"} +}; + +const VariableInfo EXTERNAL_INFO[] = { + {"P_3", "per_fmol_sec3", "SLC_template3_ss"} }; -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() +{ + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createExternalsArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(EXTERNAL_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < EXTERNAL_COUNT; ++i) { res[i] = NAN; } @@ -39,25 +84,24 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *variables, ExternalVariable externalVariable) +void initialiseVariables(double *constants, double *computedConstants, double *algebraic) { - variables[1] = 1.1; - variables[2] = 21262500.0; - variables[3] = 150.0; - variables[4] = 3402000.0; - variables[5] = 2.0; - variables[6] = 2902500.0; - variables[7] = 810000.0; - variables[8] = 247140.0; - variables[9] = externalVariable(variables, 9); + constants[0] = 1.1; + constants[1] = 21262500.0; + constants[2] = 150.0; + constants[3] = 3402000.0; + constants[4] = 2.0; + constants[5] = 2902500.0; + constants[6] = 810000.0; + constants[7] = 247140.0; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeVariables(double *variables, ExternalVariable externalVariable) +void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - variables[9] = externalVariable(variables, 9); - variables[0] = variables[1]*(variables[2]*variables[3]-variables[4]*variables[5])/(variables[6]*variables[5]+variables[9]*variables[3]+variables[8]*variables[5]*variables[3]+variables[7]); + externals[0] = externalVariable(constants, computedConstants, algebraic, externals, 0); + algebraic[0] = constants[0]*(constants[1]*constants[2]-constants[3]*constants[4])/(constants[5]*constants[4]+externals[0]*constants[2]+constants[7]*constants[4]*constants[2]+constants[6]); } diff --git a/tests/resources/generator/unknown_variable_as_external_variable/model.h b/tests/resources/generator/unknown_variable_as_external_variable/model.h index bea9fc99b3..eed09e0dc4 100644 --- a/tests/resources/generator/unknown_variable_as_external_variable/model.h +++ b/tests/resources/generator/unknown_variable_as_external_variable/model.h @@ -7,29 +7,31 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; -extern const size_t VARIABLE_COUNT; - -typedef enum { - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC, - EXTERNAL -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; +extern const size_t EXTERNAL_COUNT; typedef struct { char name[5]; char units[15]; char component[17]; - VariableType type; } VariableInfo; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; +extern const VariableInfo EXTERNAL_INFO[]; + +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); +double * createExternalsArray(); -double * createVariablesArray(); void deleteArray(double *array); -typedef double (* ExternalVariable)(double *variables, size_t index); +typedef double (* ExternalVariable)(double *constants, double *computedConstants, double *algebraic, double *externals, size_t index); -void initialiseVariables(double *variables, ExternalVariable externalVariable); -void computeComputedConstants(double *variables); -void computeVariables(double *variables, ExternalVariable externalVariable); +void initialiseVariables(double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeVariables(double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable); diff --git a/tests/resources/generator/unknown_variable_as_external_variable/model.py b/tests/resources/generator/unknown_variable_as_external_variable/model.py index adeded13d5..ed728f39cb 100644 --- a/tests/resources/generator/unknown_variable_as_external_variable/model.py +++ b/tests/resources/generator/unknown_variable_as_external_variable/model.py @@ -4,53 +4,68 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" -VARIABLE_COUNT = 10 - +CONSTANT_COUNT = 8 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 1 +EXTERNAL_COUNT = 1 + +CONSTANT_INFO = [ + {"name": "E", "units": "fmol", "component": "SLC_template3_ss"}, + {"name": "P_0", "units": "per_fmol_sec4", "component": "SLC_template3_ss"}, + {"name": "q_Ao", "units": "fmol", "component": "SLC_template3_ss"}, + {"name": "P_1", "units": "per_fmol_sec4", "component": "SLC_template3_ss"}, + {"name": "q_Ai", "units": "fmol", "component": "SLC_template3_ss"}, + {"name": "P_2", "units": "per_fmol_sec3", "component": "SLC_template3_ss"}, + {"name": "P_5", "units": "per_sec3", "component": "SLC_template3_ss"}, + {"name": "P_4", "units": "per_fmol2_sec3", "component": "SLC_template3_ss"} +] -class VariableType(Enum): - CONSTANT = 0 - COMPUTED_CONSTANT = 1 - ALGEBRAIC = 2 - EXTERNAL = 3 +COMPUTED_CONSTANT_INFO = [ +] +ALGEBRAIC_INFO = [ + {"name": "v", "units": "fmol_per_sec", "component": "SLC_template3_ss"} +] -VARIABLE_INFO = [ - {"name": "v", "units": "fmol_per_sec", "component": "SLC_template3_ss", "type": VariableType.ALGEBRAIC}, - {"name": "E", "units": "fmol", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_0", "units": "per_fmol_sec4", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "q_Ao", "units": "fmol", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_1", "units": "per_fmol_sec4", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "q_Ai", "units": "fmol", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_2", "units": "per_fmol_sec3", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_5", "units": "per_sec3", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_4", "units": "per_fmol2_sec3", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}, - {"name": "P_3", "units": "per_fmol_sec3", "component": "SLC_template3_ss", "type": VariableType.EXTERNAL} +EXTERNAL_INFO = [ + {"name": "P_3", "units": "per_fmol_sec3", "component": "SLC_template3_ss"} ] -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT + + +def create_externals_array(): + return [nan]*EXTERNAL_COUNT -def initialise_variables(variables, external_variable): - variables[1] = 1.1 - variables[2] = 21262500.0 - variables[3] = 150.0 - variables[4] = 3402000.0 - variables[5] = 2.0 - variables[6] = 2902500.0 - variables[7] = 810000.0 - variables[8] = 247140.0 - variables[9] = external_variable(variables, 9) +def initialise_variables(constants, computed_constants, algebraic): + constants[0] = 1.1 + constants[1] = 21262500.0 + constants[2] = 150.0 + constants[3] = 3402000.0 + constants[4] = 2.0 + constants[5] = 2902500.0 + constants[6] = 810000.0 + constants[7] = 247140.0 -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_variables(variables, external_variable): - variables[9] = external_variable(variables, 9) - variables[0] = variables[1]*(variables[2]*variables[3]-variables[4]*variables[5])/(variables[6]*variables[5]+variables[9]*variables[3]+variables[8]*variables[5]*variables[3]+variables[7]) +def compute_variables(constants, computed_constants, algebraic, externals, external_variable): + externals[0] = external_variable(constants, computed_constants, algebraic, externals, 0) + algebraic[0] = constants[0]*(constants[1]*constants[2]-constants[3]*constants[4])/(constants[5]*constants[4]+externals[0]*constants[2]+constants[7]*constants[4]*constants[2]+constants[6]) diff --git a/tests/resources/generator/variable_initialised_using_a_constant/model.c b/tests/resources/generator/variable_initialised_using_a_constant/model.c index 048c4adee2..d3cbdc6b9b 100644 --- a/tests/resources/generator/variable_initialised_using_a_constant/model.c +++ b/tests/resources/generator/variable_initialised_using_a_constant/model.c @@ -5,20 +5,28 @@ #include #include -const char VERSION[] = "0.5.0"; +const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.0"; const size_t STATE_COUNT = 1; -const size_t VARIABLE_COUNT = 1; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_COUNT = 0; -const VariableInfo VOI_INFO = {"t", "second", "component_1", VARIABLE_OF_INTEGRATION}; +const VariableInfo VOI_INFO = {"t", "second", "component_1"}; const VariableInfo STATE_INFO[] = { - {"X", "dimensionless", "component_1", STATE} + {"X", "dimensionless", "component_1"} }; -const VariableInfo VARIABLE_INFO[] = { - {"X_init", "dimensionless", "component_2", CONSTANT} +const VariableInfo CONSTANT_INFO[] = { + {"X_init", "dimensionless", "component_2"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_INFO[] = { }; double * createStatesArray() @@ -32,11 +40,33 @@ double * createStatesArray() return res; } -double * createVariablesArray() +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicArray() { - double *res = (double *) malloc(VARIABLE_COUNT*sizeof(double)); + double *res = (double *) malloc(ALGEBRAIC_COUNT*sizeof(double)); - for (size_t i = 0; i < VARIABLE_COUNT; ++i) { + for (size_t i = 0; i < ALGEBRAIC_COUNT; ++i) { res[i] = NAN; } @@ -48,21 +78,21 @@ void deleteArray(double *array) free(array); } -void initialiseVariables(double *states, double *rates, double *variables) +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - variables[0] = 7.0; - states[0] = variables[0]; + constants[0] = 7.0; + states[0] = constants[0]; } -void computeComputedConstants(double *variables) +void computeComputedConstants(double *constants, double *computedConstants) { } -void computeRates(double voi, double *states, double *rates, double *variables) +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { rates[0] = 3.0; } -void computeVariables(double voi, double *states, double *rates, double *variables) +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { } diff --git a/tests/resources/generator/variable_initialised_using_a_constant/model.h b/tests/resources/generator/variable_initialised_using_a_constant/model.h index c5fa4a2f9a..3bcf4f82ef 100644 --- a/tests/resources/generator/variable_initialised_using_a_constant/model.h +++ b/tests/resources/generator/variable_initialised_using_a_constant/model.h @@ -8,32 +8,30 @@ extern const char VERSION[]; extern const char LIBCELLML_VERSION[]; extern const size_t STATE_COUNT; -extern const size_t VARIABLE_COUNT; - -typedef enum { - VARIABLE_OF_INTEGRATION, - STATE, - CONSTANT, - COMPUTED_CONSTANT, - ALGEBRAIC -} VariableType; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_COUNT; typedef struct { char name[7]; char units[14]; char component[12]; - VariableType type; } VariableInfo; extern const VariableInfo VOI_INFO; extern const VariableInfo STATE_INFO[]; -extern const VariableInfo VARIABLE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_INFO[]; double * createStatesArray(); -double * createVariablesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicArray(); + void deleteArray(double *array); -void initialiseVariables(double *states, double *rates, double *variables); -void computeComputedConstants(double *variables); -void computeRates(double voi, double *states, double *rates, double *variables); -void computeVariables(double voi, double *states, double *rates, double *variables); +void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeComputedConstants(double *constants, double *computedConstants); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic); diff --git a/tests/resources/generator/variable_initialised_using_a_constant/model.py b/tests/resources/generator/variable_initialised_using_a_constant/model.py index ea64fa616a..fb44ad602b 100644 --- a/tests/resources/generator/variable_initialised_using_a_constant/model.py +++ b/tests/resources/generator/variable_initialised_using_a_constant/model.py @@ -4,29 +4,28 @@ from math import * -__version__ = "0.4.0" +__version__ = "0.5.0" LIBCELLML_VERSION = "0.6.0" STATE_COUNT = 1 -VARIABLE_COUNT = 1 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_COUNT = 0 +VOI_INFO = {"name": "t", "units": "second", "component": "component_1"} -class VariableType(Enum): - VARIABLE_OF_INTEGRATION = 0 - STATE = 1 - CONSTANT = 2 - COMPUTED_CONSTANT = 3 - ALGEBRAIC = 4 - +STATE_INFO = [ + {"name": "X", "units": "dimensionless", "component": "component_1"} +] -VOI_INFO = {"name": "t", "units": "second", "component": "component_1", "type": VariableType.VARIABLE_OF_INTEGRATION} +CONSTANT_INFO = [ + {"name": "X_init", "units": "dimensionless", "component": "component_2"} +] -STATE_INFO = [ - {"name": "X", "units": "dimensionless", "component": "component_1", "type": VariableType.STATE} +COMPUTED_CONSTANT_INFO = [ ] -VARIABLE_INFO = [ - {"name": "X_init", "units": "dimensionless", "component": "component_2", "type": VariableType.CONSTANT} +ALGEBRAIC_INFO = [ ] @@ -34,22 +33,30 @@ def create_states_array(): return [nan]*STATE_COUNT -def create_variables_array(): - return [nan]*VARIABLE_COUNT +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_array(): + return [nan]*ALGEBRAIC_COUNT -def initialise_variables(states, rates, variables): - variables[0] = 7.0 - states[0] = variables[0] +def initialise_variables(states, rates, constants, computed_constants, algebraic): + constants[0] = 7.0 + states[0] = constants[0] -def compute_computed_constants(variables): +def compute_computed_constants(constants, computed_constants): pass -def compute_rates(voi, states, rates, variables): +def compute_rates(voi, states, rates, constants, computed_constants, algebraic): rates[0] = 3.0 -def compute_variables(voi, states, rates, variables): +def compute_variables(voi, states, rates, constants, computed_constants, algebraic): pass diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index 8aafe6088e..c371142c85 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -216,7 +216,6 @@ std::vector expectedUrls(size_t size, std::string url) } void expectEqualIssues(const std::vector &issues, const libcellml::LoggerPtr &logger) - { EXPECT_EQ(issues.size(), logger->issueCount()); for (size_t i = 0; i < logger->issueCount() && i < issues.size(); ++i) { @@ -260,6 +259,57 @@ void expectEqualIssuesCellmlElementTypesLevelsReferenceRulesUrls(const std::vect } } +void expectEqualFileContents(const std::string &fileName, const std::string &fileContents) +{ + // Uncomment the below when you want to generate the expected file contents. + // #define NEW_GENERATOR + +#ifdef NEW_GENERATOR + std::ofstream file(resourcePath(fileName)); + + file << fileContents; + + file.close(); +#endif + + EXPECT_EQ(::fileContents(fileName), fileContents); +} + +double roundValue(double value, int precision) +{ + return std::round(value * std::pow(10.0, precision)) / std::pow(10.0, precision); +} + +testing::AssertionResult areEqualValues(const char *evExpr, const char *vExpr, const char *ndxExpr, + const void *ev, const void *v, const void *ndx) +{ + static const auto PRECISION = 12; + + auto expectedValues = *(static_cast *>(ev)); + auto values = static_cast(v); + auto i = *(static_cast(ndx)); + + if ((std::isnan(expectedValues[i]) && std::isnan(values[i])) + || areNearlyEqual(roundValue(expectedValues[i], PRECISION), roundValue(values[i], PRECISION))) { + return testing::AssertionSuccess(); + } + + return testing::AssertionFailure() << "Expected equality of these values:" << std::endl + << " expectedValues[" << i << "]" << std::endl + << " Which is: " << expectedValues[i] << std::endl + << " values[" << i << "]" << std::endl + << " Which is: " << values[i]; +} + +void expectEqualValues(const std::vector &expectedValues, double *values, size_t valueCount) +{ + EXPECT_EQ(expectedValues.size(), valueCount); + + for (size_t i = 0; i < valueCount; ++i) { + EXPECT_PRED_FORMAT3(areEqualValues, &expectedValues, values, &i); + } +} + libcellml::ModelPtr createModel(const std::string &name) { libcellml::ModelPtr model = libcellml::Model::create(); diff --git a/tests/test_utils.h b/tests/test_utils.h index b446ac2384..14db31d140 100644 --- a/tests/test_utils.h +++ b/tests/test_utils.h @@ -105,6 +105,10 @@ void TEST_EXPORT expectEqualIssuesCellmlElementTypesLevelsReferenceRulesUrls(con const std::vector &urls, const libcellml::LoggerPtr &logger); +void TEST_EXPORT expectEqualFileContents(const std::string &fileName, const std::string &fileContents); + +void TEST_EXPORT expectEqualValues(const std::vector &expectedValues, double *values, size_t valueCount); + libcellml::ModelPtr TEST_EXPORT createModel(const std::string &name = ""); libcellml::ModelPtr TEST_EXPORT createModelWithComponent(const std::string &modelName = "", const std::string &componentName = ""); @@ -128,3 +132,11 @@ void TEST_EXPORT compareModel(const libcellml::ModelPtr &m1, const libcellml::Mo #define EXPECT_EQ_ISSUES_CELLMLELEMENTTYPES_LEVELS_REFERENCERULES_URLS(issues, cellmlElementTypes, levels, referenceRules, urls, logger) \ SCOPED_TRACE("Issue occurred here."); \ expectEqualIssuesCellmlElementTypesLevelsReferenceRulesUrls(issues, cellmlElementTypes, levels, referenceRules, urls, logger) + +#define EXPECT_EQ_FILE_CONTENTS(fileName, fileContents) \ + SCOPED_TRACE("Issue occurred here."); \ + expectEqualFileContents(fileName, fileContents) + +#define EXPECT_EQ_VALUES(expectedValues, values, valueCount) \ + SCOPED_TRACE("Values checked here."); \ + expectEqualValues(expectedValues, values, valueCount)