Peano
Loading...
Searching...
No Matches
MaxEigenvalueReduction.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
3
4
6 """!
7
8 Let the generated abstract solver class host the maximum eigenvalue of a time step
9
10 The class collects the maximum over all patches and threads. This is
11 a reduction over the whole mesh, hence it belongs to the solver and
12 not to a cell. exahype2.api.fv.actionsets.ReduceMaxEigenvalue feeds it
13 (reduceMaxEigenvalue()), while
14 exahype2.api.fv.actionsets.ComputeGlobalCFLCondition reads and resets it
15 (getAndResetMaxEigenvalue()) in a different place of the time step.
16 Reading and resetting is one operation to avoid races.
17
18 @param solver: exahype2.api.Solver
19 The solver whose abstract class hosts the reduction.
20
21 """
22 solver.add_user_solver_includes(
23 """
24#include "tarch/multicore/BooleanSemaphore.h"
25#include "tarch/multicore/Lock.h"
26"""
27 )
28 # Brace initialisation: transient data, so the checkpoint meta data
29 # (which lists attributes of the form "double name = value;") skips it
30 solver.add_abstract_solver_attribute("double _maxEigenvalueOfTimeStep{0.0};")
31 solver.add_abstract_solver_attribute(
32 "tarch::multicore::BooleanSemaphore _maxEigenvalueSemaphore;"
33 )
34 solver.add_abstract_solver_method(
35 "void reduceMaxEigenvalue(double eigenvalue);",
36 lambda qualified_class_name: "void "
37 + qualified_class_name
38 + "::reduceMaxEigenvalue(double eigenvalue) {\n"
39 + " tarch::multicore::Lock lock(_maxEigenvalueSemaphore);\n"
40 + " _maxEigenvalueOfTimeStep = std::max(_maxEigenvalueOfTimeStep, eigenvalue);\n"
41 + "}\n",
42 )
43 solver.add_abstract_solver_method(
44 "double getAndResetMaxEigenvalue();",
45 lambda qualified_class_name: "double "
46 + qualified_class_name
47 + "::getAndResetMaxEigenvalue() {\n"
48 + " tarch::multicore::Lock lock(_maxEigenvalueSemaphore);\n"
49 + " const double result = _maxEigenvalueOfTimeStep;\n"
50 + " _maxEigenvalueOfTimeStep = 0.0;\n"
51 + " return result;\n"
52 + "}\n",
53 )
add_max_eigenvalue_reduction(solver)
Let the generated abstract solver class host the maximum eigenvalue of a time step.