Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
FEATool can be used to easily generate interactive surface, contour, arrow, and other visualizations of
unstructured mesh and simulation data in 1D, 2D, and 3D. As FEATool also supports Plotly as
rendering and visualization engine it is possible to create, interactively explore, and share simulation
and unstructured data directly on the web. This post explains and gives examples how fully three-
dimensional (3D) visualizations can be created using the Matlab or Octave CLI interface together with
FEATool and Plotly.
(Please note that due to loading the Plotly JS library and interactive plot data the responsiveness of this
page can be delayed.)
Instead of importing a mesh, here for simplicity we will manually construct a grid of overlapping
cylinders to have something interesting to look at, and generate corresponding vertex data consisting
of the distance from the center lines to the cylinder walls. The following m-script commands achieves
this (but again this will not be necessary if data is imported)
% Point distribution.
n_p = 18; % Number of radial points.
n_z = 20; % Number of points lengthwise.
th = linspace(0,2*pi,n_p);
p = [];
for r=[0.05 0.1 0.2 0.3];
for z_i=linspace(-1,1,n_z)
p = [ p; [ r*cos(th(1:end-1)) z_i*ones(1,n_p-1) r*sin(th(1:end-1)) ;
r*sin(th(1:end-1)) r*cos(th(1:end-1)) z_i*ones(1,n_p-1) ;
z_i*ones(1,n_p-1) r*sin(th(1:end-1)) r*cos(th(1:end-1)) ]' ];
end
end
% Triangulate points.
t = delaunay( p );
Here, the variables p, t, and u now contain the grid points, triangulation, and data.
Having the grid point vertices and connectivities one can use the grid utility functions gridadj and
gridbdr to reconstruct the necessary adjacency, boundary, and subdomain fields
Now, with the complete grid struct we can simply plot the grid with
plotgrid( grid )
which displays a Matlab figure with the grid. Optionally, we can add the plotly renderer property to
instead generate a plotly visualization.
(Note that the following plots are fully interactive Plotly visualizations which can be rotated, zoomed,
and inspected.)
The grid is simply stored in the corresponding grid field, while sdim represents the names of the
space dimensions. The dvar field is the name string or tag used to access and call the variables in the
postprocessing functions. Lastly, the sfun field specifies the finite element shape function, in this case
node oriented linear first order P1 functions (sflag1) are prescribed, which is appropriate when the
imported visualization data is defined in the grid points or vertex nodes.
The imported or generated data must now be converted and reshaped to a column vector format
which is specified as a column vector of size np x 1, where np is the number of grid points. Moreover,
the fea struct is checked, validated, and parsed to be able to be used by the postplot function.
% Check and parse fea struct and assign solution data field.
fea.sol.u = u(:);
fea = parseprob( fea );
In FEATool, valid string expressions may be functions of the data itself u, space dimensions x, y, z,
built-in Matlab functions (sin, log, etc.), custom user defined functions on the Matlab path, and even
first and second derivatives of the data (expressed as for example ux and uyy). In this way complex
visualization and postprocessing expressions are conveniently parsed automatically by FEATool, and
do not require the user to explicitly calculate them.
Surface: u+sin(2*pi*x)
0.5
0.5
Here we plot the computed distance from the center lines, u, as slices and add arrows for the
corresponding derivative (FEATool automatically computes this when using the ux, uy, and uz
expressions).
0.3
0.25
0.2
0.15
0.1
0.05
Iso-surface Plot
The iso-surface functionality is somewhat coarse, as it interpolates to a background grid, the example
here nevertheless illustrates the logical switch expression concept. Here by plotting u*(z<0) everyting
in the upper half plane is simply canceled out (evaluated to zero)
Iso: u*(z<0)
0.2
0.15
0.1
0.05
Although these examples have been for full 3D visualizations, 1D and 2D is similarly supported as the
two-dimensional unstructured Matlab surface and contour plots illustrated here.
SHARE ON
Prev Next
RELATED ARTICLES
Visualization and Postprocessing on Unstructured Grids and Meshes with FEATool Functions