Skip to content

Commit

Permalink
Fix svg plotting of quadratic 2D meshes (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinnala authored Nov 26, 2021
1 parent ffff920 commit 2ad3763
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ with respect to documented and/or tested features.
### Unreleased

- Fixed: `ElementDG` was not included in the wildcard import
- Fixed: Automatic visualization of `MeshTri2` and `MeshQuad2` in Jupyter
notebooks raised exception

### [5.0.0] - 2021-11-21

Expand Down
9 changes: 9 additions & 0 deletions skfem/mesh/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,15 @@ def init_refdom(cls):
"""Initialize a mesh corresponding to the reference domain."""
return cls(cls.elem.refdom.p, cls.elem.refdom.t, validate=False)

def morphed(self, *args):
"""Morph the mesh using functions."""
p = self.p.copy()
for i, arg in enumerate(args):
if arg is None:
continue
p[i] = arg(self.p)
return replace(self, doflocs=p)

def refined(self, times_or_ix: Union[int, ndarray] = 1):
"""Return a refined mesh.
Expand Down
4 changes: 4 additions & 0 deletions skfem/mesh/mesh_2d_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ def _repr_svg_(self) -> str:

def element_finder(self, *args, **kwargs):
raise NotImplementedError

@classmethod
def init_refdom(cls):
return cls.__bases__[-1].init_refdom()
23 changes: 22 additions & 1 deletion tests/test_visuals.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import unittest
import pytest

from skfem.mesh import MeshTri, MeshQuad, MeshTet, MeshLine1
from skfem.assembly import CellBasis
from skfem.mesh import (MeshTri, MeshQuad, MeshTet, MeshLine1, MeshTri2,
MeshQuad2)
from skfem.visuals.matplotlib import draw, plot, plot3
from skfem.visuals.svg import draw as drawsvg
from skfem.visuals.svg import plot as plotsvg


class CallDraw(unittest.TestCase):
Expand Down Expand Up @@ -42,3 +47,19 @@ class CallPlot3(unittest.TestCase):
def runTest(self):
m = self.mesh_type()
plot3(m, m.p[0])


@pytest.mark.parametrize(
"mtype",
[
MeshTri,
MeshQuad,
MeshTri2,
MeshQuad2,
]
)
def test_call_svg_plot(mtype):
m = mtype()
svg = drawsvg(m, nrefs=2)
basis = CellBasis(m, mtype.elem())
svg_plot = plotsvg(basis, m.p[0], nrefs=2)

0 comments on commit 2ad3763

Please sign in to comment.