[docs]def__init__(self):# flags which control which parameters are recordedself.p=True#: time-varying acoustic pressureself.p_max=False#: maximum pressure over simulationself.p_min=False#: minimum pressure over simulationself.p_rms=False#: root-mean-squared pressure over simulationself.p_max_all=False#: maximum pressure over simulation at all grid pointsself.p_min_all=False#: minimum pressure over simulation at all grid pointsself.p_final=False#: final pressure field at all grid pointsself.u=False#: time-varying particle velocityself.u_split_field=False#: compressional and shear components of time-varying particle velocityself.u_non_staggered=False#: time-varying particle velocity on non-staggered gridself.u_max=False#: maximum particle velocity over simulationself.u_min=False#: minimum particle velocity over simulationself.u_rms=False#: root-mean-squared particle velocity over simulationself.u_max_all=False#: maximum particle velocity over simulation at all grid pointsself.u_min_all=False#: minimum particle velocity over simulation at all grid pointsself.u_final=False#: final particle velocity field at all grid pointsself.I=False#: time-varying acoustic intensityself.I_avg=False#: time-averaged acoustic intensityself.cuboid_corners_list=Noneself.x1_inside,self.x2_inside=None,Noneself.y1_inside,self.y2_inside=None,Noneself.z1_inside,self.z2_inside=None,None
[docs]defset_flags_from_list(self,flags_list:List[str],is_elastic_code:bool)->None:""" Set Recorder flags that are present in the string list to True Args: flags_list: String list of flags that should be set to True is_elastic_code: Is the simulation elastic Returns: None """# check the contents of the cell array are valid inputsallowed_flags=self.get_allowed_flags(is_elastic_code)forrecord_elementinflags_list:assertrecord_elementinallowed_flags,f"{record_element} is not a valid input for sensor.record"ifrecord_element=="p":# custom logic for 'p'continueelse:setattr(self,record_element,True)# set self.record_p to false if a user input for sensor.record# is given and 'p' is not set (default is true)self.p="p"inflags_list
[docs]defset_index_variables(self,kgrid:kWaveGrid,pml_size:Vector,is_pml_inside:bool,is_axisymmetric:bool)->None:""" Assign the index variables Args: kgrid: kWaveGrid instance pml_size: Size of the PML is_pml_inside: Whether the PML is inside the grid defined by the user is_axisymmetric: Whether the simulation is axisymmetric Returns: None """ifnotis_pml_inside:self.x1_inside=pml_size.x+1.0self.x2_inside=kgrid.Nx-pml_size.xifkgrid.dim==2:ifis_axisymmetric:self.y1_inside=1else:self.y1_inside=pml_size.y+1.0self.y2_inside=kgrid.Ny-pml_size.yelifkgrid.dim==3:self.y1_inside=pml_size.y+1.0self.y2_inside=kgrid.Ny-pml_size.yself.z1_inside=pml_size.z+1.0self.z2_inside=kgrid.Nz-pml_size.zelse:self.x1_inside=1.0self.x2_inside=kgrid.Nxifkgrid.dim==2:self.y1_inside=1.0self.y2_inside=kgrid.Nyifkgrid.dim==3:self.z1_inside=1.0self.z2_inside=kgrid.Nz
[docs]@staticmethoddefget_allowed_flags(is_elastic_code):""" Get the list of allowed flags for a given simulation type Args: is_elastic_code: Whether the simulation is axisymmetric Returns: List of allowed flags for a given simulation type """allowed_flags=["p","p_max","p_min","p_rms","p_max_all","p_min_all","p_final","u","u_max","u_min","u_rms","u_max_all","u_min_all","u_final","u_non_staggered","I","I_avg",]ifis_elastic_code:# pragma: no coverallowed_flags+=["u_split_field"]returnallowed_flags
[docs]defis_set(self,attrs:List[str])->List[bool]:""" Check if the attributes are set Args: attrs: Attributes to check Returns: List of individual boolean results """return[getattr(self,a)forainattrs]