-------------------------------------------------------------
Software
-------------------------------------------------------------

This software computes the diffraction of an electromagnetic wave by a
three-dimensional object. This interaction is taken into account
rigorously by solving the Maxwell's equations, but can also do with
the approximation of Born, Rytov, BPM and scalar. The
code has an user-friendly interface and allows you to choose canonical
objects (sphere, cube, ...) as well as predefined incident waves
(plane wave, Gaussian beam, ...) or aribitrary objects and incidents
waves. After by drop-down menus, it is easy to study cross sections,
optical forces and torques, diffraction near field and far field as
well as microsocopy.

The method we use is called coupled dipoles method (CDM) or the
discrete dipole approximation (DDA). This method is a volume method,
because the diffracted field is obtained from an integral, the support
of which is the volume of the considered object.

-------------------------------------------------------------
Licence:
-------------------------------------------------------------

Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA
4.0)

You are free to:

    Share — copy and redistribute the material in any medium or format
    Adapt — remix, transform, and build upon the material

    The licensor cannot revoke these freedoms as long as you follow
    the license terms.

-----------------------------------------------------------
VERSION
-----------------------------------------------------------
The code works with Qt 6

By default, the code compiles without FFTW and HDF5. A custom FFT
library is used. It is single processor.  If you have FFTW installed,
type: qmake "CONFIG+=fftw"

to use GPU with a NVIDA card:
qmake "CONFIG+=fftw cuda"

to use simple precision :
qmake "CONFIG+=fftw simp" or qmake "CONFIG+=fftw simp cuda"

to use HDF5:
qmake "CONFIG+=fftw hdf5" and  you can add the  other option and then:

make

Note that to use hdf5 or cuda option you have to install the library hdf5
and the compiler of nvidia, respectively.



if you have 4 processors,
export OMP_NUM_THREADS=4
before launching the code.

It is compiled in parallel and hence, needs to have on the computer
openmp (version 4.5 at least).
beware that if you use the parallel version, if you have a
core dump issue, the main reason may be the stack size. Use the
instructions (on LINUX system).
ulimit-s unlimited




Notice that the code can be installed without the graphical interface.
Go to the directory tests, and then write ./comp (or /compfftw or
./compfftwhdf5 depending on the packages installed), then in the four
test directories four executables each are created corresponding to
four different configuration. It is quite clear that to change the
configuration you need to open the file main.f and change the options
inside the fortran, which is more tiedous than with the interface.
graphic.


-------------------------------------------------------------
Linux installation:
-------------------------------------------------------------

The application is based on Qt-6 and gfortran

To install it on Fedora (take a look into .gitlab-ci.yml in cas), first you need to:

1) install the Qt packages as root:
dnf install qt* qt-devel

2) install gcc-c++ and gfortran as root
dnf install gcc-c++ gcc-gfortran

3) Install all the packages FFTW
dnf install fftw*

4) Install hdf5
dnf install hdf hdf5 hdf5-static hdf5-devel

1) 2) 3) 4) on Ubuntu system you need to do:
sudo  apt install build-essential
sudo  apt install gfortran
sudo  apt install fftw*
sudo  apt install libhdf5-dev
sudo  apt install libqt5datavisualization5-dev
sudo  apt install libqt5charts5 libqt5charts5-dev
sudo  apt install qt6 and dependancies

5) at root directory
qmake "CONFIG+=fftw hdf5"
make
make install

To run the application:
cd bin
cp ../cdm/cdm .
./cdm

If you get Segmentation fault (core dumped), please fix it with
$ulimit -s unlimited

If there are some troubles with Qt, one can compile the code with the
GUI. Go to the directory tests, and then write ./comp (or /compfftw or
./compfftwhdf5 depending on the packages installed), then in the four
test directories four executables each are created corresponding to
four different configuration. It is quite clear that to change the
configuration you need to open the file main.f and change the options
inside the fortran

-------------------------------------------------------------
Windows installation:
-------------------------------------------------------------
The application is based on Qt and MinGW and OpenGL

To build and install it, you need to:

1) install the Qt (5.0 or higher) with OpenGl and MinGW options including the QtCreator IDE

2) Open cmd_install.pro file in the root directory with QtCreator.exe

3) Build full project. You can run the executable cdm.exe directly from QtCreator.

4) To run the application in stand-alone, you need to deploy it along with a few runtime libraries.
For example if you built with Qt 5.3 (OpenGL included) and MinGW-4.8.2 option, 
the list of dll (in the Qt and MinGW-4.8.2 lib subdirectories) 
that have to be present in the same directory as cdm.exe:
icudt52.dll
icuin52.dll
icuuc52.dll
libgcc_s_dw2-1.dll
libgfortran-3.dll
libquadmath-0.dll
libstdc++-6.dll
libwinpthread-1.dll
Qt5Core.dll
Qt5Gui.dll
Qt5OpenGL.dll
Qt5PrintSupport.dll
Qt5Sql.dll
Qt5Svg.dll
Qt5Widgets.dll
