mesh2scattering.input#
Provides functions to write input files for mesh2scattering.
Classes:
|
Initialize the EvaluationGrid object. |
|
Initializes the SampleMesh object. |
|
Defines a sound source including its type and coordinates. |
|
Initializes the SurfaceDescription object. |
Functions:
|
Generate a NumCalc Project to determine scattering patterns. |
- class mesh2scattering.input.EvaluationGrid(coordinates: Coordinates, faces: ndarray, name: str)[source]#
Bases:
objectInitialize the EvaluationGrid object.
Note that a EvaluationGrid object is always triangulated. Please use the corresponding constructor to use the correct triangulation.
- Parameters:
coordinates (
Coordinates) – The coordinates of the evaluation grid.faces (numpy.ndarray) – The faces of the evaluation grid.
name (string) – The name of the evaluation grid.
Examples
Generate a spherical sampling grid with pyfar and write it to the current working directory
>>> import mesh2scattering as m2s >>> import pyfar as pf >>> import spharpy >>> >>> points = spharpy.samplings.lebedev(10) >>> points.weights = spharpy.samplings.calculate_sampling_weights( ... points) >>> grid = m2s.input.EvaluationGrid.from_spherical( ... points, "Lebedev_N10")
Attributes:
coordinatesReturn the coordinates of the evaluation grid.
facesReturn the faces of the evaluation grid.
nameReturn the name of the evaluation grid.
weightsReturn the weights of the evaluation grid.
Methods:
export_numcalc(folder_path[, start])Write evaluation grid for use in NumCalc.
from_parallel_to_plane(coordinates, plane, name)Build a Evaluation grid from a sampling parallel to 'xy', 'yz' or 'xz' plane.
from_spherical(coordinates, name)Return the evaluation grid with the spherical coordinates.
- property coordinates: Coordinates#
Return the coordinates of the evaluation grid.
- Returns:
The coordinates of the evaluation grid.
- Return type:
- export_numcalc(folder_path: str, start: int = 200000)[source]#
Write evaluation grid for use in NumCalc.
NumCalc evaluation grids consist of the two text files Nodes.txt and Elements.txt. Evaluations grids are always triangulated.
- Parameters:
folder_path (str, Path) – folder path under which the evaluation grid is saved. If the folder does not exist, it is created.
start (int, optional) – The nodes and elements of the evaluation grid are numbered and the first element will have the number start. In NumCalc, each Node must have a unique number. The nodes/elements of the mesh for which the HRTFs are simulated start at 1. Thus start must at least be greater than the number of nodes/elements in the evaluation grid.
- property faces#
Return the faces of the evaluation grid.
- Returns:
The faces of the evaluation grid.
- Return type:
- classmethod from_parallel_to_plane(coordinates, plane, name)[source]#
Build a Evaluation grid from a sampling parallel to ‘xy’, ‘yz’ or ‘xz’ plane.
- Parameters:
coordinates (
Coordinates) – The coordinates of the evaluation grid.plane ("xy", "yz", "xz") – In case all values of the evaluation grid are constant for one dimension, this dimension has to be discarded during the triangulation. E.g. if all points have a z-value of 0 (or any other constant), plane must be “xy”.
name (str) – The name of the evaluation grid.
- Returns:
The evaluation grid with the parallel to the xy plane.
- Return type:
- classmethod from_spherical(coordinates, name)[source]#
Return the evaluation grid with the spherical coordinates.
- Parameters:
coordinates (
Coordinates) – The coordinates of the evaluation grid.name (str) – The name of the evaluation grid.
- Returns:
The evaluation grid with the spherical coordinates.
- Return type:
- property name: str#
Return the name of the evaluation grid.
- Returns:
The name of the evaluation grid.
- Return type:
str
- property weights#
Return the weights of the evaluation grid.
- Returns:
The weights of the evaluation grid.
- Return type:
- class mesh2scattering.input.SampleMesh(mesh: Trimesh, surface_description: SurfaceDescription, sample_baseplate_hight: float = 0.01, sample_diameter: float = 0.8, sample_shape: SampleShape = SampleShape.ROUND)[source]#
Bases:
objectInitializes the SampleMesh object.
- Parameters:
mesh (trimesh.Trimesh) – trimesh object representing the sample mesh.
surface_description (SurfaceDescription) – surface description of the sample mesh.
sample_diameter (float, optional) – diameter of the sample, by default 0.8
sample_shape (str, optional) – shape of the sample, by default ‘round’
Methods:
export_numcalc(folder_path[, start])Write mesh to NumCalc input format.
Attributes:
meshDefines the sample mesh.
mesh_facesDefines the faces of the mesh.
mesh_verticesDefines the vertices of the mesh.
n_mesh_elementsNumber of mesh elements/faces.
n_mesh_nodesNumber of mesh nodes/vertices.
n_repetitions_xDefines the number of repetitions in x direction.
n_repetitions_yDefines the number of repetitions in y direction.
sample_baseplate_hightDefines the height of the baseplate.
sample_diameterDefines the diameter of the sample.
sample_shapeDefines the shape of the sample.
surface_descriptionDefines the surface description.
- export_numcalc(folder_path, start=200000)[source]#
Write mesh to NumCalc input format.
NumCalc meshes consist of two text files Nodes.txt and Elements.txt. The Nodes.txt file contains the coordinates of the vertices and the Elements.txt file contains the indices of the vertices that form the faces of the mesh.
- Parameters:
folder_path (str) – Path to the directory where the mesh is saved. The mesh is saved in ‘Nodes.txt’ and ‘Elements.txt’ files.
start (int, optional) – The nodes and elements of the mesh are numbered and the first element will have the number start. In NumCalc, each Node must have a unique number. The nodes/elements of the mesh for which the HRTFs are simulated start at 1. Thus start must at least be greater than the number of nodes/elements in the mesh.
- property mesh#
Defines the sample mesh.
- Returns:
The sample mesh.
- Return type:
trimesh.Trimesh
- property mesh_faces#
Defines the faces of the mesh.
- Returns:
The faces of the mesh.
- Return type:
- property mesh_vertices#
Defines the vertices of the mesh.
- Returns:
The vertices of the mesh.
- Return type:
- property n_mesh_elements#
Number of mesh elements/faces.
- Returns:
number of mesh elements/faces.
- Return type:
int
- property n_mesh_nodes#
Number of mesh nodes/vertices.
- Returns:
number of mesh nodes/vertices.
- Return type:
int
- property n_repetitions_x#
Defines the number of repetitions in x direction.
- Returns:
The number of repetitions in x direction.
- Return type:
int
- property n_repetitions_y#
Defines the number of repetitions in y direction.
- Returns:
The number of repetitions in y direction.
- Return type:
int
- property sample_baseplate_hight#
Defines the height of the baseplate.
- Returns:
The height of the baseplate.
- Return type:
float
- property sample_diameter#
Defines the diameter of the sample.
- Returns:
The diameter of the sample.
- Return type:
float
- property sample_shape#
Defines the shape of the sample.
- Returns:
The shape of the sample.
- Return type:
- property surface_description#
Defines the surface description.
- Returns:
The surface description.
- Return type:
- class mesh2scattering.input.SoundSource(source_coordinates: Coordinates, source_type: SoundSourceType = SoundSourceType.POINT_SOURCE)[source]#
Bases:
objectDefines a sound source including its type and coordinates.
- Returns:
sound source object.
- Return type:
Attributes:
source_coordinatesDefines the source coordinates in meter.
source_typeDefines the source type.
- property source_coordinates#
Defines the source coordinates in meter.
- Returns:
The source coordinates in meter.
- Return type:
- property source_type#
Defines the source type.
Can be a point source or a plane wave.
- Returns:
The source type.
- Return type:
- class mesh2scattering.input.SurfaceDescription(structural_wavelength_x: float = 0, structural_wavelength_y: float = 0, structural_depth: float = 0, surface_type: SurfaceType = SurfaceType.PERIODIC, model_scale: float = 1, symmetry_azimuth: list = None, symmetry_rotational: bool = False, comment: str = '')[source]#
Bases:
objectInitializes the SurfaceDescription object.
- Parameters:
structural_wavelength_x (float, optional) – structural wavelength in x direction, by default 0.
structural_wavelength_y (float, optional) – structural wavelength in y direction, by default 0.
surface_type (SurfaceType, optional) – surface type, by default SurfaceType.PERIODIC.
model_scale (float, optional) – model scale, by default 1.
symmetry_azimuth (list, optional) – azimuth symmetry, by default [].
symmetry_rotational (bool, optional) – rotational symmetry, by default False.
comment (str, optional) – comment, by default “”.
Attributes:
Defines the comment.
Defines the model scale.
Defines the structural depth.
Defines the structural wavelength in x direction.
Defines the structural wavelength in y direction.
Defines the surface type.
Defines the azimuth symmetry.
Defines the rotational symmetry.
- property comment#
Defines the comment.
- Returns:
The comment.
- Return type:
str
- property model_scale#
Defines the model scale.
- Returns:
The model scale.
- Return type:
float
- property structural_depth#
Defines the structural depth.
- Returns:
The structural depth.
- Return type:
float
- property structural_wavelength_x#
Defines the structural wavelength in x direction.
- Returns:
The structural wavelength in x direction.
- Return type:
float
- property structural_wavelength_y#
Defines the structural wavelength in y direction.
- Returns:
The structural wavelength in y direction.
- Return type:
float
- property surface_type#
Defines the surface type.
- Returns:
The surface type.
- Return type:
- property symmetry_azimuth#
Defines the azimuth symmetry.
- Returns:
The azimuth symmetry.
- Return type:
list
- property symmetry_rotational#
Defines the rotational symmetry.
- Returns:
The rotational symmetry.
- Return type:
bool
- mesh2scattering.input.write_scattering_project_numcalc(project_path: str, project_title: str, frequencies: ndarray, sound_sources: SoundSource, evaluation_grids: list[EvaluationGrid], sample_mesh: SampleMesh, bem_method='ML-FMM BEM', speed_of_sound=346.18, density_of_medium=1.1839)[source]#
Generate a NumCalc Project to determine scattering patterns.
- Parameters:
project_path (str) – Project path where the project should be created.
project_title (str) – Project title, required for meta data files.
frequencies (numpy.ndarray) – frequency vector to be solved.
sound_sources (SoundSource) – sound sources.
evaluation_grids (list[EvaluationGrid]) – list of evaluation grids.
sample_mesh (SampleMesh) – Mesh and mesh meta data.
bem_method (str, optional) – Method of BEM solver, can be ‘BEM’, ‘SL-FMM BEM’, or ‘ML-FMM BEM’. By default ‘ML-FMM BEM’
speed_of_sound (float, optional) – speed of sound in m/s, by default 346.18
density_of_medium (float, optional) – density of air in kg/m^3, by default 1.1839
Enums:
- class mesh2scattering.input.SurfaceType(*values)[source]#
Bases:
EnumDefines the type of a sample mesh.
Can be a trimesh object or a path to a stl file.
Attributes:
The surface is flat, basically for the reference surface.
The surface is periodic.
The surface is stochastic.
- FLAT = 'Flat'#
The surface is flat, basically for the reference surface.
- PERIODIC = 'Periodic'#
The surface is periodic.
- STOCHASTIC = 'Stochastic'#
The surface is stochastic.
- class mesh2scattering.input.SampleShape(*values)[source]#
Bases:
EnumDefines the shape of a sample mesh.
Can be round or square.
Attributes:
- ROUND = 'Round'#
The sample shape is round.
- SQUARE = 'Square'#
The sample shape is square.
- class mesh2scattering.input.SoundSourceType(*values)[source]#
Bases:
EnumDefines the type of a sound source.
Can be a point source or a plane wave.
Attributes:
Plane wave sound source type.
Point source sound source type.
- PLANE_WAVE = 'Plane wave'#
Plane wave sound source type.
- POINT_SOURCE = 'Point source'#
Point source sound source type.