.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/basics/ex2_5_vectorfields3d_disp3d.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_basics_ex2_5_vectorfields3d_disp3d.py: Basics: 3D vector field sensors ================================================================================ In all our previous examples we have looked at a 2D solid mechanics simulation and applied displacement sensors to the vector field. Here we will build a custom vector field sensor array on a 3D simulation of a small linear elastic cube loaded in tension with the addition of an applied thermal gradient. Note that this tutorial assumes you are familiar with the use of `pyvale` for scalar fields as described in the first set of examples. Test case: Simple 3D cube thermo-mechanical in tension with temp gradient. .. GENERATED FROM PYTHON SOURCE LINES 21-28 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt import mooseherder as mh import pyvale as pyv .. GENERATED FROM PYTHON SOURCE LINES 29-32 First we load our simulation as a `SimData` object. In this case we are loading a 10mm cube loaded in tension in the y direction with the addition of a thermal gradient in the y direction. .. GENERATED FROM PYTHON SOURCE LINES 32-35 .. code-block:: Python data_path = pyv.DataSet.element_case_path(pyv.EElemTest.HEX20) sim_data = mh.ExodusReader(data_path).read_all_sim_data() .. GENERATED FROM PYTHON SOURCE LINES 36-38 As we are creating a 3D vector field sensor we now have a third displacement field component here. .. GENERATED FROM PYTHON SOURCE LINES 38-44 .. code-block:: Python field_name = "disp" field_comps = ("disp_x","disp_y","disp_z") sim_data = pyv.scale_length_units(scale=1000.0, sim_data=sim_data, disp_comps=field_comps) .. GENERATED FROM PYTHON SOURCE LINES 45-47 We use a helper function to print the extent of the dimensions in our `SimData` object to help us locate our sensors on the cube. .. GENERATED FROM PYTHON SOURCE LINES 47-51 .. code-block:: Python pyv.print_dimensions(sim_data) descriptor = pyv.SensorDescriptorFactory.displacement_descriptor() .. GENERATED FROM PYTHON SOURCE LINES 52-55 We pass in the string keys for the three vector field components as they appear in our `SimData` object as well as specifying that our elements are 3 dimensional. .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: Python disp_field = pyv.FieldVector(sim_data,field_name,field_comps,elem_dims=3) .. GENERATED FROM PYTHON SOURCE LINES 58-61 Here we manually define our sensor positions to place a sensor on the centre of each face of our 10mm cube. From here everything is the same as for our 2D vector field sensor arrays. .. GENERATED FROM PYTHON SOURCE LINES 61-79 .. code-block:: Python sensor_positions = np.array(((5.0,0.0,5.0), (5.0,10.0,5.0), (5.0,5.0,0.0), (5.0,5.0,10.0), (0.0,5.0,5.0), (10.0,5.0,5.0),)) sample_times = np.linspace(0.0,np.max(sim_data.time),50) sensor_data = pyv.SensorData(positions=sensor_positions, sample_times=sample_times) disp_sens_array = pyv.SensorArrayPoint(sensor_data, disp_field, descriptor) measurements = disp_sens_array.calc_measurements() .. GENERATED FROM PYTHON SOURCE LINES 80-82 Let's have a look at the y displacement field in relation to the location of our displacement sensors. .. GENERATED FROM PYTHON SOURCE LINES 82-85 .. code-block:: Python pv_plot = pyv.plot_point_sensors_on_sim(disp_sens_array,"disp_y") pv_plot.show() .. GENERATED FROM PYTHON SOURCE LINES 86-88 We print the results for one of the sensors so we can see what the errors are for the last few sampling times. .. GENERATED FROM PYTHON SOURCE LINES 88-103 .. code-block:: Python print(80*"-") sens_print = 0 comp_print = 0 time_last = 5 time_print = slice(measurements.shape[2]-time_last,measurements.shape[2]) print(f"These are the last {time_last} virtual measurements of sensor " + f"{sens_print} for {field_comps[comp_print]}:") pyv.print_measurements(disp_sens_array,sens_print,comp_print,time_print) print(80*"-") .. GENERATED FROM PYTHON SOURCE LINES 104-108 Finally, we plot the time traces for all field components noting that we expect the bottom of the cube to be fixed, the top of the cube to have the maximum y displacement, and that all sensors on the sides of the cube should give the same results. .. GENERATED FROM PYTHON SOURCE LINES 108-112 .. code-block:: Python for ff in field_comps: pyv.plot_time_traces(disp_sens_array,ff) plt.show() .. _sphx_glr_download_examples_basics_ex2_5_vectorfields3d_disp3d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ex2_5_vectorfields3d_disp3d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex2_5_vectorfields3d_disp3d.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ex2_5_vectorfields3d_disp3d.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_