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 def __init__(self, name):
58 """
59
60 Both the association and the namespace are not to be set directly,
61 but through the operation configure().
62
63 ## Additional store/load/send/receive arguments
64
65 - The first entry of this triple is the expression that you want the
66 observer to pass in.
67 - The second one is the C++ type of this expression.
68 - The third one is the name that you wanna use in the dof signatures
69 for this argument.
70
71 It is the responsibility of the DoF subclass to ensure that the second
72 entry is properly used to initialise the store and load routines.
73 Most define an additional setter for property.
74
75
76 ## Attributes
77
78 association: DoFAssociation
79
80 name: String
81 Has to be a fit to the C++ naming conventions
82
83 namespace: [String]
84 Sequence of namespaces.
85
86 additional_load_and_store_arguments: [(String,String,String)]
87 This flag is, by default, an empty list. If you add an entry to this
88 list, each store and load routine will get an additional parameter.
89 Consult documentation above for the semantics of the list entries.
90
91
92 """
93 self.association = DoFAssociation.Undef
94 self.name = name
95 self.namespace = []
97
98
99 def configure(self,namespace,association, subdirectory=""):
100 """
101 Typically called by model as soon as you add an object to it
102 """
103 self.namespace = [x for x in namespace]
104 self.association = association
105 self.namespace += [ get_subnamespace_for_association(association) ]
106 self.subdirectory = subdirectory
107
108
110 result = ""
111 for i in self.namespace:
112 result += i
113 result += "::"
114 result += self.name
115 return result
116
117
119 """
120 What should the data type be called within the data repository,
121 or within action sets. We add a prefix name here.
122 """
124
125
127 """
128 What should the data type be called within the data repository.
129 """
130 result = ""
131 if self.association==DoFAssociation.Vertex:
132 result += "peano4::datamanagement::VertexEnumerator<"
133 elif self.association==DoFAssociation.Face:
134 result += "peano4::datamanagement::FaceEnumerator<"
135 else:
136 assert False, "association was {}".format( self.association )
137 result += self.get_full_qualified_type()
138 result += ">"
139 return result
140
141
142 @property
148 self,
149 argument_name,
150 use_dof_association = None
151 ):
152 """
153
154 You can make Peano's store and load arguments of any DoF depend on other
155 DoFs that you have loaded before. So you can load X and then make Y later
156 on depend on the state of X. For this, you have to add a tuple to
157 Y's additional_load_and_store_arguments. It is a very technical tuple.
158 This routine helps you to construct it for X.
159
160 use_dof_association: DoFAssociation
161 Set this one to None and the routine will pick up self._association.
162 However, there are cases where we want to construct the string and
163 the association is not yet set properly. In this case, you have to
164 supplement the information manually.
165
166 """
167 if use_dof_association==None:
168 use_dof_association = self.association
169
170 stack_access_string = "repositories::DataRepository::_{}Stack.getForPush( repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top()".format(
171 get_logical_type_name_for_association(use_dof_association, self.name)
172 )
173
174 data_type ="{}::{}".format(
175 get_subnamespace_for_association(use_dof_association),
176 self.name
177 )
178
179 return (stack_access_string,data_type,argument_name)
180
181 @property
182 def subnamespace(self):
183 # Replace "/" with "::" in the directory string to make it a namespace
184 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
additional_load_and_store_arguments(self)
Definition DoF.py:143
get_full_qualified_type(self)
Definition DoF.py:109
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:151
__init__(self, name)
Both the association and the namespace are not to be set directly, but through the operation configur...
Definition DoF.py:57
_additional_load_and_store_arguments
Definition DoF.py:96
get_logical_type_name(self)
What should the data type be called within the data repository, or within action sets.
Definition DoF.py:118
get_enumeration_type(self)
What should the data type be called within the data repository.
Definition DoF.py:126
configure(self, namespace, association, subdirectory="")
Typically called by model as soon as you add an object to it.
Definition DoF.py:99
get_subnamespace_for_association(association)
Definition DoF.py:43
get_logical_type_name_for_association(association, name)
Definition DoF.py:27