Skip to content

Commit b32c2ed

Browse files
committed
DG work
1 parent 7dfd017 commit b32c2ed

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

demo.py renamed to check_simple.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
from firedrake import *
22

33

4-
# plex = PETSc.DMPlex().createBoxMesh(
5-
# (2, 2, 2),
6-
# lower=(0, 0, 0),
7-
# upper=(1, 1, 1),
8-
# simplex=False,
9-
# periodic=True,
10-
# interpolate=True,
11-
# sparseLocalize=False,
12-
# )
13-
# mesh = Mesh(plex)
14-
154
mesh = UnitSquareMesh(2, 2)
16-
V = FunctionSpace(mesh, "DG", 1)
175
x, _ = SpatialCoordinate(mesh)
186

197
assert np.allclose(assemble(1 * dx(domain=mesh)), 1)

firedrake/cython/dmcommon.pyx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3930,29 +3930,31 @@ def set_coordinate_section_and_such(mesh, coordinates):
39303930
plex = mesh.topology_dm
39313931
coordinate_element = coordinates.ufl_element()
39323932
gdim = plex.getCoordinateDim()
3933+
3934+
# the existing section has the correct numbering but is scalar, expand to gdim
3935+
scalar_dm = coordinates.function_space().dm
3936+
scalar_section = scalar_dm.getLocalSection()
3937+
p_start, p_end = scalar_section.getChart()
3938+
3939+
vector_section = PETSc.Section().create(comm=scalar_section.comm)
3940+
vector_section.setNumFields(1)
3941+
vector_section.setFieldComponents(0, gdim)
3942+
vector_section.setChart(p_start, p_end)
3943+
vector_section.setPermutation(scalar_section.getPermutation())
3944+
3945+
for p in range(p_start, p_end):
3946+
scalar_ndof = scalar_section.getDof(p)
3947+
CHKERR(PetscSectionSetDof(vector_section.sec, p, scalar_ndof*gdim))
3948+
CHKERR(PetscSectionSetFieldDof(vector_section.sec, p, 0, scalar_ndof*gdim))
3949+
vector_section.setUp()
3950+
39333951
if coordinate_element.family() == "Lagrange":
3934-
# the existing section has the correct numbering but is scalar, expand to gdim
3935-
scalar_dm = coordinates.function_space().dm
3936-
scalar_section = scalar_dm.getLocalSection()
3937-
p_start, p_end = scalar_section.getChart()
3938-
3939-
vector_section = PETSc.Section().create(comm=scalar_section.comm)
3940-
vector_section.setNumFields(1)
3941-
vector_section.setFieldComponents(0, gdim)
3942-
vector_section.setChart(p_start, p_end)
3943-
vector_section.setPermutation(scalar_section.getPermutation())
3944-
3945-
for p in range(p_start, p_end):
3946-
scalar_ndof = scalar_section.getDof(p)
3947-
CHKERR(PetscSectionSetDof(vector_section.sec, p, scalar_ndof*gdim))
3948-
CHKERR(PetscSectionSetFieldDof(vector_section.sec, p, 0, scalar_ndof*gdim))
3949-
vector_section.setUp()
3950-
3951-
# set coordinates
39523952
# apparently gdim ignored in this call and set explicitly below
39533953
CHKERR(DMSetCoordinateSection(plex.dm, gdim, vector_section.sec))
39543954
plex.setCoordinateDim(gdim)
3955-
39563955
plex.setCoordinatesLocal(coordinates.dat._vec)
39573956
else:
3958-
raise NotImplementedError("Need to do DG")
3957+
plex.setCellCoordinateDM(plex.getCoordinateDM().clone())
3958+
plex.setCellCoordinateSection(gdim, vector_section) # gdim ignored
3959+
plex.setCoordinateDim(gdim)
3960+
plex.setCellCoordinatesLocal(coordinates.dat._vec)

firedrake/mesh.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,13 @@ def callback(self):
23092309
# Finish the initialisation of mesh topology
23102310
self.topology.init()
23112311
coordinates_fs = functionspace.FunctionSpace(self.topology, self.ufl_coordinate_element())
2312+
2313+
# reordered_coords only needs to reorder the coordinates
2314+
# *some of the time*. If the input is a DM that has already
2315+
# been reordered to respect Firedrake then we don't have to do
2316+
# anything. Otherwise, we have the set the correct section.
2317+
# TODO: Ask Matt if there is a nice way to do this.
2318+
23122319
coordinates_data = dmcommon.reordered_coords(topology.topology_dm, coordinates_fs.dm.getDefaultSection(),
23132320
(self.num_vertices(), self.geometric_dimension()))
23142321
coordinates = function.CoordinatelessFunction(coordinates_fs,

0 commit comments

Comments
 (0)