Peano
Loading...
Searching...
No Matches
Calculator.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
4
5from tarch.plotter.api.input.Patch import Patch
6
7
8def absolute(values):
9 return [abs(values[0])]
10
11
13 """
14 Calculate some value per voxel/sample point
15 """
16
18 self,
19 run_on_individual_pieces_of_data=False,
20 output_cardinality=1,
21 functor=absolute,
22 verbose=False,
23 ):
24 Filter.__init__(self, run_on_individual_pieces_of_data, True, verbose)
25 self._output_cardinality = output_cardinality
26 self._functor = functor
27 pass
28
29 def render(
30 self,
31 cell_data,
32 dof,
33 dimensions,
34 unknowns,
35 is_data_associated_to_cell,
36 description,
37 mapping,
38 ):
39 """
40 Overwrite this one for the particular filter.
41
42 We create an empty result array. Then we run over the input sequence
43 of cell_data. Per element, we check if a cell_data to the right within
44 this input sequence overlaps.
45
46 List operations are very expensive in Python. I therefore implement a
47 two-pass strategy, where I first sort the patches according to their
48 size. Actually, I sort them according to their inverted size, i.e.
49 big entries come first.
50 """
51 if self.verbose:
52 print(
53 "Build up auxiliary data structures over "
54 + str(len(cell_data))
55 + " entries"
56 )
57
58 delta_for_print = 10
59 ratio_for_print = 0
60 if len(cell_data) > 10000:
61 delta_for_print = 1
62
63 # Run over all patches
64 total_number_of_cells_per_patch = dof * dof
65 if dimensions == 3:
66 total_number_of_cells_per_patch *= dof
67
68 result_cell_data = []
69
70 for p in cell_data:
71 new_cell_values = []
72 for k in range(0, total_number_of_cells_per_patch):
73 new_data = self._functor(
74 p.values[k * unknowns : k * unknowns + unknowns]
75 )
76 if len(new_data) != self._output_cardinality:
77 raise Exception(
78 "Returned array size has to equal output cardinality"
79 )
80 new_cell_values += new_data
81 new_patch = Patch(p.offset, p.size, new_cell_values, p.subdomain_number)
82 result_cell_data.append(new_patch)
83
84 return (
85 result_cell_data,
86 dof,
87 dimensions,
89 is_data_associated_to_cell,
90 description,
91 mapping,
92 )
Calculate some value per voxel/sample point.
Definition Calculator.py:12
__init__(self, run_on_individual_pieces_of_data=False, output_cardinality=1, functor=absolute, verbose=False)
exploit_idempotent: boolean Exploit the fact that the filter is idempotent, i.e.
Definition Calculator.py:23
An abstract filter class.
Definition Filter.py:5
Patch class that contains offset, size and value of a Peano patch.
Definition Patch.py:5