Skip to content

Commit 3e2278e

Browse files
authored
Adjust positions of DOFs not on vertices (#186)
* Fix #185 * Don't adjust position of point evaluations
1 parent f961abb commit 3e2278e

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

symfem/finite_element.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,20 +423,20 @@ def plot_dof_diagram(
423423

424424
for dim, e in entities:
425425
dofs = dofs_by_subentity[dim][e]
426-
dofs.sort(key=lambda d: img.z(d.dof_point()))
426+
dofs.sort(key=lambda d: img.z(d.adjusted_dof_point()))
427427
for d in dofs:
428428
direction = d.dof_direction()
429429
if direction is not None:
430430
shifted = False
431431
for d2 in self.dofs:
432-
if d != d2 and d.dof_point() == d2.dof_point():
432+
if d != d2 and d.adjusted_dof_point() == d2.adjusted_dof_point():
433433
shifted = True
434434
break
435-
img.add_dof_arrow(d.dof_point(), direction, self.dofs.index(d),
435+
img.add_dof_arrow(d.adjusted_dof_point(), direction, self.dofs.index(d),
436436
colors.entity(d.entity[0]), shifted)
437437
else:
438438
img.add_dof_marker(
439-
d.dof_point(), self.dofs.index(d), colors.entity(d.entity[0]))
439+
d.adjusted_dof_point(), self.dofs.index(d), colors.entity(d.entity[0]))
440440

441441
img.save(filename, plot_options=plot_options)
442442

symfem/functionals.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ def dof_point(self) -> PointType:
9494
"""Get the location of the DOF in the cell."""
9595
pass
9696

97+
def adjusted_dof_point(self) -> PointType:
98+
"""Get the adjusted position of the DOF in the cell for plotting."""
99+
point = self.dof_point()
100+
if self.entity[0] == 0:
101+
return point
102+
103+
midpoint = self.reference.sub_entity(*self.entity).midpoint()
104+
return tuple(
105+
m + sympy.Rational(7, 10) * (p - m)
106+
for m, p in zip(midpoint, point))
107+
97108
def eval_symbolic(self, function: AnyFunction) -> ScalarFunction:
98109
"""Apply to the functional to a function."""
99110
e = self._eval_symbolic(function)
@@ -136,6 +147,10 @@ def dof_point(self) -> PointType:
136147
assert isinstance(pt, tuple)
137148
return pt
138149

150+
def adjusted_dof_point(self) -> PointType:
151+
"""Get the adjusted position of the DOF in the cell for plotting."""
152+
return self.dof_point()
153+
139154
def get_tex(self) -> typing.Tuple[str, typing.List[str]]:
140155
"""Get a representation of the functional as TeX, and list of terms involved."""
141156
assert isinstance(self.point, VectorFunction)
@@ -165,6 +180,10 @@ def dof_point(self) -> PointType:
165180
assert isinstance(pt, tuple)
166181
return pt
167182

183+
def adjusted_dof_point(self) -> PointType:
184+
"""Get the adjusted position of the DOF in the cell for plotting."""
185+
return self.dof_point()
186+
168187
def get_tex(self) -> typing.Tuple[str, typing.List[str]]:
169188
"""Get a representation of the functional as TeX, and list of terms involved."""
170189
assert isinstance(self.point, VectorFunction)
@@ -199,6 +218,10 @@ def dof_point(self) -> PointType:
199218
assert isinstance(pt, tuple)
200219
return pt
201220

221+
def adjusted_dof_point(self) -> PointType:
222+
"""Get the adjusted position of the DOF in the cell for plotting."""
223+
return self.dof_point()
224+
202225
def perform_mapping(
203226
self, fs: typing.List[AnyFunction], map: PointType, inverse_map: PointType, tdim: int
204227
) -> typing.List[AnyFunction]:
@@ -273,6 +296,10 @@ def dof_direction(self) -> typing.Union[PointType, None]:
273296
assert isinstance(d, tuple)
274297
return d
275298

299+
def adjusted_dof_point(self) -> PointType:
300+
"""Get the adjusted position of the DOF in the cell for plotting."""
301+
return self.dof_point()
302+
276303
def get_tex(self) -> typing.Tuple[str, typing.List[str]]:
277304
"""Get a representation of the functional as TeX, and list of terms involved."""
278305
assert isinstance(self.point, VectorFunction)
@@ -336,6 +363,10 @@ def dof_point(self) -> PointType:
336363
assert isinstance(pt, tuple)
337364
return pt
338365

366+
def adjusted_dof_point(self) -> PointType:
367+
"""Get the adjusted position of the DOF in the cell for plotting."""
368+
return self.dof_point()
369+
339370
def get_tex(self) -> typing.Tuple[str, typing.List[str]]:
340371
"""Get a representation of the functional as TeX, and list of terms involved."""
341372
desc = "v\\mapsto"
@@ -383,6 +414,10 @@ def dof_direction(self) -> typing.Union[PointType, None]:
383414
assert isinstance(lv, tuple)
384415
return lv
385416

417+
def adjusted_dof_point(self) -> PointType:
418+
"""Get the adjusted position of the DOF in the cell for plotting."""
419+
return self.dof_point()
420+
386421
def get_tex(self) -> typing.Tuple[str, typing.List[str]]:
387422
"""Get a representation of the functional as TeX, and list of terms involved."""
388423
assert isinstance(self.lvec, VectorFunction)
@@ -430,6 +465,10 @@ def dof_direction(self) -> typing.Union[PointType, None]:
430465
return v
431466
return None
432467

468+
def adjusted_dof_point(self) -> PointType:
469+
"""Get the adjusted position of the DOF in the cell for plotting."""
470+
return self.dof_point()
471+
433472
def get_tex(self) -> typing.Tuple[str, typing.List[str]]:
434473
"""Get a representation of the functional as TeX, and list of terms involved."""
435474
desc = "\\boldsymbol{v}\\mapsto"

0 commit comments

Comments
 (0)