• The added line is THIS COLOR.
  • The deleted line is THIS COLOR.
* Step-by-step instructions to build KAPSEL [#s1fa1365]
#freeze
* Step-by-step instructions to install & run KAPSEL [#s1fa1365]

If KAPSEL binaries do not run on your machine, or if you want to modify KAPSEL source codes for your own purpose, you can build KAPSEL binaries from the source package.
** What you need to use KAPSEL [#dcb9cd13]
- Windows + Cygwin* or Linux (*Cygwin 64-bit will work fine, but if not, use Cygwin 32-bit instead.)
- gcc and make
- GOURMET (included in OCTA distribution package)
- KAPSEL source codes & examples 

** STEP 0: Linux or Windows? [#sd4e991d]
-- [[kapsel3.40.zip:https://app.box.com/s/t6wl52gu7hqcpjokcbnjufh7c7k90rsk]] [2018/04/01] Performance improvements by use of FFTW and memory optimization. Policy change in handling periodic boundary conditions in input.udf and restart.udf.

- To build KAPSEL on Linux, goto STEP 1.
-- [[kapsel3.35.zip:https://app.box.com/s/zjdjbsagzbqomga4edlmgu7iu17dol3q]] [2018/03/15] Bug fix around HDF5 file handling.

- To build KAPSEL on Windows,  install "[[Cygwin:http://cygwin.com]]" first, then goto STEP 1. Be sure to include "gcc" and "make" packages.
-- [[kapsel3.34.zip:https://app.box.com/s/obls3bg5kfpc9hnfaa91iurtnzi21lc1]] [2018/03/06] Bug fix effective only when switch.INIT_distribution.type=user_specify

- KAPSEL can be build also on Mac OS-X. (not officially supported)
-- [[kapsel3.33.zip:https://app.box.com/s/853hsocx5ygcv0lm08vmloteqkit47ha]] [2018/02/09] Compatible with OCTA8.3 with Python3

** STEP 1: Download and install "Gourmet" [#b5c31f22]
//-- &ref(kapsel3.32.zip); [2017/04/04] 
//-- &ref(kapsel3.31.zip); [2016/01/27] 
//-- &ref(kapsel3.30.zip); [2015/11/09] 
//-- &ref(kapsel3.20.zip); [2015/01/19] 
//-- &ref(kapsel3.12b.zip); [2014/10/21] (NOTE: fixes bug in v3.12)] Docs for For HDF-5 and Paraview: &ref(kapsel_3.1.pdf); &ref(paraview_howto.pdf);
//-- &ref(kapsel3.07.zip); [2013/11/13]
//-- &ref(kapsel3.06.zip); [2013/07/03]
//-- &ref(kapsel3.05.zip); [2013/06/17]
//-- &ref(kapsel3.04.zip); [2013/06/15]
//-- &ref(kapsel3.03.zip); [2013/06/12]

- Visit [[OCTA-BBS:http://octa001.muse.aist.go.jp/phpBB3/]] and Login. Registration is required if you haven't yet complete it.
** STEP 0: Linux, Windows, or Mac? [#sd4e991d]

- For Linux
-- Follow "DOWNLOAD" -> "OCTA2007" -> "GOURMET 4.1.0 (on OCTA2007) for Windows and Linux".
-- download "gourmet_2007_linux.tar.gz"
- To build KAPSEL on Linux, goto STEP 1.

    > tar zxvf gourmet_2007_linux.tar.gz
    > su
    > mkdir /usr/local/OCTA2007
    > mv GOURMET_2007 /usr/local/OCTA2007/.
- To build KAPSEL on Windows, install "[[Cygwin:http://cygwin.com]]" first, then goto STEP 1. Be sure to include "gcc", "make" (both exist under "Devel" tree) and libfftw3-devel (under "Math" tree). Both 32-bit and 64-bit cygwin should work fine. 
//, and "unzip" (under "Archive" tree) packages.

- For Windows
-- Follow "DOWNLOAD" -> "OCTA2007" -> "Platform GOURMET2007 in OCTA2007 (for Windows)".
-- download "GOURMET2007.exe" and click it.
- KAPSEL can be build also on Mac OS-X (not officially supported). By default, gcc command calls clang compiler which is not fast. You may install gcc and fftw separately by yourself to achieve better performance. 

** STEP 1: Download and install OCTA/GOURMET [#b5c31f22]

- Visit [[OCTA-BBS:http://49.212.191.63/phpBB/]] and Download an appropriate version of KAPSEL installation package. 
//You may download OCTA2013SE also from [[here:https://onedrive.live.com/redir?resid=44483796C332EDE5!1838&authkey=!AAW17-1NfPVZ7JY&ithint=folder%2c]].
Please contact us [kapsel.dev@gmail.com] if any troubles take place. 

- In the following STEPS, OCTA8.# is assumed to be installed in /usr/local/OCTA8# (Linux/Mac) or C:\OCTA8.# (Windows).

** STEP 2: Build "libplatform" [#b16eb306]

- "libplatform" is an I/O library developed by OCTA project. One needs this library to access to UDF-formatted files.

- You may have to install additional software such as Java(JDK) and Python3 to build libplatform.

- For Linux:

    > su
    > cd /usr/local/OCTA2007/GOURMET_2007
    > tar zxvf gourmet2007_src.tar.gz
    > cd src
    > cd /usr/local/OCTA8#/GOURMET/src
//    > cd src
    > make clean
    > ./configure
    > make
    > make install

- For Windows: 
-- Logon Windows with an administrator authorization
-- Open Cygwin window
-- Open Cygwin terminal window

    $ ln -s /cygdrive/c/OCTA2007/ /usr/local/.
    $ cd /usr/local/OCTA2007/GOURMET_2007
    $ unzip GOURMET_2007_SRC.zip
    $ cd src
    $ make
    $ ln -s /cygdrive/c/OCTA8.# /usr/local/OCTA8#
    $ cd /usr/local/OCTA8#/GOURMET/src
//    $ cd src
    $ make clean
    $ ./configure
    $ make (in case of error, make CCOPT=)
    $ make install

-- In my environment, I had to do the following before "./configure".

    > touch aclocal.m4
    > touch config.h.in
    > touch Makefile.in
    > touch configure

- For Mac:

-- with gcc-7

    > cd /usr/local/OCTA8#/GOURMET/src
    > make distclean; make clean
    > ./configure CC=gcc-7 CXX=g++-7
    > make
    > sudo make install
    > mv ../lib/macosx/libplatform.a ../lib/macosx/libplatform_gcc-7.a

-- or with clang

    > ./configure CC=clang CXX=clang++

-- In my environment, gourmet doesn't start properly after building libplatform. Please do the following if so.

    > cd ..
    > Make-All.sh

- See manuals for more detailed information on libplatform
-- English: &ref(libplatform_eng.pdf);
-- Japanese: &ref(libplatform_jpn.pdf);
-- English: &ref(Docs/libplatform_eng.pdf);
-- Japanese: &ref(Docs/libplatform_jpn.pdf);


** STEP 3: Download "KAPSEL" source code [#hcf749f2]

- Visit [[KAPSEL-BBS:http://www.cheme.kyoto-u.ac.jp/1koza/kapsel/phpBB3/]] and Login. Registration is required if you haven't yet complete it.
- You can download KAPSEL source codes & examples at the top of this page.
//-- &ref(kapsel3.03.zip); [2013/06/12]
//-- Examples &ref(examples.zip);
//-- Makefile for OCTA2010 &ref(Makefile);

- Follow "DOWNLOAD" -> "KAPSEL-2" -> "KAPSEL-2 source code" to download "kapsel2_src.zip".

** STEP 4: Build "KAPSEL" binary executable [#h2d3c3c3]

    > unzip kapsel2_src.zip
    > make
    > unzip kapsel3.*.zip
    > cd kapsel3.*

- You may modify GOURMET_HOME_PATH in the attached "Makefile" so that the library "libplatform.a" is correctly linked.

- "*" indicates the performance.

- Clean-up working files first.

    > make clean

- with Ooura FFT (easy to build but slow, not compatible with OpenMP)

    > make ENV=CYGWIN       (Cygwin on Windows)*
    or
    > make ENV=GCC          (gcc on Linux)*
    or
    > make ENV=ICC          (icc on Linux)*
    or
    > make ENV=GCC_MAC      (gcc on Mac)*
    or
    > make ENV=CLANG        (clang on Mac)

- with Intel MKL (as fast as FFTW, compatible with OpenMP)

    > make ENV=ICC FFT=IMKL         (icc on Linux)**
    or
    > make ENV=ICC_OMP FFT=IMKL     (icc on Linux, OpenMP)***

- with FFTW (faster than Ooura, compatible with OpenMP)

    > make ENV=CYGWIN FFT=FFTW      (Cygwin on Windows)**
    or
    > make ENV=CYGWIN_OMP FFT=FFTW  (Cygwin on Windows, OpenMP)***
    or
    > make ENV=GCC FFT=FFTW         (gcc on Linux)**
    or
    > make ENV=GCC_OMP FFT=FFTW     (gcc on Linux, OpenMP)***
    or
    > make ENV=ICC FFT=FFTW         (icc on Linux)**
    or
    > make ENV=ICC_OMP FFT=FFTW     (icc on Linux, OpenMP)****
    or 
    > make ENV=GCC_MAC FFT=FFTW     (gcc-7 on Mac)**
    or
    > make ENV=GCC_MAC_OMP FFT=FFTW (gcc-7 on Mac, OpenMP)***

- Installation memo of FFTW

-- For Windows
--- Install "libfftw3-devel" using Cygwin installer.

-- For Linux
--- Download source file and 
--- with gcc

    ./configure CFLAGS="-O3" FFLAGS="-O3" --enable-openmp --enable-threads --enable-shared --disable-fortran
    make
    make install

--- with icc

    ./configure --prefix=/opt/fftw/3.3.7 CC=icc CXX=icpc CFLAGS="-O3" FFLAGS="-O3" --enable-openmp --enable-threads --enable-shared --disable-fortran --enable-sse2 --enable-avx --enable-avx2
    make
    make install

-- For Mac
--- Download source file and 

    ./configure --prefix=/opt/fftw/3.3.7 CC=gcc-7 CXX=g++-7 CFLAGS="-O3" FFLAGS="-O3" --enable-openmp --enable-threads --enable-shared --disable-fortran
    make
    sudo make install

** STEP 5: Test run [#l7319ece]

    > ./kapsel -Icolloid_1.udf -Ooutput.udf -Ddefine.udf -Rrestart.udf
    #using colloid_1.udf as input
    #using output.udf as output
    #using define.udf as definition
    #using restart.udf as restart
    #
    # Electrolyte eq. selected.
    #
    > cd UDF
    > ../kapsel -Iinput.udf -Ooutput.udf -Ddefine.udf -Rrestart.udf
   #using input.udf as input
   #using output.udf as output
   #using define.udf as definition
   #using restart.udf as restart
   
    ...
- If you see the output as shown in the above panel, KAPSEL has been successfully built.
   
   #output.udf end.
   #restart.udf end.
   #Simulation has ended!
   #Total Running Time (s):      24.77
   #                   (m):       0.41
   #                   (h):       0.01
   #Average Step Time  (s):       0.02
   #                   (m):       0.00
   #                   (h):       0.00

* Optional information for Intel compiler [#v2b1c8eb]
- If you see a command-line output as shown above, KAPSEL has been successfully built and run.

** STEP 2a: Build "libplatform" with icc on Linux [#b16eb306]
** STEP 6: Visualization of simulation data [#de6c8fcf]

- For icc 7.1:
- The sample input.udf conduct a simulation of sedimenting 5-heavier + 5-lighter particles in Newtonian fluid, which is resolved by a 32x32x32 CFD grids. It takes less than a minute to be completed. If this sample successfully run, "output.udf" will be created. You can visualize various simulation data using python script from Gourmet. Three simple examples are shown below. 

    > su
    > cd /usr/local/OCTA2007/GOURMET_2007/src
    > make clean
    > make WITHFC=no CC=icc CXX=icc
    > make install
- Common procedure
-- Start GOURMET
-- Open "output.udf" ("File" -> "Open" -> Open "output.udf").

- For icc8.0:
- Watching variables on Gourmet
-- Instantaneous positions and velocities of all the particles can be seen as variables in "Particles[]". Use slide bar at the bottom of GOURMET viewer window to see variables at different time steps.

    > su
    > cd /usr/local/OCTA2007/GOURMET_2007/src
    > make clean
    > make WITHFC=no CC=icc CXX="icpc -U GNU "
    > make install
- Making an animation on GOURMET
//-- Start GOURMET
//-- "File" -> "Open" -> Open "output.udf".
-- Go down to "Python" panel, and click "Load"
-- Open "particleshow.py", and click "Run"
-- A new window will open, then click the playback button there.

- For icc8.1 or later:
&ref(gourmet.jpg,,75%);  &ref(anime.jpg,,75%);

    > su
    > cd /usr/local/OCTA2007/GOURMET_2007/src
    > make clean
    > make WITHFC=no CC=icc CXX="icpc -lcxaguard"
    > make install
//#youtube(mEEumRywtOI)

** STEP 4a: Build "KAPSEL" with icc on Linux [#h2d3c3c3]
- Using gnuplot on GOURMET
//-- Start GOURMET
//-- "File" -> "Open" -> Open "output.udf".
-- Go down to "Python" panel, and click "Load"
-- Open "plot.py", and click "Run"
-- Go up to "View" box, and check "Table"
-- Go left and select "Graph Sheet[]".
-- go down to "Plot" panel, and type the following in the command box.
  > plot 'plot.dat' using 2:7 with lines
-- Click "Plot", then you will see the time evolution of Vx of the 1st particle.

- For icc
&ref(gourmet2.jpg,,75%); &ref(gourmet3.jpg,,82%);  &ref(plot.jpg,,40%);

    > make clean
    > make ENV=ICC
** STEP 7: Analyzing simulation data [#d3ac46c6]

- For icc + MKL + OpenMP
- The history of simulation run (instantaneous positions and velocities of particles) is stored in "output.udf". One can access to this file by one of the following methods.

    > make clean
    > make ENV=ICC_MKL_OMP
- Python program. Please read the manual below for more general information on accessing UDF using Python.
-- English: &ref(Docs/pythoninterface_eng.pdf); 
-- Japanese: &ref(Docs/PythonInterface_jpn.pdf);
-- "sk.py" is a sample python script to calculate the static structure factor S(k) from the temporal particle positions stored in "output.udf". It requires the "numpy" package to handle array variables. You can read and edit the script for your own purposes.
 
-- For Windows: "Start Menu" > "All Programs" > "OCTA2013" > "StartGourmetTerm"
   > python sk.py
   > gnuplot
    >> plot 'sk.dat' w line
#ref(sk.jpg,,40%)

- Fortran or C program with libplatform. Please read the manual below more general information on accessing UDF using Fortran or C.
-- English: &ref(Docs/libplatform_eng.pdf);
-- Japanese: &ref(Docs/libplatform_jpn.pdf);

- KAPSEL returns several important data to stderr as well (temporal stress etc). It usually appears in command line, but one can redirect stderr to a file as follows.

-- In case of csh or tcsh
 > ../kapsel  -Iinput.udf -Ooutput.udf -Ddefine.udf -Rrestart.udf >& out
-- In case of sh, bash, or Windows command prompt
 # ../kapsel  -Iinput.udf -Ooutput.udf -Ddefine.udf -Rrestart.udf 2> out