Peano
Loading...
Searching...
No Matches
AdaptivityCriterion.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 __future__ import annotations
4
5from .PDETerm import PDETerm
6
7
9 """!
10
11 Base class of all the PDE terms which decide where to refine or coarsen
12 the mesh
13
14 An adaptivity criterion is a PDE term which writes its decision into the
15 output argument refinementCommand. It points to one
16 ::exahype2::RefinementCommand, i.e. Keep, Refine or Erase (see
17 exahype2/RefinementControl.h). The caller initialises it with Keep before
18 the call, so an implementation only has to set it if it wants to refine
19 or erase. In particular, the empty string as implementation yields a
20 criterion which always keeps the mesh.
21
22 The subclasses differ in what they are handed:
23
24 - exahype2.api.RefineErasePointwisely is handed the solution in one
25 volume.
26 - exahype2.api.GradientRefinement is handed a one-sided difference
27 quotient of the solution along one coordinate axis.
28
29 Only if a solver has an adaptivity criterion do the numerical schemes
30 and the setup evaluate it, i.e. add the action sets which collect refine
31 and erase requests (@ref exahype2.api.blockstructured.create_dynamic_mesh_refinement_action_set.create_dynamic_mesh_refinement_action_set()).
32 A solver may have at most one adaptivity criterion.
33
34 The class itself defines no signature, i.e. you always add one of its
35 subclasses to a solver.
36
37 """
38
40 self,
41 name: str,
42 implementation: str = None,
43 stateless: bool = False,
44 ):
45 """!
46
47 @param name: str
48 The C++ method name of the criterion.
49
50 @param implementation: str
51 A C++ snippet that becomes the method's body, or None (the default)
52 to leave the method pure virtual for you to implement by hand. The
53 empty string is a valid body: it leaves *refinementCommand
54 untouched, i.e. at Keep.
55
56 @param stateless: bool
57 Generate a static, GPU-offloadable method instead of a virtual
58 one. Requires an implementation.
59
60 """
61 super().__init__(
62 name=name,
63 implementation=implementation,
64 stateless=stateless,
65 )
66
67
68def get_adaptivity_criterion(solver) -> AdaptivityCriterion:
69 """!
70
71 The solver's adaptivity criterion, or None if it has none
72
73 Raises a ValueError if the solver has more than one adaptivity
74 criterion.
75
76 @param solver: exahype2.api.Solver
77 The solver to inspect.
78
79 """
80 criteria = [
81 term for term in solver.pde_terms if isinstance(term, AdaptivityCriterion)
82 ]
83 if len(criteria) > 1:
84 raise ValueError(
85 f"Solver {solver.name} has {len(criteria)} adaptivity criteria "
86 f"({', '.join(term.name for term in criteria)}), but supports at most one"
87 )
88 return criteria[0] if criteria else None
Base class of all the PDE terms which decide where to refine or coarsen the mesh.
__init__(self, str name, str implementation=None, bool stateless=False)
Represents one named, point-wise PDE operator that a solver exposes for the user to implement: a C++ ...
Definition PDETerm.py:6