1D Wave equation Solver example

This is an example usage of the dg_maxwell library to find the time_evolution of the wave equation.

Parameters

The 1D wave equation needs the following parameters to find the time evolution of the wave equation. You may find the parameters in the dg_maxwell/params.py file. Below is the list of the parameters you need to set before you run the program.

Variable Description
x_nodes The domain of the wave function.
N_LGL The number of LGL points into which an element is split.
N_Elements Number of elements the domain is to be divided into.
scheme The scheme to be used for integration. Values are either
'gauss_quadrature' or 'lobatto_quadrature'
volume_integral_scheme The scheme to integrate the volume integral flux
N_quad The number quadrature points to be used for integration.
c Wave speed.
total_time The total time for which the wave is to be evolved by the simulation.
c_lax The c_lax to be used in the Lax-Friedrichs flux.

You will also have to change the arrayfire backend you want to use in all the files where the function arrayfire.set_backend(< backend >) is being used. You may choose from the following three backends:

  1. cuda
  2. opencl
  3. cpu

Caution: If you change the backend, make sure to change the backend in every file. Failing to do so may result in unexpected errors.

Results

The time evolution of the wave will be stored in the results/1D_Wave_images directory.

To create a video from the images on Ubuntu16.04, follow these steps

sudo apt-get install ffmpeg
cd results/1D_Wave_images
ffmpeg -f image2 -i %04d.png -vcodec mpeg4 -mbd rd -trellis 2 -cmp 2 -g 300 -pass 1 -r 25 -b 18000000 movie.mp4

This will store your video in results/1D_Wave_images/movie.mp4.


In [1]:
import os
import sys
sys.path.insert(0, os.path.abspath('../'))

from dg_maxwell import wave_equation


/home/ubermensch/.local/anaconda3/lib/python3.6/site-packages/numpy/lib/polynomial.py:1193: FutureWarning: In the future extra properties will not be copied across when constructing one poly1d from another
  other = poly1d(other)
/home/ubermensch/.local/anaconda3/lib/python3.6/site-packages/numpy/lib/polynomial.py:1220: FutureWarning: In the future extra properties will not be copied across when constructing one poly1d from another
  other = poly1d(other)

In [2]:
wave_equation.time_evolution()


 25%|██▍       | 77/313 [00:05<00:17, 13.61it/s]Exception ignored in: <object repr() failed>
Traceback (most recent call last):
  File "/home/ubermensch/.local/anaconda3/lib/python3.6/site-packages/arrayfire/array.py", line 550, in __del__
    backend.get().af_release_array(self.arr)
KeyboardInterrupt
 73%|███████▎  | 230/313 [00:12<00:04, 18.81it/s]
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-2-eec26fc11f12> in <module>()
----> 1 wave_equation.time_evolution()

~/workspace/quazar/git/amanabt/DG_Maxwell/dg_maxwell/wave_equation.py in time_evolution()
    762 
    763         # Implementing RK 4 scheme
--> 764         u += RK4_timestepping(A_inverse, u, delta_t)
    765 
    766         # Implementing RK 6 scheme

~/workspace/quazar/git/amanabt/DG_Maxwell/dg_maxwell/wave_equation.py in RK4_timestepping(A_inverse, u, delta_t)
    639     k1 = af.matmul(A_inverse, b_vector(u))
    640     k2 = af.matmul(A_inverse, b_vector(u + k1 * delta_t / 2))
--> 641     k3 = af.matmul(A_inverse, b_vector(u + k2 * delta_t / 2))
    642     k4 = af.matmul(A_inverse, b_vector(u + k3 * delta_t))
    643 

~/.local/anaconda3/lib/python3.6/site-packages/arrayfire/array.py in __mul__(self, other)
    869         Return self * other.
    870         """
--> 871         return _binary_func(self, other, backend.get().af_mul)
    872 
    873     def __imul__(self, other):

~/.local/anaconda3/lib/python3.6/site-packages/arrayfire/array.py in _binary_func(lhs, rhs, c_func)
    165     other = rhs
    166 
--> 167     if (_is_number(rhs)):
    168         ldims = dim4_to_tuple(lhs.dims())
    169         rty = implicit_dtype(rhs, lhs.type())

~/.local/anaconda3/lib/python3.6/site-packages/arrayfire/util.py in _is_number(a)
     25 
     26 def _is_number(a):
---> 27     return isinstance(a, numbers.Number)
     28 
     29 def number_dtype(a):

KeyboardInterrupt: 
 73%|███████▎  | 230/313 [00:30<00:10,  7.66it/s]

In [ ]: