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.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.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
119 """
120 self.association = DoFAssociation.Undef
121 self.name = name
122 self.namespace = []
124
125
126 def configure(self,namespace,association, subdirectory=""):
127 """
128 Typically called by model as soon as you add an object to it
129 """
130 self.namespace = [x for x in namespace]
131 self.association = association
132 self.namespace += [ get_subnamespace_for_association(association) ]
133 self.subdirectory = subdirectory
134
135
137 result = ""
138 for i in self.namespace:
139 result += i
140 result += "::"
141 result += self.name
142 return result
143
144
146 """
147 What should the data type be called within the data repository,
148 or within action sets. We add a prefix name here.
149 """
151
152
154 """
155 What should the data type be called within the data repository.
156 """
157 result = ""
158 if self.association==DoFAssociation.Vertex:
159 result += "peano4::datamanagement::VertexEnumerator<"
160 elif self.association==DoFAssociation.Face:
161 result += "peano4::datamanagement::FaceEnumerator<"
162 else:
163 assert False, "association was {}".format( self.association )
164 result += self.get_full_qualified_type()
165 result += ">"
166 return result
167
168
169 @property
175 self,
176 argument_name,
177 use_dof_association = None
178 ):
179 """
180
181 You can make Peano's store and load arguments of any DoF depend on other
182 DoFs that you have loaded before. So you can load X and then make Y later
183 on depend on the state of X. For this, you have to add a tuple to
184 Y's additional_load_and_store_arguments. It is a very technical tuple.
185 This routine helps you to construct it for X.
186
187 use_dof_association: DoFAssociation
188 Set this one to None and the routine will pick up self._association.
189 However, there are cases where we want to construct the string and
190 the association is not yet set properly. In this case, you have to
191 supplement the information manually.
192
193 """
194 if use_dof_association==None:
195 use_dof_association = self.association
196
197 stack_access_string = "repositories::DataRepository::_{}Stack.getForPush( repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top()".format(
198 get_logical_type_name_for_association(use_dof_association, self.name)
199 )
200
201 data_type ="{}::{}".format(
202 get_subnamespace_for_association(use_dof_association),
203 self.name
204 )
205
206 return (stack_access_string,data_type,argument_name)
207
208 @property
209 def subnamespace(self):
210 # Replace "/" with "::" in the directory string to make it a namespace
211 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
additional_load_and_store_arguments(self)
Definition DoF.py:170
get_full_qualified_type(self)
Definition DoF.py:136
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:178
__init__(self, name)
Create a degree of freedom object.
Definition DoF.py:82
get_logical_type_name(self)
What should the data type be called within the data repository, or within action sets.
Definition DoF.py:145
get_enumeration_type(self)
What should the data type be called within the data repository.
Definition DoF.py:153
configure(self, namespace, association, subdirectory="")
Typically called by model as soon as you add an object to it.
Definition DoF.py:126
get_subnamespace_for_association(association)
Definition DoF.py:43
get_logical_type_name_for_association(association, name)
Definition DoF.py:27