Skip to content

Comparison between floats and pygalmesh.SizingFieldBase for cell sizes

Nico Schlömer edited this page Oct 1, 2020 · 1 revision

Using a SizingFieldBase instead of a float incurs a penalty of about 20% run time.

import perfplot
import pygalmesh


def cell_size_float(n):
    pygalmesh.generate_mesh(
        pygalmesh.Ball([0.0, 0.0, 0.0], 1.0),
        cell_size=1 / n,
        verbose=False
    )


def cell_size_function(n):
    class Field(pygalmesh.SizingFieldBase):
        def eval(self, x):
            return 1 / n

    pygalmesh.generate_mesh(
        pygalmesh.Ball([0.0, 0.0, 0.0], 1.0),
        cell_size=Field(),
        verbose=False
    )


perfplot.show(
    setup=lambda n: n,
    kernels=[cell_size_float, cell_size_function],
    n_range=[2 ** k for k in range(6)],
    equality_check=None,
    relative_to=0,
)
Clone this wiki locally