Peano
Loading...
Searching...
No Matches
DoF.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 enum import IntEnum
4
5
6class DoFAssociation(IntEnum):
7 """
8
9 Superclass has to be IntEnum, as I use this one within Jinja2 templates
10 where I struggled to compare against enum variants. I however can always
11 compare against integers.
12
13 """
14 Undef = 0
15 Vertex = 1
16 Face = 2
17 Cell = 3
18 #
19 # I use generic for standard MPI messages or DaStGen messages which are used
20 # within the grid mangement and traversal, i.e. have nothing to do with particular
21 # grid entities
22 #
23 Generic = 4
24 Global = 5
25
26
28 result = ""
29 if association==DoFAssociation.Vertex:
30 result += "VertexData"
31 elif association==DoFAssociation.Cell:
32 result += "CellData"
33 elif association==DoFAssociation.Face:
34 result += "FaceData"
35 elif association==DoFAssociation.Global:
36 result += "GlobalData"
37 else:
38 assert False
39 result += name
40 return result
41
42
44 if association==DoFAssociation.Vertex:
45 return "vertexdata"
46 elif association==DoFAssociation.Cell:
47 return "celldata"
48 elif association==DoFAssociation.Face:
49 return "facedata"
50 elif association==DoFAssociation.Global:
51 return "globaldata"
52 else:
53 assert False
54
55
56class DoF(object):
57 """!
58
59 Base class for any degree of freedom object
60
61 Any degree of freedom object in Peano is derived from DoF. There are
62 different subclasses of this type which are actually used in most
63 implementations. The most popular one is peano4.api.datamodel.DaStGen2 which
64 encodes a DoF implementation which is based upon plain C++ objects created
65 through DaStGen2. However, there are also other data models such as bespoke
66 patch data represented through peano4.api.datamodel.Patch.
67
68 @image html dof-class-diagram.png
69
70 Every DoF in Peano has a name and a unique association with a mesh entity
71 which is held in association. There are some further properties tied to
72 each DoF such as a position x and a mesh width h, but we leave it to
73 subclasses to provide those guys.
74
75 Please consult the tutorials on @ref tutorials_peano4_assign_data_to_mesh "assigning data to a mesh" and
76 @ref tutorials_peano4_mask_out_data_usage "masking out data storage"
77 on some instructions where this class is actually used in code.
78
79 """
80
81
82 def __init__(self, name):
83 """!
84
85 Create a degree of freedom object
86
87 Both the association and the namespace are not to be set directly,
88 but through the operation configure().
89
90 ## Additional store/load/send/receive arguments
91
92 - The first entry of this triple is the expression that you want the
93 observer to pass in.
94 - The second one is the C++ type of this expression.
95 - The third one is the name that you wanna use in the dof signatures
96 for this argument.
97
98 It is the responsibility of the DoF subclass to ensure that the second
99 entry is properly used to initialise the store and load routines.
100 Most define an additional setter for property.
101
102
103 ## Attributes
104
105 association: DoFAssociation
106
107 name: String
108 Has to be a fit to the C++ naming conventions
109
110 namespace: [String]
111 Sequence of namespaces.
112
113 additional_load_and_store_arguments: [(String,String,String)]
114 This flag is, by default, an empty list. If you add an entry to this
115 list, each store and load routine will get an additional parameter.
116 Consult documentation above for the semantics of the list entries.
117
118 grid_selector: peano4.api.toolbox.GridSelector or None
119 None by default. If set, the task graph compiler restricts the
120 storage of this DoF to the mesh entities selected: The selector's
121 guard is AND-combined with each of the use/load/store predicates the
122 compiler derives (@see peano4.api.taskgraph.compiler.DeriveLoadStoreComputeFlag).
123 That is, data are only used, loaded or stored if the selector holds
124 and the compiler has concluded that the data are needed.
125
126
127 """
128 self.association = DoFAssociation.Undef
129 self.name = name
130 self.namespace = []
132 self.grid_selector = None
133
134
135 def configure(self,namespace,association, subdirectory=""):
136 """
137 Typically called by model as soon as you add an object to it
138 """
139 self.namespace = [x for x in namespace]
140 self.association = association
141 self.namespace += [ get_subnamespace_for_association(association) ]
142 self.subdirectory = subdirectory
143
144
146 result = ""
147 for i in self.namespace:
148 result += i
149 result += "::"
150 result += self.name
151 return result
152
153
155 """
156 What should the data type be called within the data repository,
157 or within action sets. We add a prefix name here.
158 """
160
161
163 """
164 What should the data type be called within the data repository.
165 """
166 result = ""
167 if self.association==DoFAssociation.Vertex:
168 result += "peano4::datamanagement::VertexEnumerator<"
169 elif self.association==DoFAssociation.Face:
170 result += "peano4::datamanagement::FaceEnumerator<"
171 else:
172 assert False, "association was {}".format( self.association )
173 result += self.get_full_qualified_type()
174 result += ">"
175 return result
176
177
178 @property
184 self,
185 argument_name,
186 use_dof_association = None
187 ):
188 """
189
190 You can make Peano's store and load arguments of any DoF depend on other
191 DoFs that you have loaded before. So you can load X and then make Y later
192 on depend on the state of X. For this, you have to add a tuple to
193 Y's additional_load_and_store_arguments. It is a very technical tuple.
194 This routine helps you to construct it for X.
195
196 use_dof_association: DoFAssociation
197 Set this one to None and the routine will pick up self._association.
198 However, there are cases where we want to construct the string and
199 the association is not yet set properly. In this case, you have to
200 supplement the information manually.
201
202 """
203 if use_dof_association==None:
204 use_dof_association = self.association
205
206 stack_access_string = "repositories::DataRepository::_{}Stack.getForPush( repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top()".format(
207 get_logical_type_name_for_association(use_dof_association, self.name)
208 )
209
210 data_type ="{}::{}".format(
211 get_subnamespace_for_association(use_dof_association),
212 self.name
213 )
214
215 return (stack_access_string,data_type,argument_name)
216
217 @property
218 def subnamespace(self):
219 # Replace "/" with "::" in the directory string to make it a namespace
220 return self.subdirectory.replace("/", "::")
Superclass has to be IntEnum, as I use this one within Jinja2 templates where I struggled to compare ...
Definition DoF.py:6
Base class for any degree of freedom object.
Definition DoF.py:56
configure(self, namespace, association, subdirectory="")
Typically called by model as soon as you add an object to it.
Definition DoF.py:135
get_logical_type_name(self)
What should the data type be called within the data repository, or within action sets.
Definition DoF.py:154
additional_load_and_store_arguments_for_other_dof(self, argument_name, use_dof_association=None)
You can make Peano's store and load arguments of any DoF depend on other DoFs that you have loaded be...
Definition DoF.py:187
get_enumeration_type(self)
What should the data type be called within the data repository.
Definition DoF.py:162
__init__(self, name)
Create a degree of freedom object.
Definition DoF.py:82
additional_load_and_store_arguments(self)
Definition DoF.py:179
get_logical_type_name_for_association(association, name)
Definition DoF.py:27
get_subnamespace_for_association(association)
Definition DoF.py:43