analyticsimdatagenerator.py¶
Generic tools for creating SimData objects based on analytic functions for the underlying physical fields. Useful for testing pyvale.
- class AnalyticData2D(length_x=10.0, length_y=7.5, num_elem_x=4, num_elem_y=3, time_steps=None, field_keys=('scalar',), funcs_x=None, funcs_y=None, funcs_t=None, symbols=(y, x, t), offsets_space=(0.0,), offsets_time=(0.0,), nodes_per_elem=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.
- length_x¶
Length of the test case geometry in the X direction in length units. Defaults to 10.0.
- length_y¶
Length of the test case geometry in the Y direction in length units. Defaults to 7.5.
- num_elem_x¶
Number of elements in the mesh in the X direction. Defaults to 4.
- num_elem_y¶
Number of elements in the mesh in the Y direction. Defaults to 3.
- time_steps¶
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.
- field_keys¶
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_x¶
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¶
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.
- funcs_t¶
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.
- symbols¶
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.
- offsets_space¶
Constants which are added to the physical field functions in each spatial dimensions.
- offsets_time¶
Constant which is added to the physical field function in time.
- nodes_per_elem¶
Number of nodes per element. Currently only rectangular meshes and with 4 nodes per element are supported. Defaults to 4.
- __init__(length_x=10.0, length_y=7.5, num_elem_x=4, num_elem_y=3, time_steps=None, field_keys=('scalar',), funcs_x=None, funcs_y=None, funcs_t=None, symbols=(y, x, t), offsets_space=(0.0,), offsets_time=(0.0,), nodes_per_elem=4)¶
- class AnalyticSimDataGen(case_data)[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.
- __init__(case_data)[source]¶
- Parameters:
case_data (
AnalyticCaseData2D
) – Data class containing the parameters required to create the analytic mesh and the underlying physical field functions.
- case_data¶
- coords¶
- connect¶
- field_sym_funcs¶
- field_lam_funcs¶
- field_eval¶
- evaluate_field_truth(field_key, coords, time_steps=None)[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)
- evaluate_all_fields_truth(coords, time_steps=None)[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)[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_all_fields_at_nodes()[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)
- generate_sim_data()[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=None, time_step=-1)[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.