I’m trying to define the acoustic eigenvalue problem on RT elements of lowest order.
(div u, div v) = lambda (u,v)
RTel = VectorElement("RT", mesh.ufl_cell(), 1)
print('Constructing the space ...')
space = FunctionSpace(mesh, RTel)
print('done ...')
'''Trial and test functions'''
print('The trial and test functions...')
u = TrialFunctions(space)
v = TestFunctions(space)
print('done...\n')
'''Left hand side'''
print('\t Constructing the bilinear forms')
a1 = (dot(div(u),div(v)))*dx
'''Right hand side'''
b = inner(u,v)*dx
I get the following msg:
ufl.log.UFLException: Don’t know how to split tensor valued mixed functions without flattened index space.
An RT element should not be a vector element, as the RT basis is already a vector, Ref:
If you use vector RT you would get some tensor space (this is not supported). If you want multiple RT elements, use ufl.MixedElement([RTelement,RTelement]) Where RTelement=FiniteElement("RT", mesh.ufl_cell(), 1)
I did what you recommended
" RTel = FiniteElement(“RT”, mesh.ufl_cell(), 1)
space = MixedElement([RTel, RTel])
"
and got the following error:
TypeError: \ When constructing an Argument, TestFunction or TrialFunction, you
must to provide a FunctionSpace and not a FiniteElement. The
FiniteElement class provided by ufl only represents an abstract finite
element space and is only used in standalone .ufl files, while the
FunctionSpace provides a full discrete function space over a given
mesh and should be used in dolfin programs in Python.
Fr another attempt:
I added the mesh to the mixed space " space = MixedElement(mesh,[RTel, RTel]) " and got the following error:
cells = tuple(sorted(set(element.cell() for element in elements) - set([None])))
AttributeError: ‘dolfin.cpp.generation.UnitSquareMesh’ object has no attribute ‘cell’
Traceback (most recent call last):
File “fenics_rt_acoustic.py”, line 67, in
space = FunctionSpace(mesh, (“RT”, 1))
File “/home/linda/miniconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/function/functionspace.py”, line 31, in init
self._init_from_ufl(*args, **kwargs)
File “/home/linda/miniconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/function/functionspace.py”, line 39, in _init_from_ufl
ufl.FunctionSpace.init(self, mesh.ufl_domain(), element)
File “/home/linda/miniconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/functionspace.py”, line 57, in init
if element.cell() != domain_cell:
AttributeError: ‘tuple’ object has no attribute ‘cell’
I had the old fenics installed, i’m installing now fenicx but having some trouble with the pakages.
I’ll try to resolve the issue first.
Would it be possible to build the problem on the old fenics=2019.1.0
I managed to install the package but I don’t know how to impose Dirichlet zero BC and I get the below error.
Blockquote
from dolfinx.mesh import create_unit_square
from dolfinx import mesh, plot, fem
from dolfinx.fem import locate_dofs_geometrical
import pyvista
print(pyvista.global_theme.jupyter_backend)
from ufl import TrialFunction, TestFunction, dot, div, inner ,dx
import numpy as np
import petsc4py as PETSc
from petsc4py.PETSc import ScalarType
import matplotlib.pyplot as plt
import math
from mpi4py import MPI
domain = create_unit_square(MPI.COMM_WORLD,
num_elemnts, num_elemnts,
mesh.CellType.triangle)
tdim = domain.topology.dim
topology, cell_types, geometry = plot.create_vtk_mesh(domain, tdim)
grid = pyvista.UnstructuredGrid(topology, cell_types, geometry)
plotter = pyvista.Plotter()
plotter.add_mesh(grid, show_edges=True)
plotter.view_xy()
plotter.show()
‘’‘The function spaces’‘’
print(‘Constructing the space …’)
space = fem.FunctionSpace(domain, (“RT”, 1))
print(‘done …\n’)
‘’‘Trial and test functions’‘’
print(‘The trial and test functions…’)
u = TrialFunction(space)
v = TestFunction(space)
print(‘done…\n’)
‘’‘The operators and the bilinear form’‘’
print(‘Constructing the bilinear forms…’)
‘’‘Left hand side’‘’
a1 = (dot(div(u),div(v)))*dx
‘’‘Right hand side’‘’
b = inner(u,v)*dx
print(‘done…\n’)
print(‘Impossing the BC…’)
‘’’ 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(domain, fdim, boundary_facets)
bc = fem.dirichletbc(ScalarType(0), boundary_dofs, space)
I get the following error:
boundary_dofs = fem.locate_dofs_topological(domain, fdim, boundary_facets)
File “/home/linda/miniconda3/envs/fenicsx-env/lib/python3.10/site-packages/dolfinx/fem/bcs.py”, line 89, in locate_dofs_topological
raise TypeError
TypeError
I Have managed to impose the Dirichlet BC, but I’m not sure if I did it correctly and would apprentice your input.
print('Impossing the BC...')
# 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(space, fdim, boundary_facets)
ubc = fem.Function(space)
ubc.vector.set(0.0)
bc = fem.dirichletbc(ubc, boundary_dofs)
Moreover, I would like to solve a generalized eigenvalue problem Ax = \lambda Bx.Thus, I need to impose zero on the BC of B. Previously in fenics I use to do bcs.zero(B).
How can I do this now?