LineGrid#
- class acoular.grids.LineGrid
Bases:
GridDefine a 3D grid for a line geometry.
The
LineGridclass represents a grid where points are arranged linearly in 3D space. The grid is defined by a starting location (loc), a direction vector (direction), a total length (length), and the number of points (num_points) along the line.Notes
The distance between points is
length/ (num_points- 1).The direction vector is normalized to ensure consistency.
Examples
Create a line grid with 5 points along the x-axis, starting at (0, 0, 0), with a length of 4 meters:
>>> import acoular as ac >>> grid = ac.LineGrid() >>> grid.loc = (0.0, 0.0, 0.0) >>> grid.direction = (1.0, 0.0, 0.0) >>> grid.length = 4 >>> grid.num_points = 5 >>> grid.pos array([[0., 1., 2., 3., 4.], [0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.]])
- loc
Starting point of the grid in 3D space. Default is
(0.0, 0.0, 0.0).
- direction
A vector defining the orientation of the line in 3D space. Default is
(1.0, 0.0, 0.0).
- length
Total length of the line. Default is
1.0.
- num_points
Number of grid points along the line. Default is
1.
- size
The total number of grid points. Automatically updated when other grid-defining attributes are set. (read-only)
- pos
A (3,
size) array containing the x, y, and z positions of the grid points. (read-only) All positions’ coordinates are in meters by default (see here).
- 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 withName,x,y, andzattributes. The generated XML is formatted to match the structure required for importing into theImportGridclass.- Parameters:
- filename
str The path to the file to which the grid positions will be written. The file extension must be
.xml.
- filename
- Raises:
OSErrorIf the file cannot be written due to permissions issues or invalid file paths.
Notes
The file will be saved in UTF-8 encoding.
The
Nameattribute for each point is set as"Point {i+1}", whereiis the index of the grid point.If subgrids are defined, they will be included as the
subgridattribute.
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.xmlfile 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:
- sector
Sectorobject Sector describing the subdomain.
- sector
- Returns:
Notes
The
numpy.where()method is used to determine the the indices.
- shape
The shape of the grid, represented as a tuple. Primarily useful for Cartesian grids. (read-only)