How to use the dmsh.geometry.geometry.Geometry function in dmsh

To help you get started, we’ve selected a few dmsh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / dmsh / dmsh / geometry / halfspace.py View on Github external
"""This parametrization of the line is (inf, inf) for t=0 and t=1.
        """
        # Don't warn on division by 0
        with numpy.errstate(divide="ignore"):
            out = (
                numpy.multiply.outer(self.tangent, (2 * t - 1) / t / (1 - t)).T + self.v
            ).T
        return out

    def dp_dt(self, t):
        with numpy.errstate(divide="ignore"):
            dt = 1 / t ** 2 + 1 / (1 - t) ** 2
        return numpy.multiply.outer(self.tangent, dt)


class HalfSpace(Geometry):
    def __init__(self, normal, alpha):
        self.normal = normal
        self.alpha = alpha

        self.bounding_box = [-numpy.inf, +numpy.inf, -numpy.inf, +numpy.inf]
        self.feature_points = numpy.array([])

        # One point on the line:
        v = self.normal / numpy.dot(self.normal, self.normal) * self.alpha
        tangent = numpy.array([-self.normal[1], self.normal[0]])

        self.paths = [LinePath(v, tangent)]
        return

    def dist(self, x):
        assert x.shape[0] == 2
github nschloe / dmsh / dmsh / geometry / rotation.py View on Github external
import numpy

from .geometry import Geometry


class Rotation(Geometry):
    def __init__(self, geometry, angle):
        self.geometry = geometry

        self.R = numpy.array(
            [
                [+numpy.cos(angle), -numpy.sin(angle)],
                [+numpy.sin(angle), +numpy.cos(angle)],
            ]
        )
        self.R_inv = numpy.array(
            [
                [+numpy.cos(angle), +numpy.sin(angle)],
                [-numpy.sin(angle), +numpy.cos(angle)],
            ]
        )
github nschloe / dmsh / dmsh / geometry / polygon.py View on Github external
def __init__(self, x0, x1):
        self.x0 = x0
        self.x1 = x1
        return

    def p(self, t):
        return numpy.multiply.outer(self.x0, 1 - t) + numpy.multiply.outer(self.x1, t)

    def dp_dt(self, t):
        ones = numpy.ones(t.shape)
        return numpy.multiply.outer(self.x0, -ones) + numpy.multiply.outer(
            self.x1, ones
        )


class Polygon(Geometry):
    def __init__(self, points):
        points = numpy.array(points)
        self.bounding_box = [
            numpy.min(points[:, 0]),
            numpy.max(points[:, 0]),
            numpy.min(points[:, 1]),
            numpy.max(points[:, 1]),
        ]
        self.polygon = pypathlib.ClosedPath(points)
        self.feature_points = points
        self.paths = [
            LineSegmentPath(p0, p1)
            for p0, p1 in zip(points, numpy.roll(points, -1, axis=0))
        ]
        self.diameter = self.polygon.diameter
github nschloe / dmsh / dmsh / geometry / scaling.py View on Github external
import numpy

from .geometry import Geometry


class Scaling(Geometry):
    def __init__(self, geometry, alpha):
        self.geometry = geometry
        self.alpha = alpha
        self.bounding_box = alpha * numpy.array(geometry.bounding_box)
        self.feature_points = numpy.array([])
        return

    def dist(self, x):
        return self.geometry.dist(x / self.alpha)

    def boundary_step(self, x):
        return self.geometry.boundary_step(x / self.alpha) * self.alpha
github nschloe / dmsh / dmsh / geometry / union.py View on Github external
import numpy

from ..helpers import find_feature_points
from .geometry import Geometry


class Union(Geometry):
    def __init__(self, geometries):
        self.geometries = geometries
        self.bounding_box = [
            numpy.min([geo.bounding_box[0] for geo in geometries]),
            numpy.max([geo.bounding_box[1] for geo in geometries]),
            numpy.min([geo.bounding_box[2] for geo in geometries]),
            numpy.max([geo.bounding_box[3] for geo in geometries]),
        ]

        fp = [geo.feature_points for geo in geometries]
        fp.append(find_feature_points(geometries))
        self.feature_points = numpy.concatenate(fp)

        # Only keep the feature points on the outer boundary
        alpha = numpy.array([geo.dist(self.feature_points.T) for geo in geometries])
        tol = 1.0e-5
github nschloe / dmsh / dmsh / geometry / translation.py View on Github external
import numpy

from .geometry import Geometry


class Translation(Geometry):
    def __init__(self, geometry, v):
        self.geometry = geometry
        self.v = v

        self.bounding_box = [
            geometry.bounding_box[0] + v[0],
            geometry.bounding_box[1] + v[0],
            geometry.bounding_box[2] + v[1],
            geometry.bounding_box[3] + v[1],
        ]
        self.feature_points = numpy.array([])
        return

    def dist(self, x):
        return self.geometry.dist((x.T - self.v).T)