kipe.fenicsx.sampling module
Spatial samplers on meshes: fenicsx.mesh.
MeshSampler interpolates a field of the solver onto a measurement mesh, which need not
match the solver’s mesh, optionally projected onto a direction or the surface normal. Its
entries are in the order of the measurement mesh file: one value per vertex for P1 (by the
vertex’s row in the file), one per cell for DG0 (by the cell’s row); for a vector field
without projection, the components of each vertex or cell one after another. dolfinx keeps
these rows however it distributes and renumbers the mesh, so the data do not depend on the
number of ranks (see kipe.sampling).
- type kipe.fenicsx.sampling.Element = Literal['P1', 'DG0']
- type kipe.fenicsx.sampling.Projection = list[float] | Literal['surface_normal'] | None
- class kipe.fenicsx.sampling.MeshSampler(field: str, source: dolfinx.fem.FunctionSpace, mesh: str, element: Element, projection: Projection = None, padding: float = 0.0, mesh_name: str = 'mesh', comm: mpi4py.MPI.Comm = mpi4py.MPI.COMM_WORLD)[source]
Bases:
SpatialSamplerInterpolates a field onto a measurement mesh, optionally projected.
- Parameters:
field – name of the observed field
source – the field’s function space, on the solver’s mesh
mesh – path to the measurement mesh, an XDMF file
element – finite element on the measurement mesh
projection – a direction (one entry per component of the field) or
"surface_normal"(the measurement mesh must be a surface); all components if Nonepadding – distance by which a measurement point may lie outside the solver’s mesh
mesh_name – name of the mesh in the XDMF file
comm – communicator of the run
- Raises:
StudyFileError – if the file has no mesh named
mesh_name, the measurement mesh has curved cells (P1needs a linear geometry), the projection does not fit the field or the mesh, or points of the measurement mesh lie outside the solver’s mesh, beyond the padding
- sample(fields: Mapping[str, NDArray_f64]) NDArray_f64[source]
Interpolate the field onto the measurement mesh, and project it.
- Parameters:
fields – the observed state field, this rank’s owned degrees of freedom
- Returns:
the values of this rank’s owned degrees of freedom on the measurement mesh (a new array), at the positions
global_indices
- kipe.fenicsx.sampling.build_mesh_sampler(options: MeshSamplingOptions, fields: list[str], solver: ForwardSolver, comm: mpi4py.MPI.Comm = mpi4py.MPI.COMM_WORLD) MeshSampler[source]
Construct a
MeshSamplerfrom thespatial_samplingoptions of a measurement.- Parameters:
options –
spatial_samplingoptions of the measurementfields – names of the fields the measurement observes; exactly one
solver – the forward solver, which provides the field’s function space
comm – communicator of the run
- Returns:
the sampler
- Raises:
StudyFileError – if the measurement does not observe exactly one distributed field whose function space the solver provides
- kipe.fenicsx.sampling.observed_function_space(kind: str, fields: list[str], solver: ForwardSolver) tuple[str, dolfinx.fem.FunctionSpace][source]
Return the field a FEniCSx sampler observes, and its function space.
- Parameters:
kind – the sampler’s
type, for error messages, e.g.,"fenicsx.mesh"fields – names of the fields the measurement observes; exactly one
solver – the forward solver, which provides the field’s function space
- Returns:
the field’s name
its function space, on the solver’s mesh
- Raises:
StudyFileError – if the measurement does not observe exactly one distributed field whose function space the solver provides