Battery-Intelligence-Lab / SLIDE

SLIDE is C++ code that simulates degradation of lithium ion cells. It extends the single particle model with various degradation models from literature. Users can select which degradation models they want to use for a given simulation.
Other
107 stars 35 forks source link

Compile and run on macOS #1

Closed wigging closed 2 years ago

wigging commented 2 years ago

I'm trying to run the code on macOS but I'm having several problems as discussed below. The steps that I have taken to compile and run are:

  1. cd ~/SLIDE/src
  2. in determineCharacterisation.cpp change line 676 to constexpr int nCCCV = 5;
  3. in determineOCV.h add #include <iostream> before using namespace std;
  4. in Model.cpp add parent directory to all file locations such as "../Cheb_Nodes.csv"
  5. compile with $ clang++ -std=c++11 *.cpp -o main
  6. run the program with ./main

I get the following error:

zsh: segmentation fault  ./main

Any suggestions on how I can get this code to run on a Mac?

ElektrikAkar commented 2 years ago

Hi Gavin,

Thank you so much for opening an issue. Currently, we are currently working on SLIDE version 2. Although it is still incomplete, I uploaded a temporary version for you to try. New version should be easier to run on Mac. Could you please try the version in develop branch and let me know if it works? You should be able to run this version by

cd ~/SLIDE/build (folder may be different) cmake .. make ./slide

Let me also summarise some of the major changes:

wigging commented 2 years ago

Thank you for the quick reply.

I am able to compile and run the version provided in the develop branch. See below for the output:

Start simulations
Available number of threads : 12
Start hierarchy level 0 with the following search spaces: 
AMp: from 0 to 1.04644e-05 in 54 steps with magnitude 1.97442e-07
AMn: from 0 to 1.66021e-05 in 51 steps with magnitude 3.32042e-07
sp: from 0 to 1 in 11 steps with magnitude 0.1
sn: from 0 to 1 in 11 steps with magnitude 0.1
The best fit in hierarchy 0 is: AMp = 4.14627e-06, AMn = 8.96512e-06, sp = 0.4, sn = 0.4.
Start hierarchy level 1 with the following search spaces: 
AMp: from 3.94883e-06 to 4.34371e-06 in 54 steps with magnitude 7.45062e-09
AMn: from 8.63308e-06 to 9.29717e-06 in 51 steps with magnitude 1.32817e-08
sp: from 0.3 to 0.5 in 11 steps with magnitude 0.02
sn: from 0.3 to 0.5 in 11 steps with magnitude 0.02
The best fit in hierarchy 1 is: AMp = 3.94883e-06, AMn = 8.95184e-06, sp = 0.38, sn = 0.4.
The best fit is: AMp = 3.94883e-06, AMn = 8.95184e-06, sp = 0.38, sn = 0.4.
finished all simulations in 35:8.57508.

However, I received the following warnings during the make process:

/Users/gavinw/Desktop/SLIDE-develop/src/main.cpp:64:12: warning: unused variable 'cellType' [-Wunused-variable]
        const int cellType = slide::cellType::KokamNMC;

/Users/gavinw/Desktop/SLIDE-develop/src/determine_characterisation.cpp:385:19: warning: unused variable 'dt' [-Wunused-variable]
        constexpr double dt = 2;          // time step to be used for the simulation

/Users/gavinw/Desktop/SLIDE-develop/src/cycler.cpp:1299:21: warning: variables 'j' and 'timeCheck' used in loop condition not modified in loop body [-Wfor-loop-analysis]
                                for (int j = 0; j < timeCheck; i++) // #CHECK

But it looks like the simulation completed successfully despite the warnings.

ElektrikAkar commented 2 years ago

Hi Gavin,

I am glad that you could successfully run the simulation. As said, we are still developing this version. Therefore, there may be redundancies or small bugs.

For the first warning: it is due to that functions requiring cellType are not activated in main.cpp. So, when you try different functionalities of SLIDE, this variable will be relevant.

Second warning is because of a redundant variable and should not affect your simulations.

However, the last warning is a bug which also appears on the master branch of SLIDE. i++ part should probably be j++ otherwise, it would be an infinite loop. Since it is only relevant when mode==1 (recharge every day) is selected, it should also not affect your simulations.

I should also say, with the number of available threads you have (12), I assume that you have a decent computer. Therefore, I would not expect it to take 35 minutes. It should take less than a minute. Probably, you run the simulations in Debug mode. Since I am using Visual Studio Code, it automatically defines CMAKE_BUILD_TYPE as Release.

Therefore, I uploaded a new version with following updates.

However, at this moment, I do not have a Mac computer with me. Therefore, I am unable to try if it works as intended. I should be able to try tomorrow and let you know.

I can also say that although the program lets you know that you have 12 available threads, you should set it to 12 in constants.hpp file which is constexpr unsigned int numMaxParallelWorkers = 8 as default.

ElektrikAkar commented 2 years ago

I could try it now, it looks like it is working. The only difference is that since the Release mode is default now, it creates the executable in Release folder. Therefore, you should run ./slide command in SLIDE/Release folder.

wigging commented 2 years ago

I downloaded the latest code from the develop branch. Here are my build results:

$ make
[  5%] Building CXX object CMakeFiles/slide.dir/src/main.cpp.o
/Users/gavinw/Desktop/SLIDE-develop/src/main.cpp:64:12: warning: unused variable 'cellType' [-Wunused-variable]
        const int cellType = slide::cellType::KokamNMC;
                  ^
1 warning generated.
[ 10%] Building CXX object CMakeFiles/slide.dir/src/basic_cycler.cpp.o
[ 15%] Building CXX object CMakeFiles/slide.dir/src/cell_LGChemNMC.cpp.o
[ 21%] Building CXX object CMakeFiles/slide.dir/src/degradation.cpp.o
[ 26%] Building CXX object CMakeFiles/slide.dir/src/cell.cpp.o
[ 31%] Building CXX object CMakeFiles/slide.dir/src/cell_user.cpp.o
[ 36%] Building CXX object CMakeFiles/slide.dir/src/determine_characterisation.cpp.o
[ 42%] Building CXX object CMakeFiles/slide.dir/src/model.cpp.o
[ 47%] Building CXX object CMakeFiles/slide.dir/src/cell_fit.cpp.o
[ 52%] Building CXX object CMakeFiles/slide.dir/src/cycler.cpp.o
[ 57%] Building CXX object CMakeFiles/slide.dir/src/determine_OCV.cpp.o
[ 63%] Building CXX object CMakeFiles/slide.dir/src/read_CSVfiles.cpp.o
[ 68%] Building CXX object CMakeFiles/slide.dir/src/cell_KokamNMC.cpp.o
[ 73%] Building CXX object CMakeFiles/slide.dir/src/cycling.cpp.o
[ 78%] Building CXX object CMakeFiles/slide.dir/src/interpolation.cpp.o
[ 84%] Building CXX object CMakeFiles/slide.dir/src/state.cpp.o
[ 89%] Building CXX object CMakeFiles/slide.dir/src/util_error.cpp.o
[ 94%] Building CXX object CMakeFiles/slide.dir/src/util.cpp.o
[100%] Linking CXX executable ../Release/slide
[100%] Built target slide

Running the program gives the following summary and the results were written to the results folder:

$ ./slide
Start simulations
Available number of threads : 12
Start hierarchy level 0 with the following search spaces: 
AMp: from 0 to 1.04644e-05 in 54 steps with magnitude 1.97442e-07
AMn: from 0 to 1.66021e-05 in 51 steps with magnitude 3.32042e-07
sp: from 0 to 1 in 11 steps with magnitude 0.1
sn: from 0 to 1 in 11 steps with magnitude 0.1
The best fit in hierarchy 0 is: AMp = 4.14627e-06, AMn = 8.96512e-06, sp = 0.4, sn = 0.4.
Start hierarchy level 1 with the following search spaces: 
AMp: from 3.94883e-06 to 4.34371e-06 in 54 steps with magnitude 7.45062e-09
AMn: from 8.63308e-06 to 9.29717e-06 in 51 steps with magnitude 1.32817e-08
sp: from 0.3 to 0.5 in 11 steps with magnitude 0.02
sn: from 0.3 to 0.5 in 11 steps with magnitude 0.02
The best fit in hierarchy 1 is: AMp = 3.94883e-06, AMn = 8.93856e-06, sp = 0.38, sn = 0.4.
The best fit is: AMp = 3.94883e-06, AMn = 8.93856e-06, sp = 0.38, sn = 0.4.
finished all simulations in 0:1.83268.

This ran much faster than the previous version. Also, here are the specs for my laptop where I'm running SLIDE:

Laptop:  MacBook Pro (16-inch, 2019)
OS:  macOS Big Sur v11.5
CPU:  2.6 GHz 6-core Intel Core i7
RAM:  32 GB 2667 MHz DDR4
ElektrikAkar commented 2 years ago

Hi Gavin,

Thank you very much for providing feedback! I am very happy that we could solve the issue. Therefore, I am closing this issue but please feel free to open another issue if you experience any further problems or have any feedback. Have a lovely day.

Cheers, Volkan