* Step-by-step instructions to install & run KAPSEL [#s1fa1365]

** What you need to use KAPSEL [#dcb9cd13]
- Windows (with Cygwin) or Linux
- gcc and make
- GOURMET2013 (included in OCTA2013 distribution package)
- KAPSEL source codes & examples 
-- &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]

** STEP 0: Linux or Windows? [#sd4e991d]

- To build KAPSEL on Linux, goto STEP 1.

- 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 "unzip" (under "Archive" tree) packages.

- KAPSEL can be build also on Mac OS-X. (not officially supported)

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

- Visit [[OCTA-BBS:http://49.212.191.63/phpBB/]] and Login. Registration is required if you haven't yet complete it. Please contact us [kapsel.dev@gmail.com] if no response is obtained from OCTA-BBS within a few days (they don't respond daily basis).

- For Linux
-- Follow "DOWNLOAD" -> "OCTA2013" -> "OCTA2013 for linux iso image".
-- Download "OCTA2013LINUX.ISO" and follow the instructions to install OCTA2013.

- For Windows
-- Follow "DOWNLOAD" -> "OCTA2013" -> "OCTA2013 for Windows 32/64bit iso image".
-- Download "OCTA2013WIN.ISO" and follow the instructions to install OCTA2013.

- In the following STEPS, OCTA2013 is assumed to be installed in /usr/local/OCTA2013 (Linux) or C:\OCTA2013 (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.

- For Linux:

    > su
    > cd /usr/local/OCTA2013/GOURMET_2013/src
//    > cd src
    > ./configure
    > make
    > make install

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

    $ ln -s /cygdrive/c/OCTA2013/ /usr/local/.
    $ cd /usr/local/OCTA2013/GOURMET_2013/src
//    $ cd src
    $ ./configure
    $ make (in case of error, make CCOPT=)
    $ make install

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


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

- 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);


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

    > unzip kapsel3.*.zip
    > cd kapsel3.1
    > make 'ENV=CYGWIN'       (Cygwin on Windows)
    or
    > make 'ENV=GCC'          (gcc on Linux)
    or
    > make 'ENV=ICC'          (icc on Linux)
    or
    > make 'ENV=ICC_MKL_OMP'  (icc + MKL + OpenMP on Linux)
    or
    > make clean   (clean-up working files)


** STEP 5: Test run [#l7319ece]

    > 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
   
    ...
   
   #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

- If you see a command-line output as shown above, KAPSEL has been successfully built and run.

** STEP 6: Visualization of simulation data [#de6c8fcf]

- 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. 

- Common procedure
-- Start GOURMET
-- Open "output.udf" ("File" -> "Open" -> Open "output.udf").

- 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.

- 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.

&ref(gourmet.jpg,,75%);  &ref(anime.jpg,,75%);

#youtube(mEEumRywtOI)

- 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.

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

** STEP 7: Analyzing simulation data [#d3ac46c6]

- 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.

- 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