Peano
Loading...
Searching...
No Matches
Peano4SmartPointerDoubleArray.py
Go to the documentation of this file.
1# This file is part of the DaStGen2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
4
5
7 """!
8
9 Specialisation of array using Peano's tarch with a smart pointer
10
11 This routine maps a logical array of fixed size onto a smart pointer class.
12 If you use it, the resulting element tied to a cell, face or vertex might
13 induce significantly lower memory movement overhead. However, this is not
14 guaranteed, and requires some careful testing. As you work with smart
15 pointers, the routine gives you direct access to the underlying vector,
16 i.e. provides specialised routines that expose the underlying data
17 structure: There are the standard getters and setters, but there are also
18 variants which give you the start pointer data object, while get and set
19 are compatible with Peano4DoubleArray's signature.
20
21 Using this class is straightforward and doesn't seem to be any different to
22 Peano4DoubleArray. However, under the hood you'll alter the behaviour of
23 peano4.datamodel.DaStGen2.
24
25 """
26
27 def __init__(self,
28 name,
29 cardinality,
30 ifdefs=[],
31 ):
32 """
33
34 See superclass' constructor.
35
36 @param cardinality: String
37 This is important: It is not (necessarily) an integer, but can be
38 a string which is defined via a pragma or constexpr later.
39
40 """
41 super(Peano4SmartPointerDoubleArray, self).__init__(
42 name, cardinality, valid_mantissa_bits=None, ifdefs=ifdefs
43 )
44 self._cardinality_cardinality = str(cardinality)
45
46 def get_methods(self, _full_qualified_class_name, for_declaration=True):
47 """!
48
49 This routine defines which operations the generated data type offers
50
51 It is very much the same as Peano4DoubleArray, i.e. it hides the
52 underlying smart pointers. If the user calls get, the data is converted
53 into a normal tarch vector. If the user calls set, we take the argument
54 and copy it into the underlying smart pointer.
55
56 However, we add one more routine: getXXXXSmartPointer(). This way,
57 users can get access to the smart pointer data under the hood.
58
59 """
60 accessor_name = self._name_name[:1].title() + self._name_name[1:]
61 return [
62 (
63 "get" + accessor_name + "() const",
64 "tarch::la::Vector<" + self._cardinality_cardinality + ",double>",
65 ),
66 (
67 "set"
68 + accessor_name
69 + "(const tarch::la::Vector<"
71 + ",double>& value)",
72 "void",
73 ),
74 ("get" + accessor_name + "(int index) const", "double"),
75 ("set" + accessor_name + "(int index, double value)", "void"),
76 (
77 "get" + accessor_name + "SmartPointer()",
78 "tarch::la::SmartPointerVector<" + self._cardinality_cardinality + ",double>",
79 ),
80 ]
81
83 return True
84
85 def get_plain_C_attributes(self, for_constructor=False):
86 return [
87 (
88 "_" + self._name_name,
89 "tarch::la::SmartPointerVector<" + self._cardinality_cardinality + ",double>",
90 )
91 ]
92
94 return [("_" + self._name_name + ".data()[0]", "void")]
95
97 return [
98 ("_" + self._name_name, "tarch::la::Vector<" + self._cardinality_cardinality + ",double>")
99 ]
100
101 def get_method_body(self, signature):
102 if self.use_data_store:
103 name = " _dataStore._" + self._name_name
104 else:
105 name = " _" + self._name_name
106
107 if (
108 signature.startswith("get")
109 and "SmartPointer" in signature
110 ):
111 return " return " + name + ";\n"
112 if (
113 signature.startswith("get")
114 and "index" in signature
115 ):
116 return " return " + name + "(index);\n"
117 elif (
118 signature.startswith("set")
119 and "index" in signature
120 ):
121 return name + "(index) = value;\n"
122 elif signature.startswith("get"):
123 return " return " + name + ".toVector();\n"
124 elif signature.startswith("set"):
125 return name + " = value;\n"
126 else:
127 assert False
128 return ""
129
131 return [("MPI_DOUBLE", self._cardinality_cardinality)]
132
133 def get_to_string(self):
134 """
135
136 Return string representation of attribute.
137
138 """
139 if self.use_data_store:
140 return "_dataStore._" + self._name_name + ".toVector()"
141 else:
142 return "_" + self._name_name + ".toVector()"
Specialisation of array using Peano's tarch with a smart pointer.
get_first_plain_C_attribute(self)
For MPI for example, I need to know the first attribute.
get_methods(self, _full_qualified_class_name, for_declaration=True)
This routine defines which operations the generated data type offers.
use_default_copy_constructor(self)
Cannot use the default copy constructor, as it is an array, i.e.
get_constructor_arguments(self)
Return list of tuple of arguments for the constructor.
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
__init__(self, name, cardinality, ifdefs=[])
See superclass' constructor.