diff --git a/.gitignore b/.gitignore index d9722cfa618a922472a7dede3df8d593bf4e3ab4..e8212a798089e042a61dfd931844075d87096164 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,6 @@ CMakeFiles/ *.mexa* /Debug /DebugMatlab -/DebugArmadillo src/version/version.cpp src/version/version.h src/exceptions/xmlData.cpp @@ -43,3 +42,5 @@ __pycache__/ !/scenarios/*/*.csv secrets/ testing/* +.idea +cmake-build-* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6f18ae8c6175d372b9c5b3e963cce800f721e417..046f9621e7dcffc71d5b18da62b6d0c3408c19db 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,13 +11,13 @@ stages: # configure workflow workflow: rules: - - if: '$CI_COMMIT_BRANCH == "master"' - - if: '$CI_COMMIT_BRANCH == "web"' + - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH" + - if: '$CI_PIPELINE_SOURCE == "web"' - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' # set defaults default: - tags: [ 'docker' ] + tags: ["docker"] # set varialbes variables: @@ -55,9 +55,9 @@ docker-retag-images: - 'docker tag "${CI_REGISTRY_IMAGE}:${CI_MERGE_REQUEST_TARGET_BRANCH_SLUG}_linux_compile" $IMAGE_TAG_LINUX_COMPILE || :' - 'docker tag "${CI_REGISTRY_IMAGE}:${CI_MERGE_REQUEST_TARGET_BRANCH_SLUG}_linux_test" $IMAGE_TAG_LINUX_TEST || :' - 'docker tag "${CI_REGISTRY_IMAGE}:${CI_MERGE_REQUEST_TARGET_BRANCH_SLUG}_windowscc_compile" $IMAGE_TAG_WINDOWSCC_COMPILE || :' - - 'docker push $IMAGE_TAG_LINUX_COMPILE || :' - - 'docker push $IMAGE_TAG_LINUX_TEST || :' - - 'docker push $IMAGE_TAG_WINDOWSCC_COMPILE || :' + - "docker push $IMAGE_TAG_LINUX_COMPILE || :" + - "docker push $IMAGE_TAG_LINUX_TEST || :" + - "docker push $IMAGE_TAG_WINDOWSCC_COMPILE || :" # build docker image and push it into GitLab container registry docker-build-linux-compile: @@ -81,7 +81,7 @@ docker-build-linux-test: rules: - changes: - docker/* - needs: [ "docker-build-linux-compile" ] + needs: ["docker-build-linux-compile"] before_script: - docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY script: @@ -98,8 +98,8 @@ docker-build-windowscc-compile: before_script: - docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY script: - - docker build docker --target iseaframecc --cache-from $IMAGE_TAG_WINDOWSCC_COMPILE --tag $IMAGE_TAG_WINDOWSCC_COMPILE --build-arg BASE_IMAGE="base" - - docker push $IMAGE_TAG_WINDOWSCC_COMPILE + - docker build docker --target iseaframecc --cache-from $IMAGE_TAG_WINDOWSCC_COMPILE --tag $IMAGE_TAG_WINDOWSCC_COMPILE --build-arg BASE_IMAGE="base" + - docker push $IMAGE_TAG_WINDOWSCC_COMPILE linux_compile: stage: build-framework @@ -148,7 +148,7 @@ linux_standalones: image: $IMAGE_TAG_LINUX_COMPILE variables: TARGET_OS: "linux" - needs: [ "linux_compile" ] + needs: ["linux_compile"] artifacts: paths: - buildReleaseLinux/standalones @@ -161,7 +161,7 @@ windows_standalones: image: $IMAGE_TAG_WINDOWSCC_COMPILE variables: TARGET_OS: "windows" - needs: [ "windows_compile" ] + needs: ["windows_compile"] artifacts: paths: - buildReleaseWindows/standalones @@ -224,7 +224,7 @@ standalone_test: documentation: stage: docs image: $IMAGE_TAG_LINUX_COMPILE - needs: [ "linux_compile" ] + needs: ["linux_compile"] artifacts: paths: - buildReleaseLinux/docRelease/html @@ -236,7 +236,7 @@ documentation: development_documentation: stage: docs image: $IMAGE_TAG_LINUX_COMPILE - needs: [ "linux_compile" ] + needs: ["linux_compile"] artifacts: paths: - buildReleaseLinux/doc/html @@ -248,12 +248,12 @@ development_documentation: pages: stage: deploy-docs image: alpine:latest - needs: [ "development_documentation" ] + needs: ["development_documentation"] rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH artifacts: paths: - - public + - public script: - cp -r buildReleaseLinux/doc/html public @@ -262,7 +262,7 @@ docker-build-linux-interactive: # Use the official docker image. image: docker:20.10 stage: build-interactive-docker - needs: [ "linux_standalones" ] + needs: ["linux_standalones"] before_script: - docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY script: diff --git a/CHANGELOG b/CHANGELOG index 373da846532f13e4c2229a82a42337f060192134..4f28d7defe24c092731205f701adf692de20f22b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +Version 2.26.0 +=========== +- Change capacity calculation for the anode overhang to use DVA values +- Switch from mingw to clang for cross-compiling the Windows version +- Add optional XML parameters to set voltage limits for cells + Version 2.25.0 =========== - Add MaxAlphaCapacity, MaxAlphaResistance, MaxBetaCapacity, and MaxBetaResistance XML parameters to specify maximum aging coefficients diff --git a/CMakeLists.txt b/CMakeLists.txt index fdac00d0818f9637720205a8f2defe2409a479de..4dd3d1394f2e4d0145ecaad45dff38683e95d6bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ cmake_minimum_required(VERSION 3.2) project(ISEAFrame) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") +list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/cmake/") cmake_policy(SET CMP0009 NEW) set(ISEAFrameVERSION_MAJOR 2) -set(ISEAFrameVERSION_MINOR 25) +set(ISEAFrameVERSION_MINOR 26) set(ISEAFramePATCH_LEVEL 0) set(ISEAFrameNAME "max_aging") set(ISEAFrameVERSION @@ -35,10 +35,14 @@ if(CMAKE_TOOLCHAIN_FILE) include_directories(${CMAKE_FIND_ROOT_PATH}/include) # the compile options need to be seperated by semicolons so that they are # interpreted as a list - string(REPLACE " " ";" COMPILE_OPTIONS_LIST ${TOOLCHAIN_COMPILE_OPTIONS}) - string(REPLACE " " ";" LINK_OPTIONS_LIST ${TOOLCHAIN_LINK_OPTIONS}) - add_compile_options(${COMPILE_OPTIONS_LIST}) - add_link_options(${LINK_OPTIONS_LIST}) + if(TOOLCHAIN_COMPILE_OPTIONS) + string(REPLACE " " ";" COMPILE_OPTIONS_LIST ${TOOLCHAIN_COMPILE_OPTIONS}) + add_compile_options(${COMPILE_OPTIONS_LIST}) + endif() + if(TOOLCHAIN_LINK_OPTIONS) + string(REPLACE " " ";" LINK_OPTIONS_LIST ${TOOLCHAIN_LINK_OPTIONS}) + add_link_options(${LINK_OPTIONS_LIST}) + endif() endif() if(CMAKE_SYSTEM_NAME STREQUAL Windows) @@ -85,10 +89,17 @@ else() if(${USE_DEBUG_GDB}) add_compile_options(-ggdb) endif() - add_compile_options(-fPIC) + if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_compile_options(-fPIC) + endif() if(${BUILD_FOR_NATIVE_ARCH}) add_compile_options(-march=native) endif() + if(WIN_TARGET) + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + link_libraries("bcrypt") + endif() + endif() endif() if(BUILD_FOR_RT) diff --git a/README.md b/README.md index a1a70aeded2b68f3378588724803ed77a0671157..a87d2457fddb525aad3926a30ca3d0055647da47 100644 --- a/README.md +++ b/README.md @@ -32,17 +32,15 @@ Downloads ========= Precompiled versions can be downloaded from Gitlab. -Linux Standalones: [Download](https://git.rwth-aachen.de/isea/framework/-/jobs/artifacts/master/download?job=linux_standalones)<br/> -Windows Standalones: [Download](https://git.rwth-aachen.de/isea/framework/-/jobs/artifacts/master/download?job=windows_standalones)<br/> -Wndows Simulink Converter: [Download](https://git.rwth-aachen.de/isea/framework/-/jobs/artifacts/master/download?job=windows_simulink_converter)<br/> +Linux Standalones: [Download](https://git.rwth-aachen.de/isea/framework/-/jobs/artifacts/main/download?job=linux_standalones)<br/> +Windows Standalones: [Download](https://git.rwth-aachen.de/isea/framework/-/jobs/artifacts/main/download?job=windows_standalones)<br/> <br/><br/> -Documentation: [View online](https://isea.pages.rwth-aachen.de/framework) | [Download](https://git.rwth-aachen.de/isea/framework/-/jobs/artifacts/master/download?job=documentation) | [Download Development Version](https://git.rwth-aachen.de/isea/framework/-/jobs/artifacts/master/download?job=development_documentation) +Documentation: [View online](https://isea.pages.rwth-aachen.de/framework) | [Download](https://git.rwth-aachen.de/isea/framework/-/jobs/artifacts/main/download?job=documentation) | [Download Development Version](https://git.rwth-aachen.de/isea/framework/-/jobs/artifacts/main/download?job=development_documentation) Required Software: ============================== + eigen3 -+ armadillo + boost + matio diff --git a/benchmark/frameworkBenchmark_ThEl.cpp b/benchmark/frameworkBenchmark_ThEl.cpp index c83b1aef30ed63b52446c06670f7d80eb8695ae0..99de66dba42068b606cb16f2b34d50b744410b61 100644 --- a/benchmark/frameworkBenchmark_ThEl.cpp +++ b/benchmark/frameworkBenchmark_ThEl.cpp @@ -166,14 +166,10 @@ int main( int argc, char *argv[] ) // Equation solvers boost::numeric::odeint::result_of::make_controlled< boost::numeric::odeint::runge_kutta_cash_karp54< vector< double > > >::type stepperThermal = make_controlled( 1.0e-10, 1.0e-10, boost::numeric::odeint::runge_kutta_cash_karp54< vector< double > >() ); -#if defined( _ARMADILLO_ ) && not defined( SPARSE_MATRIX_FORMAT ) - boost::numeric::odeint::result_of::make_controlled< boost::numeric::odeint::runge_kutta_cash_karp54< myMatrixType > >::type stepperElectrical = - make_controlled( 1.0e-10, 1.0e-10, boost::numeric::odeint::runge_kutta_cash_karp54< myMatrixType >() ); -#else + boost::numeric::odeint::result_of::make_controlled< boost::numeric::odeint::runge_kutta_cash_karp54< vector< double > > >::type stepperElectrical = make_controlled( 1.0e-10, 1.0e-10, boost::numeric::odeint::runge_kutta_cash_karp54< vector< double > >() ); std::vector< double > tmpStateVector( electricalSimulation->mStateSystemGroup.mStateVector.n_rows, 0.0 ); -#endif boost::posix_time::ptime electricalStart; boost::posix_time::time_duration electricalDuration; @@ -211,16 +207,7 @@ int main( int argc, char *argv[] ) break; } -#if defined( _ARMADILLO_ ) && !defined( SPARSE_MATRIX_FORMAT ) - // Run electrical equation solver - electricalSimulation->mStateSystemGroup.mDt = electricalSimulation->mDeltaTime; - while ( stepperElectrical.try_step( boost::ref( *electricalSimulation->mEqSystem ), - electricalSimulation->mStateSystemGroup.mStateVector, electricalSimulation->mTime, - electricalSimulation->mDeltaTime ) != boost::numeric::odeint::success ) - { - electricalSimulation->mStateSystemGroup.mDt = electricalSimulation->mDeltaTime; - } -#else + // Run electrical equation solver misc::FastCopyMatrix( &tmpStateVector[0], electricalSimulation->mStateSystemGroup.mStateVector, tmpStateVector.size() ); electricalSimulation->mStateSystemGroup.mDt = electricalSimulation->mDeltaTime; @@ -231,7 +218,6 @@ int main( int argc, char *argv[] ) electricalSimulation->mStateSystemGroup.mDt = electricalSimulation->mDeltaTime; } misc::FastCopyMatrix( electricalSimulation->mStateSystemGroup.mStateVector, &tmpStateVector[0], tmpStateVector.size() ); -#endif electricalSimulation->UpdateSystemValues(); electricalSimulation->UpdateAllThermalStatesPowerDissipation(); diff --git a/buildtools/make_release.sh b/buildtools/make_release.sh index 8c6c03315471b6839028143da6aaf82efecd110a..6f750607fc67b42b5236293f078659158c0d10e0 100755 --- a/buildtools/make_release.sh +++ b/buildtools/make_release.sh @@ -40,7 +40,7 @@ function RunCMake then if [ $WIN_TARGET -eq 1 ] # crosscompile then - CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_TOOLCHAIN_FILE=../toolchain_files/ToolchainWin64.cmake" + CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_TOOLCHAIN_FILE=../toolchain_files/ToolchainClangLinux2Win.cmake -DBoost_COMPILER=vc143" fi fi CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_BUILD_TYPE:STRING=Release -DARCH_TYPE:STRING=64 -DBUILD_AGING:BOOL=ON -DBUILD_NUMERIC:BOOL=ON -DBUILD_SYMBOLIC:BOOL=ON -DBUILD_UNITTESTS:BOOL=ON -DBUILD_DOCS:BOOL=ON -DCREATE_RELEASE_DIRS:BOOL=ON" diff --git a/cmake/FindMATIO.cmake b/cmake/Findmatio.cmake similarity index 100% rename from cmake/FindMATIO.cmake rename to cmake/Findmatio.cmake diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000000000000000000000000000000000000..9b970aff0116e9685123c9516e1133fd63b06a65 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,16 @@ +from conans import ConanFile, CMake + + +class ISEAFrameworkConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + requires = ( + "boost/1.78.0", + "eigen/3.4.0", + 'matio/1.5.21', + ) # comma-separated list of requirements + generators = "cmake_find_package_multi","cmake_find_package" + default_options = {"boost:shared": False} + + def imports(self): + self.copy("*.dll", dst="bin", src="bin") # From bin to bin + self.copy("*.dylib*", dst="bin", src="lib") # From lib to bin diff --git a/docker/Docker.md b/docker/Docker.md index 6668e4ad0d5f8184b6855ee2a9eab9d579ae4548..9351b6ae075a3b97a77ecc2ad904f0f3b820d754 100644 --- a/docker/Docker.md +++ b/docker/Docker.md @@ -16,5 +16,4 @@ Build local docker image Run local docker image -'docker run --rm -it iseaframe_cicd:local' - +'docker run --rm -it iseaframe_cicd:local' \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 1c738cac0b1efd39006d90b2fa4732c8236d045e..f1de67f676b72c4b9249709022aac7e195bd54e1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,11 +1,11 @@ ARG BASE_IMAGE=base -FROM phusion/baseimage:hirsute AS iseaframe-base +FROM phusion/baseimage:jammy-1.0.0 AS iseaframe-base -FROM mathworks/matlab:r2020b AS iseaframe-matlab +FROM mathworks/matlab:r2021b AS iseaframe-matlab FROM iseaframe-${BASE_IMAGE} AS iseaframebase - + ARG DEBIAN_FRONTEND=noninteractive @@ -30,7 +30,6 @@ RUN set -ex ; \ cmake \ libeigen3-dev \ libmatio-dev \ - libarmadillo-dev \ valgrind \ graphviz ; \ apt-get -y -qq install --no-install-recommends ccache ; \ @@ -39,15 +38,15 @@ RUN set -ex ; \ # install python packages RUN pip install --no-cache-dir numpy matplotlib scipy + FROM iseaframebase AS iseaframelinux # noop if base=matlab, needed otherwise -COPY --from=iseaframe-matlab /opt/matlab/R2020b/appdata/version.xml /usr/local/MATLAB/R2020b/appdata/version.xml -COPY --from=iseaframe-matlab /opt/matlab/R2020b/extern /usr/local/MATLAB/R2020b/extern/ -COPY --from=iseaframe-matlab /opt/matlab/R2020b/bin/mexext /usr/local/MATLAB/R2020b/bin/ -COPY --from=iseaframe-matlab /opt/matlab/R2020b/bin/glnxa64/libmat.so /usr/local/MATLAB/R2020b/bin/glnxa64/ -COPY --from=iseaframe-matlab /opt/matlab/R2020b/bin/glnxa64/libmex.so /usr/local/MATLAB/R2020b/bin/glnxa64/ -COPY --from=iseaframe-matlab /opt/matlab/R2020b/bin/glnxa64/libmx.so /usr/local/MATLAB/R2020b/bin/glnxa64/ +COPY --from=iseaframe-matlab /opt/matlab/R2021b/extern /usr/local/MATLAB/R2021b/extern/ +COPY --from=iseaframe-matlab /opt/matlab/R2021b/bin/mexext /usr/local/MATLAB/R2021b/bin/ +COPY --from=iseaframe-matlab /opt/matlab/R2021b/bin/glnxa64/libmat.so /usr/local/MATLAB/R2021b/bin/glnxa64/ +COPY --from=iseaframe-matlab /opt/matlab/R2021b/bin/glnxa64/libmex.so /usr/local/MATLAB/R2021b/bin/glnxa64/ +COPY --from=iseaframe-matlab /opt/matlab/R2021b/bin/glnxa64/libmx.so /usr/local/MATLAB/R2021b/bin/glnxa64/ # lbzip2 package in ubuntu hirsute is broken https://bugs.launchpad.net/ubuntu/+source/lbzip2/+bug/1926092 # temporarily installed from focal repo @@ -58,8 +57,8 @@ RUN set -ex; \ echo "deb http://cz.archive.ubuntu.com/ubuntu focal main universe" > /etc/apt/sources.list ; \ apt-get update; \ apt-get install -y --no-install-recommends \ - wget \ - lbzip2 ; \ + wget \ + lbzip2 ; \ mkdir -p /usr/src/boost; \ cd /usr/src; \ wget -O boost.tar.bz2 https://boostorg.jfrog.io/artifactory/main/release/1.67.0/source/boost_1_67_0.tar.bz2; \ @@ -74,6 +73,8 @@ RUN set -ex; \ mv /etc/apt/sources.list.bu /etc/apt/sources.list ; \ rm -rf /var/lib/apt/lists/* +# force usage of system libraries +RUN rm -f /usr/local/MATLAB/R2021b/sys/os/glnxa64/libstdc++.so.6 FROM iseaframebase AS iseaframecc @@ -93,69 +94,106 @@ RUN set -ex ; \ # lbzip2 package in ubuntu hirsute is broken https://bugs.launchpad.net/ubuntu/+source/lbzip2/+bug/1926092 # temporarily installed from focal repo -# install boost -COPY patches/boost/gcc.jam.patch /usr/src/patches/boost/gcc.jam.patch -COPY patches/boost/mc.jam.patch /usr/src/patches/boost/mc.jam.patch -RUN set -ex; \ - cp /etc/apt/sources.list /etc/apt/sources.list.bu ; \ - echo "deb http://cz.archive.ubuntu.com/ubuntu focal main universe" > /etc/apt/sources.list ; \ - apt-get update; \ - apt-get install -y --no-install-recommends \ - wget \ - patch \ - lbzip2 ; \ - mkdir -p /usr/src/boost; \ - cd /usr/src; \ - wget -O boost.tar.bz2 https://boostorg.jfrog.io/artifactory/main/release/1.71.0/source/boost_1_71_0.tar.bz2; \ - tar -I lbzip2 -xf boost.tar.bz2 -C boost --strip-components=1; \ - cd boost; \ - patch /usr/src/boost/tools/build/src/tools/gcc.jam /usr/src/patches/boost/gcc.jam.patch ; \ - patch /usr/src/boost/tools/build/src/tools/mc.jam /usr/src/patches/boost/mc.jam.patch ; \ - echo "using gcc : mingw : x86_64-w64-mingw32-g++-posix ;" > user-config.jam; \ - ./bootstrap.sh mingw; \ - ./b2 --user-config=./user-config.jam toolset=gcc-mingw mc-compiler=windmc target-os=windows variant=release address-model=64 stage -j $(nproc) || :; \ - mkdir -p /usr/x86_64-w64-mingw32/FrameworkExtensions/boost; \ - mkdir -p /usr/x86_64-w64-mingw32/FrameworkExtensions/include; \ - mkdir -p /usr/x86_64-w64-mingw32/FrameworkExtensions/lib; \ - cp -R /usr/src/boost/boost /usr/x86_64-w64-mingw32/FrameworkExtensions/include/boost; \ - cp stage/lib/* /usr/x86_64-w64-mingw32/FrameworkExtensions/lib/; \ - cd ..; \ - rm -r patches; \ - rm -r boost; \ - rm boost.tar.bz2; \ - apt-get autoremove -y wget patch lbzip2 ; \ - mv /etc/apt/sources.list.bu /etc/apt/sources.list ; \ - rm -rf /var/lib/apt/lists/* - +# boost +RUN set -ex ; \ + apt-get update ; \ + DEBIAN_FRONTEND=noninteractive apt-get -y -qq install --no-install-recommends \ + curl p7zip ; \ + curl --fail -L https://downloads.sourceforge.net/project/boost/boost-binaries/1.79.0/boost_1_79_0-bin-msvc-all-32-64.7z -o boost_1_79_0-bin-msvc-all-32-64.7z ; \ + 7zr x boost_1_79_0-bin-msvc-all-32-64.7z ; \ + mkdir -p /usr/x86_64-w64-mingw32/FrameworkExtensions/boost ; \ + mkdir -p /usr/x86_64-w64-mingw32/FrameworkExtensions/include ; \ + mkdir -p /usr/x86_64-w64-mingw32/FrameworkExtensions/lib ; \ + mv boost_1_79_0/boost /usr/x86_64-w64-mingw32/FrameworkExtensions/include ; \ + sed -i "s+// #define BOOST_ALL_NO_LIB+#define BOOST_ALL_NO_LIB+g" /usr/x86_64-w64-mingw32/FrameworkExtensions/include/boost/config/user.hpp ; \ + mv boost_1_79_0/lib64-msvc-14.3/* /usr/x86_64-w64-mingw32/FrameworkExtensions/lib ; \ + rm -rf boost_1_79_0-bin-msvc-all-32-64.7z boost_1_79_0 ; \ + apt-get purge --autoremove -y curl p7zip ; \ + rm -rf /var/lib/apt/lists/* ; + + +# clang/lld/llvm +RUN set -eux; \ + mkdir -p /usr/local/share/keyrings; \ + apt-get update && apt-get install -y -qq --no-install-recommends gpg curl; \ + # clang/lld/llvm + curl --fail https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor > /usr/local/share/keyrings/llvm.gpg; \ + echo "deb [signed-by=/usr/local/share/keyrings/llvm.gpg] http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-13 main" > /etc/apt/sources.list.d/llvm.list; \ + apt-get update && apt-get install --no-install-recommends -y \ + clang-13 \ + llvm-13 \ + lld-13 ; \ + # ensure that clang/clang++ are callable directly + ln -s clang-13 /usr/bin/clang && ln -s clang /usr/bin/clang++ && ln -s lld-13 /usr/bin/ld.lld; \ + # We also need to setup symlinks ourselves for the MSVC shims because they aren't in the debian packages + ln -s clang-13 /usr/bin/clang-cl && ln -s llvm-ar-13 /usr/bin/llvm-lib && ln -s lld-link-13 /usr/bin/lld-link; \ + ln -s llvm-mt-13 /usr/bin/mt ; \ + # Verify the symlinks are correct + clang++ -v; \ + ld.lld -v; \ + # Doesn't have an actual -v/--version flag, but it still exits with 0 + llvm-lib -v; \ + clang-cl -v; \ + lld-link --version; \ + # Use clang instead of gcc when compiling binaries targeting the host (eg proc macros, build files) + update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100; \ + update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100; \ + apt-get purge -y --auto-remove curl gpg; \ + rm -rf /var/lib/apt/lists/*; + +# xwin +RUN set -eux; \ + xwin_version="0.2.4"; \ + xwin_prefix="xwin-$xwin_version-x86_64-unknown-linux-musl"; \ + apt-get update && apt-get install -y -qq --no-install-recommends curl tar ; \ + curl --fail -L https://github.com/Jake-Shadle/xwin/releases/download/$xwin_version/$xwin_prefix.tar.gz | tar -xzv --strip-components=1 $xwin_prefix/xwin; \ + # Splat the CRT and SDK files to /xwin/crt and /xwin/sdk respectively + ./xwin --accept-license splat --output /usr/x86_64-w64-mingw32/FrameworkExtensions/xwin ; \ + ln -s /usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/lib/x86_64/msvcrt.lib /usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/lib/x86_64/msvcrtd.lib ; \ + # Remove unneeded files to reduce image size + rm -rf .xwin-cache ./xwin; \ + apt-get purge -y --auto-remove curl ; \ + # tar is needed by dpkg + rm -rf /var/lib/apt/lists/*; + # install zlib COPY ToolchainWin64.cmake /usr/src/toolchain_files/ToolchainWin64.cmake +COPY ToolchainClangLinux2Win.cmake /usr/src/toolchain_files/ToolchainClangLinux2Win.cmake RUN cd /usr/src ; \ git clone https://github.com/madler/zlib.git ; \ mkdir zlib/build ; \ cd zlib/build ; \ - cmake .. -DCMAKE_TOOLCHAIN_FILE=/usr/src/toolchain_files/ToolchainWin64.cmake ; \ + cmake .. -DCMAKE_TOOLCHAIN_FILE=/usr/src/toolchain_files/ToolchainClangLinux2Win.cmake ; \ make -j8 ; \ - make install ; \ mkdir -p /usr/x86_64-w64-mingw32/FrameworkExtensions/lib/64/ ; \ - cp libzlib.dll /usr/x86_64-w64-mingw32/FrameworkExtensions/lib/64/ - + cp zlibd.dll /usr/x86_64-w64-mingw32/FrameworkExtensions/lib/64/libzlib.dll + # install matio RUN cd /usr/src ; \ git clone https://github.com/tbeu/matio.git ; \ mkdir matio/build ; \ cd matio/build ; \ - cmake .. -DCMAKE_TOOLCHAIN_FILE=/usr/src/toolchain_files/ToolchainWin64.cmake -DMATIO_MAT73:BOOL=OFF -DMATIO_WITH_HDF5:BOOL=OFF -DMATIO_SHARED:BOOL=OFF ; \ + cmake .. -DCMAKE_TOOLCHAIN_FILE=/usr/src/toolchain_files/ToolchainClangLinux2Win.cmake -DMATIO_MAT73:BOOL=OFF -DMATIO_WITH_HDF5:BOOL=OFF -DMATIO_SHARED:BOOL=OFF ; \ make -j8 ; \ - make install ; \ - cp libmatio.a /usr/x86_64-w64-mingw32/FrameworkExtensions/lib/libmatio64.lib ; \ + cp libmatio.lib /usr/x86_64-w64-mingw32/FrameworkExtensions/lib/libmatio64.lib ; \ mkdir -p /usr/x86_64-w64-mingw32/FrameworkExtensions/include/ ; \ cp ../src/*.h /usr/x86_64-w64-mingw32/FrameworkExtensions/include/ ; \ cp ./src/*.h /usr/x86_64-w64-mingw32/FrameworkExtensions/include/ RUN cp /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll /usr/x86_64-w64-mingw32/FrameworkExtensions/lib/64/libwinpthread-1.dll ; \ - cp -r /usr/include/eigen3 /usr/x86_64-w64-mingw32/FrameworkExtensions/include/eigen3 ; \ - cp -r /usr/include/armadillo_bits /usr/x86_64-w64-mingw32/FrameworkExtensions/include/armadillo_bits ; \ - cp /usr/include/armadillo /usr/x86_64-w64-mingw32/FrameworkExtensions/include/armadillo + cp -r /usr/include/eigen3 /usr/x86_64-w64-mingw32/FrameworkExtensions/include/eigen3 + +# install cxxtest headers +RUN cd /usr/src ; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + wget ; \ + wget https://netcologne.dl.sourceforge.net/project/cxxtest/cxxtest/4.4/cxxtest-4.4.tar.gz ; \ + tar -xf cxxtest-4.4.tar.gz ; \ + mv cxxtest-4.4/cxxtest/ /usr/x86_64-w64-mingw32/FrameworkExtensions/include/ ; \ + rm cxxtest-4.4.tar.gz ; \ + rm -r cxxtest-4.4 ; \ + apt-get autoremove -y wget FROM iseaframelinux AS iseaframedev RUN set -ex ; \ @@ -164,9 +202,9 @@ RUN set -ex ; \ liblapack-dev \ libmpich-dev \ libopenblas-dev \ - clang \ - clang-format \ - clang-tidy \ + clang \ + clang-format \ + clang-tidy \ git-lfs ; \ rm -rf /var/lib/apt/lists/* diff --git a/docker/ToolchainClangLinux2Win.cmake b/docker/ToolchainClangLinux2Win.cmake new file mode 100644 index 0000000000000000000000000000000000000000..f40b8bbb7667d79f18beb477feb6f68d2d7e5490 --- /dev/null +++ b/docker/ToolchainClangLinux2Win.cmake @@ -0,0 +1,35 @@ +set(CMAKE_SYSTEM_NAME Windows) + +set(CMAKE_C_COMPILER clang-cl) +set(CMAKE_CXX_COMPILER clang-cl) + +set(CMAKE_RC_COMPILER llvm-rc-13) + +set(CMAKE_C_FLAGS "-Wno-unused-command-line-argument -fuse-ld=lld-link /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/include /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/ucrt /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/um /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/shared") +set(CMAKE_CXX_FLAGS "-Wno-unused-command-line-argument -fuse-ld=lld-link /GR /EHsc /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/include /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/ucrt /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/um /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/shared") +set(CMAKE_RC_FLAGS "-Wno-unused-command-line-argument -fuse-ld=lld-link /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/include /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/ucrt /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/um /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/shared") + +set(CMAKE_EXE_LINKER_FLAGS "/libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/um/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/lib/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/ucrt/x86_64") +set(CMAKE_SHARED_LINKER_FLAGS "/libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/um/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/lib/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/ucrt/x86_64") +set(CMAKE_MODULE_LINKER_FLAGS "/libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/um/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/lib/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/ucrt/x86_64") +set(CMAKE_STATIC_LINKER_FLAGS "/libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/um/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/lib/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/ucrt/x86_64") + +set(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32/FrameworkExtensions") +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +set(Matlab_INCLUDE_DIRS + /usr/x86_64-w64-mingw32/matlab/include + CACHE STRING "Path to matlab header files") +file(GLOB LIBRARIES /usr/x86_64-w64-mingw32/matlab/lib/*.lib) +set(Matlab_LIBRARIES + ${LIBRARIES} + CACHE STRING "Path to matlab library files") + +set(TOOLCHAIN_COMPILE_OPTIONS "" CACHE STRING "Compile options specified by the toolchain file") +set(TOOLCHAIN_LINK_OPTIONS "" CACHE STRING "Compile options specified by the toolchain file") + +cmake_policy(SET CMP0091 NEW) +set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL) \ No newline at end of file diff --git a/doxygen/Doxyfile.in b/doxygen/Doxyfile.in index 7eee076780b376385ea0148b76bb0cf2f8876f25..51f96dc8471a833a30391a441dd4f1577be0b243 100644 --- a/doxygen/Doxyfile.in +++ b/doxygen/Doxyfile.in @@ -2054,7 +2054,6 @@ INCLUDE_FILE_PATTERNS = PREDEFINED = BOOST_MPI \ BOOST_THREAD \ - _ARMADILLO_ \ __EXCEPTIONS__ \ BUILD_AGING_SIMULATION diff --git a/doxygen/Doxyfile_release.in b/doxygen/Doxyfile_release.in index 9f3a64ea12d329f7e63bf3d490c4413e14b4e28e..d5084e4f3c03ae622f632352abc0f98b7c220bf9 100644 --- a/doxygen/Doxyfile_release.in +++ b/doxygen/Doxyfile_release.in @@ -2048,7 +2048,6 @@ INCLUDE_FILE_PATTERNS = PREDEFINED = BOOST_MPI \ BOOST_THREAD \ - _ARMADILLO_ \ __EXCEPTIONS__ # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this diff --git a/doxygen/compiling.md b/doxygen/compiling.md index 0e2a374b1cf6ed25199902eaae1cb3cdceea267f..a1e5098390eb5bea17c74d804b21b768282cfa58 100644 --- a/doxygen/compiling.md +++ b/doxygen/compiling.md @@ -4,7 +4,7 @@ Compiling the framework {#compiling} Linux ----- -The libraries eigen3, armadillo, boost and matio need to be installed. +The libraries eigen3, boost and matio need to be installed. The build options must be configured using cmake. To select the options ccmake can be used as a CLI interface. Afterwards make is used to compile. For example: ```bash @@ -75,36 +75,36 @@ CMake Options The cmake file provides severeal cached options that can be configured using ccmake or passed as command line options. -| Option | Explanation | -| ----------------------------------- | ----------- | -| ARCH_TYPE | Either 64 or 32, depending ón the target system | -| BUILD_AGING | Build all classes required for the aging simulation | -| BUILD_AGING_SIMULATION | Build a standalone for aging simulations | -| BUILD_DOCS | Generate this documentation using doxygen | -| BUILD_DOT_EXPORT | Build a standalone that creates dot files showing the electrical circuit | -| BUILD_EIGENWERTE | Build a standalone that calculates the Eigenwerte of a system | -| BUILD_ELECTRICAL_SIMULATION | Build a standalone for electrical simulations | -| BUILD_FOR_RT | Set compiler options needed for the realtime system, disable strings, streams and exceptions | -| BUILD_GETTOTALCAPACITY | Build a standalone that calculated the total capacity of the whole system | -| BUILD_NUMERIC | Build the numeric version of the ISEAFrame library | -| BUILD_QUICKVERIFICATION | Build a standalone that verifies XML files and determines the simulation type | -| BUILD_SIMULINK_MATRIX_MODEL | Build mex files that create a simulink model from an XML file | -| BUILD_SVG_EXPORT | Build a standalone that creates svg files showing the electrical circuit | -| BUILD_SYMBOLIC | Build the symbolic version of the ISEAFrame library | -| BUILD_SYMBOLIC_2_TEX | Build a standalone that creates tex files from a symbolic string | -| BUILD_SYSTEM_2_MATLAB | Build a standalone that creates a matlab file of the equation system | -| BUILD_SYSTEM_2_SYMBOLIC | Build a standalone that prints the symbolic equations describing a system | -| BUILD_SYSTEM_2_TEX | Build a standalone that creates tex files with the equations describing the system | -| BUILD_S_FUNCTIONS | Create mex files for using the framework as a block in a simulink model | -| BUILD_THERMAL_ELECTRICAL_SIMULATION | Build a standalone for thermal-electrical simulations | -| BUILD_THERMAL_SIMULATION | Build a standalone for thermal simulations | -| BUILD_UNITTESTS | Build unittests | -| BUILD_VISUALIZER | Build a standalone for creating csv files describing the thermal areas and volumes | -| CMAKE_BUILD_TYPE | Either RELEASE or DEBUG, determines the level of optimization done by the compiler | -| ERROR_LANG | Either EN or DE, sets the language of error messages | -| MATRIX_IMPLEMENTATION | Can be Eigen, Armadillo or Sparse (currently only Eigen). Sets which type of matrix ist used | -| MATLAB_INCLUDE_DIR | Location of the matlab header files | -| MATLIAB_LINK_DIR | Location of the matlab libraries | -| SIMULINK_INCLUDE_DIR | Location of the simulink header files | -| USE_BOOST_THREADS | Enable multithreading | -| USE_DEBUG_GDB | Add debug symbols to the build so that gdb can display function and variable names | +| Option | Explanation | +| ----------------------------------- |----------------------------------------------------------------------------------------------| +| ARCH_TYPE | Either 64 or 32, depending ón the target system | +| BUILD_AGING | Build all classes required for the aging simulation | +| BUILD_AGING_SIMULATION | Build a standalone for aging simulations | +| BUILD_DOCS | Generate this documentation using doxygen | +| BUILD_DOT_EXPORT | Build a standalone that creates dot files showing the electrical circuit | +| BUILD_EIGENWERTE | Build a standalone that calculates the Eigenwerte of a system | +| BUILD_ELECTRICAL_SIMULATION | Build a standalone for electrical simulations | +| BUILD_FOR_RT | Set compiler options needed for the realtime system, disable strings, streams and exceptions | +| BUILD_GETTOTALCAPACITY | Build a standalone that calculated the total capacity of the whole system | +| BUILD_NUMERIC | Build the numeric version of the ISEAFrame library | +| BUILD_QUICKVERIFICATION | Build a standalone that verifies XML files and determines the simulation type | +| BUILD_SIMULINK_MATRIX_MODEL | Build mex files that create a simulink model from an XML file | +| BUILD_SVG_EXPORT | Build a standalone that creates svg files showing the electrical circuit | +| BUILD_SYMBOLIC | Build the symbolic version of the ISEAFrame library | +| BUILD_SYMBOLIC_2_TEX | Build a standalone that creates tex files from a symbolic string | +| BUILD_SYSTEM_2_MATLAB | Build a standalone that creates a matlab file of the equation system | +| BUILD_SYSTEM_2_SYMBOLIC | Build a standalone that prints the symbolic equations describing a system | +| BUILD_SYSTEM_2_TEX | Build a standalone that creates tex files with the equations describing the system | +| BUILD_S_FUNCTIONS | Create mex files for using the framework as a block in a simulink model | +| BUILD_THERMAL_ELECTRICAL_SIMULATION | Build a standalone for thermal-electrical simulations | +| BUILD_THERMAL_SIMULATION | Build a standalone for thermal simulations | +| BUILD_UNITTESTS | Build unittests | +| BUILD_VISUALIZER | Build a standalone for creating csv files describing the thermal areas and volumes | +| CMAKE_BUILD_TYPE | Either RELEASE or DEBUG, determines the level of optimization done by the compiler | +| ERROR_LANG | Either EN or DE, sets the language of error messages | +| MATRIX_IMPLEMENTATION | Can be Eigen or Sparse (currently only Eigen). Sets which type of matrix ist used | +| MATLAB_INCLUDE_DIR | Location of the matlab header files | +| MATLIAB_LINK_DIR | Location of the matlab libraries | +| SIMULINK_INCLUDE_DIR | Location of the simulink header files | +| USE_BOOST_THREADS | Enable multithreading | +| USE_DEBUG_GDB | Add debug symbols to the build so that gdb can display function and variable names | diff --git a/doxygen/xmloptionen.md b/doxygen/xmloptionen.md index 24398f835bd58768f26917e0a8ebb8be664b6507..073bfb52030500c6b8b92dbca3e982f095eeb4bb 100644 --- a/doxygen/xmloptionen.md +++ b/doxygen/xmloptionen.md @@ -12,8 +12,9 @@ SocStopCriterion | % | 5.0 | Maximum va ThermalStopCriterionInDegreeC | °C | 5.0 | Maximum temperature change in any thermal state during a thermal simulation step before the electrcal simulation is reset. Cycles | int > 0 | 1 | Gives the number of times the current/power profile is executed by the [thermal-electrical standalone](xmlexecutable.html) SampleRate | Hz | 1.0e6 | Sample rate for the automatic simplification of fast time constants, see [automatic simplification](xmlvereinfachung.html) -MaximalOperationalCellVoltageV | V | no limit | Maximum voltage of the simulated cells. If any cell voltage goes above this limit, values from the current profile are skipped until a negative value / discharge is found. -MinimalOperationalCellVoltageV | V | no limit | Minimum voltage of the simulated cells. If any cell voltage goes below this limit, values from the current profile are skipped until a positive value / charge is found. +MaximalOperationalCellVoltageV | V | 10.0 | Maximum voltage of the simulated cells. If any cell voltage goes above this limit, values from the current profile are skipped until a negative value / discharge is found. +MinimalOperationalCellVoltageV | V | 0.0 | Minimum voltage of the simulated cells. If any cell voltage goes below this limit, values from the current profile are skipped until a positive value / charge is found. +VerificationDelayForVoltageLimitSteps | Steps | 4 | Number of electrical simulations steps before the breach of the operational limits is verified again. This allows the electrical model to "leave" the boundaries. Thermal model =============== diff --git a/scenarios/aging/i3Cell_aging.xml b/scenarios/aging/i3Cell_aging.xml index 38a0a12ff7b7f8164a84624da6dd37405ead8832..24dc06fd31a27a1d74c892423eff9351af01b951 100644 --- a/scenarios/aging/i3Cell_aging.xml +++ b/scenarios/aging/i3Cell_aging.xml @@ -269,9 +269,9 @@ <Cyclical class="CyclicalAging"> <ChargeExponentCapacity>0.5</ChargeExponentCapacity> <ChargeExponentResistance>1</ChargeExponentResistance> - <FormulaCapacity>4.0 * pow( 10, -3 ) * pow( meanV - 4.5, 2 ) + 6.5 * pow( 10, -4 ) + 4.0 * pow( 10, -3 ) * deltaDOD</FormulaCapacity> + <FormulaCapacity>4.0 * pow( 10, -3 ) * pow( meanV - 4.5, 2 ) + 6.5 * pow( 10, -4 ) + 4.0 * pow( 10, -5 ) * deltaDOD</FormulaCapacity> <MinBetaCapacity>0</MinBetaCapacity> - <FormulaResistance>2.0 * pow( 10, -4 ) * pow( meanV - 3.5, 2 ) - 1.3 * pow( 10, -5 ) + 3.0 * pow( 10, -4 ) * deltaDOD</FormulaResistance> + <FormulaResistance>2.0 * pow( 10, -4 ) * pow( meanV - 3.5, 2 ) - 1.3 * pow( 10, -5 ) + 3.0 * pow( 10, -6 ) * deltaDOD</FormulaResistance> <MinBetaResistance>0</MinBetaResistance> </Cyclical> </Aging> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5f94bcfaa72ebb19d81c3526f52f9ef464071b9..63fa70acb25a46893cfa46a3c72f9562af73a42a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,146 +2,153 @@ add_custom_target(framework) # list of directories inside src that should not be included set(UNINCLUDE - ${UNINCLUDE} - ${PROJECT_SOURCE_DIR}/src/cinterface/ - ${PROJECT_SOURCE_DIR}/src/unittest - ${PROJECT_SOURCE_DIR}/src/simulink_mock/ - ${PROJECT_SOURCE_DIR}/src/thermal/executable - ${PROJECT_SOURCE_DIR}/src/export/mex - ${PROJECT_SOURCE_DIR}/src/export/circuit_simulink_model - ${PROJECT_SOURCE_DIR}/src/export/matrix_simulink_model - ${PROJECT_SOURCE_DIR}/src/export/CreateSimulinkModelFunction - ${PROJECT_SOURCE_DIR}/src/export/LoadInitialStateFunction - ${PROJECT_SOURCE_DIR}/src/export/LoadObjectValuesFunction) + ${UNINCLUDE} + ${PROJECT_SOURCE_DIR}/src/cinterface/ + ${PROJECT_SOURCE_DIR}/src/unittest + ${PROJECT_SOURCE_DIR}/src/simulink_mock/ + ${PROJECT_SOURCE_DIR}/src/thermal/executable + ${PROJECT_SOURCE_DIR}/src/export/mex + ${PROJECT_SOURCE_DIR}/src/export/circuit_simulink_model + ${PROJECT_SOURCE_DIR}/src/export/matrix_simulink_model + ${PROJECT_SOURCE_DIR}/src/export/CreateSimulinkModelFunction + ${PROJECT_SOURCE_DIR}/src/export/LoadInitialStateFunction + ${PROJECT_SOURCE_DIR}/src/export/LoadObjectValuesFunction) set(NUMERIC_UNINCLUDE ${NUMERIC_UNINCLUDE}) set(SYMBOLIC_UNINCLUDE - ${SYMBOLIC_UNINCLUDE} - ${PROJECT_SOURCE_DIR}/src/export/baseExport - ${PROJECT_SOURCE_DIR}/src/export/electrical_simulink_model - ${PROJECT_SOURCE_DIR}/src/export/esbVisualizer - ${PROJECT_SOURCE_DIR}/src/export/spiceExport - ${PROJECT_SOURCE_DIR}/src/factory/electricalEquationSystem/chooseElectricSystemType - ${PROJECT_SOURCE_DIR}/src/system/constantstepdglsystemsolver - ${PROJECT_SOURCE_DIR}/src/system/linAlg_sys - ${PROJECT_SOURCE_DIR}/src/system/linearsystemsolver - ${PROJECT_SOURCE_DIR}/src/system/system - ${PROJECT_SOURCE_DIR}/src/system/systemSolver - ${PROJECT_SOURCE_DIR}/src/system/variablestepdglsystemsolver - ${PROJECT_SOURCE_DIR}/src/thermal/block_observer - ${PROJECT_SOURCE_DIR}/src/observer/) + ${SYMBOLIC_UNINCLUDE} + ${PROJECT_SOURCE_DIR}/src/export/baseExport + ${PROJECT_SOURCE_DIR}/src/export/electrical_simulink_model + ${PROJECT_SOURCE_DIR}/src/export/esbVisualizer + ${PROJECT_SOURCE_DIR}/src/export/spiceExport + ${PROJECT_SOURCE_DIR}/src/factory/electricalEquationSystem/chooseElectricSystemType + ${PROJECT_SOURCE_DIR}/src/system/constantstepdglsystemsolver + ${PROJECT_SOURCE_DIR}/src/system/linAlg_sys + ${PROJECT_SOURCE_DIR}/src/system/linearsystemsolver + ${PROJECT_SOURCE_DIR}/src/system/system + ${PROJECT_SOURCE_DIR}/src/system/systemSolver + ${PROJECT_SOURCE_DIR}/src/system/variablestepdglsystemsolver + ${PROJECT_SOURCE_DIR}/src/thermal/block_observer + ${PROJECT_SOURCE_DIR}/src/observer/) # automatically find all needed source and header files file(GLOB_RECURSE TMP_SOURCE *.cpp) -foreach(f ${TMP_SOURCE}) - # if part of uninclude then drop it - foreach(g ${UNINCLUDE}) - string(FIND ${f} ${g} tmp_found REVERSE) - if(NOT ${tmp_found} EQUAL -1) - break() - endif(NOT ${tmp_found} EQUAL -1) - endforeach(g ${UNINCLUDE}) - - # else add it to sources - if(${tmp_found} EQUAL -1) - - # check if part of numeric uninclude - foreach(g ${NUMERIC_UNINCLUDE}) - string(FIND ${f} ${g} tmp_found REVERSE) - if(NOT ${tmp_found} EQUAL -1) - break() - endif(NOT ${tmp_found} EQUAL -1) - endforeach(g ${NUMERIC_UNINCLUDE}) - - # else add to numeric sources - if(${tmp_found} EQUAL -1) - set(NUMERIC_SOURCE ${NUMERIC_SOURCE} ${f}) - endif(${tmp_found} EQUAL -1) - - # check if part of symbolic uninclude - foreach(g ${SYMBOLIC_UNINCLUDE}) - string(FIND ${f} ${g} tmp_found REVERSE) - if(NOT ${tmp_found} EQUAL -1) - break() - endif(NOT ${tmp_found} EQUAL -1) - endforeach(g ${SYMBOLIC_UNINCLUDE}) - - # else add to symbolic sources - if(${tmp_found} EQUAL -1) - set(SYMBOLIC_SOURCE ${SYMBOLIC_SOURCE} ${f}) - endif(${tmp_found} EQUAL -1) - - endif(${tmp_found} EQUAL -1) -endforeach(f ${TMP_SOURCE}) +foreach (f ${TMP_SOURCE}) + # if part of uninclude then drop it + foreach (g ${UNINCLUDE}) + string(FIND ${f} ${g} tmp_found REVERSE) + if (NOT ${tmp_found} EQUAL -1) + break() + endif (NOT ${tmp_found} EQUAL -1) + endforeach (g ${UNINCLUDE}) + + # else add it to sources + if (${tmp_found} EQUAL -1) + + # check if part of numeric uninclude + foreach (g ${NUMERIC_UNINCLUDE}) + string(FIND ${f} ${g} tmp_found REVERSE) + if (NOT ${tmp_found} EQUAL -1) + break() + endif (NOT ${tmp_found} EQUAL -1) + endforeach (g ${NUMERIC_UNINCLUDE}) + + # else add to numeric sources + if (${tmp_found} EQUAL -1) + set(NUMERIC_SOURCE ${NUMERIC_SOURCE} ${f}) + endif (${tmp_found} EQUAL -1) + + # check if part of symbolic uninclude + foreach (g ${SYMBOLIC_UNINCLUDE}) + string(FIND ${f} ${g} tmp_found REVERSE) + if (NOT ${tmp_found} EQUAL -1) + break() + endif (NOT ${tmp_found} EQUAL -1) + endforeach (g ${SYMBOLIC_UNINCLUDE}) + + # else add to symbolic sources + if (${tmp_found} EQUAL -1) + set(SYMBOLIC_SOURCE ${SYMBOLIC_SOURCE} ${f}) + endif (${tmp_found} EQUAL -1) + + endif (${tmp_found} EQUAL -1) +endforeach (f ${TMP_SOURCE}) file(GLOB_RECURSE HEADERS *.h) -foreach(f ${TMP_SOURCE}) - - # if part of uninclude then drop it - foreach(g ${UNINCLUDE}) - - string(FIND ${f} ${g} tmp_found REVERSE) - if(NOT ${tmp_found} EQUAL -1) - break() - endif(NOT ${tmp_found} EQUAL -1) - - endforeach(g ${UNINCLUDE}) - - # else add it to headers - if(${tmp_found} EQUAL -1) - - # check if part of numeric uninclude - foreach(g ${NUMERIC_UNINCLUDE}) - string(FIND ${f} ${g} tmp_found REVERSE) - if(NOT ${tmp_found} EQUAL -1) - break() - endif(NOT ${tmp_found} EQUAL -1) - endforeach(g ${NUMERIC_UNINCLUDE}) - - # else add to numeric headers - if(${tmp_found} EQUAL -1) - set(NUMERIC_HEADERS ${NUMERIC_HEADERS} ${f}) - endif(${tmp_found} EQUAL -1) - - # check if part of symbolic uninclude - foreach(g ${SYMBOLIC_UNINCLUDE}) - string(FIND ${f} ${g} tmp_found REVERSE) - if(NOT ${tmp_found} EQUAL -1) - break() - endif(NOT ${tmp_found} EQUAL -1) - endforeach(g ${SYMBOLIC_UNINCLUDE}) - - # else add to symbolic headers - if(${tmp_found} EQUAL -1) - set(SYMBOLIC_HEADERS ${SYMBOLIC_HEADERS} ${f}) - endif(${tmp_found} EQUAL -1) - - endif(${tmp_found} EQUAL -1) -endforeach(f ${TMP_SOURCE}) +foreach (f ${TMP_SOURCE}) + + # if part of uninclude then drop it + foreach (g ${UNINCLUDE}) + + string(FIND ${f} ${g} tmp_found REVERSE) + if (NOT ${tmp_found} EQUAL -1) + break() + endif (NOT ${tmp_found} EQUAL -1) + + endforeach (g ${UNINCLUDE}) + + # else add it to headers + if (${tmp_found} EQUAL -1) + + # check if part of numeric uninclude + foreach (g ${NUMERIC_UNINCLUDE}) + string(FIND ${f} ${g} tmp_found REVERSE) + if (NOT ${tmp_found} EQUAL -1) + break() + endif (NOT ${tmp_found} EQUAL -1) + endforeach (g ${NUMERIC_UNINCLUDE}) + + # else add to numeric headers + if (${tmp_found} EQUAL -1) + set(NUMERIC_HEADERS ${NUMERIC_HEADERS} ${f}) + endif (${tmp_found} EQUAL -1) + + # check if part of symbolic uninclude + foreach (g ${SYMBOLIC_UNINCLUDE}) + string(FIND ${f} ${g} tmp_found REVERSE) + if (NOT ${tmp_found} EQUAL -1) + break() + endif (NOT ${tmp_found} EQUAL -1) + endforeach (g ${SYMBOLIC_UNINCLUDE}) + + # else add to symbolic headers + if (${tmp_found} EQUAL -1) + set(SYMBOLIC_HEADERS ${SYMBOLIC_HEADERS} ${f}) + endif (${tmp_found} EQUAL -1) + + endif (${tmp_found} EQUAL -1) +endforeach (f ${TMP_SOURCE}) find_package(Boost REQUIRED) -find_package(MATIO REQUIRED) - -if(BUILD_NUMERIC) - set(libname_NUMERIC ISEAFrameNumeric) - add_library(${libname_NUMERIC} ${NUMERIC_SOURCE} ${NUMERIC_HEADERS}) - target_link_libraries( - ${libname_NUMERIC} PUBLIC ${COMMON_LIBRARIES} ${NUMERIC_LIBRARIES} - matio::matio) - target_include_directories(${libname_NUMERIC} PUBLIC ${Boost_INCLUDE_DIRS}) - target_compile_definitions(${libname_NUMERIC} PUBLIC ${COMMON_DEFINITIONS} - ${NUMERIC_DEFINITIONS}) - add_dependencies(framework ${libname_NUMERIC}) -endif() - -if(BUILD_SYMBOLIC) - set(libname_SYMBOLIC ISEAFrameSymbolic) - add_library(${libname_SYMBOLIC} ${SYMBOLIC_SOURCE} ${SYMBOLIC_HEADERS}) - target_link_libraries( - ${libname_SYMBOLIC} PUBLIC Boost::headers ${COMMON_LIBRARIES} - ${SYMBOLIC_LIBRARIES}) - target_compile_definitions(${libname_SYMBOLIC} PUBLIC ${COMMON_DEFINITIONS} - ${SYMBOLIC_DEFINITIONS}) - add_dependencies(framework ${libname_SYMBOLIC}) -endif() +find_package(matio REQUIRED) +find_package(Eigen3 REQUIRED) + +if (${Eigen3_INCLUDE_DIR}) + set(EIGEN3_INCLUDE_DIR ${Eigen3_INCLUDE_DIR}) +elseif (TARGET Eigen3::Eigen) + get_target_property(EIGEN3_INCLUDE_DIR Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES) +endif () +if (BUILD_NUMERIC) + set(libname_NUMERIC ISEAFrameNumeric) + add_library(${libname_NUMERIC} ${NUMERIC_SOURCE} ${NUMERIC_HEADERS}) + target_link_libraries(${libname_NUMERIC} + PUBLIC ${COMMON_LIBRARIES} ${NUMERIC_LIBRARIES} matio::matio + ) + target_include_directories(${libname_NUMERIC} SYSTEM PUBLIC ${Boost_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR}) + target_compile_definitions(${libname_NUMERIC} PUBLIC ${COMMON_DEFINITIONS} + ${NUMERIC_DEFINITIONS}) + add_dependencies(framework ${libname_NUMERIC}) +endif () + +if (BUILD_SYMBOLIC) + set(libname_SYMBOLIC ISEAFrameSymbolic) + add_library(${libname_SYMBOLIC} ${SYMBOLIC_SOURCE} ${SYMBOLIC_HEADERS}) + target_include_directories(${libname_SYMBOLIC} SYSTEM PUBLIC ${Boost_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR}) + target_link_libraries( + ${libname_SYMBOLIC} PUBLIC Boost::headers ${COMMON_LIBRARIES} + ${SYMBOLIC_LIBRARIES}) + target_compile_definitions(${libname_SYMBOLIC} PUBLIC ${COMMON_DEFINITIONS} + ${SYMBOLIC_DEFINITIONS}) + add_dependencies(framework ${libname_SYMBOLIC}) +endif () diff --git a/src/aging/anode_overhang.cpp b/src/aging/anode_overhang.cpp index 2d237440cd336b9e94c3b962b11e931d007be90c..1599a83a9b10d677a95ae6a7ba7ee8f97817a9e5 100644 --- a/src/aging/anode_overhang.cpp +++ b/src/aging/anode_overhang.cpp @@ -2,12 +2,14 @@ namespace aging { -AnodeOverhang::AnodeOverhang( const double agingStepTime, const boost::shared_ptr< object::Object< double > >& voltage, +AnodeOverhang::AnodeOverhang( const double agingStepTime, const boost::shared_ptr< object::Object< double > >& voltage, + const boost::shared_ptr< object::Object< double > >& dva, const double& activCoef, const double& tauCoef, const boost::shared_ptr< state::Soc >& socState, const double socWhereOffsetIsZero, bool isEnabled ) : AgingBase( agingStepTime, isEnabled ) , mVoltage( voltage ) + , mDVA (dva) , mActivCoef( activCoef ) , mTauCoef( tauCoef ) , mSocState( socState ) @@ -48,16 +50,13 @@ void AnodeOverhang::CalculateAging( const TwoportState&, double timestep, double double anodeVoltage = anodeVoltageSum / this->mTotalCalculationTime; double temperature = temperatureSum / this->mTotalCalculationTime; double tau = this->mTauCoef * std::exp( this->mActivCoef / temperature ) * 3600 * 24; - double charge = this->mSocState->GetValue< state::SocGetFormat::AS >(); - if ( charge == 0 ) // If the charge is exactly 0, the overhang has no capacity and no charge can ever flow - { - charge = 1.0; - this->mSocState->SetStoredEnergy< state::SocSetFormat::ABSOLUT >( charge ); - } + double overhangVoltage = mVoltage->GetValue(); - double capacity = charge / overhangVoltage; - - double additionalCharge = capacity * ( overhangVoltage - anodeVoltage ) * ( 1 - exp( -stepTimeSeconds / tau ) ); + + double capacitance = 1 / ( mDVA->GetValue(this->mSocState->GetValue< state::SocGetFormat::PERCENT >()) + * this->mSocState->GetActualCapacity< state::SocGetFormat::AS >() ); + + double additionalCharge = capacitance * ( overhangVoltage - anodeVoltage ) * ( 1 - exp( -stepTimeSeconds / tau ) ); this->mSocState->SetStoredEnergy< state::SocSetFormat::DELTA >( additionalCharge ); this->mAnodeOffset -= additionalCharge; @@ -68,6 +67,35 @@ void AnodeOverhang::CalculateAging( const TwoportState&, double timestep, double } } +double AnodeOverhang::CalculateLinearCapacitance() +{ + double saveCharge = this->mSocState->GetValue< state::SocGetFormat::AS >(); + double overhangVoltage = mVoltage->GetValue(); + + // Evaluate two additional points on the Anode QOCV for linearisation + double overhangCap = this->mSocState->GetActualCapacity(); + double chargeDiff = 0.01 * overhangCap; + double chargePlus = saveCharge + chargeDiff; + double chargeMinus = saveCharge - chargeDiff; + + this->mSocState->SetStoredEnergy< state::SocSetFormat::ABSOLUT >( chargePlus ); + double overhangVoltagePlus = mVoltage->GetValue(); + this->mSocState->SetStoredEnergy< state::SocSetFormat::ABSOLUT >( chargeMinus ); + double overhangVoltageMinus = mVoltage->GetValue(); + + this->mSocState->SetStoredEnergy< state::SocSetFormat::ABSOLUT >( saveCharge ); + + double calculatedCapacity = (2 * chargeDiff) / (overhangVoltagePlus - overhangVoltageMinus); + + if (calculatedCapacity > (saveCharge / overhangVoltage) ) + { + calculatedCapacity = saveCharge / overhangVoltage; + } + + return calculatedCapacity; +} + + void AnodeOverhang::CollectData( const TwoportState& twoportState, const TwoportState&, double timestep ) { if ( this->mIsEnabled ) diff --git a/src/aging/anode_overhang.h b/src/aging/anode_overhang.h index 81618249f14b43c7034c138de0e9c660a00a3136..c874513e37d5dfb5159fbab7dca60bc5a56fbeed 100644 --- a/src/aging/anode_overhang.h +++ b/src/aging/anode_overhang.h @@ -17,7 +17,7 @@ class AnodeOverhang : public AgingBase { public: /// Constructor - AnodeOverhang( const double agingStepTime, const boost::shared_ptr< object::Object< double > >& voltage, + AnodeOverhang( const double agingStepTime, const boost::shared_ptr< object::Object< double > >& voltage, const boost::shared_ptr< object::Object< double > >& dva, const double& activCoef, const double& tauCoef, const boost::shared_ptr< state::Soc >& socState, const double socWhereOffsetIsZero, bool isEnabled = true ); @@ -36,11 +36,14 @@ class AnodeOverhang : public AgingBase virtual double GetCapacityFactor() { return 1; }; virtual double GetSocOffset() { return mAnodeOffset; }; // in As virtual double GetResistanceFactor() { return 1; }; + + virtual double CalculateLinearCapacitance(); virtual void AcceptVisitor( visitor::Visitor< AgingBase >& visitor ) { visitor.Visit( *this ); } private: boost::shared_ptr< object::Object< double > > mVoltage; + boost::shared_ptr< object::Object< double > > mDVA; const double mActivCoef; const double mTauCoef; boost::shared_ptr< state::Soc > mSocState; diff --git a/src/aging/calendarian_aging.cpp b/src/aging/calendarian_aging.cpp index edaf2c0b469851a6a34f0441034097af8bf320ba..81705e41caaf782a55a63db30d58f3434d0df766 100644 --- a/src/aging/calendarian_aging.cpp +++ b/src/aging/calendarian_aging.cpp @@ -84,7 +84,7 @@ void CalendarianAging::CollectData( const TwoportState& twoportState, const Twop mTimeValues.push_back( mTimeSinceLastAgingStep ); mVoltageValues.push_back( cellState.mElectricalData->mVoltageValue ); mTemperatureValues.push_back( twoportState.mThermalState->GetValue< TemperatureGetFormat::KELVIN >() ); - mSocValues.push_back( twoportState.mSocState->GetValue< state::SocGetFormat::PERCENT >() / 100 ); + mSocValues.push_back( twoportState.mSocState->GetValue< state::SocGetFormat::PERCENT >() ); } } diff --git a/src/aging/cyclical_aging.cpp b/src/aging/cyclical_aging.cpp index a49976aaf531fc1786ec0a28a0e27e30721946e1..f7e5d0ac1f14a50027e8134c7f6e92a9851e64da 100644 --- a/src/aging/cyclical_aging.cpp +++ b/src/aging/cyclical_aging.cpp @@ -1,7 +1,8 @@ -#include "cyclical_aging.h" -#include "../misc/rainflow.h" #include <fstream> #include <iostream> +#include <numeric> +#include "cyclical_aging.h" +#include "../misc/rainflow.h" namespace aging { @@ -10,16 +11,19 @@ CyclicalAging::CyclicalAging( const double agingStepTime, const double minBetaCa const boost::shared_ptr< object::Object< double > >& alphaCapacity, const boost::shared_ptr< object::Object< double > >& alphaResistance, const double initialCapacityFactor, const double initialResistanceFactor, const bool isEnabled, - const double chargeThroughputExponentCapacity, const double chargeThroughputExponentResistance ) + const double chargeThroughputExponentCapacity, const double chargeThroughputExponentResistance, + const std::string chargeCounting) : EmpiricalAging( agingStepTime, minBetaCapacity, minBetaResistance, maxBetaCapacity, maxBetaResistance, alphaCapacity, alphaResistance, initialCapacityFactor, initialResistanceFactor, isEnabled ) , mChargeThroughputExponentCapacity( chargeThroughputExponentCapacity ) , mChargeThroughputExponentResistance( chargeThroughputExponentResistance ) + , mChargeCounting( chargeCounting ) , mActualDod( 0.0 ) , mActualVoltage( 0.0 ) , mActualSoc( 0.0 ) , mActualCurrent( 0.0 ) , mTimeSinceLastAgingStep( 0.0 ) + , mActualTemperature( 0.0 ) { } @@ -42,13 +46,23 @@ void CyclicalAging::CalculateAging( const TwoportState& twoportState, double tim { double cycleStart = this->mTimeValues[cycle.mStartIndex]; double cycleEnd = this->mTimeValues[cycle.mEndIndex]; - double cycleChargeThroughput = cycle.mDepth * capacity * cycle.mCycleCount; - + double cycleChargeThroughput = 0; + if ( this->mChargeCounting == "EFC" ) + { + cycleChargeThroughput = cycle.mDepth / 100 * cycle.mCycleCount; + } + else if ( this->mChargeCounting == "Ah" ) + { + cycleChargeThroughput = cycle.mDepth / 100 * capacity * cycle.mCycleCount; + } + + mActualDod = cycle.mDepth; mActualSoc = cycle.mMeanValue; // convert CTP to As and double it to get the integral over the absolute value of the current mActualCurrent = ( cycleChargeThroughput * 2 * 3600 ) / ( cycleEnd - cycleStart ); - mActualVoltage = GetAverageVoltage( cycleStart, cycleEnd ); + mActualVoltage = GetAverageValue( cycleStart, cycleEnd, mVoltageValues ); + mActualTemperature = GetAverageValue( cycleStart, cycleEnd, mTemperatureValues ); double betaCapacity = this->mCapacityStressFactor->GetValue(); double betaResistance = this->mResistanceStressFactor->GetValue(); betaCapacity = clamp( betaCapacity, this->mMinStressFactorCapacity, this->mMaxStressFactorCapacity ); @@ -87,6 +101,7 @@ void CyclicalAging::CalculateAging( const TwoportState& twoportState, double tim this->mTimeValues.clear(); this->mVoltageValues.clear(); this->mSocValues.clear(); + this->mTemperatureValues.clear(); this->mTimeSinceLastAgingStep = 0.0; } @@ -95,8 +110,9 @@ void CyclicalAging::CollectData( const TwoportState& twoportState, const Twoport // Needed for for the calculation of the total charge throughput mTimeSinceLastAgingStep += timestep; mTimeValues.push_back( this->mTimeSinceLastAgingStep ); - mSocValues.push_back( twoportState.mSocState->GetValue() / 100 ); + mSocValues.push_back( twoportState.mSocState->GetValue< state::SocGetFormat::PERCENT >()); mVoltageValues.push_back( cellState.mElectricalData->mVoltageValue ); + mTemperatureValues.push_back( cellState.mThermalState->GetValue< TemperatureGetFormat::KELVIN >() ); } void CyclicalAging::ResetToPointInTime( double time ) @@ -106,18 +122,19 @@ void CyclicalAging::ResetToPointInTime( double time ) mTimeValues.erase( firstDelete, mTimeValues.end() ); mVoltageValues.erase( mVoltageValues.begin() + firstDeleteIndex, mVoltageValues.end() ); mSocValues.erase( mSocValues.begin() + firstDeleteIndex, mSocValues.end() ); + mTemperatureValues.erase( mTemperatureValues.begin() + firstDeleteIndex, mTemperatureValues.end() ); mTimeSinceLastAgingStep = time; } -double CyclicalAging::GetAverageVoltage( double startTime, double endTime ) +double CyclicalAging::GetAverageValue( double startTime, double endTime, std::vector< double > valuesToAvg ) { std::vector< double >::iterator startIterator = std::lower_bound( mTimeValues.begin(), mTimeValues.end(), startTime ); std::vector< double >::iterator endIterator = std::upper_bound( mTimeValues.begin(), mTimeValues.end(), endTime ); size_t startIndex = startIterator - mTimeValues.begin(); size_t endIndex = endIterator - mTimeValues.begin(); - double voltageSum = std::accumulate< std::vector< double >::iterator, double >( mVoltageValues.begin() + startIndex, - mVoltageValues.begin() + endIndex, 0.0 ); - return voltageSum / ( endIndex - startIndex ); + double valueSum = std::accumulate< std::vector< double >::iterator, double >( valuesToAvg.begin() + startIndex, + valuesToAvg.begin() + endIndex, 0.0 ); + return valueSum / ( endIndex - startIndex ); } } // namespace aging diff --git a/src/aging/cyclical_aging.h b/src/aging/cyclical_aging.h index 22d15513e8bbcb97cb2d8fdea6db4228aa964b8f..cee74812acc1827b95fa3d8d4b77c1399ad27e9a 100644 --- a/src/aging/cyclical_aging.h +++ b/src/aging/cyclical_aging.h @@ -34,7 +34,8 @@ class CyclicalAging : public EmpiricalAging const double maxBetaResistance, const boost::shared_ptr< object::Object< double > >& alphaCapacity, const boost::shared_ptr< object::Object< double > >& alphaResistance, const double initialCapacityFactor, const double initialResistanceFactor, const bool isEnabled, - const double chargeThroughputExponentCapacity, const double chargeThroughputExponentResistance ); + const double chargeThroughputExponentCapacity, const double chargeThroughputExponentResistance, + const std::string chargeCounting); /// Returns AgingType::CYCLICAL /// Derived from AgingBase @@ -52,20 +53,23 @@ class CyclicalAging : public EmpiricalAging virtual void AcceptVisitor( visitor::Visitor< AgingBase >& visitor ) { visitor.Visit( *this ); } private: - double GetAverageVoltage( double startTime, double endTime ); + double GetAverageValue( double startTime, double endTime, std::vector< double > valuesToAvg ); const double mChargeThroughputExponentCapacity; const double mChargeThroughputExponentResistance; - double mActualDod; // [%/100] + double mActualDod; // [%] double mActualVoltage; // [V] - double mActualSoc; // [%/100] + double mActualSoc; // [%] double mActualCurrent; // [A] double mTimeSinceLastAgingStep; // [s] + double mActualTemperature; // [K] std::vector< double > mTimeValues; // [s] std::vector< double > mSocValues; // [%] std::vector< double > mVoltageValues; // [V] + std::vector< double > mTemperatureValues; // [V] + const std::string mChargeCounting; }; } // namespace aging diff --git a/src/cinterface/CMakeLists.txt b/src/cinterface/CMakeLists.txt index 523aad301265ba1f8e0e54f8511d0e437b147e4b..e7a0d3345d958515df364cf5f2d7a5436cd94c3c 100644 --- a/src/cinterface/CMakeLists.txt +++ b/src/cinterface/CMakeLists.txt @@ -1,6 +1,6 @@ file(GLOB_RECURSE SOURCEFILES *.cpp) -find_package(MATIO REQUIRED) +find_package(matio REQUIRED) add_library(cinterface ${SOURCEFILES}) target_link_libraries(cinterface PUBLIC ISEAFrameNumeric) diff --git a/src/cinterface/cinterface_ThEl_Aging.cpp b/src/cinterface/cinterface_ThEl_Aging.cpp index 437850b11f40e8e6cbe34b02ed35072da809dcff..88b68b450ababe87ab644ea98a6967e111e1d433 100644 --- a/src/cinterface/cinterface_ThEl_Aging.cpp +++ b/src/cinterface/cinterface_ThEl_Aging.cpp @@ -77,12 +77,13 @@ extern "C" { DeleteSystem_ThEl( pointerStructureAddress ); InitializeSystem_ThEl_Aging( configStr, pointerStructureAddress, stateVector ); - SetOutputVectors_ThEl( pointerStructureAddress, voltageOutputVec, currentOutputVec, powerOutputVec, + SetOutputVectors_ThEl_Aging( pointerStructureAddress, voltageOutputVec, currentOutputVec, powerOutputVec, socOutputVec, socSurfaceOutputVec ); } void SetOutputVectors_ThEl_Aging( const size_t *pointerStructureAddress, real_T *voltageOutputVec, real_T *currentOutputVec, real_T *powerOutputVec, real_T *socOutputVec, real_T *socSurfaceOutputVec ) + { PointerStructure_ThEl_Aging *pointerStructure = (PointerStructure_ThEl_Aging *)*pointerStructureAddress; @@ -95,16 +96,22 @@ extern "C" std::vector< boost::shared_ptr< electrical::TwoPort< myMatrixType > > > twoportVector( observedTwoports.size(), nullptr ); size_t outputRows = numberOfCellelements; size_t outputColumns = std::ceil( (double)observedTwoports.size() / outputRows ); - // first column has all the cellements, so they can just be copied - for ( size_t i = 0; i < numberOfCellelements; ++i ) + + // first column has all the cellements, so they can just be copied + + size_t i=0; + for ( size_t n = 0; n < observedTwoports.size(); n += outputColumns ) { - twoportVector[i] = observedTwoports[i]; + twoportVector[i] = observedTwoports[n]; + i++; } - for ( size_t i = numberOfCellelements; i < observedTwoports.size(); ++i ) + + for ( size_t n = 0; n < observedTwoports.size(); ++n ) { - size_t row = ( i - numberOfCellelements ) / ( outputColumns - 1 ); - size_t column = ( i - numberOfCellelements ) % ( outputColumns - 1 ) + 1; - twoportVector[column * outputRows + row] = observedTwoports[i]; + if ((n%outputColumns)==0) + continue; + twoportVector[i]=observedTwoports[n]; + i++; } pointerStructure->mElectricalSimulation->mObserver = CreateTwoPortObserver< std::vector< boost::shared_ptr< electrical::TwoPort< myUnit > > >, myUnit, false >( diff --git a/src/container/armadillo_wrapper.cpp b/src/container/armadillo_wrapper.cpp deleted file mode 100644 index 0631d4035547bca31c58c9a38644d9ca71cefc2b..0000000000000000000000000000000000000000 --- a/src/container/armadillo_wrapper.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "armadillo_wrapper.h" -#ifdef _ARMADILLO_ -#ifdef __EXCEPTIONS__ -#include "../exceptions/error_proto.h" -#else -#include <cstdlib> -#endif -namespace boost -{ -namespace numeric -{ -namespace odeint -{ - - -// In case of SpMat - -// template<> template<> -// void default_operations::rel_error<double>::operator()<arma::SpMat<double>,arma::SpMat<double>,arma::SpMat<double> >( -// arma::SpMat<double> &t3 , const arma::SpMat<double> &t1 , const arma::SpMat<double> &t2 ) const -//{ -// for( size_t i = 0 ; i < t3.n_cols ; ++i ) -// { -// t3(i,i) = t3(i,i) / (m_eps_abs + m_eps_rel * ( m_a_x * arma::abs(t1)(i,i) + m_a_dxdt * arma::abs( t2 )(i,i) -// ) ); -// } -// -//} -// -//}}} -} -} -} - -namespace arma -{ -const SpMat< double > solve( const SpMat< double > &A, const SpMat< double > &B ) -{ - return arma::SpMat< double >( arma::solve( arma::Mat< double >( A ), arma::Mat< double >( B ) ) ); -} - -const SpMat< double > inv( const SpMat< double > &A ) -{ - return arma::SpMat< double >( arma::inv( arma::Mat< double >( A ) ) ); -} - -SpMat< double > operator/( const SpMat< double > &A, const SpMat< double > &B ) -{ - if ( ( A.n_cols != B.n_cols || A.n_rows != B.n_rows ) && A.n_cols != A.n_rows ) - { - ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, "UnequalSize", A.n_cols, B.n_cols ); - } - - SpMat< double > C( A.n_cols, A.n_rows ); - - for ( size_t i = 0; i < A.n_cols; ++i ) - { - for ( size_t j = 0; j < A.n_rows; ++j ) - { - C( j, i ) = A( j, i ) / B( j, i ); - } - } - return C; -} - -double ScalarMul( const SpMat< double > &rowMatrix, const SpMat< double > &colMatrix ) -{ - double sum = 0; - if ( colMatrix.n_rows > 0 ) - { - SpMat< double > subMat = rowMatrix.cols( 0, colMatrix.n_rows - 1 ); - for ( arma::SpMat< double >::const_iterator it = subMat.begin(); it != subMat.end(); it++ ) - sum += *it * colMatrix( it.col(), 0 ); - } - return sum; -} - -double ScalarMul( const Mat< double > &rowMatrix, const Mat< double > &colMatrix ) -{ - double sum = 0; - for ( size_t i = 0; i < colMatrix.n_rows; ++i ) - sum += rowMatrix( 0, i ) * colMatrix( i, 0 ); - return sum; -} - -double SumOfElements( const SpMat< double > &matrix ) { return sum( sum( matrix ) ); } - -double SumOfElements( const Mat< double > &matrix ) { return sum( sum( matrix ) ); } -} - -#endif diff --git a/src/container/armadillo_wrapper.h b/src/container/armadillo_wrapper.h deleted file mode 100644 index ceb309516421a713606a64369b93c863da9135ac..0000000000000000000000000000000000000000 --- a/src/container/armadillo_wrapper.h +++ /dev/null @@ -1,208 +0,0 @@ -/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -* File Name : armadillo_wrapper.hpp -* Creation Date : 15-09-2012 -* Last Modified : Di 01 Okt 2013 23:31:35 CEST -* Created By : Friedrich Hust -_._._._._._._._._._._._._._._._._._._._._.*/ - -#ifndef BOOST_NUMERIC_ODEINT_UTIL_ARMADILLO_WRAPPER_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_UTIL_ARMADILLO_WRAPPER_HPP_INCLUDED - -//ARMADILLO -// -#if defined(_ARMADILLO_) || defined(_EIGEN_) && ! defined(_DS1006) -#include <armadillo> -#else -#include "../stub/armadillo.h" -#endif - -#if defined(_ARMADILLO_) || defined(_EIGEN_) && ! defined(_DS1006) -//BOOST -//#include <boost/numeric/odeint/util/state_wrapper.hpp> //doesn't compile on cluster with this line: cannot find file state_wrapper.hpp -#include <boost/numeric/odeint.hpp> - -namespace boost { -namespace numeric { -namespace odeint { - -/* - * resizeable specialization for arma::Mat - */ -template< class T > -struct is_resizeable< arma::Mat< T > > -{ - typedef boost::true_type type; - const static bool value = type::value; -}; - -template< class T > -struct is_resizeable< arma::SpMat< T > > -{ - typedef boost::true_type type; - const static bool value = type::value; -}; - -template< class T , class T2 > -struct same_size_impl< arma::SpMat< T > , arma::SpMat< T2 > > -{ - static bool same_size( const arma::SpMat< T > &m1 , - const arma::SpMat< T2 > &m2 ) - { - return ( ( m1.n_rows == m2.n_rows ) && ( m1.n_cols == m2.n_cols ) ); - } -}; - -// specialization for arma::Mat -// same size and resize specialization for matrix-matrix resizing -template< class T , class T2 > -struct same_size_impl< arma::Mat< T > , arma::Mat< T2 > > -{ - static bool same_size( const arma::Mat< T > &m1 , - const arma::Mat< T2 > &m2 ) - { - return ( ( m1.n_rows == m2.n_rows ) && ( m1.n_cols == m2.n_cols ) ); - } -}; - -template< class T , class T2 > -struct resize_impl< arma::SpMat< T > , arma::SpMat< T2 > > -{ - static void resize( arma::SpMat< T > &m1 , - const arma::SpMat< T2 > &m2 ) - { - arma::SpMat< T > tmp( m2.n_rows , m2.n_cols ); - for (unsigned i = 0; i < m2.n_rows && i <m1.n_rows; ++i) - { - for (unsigned j = 0; j < m2.n_cols && j <m1.n_cols; ++j) - { - tmp(i,j) = m1(i,j); - } - } - m1 = tmp; - } -}; -template< class T , class T2 > -struct resize_impl< arma::Mat< T > , arma::Mat< T2 > > -{ - static void resize( arma::Mat< T > &m1 , - const arma::Mat< T2 > &m2 ) - { - m1 = arma::resize(m2,m2.n_rows, m2.n_cols); - //m1.resize(m2.n_rows, m2.n_cols); - } -}; - -} } } - - - -/* - * preparing ublas::matrix for boost::range, such that ublas::matrix can be used in all steppers with the range algebra - */ -namespace boost -{ -template< class T > -struct range_mutable_iterator< arma::SpMat< T > > -{ - typedef typename arma::SpMat< T >::iterator type; -}; - -template< class T > -struct range_const_iterator< arma::SpMat< T > > -{ - typedef typename arma::SpMat< T >::const_iterator type; -}; - -template< class T > -struct range_mutable_iterator< arma::Mat< T > > -{ - typedef typename arma::Mat< T >::iterator type; -}; - -template< class T > -struct range_const_iterator< arma::Mat< T > > -{ - typedef typename arma::Mat< T >::const_iterator type; -}; - -} // namespace boost - -namespace arma { -template< class T > -inline typename SpMat< T >::iterator -range_begin( SpMat< T> &x ) -{ - return x.begin(); -} - -template< class T > -inline typename SpMat< T >::iterator -range_end( SpMat< T > &x ) -{ - return x.end(); -} - -template< class T > -inline typename SpMat< T >::const_iterator -range_begin( const SpMat< T> &x ) -{ - return x.begin(); -} - -template< class T > -inline typename SpMat< T >::const_iterator -range_end( const SpMat< T > &x ) -{ - return x.end(); -} - -// ___ -template< class T > -inline typename Mat< T >::iterator -range_begin( Mat< T> &x ) -{ - return x.begin(); -} - -template< class T > -inline typename Mat< T >::iterator -range_end( Mat< T > &x ) -{ - return x.end(); -} - -template< class T > -inline typename Mat< T >::const_iterator -range_begin( const Mat< T> &x ) -{ - return x.begin(); -} - -template< class T > -inline typename Mat< T >::const_iterator -range_end( const Mat< T > &x ) -{ - return x.end(); -} -} // nampespace arma - -namespace boost { -namespace numeric { -namespace odeint { - -template<> template<> void default_operations::rel_error<double>::operator()<arma::SpMat<double>,arma::SpMat<double>,arma::SpMat<double> >( arma::SpMat<double> &t3 , const arma::SpMat<double> &t1 , const arma::SpMat<double> &t2 ) const; -}}} - -namespace arma -{ -const SpMat<double> solve(const SpMat<double> &A, const SpMat<double> &B); -const SpMat<double> inv(const SpMat<double> &A); -double ScalarMul(const SpMat<double> &rowMatrix, const SpMat<double> &colMatrix); -double ScalarMul(const Mat<double> &rowMatrix, const Mat<double> &colMatrix); -double SumOfElements(const SpMat<double> &matrix); -double SumOfElements(const Mat<double> &matrix); -SpMat<double> operator/(const SpMat<double> &A, const SpMat<double> &B); -} -#endif /* _ARMADILLO_ */ - -#endif // BOOST_NUMERIC_ODEINT_UTIL_UBLAS_WRAPPER_HPP_INCLUDED diff --git a/src/container/eigen_wrapper.h b/src/container/eigen_wrapper.h index 6e62e2058dc346f913132a406b16e60e5d78fc4c..38371629afb82dd9de20b1373bee855d8ffeeb57 100644 --- a/src/container/eigen_wrapper.h +++ b/src/container/eigen_wrapper.h @@ -19,7 +19,7 @@ double ScalarMul( const myMatrixType &rowMatrix, const myMatrixType &colMatrix ) #ifdef _SYMBOLIC_ #include "../misc/symbolic.h" -#include <eigen3/Eigen/Core> +#include <Eigen/Core> template <> diff --git a/src/electrical/capacity.h b/src/electrical/capacity.h index c2c595b45e7cac1702d1ead24d5e386a226345f4..bc4d1298d07bce3053c45118a7fce821d973794e 100644 --- a/src/electrical/capacity.h +++ b/src/electrical/capacity.h @@ -32,7 +32,7 @@ class Capacity : public ElectricalElement< T > explicit Capacity( object::Object< double >* obj, const bool observable = false, typename TwoPort< T >::DataType dataValues = typename TwoPort< T >::DataType( new ElectricalDataStruct< ScalarUnit > ) ); - virtual ~Capacity(){}; + virtual ~Capacity()= default;; virtual T* GetVoltage(); /// Returns Uc = 1 diff --git a/src/electrical/cellelement.cpp b/src/electrical/cellelement.cpp index 2a60dbe3e8a0c1b5347e979d2e6159acb1f8411a..e3f5caf0c38a34b59b50b1cd1bd6f931508713bd 100644 --- a/src/electrical/cellelement.cpp +++ b/src/electrical/cellelement.cpp @@ -126,7 +126,7 @@ ScalarUnit Cellelement< T >::CalculateReversibleHeat() const if ( !HasReversibleHeat() ) { - return 0; + return static_cast< ScalarUnit >( 0 ); } return ( this->mThermalState->template GetValue< TemperatureGetFormat::KELVIN >() * this->mCurrentValue * mReversibleHeat->GetValue() ); @@ -351,7 +351,7 @@ std::pair< ScalarUnit, ScalarUnit > Cellelement< T >::GetVoltageRange() { if ( !mHasVoltageRange ) CalculateVoltageRange(); - return {mMinimumVoltage, mMaximumVoltage}; + return { mMinimumVoltage, mMaximumVoltage }; } } // namespace electrical diff --git a/src/electrical/electrical_simulation.h b/src/electrical/electrical_simulation.h index 704c855d573485ffd77743513198478eeb15e152..03c179c8a267ea24ac1daf23282102966934ce22 100644 --- a/src/electrical/electrical_simulation.h +++ b/src/electrical/electrical_simulation.h @@ -83,6 +83,8 @@ class ElectricalSimulation void ResetSystemStates(); /// Sets a maximul deviation in total power generation in percent. 0 means no stop criterion. void SetPowerStopCriterion( T maximumDeviation ); + /// Set limit for cell voltage. Steps in the current profile are skipped if the limits are exceeded. + void SetVoltageStopCriterion( T minimumVoltage, T maximumVoltage ); void UpdateSimulationDuration( const T &simulationDuration ) { mSimulationDuration = simulationDuration; } @@ -143,9 +145,9 @@ ElectricalSimulation< Matrix, T, filterTypeChoice >::ElectricalSimulation( , mMaxSimulationStepDuration( maxSimulationStepDuration ) , mStepStartTime( 0.0 ) , mSocStopCriterion( socStopCriterion ) - , mMinVoltageStopCriterion( 0.0 ) - , mMaxVoltageStopCriterion( 10.0 ) - , mVoltageLimitDelay( 5 ) + , mMinVoltageStopCriterion( nan( "" ) ) + , mMaxVoltageStopCriterion( nan( "" ) ) + , mVoltageLimitDelay( 4 ) , mPowerStopCriterion( 0.0 ) , mNumberOfSteps( 0 ) { @@ -300,6 +302,13 @@ ElectricalSimulation< Matrix, T, filterTypeChoice >::ElectricalSimulation( if ( mMaxVoltageStopCriterion < 0.0 ) ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, "MinimalVoltageCriterionIsNegative" ); } + if ( optionsNode->HasElementDirectChild( "VerificationDelayForVoltageLimitSteps" ) ) + { + mVoltageLimitDelay = optionsNode->GetElementDoubleValue( "VerificationDelayForVoltageLimitSteps" ); + if ( mVoltageLimitDelay < 0.0 ) + ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, + "VerificationDelayForVoltageLimitSteps" ); + } } template < typename Matrix, typename T, bool filterTypeChoice > @@ -314,9 +323,6 @@ template < typename Matrix, typename T, bool filterTypeChoice > void ElectricalSimulation< Matrix, T, filterTypeChoice >::UpdateSystemValues() { mRootTwoPort->CalculateStateDependentValues(); -#if defined( _ARMADILLO_ ) && defined( SPARSE_MATRIX_FORMAT ) - mStateSystemGroup.ResetSystem(); -#endif } template < typename Matrix, typename T, bool filterTypeChoice > @@ -389,13 +395,14 @@ bool ElectricalSimulation< Matrix, T, filterTypeChoice >::IsStopElectricalCriter { bool isStop = false; #ifndef _SYMBOLIC_ - if ( mNumberOfSteps > mVoltageLimitDelay ) + if ( mNumberOfSteps > mVoltageLimitDelay && !isnan( mMinVoltageStopCriterion ) && !isnan( mMaxVoltageStopCriterion ) ) { // Check voltage for ( size_t i = 0; i < mCellElements.size(); ++i ) { double cellVoltage = mCellElements[i]->GetVoltageValue(); - if ( cellVoltage > mMaxVoltageStopCriterion || cellVoltage < mMinVoltageStopCriterion ) + if ( ( cellVoltage > mMaxVoltageStopCriterion || cellVoltage < mMinVoltageStopCriterion ) && + mRootTwoPort->GetCurrentValue() != 0 ) { isStop = true; break; @@ -509,7 +516,7 @@ void ElectricalSimulation< Matrix, T, filterTypeChoice >::SaveCapacityForLaterRe { for ( size_t i = 0; i < mSocStates.size(); ++i ) { - mSavedSocValues[i] = mSocStates[i]->template GetValue< state::SocGetFormat::AS >(); + mSavedSocValues[i] = mSocStates[i]->template GetValue< state::SocGetFormat::PERCENT >(); mSavedSocOffsets[i] = mSocStates[i]->template GetOffset< state::SocGetFormat::AS >(); } } @@ -520,7 +527,7 @@ void ElectricalSimulation< Matrix, T, filterTypeChoice >::LoadCapacityForLaterRe for ( size_t i = 0; i < mSocStates.size(); ++i ) { mSocStates[i]->template SetOffset< state::SocSetFormat::ABSOLUT >( mSavedSocOffsets[i] ); - mSocStates[i]->template SetStoredEnergy< state::SocSetFormat::ABSOLUT >( mSavedSocValues[i] ); + mSocStates[i]->template SetStoredEnergy< state::SocSetFormat::FACTOR >( mSavedSocValues[i] / 100 ); } } @@ -543,5 +550,12 @@ void ElectricalSimulation< Matrix, T, filterTypeChoice >::SetPowerStopCriterion( mPowerStopCriterion = maximumDeviation / 100; } +template < typename Matrix, typename T, bool filterTypeChoice > +void ElectricalSimulation< Matrix, T, filterTypeChoice >::SetVoltageStopCriterion( T minimumVoltage, T maximumVoltage ) +{ + mMinVoltageStopCriterion = minimumVoltage; + mMaxVoltageStopCriterion = maximumVoltage; +} + } // namespace simulation #endif diff --git a/src/export/matrix_simulink_model.h b/src/export/matrix_simulink_model.h index 6524723370b2796ae0a6508495791bc5b781b7e8..8d5517885fd39a754b7ff1c331382a11b7eb9f5b 100644 --- a/src/export/matrix_simulink_model.h +++ b/src/export/matrix_simulink_model.h @@ -233,7 +233,7 @@ void MatrixSimulinkModel< Matrix, T >::CreateMatrixModel() const int returnValue = mexCallMATLAB( 0, plhs, 1, openSystem.data(), "open_system" ); if ( returnValue ) { - mexPrintf( "Error while opening system %s.\n", mFilename ); + mexPrintf( "Error while opening system %s.\n", (const char *)mFilename ); return; } } @@ -439,9 +439,8 @@ void MatrixSimulinkModel< Matrix, T >::CreateThermalProbes() { thermal::ThermalElement< T > *probeElement = ( *mThermalSimulation->mThermalProbes )[i].GetCorrespondingThermalElement(); auto it = std::find_if( thermalElements.begin(), thermalElements.end(), - [probeElement]( const boost::shared_ptr< thermal::ThermalElement< T > > &element ) { - return element.get() == probeElement; - } ); + [probeElement]( const boost::shared_ptr< thermal::ThermalElement< T > > &element ) + { return element.get() == probeElement; } ); size_t index = std::distance( thermalElements.begin(), it ); finiteVolumesIndices[i] = index + 1; } diff --git a/src/factory/aging/aging_class_wrapper.h b/src/factory/aging/aging_class_wrapper.h index 86ad3fd94e1ba04469071bd2322b7fbed9678379..db2a97ada9c86f6992281255c6b418be1fe71afe 100644 --- a/src/factory/aging/aging_class_wrapper.h +++ b/src/factory/aging/aging_class_wrapper.h @@ -157,10 +157,12 @@ class AgingClassWrapper< aging::CyclicalAging > : public AgingClassWrapperBase auto voltageState = boost::make_shared< state::ValueStateWrapper< double > >( nullptr ); auto socState = boost::make_shared< state::ValueStateWrapper< double > >( nullptr ); auto currentState = boost::make_shared< state::ValueStateWrapper< double > >( nullptr ); + auto temperatureState = boost::make_shared< state::ValueStateWrapper< double > >( nullptr ); this->GetStateFactory()->CacheInstance( "deltaDOD", dodState ); this->GetStateFactory()->CacheInstance( "meanV", voltageState ); this->GetStateFactory()->CacheInstance( "meanSOC", socState ); this->GetStateFactory()->CacheInstance( "meanI", currentState ); + this->GetStateFactory()->CacheInstance( "meanT", temperatureState ); boost::shared_ptr< object::Object< double > > betaCapacity; boost::shared_ptr< object::Object< double > > betaResistance; @@ -168,7 +170,8 @@ class AgingClassWrapper< aging::CyclicalAging > : public AgingClassWrapperBase std::vector< typename object::ExpressionObject< double >::Parameter > objectParameters{ { "deltaDOD", dodState }, { "meanV", voltageState }, { "meanSOC", socState }, - { "meanI", currentState } }; + { "meanI", currentState }, + { "meanT", temperatureState} }; // Collects the cyclical data from the cell-specific aging node if ( param->HasElementDirectChild( "BetaCapacity" ) ) { @@ -194,6 +197,7 @@ class AgingClassWrapper< aging::CyclicalAging > : public AgingClassWrapperBase const double chargeExponentResistance = param->GetElementDoubleValue( "ChargeExponentResistance" ); const double minBetaCap = param->GetElementDoubleValue( "MinBetaCapacity" ); const double minBetaRes = param->GetElementDoubleValue( "MinBetaResistance" ); + const std::string chargeCountingType = param->GetElementStringValue( "ChargeCountingType", "Ah" ); const double maxBetaCap = param->GetElementDoubleValue( "MaxBetaCapacity", std::numeric_limits< double >::max() ); const double maxBetaRes = param->GetElementDoubleValue( "MaxBetaResistance", std::numeric_limits< double >::max() ); @@ -213,12 +217,13 @@ class AgingClassWrapper< aging::CyclicalAging > : public AgingClassWrapperBase boost::shared_ptr< aging::CyclicalAging > cyclicalAging = boost::make_shared< aging::CyclicalAging >( agingStepTime, minBetaCap, minBetaRes, maxBetaCap, maxBetaRes, betaCapacity, betaResistance, initialCapacityFactor, initialResistanceFactor, - isEnabled, chargeExponentCapacity, chargeExponentResistance ); + isEnabled, chargeExponentCapacity, chargeExponentResistance, chargeCountingType ); *dodState = state::ValueStateWrapper< double >( &cyclicalAging->mActualDod ); *voltageState = state::ValueStateWrapper< double >( &cyclicalAging->mActualVoltage ); *socState = state::ValueStateWrapper< double >( &cyclicalAging->mActualSoc ); *currentState = state::ValueStateWrapper< double >( &cyclicalAging->mActualCurrent ); + *temperatureState = state::ValueStateWrapper< double >( &cyclicalAging->mActualTemperature ); return cyclicalAging; } @@ -246,12 +251,14 @@ class AgingClassWrapper< aging::AnodeOverhang > : public AgingClassWrapperBase argObject->mSoc = soc; boost::shared_ptr< object::Object< double > > voltage = this->GetObjectFactory()->CreateInstance( param->GetElementChild( "Voltage" ), argObject.get() ); + boost::shared_ptr< object::Object< double > > dva = + this->GetObjectFactory()->CreateInstance( param->GetElementChild( "DVA" ), argObject.get() ); double activCoef = param->GetElementDoubleValue( "ActivationCoefficient" ); double tauCoef = param->GetElementDoubleValue( "TauCoefficient" ); double zeroOffsetSoc = param->GetElementDoubleValue( "SocWhereOffsetIsZero" ); bool isEnabled = param->GetElementAttributeBoolValue( "enabled", true ); - return boost::make_shared< aging::AnodeOverhang >( agingStepTime, voltage, activCoef, tauCoef, soc, zeroOffsetSoc, isEnabled ); + return boost::make_shared< aging::AnodeOverhang >( agingStepTime, voltage, dva, activCoef, tauCoef, soc, zeroOffsetSoc, isEnabled ); } }; diff --git a/src/misc/StrCont.cpp b/src/misc/StrCont.cpp index e6f9725ed21245a5379473f6274c383a6ec4ec7b..b77143759ed38eac3d52c65b359adf4e0808a606 100644 --- a/src/misc/StrCont.cpp +++ b/src/misc/StrCont.cpp @@ -58,7 +58,20 @@ StrCont::StrCont( const size_t &inputInt ) #endif } -StrCont::StrCont( const std::ptrdiff_t &inputInt ) +StrCont::StrCont( const long int &inputInt ) +{ +#ifdef __NO_STRING__ + char inputString[MAX_SIZE] = {0}; + real_snprintf( inputString, MAX_SIZE, "%l", inputInt ); + const size_t sizeOfBuffer = strnlen( inputString, MAX_SIZE ) + 1; + mContent.resize( sizeOfBuffer, '\0' ); + strlcpy( &( mContent[0] ), inputString, sizeOfBuffer ); +#else + mContent = boost::lexical_cast< std::string >( inputInt ); +#endif +} + +StrCont::StrCont( const long long int &inputInt ) { #ifdef __NO_STRING__ char inputString[MAX_SIZE] = {0}; @@ -86,7 +99,7 @@ StrCont::StrCont( const double &inputDouble ) #endif } -StrCont::~StrCont() {} + StrCont::operator const char *() const { return &( mContent[0] ); } diff --git a/src/misc/StrCont.h b/src/misc/StrCont.h index c133cd20359cc63b4101c883852af391b1d2f7e5..4f0051c11b833964031d20db2cf73ed0f4df0e13 100644 --- a/src/misc/StrCont.h +++ b/src/misc/StrCont.h @@ -27,11 +27,13 @@ class StrCont ///@param[in] inputInt Is transformed into string and copied into instance StrCont( const size_t &inputInt ); ///@param[in] inputInt Is transformed into string and copied into instance - StrCont( const std::ptrdiff_t &inputInt ); + StrCont( const long int &inputInt ); ///@param[in] inputDouble Is transformed into string and copied into instance StrCont( const double &inputDouble ); + StrCont( const long long int &inputInt ); + void swap( StrCont &rhs ); - virtual ~StrCont(); + virtual ~StrCont() = default; operator const char *() const; StrCont &operator+=( const StrCont &rhs ); size_t size() const { return mContent.size(); }; diff --git a/src/misc/WarningsToTestBuild.cpp_save b/src/misc/WarningsToTestBuild.cpp_save index 02794835c766f370393bc9e19a28793fde6b92f8..1c9e129e7cc786ca05f210b6fd5d9d174a6e69fc 100644 --- a/src/misc/WarningsToTestBuild.cpp_save +++ b/src/misc/WarningsToTestBuild.cpp_save @@ -1,24 +1,6 @@ #include "matrixInclude.h" -#ifdef _ARMADILLO_ - int PseudoFunction(int i) - { - return i + 1; - }; - #ifdef SPARSE_MATRIX_FORMAT - int PseudoFunction2(int i) - { - return i - 1; - }; - #warning Building with Sparse - #else - int PseudoFunction2(int i) - { - return i - 1; - }; - #warning Building with Armadillo - #endif -#elif _MATLAB_ +#ifdef _MATLAB_ int PseudoFunction(int i) { return i + 1; @@ -47,7 +29,7 @@ { return i + 1; }; - #Error Either _ARMADILLO_, _MATLAB_ or _EIGEN_ must be defined + #Error Either _MATLAB_ or _EIGEN_ must be defined #endif diff --git a/src/misc/fast_copy_matrix.cpp b/src/misc/fast_copy_matrix.cpp index 580974743962990a879f4c1089aba4a1c75f8f87..c309e35ebf02dfbe2d7fbd3098d4eaf56d863077 100644 --- a/src/misc/fast_copy_matrix.cpp +++ b/src/misc/fast_copy_matrix.cpp @@ -5,30 +5,7 @@ namespace misc { -// Arma -#if defined( _ARMADILLO_ ) && !defined( SPARSE_MATRIX_FORMAT ) -template <> -void FastCopyMatrix( real_T *array, const arma::Mat< double > &matrix, unsigned int numberOfElements ) -{ - memcpy( (void *)array, matrix.memptr(), numberOfElements * sizeof( real_T ) ); -} -template <> -void FastCopyMatrix( arma::Mat< double > &matrix, const real_T *array, unsigned int numberOfElements ) -{ - memcpy( (void *)matrix.memptr(), array, numberOfElements * sizeof( real_T ) ); -} -template <> -void FastCopyMatrix( arma::Mat< double > &matrix, const arma::Mat< double > &matrixToCopyFrom, - unsigned int numberOfElementsMatrix, const real_T *array, unsigned int numberOfElementsArray ) -{ - real_T *const matrixPtr = matrix.memptr(); - FastCopyMatrix( matrixPtr, matrixToCopyFrom, numberOfElementsMatrix ); - memcpy( (void *)( matrixPtr + numberOfElementsMatrix ), array, numberOfElementsArray * sizeof( real_T ) ); -} - - -// Matlab -#elif defined( _MATLAB_ ) +#if defined( _MATLAB_ ) #ifndef _DS1006 #include "mex.h" #else @@ -56,52 +33,6 @@ void FastCopyMatrix( matlab::MMatrix< mxDOUBLE_CLASS > &matrix, const matlab::MM // Sparse -#elif defined( _ARMADILLO_ ) && defined( SPARSE_MATRIX_FORMAT ) -template <> -void FastCopyMatrix( real_T *array, const arma::SpMat< double > &matrix, unsigned int numberOfElements ) -{ - memset( array, 0, numberOfElements * sizeof( real_T ) ); - - const arma::SpMat< double >::iterator itEnd = matrix.end(); - for ( arma::SpMat< double >::iterator it = matrix.begin(); it != itEnd; ++it ) - if ( it.row() < numberOfElements ) - array[it.row()] = *it; -} -template <> -void FastCopyMatrix( arma::SpMat< double > &matrix, const real_T *array, unsigned int numberOfElements ) -{ - arma::umat locations( 2, numberOfElements, arma::fill::zeros ); - for ( size_t i = 0; i < numberOfElements; ++i ) - locations( 0, i ) = i; - arma::Col< double > values( (double *)array, numberOfElements, false ); - - matrix = arma::SpMat< double >( locations, values, false ); -} -template <> -void FastCopyMatrix( arma::SpMat< double > &matrix, const arma::SpMat< double > &matrixToCopyFrom, - unsigned int numberOfElementsMatrix, const real_T *array, unsigned int numberOfElementsArray ) -{ - const unsigned int numberOfElements = numberOfElementsMatrix + numberOfElementsArray; - // locations and values are used for arma::SpMat<>-Constructor - arma::umat locations( 2, numberOfElements, arma::fill::zeros ); - for ( size_t i = 0; i < numberOfElements; ++i ) - locations( 0, i ) = i; - - arma::Col< double > values( numberOfElements ); - double *const colVecPtr = values.memptr(); - // At first, fill in values of the electrical part of the states into values - memset( colVecPtr, 0, numberOfElementsMatrix * sizeof( real_T ) ); - const arma::SpMat< double >::iterator itEnd = matrixToCopyFrom.end(); - for ( arma::SpMat< double >::iterator it = matrixToCopyFrom.begin(); it != itEnd; ++it ) - colVecPtr[it.row()] = *it; - // Then, fill in values of the thermal part of the states into values - memcpy( (void *)( colVecPtr + numberOfElementsMatrix ), array, numberOfElementsArray * sizeof( real_T ) ); - - matrix = arma::SpMat< double >( locations, values, false ); -} - - -// Eigen #elif defined( _EIGEN_ ) template <> void FastCopyMatrix( ScalarUnit *array, const Eigen::SparseMatrix< double, Eigen::RowMajor > &matrix, unsigned int numberOfElements ) diff --git a/src/misc/fast_copy_matrix.h b/src/misc/fast_copy_matrix.h index 54a47aa8c9bf51d0df60f14952eb8715a625756c..ae3a821c2ade3b1b9d516bc569eb00935798f59a 100644 --- a/src/misc/fast_copy_matrix.h +++ b/src/misc/fast_copy_matrix.h @@ -33,7 +33,7 @@ void FastCopyMatrix( Matrix &matrix, const Matrix &matrixToCopyFrom, unsigned in matrix.coeffRef( numberOfElementsMatrix + i, 0 ) = array[i]; } -#if defined( _ARMADILLO_ ) || defined( _MATLAB_ ) || defined( _EIGEN_ ) +#if defined( _MATLAB_ ) || defined( _EIGEN_ ) template <> void FastCopyMatrix< myMatrixType >( ScalarUnit *array, const myMatrixType &matrix, unsigned int numberOfElements ); template <> diff --git a/src/misc/matrixInclude.h b/src/misc/matrixInclude.h index 2688ed18cd25c29bc60265aac4a5e97628ef2d10..481faf5f8978429a4ba0df0c13aa45905d3c39e7 100644 --- a/src/misc/matrixInclude.h +++ b/src/misc/matrixInclude.h @@ -8,40 +8,27 @@ #ifndef MATRIXINCLUDE_H_ #define MATRIXINCLUDE_H_ -#ifdef _ARMADILLO_ -#include <armadillo> -using namespace arma; -#include "../container/armadillo_wrapper.h" - -#ifdef SPARSE_MATRIX_FORMAT -typedef arma::SpMat< double > myMatrixType; -#else -typedef arma::Mat< double > myMatrixType; -#endif -#elif _EIGEN_ -#include "../container/armadillo_wrapper.h" -#include <armadillo> +#ifdef _EIGEN_ -#include <eigen3/Eigen/Cholesky> -#include <eigen3/Eigen/Core> -#include <eigen3/Eigen/Eigenvalues> -#include <eigen3/Eigen/LU> -#include <eigen3/Eigen/Sparse> -#include <eigen3/Eigen/SparseLU> +#include <Eigen/Cholesky> +#include <Eigen/Core> +#include <Eigen/Eigenvalues> +#include <Eigen/LU> +#include <Eigen/Sparse> +#include <Eigen/SparseLU> // using namespace Eigen; typedef Eigen::SparseMatrix< double, Eigen::RowMajor > myMatrixType; #include "../container/eigen_wrapper.h" #elif _SYMBOLIC_ -#include "../stub/armadillo.h" #include "symbolic.h" -#include <eigen3/Eigen/Cholesky> -#include <eigen3/Eigen/Eigenvalues> -#include <eigen3/Eigen/LU> -#include <eigen3/Eigen/Sparse> -#include <eigen3/Eigen/SparseLU> +#include <Eigen/Cholesky> +#include <Eigen/Eigenvalues> +#include <Eigen/LU> +#include <Eigen/Sparse> +#include <Eigen/SparseLU> // using namespace Eigen; typedef Eigen::SparseMatrix< symbolic::Symbolic< double >, Eigen::RowMajor > myMatrixType; @@ -54,7 +41,7 @@ using SymbolicMatrix = Eigen::SparseMatrix< symbolic::Symbolic< Output >, Eigen: } using namespace symbolic; #else -#Error Either _ARMADILLO_ or _EIGEN_ must be defined +#Error _EIGEN_ must be defined #endif template < typename MatrixType > diff --git a/src/misc/symbolic.h b/src/misc/symbolic.h index e94cc6ca3c3a2472f23838fc9369b39f963a169b..bbf41e62d491bd1eb5aeafb12a8964d57063bfd2 100644 --- a/src/misc/symbolic.h +++ b/src/misc/symbolic.h @@ -33,12 +33,14 @@ class Symbolic bool empty() const { return IsEmpty(); }; Symbolic(); explicit Symbolic( const char *content ); - explicit Symbolic( const size_t content ); - explicit Symbolic( const int content ); - explicit Symbolic( const std::ptrdiff_t content ); + explicit Symbolic( size_t content ); + explicit Symbolic( int content ); + explicit Symbolic( long int content ); + explicit Symbolic( long long int content ); - Symbolic( const double content ); - ~Symbolic(); + + Symbolic( double content );//::TODO:: making one of the int copy contrsuctors non explicit instead of this one + ~Symbolic() = default; bool IsEmpty() const; bool IsOne() const; size_t size() const { return mContent.size(); }; @@ -55,7 +57,8 @@ class Symbolic private: bool ContentIsZero( const size_t &content ) const; - bool ContentIsZero( const std::ptrdiff_t &content ) const; + bool ContentIsZero( const long long int &content ) const; + bool ContentIsZero( const long int &content ) const; bool ContentIsZero( const int &content ) const; bool ContentIsZero( const double &content ) const; void DoNothingButAvoidCompilerWarning() const; @@ -166,11 +169,6 @@ bool Symbolic< OutputType >::operator!=( const Symbolic< OutputType > &rhs ) con return strcmp( mContent, rhs.mContent ) != 0; } -template < typename OutputType > -Symbolic< OutputType >::Symbolic( const char *content ) - : mContent( content ) -{ -} template < typename OutputType > Symbolic< OutputType > &Symbolic< OutputType >::operator=( const char *content ) @@ -182,42 +180,48 @@ Symbolic< OutputType > &Symbolic< OutputType >::operator=( const char *content ) this->Simplyfy(); return *this; } - template < typename OutputType > -Symbolic< OutputType >::Symbolic( const size_t content ) +Symbolic< OutputType >::Symbolic( const char *content ) + : mContent( content ) +{ +} +template < typename OutputType > +Symbolic< OutputType >::Symbolic( size_t content ) : mContent( ContentIsZero( content ) ? StrCont() : StrCont( content ) ) { } + template < typename OutputType > -Symbolic< OutputType >::Symbolic( const std::ptrdiff_t content ) +Symbolic< OutputType >::Symbolic( int content ) : mContent( ContentIsZero( content ) ? StrCont() : StrCont( content ) ) { } - template < typename OutputType > -Symbolic< OutputType >::Symbolic( const int content ) +Symbolic< OutputType >::Symbolic( long int content ) : mContent( ContentIsZero( content ) ? StrCont() : StrCont( content ) ) { } - template < typename OutputType > -Symbolic< OutputType >::Symbolic( const double content ) +Symbolic< OutputType >::Symbolic( long long int content ) : mContent( ContentIsZero( content ) ? StrCont() : StrCont( content ) ) { } template < typename OutputType > -Symbolic< OutputType >::Symbolic() - : mContent( StrCont() ) +Symbolic< OutputType >::Symbolic( double content ) + : mContent( ContentIsZero( content ) ? StrCont() : StrCont( content ) ) { } template < typename OutputType > -Symbolic< OutputType >::~Symbolic() +Symbolic< OutputType >::Symbolic() + : mContent( StrCont() ) { } + + template < typename OutputType > bool Symbolic< OutputType >::IsEmpty() const { @@ -247,9 +251,13 @@ bool Symbolic< OutputType >::ContentIsZero( const size_t &content ) const { return content == 0; } - template < typename OutputType > -bool Symbolic< OutputType >::ContentIsZero( const std::ptrdiff_t &content ) const +bool Symbolic< OutputType >::ContentIsZero( const long long int &content ) const +{ + return content == 0; +} +template < typename OutputType > +bool Symbolic< OutputType >::ContentIsZero( const long int &content ) const { return content == 0; } diff --git a/src/object/expression_obj.h b/src/object/expression_obj.h index 7b78c25d469d25c033870be2cea0cbcc97d0afb7..da425c76e4cfed42d8f3aef60ce1d67d50217017 100644 --- a/src/object/expression_obj.h +++ b/src/object/expression_obj.h @@ -1,10 +1,10 @@ #ifndef _EXPRESSION_OBJ_ #define _EXPRESSION_OBJ_ - +#include <boost/shared_ptr.hpp> +#include <array> #include "../../libraries/exprtk/exprtk.hpp" #include "../state/state.h" #include "object.h" -#include <boost/shared_ptr.hpp> namespace object { diff --git a/src/observer/filter/csvfilter.h b/src/observer/filter/csvfilter.h index b2d67d7e034f57dca3d1ba3982fc33eb76127e72..79af243d70143cb91472584ee29d167d65e15d97 100644 --- a/src/observer/filter/csvfilter.h +++ b/src/observer/filter/csvfilter.h @@ -138,7 +138,7 @@ class CsvFilterBase< T, electrical::TwoPort, PreparationType< T > > { if ( mRootPort ) { - this->mFilestream << "," << -1; + this->mFilestream << t << "," << -1; PrintData( mRootPort ); } @@ -275,11 +275,11 @@ class CsvFilterBase< T, thermal::ThermalElement, ThermalPreperation > this->mFilestream << "\n"; this->mFilestream << std::flush; + this->mProbeFile << t; for ( const auto& probe : ( *mThermalProbes ) ) { this->mProbeFile << ", " << probe.GetTemperature(); } - this->mProbeFile << "\n"; this->mProbeFile << std::flush; diff --git a/src/state/soc.h b/src/state/soc.h index 8f82571d4552b68040ae5149062fd9a616992f57..bd37008b3c5cdf19d145efb90feef03a04df702d 100644 --- a/src/state/soc.h +++ b/src/state/soc.h @@ -33,7 +33,9 @@ enum class SocSetFormat { ABSOLUT, DELTA, - FACTOR + DELTALIM, + FACTOR, + PERCENT }; /// This class describes the behaviour of the State of Charge depending on the capacity @@ -208,9 +210,23 @@ void Soc::SetStoredEnergy( const double value ) mActualSoc += value / mActualCapacity; break; + case SocSetFormat::DELTALIM: + mActualSoc += value / mActualCapacity; + if ( mActualSoc < 0 ) { + mActualSoc = 0; + } + else if ( mActualSoc > 1 ) { + mActualSoc = 1; + } + break; + case SocSetFormat::FACTOR: mActualSoc = value; break; + + case SocSetFormat::PERCENT: + mActualSoc = value / 100; + break; default: ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, "UndefinedFormat", "Soc" ); diff --git a/src/state/surface_soc.h b/src/state/surface_soc.h index 85e8b427abbe1c3d16f2997e6f5bccb0f2d8f9a8..04539241f1bcd1d434eb122c3a0c7023adefd797 100644 --- a/src/state/surface_soc.h +++ b/src/state/surface_soc.h @@ -7,6 +7,12 @@ _._._._._._._._._._._._._._._._._._._._._.*/ #ifndef _SURFACE_SOC_ #define _SURFACE_SOC_ +#ifdef max +#pragma push_macro( "max" ) +#undef max +#define RESTORE_MAX_MACRO +#endif + // STD #include <boost/shared_ptr.hpp> #include <limits> @@ -59,4 +65,10 @@ class SurfaceSoc : public State double mCurrentValue; }; } // namespace state + +#ifdef RESTORE_MAX_MACRO +#pragma pop_macro( "size" ) +#undef RESTORE_MAX_MACRO +#endif + #endif /* _SURFACE_SOC_ */ diff --git a/src/system/constantstepdglsystemsolver.cpp b/src/system/constantstepdglsystemsolver.cpp index 5696c0d0bbc3ca350cb1fcb5c62611db89164b01..0aeea0fedc01b6c486072e49fc61a7b91e4396dd 100644 --- a/src/system/constantstepdglsystemsolver.cpp +++ b/src/system/constantstepdglsystemsolver.cpp @@ -36,30 +36,7 @@ double ConstantStepDglSystemSolver< Eigen::SparseMatrix< double, Eigen::RowMajor #endif /* _EIGEN_ */ -#ifdef _ARMADILLO_ -ConstantStepDglSystemSolver< arma::Mat< double > >::ConstantStepDglSystemSolver( StateSystemGroup< arma::Mat< double > >* stateSystemGroup, - double dt ) - : SystemSolver< arma::Mat< double > >( stateSystemGroup, dt ) - , daeSystem( new systm::DifferentialAlgebraicSystem< arma::Mat< double > >( stateSystemGroup ) ) -{ -} - -double ConstantStepDglSystemSolver< arma::Mat< double > >::Solve() -{ - daeSystem->PrepareEquationSystem(); - arma::Mat< double > states = this->mStateVector.submat( 0, 0, this->mStateVector.rows() - 2, 0 ); - mStepper.do_step( *daeSystem, states, 0, this->mDt ); - this->mStateVector.submat( 0, 0, this->mStateVector.rows() - 2, 0 ) = states; - - this->mTime += this->mDt; - - this->ResetStateSystemGroup(); - - return this->mTime; -} - -#endif /* _ARMADILLO_ */ } /* namespace systm */ diff --git a/src/system/constantstepdglsystemsolver.h b/src/system/constantstepdglsystemsolver.h index 7848a61b1e4c41e765efe561e6bc2bd42f95c9bb..17aaf27f3f775640589aede8a302e3f42af1b76c 100644 --- a/src/system/constantstepdglsystemsolver.h +++ b/src/system/constantstepdglsystemsolver.h @@ -60,25 +60,6 @@ template <> double ConstantStepDglSystemSolver< Eigen::SparseMatrix< double, Eigen::RowMajor > >::Solve(); #endif /* _EIGEN_ */ -#ifdef _ARMADILLO_ - -/// Solver with constant dt and euler integration -template <> -class ConstantStepDglSystemSolver< arma::Mat< double > > : public SystemSolver< arma::Mat< double > > -{ - public: - ConstantStepDglSystemSolver( StateSystemGroup< arma::Mat< double > >* stateSystemGroup, double dt ); - - virtual ~ConstantStepDglSystemSolver() {} - - virtual double Solve(); - - private: - boost::scoped_ptr< systm::DifferentialAlgebraicSystem< arma::Mat< double > > > daeSystem; - boost::numeric::odeint::runge_kutta4< arma::Mat< double > > mStepper; -}; - -#endif /* _ARMADILLO_ */ } /* namespace systm */ diff --git a/src/system/dae_sys.cpp b/src/system/dae_sys.cpp index 391a6cc060a1765c05570cbc42637055e210a835..9b226069535521b8c31453863d0220978deb7e9d 100644 --- a/src/system/dae_sys.cpp +++ b/src/system/dae_sys.cpp @@ -45,165 +45,6 @@ void DifferentialAlgebraicSystem< matlab::MMatrix< mxDOUBLE_CLASS > >::CopyDGLRe #endif -#ifdef _ARMADILLO_ - -template <> -void DifferentialAlgebraicSystem< Mat< double > >::CopyALGResultsToMatrixAndVector( const size_t dglUIDCount, const size_t algUIDCount, - const Mat< double > &sourceMatrix, - const Mat< double > &sourceVector, - const Mat< double > &invertedMat ) -{ - mStateSystemGroup->mStateVector.submat( dglUIDCount, 0, dglUIDCount + algUIDCount - 1, 0 ) = invertedMat; - mMatrixA.submat( dglUIDCount, 0, dglUIDCount + algUIDCount - 1, algUIDCount + dglUIDCount - 1 ) = sourceMatrix; - mVectorC.submat( dglUIDCount, 0, dglUIDCount + algUIDCount - 1, 0 ) = sourceVector; -} - -template <> -void DifferentialAlgebraicSystem< Mat< double > >::CopyDGLResultsToMatrixAndVector( const size_t dglUIDCount, const size_t algUIDCount, - const Mat< double > &sourceMatrix, - const Mat< double > &sourceVector ) -{ - mMatrixA.submat( 0, 0, dglUIDCount - 1, algUIDCount + dglUIDCount - 1 ) = sourceMatrix; - mVectorC.submat( 0, 0, dglUIDCount - 1, 0 ) = sourceVector; -} - -template <> -DifferentialAlgebraicSystem< arma::SpMat< double > >::DifferentialAlgebraicSystem( StateSystemGroup< arma::SpMat< double > > *stateSystemGroup ) - : GeneralizedSystem< arma::SpMat< double > >() - , mMatrixA( arma::Mat< double >() ) - , mStateSystemGroup( stateSystemGroup ) - , mDglStateSystem( &stateSystemGroup->mDglStateSystem ) - , mAlgStateSystem( &stateSystemGroup->mAlgStateSystem ) -{ - const size_t statecount = mStateSystemGroup->GetStateCount(); - mMatrixA.zeros( statecount, statecount ); - mVectorC.zeros( statecount, 1 ); - CalculateInitialState(); -} - -template <> -const arma::SpMat< double > DifferentialAlgebraicSystem< arma::SpMat< double > >::GetA() const ///< Get MatrixA -{ - return arma::SpMat< double >( mMatrixA ); -} - -template <> -const arma::SpMat< double > DifferentialAlgebraicSystem< arma::SpMat< double > >::GetC() const ///< Get VectorC -{ - return arma::SpMat< double >( mVectorC ); -} - -template <> -void DifferentialAlgebraicSystem< arma::SpMat< double > >::PrepareEquationSystem() ///< make ode equations out of the linear ones (alg1,alg2) -{ - const size_t algUIDCount = mAlgStateSystem->GetEquationCount(); - const size_t dglUIDCount = mDglStateSystem->GetEquationCount(); - - if ( dglUIDCount == 0 ) - ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, "DGLNotEnough" ); - - mMatrixA.zeros(); - mVectorC.zeros(); - - const arma::SpMat< double > &dglMatrixA = mStateSystemGroup->mDglStateSystem.GetEquationSystemAMatrix(); - const arma::SpMat< double > &dglVectorC = mDglStateSystem->GetEquationSystemCVector(); - - for ( arma::SpMat< double >::const_iterator it = dglMatrixA.begin(); it != dglMatrixA.end(); it++ ) - mMatrixA( it.row(), it.col() ) = *it; - - for ( arma::SpMat< double >::const_iterator it = dglVectorC.begin(); it != dglVectorC.end(); it++ ) - mVectorC( it.row(), 0 ) = *it; - - if ( algUIDCount == 0 ) - return; - - const arma::SpMat< double > &algVectorC = mAlgStateSystem->GetEquationSystemCVector(); - const arma::SpMat< double > mAlg1MatrixA = mAlgStateSystem->GetEquationSystemAMatrix().cols( 0, dglUIDCount - 1 ); - const arma::SpMat< double > mAlg2MatrixA = - mAlgStateSystem->GetEquationSystemAMatrix().cols( dglUIDCount, dglUIDCount + algUIDCount - 1 ); - - // CalculateInitialStateFromCurrentState - arma::SpMat< double > &stateVector = mStateSystemGroup->mStateVector; - arma::SpMat< double > invertedMat = - solve( mAlg2MatrixA, -1 * algVectorC - mAlg1MatrixA * ( stateVector.rows( 0, dglUIDCount - 1 ) ) ); - for ( size_t i = 0; i < algUIDCount; ++i ) - stateVector( dglUIDCount + i, 0 ) = invertedMat( i, 0 ); - //..................................... - - const arma::SpMat< double > invAlg2MinusAlg1 = inv( mAlg2MatrixA ) * ( -1.0 * mAlg1MatrixA ); - const arma::SpMat< double > DGLifiedA = invAlg2MinusAlg1 * dglMatrixA; - const arma::SpMat< double > DGLifiedC = invAlg2MinusAlg1 * dglVectorC; - - for ( arma::SpMat< double >::const_iterator it = DGLifiedA.begin(); it != DGLifiedA.end(); it++ ) - mMatrixA( it.row() + dglUIDCount, it.col() ) = *it; - - for ( arma::SpMat< double >::const_iterator it = DGLifiedC.begin(); it != DGLifiedC.end(); it++ ) - mVectorC( it.row() + dglUIDCount, 0 ) = *it; -} - -template <> -void DifferentialAlgebraicSystem< arma::SpMat< double > >:: -operator()( const arma::SpMat< double > &x, arma::SpMat< double > &dxdt, const double /* t */ ) -{ - dxdt = mMatrixA * x + mVectorC; -} - -template <> -void DifferentialAlgebraicSystem< arma::SpMat< double > >:: -operator()( const arma::Mat< double > &x, arma::Mat< double > &dxdt, const double /* t */ ) -{ - dxdt = mMatrixA * x + mVectorC; -} - -template <> -void DifferentialAlgebraicSystem< arma::SpMat< double > >:: -operator()( const std::vector< double > &x, std::vector< double > &dxdt, const double /* t */ ) -{ - const size_t stateCount = mStateSystemGroup->GetStateCount(); - - // Store x into temporary states - arma::SpMat< double > tmpX( stateCount, 1 ); - misc::FastCopyMatrix( tmpX, &x[0], stateCount ); - - // Calculate dxdt - arma::SpMat< double > tmpDxdt( stateCount, 1 ); - operator()( tmpX, tmpDxdt, 0.0 ); - - // Store result back into dxdt - dxdt.resize( x.size() ); - misc::FastCopyMatrix( &dxdt[0], tmpDxdt, stateCount ); -} - -template <> -void DifferentialAlgebraicSystem< arma::SpMat< double > >::CalculateInitialState() ///< output x vector with all DGL values set to zero -{ - const size_t algUIDCount = mAlgStateSystem->GetEquationCount(); - const size_t dglUIDCount = mDglStateSystem->GetEquationCount(); - - if ( algUIDCount == 0 ) - return; - - const arma::SpMat< double > &algVectorC = mAlgStateSystem->GetEquationSystemCVector(); - const arma::SpMat< double > &mAlg2MatrixA = - mAlgStateSystem->GetEquationSystemAMatrix().cols( dglUIDCount, dglUIDCount + algUIDCount - 1 ); - - if ( mAlg2MatrixA.n_nonzero == 0 ) - ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, "AlgNotInvertable" ); - - arma::SpMat< double > &stateVector = mStateSystemGroup->mStateVector; - - arma::SpMat< double > invertedMat = solve( mAlg2MatrixA, algVectorC ); // -1 is beeing put later - for ( size_t i = 0; i < algUIDCount; ++i ) // is faster than memcpy ...? - stateVector( dglUIDCount + i, 0 ) = -invertedMat( i, 0 ); -} - -template <> -const char *DifferentialAlgebraicSystem< arma::SpMat< double > >::GetName() const -{ - return "DifferentialAlgebraicSystem"; -} - -#endif /* _ARMADILLO_ */ #if defined( _EIGEN_ ) || defined( _SYMBOLIC_ ) diff --git a/src/system/dae_sys.h b/src/system/dae_sys.h index 08d200e979fc7072d9a7b706341c2a64ebbb3b44..7085331431a8c4d12b4c9dd39da220bf18ba1e88 100644 --- a/src/system/dae_sys.h +++ b/src/system/dae_sys.h @@ -226,54 +226,6 @@ void DifferentialAlgebraicSystem< matlab::MMatrix< mxDOUBLE_CLASS > >::CopyDGLRe const matlab::MMatrix< mxDOUBLE_CLASS >& sourceVector ); #endif -#ifdef _ARMADILLO_ - -template <> -void DifferentialAlgebraicSystem< Mat< double > >::CopyALGResultsToMatrixAndVector( const size_t dglUIDCount, const size_t algUIDCount, - const Mat< double >& sourceMatrix, - const Mat< double >& sourceVector, - const Mat< double >& invertedMat ); - -template <> -void DifferentialAlgebraicSystem< Mat< double > >::CopyDGLResultsToMatrixAndVector( const size_t dglUIDCount, const size_t algUIDCount, - const Mat< double >& sourceMatrix, - const Mat< double >& sourceVector ); - - -/// Class for creating a Differential Algebraic System from a electric circuit -template <> -class DifferentialAlgebraicSystem< arma::SpMat< double > > -{ - public: - DifferentialAlgebraicSystem( StateSystemGroup< arma::SpMat< double > >* stateSystemGroup ); - virtual ~DifferentialAlgebraicSystem(){}; - - virtual const arma::SpMat< double > GetA() const; ///< Get MatrixA - virtual const arma::SpMat< double > GetC() const; ///< Get VectorC - - virtual const arma::SpMat< double > GetAODE() const; ///< Get MatrixA - virtual const arma::SpMat< double > GetCODE() const; ///< Get VectorC - - void PrepareEquationSystem(); - void operator()( const arma::SpMat< double >& x, arma::SpMat< double >& dxdt, const double /* t */ ); - void operator()( const arma::Mat< double >& x, arma::Mat< double >& dxdt, const double /* t */ ); - void operator()( const std::vector< double >& x, std::vector< double >& dxdt, const double /* t */ ); - - virtual const char* GetName() const { return "DifferentialAlgebraicSystem"; } - - private: - void CalculateInitialState(); ///< output x vector with all DGL values set to zero - // void ODEifyEquations(); ///< make ode equations out of the linear ones (alg1,alg2) - - arma::Mat< double > mMatrixA; - arma::Mat< double > mVectorC; - StateSystemGroup< arma::SpMat< double > >* mStateSystemGroup; - StateSystem< arma::SpMat< double > >* mDglStateSystem; - StateSystem< arma::SpMat< double > >* mAlgStateSystem; -}; - -#endif /* _ARMADILLO_ */ - #ifdef _SYMBOLIC_ typedef symbolic::Symbolic< double > _Scalar; @@ -387,26 +339,7 @@ class DifferentialAlgebraicSystem< MatrixType > dxdt.bottomRows( algUIDCount ) = ret; } -#if defined( _DS1006 ) || !defined( _SYMBOLIC_ ) - void operator()( const arma::Mat< double >& x, arma::Mat< double >& dxdt, const double /* t */ ) - { - // Read from arma matrix - // TODO:Use memcpy in future - Eigen::Matrix< _Scalar, Eigen::Dynamic, 1 > x2( x.n_rows, x.n_cols ); - for ( size_t i = 0; i < x.n_rows; ++i ) - x2.coeffRef( i, 0 ) = x( i, 0 ); - - dxdt.resize( x.n_rows, x.n_cols ); - Eigen::Matrix< _Scalar, Eigen::Dynamic, 1 > dxdt2( dxdt.n_rows, dxdt.n_cols ); - // Do the job - operator()( x2, dxdt2, 0 ); - - // Write back to arma matrix - for ( size_t i = 0; i < dxdt.n_rows; ++i ) - dxdt( i, 0 ) = dxdt2( i, 0 ); - } -#endif void operator()( const std::vector< _Scalar >& x, std::vector< _Scalar >& dxdt, const double /* t */ ) { const size_t stateCount = mStateSystemGroup->GetStateCount(); diff --git a/src/system/rawsparsedata.cpp b/src/system/rawsparsedata.cpp index 8b354e19affd885480c966790221e999f826dd2b..7ac95c6abc51cc10c09cc059011afd9cd5ad74db 100644 --- a/src/system/rawsparsedata.cpp +++ b/src/system/rawsparsedata.cpp @@ -7,97 +7,3 @@ #include "rawsparsedata.h" -#ifdef _ARMADILLO_ - -namespace systm -{ - -RawSparseData::RawSparseData() - : mLocations(arma::umat(2,1000)), - mValues(arma::colvec(1000)), - mElements(0) -{ } - -RawSparseData::RawSparseData(const std::vector< RawSparseData >& vector) - : mElements(0) -{ - for(size_t i = 0; i < vector.size(); ++i) - mElements += vector.at(i).mElements; - - mLocations.set_size(2, mElements); - mValues.set_size(mElements); - - size_t index = 0; - for(size_t i = 0; i < vector.size(); ++i) - { - const RawSparseData& data = vector.at(i); - const size_t rows = data.mElements; - - if(!rows) - continue; - - mLocations.cols( index, index + rows -1) = data.mLocations.cols(0, rows -1); - mValues.rows( index, index + rows -1) = data.mValues.rows(0, rows -1); - index += rows; - } -} - -void RawSparseData::Clear() -{ - mElements = 0; -} - -void RawSparseData::Add(const arma::SpMat<double>& matrix, size_t rowOffset) -{ - CheckAndAdaptSize( matrix.n_nonzero ); - - for(arma::SpMat<double>::const_iterator it = matrix.begin(); it != matrix.end(); ++it) - { - mLocations(0, mElements) = it.row() + rowOffset; - mLocations(1, mElements) = it.col(); - mValues(mElements) = *it; - ++mElements; - } -} - -void RawSparseData::Add(const size_t row, const size_t col, const double value) -{ - CheckAndAdaptSize(); - - mLocations(0, mElements) = row; - mLocations(1, mElements) = col; - mValues(mElements) = value; - ++mElements; -} - -void RawSparseData::Add(const arma::SpMat<double>::const_iterator& beginIt, const arma::SpMat<double>::const_iterator& endIt, size_t rowOffset) -{ - CheckAndAdaptSize(); - - for(arma::SpMat<double>::const_iterator it = beginIt; it != endIt; ++it) - { - mLocations(0, mElements) = it.row() + rowOffset; - mLocations(1, mElements) = it.col(); - mValues(mElements) = *it; - ++mElements; - } -} - -void RawSparseData::FillMatrix(arma::SpMat<double>& matrix, const arma::uword rows, const arma::uword cols) -{ - matrix = arma::SpMat<double>(mLocations, mValues, rows, cols); -} - -void RawSparseData::CheckAndAdaptSize(size_t additionalNeededElements) -{ - const size_t neededRows = mElements + additionalNeededElements + 500; - if(mValues.n_rows < neededRows) - { - mLocations.resize(2, neededRows + 1000); - mValues.resize(neededRows + 1000); - } -} - -} /* namespace systm */ - -#endif /* _ARMADILLO_ */ diff --git a/src/system/rawsparsedata.h b/src/system/rawsparsedata.h index e56b555e0a22d939b41d1d907e7f548a8ae0022e..8549bef7a54a4dfe3bd594ffbb9ff4f69b70c008 100644 --- a/src/system/rawsparsedata.h +++ b/src/system/rawsparsedata.h @@ -8,53 +8,6 @@ #ifndef RAWSPARSEDATA_H_ #define RAWSPARSEDATA_H_ -#ifdef _ARMADILLO_ -#include <armadillo> - -namespace systm -{ - -///Data container for sparse data. It can be merged into a single sparse matrix. -class RawSparseData -{ -public: - ///Create an empty container - RawSparseData(); - - ///Merge several containers into one - RawSparseData(const std::vector< RawSparseData >& vector); - - ///Clears the added data. (no time consumption) - void Clear(); - - ///Add some data - void Add(const arma::SpMat<double>& matrix, size_t rowOffset); - - ///Add some data - void Add(const arma::SpMat<double>::const_iterator& beginIt, const arma::SpMat<double>::const_iterator& endIt, size_t rowOffset); - - ///Add some data - void Add(const size_t row, const size_t col, const double value); - - ///Add some data - void FillMatrix(arma::SpMat<double>& matrix, const arma::uword rows, const arma::uword cols); - - ///Extends the underlying storage capacity if needed - void CheckAndAdaptSize(size_t additionalNeededElements = 0); - - ///Cell locations - arma::umat mLocations; - - ///Cell values - arma::colvec mValues; - - ///Number of added Cells - size_t mElements; -}; - -} /* namespace systm */ - -#endif /* _ARMADILLO_ */ #endif /* RAWSPARSEDATA_H_ */ diff --git a/src/system/stateSystem.cpp b/src/system/stateSystem.cpp index 33d3699d00394030a1328dd4680a4b7e235abdc9..10c106e2ea33cc7cce21fbb5b000f3b34b43ac3f 100644 --- a/src/system/stateSystem.cpp +++ b/src/system/stateSystem.cpp @@ -40,169 +40,6 @@ void StateSystem< Eigen::SparseMatrix< double, Eigen::RowMajor > >::ResetSystem( #endif /* _EIGEN_ */ -#ifdef _ARMADILLO_ -/// Standard constructor for empty StateSystem -StateSystem< arma::SpMat< double > >::StateSystem() - : mEquationCount( 0 ) - , mStateCount( 0 ) - , mIsInitialized( false ) - , mMatrixANeedsUpdate( true ) - , mMatrixCNeedsUpdate( true ) -{ - ResetSystem(); -} - -/// Constructs a system with a given matrix's data -StateSystem< arma::SpMat< double > >::StateSystem( const arma::SpMat< double > &matrixA, const arma::SpMat< double > &vectorC ) - : mMatrixA( matrixA ) - , mVectorC( vectorC ) - , mEquationCount( matrixA.n_rows ) - , mStateCount( matrixA.n_cols ) - , mIsInitialized( true ) - , mMatrixANeedsUpdate( true ) - , mMatrixCNeedsUpdate( true ) -{ -} - -void StateSystem< arma::SpMat< double > >::AddPartition( size_t &rowOffset, size_t startRow, size_t endRow ) -{ - const size_t rowSpan = endRow - startRow; - const size_t partitionIndex = mSubMatrixARawDataVector.size(); - - if ( !rowSpan ) - return; - - rowOffset += rowSpan; - - std::vector< size_t > tmp( rowSpan, partitionIndex ); - mPartitionLookupVector.insert( mPartitionLookupVector.end(), tmp.begin(), tmp.end() ); - - mSubMatrixARawDataVector.push_back( RawSparseData() ); - mSubVectorCRawDataVector.push_back( RawSparseData() ); - mMatrixANeedsUpdate = true; - mMatrixCNeedsUpdate = true; -} - -void StateSystem< arma::SpMat< double > >::PartitionSystem( std::vector< std::pair< size_t, size_t > > partitions ) // index = workerid ^ value = rows -{ - size_t rowOffset = 0; - - mMatrixANeedsUpdate = true; - mMatrixCNeedsUpdate = true; - - mPartitionLookupVector.clear(); - mSubMatrixARawDataVector.clear(); - mSubVectorCRawDataVector.clear(); - - for ( size_t i = 0; i < partitions.size(); ++i ) - { - const size_t startRow = partitions.at( i ).first; - const size_t endRow = partitions.at( i ).second; - - if ( startRow > rowOffset ) - { - AddPartition( rowOffset, rowOffset, startRow ); - } - - AddPartition( rowOffset, startRow, endRow ); - } - - AddPartition( rowOffset, rowOffset, mEquationCount ); -} - -/// Set one or more lines in the matrix -void StateSystem< arma::SpMat< double > >::AddEquations( size_t equationNumber, const arma::SpMat< double > &matrix ) -{ - size_t partitionIndex = mPartitionLookupVector.at( equationNumber ); - mSubMatrixARawDataVector.at( partitionIndex ).Add( matrix.cols( 0, matrix.n_cols - 2 ), equationNumber ); - mSubVectorCRawDataVector.at( partitionIndex ).Add( matrix.col( matrix.n_cols - 1 ), equationNumber ); - - mMatrixANeedsUpdate = true; - mMatrixCNeedsUpdate = true; -} - -/// Set one or more lines in the matrix -void StateSystem< arma::SpMat< double > >::AddEquations( size_t equationNumber, const arma::SpMat< double > &matrixA, - const arma::SpMat< double > &vectorC ) -{ - size_t partitionIndex = mPartitionLookupVector.at( equationNumber ); - mSubMatrixARawDataVector.at( partitionIndex ).Add( matrixA, equationNumber ); - mSubVectorCRawDataVector.at( partitionIndex ).Add( vectorC, equationNumber ); - - mMatrixANeedsUpdate = true; - mMatrixCNeedsUpdate = true; -} - -/// Reset the matrix to zeros (used for sparse only) -void StateSystem< arma::SpMat< double > >::ResetSystem() -{ - for ( size_t i = 0; i < mSubMatrixARawDataVector.size(); ++i ) - { - mSubMatrixARawDataVector.at( i ).Clear(); - mSubVectorCRawDataVector.at( i ).Clear(); - } - mMatrixA.zeros(); - mVectorC.zeros(); -} - -/// After all equations have been registered, this method will set the data sizes and calls itself the reset method -void StateSystem< arma::SpMat< double > >::Initialize( size_t stateCount ) -{ - if ( mIsInitialized ) - ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, "AlreadyInitialized", "StateSystem" ); - - mStateCount = stateCount; - mMatrixA.zeros( mEquationCount, mStateCount ); - mVectorC.zeros( mEquationCount, 1 ); - - mPartitionLookupVector = std::vector< size_t >( mEquationCount + 1, 0 ); - mSubMatrixARawDataVector.push_back( RawSparseData() ); - mSubVectorCRawDataVector.push_back( RawSparseData() ); - - mIsInitialized = true; -} - -/// Returns the constant part "C" of the matrix -const arma::SpMat< double > &StateSystem< arma::SpMat< double > >::GetEquationSystemCVector() -{ - if ( !mMatrixCNeedsUpdate ) - return mVectorC; - mMatrixCNeedsUpdate = true; - - RawSparseData rawCData( mSubVectorCRawDataVector ); - rawCData.FillMatrix( mVectorC, mEquationCount, 1 ); - - return mVectorC; -} - -/// Returns the matrix part "A" of the matrix -const arma::SpMat< double > &StateSystem< arma::SpMat< double > >::GetEquationSystemAMatrix() -{ - if ( !mMatrixANeedsUpdate ) - return mMatrixA; - mMatrixANeedsUpdate = true; - - RawSparseData rawAData( mSubMatrixARawDataVector ); - rawAData.FillMatrix( mMatrixA, mEquationCount, mStateCount ); - - return mMatrixA; -} - -/// Register a new equation and get its rownumber -size_t StateSystem< arma::SpMat< double > >::GetNewEquation() -{ - if ( mIsInitialized ) - ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, - "CannotRegisterEquationAfterInitializationException" ); - - return ++mEquationCount - 1; -} - -/// The number of registered equations -size_t StateSystem< arma::SpMat< double > >::GetEquationCount() { return mEquationCount; } - -#endif /* _ARMADILLO_ */ - } /* namespace systm */ diff --git a/src/system/stateSystem.h b/src/system/stateSystem.h index 39e35be0ff4d980b61dea5c1f5b73557d7f75e3e..c464c4e89819f2d192826159be2998f6fb4b11a6 100644 --- a/src/system/stateSystem.h +++ b/src/system/stateSystem.h @@ -188,71 +188,6 @@ size_t StateSystem< MatrixType >::GetEquationCount() } -/* SPARSE ADDITIONS */ - -#ifdef _ARMADILLO_ - -/// Equationsystem which contains the statesystemmatrix -template <> -class StateSystem< arma::SpMat< double > > -{ - public: - /// Standard constructor for empty StateSystem - StateSystem(); - - /// Constructs a system with a given matrix's data - StateSystem( const arma::SpMat< double > &matrixA, const arma::SpMat< double > &vectorC ); - - virtual ~StateSystem() {} - - /// Set one or more lines in the matrix - void AddEquations( size_t equationNumber, const arma::SpMat< double > &matrix ); - - /// Set one or more lines in the matrix - void AddEquations( size_t equationNumber, const arma::SpMat< double > &matrix, const arma::SpMat< double > &vectorC ); - - /// Reset the matrix to zeros - void ResetSystem(); - - /// After all equations have been registered, this method will set the data sizes and calls itself the reset method - void Initialize( size_t stateCount ); - - /// Returns the constant part "C" of the matrix - const arma::SpMat< double > &GetEquationSystemCVector(); - - /// Returns the matrix part "A" of the matrix - const arma::SpMat< double > &GetEquationSystemAMatrix(); - - /// Register a new equation and get its rownumber - size_t GetNewEquation(); - - /// The number of registered equations - size_t GetEquationCount(); - - /// The systemmatrices can be parted into multiple matrices for being able to write to them in parallel. This method - /// does the partitioning work. - void PartitionSystem( std::vector< std::pair< size_t, size_t > > partitions ); - - private: - /// Add a new partition to the system. - void AddPartition( size_t &rowOffset, size_t startRow, size_t endRow ); - - arma::SpMat< double > mMatrixA; - arma::SpMat< double > mVectorC; - - std::vector< RawSparseData > mSubMatrixARawDataVector; - std::vector< RawSparseData > mSubVectorCRawDataVector; - std::vector< size_t > mPartitionLookupVector; - std::vector< size_t > mRowOffsetLookupVector; - - size_t mEquationCount; - size_t mStateCount; - bool mIsInitialized; - bool mMatrixANeedsUpdate; - bool mMatrixCNeedsUpdate; -}; - -#endif /* _ARMADILLO_ */ } /* namespace systm */ diff --git a/src/system/variablestepdglsystemsolver.cpp b/src/system/variablestepdglsystemsolver.cpp deleted file mode 100644 index 031eac5f25e2fedaea565b9f5eb5750303a27ee3..0000000000000000000000000000000000000000 --- a/src/system/variablestepdglsystemsolver.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * variablestepdglsystemsolver.cpp - * - * Created on: 06.01.2014 - * Author: chris - */ - -// STD -#ifdef __EXCEPTIONS__ -#include <stdexcept> -#include <string> -#endif /* __EXCEPTIONS__ */ - -// ETC -#include "../exceptions/error_proto.h" -#include "variablestepdglsystemsolver.h" -#ifndef _DS1006 -namespace systm -{ -#ifdef _ARMADILLO_ - -VariableStepDglSystemSolver< arma::Mat< double > >::VariableStepDglSystemSolver( StateSystemGroup< arma::Mat< double > >* stateSystemGroup ) - : SystemSolver< arma::Mat< double > >( stateSystemGroup, 0.0001 ) - , daeSystem( new systm::DifferentialAlgebraicSystem< arma::Mat< double > >( stateSystemGroup ) ) - , mStepper( make_controlled( 1.0e-10, 1.0e-10, boost::numeric::odeint::runge_kutta_cash_karp54< arma::Mat< double > >() ) ) -{ -} - -double VariableStepDglSystemSolver< arma::Mat< double > >::Solve() -{ - bool successfull = false; - - daeSystem->PrepareEquationSystem(); - - for ( size_t tries = SOLVER_TRIES; tries > 0 && !successfull; --tries ) - { - arma::Mat< double > states = this->mStateVector.submat( 0, 0, this->mStateVector.n_rows - 2, 0 ); - successfull = ( mStepper.try_step( boost::ref( *daeSystem ), states, mTime, mDt ) == boost::numeric::odeint::success ); - this->mStateVector.submat( 0, 0, this->mStateVector.n_rows - 2, 0 ) = states; - } - - if ( !successfull ) - ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, "ErrorStep" ); - - this->ResetStateSystemGroup(); - - return mTime; -} - -VariableStepDglSystemSolver< arma::SpMat< double > >::VariableStepDglSystemSolver( StateSystemGroup< arma::SpMat< double > >* stateSystemGroup ) - : SystemSolver< arma::SpMat< double > >( stateSystemGroup, 0.0001 ) - , daeSystem( new systm::DifferentialAlgebraicSystem< arma::SpMat< double > >( stateSystemGroup ) ) - , mStepper( make_controlled( 1.0e-10, 1.0e-10, boost::numeric::odeint::runge_kutta_cash_karp54< arma::Mat< double > >() ) ) -{ - mDenseStateVector.zeros( stateSystemGroup->GetStateCount(), 1 ); -} - -double VariableStepDglSystemSolver< arma::SpMat< double > >::Solve() -{ - bool successfull = false; - - daeSystem->PrepareEquationSystem(); - - for ( size_t row = 0; row < mDenseStateVector.n_rows; ++row ) - mDenseStateVector( row, 0 ) = this->mStateVector( row, 0 ); - - for ( size_t tries = SOLVER_TRIES; tries > 0 && !successfull; --tries ) - { - successfull = - ( mStepper.try_step( boost::ref( *daeSystem ), mDenseStateVector, mTime, mDt ) == boost::numeric::odeint::success ); - } - - for ( size_t row = 0; row < mDenseStateVector.n_rows; ++row ) - this->mStateVector( row, 0 ) = mDenseStateVector( row, 0 ); - - if ( !successfull ) - ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, "ErrorStep" ); - - this->ResetStateSystemGroup(); - - return mTime; -} - -#endif /* _ARMADILLO_ */ - -#ifdef _EIGEN_ - -VariableStepDglSystemSolver< Eigen::SparseMatrix< double, Eigen::RowMajor > >::VariableStepDglSystemSolver( - StateSystemGroup< Eigen::SparseMatrix< double, Eigen::RowMajor > >* stateSystemGroup ) - : SystemSolver< Eigen::SparseMatrix< double, Eigen::RowMajor > >( stateSystemGroup, 0.0001 ) - , daeSystem( new systm::DifferentialAlgebraicSystem< Eigen::SparseMatrix< double, Eigen::RowMajor > >( stateSystemGroup ) ) - , mStepper( make_controlled( 1.0e-10, 1.0e-10, boost::numeric::odeint::runge_kutta_cash_karp54< arma::Mat< double > >() ) ) -{ -} - -double VariableStepDglSystemSolver< Eigen::SparseMatrix< double, Eigen::RowMajor > >::Solve() -{ - bool successfull = false; - - daeSystem->PrepareEquationSystem(); - - size_t realStates = this->mStateVector.rows() - 1; // TODO: Uncomment when one is concatenated to state vector - - // MatrixXd x = this->mStateVector.topRows(realStates); - arma::Mat< double > x( realStates, 1 ); - for ( size_t i = 0; i < realStates; ++i ) - x( i, 0 ) = this->mStateVector.coeff( i, 0 ); - - for ( size_t tries = SOLVER_TRIES; tries > 0 && !successfull; --tries ) - { - successfull = ( mStepper.try_step( boost::ref( *daeSystem ), x, mTime, mDt ) == boost::numeric::odeint::success ); - } - - for ( size_t i = 0; i < realStates; ++i ) - this->mStateVector.coeffRef( i, 0 ) = x( i, 0 ); - - this->mStateVector.coeffRef( realStates, 0 ) = 1; // TODO: Uncomment when one is concatenated to state vector - - if ( !successfull ) - ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, "ErrorStep" ); - - this->ResetStateSystemGroup(); - - return mTime; -} - -#endif /* _EIGEN_ */ - -} /* namespace systm */ -#endif /* _DS1006 */ diff --git a/src/system/variablestepdglsystemsolver.cpp_bck b/src/system/variablestepdglsystemsolver.cpp_bck new file mode 100644 index 0000000000000000000000000000000000000000..b229b103a2c5a2820f4c29f9e54ef4ece45c3df6 --- /dev/null +++ b/src/system/variablestepdglsystemsolver.cpp_bck @@ -0,0 +1,66 @@ +/* + * variablestepdglsystemsolver.cpp + * + * Created on: 06.01.2014 + * Author: chris + */ + +// STD +#ifdef __EXCEPTIONS__ +#include <stdexcept> +#include <string> +#endif /* __EXCEPTIONS__ */ + +// ETC +#include "../exceptions/error_proto.h" +#include "variablestepdglsystemsolver.h_bck" +#ifndef _DS1006 +namespace systm +{ + + +#ifdef _EIGEN_ + +VariableStepDglSystemSolver< Eigen::SparseMatrix< double, Eigen::RowMajor > >::VariableStepDglSystemSolver( + StateSystemGroup< Eigen::SparseMatrix< double, Eigen::RowMajor > >* stateSystemGroup ) + : SystemSolver< Eigen::SparseMatrix< double, Eigen::RowMajor > >( stateSystemGroup, 0.0001 ) + , daeSystem( new systm::DifferentialAlgebraicSystem< Eigen::SparseMatrix< double, Eigen::RowMajor > >( stateSystemGroup ) ) + , mStepper( make_controlled( 1.0e-10, 1.0e-10, boost::numeric::odeint::runge_kutta_cash_karp54< arma::Mat< double > >() ) ) +{ +} + +double VariableStepDglSystemSolver< Eigen::SparseMatrix< double, Eigen::RowMajor > >::Solve() +{ + bool successfull = false; + + daeSystem->PrepareEquationSystem(); + + size_t realStates = this->mStateVector.rows() - 1; // TODO: Uncomment when one is concatenated to state vector + + // MatrixXd x = this->mStateVector.topRows(realStates); + arma::Mat< double > x( realStates, 1 ); + for ( size_t i = 0; i < realStates; ++i ) + x( i, 0 ) = this->mStateVector.coeff( i, 0 ); + + for ( size_t tries = SOLVER_TRIES; tries > 0 && !successfull; --tries ) + { + successfull = ( mStepper.try_step( boost::ref( *daeSystem ), x, mTime, mDt ) == boost::numeric::odeint::success ); + } + + for ( size_t i = 0; i < realStates; ++i ) + this->mStateVector.coeffRef( i, 0 ) = x( i, 0 ); + + this->mStateVector.coeffRef( realStates, 0 ) = 1; // TODO: Uncomment when one is concatenated to state vector + + if ( !successfull ) + ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, "ErrorStep" ); + + this->ResetStateSystemGroup(); + + return mTime; +} + +#endif /* _EIGEN_ */ + +} /* namespace systm */ +#endif /* _DS1006 */ diff --git a/src/system/variablestepdglsystemsolver.h b/src/system/variablestepdglsystemsolver.h_bck similarity index 63% rename from src/system/variablestepdglsystemsolver.h rename to src/system/variablestepdglsystemsolver.h_bck index 2b27a7f39ab6d6353dc7ce0551925debb8d6facd..a78ee778d449cec2ec1eca3a230f2e64edb49f90 100644 --- a/src/system/variablestepdglsystemsolver.h +++ b/src/system/variablestepdglsystemsolver.h_bck @@ -52,42 +52,7 @@ VariableStepDglSystemSolver< T >::VariableStepDglSystemSolver( StateSystemGroup< ErrorFunction< std::runtime_error >( __FUNCTION__, __LINE__, __FILE__, "OnlyArmadillo" ); } -#ifdef _ARMADILLO_ -/// Solver with variable dt -template <> -class VariableStepDglSystemSolver< arma::Mat< double > > : public SystemSolver< arma::Mat< double > > -{ - public: - VariableStepDglSystemSolver( StateSystemGroup< arma::Mat< double > >* stateSystemGroup ); - - virtual ~VariableStepDglSystemSolver() {} - - virtual double Solve(); - - private: - boost::scoped_ptr< systm::DifferentialAlgebraicSystem< arma::Mat< double > > > daeSystem; - boost::numeric::odeint::result_of::make_controlled< boost::numeric::odeint::runge_kutta_cash_karp54< arma::Mat< double > > >::type mStepper; -}; - -/// Solver with variable dt -template <> -class VariableStepDglSystemSolver< arma::SpMat< double > > : public SystemSolver< arma::SpMat< double > > -{ - public: - VariableStepDglSystemSolver( StateSystemGroup< arma::SpMat< double > >* stateSystemGroup ); - - virtual ~VariableStepDglSystemSolver() {} - - virtual double Solve(); - - private: - boost::scoped_ptr< systm::DifferentialAlgebraicSystem< arma::SpMat< double > > > daeSystem; - boost::numeric::odeint::result_of::make_controlled< boost::numeric::odeint::runge_kutta_cash_karp54< arma::Mat< double > > >::type mStepper; - arma::Mat< double > mDenseStateVector; -}; - -#endif /* _ARMADILLO_ */ #ifdef _EIGEN_ template <> diff --git a/src/thermal/ode_system_thermal.h b/src/thermal/ode_system_thermal.h index f9be9a90f042557211527ecb0be294ecf4970fa7..88cf1848c161620167cbce217dc7d8adff582990 100644 --- a/src/thermal/ode_system_thermal.h +++ b/src/thermal/ode_system_thermal.h @@ -12,7 +12,7 @@ #include <map> #include <vector> -#include <eigen3/Eigen/Sparse> +#include <Eigen/Sparse> class TestOdeSystemThermal; class TestSimulation; diff --git a/src/threading/serialization/armadilloMatrix.h b/src/threading/serialization/armadilloMatrix.h deleted file mode 100644 index e7b2530a74fc2cc82b6e71fdd599a65b2ace18e6..0000000000000000000000000000000000000000 --- a/src/threading/serialization/armadilloMatrix.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * armadilloMatrix.h - * - * Created on: 22.11.2013 - * Author: chris - */ - -#ifndef ARMADILLOMATRIX_H_ -#define ARMADILLOMATRIX_H_ - -#ifdef _ARMADILLO_ -#include "../../misc/matrixInclude.h" - -#include <boost/serialization/split_free.hpp> -#include <boost/serialization/string.hpp> - -#include <sstream> -#include <boost/iostreams/filtering_streambuf.hpp> -#include <boost/iostreams/copy.hpp> -#include <boost/iostreams/filter/zlib.hpp> - - - -namespace boost { -namespace serialization { - -template<class Archive> -void save(Archive & ar, const arma::Mat<double> & t, unsigned int /* version */) -{ - std::stringstream decompressed; - - arma::SpMat<double> sparseMatrix(t); - - sparseMatrix.quiet_save(decompressed); - -#ifdef USE_ZLIB - std::stringstream compressed; - boost::iostreams::filtering_streambuf<boost::iostreams::input> out; - out.push(boost::iostreams::zlib_compressor()); - out.push(decompressed); - boost::iostreams::copy(out, compressed); - - std::string mystring(compressed.str()); -#else - std::string mystring(decompressed.str()); -#endif - - ar << mystring; -} - -template<class Archive> -void load(Archive & ar, arma::Mat<double> & t, unsigned int /* version */) -{ - std::string mystring; - ar >> mystring; - -#ifdef USE_ZLIB - std::stringstream compressed(mystring); - std::stringstream decompressed; - - boost::iostreams::filtering_streambuf<boost::iostreams::input> out; - out.push(boost::iostreams::zlib_decompressor()); - out.push(compressed); - boost::iostreams::copy(out, decompressed); -#else - std::stringstream decompressed(mystring); -#endif - - arma::SpMat<double> sparseMatrix; - sparseMatrix.quiet_load(decompressed); - - t = sparseMatrix; -} - -template<class Archive> -void save(Archive & ar, const arma::sp_mat & t, unsigned int /* version */) -{ - std::stringstream decompressed; - - t.quiet_save(decompressed); - -#ifdef USE_ZLIB - std::stringstream compressed; - boost::iostreams::filtering_streambuf<boost::iostreams::input> out; - out.push(boost::iostreams::zlib_compressor()); - out.push(decompressed); - boost::iostreams::copy(out, compressed); - - std::string mystring(compressed.str()); -#else - std::string mystring(decompressed.str()); -#endif - - ar << mystring; -} - -template<class Archive> -void load(Archive & ar, arma::sp_mat & t, unsigned int /* version */) -{ - std::string mystring; - ar >> mystring; - -#ifdef USE_ZLIB - std::stringstream compressed(mystring); - std::stringstream decompressed; - - boost::iostreams::filtering_streambuf<boost::iostreams::input> out; - out.push(boost::iostreams::zlib_decompressor()); - out.push(compressed); - boost::iostreams::copy(out, decompressed); -#else - std::stringstream decompressed(mystring); -#endif - - t.quiet_load(decompressed); -} - -} } - -BOOST_SERIALIZATION_SPLIT_FREE(arma::Mat<double>) -BOOST_SERIALIZATION_SPLIT_FREE(arma::sp_mat) - - -#endif - -#endif //ARMADILLOMATRIX_H_ diff --git a/src/threading/tasks/daetask/daeInputData.h b/src/threading/tasks/daetask/daeInputData.h index 7b612e94abf80c2045fa63ceb5c5e1e2c043fb7f..043ae3be023912a76d36261bb25b3572b28222ff 100644 --- a/src/threading/tasks/daetask/daeInputData.h +++ b/src/threading/tasks/daetask/daeInputData.h @@ -16,7 +16,6 @@ #include <boost/serialization/split_free.hpp> #include <boost/serialization/string.hpp> -#include "../../serialization/armadilloMatrix.h" #include "../../serialization/matlabMatrix.h" namespace threading { namespace daetask diff --git a/src/threading/tasks/daetask/daeOutputData.h b/src/threading/tasks/daetask/daeOutputData.h index 431e6e418259f7a50b0d0292b149a6fe55d5e789..7104cff18bdc115c1118e58ea8870f033d189519 100644 --- a/src/threading/tasks/daetask/daeOutputData.h +++ b/src/threading/tasks/daetask/daeOutputData.h @@ -11,7 +11,6 @@ #include "../../taskData.h" #include "../../../misc/matrixInclude.h" #include <boost/shared_ptr.hpp> -#include "../../serialization/armadilloMatrix.h" #include <boost/serialization/vector.hpp> diff --git a/src/time_series/eval_linear_interpolation.h b/src/time_series/eval_linear_interpolation.h index 8793c1bbe29067fac5ceb9f2d88e04e2cf97e42b..ea8ecf5f0736210ee2215f73fefda62feec0e431 100644 --- a/src/time_series/eval_linear_interpolation.h +++ b/src/time_series/eval_linear_interpolation.h @@ -1,68 +1,75 @@ #ifndef _EVAL_LINEAR_INTERPOLATION_ #define _EVAL_LINEAR_INTERPOLATION_ -#include <vector> -#include <limits> +#ifdef max +#pragma push_macro( "max" ) +#undef max +#define RESTORE_MAX_MACRO +#endif + #include <cmath> +#include <limits> +#include <vector> -class TestTimeSeries; +class TestTimeSeries; namespace electrical { - using std::vector; +using std::vector; -template<typename T = double> +template < typename T = double > class EvalLinearInterpolation { -friend class ::TestTimeSeries; + friend class ::TestTimeSeries; -public: - inline void CalculateValue(bool hasIndexChanged, const vector<T> ×Data, const vector<T> &valuesData - , const T &time, const size_t &index, T &value) + public: + inline void CalculateValue( bool hasIndexChanged, const vector< T > ×Data, const vector< T > &valuesData, + const T &time, const size_t &index, T &value ) { - if(hasIndexChanged) - CalculateOffsetSlope(timesData, valuesData, index, mOffset, mSlope); + if ( hasIndexChanged ) + CalculateOffsetSlope( timesData, valuesData, index, mOffset, mSlope ); value = mOffset + mSlope * time; } - inline T GetTimeUntilMaxValueDeviation(const vector<T> ×Data, const vector<T> &valuesData - , const T &time, const T &value, const size_t &index, const T& maxDeltaValue) const + inline T GetTimeUntilMaxValueDeviation( const vector< T > ×Data, const vector< T > &valuesData, const T &time, + const T &value, const size_t &index, const T &maxDeltaValue ) const { - for(size_t maxDeviationIndex = index; maxDeviationIndex < timesData.size() - 1; ++maxDeviationIndex) + for ( size_t maxDeviationIndex = index; maxDeviationIndex < timesData.size() - 1; ++maxDeviationIndex ) { - if(fabs(valuesData[maxDeviationIndex + 1] - value) > maxDeltaValue) + if ( fabs( valuesData[maxDeviationIndex + 1] - value ) > maxDeltaValue ) { T slope, offset; - if(maxDeviationIndex == index) + if ( maxDeviationIndex == index ) { offset = mOffset; slope = mSlope; } else - CalculateOffsetSlope(timesData, valuesData, maxDeviationIndex, offset, slope); + CalculateOffsetSlope( timesData, valuesData, maxDeviationIndex, offset, slope ); - T timeUntilMaxDeltaValue = (value + maxDeltaValue - offset) / slope; - if(timeUntilMaxDeltaValue < timesData[maxDeviationIndex] - || timeUntilMaxDeltaValue > timesData[maxDeviationIndex + 1] - || timeUntilMaxDeltaValue < time) - timeUntilMaxDeltaValue = (value - maxDeltaValue - offset) / slope; + T timeUntilMaxDeltaValue = ( value + maxDeltaValue - offset ) / slope; + if ( timeUntilMaxDeltaValue < timesData[maxDeviationIndex] || + timeUntilMaxDeltaValue > timesData[maxDeviationIndex + 1] || timeUntilMaxDeltaValue < time ) + timeUntilMaxDeltaValue = ( value - maxDeltaValue - offset ) / slope; return timeUntilMaxDeltaValue; } } - return std::numeric_limits<T>::max(); + return std::numeric_limits< T >::max(); } -private: - void CalculateOffsetSlope(const vector<T> ×Data, const vector<T> &valuesData, const size_t &index, T &offset, T &slope) const + + private: + void CalculateOffsetSlope( const vector< T > ×Data, const vector< T > &valuesData, const size_t &index, + T &offset, T &slope ) const { - if(index + 1 == timesData.size()) + if ( index + 1 == timesData.size() ) { slope = 0.0; offset = valuesData[index]; } else { - slope = (valuesData[index+1] - valuesData[index]) / (timesData[index+1] - timesData[index]); + slope = ( valuesData[index + 1] - valuesData[index] ) / ( timesData[index + 1] - timesData[index] ); offset = valuesData[index] - timesData[index] * slope; } } @@ -70,5 +77,11 @@ private: T mSlope; }; -} //namespace -#endif //Include guard +} // namespace electrical + +#ifdef RESTORE_MAX_MACRO +#pragma pop_macro( "size" ) +#undef RESTORE_MAX_MACRO +#endif + +#endif // Include guard diff --git a/src/time_series/eval_no_interpolation.h b/src/time_series/eval_no_interpolation.h index 8c2a96b2f1f9be383803b88062b1aa110dac0b7b..695a5f504bdf98432cc1e52e79b33f30d64a00f7 100644 --- a/src/time_series/eval_no_interpolation.h +++ b/src/time_series/eval_no_interpolation.h @@ -1,43 +1,46 @@ #ifndef _EVAL_NO_INTERPOLATION_ #define _EVAL_NO_INTERPOLATION_ -#include <vector> -#include <limits> #include <cmath> +#include <limits> +#include <vector> +#ifdef max +#pragma push_macro( "max" ) +#undef max +#define RESTORE_MAX_MACRO +#endif namespace electrical { - using std::vector; +using std::vector; -template<typename T = double> +template < typename T = double > class EvalNoInterpolation { -public: - inline void CalculateValue(bool hasIndexChanged - , const vector<T> & - , const vector<T> &valuesData - , const T & - , const size_t &index - , T &value) + public: + inline void CalculateValue( bool hasIndexChanged, const vector< T > &, const vector< T > &valuesData, const T &, + const size_t &index, T &value ) { - if(hasIndexChanged) + if ( hasIndexChanged ) value = valuesData[index]; } - inline T GetTimeUntilMaxValueDeviation(const vector<T> ×Data - , const vector<T> &valuesData - , const T & - , const T &value - , const size_t &index - , const T& maxDeltaValue) const + inline T GetTimeUntilMaxValueDeviation( const vector< T > ×Data, const vector< T > &valuesData, const T &, + const T &value, const size_t &index, const T &maxDeltaValue ) const { - for(size_t maxDeviationIndex = index + 1; maxDeviationIndex < timesData.size(); ++maxDeviationIndex) - if(fabs(valuesData[maxDeviationIndex] - value) >= maxDeltaValue) + for ( size_t maxDeviationIndex = index + 1; maxDeviationIndex < timesData.size(); ++maxDeviationIndex ) + if ( fabs( valuesData[maxDeviationIndex] - value ) >= maxDeltaValue ) return timesData[maxDeviationIndex]; - return std::numeric_limits<T>::max(); + return std::numeric_limits< T >::max(); } }; -} //namespace -#endif //Include guard \ No newline at end of file +} // namespace electrical + +#ifdef RESTORE_MAX_MACRO +#pragma pop_macro( "size" ) +#undef RESTORE_MAX_MACRO +#endif + +#endif // Include guard \ No newline at end of file diff --git a/src/unittests/CMakeLists.txt b/src/unittests/CMakeLists.txt index 60ccf16916179008bfb176fd17fa001a402be324..6b48640daac3aba15c5d43e9457a86dafc4d5be9 100644 --- a/src/unittests/CMakeLists.txt +++ b/src/unittests/CMakeLists.txt @@ -2,8 +2,8 @@ option(BUILD_UNITTESTS "Build all unittests" ON) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/unittest) if(BUILD_UNITTESTS) - find_package(CxxTest) - find_package(MATIO REQUIRED) + find_package(CxxTest REQUIRED) + find_package(matio REQUIRED) add_custom_target(unittests) # find all header files to pass to the test generator diff --git a/src/unittests/aging/TestAnodeOverhang.cpp b/src/unittests/aging/TestAnodeOverhang.cpp index 85ea97d4f9495856727c33a6b31f11bcef8fbdf6..448f393be35f36b334600119d8ac5b8c3ac84b7a 100644 --- a/src/unittests/aging/TestAnodeOverhang.cpp +++ b/src/unittests/aging/TestAnodeOverhang.cpp @@ -9,25 +9,26 @@ void TestAnodeOverhang::testNoAging() auto thermalState = boost::make_shared< state::ThermalState< double > >( 20.0 ); aging::TwoportState tpState( electricalData, socState, thermalState ); auto voltageObj = boost::make_shared< object::ConstObj< double > >( 3.0 ); + auto dvaObj = boost::make_shared< object::ConstObj< double > >( 0.3 ); auto overhangSoc = boost::make_shared< state::Soc >( 3.0, 3.0, 50.0 ); double tauCoef = 5.0; double activCoef = 2.3; { // aging is disabled - aging::AnodeOverhang aging( 10.0, voltageObj, activCoef, tauCoef, overhangSoc, 60.0, false ); + aging::AnodeOverhang aging( 10.0, voltageObj, dvaObj, activCoef, tauCoef, overhangSoc, 60.0, false ); aging.CalculateAging( tpState, 10.0, 1.0 ); TS_ASSERT_EQUALS( aging.GetCapacityFactor(), 1.0 ); TS_ASSERT_EQUALS( aging.GetSocOffset(), 0.0 ); TS_ASSERT_EQUALS( aging.GetResistanceFactor(), 1.0 ); } { // no aging data collected - aging::AnodeOverhang aging( 10.0, voltageObj, activCoef, tauCoef, overhangSoc, 50.0, true ); + aging::AnodeOverhang aging( 10.0, voltageObj, dvaObj, activCoef, tauCoef, overhangSoc, 50.0, true ); aging.CalculateAging( tpState, 10.0, 1.0 ); TS_ASSERT_EQUALS( aging.GetCapacityFactor(), 1.0 ); TS_ASSERT_EQUALS( aging.GetSocOffset(), 0.0 ); TS_ASSERT_EQUALS( aging.GetResistanceFactor(), 1.0 ); } { // anode and overhang have the same voltage - aging::AnodeOverhang aging( 10.0, voltageObj, activCoef, tauCoef, overhangSoc, 50.0, true ); + aging::AnodeOverhang aging( 10.0, voltageObj, dvaObj, activCoef, tauCoef, overhangSoc, 50.0, true ); aging.CollectData( tpState, tpState, 10.0 ); aging.CalculateAging( tpState, 10.0, 1.0 ); TS_ASSERT_EQUALS( aging.GetCapacityFactor(), 1.0 ); @@ -42,10 +43,12 @@ void TestAnodeOverhang::testInitialOffset() double initialSoc = 60.0; double overhangCapacity = 3.0; auto voltageObj = boost::make_shared< object::ConstObj< double > >( 3.0 ); + auto dvaObj = boost::make_shared< object::ConstObj< double > >( 0.3 ); + auto overhangSoc = boost::make_shared< state::Soc >( overhangCapacity, overhangCapacity, initialSoc ); double tauCoef = 5.0; double activCoef = 2.3; - aging::AnodeOverhang aging( 10.0, voltageObj, activCoef, tauCoef, overhangSoc, socWithoutOffset, true ); + aging::AnodeOverhang aging( 10.0, voltageObj, dvaObj, activCoef, tauCoef, overhangSoc, socWithoutOffset, true ); TS_ASSERT_EQUALS( aging.GetCapacityFactor(), 1.0 ); TS_ASSERT_DELTA( aging.GetSocOffset(), ( socWithoutOffset - initialSoc ) / 100 * overhangCapacity * 3600, 1.0e-5 ); TS_ASSERT_EQUALS( aging.GetResistanceFactor(), 1.0 ); @@ -57,11 +60,12 @@ void TestAnodeOverhang::testAgingCalculation() double initialSoc = 60.0; double overhangCapacity = 3.0; auto voltageObj = boost::make_shared< object::ConstObj< double > >( 3.0 ); + auto dvaObj = boost::make_shared< object::ConstObj< double > >( 0.3 ); auto overhangSoc = boost::make_shared< state::Soc >( overhangCapacity, overhangCapacity, initialSoc ); double tauCoef = 5.0; double activCoef = 2.3; double offset = ( socWithoutOffset - initialSoc ) / 100 * overhangCapacity * 3600; - aging::AnodeOverhang aging( 10.0, voltageObj, activCoef, tauCoef, overhangSoc, socWithoutOffset, true ); + aging::AnodeOverhang aging( 10.0, voltageObj, dvaObj, activCoef, tauCoef, overhangSoc, socWithoutOffset, true ); auto electricalData = boost::make_shared< ElectricalDataStruct< double > >( 1.0, -2.7, 0.5 ); auto socState = boost::make_shared< state::Soc >( 10.0, 10.0, 50.0 ); @@ -77,11 +81,11 @@ void TestAnodeOverhang::testAgingCalculation() double avgTemp = ( 20.0 * 3.0 + 23.0 * 6.2 ) / ( 3.0 + 6.2 ) + 273.15; double avgVoltage = ( 2.7 * 3.0 + 2.1 * 6.2 ) / ( 3.0 + 6.2 ); double tau = tauCoef * std::exp( activCoef / avgTemp ) * 3600 * 24; - double overhangCap = ( initialSoc / 100 ) * ( overhangCapacity * 3600 ) / voltageObj->GetValue(); - offset += overhangCap * ( avgVoltage - voltageObj->GetValue() ) * ( 1 - exp( -10.0 * 3600 * 24 / tau ) ); + double capacitance = 1 / ( dvaObj->GetValue() * socState->GetActualCapacity< state::SocGetFormat::AS >() ); + offset += capacitance * ( avgVoltage - voltageObj->GetValue() ) * ( 1 - exp( -10.0 * 3600 * 24 / tau ) ); TS_ASSERT_EQUALS( aging.GetCapacityFactor(), 1.0 ); - TS_ASSERT_DELTA( aging.GetSocOffset(), offset, 1.0e-5 ); + TS_ASSERT_DELTA( aging.GetSocOffset(), offset, 1.0e-3 ); TS_ASSERT_EQUALS( aging.GetResistanceFactor(), 1.0 ); } @@ -91,11 +95,13 @@ void TestAnodeOverhang::testReset() double initialSoc = 60.0; double overhangCapacity = 3.0; auto voltageObj = boost::make_shared< object::ConstObj< double > >( 3.0 ); + auto dvaObj = boost::make_shared< object::ConstObj< double > >( 0.3 ); + auto overhangSoc = boost::make_shared< state::Soc >( overhangCapacity, overhangCapacity, initialSoc ); double tauCoef = 5.0; double activCoef = 2.3; double offset = ( socWithoutOffset - initialSoc ) / 100 * overhangCapacity * 3600; - aging::AnodeOverhang aging( 10.0, voltageObj, activCoef, tauCoef, overhangSoc, socWithoutOffset, true ); + aging::AnodeOverhang aging( 10.0, voltageObj, dvaObj, activCoef, tauCoef, overhangSoc, socWithoutOffset, true ); auto electricalData = boost::make_shared< ElectricalDataStruct< double > >( 1.0, -2.7, 0.5 ); auto socState = boost::make_shared< state::Soc >( 10.0, 10.0, 50.0 ); @@ -123,10 +129,10 @@ void TestAnodeOverhang::testReset() double avgTemp = ( 20.0 * 3.0 + 23.0 * 6.2 ) / ( 3.0 + 6.2 ) + 273.15; double avgVoltage = ( 2.7 * 3.0 + 2.1 * 6.2 ) / ( 3.0 + 6.2 ); double tau = tauCoef * std::exp( activCoef / avgTemp ) * 3600 * 24; - double overhangCap = ( initialSoc / 100 ) * ( overhangCapacity * 3600 ) / voltageObj->GetValue(); - offset += overhangCap * ( avgVoltage - voltageObj->GetValue() ) * ( 1 - exp( -10.0 * 3600 * 24 / tau ) ); + double capacitance = 1 / ( dvaObj->GetValue() * socState->GetActualCapacity< state::SocGetFormat::AS >() ); + offset += capacitance * ( avgVoltage - voltageObj->GetValue() ) * ( 1 - exp( -10.0 * 3600 * 24 / tau ) ); TS_ASSERT_EQUALS( aging.GetCapacityFactor(), 1.0 ); - TS_ASSERT_DELTA( aging.GetSocOffset(), offset, 1.0e-5 ); + TS_ASSERT_DELTA( aging.GetSocOffset(), offset, 1.0e-3 ); TS_ASSERT_EQUALS( aging.GetResistanceFactor(), 1.0 ); } \ No newline at end of file diff --git a/src/unittests/aging/TestCalendarianAging.cpp b/src/unittests/aging/TestCalendarianAging.cpp index 3db9ff62bc894f0b2c2fe668301ed02da2b79ade..f1e27e2f5b3140cbe5494b7af76cc2e259d892b7 100644 --- a/src/unittests/aging/TestCalendarianAging.cpp +++ b/src/unittests/aging/TestCalendarianAging.cpp @@ -144,10 +144,10 @@ void TestCalendarianAging::testReset() void TestCalendarianAging::testFormulaVariables() { double voltage = 3.5; - double soc = 0.73; + double soc = 73; // [%] double temperature = 300.0; // [K] auto electricalData = boost::make_shared< ElectricalDataStruct< double > >( 0, voltage, 0 ); - auto socState = boost::make_shared< state::Soc >( 1.0, 1.0, soc * 100 ); + auto socState = boost::make_shared< state::Soc >( 1.0, 1.0, soc ); auto thermalState = boost::make_shared< state::ThermalState< double > >( temperature - 273.15 ); aging::TwoportState tpState( electricalData, socState, thermalState ); auto voltageValueState = boost::make_shared< state::ValueStateWrapper< double > >( nullptr ); diff --git a/src/unittests/aging/TestCyclicalAging.cpp b/src/unittests/aging/TestCyclicalAging.cpp index c86f40f6c013c3b243e3b6e8fce13b5f8a1b068b..5731820a2f8aec29aa62078f1e805f9c5bef8ee6 100644 --- a/src/unittests/aging/TestCyclicalAging.cpp +++ b/src/unittests/aging/TestCyclicalAging.cpp @@ -13,7 +13,7 @@ void TestCyclicalAging::testNoAging() std::vector< typename object::ExpressionObject< double >::Parameter > objParams; const auto obj = boost::make_shared< object::ExpressionObject< double > >( "0.0001", objParams ); { // calculation time of zero seconds - aging::CyclicalAging aging( 10, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, true, 1, 1 ); + aging::CyclicalAging aging( 10, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, true, 1, 1, "Ah" ); aging.CalculateAging( tpState, 3.0, 1.0 ); TS_ASSERT_EQUALS( aging.GetCapacityFactor(), 1.0 ); TS_ASSERT_EQUALS( aging.GetSocOffset(), 0.0 ); @@ -27,7 +27,7 @@ void TestCyclicalAging::testNoAging() TS_ASSERT_EQUALS( aging.GetResistanceFactor(), 1.0 ); } { // aging disabled - aging::CyclicalAging aging( 10, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, false, 1, 1 ); + aging::CyclicalAging aging( 10, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, false, 1, 1, "Ah" ); aging.CollectData( tpState, tpState, 10 ); aging.CalculateAging( tpState, 3.0, 1.0 ); @@ -58,10 +58,10 @@ void TestCyclicalAging::testAgingCalculation() { "meanV", voltageValueState }, { "meanSOC", socValueState }, { "meanI", currentValueState } }; - const auto objCap = boost::make_shared< object::ExpressionObject< double > >( "0.0001 * (meanV + deltaDOD)", objParams ); - const auto objRes = boost::make_shared< object::ExpressionObject< double > >( "0.00015 * (meanV + deltaDOD)", objParams ); + const auto objCap = boost::make_shared< object::ExpressionObject< double > >( "0.0001 * meanV + 0.000001 * deltaDOD", objParams ); + const auto objRes = boost::make_shared< object::ExpressionObject< double > >( "0.00015 * meanV + 0.0000015 * deltaDOD", objParams ); - aging::CyclicalAging aging( steptime, 0, 0, 1e3, 1e3, objCap, objRes, initialCap, initialRes, true, exponentCap, exponentRes ); + aging::CyclicalAging aging( steptime, 0, 0, 1e3, 1e3, objCap, objRes, initialCap, initialRes, true, exponentCap, exponentRes, "Ah" ); *dodValueState = state::ValueStateWrapper< double >( &aging.mActualDod ); *voltageValueState = state::ValueStateWrapper< double >( &aging.mActualVoltage ); *socValueState = state::ValueStateWrapper< double >( &aging.mActualSoc ); @@ -111,10 +111,10 @@ void TestCyclicalAging::testReset() { "meanV", voltageValueState }, { "meanSOC", socValueState }, { "meanI", currentValueState } }; - const auto objCap = boost::make_shared< object::ExpressionObject< double > >( "0.0001 * (meanV + deltaDOD)", objParams ); - const auto objRes = boost::make_shared< object::ExpressionObject< double > >( "0.00015 * (meanV + deltaDOD)", objParams ); + const auto objCap = boost::make_shared< object::ExpressionObject< double > >( "0.0001 * meanV + 0.000001 * deltaDOD", objParams ); + const auto objRes = boost::make_shared< object::ExpressionObject< double > >( "0.00015 * meanV + 0.0000015 * deltaDOD", objParams ); - aging::CyclicalAging aging( steptime, 0, 0, 1e3, 1e3, objCap, objRes, initialCap, initialRes, true, exponentCap, exponentRes ); + aging::CyclicalAging aging( steptime, 0, 0, 1e3, 1e3, objCap, objRes, initialCap, initialRes, true, exponentCap, exponentRes, "Ah" ); *dodValueState = state::ValueStateWrapper< double >( &aging.mActualDod ); *voltageValueState = state::ValueStateWrapper< double >( &aging.mActualVoltage ); *socValueState = state::ValueStateWrapper< double >( &aging.mActualSoc ); @@ -155,11 +155,11 @@ void TestCyclicalAging::testReset() void TestCyclicalAging::testFormulaVariables() { double voltage = 3.5; - double soc = 0.73; - double dod = 0.43; + double soc = 73; // [%] + double dod = 43; // [%] double capacity = 3600; // [As] auto electricalData = boost::make_shared< ElectricalDataStruct< double > >( 0, voltage, 0 ); - auto socState = boost::make_shared< state::Soc >( capacity / 3600, capacity / 3600, soc * 100 ); + auto socState = boost::make_shared< state::Soc >( capacity / 3600, capacity / 3600, soc ); auto thermalState = boost::make_shared< state::ThermalState< double > >( 20.0 ); aging::TwoportState tpState( electricalData, socState, thermalState ); auto dodValueState = boost::make_shared< state::ValueStateWrapper< double > >( nullptr ); @@ -172,15 +172,15 @@ void TestCyclicalAging::testFormulaVariables() { "meanI", currentValueState } }; { const auto obj = boost::make_shared< object::ExpressionObject< double > >( "meanV", objParams ); - aging::CyclicalAging aging( 1.0, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, true, 1.0, 1.0 ); + aging::CyclicalAging aging( 1.0, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, true, 1.0, 1.0, "Ah" ); *dodValueState = state::ValueStateWrapper< double >( &aging.mActualDod ); *voltageValueState = state::ValueStateWrapper< double >( &aging.mActualVoltage ); *socValueState = state::ValueStateWrapper< double >( &aging.mActualSoc ); *currentValueState = state::ValueStateWrapper< double >( &aging.mActualCurrent ); aging.CollectData( tpState, tpState, 0.0 ); - socState->SetStoredEnergy< state::SocSetFormat::FACTOR >( soc - dod ); + socState->SetStoredEnergy< state::SocSetFormat::PERCENT >( soc - dod ); aging.CollectData( tpState, tpState, 5.0 ); - socState->SetStoredEnergy< state::SocSetFormat::FACTOR >( soc ); + socState->SetStoredEnergy< state::SocSetFormat::PERCENT >( soc ); aging.CollectData( tpState, tpState, 5.0 ); aging.CalculateAging( tpState, 10.0, 1.0 ); TS_ASSERT_DELTA( aging.GetStressFactorCapacity(), voltage, 1e-6 ); @@ -188,31 +188,31 @@ void TestCyclicalAging::testFormulaVariables() } { const auto obj = boost::make_shared< object::ExpressionObject< double > >( "meanSOC", objParams ); - aging::CyclicalAging aging( 1.0, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, true, 1.0, 1.0 ); + aging::CyclicalAging aging( 1.0, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, true, 1.0, 1.0, "Ah" ); *dodValueState = state::ValueStateWrapper< double >( &aging.mActualDod ); *voltageValueState = state::ValueStateWrapper< double >( &aging.mActualVoltage ); *socValueState = state::ValueStateWrapper< double >( &aging.mActualSoc ); *currentValueState = state::ValueStateWrapper< double >( &aging.mActualCurrent ); - socState->SetStoredEnergy< state::SocSetFormat::FACTOR >( soc + dod / 2 ); + socState->SetStoredEnergy< state::SocSetFormat::PERCENT >( soc + dod / 2 ); aging.CollectData( tpState, tpState, 0.0 ); - socState->SetStoredEnergy< state::SocSetFormat::FACTOR >( soc - dod / 2 ); + socState->SetStoredEnergy< state::SocSetFormat::PERCENT >( soc - dod / 2 ); aging.CollectData( tpState, tpState, 5.0 ); - socState->SetStoredEnergy< state::SocSetFormat::FACTOR >( soc ); + socState->SetStoredEnergy< state::SocSetFormat::PERCENT >( soc ); aging.CalculateAging( tpState, 5.0, 1.0 ); TS_ASSERT_DELTA( aging.GetStressFactorCapacity(), soc, 1e-6 ); TS_ASSERT_DELTA( aging.GetStressFactorResistance(), soc, 1e-6 ); } { const auto obj = boost::make_shared< object::ExpressionObject< double > >( "deltaDOD", objParams ); - aging::CyclicalAging aging( 1.0, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, true, 1.0, 1.0 ); + aging::CyclicalAging aging( 1.0, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, true, 1.0, 1.0, "Ah" ); *dodValueState = state::ValueStateWrapper< double >( &aging.mActualDod ); *voltageValueState = state::ValueStateWrapper< double >( &aging.mActualVoltage ); *socValueState = state::ValueStateWrapper< double >( &aging.mActualSoc ); *currentValueState = state::ValueStateWrapper< double >( &aging.mActualCurrent ); aging.CollectData( tpState, tpState, 0.0 ); - socState->SetStoredEnergy< state::SocSetFormat::FACTOR >( soc - dod ); + socState->SetStoredEnergy< state::SocSetFormat::PERCENT >( soc - dod ); aging.CollectData( tpState, tpState, 5.0 ); - socState->SetStoredEnergy< state::SocSetFormat::FACTOR >( soc ); + socState->SetStoredEnergy< state::SocSetFormat::PERCENT >( soc ); aging.CollectData( tpState, tpState, 5.0 ); aging.CalculateAging( tpState, 10.0, 1.0 ); TS_ASSERT_DELTA( aging.GetStressFactorCapacity(), dod, 1e-6 ); @@ -220,19 +220,19 @@ void TestCyclicalAging::testFormulaVariables() } { const auto obj = boost::make_shared< object::ExpressionObject< double > >( "meanI", objParams ); - aging::CyclicalAging aging( 1.0, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, true, 1.0, 1.0 ); + aging::CyclicalAging aging( 1.0, 0, 0, 1e3, 1e3, obj, obj, 1.0, 1.0, true, 1.0, 1.0, "Ah" ); *dodValueState = state::ValueStateWrapper< double >( &aging.mActualDod ); *voltageValueState = state::ValueStateWrapper< double >( &aging.mActualVoltage ); *socValueState = state::ValueStateWrapper< double >( &aging.mActualSoc ); *currentValueState = state::ValueStateWrapper< double >( &aging.mActualCurrent ); double dt = 5.0; aging.CollectData( tpState, tpState, 0.0 ); - socState->SetStoredEnergy< state::SocSetFormat::FACTOR >( soc - dod ); + socState->SetStoredEnergy< state::SocSetFormat::PERCENT >( soc - dod ); aging.CollectData( tpState, tpState, dt ); - socState->SetStoredEnergy< state::SocSetFormat::FACTOR >( soc ); + socState->SetStoredEnergy< state::SocSetFormat::PERCENT >( soc ); aging.CollectData( tpState, tpState, dt ); aging.CalculateAging( tpState, 10.0, 1.0 ); - double meanI = dod * capacity / dt; + double meanI = dod / 100 * capacity / dt; TS_ASSERT_DELTA( aging.GetStressFactorCapacity(), meanI, 1e-6 ); TS_ASSERT_DELTA( aging.GetStressFactorResistance(), meanI, 1e-6 ); } diff --git a/src/unittests/container/TestArmadillowrap.cpp b/src/unittests/container/TestArmadillowrap.cpp deleted file mode 100644 index 30fdb584d3f078ac658d4d498af2e510d27e3a49..0000000000000000000000000000000000000000 --- a/src/unittests/container/TestArmadillowrap.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -* File Name : TestArmadillowrap.cpp -* Creation Date : 21-02-2014 -* Last Modified : Fr 21 Feb 2014 15:12:17 CET -* Created By : Friedrich Hust -_._._._._._._._._._._._._._._._._._._._._.*/ -#include "TestArmadillowrap.h" - -#ifdef _ARMADILLO_ -#include <armadillo> -#else -#include "../../stub/armadillo.h" -#endif /* _ARMADILLO_ */ - - -void TestContainer::testArma() -{ -#ifdef _ARMADILLO_ - arma::SpMat<double> t(3,3); - t(0,0) = 8; - t(0,1) = 1; - t(0,2) = 6; - t(1,0) = 3; - t(1,1) = 5; - t(1,2) = 7; - t(2,0) = 4; - t(2,1) = 9; - t(2,2) = 2; - - arma::Mat<double> x(3,3); - x(0,0 ) = 8; - x(0,1) = 1; - x(0,2) = 6; - x(1,0) = 3; - x(1,1) = 5; - x(1,2) = 7; - x(2,0) = 4; - x(2,1) = 9; - x(2,2) = 2; - - arma::SpMat<double> result = arma::inv(t) - arma::SpMat<double>(arma::inv(x)); - - for( size_t i = 0 ; i < 3 ; ++i ) - { - for( size_t j=0 ; j<3 ; ++j ) - { - TS_ASSERT_EQUALS(result(i,j), 0); - } - } - // 0.147222 -0.144444 0.063889 - // -0.061111 0.022222 0.105556 - // -0.019444 0.188889 -0.102778 - - t = arma::inv(t); - TS_ASSERT_DELTA( t(0,0),0.147222, 0.00001); - TS_ASSERT_DELTA( t(0,1),-0.144444, 0.00001); - TS_ASSERT_DELTA( t(0,2),0.063889,0.00001); - TS_ASSERT_DELTA( t(1,0),-0.061111,0.00001); - TS_ASSERT_DELTA( t(1,1),0.022222,0.00001); - TS_ASSERT_DELTA( t(1,2),0.105556,0.00001); - TS_ASSERT_DELTA( t(2,0),-0.019444,0.00001); - TS_ASSERT_DELTA( t(2,1),0.188889,0.00001); - TS_ASSERT_DELTA( t(2,2),-0.102778,0.00001); - - t(0,0) = 8; - t(0,1) = 1; - t(0,2) = 6; - t(1,0) = 3; - t(1,1) = 5; - t(1,2) = 7; - t(2,0) = 4; - t(2,1) = 9; - t(2,2) = 2; - - arma::SpMat<double>(b)(3,1); - b(0,0) = 1; - b(1,0) = 2; - b(2,0) = 3; - - - t = arma::solve(t,b); - TS_ASSERT_DELTA(t(0,0), 0.050000, 0.0001); - TS_ASSERT_DELTA(t(1,0), 0.3, 0.0001); - TS_ASSERT_DELTA(t(2,0), 0.05, 0.0001); - - // 0.050000 - // 0.300000 - // 0.050000 - - // testfunct<arma::SpMat<double> > (); - // testfunct<arma::Mat<double> >(); -#endif /* _ARMADILLO_ */ -} - diff --git a/src/unittests/container/TestArmadillowrap.h b/src/unittests/container/TestArmadillowrap.h deleted file mode 100644 index 815ad55639b65f3d10bed5737e11e073ac7b6ba3..0000000000000000000000000000000000000000 --- a/src/unittests/container/TestArmadillowrap.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -* File Name : TestSimuOptions.h -* Creation Date : 11-05-2012 -* Last Modified : Fr 21 Feb 2014 13:06:53 CET -* Created By : Friedrich Hust -_._._._._._._._._._._._._._._._._._._._._.*/ -#ifndef _TESTCONTAINER_ -#define _TESTCONTAINER_ -#include <cxxtest/TestSuite.h> - -#include "../../container/armadillo_wrapper.h" - -template<typename T> -void testfunct() -{ -#ifdef _ARMADILLO_ - T t(2,1), t1(2,1), t2(10,1); - t(0,0) = 1; t(1,0) = 2; - t1(0,0) = 3; t1(0,0) = 4; - for (unsigned i = 5, j = 0; i< 15; ++i) - { - t2(j,0) = i; - ++j; - } - TS_ASSERT_EQUALS( (boost::numeric::odeint::same_size_impl< T, T >().same_size(t,t1)), true); - TS_ASSERT_EQUALS( (boost::numeric::odeint::same_size_impl< T, T >().same_size(t,t2)), false); - - boost::numeric::odeint::resize_impl< T, T >().resize(t,t2); - TS_ASSERT_EQUALS( (boost::numeric::odeint::same_size_impl< T, T >().same_size(t,t2)), true); - TS_ASSERT_EQUALS( (boost::numeric::odeint::same_size_impl< T, T >().same_size(t,t1)), false); - - TS_ASSERT_EQUALS( t(0,0), 1); - TS_ASSERT_EQUALS( t(1,0), 2); - for (unsigned i = 2; i< t.n_rows; ++i) - { - TS_ASSERT_EQUALS( t(i,0), 0); - } - - boost::numeric::odeint::resize_impl< T, T >().resize(t2,t1); - TS_ASSERT_EQUALS( (boost::numeric::odeint::same_size_impl< T, T >().same_size(t2,t1)), true); - TS_ASSERT_EQUALS( (boost::numeric::odeint::same_size_impl< T, T >().same_size(t2,t)), false); - for (unsigned i = 0; i< t2.n_rows; ++i) - { - TS_ASSERT_EQUALS( t2(i,0), i+5); - } -#endif -} - -class TestContainer: public CxxTest::TestSuite -{ -typedef arma::SpMat<double> state_type; -typedef arma::Mat<double> state_type1; -public: - void testArma(); -}; - -#endif /* _TESTCONTAINER_ */ diff --git a/src/unittests/container/TestEigenwrap.cpp b/src/unittests/container/TestEigenwrap.cpp index 082425394b2a866d3bc92fafde1464d5ddb4fc9f..f3bc310237c784ad8d8684440cb90282335f1ab7 100644 --- a/src/unittests/container/TestEigenwrap.cpp +++ b/src/unittests/container/TestEigenwrap.cpp @@ -6,7 +6,7 @@ _._._._._._._._._._._._._._._._._._._._._.*/ #include "TestEigenwrap.h" -#include <eigen3/Eigen/Sparse> +#include <Eigen/Sparse> namespace CxxTest { diff --git a/src/unittests/misc/TestSymbolic.cpp b/src/unittests/misc/TestSymbolic.cpp index 520f572f52d232c0f6bbf36af6017ee18419d9bb..1a9a31abc804f08e963f1ff7b909c54ce090f4b5 100644 --- a/src/unittests/misc/TestSymbolic.cpp +++ b/src/unittests/misc/TestSymbolic.cpp @@ -340,51 +340,73 @@ void TestSymbolic::TestSolve() SymbolicMatrix< OutType > sol = Eigen::solve123( matA, matB ); -// std::cout << "Here is the matrix A:\n" << matA << std::endl; -// std::cout << "Here is the matrix B:\n" << matB << std::endl; -// std::cout << "Here is the solution for coeffRef(0,0):\n" << sol.coeffRef( 0, 0 ) << std::endl; -// std::cout << "Here is the solution for coeffRef(1,0):\n" << sol.coeffRef( 1, 0 ) << std::endl; -// std::cout << "Here is the solution for coeffRef(2,0):\n" << sol.coeffRef( 2, 0 ) << std::endl; + // std::cout << "Here is the matrix A:\n" << matA << std::endl; + // std::cout << "Here is the matrix B:\n" << matB << std::endl; + // std::cout << "Here is the solution for coeffRef(0,0):\n" << sol.coeffRef( 0, 0 ) << std::endl; + // std::cout << "Here is the solution for coeffRef(1,0):\n" << sol.coeffRef( 1, 0 ) << std::endl; + // std::cout << "Here is the solution for coeffRef(2,0):\n" << sol.coeffRef( 2, 0 ) << std::endl; - TS_ASSERT_EQUALS( sol.coeffRef( 0, 0 ), - symbolic::Symbolic< OutType >( "MUL(SUB(SUB(x1,MUL(MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a)))),MUL(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(ADD(h,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,b))),DIV(1.000000,ADD(e,MUL(MUL(d,DIV(1.000000,a)),MUL(-1,b))))))),DIV(1,ADD(ADD(i,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,c))),MUL(MUL(ADD(h,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,b))),DIV(1.000000,ADD(e,MUL(MUL(d,DIV(1.000000,a)),MUL(-1,b))))),MUL(-1,SUB(f,MUL(c,MUL(d,DIV(1.000000,a))))))))),c)),MUL(MUL(SUB(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a)))),MUL(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(ADD(h,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,b))),DIV(1.000000,ADD(e,MUL(MUL(d,DIV(1.000000,a)),MUL(-1,b))))))),DIV(1,ADD(ADD(i,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,c))),MUL(MUL(ADD(h,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,b))),DIV(1.000000,ADD(e,MUL(MUL(d,DIV(1.000000,a)),MUL(-1,b))))),MUL(-1,SUB(f,MUL(c,MUL(d,DIV(1.000000,a))))))))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a)))))),DIV(1,ADD(e,MUL(MUL(d,DIV(1.000000,a)),MUL(-1,b))))),b)),DIV(1,a))" ) ); - TS_ASSERT_EQUALS( sol.coeff( 1, 0 ), - symbolic::Symbolic< OutType >( "MUL(SUB(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a)))),MUL(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(ADD(h,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,b))),DIV(1.000000,ADD(e,MUL(MUL(d,DIV(1.000000,a)),MUL(-1,b))))))),DIV(1,ADD(ADD(i,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,c))),MUL(MUL(ADD(h,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,b))),DIV(1.000000,ADD(e,MUL(MUL(d,DIV(1.000000,a)),MUL(-1,b))))),MUL(-1,SUB(f,MUL(c,MUL(d,DIV(1.000000,a))))))))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a)))))),DIV(1,ADD(e,MUL(MUL(d,DIV(1.000000,a)),MUL(-1,b)))))" ) ); - TS_ASSERT_EQUALS( sol.coeff( 2, 0 ), - symbolic::Symbolic< OutType >( "MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a)))),MUL(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(ADD(h,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,b))),DIV(1.000000,ADD(e,MUL(MUL(d,DIV(1.000000,a)),MUL(-1,b))))))),DIV(1,ADD(ADD(i,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,c))),MUL(MUL(ADD(h,MUL(MUL(g,DIV(1.000000,a)),MUL(-1,b))),DIV(1.000000,ADD(e,MUL(MUL(d,DIV(1.000000,a)),MUL(-1,b))))),MUL(-1,SUB(f,MUL(c,MUL(d,DIV(1.000000,a)))))))))" ) ); - -/* TS_ASSERT_EQUALS( sol.coeffRef( 0, 0 ), symbolic::Symbolic< OutType >( "MUL(SUB(SUB(x1,MUL(MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a)))),MUL(SUB(x2,MUL(x1,MUL(d,DIV(" "1.000000,a)))),MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d," - "DIV(1.000000,a)),b),-1),e))))),DIV(1,ADD(MUL(ADD(MUL(MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b)," - "-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))),SUB(f,MUL(c,MUL(d,DIV(1." - "000000,a))))),MUL(MUL(g,DIV(1.000000,a)),c)),-1),i))),c)),MUL(MUL(SUB(SUB(x2,MUL(x1,MUL(d,DIV(" - "1.000000,a)))),MUL(MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a)))),MUL(SUB(x2,MUL(x1,MUL(d,DIV(" - "1.000000,a)))),MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d," - "DIV(1.000000,a)),b),-1),e))))),DIV(1,ADD(MUL(ADD(MUL(MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b)," - "-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))),SUB(f,MUL(c,MUL(d,DIV(1." - "000000,a))))),MUL(MUL(g,DIV(1.000000,a)),c)),-1),i))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a))))))," + "DIV(1.000000,a)),b),-1),e))))),DIV(1,ADD(i,MUL(-1,ADD(MUL(MUL(g,DIV(1.000000,a)),c),MUL(MUL(" + "ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b)" + ",-1),e))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a)))))))))),c)),MUL(MUL(SUB(SUB(x2,MUL(x1,MUL(d,DIV(1." + "000000,a)))),MUL(MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a)))),MUL(SUB(x2,MUL(x1,MUL(d,DIV(1." + "000000,a)))),MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d," + "DIV(1.000000,a)),b),-1),e))))),DIV(1,ADD(i,MUL(-1,ADD(MUL(MUL(g,DIV(1.000000,a)),c),MUL(MUL(" + "ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b)" + ",-1),e))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a)))))))))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a))))))," "DIV(1,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))),b)),DIV(1,a))" ) ); - TS_ASSERT_EQUALS( sol.coeff( 1, 0 ), symbolic::Symbolic< OutType >( "MUL(SUB(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a))" ")),MUL(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h)," - "DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))))),DIV(1,ADD(MUL(ADD(MUL(MUL(ADD(" - "MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1)" - ",e))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a))))),MUL(MUL(g,DIV(1.000000,a)),c)),-1),i))),SUB(f,MUL(" - "c,MUL(d,DIV(1.000000,a)))))),DIV(1,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e)))" ) ); + "DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))))),DIV(1,ADD(i,MUL(-1,ADD(MUL(MUL(g," + "DIV(1.000000,a)),c),MUL(MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(" + "MUL(MUL(d,DIV(1.000000,a)),b),-1),e))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a)))))))))),SUB(f,MUL(c," + "MUL(d,DIV(1.000000,a)))))),DIV(1,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e)))" ) ); TS_ASSERT_EQUALS( sol.coeff( 2, 0 ), symbolic::Symbolic< OutType >( "MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a)))),MUL(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(" "ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b)" - ",-1),e))))),DIV(1,ADD(MUL(ADD(MUL(MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1." - "000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a)))))," - "MUL(MUL(g,DIV(1.000000,a)),c)),-1),i)))" ) ); -*/ + ",-1),e))))),DIV(1,ADD(i,MUL(-1,ADD(MUL(MUL(g,DIV(1.000000,a)),c),MUL(MUL(ADD(MUL(MUL(MUL(g,DIV(" + "1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))),SUB(f,MUL(c," + "MUL(d,DIV(1.000000,a))))))))))" ) ); + + /* + TS_ASSERT_EQUALS( sol.coeffRef( 0, 0 ), + symbolic::Symbolic< OutType >( + "MUL(SUB(SUB(x1,MUL(MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a)))),MUL(SUB(x2,MUL(x1,MUL(d,DIV(" + "1.000000,a)))),MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d," + "DIV(1.000000,a)),b),-1),e))))),DIV(1,ADD(MUL(ADD(MUL(MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b)," + "-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))),SUB(f,MUL(c,MUL(d,DIV(1." + "000000,a))))),MUL(MUL(g,DIV(1.000000,a)),c)),-1),i))),c)),MUL(MUL(SUB(SUB(x2,MUL(x1,MUL(d,DIV(" + "1.000000,a)))),MUL(MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a)))),MUL(SUB(x2,MUL(x1,MUL(d,DIV(" + "1.000000,a)))),MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d," + "DIV(1.000000,a)),b),-1),e))))),DIV(1,ADD(MUL(ADD(MUL(MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b)," + "-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))),SUB(f,MUL(c,MUL(d,DIV(1." + "000000,a))))),MUL(MUL(g,DIV(1.000000,a)),c)),-1),i))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a))))))," + "DIV(1,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))),b)),DIV(1,a))" ) ); + + TS_ASSERT_EQUALS( sol.coeff( 1, 0 ), + symbolic::Symbolic< OutType >( + "MUL(SUB(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a))" + ")),MUL(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h)," + "DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))))),DIV(1,ADD(MUL(ADD(MUL(MUL(ADD(" + "MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1)" + ",e))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a))))),MUL(MUL(g,DIV(1.000000,a)),c)),-1),i))),SUB(f,MUL(" + "c,MUL(d,DIV(1.000000,a)))))),DIV(1,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e)))" ) ); + TS_ASSERT_EQUALS( sol.coeff( 2, 0 ), + symbolic::Symbolic< OutType >( + "MUL(SUB(SUB(x3,MUL(x1,MUL(g,DIV(1.000000,a)))),MUL(SUB(x2,MUL(x1,MUL(d,DIV(1.000000,a)))),MUL(" + "ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1.000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b)" + ",-1),e))))),DIV(1,ADD(MUL(ADD(MUL(MUL(ADD(MUL(MUL(MUL(g,DIV(1.000000,a)),b),-1),h),DIV(1." + "000000,ADD(MUL(MUL(MUL(d,DIV(1.000000,a)),b),-1),e))),SUB(f,MUL(c,MUL(d,DIV(1.000000,a)))))," + "MUL(MUL(g,DIV(1.000000,a)),c)),-1),i)))" ) ); + */ // MATLAB / Octave code diff --git a/src/unittests/system/TestDaeSystem.cpp b/src/unittests/system/TestDaeSystem.cpp index d074a7619533fbe77b19be14f7016b8e75e4217f..5e4ac0adbb793b681ade27d093630e5a6de66bf3 100644 --- a/src/unittests/system/TestDaeSystem.cpp +++ b/src/unittests/system/TestDaeSystem.cpp @@ -15,7 +15,6 @@ _._._._._._._._._._._._._._._._._._._._._.*/ #include <iostream> #include <string> -#include "../../container/armadillo_wrapper.h" #include "../../electrical/capacity.h" #include "../../electrical/cellelement.h" #include "../../electrical/ohmicresistance.h" @@ -30,7 +29,7 @@ _._._._._._._._._._._._._._._._._._._._._.*/ #include "../../system/constantstepdglsystemsolver.h" #include "../../system/dae_sys.h" #include "../../system/stateSystemGroup.h" -#include "../../system/variablestepdglsystemsolver.h" +//#include "../../system/variablestepdglsystemsolver.h" std::vector< std::vector< double > > TestDaeSystem::CopyToVector( const double data[7][4] ) { @@ -919,58 +918,58 @@ void TestDaeSystem::testMultiCellellementBalancing() TS_ASSERT_DELTA( cellelem2->GetCurrentValue(), 6, 0.001 ) } -void TestDaeSystem::testVariableStepSolverWithParallelRCMindingResults() -{ -#if defined( _EIGEN_ ) || defined( _ARMADILLO_ ) - boost::shared_ptr< electrical::SerialTwoPort<> > serial( new electrical::SerialTwoPort<>() ); - - boost::shared_ptr< object::Object< double > > objR( new object::ConstObj< double >( 0.6 ) ); - boost::shared_ptr< object::Object< double > > objTau( new object::ConstObj< double >( 0.6 * 0.5 ) ); - boost::shared_ptr< electrical::ParallelRC<> > parallelRC( new electrical::ParallelRC<>( objR, objTau, true ) ); - - serial->AddChild( parallelRC ); - - - double t = 0.0; - - systm::StateSystemGroup< myMatrixType > stateSystemGroup; - serial->SetSystem( &stateSystemGroup ); - stateSystemGroup.Initialize(); - serial->SetInitialCurrent( 2.0 ); - serial->UpdateStateSystemGroup(); - - systm::VariableStepDglSystemSolver< myMatrixType > solver( - &stateSystemGroup ); // systm::ConstantStepDglSystemSolver< myMatrixType > solver(&stateSystemGroup, 0.001); - - while ( t < 1.0 ) - { - serial->UpdateStateSystemGroup(); - t = solver.Solve(); - serial->CalculateStateDependentValues(); - TS_ASSERT_DELTA( serial->GetVoltageValue(), 2.0 * 0.6 * ( 1 - exp( -( t - 0.0 ) / 0.3 ) ), 0.01 ); - } - double lastCurrentSwitchTime = t; - double lastVoltageValue = serial->GetVoltageValue(); - - serial->SetCurrent( -0.4 ); - while ( t < 3.0 ) - { - serial->UpdateStateSystemGroup(); - t = solver.Solve(); - serial->CalculateStateDependentValues(); - TS_ASSERT_DELTA( serial->GetVoltageValue(), - ( lastVoltageValue + 0.4 * 0.6 ) * exp( -( t - lastCurrentSwitchTime ) / 0.3 ) - 0.4 * 0.6, 0.01 ); - } - lastCurrentSwitchTime = t; - lastVoltageValue = serial->GetVoltageValue(); - - serial->SetCurrent( 0.0 ); - while ( t < 6.0 ) - { - serial->UpdateStateSystemGroup(); - t = solver.Solve(); - serial->CalculateStateDependentValues(); - TS_ASSERT_DELTA( serial->GetVoltageValue(), lastVoltageValue * exp( -( t - lastCurrentSwitchTime ) / 0.3 ), 0.01 ); - } -#endif -} +//void TestDaeSystem::testVariableStepSolverWithParallelRCMindingResults() +//{ +//#if defined( _EIGEN_ ) +// boost::shared_ptr< electrical::SerialTwoPort<> > serial( new electrical::SerialTwoPort<>() ); +// +// boost::shared_ptr< object::Object< double > > objR( new object::ConstObj< double >( 0.6 ) ); +// boost::shared_ptr< object::Object< double > > objTau( new object::ConstObj< double >( 0.6 * 0.5 ) ); +// boost::shared_ptr< electrical::ParallelRC<> > parallelRC( new electrical::ParallelRC<>( objR, objTau, true ) ); +// +// serial->AddChild( parallelRC ); +// +// +// double t = 0.0; +// +// systm::StateSystemGroup< myMatrixType > stateSystemGroup; +// serial->SetSystem( &stateSystemGroup ); +// stateSystemGroup.Initialize(); +// serial->SetInitialCurrent( 2.0 ); +// serial->UpdateStateSystemGroup(); +// +// systm::VariableStepDglSystemSolver< myMatrixType > solver( +// &stateSystemGroup ); // systm::ConstantStepDglSystemSolver< myMatrixType > solver(&stateSystemGroup, 0.001); +// +// while ( t < 1.0 ) +// { +// serial->UpdateStateSystemGroup(); +// t = solver.Solve(); +// serial->CalculateStateDependentValues(); +// TS_ASSERT_DELTA( serial->GetVoltageValue(), 2.0 * 0.6 * ( 1 - exp( -( t - 0.0 ) / 0.3 ) ), 0.01 ); +// } +// double lastCurrentSwitchTime = t; +// double lastVoltageValue = serial->GetVoltageValue(); +// +// serial->SetCurrent( -0.4 ); +// while ( t < 3.0 ) +// { +// serial->UpdateStateSystemGroup(); +// t = solver.Solve(); +// serial->CalculateStateDependentValues(); +// TS_ASSERT_DELTA( serial->GetVoltageValue(), +// ( lastVoltageValue + 0.4 * 0.6 ) * exp( -( t - lastCurrentSwitchTime ) / 0.3 ) - 0.4 * 0.6, 0.01 ); +// } +// lastCurrentSwitchTime = t; +// lastVoltageValue = serial->GetVoltageValue(); +// +// serial->SetCurrent( 0.0 ); +// while ( t < 6.0 ) +// { +// serial->UpdateStateSystemGroup(); +// t = solver.Solve(); +// serial->CalculateStateDependentValues(); +// TS_ASSERT_DELTA( serial->GetVoltageValue(), lastVoltageValue * exp( -( t - lastCurrentSwitchTime ) / 0.3 ), 0.01 ); +// } +//#endif +//} diff --git a/src/unittests/system/TestDaeSystem.h b/src/unittests/system/TestDaeSystem.h index d2b2c18f5c72ecab957dc50758894d7a7986cb19..596b90c84a480edc9be2fa9d77753893eef945be 100644 --- a/src/unittests/system/TestDaeSystem.h +++ b/src/unittests/system/TestDaeSystem.h @@ -14,7 +14,7 @@ class TestDaeSystem: public CxxTest::TestSuite public: void testDaeSystemMixedSystemCurrentUnsolveable(); - void testDaeSystemMixedSystemCurrentSolveable(); + __attribute__( ( unused ) ) __attribute__( ( unused ) ) void testDaeSystemMixedSystemCurrentSolveable(); void testDaeSystemMixedSystemCurrentSolveableIntegrate(); void testRC(); void testRCParallel(); @@ -25,7 +25,7 @@ class TestDaeSystem: public CxxTest::TestSuite void testSingleCellellement(); void testSingleCellellementBalancing(); void testMultiCellellementBalancing(); - void testVariableStepSolverWithParallelRCMindingResults(); + //void testVariableStepSolverWithParallelRCMindingResults(); private: std::vector< std::vector<double> > CopyToVector(const double data[7][4]); diff --git a/src/unittests/system/TestLinearSystem.cpp b/src/unittests/system/TestLinearSystem.cpp index 0e37966f154d22df34a4f4458f7e0cf4a1e3ffb8..060d8c4476e238c9213c45625ea0b4b063eeeb4e 100644 --- a/src/unittests/system/TestLinearSystem.cpp +++ b/src/unittests/system/TestLinearSystem.cpp @@ -14,7 +14,6 @@ _._._._._._._._._._._._._._._._._._._._._.*/ // STD #include <string> -#include "../../container/armadillo_wrapper.h" #include "../../electrical/capacity.h" #include "../../electrical/cellelement.h" #include "../../electrical/ohmicresistance.h" diff --git a/standalone/CMakeLists.txt b/standalone/CMakeLists.txt index 3e084592939161b8b07c2c34d20c9f3f70f11f01..a258f227a1e6e981eb40bb78739c120fb204c55c 100644 --- a/standalone/CMakeLists.txt +++ b/standalone/CMakeLists.txt @@ -10,7 +10,7 @@ if(WIN_TARGET AND LINUX_HOST) endforeach() endif() -find_package(MATIO REQUIRED) +find_package(matio REQUIRED) file(GLOB_RECURSE SOURCEFILES standalone/*.cpp) add_library(ISEAFrameStandalone STATIC EXCLUDE_FROM_ALL ${SOURCEFILES}) @@ -65,6 +65,7 @@ function(create_numeric_standalone condition standalone_name sourcefile) if(${condition}) add_executable(${standalone_name} ${sourcefile} standalone/standalone.cpp) target_link_libraries(${standalone_name} ISEAFrameStandalone) + set_target_properties( ${standalone_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/standalones) diff --git a/standalone/standalone/electrical_standalone.cpp b/standalone/standalone/electrical_standalone.cpp index 18dc5827b7fdf50771de45759b866734d6f935b3..8b9c785de8d29ee0880b8211117a50772a843b60 100644 --- a/standalone/standalone/electrical_standalone.cpp +++ b/standalone/standalone/electrical_standalone.cpp @@ -38,15 +38,13 @@ bool ElectricalStandalone::CreateElectricalSimulation( factory::FactoryBuilder< mElectricalSimulation->SetPowerStopCriterion( mPowerStopCriterion ); } -// create equation solvers -#if defined( _ARMADILLO_ ) && not defined( SPARSE_MATRIX_FORMAT ) - mStepperElectrical = - make_controlled( 1.0e-10, 1.0e-10, boost::numeric::odeint::runge_kutta_cash_karp54< myMatrixType >() ); -#else + mElectricalSimulation->SetVoltageStopCriterion( mMinCellVoltage, mMaxCellVoltage ); + + // create equation solvers + mStepperElectrical = make_controlled( 1.0e-10, 1.0e-10, boost::numeric::odeint::runge_kutta_cash_karp54< std::vector< double > >() ); mStateVector = std::vector< double >( mElectricalSimulation->mStateSystemGroup.mStateVector.rows(), 0.0 ); -#endif } catch ( std::exception &e ) { @@ -124,21 +122,7 @@ void ElectricalStandalone::DoElectricalStep() { mElectricalSimulation->UpdateSystem(); -#if defined( _ARMADILLO_ ) && !defined( SPARSE_MATRIX_FORMAT ) - // Run electrical equation solver - mStateVector = mElectricalSimulation->mStateSystemGroup.mStateVector.submat( - 0, 0, mElectricalSimulation->mStateSystemGroup.mStateVector.n_rows - 2, 0 ); - mElectricalSimulation->mStateSystemGroup.mDt = mElectricalSimulation->mDeltaTime; - while ( mStepperElectrical.try_step( boost::ref( *mElectricalSimulation->mEqSystem ), mStateVector, - mElectricalSimulation->mTime, - mElectricalSimulation->mDeltaTime ) != boost::numeric::odeint::success ) - { - mElectricalSimulation->mStateSystemGroup.mStateVector.submat( - 0, 0, mElectricalSimulation->mStateSystemGroup.mStateVector.n_rows - 2, 0 ) = mStateVector; - mElectricalSimulation->mStateSystemGroup.mDt = mElectricalSimulation->mDeltaTime; - } -#else // Run electrical equation solver misc::FastCopyMatrix( &mStateVector[0], mElectricalSimulation->mStateSystemGroup.mStateVector, mStateVector.size() ); mElectricalSimulation->mStateSystemGroup.mDt = mElectricalSimulation->mDeltaTime; @@ -149,7 +133,6 @@ void ElectricalStandalone::DoElectricalStep() mElectricalSimulation->mStateSystemGroup.mDt = mElectricalSimulation->mDeltaTime; } misc::FastCopyMatrix( mElectricalSimulation->mStateSystemGroup.mStateVector, &mStateVector[0], mStateVector.size() ); -#endif mElectricalSimulation->UpdateSystemValues(); diff --git a/standalone/standalone/electrical_standalone.h b/standalone/standalone/electrical_standalone.h index b907f3578ba2fbea63a14f6da7c7439b46482257..a4612b772a2237bfa32274265582579159c8f7fe 100644 --- a/standalone/standalone/electrical_standalone.h +++ b/standalone/standalone/electrical_standalone.h @@ -22,13 +22,9 @@ class ElectricalStandalone : virtual public SimulationStandalone boost::shared_ptr< simulation::ElectricalSimulation< myMatrixType, double, true > > mElectricalSimulation; std::vector< boost::shared_ptr< electrical::TwoPort< myMatrixType > > > mCells; -#if defined( _ARMADILLO_ ) && !defined( SPARSE_MATRIX_FORMAT ) - boost::numeric::odeint::result_of::make_controlled< boost::numeric::odeint::runge_kutta_cash_karp54< myMatrixType > >::type mStepperElectrical; - myMatrixType mStateVector; -#else + boost::numeric::odeint::result_of::make_controlled< boost::numeric::odeint::runge_kutta_cash_karp54< std::vector< double > > >::type mStepperElectrical; std::vector< double > mStateVector; -#endif }; } // namespace standalone diff --git a/standalone/standalone/simulation_standalone.cpp b/standalone/standalone/simulation_standalone.cpp index a8b22add83fa3ee74b03769dc1f4b25065f7fd04..533251b1cf7c036acb244b8098d82395866876d0 100644 --- a/standalone/standalone/simulation_standalone.cpp +++ b/standalone/standalone/simulation_standalone.cpp @@ -99,12 +99,12 @@ void SimulationStandalone::ReadXmlOptions() if ( optionsNode->HasElementDirectChild( "MaximalOperationalCellVoltageV" ) ) mMaxCellVoltage = optionsNode->GetElementDoubleValue( "MaximalOperationalCellVoltageV" ); else - mMaxCellVoltage = 10.0; // Default voltage limit electrical simulation + mMaxCellVoltage = nan( "" ); // Default voltage limit electrical simulation if ( optionsNode->HasElementDirectChild( "MinimalOperationalCellVoltageV" ) ) mMinCellVoltage = optionsNode->GetElementDoubleValue( "MinimalOperationalCellVoltageV" ); else - mMinCellVoltage = 0.0; // Default voltage limit electrical simulation - if ( mOutputDecimation < 0.0 ) // set default value if no decimation was given on the command line + mMinCellVoltage = nan( "" ); // Default voltage limit electrical simulation + if ( mOutputDecimation < 0.0 ) // set default value if no decimation was given on the command line mOutputDecimation = mStepTime; } diff --git a/standalone/standalone/thermal_electrical_standalone.cpp b/standalone/standalone/thermal_electrical_standalone.cpp index 211935c22ac9436f3b9d7c1383a42821eed3f439..8a37b8220496f6af19be2e94405492c117dcfc63 100644 --- a/standalone/standalone/thermal_electrical_standalone.cpp +++ b/standalone/standalone/thermal_electrical_standalone.cpp @@ -57,21 +57,7 @@ void ThermalElectricalStandalone::DoElectricalStep() !mElectricalSimulation->IsStopCriterionFulfilled() ) { mElectricalSimulation->UpdateSystem(); -#if defined( _ARMADILLO_ ) && !defined( SPARSE_MATRIX_FORMAT ) - // Run electrical equation solver - mStateVector = mElectricalSimulation->mStateSystemGroup.mStateVector.submat( - 0, 0, mElectricalSimulation->mStateSystemGroup.mStateVector.n_rows - 2, 0 ); - mElectricalSimulation->mStateSystemGroup.mDt = mElectricalSimulation->mDeltaTime; - while ( mStepperElectrical.try_step( boost::ref( *mElectricalSimulation->mEqSystem ), mStateVector, - mElectricalSimulation->mTime, - mElectricalSimulation->mDeltaTime ) != boost::numeric::odeint::success ) - { - mElectricalSimulation->mStateSystemGroup.mStateVector.submat( - 0, 0, mElectricalSimulation->mStateSystemGroup.mStateVector.n_rows - 2, 0 ) = mStateVector; - mElectricalSimulation->mStateSystemGroup.mDt = mElectricalSimulation->mDeltaTime; - } -#else // Run electrical equation solver misc::FastCopyMatrix( &mStateVector[0], mElectricalSimulation->mStateSystemGroup.mStateVector, mStateVector.size() ); mElectricalSimulation->mStateSystemGroup.mDt = mElectricalSimulation->mDeltaTime; @@ -82,7 +68,6 @@ void ThermalElectricalStandalone::DoElectricalStep() mElectricalSimulation->mStateSystemGroup.mDt = mElectricalSimulation->mDeltaTime; } misc::FastCopyMatrix( mElectricalSimulation->mStateSystemGroup.mStateVector, &mStateVector[0], mStateVector.size() ); -#endif mElectricalSimulation->UpdateSystemValues(); diff --git a/toolchain_files/ToolchainClangLinux2Win.cmake b/toolchain_files/ToolchainClangLinux2Win.cmake new file mode 100644 index 0000000000000000000000000000000000000000..f40b8bbb7667d79f18beb477feb6f68d2d7e5490 --- /dev/null +++ b/toolchain_files/ToolchainClangLinux2Win.cmake @@ -0,0 +1,35 @@ +set(CMAKE_SYSTEM_NAME Windows) + +set(CMAKE_C_COMPILER clang-cl) +set(CMAKE_CXX_COMPILER clang-cl) + +set(CMAKE_RC_COMPILER llvm-rc-13) + +set(CMAKE_C_FLAGS "-Wno-unused-command-line-argument -fuse-ld=lld-link /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/include /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/ucrt /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/um /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/shared") +set(CMAKE_CXX_FLAGS "-Wno-unused-command-line-argument -fuse-ld=lld-link /GR /EHsc /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/include /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/ucrt /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/um /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/shared") +set(CMAKE_RC_FLAGS "-Wno-unused-command-line-argument -fuse-ld=lld-link /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/include /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/ucrt /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/um /imsvc/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/include/shared") + +set(CMAKE_EXE_LINKER_FLAGS "/libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/um/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/lib/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/ucrt/x86_64") +set(CMAKE_SHARED_LINKER_FLAGS "/libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/um/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/lib/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/ucrt/x86_64") +set(CMAKE_MODULE_LINKER_FLAGS "/libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/um/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/lib/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/ucrt/x86_64") +set(CMAKE_STATIC_LINKER_FLAGS "/libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/um/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/crt/lib/x86_64 /libpath:/usr/x86_64-w64-mingw32/FrameworkExtensions/xwin/sdk/lib/ucrt/x86_64") + +set(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32/FrameworkExtensions") +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +set(Matlab_INCLUDE_DIRS + /usr/x86_64-w64-mingw32/matlab/include + CACHE STRING "Path to matlab header files") +file(GLOB LIBRARIES /usr/x86_64-w64-mingw32/matlab/lib/*.lib) +set(Matlab_LIBRARIES + ${LIBRARIES} + CACHE STRING "Path to matlab library files") + +set(TOOLCHAIN_COMPILE_OPTIONS "" CACHE STRING "Compile options specified by the toolchain file") +set(TOOLCHAIN_LINK_OPTIONS "" CACHE STRING "Compile options specified by the toolchain file") + +cmake_policy(SET CMP0091 NEW) +set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL) \ No newline at end of file