edg_acoustics.acoustics_simulation
This module provides the AcousticsSimulation class, which includes the data structure for running a DG acoustics simulation. The AcousticsSimulation class sets up the DG finite element discretization for the solution to the acoustic wave propagation problem.
Note that objects enclosed by square brackets (e.g., [dimension1, dimension2]) denotes a matrix of dimension [dimension1, dimension2].
Module Contents
Classes
Acoustics simulation data structure for running a DG acoustics simulation. |
Attributes
Tolerance used to determine if a node lies on a facet. |
- edg_acoustics.acoustics_simulation.NODETOL = 1e-07[source]
Tolerance used to determine if a node lies on a facet.
- Type:
- class edg_acoustics.acoustics_simulation.AcousticsSimulation(rho0, c0, Nx, mesh, BC_list, node_tolerance=NODETOL)[source]
Acoustics simulation data structure for running a DG acoustics simulation.
AcousticsSimulationcontains the domain discretization and sets up the DG finite element discretisation for the solution to the acoustic wave propagation.- Parameters:
rho0 (float) – the density of the medium in which the acoustic wave propagates.
c0 (float) – the speed of sound in the medium in which the acoustic wave propagates.
Nx (int) – the polynomial degree of the approximating DG finite element space used to solve the acoustic wave propagation problem.
mesh (edg_acoustics.Mesh) – the mesh object containing the mesh information for the domain discretisation.
BC_list (dict[str, int]) – a dictionary containing the definition of the boundary conditions that are present in the mesh. BC_list must contain the same keys as
edg_acoustics.Mesh.BC_triangles, i.e., all boundary conditions in the mesh must have an associated boundary condition definition.node_tolerance (float) – the tolerance used to check if a node belongs to a facet or not. <default>:
edg_acoustics.acoustics_simulation.NODETOL
- Raises:
ValueError – If BC_list[‘my_label’] is not present in the mesh, an error is raised. If a label is present in the mesh but not in BC_list, an error is raised.
- BC_list
a dictionary containing the definition of the boundary conditions that are present in the mesh. BC_list must contain the same keys as
edg_acoustics.Mesh.BC_triangles, i.e., all boundary conditions in the mesh must have an associated boundary condition definition.
- BCnode
List of boundary map nodes, each element being a dictionary with keys (values) [‘label’ (int), ‘map’ (numpy.ndarray), ‘vmap’ (numpy.ndarray)].
- Dr
the reference element differentiation matrices containing the discrete representation of \(\frac{\partial}{\partial r}\), in the rst reference element coordinate system.
- Type:
- Ds
the reference element differentiation matrices containing the discrete representation of \(\frac{\partial}{\partial s}\), in the rst reference element coordinate system.
- Type:
- Dt
the reference element differentiation matrices containing the discrete representation of \(\frac{\partial}{\partial t}\), in the rst reference element coordinate system.
- Type:
- dim
the geometric dimension of the space where the acoustic problem is solved. Always set to 3.
- Type:
- dtscale
the time step scale based on the mesh size measure, is set to the minimum diameter of the inscribed spheres in all elements.
- Type:
- Fmask
[4, Nfp]array containing indices of nodes per surface of the tetrahedron.- Type:
- Fscale
[4*Nfp, N_tets]ratio of surface to volume Jacobian of facial node.- Type:
- J
[Np, N_tets]The determinant of the Jacobian matrix for the coordinate transformation, at the collocation nodes.- Type:
- lift
[Np, 4*Nfp]an array containing the product of inverse of the mass matrix (3D) with the face-mass matrices (2D).- Type:
- mesh
the mesh object containing the mesh information for the domain discretisation.
- Type:
- Nx
the polynomial degree of the approximating DG finite element space used to solve the acoustic wave propagation problem.
- Type:
- node_tolerance
the tolerance used to check if a node belongs to a facet or not. <default>:
edg_acoustics.acoustics_simulation.NODETOL.- Type:
- rst
the reference element coordinates \((r, s, t)\) of the collocation points. Physical coordinates
xyzare obtained by mapping for each element therstcoordinates of the reference element into the physical domain. rst[0] contains the r-coordinates, rst[1] contains the s-coordinates, rst[2] contains the t-coordinates.- Type:
- rst_xyz
[3, 3, Np, N_tets]The derivative of the local coordinates \(R = (r, s, t)\) with respect to the physical coordinates \(X = (x, y, z)\), i.e., \(\frac{\partial R}{\partial X}\), at the collocation nodes. Specifically:rst_xyz[0, 0]: rx (numpy.ndarray):
[Np, N_tets]The derivative of the local coordinates \(r\) with respect to the physical coordinates \(x\), i.e., \(\frac{\partial r}{\partial x}\), at the collocation nodes.rst_xyz[1, 0]: sx (numpy.ndarray):
[Np, N_tets]The derivative of the local coordinates \(s\) with respect to the physical coordinates \(x\), i.e., \(\frac{\partial s}{\partial x}\), at the collocation nodes.rst_xyz[2, 0]: tx (numpy.ndarray):
[Np, N_tets]The derivative of the local coordinates \(t\) with respect to the physical coordinates \(x\), i.e., \(\frac{\partial t}{\partial x}\), at the collocation nodes.rst_xyz[0, 1]: ry (numpy.ndarray):
[Np, N_tets]The derivative of the local coordinates \(r\) with respect to the physical coordinates \(y\), i.e., \(\frac{\partial r}{\partial y}\), at the collocation nodes.rst_xyz[1, 1]: sy (numpy.ndarray):
[Np, N_tets]The derivative of the local coordinates \(s\) with respect to the physical coordinates \(y\), i.e., \(\frac{\partial s}{\partial y}\), at the collocation nodes.rst_xyz[2, 1]: ty (numpy.ndarray):
[Np, N_tets]The derivative of the local coordinates \(t\) with respect to the physical coordinates \(y\), i.e., \(\frac{\partial t}{\partial y}\), at the collocation nodes.rst_xyz[0, 2]: rz (numpy.ndarray):
[Np, N_tets]The derivative of the local coordinates \(r\) with respect to the physical coordinates \(z\), i.e., \(\frac{\partial r}{\partial z}\), at the collocation nodes.rst_xyz[1, 2]: sz (numpy.ndarray):
[Np, N_tets]The derivative of the local coordinates \(s\) with respect to the physical coordinates \(z\), i.e., \(\frac{\partial s}{\partial z}\), at the collocation nodes.rst_xyz[2, 2]: tz (numpy.ndarray):
[Np, N_tets]The derivative of the local coordinates \(t\) with respect to the physical coordinates \(z\), i.e., \(\frac{\partial t}{\partial z}\), at the collocation nodes.
- Type:
- sJ
[4*Nfp, N_tets]The determinant of the surface Jacobian matrix at each of the collocation nodes, for each of the 4 faces of theN_tetselements.- Type:
- V
[Np, Np]vandermonde matrix of the orthonormal basis functions on the reference simplex element. Polynomial basis can exactly represent polynomials up to degreeNx. Consider the set ofNp3D nodes, with the coordinates of each node \(i\) equal to \((r_{i}, s_{i}, t_{i})\), inrst, and the set of \(m\) orthonormal basis functions, the vandermonde matrix will be \(V_{i,j} = f_{j}(r_{i}, s_{i}, t_{i})\).- Type:
- xyz
[3, Np, N_tets]the physical space coordinates \((x, y, z)\) of the collocation points of each element of the mesh. xyz[0] contains the x-coordinates, xyz[1] contains the y-coordinates, xyz[2] contains the z-coordinates.- Type:
- n_xyz
[3, 4*Np, N_tets]the outwards normals \(\vec{n}= (n_x, n_y, n_z)\) at each collocation point on the element faces. Specifically:n_xyz[0, :] (numpy.ndarray): nx
[4*Nfp, N_tets]The \(x\)-component of the outward normal \(\vec{n}\) at each of theNfpnodes on each of the 4 facets of each of theN_tetselements.n_xyz[1, :] (numpy.ndarray): ny
[4*Nfp, N_tets]The \(y\)-component of the outward normal \(\vec{n}\) at each of theNfpnodes on each of the 4 facets of each of theN_tetselements.n_xyz[2, :] (numpy.ndarray): nz
[4*Nfp, N_tets]The \(z\)-component of the outward normal \(\vec{n}\) at each of theNfpnodes on each of the 4 facets of each of theN_tetselements.
- Type:
- vmapM
[4*Nfp*N_tets, 1]an array containing the global indices for interior values.- Type:
- vmapP
[4*Nfp*N_tets, 1]an array containing the global indices for exterior values.- Type:
- init_local_system()[source]
Call the methods to initialise the local system and compute all the attributes of the AcousticsSimulation object.
- static compute_Np(Nx)[source]
Computes the number of collocation nodes for basis of polynomial degree
Nx.
- static compute_Nfp(Nx)[source]
Computes the number of collocation nodes lying on a face of the elements for basis of polynomial degree
Nx.
- static compute_Nx_from_Np(Np)[source]
Computes the polynomial degree
Nxof basis from the number of collocation pointsNp.
- static check_BC_list(BC_list, mesh)[source]
Check if BC_list is compatible with mesh. Given a mesh with a set of boundary conditions specified in mesh.BC_triangles, check if the list of boundary conditions specification, BC_list, is compatible. By compatible we mean that all boundary conditions (keys) in BC_list exist in mesh.BC_labels, and vice-versa.
- static compute_collocation_nodes(EToV, vertices, Nx, dim=3)[source]
Compute reference element \((r, s, t)\) coordinates of collocation points
rstand the physical domainxyzcoordinates for each element.- Parameters:
EToV (numpy.ndarray) – See
edg_acoustics.Mesh.EToV.vertices (numpy.ndarray) – see
edg_acoustics.Mesh.vertices.
- Returns:
- static compute_van_der_monde_matrix(Nx, rst, dim=3)[source]
- Compute vandermonde matrix of the orthonormal basis functions on the reference simplex element. Polynomial basis
can exactly represent polynomials up to degree
Nx. Consider the set ofNp3D nodes, with the coordinates of each node \(i\) equal to \((r_{i}, s_{i}, t_{i})\), inrst, and the set of \(m\) orthonormal basis functions, the vandermonde matrix will be \(V_{i,j} = f_{j}(r_{i}, s_{i}, t_{i})\).
- Parameters:
- Returns:
V (numpy.ndarray) – see
V.- Return type:
- static compute_derivative_matrix(Nx, rst, dim=3)[source]
Compute the derivative matrix on the reference element.
- static compute_Fmask(rst, node_tol)[source]
Find all the :attr:
Nfpface nodes that lie on each surface.- Parameters:
rst (numpy.ndarray) – see
rst.node_tol (float) – see
node_tolerance.
- Returns:
Fmask (numpy.ndarray) – see
Fmask.
- static compute_lift(V, rst, Fmask)[source]
Compute the lift matrix.
- Parameters:
V (numpy.ndarray) – see
V.rst (numpy.ndarray) – see
rst.Fmask (numpy.ndarray) – see
Fmask.
- Returns:
lift (numpy.ndarray) – see
lift.
- static geometric_factors_3d(xyz, Dr, Ds, Dt)[source]
Compute the metric elements for the local mappings of the elements.
- Parameters:
xyz (numpy.ndarray) – see
xyz.Dr (numpy.ndarray) – see
Dr.Ds (numpy.ndarray) – see
Ds.Dt (numpy.ndarray) – see
Dt.
- Returns:
- static normals_3d(xyz, rst_xyz, J, Fmask)[source]
Compute outward pointing normals at element’s faces as well as surface Jacobians.
- Parameters:
xyz (numpy.ndarray) – see
xyz.rst_xyz (numpy.ndarray) – see
rst_xyz.J (numpy.ndarray) – see
J.Fmask (numpy.ndarray) – see
Fmask.
- Returns:
- static build_maps_3d(xyz, EToE, EToF, Fmask, node_tol)[source]
Find connectivity for nodes given per surface in all elements
- Parameters:
xyz (numpy.ndarray) – see
xyz.EToE (numpy.ndarray) – see
edg_acoustics.Mesh.EToE.EToF (numpy.ndarray) – see
edg_acoustics.Mesh.EToF.Fmask (numpy.ndarray) – see
Fmask.node_tol (float) – see
node_tolerance.
- Returns:
- static ismember_col(a, b)[source]
find the indices of the columns of a that are in b
- Parameters:
a (numpy.ndarray) – matrix a to be checked
b (numpy.ndarray) – matrix b to be checked against
- Returns:
indices (numpy.ndarray) – boolean indices of the columns of a that are in b
- static build_BCmaps_3d(BC_list, EToV, vmapM, BC_triangles, Nx)[source]
Build specialized nodal maps for various types of boundary conditions,specified in BC_list
- Parameters:
EToV (numpy.ndarray) – see
edg_acoustics.Mesh.EToV.vmapM (numpy.ndarray) – see
vmapM.BC_triangles (dict[str, numpy.ndarray]) – see
edg_acoustics.mesh.Mesh.BC_triangles.
- Returns:
BCnode (list[dict]) – see
BCnode.
- static diameter_3d(Fscale)[source]
Compute the minimum diameter of the inscribed spheres in all elements.
- Parameters:
Fscale (numpy.ndarray) – see
Fscale.- Returns:
diameter (float) – minimum diameter of the inscribed spheres in all elements.
- grad_3d(U, axis)[source]
Compute partial derivative dU/dx, dU/dy, dU/dz, or gradient dU/dx + dU/dy + dU/dz
- Parameters:
U (numpy.ndarray) –
[Np, N_tets]the acoustic variables that needs to be differentiated.axis (str) – the axis to be differentiated w.r.t, e.g. ‘x’, ‘y’, ‘z’, ‘xyz’
- Returns:
dUdx (numpy.ndarray) –
[Np, N_tets]derivatives \(\frac{\partial U}{\partial x}\) at every nodal point, if axis is ‘x’.dUdy (numpy.ndarray) –
[Np, N_tets]derivatives \(\frac{\partial U}{\partial y}\) at every nodal point, if axis is ‘y’.dUdz (numpy.ndarray) –
[Np, N_tets]derivatives \(\frac{\partial U}{\partial z}\) at every nodal point, if axis is ‘z’.Tuple of gradient (numpy.ndarray) –
[Np, N_tets]gradient (\(\frac{\partial U}{\partial x}, \frac{\partial U}{\partial y}, \frac{\partial U}{\partial z}\)), if axis is ‘xyz’.
- static locate_simplex(node_coordinates, EToV, rec, methodLocate='scipy')[source]
Locate the simplices containing the sample points.
- Parameters:
node_coordinates (numpy.ndarray) – see
edg_acoustics.Mesh.vertices.EToV (numpy.ndarray) – see
edg_acoustics.Mesh.EToV.rec (numpy.ndarray) – An (N_rec x 3) array containing the (x, y, z) coordinates of N_rec microphone locations.
methodLocate (str) – search method to locate the simplices containing the sample points. Available methods are ‘scipy’ and ‘brute_force’. brutal force approach, adopted from https://stackoverflow.com/questions/25179693/how-to-check-whether-the-point-is-in-the-tetrahedron-or-not/60745339#60745339
- Returns:
nodeindex (numpy.ndarray) – indices of simplices containing the N_rec microphone points
- sample3D(methodLocate='scipy')[source]
Compute interpolation weights required to interpolate the nodal data to the sample (i.e., microphone location)
- Parameters:
methodLocate (str) – search method to locate the simplices containing the sample points. Available methods are ‘scipy’ and ‘brute_force’. brutal force approach, adopted from https://stackoverflow.com/questions/25179693/how-to-check-whether-the-point-is-in-the-tetrahedron-or-not/60745339#60745339
- Returns:
sampleWeight (numpy.ndarray) –
[N_rec, Np]interpolation weights required to interpolate the nodal data to the sample (i.e., microphone location).nodeindex (numpy.ndarray) –
[N_rec, ]index of simplices that contatin the sample (microphone) points.
- init_IC(IC)[source]
setup the initial condition and save it to the
AcousticsSimulationclass.- Parameters:
IC (edg_acoustics.InitialCondition) – the initial condition object.
- init_BC(BC)[source]
load the boundary condition and save it to the
AcousticsSimulationclass.- Parameters:
BC (edg_acoustics.BoundaryCondition) – the boundary condition object.
- init_rec(rec, methodLocate='scipy')[source]
load the receiver locations and save it to the
AcousticsSimulationclass. Then compute the interpolation weights required to interpolate the nodal data to the sample (i.e., microphone location).- Parameters:
rec (numpy.ndarray) – An
[3, N_rec]array containing the (x, y, z) coordinates of N_rec microphone locations.methodLocate (str) – search method to locate the simplices containing the sample points. Available methods are ‘scipy’ and ‘brute_force’. brutal force approach, adopted from https://stackoverflow.com/questions/25179693/how-to-check-whether-the-point-is-in-the-tetrahedron-or-not/60745339
- init_Flux(Flux)[source]
load the interior flux calculation and save it to the
AcousticsSimulationclass.- Parameters:
Flux (edg_acoustics.Flux) – the flux object.
- init_TimeIntegrator(time_integrator)[source]
load the time integrator to be used to and save it to the
AcousticsSimulationclass.- Parameters:
time_integrator (edg_acoustics.TimeIntegrator)
- RHS_operator(P, Vx, Vy, Vz, BCvar)[source]
Compute the right-hand side of the linear acoustic equations with the DG discretization.
- Parameters:
P (numpy.ndarray) – Pressure field.
Vx (numpy.ndarray) – Velocity field in the x-direction.
Vy (numpy.ndarray) – Velocity field in the y-direction.
Vz (numpy.ndarray) – Velocity field in the z-direction.
BCvar (list[dict]) – see
edg_acoustics.AbsorbBC.BCvar.
- Returns:
RHS_P (numpy.ndarray) – Right-hand side values for pressure.
RHS_Vx (numpy.ndarray) – Right-hand side values for velocity in the x-direction.
RHS_Vy (numpy.ndarray) – Right-hand side values for velocity in the y-direction.
RHS_Vz (numpy.ndarray) – Right-hand side values for velocity in the z-direction.
BCvar (list[dict]) – updated boundary condition variables.
- time_integration(**kwargs)[source]
Perform time integration for the acoustics simulation. Additional keyword arguments are optional and can vary:
- Parameters:
n_time_steps (int) – number of time steps to be performed.
total_time (float) – total simulation time to be performed, determines the number of time steps given the current time step.
delta_step (int) – print solution every delta_step time steps.
save_step (int) – save solution every save_step time steps.
format (str) – the format of the file to save the results. Can be either ‘mat’ or ‘npy’. The default format is ‘mat’.
- Returns:
prec (numpy.ndarray) – Pressure field at the microphone locations.