Peano
Loading...
Searching...
No Matches
MPI.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.api.solversteps.ActionSet import ActionSet
4
5
6
7def get_face_merge_implementation(patch_overlap):
8 """
9
10 Generic exchange of block-structured halo layers
11
12 This routine realises a halo exchange via plain copies. It assumes that the
13 overhead itself is modelled as a patch, where the first dimension of the
14 patch_overlap is actually the "short" dimension, i.e. the direction which
15 indeed overlaps with the two adjacent patches. It has to be a multiple of 2.
16 The other remaining dimensions are plain Cartesian overlaps and match the
17 size of the adjacent blocks.
18
19 """
20 d = {
21 "OVERLAP": int(patch_overlap.dim[0]/2),
22 "DOFS_PER_AXIS": int(patch_overlap.dim[1]),
23 "UNKNOWNS": int(patch_overlap.no_of_unknowns)
24 }
25
26
27 template = """
28 auto serialisePatchIndex = [](tarch::la::Vector<Dimensions,int> overlapCell, int normal) {{
29 int base = 1;
30 int result = 0;
31 for (int d=0; d<Dimensions; d++) {{
32 result += overlapCell(d) * base;
33 if (d==normal) {{
34 base *= {OVERLAP}*2;
35 }}
36 else {{
37 base *= {DOFS_PER_AXIS};
38 }}
39 }}
40 return result;
41 }};
42
43
44 switch (context) {{
45 case ::peano4::grid::TraversalObserver::SendReceiveContext::PeriodicBoundaryDataSwap:
46 case ::peano4::grid::TraversalObserver::SendReceiveContext::BoundaryExchange:
47 {{
48 const int faceNormal = marker.getSelectedFaceNumber() % Dimensions;
49 dfore(i,{DOFS_PER_AXIS},faceNormal,0) {{
50 for (int j=0; j<{OVERLAP}; j++) {{
51 tarch::la::Vector<Dimensions,int> volume = i;
52 volume(faceNormal) += marker.outerNormal()(faceNormal)>0 ? j + {OVERLAP} : j;
53
54 int volumeSerialised = serialisePatchIndex(volume, faceNormal);
55 for (int k=0; k<{UNKNOWNS}; k++) {{
56 assertion5(
57 neighbour.value[volumeSerialised*{UNKNOWNS}+k]==neighbour.value[volumeSerialised*{UNKNOWNS}+k],
58 value[volumeSerialised*{UNKNOWNS}+k],
59 k, {UNKNOWNS},
60 volume,
61 marker.toString()
62 );
63
64 value[volumeSerialised*{UNKNOWNS}+k] = neighbour.value[volumeSerialised*{UNKNOWNS}+k];
65
66 }}
67
68 // This should be non-critical assertion, but this assertion is only
69 // generically available in ExaHyPE 2, so I comment the assertion out
70 // here.
71 // assertion(value[volumeSerialised]==value[volumeSerialised]);
72 }}
73 }}
74 }}
75 break;
76
77 case ::peano4::grid::TraversalObserver::SendReceiveContext::MultiscaleExchange:
78 assertionMsg( false, "not implemented yet" );
79 break;
80
81 default:
82 assertionMsg( false, "not implemented yet" );
83 break;
84 }}
85"""
86
87 return template.format(**d)
88
89
90def get_cell_merge_implementation(patch_overlap):
91 d = {
92 "DOFS_PER_AXIS": int(patch_overlap.dim[1]),
93 "UNKNOWNS": int(patch_overlap.no_of_unknowns)
94 }
95
96
97 template = """
98 switch (context) {{
99 case ::peano4::grid::TraversalObserver::SendReceiveContext::BoundaryExchange:
100 assertionMsg( false, "should not be called, as cells (on the same level) cannot overlap in Peano" );
101 break;
102
103 case ::peano4::grid::TraversalObserver::SendReceiveContext::MultiscaleExchange:
104 assertionMsg( false, "not implemented yet" );
105 break;
106
107 case ::peano4::grid::TraversalObserver::SendReceiveContext::PeriodicBoundaryDataSwap:
108 assertionMsg( false, "should never be called" );
109 break;
110
111 default:
112 assertionMsg( false, "not implemented yet" );
113 break;
114 }}
115"""
116
117 return template.format(**d)
Action set (reactions to events)
Definition ActionSet.py:6