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://doi.org/10.1007/s40192-024-00359-1 - 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://doi.org/10.1088/0965-0393/23/4/045005 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. > > 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 3001 Leuven, Belgium
signature.asc
Description: This is a digitally signed message part
