MergeGrid#

class acoular.grids.MergeGrid

Bases: Grid

Base class for merging multiple grid geometries.

The MergeGrid class allows the combination of multiple grid geometries into a single unified grid. Each input grid is assigned a subdomain in the resulting grid, and all properties, such as positions and identifiers, are appropriately merged.

Notes

  • The merged grid eliminates duplicate points based on their positions.

  • Each subgrid retains its original grid properties, such as digest and size.

Examples

Merging two simple grids:

>>> import acoular as ac
>>> grid1 = ac.LineGrid(loc=(0, 0, 0), direction=(1, 0, 0), length=1, num_points=3)
>>> grid2 = ac.LineGrid(loc=(0, 0, 0), direction=(0, 1, 0), length=1, num_points=3)
>>> merged_grid = ac.MergeGrid()
>>> merged_grid.grids = [grid1, grid2]
>>> merged_grid.size
5
>>> merged_grid.pos
array([[0. , 0. , 0. , 0.5, 1. ],
       [0. , 0.5, 1. , 0. , 0. ],
       [0. , 0. , 0. , 0. , 0. ]])
grids

A list of Grid objects to be merged. Each grid is treated as a subdomain in the resulting merged grid.

grid_digest

A list of unique digests for each grid being merged. (read-only)

subgrids

Names of subgrids corresponding to each point in the merged grid. (read-only)

digest

A unique identifier for the grid, based on its properties. (read-only)

export_gpos(filename)

Export the grid positions to an XML file.

This method generates an XML file containing the positions of all grid points. Each point is represented by a <pos> element with Name, x, y, and z attributes. The generated XML is formatted to match the structure required for importing into the ImportGrid class.

Parameters:
filenamestr

The path to the file to which the grid positions will be written. The file extension must be .xml.

Raises:
OSError

If the file cannot be written due to permissions issues or invalid file paths.

Notes

  • The file will be saved in UTF-8 encoding.

  • The Name attribute for each point is set as "Point {i+1}", where i is the index of the grid point.

  • If subgrids are defined, they will be included as the subgrid attribute.

Examples

Export a grid with 100 points to an XML file:

>>> import acoular as ac
>>> import numpy as np
>>> grid = ac.ImportGrid()
>>> # Create some grid points
>>> points = np.arange(9).reshape(3, 3)
>>> grid.pos = points
>>> grid.export_gpos('grid_points.xml')

The generated grid_points.xml file will look like this:

<?xml version="1.1" encoding="utf-8"?><Grid name="grid_points">
  <pos Name="Point 1" x="0" y="1" z="2"/>
  <pos Name="Point 2" x="3" y="4" z="5"/>
  <pos Name="Point 3" x="6" y="7" z="8"/>
</Grid>
subdomain(sector)

Return the indices for a subdomain in the grid.

Allows arbitrary subdomains of type Sector.

Parameters:
sectorSector object

Sector describing the subdomain.

Returns:
tuple

A 2-tuple of arrays of integers or numpy.s_ objects that can be used to mask or select the specified subdomain from a grid-shaped array.

Notes

The numpy.where() method is used to determine the the indices.

size

The total number of grid points. This property is automatically calculated based on other defining attributes of the grid. (read-only)

shape

The shape of the grid, represented as a tuple. Primarily useful for Cartesian grids. (read-only)

pos

The grid positions represented as a (3, size) array of floats. (read-only) All positions’ coordinates are in meters by default (see here).