Peano
Loading...
Searching...
No Matches
AverageOverCell.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 .Filter import Filter
4from tarch.plotter.api.input.Patch import Patch
5
6
8 """
9 Run over all cells. Each cell holds a patch with dof x dof (2d) or
10 dof x dof x dof (3d) cells. Each cell hosts unknown unknowns. This
11 filter reduces each patch to a 1x1 or 1x1x1 outcome, i.e. a point
12 cloud.
13 """
14
15 def __init__(self, verbose=False):
16 Filter.__init__(self, True, False, verbose)
17 pass
18
19 def render(
20 self,
21 cell_data,
22 dof,
23 dimension,
24 unknowns,
25 is_data_associated_to_cell,
26 description,
27 mapping,
28 ):
29 """
30 Overwrite this one for the particular filter.
31 """
32 result_cell_data = []
33
34 for patch in cell_data:
35 average_values = [0] * unknowns
36
37 entries_per_cell = dof**dimension
38
39 for i in range(0, entries_per_cell):
40 for j in range(0, unknowns):
41 average_values[j] = (
42 average_values[j] + patch.values[i * unknowns + j]
43 )
44 for j in range(0, unknowns):
45 average_values[j] = average_values[j] / entries_per_cell
46
47 new_patch = Patch(
48 patch.offset, patch.size, average_values, patch.subdomain_number
49 )
50 result_cell_data.append(new_patch)
51
52 if self.verbose and len(result_cell_data) == 0:
53 print("Snapshot has been empty")
54 elif self.verbose:
55 print(
56 "Replaced "
57 + str(len(result_cell_data))
58 + " patches with one voxel with average values"
59 )
60
61 mapping = []
62 if dimension == 2:
63 mapping = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]
64 else:
65 mapping = [
66 0.0,
67 0.0,
68 0.0,
69 1.0,
70 0.0,
71 0.0,
72 0.0,
73 1.0,
74 0.0,
75 1.0,
76 1.0,
77 0.0,
78 0.0,
79 0.0,
80 1.0,
81 1.0,
82 0.0,
83 1.0,
84 0.0,
85 1.0,
86 1.0,
87 1.0,
88 1.0,
89 1.0,
90 ]
91 return result_cell_data, 1, dimension, unknowns, True, description, mapping
__init__(self, verbose=False)
exploit_idempotent: boolean Exploit the fact that the filter is idempotent, i.e.
An abstract filter class.
Definition Filter.py:5
Patch class that contains offset, size and value of a Peano patch.
Definition Patch.py:5