Skip to content

Add maximum marking#4156

Open
schnellerhase wants to merge 10 commits intomainfrom
schnellerhase/maximum-marking
Open

Add maximum marking#4156
schnellerhase wants to merge 10 commits intomainfrom
schnellerhase/maximum-marking

Conversation

@schnellerhase
Copy link
Copy Markdown
Contributor

@schnellerhase schnellerhase commented Apr 18, 2026

Implements a maximum marking criterion for AFEM schemes, i.e. for $\theta \in [0, 1]$ and a marker $\eta \in \mathbb{R}^N$, computes

$$ \mathcal{I} = \{ i \ | \ \eta_i \geq \theta \max_j \eta_j \}. $$

In particular this introduces/defines the interface for other marking routines (to follow in the future): based on a process local list of (entity-)indicators the (local) marked index set of it is computed.

Test program to visualise results (parallel ready).
from mpi4py import MPI

import numpy as np

from dolfinx import mesh, plot
import pyvista as pv

mesh_0 = mesh.create_unit_square(comm := MPI.COMM_WORLD, n := 10, n)

cell_im = mesh_0.topology.index_map(tdim := mesh_0.topology.dim)
cell_count = cell_im.size_local + cell_im.num_ghosts

marker = np.random.random(cell_count)
marked_cells = mesh.mark_maximum(marker, theta := 0.5, comm)

mesh_0.topology.create_entities(1)
marked_edges = mesh.compute_incident_entities(mesh_0.topology, marked_cells, tdim, 1)

mesh_1, _, _ = mesh.refine(mesh_0, marked_edges)

grid_0 = pv.UnstructuredGrid(*plot.vtk_mesh(mesh_0))
grid_1 = pv.UnstructuredGrid(*plot.vtk_mesh(mesh_1))

plotter = pv.Plotter(shape=(1, 2))
plotter.subplot(0, 0)
plotter.add_mesh(grid_0, show_edges=True)
plotter.view_xy()
plotter.add_text("mesh_0", position="upper_left")

plotter.subplot(0, 1)
plotter.add_mesh(grid_1, show_edges=True)
plotter.view_xy()
plotter.add_text("mesh_1", position="upper_left")

plotter.link_views()
plotter.show()

Work towards #4141.

@schnellerhase schnellerhase force-pushed the schnellerhase/maximum-marking branch 7 times, most recently from 275ba33 to 6c6adf9 Compare April 18, 2026 14:37
@schnellerhase schnellerhase added the enhancement New feature or request label Apr 18, 2026
@schnellerhase schnellerhase self-assigned this Apr 18, 2026
@schnellerhase schnellerhase force-pushed the schnellerhase/maximum-marking branch from 6c6adf9 to 60086aa Compare April 18, 2026 14:42
@schnellerhase schnellerhase marked this pull request as ready for review April 18, 2026 14:59
jhale
jhale previously requested changes Apr 20, 2026
Comment thread cpp/dolfinx/refinement/mark.h Outdated
Comment thread cpp/dolfinx/refinement/mark.h
Comment thread cpp/dolfinx/refinement/mark.h Outdated
: std::ranges::max(marker);
MPI_Allreduce(MPI_IN_PLACE, &max, 1, dolfinx::MPI::mpi_t<T>, MPI_MAX, comm);

auto mark = [=](auto e) { return e >= theta * max; };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use const T instead of auto e?

Also remove inequality, pointless for floating point arithmetic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to T - think we do not follow const correctness for trivial types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also remove inequality, pointless for floating point arithmetic.

Don't think this is correct: for $\theta=1.0$ and $\eta = [ 1, \dots, 1]$ that would then mark nothing (tested).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And through what astronomically unlikely event would eta be binary 1.0 for every cell?

Copy link
Copy Markdown
Contributor Author

@schnellerhase schnellerhase Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlikely but valid input to the function. We can either leave as is or change to $e + \epsilon &gt; \theta \max \eta$ for some close to machine epsilon $\epsilon$, which should ensure this edge case passes. Fine with both.

@schnellerhase schnellerhase requested a review from jhale April 20, 2026 10:36
Comment thread cpp/dolfinx/refinement/mark.h Outdated
Comment thread cpp/dolfinx/refinement/mark.h
@chrisrichardson chrisrichardson self-requested a review April 21, 2026 12:39
@chrisrichardson chrisrichardson added this pull request to the merge queue Apr 21, 2026
@jhale
Copy link
Copy Markdown
Member

jhale commented Apr 21, 2026

My comments on the floating point comparisons are not resolved.

@jhale jhale removed this pull request from the merge queue due to a manual request Apr 21, 2026
@chrisrichardson
Copy link
Copy Markdown
Contributor

@jhale - I think @schnellerhase did address it. Did you mean that it should be a simple > rather than >=?

@jhale
Copy link
Copy Markdown
Member

jhale commented Apr 21, 2026

Yes - the equality is completely redundant in a floating point context and the example given is a contrived one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants