Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f374dc5
Initial commit for the Python backend. A shell script is used for sta…
simonius Dec 12, 2018
0e4d769
bugfix for intel OpenCL, some cleanups
simonius Dec 19, 2018
6d1b033
added axis labels
simonius Dec 19, 2018
9c5b1e4
merge with master
simonius Feb 21, 2019
246128c
bugfix and preparation for MHD Boundary conditions
simonius Feb 21, 2019
4eb3793
boundary conditions for MHD
simonius Feb 21, 2019
22d4739
Merge commit '4eb3793' into pythonbackend
simonius Feb 21, 2019
03e8aa3
initial AoS SoA support without correct printing
simonius Feb 21, 2019
0b63d45
applied requested changes
simonius Feb 22, 2019
29f4a28
Merge commit '0b63d45' into pythonbackend
simonius Feb 22, 2019
97c2972
applied requested changes
simonius Feb 22, 2019
566cfba
merge
simonius Feb 22, 2019
6fbddd4
used a Macro instead of pow(..., 2)
simonius Feb 23, 2019
6cac93f
Merge commit '6fbddd4' into pythonbackend
simonius Feb 23, 2019
91ec609
merge from master
Apr 17, 2019
023cec7
changed the code to reflect the changes in the master tree, added the…
Apr 26, 2019
513515d
changed the dipole position
May 22, 2019
e2b2ab5
saving hdf5 snapshots on the fly
simonius May 22, 2019
507c636
ideal_MHD_B0.py
May 24, 2019
67d3058
Merge branch 'master' of git://github.com/IANW-Projects/ConservationL…
Jun 5, 2019
e0af8dd
adjustments for the master tree and the new Lax-Friedrichs Flux
Jun 5, 2019
8cca89c
Merge branch 'pythonbackend' of https://github.com/simonius/Conservat…
Jun 5, 2019
15ad872
changed time accounting and added the ability to reload the fields ou…
Jun 21, 2019
d4c2c97
bugfix
Jun 21, 2019
ffcb406
added loading of variables
Jun 21, 2019
4b7838a
bugfix
Jun 24, 2019
b70e9aa
changes for the new testcase
Jul 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<<<<<<< HEAD
# Python files
=======
# MatCL files
matlab/*.mexa64
matlab/*.mexmaci64
Expand All @@ -8,6 +11,7 @@ matlab/*.mexw64
*/*.m~

# python files
>>>>>>> 98f26b21b4
__pycache__/
*.py[cod]
*$py.class
Expand Down
87 changes: 87 additions & 0 deletions examples/ideal_MHD.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import numpy as np
import sys
import math



prepare_vars()


N_fac = 1

I_Mesh['NODES_X'] = int(N_fac * 58)
I_Mesh['NODES_Y'] = int(N_fac * 100)
I_Mesh['NODES_Z'] = int(N_fac * 12)

I_Mesh['XMIN'] = 0.0
I_Mesh['YMIN'] = 0.0
I_Mesh['ZMIN'] = 0.0

I_Mesh['XMAX'] = 2.0/math.sqrt(3)
I_Mesh['YMAX'] = 2.0
I_Mesh['ZMAX'] = 1.0

I_TI['final_time'] = 5
I_TI['cfl'] = 0.3

dt = I_TI['cfl'] * 2.0 / float(I_Mesh['NODES_Y'])
num_steps = math.ceil(I_TI['final_time']/dt)
dt = I_TI['final_time'] / num_steps

I_TI['time_integrator'] = 'CarpenterKennedy2N54'

I_TI['DT'] = dt
I_TI['num_steps'] = num_steps

# I_Tech['device'] = 1

I_Tech['REAL'] = 'double'
I_Tech['REAL4'] = I_Tech['REAL'] + "4"
I_Tech['memory_layout'] = 'USE_ARRAY_OF_STRUCTURES'#'USE_STRUCTURE_OF_ARRAYS'


I_BalanceLaws['NUM_CONSERVED_VARS'] = 8
I_BalanceLaws['NUM_AUXILIARY_VARS'] = 4
I_BalanceLaws['NUM_TOTAL_VARS'] = I_BalanceLaws['NUM_CONSERVED_VARS'] + I_BalanceLaws['NUM_AUXILIARY_VARS']

# Compiler based optimizations

if I_Tech['REAL'] == 'float':
I_Tech['optimizations'] = ' -cl-mad-enable -cl-no-signed-zeros -cl-finite-math-only -cl-single-precision-constant'
else:
I_Tech['optimizations'] = ' -cl-mad-enable -cl-no-signed-zeros -cl-finite-math-only'

I_RunOps['periodicx'] = 'None' #'USE_PERIODIC_X'
I_RunOps['periodicy'] = 'None' #'USE_PERIODIC_Y'
I_RunOps['periodicz'] = 'None' #'USE_PERIODIC_Z'

I_RunOps['order'] = 4
I_RunOps['conservation_laws'] = 'ideal_MHD'
I_RunOps['testcase'] = 'alfven_periodic'
I_RunOps['plot_numerical_solution'] = 'z'
I_RunOps['save_integrals_over_time'] = False
I_RunOps['norm'] = 'LInf'

## Initialize

field_u1, field_u2 = initialize()


print('Testcase: ' + I_RunOps['testcase'] + '\nOrder: ' + str(I_RunOps['order']) + '\nTime integrator: ' + \
I_TI['time_integrator'] +' \nDT: ' + str(I_TI['DT']) + '\nN_STEPS: ' +str(I_TI['num_steps']) + " FINAL_TIME: " + \
str(I_TI['final_time']) + '\nDX: ' + str(I_Mesh['DX']) + ' NODES_X: ' +str(I_Mesh['NODES_X'])+'\nDY: '+ str(I_Mesh['DY']) + \
' NODES_Y: ' + str(I_Mesh['NODES_Y']) + '\nDZ: ' + str(I_Mesh['DZ'])+ ' NODES_Z: ' + str(I_Mesh['NODES_Z']) + '\nREAL: ' + \
str(I_Tech['REAL']))

compute_numerical_solution(field_u1, field_u2)

rel_err = I_Results['rel_err']
for comp in range(I_BalanceLaws['NUM_CONSERVED_VARS']):
print("Relative Error of Field Component " + str(comp) +": " + str(100*rel_err[comp]))


field_u1_reshaped = np.reshape(field_u1, (I_Tech['NUM_NODES_PAD'], I_BalanceLaws['NUM_TOTAL_VARS']))


save_all_variables(field_u1_reshaped, "output.hdf5", ['rho', 'px', 'py', 'pz', 'E', 'Bx', 'By', 'Bz'])
plot_2D(field_u1_reshaped, I_RunOps['plot_numerical_solution'], I_Mesh['NODES_X'], I_Mesh['NODES_Y'], I_Mesh['NODES_Z'], 'Numerical Solution', 1,1)
90 changes: 90 additions & 0 deletions examples/ideal_MHD_B0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import numpy as np
import sys
import math

prepare_vars()


N_fac = 1

I_Mesh['NODES_X'] = int(N_fac * 100)
I_Mesh['NODES_Y'] = int(N_fac * 100)
I_Mesh['NODES_Z'] = int(N_fac * 100)

I_Mesh['XMIN'] = 0.0
I_Mesh['YMIN'] = 0.0
I_Mesh['ZMIN'] = 0.0

I_Mesh['XMAX'] = 1.0
I_Mesh['YMAX'] = 1.0
I_Mesh['ZMAX'] = 1.0

I_TI['final_time'] = 0.1
I_TI['cfl'] = 0.2
k = 100

dt = I_TI['cfl'] * 2.0 / float(I_Mesh['NODES_Y']) # this has to be estimated
num_steps = math.ceil(I_TI['final_time']/dt)
dt = I_TI['final_time'] / num_steps

I_TI['time_integrator'] = 'CarpenterKennedy2N54'

I_TI['DT'] = dt
I_TI['num_steps'] = num_steps

# I_Tech['device'] = 1

I_Tech['REAL'] = 'double'
I_Tech['REAL4'] = I_Tech['REAL'] + "4"
I_Tech['memory_layout'] = 'USE_ARRAY_OF_STRUCTURES' #'USE_STRUCTURE_OF_ARRAYS'


I_BalanceLaws['NUM_CONSERVED_VARS'] = 8
I_BalanceLaws['NUM_AUXILIARY_VARS'] = 4
I_BalanceLaws['NUM_TOTAL_VARS'] = I_BalanceLaws['NUM_CONSERVED_VARS'] + I_BalanceLaws['NUM_AUXILIARY_VARS']

# Compiler based optimizations

if I_Tech['REAL'] == 'float':
I_Tech['optimizations'] = ' -cl-mad-enable -cl-no-signed-zeros -cl-finite-math-only -cl-single-precision-constant'
else:
I_Tech['optimizations'] = ' -cl-mad-enable -cl-no-signed-zeros -cl-finite-math-only'

I_RunOps['periodic'] = 'none'# 'USE_PERIODIC'
I_RunOps['vr'] = 'none'#'USE_VR_KUSANO'

I_RunOps['order'] = 4
I_RunOps['conservation_laws'] = 'ideal_MHD'
I_RunOps['testcase'] = 'B0'
I_RunOps['plot_numerical_solution'] = 'z'
I_RunOps['save_integrals_over_time'] = False
I_RunOps['norm'] = 'LInf'

## Initialize

field_u1, field_u2 = initialize()


print('Testcase: ' + I_RunOps['testcase'] + '\nOrder: ' + str(I_RunOps['order']) + '\nTime integrator: ' + \
I_TI['time_integrator'] +' \nDT: ' + str(I_TI['DT']) + '\nN_STEPS: ' +str(I_TI['num_steps']) + " FINAL_TIME: " + \
str(I_TI['final_time']) + '\nDX: ' + str(I_Mesh['DX']) + ' NODES_X: ' +str(I_Mesh['NODES_X'])+'\nDY: '+ str(I_Mesh['DY']) + \
' NODES_Y: ' + str(I_Mesh['NODES_Y']) + '\nDZ: ' + str(I_Mesh['DZ'])+ ' NODES_Z: ' + str(I_Mesh['NODES_Z']) + '\nREAL: ' + \
str(I_Tech['REAL']))

print(str(k) + " snapshots")
for i in range(k):
compute_numerical_solution(field_u1, field_u2)
save_all_variables(field_u1, "results/output" + str(i) + ".hdf5", ['rho', 'px', 'py', 'pz', 'E', 'Bx', 'By', 'Bz'])
print(i)

#rel_err = I_Results['rel_err']
#for comp in range(I_BalanceLaws['NUM_CONSERVED_VARS']):
# print("Relative Error of Field Component " + str(comp) +": " + str(100*rel_err[comp]))


#field_u1_reshaped = np.reshape(field_u1, (I_Tech['NUM_NODES_PAD'], I_BalanceLaws['NUM_TOTAL_VARS']))



#plot_fieldlines_B(field_u1_reshaped, I_RunOps['plot_numerical_solution'], I_Mesh['NODES_X'], I_Mesh['NODES_Y'], I_Mesh['NODES_Z'], 'Numerical Solution', Field_Bx, Field_By)
#plot_2D(field_u1_reshaped, I_RunOps['plot_numerical_solution'], I_Mesh['NODES_X'], I_Mesh['NODES_Y'], I_Mesh['NODES_Z'], 'Numerical Solution', Field_By,Field_By)
98 changes: 98 additions & 0 deletions examples/ideal_MHD_dipole.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import numpy as np
import sys
import math

prepare_vars()


N_fac = 1

I_Mesh['NODES_X'] = int(N_fac * 100)
I_Mesh['NODES_Y'] = int(N_fac * 100)
I_Mesh['NODES_Z'] = int(N_fac * 100)

I_Mesh['XMIN'] = 0.0
I_Mesh['YMIN'] = 0.0
I_Mesh['ZMIN'] = 0.0

I_Mesh['XMAX'] = 1.0
I_Mesh['YMAX'] = 1.0
I_Mesh['ZMAX'] = 1.0

I_TI['final_time'] = 0.1
I_TI['cfl'] = 0.2
k = 10

dt = I_TI['cfl'] * 2.0 / float(I_Mesh['NODES_Y']) # this has to be estimated
num_steps = math.ceil(I_TI['final_time']/dt)
dt = I_TI['final_time'] / num_steps

I_TI['time_integrator'] = 'CarpenterKennedy2N54'

I_TI['DT'] = dt
I_TI['num_steps'] = num_steps

# I_Tech['device'] = 1

I_Tech['REAL'] = 'float' #'double'
I_Tech['REAL4'] = I_Tech['REAL'] + "4"
I_Tech['memory_layout'] = 'USE_ARRAY_OF_STRUCTURES' #'USE_STRUCTURE_OF_ARRAYS'


I_BalanceLaws['NUM_CONSERVED_VARS'] = 8
I_BalanceLaws['NUM_AUXILIARY_VARS'] = 4
I_BalanceLaws['NUM_TOTAL_VARS'] = I_BalanceLaws['NUM_CONSERVED_VARS'] + I_BalanceLaws['NUM_AUXILIARY_VARS']

# Compiler based optimizations

if I_Tech['REAL'] == 'float':
I_Tech['optimizations'] = ' -cl-mad-enable -cl-no-signed-zeros -cl-finite-math-only -cl-single-precision-constant'
else:
I_Tech['optimizations'] = ' -cl-mad-enable -cl-no-signed-zeros -cl-finite-math-only'

I_RunOps['periodicx'] = 'none'# 'USE_PERIODIC'
I_RunOps['periodicy'] = 'none'
I_RunOps['periodicz'] = 'none'

I_RunOps['vr'] = 'none'#'USE_VR_KUSANO'

I_RunOps['order'] = 2
I_RunOps['conservation_laws'] = 'ideal_MHD'
I_RunOps['testcase'] = 'far_dipole'
I_RunOps['plot_numerical_solution'] = 'z'
I_RunOps['save_integrals_over_time'] = False
I_RunOps['norm'] = 'LInf'

## Initialize

field_u1, field_u2 = initialize()

if len(sys.argv) > 1:
field_u1 = reload_all_variables(field_u1, sys.argv[1], ['rho', 'px', 'py', 'pz', 'E', 'Bx', 'By', 'Bz'])
print(f"reloaded the conserved variables out of {sys.argv[1]}")

print('Testcase: ' + I_RunOps['testcase'] + '\nOrder: ' + str(I_RunOps['order']) + '\nTime integrator: ' + \
I_TI['time_integrator'] +' \nDT: ' + str(I_TI['DT']) + '\nN_STEPS: ' +str(I_TI['num_steps']) + " FINAL_TIME: " + \
str(I_TI['final_time']) + '\nDX: ' + str(I_Mesh['DX']) + ' NODES_X: ' +str(I_Mesh['NODES_X'])+'\nDY: '+ str(I_Mesh['DY']) + \
' NODES_Y: ' + str(I_Mesh['NODES_Y']) + '\nDZ: ' + str(I_Mesh['DZ'])+ ' NODES_Z: ' + str(I_Mesh['NODES_Z']) + '\nREAL: ' + \
str(I_Tech['REAL']))

print(str(k) + " snapshots")
ct = False

for i in range(k):
ct = compute_numerical_solution(field_u1, field_u2, ct)
save_all_variables(field_u1, "results/output" + str(i) + ".hdf5", ['rho', 'px', 'py', 'pz', 'E', 'Bx', 'By', 'Bz'])
print(i)

#rel_err = I_Results['rel_err']
#for comp in range(I_BalanceLaws['NUM_CONSERVED_VARS']):
# print("Relative Error of Field Component " + str(comp) +": " + str(100*rel_err[comp]))


#field_u1_reshaped = np.reshape(field_u1, (I_Tech['NUM_NODES_PAD'], I_BalanceLaws['NUM_TOTAL_VARS']))



#plot_fieldlines_B(field_u1_reshaped, I_RunOps['plot_numerical_solution'], I_Mesh['NODES_X'], I_Mesh['NODES_Y'], I_Mesh['NODES_Z'], 'Numerical Solution', Field_Bx, Field_By)
#plot_2D(field_u1_reshaped, I_RunOps['plot_numerical_solution'], I_Mesh['NODES_X'], I_Mesh['NODES_Y'], I_Mesh['NODES_Z'], 'Numerical Solution', Field_By,Field_By)
98 changes: 98 additions & 0 deletions examples/ideal_MHD_ulf_p.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import numpy as np
import sys
import math

prepare_vars()


N_fac = 1

I_Mesh['NODES_X'] = int(N_fac * 100)
I_Mesh['NODES_Y'] = int(N_fac * 100)
I_Mesh['NODES_Z'] = int(N_fac * 100)

I_Mesh['XMIN'] = 0.0
I_Mesh['YMIN'] = 0.0
I_Mesh['ZMIN'] = 0.0

I_Mesh['XMAX'] = 1.0
I_Mesh['YMAX'] = 1.0
I_Mesh['ZMAX'] = 1.0

I_TI['final_time'] = 0.1
I_TI['cfl'] = 0.2
k = 10

dt = I_TI['cfl'] * 2.0 / float(I_Mesh['NODES_Y']) # this has to be estimated
num_steps = math.ceil(I_TI['final_time']/dt)
dt = I_TI['final_time'] / num_steps

I_TI['time_integrator'] = 'CarpenterKennedy2N54'

I_TI['DT'] = dt
I_TI['num_steps'] = num_steps

# I_Tech['device'] = 1

I_Tech['REAL'] = 'float' #'double'
I_Tech['REAL4'] = I_Tech['REAL'] + "4"
I_Tech['memory_layout'] = 'USE_ARRAY_OF_STRUCTURES' #'USE_STRUCTURE_OF_ARRAYS'


I_BalanceLaws['NUM_CONSERVED_VARS'] = 8
I_BalanceLaws['NUM_AUXILIARY_VARS'] = 4
I_BalanceLaws['NUM_TOTAL_VARS'] = I_BalanceLaws['NUM_CONSERVED_VARS'] + I_BalanceLaws['NUM_AUXILIARY_VARS']

# Compiler based optimizations

if I_Tech['REAL'] == 'float':
I_Tech['optimizations'] = ' -cl-mad-enable -cl-no-signed-zeros -cl-finite-math-only -cl-single-precision-constant'
else:
I_Tech['optimizations'] = ' -cl-mad-enable -cl-no-signed-zeros -cl-finite-math-only'

I_RunOps['periodicx'] = 'none'# 'USE_PERIODIC'
I_RunOps['periodicy'] = 'none'
I_RunOps['periodicz'] = 'none'

I_RunOps['vr'] = 'none'#'USE_VR_KUSANO'

I_RunOps['order'] = 6
I_RunOps['conservation_laws'] = 'ideal_MHD'
I_RunOps['testcase'] = 'ufp'
I_RunOps['plot_numerical_solution'] = 'z'
I_RunOps['save_integrals_over_time'] = False
I_RunOps['norm'] = 'LInf'

## Initialize

field_u1, field_u2 = initialize()

if len(sys.argv) > 1:
field_u1 = reload_all_variables(field_u1, sys.argv[1], ['rho', 'px', 'py', 'pz', 'E', 'Bx', 'By', 'Bz'])
print(f"reloaded the conserved variables out of {sys.argv[1]}")

print('Testcase: ' + I_RunOps['testcase'] + '\nOrder: ' + str(I_RunOps['order']) + '\nTime integrator: ' + \
I_TI['time_integrator'] +' \nDT: ' + str(I_TI['DT']) + '\nN_STEPS: ' +str(I_TI['num_steps']) + " FINAL_TIME: " + \
str(I_TI['final_time']) + '\nDX: ' + str(I_Mesh['DX']) + ' NODES_X: ' +str(I_Mesh['NODES_X'])+'\nDY: '+ str(I_Mesh['DY']) + \
' NODES_Y: ' + str(I_Mesh['NODES_Y']) + '\nDZ: ' + str(I_Mesh['DZ'])+ ' NODES_Z: ' + str(I_Mesh['NODES_Z']) + '\nREAL: ' + \
str(I_Tech['REAL']))

print(str(k) + " snapshots")
ct = False

for i in range(k):
ct = compute_numerical_solution(field_u1, field_u2, ct)
save_all_variables(field_u1, "results/output" + str(i) + ".hdf5", ['rho', 'px', 'py', 'pz', 'E', 'Bx', 'By', 'Bz'])
print(i)

#rel_err = I_Results['rel_err']
#for comp in range(I_BalanceLaws['NUM_CONSERVED_VARS']):
# print("Relative Error of Field Component " + str(comp) +": " + str(100*rel_err[comp]))


#field_u1_reshaped = np.reshape(field_u1, (I_Tech['NUM_NODES_PAD'], I_BalanceLaws['NUM_TOTAL_VARS']))



#plot_fieldlines_B(field_u1_reshaped, I_RunOps['plot_numerical_solution'], I_Mesh['NODES_X'], I_Mesh['NODES_Y'], I_Mesh['NODES_Z'], 'Numerical Solution', Field_Bx, Field_By)
#plot_2D(field_u1_reshaped, I_RunOps['plot_numerical_solution'], I_Mesh['NODES_X'], I_Mesh['NODES_Y'], I_Mesh['NODES_Z'], 'Numerical Solution', Field_By,Field_By)
Loading