fuse-element 0.1.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fuse/__init__.py +10 -0
- fuse/cells.py +850 -0
- fuse/dof.py +363 -0
- fuse/groups.py +388 -0
- fuse/serialisation.py +121 -0
- fuse/spaces/__init__.py +0 -0
- fuse/spaces/element_sobolev_spaces.py +80 -0
- fuse/spaces/interpolation_spaces.py +138 -0
- fuse/spaces/polynomial_spaces.py +203 -0
- fuse/traces.py +196 -0
- fuse/triples.py +470 -0
- fuse/utils.py +64 -0
- fuse_element-0.1.dev0.dist-info/LICENSE +165 -0
- fuse_element-0.1.dev0.dist-info/METADATA +17 -0
- fuse_element-0.1.dev0.dist-info/RECORD +17 -0
- fuse_element-0.1.dev0.dist-info/WHEEL +5 -0
- fuse_element-0.1.dev0.dist-info/top_level.txt +1 -0
fuse/triples.py
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
from fuse.cells import Point
|
|
2
|
+
from fuse.spaces.element_sobolev_spaces import ElementSobolevSpace
|
|
3
|
+
from fuse.dof import DeltaPairing, L2Pairing, MyTestFunction, PointKernel
|
|
4
|
+
from fuse.traces import Trace
|
|
5
|
+
from fuse.groups import perm_matrix_to_perm_array
|
|
6
|
+
from FIAT.dual_set import DualSet
|
|
7
|
+
from FIAT.finite_element import CiarletElement
|
|
8
|
+
import matplotlib as mpl
|
|
9
|
+
mpl.use('Agg')
|
|
10
|
+
import matplotlib.pyplot as plt
|
|
11
|
+
import inspect
|
|
12
|
+
from finat.ufl import FuseElement
|
|
13
|
+
import warnings
|
|
14
|
+
import numpy as np
|
|
15
|
+
import scipy
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ElementTriple():
|
|
19
|
+
"""
|
|
20
|
+
Class to represent the three core parts of the element
|
|
21
|
+
|
|
22
|
+
:param: cell: CellComplex
|
|
23
|
+
:param: spaces: Triple of spaces: (PolynomialSpace, SobolovSpace, InterpolationSpace)
|
|
24
|
+
:param: dof_gen: Generator Triple to generate the degrees of freedom.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, cell, spaces, dof_gen):
|
|
28
|
+
assert isinstance(cell, Point)
|
|
29
|
+
if isinstance(dof_gen, DOFGenerator):
|
|
30
|
+
dof_gen = [dof_gen]
|
|
31
|
+
for d in dof_gen:
|
|
32
|
+
assert isinstance(d, DOFGenerator)
|
|
33
|
+
d.add_cell(cell)
|
|
34
|
+
|
|
35
|
+
self.cell = cell
|
|
36
|
+
cell_spaces = []
|
|
37
|
+
for space in spaces:
|
|
38
|
+
# TODO: Fix this to a more sensible condition when all spaces
|
|
39
|
+
# implemented
|
|
40
|
+
if inspect.isclass(space) and issubclass(space, ElementSobolevSpace):
|
|
41
|
+
cell_spaces.append(space(cell))
|
|
42
|
+
else:
|
|
43
|
+
cell_spaces.append(space)
|
|
44
|
+
self.spaces = tuple(cell_spaces)
|
|
45
|
+
self.DOFGenerator = dof_gen
|
|
46
|
+
|
|
47
|
+
def generate(self):
|
|
48
|
+
res = []
|
|
49
|
+
id_counter = 0
|
|
50
|
+
for dof_gen in self.DOFGenerator:
|
|
51
|
+
generated = dof_gen.generate(self.cell, self.spaces[1], id_counter)
|
|
52
|
+
res.extend(generated)
|
|
53
|
+
id_counter += len(generated)
|
|
54
|
+
return res
|
|
55
|
+
|
|
56
|
+
def __iter__(self):
|
|
57
|
+
yield self.cell
|
|
58
|
+
yield self.spaces
|
|
59
|
+
yield self.DOFGenerator
|
|
60
|
+
|
|
61
|
+
def num_dofs(self):
|
|
62
|
+
return sum([dof_gen.num_dofs() for dof_gen in self.DOFGenerator])
|
|
63
|
+
|
|
64
|
+
def get_dof_info(self, dof):
|
|
65
|
+
if dof.trace_entity.dimension == 0:
|
|
66
|
+
center = self.cell.cell_attachment(dof.trace_entity.id)()
|
|
67
|
+
color = "b"
|
|
68
|
+
elif dof.trace_entity.dimension == 1:
|
|
69
|
+
color = "r"
|
|
70
|
+
center = self.cell.cell_attachment(dof.trace_entity.id)(0)
|
|
71
|
+
elif dof.trace_entity.dimension == 2:
|
|
72
|
+
color = "g"
|
|
73
|
+
center = self.cell.cell_attachment(dof.trace_entity.id)(0, 0)
|
|
74
|
+
else:
|
|
75
|
+
color = "b"
|
|
76
|
+
center = None
|
|
77
|
+
|
|
78
|
+
return center, color
|
|
79
|
+
|
|
80
|
+
def get_value_shape(self):
|
|
81
|
+
# TODO Shape should be specificed somewhere else probably
|
|
82
|
+
if self.spaces[0].set_shape:
|
|
83
|
+
return (self.cell.get_spatial_dimension(),)
|
|
84
|
+
else:
|
|
85
|
+
return ()
|
|
86
|
+
|
|
87
|
+
def to_ufl(self):
|
|
88
|
+
return FuseElement(self)
|
|
89
|
+
|
|
90
|
+
def to_fiat(self):
|
|
91
|
+
ref_el = self.cell.to_fiat()
|
|
92
|
+
dofs = self.generate()
|
|
93
|
+
degree = self.spaces[0].degree()
|
|
94
|
+
entity_ids = {}
|
|
95
|
+
entity_perms = {}
|
|
96
|
+
nodes = []
|
|
97
|
+
top = ref_el.get_topology()
|
|
98
|
+
min_ids = self.cell.get_starter_ids()
|
|
99
|
+
poly_set = self.spaces[0].to_ON_polynomial_set(ref_el)
|
|
100
|
+
|
|
101
|
+
for dim in sorted(top):
|
|
102
|
+
entity_ids[dim] = {i: [] for i in top[dim]}
|
|
103
|
+
entity_perms[dim] = {}
|
|
104
|
+
|
|
105
|
+
for i in range(len(dofs)):
|
|
106
|
+
entity = dofs[i].trace_entity
|
|
107
|
+
dim = entity.dim()
|
|
108
|
+
entity_ids[dim][entity.id - min_ids[dim]].append(i)
|
|
109
|
+
nodes.append(dofs[i].convert_to_fiat(ref_el, degree))
|
|
110
|
+
entity_perms, pure_perm = self.make_dof_perms(ref_el, entity_ids, nodes, poly_set)
|
|
111
|
+
|
|
112
|
+
form_degree = 1 if self.spaces[0].set_shape else 0
|
|
113
|
+
print("my", [n.pt_dict for n in nodes])
|
|
114
|
+
print(entity_perms)
|
|
115
|
+
# TODO: Change this when Dense case in Firedrake
|
|
116
|
+
if pure_perm:
|
|
117
|
+
dual = DualSet(nodes, ref_el, entity_ids, entity_perms)
|
|
118
|
+
else:
|
|
119
|
+
dual = DualSet(nodes, ref_el, entity_ids)
|
|
120
|
+
return CiarletElement(poly_set, dual, degree, form_degree)
|
|
121
|
+
|
|
122
|
+
def plot(self, filename="temp.png"):
|
|
123
|
+
# point evaluation nodes only
|
|
124
|
+
dofs = self.generate()
|
|
125
|
+
identity = MyTestFunction(lambda *x: x)
|
|
126
|
+
|
|
127
|
+
if self.cell.dimension == 0:
|
|
128
|
+
raise ValueError(" Dimension 0 cells cannot be plotted")
|
|
129
|
+
|
|
130
|
+
if self.cell.dimension < 3:
|
|
131
|
+
fig = plt.figure()
|
|
132
|
+
ax = plt.gca()
|
|
133
|
+
self.cell.plot(show=False, plain=True, ax=ax)
|
|
134
|
+
for dof in dofs:
|
|
135
|
+
center, color = self.get_dof_info(dof)
|
|
136
|
+
if isinstance(dof.pairing, DeltaPairing) and isinstance(dof.kernel, PointKernel):
|
|
137
|
+
coord = dof.eval(identity, pullback=False)
|
|
138
|
+
elif isinstance(dof.pairing, L2Pairing):
|
|
139
|
+
coord = center
|
|
140
|
+
if len(coord) == 1:
|
|
141
|
+
coord = (coord[0], 0)
|
|
142
|
+
if isinstance(dof.target_space, Trace):
|
|
143
|
+
dof.target_space.plot(ax, coord, dof.trace_entity, dof.g, color=color)
|
|
144
|
+
else:
|
|
145
|
+
ax.scatter(*coord, color=color)
|
|
146
|
+
ax.text(*coord, dof.id)
|
|
147
|
+
|
|
148
|
+
fig.savefig(filename)
|
|
149
|
+
elif self.cell.dimension == 3:
|
|
150
|
+
fig = plt.figure()
|
|
151
|
+
ax = fig.add_subplot(projection='3d')
|
|
152
|
+
self.cell.plot3d(show=False, ax=ax)
|
|
153
|
+
for dof in dofs:
|
|
154
|
+
center, color = self.get_dof_info(dof)
|
|
155
|
+
if center is None:
|
|
156
|
+
center = [0, 0, 0]
|
|
157
|
+
if isinstance(dof.pairing, DeltaPairing):
|
|
158
|
+
coord = dof.eval(identity, pullback=False)
|
|
159
|
+
if isinstance(dof.target_space, Trace):
|
|
160
|
+
dof.target_space.plot(ax, coord, dof.trace_entity, dof.g, color=color)
|
|
161
|
+
else:
|
|
162
|
+
ax.scatter(*coord, color=color)
|
|
163
|
+
elif isinstance(dof.pairing, L2Pairing):
|
|
164
|
+
dof.target_space.plot(ax, center, dof.trace_entity, dof.g, color=color, length=0.2)
|
|
165
|
+
ax.text(*coord, dof.id)
|
|
166
|
+
|
|
167
|
+
fig.savefig(filename)
|
|
168
|
+
else:
|
|
169
|
+
raise ValueError("Plotting not supported in this dimension")
|
|
170
|
+
|
|
171
|
+
def compute_dense_matrix(self, ref_el, entity_ids, nodes, poly_set):
|
|
172
|
+
dual = DualSet(nodes, ref_el, entity_ids)
|
|
173
|
+
|
|
174
|
+
old_coeffs = poly_set.get_coeffs()
|
|
175
|
+
dualmat = dual.to_riesz(poly_set)
|
|
176
|
+
|
|
177
|
+
shp = dualmat.shape
|
|
178
|
+
A = dualmat.reshape((shp[0], -1))
|
|
179
|
+
B = old_coeffs.reshape((shp[0], -1))
|
|
180
|
+
V = np.dot(A, np.transpose(B))
|
|
181
|
+
|
|
182
|
+
with warnings.catch_warnings():
|
|
183
|
+
warnings.filterwarnings("error")
|
|
184
|
+
try:
|
|
185
|
+
new_coeffs_flat = scipy.linalg.solve(V, B, transposed=True)
|
|
186
|
+
except (scipy.linalg.LinAlgWarning, scipy.linalg.LinAlgError):
|
|
187
|
+
raise np.linalg.LinAlgError("Singular Vandermonde matrix")
|
|
188
|
+
return A, new_coeffs_flat
|
|
189
|
+
|
|
190
|
+
def make_overall_dense_matrices(self, ref_el, entity_ids, nodes, poly_set):
|
|
191
|
+
min_ids = self.cell.get_starter_ids()
|
|
192
|
+
dim = self.cell.dim()
|
|
193
|
+
e = self.cell
|
|
194
|
+
e_id = e.id - min_ids[dim]
|
|
195
|
+
res_dict = {dim: {e_id: {}}}
|
|
196
|
+
degree = self.spaces[0].degree()
|
|
197
|
+
original_V, original_basis = self.compute_dense_matrix(ref_el, entity_ids, nodes, poly_set)
|
|
198
|
+
for g in self.cell.group.members():
|
|
199
|
+
val = g.numeric_rep()
|
|
200
|
+
if g.perm.is_Identity:
|
|
201
|
+
res_dict[dim][e_id][val] = np.eye(len(nodes))
|
|
202
|
+
else:
|
|
203
|
+
new_nodes = [d(g).convert_to_fiat(ref_el, degree) for d in self.generate()]
|
|
204
|
+
transformed_V, transformed_basis = self.compute_dense_matrix(ref_el, entity_ids, new_nodes, poly_set)
|
|
205
|
+
res_dict[dim][e_id][val] = np.matmul(transformed_basis, original_V.T)
|
|
206
|
+
return res_dict
|
|
207
|
+
|
|
208
|
+
def make_dof_perms(self, ref_el, entity_ids, nodes, poly_set):
|
|
209
|
+
dofs = self.generate()
|
|
210
|
+
min_ids = self.cell.get_starter_ids()
|
|
211
|
+
entity_associations = {dim: {e.id - min_ids[dim]: {} for e in self.cell.d_entities(dim)}
|
|
212
|
+
for dim in range(self.cell.dim() + 1)}
|
|
213
|
+
cell_dim = self.cell.dim()
|
|
214
|
+
cell_dict = entity_associations[cell_dim][self.cell.id - min_ids[cell_dim]]
|
|
215
|
+
pure_perm = True
|
|
216
|
+
|
|
217
|
+
# construct mapping of entities to the dof generators and the dofs they generate
|
|
218
|
+
for d in dofs:
|
|
219
|
+
sub_dim = d.trace_entity.dim()
|
|
220
|
+
sub_dict = entity_associations[sub_dim][d.trace_entity.id - min_ids[sub_dim]]
|
|
221
|
+
dof_gen = str(d.generation[sub_dim])
|
|
222
|
+
if not len(d.generation[sub_dim].g2.members()) == 1:
|
|
223
|
+
pure_perm = False
|
|
224
|
+
if dof_gen in sub_dict.keys():
|
|
225
|
+
sub_dict[dof_gen] += [d]
|
|
226
|
+
else:
|
|
227
|
+
sub_dict[dof_gen] = [d]
|
|
228
|
+
if sub_dim != cell_dim:
|
|
229
|
+
dof_gen = str(d.generation[cell_dim])
|
|
230
|
+
if not len(d.generation[cell_dim].g2.members()) == 1:
|
|
231
|
+
pure_perm = False
|
|
232
|
+
|
|
233
|
+
if dof_gen in cell_dict.keys():
|
|
234
|
+
cell_dict[dof_gen] += [d]
|
|
235
|
+
else:
|
|
236
|
+
cell_dict[dof_gen] = [d]
|
|
237
|
+
|
|
238
|
+
if pure_perm is False:
|
|
239
|
+
# TODO think about where this call goes
|
|
240
|
+
return self.make_overall_dense_matrices(ref_el, entity_ids, nodes, poly_set), pure_perm
|
|
241
|
+
|
|
242
|
+
dof_id_mat = np.eye(len(dofs))
|
|
243
|
+
oriented_mats_by_entity = {}
|
|
244
|
+
flat_by_entity = {}
|
|
245
|
+
|
|
246
|
+
# for each entity, look up generation on that entity and permute the
|
|
247
|
+
# dof mapping according to the generation
|
|
248
|
+
for dim in range(self.cell.dim()):
|
|
249
|
+
oriented_mats_by_entity[dim] = {}
|
|
250
|
+
flat_by_entity[dim] = {}
|
|
251
|
+
ents = self.cell.d_entities(dim)
|
|
252
|
+
for e in ents:
|
|
253
|
+
e_id = e.id - min_ids[dim]
|
|
254
|
+
members = e.group.members()
|
|
255
|
+
oriented_mats_by_entity[dim][e_id] = {}
|
|
256
|
+
flat_by_entity[dim][e_id] = {}
|
|
257
|
+
for g in members:
|
|
258
|
+
val = g.numeric_rep()
|
|
259
|
+
oriented_mats_by_entity[dim][e_id][val] = dof_id_mat.copy()
|
|
260
|
+
flat_by_entity[dim][e_id][val] = []
|
|
261
|
+
total_ent_dof_ids = []
|
|
262
|
+
for dof_gen in entity_associations[dim][e_id].keys():
|
|
263
|
+
ent_dofs = entity_associations[dim][e_id][dof_gen]
|
|
264
|
+
ent_dofs_ids = np.array([ed.id for ed in ent_dofs], dtype=int)
|
|
265
|
+
total_ent_dof_ids += [ed.id for ed in ent_dofs]
|
|
266
|
+
dof_gen_class = ent_dofs[0].generation[dim]
|
|
267
|
+
|
|
268
|
+
# if not len(dof_gen_class.g2.members()) == 1:
|
|
269
|
+
# print("NOT PERM")
|
|
270
|
+
# degree = ent_dofs[0].triple.spaces[0].degree()
|
|
271
|
+
# nodes = [d.convert_to_fiat(ref_el, degree) for d in ent_dofs]
|
|
272
|
+
# new_nodes = [d(g).convert_to_fiat(ref_el, degree) for d in ent_dofs]
|
|
273
|
+
# sub_ref_el = ref_el.construct_subelement(dim)
|
|
274
|
+
# print("sub ref el", sub_ref_el.fe_cell.get_topology())
|
|
275
|
+
# print("sub ref el", sub_ref_el.get_spatial_dimension())
|
|
276
|
+
# sub_poly_set = ent_dofs[0].triple.spaces[0].to_ON_polynomial_set(sub_ref_el)
|
|
277
|
+
# print(new_nodes)
|
|
278
|
+
# print([d(g) for d in ent_dofs])
|
|
279
|
+
# print(entity_ids)
|
|
280
|
+
# print(entity_ids[e.dimension][e_id])
|
|
281
|
+
# print(ent_dofs_ids)
|
|
282
|
+
# print(sub_poly_set)
|
|
283
|
+
# sub_entity_ids = dof_gen_class.make_entity_ids()
|
|
284
|
+
# print(sub_ref_el.get_topology())
|
|
285
|
+
# transformed_V, transformed_basis = self.compute_dense_matrix(sub_ref_el, sub_entity_ids, new_nodes, sub_poly_set)
|
|
286
|
+
# original_V, original_basis = self.compute_dense_matrix(sub_ref_el, sub_entity_ids, nodes, sub_poly_set)
|
|
287
|
+
# print(transformed_V)
|
|
288
|
+
# res_dict[dim][e_id][val] = np.matmul(transformed_basis, original_V.T)
|
|
289
|
+
# TODO not sure about correctness of this
|
|
290
|
+
if g.perm.is_Identity or (pure_perm and len(ent_dofs_ids) == 1):
|
|
291
|
+
oriented_mats_by_entity[dim][e_id][val][np.ix_(ent_dofs_ids, ent_dofs_ids)] = np.eye(len(ent_dofs_ids))
|
|
292
|
+
elif g in dof_gen_class.g1.members():
|
|
293
|
+
sub_mat = g.matrix_form()
|
|
294
|
+
oriented_mats_by_entity[dim][e_id][val][np.ix_(ent_dofs_ids, ent_dofs_ids)] = sub_mat.copy()
|
|
295
|
+
else:
|
|
296
|
+
pass
|
|
297
|
+
# # sub component dense case
|
|
298
|
+
flat_by_entity[dim][e_id][val] = perm_matrix_to_perm_array(oriented_mats_by_entity[dim][e_id][val][np.ix_(total_ent_dof_ids, total_ent_dof_ids)])
|
|
299
|
+
|
|
300
|
+
oriented_mats_overall = {}
|
|
301
|
+
dim = self.cell.dim()
|
|
302
|
+
e = self.cell
|
|
303
|
+
e_id = e.id - min_ids[dim]
|
|
304
|
+
flat_by_entity[dim] = {e_id: {}}
|
|
305
|
+
members = e.group.members()
|
|
306
|
+
for g in members:
|
|
307
|
+
val = g.numeric_rep()
|
|
308
|
+
oriented_mats_overall[val] = dof_id_mat.copy()
|
|
309
|
+
flat_by_entity[dim][e_id][val] = []
|
|
310
|
+
for dof_gen in entity_associations[dim][e_id].keys():
|
|
311
|
+
ent_dofs = entity_associations[dim][e_id][dof_gen]
|
|
312
|
+
ent_dofs_ids = np.array([ed.id for ed in ent_dofs], dtype=int)
|
|
313
|
+
dof_gen_class = ent_dofs[0].generation
|
|
314
|
+
for key in dof_gen_class.keys():
|
|
315
|
+
if not key == dim:
|
|
316
|
+
immersed_dim = key
|
|
317
|
+
for sub_e, sub_g in e.permute_entities(g, immersed_dim):
|
|
318
|
+
sub_e = e.get_node(sub_e)
|
|
319
|
+
sub_e_id = sub_e.id - min_ids[sub_e.dim()]
|
|
320
|
+
sub_ent_ids = []
|
|
321
|
+
for (k, v) in entity_associations[immersed_dim][sub_e_id].items():
|
|
322
|
+
sub_ent_ids += [e.id for e in v]
|
|
323
|
+
sub_mat = oriented_mats_by_entity[immersed_dim][sub_e_id][sub_g.numeric_rep()][np.ix_(sub_ent_ids, sub_ent_ids)]
|
|
324
|
+
g_sub_mat = g.matrix_form()
|
|
325
|
+
expanded = np.kron(g_sub_mat, sub_mat)
|
|
326
|
+
# potentially permute the dof ids instead
|
|
327
|
+
oriented_mats_overall[val][np.ix_(ent_dofs_ids, ent_dofs_ids)] = expanded.copy()
|
|
328
|
+
elif len(dof_gen_class.keys()) == 1:
|
|
329
|
+
if g in dof_gen_class[dim].g1.members() or (pure_perm and len(dof_gen_class[dim].g1.members()) > 1):
|
|
330
|
+
sub_mat = g.matrix_form()
|
|
331
|
+
oriented_mats_overall[val][np.ix_(ent_dofs_ids, ent_dofs_ids)] = sub_mat.copy()
|
|
332
|
+
|
|
333
|
+
for val, mat in oriented_mats_overall.items():
|
|
334
|
+
cell_dofs = entity_ids[dim][0]
|
|
335
|
+
flat_by_entity[dim][e_id][val] = perm_matrix_to_perm_array(mat[np.ix_(cell_dofs, cell_dofs)])
|
|
336
|
+
return flat_by_entity, pure_perm
|
|
337
|
+
|
|
338
|
+
def _to_dict(self):
|
|
339
|
+
o_dict = {"cell": self.cell, "spaces": self.spaces, "dofs": self.DOFGenerator}
|
|
340
|
+
return o_dict
|
|
341
|
+
|
|
342
|
+
def dict_id(self):
|
|
343
|
+
return "Triple"
|
|
344
|
+
|
|
345
|
+
def _from_dict(o_dict):
|
|
346
|
+
return ElementTriple(o_dict["cell"], o_dict["spaces"], o_dict["dofs"])
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
class DOFGenerator():
|
|
350
|
+
|
|
351
|
+
def __init__(self, generator_funcs, gen_group, trans_group):
|
|
352
|
+
# assert isinstance(G_1, Group)
|
|
353
|
+
# assert isinstance(G_2, Group)
|
|
354
|
+
self.x = generator_funcs
|
|
355
|
+
self.g1 = gen_group
|
|
356
|
+
self.g2 = trans_group
|
|
357
|
+
self.dof_numbers = None
|
|
358
|
+
self.ls = None
|
|
359
|
+
|
|
360
|
+
def __iter__(self):
|
|
361
|
+
yield self.x
|
|
362
|
+
yield self.g1
|
|
363
|
+
yield self.g2
|
|
364
|
+
|
|
365
|
+
def add_cell(self, cell):
|
|
366
|
+
self.g1 = self.g1.add_cell(cell)
|
|
367
|
+
self.g2 = self.g2.add_cell(cell)
|
|
368
|
+
|
|
369
|
+
def num_dofs(self):
|
|
370
|
+
if self.dof_numbers is None:
|
|
371
|
+
raise ValueError("DOFs not generated yet")
|
|
372
|
+
return self.dof_numbers
|
|
373
|
+
|
|
374
|
+
def generate(self, cell, space, id_counter):
|
|
375
|
+
if self.ls is None:
|
|
376
|
+
self.ls = []
|
|
377
|
+
for l_g in self.x:
|
|
378
|
+
i = 0
|
|
379
|
+
for g in self.g1.members():
|
|
380
|
+
generated = l_g(g)
|
|
381
|
+
if not isinstance(generated, list):
|
|
382
|
+
generated = [generated]
|
|
383
|
+
for dof in generated:
|
|
384
|
+
dof.add_context(self, cell, space, g, id_counter, i)
|
|
385
|
+
id_counter += 1
|
|
386
|
+
i += 1
|
|
387
|
+
self.ls.extend(generated)
|
|
388
|
+
self.dof_numbers = len(self.ls)
|
|
389
|
+
self.dof_ids = [dof.id for dof in self.ls]
|
|
390
|
+
return self.ls
|
|
391
|
+
|
|
392
|
+
def make_entity_ids(self):
|
|
393
|
+
dofs = self.ls
|
|
394
|
+
entity_ids = {}
|
|
395
|
+
min_ids = dofs[0].cell.get_starter_ids()
|
|
396
|
+
|
|
397
|
+
top = dofs[0].cell.get_topology()
|
|
398
|
+
|
|
399
|
+
for dim in sorted(top):
|
|
400
|
+
entity_ids[dim] = {i: [] for i in top[dim]}
|
|
401
|
+
|
|
402
|
+
for i in range(len(dofs)):
|
|
403
|
+
entity = dofs[i].trace_entity
|
|
404
|
+
dim = entity.dim()
|
|
405
|
+
entity_ids[dim][entity.id - min_ids[dim]].append(i)
|
|
406
|
+
return entity_ids
|
|
407
|
+
|
|
408
|
+
def __repr__(self):
|
|
409
|
+
repr_str = "DOFGen("
|
|
410
|
+
for x_elem in self.x:
|
|
411
|
+
repr_str += "g(" + str(x_elem) + ")"
|
|
412
|
+
repr_str += str(self.g1) + str(self.g2) + ")"
|
|
413
|
+
return repr_str
|
|
414
|
+
|
|
415
|
+
def _to_dict(self):
|
|
416
|
+
o_dict = {"x": self.x, "g1": self.g1, "g2": self.g2}
|
|
417
|
+
return o_dict
|
|
418
|
+
|
|
419
|
+
def dict_id(self):
|
|
420
|
+
return "DOFGen"
|
|
421
|
+
|
|
422
|
+
def _from_dict(obj_dict):
|
|
423
|
+
return DOFGenerator(obj_dict["x"], obj_dict["g1"], obj_dict["g2"])
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
class ImmersedDOFs():
|
|
427
|
+
|
|
428
|
+
def __init__(self, target_cell, triple, trace, start_node=0):
|
|
429
|
+
self.target_cell = target_cell
|
|
430
|
+
self.triple = triple
|
|
431
|
+
self.C, self.V, self.E = triple
|
|
432
|
+
self.trace = trace(target_cell)
|
|
433
|
+
self.start_node = start_node
|
|
434
|
+
|
|
435
|
+
def __call__(self, g):
|
|
436
|
+
target_node, o = self.target_cell.permute_entities(g, self.C.dim())[self.start_node]
|
|
437
|
+
if self.C.dim() > 0 and o != o.group.identity:
|
|
438
|
+
raise ValueError("Not matching orientation - groups incorrect")
|
|
439
|
+
attachment = self.target_cell.cell_attachment(target_node)
|
|
440
|
+
new_dofs = []
|
|
441
|
+
|
|
442
|
+
def oriented_attachment(*x):
|
|
443
|
+
return attachment(*o(x))
|
|
444
|
+
|
|
445
|
+
for generated_dof in self.triple.generate():
|
|
446
|
+
new_dof = generated_dof.immerse(self.target_cell.get_node(target_node),
|
|
447
|
+
oriented_attachment,
|
|
448
|
+
self.trace, g, self.triple)
|
|
449
|
+
new_dofs.append(new_dof)
|
|
450
|
+
return new_dofs
|
|
451
|
+
|
|
452
|
+
def __repr__(self):
|
|
453
|
+
repr_str = ""
|
|
454
|
+
for dof_gen in self.E:
|
|
455
|
+
repr_str += "Im_" + str(self.trace) + "_" + str(self.target_cell) + "(" + str(dof_gen) + ")"
|
|
456
|
+
return repr_str
|
|
457
|
+
|
|
458
|
+
def _to_dict(self):
|
|
459
|
+
o_dict = {"target_cell": self.target_cell, "triple": self.triple, "trace": self.trace}
|
|
460
|
+
return o_dict
|
|
461
|
+
|
|
462
|
+
def dict_id(self):
|
|
463
|
+
return "ImmersedDOF"
|
|
464
|
+
|
|
465
|
+
def _from_dict(obj_dict):
|
|
466
|
+
return ImmersedDOFs(obj_dict["target_cell"], obj_dict["triple"], obj_dict["trace"])
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
def immerse(target_cell, triple, target_space, node=0):
|
|
470
|
+
return ImmersedDOFs(target_cell, triple, target_space, node)
|
fuse/utils.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import sympy as sp
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def fold_reduce(func_list, *prev):
|
|
6
|
+
"""
|
|
7
|
+
Right to left function comprehension
|
|
8
|
+
|
|
9
|
+
:param: func_list: list of functions
|
|
10
|
+
:param: prev: starting value(s)
|
|
11
|
+
"""
|
|
12
|
+
for func in reversed(func_list):
|
|
13
|
+
prev = func(*prev)
|
|
14
|
+
return prev
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def sympy_to_numpy(array, symbols, values):
|
|
18
|
+
"""
|
|
19
|
+
Convert a sympy array to a numpy array.
|
|
20
|
+
|
|
21
|
+
:param: array: sympy array
|
|
22
|
+
:param: symbols: array of symbols contained in the sympy exprs
|
|
23
|
+
:param: values: array of values to replace the symbols with.
|
|
24
|
+
|
|
25
|
+
Due to how sympy handles arrays, we need to squeeze if resulting array
|
|
26
|
+
is greater than 1 dimension to remove extra dimensions
|
|
27
|
+
"""
|
|
28
|
+
substituted = array.subs({symbols[i]: values[i] for i in range(len(values))})
|
|
29
|
+
nparray = np.array(substituted).astype(np.float64)
|
|
30
|
+
|
|
31
|
+
if len(nparray.shape) > 1:
|
|
32
|
+
return nparray.squeeze()
|
|
33
|
+
|
|
34
|
+
if len(nparray.shape) == 0:
|
|
35
|
+
return nparray.item()
|
|
36
|
+
|
|
37
|
+
return nparray
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def tabulate_sympy(expr, pts):
|
|
41
|
+
# expr: sp matrix expression in x,y,z for components of R^d
|
|
42
|
+
# pts: n values in R^d
|
|
43
|
+
# returns: evaluation of expr at pts
|
|
44
|
+
res = np.array(pts)
|
|
45
|
+
i = 0
|
|
46
|
+
syms = ["x", "y", "z"]
|
|
47
|
+
for pt in pts:
|
|
48
|
+
if not hasattr(pt, "__iter__"):
|
|
49
|
+
pt = (pt,)
|
|
50
|
+
subbed = expr.evalf(subs={syms[i]: pt[i] for i in range(len(pt))})
|
|
51
|
+
subbed = np.array(subbed).astype(np.float64)
|
|
52
|
+
res[i] = subbed[0]
|
|
53
|
+
i += 1
|
|
54
|
+
final = res.squeeze()
|
|
55
|
+
return final
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def max_deg_sp_mat(sp_mat):
|
|
59
|
+
degs = []
|
|
60
|
+
for comp in sp_mat:
|
|
61
|
+
# only compute degree if component is a polynomial
|
|
62
|
+
if sp.sympify(comp).as_poly():
|
|
63
|
+
degs += [sp.sympify(comp).as_poly().degree()]
|
|
64
|
+
return max(degs)
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|