-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mesh.save subdomains and boundaries #261
Comments
I think this shouldn't be a huge task to implement. I'll keep it in mind for future coding sessions. |
Not a huge task to implement, no, but maybe there is a preliminary question to think about: ‘tagged subsets of elements’ nschloe/meshio#290. The current However, the These two kinds of representations:
are discussed in nschloe/meshio#175, nschloe/meshio#290, nschloe/meshio#347, … The current behaviour of So I'm wondering whether it might be better to avoid that conversion and see whether (already or in the future) |
That |
In recent work reading and writing XDMF nschloe/meshio#599 nschloe/meshio#600, I noticed a couple of interesting features of the format that might be useful here:
I don't think either are supported in meshio yet, but that can be fixed. Other advanced mesh formats (MED, Exodus II, Silo, …?) might have something similar but I'm less familiar with them. I think the XDMF Face corresponds to a scikit-fem facet and is indexed as the facet of a cell rather than in a global array of facets, but that can be worked with via the scikit-fem/skfem/importers/meshio.py Line 91 in e77096e
(I've been pondering a comment in nschloe/meshio#571: ‘The devil invented mixed topologies.’) |
Currently there is the possibility to use |
I was thinking of an external format, yes:
I think this is a desirable long-term goal. I made efforts on the subdomains part in XDMF but met intransigence in nschloe/meshio#622. I haven't completely abandoned that proposal but wearying of the repeated rejection did experiment with pyexodus; that was just preliminary but did seem promising. |
I did have a different idea for this a while ago, if existing external formats proved too difficult. Leaning on another part of the Python standard library than JSON, I was looking at xdrlib, the idea being something as isomorphic as possible to I got this idea from (libMesh/External packages/Utilities).
A minor hindrance with XDR and JSON is that they don't support |
The thinking with pyexodus was probably not to wrap it for scikit-fem but to use it to learn how to save subdomains and boundaries (if indeed the Exodus format permits that) and then use the resulting Exodus files as examples for meshio, to see how much its Exodus writer and reader need extending. |
The comment in #556 yesterday was:
So as well as meshio, does that imply an existing file format? meshio no native serialization format. It does have sort of an internal data structure but it's evolving and not completely uniform with respect to the supported input and output formats. The The The main hurdle with Exodus is that I don't think meshio currently supports the its features that are needed here (see, e.g., nschloe/meshio#1031). I think it might be possible to get the required features into meshio, despite that having failed for XDMF; I think the Exodus specification is less ambiguous, which is what went wrong in nschloe/meshio#622. There is also pyexodus and the possibility of reading Exodus directly as HDF. Of course, whether meshio is used or not, relying on Exodus would introduce a dependency on Are there other options that I've overlooked? |
Oh yes, I had forgotten this discrepancy.
The missing support is probably because there is not a unique way of mapping internal elements to facets. We have one implementation in scikit-fem but other codes might do it differently and some additional details must be fixed to have a well defined format. So again it comes back to inventing our own format. |
Now that the new BaseMesh class in #556 will be "immutable", there should be no issues of simply dumping the contents into HDF5 directly using |
True, but also true of the ordering of nodes in some elements , which is handled as in Lines 66 to 67 in de01235
The XDMF spec says:
That's for an (I didn't know VTK had such an ordering. That might be worth looking into too.) |
I had a bit of a look for whether VTK had a way of serializing data on facets but didn't find anything in: |
Some thoughts provoked by the difficulties encountered in using meshio in #680: I wonder whether we might do better by avoiding meshio's Extension of that idea: some mesh formats (notably XDMF—see xdmf#15 nschloe/meshio#568, nschloe/meshio#622) don't like storing more than one kind of element. Could we get away from Gmsh's idea of representing boundary facets as lower-order elements and instead in the Would such a scheme:
How does this compare with #680 and its objectives? I'm not exactly sure what those are. Shall I develop this idea? Actually I'm not even sure that it needs support from the |
No good: a cell can have more than one facet on a boundary. |
Let me add a remark that in #680 the call m = MeshTet().with_boundaries({'left': lambda x: x[0]==0.0})
m.save('test.msh', write_boundaries=True, sets_to_int_data=True, binary=False, file_format='gmsh22') seems to produce completely reasonable results: Here is the resulting
|
MSH 4.1 is really confusing because the nodes must be assigned to geometric entities with some dimension ( |
Yes... One plan that i did have, but never tried, was to take a simple MSH 2.2 like that and ask Gmsh to update it to MSH 4.1. I hoped that that would shed light on what on Earth one is supposed to posit for entities. |
Another shortcoming with MSH 2.2 (and the simple integer tagging of cells in general, e.g. also in MEDIT) is the inability to handle overlapping subdomains or boundaries; e.g. consider a slight extension of your example: m = MeshTet().with_boundaries(
{
"left": lambda x: x[0] == 0.0,
"vertical": lambda x: np.logical_or(x[0] == 0.0, x[0] == 1.0),
}
) (e.g. for a free convection problem, this might be a plane vertical channel with zero-velocity on both walls and a Dirichlet temperature or applied heat flux on the left). When I look at {'left': array([0, 4]), 'vertical': array([ 0, 4, 12, 13])} but in the resulting MSH 2.2, the two subsets are combined
This can be avoided by the user never specifying overlapping subdomains or boundaries, e.g. here splitting |
Extending the example in nschloe/meshio#1165 with a third element of cell_sets={
'test': [array([], dtype=int64), array([1])],
'sets': [array([0, 1]), array([0, 2, 3])],
'subs': [array([1]), array([2, 3])],
} leaves only the set-difference in 'sets': [array([0]), array([0])], while extending that third subset beyond the second 'subs': [array([1]), array([1, 2, 3])], yields something entirely different: {'set1': [array([0]), array([0])], 'set2': [array([1]), array([1, 2, 3])]} |
This is expected I think. That's how you'd also specify overlapping boundary conditions in ElmerFEM. Boundary is split into three: 1 for BC1, 2 for BC2 and 3 for BC1&BC2. Then in the simulation spec you set BC1 to tags 1&3 and BC2 to tags 2&3. However, in this PR I plan to add yet another approach of using multiple cell_data keys. I don't know if MSH 2.1 supports that but it's worth a try. Another thing I wan't to try is writing this gmsh:dim_tags so that MSH 4.1 export doesn't crash. |
Maybe an improvement to int_data_to_sets / sets_to_int_data would detect or deal properly with the overlap. Right now the user must be aware that there cannot be such overlapping cell_sets. But I won't push that because it's not needed in what I have in mind. |
There is also the question that where do these overlapping cell_sets originate from? In particular, if there are no importers in meshio that write overlapping cell_sets then that's probably not very high priority. If you can construct, e.g., inp-file which leads to overlapping cell_sets then it should be fixed. |
I now see that, e.g., Medit format is similar to Elmer format because it carries no tag names. It is possible to tag each edge with a number but there is no name associated with the number so therefore |
Now I'm looking into creating our own variant of |
No, meshio reads MSH 4.1 fine and MSH 4.1 does describe subdomains and boundaries as subsets of cells. The meshio reader does populate |
I use overlapping subdomains and boundaries a lot. I usually generate the mesh in Gmsh, export as MSH 4.1, read with meshio, take into skfem, export results as XDMF. That's quite a good one way pipeline but it fails if i have to go backwards: the XDMF has forgotten the subdomains and boundaries. |
2.2 or 4.1? But anyway yes, both support an arbitrary number of |
Intrigued! So that was kind of achieved in #681 with the binary-encoding, but I didn't really think it through or test it very thoroughly. Intrigued to see what you've come up with. The state of mesh file formats is really disappointing! |
I'm planning to use products of prime numbers to distinguish the overlaps. |
Ha. I did think of that. I have done it before. Is it better than the binary? I thought the binary was more compact. |
Oh, well I was using it for the multiple facets of a cell on a boundary rather than a cell belonging to multiple subdomains, but yes. |
Now it's kind of working locally and it seems I can encode subdomains/boundaries to almost any format, even VTK is working even though Paraview is not visualizing the boundary mesh! How crazy's that. |
I'll clean it up a bit and push to #680 |
Yes this is a really neat idea. I suppose it's only possible because of meshio, approximating as it does a neutral format. Being able to visualise subdomains and boundaries is a bonus. I wonder whether we can get that to work. Is it not working because of that new cellblock list for cells in meshio 4? Does that force each cell-data field to be defined on both domain and boundary cells? |
I think right now one should be able to open |
Yes, that should work. In #681, which used only domain-cells, no boundary-cells, the boundaries were sort-of depicted by colouring those cells having a facet on the boundary. If now in #680 you do have boundary cells and domain cells, do you have to provide cell data for the domain cells even for boundaries? At the moment is that just getting zeros or similar? If so, and you have to put something there anyway, could you put something like what went into the domain cell data for boundaries in #681? That worked particularly well in three dimensions because only the boundary facets are visible anyway. |
Domain cells are used to encode |
Of course, but isn't it a quirk of meshio 4 that all cell data fields have to de defined over all cells? So that even if you only want to encode a boundary over the boundary cells, you also have to provide values for that field over the domain cells too? (And vice versa for subdomains.) |
Yeah. Would you want to write |
Or maybe you are suggesting that we write multiple |
Is this just for visualizing the boundaries? I mean, using |
Right, yes, i'm probably still thinking too much in terms of #681, sorry. I'll leave you to it and check back on Monday morning. It sounds like you're very close to fixing this which is great. |
Should
Mesh.save
save the.subdomains
and.boundaries
attributes? In a way that they might be reread byMesh.load
.If I/O is to continue to rely on
meshio.write
andmeshio.read
(as it should), I think that saving boundaries requires saving cells of typebnd_type
(e.g.'line'
forMeshQuad
); currentlyskfem.Mesh.save
only saves cells of typeMesh.meshio_type
.(I'm currently parsing a
polyMesh
from OpenFOAM and constructing anskfem.Mesh
. My parser is very slow so I want to be able to save the mesh while experimenting with the solver.)Perhaps instead for the moment I should just construct a
meshio.Mesh
andmeshio.write
that, leaving scikit-fem out of it, but this might be something to think about for other cases, e.g. when the mesh has been refined or adapted inside scikit-fem.The text was updated successfully, but these errors were encountered: