Skip to content

Commit

Permalink
Merge branch 'master' into lax_friedrichs_flux
Browse files Browse the repository at this point in the history
  • Loading branch information
Balavarun5 authored Sep 8, 2017
2 parents 457f42d + 08b38d7 commit 28729c3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@amanabt
@Balavarun5
@mchandra
6 changes: 3 additions & 3 deletions code/app/global_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def LGL_points(N):

return lgl_points


def lobatto_weight_function(n, x):
'''
Calculates and returns the weight function for an index :math:`n`
Expand All @@ -64,9 +63,10 @@ def lobatto_weight_function(n, x):
Returns
-------
gauss_lobatto_weights : arrayfire.Array
An array of lobatto weight functions for
the given :math: `x` points and index.
An array of lobatto weight functions for
the given :math: `x` points and index.
Reference
---------
Gauss-Lobatto weights Wikipedia link-
Expand Down
4 changes: 1 addition & 3 deletions code/app/lagrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,4 @@ def dLp_xi_LGL(lagrange_coeff_array):

dLp_xi = af.blas.matmul(differentiation_coeffs, nodes_power_tile)

return dLp_xi


return dLp_xi
20 changes: 10 additions & 10 deletions code/app/wave_equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
plt.rcParams['ytick.direction'] = 'in'



def mapping_xi_to_x(x_nodes, xi):
'''
Maps points in :math: `\\xi` space to :math:`x` space using the formula
Expand All @@ -63,15 +62,15 @@ def mapping_xi_to_x(x_nodes, xi):
N_0 = (1 - xi) / 2
N_1 = (1 + xi) / 2


N0_x0 = af.broadcast(utils.multiply, N_0, x_nodes[0])
N1_x1 = af.broadcast(utils.multiply, N_1, x_nodes[1])

x = N0_x0 + N1_x1

return x




def dx_dxi_numerical(x_nodes, xi):
'''
Differential :math: `\\frac{dx}{d \\xi}` calculated by central differential
Expand All @@ -92,6 +91,7 @@ def dx_dxi_numerical(x_nodes, xi):
:math:`\\frac{dx}{d \\xi}`.
'''
dxi = 1e-7

x2 = mapping_xi_to_x(x_nodes, xi + dxi)
x1 = mapping_xi_to_x(x_nodes, xi - dxi)

Expand Down Expand Up @@ -120,7 +120,6 @@ def dx_dxi_analytical(x_nodes, xi):

return analytical_dx_dxi


def A_matrix():
'''
Calculates A matrix whose elements :math:`A_{p i}` are given by
Expand Down Expand Up @@ -153,13 +152,13 @@ def A_matrix():

def flux_x(u):
'''
A function which returns the value of flux for a given wave function u.
:math:`f(u) = c u^k`
A function which calcultes and returns the value of flux for a given
wave function u. :math:`f(u) = c u^k`
Parameters
----------
u : arrayfire.Array
A 1-D array which contains the value of wave function.
u : arrayfire.Array [N 1 1 1]
A 1-D array which contains the value of wave function.
Returns
-------
Expand All @@ -181,6 +180,7 @@ def volume_integral_flux(u):
Parameters
----------
u : arrayfire.Array [N_LGL N_Elements 1 1]
A 1-D array containing the value of the wave function at
the mapped LGL nodes in the element.
Expand All @@ -192,6 +192,7 @@ def volume_integral_flux(u):
for various lagrange basis functions.
'''


dLp_xi = gvar.dLp_xi
weight_tile = af.transpose(af.tile(gvar.lobatto_weights, 1, gvar.N_LGL))
dLp_xi *= weight_tile
Expand Down Expand Up @@ -323,5 +324,4 @@ def time_evolution():
fig.savefig('results/1D_Wave_images/%04d' %(t_n / 100) + '.png')
plt.close('all')

return

return
3 changes: 2 additions & 1 deletion code/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@

if __name__ == '__main__':

wave_equation.time_evolution()

wave_equation.time_evolution()
16 changes: 13 additions & 3 deletions code/unit_test/test_waveEqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
af.set_backend('opencl')



def test_mapping_xi_to_x():
'''
A test function to check the mapping_xi_to_x function in wave_equation module,
Expand All @@ -21,18 +22,20 @@ def test_mapping_xi_to_x():
test_element_nodes = af.interop.np_to_af_array(np.array([7, 11]))
test_xi = 0
analytical_x_value = 9

numerical_x_value = wave_equation.mapping_xi_to_x(test_element_nodes, test_xi)

assert af.abs(analytical_x_value - numerical_x_value) <= threshold


def test_dx_dxi():
'''
A Test function to check the dx_xi function in wave_equation module by
passing nodes of an element and using the LGL points. Analytically, the
differential would be a constant. The check has a tolerance 1e-7.
'''

threshold = 1e-14

nodes = np.array([7, 10], dtype = np.float64)
test_nodes = af.interop.np_to_af_array(nodes)
analytical_dx_dxi = 1.5
Expand All @@ -56,6 +59,7 @@ def test_dx_dxi_analytical():
assert check_analytical_dx_dxi



def test_lagrange_coeffs():
'''
Function to test the lagrange_coeffs in global_variables module by
Expand All @@ -69,6 +73,7 @@ def test_lagrange_coeffs():
https://cocalc.com/projects/1b7f404c-87ba-40d0-816c-2eba17466aa8/files
/PM_2_5/wave_equation/worksheets/l_basis_array.sagews
'''

threshold = 6e-10
basis_array_analytical = np.zeros([8, 8])

Expand Down Expand Up @@ -142,6 +147,7 @@ def test_lagrange_coeffs():

basis_array_analytical = af.interop.np_to_af_array(basis_array_analytical)


assert af.sum(af.abs(basis_array_analytical - gvar.lagrange_coeffs)) < threshold


Expand All @@ -153,6 +159,7 @@ def test_integral_Li_Lp():
all elements above a certain threshold to be 1 and plotting it.
'''
threshold = 1e-5

A_matrix_structure = np.zeros([gvar.N_LGL, gvar.N_LGL])
non_zero_indices = np.where(np.array(wave_equation.A_matrix()) > threshold)

Expand All @@ -178,6 +185,7 @@ def test_A_matrix():
The A matrix calculated analytically gives a different matrix.
'''

threshold = 3e-10

reference_A_matrix = af.tile(gvar.lobatto_weights, 1, gvar.N_LGL)\
Expand All @@ -188,6 +196,7 @@ def test_A_matrix():
test_A_matrix = wave_equation.A_matrix()
error_array = af.abs(reference_A_matrix - test_A_matrix)


print(af.max(error_array))

assert af.algorithm.max(error_array) < threshold
Expand Down Expand Up @@ -235,7 +244,6 @@ def test_dLp_xi():

assert af.max(reference_d_Lp_xi - gvar.dLp_xi) < threshold


def test_volume_integral_flux():
'''
A test function to check the volume_integral_flux function in wave_equation
Expand All @@ -245,6 +253,7 @@ def test_volume_integral_flux():
---------
The link to the sage worksheet where the calculations were caried out is
given below.
https://cocalc.com/projects/1b7f404c-87ba-40d0-816c-2eba17466aa8/files
/PM_2_5/wave_equation/worksheets/volume_integral_flux.sagews
Expand Down Expand Up @@ -273,6 +282,7 @@ def test_volume_integral_flux():
[-0.102576031756, 0.0154359890788, 0.0209837936827, 0.019612124119, \
0.0144355176966, 0.00882630935977, 0.00431252844519, 0.018969769374],\
[-0.0176615086879, 0.00344551201015 ,0.00432019709409, 0.00362050204766,\

0.00236838757932, 0.00130167737191, 0.000588597708116, 0.00201663487667\
]])))

Expand Down Expand Up @@ -335,4 +345,4 @@ def test_b_vector():
(surface_term)) * gvar.delta_t
b_vector_array = wave_equation.b_vector(gvar.u[:, :, 0])

assert (b_vector_analytical - b_vector_array) < threshold
assert (b_vector_analytical - b_vector_array) < threshold
12 changes: 9 additions & 3 deletions code/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
def add(a, b):
'''
'''
return a + b
sum = a + b

return sum


def divide(a, b):
'''
'''
return a / b
quotient = a / b

return quotient


def multiply(a, b):
'''
'''
return a * b
product = a* b

return product


def linspace(start, end, number_of_points):
Expand Down

0 comments on commit 28729c3

Please sign in to comment.