Peano
Loading...
Searching...
No Matches
UpdateCellGPU.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
3from .AbstractFVActionSet import AbstractFVActionSet
4
5from exahype2.api.Solver import Solver
6from ...AuxiliaryVariables import (
7 code_to_assemble_kernel_input,
8 code_to_allocate_kernel_output,
9 code_to_copy_back_kernel_output,
10)
11import peano4.api
12
13
15 """!
16
17 Update a Finite Volume patch (solver._patch) from its halo-augmented
18 reconstruction (solver._patch_with_halo, see
19 toolbox.blockstructured.api.ReconstructPatchWithHalo) by applying the
20 solver's numerical scheme (Rusanov flux, explicit Euler time stepping)
21 once per volume.
22
23 Global time stepping: all cells share one time stamp and time step
24 size, which are taken from the solver (getMinTimeStamp() and
25 getMinTimeStepSize()) rather than from per-cell bookkeeping.
26
27 The kernel does not return any eigenvalue: exahype2.api.fv.actionsets.ComputeMaxEigenvalue
28 determines it in a task of its own, and
29 exahype2.api.fv.actionsets.ComputeGlobalCFLCondition derives the next
30 time step size from it.
31
32 """
33
34 def __init__(self, solver: Solver, guard):
35 """!
36
37 @param solver: exahype2.api.Solver
38 Has to have solver._patch and
39 solver._patch_with_halo set - @see
40 exahype2.api.fv.RusanovWithExplicitEuler.
41
42 @param guard: str
43 C++ boolean expression, evaluated per cell in touchCellFirstTime,
44 guarding whether that cell's patch is updated. Typically the
45 output of the solver's grid_selector (@see
46 peano4.api.toolbox.GridSelector).
47
48 """
49 AbstractFVActionSet.__init__(self, solver)
50 self.guard = guard
51
52 def get_body_of_operation(self, operation_name):
53 result = ""
54
55 stride_per_dof = self._solver.unknowns + self._solver.number_of_auxiliary_variables
56 input_dofs_per_axis = self._solver.numerical_scheme.patch_size + 2 * self._solver.numerical_scheme.halo_size
57 output_dofs_per_axis = self._solver.numerical_scheme.patch_size
58
59
60 if operation_name == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
61 solver = self._solver
62 unknowns_in = f"fineGridCell{solver._patch_with_halo.name}.value"
63 unknowns_out = f"fineGridCell{solver._patch.name}.value"
64 has_parameters = len(solver.auxiliary_variables) > 0
65 kernel_in = "kernelIn.data()" if has_parameters else unknowns_in
66 kernel_out = "kernelOut.data()" if has_parameters else unknowns_out
67 result = f"""
68 #if Dimensions == 2
69 int inputStride = {stride_per_dof} * {input_dofs_per_axis} * {input_dofs_per_axis};
70 int outputStride = {stride_per_dof} * {output_dofs_per_axis} * {output_dofs_per_axis};
71 #else
72 int inputStride = {stride_per_dof} * {input_dofs_per_axis} * {input_dofs_per_axis} * {input_dofs_per_axis};
73 int outputStride = {stride_per_dof} * {output_dofs_per_axis} * {output_dofs_per_axis} * {output_dofs_per_axis};
74 #endif
75
76 double timeStamp = repositories::{self._solver.get_name_of_global_instance()}.getMinTimeStamp();
77 double timeStepSize = repositories::{self._solver.get_name_of_global_instance()}.getMinTimeStepSize();
78 {code_to_assemble_kernel_input(solver, "kernelIn", unknowns_in, solver.numerical_scheme.halo_size)}
79 {code_to_allocate_kernel_output(solver, "kernelOut")}
80 ::exahype2::CellData patchData({kernel_in}, marker.x(), marker.h(), timeStamp, timeStepSize, {kernel_out});
81 ::exahype2::CopyCellDataGPU gpuPatchData(patchData, inputStride, outputStride);
82 {self._solver.compute_kernel_call}
83 gpuPatchData.copyBackAndDestroy();
84 {code_to_copy_back_kernel_output(solver, "kernelOut", unknowns_out)}
85
86"""
87 return result
88
89 def get_guard_of_operation(self, operation_name):
90 if operation_name == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
91 return self.guard
92 return "true"
93
95 return __name__.replace(".py", "").replace(".", "_")
Abstract base class for all ExaHyPE 2 solvers.
Definition Solver.py:17
Update a Finite Volume patch (solver._patch) from its halo-augmented reconstruction (solver....
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
get_guard_of_operation(self, operation_name)
Return the guard of an operation.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.