120 The advection equation and marker-in-cell method
implementations of Eq. (8.22)are
i = double(int16(xm/dx − 0.5)) +1;
i = double(int16(xm/dx + 0.5));
Examples are in FCT_1D.m and Markers_1D.m.
Exercise 8.3
Modify the previous marker-based code by introducing non-uniform distances
between nodal points and markers and by using a bisection algorithm (Fig. 8.10)
to define indices of the nearest nodes. Prescribe a slightly variable velocity on the
nodal points and interpolate it to markers when displacing them. An example is
given in Markers_1Dirregular.m associated with this chapter.
Exercise 8.4
Modify the 2D model with the variable viscosity (Exercise 7.2) by including the
advection of density and viscosity fields with markers. Create a grid of 200 ×300
markers with small (up to half of the marker grid distance) random displacements
(rand) relative to regular positions. Randomisation is introduced to prevent the
opening of big gaps between markers during the simulation which often occurs if
regular marker grids are used (e.g. due to pure-shear-related stretching that increases
the distances between markers). Save the horizontal and vertical coordinate for
every marker and assign it with the density and viscosity depending on the position
in either the left or the right layer. An alternative approach, which requires less
memory, is to assign every marker with a material type index depending on the
initial position (i.e. 1 and 2 for the left and right layer, respectively). Then the marker
density and viscosity (and potentially any other material-dependent property) can
be estimated based on the material type index. Interpolate the marker density and
viscosity (η
s
in Fig. 7.19) to the basic nodes of the grid using Eq. (8.18) (write
a loop over the markers and add the density and viscosity of each marker to the
four surrounding nodes, Fig. 8.9). For computing i and j indices for the upper left
node next to the marker (Fig. 8.9), apply Eq. (8.22) separately for each coordinate.
Compute the viscosity for the centres of cells (η
n
in Fig. 7.19) by averaging the
viscosity from the four surrounding basic nodes (an alternative way is to interpolate
this viscosity directly from markers based on Eq. 8.18). After obtaining a velocity
field, define a time step in such a manner that the marker displacements do not
exceed half the grid spacing. Interpolate the v
x
and v
y
velocity components for the
markers from the staggered nodes (Eq. 8.19) and displace them using a first-order
accurate scheme (Eq. (8.13)). Note that for staggered nodes, Eq. (8.22) is modified
since these nodes are displaced by half of the grid distance relative to the basic