Skip to content

Commit c91fedd

Browse files
committed
Revert "Fix ghost facet double-counting in solver natural BCs under MPI"
This reverts commit d998732.
1 parent d998732 commit c91fedd

File tree

6 files changed

+9
-279
lines changed

6 files changed

+9
-279
lines changed

src/underworld3/cython/petsc_compat.h

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -139,106 +139,6 @@ PetscErrorCode UW_DMPlexSetSNESLocalFEM(DM dm, PetscBool flag, void *ctx)
139139
#endif
140140
}
141141

142-
// Create a ghost-filtered copy of a DMLabel on a DM.
143-
//
144-
// PETSc's boundary integration and residual routines iterate over ALL stratum
145-
// points in a label, including ghost facets. For internal boundaries whose
146-
// facets sit between cells on different ranks, this leads to double-counting.
147-
//
148-
// This helper creates a new label (dstName) that contains only the owned
149-
// (non-ghost) points from srcLabel. Ghost points are identified via the
150-
// point SF: every leaf in the SF is a ghost point.
151-
//
152-
// Usage:
153-
// UW_CreateOwnedLabel(dm, srcLabel, "UW_Boundaries_no_ghost");
154-
// // The new label is now attached to dm under the given name.
155-
PetscErrorCode UW_CreateOwnedLabel(DM dm, DMLabel srcLabel, const char dstName[])
156-
{
157-
PetscInt pStart, pEnd;
158-
159-
PetscFunctionBeginUser;
160-
161-
// --- Build ghost-point bitset from the point SF ---
162-
PetscSF sf;
163-
PetscInt nleaves;
164-
const PetscInt *ilocal;
165-
PetscCall(DMGetPointSF(dm, &sf));
166-
PetscCall(PetscSFGetGraph(sf, NULL, &nleaves, &ilocal, NULL));
167-
PetscCall(DMPlexGetChart(dm, &pStart, &pEnd));
168-
169-
PetscBT ghostBT;
170-
PetscCall(PetscBTCreate(pEnd - pStart, &ghostBT));
171-
if (ilocal) {
172-
for (PetscInt i = 0; i < nleaves; i++) {
173-
PetscCall(PetscBTSet(ghostBT, ilocal[i] - pStart));
174-
}
175-
}
176-
177-
// --- Remove any pre-existing label with this name, then create fresh ---
178-
DMLabel existing;
179-
PetscCall(DMGetLabel(dm, dstName, &existing));
180-
if (existing) {
181-
PetscCall(DMRemoveLabel(dm, dstName, NULL));
182-
}
183-
PetscCall(DMCreateLabel(dm, dstName));
184-
185-
DMLabel dstLabel;
186-
PetscCall(DMGetLabel(dm, dstName, &dstLabel));
187-
188-
// --- Copy each stratum, keeping only owned points ---
189-
PetscInt numValues;
190-
IS valueIS;
191-
PetscCall(DMLabelGetNumValues(srcLabel, &numValues));
192-
PetscCall(DMLabelGetValueIS(srcLabel, &valueIS));
193-
194-
const PetscInt *values;
195-
PetscCall(ISGetIndices(valueIS, &values));
196-
197-
for (PetscInt v = 0; v < numValues; v++) {
198-
PetscInt val = values[v];
199-
200-
IS origIS;
201-
PetscCall(DMLabelGetStratumIS(srcLabel, val, &origIS));
202-
if (!origIS) continue;
203-
204-
PetscInt n;
205-
const PetscInt *indices;
206-
PetscCall(ISGetLocalSize(origIS, &n));
207-
PetscCall(ISGetIndices(origIS, &indices));
208-
209-
// Count owned points
210-
PetscInt nOwned = 0;
211-
for (PetscInt i = 0; i < n; i++) {
212-
if (!PetscBTLookup(ghostBT, indices[i] - pStart)) nOwned++;
213-
}
214-
215-
// Build owned-only index array
216-
PetscInt *owned;
217-
PetscCall(PetscMalloc1(nOwned, &owned));
218-
PetscInt j = 0;
219-
for (PetscInt i = 0; i < n; i++) {
220-
if (!PetscBTLookup(ghostBT, indices[i] - pStart)) {
221-
owned[j++] = indices[i];
222-
}
223-
}
224-
225-
PetscCall(ISRestoreIndices(origIS, &indices));
226-
PetscCall(ISDestroy(&origIS));
227-
228-
IS ownedIS;
229-
PetscCall(ISCreateGeneral(PETSC_COMM_SELF,
230-
nOwned, owned, PETSC_OWN_POINTER, &ownedIS));
231-
PetscCall(DMLabelSetStratumIS(dstLabel, val, ownedIS));
232-
PetscCall(ISDestroy(&ownedIS));
233-
}
234-
235-
PetscCall(ISRestoreIndices(valueIS, &values));
236-
PetscCall(ISDestroy(&valueIS));
237-
PetscCall(PetscBTDestroy(&ghostBT));
238-
239-
PetscFunctionReturn(PETSC_SUCCESS);
240-
}
241-
242142
// Simplified wrapper for DMPlexComputeBdIntegral.
243143
// Takes a single boundary pointwise function (for field 0) instead of an Nf-element array.
244144
//

src/underworld3/cython/petsc_extras.pxi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ cdef extern from "petsc_compat.h":
4343
PetscErrorCode UW_PetscDSViewWF(PetscDS)
4444
PetscErrorCode UW_PetscDSViewBdWF(PetscDS, PetscInt)
4545
PetscErrorCode UW_DMPlexSetSNESLocalFEM( PetscDM, PetscBool, void *)
46-
PetscErrorCode UW_CreateOwnedLabel( PetscDM, PetscDMLabel, const char[])
4746
PetscErrorCode UW_DMPlexComputeBdIntegral( PetscDM, PetscVec, PetscDMLabel, PetscInt, const PetscInt*, void*, PetscScalar*, void*)
4847

4948
cdef extern from "petsc.h" nogil:

src/underworld3/cython/petsc_generic_snes_solvers.pyx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ class SNES_Scalar(SolverBaseClass):
13171317
bc = PetscDSAddBoundary_UW(cdm.dm,
13181318
bc_type,
13191319
str(boundary+f"{bc.components}").encode('utf8'),
1320-
"UW_Boundaries_no_ghost".encode('utf8'), # ghost-filtered for natural BCs
1320+
"UW_Boundaries".encode('utf8'), # consolidated boundary label
13211321
bc.f_id, # field ID in the DM
13221322
num_constrained_components,
13231323
<const PetscInt *> &comps_view[0],
@@ -1535,7 +1535,6 @@ class SNES_Scalar(SolverBaseClass):
15351535
)
15361536

15371537
## Now add the boundary residual / jacobian terms
1538-
## Use ghost-filtered label to prevent double-counting on internal boundaries
15391538

15401539
cdef DMLabel c_label
15411540

@@ -1545,7 +1544,7 @@ class SNES_Scalar(SolverBaseClass):
15451544
boundary_id = bc.PETScID
15461545

15471546
value = self.mesh.boundaries[bc.boundary].value
1548-
bc_label = self.dm.getLabel("UW_Boundaries_no_ghost")
1547+
bc_label = self.dm.getLabel("UW_Boundaries")
15491548

15501549
label_val = value
15511550

@@ -2038,7 +2037,7 @@ class SNES_Vector(SolverBaseClass):
20382037
bc = PetscDSAddBoundary_UW(cdm.dm,
20392038
bc_type,
20402039
str(boundary+f"{bc.components}").encode('utf8'),
2041-
"UW_Boundaries_no_ghost".encode('utf8'), # ghost-filtered for natural BCs
2040+
"UW_Boundaries".encode('utf8'), # was: str(boundary)
20422041
bc.f_id, # field ID in the DM
20432042
num_constrained_components,
20442043
<const PetscInt *> &comps_view[0],
@@ -2073,7 +2072,7 @@ class SNES_Vector(SolverBaseClass):
20732072
bc = PetscDSAddBoundary_UW(cdm.dm,
20742073
bc_type,
20752074
str(boundary+f"{bc.components}").encode('utf8'),
2076-
"UW_Boundaries".encode('utf8'),
2075+
"UW_Boundaries".encode('utf8'), # was: str(boundary)
20772076
bc.f_id, # field ID in the DM
20782077
num_constrained_components,
20792078
<const PetscInt *> &comps_view[0],
@@ -2278,7 +2277,6 @@ class SNES_Vector(SolverBaseClass):
22782277
)
22792278

22802279
## SNES VECTOR ADD Boundary terms
2281-
## Use ghost-filtered label to prevent double-counting on internal boundaries
22822280

22832281
cdef DMLabel c_label
22842282

@@ -2288,7 +2286,8 @@ class SNES_Vector(SolverBaseClass):
22882286
boundary_id = bc.PETScID
22892287

22902288
value = self.mesh.boundaries[bc.boundary].value
2291-
bc_label = self.dm.getLabel("UW_Boundaries_no_ghost")
2289+
bc_label = self.dm.getLabel("UW_Boundaries")
2290+
#bc_label = self.dm.getLabel(boundary)
22922291

22932292
label_val = value
22942293

@@ -3455,7 +3454,7 @@ class SNES_Stokes_SaddlePt(SolverBaseClass):
34553454
bc = PetscDSAddBoundary_UW(cdm.dm,
34563455
bc_type,
34573456
str(boundary+f"{bc.components}").encode('utf8'),
3458-
str("UW_Boundaries_no_ghost").encode('utf8'), # ghost-filtered for natural BCs
3457+
str("UW_Boundaries").encode('utf8'),
34593458
bc.f_id, # field ID in the DM
34603459
num_constrained_components,
34613460
<const PetscInt *> &comps_view[0],
@@ -3553,7 +3552,8 @@ class SNES_Stokes_SaddlePt(SolverBaseClass):
35533552
boundary_id = bc.PETScID
35543553

35553554
value = self.mesh.boundaries[bc.boundary].value
3556-
bc_label = self.dm.getLabel("UW_Boundaries_no_ghost")
3555+
bc_label = self.dm.getLabel("UW_Boundaries")
3556+
# bc_label = self.dm.getLabel(boundary)
35573557

35583558
label_val = value
35593559

src/underworld3/cython/petsc_maths.pyx

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,6 @@ cdef extern from "petsc.h" nogil:
1515
PetscErrorCode DMPlexComputeCellwiseIntegralFEM( PetscDM, PetscVec, PetscVec, void* )
1616

1717

18-
def create_owned_label(dm, src_label_name, dst_label_name):
19-
"""Create a ghost-filtered copy of a DMLabel on a DM.
20-
21-
Ghost facets (identified via the point SF) are excluded from the
22-
destination label. This prevents double-counting when PETSc
23-
integrates over boundary label strata in parallel.
24-
25-
Parameters
26-
----------
27-
dm : PETSc.DM
28-
The distributed mesh DM.
29-
src_label_name : str
30-
Name of the source label (e.g. ``"UW_Boundaries"``).
31-
dst_label_name : str
32-
Name for the new ghost-filtered label (e.g. ``"UW_Boundaries_no_ghost"``).
33-
"""
34-
35-
cdef DM c_dm = dm
36-
src_label = dm.getLabel(src_label_name)
37-
if src_label is None:
38-
return
39-
40-
cdef DMLabel c_src = src_label
41-
UW_CreateOwnedLabel(c_dm.dm, c_src.dmlabel, dst_label_name.encode('utf8'))
42-
43-
4418
class Integral:
4519
"""
4620
The `Integral` class constructs the volume integral

src/underworld3/discretisation/discretisation_mesh.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,6 @@ class replacement_boundaries(Enum):
438438

439439
uw.mpi.barrier()
440440

441-
# Ghost-filtered copy for natural BC residual integration.
442-
# PETSc boundary integration iterates ALL label stratum points
443-
# including ghost facets, causing double-counting on internal
444-
# boundaries. The _no_ghost variant is used by solvers for
445-
# natural BC registration.
446-
from underworld3.cython.petsc_maths import create_owned_label
447-
create_owned_label(self.dm, "UW_Boundaries", "UW_Boundaries_no_ghost")
448-
449441
## ---
450442
## Note - coarsening callback is tricky because the coarse meshes do not have the labels
451443
##

tests/test_0503_solver_natural_bc.py

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)