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

Template distribute_entity_data to support multiple data-types #3119

Merged
merged 15 commits into from
Apr 15, 2024

Conversation

jorgensd
Copy link
Sponsor Member

@jorgensd jorgensd commented Apr 2, 2024

First step towards resolving #1253
Second step would be to template XDMFFile.read_meshtags. This is fairly trivial, but I figured we should agree on the core changes before doing that change.

Currently tested with:

from mpi4py import MPI
import numpy as np
import dolfinx

mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 2, 2)
num_vertices = mesh.topology.index_map(0).size_local
entities = np.arange(num_vertices, dtype=np.int32)


def distribute_data(dtype):
    values = entities.astype(dtype).copy()
    if dtype == np.float64:
        values -= 0.6
    return dolfinx.io.distribute_entity_data(mesh, 0, entities.reshape(-1, 1).copy(), values[::-1].copy())


a = distribute_data(np.int32)

b = distribute_data(np.float64)
c = distribute_data(np.complex128)
print(a, b, c)

I've removed the unnecessary mesh geometry templating of this function, and made the Python-binding more low-level (improving the Python layer of distribute_entity_data to work with the new binding). The PR also has documentation improvements of this function.

This would enabling reading vertex, facet and cell data that is single or double precision, which is the case in many biomedical applications (where one for instance have voxel data, or material parameters).

The major difference in the code is that the communication of entity indices and values are split into two separate neighbourhood alltoallv calls.

No major changes in the actual functional structure of the code.

@jorgensd
Copy link
Sponsor Member Author

jorgensd commented Apr 2, 2024

@massimiliano-leoni could you test this?:)

@jorgensd jorgensd added the enhancement New feature or request label Apr 2, 2024
@jorgensd jorgensd changed the title Template distribute entity data Template distribute_entity_data to support multiple data-types Apr 3, 2024
Copy link
Member

@garth-wells garth-wells left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest leaving the code in the .cpp file and explicitly instantiating for the small number of types that we'll use (at this stage). It's preferable to keep code in the implementation file. This is what we do elsewhere for the mesh.

cpp/dolfinx/io/xdmf_utils.h Outdated Show resolved Hide resolved
python/dolfinx/io/utils.py Outdated Show resolved Hide resolved
@jorgensd
Copy link
Sponsor Member Author

@garth-wells any further changes you would like to see in this PR?

@garth-wells garth-wells added this pull request to the merge queue Apr 15, 2024
Merged via the queue into main with commit c5c757b Apr 15, 2024
21 checks passed
@garth-wells garth-wells deleted the dokken/generalize_distribute_entity_data branch April 15, 2024 19:19
jorgensd added a commit to jorgensd/adios4dolfinx that referenced this pull request Apr 16, 2024
jorgensd added a commit to jorgensd/adios4dolfinx that referenced this pull request Apr 16, 2024
jorgensd added a commit to jorgensd/adios4dolfinx that referenced this pull request Apr 23, 2024
jorgensd added a commit to jorgensd/adios4dolfinx that referenced this pull request Apr 23, 2024
* API updates relating to:
FEniCS/dolfinx#3149

* Updates due to: FEniCS/dolfinx#3119
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants