Skip to content
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

serialization of meshes and solutions #158

Closed
gdmcbain opened this issue Apr 2, 2019 · 2 comments · Fixed by #680
Closed

serialization of meshes and solutions #158

gdmcbain opened this issue Apr 2, 2019 · 2 comments · Fixed by #680

Comments

@gdmcbain
Copy link
Contributor

gdmcbain commented Apr 2, 2019

In working on combining a Navier–Stokes solution #145 with an advection–diffusion problem #152, I thought to first solve for the flow, then save it. Then in a second script, for the advection–diffusion, load the mesh and velocity and solve for the temperature.

The motivation is that, depending on fineness of the mesh, the flow takes a few minutes to solve whereas the advection–diffusion should take much less and I might be making lots of little changes to the second script and don't want to have to rerun the first script every time.

The two hurdles I see are:

  1. Just calling save doesn't save the boundaries attribute. This attribute doesn't fit into either the point_data or cell_data optional arguments as I think these are supposed to have lengths matching .shape[1] of .p or .t, respectively. Thus it's not obvious how to get meshio to save this, despite its various output formats. It could be stored in the field_data of a meshio.Mesh, but I don't know whether this would be stored in an ouput mesh file, or whether it would subsequently be reread. Maybe construct the (n − 1)-dimensional elements corresponding to the boundary facets and pack these into the cells variable passed to the meshio.Mesh constructor inside skfem.Mesh.save? Along with the appropriate cell_data.
  2. The velocity is typically solved as P2 if using Taylor–Hood elements, but mesh typically has 'triangle' cells (in two dimensions), which only have three nodes. It's not obvious how to get meshio to save a P2 solution on a mesh of simple triangles or tetrahedra. Should the facet-midpoint nodes and then the six-node triangles be constructed? (Which gets back to finding dof locations Finding dof locations  #84).

For the moment, it'll probably do to locally pickle the boundaries attribute and numpy.save the solution array, but serialization of meshes and solutions is likely to be something that's going to be wanted eventually, as more problems get more complicated and solution times grow.

@gdmcbain
Copy link
Contributor Author

gdmcbain commented Apr 2, 2019

For meshes created with classmethod from_meshio, the external attribute should have everything required for resaving the mesh. I didn't know about that.

@kinnala
Copy link
Owner

kinnala commented Jun 22, 2019

You can now serialize meshes via Mesh.to_dict and then dump those to json:

import json
json.dumps(m.to_dict())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants