### ===================================================================================================================
### Functionality for the vibration simulation
### ===================================================================================================================
# Copyright ©2026 Haskoning Nederland B.V.
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
import warnings
from typing import List, Literal
# References for functions and classes in the haskoning_atr_tools package
from haskoning_atr_tools.vibration_contour_plot.simulation.material import Material
from haskoning_atr_tools.vibration_contour_plot.simulation.vibration_simulation import (
VibrationSimulation,
VibrationSource,
)
### ===================================================================================================================
### 2. Function to create vibration sources
### ===================================================================================================================
[docs]
def create_vibration_sources(
project, activity: Literal['continuous', 'intermittent', 'emergency'] = 'continuous') -> List[VibrationSource]:
"""
Function to create the vibration sources at the location of the equipment. This function matches the location of the
equipment to the mesh-node in the vibration simulation.
Input:
- project (obj): Project object containing collections of objects and project variables.
- activity (str): Select the activity for the vibration sources. For the activity or operational state of the
equipment, select from 'continuous', 'intermittent' or 'emergency'. Default value is 'continuous'.
Output:
- Returns list of vibration sources at the mesh-node or location of the equipment.
"""
# Apply the activity filter for the equipment present in the project
equipments = [equipment for equipment in project.equipment_list if equipment.activity == activity]
# Create the vibration sources for the requested equipments
created_vibration_sources = []
for equipment in equipments:
mesh_node = project.mesh.get_mesh_node_by_coordinates_2d(
coordinates=[equipment.coordinates[0], equipment.coordinates[1], equipment.coordinates[2]])
z = equipment.coordinates[2]
if mesh_node is None:
warnings.warn(
f"WARNING: Source node not found at {equipment.coordinates}. Check your mesh, make sure the mesh is "
f"properly generated and that there is a mesh-node at the location of the vibration source ID "
f"({equipment.id}). Check if the source is within the mesh surface.")
continue
created_vibration_sources.append(VibrationSource(
id=equipment.id, mesh_node=mesh_node, equipment=equipment, z=z))
return created_vibration_sources
### ===================================================================================================================
### 3. Function to create the vibration simulation
### ===================================================================================================================
[docs]
def create_vibration_simulation(
project, name: str, material: Material,
activity: Literal['continuous', 'intermittent', 'emergency'] = 'continuous') -> VibrationSimulation:
"""
Function to create the vibration simulation.
Input:
- project (obj): Project object containing collections of objects and project variables.
- name (str): The name of the vibration simulation.
- material (Material): Material containing the material properties for the vibration simulation.
- activity (str): Select the activity for the vibration sources. For the activity or operational state of the
equipment, select from 'continuous', 'intermittent' or 'emergency'. Default value is 'continuous'.
Output:
- The vibration simulation is created based on requested parameters and the requested vibration sources are
added. The simulation object is added to the project.
- Returns the vibration simulation object.
"""
# Before creating a simulation the mesh should be present
if project.mesh is None:
raise ValueError("ERROR: Before creating the vibration simulation object, the mesh should have been generated.")
# Create the vibration sources
vibration_sources = create_vibration_sources(project=project, activity=activity)
# Create the vibration simulation object
vibration_simulation = VibrationSimulation(name=name, material=material, vibration_sources=vibration_sources)
vibration_simulation.project = project
return vibration_simulation
### ===================================================================================================================
### 4. End of script
### ===================================================================================================================