analyticsimdatagenerator¶
Generic tools for creating SimData objects based on analytic functions for the underlying physical fields. Useful for testing pyvale.
- class pyvale.analyticsimdatagenerator.AnalyticData2D(length_x: float = 10.0, length_y: float = 7.5, num_elem_x: int = 4, num_elem_y: int = 3, time_steps: ndarray | None = None, field_keys: tuple[str, ...] = ('scalar',), funcs_x: tuple[Expr, ...] | None = None, funcs_y: tuple[Expr, ...] | None = None, funcs_t: tuple[Expr, ...] | None = None, symbols: tuple[Symbol, ...] = (y, x, t), offsets_space: tuple[float, ...] = (0.0,), offsets_time: tuple[float, ...] = (0.0,), nodes_per_elem: int = 4)[source]¶
Bases:
object
Dataclass for describing a 2D analytic test case for pyvale sensor simulation. Includes information about the geometry, the mesh and the analytic functions used to generate the field data.
- field_keys: tuple[str, ...]¶
Keys used to describe the field of interest. For a scalar field there is only a single key. For a vector field 2 keys are required in 2D (xx,yy). For a tensor field 3 keys are required for 2D (xx,yy,xy). Defaults to a single key for a scalar field: ("scalar",).
- funcs_t: tuple[Expr, ...] | None¶
Analytic functions describing the field variation as a function of time This tuple should have the same number of functions as the number of field keys. Analytic functions in x, y and t are multiplied together so setting a function to a constant of 1 will have no effect.
- funcs_x: tuple[Expr, ...] | None¶
Analytic functions describing the field variation as a function of the x coordinate. This tuple should have the same number of functions as the number of field keys. Analytic functions in x, y and t are multiplied together so setting a function to a constant of 1 will have no effect.
- funcs_y: tuple[Expr, ...] | None¶
Analytic functions describing the field variation as a function of the y coordinate. This tuple should have the same number of functions as the number of field keys. Analytic functions in x, y and t are multiplied together so setting a function to a constant of 1 will have no effect.
- length_x: float¶
Length of the test case geometry in the X direction in length units. Defaults to 10.0.
- length_y: float¶
Length of the test case geometry in the Y direction in length units. Defaults to 7.5.
- nodes_per_elem: int¶
Number of nodes per element. Currently only rectangular meshes and with 4 nodes per element are supported. Defaults to 4.
- num_elem_x: int¶
Number of elements in the mesh in the X direction. Defaults to 4.
- num_elem_y: int¶
Number of elements in the mesh in the Y direction. Defaults to 3.
- offsets_space: tuple[float, ...]¶
Constants which are added to the physical field functions in each spatial dimensions.
- offsets_time: tuple[float, ...]¶
Constant which is added to the physical field function in time.
- symbols: tuple[Symbol, ...]¶
Sympy symbols describing the relevant dimensions of the problem. For 2D spatial dimensions default to x and y and time is denoted t. Note that these are the symbols used to describe the analytic field functions.
- time_steps: ndarray | None¶
1D array of time steps for the analytic test case. Defaults to None which is for a test case that only has spatially varying functions.
- class pyvale.analyticsimdatagenerator.AnalyticSimDataGen(case_data: AnalyticData2D)[source]¶
Bases:
object
Class for generating analytic field data as a SimData object to test the sensor simulation functionality of pyvale. Provides tools to evaluate the analytic field functions at a given spatial coordinate/time to check against pyvale interpolation functions. Currently only support 2D cases.
- Parameters:
case_data (AnalyticCaseData2D) -- Data class containing the parameters required to create the analytic mesh and the underlying physical field functions.
- case_data¶
- connect¶
- coords¶
- evaluate_all_fields_at_nodes() dict[str, ndarray] [source]¶
Evaluates all physical fields at the node locations and nominal time steps.
- Returns:
dict[str,np.ndarray] -- Dictionary keyed by the field name giving a numpy array with shape = (n_coords,n_timesteps)
- evaluate_all_fields_truth(coords: ndarray, time_steps: ndarray | None = None) dict[str, ndarray] [source]¶
Evaluates all analytic physical fields at the specified coordinates and time steps.
- Parameters:
coords (np.ndarray) -- Coordinates at which to evaluate the analytic physical field. shape =(n_coords,coord[x,y,z])
time_steps (np.ndarray | None, optional) -- Time steps at which to evaluate the physical field, by default None. If this is none the evaluation time steps are assumed to match the nominal time steps.
- Returns:
dict[str,np.ndarray] -- Dictionary keyed by the field name giving a numpy array with shape = (n_coords,n_timesteps)
- evaluate_field_at_nodes(field_key: str) ndarray [source]¶
Evaluates the underlying physical field at the node locations and nominal time steps.
- Parameters:
field_key (str) -- String key for the field to be evaluated.
- Returns:
np.ndarray -- Array of field evaluations with shape=(n_nodes,n_timesteps)
- evaluate_field_truth(field_key: str, coords: ndarray, time_steps: ndarray | None = None) ndarray [source]¶
Calculates the 'truth' from the analytical functions describing the physical fields at the specified coordinates and time steps.
- Parameters:
field_key (str) -- Key for the underlying physical field.
coords (np.ndarray) -- Coordinates at which to evaluate the analytic physical field. shape =(n_coords,coord[x,y,z])
time_steps (np.ndarray | None, optional) -- Time steps at which to evaluate the physical field, by default None. If this is none the evaluation time steps are assumed to match the nominal time steps.
- Returns:
np.ndarray -- Array of analytic field evaluations with shape = (n_coords, n_time_steps)
- field_eval¶
- field_lam_funcs¶
- field_sym_funcs¶
- generate_sim_data() SimData [source]¶
Creates a SimData object using the analytic case geometry, mesh parameters and the underlying physical fields.
- Returns:
mh.SimData -- SimData object built from the analytic case data.
- get_visualisation_grid(field_key: str | None = None, time_step: int = -1) tuple[ndarray, ndarray, ndarray] [source]¶
Creates a visualisation grid for plotting heatmaps of the specified analytic field using matplotlib.
- Parameters:
field_key (str | None, optional) -- String key for the field to be visualised, by default None. If None then the first field key is used.
time_step (int, optional) -- Time step at which to extract the field to be plotted, by default -1
- Returns:
tuple[np.ndarray,np.ndarray,np.ndarray] -- Tuple containing the 2D grid of x coordinates, grid of y coordinates and a grid of field evaluations.