Peano
Loading...
Searching...
No Matches
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#
16import os
17import peano4
18import peano4.datamodel
19import peano4.solversteps
20import peano4.output
21import peano4.visualisation
23
24
25import exahype2
26
27
28#
29# Lets first clean up all plot files, so we don't get a mismatch
30#
31output_files = [ f for f in os.listdir(".") if f.endswith(".peano-patch-file") or f.endswith(".vtu") ]
32for 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#
40project = exahype2.Project( ["examples", "exahype2", "finitevolumes"], "finitevolumes", "." )
41
42
43#
44# Add the Finite Volumes solver
45#
46patch_size = 23
47unknowns = 9
48time_step_size = 0.01
49project.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
61dimensions = 2
62build_mode = peano4.output.CompileMode.Asserts
63
64#
65# Lets configure some global parameters
66#
67if 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 )
73else:
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
82peano4_project = project.generate_Peano4_project()
83
84peano4_project.output.makefile.parse_configure_script_outcome( "../../.." )
85peano4_project.output.makefile.set_mode(build_mode)
86
87peano4_project.output.makefile.add_Fortran_file( "Parameters.f90" )
88peano4_project.output.makefile.add_Fortran_file( "C2P-MHD.f90" )
89peano4_project.output.makefile.add_Fortran_file( "C2PRoutines.f90" )
90peano4_project.output.makefile.add_Fortran_file( "PDE.f90" )
91peano4_project.output.makefile.add_Fortran_file( "InitialData.f90" )
92
93peano4_project.generate(peano4.output.Overwrite.Default)
94peano4_project.build()
95success = peano4_project.run( [] )
96
97
98if 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