integral over embedded, straight line #683
-
Given a topology and two points, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If the topology is 2d you can create a levelset that vanishes at the line through import numpy
from nutils import function
from nutils.topology import Topology
def make_line_2d(topo: Topology,
x: function.Array,
x0: numpy.ndarray,
x1: numpy.ndarray,
end_at_points=True,
maxrefine: int = 0) -> Topology:
'''Create a line topology through the given points.
By default the line topology ends in the given points. Setting
``end_at_points`` to false lets the line extend to the bounary of the
topology.
Parameters
----------
topo : :class:`nutils.topology.Topology`
The 2D topology to make a line in.
x : :class:`nutils.function.Array`
The geometry.
x0 : :class:`numpy.ndarray`
Let the line go through this point.
x1 : :class:`numpy.ndarray`
Let the line go through this point as well.
end_at_points : :class:`bool`
If true the line topology ends at the given points, otherwise the line
extends to the boundary of ``topo``.
maxrefine : :class:`int`
Number of times to refine. See :meth:`nutils.topology.Topology.trim`
Example
-------
>>> import numpy
>>> from nutils import function, mesh
>>> topo, geom = mesh.rectilinear([5, 5])
>>> line = make_line_2d(topo, geom, numpy.array([0.15, 0.35]), numpy.array([3.15, 4.35]))
>>> line.integrate(function.J(geom), degree=0).round(3)
5.0
'''
t = x1 - x0
n = numpy.array([-t[1], t[0]])
topo = topo.trim((x - x0) @ n, maxrefine=maxrefine, name='line')
if end_at_points:
topo = topo.trim(t @ t - abs((x1 + x0 - 2 * x) @ t), maxrefine=maxrefine)
return topo.boundary['line'] |
Beta Was this translation helpful? Give feedback.
-
You could also discretize the line with Gaussian quadratures, locate the points with |
Beta Was this translation helpful? Give feedback.
If the topology is 2d you can create a levelset that vanishes at the line through
x0
andx1
, trim the topology and take the trim boundary. Example for Nutils v6 and up: