├── .codedocs ├── .github └── workflows │ ├── cmake-multi-platform.yml │ └── codeql-analysis.yml ├── .travis.yml ├── CMakeLists.txt ├── Doxyfile ├── LICENSE ├── NOTICE ├── README.md ├── cmake ├── CheckSafeStrings.cmake └── daceConfig.cmake ├── core ├── CMakeLists.txt ├── contrib │ ├── CMakeLists.txt │ ├── dgamma.c │ ├── include │ │ ├── dacecontrib.h │ │ └── f2c.h │ ├── libf2c.c │ ├── netlib │ │ ├── change.py │ │ ├── dgamma.f │ │ ├── psi.f │ │ ├── ribesl.f │ │ ├── rjbesl.f │ │ ├── rkbesl.f │ │ ├── rybesl.f │ │ └── zeta.c │ ├── psi.c │ ├── ribesl.c │ ├── rjbesl.c │ ├── rkbesl.c │ ├── rybesl.c │ └── zeta.c ├── daceaux.c ├── dacebasic.c ├── dacecompat.c ├── daceerror.c ├── daceeval.c ├── daceinit.c ├── daceio.c ├── dacemath.c ├── dacememory.c ├── dacenorm.c └── include │ └── dace │ ├── config.h.in │ ├── daceaux.h │ ├── dacebase.h │ ├── dacecompat.h │ ├── dacecore.h │ ├── dacecore_s.h │ └── daceerror.h ├── deploy.sh └── interfaces └── cxx ├── AlgebraicMatrix.cpp ├── AlgebraicVector.cpp ├── CMakeLists.txt ├── DA.cpp ├── DACEException.cpp ├── DAFormatter.cpp ├── MathExtension.cpp ├── Monomial.cpp ├── compiledDA.cpp └── include └── dace ├── AlgebraicMatrix.h ├── AlgebraicMatrix_t.h ├── AlgebraicVector.h ├── AlgebraicVector_t.h ├── DA.h ├── DACEException.h ├── DAFormatter.h ├── DA_t.h ├── Interval.h ├── MathExtension.h ├── Monomial.h ├── PromotionTrait.h ├── compiledDA.h ├── compiledDA_t.h ├── dace.h └── dace_s.h /.codedocs: -------------------------------------------------------------------------------- 1 | # CodeDocs.xyz Configuration File 2 | # 3 | # Rename this example to '.codedocs' and put it in the root directory of your 4 | # repository. This file is optional, documentation will still be generated 5 | # without it using sensible defaults. 6 | 7 | #--------------------------------------------------------------------------- 8 | # CodeDocs Configuration 9 | #--------------------------------------------------------------------------- 10 | 11 | # Include the Doxygen configuration from another file. 12 | # The file must be a relative path with respect to the root of the repository. 13 | # If any of the options in this doxyfile include a path (ie, INPUT), these 14 | # paths will be considered relative to the root of the repository, not the 15 | # location of the DOXYFILE. 16 | 17 | DOXYFILE = Doxyfile 18 | 19 | # Specify external repository to link documentation with. 20 | # This is similar to Doxygen's TAGFILES option, but will automatically link to 21 | # tags of other repositories already using CodeDocs. List each repository to 22 | # link with by giving its location in the form of owner/repository. 23 | # For example: 24 | # TAGLINKS = doxygen/doxygen CodeDocs/osg 25 | # Note: these repositories must already be built on CodeDocs. 26 | 27 | TAGLINKS = 28 | 29 | #--------------------------------------------------------------------------- 30 | # Doxygen Configuration 31 | #--------------------------------------------------------------------------- 32 | 33 | # Doxygen configuration may also be placed in this file. 34 | # Currently, the following Doxygen configuration options are available. Refer 35 | # to http://doxygen.org/manual/config.html for detailed explanation of the 36 | # options. To request support for more options, contact support@codedocs.xyz. 37 | # 38 | # ABBREVIATE_BRIEF = 39 | # ALIASES = 40 | # ALLEXTERNALS = 41 | # ALLOW_UNICODE_NAMES = 42 | # ALPHABETICAL_INDEX = 43 | # ALWAYS_DETAILED_SEC = 44 | # AUTOLINK_SUPPORT = 45 | # BRIEF_MEMBER_DESC = 46 | # BUILTIN_STL_SUPPORT = 47 | # CALLER_GRAPH = 48 | # CALL_GRAPH = 49 | # CASE_SENSE_NAMES = 50 | # CITE_BIB_FILES = 51 | # CLASS_DIAGRAMS = 52 | # CLASS_GRAPH = 53 | # COLLABORATION_GRAPH = 54 | # COLS_IN_ALPHA_INDEX = 55 | # CPP_CLI_SUPPORT = 56 | # DIAFILE_DIRS = 57 | # DIRECTORY_GRAPH = 58 | # DISABLE_INDEX = 59 | # DISTRIBUTE_GROUP_DOC = 60 | # DOTFILE_DIRS = 61 | # DOT_FONTNAME = 62 | # DOT_FONTSIZE = 63 | # DOT_GRAPH_MAX_NODES = 64 | # DOT_IMAGE_FORMAT = 65 | # DOT_TRANSPARENT = 66 | # DOXYFILE_ENCODING = 67 | # ENABLED_SECTIONS = 68 | # ENABLE_PREPROCESSING = 69 | # ENUM_VALUES_PER_LINE = 70 | # EXAMPLE_PATH = 71 | # EXAMPLE_PATTERNS = 72 | # EXAMPLE_RECURSIVE = 73 | # EXCLUDE = 74 | # EXCLUDE_PATTERNS = 75 | # EXCLUDE_SYMBOLS = 76 | # EXPAND_AS_DEFINED = 77 | # EXPAND_ONLY_PREDEF = 78 | # EXTENSION_MAPPING = 79 | # EXTERNAL_GROUPS = 80 | # EXTERNAL_PAGES = 81 | # EXTRACT_ALL = 82 | # EXTRACT_ANON_NSPACES = 83 | # EXTRACT_LOCAL_CLASSES = 84 | # EXTRACT_LOCAL_METHODS = 85 | # EXTRACT_PACKAGE = 86 | # EXTRACT_PRIVATE = 87 | # EXTRACT_STATIC = 88 | # EXT_LINKS_IN_WINDOW = 89 | # FILE_PATTERNS = 90 | # FORCE_LOCAL_INCLUDES = 91 | # FORMULA_FONTSIZE = 92 | # FORMULA_TRANSPARENT = 93 | # FULL_PATH_NAMES = 94 | # GENERATE_BUGLIST = 95 | # GENERATE_DEPRECATEDLIST = 96 | # GENERATE_LEGEND = 97 | # GENERATE_TESTLIST = 98 | # GENERATE_TODOLIST = 99 | # GENERATE_TREEVIEW = 100 | # GRAPHICAL_HIERARCHY = 101 | # GROUP_GRAPHS = 102 | # GROUP_NESTED_COMPOUNDS = 103 | # HIDE_COMPOUND_REFERENCE= = 104 | # HIDE_FRIEND_COMPOUNDS = 105 | # HIDE_IN_BODY_DOCS = 106 | # HIDE_SCOPE_NAMES = 107 | # HIDE_UNDOC_CLASSES = 108 | # HIDE_UNDOC_MEMBERS = 109 | # HIDE_UNDOC_RELATIONS = 110 | # HTML_COLORSTYLE_GAMMA = 111 | # HTML_COLORSTYLE_HUE = 112 | # HTML_COLORSTYLE_SAT = 113 | # HTML_DYNAMIC_SECTIONS = 114 | # HTML_EXTRA_FILES = 115 | # HTML_EXTRA_STYLESHEET = 116 | # HTML_FOOTER = 117 | # HTML_HEADER = 118 | # HTML_INDEX_NUM_ENTRIES = 119 | # HTML_STYLESHEET = 120 | # HTML_TIMESTAMP = 121 | # IDL_PROPERTY_SUPPORT = 122 | # IGNORE_PREFIX = 123 | # IMAGE_PATH = 124 | # INCLUDED_BY_GRAPH = 125 | # INCLUDE_FILE_PATTERNS = 126 | # INCLUDE_GRAPH = 127 | # INCLUDE_PATH = 128 | # INHERIT_DOCS = 129 | # INLINE_GROUPED_CLASSES = 130 | # INLINE_INFO = 131 | # INLINE_INHERITED_MEMB = 132 | # INLINE_SIMPLE_STRUCTS = 133 | # INLINE_SOURCES = 134 | # INPUT = 135 | # INPUT_ENCODING = 136 | # INTERACTIVE_SVG = 137 | # INTERNAL_DOCS = 138 | # JAVADOC_AUTOBRIEF = 139 | # LAYOUT_FILE = 140 | # MACRO_EXPANSION = 141 | # MARKDOWN_SUPPORT = 142 | # MAX_DOT_GRAPH_DEPTH = 143 | # MSCFILE_DIRS = 144 | # MULTILINE_CPP_IS_BRIEF = 145 | # OPTIMIZE_FOR_FORTRAN = 146 | # OPTIMIZE_OUTPUT_FOR_C = 147 | # OPTIMIZE_OUTPUT_JAVA = 148 | # OPTIMIZE_OUTPUT_VHDL = 149 | # OUTPUT_LANGUAGE = 150 | # PLANTUML_JAR_PATH = 151 | # PREDEFINED = 152 | # PROJECT_BRIEF = 153 | # PROJECT_LOGO = 154 | # PROJECT_NAME = 155 | # PROJECT_NUMBER = 156 | # QT_AUTOBRIEF = 157 | # RECURSIVE = 158 | # REFERENCED_BY_RELATION = 159 | # REFERENCES_LINK_SOURCE = 160 | # REFERENCES_RELATION = 161 | # REPEAT_BRIEF = 162 | # SEARCHENGINE = 163 | # SEARCH_INCLUDES = 164 | # SEPARATE_MEMBER_PAGES = 165 | # SHORT_NAMES = 166 | # SHOW_FILES = 167 | # SHOW_GROUPED_MEMB_INC = 168 | # SHOW_INCLUDE_FILES = 169 | # SHOW_NAMESPACES = 170 | # SHOW_USED_FILES = 171 | # SIP_SUPPORT = 172 | # SKIP_FUNCTION_MACROS = 173 | # SORT_BRIEF_DOCS = 174 | # SORT_BY_SCOPE_NAME = 175 | # SORT_GROUP_NAMES = 176 | # SORT_MEMBERS_CTORS_1ST = 177 | # SORT_MEMBER_DOCS = 178 | # SOURCE_BROWSER = 179 | # SOURCE_TOOLTIPS = 180 | # STRICT_PROTO_MATCHING = 181 | # STRIP_CODE_COMMENTS = 182 | # STRIP_FROM_INC_PATH = 183 | # STRIP_FROM_PATH = 184 | # SUBGROUPING = 185 | # TAB_SIZE = 186 | # TEMPLATE_RELATIONS = 187 | # TREEVIEW_WIDTH = 188 | # TYPEDEF_HIDES_STRUCT = 189 | # UML_LIMIT_NUM_FIELDS = 190 | # UML_LOOK = 191 | # USE_MDFILE_AS_MAINPAGE = 192 | # VERBATIM_HEADERS = 193 | # -------------------------------------------------------------------------------- /.github/workflows/cmake-multi-platform.yml: -------------------------------------------------------------------------------- 1 | # This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. 2 | # See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml 3 | name: CMake on multiple platforms 4 | 5 | on: 6 | push: 7 | branches: [ "master" ] 8 | pull_request: 9 | branches: [ "master" ] 10 | 11 | jobs: 12 | build: 13 | runs-on: ${{ matrix.os }} 14 | 15 | strategy: 16 | # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. 17 | fail-fast: false 18 | 19 | # Set up a matrix to run the following 3 configurations: 20 | # 1. 21 | # 2. 22 | # 3. 23 | # 24 | # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. 25 | matrix: 26 | os: [ubuntu-latest, windows-latest, macos-13, macos-latest] 27 | build_type: [RelWithDebInfo] 28 | c_compiler: [gcc, clang, cl] 29 | include: 30 | - os: windows-latest 31 | c_compiler: cl 32 | cpp_compiler: cl 33 | - os: ubuntu-latest 34 | c_compiler: gcc 35 | cpp_compiler: g++ 36 | - os: ubuntu-latest 37 | c_compiler: clang 38 | cpp_compiler: clang++ 39 | - os: macos-13 40 | c_compiler: clang 41 | cpp_compiler: clang++ 42 | - os: macos-latest 43 | c_compiler: clang 44 | cpp_compiler: clang++ 45 | exclude: 46 | - os: windows-latest 47 | c_compiler: gcc 48 | - os: windows-latest 49 | c_compiler: clang 50 | - os: ubuntu-latest 51 | c_compiler: cl 52 | - os: macos-13 53 | c_compiler: cl 54 | - os: macos-13 55 | c_compiler: gcc 56 | - os: macos-latest 57 | c_compiler: cl 58 | - os: macos-latest 59 | c_compiler: gcc 60 | 61 | steps: 62 | - uses: actions/checkout@v4 63 | 64 | - name: Set reusable strings 65 | # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. 66 | id: strings 67 | shell: bash 68 | run: | 69 | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" 70 | 71 | - name: Configure CMake 72 | # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. 73 | # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type 74 | run: > 75 | cmake -B ${{ steps.strings.outputs.build-output-dir }} 76 | -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} 77 | -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} 78 | -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} 79 | -S ${{ github.workspace }} 80 | 81 | - name: Build 82 | # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). 83 | run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} 84 | 85 | - name: Test 86 | working-directory: ${{ steps.strings.outputs.build-output-dir }} 87 | # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). 88 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail 89 | run: ctest --build-config ${{ matrix.build_type }} 90 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "master" ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ "master" ] 20 | schedule: 21 | - cron: '36 14 4 * 1-5' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'cpp' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v3 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v2 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | 52 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 53 | # queries: security-extended,security-and-quality 54 | 55 | 56 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 57 | # If this step fails, then you should remove it and run the build manually (see below) 58 | - name: Autobuild 59 | uses: github/codeql-action/autobuild@v2 60 | 61 | # ℹ️ Command-line programs to run using the OS shell. 62 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 63 | 64 | # If the Autobuild fails above, remove it and uncomment the following three lines. 65 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 66 | 67 | # - run: | 68 | # echo "Run, Build Application using script" 69 | # ./location_of_script_within_repo/buildscript.sh 70 | 71 | - name: Perform CodeQL Analysis 72 | uses: github/codeql-action/analyze@v2 73 | with: 74 | category: "/language:${{matrix.language}}" 75 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | script: 3 | - mkdir build && cd build 4 | - cmake .. 5 | - make 6 | - make package 7 | - mkdir packages && for f in DACE-2.0*; do mv $f packages/${PKG_PREFIX}${f}; done 8 | - ls -la packages 9 | dist: trusty 10 | sudo: false 11 | git: 12 | depth: 1 13 | 14 | 15 | matrix: 16 | include: 17 | - os: linux 18 | compilers: clang 19 | env: 20 | - MATRIX_EVAL="CC=clang CXX=clang++ PKG_PREFIX=linux-clang-" 21 | 22 | - os: linux 23 | compilers: gcc 24 | env: 25 | - MATRIX_EVAL="PKG_PREFIX=linux-gcc-" 26 | 27 | # - os: linux 28 | # addons: 29 | # apt: 30 | # update: true 31 | # sources: 32 | # - "ubuntu-toolchain-r-test" 33 | # packages: 34 | # - "g++-4.9" 35 | # env: 36 | # - MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9 && PKG_PREFIX=linux-gcc-4.9-" 37 | 38 | # - os: linux 39 | # addons: 40 | # apt: 41 | # update: true 42 | # sources: 43 | # - "ubuntu-toolchain-r-test" 44 | # packages: 45 | # - "g++-5" 46 | # env: 47 | # - MATRIX_EVAL="CC=gcc-5 && CXX=g++-5 && PKG_PREFIX=linux-gcc-5-" 48 | 49 | # - os: linux 50 | # addons: 51 | # apt: 52 | # update: true 53 | # sources: 54 | # - "ubuntu-toolchain-r-test" 55 | # packages: 56 | # - "g++-6" 57 | # env: 58 | # - MATRIX_EVAL="CC=gcc-6 && CXX=g++-6 && PKG_PREFIX=linux-gcc-6-" 59 | 60 | - os: linux 61 | addons: 62 | apt: 63 | update: true 64 | sources: 65 | - "ubuntu-toolchain-r-test" 66 | packages: 67 | - "g++-7" 68 | env: 69 | - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && PKG_PREFIX=linux-gcc-7-" 70 | 71 | # - os: linux 72 | # addons: 73 | # apt: 74 | # sources: 75 | # - "ubuntu-toolchain-r-test" 76 | # - "llvm-toolchain-trusty-4.0" 77 | # packages: 78 | # - "clang-4.0" 79 | # env: 80 | # - MATRIX_EVAL="CC=clang-4.0 && CXX=clang++-4.0 && PKG_PREFIX=linux-clang-4-" 81 | 82 | # - os: linux 83 | # addons: 84 | # apt: 85 | # sources: 86 | # - "ubuntu-toolchain-r-test" 87 | # - "llvm-toolchain-trusty-5.0" 88 | # packages: 89 | # - "clang-5.0" 90 | # env: 91 | # - MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0 && PKG_PREFIX=linux-clang-5-" 92 | 93 | - os: linux 94 | addons: 95 | apt: 96 | sources: 97 | - "ubuntu-toolchain-r-test" 98 | - "llvm-toolchain-trusty-6.0" 99 | packages: 100 | - "clang-6.0" 101 | env: 102 | - MATRIX_EVAL="CC=clang-6.0 && CXX=clang++-6.0 && PKG_PREFIX=linux-clang-6-" 103 | 104 | - os: osx 105 | osx_image: xcode9 106 | env: 107 | - MATRIX_EVAL="PKG_PREFIX=osx-xcode9-" 108 | 109 | deploy: 110 | - provider: releases 111 | api_key: $GITHUB_TOKEN 112 | file_glob: true 113 | file: packages/* 114 | skip_cleanup: true 115 | on: 116 | tags: true # only upload tagged builds (= releases) 117 | 118 | # - provider: pages 119 | # target-branch: pkg-latest 120 | # github-token: $GITHUB_TOKEN 121 | # keep-history: true 122 | # local-dir: build/packages 123 | # skip_cleanup: true 124 | # on: 125 | # branch: master 126 | # tags: false 127 | # condition: $TRAVIS_EVENT_TYPE != pull_request 128 | 129 | - provider: script 130 | script: sh ${TRAVIS_BUILD_DIR}/deploy.sh 131 | skip_cleanup: true 132 | on: 133 | branch: master 134 | tags: false 135 | condition: $TRAVIS_EVENT_TYPE != pull_request 136 | 137 | before_install: 138 | - eval "${MATRIX_EVAL}" 139 | - eval "${CC} --version" 140 | - eval "${CXX} --version" 141 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | # since MacOS 10.14 (XCode 10.0), default includes are no longer installed to /usr/include or /usr/local/include 4 | # the SDK to use must be specified explicitly in CMAKE_OSX_SYSROOT as it seems at least cmake 3.12.4 does not find it automatically if left empty 5 | # this must happen before project() 6 | if(APPLE AND NOT DEFINED ENV{SDKROOT}) 7 | execute_process(COMMAND xcodebuild -sdk macosx -version Path OUTPUT_VARIABLE RES OUTPUT_STRIP_TRAILING_WHITESPACE) 8 | set(CMAKE_OSX_SYSROOT "${RES}" CACHE PATH "Build against headers and libraries in this SDK.") 9 | endif(APPLE AND NOT DEFINED ENV{SDKROOT}) 10 | 11 | # global OS specific settings 12 | if(WIN32) 13 | cmake_policy(SET CMP0054 NEW) 14 | elseif(APPLE) 15 | cmake_policy(SET CMP0042 NEW) 16 | cmake_policy(SET CMP0068 NEW) 17 | # build libraries use full hard-coded binary path, install libraries replace it by @rpath 18 | set(CMAKE_MACOSX_RPATH OFF) 19 | set(CMAKE_INSTALL_NAME_DIR "@rpath") 20 | endif(WIN32) 21 | 22 | 23 | project(DACE C CXX) 24 | 25 | # versioning 26 | set(DACE_MAJOR_VERSION 2) 27 | set(DACE_MINOR_VERSION 1) 28 | set(DACE_PATCH_VERSION 0) 29 | 30 | # CMake includes 31 | list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") 32 | include(CMakeDependentOption) 33 | include(CheckSafeStrings) 34 | include(CMakePackageConfigHelpers) 35 | 36 | 37 | # Set C/C++ standard (adapted https://github.com/ceres-solver/ceres-solver/blob/master/CMakeLists.txt) 38 | # Respect user-specified CMAKE_C/C++_STANDARD or default to C99/C++11. 39 | # Standard is a hard requirement and that option is hidden from CMake GUI 40 | if(NOT CMAKE_C_STANDARD) 41 | set(CMAKE_C_STANDARD 99 CACHE STRING "C standard (minimum 99)" FORCE) 42 | set_property(CACHE CMAKE_C_STANDARD PROPERTY STRINGS 99 11 17) # options shown in CMake GUI 43 | endif(NOT CMAKE_C_STANDARD) 44 | set(CMAKE_C_STANDARD_REQUIRED ON CACHE BOOL "") 45 | mark_as_advanced(CMAKE_C_STANDARD_REQUIRED) 46 | 47 | if(NOT CMAKE_CXX_STANDARD) 48 | set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard (minimum 14)" FORCE) 49 | set_property(CACHE CMAKE_CXX_STANDARD PROPERTY STRINGS 14 17 20) # options shown in CMake GUI 50 | endif(NOT CMAKE_CXX_STANDARD) 51 | set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "") 52 | mark_as_advanced(CMAKE_CXX_STANDARD_REQUIRED) 53 | 54 | 55 | # Set generally understood compiler flags (enforcing -O2) 56 | add_compile_options("$<$:-O2>" "$<$:-O2>") 57 | 58 | # Set compiler specific flags 59 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU") 60 | add_compile_options("-Wall" "$<$:-frounding-math>" "$<$:-fsignaling-nans>" "$<$:-frounding-math>" "$<$:-fsignaling-nans>") 61 | elseif(CMAKE_C_COMPILER_ID MATCHES ".*Clang") # Also catch IDs like "AppleClang" 62 | add_compile_options("-Wall") 63 | elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC") 64 | add_compile_options("/W4" "$<$:/fp:strict>" "$<$:/fp:strict>") 65 | endif(CMAKE_C_COMPILER_ID STREQUAL "GNU") 66 | 67 | 68 | # Boolean options 69 | option(WITH_ALGEBRAICMATRIX "Include the AlgebraicMatrix type (experimental)" OFF) 70 | option(WITH_PTHREAD "Enable threading via pthread library" OFF) 71 | 72 | # Tri-state option for memory model and the associated choices 73 | set(DACE_MEMORY_MODEL DYNAMIC CACHE STRING "DACE memory model") 74 | set_property(CACHE DACE_MEMORY_MODEL PROPERTY STRINGS DYNAMIC STATIC HYBRID) 75 | string(TOUPPER "${DACE_MEMORY_MODEL}" DACE_MEMORY_MODEL_U) 76 | 77 | # Default build type option if not set already 78 | if(NOT CMAKE_BUILD_TYPE) 79 | set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING 80 | "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." 81 | FORCE) 82 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel) # options shown in CMake GUI 83 | endif(NOT CMAKE_BUILD_TYPE) 84 | 85 | # Debug flag 86 | string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_U) 87 | if(CMAKE_BUILD_TYPE_U STREQUAL "DEBUG") 88 | set(WITH_DEBUG 1) 89 | endif(CMAKE_BUILD_TYPE_U STREQUAL "DEBUG") 90 | 91 | # Static memory management default sizes 92 | # If you do not know what these values are, you probably do not want to touch them! 93 | if(DACE_MEMORY_MODEL_U STREQUAL "STATIC") 94 | # Pick any maximum NO, NV combination to support, then set these values like this: 95 | # NMMAX = (NO+NV)!/NO!/NV! LIAMAX = (NO+1)^((NV+1)/2) 96 | # For example, for NO=10 and NV=10 set DACE_STATIC_NMMAX=184756 and DACE_STATIC_LIAMAX=161051 97 | # The following default values are sized for NO=10 and NV=7 98 | set(DACE_STATIC_NOMAX 10 CACHE STRING "(EXPERT) Maximum order." FORCE) 99 | set(DACE_STATIC_NVMAX 10 CACHE STRING "(EXPERT) Maximum number of variables." FORCE) 100 | set(DACE_STATIC_NMMAX 19448 CACHE STRING "(EXPERT) Maximum number of monomials [(NO+NV)!/NO!/NV!]." FORCE) 101 | set(DACE_STATIC_LIAMAX 161051 CACHE STRING "(EXPERT) Maximum addressing array size [(NO+1)^((NV+1)/2)]." FORCE) 102 | set(DACE_STATIC_VAR_SIZE 100 CACHE STRING "(EXPERT) Maximum number of DA variables." FORCE) 103 | set(DACE_STATIC_MEM_SIZE 1944800 CACHE STRING "(EXPERT) Maximum stack size [NMMAX*VAR_SIZE]." FORCE) 104 | endif(DACE_MEMORY_MODEL_U STREQUAL "STATIC") 105 | 106 | 107 | # Check platform specific functions and pass options by configuring config.h file in core 108 | check_safe_strings(HAVE_SAFE_STRINGS) 109 | configure_file(core/include/dace/config.h.in core/include/dace/config.h) 110 | 111 | 112 | # process the subdirectories with actual code 113 | add_subdirectory(core/contrib) 114 | add_subdirectory(core) 115 | add_subdirectory(interfaces/cxx) 116 | 117 | 118 | # statically and dynamically linked DACE library with C core and C++ interface 119 | add_library(dace SHARED $ $ $) 120 | add_library(dace_s STATIC $ $ $) 121 | 122 | # hard code all required include directories when building from source (C++ includes, core includes, config.h include) 123 | target_include_directories(dace INTERFACE $ 124 | $ 125 | $ 126 | $ 127 | ) 128 | target_include_directories(dace_s INTERFACE $ 129 | $ 130 | $ 131 | $ 132 | ) 133 | 134 | if(WITH_PTHREAD) 135 | target_link_libraries(dace PUBLIC pthread) 136 | target_link_libraries(dace_s PUBLIC pthread) 137 | endif(WITH_PTHREAD) 138 | 139 | # library versioning 140 | set_property(TARGET dace PROPERTY VERSION "${DACE_MAJOR_VERSION}.${DACE_MINOR_VERSION}.${DACE_PATCH_VERSION}") 141 | set_property(TARGET dace PROPERTY SOVERSION ${DACE_MAJOR_VERSION}) 142 | set_property(TARGET dace PROPERTY INTERFACE_dace_MAJOR_VERSION ${DACE_MAJOR_VERSION}) 143 | set_property(TARGET dace APPEND PROPERTY COMPATIBLE_INTERFACE_STRING dace_MAJOR_VERSION) 144 | set_property(TARGET dace_s PROPERTY VERSION "${DACE_MAJOR_VERSION}.${DACE_MINOR_VERSION}.${DACE_PATCH_VERSION}") 145 | set_property(TARGET dace_s PROPERTY INTERFACE_dace_s_MAJOR_VERSION ${DACE_MAJOR_VERSION}) 146 | set_property(TARGET dace_s APPEND PROPERTY COMPATIBLE_INTERFACE_STRING dace_s_MAJOR_VERSION) 147 | 148 | # explicitly set required minimum C++ standard so it carries through to exported targets and consumers 149 | set_property(TARGET dace PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_11) 150 | set_property(TARGET dace_s PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_11) 151 | 152 | 153 | # install DACE libraries and required headers 154 | install(TARGETS dace EXPORT dace 155 | LIBRARY DESTINATION lib COMPONENT libraries 156 | RUNTIME DESTINATION lib COMPONENT libraries 157 | ARCHIVE DESTINATION lib COMPONENT libraries 158 | PUBLIC_HEADER DESTINATION include COMPONENT headers) 159 | install(TARGETS dace_s EXPORT dace 160 | LIBRARY DESTINATION lib COMPONENT libraries 161 | RUNTIME DESTINATION lib COMPONENT libraries 162 | ARCHIVE DESTINATION lib COMPONENT libraries 163 | PUBLIC_HEADER DESTINATION include COMPONENT headers) 164 | install(DIRECTORY ${PROJECT_SOURCE_DIR}/interfaces/cxx/include/dace DESTINATION include 165 | COMPONENT headers FILES_MATCHING PATTERN "*.h") 166 | install(DIRECTORY ${PROJECT_SOURCE_DIR}/core/include/ DESTINATION include/ COMPONENT headers FILES_MATCHING PATTERN "*.h") 167 | install(FILES ${PROJECT_BINARY_DIR}/core/include/dace/config.h DESTINATION include/dace COMPONENT headers) 168 | 169 | 170 | # Automatically create cmake package files to find the DACE 171 | write_basic_package_version_file( 172 | "${CMAKE_CURRENT_BINARY_DIR}/dace/daceConfigVersion.cmake" 173 | VERSION "${DACE_MAJOR_VERSION}.${DACE_MINOR_VERSION}.${DACE_PATCH_VERSION}" 174 | COMPATIBILITY AnyNewerVersion 175 | ) 176 | 177 | export(EXPORT dace 178 | FILE "${CMAKE_CURRENT_BINARY_DIR}/dace/dace.cmake" 179 | NAMESPACE dace:: 180 | ) 181 | 182 | configure_file("cmake/daceConfig.cmake" 183 | "${CMAKE_CURRENT_BINARY_DIR}/dace/daceConfig.cmake" 184 | COPYONLY 185 | ) 186 | 187 | # install cmake package files 188 | install(EXPORT dace NAMESPACE dace:: DESTINATION lib/cmake/dace COMPONENT cmake) 189 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/dace/daceConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/dace/daceConfigVersion.cmake" DESTINATION lib/cmake/dace COMPONENT cmake) 190 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Differential Algebra Core Engine (DACE) 2 | Copyright 2016 Politecnico di Milano and contributors (2014 Dinamica Srl) 3 | 4 | This product includes software developed at 5 | Dinamica Srl in 2014 and extended by Politecnico di Milano and ESA ACT in 2016. 6 | 7 | In 2014 Dinamica Srl developed DACE 1.0 which comprises a Core and a C++ interface. 8 | The work as been performed under ESA Contract "Nonlinear Propagation of Uncertainties in Space Dynamics based on Taylor Differential Algebra" 9 | People involved in the fist development at Dinamica Srl: 10 | - Pierluigi Di Lizia 11 | - Mauro Massari 12 | - Mirco Rasotto 13 | - Alexander Wittig 14 | - Roberto Armellin 15 | - Alessandro Morselli 16 | - Martin Berz 17 | 18 | In 2016 Politecnico di Milano and ESA's Advanced Concepts Team developed an improved Core while keeping the previously developed C++ interface. 19 | This work has been performed under an ESA ACT Ariadna Study "Assessment of Onboard DA State Estimation for Spacecraft Relative Navigation" 20 | People involved in the development at Politecnico di Milano and ESA-ACT: 21 | - Mauro Massari 22 | - Pierluigi Di Lizia 23 | - Alexander Wittig 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/dacelib/dace.svg?branch=master)](https://travis-ci.org/dacelib/dace) 2 | 3 | # DACE 4 | The Differential Algebra Computational Toolbox. 5 | 6 | ## Requirements 7 | To use the DACE library, you need a C++11 compatible C++ compiler. Almost all modern C++ compilers (GNU, Clang, MS Visual Studio) meet that requirement nowadays. We also highly recommend using CMake as a build system, and obviously Git as your source code management system. 8 | 9 | On Linux, you can install the compiler toolchain through your package system if they don't already come pre-installed. On Windows it is suggested to use the WSL environment and follow the linux procedure, or download Microsoft Visual Studio (the free Community Edition is fine). On MacOS X, you need to install the Xcode package from Apple from the App Store. 10 | 11 | To build Windows DACE library installer packages, you additionally need the NSIS installer compiler. (Deprecated, will be removed soon) 12 | 13 | ## Getting started 14 | To get started just clone the entire repository and build the library from scratch (which really is very easy). You can use the current development version if you want the latests improvement and bug fixes or point to the Releases page for official released versions. 15 | 16 | ## Building the DACE 17 | To build the DACE library, simply clone this repository: 18 | ``` 19 | git clone "https://github.com/dacelib/dace.git" dace 20 | ``` 21 | Then create a build directory, run cmake, and then cmake --build to compile everything: 22 | ``` 23 | mkdir dace-build 24 | cmake -S dace/ -B dace-build/ 25 | cmake --build dace-build/ 26 | ``` 27 | After some compiling, you should have a sparkling new dace library ready for use in the dace-build folder. 28 | 29 | Optionally you can install the freshly built DACE library directly into your system: 30 | ``` 31 | sudo cmake --install dace-build/ 32 | ``` 33 | The ```sudo``` is there to give you the required permissions to install into your system directories (usually ```/usr/local```). 34 | 35 | We have moved the tutorials to a different repository https://github.com/dacelib/dace-tutorials to keep the main repository clean. You can clone the tutorials repository and follow the instructions there to get started with DACE. 36 | 37 | Also have a look at the [DACE Wiki pages](https://github.com/dacelib/dace/wiki) if you have further questions. 38 | 39 | ## Embedding the DACE in other projects 40 | To use the DACE library without installing it locally, use the [FetchContent](https://cmake.org/cmake/help/v3.19/module/FetchContent.html) mechanism of CMake. 41 | 42 | Include this code at the start of your CMakeList.txt file to have CMake automatically clone and build the DACE within your project and make the resulting libraries available as the `dace::dace_s` (static) and `dace::dace` (dynamic) targets. 43 | ``` 44 | include(FetchContent) 45 | FetchContent_Declare( 46 | DACE 47 | GIT_REPOSITORY https://github.com/dacelib/dace.git 48 | GIT_TAG v2.1.0 49 | ) 50 | FetchContent_MakeAvailable(DACE) 51 | add_library(dace::dace ALIAS dace) 52 | add_library(dace::dace_s ALIAS dace_s) 53 | ``` 54 | 55 | To build against the DACE, simply add your own executable and link it with one of these targets: 56 | ``` 57 | add_executable(my-code my-code.cpp) 58 | target_link_libraries(my-code PUBLIC dace::dace_s) 59 | ``` 60 | -------------------------------------------------------------------------------- /cmake/CheckSafeStrings.cmake: -------------------------------------------------------------------------------- 1 | # Check if safe C string functions with _s suffix are available 2 | function(check_safe_strings HAVE_SAFE_STRINGS_VAR) 3 | include(CheckSymbolExists) 4 | set(CMAKE_REQUIRED_DEFINITIONS "-D__STDC_WANT_LIB_EXT1__=1") 5 | check_symbol_exists(strncpy_s string.h HAVE_SAFE_STRINGS) 6 | set(${HAVE_SAFE_STRINGS_VAR} ${HAVE_SAFE_STRINGS} PARENT_SCOPE) 7 | endfunction() 8 | -------------------------------------------------------------------------------- /cmake/daceConfig.cmake: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/dace.cmake") 2 | -------------------------------------------------------------------------------- /core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SRCCCORE daceaux.c dacebasic.c dacecompat.c daceerror.c daceeval.c daceinit.c daceio.c dacemath.c dacememory.c dacenorm.c) 2 | include_directories(include ${PROJECT_BINARY_DIR}/core/include contrib/include) 3 | 4 | add_library(c_core_s OBJECT ${SRCCCORE}) 5 | add_library(c_core OBJECT ${SRCCCORE}) 6 | 7 | set_target_properties(c_core PROPERTIES POSITION_INDEPENDENT_CODE True) 8 | if(WIN32) 9 | target_compile_definitions(c_core PRIVATE "DACE_API=__declspec(dllexport)") 10 | target_compile_definitions(c_core_s PRIVATE "DACE_API=") 11 | endif(WIN32) 12 | -------------------------------------------------------------------------------- /core/contrib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # all of these are only used internally by the DACE core and not ever exposed 2 | # hence nothing is installed and no headers are made public 3 | set(SRCCCONTRIB libf2c.c dgamma.c ribesl.c rjbesl.c rkbesl.c rybesl.c psi.c zeta.c) 4 | include_directories(include) 5 | 6 | add_library(c_core_contrib_s OBJECT ${SRCCCONTRIB}) 7 | add_library(c_core_contrib OBJECT ${SRCCCONTRIB}) 8 | set_target_properties(c_core_contrib PROPERTIES POSITION_INDEPENDENT_CODE True) 9 | -------------------------------------------------------------------------------- /core/contrib/include/dacecontrib.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2019 University of Southampton * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * dacecontrib.h 24 | * 25 | * Created on: November 8, 2019 26 | * Author: Alexander Wittig 27 | */ 28 | 29 | /* 30 | This file contains all contributed routines to the DACE core. 31 | It is never included publicly by DACE users or high level interfaces. 32 | */ 33 | /** \addtogroup DACEContrib Contrib 34 | * @{ 35 | */ 36 | 37 | /// @cond 38 | 39 | #ifndef DINAMICA_DACECONTRIB_H_ 40 | #define DINAMICA_DACECONTRIB_H_ 41 | 42 | double zeta_(const double x, const double q, unsigned int *err); 43 | double dgamma_(const double *x); 44 | double psi_(const double *x); 45 | int ribesl_(double *x, double *alpha, long int *nb, long int *ize, double *b, long int *ncalc); 46 | int rjbesl_(double *x, double *alpha, long int *nb, double *b, long int *ncalc); 47 | int rkbesl_(double *x, double *alpha, long int *nb, long int *ize, double *b, long int *ncalc); 48 | int rybesl_(double *x, double *alpha, long int *nb, double *b, long int *ncalc); 49 | 50 | /// @endcond 51 | /** @}*/ 52 | #endif /* DINAMICA_DACECONTRIB_H_ */ 53 | -------------------------------------------------------------------------------- /core/contrib/include/f2c.h: -------------------------------------------------------------------------------- 1 | /* f2c.h -- Standard Fortran to C header file */ 2 | 3 | /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." 4 | 5 | - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ 6 | 7 | #ifndef F2C_INCLUDE 8 | #define F2C_INCLUDE 9 | 10 | typedef long int integer; 11 | typedef unsigned long int uinteger; 12 | typedef char *address; 13 | typedef short int shortint; 14 | typedef float real; 15 | typedef double doublereal; 16 | typedef struct { real r, i; } complex; 17 | typedef struct { doublereal r, i; } doublecomplex; 18 | typedef long int logical; 19 | typedef short int shortlogical; 20 | typedef char logical1; 21 | typedef char integer1; 22 | #ifdef INTEGER_STAR_8 /* Adjust for integer*8. */ 23 | typedef long long longint; /* system-dependent */ 24 | typedef unsigned long long ulongint; /* system-dependent */ 25 | #define qbit_clear(a,b) ((a) & ~((ulongint)1 << (b))) 26 | #define qbit_set(a,b) ((a) | ((ulongint)1 << (b))) 27 | #endif 28 | 29 | #define TRUE_ (1) 30 | #define FALSE_ (0) 31 | 32 | /* Extern is for use with -E */ 33 | #ifndef Extern 34 | #define Extern extern 35 | #endif 36 | 37 | /* I/O stuff */ 38 | 39 | #ifdef f2c_i2 40 | /* for -i2 */ 41 | typedef short flag; 42 | typedef short ftnlen; 43 | typedef short ftnint; 44 | #else 45 | typedef long int flag; 46 | typedef long int ftnlen; 47 | typedef long int ftnint; 48 | #endif 49 | 50 | /*external read, write*/ 51 | typedef struct 52 | { flag cierr; 53 | ftnint ciunit; 54 | flag ciend; 55 | char *cifmt; 56 | ftnint cirec; 57 | } cilist; 58 | 59 | /*internal read, write*/ 60 | typedef struct 61 | { flag icierr; 62 | char *iciunit; 63 | flag iciend; 64 | char *icifmt; 65 | ftnint icirlen; 66 | ftnint icirnum; 67 | } icilist; 68 | 69 | /*open*/ 70 | typedef struct 71 | { flag oerr; 72 | ftnint ounit; 73 | char *ofnm; 74 | ftnlen ofnmlen; 75 | char *osta; 76 | char *oacc; 77 | char *ofm; 78 | ftnint orl; 79 | char *oblnk; 80 | } olist; 81 | 82 | /*close*/ 83 | typedef struct 84 | { flag cerr; 85 | ftnint cunit; 86 | char *csta; 87 | } cllist; 88 | 89 | /*rewind, backspace, endfile*/ 90 | typedef struct 91 | { flag aerr; 92 | ftnint aunit; 93 | } alist; 94 | 95 | /* inquire */ 96 | typedef struct 97 | { flag inerr; 98 | ftnint inunit; 99 | char *infile; 100 | ftnlen infilen; 101 | ftnint *inex; /*parameters in standard's order*/ 102 | ftnint *inopen; 103 | ftnint *innum; 104 | ftnint *innamed; 105 | char *inname; 106 | ftnlen innamlen; 107 | char *inacc; 108 | ftnlen inacclen; 109 | char *inseq; 110 | ftnlen inseqlen; 111 | char *indir; 112 | ftnlen indirlen; 113 | char *infmt; 114 | ftnlen infmtlen; 115 | char *inform; 116 | ftnint informlen; 117 | char *inunf; 118 | ftnlen inunflen; 119 | ftnint *inrecl; 120 | ftnint *innrec; 121 | char *inblank; 122 | ftnlen inblanklen; 123 | } inlist; 124 | 125 | #define VOID void 126 | 127 | union Multitype { /* for multiple entry points */ 128 | integer1 g; 129 | shortint h; 130 | integer i; 131 | /* longint j; */ 132 | real r; 133 | doublereal d; 134 | complex c; 135 | doublecomplex z; 136 | }; 137 | 138 | typedef union Multitype Multitype; 139 | 140 | /*typedef long int Long;*/ /* No longer used; formerly in Namelist */ 141 | 142 | struct Vardesc { /* for Namelist */ 143 | char *name; 144 | char *addr; 145 | ftnlen *dims; 146 | int type; 147 | }; 148 | typedef struct Vardesc Vardesc; 149 | 150 | struct Namelist { 151 | char *name; 152 | Vardesc **vars; 153 | int nvars; 154 | }; 155 | typedef struct Namelist Namelist; 156 | 157 | #define abs(x) ((x) >= 0 ? (x) : -(x)) 158 | #define dabs(x) (doublereal)abs(x) 159 | #define min(a,b) ((a) <= (b) ? (a) : (b)) 160 | #define max(a,b) ((a) >= (b) ? (a) : (b)) 161 | #define dmin(a,b) (doublereal)min(a,b) 162 | #define dmax(a,b) (doublereal)max(a,b) 163 | #define bit_test(a,b) ((a) >> (b) & 1) 164 | #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) 165 | #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) 166 | 167 | /* procedure parameter types for -A and -C++ */ 168 | 169 | #define F2C_proc_par_types 1 170 | #ifdef __cplusplus 171 | typedef int /* Unknown procedure type */ (*U_fp)(...); 172 | typedef shortint (*J_fp)(...); 173 | typedef integer (*I_fp)(...); 174 | typedef real (*R_fp)(...); 175 | typedef doublereal (*D_fp)(...), (*E_fp)(...); 176 | typedef /* Complex */ VOID (*C_fp)(...); 177 | typedef /* Double Complex */ VOID (*Z_fp)(...); 178 | typedef logical (*L_fp)(...); 179 | typedef shortlogical (*K_fp)(...); 180 | typedef /* Character */ VOID (*H_fp)(...); 181 | typedef /* Subroutine */ int (*S_fp)(...); 182 | #else 183 | typedef int /* Unknown procedure type */ (*U_fp)(); 184 | typedef shortint (*J_fp)(); 185 | typedef integer (*I_fp)(); 186 | typedef real (*R_fp)(); 187 | typedef doublereal (*D_fp)(), (*E_fp)(); 188 | typedef /* Complex */ VOID (*C_fp)(); 189 | typedef /* Double Complex */ VOID (*Z_fp)(); 190 | typedef logical (*L_fp)(); 191 | typedef shortlogical (*K_fp)(); 192 | typedef /* Character */ VOID (*H_fp)(); 193 | typedef /* Subroutine */ int (*S_fp)(); 194 | #endif 195 | /* E_fp is for real functions when -R is not specified */ 196 | typedef VOID C_f; /* complex function */ 197 | typedef VOID H_f; /* character function */ 198 | typedef VOID Z_f; /* double complex function */ 199 | typedef doublereal E_f; /* real function with -R not specified */ 200 | 201 | /* undef any lower-case symbols that your C compiler predefines, e.g.: */ 202 | 203 | #ifndef Skip_f2c_Undefs 204 | #undef cray 205 | #undef gcos 206 | #undef mc68010 207 | #undef mc68020 208 | #undef mips 209 | #undef pdp11 210 | #undef sgi 211 | #undef sparc 212 | #undef sun 213 | #undef sun2 214 | #undef sun3 215 | #undef sun4 216 | #undef u370 217 | #undef u3b 218 | #undef u3b2 219 | #undef u3b5 220 | #undef unix 221 | #undef vax 222 | #endif 223 | #endif 224 | /* If you are using a C++ compiler, append the following to f2c.h 225 | for compiling libF77 and libI77. */ 226 | 227 | #ifdef __cplusplus 228 | extern "C" { 229 | extern int abort_(void); 230 | extern double c_abs(complex *); 231 | extern void c_cos(complex *, complex *); 232 | extern void c_div(complex *, complex *, complex *); 233 | extern void c_exp(complex *, complex *); 234 | extern void c_log(complex *, complex *); 235 | extern void c_sin(complex *, complex *); 236 | extern void c_sqrt(complex *, complex *); 237 | extern double d_abs(double *); 238 | extern double d_acos(double *); 239 | extern double d_asin(double *); 240 | extern double d_atan(double *); 241 | extern double d_atn2(double *, double *); 242 | extern void d_cnjg(doublecomplex *, doublecomplex *); 243 | extern double d_cos(double *); 244 | extern double d_cosh(double *); 245 | extern double d_dim(double *, double *); 246 | extern double d_exp(double *); 247 | extern double d_imag(doublecomplex *); 248 | extern double d_int(double *); 249 | extern double d_lg10(double *); 250 | extern double d_log(double *); 251 | extern double d_mod(double *, double *); 252 | extern double d_nint(double *); 253 | extern double d_prod(float *, float *); 254 | extern double d_sign(double *, double *); 255 | extern double d_sin(double *); 256 | extern double d_sinh(double *); 257 | extern double d_sqrt(double *); 258 | extern double d_tan(double *); 259 | extern double d_tanh(double *); 260 | extern double derf_(double *); 261 | extern double derfc_(double *); 262 | extern integer do_fio(ftnint *, char *, ftnlen); 263 | extern integer do_lio(ftnint *, ftnint *, char *, ftnlen); 264 | extern integer do_uio(ftnint *, char *, ftnlen); 265 | extern integer e_rdfe(void); 266 | extern integer e_rdue(void); 267 | extern integer e_rsfe(void); 268 | extern integer e_rsfi(void); 269 | extern integer e_rsle(void); 270 | extern integer e_rsli(void); 271 | extern integer e_rsue(void); 272 | extern integer e_wdfe(void); 273 | extern integer e_wdue(void); 274 | extern integer e_wsfe(void); 275 | extern integer e_wsfi(void); 276 | extern integer e_wsle(void); 277 | extern integer e_wsli(void); 278 | extern integer e_wsue(void); 279 | extern int ef1asc_(ftnint *, ftnlen *, ftnint *, ftnlen *); 280 | extern integer ef1cmc_(ftnint *, ftnlen *, ftnint *, ftnlen *); 281 | extern double erf(double); 282 | extern double erf_(float *); 283 | extern double erfc(double); 284 | extern double erfc_(float *); 285 | extern integer f_back(alist *); 286 | extern integer f_clos(cllist *); 287 | extern integer f_end(alist *); 288 | extern void f_exit(void); 289 | extern integer f_inqu(inlist *); 290 | extern integer f_open(olist *); 291 | extern integer f_rew(alist *); 292 | extern int flush_(void); 293 | extern void getarg_(integer *, char *, ftnlen); 294 | extern void getenv_(char *, char *, ftnlen, ftnlen); 295 | extern short h_abs(short *); 296 | extern short h_dim(short *, short *); 297 | extern short h_dnnt(double *); 298 | extern short h_indx(char *, char *, ftnlen, ftnlen); 299 | extern short h_len(char *, ftnlen); 300 | extern short h_mod(short *, short *); 301 | extern short h_nint(float *); 302 | extern short h_sign(short *, short *); 303 | extern short hl_ge(char *, char *, ftnlen, ftnlen); 304 | extern short hl_gt(char *, char *, ftnlen, ftnlen); 305 | extern short hl_le(char *, char *, ftnlen, ftnlen); 306 | extern short hl_lt(char *, char *, ftnlen, ftnlen); 307 | extern integer i_abs(integer *); 308 | extern integer i_dim(integer *, integer *); 309 | extern integer i_dnnt(double *); 310 | extern integer i_indx(char *, char *, ftnlen, ftnlen); 311 | extern integer i_len(char *, ftnlen); 312 | extern integer i_mod(integer *, integer *); 313 | extern integer i_nint(float *); 314 | extern integer i_sign(integer *, integer *); 315 | extern integer iargc_(void); 316 | extern ftnlen l_ge(char *, char *, ftnlen, ftnlen); 317 | extern ftnlen l_gt(char *, char *, ftnlen, ftnlen); 318 | extern ftnlen l_le(char *, char *, ftnlen, ftnlen); 319 | extern ftnlen l_lt(char *, char *, ftnlen, ftnlen); 320 | extern void pow_ci(complex *, complex *, integer *); 321 | extern double pow_dd(double *, double *); 322 | extern double pow_di(double *, integer *); 323 | extern short pow_hh(short *, shortint *); 324 | extern integer pow_ii(integer *, integer *); 325 | extern double pow_ri(float *, integer *); 326 | extern void pow_zi(doublecomplex *, doublecomplex *, integer *); 327 | extern void pow_zz(doublecomplex *, doublecomplex *, doublecomplex *); 328 | extern double r_abs(float *); 329 | extern double r_acos(float *); 330 | extern double r_asin(float *); 331 | extern double r_atan(float *); 332 | extern double r_atn2(float *, float *); 333 | extern void r_cnjg(complex *, complex *); 334 | extern double r_cos(float *); 335 | extern double r_cosh(float *); 336 | extern double r_dim(float *, float *); 337 | extern double r_exp(float *); 338 | extern double r_imag(complex *); 339 | extern double r_int(float *); 340 | extern double r_lg10(float *); 341 | extern double r_log(float *); 342 | extern double r_mod(float *, float *); 343 | extern double r_nint(float *); 344 | extern double r_sign(float *, float *); 345 | extern double r_sin(float *); 346 | extern double r_sinh(float *); 347 | extern double r_sqrt(float *); 348 | extern double r_tan(float *); 349 | extern double r_tanh(float *); 350 | extern void s_cat(char *, char **, integer *, integer *, ftnlen); 351 | extern integer s_cmp(char *, char *, ftnlen, ftnlen); 352 | extern void s_copy(char *, char *, ftnlen, ftnlen); 353 | extern int s_paus(char *, ftnlen); 354 | extern integer s_rdfe(cilist *); 355 | extern integer s_rdue(cilist *); 356 | extern integer s_rnge(char *, integer, char *, integer); 357 | extern integer s_rsfe(cilist *); 358 | extern integer s_rsfi(icilist *); 359 | extern integer s_rsle(cilist *); 360 | extern integer s_rsli(icilist *); 361 | extern integer s_rsne(cilist *); 362 | extern integer s_rsni(icilist *); 363 | extern integer s_rsue(cilist *); 364 | extern int s_stop(char *, ftnlen); 365 | extern integer s_wdfe(cilist *); 366 | extern integer s_wdue(cilist *); 367 | extern integer s_wsfe(cilist *); 368 | extern integer s_wsfi(icilist *); 369 | extern integer s_wsle(cilist *); 370 | extern integer s_wsli(icilist *); 371 | extern integer s_wsne(cilist *); 372 | extern integer s_wsni(icilist *); 373 | extern integer s_wsue(cilist *); 374 | extern void sig_die(char *, int); 375 | extern integer signal_(integer *, void (*)(int)); 376 | extern integer system_(char *, ftnlen); 377 | extern double z_abs(doublecomplex *); 378 | extern void z_cos(doublecomplex *, doublecomplex *); 379 | extern void z_div(doublecomplex *, doublecomplex *, doublecomplex *); 380 | extern void z_exp(doublecomplex *, doublecomplex *); 381 | extern void z_log(doublecomplex *, doublecomplex *); 382 | extern void z_sin(doublecomplex *, doublecomplex *); 383 | extern void z_sqrt(doublecomplex *, doublecomplex *); 384 | } 385 | #endif 386 | -------------------------------------------------------------------------------- /core/contrib/libf2c.c: -------------------------------------------------------------------------------- 1 | /* Extract from libf2c (11 March 2019) containing only those 2 | routines used by the contributed code. 3 | 4 | Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., 5 | 6 | http://www.netlib.org/f2c/libf2c.zip 7 | */ 8 | 9 | /** \addtogroup DACEContrib Contrib 10 | * @{ 11 | */ 12 | 13 | /// @cond 14 | 15 | #include "f2c.h" 16 | 17 | #undef abs 18 | #include 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | double d_int(const doublereal *x) 23 | { 24 | return( (*x>0) ? floor(*x) : -floor(- *x) ); 25 | } 26 | 27 | double pow_dd(const doublereal *ap, const doublereal *bp) 28 | { 29 | return(pow(*ap, *bp) ); 30 | } 31 | 32 | double pow_di(const doublereal *ap, const integer *bp) 33 | { 34 | double pow, x; 35 | integer n; 36 | unsigned long u; 37 | 38 | pow = 1; 39 | x = *ap; 40 | n = *bp; 41 | 42 | if(n != 0) 43 | { 44 | if(n < 0) 45 | { 46 | n = -n; 47 | x = 1/x; 48 | } 49 | for(u = n; ; ) 50 | { 51 | if(u & 01) 52 | pow *= x; 53 | if(u >>= 1) 54 | x *= x; 55 | else 56 | break; 57 | } 58 | } 59 | return(pow); 60 | } 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | /// @endcond 66 | /** @}*/ 67 | -------------------------------------------------------------------------------- /core/contrib/netlib/change.py: -------------------------------------------------------------------------------- 1 | import sys 2 | with open(sys.argv[1]) as f: 3 | for line in f: 4 | line = line.rstrip() 5 | if line[0:2] == 'CD': 6 | line = ' ' + line[2:].ljust(74,' ') + 'CD' 7 | print( line ) 8 | -------------------------------------------------------------------------------- /core/contrib/netlib/dgamma.f: -------------------------------------------------------------------------------- 1 | CS REAL FUNCTION GAMMA(X) 2 | DOUBLE PRECISION FUNCTION DGAMMA(X) CD 3 | C---------------------------------------------------------------------- 4 | C 5 | C This routine calculates the GAMMA function for a real argument X. 6 | C Computation is based on an algorithm outlined in reference 1. 7 | C The program uses rational functions that approximate the GAMMA 8 | C function to at least 20 significant decimal digits. Coefficients 9 | C for the approximation over the interval (1,2) are unpublished. 10 | C Those for the approximation for X .GE. 12 are from reference 2. 11 | C The accuracy achieved depends on the arithmetic system, the 12 | C compiler, the intrinsic functions, and proper selection of the 13 | C machine-dependent constants. 14 | C 15 | C 16 | C******************************************************************* 17 | C******************************************************************* 18 | C 19 | C Explanation of machine-dependent constants 20 | C 21 | C beta - radix for the floating-point representation 22 | C maxexp - the smallest positive power of beta that overflows 23 | C XBIG - the largest argument for which GAMMA(X) is representable 24 | C in the machine, i.e., the solution to the equation 25 | C GAMMA(XBIG) = beta**maxexp 26 | C XINF - the largest machine representable floating-point number; 27 | C approximately beta**maxexp 28 | C EPS - the smallest positive floating-point number such that 29 | C 1.0+EPS .GT. 1.0 30 | C XMININ - the smallest positive floating-point number such that 31 | C 1/XMININ is machine representable 32 | C 33 | C Approximate values for some important machines are: 34 | C 35 | C beta maxexp XBIG 36 | C 37 | C CRAY-1 (S.P.) 2 8191 966.961 38 | C Cyber 180/855 39 | C under NOS (S.P.) 2 1070 177.803 40 | C IEEE (IBM/XT, 41 | C SUN, etc.) (S.P.) 2 128 35.040 42 | C IEEE (IBM/XT, 43 | C SUN, etc.) (D.P.) 2 1024 171.624 44 | C IBM 3033 (D.P.) 16 63 57.574 45 | C VAX D-Format (D.P.) 2 127 34.844 46 | C VAX G-Format (D.P.) 2 1023 171.489 47 | C 48 | C XINF EPS XMININ 49 | C 50 | C CRAY-1 (S.P.) 5.45E+2465 7.11E-15 1.84E-2466 51 | C Cyber 180/855 52 | C under NOS (S.P.) 1.26E+322 3.55E-15 3.14E-294 53 | C IEEE (IBM/XT, 54 | C SUN, etc.) (S.P.) 3.40E+38 1.19E-7 1.18E-38 55 | C IEEE (IBM/XT, 56 | C SUN, etc.) (D.P.) 1.79D+308 2.22D-16 2.23D-308 57 | C IBM 3033 (D.P.) 7.23D+75 2.22D-16 1.39D-76 58 | C VAX D-Format (D.P.) 1.70D+38 1.39D-17 5.88D-39 59 | C VAX G-Format (D.P.) 8.98D+307 1.11D-16 1.12D-308 60 | C 61 | C******************************************************************* 62 | C******************************************************************* 63 | C 64 | C Error returns 65 | C 66 | C The program returns the value XINF for singularities or 67 | C when overflow would occur. The computation is believed 68 | C to be free of underflow and overflow. 69 | C 70 | C 71 | C Intrinsic functions required are: 72 | C 73 | C INT, DBLE, EXP, LOG, REAL, SIN 74 | C 75 | C 76 | C References: "An Overview of Software Development for Special 77 | C Functions", W. J. Cody, Lecture Notes in Mathematics, 78 | C 506, Numerical Analysis Dundee, 1975, G. A. Watson 79 | C (ed.), Springer Verlag, Berlin, 1976. 80 | C 81 | C Computer Approximations, Hart, Et. Al., Wiley and 82 | C sons, New York, 1968. 83 | C 84 | C Latest modification: October 12, 1989 85 | C 86 | C Authors: W. J. Cody and L. Stoltz 87 | C Applied Mathematics Division 88 | C Argonne National Laboratory 89 | C Argonne, IL 60439 90 | C 91 | C---------------------------------------------------------------------- 92 | INTEGER I,N 93 | LOGICAL PARITY 94 | CS REAL 95 | DOUBLE PRECISION CD 96 | 1 C,CONV,EPS,FACT,HALF,ONE,P,PI,Q,RES,SQRTPI,SUM,TWELVE, 97 | 2 TWO,X,XBIG,XDEN,XINF,XMININ,XNUM,Y,Y1,YSQ,Z,ZERO 98 | DIMENSION C(7),P(8),Q(8) 99 | C---------------------------------------------------------------------- 100 | C Mathematical constants 101 | C---------------------------------------------------------------------- 102 | CS DATA ONE,HALF,TWELVE,TWO,ZERO/1.0E0,0.5E0,12.0E0,2.0E0,0.0E0/, 103 | CS 1 SQRTPI/0.9189385332046727417803297E0/, 104 | CS 2 PI/3.1415926535897932384626434E0/ 105 | DATA ONE,HALF,TWELVE,TWO,ZERO/1.0D0,0.5D0,12.0D0,2.0D0,0.0D0/, CD 106 | 1 SQRTPI/0.9189385332046727417803297D0/, CD 107 | 2 PI/3.1415926535897932384626434D0/ CD 108 | C---------------------------------------------------------------------- 109 | C Machine dependent parameters 110 | C---------------------------------------------------------------------- 111 | CS DATA XBIG,XMININ,EPS/35.040E0,1.18E-38,1.19E-7/, 112 | CS 1 XINF/3.4E38/ 113 | DATA XBIG,XMININ,EPS/171.624D0,2.23D-308,2.22D-16/, CD 114 | 1 XINF/1.79D308/ CD 115 | C---------------------------------------------------------------------- 116 | C Numerator and denominator coefficients for rational minimax 117 | C approximation over (1,2). 118 | C---------------------------------------------------------------------- 119 | CS DATA P/-1.71618513886549492533811E+0,2.47656508055759199108314E+1, 120 | CS 1 -3.79804256470945635097577E+2,6.29331155312818442661052E+2, 121 | CS 2 8.66966202790413211295064E+2,-3.14512729688483675254357E+4, 122 | CS 3 -3.61444134186911729807069E+4,6.64561438202405440627855E+4/ 123 | CS DATA Q/-3.08402300119738975254353E+1,3.15350626979604161529144E+2, 124 | CS 1 -1.01515636749021914166146E+3,-3.10777167157231109440444E+3, 125 | CS 2 2.25381184209801510330112E+4,4.75584627752788110767815E+3, 126 | CS 3 -1.34659959864969306392456E+5,-1.15132259675553483497211E+5/ 127 | DATA P/-1.71618513886549492533811D+0,2.47656508055759199108314D+1, CD 128 | 1 -3.79804256470945635097577D+2,6.29331155312818442661052D+2, CD 129 | 2 8.66966202790413211295064D+2,-3.14512729688483675254357D+4, CD 130 | 3 -3.61444134186911729807069D+4,6.64561438202405440627855D+4/ CD 131 | DATA Q/-3.08402300119738975254353D+1,3.15350626979604161529144D+2, CD 132 | 1 -1.01515636749021914166146D+3,-3.10777167157231109440444D+3, CD 133 | 2 2.25381184209801510330112D+4,4.75584627752788110767815D+3, CD 134 | 3 -1.34659959864969306392456D+5,-1.15132259675553483497211D+5/ CD 135 | C---------------------------------------------------------------------- 136 | C Coefficients for minimax approximation over (12, INF). 137 | C---------------------------------------------------------------------- 138 | CS DATA C/-1.910444077728E-03,8.4171387781295E-04, 139 | CS 1 -5.952379913043012E-04,7.93650793500350248E-04, 140 | CS 2 -2.777777777777681622553E-03,8.333333333333333331554247E-02, 141 | CS 3 5.7083835261E-03/ 142 | DATA C/-1.910444077728D-03,8.4171387781295D-04, CD 143 | 1 -5.952379913043012D-04,7.93650793500350248D-04, CD 144 | 2 -2.777777777777681622553D-03,8.333333333333333331554247D-02, CD 145 | 3 5.7083835261D-03/ CD 146 | C---------------------------------------------------------------------- 147 | C Statement functions for conversion between integer and float 148 | C---------------------------------------------------------------------- 149 | CS CONV(I) = REAL(I) 150 | CONV(I) = DBLE(I) CD 151 | PARITY = .FALSE. 152 | FACT = ONE 153 | N = 0 154 | Y = X 155 | IF (Y .LE. ZERO) THEN 156 | C---------------------------------------------------------------------- 157 | C Argument is negative 158 | C---------------------------------------------------------------------- 159 | Y = -X 160 | Y1 = AINT(Y) 161 | RES = Y - Y1 162 | IF (RES .NE. ZERO) THEN 163 | IF (Y1 .NE. AINT(Y1*HALF)*TWO) PARITY = .TRUE. 164 | FACT = -PI / SIN(PI*RES) 165 | Y = Y + ONE 166 | ELSE 167 | RES = XINF 168 | GO TO 900 169 | END IF 170 | END IF 171 | C---------------------------------------------------------------------- 172 | C Argument is positive 173 | C---------------------------------------------------------------------- 174 | IF (Y .LT. EPS) THEN 175 | C---------------------------------------------------------------------- 176 | C Argument .LT. EPS 177 | C---------------------------------------------------------------------- 178 | IF (Y .GE. XMININ) THEN 179 | RES = ONE / Y 180 | ELSE 181 | RES = XINF 182 | GO TO 900 183 | END IF 184 | ELSE IF (Y .LT. TWELVE) THEN 185 | Y1 = Y 186 | IF (Y .LT. ONE) THEN 187 | C---------------------------------------------------------------------- 188 | C 0.0 .LT. argument .LT. 1.0 189 | C---------------------------------------------------------------------- 190 | Z = Y 191 | Y = Y + ONE 192 | ELSE 193 | C---------------------------------------------------------------------- 194 | C 1.0 .LT. argument .LT. 12.0, reduce argument if necessary 195 | C---------------------------------------------------------------------- 196 | N = INT(Y) - 1 197 | Y = Y - CONV(N) 198 | Z = Y - ONE 199 | END IF 200 | C---------------------------------------------------------------------- 201 | C Evaluate approximation for 1.0 .LT. argument .LT. 2.0 202 | C---------------------------------------------------------------------- 203 | XNUM = ZERO 204 | XDEN = ONE 205 | DO 260 I = 1, 8 206 | XNUM = (XNUM + P(I)) * Z 207 | XDEN = XDEN * Z + Q(I) 208 | 260 CONTINUE 209 | RES = XNUM / XDEN + ONE 210 | IF (Y1 .LT. Y) THEN 211 | C---------------------------------------------------------------------- 212 | C Adjust result for case 0.0 .LT. argument .LT. 1.0 213 | C---------------------------------------------------------------------- 214 | RES = RES / Y1 215 | ELSE IF (Y1 .GT. Y) THEN 216 | C---------------------------------------------------------------------- 217 | C Adjust result for case 2.0 .LT. argument .LT. 12.0 218 | C---------------------------------------------------------------------- 219 | DO 290 I = 1, N 220 | RES = RES * Y 221 | Y = Y + ONE 222 | 290 CONTINUE 223 | END IF 224 | ELSE 225 | C---------------------------------------------------------------------- 226 | C Evaluate for argument .GE. 12.0, 227 | C---------------------------------------------------------------------- 228 | IF (Y .LE. XBIG) THEN 229 | YSQ = Y * Y 230 | SUM = C(7) 231 | DO 350 I = 1, 6 232 | SUM = SUM / YSQ + C(I) 233 | 350 CONTINUE 234 | SUM = SUM/Y - Y + SQRTPI 235 | SUM = SUM + (Y-HALF)*LOG(Y) 236 | RES = EXP(SUM) 237 | ELSE 238 | RES = XINF 239 | GO TO 900 240 | END IF 241 | END IF 242 | C---------------------------------------------------------------------- 243 | C Final adjustments and return 244 | C---------------------------------------------------------------------- 245 | IF (PARITY) RES = -RES 246 | IF (FACT .NE. ONE) RES = FACT / RES 247 | CS900 GAMMA = RES 248 | 900 DGAMMA = RES CD 249 | RETURN 250 | C ---------- Last line of GAMMA ---------- 251 | END 252 | -------------------------------------------------------------------------------- /core/contrib/netlib/psi.f: -------------------------------------------------------------------------------- 1 | FUNCTION PSI(XX) 2 | C---------------------------------------------------------------------- 3 | C 4 | C This function program evaluates the logarithmic derivative of the 5 | C gamma function, 6 | C 7 | C psi(x) = d/dx (gamma(x)) / gamma(x) = d/dx (ln gamma(x)) 8 | C 9 | C for real x, where either 10 | C 11 | C -xmax1 < x < -xmin (x not a negative integer), or 12 | C xmin < x. 13 | C 14 | C The calling sequence for this function is 15 | C 16 | C Y = PSI(X) 17 | C 18 | C The main computation uses rational Chebyshev approximations 19 | C published in Math. Comp. 27, 123-127 (1973) by Cody, Strecok and 20 | C Thacher. This transportable program is patterned after the 21 | C machine-dependent FUNPACK program PSI(X), but cannot match that 22 | C version for efficiency or accuracy. This version uses rational 23 | C approximations that are theoretically accurate to 20 significant 24 | C decimal digits. The accuracy achieved depends on the arithmetic 25 | C system, the compiler, the intrinsic functions, and proper selection 26 | C of the machine-dependent constants. 27 | C 28 | C******************************************************************* 29 | C******************************************************************* 30 | C 31 | C Explanation of machine-dependent constants 32 | C 33 | C XINF = largest positive machine number 34 | C XMAX1 = beta ** (p-1), where beta is the radix for the 35 | C floating-point system, and p is the number of base-beta 36 | C digits in the floating-point significand. This is an 37 | C upper bound on non-integral floating-point numbers, and 38 | C the negative of the lower bound on acceptable negative 39 | C arguments for PSI. If rounding is necessary, round this 40 | C value down. 41 | C XMIN1 = the smallest in magnitude acceptable argument. We 42 | C recommend XMIN1 = MAX(1/XINF,xmin) rounded up, where 43 | C xmin is the smallest positive floating-point number. 44 | C XSMALL = absolute argument below which PI*COTAN(PI*X) may be 45 | C represented by 1/X. We recommend XSMALL < sqrt(3 eps)/pi, 46 | C where eps is the smallest positive number such that 47 | C 1+eps > 1. 48 | C XLARGE = argument beyond which PSI(X) may be represented by 49 | C LOG(X). The solution to the equation 50 | C x*ln(x) = beta ** p 51 | C is a safe value. 52 | C 53 | C Approximate values for some important machines are 54 | C 55 | C beta p eps xmin XINF 56 | C 57 | C CDC 7600 (S.P.) 2 48 7.11E-15 3.13E-294 1.26E+322 58 | C CRAY-1 (S.P.) 2 48 7.11E-15 4.58E-2467 5.45E+2465 59 | C IEEE (IBM/XT, 60 | C SUN, etc.) (S.P.) 2 24 1.19E-07 1.18E-38 3.40E+38 61 | C IEEE (IBM/XT, 62 | C SUN, etc.) (D.P.) 2 53 1.11D-16 2.23E-308 1.79D+308 63 | C IBM 3033 (D.P.) 16 14 1.11D-16 5.40D-79 7.23D+75 64 | C SUN 3/160 (D.P.) 2 53 1.11D-16 2.23D-308 1.79D+308 65 | C VAX 11/780 (S.P.) 2 24 5.96E-08 2.94E-39 1.70E+38 66 | C (D.P.) 2 56 1.39D-17 2.94D-39 1.70D+38 67 | C (G Format) (D.P.) 2 53 1.11D-16 5.57D-309 8.98D+307 68 | C 69 | C XMIN1 XMAX1 XSMALL XLARGE 70 | C 71 | C CDC 7600 (S.P.) 3.13E-294 1.40E+14 4.64E-08 9.42E+12 72 | C CRAY-1 (S.P.) 1.84E-2466 1.40E+14 4.64E-08 9.42E+12 73 | C IEEE (IBM/XT, 74 | C SUN, etc.) (S.P.) 1.18E-38 8.38E+06 1.90E-04 1.20E+06 75 | C IEEE (IBM/XT, 76 | C SUN, etc.) (D.P.) 2.23D-308 4.50D+15 5.80D-09 2.71D+14 77 | C IBM 3033 (D.P.) 1.39D-76 4.50D+15 5.80D-09 2.05D+15 78 | C SUN 3/160 (D.P.) 2.23D-308 4.50D+15 5.80D-09 2.71D+14 79 | C VAX 11/780 (S.P.) 5.89E-39 8.38E+06 1.35E-04 1.20E+06 80 | C (D.P.) 5.89D-39 3.60D+16 2.05D-09 2.05D+15 81 | C (G Format) (D.P.) 1.12D-308 4.50D+15 5.80D-09 2.71D+14 82 | C 83 | C******************************************************************* 84 | C******************************************************************* 85 | C 86 | C Error Returns 87 | C 88 | C The program returns XINF for X < -XMAX1, for X zero or a negative 89 | C integer, or when X lies in (-XMIN1, 0), and returns -XINF 90 | C when X lies in (0, XMIN1). 91 | C 92 | C Intrinsic functions required are: 93 | C 94 | C ABS, AINT, DBLE, INT, LOG, REAL, TAN 95 | C 96 | C 97 | C Author: W. J. Cody 98 | C Mathematics and Computer Science Division 99 | C Argonne National Laboratory 100 | C Argonne, IL 60439 101 | C 102 | C Latest modification: June 8, 1988 103 | C 104 | C---------------------------------------------------------------------- 105 | INTEGER I,N,NQ 106 | CS REAL 107 | DOUBLE PRECISION 108 | 1 AUG,CONV,DEN,PSI,FOUR,FOURTH,HALF,ONE,P1,P2,PIOV4,Q1,Q2, 109 | 2 SGN,THREE,XLARGE,UPPER,W,X,XINF,XMAX1,XMIN1,XSMALL,X01, 110 | 3 X01D,X02,XX,Z,ZERO 111 | DIMENSION P1(9),P2(7),Q1(8),Q2(6) 112 | C---------------------------------------------------------------------- 113 | C Mathematical constants. PIOV4 = pi / 4 114 | C---------------------------------------------------------------------- 115 | CS DATA ZERO,FOURTH,HALF,ONE/0.0E0,0.25E0,0.5E0,1.0E0/ 116 | CS DATA THREE,FOUR/3.0E0,4.0E0/,PIOV4/7.8539816339744830962E-01/ 117 | DATA ZERO,FOURTH,HALF,ONE/0.0D0,0.25D0,0.5D0,1.0D0/ 118 | DATA THREE,FOUR/3.0D0,4.0D0/,PIOV4/7.8539816339744830962D-01/ 119 | C---------------------------------------------------------------------- 120 | C Machine-dependent constants 121 | C---------------------------------------------------------------------- 122 | CS DATA XINF/1.7E+38/, XMIN1/5.89E-39/, XMAX1/8.38E+06/, 123 | CS 1 XSMALL/1.35E-04/, XLARGE/1.20E+06/ 124 | DATA XINF/1.79D+308/, XMIN1/2.23D-308/, XMAX1/4.50D+15/, 125 | 1 XSMALL/5.80D-09/, XLARGE/2.71D+14/ 126 | C---------------------------------------------------------------------- 127 | C Zero of psi(x) 128 | C---------------------------------------------------------------------- 129 | CS DATA X01/187.0E0/,X01D/128.0E0/,X02/6.9464496836234126266E-04/ 130 | DATA X01/187.0D0/,X01D/128.0D0/,X02/6.9464496836234126266D-04/ 131 | C---------------------------------------------------------------------- 132 | C Coefficients for approximation to psi(x)/(x-x0) over [0.5, 3.0] 133 | C---------------------------------------------------------------------- 134 | CS DATA P1/4.5104681245762934160E-03,5.4932855833000385356E+00, 135 | CS 1 3.7646693175929276856E+02,7.9525490849151998065E+03, 136 | CS 2 7.1451595818951933210E+04,3.0655976301987365674E+05, 137 | CS 3 6.3606997788964458797E+05,5.8041312783537569993E+05, 138 | CS 4 1.6585695029761022321E+05/ 139 | CS DATA Q1/9.6141654774222358525E+01,2.6287715790581193330E+03, 140 | CS 1 2.9862497022250277920E+04,1.6206566091533671639E+05, 141 | CS 2 4.3487880712768329037E+05,5.4256384537269993733E+05, 142 | CS 3 2.4242185002017985252E+05,6.4155223783576225996E-08/ 143 | DATA P1/4.5104681245762934160D-03,5.4932855833000385356D+00, 144 | 1 3.7646693175929276856D+02,7.9525490849151998065D+03, 145 | 2 7.1451595818951933210D+04,3.0655976301987365674D+05, 146 | 3 6.3606997788964458797D+05,5.8041312783537569993D+05, 147 | 4 1.6585695029761022321D+05/ 148 | DATA Q1/9.6141654774222358525D+01,2.6287715790581193330D+03, 149 | 1 2.9862497022250277920D+04,1.6206566091533671639D+05, 150 | 2 4.3487880712768329037D+05,5.4256384537269993733D+05, 151 | 3 2.4242185002017985252D+05,6.4155223783576225996D-08/ 152 | C---------------------------------------------------------------------- 153 | C Coefficients for approximation to psi(x) - ln(x) + 1/(2x) 154 | C for x > 3.0 155 | C---------------------------------------------------------------------- 156 | CS DATA P2/-2.7103228277757834192E+00,-1.5166271776896121383E+01, 157 | CS 1 -1.9784554148719218667E+01,-8.8100958828312219821E+00, 158 | CS 2 -1.4479614616899842986E+00,-7.3689600332394549911E-02, 159 | CS 3 -6.5135387732718171306E-21/ 160 | CS DATA Q2/ 4.4992760373789365846E+01, 2.0240955312679931159E+02, 161 | CS 1 2.4736979003315290057E+02, 1.0742543875702278326E+02, 162 | CS 2 1.7463965060678569906E+01, 8.8427520398873480342E-01/ 163 | DATA P2/-2.7103228277757834192D+00,-1.5166271776896121383D+01, 164 | 1 -1.9784554148719218667D+01,-8.8100958828312219821D+00, 165 | 2 -1.4479614616899842986D+00,-7.3689600332394549911D-02, 166 | 3 -6.5135387732718171306D-21/ 167 | DATA Q2/ 4.4992760373789365846D+01, 2.0240955312679931159D+02, 168 | 1 2.4736979003315290057D+02, 1.0742543875702278326D+02, 169 | 2 1.7463965060678569906D+01, 8.8427520398873480342D-01/ 170 | C---------------------------------------------------------------------- 171 | CS CONV(I) = REAL(I) 172 | CONV(I) = DBLE(I) 173 | X = XX 174 | W = ABS(X) 175 | AUG = ZERO 176 | C---------------------------------------------------------------------- 177 | C Check for valid arguments, then branch to appropriate algorithm 178 | C---------------------------------------------------------------------- 179 | IF ((-X .GE. XMAX1) .OR. (W .LT. XMIN1)) THEN 180 | GO TO 410 181 | ELSE IF (X .GE. HALF) THEN 182 | GO TO 200 183 | C---------------------------------------------------------------------- 184 | C X < 0.5, use reflection formula: psi(1-x) = psi(x) + pi * cot(pi*x) 185 | C Use 1/X for PI*COTAN(PI*X) when XMIN1 < |X| <= XSMALL. 186 | C---------------------------------------------------------------------- 187 | ELSE IF (W .LE. XSMALL) THEN 188 | AUG = -ONE / X 189 | GO TO 150 190 | END IF 191 | C---------------------------------------------------------------------- 192 | C Argument reduction for cot 193 | C---------------------------------------------------------------------- 194 | 100 IF (X .LT. ZERO) THEN 195 | SGN = PIOV4 196 | ELSE 197 | SGN = -PIOV4 198 | END IF 199 | W = W - AINT(W) 200 | NQ = INT(W * FOUR) 201 | W = FOUR * (W - CONV(NQ) * FOURTH) 202 | C---------------------------------------------------------------------- 203 | C W is now related to the fractional part of 4.0 * X. 204 | C Adjust argument to correspond to values in the first 205 | C quadrant and determine the sign. 206 | C---------------------------------------------------------------------- 207 | N = NQ / 2 208 | IF ((N+N) .NE. NQ) W = ONE - W 209 | Z = PIOV4 * W 210 | IF (MOD(N,2) .NE. 0) SGN = - SGN 211 | C---------------------------------------------------------------------- 212 | C determine the final value for -pi * cotan(pi*x) 213 | C---------------------------------------------------------------------- 214 | N = (NQ + 1) / 2 215 | IF (MOD(N,2) .EQ. 0) THEN 216 | C---------------------------------------------------------------------- 217 | C Check for singularity 218 | C---------------------------------------------------------------------- 219 | IF (Z .EQ. ZERO) GO TO 410 220 | AUG = SGN * (FOUR / TAN(Z)) 221 | ELSE 222 | AUG = SGN * (FOUR * TAN(Z)) 223 | END IF 224 | 150 X = ONE - X 225 | 200 IF (X .GT. THREE) GO TO 300 226 | C---------------------------------------------------------------------- 227 | C 0.5 <= X <= 3.0 228 | C---------------------------------------------------------------------- 229 | DEN = X 230 | UPPER = P1(1) * X 231 | DO 210 I = 1, 7 232 | DEN = (DEN + Q1(I)) * X 233 | UPPER = (UPPER + P1(I+1)) * X 234 | 210 CONTINUE 235 | DEN = (UPPER + P1(9)) / (DEN + Q1(8)) 236 | X = (X-X01/X01D) - X02 237 | PSI = DEN * X + AUG 238 | GO TO 500 239 | C---------------------------------------------------------------------- 240 | C 3.0 < X 241 | C---------------------------------------------------------------------- 242 | 300 IF (X .LT. XLARGE) THEN 243 | W = ONE / (X * X) 244 | DEN = W 245 | UPPER = P2(1) * W 246 | DO 310 I = 1, 5 247 | DEN = (DEN + Q2(I)) * W 248 | UPPER = (UPPER + P2(I+1)) * W 249 | 310 CONTINUE 250 | AUG = (UPPER + P2(7)) / (DEN + Q2(6)) - HALF / X + AUG 251 | END IF 252 | PSI = AUG + LOG(X) 253 | GO TO 500 254 | C---------------------------------------------------------------------- 255 | C Error return 256 | C---------------------------------------------------------------------- 257 | 410 PSI = XINF 258 | IF (X .GT. ZERO) PSI = -XINF 259 | 500 RETURN 260 | C---------- Last card of PSI ---------- 261 | END 262 | -------------------------------------------------------------------------------- /core/contrib/netlib/zeta.c: -------------------------------------------------------------------------------- 1 | /* zeta.c 2 | * 3 | * Riemann zeta function of two arguments 4 | * 5 | * 6 | * 7 | * SYNOPSIS: 8 | * 9 | * double x, q, y, zeta(); 10 | * 11 | * y = zeta( x, q ); 12 | * 13 | * 14 | * 15 | * DESCRIPTION: 16 | * 17 | * 18 | * 19 | * inf. 20 | * - -x 21 | * zeta(x,q) = > (k+q) 22 | * - 23 | * k=0 24 | * 25 | * where x > 1 and q is not a negative integer or zero. 26 | * The Euler-Maclaurin summation formula is used to obtain 27 | * the expansion 28 | * 29 | * n 30 | * - -x 31 | * zeta(x,q) = > (k+q) 32 | * - 33 | * k=1 34 | * 35 | * 1-x inf. B x(x+1)...(x+2j) 36 | * (n+q) 1 - 2j 37 | * + --------- - ------- + > -------------------- 38 | * x-1 x - x+2j+1 39 | * 2(n+q) j=1 (2j)! (n+q) 40 | * 41 | * where the B2j are Bernoulli numbers. Note that (see zetac.c) 42 | * zeta(x,1) = zetac(x) + 1. 43 | * 44 | * 45 | * 46 | * ACCURACY: 47 | * 48 | * 49 | * 50 | * REFERENCE: 51 | * 52 | * Gradshteyn, I. S., and I. M. Ryzhik, Tables of Integrals, 53 | * Series, and Products, p. 1073; Academic Press, 1980. 54 | * 55 | */ 56 | 57 | /* 58 | Cephes Math Library Release 2.8: June, 2000 59 | Copyright 1984, 1987, 2000 by Stephen L. Moshier 60 | */ 61 | 62 | #include "mconf.h" 63 | #ifdef ANSIPROT 64 | extern double fabs ( double ); 65 | extern double pow ( double, double ); 66 | extern double floor ( double ); 67 | #else 68 | double fabs(), pow(), floor(); 69 | #endif 70 | extern double MAXNUM, MACHEP; 71 | 72 | /* Expansion coefficients 73 | * for Euler-Maclaurin summation formula 74 | * (2k)! / B2k 75 | * where B2k are Bernoulli numbers 76 | */ 77 | static double A[] = { 78 | 12.0, 79 | -720.0, 80 | 30240.0, 81 | -1209600.0, 82 | 47900160.0, 83 | -1.8924375803183791606e9, /*1.307674368e12/691*/ 84 | 7.47242496e10, 85 | -2.950130727918164224e12, /*1.067062284288e16/3617*/ 86 | 1.1646782814350067249e14, /*5.109094217170944e18/43867*/ 87 | -4.5979787224074726105e15, /*8.028576626982912e20/174611*/ 88 | 1.8152105401943546773e17, /*1.5511210043330985984e23/854513*/ 89 | -7.1661652561756670113e18 /*1.6938241367317436694528e27/236364091*/ 90 | }; 91 | /* 30 Nov 86 -- error in third coefficient fixed */ 92 | 93 | 94 | double zeta(x,q) 95 | double x,q; 96 | { 97 | int i; 98 | double a, b, k, s, t, w; 99 | 100 | if( x == 1.0 ) 101 | goto retinf; 102 | 103 | if( x < 1.0 ) 104 | { 105 | domerr: 106 | mtherr( "zeta", DOMAIN ); 107 | return(0.0); 108 | } 109 | 110 | if( q <= 0.0 ) 111 | { 112 | if(q == floor(q)) 113 | { 114 | mtherr( "zeta", SING ); 115 | retinf: 116 | return( MAXNUM ); 117 | } 118 | if( x != floor(x) ) 119 | goto domerr; /* because q^-x not defined */ 120 | } 121 | 122 | /* Euler-Maclaurin summation formula */ 123 | /* 124 | if( x < 25.0 ) 125 | */ 126 | { 127 | /* Permit negative q but continue sum until n+q > +9 . 128 | * This case should be handled by a reflection formula. 129 | * If q<0 and x is an integer, there is a relation to 130 | * the polygamma function. 131 | */ 132 | s = pow( q, -x ); 133 | a = q; 134 | i = 0; 135 | b = 0.0; 136 | while( (i < 9) || (a <= 9.0) ) 137 | { 138 | i += 1; 139 | a += 1.0; 140 | b = pow( a, -x ); 141 | s += b; 142 | if( fabs(b/s) < MACHEP ) 143 | goto done; 144 | } 145 | 146 | w = a; 147 | s += b*w/(x-1.0); 148 | s -= 0.5 * b; 149 | a = 1.0; 150 | k = 0.0; 151 | for( i=0; i<12; i++ ) 152 | { 153 | a *= x + k; 154 | b /= w; 155 | t = a*b/A[i]; 156 | s = s + t; 157 | t = fabs(t/s); 158 | if( t < MACHEP ) 159 | goto done; 160 | k += 1.0; 161 | a *= x + k; 162 | b /= w; 163 | k += 1.0; 164 | } 165 | done: 166 | return(s); 167 | } 168 | 169 | 170 | 171 | /* Basic sum of inverse powers */ 172 | /* 173 | pseres: 174 | 175 | s = pow( q, -x ); 176 | a = q; 177 | do 178 | { 179 | a += 2.0; 180 | b = pow( a, -x ); 181 | s += b; 182 | } 183 | while( b/s > MACHEP ); 184 | 185 | b = pow( 2.0, -x ); 186 | s = (s + b)/(1.0-b); 187 | return(s); 188 | */ 189 | } 190 | -------------------------------------------------------------------------------- /core/contrib/zeta.c: -------------------------------------------------------------------------------- 1 | /* zeta.c 2 | * 3 | * Riemann zeta function of two arguments 4 | * 5 | * 6 | * 7 | * SYNOPSIS: 8 | * 9 | * double x, q, y, zeta(); 10 | * 11 | * y = zeta( x, q ); 12 | * 13 | * 14 | * 15 | * DESCRIPTION: 16 | * 17 | * 18 | * 19 | * inf. 20 | * - -x 21 | * zeta(x,q) = > (k+q) 22 | * - 23 | * k=0 24 | * 25 | * where x > 1 and q is not a negative integer or zero. 26 | * The Euler-Maclaurin summation formula is used to obtain 27 | * the expansion 28 | * 29 | * n 30 | * - -x 31 | * zeta(x,q) = > (k+q) 32 | * - 33 | * k=1 34 | * 35 | * 1-x inf. B x(x+1)...(x+2j) 36 | * (n+q) 1 - 2j 37 | * + --------- - ------- + > -------------------- 38 | * x-1 x - x+2j+1 39 | * 2(n+q) j=1 (2j)! (n+q) 40 | * 41 | * where the B2j are Bernoulli numbers. Note that (see zetac.c) 42 | * zeta(x,1) = zetac(x) + 1. 43 | * 44 | * 45 | * 46 | * ACCURACY: 47 | * 48 | * 49 | * 50 | * REFERENCE: 51 | * 52 | * Gradshteyn, I. S., and I. M. Ryzhik, Tables of Integrals, 53 | * Series, and Products, p. 1073; Academic Press, 1980. 54 | * 55 | */ 56 | 57 | /* 58 | Cephes Math Library Release 2.8: June, 2000 59 | Copyright 1984, 1987, 2000 by Stephen L. Moshier 60 | 61 | Modified interface by Alexander Wittig, November 2019. 62 | */ 63 | 64 | /** \addtogroup DACEContrib Contrib 65 | * @{ 66 | */ 67 | 68 | /// @cond 69 | 70 | #include 71 | 72 | /* Expansion coefficients 73 | * for Euler-Maclaurin summation formula 74 | * (2k)! / B2k 75 | * where B2k are Bernoulli numbers 76 | */ 77 | static double A[] = { 78 | 12.0, 79 | -720.0, 80 | 30240.0, 81 | -1209600.0, 82 | 47900160.0, 83 | -1.8924375803183791606e9, /*1.307674368e12/691*/ 84 | 7.47242496e10, 85 | -2.950130727918164224e12, /*1.067062284288e16/3617*/ 86 | 1.1646782814350067249e14, /*5.109094217170944e18/43867*/ 87 | -4.5979787224074726105e15, /*8.028576626982912e20/174611*/ 88 | 1.8152105401943546773e17, /*1.5511210043330985984e23/854513*/ 89 | -7.1661652561756670113e18 /*1.6938241367317436694528e27/236364091*/ 90 | }; 91 | /* 30 Nov 86 -- error in third coefficient fixed */ 92 | 93 | static const double MACHEP = 1.11022302462515654042E-16; 94 | 95 | double zeta_(const double x, const double q, unsigned int *err) 96 | { 97 | double a, b, k, s, t, w; 98 | 99 | if( err ) *err = 0; 100 | 101 | if( x == 1.0 ) 102 | goto retinf; 103 | 104 | if( x < 1.0 ) 105 | { 106 | domerr: 107 | if( err ) *err = 1; 108 | return(NAN); 109 | } 110 | 111 | if( q <= 0.0 ) 112 | { 113 | if(q == floor(q)) 114 | { 115 | retinf: 116 | if( err ) *err = 2; 117 | return(INFINITY); 118 | } 119 | if( x != floor(x) ) 120 | goto domerr; /* because q^-x not defined */ 121 | } 122 | 123 | /* Euler-Maclaurin summation formula */ 124 | /* Permit negative q but continue sum until n+q > +9 . 125 | * This case should be handled by a reflection formula. 126 | * If q<0 and x is an integer, there is a relation to 127 | * the polygamma function. 128 | */ 129 | s = pow( q, -x ); 130 | a = q; 131 | b = 0.0; 132 | for( unsigned int i = 0; (i < 9) || (a <= 9.0); i++ ) 133 | { 134 | a += 1.0; 135 | b = pow( a, -x ); 136 | s += b; 137 | if( fabs(b/s) < MACHEP ) 138 | goto done; 139 | } 140 | 141 | w = a; 142 | s += b*w/(x-1.0); 143 | s -= 0.5 * b; 144 | a = 1.0; 145 | k = 0.0; 146 | for( unsigned int i=0; i<12; i++ ) 147 | { 148 | a *= x + k; 149 | b /= w; 150 | t = a*b/A[i]; 151 | s = s + t; 152 | if( fabs(t/s) < MACHEP ) 153 | goto done; 154 | k += 1.0; 155 | a *= x + k; 156 | b /= w; 157 | k += 1.0; 158 | } 159 | done: 160 | return(s); 161 | } 162 | 163 | /// @endcond 164 | /** @}*/ 165 | -------------------------------------------------------------------------------- /core/dacecompat.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * dacecompat.c 24 | * 25 | * Created on: November 18, 2016 26 | * Author: Politecnico di Milano 27 | */ 28 | 29 | /** \addtogroup DACE Core 30 | * @{ 31 | */ 32 | 33 | #include "dace/config.h" 34 | #include "dace/dacebase.h" 35 | #include "dace/dacecompat.h" 36 | #include "dace/daceaux.h" 37 | 38 | /******************************************************************************** 39 | * Compatibility shims to bridge old and new interface 40 | *********************************************************************************/ 41 | 42 | /*! Return the number of non-zero monomials in a DA object. 43 | \param[in] ina Pointer to DA object to get length of 44 | \param[out] size Number of non-zero monomials 45 | \deprecated Has been renamed to daceGetLength() 46 | \sa daceGetLength() 47 | */ 48 | void dacesize(const DACEDA *ina, unsigned int *size) 49 | { 50 | *size = daceGetLength(ina); 51 | } 52 | 53 | /*! Extract coefficient of a monomial in a DA object. 54 | \param[in] ina Pointer to DA object to extract monomial coefficient from 55 | \param[in] jj C array of nvmax exponents identifying the monomial 56 | \param[out] cjj Pointer where to store the value of the coefficient 57 | \deprecated Has been replaced by daceGetCoefficient() 58 | \sa daceGetCoefficient() 59 | */ 60 | void dacepek(const DACEDA *ina, const unsigned int jj[], double *cjj) 61 | { 62 | *cjj = daceGetCoefficient0(ina, daceEncode(jj)); 63 | } 64 | 65 | /*! Compute absolute value of a DA object. 66 | \param[in] ina Pointer to DA object to take absolute value of 67 | \param[out] anorm Pointer where to store the absolute value 68 | \deprecated Has been replaced by daceAbsoluteValue() 69 | \sa daceAbsoluteValue() 70 | */ 71 | void daceabs(const DACEDA *ina, double *anorm) 72 | { 73 | *anorm = daceAbsoluteValue(ina); 74 | } 75 | 76 | /*! Compute absolute value of a DA object. 77 | \param[in] ina Pointer to DA object to take norm of 78 | \param[in] ityp Type of norm to take (see daceNorm()) 79 | \param[out] anorm Pointer where to store the norm 80 | \deprecated Has been replaced by daceNorm() 81 | \sa daceNorm() 82 | */ 83 | void dacenorm(const DACEDA *ina, const unsigned int ityp, double *anorm) 84 | { 85 | *anorm = daceNorm(ina, ityp); 86 | } 87 | 88 | /*! Compute an evaluation tree for efficient evaluation of DA objects. 89 | \param[in] das Pointers to DA objects to evaluate 90 | \param[in] count Number of DA objects in das[] 91 | \param[out] ac C array containing compiled evaluation tree data 92 | \param[out] nterm resulting number of terms in evaluation tree 93 | \param[out] nvar number of variables appearing in evaluation tree 94 | \param[out] nord maximum order appearing in evaluation tree 95 | \deprecated Has been replaced by daceEvalTree() 96 | \sa daceEvalTree() 97 | */ 98 | void dacetree(const DACEDA das[], const unsigned int count, double ac[], unsigned int *nterm, unsigned int *nvar, unsigned int *nord) 99 | { 100 | #if DACE_MEMORY_MODEL == DACE_MEMORY_STATIC 101 | if(count > 10*DACE_STATIC_NVMAX) 102 | { 103 | daceSetError("dacetree: number of DAs too high", DACE_ERROR, 111); 104 | return; 105 | } 106 | const DACEDA *temp[10*DACE_STATIC_NVMAX]; 107 | #else 108 | const DACEDA **temp = dacecalloc(count, sizeof(const DACEDA *)); 109 | #endif 110 | for(unsigned int i = 0; i < count; i++) temp[i] = &das[i]; 111 | daceEvalTree(temp, count, ac, nterm, nvar, nord); 112 | #if DACE_MEMORY_MODEL != DACE_MEMORY_STATIC 113 | dacefree((void*)temp); 114 | #endif 115 | } 116 | /** @}*/ 117 | -------------------------------------------------------------------------------- /core/daceerror.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * daceerror.c 24 | * 25 | * Created on: November 18, 2016 26 | * Author: Politecnico di Milano 27 | */ 28 | 29 | /** \addtogroup DACE Core 30 | * @{ 31 | */ 32 | 33 | // indicate that we want to use strXXX_s functions, if available 34 | #define __STDC_WANT_LIB_EXT1__ 1 35 | #include 36 | #include 37 | 38 | #include "dace/config.h" 39 | #include "dace/dacebase.h" 40 | #include "dace/daceaux.h" 41 | #include "dace/daceerror.h" 42 | 43 | 44 | /******************************************************************************** 45 | * DACE error state routine 46 | ********************************************************************************/ 47 | 48 | /*! Return the current error XYY code. 49 | \return The error code in XYY form 50 | \sa daceerror.h 51 | */ 52 | unsigned int daceGetError() 53 | { 54 | return DACEDbg.ierr; 55 | } 56 | 57 | /*! Return the current error X code. 58 | \return The X error code X 59 | \sa daceerror.h 60 | */ 61 | unsigned int daceGetErrorX() 62 | { 63 | return DACEDbg.ixerr; 64 | } 65 | 66 | /*! Return the current error YY code. 67 | \return The YY error code 68 | \sa daceerror.h 69 | */ 70 | unsigned int daceGetErrorYY() 71 | { 72 | return DACEDbg.iyyerr; 73 | } 74 | 75 | /*! Return the function name of current generated error. 76 | \return The function name originating the error. 77 | */ 78 | const char* daceGetErrorFunName() 79 | { 80 | return DACEDbg.name; 81 | } 82 | 83 | /*! Return the current error message. 84 | \return The current error message string 85 | \sa daceerror.h 86 | */ 87 | const char* daceGetErrorMSG() 88 | { 89 | return DACEDbg.msg; 90 | } 91 | 92 | /* *********************** 93 | * 94 | * THIS SUBROUTINE CLEARS THE ERROR STATE. 95 | * Should be called by the interface once the error has been corrected 96 | * 97 | */ 98 | /*! Clear the error code. 99 | */ 100 | void daceClearError() 101 | { 102 | DACEDbg.ierr = 0; 103 | DACEDbg.ixerr = 0; 104 | DACEDbg.iyyerr = 0; 105 | *DACEDbg.name = '\0'; 106 | *DACEDbg.msg = '\0'; 107 | } 108 | 109 | /*! This subroutine serves as an error handler for errors within the dace. 110 | It is intended mostly for development and debugging. More descriptive error messages should be 111 | displayed by the user interface. 112 | 113 | The error codes are defined as XYY with X indicating the severity and 114 | YY corresponding to the actual error code 115 | 116 | Severity Levels X 117 | 118 | 1 = Info: Informative, no action required 119 | 120 | 3 = Warning: Serious, possibly incorrect use of DACE routines 121 | 122 | 6 = Error: Recoverable, result may not be correct or assumptions have 123 | been made 124 | 125 | 9 = Error: Unrecoverable, new call to DACEINI is required to 126 | reinitialize DACE, DACE objects are no longer valid 127 | 128 | 10 = Critical: Crash in the DACE, just printing as much as possible 129 | and dying 130 | 131 | Currently used error codes XYY are defined in daceerror.h 132 | 133 | \param[in] c an error string representing the error 134 | \param[in] ix is the error severity code 135 | \param[in] iyy is the error code 136 | \sa daceerror.h 137 | */ 138 | 139 | void daceSetError(const char *c, const unsigned int ix, const unsigned int iyy) 140 | { 141 | // check if it is a critical error 142 | if(ix == DACE_PANIC) 143 | { 144 | fprintf(stderr, "DACE critical error %u in %s:\n%s\nbye bye!\n", DACEerr[iyy].ID, c, DACEerr[iyy].msg); 145 | exit(1); 146 | } 147 | else 148 | { 149 | if(ix > DACEDbg.ixerr) 150 | { 151 | DACEDbg.ierr = ix*100+iyy; // set error code xyy 152 | DACEDbg.ixerr = ix; 153 | DACEDbg.iyyerr = iyy; 154 | #ifdef HAVE_SAFE_STRINGS 155 | strncpy_s(DACEDbg.name, ERROR_FUN_SIZE, c, ERROR_FUN_SIZE-1); 156 | strncpy_s(DACEDbg.msg, ERROR_MSG_SIZE, c, ERROR_MSG_SIZE-1); 157 | strncat_s(DACEDbg.msg, ERROR_MSG_SIZE, ": ", ERROR_MSG_SIZE-strnlen_s(DACEDbg.msg, ERROR_MSG_SIZE)-1); 158 | strncat_s(DACEDbg.msg, ERROR_MSG_SIZE, DACEerr[DACEDbg.iyyerr].msg, ERROR_MSG_SIZE-strnlen_s(DACEDbg.msg, ERROR_MSG_SIZE)-1); 159 | #else 160 | strncpy(DACEDbg.name, c, ERROR_FUN_SIZE-1); DACEDbg.name[ERROR_FUN_SIZE-1] = '\0'; 161 | strncpy(DACEDbg.msg, c, ERROR_MSG_SIZE-1); DACEDbg.msg[ERROR_MSG_SIZE-1] = '\0'; 162 | strncat(DACEDbg.msg, ": ", ERROR_MSG_SIZE-strnlen(DACEDbg.msg, ERROR_MSG_SIZE)-1); 163 | strncat(DACEDbg.msg, DACEerr[DACEDbg.iyyerr].msg, ERROR_MSG_SIZE-strnlen(DACEDbg.msg, ERROR_MSG_SIZE)-1); 164 | #endif 165 | } 166 | } 167 | } 168 | /** @}*/ 169 | -------------------------------------------------------------------------------- /core/dacenorm.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * dacenorm.c 24 | * 25 | * Created on: November 18, 2016 26 | * Author: Politecnico di Milano 27 | */ 28 | 29 | /** \addtogroup DACE Core 30 | * @{ 31 | */ 32 | 33 | #include 34 | #include 35 | 36 | #include "dace/config.h" 37 | #include "dace/dacebase.h" 38 | #include "dace/daceaux.h" 39 | 40 | 41 | /******************************************************************************** 42 | * DACE norm and norm estimation routines 43 | *********************************************************************************/ 44 | 45 | /*! Compute the absolute value (maximum coefficient norm) of a DA object. 46 | \param[in] ina Pointer to the DA object to take absolute value of 47 | \return The absolute value of ina 48 | */ 49 | double daceAbsoluteValue(const DACEDA *ina) 50 | { 51 | return daceNorm(ina, 0); 52 | } 53 | 54 | /*! Compute a norm of a DA object. 55 | \param[in] ina Pointer to the DA object to take norm of 56 | \param[in] ityp Type of norm to compute. 57 | 0 = max norm 58 | 1 = sum norm 59 | >1 = corresponding vector norm 60 | \return The norm of ina 61 | */ 62 | double daceNorm(const DACEDA *ina, const unsigned int ityp) 63 | { 64 | monomial *ipoa; unsigned int ilma, illa; 65 | double anorm = 0.0; 66 | 67 | daceVariableInformation(ina, &ipoa, &ilma, &illa); 68 | 69 | if(ityp == 0) 70 | { 71 | // max norm 72 | for(monomial *i = ipoa; i < ipoa+illa; i++) 73 | anorm = fmax(anorm, fabs(i->cc)); 74 | } 75 | else if(ityp == 1) 76 | { 77 | // sum norm 78 | for(monomial *i = ipoa; i < ipoa+illa; i++) 79 | anorm += fabs(i->cc); 80 | } 81 | else 82 | { 83 | // ityp vector norm 84 | for(monomial *i = ipoa; i < ipoa+illa; i++) 85 | anorm += pown(fabs(i->cc), ityp); 86 | anorm = pow(anorm, 1.0/ityp); 87 | } 88 | return anorm; 89 | } 90 | 91 | /*! Compute an order sorted norm of a DA object. 92 | \param[in] ina Pointer to the DA object to take norm of 93 | \param[in] ivar Independent variable with respect to which to group. 94 | 0 = group by monomial order 95 | >1 = group by given independent variable 96 | \param[in] ityp Type of norm to compute. 97 | 0 = max norm 98 | 1 = sum norm 99 | >1 = corresponding vector norm 100 | \param[out] onorm C array of length nomax+1 containing the grouped estimates 101 | */ 102 | void daceOrderedNorm(const DACEDA *ina, const unsigned int ivar, const unsigned int ityp, double onorm[]) 103 | { 104 | monomial *ipoa; unsigned int ilma, illa; 105 | 106 | daceVariableInformation(ina, &ipoa, &ilma, &illa); 107 | for(unsigned int i = 0; i <= DACECom.nomax; i++) onorm[i] = 0.0; 108 | 109 | if(ivar > DACECom.nvmax) 110 | { 111 | daceSetError(__func__, DACE_ERROR, 24); 112 | return; 113 | } 114 | 115 | if(ivar == 0) 116 | { 117 | if(ityp == 0) 118 | { 119 | // max norm 120 | for(monomial *i = ipoa; i < ipoa+illa; i++ ) 121 | { 122 | const unsigned int io = DACECom.ieo[i->ii]; 123 | onorm[io] = fmax(onorm[io], fabs(i->cc)); 124 | } 125 | } 126 | else if(ityp == 1) 127 | { 128 | // sum norm 129 | for(monomial *i = ipoa; i < ipoa+illa; i++ ) 130 | { 131 | const unsigned int io = DACECom.ieo[i->ii]; 132 | onorm[io] += fabs(i->cc); 133 | } 134 | } 135 | else 136 | { 137 | // ityp vector norm 138 | for(monomial *i = ipoa; i < ipoa+illa; i++ ) 139 | { 140 | const unsigned int io = DACECom.ieo[i->ii]; 141 | onorm[io] += pown(fabs(i->cc), ityp); 142 | } 143 | for(unsigned int i = 0; i <= DACECom.nomax; i++) 144 | onorm[i] = pow(onorm[i], 1.0/ityp); 145 | } 146 | } 147 | else 148 | { 149 | #if DACE_MEMORY_MODEL == DACE_MEMORY_STATIC 150 | unsigned int jj[DACE_STATIC_NVMAX]; 151 | #else 152 | unsigned int *jj = (unsigned int*)dacecalloc(DACECom.nvmax, sizeof(unsigned int)); 153 | #endif 154 | 155 | if(ityp == 0) 156 | { 157 | // max norm 158 | for(monomial *i = ipoa; i < ipoa+illa; i++ ) 159 | { 160 | daceDecode(i->ii, jj); 161 | onorm[jj[ivar-1]] = fmax(onorm[jj[ivar-1]], fabs(i->cc)); 162 | } 163 | } 164 | else if(ityp == 1) 165 | { 166 | // sum norm 167 | for(monomial *i = ipoa; i < ipoa+illa; i++ ) 168 | { 169 | daceDecode(i->ii, jj); 170 | onorm[jj[ivar-1]] += fabs(i->cc); 171 | } 172 | } 173 | else 174 | { 175 | // ityp vector norm 176 | for(monomial *i = ipoa; i < ipoa+illa; i++ ) 177 | { 178 | daceDecode(i->ii, jj); 179 | onorm[jj[ivar-1]] += pown(fabs(i->cc), ityp); 180 | } 181 | for(unsigned int i = 0; i <= DACECom.nomax; i++) 182 | onorm[i] = pow(onorm[i], 1.0/ityp); 183 | } 184 | 185 | #if DACE_MEMORY_MODEL != DACE_MEMORY_STATIC 186 | dacefree(jj); 187 | #endif 188 | } 189 | } 190 | 191 | /*! Estimate order sorted norms of DA object ina up to given order. 192 | \param[in] ina Pointer to the DA object to take norm of 193 | \param[in] ivar Independent variable with respect to which to group. 194 | 0 = group by monomial order 195 | >1 = group by given independent variable 196 | \param[in] ityp Type of norm to compute. 197 | 0 = max norm 198 | 1 = sum norm 199 | >1 = corresponding vector norm 200 | \param[in] nc Maximum order to estimate 201 | \param[out] c C array of length nc+1 containing the grouped estimates 202 | \param[out] err C array of length min(nc, nomax)+1 containing the residuals 203 | of the exponential fit at each order. If NULL is passed in, no residuals 204 | are computed and returned. 205 | \note If estimation is not possible, zero is returned for all 206 | requested orders. In most cases this is actually not too far off. 207 | */ 208 | void daceEstimate(const DACEDA *ina, const unsigned int ivar, const unsigned int ityp, double c[], double err[], const unsigned int nc) 209 | { 210 | for(unsigned int i = 0; i <= nc; i++) c[i] = 0.0; 211 | 212 | // check input 213 | if(DACECom.nomax < 2) 214 | { 215 | daceSetError(__func__, DACE_ERROR, 51); 216 | return; 217 | } 218 | 219 | // get order sorted norms 220 | #if DACE_MEMORY_MODEL == DACE_MEMORY_STATIC 221 | double onorm[DACE_STATIC_NOMAX+1]; 222 | #else 223 | double *onorm = (double*)dacecalloc(DACECom.nomax+1, sizeof(double)); 224 | #endif 225 | daceOrderedNorm(ina, ivar, ityp, onorm); 226 | 227 | // set up xtx^-1 and xty for linear least squares 228 | double ai[2] = {0.0}; 229 | double xtx[2][2] = {{0.0}, {0.0}}; 230 | for(unsigned int i = 1; i <= DACECom.nomax; i++) 231 | { 232 | if(!(onorm[i] <= DACECom_t.eps)) 233 | { 234 | xtx[0][0] += i*i; 235 | xtx[0][1] -= i; 236 | xtx[1][1]++; 237 | ai[0] += log(onorm[i]); 238 | ai[1] += i*log(onorm[i]); 239 | } 240 | } 241 | 242 | if(xtx[1][1] < 2) 243 | { 244 | daceSetError(__func__, DACE_INFO, 63); 245 | #if DACE_MEMORY_MODEL != DACE_MEMORY_STATIC 246 | dacefree(onorm); 247 | #endif 248 | return; 249 | } 250 | 251 | xtx[1][0] = xtx[0][1]; 252 | const double det = xtx[0][0]*xtx[1][1]-xtx[0][1]*xtx[1][0]; 253 | 254 | // compute ai=(xtx^-1)(xty) 255 | double a[2]; 256 | a[0] = (ai[0]*xtx[0][0]+ai[1]*xtx[0][1])/det; 257 | a[1] = (ai[0]*xtx[1][0]+ai[1]*xtx[1][1])/det; 258 | 259 | // actually compute the order sorted norm estimates 260 | for(unsigned int i = 0; i <= nc; i++) 261 | c[i] = exp(a[0]+a[1]*i); 262 | 263 | // compute estimation error, if requested 264 | if(err != NULL) 265 | for(unsigned int i = 0; i <= umin(DACECom.nomax, nc); i++) 266 | { 267 | const double temp = onorm[i]-c[i]; 268 | err[i] = temp > 0.0 ? temp : 0.0; 269 | } 270 | 271 | #if DACE_MEMORY_MODEL != DACE_MEMORY_STATIC 272 | dacefree(onorm); 273 | #endif 274 | } 275 | 276 | /*! Compute an upper and lower bound of DA object ina over the domain [-1,1]^n. 277 | \param[in] ina Pointer to the DA object to bound 278 | \param[out] alo Pointer where to store the lower bound 279 | \param[out] aup Pointer where to store the upper bound 280 | */ 281 | void daceGetBounds(const DACEDA *ina, double *alo, double *aup) 282 | { 283 | monomial *ipoa; unsigned int ilma, illa; 284 | daceVariableInformation(ina, &ipoa, &ilma, &illa); 285 | 286 | // check special cases 287 | *alo = 0.0; 288 | *aup = 0.0; 289 | if(illa == 0) return; 290 | 291 | // constant part is special 292 | if(ipoa->ii == 0) 293 | { 294 | *alo = ipoa->cc; 295 | *aup = *alo; 296 | ipoa++; 297 | illa--; 298 | } 299 | 300 | #if DACE_MEMORY_MODEL == DACE_MEMORY_STATIC 301 | unsigned int jj[DACE_STATIC_NVMAX]; 302 | #else 303 | unsigned int *jj = (unsigned int*)dacecalloc(DACECom.nvmax, sizeof(unsigned int)); 304 | #endif 305 | 306 | // bound each non-constant term 307 | for(monomial *i = ipoa; i < ipoa+illa; i++) 308 | { 309 | daceDecode(i->ii, jj); 310 | bool odd = false; 311 | for(unsigned int j = 0; j < DACECom.nvmax; j++) 312 | { 313 | if(jj[j] & 1) 314 | { 315 | odd = true; 316 | break; 317 | } 318 | } 319 | 320 | if(odd) 321 | { 322 | *aup += fabs(i->cc); 323 | *alo -= fabs(i->cc); 324 | } 325 | else 326 | { 327 | if(i->cc > 0.0) 328 | *aup += i->cc; 329 | else 330 | *alo += i->cc; 331 | } 332 | } 333 | 334 | #if DACE_MEMORY_MODEL != DACE_MEMORY_STATIC 335 | dacefree(jj); 336 | #endif 337 | } 338 | /** @}*/ 339 | -------------------------------------------------------------------------------- /core/include/dace/config.h.in: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * config.h 24 | * 25 | * Created on: July 19, 2018 26 | * Author: University of Southampton 27 | */ 28 | 29 | /* 30 | This file contains the build time configuration options used for building the DACE library. 31 | */ 32 | /** \addtogroup DACE Core 33 | * @{ 34 | */ 35 | 36 | #ifndef DINAMICA_CONFIG_H_ 37 | #define DINAMICA_CONFIG_H_ 38 | 39 | #define DACE_MAJOR_VERSION @DACE_MAJOR_VERSION@ 40 | #define DACE_MINOR_VERSION @DACE_MINOR_VERSION@ 41 | #define DACE_PATCH_VERSION @DACE_PATCH_VERSION@ 42 | 43 | #define DACE_MEMORY_HYBRID 1 44 | #define DACE_MEMORY_STATIC 2 45 | #define DACE_MEMORY_DYNAMIC 3 46 | #define DACE_MEMORY_MODEL DACE_MEMORY_@DACE_MEMORY_MODEL_U@ 47 | #define DACE_MEMORY_MODEL_STR "@DACE_MEMORY_MODEL_U@" 48 | 49 | #cmakedefine WITH_DEBUG 50 | #cmakedefine WITH_ALGEBRAICMATRIX 51 | #cmakedefine WITH_PTHREAD 52 | 53 | // automatically detected function availability at library build time 54 | #cmakedefine HAVE_SAFE_STRINGS 55 | 56 | // The following limits are only used when *building* the DACE library with DACE_MEMORY_STATIC memory model. 57 | // They are repeated here merely for reference and do not change the available memory in the library 58 | // unless the library is recompiled. 59 | #if DACE_MEMORY_MODEL == DACE_MEMORY_STATIC 60 | // Maximum order and maximum variables supported independently of each other 61 | #cmakedefine DACE_STATIC_NOMAX @DACE_STATIC_NOMAX@ 62 | #cmakedefine DACE_STATIC_NVMAX @DACE_STATIC_NVMAX@ 63 | // Maximum number of monomials supported in any NO, NV pair 64 | #cmakedefine DACE_STATIC_NMMAX @DACE_STATIC_NMMAX@ 65 | #cmakedefine DACE_STATIC_LIAMAX @DACE_STATIC_LIAMAX@ 66 | // maximum number of DA variables and memory size 67 | #cmakedefine DACE_STATIC_VAR_SIZE @DACE_STATIC_VAR_SIZE@ 68 | #cmakedefine DACE_STATIC_MEM_SIZE @DACE_STATIC_MEM_SIZE@ 69 | #endif 70 | 71 | // On Windows, set the default DACE_API to import from a DLL for dynamic linking 72 | #ifndef DACE_API 73 | #if defined _WIN32 || defined __CYGWIN__ 74 | #define DACE_API __declspec(dllimport) 75 | #else 76 | #define DACE_API 77 | #endif 78 | #endif 79 | 80 | // Define DACE_THREAD_LOCAL decorator for thread local variable storage 81 | #ifdef WITH_PTHREAD 82 | #ifdef _WIN32 83 | #define DACE_THREAD_LOCAL __declspec(thread) 84 | #else 85 | #define DACE_THREAD_LOCAL __thread 86 | #endif 87 | #else 88 | // just treat thread local stuff as normal variables 89 | #define DACE_THREAD_LOCAL 90 | #endif 91 | 92 | /** @}*/ 93 | #endif /* DINAMICA_CONFIG_H_ */ 94 | -------------------------------------------------------------------------------- /core/include/dace/daceaux.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * daceaux.h 24 | * 25 | * Created on: November 18, 2016 26 | * Author: Politecnico di Milano 27 | */ 28 | 29 | /* 30 | This file contains all internal DACE auxiliary functions used by the DACE core. 31 | It is not meant to be included publicly by DACE users or high level interfaces. 32 | */ 33 | /** \addtogroup DACE Core 34 | * @{ 35 | */ 36 | 37 | #ifndef DINAMICA_DACEAUX_H_ 38 | #define DINAMICA_DACEAUX_H_ 39 | 40 | #include // for size_t 41 | #include // for bool 42 | #include 43 | 44 | #include "dace/config.h" 45 | 46 | // macro to help tell supported compiler which branch is most likely 47 | #if __GNUC__ || __clang__ 48 | #define UNLIKELY(expr) __builtin_expect(!!(expr), 0) 49 | #define LIKELY(expr) __builtin_expect(!!(expr), 1) 50 | #else 51 | #define UNLIKELY(expr) expr 52 | #define LIKELY(expr) expr 53 | #endif 54 | 55 | // DACE internal data structure 56 | typedef struct dcom { 57 | unsigned int *ie1, *ie2, *ieo, *ia1, *ia2; 58 | unsigned int nomax, nvmax, nv1, nv2, nmmax; 59 | double epsmac; 60 | } dacecom; 61 | 62 | // DACE thread local data structure 63 | typedef struct dcom_t { 64 | unsigned int nocut; 65 | double eps; 66 | #ifdef DACE_FILTERING 67 | unsigned int *ifi; 68 | unsigned int lfi; 69 | #endif 70 | } dacecom_t; 71 | 72 | #define ERROR_FUN_SIZE 64 73 | #define ERROR_MSG_SIZE 256 74 | // DACE error management 75 | typedef struct ddbg { 76 | unsigned int ierr, ixerr, iyyerr; 77 | char name[ERROR_FUN_SIZE]; 78 | char msg[ERROR_MSG_SIZE]; 79 | } dacedbg; 80 | 81 | // Basic memory structure of a monomial 82 | typedef struct dmonomial { 83 | double cc; 84 | unsigned int ii; 85 | } monomial; 86 | 87 | // Basic memory structure of an extended monomial (these are written and read from binary files, so enforce no padding!) 88 | #pragma pack(push,1) 89 | typedef struct dextendedmonomial { 90 | unsigned int i1, i2; 91 | double cc; 92 | } extended_monomial; 93 | #pragma pack(pop) 94 | 95 | // 32 bit magic marker to identify beginning of binary DACE blobs (in little endian the letters DA0 and the record separator 1E) 96 | #define DACE_BINARY_MAGIC (0x1E304144) 97 | 98 | // Memory structure of a DACE blob (not public!) 99 | #pragma pack(push,1) 100 | struct daceblob { 101 | unsigned int magic; 102 | unsigned int no, nv1, nv2, len; 103 | extended_monomial monomials[1]; 104 | }; 105 | #pragma pack(pop) 106 | 107 | // external global symbols for common DACE structures (actually allocated in dacememory.c) 108 | extern dacecom DACECom; 109 | extern DACE_THREAD_LOCAL dacecom_t DACECom_t; 110 | extern DACE_THREAD_LOCAL dacedbg DACEDbg; 111 | 112 | /// @cond 113 | // math utility routines 114 | unsigned int umin(const unsigned int a, const unsigned int b); 115 | unsigned int umax(const unsigned int a, const unsigned int b); 116 | double pown(double a, unsigned int b); 117 | int npown(int a, unsigned int b); 118 | 119 | #if DACE_MEMORY_MODEL == DACE_MEMORY_HYBRID || DACE_MEMORY_MODEL == DACE_MEMORY_DYNAMIC 120 | // dynamic memory allocation wrappers 121 | void* dacecalloc(size_t count, size_t size); 122 | void* dacemalloc(size_t size); 123 | void* dacemalloc0(size_t size); 124 | void* dacerealloc(void* ptr, size_t size); 125 | void dacefree(void* ptr); 126 | #endif 127 | 128 | // internal memory related routines 129 | void daceFreeMemory(); 130 | void daceVariableInformation(const DACEDA *inc, monomial **ipoc, unsigned int *ilmc, unsigned int *illc); 131 | void daceSetLength(DACEDA *inc, const size_t len); 132 | bool daceIsSameObject(const DACEDA *ina, const DACEDA *inb); 133 | 134 | // basic monomial coding integer related routines 135 | unsigned int daceEncodeExponents(const unsigned int p[], const unsigned int no, const unsigned int nv); 136 | unsigned int daceEncode(const unsigned int p[]); 137 | unsigned int daceDecodeExponents(unsigned int ic, const unsigned int no, const unsigned int nv, unsigned int p[]); 138 | void daceDecode(const unsigned int ic, unsigned int p[]); 139 | unsigned int daceCountMonomials(unsigned int no, unsigned int nv); 140 | unsigned int daceNextMonomial(unsigned int p[], const unsigned int no, const unsigned int nv); 141 | unsigned int daceNextOrderedMonomial(unsigned int p[], const unsigned int no, const unsigned int nv); 142 | 143 | // internal routines 144 | void daceInitializeThread0(); 145 | void daceSetError(const char *c, const unsigned int ix, const unsigned int iyy); 146 | void dacePack(double *restrict cc, DACEDA *restrict inc); 147 | void daceMultiplicativeInverse0(const DACEDA *ina, DACEDA *inc, const double a0); 148 | int BesselWrapper(const double x, const int n0, const int n1, const int type, double *bz); 149 | int ModifiedBesselWrapper(const double x, const int n0, const int n1, const int type, double *bz); 150 | void daceEvaluateBesselFunction(const DACEDA *ina, const double bz[], const double type, const double ktype, DACEDA *inc); 151 | void daceEvaluateScaledModifiedBesselFunction(const DACEDA *ina, const double bz[], const double type, DACEDA *inc); 152 | void daceLogGammaFunction0(const DACEDA *ina, const double a0, DACEDA *inc); 153 | void daceEvaluateSeries(const DACEDA *ina, const double xf[], DACEDA *inc); 154 | /// @endcond 155 | /** @}*/ 156 | #endif /* DINAMICA_DACEAUX_H_ */ 157 | -------------------------------------------------------------------------------- /core/include/dace/dacecompat.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | /* 22 | * dacecompat.h 23 | * 24 | * Created on: November 18, 2016 25 | * Author: Politecnico di Milano 26 | */ 27 | 28 | /* 29 | Compatibility file mapping old unreadable names to new DACE function names. 30 | Where possible, function names are #define'ed to map to new names. 31 | Where necessary, small shims with the old interface are provided in dacecompat.c. 32 | */ 33 | 34 | /** \addtogroup DACE Core 35 | * @{ 36 | */ 37 | #ifndef DINAMICA_DACECOMPAT_H_ 38 | #define DINAMICA_DACECOMPAT_H_ 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif /* __cplusplus */ 43 | 44 | #define daceini(no, nv) daceInitialize(no, nv) 45 | #define dacever(imaj, imin, icos) daceGetVersion(imaj, imin, icos) 46 | #define daceseteps(deps) daceSetEpsilon(deps) 47 | #define dacegeteps() daceGetEpsilon() 48 | #define dacegetepsmac() daceGetMachineEpsilon() 49 | #define dacegetnomax() daceGetMaxOrder() 50 | #define dacegetnvmax() daceGetMaxVariables() 51 | #define dacegetnmmax() daceGetMaxMonomials() 52 | #define dacegetnot() daceGetTruncationOrder() 53 | #define dacesetnot(fnot) daceSetTruncationOrder(fnot) 54 | 55 | //#define dacegeterr() daceGetError() // do not redefine this routine, it causes problems with the inlining of a function of the same name we do in C++ interface! 56 | #define dacegetxerr() daceGetErrorX() 57 | #define dacegetyyerr() daceGetErrorYY() 58 | #define daceclrerr() daceClearError() 59 | 60 | #define daceall(inc, len) daceAllocateDA(inc, len) 61 | #define dacedal(inc) daceFreeDA(ARG(inc)) 62 | #define dacememdump(iunit) daceMemoryDump() 63 | 64 | #define dacevar(ina, i, ckon) daceCreateVariable(ARG(ina), i, ckon) 65 | #define dacecoef(ina, jj, ckon) daceCreateMonomial(ARG(ina), jj, ckon) 66 | #define dacecon(ina, ckon) daceCreateConstant(ARG(ina), ckon) 67 | #define daceran(ina, cm) daceCreateRandom(ARG(ina), cm) 68 | 69 | #define daceconst(ina) daceGetConstant(ARG(ina)) 70 | #define dacelinear(ina, c) daceGetLinear(ARG(ina), c) 71 | #define dacepok(ina, jj, cjj) daceSetCoefficient(ARG(ina), jj, cjj) 72 | DACE_API void dacepek(const DACEDA REF(ina), const unsigned int jj[], double REF(cjj)); 73 | #define dacelist(ina, npos, jj, cjj) daceGetCoefficientAt(ARG(ina), npos, jj, cjj) 74 | DACE_API void dacesize(const DACEDA REF(ina), unsigned int REF(size)); 75 | 76 | #define dacecop(ina, inb) daceCopy(ARG(ina), ARG(inb)) 77 | 78 | #define dacetrim(ina, imin, imax, inc) daceTrim(ARG(ina), imin, imax, ARG(inc)) 79 | 80 | DACE_API void daceabs(const DACEDA REF(ina), double REF(anorm)); 81 | DACE_API void dacenorm(const DACEDA REF(ina), const unsigned int ityp, double REF(anorm)); 82 | #define daceonorm(ina, ivar, ityp, onorm) daceOrderedNorm(ARG(ina), ivar, ityp, onorm) 83 | #define daceest(ina, ivar, ityp, c, nc) daceEstimate(ARG(ina), ivar, ityp, c, NULL, nc) 84 | #define dacebound(ina, alo, aup) daceGetBounds(ARG(ina), alo, aup) 85 | 86 | #define daceplug(ina, nvar, val, inc) daceEvalVariable(ARG(ina), nvar, val, ARG(inc)) 87 | DACE_API void dacetree(const DACEDA das[], const unsigned int count, double ac[], unsigned int REF(nterm), unsigned int REF(nvar), unsigned int REF(nord)); 88 | #define dacewrite(ina, strs, nstrs) daceWrite(ARG(ina), strs, nstrs) 89 | #define daceread(ina, strs, nstrs) daceRead(ARG(ina), strs, nstrs) 90 | 91 | #define daceadd(ina, inb, inc) daceAdd(ARG(ina), ARG(inb), ARG(inc)) 92 | #define dacesub(ina, inb, inc) daceSubtract(ARG(ina), ARG(inb), ARG(inc)) 93 | #define dacemul(ina, inb, inc) daceMultiply(ARG(ina), ARG(inb), ARG(inc)) 94 | #define dacediv(ina, inb, inc) daceDivide(ARG(ina), ARG(inb), ARG(inc)) 95 | #define dacesqr(ina, inb) daceSquare(ARG(ina), ARG(inb)) 96 | #define dacecadd(ina, ckon, inb) daceAddDouble(ARG(ina), ckon, ARG(inb)) 97 | #define dacecsub(ina, ckon, inb) daceDoubleSubtract(ARG(ina), ckon, ARG(inb)) 98 | #define dacesubc(ina, ckon, inb) daceSubtractDouble(ARG(ina), ckon, ARG(inb)) 99 | #define dacecmul(ina, ckon, inb) daceMultiplyDouble(ARG(ina), ckon, ARG(inb)) 100 | #define dacecdiv(ina, ckon, inb) daceDoubleDivide(ARG(ina), ckon, ARG(inb)) 101 | #define dacedivc(ina, ckon, inb) daceDivideDouble(ARG(ina), ckon, ARG(inb)) 102 | #define daceder(idif, ina, inc) daceDifferentiate(idif, ARG(ina), ARG(inc)) 103 | #define daceint(iint, ina, inc) daceIntegrate(iint, ARG(ina), ARG(inc)) 104 | 105 | #define dacetrunc(ina, inc) daceTruncate(ARG(ina), ARG(inc)) 106 | #define daceround(ina, inc) daceRound(ARG(ina), ARG(inc)) 107 | #define dacemod(ina, p, inc) daceModulo(ARG(ina), p, ARG(inc)) 108 | #define dacepow(ina, np, inc) dacePower(ARG(ina), np, ARG(inc)) 109 | #define daceroot(ina, np, inc) daceRoot(ARG(ina), np, ARG(inc)) 110 | #define daceminv(ina, inc) daceMultiplicativeInverse(ARG(ina), ARG(inc)) 111 | #define dacesqrt(ina, inc) daceSquareRoot(ARG(ina), ARG(inc)) 112 | #define daceisrt(ina, inc) daceInverseSquareRoot(ARG(ina), ARG(inc)) 113 | #define daceexp(ina, inc) daceExponential(ARG(ina), ARG(inc)) 114 | #define dacelog(ina, inc) daceLogarithm(ARG(ina), ARG(inc)) 115 | #define dacelogb(ina, b, inc) daceLogarithmBase(ARG(ina), b, ARG(inc)) 116 | #define dacesin(ina, inc) daceSine(ARG(ina), ARG(inc)) 117 | #define dacecos(ina, inc) daceCosine(ARG(ina), ARG(inc)) 118 | #define dacetan(ina, inc) daceTangent(ARG(ina), ARG(inc)) 119 | #define daceasin(ina, inc) daceArcSine(ARG(ina), ARG(inc)) 120 | #define daceacos(ina, inc) daceArcCosine(ARG(ina), ARG(inc)) 121 | #define daceatan(ina, inc) daceArcTangent(ARG(ina), ARG(inc)) 122 | #define daceatan2(ina, inb, inc) daceArcTangent2(ARG(ina), ARG(inb), ARG(inc)) 123 | #define dacesinh(ina, inc) daceHyperbolicSine(ARG(ina), ARG(inc)) 124 | #define dacecosh(ina, inc) daceHyperbolicCosine(ARG(ina), ARG(inc)) 125 | #define dacetanh(ina, inc) daceHyperbolicTangent(ARG(ina), ARG(inc)) 126 | #define daceasinh(ina, inc) daceHyperbolicArcSine(ARG(ina), ARG(inc)) 127 | #define daceacosh(ina, inc) daceHyperbolicArcCosine(ARG(ina), ARG(inc)) 128 | #define daceatanh(ina, inc) daceHyperbolicArcTangent(ARG(ina), ARG(inc)) 129 | 130 | #ifdef __cplusplus 131 | } // extern "C" 132 | #endif /* __cplusplus */ 133 | /** @}*/ 134 | #endif /* DINAMICA_DACECOMPAT_H_ */ 135 | -------------------------------------------------------------------------------- /core/include/dace/dacecore.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * dacecore.h 24 | * 25 | * Created on: November 18, 2016 26 | * Author: Politecnico di Milano 27 | */ 28 | 29 | /* 30 | User interface header for DACE core library. 31 | Includes all relevant headers with public interfaces to the DACE core. 32 | */ 33 | /** \addtogroup DACE Core 34 | * @{ 35 | */ 36 | 37 | #ifndef DINAMICA_DACECORE_H_ 38 | #define DINAMICA_DACECORE_H_ 39 | 40 | #include "dace/dacebase.h" 41 | /** @}*/ 42 | #endif /* DINAMICA_DACECORE_H_ */ 43 | -------------------------------------------------------------------------------- /core/include/dace/dacecore_s.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * dacecore.h 24 | * 25 | * Created on: Jul 20, 2018 26 | * Author: University of Southampton 27 | */ 28 | 29 | /* 30 | User interface header for DACE core library using static linking. 31 | Includes all relevant headers with public interfaces to the DACE core 32 | with the correct API decorations for Windows static linking. 33 | */ 34 | /** \addtogroup DACE Core 35 | * @{ 36 | */ 37 | 38 | #ifndef DINAMICA_DACECORE_S_H_ 39 | #define DINAMICA_DACECORE_S_H_ 40 | 41 | // explicitly define DACE_API to be empty for static linking 42 | #define DACE_API 43 | #include "dace/dacecore.h" 44 | /** @}*/ 45 | #endif /* DINAMICA_DACECORE_S_H_ */ 46 | -------------------------------------------------------------------------------- /core/include/dace/daceerror.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * daceerror.h 24 | * 25 | * Created on: November 18, 2016 26 | * Author: Politecnico di Milano 27 | */ 28 | 29 | #ifndef DINAMICA_DACEERROR_H 30 | #define DINAMICA_DACEERROR_H 31 | 32 | /** \addtogroup DACE Core 33 | * @{ 34 | */ 35 | typedef struct { 36 | int ID; //!< Internal ID of the error 37 | const char* msg; //!< Human readable error message 38 | } errstrings; 39 | 40 | 41 | DACE_API const errstrings DACEerr[] = { 42 | { 0, "Unknown DACE error. Contact DACE developers for filing a bug report."}, 43 | {1001, "Dynamic memory allocation failure"}, 44 | {1002, "Out of memory"}, 45 | {1003, "DACE has not been initialized"}, 46 | {1004, "DA object not allocated"}, 47 | {1005, "Incorrect number of monomials"}, 48 | {1006, "Incorrect DA coding arrays"}, 49 | {1007, "Requested length too long"}, 50 | {1008, "Error in monomial evaluation tree construction"}, 51 | { 9, ""}, 52 | { 10, ""}, 53 | { 911, "Order and/or variable too large"}, 54 | { 12, ""}, 55 | { 13, ""}, 56 | { 14, ""}, 57 | { 15, ""}, 58 | { 16, ""}, 59 | { 17, ""}, 60 | { 18, ""}, 61 | { 19, ""}, 62 | { 20, ""}, 63 | { 621, "Not enough storage"}, 64 | { 622, "Order too large"}, 65 | { 623, "Number of variables too high"}, 66 | { 624, "Invalid independent variable"}, 67 | { 625, "Invalid DA codes"}, 68 | { 626, "Invalid encoded exponent"}, 69 | { 27, ""}, 70 | { 28, ""}, 71 | { 29, ""}, 72 | { 30, ""}, 73 | { 631, "Invalid data"}, 74 | { 632, "Unknown format"}, 75 | { 633, "DA vector too long"}, 76 | { 634, "Not enough lines to read"}, 77 | { 35, ""}, 78 | { 36, ""}, 79 | { 37, ""}, 80 | { 38, ""}, 81 | { 39, ""}, 82 | { 40, ""}, 83 | { 641, "Dividing by zero"}, 84 | { 642, "Inverse does not exists"}, 85 | { 643, "Non-integer power of non-positive DA"}, 86 | { 644, "Zero-th root does not exist"}, 87 | { 645, "Even root of negative DA"}, 88 | { 646, "Odd root of zero DA"}, 89 | { 647, "Negative constant part in logarithm"}, 90 | { 648, "Base of logarithm must be positive"}, 91 | { 649, "Cosine is zero in tangent"}, 92 | { 650, "Out of domain"}, 93 | { 651, "No estimate is possible"}, 94 | { 52, ""}, 95 | { 53, ""}, 96 | { 54, ""}, 97 | { 55, ""}, 98 | { 56, ""}, 99 | { 57, ""}, 100 | { 58, ""}, 101 | { 59, ""}, 102 | { 60, ""}, 103 | { 161, "Free or invalid variable"}, 104 | { 162, "Truncation order too high"}, 105 | { 163, "Inacurate estimate"}, 106 | { 164, "Numbering out of order"}, 107 | { 165, "Too many variables"}, 108 | { 166, "Duplicate monomial"}, 109 | { 167, "Order increased to 1"}, 110 | { 168, "Variable increased to 1"}, 111 | { 69, ""}, 112 | { 70, ""} 113 | }; //!< Variable containing all errors strings and codes 114 | /** @}*/ 115 | #endif 116 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ "x${GITHUB_USER}" != "x" -a "x${GITHUB_TOKEN}" != "x" ]; then 3 | cd ${TRAVIS_BUILD_DIR}/build 4 | git clone -b pkg-latest https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_USER}/dace.git pkg-latest >/dev/null 2>&1 5 | cd pkg-latest 6 | cp ${TRAVIS_BUILD_DIR}/build/packages/* . 7 | git add * 8 | git commit -a -m "Automatic update of build artifacts for commit ${TRAVIS_COMMIT}" 9 | git pull 10 | git push 11 | cd .. 12 | rm -rf pkg-latest 13 | fi 14 | -------------------------------------------------------------------------------- /interfaces/cxx/AlgebraicMatrix.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * AlgebraicMatrix.cpp 24 | * 25 | * Created on: January 21, 2015 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | // C++ stdlib classes used only internally in this implementation 30 | #include 31 | #include 32 | 33 | // DACE classes 34 | #include "dace/config.h" 35 | #include "dace/DA.h" 36 | #include "dace/AlgebraicMatrix.h" 37 | #include "dace/AlgebraicMatrix_t.h" 38 | 39 | namespace DACE { 40 | 41 | /*********************************************************************************** 42 | * Input/Output routines 43 | ************************************************************************************/ 44 | template<> std::ostream& operator<<(std::ostream &out, const AlgebraicMatrix &obj) 45 | { 46 | /*! Specialized stream output operator for DA matrices. 47 | \param[in] out Standard output stream. 48 | \param[in] obj AlgebraicMatrix to be printed in the stream 49 | \return Reference to the standard output stream. 50 | */ 51 | const unsigned int nrows = obj.nrows(); 52 | const unsigned int ncols = obj.ncols(); 53 | 54 | out << "[[[ " << nrows << "x" << ncols << " matrix" << std::endl; 55 | for(unsigned int j = 0; j std::istream& operator>>(std::istream &in, AlgebraicMatrix &obj){ 66 | /*! Specialized stream input operator for DA matrices. 67 | \param[in] in Standard input stream. 68 | \param[out] obj AlgebraicMatrix to be read from the stream 69 | \return Reference to the standard input stream. 70 | */ 71 | // read the first line 72 | std::string line; 73 | std::getline(in, line); 74 | 75 | unsigned int n_rows = 0; 76 | unsigned int n_cols = 0; 77 | 78 | if(in.good()){ 79 | // Find the number of rows 80 | std::size_t found = line.find_first_of('x'); 81 | std::string size_str; 82 | 83 | for( unsigned int j = 4; j> n_rows)) 87 | n_rows = 0; 88 | 89 | // Find the number of columns (stop when 'm' of "matrix" is met) 90 | std::size_t found2 = line.find_first_of('m', found); 91 | size_str.clear(); 92 | 93 | for( unsigned int j = found+1; j> n_cols)) 97 | n_cols = 0; 98 | 99 | // resize the object to meet the size of the vector to be read 100 | obj.resize(n_rows, n_cols); 101 | 102 | // fill the AlgebraicMatrix 103 | for( unsigned int j = 0; j> obj.at(i,j); 110 | } 111 | 112 | // skip the line at the end of a AlgebraicMatrix (containing ]]]) 113 | std::getline(in, line); 114 | } else { 115 | obj.resize(0, 0); } 116 | 117 | return in; 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /interfaces/cxx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # C++ interface source files 2 | set(SRCCXXIF AlgebraicVector.cpp DA.cpp DACEException.cpp DAFormatter.cpp MathExtension.cpp Monomial.cpp compiledDA.cpp) 3 | include_directories(include ${PROJECT_BINARY_DIR}/core/include ${PROJECT_SOURCE_DIR}/core/include) 4 | 5 | if(WITH_ALGEBRAICMATRIX) 6 | list(APPEND SRCCXXIF "AlgebraicMatrix.cpp") 7 | endif(WITH_ALGEBRAICMATRIX) 8 | 9 | # Build object files for static and dynamic libraries of C++ interface 10 | add_library(dacecxx_s OBJECT ${SRCCXXIF}) 11 | add_library(dacecxx OBJECT ${SRCCXXIF}) 12 | set_target_properties(dacecxx PROPERTIES POSITION_INDEPENDENT_CODE True) 13 | if(WIN32) 14 | target_compile_definitions(dacecxx PRIVATE "DACE_API=__declspec(dllexport)") 15 | target_compile_definitions(dacecxx_s PRIVATE "DACE_API=") 16 | endif(WIN32) 17 | -------------------------------------------------------------------------------- /interfaces/cxx/DAFormatter.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * DAFormatter.cpp 24 | * 25 | * Created on: Oct 20, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | // C++ stdlib classes used only internally in the implementation 30 | #include 31 | 32 | // DACE classes 33 | #include "dace/config.h" 34 | #include "dace/DAFormatter.h" 35 | #include "dace/Monomial.h" 36 | #include "dace/DA.h" 37 | 38 | namespace DACE{ 39 | 40 | const DASimpleFormat DASimpleFormatter::C = { "+", "-", "*", "", "p", "[", "", "][", "]", " \\\n\t", 0, -1, 20, false }; 41 | const DASimpleFormat DASimpleFormatter::C_POW = { "+", "-", "*", "pow(", "x", "[", "]", ",", ")", " \\\n\t", 0, 0, 20, true }; 42 | const DASimpleFormat DASimpleFormatter::FORTRAN = { "+", "-", "*", "", "p", "(", "", ",", ")", " &\n &", 1, 0, 20, false }; 43 | const DASimpleFormat DASimpleFormatter::FORTRAN_POW = { "+", "-", "*", "", "x", "(", ")", "**(", ")", " &\n &", 1, 0, 20, true }; 44 | const DASimpleFormat DASimpleFormatter::MATLAB = { "+", "-", ".*", "", "p", "(", "", ",", ")", " ...\n\t", 1, 0, 20, false }; 45 | const DASimpleFormat DASimpleFormatter::MATLAB_POW = { "+", "-", ".*", "", "x", "(", ")", ".^(", ")", " ...\n\t", 1, 0, 20, true }; 46 | const DASimpleFormat DASimpleFormatter::LATEX = { " +", " -", " \\cdot ", "", "x", "_{", "}", "^{", "}", " \n\t", 1, 0, 20, true }; 47 | 48 | std::string DASimpleFormatter::format(const DA &da){ 49 | /*! Format and print a DA. 50 | \param[in] da The DA to be printed. 51 | */ 52 | const std::vector monomials = da.getMonomials(); 53 | const size_t size = monomials.size(); 54 | std::ostringstream res; 55 | 56 | res.precision(16); 57 | for(size_t i=0; i &da){ 77 | /*! Format and print a vector of DA. 78 | \param[in] da The vector of DA to be printed. 79 | */ 80 | std::ostringstream res; 81 | 82 | for(unsigned int i=0; i 31 | 32 | // DACE classes 33 | #include "dace/config.h" 34 | #include "dace/MathExtension.h" 35 | 36 | namespace DACE{ 37 | 38 | double cons(const double x){ 39 | /*! Constant part. For double type this is just x. 40 | \param[in] x Function argument. 41 | */ 42 | return x; 43 | } 44 | 45 | double logb(const double x, const double b){ 46 | /*! Logarithm relative to base b. 47 | \param[in] x Function argument. 48 | \param[in] b Base of the logarithm (must be positive). 49 | */ 50 | return std::log(x)/std::log(b); 51 | } 52 | 53 | double isrt(const double x){ 54 | /*! Inverse square root 1/sqrt(x). 55 | \param[in] x Function argument. 56 | */ 57 | return 1.0/std::sqrt(x); 58 | } 59 | 60 | double sqr(const double x){ 61 | /*! Square of x. 62 | \param[in] x Function argument. 63 | */ 64 | return x*x; 65 | } 66 | 67 | double minv(const double x){ 68 | /*! Multiplicative inverse 1/x. 69 | \param[in] x Function argument. 70 | */ 71 | return 1.0/x; 72 | } 73 | 74 | double root(const double x, const int p){ 75 | /*! p-th root of x. 76 | \param[in] x Function argument. 77 | \param[in] p Root to take. 78 | */ 79 | return std::pow(x, 1.0/p); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /interfaces/cxx/Monomial.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * Monomial.cpp 24 | * 25 | * Created on: Mar 10, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | // C++ stdlib classes used only internally in the implementation 30 | #include 31 | #include 32 | 33 | // DACE classes 34 | #include "dace/config.h" 35 | #include "dace/Monomial.h" 36 | #include "dace/DA.h" 37 | 38 | namespace DACE{ 39 | 40 | /******************************************************************************** 41 | * Constructors & Destructors 42 | *********************************************************************************/ 43 | Monomial::Monomial() : m_jj(DA::getMaxVariables()), m_coeff(0.0) { 44 | /*! Create a Monomial object large enough to hold all current monomials. 45 | */ 46 | } 47 | 48 | unsigned int Monomial::order() const{ 49 | /*! Compute the order of the monomial. 50 | \return Order of the monomial 51 | */ 52 | unsigned int ord = 0; 53 | 54 | for(unsigned int i = 0; i < m_jj.size(); i++) 55 | ord += m_jj[i]; 56 | 57 | return ord; 58 | } 59 | 60 | std::string Monomial::toString() const{ 61 | /*! Convert monomial to string. 62 | \return A string representing the monomial in human readable form. 63 | */ 64 | std::ostringstream oss; 65 | 66 | oss << " I COEFFICIENT ORDER EXPONENTS" << std::endl; 67 | 68 | // value and order 69 | oss << " 1 "; 70 | oss << std::setiosflags(std::ios::uppercase) << std::setprecision(16) << std::scientific << std::setw(24) << m_coeff; 71 | oss << std::setw(4) << order() << std::setw(1) << ' '; 72 | 73 | // exponents 74 | for(unsigned int i = 0; i < m_jj.size(); i++){ 75 | oss << std::setw(1) << ' ' << std::setw(2) << m_jj[i];} 76 | 77 | oss << std::endl; 78 | oss << "------------------------------------------------" << std::endl; 79 | 80 | return oss.str(); 81 | } 82 | 83 | std::ostream& operator<< (std::ostream &out, const Monomial &m){ 84 | /*! Overload of std::operator<< in iostream. 85 | \param[in] out standard output stream. 86 | \param[in] m Monomial vector to be printed in the stream 87 | \return The output stream out. 88 | */ 89 | out << m.toString(); 90 | return out; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /interfaces/cxx/compiledDA.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * compiledDA.cpp 24 | * 25 | * Created on: Mar 01, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | // DACE classes 30 | #include "dace/config.h" 31 | #include "dace/compiledDA.h" 32 | #include "dace/DA.h" 33 | #include "dace/DACEException.h" 34 | 35 | namespace DACE{ 36 | 37 | /******************************************************************************** 38 | * Constructors & Destructors 39 | *********************************************************************************/ 40 | compiledDA::compiledDA(const compiledDA &cda){ 41 | /*! Create a copy of a compiledDA object. 42 | \param[in] cda compiled DA object to be copied. 43 | */ 44 | dim = cda.dim; 45 | terms = cda.terms; 46 | vars = cda.vars; 47 | ord = cda.ord; 48 | ac = new double[terms*(dim+2)]; 49 | for(int i=terms*(dim+2)-1; i>=0; i--) ac[i] = cda.ac[i]; 50 | } 51 | 52 | compiledDA::compiledDA(const std::vector &da){ 53 | /*! Create a vector of compiledDA objects from a vector of DA objects. 54 | \param[in] da vector of DA objects. 55 | \throw DACE::DACEException 56 | */ 57 | dim = (unsigned int)da.size(); 58 | if(dim<1) DACEException(16,04); 59 | 60 | ac = new double[DA::getMaxMonomials()*(dim+2)]; 61 | unsigned int nterms, nvars, nord; 62 | const DACEDA **mb = new const DACEDA*[dim]; 63 | for(unsigned int i=0; i=0; i--) ac[i] = cda.ac[i];} 110 | 111 | return *this; 112 | } 113 | 114 | /******************************************************************************** 115 | * Evaluation overloads and template specialization 116 | *********************************************************************************/ 117 | // double evaluation 118 | template<> void compiledDA::eval(const std::vector &args, std::vector &res) const{ 119 | const size_t narg = args.size(); 120 | double *p = ac+2; 121 | double *xm = new double[ord+1]; 122 | 123 | // prepare temporary powers 124 | xm[0] = 1.0; 125 | // constant part 126 | for(unsigned int i=0; i void compiledDA::eval(const std::vector &args, std::vector &res) const{ 145 | const size_t narg = args.size(); 146 | unsigned int jlskip = ord+1; 147 | double *p = ac+2; 148 | DACEDA *xm = new DACEDA[ord+1]; 149 | DACEDA tmp; 150 | 151 | // allocate temporary DA variables in dace 152 | for(unsigned int i=0; i jlskip) 165 | { 166 | p += dim; 167 | continue; 168 | } 169 | if(jv >= narg) 170 | { 171 | jlskip = jl; 172 | p += dim; 173 | continue; 174 | } 175 | jlskip = ord+1; 176 | daceMultiply(xm[jl-1],args[jv].m_index,xm[jl]); 177 | for(unsigned int j=0; j=0; i--) daceFreeDA(xm[i]); 187 | delete[] xm; 188 | 189 | if(daceGetError()) DACEException(); 190 | } 191 | 192 | /******************************************************************************** 193 | * Member access routines 194 | *********************************************************************************/ 195 | const double* compiledDA::getAc() const{ 196 | return this->ac; 197 | } 198 | 199 | unsigned int compiledDA::getDim() const{ 200 | return this->dim; 201 | } 202 | 203 | unsigned int compiledDA::getOrd() const{ 204 | return this->ord; 205 | } 206 | 207 | unsigned int compiledDA::getVars() const{ 208 | return this->vars; 209 | } 210 | 211 | unsigned int compiledDA::getTerms() const{ 212 | return this->terms; 213 | } 214 | 215 | } 216 | -------------------------------------------------------------------------------- /interfaces/cxx/include/dace/AlgebraicMatrix.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * AlgebraicMatrix.h 24 | * 25 | * Created on: July 17, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | #ifndef DINAMICA_DAMATRIX_H_ 30 | #define DINAMICA_DAMATRIX_H_ 31 | 32 | // C++ stdlib classes required for interface definition 33 | #include 34 | #include 35 | 36 | // DACE classes required for interface definition 37 | #include "dace/PromotionTrait.h" 38 | 39 | namespace DACE{ 40 | 41 | // forward declarations 42 | class DA; 43 | template class AlgebraicVector; 44 | 45 | /*! Class to handle matrices and their operations. */ 46 | template class AlgebraicMatrix 47 | { 48 | public: 49 | /*********************************************************************************** 50 | * Constructors & Destructors 51 | ************************************************************************************/ 52 | AlgebraicMatrix() : _nrows(0), _ncols(0) {}; //!< Default Constructor 53 | 54 | /*! 55 | * Constructor for square matrices. 56 | * \param[in] size size of the matrix, i.e. the number of rows and columns. 57 | */ 58 | explicit AlgebraicMatrix(const int size) : _nrows(size), _ncols(size), _data(size*size,0.0) { }; 59 | 60 | /*! 61 | * Constructor for rectangular matrices. 62 | * \param[in] nrows number of rows of the matrix 63 | * \param[in] ncols number of columns of the matrix 64 | */ 65 | AlgebraicMatrix(const int nrows, const int ncols) : _nrows(nrows), _ncols(ncols), _data(nrows*ncols,0.0) { }; 66 | 67 | /*! 68 | * Constructor for rectangular matrices that allows to set all elements equal to a variable. 69 | * \param[in] nrows number of rows of the matrix 70 | * \param[in] ncols number of columns of the matrix 71 | * \param[in] d matrix elements value 72 | */ 73 | AlgebraicMatrix(const int nrows, const int ncols, const T &d) : _nrows(nrows), _ncols(ncols), _data(nrows*ncols, d) { }; 74 | 75 | /*********************************************************************************** 76 | * Output number of rows, columns, and size 77 | ************************************************************************************/ 78 | /*! 79 | * Returns the number of columns of the matrix 80 | * \return number of columns of the matrix. 81 | */ 82 | unsigned int ncols() const { return this->_ncols; }; 83 | 84 | /*! 85 | * Returns the number of rows of the matrix 86 | * \return number of rows of the matrix. 87 | */ 88 | unsigned int nrows() const { return this->_nrows; }; 89 | 90 | /*! 91 | * Returns the number of elements of the matrix 92 | * \return number of elements of the matrix. 93 | */ 94 | unsigned int size() const { return this->_data.size(); }; 95 | 96 | void resize(int size); 97 | void resize(int rows, int cols); 98 | 99 | /*********************************************************************************** 100 | * Element access routine 101 | ************************************************************************************/ 102 | T& at(const unsigned int irow, const unsigned int icol); //!< Reading/Writing single element 103 | const T& at(const unsigned int irow, const unsigned int icol) const; //!< Reading/Writing single element 104 | 105 | std::vector getrow(const unsigned int irow) const; //!< Reading row 106 | std::vector getcol(const unsigned int icol) const; //!< Reading column 107 | 108 | void setrow(const unsigned int irow, const std::vector &obj); //!< Set row equal to std::vector 109 | void setcol(const unsigned int icol, const std::vector &obj); //!< Set column equal to std::vector 110 | 111 | AlgebraicMatrix submat(const unsigned int first_row, const unsigned int first_col, const unsigned int last_row, const unsigned int last_col) const; //!< Extract submatrix 112 | AlgebraicMatrix submat(const unsigned int last_row, const unsigned int last_col) const; //!< Extract submatrix, starting from position (0,0) 113 | 114 | /*********************************************************************************** 115 | * Matrix operations 116 | ************************************************************************************/ 117 | AlgebraicMatrix transpose() const; //!< Matrix transpose 118 | T det() const; //!< Matrix determinant 119 | AlgebraicMatrix inv() const; //!< Matrix inverse XXX: name 120 | 121 | /*********************************************************************************** 122 | * Coefficient access routines 123 | ************************************************************************************/ 124 | AlgebraicMatrix cons() const; //!< Return the costant part of a AlgebraicMatrix 125 | 126 | private: 127 | unsigned int _nrows; //!< Number of rows of the matrix 128 | unsigned int _ncols; //!< Number of columns of the matrix 129 | std::vector _data; //!< Elements container 130 | 131 | static unsigned int pivot(unsigned int& k, const unsigned int ii, const AlgebraicMatrix& A, std::vector& P, std::vector& R, std::vector& C1, std::vector& C2, T& det); 132 | static void eliminate(const unsigned int k, AlgebraicMatrix& A, std::vector& R); 133 | }; 134 | 135 | /*********************************************************************************** 136 | * Operators 137 | ************************************************************************************/ 138 | template std::ostream& operator<<(std::ostream &out, const AlgebraicMatrix &obj); //!< Overload output stream operator 139 | template<> DACE_API std::ostream& operator<<(std::ostream &out, const AlgebraicMatrix &obj); //!< DA specialization of output stream operator 140 | template std::istream& operator>>(std::istream &in, AlgebraicMatrix &obj); //!< Overload input stream operator 141 | template<> DACE_API std::istream& operator>>(std::istream &in, AlgebraicMatrix &obj); //!< DA specialization of input stream operator 142 | 143 | template AlgebraicMatrix::returnType> operator+( const AlgebraicMatrix &obj1, const AlgebraicMatrix &obj2); 144 | template AlgebraicMatrix::returnType> operator+( const AlgebraicMatrix &obj1, const V &obj2 ); 145 | template AlgebraicMatrix::returnType> operator+( const U &obj1, const AlgebraicMatrix &obj2 ); 146 | 147 | template AlgebraicMatrix::returnType> operator-( const AlgebraicMatrix &obj1, const AlgebraicMatrix &obj2); 148 | template AlgebraicMatrix::returnType> operator-( const AlgebraicMatrix &obj1, const V &obj2 ); 149 | template AlgebraicMatrix::returnType> operator-( const U &obj1, const AlgebraicMatrix &obj2 ); 150 | 151 | template AlgebraicMatrix::returnType> operator*( const AlgebraicMatrix &obj1, const AlgebraicMatrix &obj2); 152 | template AlgebraicMatrix::returnType> operator*( const AlgebraicMatrix &obj1, const V &obj2 ); 153 | template AlgebraicMatrix::returnType> operator*( const U &obj1, const AlgebraicMatrix &obj2 ); 154 | template AlgebraicVector::returnType> operator*( const AlgebraicVector &obj1, const AlgebraicMatrix &obj2 ); 155 | template AlgebraicVector::returnType> operator*( const AlgebraicMatrix &obj1, const AlgebraicVector &obj2 ); 156 | 157 | /*********************************************************************************** 158 | * Functional style wrappers 159 | ************************************************************************************/ 160 | template AlgebraicMatrix transpose(const AlgebraicMatrix &obj); 161 | template T det(const AlgebraicMatrix &obj); 162 | template AlgebraicMatrix inv(const AlgebraicMatrix &obj); 163 | template AlgebraicMatrix cons(const AlgebraicMatrix &obj); 164 | 165 | /*********************************************************************************** 166 | * Type definitions 167 | ************************************************************************************/ 168 | typedef AlgebraicMatrix matrixDA; //!< Short for AlgebraicMatrix 169 | typedef AlgebraicMatrix matrixdb; //!< Short for AlgebraicMatrix 170 | 171 | } 172 | 173 | #endif /* AlgebraicMatrix_H_ */ 174 | -------------------------------------------------------------------------------- /interfaces/cxx/include/dace/DACEException.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * DACEException.h 24 | * 25 | * Created on: Mar 11, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | #ifndef DINAMICA_DACEEXCEPTION_H_ 30 | #define DINAMICA_DACEEXCEPTION_H_ 31 | 32 | // C++ stdlib classes used in this public interface 33 | #include 34 | #include 35 | #include 36 | 37 | namespace DACE{ 38 | 39 | /*! DACEException class containing methods for error handling within the DACE C++ interface. */ 40 | class DACE_API DACEException : public std::exception 41 | { 42 | private: 43 | int m_x; //!< Severity code 44 | int m_yy; //!< Error code 45 | std::string msg; //!< Error message 46 | static int severity; //!< Default severity code 47 | static bool warning; //!< Default warning status 48 | void execute() const; //!< Execute the exception 49 | void updateMessage(); //!< Update the error message 50 | 51 | public: 52 | DACEException(); //!< Default constructor 53 | DACEException(const int exc_sv, const int exc_id); //!< Constructor 54 | ~DACEException() throw(); //!< Destructor 55 | 56 | const char* what() const throw(); //!< Convert exception to string 57 | static void setSeverity(const int n); //!< Select the desired severity code 58 | static void setWarning(const bool w); //!< Select the warning status 59 | 60 | friend DACE_API std::ostream& operator<< (std::ostream &out, const DACEException &ex); //!< Overload output stream operator 61 | }; 62 | 63 | } 64 | #endif /* DINAMICA_DACEEXCEPTION_H_ */ 65 | -------------------------------------------------------------------------------- /interfaces/cxx/include/dace/DAFormatter.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * DAFormatter.h 24 | * 25 | * Created on: Oct 18, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | #ifndef DINAMICA_DAFORMATTER_H_ 30 | #define DINAMICA_DAFORMATTER_H_ 31 | 32 | // C++ stdlib classes used in this public interface 33 | #include 34 | #include 35 | 36 | namespace DACE{ 37 | 38 | // forward declaration 39 | class DA; 40 | 41 | /*! Abstract class providing a DA formatter to output DA vectors in some advanced format. */ 42 | class DACE_API DAFormatter 43 | { 44 | public: 45 | virtual std::string format(const DA &da) = 0; 46 | virtual std::string format(const std::vector &da) = 0; 47 | }; 48 | 49 | /*! Class containing the elements of a simple format as used by the DASimpleFormatter. 50 | \sa DASimpleFormatter 51 | */ 52 | struct DASimpleFormat { 53 | std::string pos, neg, mul, pre_pow, var, pre_var, post_var, pow, post_pow, linebreak; 54 | int first_var, first_pow; 55 | unsigned int monperline; 56 | bool shorten; 57 | }; 58 | 59 | /*! DASimpleFormatter class which formats a DA vector using simple rules to output code suitable for various programming languages. */ 60 | class DACE_API DASimpleFormatter : public DAFormatter 61 | { 62 | public: 63 | static const DASimpleFormat C; 64 | static const DASimpleFormat C_POW; 65 | static const DASimpleFormat FORTRAN; 66 | static const DASimpleFormat FORTRAN_POW; 67 | static const DASimpleFormat MATLAB; 68 | static const DASimpleFormat MATLAB_POW; 69 | static const DASimpleFormat LATEX; 70 | 71 | DASimpleFormat sf; 72 | 73 | DASimpleFormatter() : sf(C) {}; 74 | DASimpleFormatter(const DASimpleFormat& isf) : sf(isf) {}; 75 | 76 | std::string format(const DA &da); 77 | std::string format(const std::vector &da); 78 | }; 79 | 80 | } 81 | #endif /* DINAMICA_DAFORMATTER_H_ */ 82 | -------------------------------------------------------------------------------- /interfaces/cxx/include/dace/DA_t.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * DA_t.h 24 | * 25 | * Created on: Apr 07, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | #ifndef DINAMICA_DA_T_H_ 30 | #define DINAMICA_DA_T_H_ 31 | 32 | // DACE classes 33 | #include "dace/compiledDA.h" 34 | #include "dace/DA.h" 35 | 36 | namespace DACE{ 37 | 38 | /******************************************************************************** 39 | * DA polynomial evaluation routines 40 | *********************************************************************************/ 41 | template T DA::eval(const std::vector &args) const{ 42 | /*! Generic evaluation of the DA with a vector of arithmetic type T arguments. 43 | \param[in] args std::vector of arithmetic type T with which the DA vector is evaluated 44 | \return The result of the evaluation 45 | \throw DACE::DACEException 46 | \note To be used only for single polynomial evaluation. For multiple 47 | evaluations of the same polynomial use the corresponding method in class 48 | compiledDA. 49 | \note This function can be called with a braced initializer list. However, C++ 50 | is not able to derive the type of elements of an initializer list automatically. 51 | That means eval() must be called explicitly as e.g. eval({1.0, 2.0, 3.0}) when 52 | used with initializer lists. 53 | \sa compiledDA::eval 54 | */ 55 | return compiledDA(*this).eval(args)[0]; 56 | } 57 | 58 | template T DA::eval(const T args[], const unsigned int length) const{ 59 | /*! Generic evaluation of the DA with an array of arithmetic type T arguments. 60 | \param[in] args array of arithmetic type T with which the DA vector is evaluated. 61 | \param[in] length number of elements in the array args. 62 | \return The result of the evaluation. 63 | \throw DACE::DACEException 64 | \note To be used only for single polynomial evaluation. For multiple 65 | evaluations of the same polynomial use the corresponding method in class 66 | compiledDA. 67 | \sa compiledDA::eval 68 | */ 69 | return compiledDA(*this).eval(args,length)[0]; 70 | } 71 | 72 | template T DA::evalScalar(const T &arg) const{ 73 | /*! Generic evaluation of the DA with a single arithmetic type T argument. 74 | \param[in] arg single variable of arithmetic type T of the first independent DA variable. 75 | \return The result of the evaluation. 76 | \note To be used only for single polynomial evaluation. For multiple 77 | evaluations of the same polynomial use the corresponding method in class 78 | compiledDA. 79 | \sa compiledDA::evalScalar 80 | */ 81 | return compiledDA(*this).evalScalar(arg)[0]; 82 | } 83 | 84 | template T eval(const DA &da, const std::vector &args) { 85 | /*! Generic evaluation of the DA with a vector of arithmetic type T arguments. 86 | \param[in] da a given DA object. 87 | \param[in] args std::vector of arithmetic type T with which the DA vector is evaluated. 88 | \return The result of the evaluation. 89 | \throw DACE::DACEException 90 | \note To be used only for single polynomial evaluation. For multiple 91 | evaluations of the same polynomial use the corresponding method in class 92 | compiledDA. 93 | \note This function can be called with a braced initializer list. However, C++ 94 | is not able to derive the type of elements of an initializer list automatically. 95 | That means eval() must be called explicitly as e.g. eval(x, {1.0, 2.0, 3.0}) when 96 | used with initializer lists. 97 | \sa compiledDA 98 | */ 99 | return da.eval(args); 100 | } 101 | 102 | template T eval(const DA &da, const T args[], const unsigned int length) { 103 | /*! Generic evaluation of the DA with an array of arithmetic type T arguments. 104 | \param[in] da a given DA object. 105 | \param[in] args array of arithmetic type T with which the DA vector is evaluated. 106 | \param[in] length number of elements in the array args. 107 | \return The result of the evaluation. 108 | \throw DACE::DACEException 109 | \note To be used only for single polynomial evaluation. For multiple 110 | evaluations of the same polynomial use the corresponding method in class 111 | compiledDA. 112 | \sa compiledDA::eval 113 | */ 114 | return da.eval(args,length); 115 | } 116 | 117 | template T evalScalar(const DA &da, const T &arg) { 118 | /*! Generic evaluation of the DA with a single arithmetic type T arguments. 119 | \param[in] da a given DA object. 120 | \param[in] arg single variable of arithmetic type T of the first independent DA variable. 121 | \return The result of the evaluation. 122 | \throw DACE::DACEException 123 | \note To be used only for single polynomial evaluation. For multiple 124 | evaluations of the same polynomial use the corresponding method in class 125 | compiledDA. 126 | \sa compiledDA::evalScalar 127 | */ 128 | return da.evalScalar(arg); 129 | } 130 | 131 | } 132 | #endif /* DINAMICA_DA_T_H_ */ 133 | -------------------------------------------------------------------------------- /interfaces/cxx/include/dace/Interval.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * Interval.h 24 | * 25 | * Created on: Mar 14, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | #ifndef DINAMICA_INTERVAL_H_ 30 | #define DINAMICA_INTERVAL_H_ 31 | 32 | namespace DACE{ 33 | 34 | /*! Class representing an interval. */ 35 | class DACE_API Interval 36 | { 37 | public: 38 | double m_lb; //!< Lower bound. 39 | double m_ub; //!< Upper bound. 40 | }; 41 | 42 | } 43 | #endif /* DINAMICA_INTERVAL_H_ */ 44 | -------------------------------------------------------------------------------- /interfaces/cxx/include/dace/MathExtension.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * MathExtension.h 24 | * 25 | * Created on: Sep. 22, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | #ifndef DINAMICA_MATHEXTENSION_H_ 30 | #define DINAMICA_MATHEXTENSION_H_ 31 | 32 | namespace DACE{ 33 | 34 | DACE_API double cons(const double x); //!< Constant part (i.e. the value x) 35 | DACE_API double logb(const double x, const double b = 10.0); //!< Logarithm relative to base b 36 | DACE_API double isrt(const double x); //!< Inverse square root 37 | DACE_API double sqr(const double x); //!< Square 38 | DACE_API double minv(const double x); //!< Multiplicative inverse 39 | DACE_API double root(const double x, const int p = 2); //!< p-th root 40 | 41 | } 42 | 43 | #endif /* DINAMICA_MATHEXTENSION_H_ */ 44 | -------------------------------------------------------------------------------- /interfaces/cxx/include/dace/Monomial.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * Monomial.h 24 | * 25 | * Created on: Mar 10, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | #ifndef DINAMICA_MONOMIAL_H_ 30 | #define DINAMICA_MONOMIAL_H_ 31 | 32 | // C++ stdlib classes used in this public interface 33 | #include 34 | #include 35 | #include 36 | 37 | namespace DACE{ 38 | 39 | /*! Monomial class */ 40 | class DACE_API Monomial 41 | { 42 | public: 43 | std::vector m_jj; /*!< Vector of exponents. */ 44 | double m_coeff; /*!< Coefficient. */ 45 | 46 | Monomial(); /*!< Default constructor. */ 47 | 48 | unsigned int order() const; /*!< Return the order of the Monomial. */ 49 | std::string toString() const; /*!< Convert current monomial to string.*/ 50 | }; 51 | 52 | DACE_API std::ostream& operator<< (std::ostream &out, const Monomial &m); /*!< Overload output stream operator. */ 53 | 54 | } 55 | 56 | #endif /* DINAMICA_MONOMIAL_H_ */ 57 | -------------------------------------------------------------------------------- /interfaces/cxx/include/dace/PromotionTrait.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * PromotionTrait.h 24 | * 25 | * Created on: Sep. 15, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | #ifndef DINAMICA_PROMOTIONTRAIT_H_ 30 | #define DINAMICA_PROMOTIONTRAIT_H_ 31 | 32 | namespace DACE{ 33 | 34 | // forward declaration 35 | class DA; 36 | 37 | /*********************************************************************************** 38 | PromotionTrait template class 39 | ************************************************************************************/ 40 | /* General template implementation: 41 | By default, everything is a double and two things of the same type return that type. */ 42 | template class PromotionTrait { public: typedef double returnType; }; 43 | template class PromotionTrait { public: typedef T returnType; }; 44 | 45 | // type A with B (and B with A) yields a C 46 | #define ADD_PROMOTION(A,B,C) \ 47 | template<> class PromotionTrait { public: typedef C returnType; }; \ 48 | template<> class PromotionTrait { public: typedef C returnType; }; 49 | 50 | // type A with any other type (and any other type with A) yields a C 51 | // includes also the case A with A to resolve the problem of which template to use otherwise 52 | #define ADD_PROMOTION_ALL(A,C) \ 53 | template class PromotionTrait { public: typedef C returnType; }; \ 54 | template class PromotionTrait { public: typedef C returnType; }; \ 55 | template<> class PromotionTrait { public: typedef C returnType; }; 56 | 57 | /* Specialization for DA: everything with DA returns a DA */ 58 | ADD_PROMOTION_ALL(DA,DA) 59 | 60 | #undef ADD_PROMOTION 61 | #undef ADD_PROMOTION_ALL 62 | } 63 | 64 | // not sure this is a good idea 65 | //#define PROMOTE(A,B) typename PromotionTrait::returnType 66 | 67 | #endif /* DINAMICA_PROMOTIONTRAIT_H_ */ 68 | -------------------------------------------------------------------------------- /interfaces/cxx/include/dace/compiledDA.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * compiledDA.h 24 | * 25 | * Created on: Mar 01, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | #ifndef DINAMICA_COMPILEDDA_H_ 30 | #define DINAMICA_COMPILEDDA_H_ 31 | 32 | // C++ stdlib classes used in this public interface 33 | #include 34 | #include 35 | 36 | namespace DACE{ 37 | 38 | class DA; // forward declaration 39 | 40 | /*! compiledDA class representing a precomputed representation of a polynomial for efficient evaluation. */ 41 | class DACE_API compiledDA 42 | { 43 | private: 44 | double *ac; //!< Compiled polynomial evaluation data 45 | unsigned int dim; //!< Number of polynomials (dimension) 46 | unsigned int ord; //!< Maximum order of the polynomial 47 | unsigned int vars; //!< Number of variables in the polynomial 48 | unsigned int terms; //!< Number of terms in the polynomial 49 | 50 | public: 51 | /******************************************************************************** 52 | * Constructors & Destructors 53 | *********************************************************************************/ 54 | compiledDA(const compiledDA &cda); //!< Copy constructor. 55 | compiledDA(const DA &da); //!< Constructor from a single DA. 56 | compiledDA(const std::vector &da); //!< Constructor from a vector of DA. 57 | ~compiledDA() throw(); //!< Default destructor. 58 | 59 | /******************************************************************************** 60 | * Assignments 61 | *********************************************************************************/ 62 | compiledDA& operator=(const compiledDA &cda); //!< Copy assignment. 63 | 64 | /******************************************************************************** 65 | * Evaluation 66 | *********************************************************************************/ 67 | template V eval(const V &args) const; //!< Evaluate the compiled polynomial with a vector of any arithmetic type and return vector of results. 68 | template std::vector eval(const std::initializer_list l) const; //! std::vector eval(const T args[], const unsigned int length) const; //!< Evaluate the compiled polynomial with an array of any arithmetic type and return vector of results. 70 | template std::vector evalScalar(const T &arg) const; //!< Evaluate the compiled polynomial with a single variable of arithmetic type and return vector of results. 71 | template void eval(const std::vector &args, std::vector &res) const; //!< Evaluate the compiled polynomial with a vector of any arithmetic type and store results in provided vector. 72 | 73 | /******************************************************************************** 74 | * Member access routines 75 | *********************************************************************************/ 76 | const double* getAc() const; //!< Return a pointer to the internal coefficient array 77 | unsigned int getDim() const; //!< Return the number of polynomials 78 | unsigned int getOrd() const; //!< Return the maximum order in all polynomials 79 | unsigned int getVars() const; //!< Return the number of independent variables in all polynomials 80 | unsigned int getTerms() const; //!< Return the number of terms 81 | }; 82 | 83 | // specializations for particularly efficient evaluation with double and DA arguments implemented in the library 84 | template<> DACE_API void compiledDA::eval(const std::vector &args, std::vector &res) const; 85 | template<> DACE_API void compiledDA::eval(const std::vector &args, std::vector &res) const; 86 | 87 | } 88 | #endif /* DINAMICA_COMPILEDDA_H_ */ 89 | -------------------------------------------------------------------------------- /interfaces/cxx/include/dace/compiledDA_t.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * 3 | * DIFFERENTIAL ALGEBRA CORE ENGINE * 4 | * * 5 | ******************************************************************************* 6 | * * 7 | * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); * 9 | * you may not use this file except in compliance with the License. * 10 | * You may obtain a copy of the License at * 11 | * * 12 | * http://www.apache.org/licenses/LICENSE-2.0 * 13 | * * 14 | * Unless required by applicable law or agreed to in writing, software * 15 | * distributed under the License is distributed on an "AS IS" BASIS, * 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 17 | * See the License for the specific language governing permissions and * 18 | * limitations under the License. * 19 | * * 20 | *******************************************************************************/ 21 | 22 | /* 23 | * compiledDA_t.h 24 | * 25 | * Created on: Apr 07, 2014 26 | * Author: Dinamica Srl 27 | */ 28 | 29 | #ifndef DINAMICA_COMPILEDDA_T_H_ 30 | #define DINAMICA_COMPILEDDA_T_H_ 31 | 32 | // DACE classes 33 | #include "dace/compiledDA.h" 34 | 35 | namespace DACE{ 36 | 37 | /******************************************************************************** 38 | * compiledDA evaluation routines 39 | *********************************************************************************/ 40 | template V compiledDA::eval(const V &args) const{ 41 | /*! Evaluate the compiled polynomial with a vector of any arithmetic type 42 | (such as DA or double) and return vector of results. 43 | \param[in] args the values of the independent DA variables to evaluate 44 | with. Must be a std::vector<> (or derived class) of an arithmetic 45 | type. If less than the number of independent DA variables defined 46 | during the DACE initialization are given, the missing entries are 47 | assumed to be zero. 48 | \return Vector with the result of the evaluation. The vector is of 49 | the same type as the argument args. 50 | */ 51 | V res(dim); 52 | eval(args, res); 53 | 54 | return res; 55 | } 56 | 57 | template std::vector compiledDA::eval(const std::initializer_list l) const{ 58 | /*! Evaluate the compiled polynomial with a braced initializer list of any arithmetic type 59 | (such as DA or double) and return vector of results. 60 | \param[in] l the values of the independent DA variables to evaluate 61 | with. Must be a braced initializer list of an arithmetic 62 | type. If less than the number of independent DA variables defined 63 | during the DACE initialization are given, the missing entries are 64 | assumed to be zero. 65 | \return std::vector with the result of the evaluation. 66 | \note C++ is not able to derive the type of elements of an initializer list automatically. 67 | That means eval() must be called explicitly as e.g. eval({1.0, 2.0, 3.0}) when 68 | used with initializer lists. 69 | */ 70 | std::vector res(dim); 71 | eval(std::vector(l), res); 72 | 73 | return res; 74 | } 75 | 76 | template std::vector compiledDA::eval(const T args[], const unsigned int length) const{ 77 | /*! Evaluate the compiled polynomial with an array of any arithmetic type 78 | (such as DA or double) and return vector of results. 79 | \param[in] args array of the values of the independent DA variables to 80 | evaluate with. 81 | \param[in] length Size of the array args[]. If less than the number of 82 | variables defined during the DACE initialization are given, the 83 | missing entries are assumed to be zero. 84 | \return Vector with the result of the evaluation. The vector is of 85 | type std::vector. 86 | */ 87 | std::vector arg(args,args+length); 88 | std::vector res(dim); 89 | eval(arg, res); 90 | 91 | return res; 92 | } 93 | 94 | template std::vector compiledDA::evalScalar(const T &arg) const{ 95 | /*! Evaluate the compiled polynomial with a single argument of any 96 | arithmetic type (such as DA or double) and return vector of results. 97 | \param[in] arg The value of the first independent DA variable to evaluate 98 | with. All remaining independent DA variables are assumed to be zero. 99 | \return Vector with the result of the evaluation. The vector is of 100 | type std::vector. 101 | */ 102 | std::vector args(1); 103 | std::vector res(dim); 104 | args[0] = arg; 105 | eval(args, res); 106 | 107 | return res; 108 | } 109 | 110 | /* Actual evaluation with a std::vector of algebraic type T. 111 | T must support at least: 112 | - default constructor T::T() 113 | - assignment T::operator=(const T& t) 114 | - assignment & addition T::operator+=(const T& t) 115 | - double multiplication T::operator*(const double d) 116 | - double addition T::operator+(const double d) 117 | */ 118 | template void compiledDA::eval(const std::vector &args, std::vector &res) const{ 119 | const unsigned int narg = args.size(); 120 | unsigned int jlskip = ord+1; 121 | double *p = ac+2; 122 | T *xm = new T[ord+1]; 123 | 124 | // prepare temporary powers 125 | xm[0] = args[0]*0.0 + 1.0; 126 | // constant part 127 | for(unsigned int i=0; i jlskip) 134 | { 135 | p += dim; 136 | continue; 137 | } 138 | if(jv >= narg) 139 | { 140 | jlskip = jl; 141 | p += dim; 142 | continue; 143 | } 144 | jlskip = ord+1; 145 | xm[jl] = xm[jl-1]*args[jv]; 146 | for(unsigned int j=0; j