File: test_inr.py

package info (click to toggle)
pygalmesh 0.9.4-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,152 kB
  • sloc: cpp: 2,251; python: 1,562; makefile: 44
file content (42 lines) | stat: -rw-r--r-- 1,422 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pathlib
import tempfile

import helpers
import meshio

import pygalmesh


def test_inr():
    this_dir = pathlib.Path(__file__).resolve().parent
    # mesh = pygalmesh.generate_from_inr(
    #     this_dir / "meshes" / "skull_2.9.inr", max_cell_circumradius=5.0, verbose=False
    # )
    with tempfile.TemporaryDirectory() as tmp:
        out_filename = str(pathlib.Path(tmp) / "out.vtk")
        pygalmesh._cli.inr(
            [
                str(this_dir / "meshes" / "skull_2.9.inr"),
                out_filename,
                "--max-cell-circumradius",
                "5.0",
                "--quiet",
            ]
        )
        mesh = meshio.read(out_filename)

    tol = 2.0e-3
    ref = [2.031053e02, 3.739508e01, 2.425594e02, 2.558910e01, 2.300883e02, 1.775010e00]
    assert abs(max(mesh.points[:, 0]) - ref[0]) < tol * ref[0]
    assert abs(min(mesh.points[:, 0]) - ref[1]) < tol * ref[1]
    assert abs(max(mesh.points[:, 1]) - ref[2]) < tol * ref[2]
    assert abs(min(mesh.points[:, 1]) - ref[3]) < tol * ref[3]
    assert abs(max(mesh.points[:, 2]) - ref[4]) < tol * ref[4]
    tol = 5.0e-2
    assert abs(min(mesh.points[:, 2]) - ref[5]) < tol * ref[5]

    vol = sum(helpers.compute_volumes(mesh.points, mesh.get_cells_type("tetra")))
    ref = 2.725335e06
    # Debian needs 2.0e-2 here.
    # <https://github.com/nschloe/pygalmesh/issues/60>
    assert abs(vol - ref) < ref * 2.0e-2