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

Drop quadpy #96

Merged
merged 3 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion felupe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
FieldMixed,
)
from .dof import Boundary

try:
from .dof import (
MultiPointConstraint,
MultiPointConstraint,
MultiPointContact,
)
except:
Expand Down
4 changes: 3 additions & 1 deletion felupe/_field/_axi.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def _grad_2d(self, sym=False):
# w.r.t. undeformed coordinate "J" evaluated at quadrature point "p"
# for each cell "e"
g = np.einsum(
"ca...,aJpc->...Jpc", self.values[self.region.mesh.cells], self.region.dhdX,
"ca...,aJpc->...Jpc",
self.values[self.region.mesh.cells],
self.region.dhdX,
)

if sym:
Expand Down
4 changes: 3 additions & 1 deletion felupe/_field/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ def grad(self, sym=False):
# w.r.t. undeformed coordinates "J" evaluated at quadrature point "p"
# for each cell "e"
g = np.einsum(
"ea...,aJpe->...Jpe", self.values[self.region.mesh.cells], self.region.dhdX,
"ea...,aJpe->...Jpe",
self.values[self.region.mesh.cells],
self.region.dhdX,
)

if sym:
Expand Down
1 change: 1 addition & 0 deletions felupe/dof/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
symmetry,
uniaxial,
)

try:
from ._multipoint import (
MultiPointConstraint,
Expand Down
6 changes: 5 additions & 1 deletion felupe/element/_triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ def gradient(self, rs):

dhdr_a = np.array([[-1, -1], [1, 0], [0, 1]], dtype=float)
dhdr_b = np.array(
[[4 * (t1 - t2), -4 * t2], [4 * t3, 4 * t2], [-4 * t3, 4 * (t1 - t2)],]
[
[4 * (t1 - t2), -4 * t2],
[4 * t3, 4 * t2],
[-4 * t3, 4 * (t1 - t2)],
]
)
dhdr = np.vstack((dhdr_a, dhdr_b))
dhdr[0] += -dhdr[3] / 2 - dhdr[5] / 2
Expand Down
18 changes: 15 additions & 3 deletions felupe/mesh/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ def add_midpoints_edges(points, cells, cell_type):
}

# collect edges
points_edges, cells_edges = collect_edges(points, cells, cell_type,)
points_edges, cells_edges = collect_edges(
points,
cells,
cell_type,
)

# add offset to point index for edge-midpoints
# in additional cells array
Expand Down Expand Up @@ -424,7 +428,11 @@ def add_midpoints_faces(points, cells, cell_type):
}

# collect faces
points_faces, cells_faces = collect_faces(points, cells, cell_type,)
points_faces, cells_faces = collect_faces(
points,
cells,
cell_type,
)

# add offset to point index for faces-midpoints
# in additional cells array
Expand Down Expand Up @@ -452,7 +460,11 @@ def add_midpoints_volumes(points, cells, cell_type):
}

# collect volumes
points_volumes, cells_volumes = collect_volumes(points, cells, cell_type,)
points_volumes, cells_volumes = collect_volumes(
points,
cells,
cell_type,
)

# add offset to point index for volumes-midpoints
# in additional cells array
Expand Down
28 changes: 11 additions & 17 deletions felupe/quadrature/_gausslegendre.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

"""

import quadpy
import numpy as np
from string import ascii_lowercase

from . import Scheme

Expand All @@ -44,23 +45,16 @@ def __init__(self, order: int, dim: int):
"""
# integration point weights and coordinates

if dim == 3:
scheme = quadpy.c3.product(quadpy.c1.gauss_legendre(order + 1))

elif dim == 2:
scheme = quadpy.c2.product(quadpy.c1.gauss_legendre(order + 1))

elif dim == 1:
scheme = quadpy.c1.gauss_legendre(order + 1)
scheme.points = scheme.points.reshape(1, -1)

else:
if dim not in [1, 2, 3]:
raise ValueError("Wrong dimension.")

if dim > 1:
weights = scheme.weights * 2 ** dim
x, w = np.polynomial.legendre.leggauss(1 + order)

points = (
np.stack(np.meshgrid(*([x] * dim), indexing="ij"))[::-1].reshape(dim, -1).T
)

else:
weights = scheme.weights
idx = list(ascii_lowercase)[:dim]
weights = np.einsum(", ".join(idx), *([w] * dim)).ravel()

super().__init__(scheme.points.T, weights)
super().__init__(points, weights)
4 changes: 3 additions & 1 deletion felupe/tools/_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def save(

mesh = meshio.Mesh(
points=mesh.points,
cells=[(mesh.cell_type, mesh.cells),],
cells=[
(mesh.cell_type, mesh.cells),
],
point_data=point_data,
cell_data=cell_data,
)
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ classifiers = [
dependencies = [
"numpy",
"scipy",
"quadpy",
"h5py",
"meshio",
]
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ packages = find:
install_requires =
numpy
scipy
quadpy
h5py
meshio
python_requires = >=3.6
Expand Down
13 changes: 11 additions & 2 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ def test_solve_check():
fe.tools.save(r, u)
fe.tools.save(r, u, r=b)
fe.tools.save(
r, u, r=b, F=F, gradient=W.gradient(F),
r,
u,
r=b,
F=F,
gradient=W.gradient(F),
)

force = fe.tools.force(u, b, bounds["symx"])
Expand Down Expand Up @@ -118,7 +122,12 @@ def test_solve_mixed_check():
fe.tools.save(r, f, unstack=unstack)
fe.tools.save(r, f, r=b, unstack=unstack)
fe.tools.save(
r, f, r=b, unstack=unstack, F=F, gradient=W_mixed.gradient(F, p, J),
r,
f,
r=b,
unstack=unstack,
F=F,
gradient=W_mixed.gradient(F, p, J),
)

force = fe.tools.force(u, b, bounds["symx"], unstack=unstack)
Expand Down