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

2D mesh and 3D problem

+1 vote

Hi,

Is it possible to define a 3D function over a 2D mesh?

Because setting dim=3 in VectorElement does not change the dimension of the problem.

from dolfin import *

mesh=UnitSquareMesh(3,3)

V = VectorElement("CG", mesh.ufl_cell(),degree=1, dim=3)
Vf = FunctionSpace(mesh,V)
print "dim=", Vf.ufl_cell().geometric_dimension()

Thanks.

asked Mar 23, 2017 by User04 FEniCS Novice (140 points)

The cell geometry and topology is different from your function space. This is expected. What do you want to achieve?

1 Answer

0 votes

There was a similar question with an answear some time ago, but I don't find it anymore. Nevertheless, here is the suggested workaround by reducing a 3D-mesh to a 2D-mesh with topological dimension 3 which works fine (but only in serial).

import dolfin as df

x_min, x_max = -1e2, 1e2
y_min, y_max = -1e2, 1e2
z_min, z_max = -1e2, 1e2
n_elem = 10
tol = 1e-2
z_offset = 0.0

cube_mesh = df.BoxMesh(df.Point(x_min, y_min, z_min),
                       df.Point(x_max, y_max, z_max), n_elem, n_elem, 2)
z_slice_mesh = df.BoundaryMesh(cube_mesh, 'exterior')

cc = df.CellFunction('size_t', z_slice_mesh, 0)
zs = df.AutoSubDomain(lambda x: x[2] < z_min + tol)
zs.mark(cc, 1)
z_2D_mesh = df.SubMesh(z_slice_mesh, cc, 1)
z_2D_mesh.coordinates()[:, 2] -= z_min + z_offset

mesh = z_2D_mesh
V = df.VectorElement("CG", mesh.ufl_cell(),degree=1, dim=3)
Vf = df.FunctionSpace(mesh,V)
print('dim= ', Vf.ufl_cell().geometric_dimension()
print mesh.coordinates()

You have 3D coordinates with z=0 now, but that should not be a problem I think. Of course you can also adapt this code snippet for x- or y- slices.

answered Mar 23, 2017 by RR FEniCS User (3,330 points)
...