from mpi4py import MPI
from dolfinx import mesh
import numpy as np
from dolfinx.fem import FunctionSpace
from dolfinx import fem
import ufl
from petsc4py.PETSc import ScalarType
domain = mesh.create_unit_square(MPI.COMM_WORLD, 8, 8, mesh.CellType.quadrilateral)
V = FunctionSpace(domain, ("CG", 1))
uD = fem.Function(V)
uD.interpolate(lambda x: 1 + x[0]**2 + 2 * x[1]**2)
# Create facet to cell connectivity required to determine boundary facets
tdim = domain.topology.dim
fdim = tdim - 1
domain.topology.create_connectivity(fdim, tdim)
boundary_facets = mesh.exterior_facet_indices(domain.topology)
boundary_dofs = fem.locate_dofs_topological(V, fdim, boundary_facets)
bc = fem.dirichletbc(uD, boundary_dofs)
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
f = fem.Constant(domain, ScalarType(-6))
a = ufl.dot(ufl.grad(u), ufl.grad(v)) * ufl.dx
v = fem.Constant(domain.ufl_cell(), np.float32)
# from test file...
xtype = np.float32.real.dtype
domain2 = mesh.create_unit_square(MPI.COMM_WORLD, 4, 4, dtype=xtype)
v = fem.Constant(domain2.ufl_cell(), dtype(1))
u = fem.Function(FunctionSpace(domain2, ("Lagrange", 1)), dtype=dtype)
fem.Expression(v, u.function_space.element.interpolation_points())
fem.Expression(v, u.function_space.element.interpolation_points(), comm=MPI.COMM_WORLD)
fem.Expression(v, u.function_space.element.interpolation_points(), comm=MPI.COMM_SELF)
I brought this over from the test file. So far the difficulties I will have to work through are:
- The data typing (dtype) and how to free that from a pytest format.
- The ufl that I would like an expression to is ‘a’ not ‘v’, how to swap v, for a and get that to work.
- How to swap domain as opposed to domain2 which came from the pytest example.
Anyone can shed light on how to get those things working?
…
…
…
Just an aside but at the current time:
root@1bb2dcd10d7b:~/shared/dolfinx/python# /usr/bin/env /bin/python3 /root/.vscode-server/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 57547 -- /root/shared/dolfinx/python/test/unit/fem/test_expression.py
Traceback (most recent call last):
File "/root/shared/dolfinx/python/test/unit/fem/test_expression.py", line 12, in <module>
from dolfinx.fem import (Constant, Expression, Function, FunctionSpace,
File "/usr/local/dolfinx-real/lib/python3.10/dist-packages/dolfinx/__init__.py", line 29, in <module>
from dolfinx import common
File "/usr/local/dolfinx-real/lib/python3.10/dist-packages/dolfinx/common.py", line 11, in <module>
from dolfinx import cpp as _cpp
ImportError: /usr/local/dolfinx-real/lib/libdolfinx.so.0.6: undefined symbol: _ZNK5basix13FiniteElement25interpolation_is_identityEv
root@1bb2dcd10d7b:~/shared/dolfinx/python#
when running the test file in question but at the current time I don’t know if I should try to compile cpp into the container or what might be wrong with symbols that are missing… I am using the r1 cpp container.