Peano
Loading...
Searching...
No Matches
fd.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import peano4
4import exahype2
5
6parser = exahype2.ArgumentParser("ExaHyPE 2 - Finite Differences Testing Script")
7
8parser.set_defaults(
9 min_depth=-1,
10 degrees_of_freedom=16,
11 end_time=0.5,
12 time_step_relaxation=0.4,
13 periodic_boundary_conditions_x=False,
14 periodic_boundary_conditions_y=False,
15 periodic_boundary_conditions_z=False,
16)
17args = parser.parse_args()
18
19"""
20/****************************************************************************************************************************************
21 * Aluminium *
22 * *
23 * References: *
24 * Zhang A, Li Y. Thermal Conductivity of Aluminum Alloys-A Review. Materials (Basel). 2023 Apr 8;16(8):2972. doi: 10.3390/ma16082972. *
25 * https://webbook.nist.gov/cgi/inchi/InChI%3D1S/Al, accessed on 12/09/2025 *
26 ****************************************************************************************************************************************/
27"""
28
29MOLAR_HEAT_CAPACITY = 25.78 # in J / (mol * K)
30MOLAR_WEIGHT = 0.0269815386 # in kg / mol
31THERMAL_CONDUCTIVITY = 237 # in W / (m * K)
32DENSITY = 2700 # in kg / m^3
33SPECIFIC_HEAT_CAPACITY = MOLAR_HEAT_CAPACITY / MOLAR_WEIGHT # in J / (kg * K)
34THERMAL_DIFFUSIVITY = THERMAL_CONDUCTIVITY / (
35 SPECIFIC_HEAT_CAPACITY * DENSITY
36) # in m^2 / s
37
38initial_conditions = """
39 Q[Shortcuts::T] = 400; // in K
40 Q[Shortcuts::kappa] = THERMAL_DIFFUSIVITY;
41"""
42
43boundary_conditions = """
44 // normal == 0 => left
45 // normal == 1 => bottom
46 // normal == 2 => right
47 // normal == 3 => top
48 if (normal == 0) {
49 // Heat sink
50 Qoutside0[Shortcuts::T] = 300; // in K
51 Qoutside0[Shortcuts::kappa] = Qinside[Shortcuts::kappa];
52 } else {
53 // Insulation everywhere else
54 Qoutside0[Shortcuts::T] = Qinside[Shortcuts::T];
55 Qoutside0[Shortcuts::kappa] = Qinside[Shortcuts::kappa];
56 }
57"""
58
59max_h = 0.0007
60min_h = 0.0007
61
62fd_solver = exahype2.solvers.fd.GlobalFixedTimeStep(
63 name="FDSolver",
64 patch_size=args.degrees_of_freedom,
65 unknowns={"T": 1},
66 auxiliary_variables={"kappa": 1},
67 min_h=min_h,
68 max_h=max_h,
69 normalised_time_step_size=(
70 args.time_step_relaxation * (min_h) ** 2 / THERMAL_DIFFUSIVITY
71 ),
72 order=1,
73)
74
75fd_solver.set_implementation(
76 initial_conditions=initial_conditions,
77 boundary_conditions=boundary_conditions,
78 solver="""
79 {{COMPUTE_PRECISION}} temperatureLaplacian = 0.0;
80 // x-direction
81 temperatureLaplacian += (QRight0[Shortcuts::T] - 2.0 * Q[Shortcuts::T] + QLeft0[Shortcuts::T]) / (h(0) * h(0));
82 // y-direction
83 temperatureLaplacian += (QTop0[Shortcuts::T] - 2.0 * Q[Shortcuts::T] + QDown0[Shortcuts::T]) / (h(1) * h(1));
84#if DIMENSIONS == 3
85 // z-direction
86 temperatureLaplacian += (QFront0[Shortcuts::T] - 2.0 * Q[Shortcuts::T] + QBack0[Shortcuts::T]) / (h(2) * h(2));
87#endif
88
89 QNew[Shortcuts::T] = Q[Shortcuts::T] + dt * Q[Shortcuts::kappa] * temperatureLaplacian;
90""",
91)
92
93project = exahype2.Project(
94 namespace=["tests", "exahype2", "fd"],
95 project_name=".",
96 directory=".",
97 executable="ExaHyPE",
98)
99project.add_solver(fd_solver)
100
101if args.number_of_snapshots <= 0:
102 time_in_between_plots = 0.0
103else:
104 time_in_between_plots = args.end_time / args.number_of_snapshots
105 project.set_output_path(args.output)
106
107project.set_global_simulation_parameters(
108 dimensions=args.dimensions,
109 size=[0.1, 0.1, 0.1][0 : args.dimensions],
110 offset=[0.0, 0.0, 0.0][0 : args.dimensions],
111 min_end_time=args.end_time,
112 max_end_time=args.end_time,
113 first_plot_time_stamp=0.0,
114 time_in_between_plots=time_in_between_plots,
115 periodic_BC=[
116 args.periodic_boundary_conditions_x,
117 args.periodic_boundary_conditions_y,
118 args.periodic_boundary_conditions_z,
119 ],
120)
121
122project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
123project.set_Peano4_installation(
124 "../../../", mode=peano4.output.string_to_mode(args.build_mode)
125)
126project = project.generate_Peano4_project(verbose=False)
127project.output.makefile.add_CXX_flag(f"""-DTHERMAL_DIFFUSIVITY={THERMAL_DIFFUSIVITY}""")
128project.set_fenv_handler(args.fpe)
129project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)