On Thu, Oct 1, 2026 at 1:10 AM Martin Diehl <[email protected]>
wrote:

> Hi Matt,
>
> thanks a lot. Pls. find answers below
>
> best regards,
> Martin
>
> On Wed, 2026-09-30 at 20:19 -0400, Matthew Knepley wrote:
> > 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().
> Your interpretation is correct. What I wanted to say that M can vary
> from 1 (same material everywhere) to N_elem/cell (each point has a
> different material).
> >
> > > 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.
> That is what we're looking for. Have one array of size N_cell and fill
> it with the material ID.
> >
> > 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).
> A moderate number of materials (in comparison to the mesh size) is also
> a common case for us.
> >
> > Can you explain the use case for each mesh point carrying a different
> > value?
> > I have never had anything like this.
> There are two similar cases when that appear in crystal plasticity
> modeling:
> - Use of measured microstructures, where (almost) each grid point has a
> different crystallographic orientation. An example is
> https://urldefense.us/v3/__https://doi.org/10.1007/s40192-024-00359-1__;!!G_uCfscf7eWS!YL-UtGx3FaGDf-Va3f6ZYt5O_02jP1yVVgaXl1MA_vmqt0Imy9q9COZlZrStUP7sRwL956TZEkwzg1dbDImQ$
>  
> - In component-scale simulations, it's not possible to resolve
> individual grains. To include anisotropy due to crystallographic
> texture, each cell gets its own orientation that is sampled from the
> texture. An example is 
> https://urldefense.us/v3/__https://doi.org/10.1088/0965-0393/23/4/045005__;!!G_uCfscf7eWS!YL-UtGx3FaGDf-Va3f6ZYt5O_02jP1yVVgaXl1MA_vmqt0Imy9q9COZlZrStUP7sRwL956TZEkwzg1ydhFSk$
>  
>
> We're also planning to implement heat conduction. In that case, the
> initial temperature could also vary from cell to cell and I expect a
> similar situation. But we have not looked into this yet.
>

Ah, your examples make this much clearer for me.

So DMLabel is intended for a small set of discrete labels, so it is not
appropriate here.

I would classify initial temperature and crystal orientation as "fields",
which could be usefully represented in the same way as solution fields. In
my examples, I do this with "auxiliary fields" in the DM. To do this, you
create an auxiliary DM, usually just with DMClone() of your solution DM
so that they share the same topology/geometry. You choose a discretization
for the fields. It sounds like the default (P0) is appropriate here, but
you could choose anything you like. Create a vector from the auxDM and
populate it with the values (note that you can have multiple fields in the
auxDM). Then when you want to lookup values, you use the Section that comes
with the auxDM.

Does that make sense?

  Thanks,

     Matt


> >
> >   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
> <https://urldefense.us/v3/__https://www.google.com/maps/search/uire*modification*of?entry=gmail&source=g__;Kys!!G_uCfscf7eWS!YL-UtGx3FaGDf-Va3f6ZYt5O_02jP1yVVgaXl1MA_vmqt0Imy9q9COZlZrStUP7sRwL956TZEkwzgw96HGWb$
>  >
> the
> > > underlying datastructure in PETSc?
> > >
> > > best regards,
> > > Martin
>
> --
> KU Leuven
> Department of Computer Science
> Department of Materials Engineering
> Celestijnenlaan 200a
> 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!YL-UtGx3FaGDf-Va3f6ZYt5O_02jP1yVVgaXl1MA_vmqt0Imy9q9COZlZrStUP7sRwL956TZEkwzg5oKvQCt$
  
<https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!YL-UtGx3FaGDf-Va3f6ZYt5O_02jP1yVVgaXl1MA_vmqt0Imy9q9COZlZrStUP7sRwL956TZEkwzg4BaQEgo$
 >

Reply via email to