I have found the solution. For others to benafit (With fenicsx, I don’t know if it works with fenics) if you have a petsc matrix B and you want to convert it to numpy, just use
Thank you.
But I encountered now a new problem:
when I change the domain to quads I get the following:
Error:
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Cellname “quadrilateral” invalid for “Raviart-Thomas” finite element.
This is the code:
Blockquote
from dolfinx.mesh import create_unit_square, create_box, CellType
from dolfinx import mesh, plot, fem
from mpi4py import MPI
import numpy as np
import matplotlib.pyplot as plt
import pyvista # visualizing the mesh using pyvista, an interface to the VTK toolkit.
print(pyvista.global_theme.jupyter_backend)
from ufl import (VectorElement, FiniteElement, MixedElement )
###############################################################
Lx,Ly = 1,1.1
xL=[0,0]
xR=[Lx,Ly]
num_elemnts = 4
RT_order = 1
domain = mesh.create_rectangle(MPI.COMM_WORLD,
[np.array(xL), np.array(xR)],
[num_elemnts, num_elemnts], mesh.CellType.quadrilateral)
‘’’
domain = mesh.create_rectangle(MPI.COMM_WORLD,
[np.array(xL), np.array(xR)],
[num_elemnts, num_elemnts], mesh.CellType.triangle)
#############################################################
print(‘Constructing the mesh …’)
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()
print(‘done…’)
##############################################################
‘’‘The function spaces’‘’
print(‘Constructing the spaces …’)
RTelement = FiniteElement(“RT”,domain.ufl_cell(), RT_order)
DGelement = FiniteElement(“DG”,domain.ufl_cell(), RT_order-1)
Mixed_element = MixedElement([RTelement, DGelement])
MixedSpace = fem.FunctionSpace(domain, Mixed_element)
There is something that I don’t get or I’m missing.
I have previously defined it on a different problem with traig/quads elements and I get the correct results:
The code runs for both domains:
Blockquote
from dolfinx.mesh import create_unit_square, create_box, CellType
from dolfinx import mesh, plot, fem
from mpi4py import MPI
import numpy as np
import matplotlib.pyplot as plt
import pyvista # visualizing the mesh using pyvista, an interface to the VTK toolkit.
print(pyvista.global_theme.jupyter_backend)
from ufl import (VectorElement, FiniteElement, MixedElement )
###############################################################
Lx,Ly = 1,1.1
xL=[0,0]
xR=[Lx,Ly]
num_elemnts = 4
RT_order = 1
##############################################################
domain = mesh.create_rectangle(MPI.COMM_WORLD,
[np.array(xL), np.array(xR)],
[num_elemnts, num_elemnts], mesh.CellType.quadrilateral)
‘’’
domain = mesh.create_rectangle(MPI.COMM_WORLD,
[np.array(xL), np.array(xR)],
[num_elemnts, num_elemnts], mesh.CellType.triangle)
‘’’
#############################################################
print(‘Constructing the mesh …’)
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()
print(‘done…’)
##############################################################
‘’‘The function spaces’‘’
print(‘Constructing the spaces …’)
space = fem.FunctionSpace(domain, (“RT”, 1))
In the below code, I use the RT element with quads and it works fine. But in the previous code for the mixed space, I had to run it with RTCF with quads. I would like to understand why does it work in the below code and not with the mixed case?
from dolfinx.mesh import create_unit_square, create_box, CellType
from dolfinx import mesh, plot, fem
from mpi4py import MPI
import numpy as np
import matplotlib.pyplot as plt
import pyvista # visualizing the mesh using pyvista, an interface to the VTK toolkit.
print(pyvista.global_theme.jupyter_backend)
from ufl import (VectorElement, FiniteElement, MixedElement )
###############################################################
Lx,Ly = 1,1.1
xL=[0,0]
xR=[Lx,Ly]
num_elemnts = 4
RT_order = 1
##############################################################
domain = mesh.create_rectangle(MPI.COMM_WORLD,
[np.array(xL), np.array(xR)],
[num_elemnts, num_elemnts], mesh.CellType.quadrilateral)
‘’’
domain = mesh.create_rectangle(MPI.COMM_WORLD,
[np.array(xL), np.array(xR)],
[num_elemnts, num_elemnts], mesh.CellType.triangle)
‘’’
#############################################################
print(‘Constructing the mesh …’)
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()
print(‘done…’)
##############################################################
‘’‘The function spaces’‘’
print(‘Constructing the spaces …’)
space = fem.FunctionSpace(domain, (“RT”, 1))