Hi, I post my script up to the boundary condition part, since I don’t know if any shortcuts cause issues with recreating. I marked the proplematic line with the comment <<<<===== This causes issues!
.
Since my problem only came with an software update of Fenicsx using the apt-package-manager, I do also post the printed version details underneath. Thank you so much for looking into this matter!
from dolfinx import *
from mpi4py import MPI
import numpy as np
import matplotlib.pyplot as plt
import ufl
import scipy.io
from petsc4py import PETSc
# mesh = UnitSquareMesh(MPI.COMM_WORLD, nx=1, ny=1, cell_type=cpp.mesh.CellType.quadrilateral) # Does not work either, neither the cell_type "cpp.mesh.CellType.quadrilateral"
# mesh = mesh.create_unit_square(MPI.COMM_WORLD, nx=1, ny=1) # https://docs.fenicsproject.org/dolfinx/main/python/generated/dolfinx.mesh.html#dolfinx.mesh.create_unit_cube
# mesh = UnitCubeMesh(MPI.COMM_WORLD, nx=1, ny=1, nz=1) # keine CellTypes in Docs zu finden für 3d, z.B. mesh.CellType.hexahedron aus Bsp. Hyperelasticity
mesh = mesh.create_unit_cube(MPI.COMM_WORLD, nx=1, ny=1, nz=1)
n = ufl.FacetNormal(mesh)
P = ufl.VectorElement("CG", mesh.ufl_cell(), 1)
R = ufl.TensorElement("DG", mesh.ufl_cell(), 1)
P_wish = ufl.VectorElement("CG", mesh.ufl_cell(), 1)
R_wish = ufl.TensorElement("DG", mesh.ufl_cell(), 1)
mel = ufl.MixedElement([P, R, P_wish, R_wish])
U = fem.FunctionSpace(mesh, mel)
u = fem.Function(U)
(p, F, v, P) = ufl.split(u)
(dv, dP, dp, dF) = ufl.TestFunctions(U)
rho_0=1
mu=1
lamb=1
Psi_fun=lambda F: mu/2*(np.trace(F.T@F)-3)-mu*np.log(np.sqrt(np.linalg.det(F.T@F)))+lamb/2*np.log(np.sqrt(np.linalg.det(F.T@F)))**2
P_fun=lambda F: ufl.dot(F,mu*(ufl.classes.Identity(F.ufl_shape[0])-ufl.inv(ufl.dot(F.T,F)))+lamb*ufl.ln(ufl.sqrt(ufl.classes.Determinant(ufl.dot(F.T,F))))*ufl.inv(ufl.dot(F.T,F)))
u_n = fem.Function(U)
(p_n, F_n, v_n, P_n) = ufl.split(u_n)
# Initial conditions:
def initial_cond(x,y,z):
return np.eye(F.ufl_shape[0])
def T(x):
values = np.zeros((mesh.geometry.dim*mesh.geometry.dim, x.shape[1]), dtype=np.float64)
values[0,:] = 1
values[4,:] = 1
values[8,:] = 1
return values
u.sub(1).interpolate(T)
T = 1.5
N = 300 #3000
dt = float(T / N)
time = np.zeros(N + 1)
v_DBC = np.zeros(N + 1)
q_NBC = np.zeros(N + 1)
Hamiltonian = np.zeros(N + 1)
# Physical Parameters
k_w = 3.0
rho_w = 2.0
boundaries = [(1, lambda x: np.isclose(x[0], 0)),
(2, lambda x: np.isclose(x[0], 1)),
(3, lambda x: np.isclose(x[1], 0)),
(4, lambda x: np.isclose(x[1], 1)),
(5, lambda x: np.isclose(x[2], 0)),
(6, lambda x: np.isclose(x[2], 1))]
facet_indices, facet_markers = [], []
fdim = mesh.topology.dim - 1
for (marker, locator) in boundaries:
facets = mesh.locate_entities(mesh, fdim, locator) # <<<<===== This causes issues!
facets = mesh.locate_entities(mesh, fdim, locator)
facet_indices.append(facets)
facet_markers.append(np.full(len(facets), marker))
facet_indices = np.array(np.hstack(facet_indices), dtype=np.int32)
facet_markers = np.array(np.hstack(facet_markers), dtype=np.int32)
sorted_facets = np.argsort(facet_indices)
facet_tag = MeshTags(mesh, fdim, facet_indices[sorted_facets], facet_markers[sorted_facets])
ds = ufl.Measure("ds", domain=mesh, subdomain_data=facet_tag)
ds_Dirichlet=ds(0)+ds(2)
ds_Neumann=ds(1)+ds(3)
Software version:
$ apt-cache madison fenicsx
fenicsx | 2:0.4.1.2~ppa1~jammy1 | https://ppa.launchpadcontent.net/fenics-packages/fenics/ubuntu jammy/main amd64 Packages
fenicsx | 2:0.4.1.2~ppa1~jammy1 | https://ppa.launchpadcontent.net/fenics-packages/fenics/ubuntu jammy/main i386 Packages
In python,
import dolfinx
print(dolfinx.__version__)
outputs
0.4.1