This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Plotting Error

0 votes

I am trying to view the geometry of a CSG 3D-geometry, but run into an error.

Here is a portion of the code:

Nx = 10
Ny = 0.25*Nx
Nz = 0.3*Nx

# 6 rows x 3 cols

x = 5 # space between rows
centerX = -5 # center nickel x
centerY = -15 # center nickel y
left = centerX - 15
right = centerX + 15
baseHeight = 250 # start height of nickels
diameter = 32 # diameter of cell
cellHeight = 3 # height of cell
cellBaseHeight = 253 # base height of cell

# Create geometry and define function space
box11 = Box(Point(centerX, centerY, baseHeight), Point(centerX + Nx, centerY + Ny, baseHeight + Nz))
box12 = Box(Point(left, centerY, baseHeight), Point(left + Nx, centerY + Ny, baseHeight + Nz))
box13 = Box(Point(right, centerY, baseHeight), Point(right + Nx, centerY + Ny, baseHeight + Nz))

box21 = Box(Point(centerX, centerY + x, baseHeight), Point(centerX + Nx, centerY + x + Ny, baseHeight + Nz))
box22 = Box(Point(left, centerY + x, baseHeight), Point(left + Nx, centerY + x + Ny, baseHeight + Nz))
box23 = Box(Point(right, centerY + x, baseHeight), Point(right + Nx, centerY + x + Ny, baseHeight + Nz))

box31 = Box(Point(centerX, centerY + x * 2, baseHeight), Point(centerX + Nx, centerY + x * 2 + Ny, baseHeight + Nz))
box32 = Box(Point(left, centerY + x * 2, baseHeight), Point(left + Nx, centerY + x * 2 + Ny, baseHeight + Nz))
box33 = Box(Point(right, centerY + x * 2, baseHeight), Point(right + Nx, centerY + x * 2 + Ny, baseHeight + Nz))

box41 = Box(Point(centerX, centerY + x * 3, baseHeight), Point(centerX + Nx, centerY + x * 3 + Ny, baseHeight + Nz))
box42 = Box(Point(left, centerY + x * 3, baseHeight), Point(left + Nx, centerY + x * 3 + Ny, baseHeight + Nz))
box43 = Box(Point(right, centerY + x * 3, baseHeight), Point(right + Nx, centerY + x * 3 + Ny, baseHeight + Nz))

box51 = Box(Point(centerX, centerY + x * 4, baseHeight), Point(centerX + Nx, centerY + x * 4 + Ny, baseHeight + Nz))
box52 = Box(Point(left, centerY + x * 4, baseHeight), Point(left + Nx, centerY + x * 4 + Ny, baseHeight + Nz))
box53 = Box(Point(right, centerY + x * 4, baseHeight), Point(right + Nx, centerY + x * 4 + Ny, baseHeight + Nz))

box61 = Box(Point(centerX, centerY + x * 5, baseHeight), Point(centerX + Nx, centerY + x * 5 + Ny, baseHeight + Nz))
box62 = Box(Point(left, centerY + x * 5, baseHeight), Point(left + Nx, centerY + x * 5 + Ny, baseHeight + Nz))
box63 = Box(Point(right, centerY + x * 5, baseHeight), Point(right + Nx, centerY + x * 5 + Ny, baseHeight + Nz))

cylinder = Cylinder(Point(0, 0, cellBaseHeight + cellHeight), Point(0, 0, cellBaseHeight), diameter, diameter, 20)

row1 = box11 + box12 + box13
row2 = box21 + box22 + box23
row3 = box31 + box32 + box33
row4 = box41 + box42 + box43
row5 = box51 + box52 + box53
row6 = box61 + box62 + box63

shape = cylinder + row1 + row2 + row3 + row4 + row5 + row6
plot(shape)

Here is the error:

Object cannot be plotted directly, projecting to piecewise linears.
Traceback (most recent call last):
    File "test.py", line 110, in <module>
        plot(shape)
    File "/usr/lib/python2.7/dist-packages/dolfin/common/plotting.py", line 126 in plot
        object = project(object, mesh=mesh)
    File "/usr/lib/python2.7/dist-packages/dolfin/fem/projection.py", line 90, in project
        V = extract_function_space(v, mesh)
    File "/usr/lib/python2.7/dist-packages/dolfin/fem/projection.py", line 126, in _extract_function_space
        domain = expression.domain()
AttributeError: 'CSGUnion' object has no attribute 'domain'

How do I fix this?

asked Mar 23, 2017 by nicsn FEniCS Novice (150 points)

1 Answer

+1 vote

I don't think you can plot the geometry, but you can generate and plot the mesh:

mesh = generate_mesh(shape, 15)
plot(mesh, interactive=True)
answered Mar 27, 2017 by johannr FEniCS Expert (17,350 points)
...