+
Skip to content

Fix RegionQuadraticQuadBoundary #933

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

Merged
merged 3 commits into from
Feb 7, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ All notable changes to this project will be documented in this file. The format
### Fixed
- Fix `Boundary(..., mode="and")` by ignoring any undefined axis.
- Fix `tools.hello_world(planestrain=True)` with the correct region `RegionQuad` for the plane-strain template.
- Fix the cells-array in `RegionQuadraticQuadBoundary` for midpoints of edges.

### Removed
- Remove the unused `shape`-argument in `element.Element(shape)`. Adopt the arbitrary-lagrange element to use its own `dim`-argument. This simplifies the creation of custom finite element formulations.
Expand Down
6 changes: 3 additions & 3 deletions src/felupe/region/_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def boundary_cells_quad8(mesh):

# complementary midpoints of edges for the creation of "boundary" quadratic quads
# (rotated quads with 1st edge as n-th edge of one original quad)
n = [5, 6, 7, 4]
p = [4, 5, 6, 7]
q = [6, 7, 4, 5]
n = [4, 6, 5, 7]
p = [5, 7, 6, 4]
q = [6, 4, 7, 5]

cells = np.dstack(
(
Expand Down
96 changes: 76 additions & 20 deletions tests/test_constitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def elasticity(x, mu, lmbda):
dsde = linear_elastic.hessian([F, None])


def test_umat_hyperelastic_statevars():
def test_umat_hyperelastic_statevars(close_figs=True):
r, x = pre(sym=False, add_identity=True)
F = x[0]

Expand All @@ -329,8 +329,11 @@ def test_umat_hyperelastic_statevars():
ux = fem.math.linsteps([1, 2, 1], num=10)
ax = umat.plot(ux=ux, bx=None, ps=None, incompressible=True)

if close_figs:
plt.close(ax.get_figure())


def test_umat_hyperelastic():
def test_umat_hyperelastic(close_figs=True):
r, x = pre(sym=False, add_identity=True)
F = x[0]

Expand Down Expand Up @@ -433,18 +436,34 @@ def neo_hooke(C, mu=1):

for incompressible in [False, True]:
ax = umat.plot(incompressible=incompressible)

if close_figs:
plt.close(ax.get_figure())

ax = umat.screenshot(incompressible=incompressible)

if close_figs:
plt.close(ax.get_figure())

umat = fem.Hyperelastic(fem.neo_hooke, mu=np.nan)

with pytest.raises(ValueError):
umat.plot(bx=None, ps=None)
ax = umat.plot(bx=None, ps=None)

if close_figs:
plt.close(ax.get_figure())

with pytest.raises(ValueError):
umat.plot(ux=None, bx=None)
ax = umat.plot(ux=None, bx=None)

if close_figs:
plt.close(ax.get_figure())

with pytest.raises(ValueError):
umat.plot(ux=None, ps=None)
ax = umat.plot(ux=None, ps=None)

if close_figs:
plt.close(ax.get_figure())


def test_umat_hyperelastic2():
Expand Down Expand Up @@ -476,7 +495,7 @@ def neo_hooke(F, mu=1):
assert np.allclose(dsde, dsde2)


def test_umat_viscoelastic():
def test_umat_viscoelastic(close_figs=True):
r, x = pre(sym=False, add_identity=True, add_random=True)
F = x[0]

Expand All @@ -503,13 +522,16 @@ def viscoelastic(C, Cin, mu, eta, dtime):
umat = fem.Hyperelastic(
fem.constitution.finite_strain_viscoelastic, nstatevars=6, **kwargs
)
umat.plot(
ax = umat.plot(
ux=fem.math.linsteps([1, 1.5, 1, 2, 1, 2.5, 1], num=15),
ps=None,
bx=None,
incompressible=True,
)

if close_figs:
plt.close(ax.get_figure())

s2, statevars_new = umat.gradient([F, statevars])
dsde2 = umat.hessian([F, statevars])

Expand Down Expand Up @@ -598,7 +620,7 @@ def test_elpliso():
dsde = umat.hessian([F, statevars])


def test_composite():
def test_composite(close_figs=True):
r, x = pre(sym=False, add_identity=True)
F = x[0]

Expand All @@ -608,11 +630,14 @@ def test_composite():

ax = umat.plot()

if close_figs:
plt.close(ax.get_figure())

dWdF, statevars_new = umat.gradient([F, None])
(d2WdFdF,) = umat.hessian([F, None])


def test_optimize():
def test_optimize(close_figs=True):
stretches, stresses = (
np.array(
[
Expand Down Expand Up @@ -646,11 +671,24 @@ def test_optimize():
* np.array([1.0, 0.0980665])
).T

for model in [
fem.extended_tube,
]:
umat = fem.Hyperelastic(model)
with pytest.warns():
umat_new, res = umat.optimize(ux=[stretches, stresses], incompressible=True)

ux = np.linspace(stretches.min(), stretches.max(), num=200)
ax = umat_new.plot(incompressible=True, ux=ux, bx=None, ps=None)
ax.plot(stretches, stresses, "C0x")

if close_figs:
plt.close(ax.get_figure())

for model in [
fem.neo_hooke,
fem.ogden,
fem.third_order_deformation,
fem.extended_tube,
fem.alexander,
]:
umat = fem.Hyperelastic(model)
Expand All @@ -660,6 +698,9 @@ def test_optimize():
ax = umat_new.plot(incompressible=True, ux=ux, bx=None, ps=None)
ax.plot(stretches, stresses, "C0x")

if close_figs:
plt.close(ax.get_figure())

for model in [
fem.neo_hooke,
fem.miehe_goektepe_lulei,
Expand All @@ -673,6 +714,9 @@ def test_optimize():
ax = umat_new.plot(incompressible=True, ux=ux, bx=None, ps=None)
ax.plot(stretches, stresses, "C0x")

if close_figs:
plt.close(ax.get_figure())


def test_lagrange():
r, x = pre(sym=False, add_identity=True)
Expand Down Expand Up @@ -766,40 +810,52 @@ def test_laplace():
assert A[0].shape == (3, 3, 3, 3, 1, 1)


def test_plot_negative_stretches():
def test_plot_negative_stretches(close_figs=True):
stretches = np.linspace(-0.5, 1, 16)
umat = fem.NeoHooke(mu=1.0, bulk=2.0)

for incompressible in [False, True]:
with pytest.raises(ValueError):
umat.plot(ux=stretches, incompressible=incompressible)
ax = umat.plot(ux=stretches, incompressible=incompressible)

if close_figs:
plt.close(ax.get_figure())

with pytest.raises(ValueError):
umat.plot(bx=stretches, incompressible=incompressible)
ax = umat.plot(bx=stretches, incompressible=incompressible)

if close_figs:
plt.close(ax.get_figure())

with pytest.raises(ValueError):
umat.plot(ps=stretches, incompressible=incompressible)
ax = umat.plot(ps=stretches, incompressible=incompressible)

if close_figs:
plt.close(ax.get_figure())


if __name__ == "__main__":

close_figs = True

test_nh()
test_linear()
test_linear_orthotropic()
test_linear_planestress()
test_linear_planestrain()
test_kinematics()
test_umat()
test_umat_hyperelastic()
test_umat_hyperelastic(close_figs=close_figs)
test_umat_hyperelastic2()
test_umat_hyperelastic_statevars()
test_umat_viscoelastic()
test_umat_hyperelastic_statevars(close_figs=close_figs)
test_umat_viscoelastic(close_figs=close_figs)
test_umat_viscoelastic2()
test_umat_strain()
test_umat_strain_plasticity()
test_elpliso()
test_composite()
test_optimize()
test_composite(close_figs=close_figs)
test_optimize(close_figs=close_figs)
test_lagrange()
test_lagrange_statevars()
test_laplace()
test_plot_negative_stretches()
test_plot_negative_stretches(close_figs=True)
4 changes: 3 additions & 1 deletion tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def test_job():


def test_job_xdmf():
field, step = pre(SolidBodyForce=fem.SolidBodyGravity)
with pytest.warns(): # solidbodygravity is deprecated
field, step = pre(SolidBodyForce=fem.SolidBodyGravity)

job = fem.Job(steps=[step])
job.evaluate()

Expand Down
10 changes: 10 additions & 0 deletions tests/test_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,15 @@ def test_region():
assert not np.any(r.dV <= 0)


def test_region_negative_volumes_cells():

mesh = fem.Rectangle()
mesh.cells = mesh.cells[:, ::-1]

with pytest.warns(): # negative volumes of cells
region = fem.RegionQuad(mesh)


if __name__ == "__main__":
test_region()
test_region_negative_volumes_cells()
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载