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

Updates for development #11

Merged
merged 8 commits into from
Mar 26, 2024
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
16 changes: 4 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@ on:
jobs:
build-and-test:
runs-on: ubuntu-latest
container: ghcr.io/fenics/dolfinx/dolfinx:v0.7.2
container: ghcr.io/fenics/dolfinx/dolfinx:nightly
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Flake8 checks
- name: ruff checks
run: |
python3 -m flake8 fenicsx_shells
cd demo && python3 -m flake8 . && cd ../
python3 -m flake8 test
- name: isort checks (non-blocking)
continue-on-error: true
run: |
python3 -m isort --check fenicsx_shells
python3 -m isort --check demo
python3 -m isort --check test
ruff check .
ruff format --check .

- name: Install FEniCSx-Shells
run: |
pip install scikit-build-core[pyproject] # TO REMOVE ONCE 0.8.0 RELEASED
python3 -m pip install --no-build-isolation --check-build-dependencies .

- name: Build documentation
Expand Down
18 changes: 0 additions & 18 deletions CMakeLists.txt

This file was deleted.

11 changes: 7 additions & 4 deletions demo/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@


def pytest_addoption(parser):
parser.addoption("--mpiexec", action="store", default="mpirun",
help="Name of program to run MPI, e.g. mpiexex")
parser.addoption("--num-proc", action="store", default=1,
help="Number of MPI processes to use")
parser.addoption(
"--mpiexec",
action="store",
default="mpirun",
help="Name of program to run MPI, e.g. mpiexex",
)
parser.addoption("--num-proc", action="store", default=1, help="Number of MPI processes to use")


@pytest.fixture
Expand Down
51 changes: 28 additions & 23 deletions demo/demo_kirchhoff-love-clamped.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
# We begin by importing the necessary functionality from DOLFINx, UFL and
# PETSc.

from mpi4py import MPI

import numpy as np

import dolfinx
import ufl
from dolfinx.fem import FunctionSpace, dirichletbc
from basix.ufl import element, mixed_element
from dolfinx.fem import dirichletbc, functionspace
from dolfinx.fem.petsc import LinearProblem
from dolfinx.mesh import CellType, create_unit_square
from ufl import (FacetNormal, FiniteElement, Identity, Measure, MixedElement,
grad, inner, sym, tr)

from mpi4py import MPI
from ufl import FacetNormal, Identity, Measure, grad, inner, sym, tr

# We then create a two-dimensional mesh of the mid-plane of the plate $\Omega =
# [0, 1] \times [0, 1]$.
Expand All @@ -65,9 +65,10 @@

# +
k = 2
U_el = MixedElement([FiniteElement("Lagrange", ufl.triangle, k + 1),
FiniteElement("HHJ", ufl.triangle, k)])
U = FunctionSpace(mesh, U_el)
U_el = mixed_element(
[element("Lagrange", mesh.basix_cell(), k + 1), element("HHJ", mesh.basix_cell(), k)]
)
U = functionspace(mesh, U_el)

w, M = ufl.TrialFunctions(U)
w_t, M_t = ufl.TestFunctions(U)
Expand Down Expand Up @@ -148,7 +149,7 @@ def k_theta(theta):

def k_M(M):
"""Bending strain tensor in terms of bending moments"""
return (12.0/(E*t**3))*((1.0 + nu)*M - nu*Identity(2)*tr(M))
return (12.0 / (E * t**3)) * ((1.0 + nu) * M - nu * Identity(2) * tr(M))


def nn(M):
Expand All @@ -163,14 +164,16 @@ def inner_divdiv(M, theta):
"""Discrete div-div inner product"""
n = FacetNormal(M.ufl_domain())
M_nn = nn(M)
result = -inner(M, k_theta(theta))*dx + inner(M_nn("+"),
ufl.jump(theta, n))*dS + inner(M_nn, ufl.dot(theta, n))*ds
result = (
-inner(M, k_theta(theta)) * dx
+ inner(M_nn("+"), ufl.jump(theta, n)) * dS
+ inner(M_nn, ufl.dot(theta, n)) * ds
)
return result


a = inner(k_M(M), M_t)*dx + inner_divdiv(M_t, theta(w)) + \
inner_divdiv(M, theta(w_t))
L = -inner(t**3, w_t)*dx
a = inner(k_M(M), M_t) * dx + inner_divdiv(M_t, theta(w)) + inner_divdiv(M, theta(w_t))
L = -inner(t**3, w_t) * dx


def all_boundary(x):
Expand All @@ -187,15 +190,14 @@ def all_boundary(x):
# TODO: Add table like TDNNS example.

# +
boundary_entities = dolfinx.mesh.locate_entities_boundary(
mesh, mesh.topology.dim - 1, all_boundary)
boundary_entities = dolfinx.mesh.locate_entities_boundary(mesh, mesh.topology.dim - 1, all_boundary)

bcs = []
# Transverse displacement
boundary_dofs_displacement = dolfinx.fem.locate_dofs_topological(
U.sub(0), mesh.topology.dim - 1, boundary_entities)
bcs.append(dirichletbc(np.array(0.0, dtype=np.float64),
boundary_dofs_displacement, U.sub(0)))
U.sub(0), mesh.topology.dim - 1, boundary_entities
)
bcs.append(dirichletbc(np.array(0.0, dtype=np.float64), boundary_dofs_displacement, U.sub(0)))


# -
Expand All @@ -204,15 +206,18 @@ def all_boundary(x):
# centre of the plate.

# +
problem = LinearProblem(a, L, bcs=bcs, petsc_options={
"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps"})
problem = LinearProblem(
a,
L,
bcs=bcs,
petsc_options={"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps"},
)
u_h = problem.solve()

bb_tree = dolfinx.geometry.bb_tree(mesh, 2)
point = np.array([[0.5, 0.5, 0.0]], dtype=np.float64)
cell_candidates = dolfinx.geometry.compute_collisions_points(bb_tree, point)
cells = dolfinx.geometry.compute_colliding_cells(
mesh, cell_candidates, point)
cells = dolfinx.geometry.compute_colliding_cells(mesh, cell_candidates, point)

w, M = u_h.split()

Expand Down
65 changes: 39 additions & 26 deletions demo/demo_reissner-mindlin-clamped-tdnns.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# conditions using the TDNNS (tangential displacement normal-normal stress)
# element developed in:
#
# Pechstein, A. S., Schöberl, J. The TDNNS method for ReissnerMindlin plates.
# Numer. Math. 137, 713740 (2017).
# Pechstein, A. S., Schöberl, J. The TDNNS method for Reissner-Mindlin plates.
# Numer. Math. 137, 713-740 (2017).
# [doi:10.1007/s00211-017-0883-9](https://doi.org/10.1007/s00211-017-0883-9)
#
# The idea behind this element construction is that the rotations, transverse
Expand All @@ -37,17 +37,17 @@
# PETSc.

# +
from mpi4py import MPI

import numpy as np

import dolfinx
import ufl
from dolfinx.fem import Function, FunctionSpace, dirichletbc
from basix.ufl import element, mixed_element
from dolfinx.fem import Function, dirichletbc, functionspace
from dolfinx.fem.petsc import LinearProblem
from dolfinx.mesh import CellType, create_unit_square
from ufl import (FacetNormal, FiniteElement, Identity, Measure, MixedElement,
grad, inner, split, sym, tr)

from mpi4py import MPI
from ufl import FacetNormal, Identity, Measure, grad, inner, split, sym, tr

# -

Expand All @@ -74,9 +74,11 @@

# +
k = 3
U_el = MixedElement([FiniteElement("N2curl", ufl.triangle, k), FiniteElement("Lagrange", ufl.triangle, k + 1),
FiniteElement("HHJ", ufl.triangle, k)])
U = FunctionSpace(mesh, U_el)
cell = mesh.basix_cell()
U_el = mixed_element(
[element("N2curl", cell, k), element("Lagrange", cell, k + 1), element("HHJ", cell, k)]
)
U = functionspace(mesh, U_el)

u = ufl.TrialFunction(U)
u_t = ufl.TestFunction(U)
Expand All @@ -91,7 +93,7 @@
# +
E = 10920.0
nu = 0.3
kappa = 5.0/6.0
kappa = 5.0 / 6.0
t = 0.001
# -

Expand Down Expand Up @@ -143,13 +145,13 @@ def k_theta(theta):

def k_M(M):
"""Bending strain tensor in terms of bending moments"""
return (12.0/(E*t**3))*((1.0 + nu)*M - nu*Identity(2)*tr(M))
return (12.0 / (E * t**3)) * ((1.0 + nu) * M - nu * Identity(2) * tr(M))


def nn(M):
"""Normal-normal component of tensor"""
n = FacetNormal(M.ufl_domain())
M_n = M*n
M_n = M * n
M_nn = ufl.dot(M_n, n)
return M_nn

Expand All @@ -158,8 +160,11 @@ def inner_divdiv(M, theta):
"""Discrete div-div inner product"""
n = FacetNormal(M.ufl_domain())
M_nn = nn(M)
result = -inner(M, k_theta(theta))*dx + inner(M_nn("+"),
ufl.jump(theta, n))*dS + inner(M_nn, ufl.dot(theta, n))*ds
result = (
-inner(M, k_theta(theta)) * dx
+ inner(M_nn("+"), ufl.jump(theta, n)) * dS
+ inner(M_nn, ufl.dot(theta, n)) * ds
)
return result


Expand All @@ -168,9 +173,13 @@ def gamma(theta, w):
return grad(w) - theta


a = inner(k_M(M), M_t)*dx + inner_divdiv(M_t, theta) + inner_divdiv(M, theta_t) - \
((E*kappa*t)/(2.0*(1.0 + nu)))*inner(gamma(theta, w), gamma(theta_t, w_t))*dx
L = -inner(1.0*t**3, w_t)*dx
a = (
inner(k_M(M), M_t) * dx
+ inner_divdiv(M_t, theta)
+ inner_divdiv(M, theta_t)
- ((E * kappa * t) / (2.0 * (1.0 + nu))) * inner(gamma(theta, w), gamma(theta_t, w_t)) * dx
)
L = -inner(1.0 * t**3, w_t) * dx

# -

Expand Down Expand Up @@ -206,19 +215,20 @@ def all_boundary(x):
return np.full(x.shape[1], True, dtype=bool)


boundary_entities = dolfinx.mesh.locate_entities_boundary(
mesh, mesh.topology.dim - 1, all_boundary)
boundary_entities = dolfinx.mesh.locate_entities_boundary(mesh, mesh.topology.dim - 1, all_boundary)

bcs = []
# Transverse displacement
boundary_dofs = dolfinx.fem.locate_dofs_topological(
U.sub(1), mesh.topology.dim - 1, boundary_entities)
U.sub(1), mesh.topology.dim - 1, boundary_entities
)
bcs.append(dirichletbc(np.array(0.0, dtype=np.float64), boundary_dofs, U.sub(1)))

# Fix tangential component of rotation
R = U.sub(0).collapse()[0]
boundary_dofs = dolfinx.fem.locate_dofs_topological(
(U.sub(0), R), mesh.topology.dim - 1, boundary_entities)
(U.sub(0), R), mesh.topology.dim - 1, boundary_entities
)

theta_bc = Function(R)
bcs.append(dirichletbc(theta_bc, boundary_dofs, U.sub(0)))
Expand All @@ -229,15 +239,18 @@ def all_boundary(x):
# centre of the plate.

# +
problem = LinearProblem(a, L, bcs=bcs, petsc_options={
"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps"})
problem = LinearProblem(
a,
L,
bcs=bcs,
petsc_options={"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps"},
)
u_h = problem.solve()

bb_tree = dolfinx.geometry.bb_tree(mesh, 2)
point = np.array([[0.5, 0.5, 0.0]], dtype=np.float64)
cell_candidates = dolfinx.geometry.compute_collisions_points(bb_tree, point)
cells = dolfinx.geometry.compute_colliding_cells(
mesh, cell_candidates, point)
cells = dolfinx.geometry.compute_colliding_cells(mesh, cell_candidates, point)

theta, w, M = u_h.split()

Expand Down
Loading
Loading