On Wed, Sep 30, 2026 at 6:18 PM Martin Diehl <[email protected]>
wrote:
> Hello,
>
> we're using the "Cell Sets" of a DM created from a loaded *.msh file to
> communicate an ID that specifies the material behavior. That means:
> Each element has a tag in msh, and there are 1 to N_elem=N_cell
> different tags in the mesh.
>
I do not understand the last sentence. For example, if you have M different
materials in the mesh, I would say that you have M tags. In PETSc, we call
these "label values", and you can get the different ones with
DMLabelGetValueIS().
> The simplest implementation loops over all elements and query the value
> for "Cell Sets" with DMGetLabelValue.
That depends on what you want to do. For example, I often want to loop over
all the cells in a given material, so I use DMLabelGetStratumIS() which is
O(1)
and get the sorted list. You can use DMLabelGetValue(), but I tend to use
this
for random checks.
> Unfortunately, this is rather
> slow and has quadratic scaling in the case that there are N_elem
> different IDs.
Yes, this is definitely true if each cell has a different id. However, this
is not
the use case. If every cell has a different ID, just allocate an array and
do
direct lookup. You do not need a fancy data structure.
I think the usual use case is a few IDs which each map to a large number of
cells.
DMLabel is optimized for this kind of query, either with random lookup
(DMLabelGetValue)
or range queries (DMLabelGetStratumIS).
Can you explain the use case for each mesh point carrying a different value?
I have never had anything like this.
Thanks,
Matt
> We therefore came up with an alternative approach that
> is faster, but still scales quadratic for N_elem = ID.
>
> The code and figures showing the performance are attached. Is there a
> smarter way to do this or would that require modification of the
> underlying datastructure in PETSc?
>
> best regards,
> Martin
> --
> KU Leuven
> Department of Computer Science
> Department of Materials Engineering
> Celestijnenlaan 200a
> <https://urldefense.us/v3/__https://www.google.com/maps/search/Celestijnenlaan*200a?entry=gmail&source=g__;Kw!!G_uCfscf7eWS!e9oczEFpf3QX7GZ763G-rIhu_QEyDACrrQ5zgeTTHYsypwRCZsusINW2qufjxrlXZD_ZCQiCOR1izL_ANEkN$
> >
> 3001 Leuven, Belgium
>
--
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!e9oczEFpf3QX7GZ763G-rIhu_QEyDACrrQ5zgeTTHYsypwRCZsusINW2qufjxrlXZD_ZCQiCOR1izLNkYI_d$
<https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!e9oczEFpf3QX7GZ763G-rIhu_QEyDACrrQ5zgeTTHYsypwRCZsusINW2qufjxrlXZD_ZCQiCOR1izOtfiGTG$
>