We, i.e. OpenCode, looked into this and opened an issue: https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/work_items/2008__;!!G_uCfscf7eWS!YzRqjXF-XraRWaFn7Nd0GGCN3G-gtKPNN43WQUP_SZjctw-0NCav692K-HB0GA4DSZQffuNUZuuhRxi1tNKGjZJx9y9Ldqig$
On Thu, 2026-10-01 at 14:48 +0000, Blaise Bourdin wrote: > > Hi, > > Here is how I deal with this type of problem in mef90, which is > consistent with what Matt is suggesting: > > * I assume that the number of cell sets is << number of cells. > * I make a distinction between cell/face/vertex set based > quantities, and those defined on some finite element space (cell- > constant, vertex based etc) > * Set-based properties are either obtained from the options database > as needed, or stored in regular fortran arrays (or arrays of derived > types) > * Cell / Vertex / FE space based quantities use DM + Section + Vec > * I build 2 DMs: one for unknown and one for parameters, which is > passed in SNES / TS / TAO as part of a user context > * I find it easier to build the parameter DM from the bottom up, > using DMCreateSuperDM > > > Regards, > Blaise > > > > On Oct 1, 2026, at 7:28 AM, Matthew Knepley <[email protected]> > > wrote: > > > > > > > > Caution: External email. > > > > > > 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!YzRqjXF-XraRWaFn7Nd0GGCN3G-gtKPNN43WQUP_SZjctw-0NCav692K-HB0GA4DSZQffuNUZuuhRxi1tNKGjZJx9ylwOrlW$ > > > > > > - 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!YzRqjXF-XraRWaFn7Nd0GGCN3G-gtKPNN43WQUP_SZjctw-0NCav692K-HB0GA4DSZQffuNUZuuhRxi1tNKGjZJx9znh2NUX$ > > > > > > > > > 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 > > > > > the > > > > > underlying datastructure in PETSc? > > > > > > > > > > best regards, > > > > > Martin > > > -- KU Leuven Department of Computer Science Department of Materials Engineering Celestijnenlaan 200a 3001 Leuven, Belgium
