mesh2scattering.input.bc#

By default, all boundary conditions in mesh2scattering are assumed to be sound hard unless specified otherwise.

This module provides classes and types to define custom boundary conditions for individual mesh elements.

Supported boundary condition types are described in BoundaryConditionType. Use the BoundaryCondition class to specify the complex values of boundary conditions. The BoundaryConditionMapping class maps boundary conditions to mesh elements as defined in the Mesh, with element indices starting at 0.

Examples

The following example demonstrates how to define a sound soft boundary condition for a mesh with 100 elements:

>>> import mesh2scattering.input as m2si
>>> import pyfar as pf
>>> bc = m2si.bc.BoundaryCondition(
...     kind=m2si.bc.BoundaryConditionType.pressure,
...     values=0,
... )
>>> mapping = m2si.bc.BoundaryConditionMapping(100)
>>> mapping.add_boundary_condition(bc, 0, 99)  # apply to all elements

(Source code)

Classes:

BoundaryCondition(values, kind)

Represents a boundary condition for a mesh, such as a material property.

BoundaryConditionMapping(n_mesh_faces)

Represents the assignment of boundary conditions to mesh faces.

BoundaryConditionType(*values)

Enumeration of possible boundary condition types.

class mesh2scattering.input.bc.BoundaryCondition(values: FrequencyData, kind: BoundaryConditionType)[source]#

Bases: object

Represents a boundary condition for a mesh, such as a material property.

Notes

Only admittance boundary conditions can be frequency dependent. Impedance, pressure, and velocity boundary conditions must be constant across all frequencies.

Parameters:
  • values (pyfar.FrequencyData or float) – The value(s) of the boundary condition. If a float is given, it is treated as a constant across all frequencies. If a FrequencyData object is provided, it must be frequency dependent and is only valid for admittance.

  • kind (BoundaryConditionType) – The type of boundary condition.

Attributes:

frequency_dependent

Indicates if the boundary condition depends on frequency.

kind

Get the type of boundary condition as a BoundaryConditionType.

kind_str

Get the boundary condition type as a string.

values

Get the boundary condition values.

property frequency_dependent#

Indicates if the boundary condition depends on frequency.

Returns:

True if the boundary condition is frequency dependent, otherwise False.

Return type:

bool

property kind#

Get the type of boundary condition as a BoundaryConditionType.

See BoundaryConditionType for more information.

Returns:

The type of boundary condition.

Return type:

BoundaryConditionType

property kind_str#

Get the boundary condition type as a string.

Returns:

String representation of the boundary condition type.

Return type:

str

property values#

Get the boundary condition values.

Returns:

The boundary condition values as a FrequencyData object if frequency dependent, or as a single number otherwise.

Return type:

pyfar.FrequencyData, number

class mesh2scattering.input.bc.BoundaryConditionMapping(n_mesh_faces: int)[source]#

Bases: object

Represents the assignment of boundary conditions to mesh faces.

Parameters:

n_mesh_faces (int) – Total number of mesh faces available for boundary condition assignment.

Methods:

add_boundary_condition(material, ...)

Assign a boundary condition to a range of mesh faces.

to_nc_out()

Convert the boundary condition mapping to NumCalc input file format.

Attributes:

n_frequency_curves

Get the total number of frequency curves for all boundary conditions.

n_mesh_faces

Return the total number of mesh faces independent of the assignment.

add_boundary_condition(material: BoundaryCondition, first_element: int, last_element: int)[source]#

Assign a boundary condition to a range of mesh faces.

Multiple boundary conditions can be assigned. An error is raised if any mesh face in the specified range has already been assigned a material.

Parameters:
  • material (BoundaryCondition) – The boundary condition to assign.

  • first_element (int) – Index of the first mesh face to assign the boundary condition to (starting from 0).

  • last_element (int) – Index of the last mesh face to assign the boundary condition to (starting from 0).

property n_frequency_curves#

Get the total number of frequency curves for all boundary conditions.

Returns:

Total number of frequency curves present in the material list.

Return type:

int

property n_mesh_faces#

Return the total number of mesh faces independent of the assignment.

Returns:

Total number of mesh faces.

Return type:

int

to_nc_out()[source]#

Convert the boundary condition mapping to NumCalc input file format.

For details, see: Any2HRTF/Mesh2HRTF

Returns:

  • nc_boundary (str) – String containing the boundary condition definitions in NumCalc format.

  • nc_frequency_curve (str) – String containing the frequency curve definitions for frequency-dependent boundary conditions in NumCalc format. Returns an empty string if not frequency dependent.

class mesh2scattering.input.bc.BoundaryConditionType(*values)[source]#

Bases: Enum

Enumeration of possible boundary condition types.

Attributes:

admittance

Normalized admittance boundary condition.

impedance

Normalized impedance boundary condition.

pressure

Pressure boundary condition.

velocity

Velocity boundary condition.

admittance = 'ADMI'#

Normalized admittance boundary condition.

This boundary condition can be frequency dependent. NumCalc expects normalized admittance, i.e., \((\rho c)/\text{admittance}\), where \(\rho\) is the density of air and \(c\) is the speed of sound.

Normalization is advantageous because it eliminates the need to specify the speed of sound and air density.

impedance = 'IMPE'#

Normalized impedance boundary condition.

This boundary condition cannot be frequency dependent; it must remain constant across all frequencies. NumCalc expects normalized impedance, i.e., \(\text{impedance}/(\rho c)\), where \(\rho\) is the density of air and \(c\) is the speed of sound.

Normalization is advantageous because it removes the need to specify the speed of sound and air density.

pressure = 'PRES'#

Pressure boundary condition.

This boundary condition cannot be frequency dependent; it must remain constant across all frequencies. A pressure value of 0 defines a sound soft boundary.

velocity = 'VELO'#

Velocity boundary condition.

This boundary condition must remain constant across all frequencies; it cannot be frequency dependent. A velocity value of 0 defines a sound hard boundary.