Peano
finitevolumes.py
Go to the documentation of this file.
1 """
2 
3  A very simple example which demonstrates how to configure a patch-based
4  Finite Volume solver in Peano4. The code relies on snippets from ExaHyPE2.
5  However, it relies only on ExaHyPE's C/FORTRAN compute kernels, i.e. the
6  sophisticated build environment of this H2020 project is not used. The
7  solver simulates the simple MHD equations.
8 
9 """
10 
11 
12 #
13 # We import Peano4 as project. If this step fails, ensure that your environment
14 # variable PYTHONPATH points to Peano4's python directory.
15 #
16 import os
17 import peano4
18 import peano4.datamodel
19 import peano4.solversteps
20 import peano4.output
21 import peano4.visualisation
23 
24 
25 import exahype2
26 
27 
28 #
29 # Lets first clean up all plot files, so we don't get a mismatch
30 #
31 output_files = [ f for f in os.listdir(".") if f.endswith(".peano-patch-file") or f.endswith(".vtu") ]
32 for f in output_files:
33  os.remove(f)
34 
35 
36 #
37 # Create a project and configure it to end up in a subnamespace (and thus
38 # subdirectory).
39 #
40 project = exahype2.Project( ["examples", "exahype2", "finitevolumes"], "finitevolumes", "." )
41 
42 
43 #
44 # Add the Finite Volumes solver
45 #
46 patch_size = 23
47 unknowns = 9
48 time_step_size = 0.01
49 project.add_solver( exahype2.solvers.fv.GenericRusanovFixedTimeStepSize(
50  name="MHD",
51  patch_size=patch_size,
52  unknowns=unknowns,
53  auxiliary_variables=0,
54  min_h=0.1,
55  max_h=0.1,
56  time_step_size=0.001,
57  #flux=PDETerms.User_Defined_Implementation, ncp=None, plot_grid_properties=False
58 ))
59 
60 
61 dimensions = 2
62 build_mode = peano4.output.CompileMode.Asserts
63 
64 #
65 # Lets configure some global parameters
66 #
67 if dimensions==2:
68  project.set_global_simulation_parameters(
69  dimensions, [0.0,0.0], [1.0,1.0],
70  0.1, # end time
71  0.0, 0.1 # snapshots
72  )
73 else:
74  project.set_global_simulation_parameters(
75  dimensions, [0.0,0.0,0.0], [1.0,1.0,1.0],
76  1.0, # end time
77  0.0, 0.1
78  )
79 
80 
81 
82 peano4_project = project.generate_Peano4_project()
83 
84 peano4_project.output.makefile.parse_configure_script_outcome( "../../.." )
85 peano4_project.output.makefile.set_mode(build_mode)
86 
87 peano4_project.output.makefile.add_Fortran_file( "Parameters.f90" )
88 peano4_project.output.makefile.add_Fortran_file( "C2P-MHD.f90" )
89 peano4_project.output.makefile.add_Fortran_file( "C2PRoutines.f90" )
90 peano4_project.output.makefile.add_Fortran_file( "PDE.f90" )
91 peano4_project.output.makefile.add_Fortran_file( "InitialData.f90" )
92 
93 peano4_project.generate(peano4.output.Overwrite.Default)
94 peano4_project.build()
95 success = peano4_project.run( [] )
96 
97 
98 if success:
99  convert = peano4.visualisation.Convert( "solutionMHD", True )
100  convert.set_visualisation_tools_path( "../../../../src/visualisation" )
101  convert.extract_fine_grid()
102  convert.convert_to_vtk()
103 
104 
105