Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use affine root coords as geom if possible #855

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions nutils/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ def rectilinear(richshape: Sequence[Union[int, Sequence[float]]], periodic: Sequ
axes = [transformseq.DimAxis(i=0, j=n, mod=n if idim in periodic else 0, isperiodic=idim in periodic) for idim, n in enumerate(shape)]
topo = topology.StructuredTopology(space, root, axes)

funcsp = topo.basis('spline', degree=1, periodic=())
coords = numeric.meshgrid(*verts).reshape(ndims, -1)
geom = (funcsp * coords).sum(-1)
if all(map(numeric.isint, richshape)):
flat_index = topo.f_index
rev_unraveled_index = []
for n in shape[:0:-1]:
rev_unraveled_index.append(flat_index % n)
flat_index //= n
rev_unraveled_index.append(flat_index)
geom = topo.f_coords + numpy.stack(rev_unraveled_index[::-1])
else:
funcsp = topo.basis('spline', degree=1, periodic=())
coords = numeric.meshgrid(*verts).reshape(ndims, -1)
geom = (funcsp * coords).sum(-1)

return topo, geom

Expand All @@ -52,10 +61,12 @@ def rectilinear(richshape: Sequence[Union[int, Sequence[float]]], periodic: Sequ
def line(nodes: Union[int, Sequence[float]], periodic: bool = False, bnames: Optional[Tuple[str, str]] = None, *, space: str = 'X', root: Optional[TransformItem] = None) -> Tuple[Topology, function.Array]:
if root is None:
root = transform.Index(1, 0)
nelems = nodes if isinstance(nodes, int) else len(nodes) - 1
domain = topology.StructuredLine(space, root, 0, nelems, periodic=periodic, bnames=bnames)
if isinstance(nodes, int):
nodes = numpy.arange(nodes + 1)
domain = topology.StructuredLine(space, root, 0, len(nodes) - 1, periodic=periodic, bnames=bnames)
geom = domain.basis('std', degree=1, periodic=[]).dot(nodes)
geom = domain.f_coords[0] + domain.f_index
else:
geom = domain.basis('std', degree=1, periodic=[]).dot(nodes)
return domain, geom


Expand Down
Loading