Manish Agrawal


Week 8

21 Jul 2019 »

GSoC 2019 :: gprMax Weekly Documentation

Week 8

This week I had to focus on implementing OpenCl implementation for Dispersive Materials. Usually single-pole Debye model can adequately represent many materials however, multi-pole Debye, Drude and Lorentz functions are often used for simulations of common materials.

gprMax takes input for dispersive materials through the model .in file. Command lines with #add_dispersion_debye, #add_dispersion_lorentz and #add_dispersion_drude adds the requirement of dispersive materials into the model simulation. Again, for writing the OpenCl kernel codes, significant references are taken from the corresponding CUDA kernel codes. In the host side, which is OpenClSolver class, required template loader are written, programs are build and corresponding kernel functions are called. For the kernel side, functions for update_e_dispersive_A and update_e_dispersive_B were added with some changes. PyCUDA inbuilt can handle simple operations of complex numbers like addition, subtraction, multiplication and division. Thus, CUDA kernels which are written for dispersive materials cannot be simply adapted in OpenCl without required changes.

Complex Numbers in PyOpenCl

PyOpenCL’s Array type supports complex numbers out of the box. If complex numbers are to be used in kernels adding:

#include <pyopencl-complex.h>

in the kernel files which will add support for complex types cfloat_t and cdouble_t along with other operation functions. The full list of supporting complex number operation function can be found here.

If a is a complex number defined in the kernel file as type cfloat_t then a.real returns the real part and a.imag returns the imaginary part of the complex number. cfloat_add(a,b) adds up two complex numbers, cfloat_sub(a,b) subtracts b from a and similarly cfloat_mul(a,b), cfloat_divide(a,b), cfloat_pow(a,b), cfloat_sqrt(a), etc are defined.

The PR #218 is the work being accepted for adding dispersive materials into OpenCl Solver.