Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

13. DEVSS-G stabilization and a coupled two-dimensional log-conformation solver

The log-conformation formulation of Lecture 2 keeps the conformation tensor positive definite in a given velocity field. When the polymer stress is coupled to the momentum equation, a second difficulty appears if the solvent contributes little to the viscosity (βs=ηs/η0→0\beta_s = \eta_s/\eta_0 \to 0): the viscous term βs∇2u\beta_s \nabla^2\mathbf{u}, which makes the momentum equation elliptic in the velocity, becomes small, and an iteration that treats the polymer stress explicitly stops converging.

The DEVSS method of Guénette and Fortin (1995) adds a viscous term to the implicit side of the momentum equation and subtracts the same term on the explicit side; in the variant DEVSS-G of Liu, Bornside, Armstrong and Brown (1998) the subtracted term is computed from the velocity gradient. The converged solution is unchanged and the iteration is stabilized. This lecture treats the building blocks of a two-dimensional solver (a Poisson solver and the projection step, a log-conformation step, and DEVSS-G) and applies the solver of the package, which works with the stream function, to cavity flow.

Learning objectives

  1. Explain why the coupled iteration fails as βs=ηs/η0→0\beta_s = \eta_s/\eta_0 \to 0.

  2. Derive the DEVSS-G terms, with the effective viscosity ratio βeff=βs+αdevss(1−βs)\beta_{\mathrm{eff}} = \beta_s + \alpha_{\mathrm{devss}}(1-\beta_s), and show that they cancel in a converged solution.

  3. Check the Poisson solver based on the discrete cosine transform, the projection step and the two-dimensional log-conformation step against exact solutions.

  4. Compute cavity flow at small solvent viscosity ratios, with det⁡C=exp⁡(tr⁡Ψ)>0\det\mathbf{C} = \exp(\operatorname{tr}\boldsymbol{\Psi}) > 0 everywhere.

Time: about 60 min

1. The projection step and the Poisson solver

With lengths scaled by LL, velocities by UU and stresses with the total viscosity η0=ηs+ηp\eta_0 = \eta_s + \eta_p, the equations of two-dimensional viscoelastic flow are

Re(∂u∂t+u⋅∇u)=−∇p+βs∇2u+∇⋅τp,∇⋅u=0\mathrm{Re}\left(\frac{\partial \mathbf{u}}{\partial t} + \mathbf{u}\cdot\nabla\mathbf{u}\right) = -\nabla p + \beta_s \nabla^2\mathbf{u} + \nabla\cdot\boldsymbol{\tau}_p, \qquad \nabla\cdot\mathbf{u} = 0

with the polymer stress τp=1−βsWi(C−I)\boldsymbol{\tau}_p = \frac{1-\beta_s}{\mathrm{Wi}}(\mathbf{C} - \mathbf{I}). To make a velocity field divergence free, or to obtain the pressure p(x,y)p(x,y) from the momentum balance, one solves a Poisson problem −∇h2p=f-\nabla_h^2 p = f with Neumann conditions on a cell-centred grid. The problem has a solution only if ff has zero mean, and the solution is fixed by requiring that pp has zero mean as well.

The function viscoelastic_fvm_2d._dct2_poisson_neumann_2d uses the discrete cosine transform. The cosine modes correspond to an even reflection of the cell values across the four walls, and they are the eigenvectors of the five-point Laplacian with Neumann conditions, with the eigenvalues

λkx,ky=4hx2sin⁡2 ⁣(πkx2Nx)+4hy2sin⁡2 ⁣(πky2Ny),(kx,ky)≠(0,0)\lambda_{k_x, k_y} = \frac{4}{h_x^2}\sin^2\!\left(\frac{\pi k_x}{2 N_x}\right) + \frac{4}{h_y^2}\sin^2\!\left(\frac{\pi k_y}{2 N_y}\right), \qquad (k_x, k_y) \neq (0, 0)

A velocity field u∗\mathbf{u}^* is made divergence free by subtracting ∇hϕ\nabla_h \phi, where −∇h2ϕ=−∇h⋅u∗-\nabla_h^2 \phi = -\nabla_h\cdot\mathbf{u}^* (the projection step). The cost is of order NxNylog⁡(NxNy)N_x N_y \log(N_x N_y) operations.


Demonstration 1: the Poisson solver and the projection step
===========================================================
Discrete 5-point Neumann Poisson residual ||-Lap_h(p) - rhs||_inf : 2.309e-14
Grid errors (N=16, 32, 64): [0.010726, 0.002719, 0.000682] -> observed order = 1.995
<Figure size 1166x440 with 3 Axes>

Figure 13.1. (a) Pressure from the cosine-transform solver for a manufactured right-hand side. (b) Maximum error against the number of cells per side; the fitted order is 2.00.

2. The log-conformation step in two dimensions

In a two-dimensional flow the logarithm Ψ(x,y,t)=log⁡C(x,y,t)\boldsymbol{\Psi}(x,y,t) = \log\mathbf{C}(x,y,t) has three independent components, Ψxx\Psi_{xx}, Ψyy\Psi_{yy} and Ψxy\Psi_{xy}. A call of np.linalg.eigh in a Python loop over all cells would be slow. The function viscoelastic_fvm_2d._log_step_2d_field uses instead the closed-form eigenvalues and eigenvectors of a symmetric 2×22\times 2 matrix, for all cells at once:

ψ1,2=Ψxx+Ψyy2±(Ψxx−Ψyy2)2+Ψxy2,θ=12atan2⁡ ⁣(2Ψxy, Ψxx−Ψyy)\psi_{1,2} = \frac{\Psi_{xx} + \Psi_{yy}}{2} \pm \sqrt{\left(\frac{\Psi_{xx} - \Psi_{yy}}{2}\right)^2 + \Psi_{xy}^2}, \qquad \theta = \frac{1}{2}\operatorname{atan2}\!\left(2\Psi_{xy},\, \Psi_{xx} - \Psi_{yy}\right)
  1. The eigenvalues of C\mathbf{C} are λ1,2=eψ1,2>0\lambda_{1,2} = e^{\psi_{1,2}} > 0, so that det⁡C=λ1λ2=exp⁡(Ψxx+Ψyy)>0\det\mathbf{C} = \lambda_1\lambda_2 = \exp(\Psi_{xx} + \Psi_{yy}) > 0 in every cell.

  2. The velocity gradient L=∇u\mathbf{L} = \nabla\mathbf{u} is transformed to the principal axes, M~=RTLR\tilde{\mathbf{M}} = \mathbf{R}^T\mathbf{L}\mathbf{R}. The off-diagonal term of the commutator of Lecture 2, [Ω~,diag⁡(ψ1,ψ2)]12=λ2m~12+λ1m~21λ2−λ1(ψ2−ψ1)[\tilde{\boldsymbol{\Omega}}, \operatorname{diag}(\psi_1, \psi_2)]_{12} = \frac{\lambda_2 \tilde{m}_{12} + \lambda_1 \tilde{m}_{21}}{\lambda_2 - \lambda_1}(\psi_2 - \psi_1), is replaced by its limit m~12+m~21\tilde{m}_{12} + \tilde{m}_{21} when the two eigenvalues are nearly equal.

  3. The advection term (u⋅∇)Ψ(\mathbf{u}\cdot\nabla)\boldsymbol{\Psi} is discretized with first-order upwind differences, which do not produce undershoots.


Demonstration 2: the two-dimensional log-conformation step in plane Poiseuille flow
===================================================================================
2-D log-conformation Poiseuille max |tau_xy - exact| : 8.091e-04
2-D log-conformation Poiseuille max |N1 - exact|     : 3.556e-02
Minimum conformation determinant min det(C)          : 1.006873 (> 0)
<Figure size 1166x440 with 2 Axes>

Figure 13.2. The two-dimensional log-conformation step in plane Poiseuille flow. (a) Shear stress and first normal stress difference across the channel against the Oldroyd-B values. (b) Determinant of C\mathbf{C} against 1+(Wi γ˙)21 + (\mathrm{Wi}\,\dot\gamma)^2.

3. DEVSS-G stabilization as βs→0\beta_s \to 0

The polymer stress is now coupled to the momentum equation. In the simplest iteration the velocity is obtained from −βs∇2uk+1+∇pk+1=∇⋅τpk-\beta_s \nabla^2\mathbf{u}^{k+1} + \nabla p^{k+1} = \nabla\cdot\boldsymbol{\tau}_p^k, with the polymer stress of the previous iterate. When βs≪1\beta_s \ll 1 the divergence of the polymer stress is divided by a small number, and an error of the stress is amplified by the factor (1−βs)/βs≫1(1-\beta_s)/\beta_s \gg 1 in each iteration.

The discrete elastic-viscous split stress method (DEVSS, Guénette and Fortin, 1995; in the variant DEVSS-G of Liu, Bornside, Armstrong and Brown, 1998) adds the viscous term αdevss(1−βs)∇2u\alpha_{\mathrm{devss}}(1-\beta_s)\nabla^2\mathbf{u} to the implicit left-hand side and subtracts the same quantity, computed from the velocity gradient of the previous iterate as ∇⋅[αdevss(1−βs)(L+LT)]\nabla\cdot[\alpha_{\mathrm{devss}}(1-\beta_s)(\mathbf{L} + \mathbf{L}^T)], on the right-hand side:

−βeff∇2u+∇p=∇⋅[τp−αdevss(1−βs)(L+LT)]−Re u⋅∇u,βeff=βs+αdevss(1−βs)-\beta_{\mathrm{eff}}\nabla^2\mathbf{u} + \nabla p = \nabla\cdot\Big[\boldsymbol{\tau}_p - \alpha_{\mathrm{devss}}(1-\beta_s)\left(\mathbf{L} + \mathbf{L}^T\right)\Big] - \mathrm{Re}\,\mathbf{u}\cdot\nabla\mathbf{u}, \qquad \beta_{\mathrm{eff}} = \beta_s + \alpha_{\mathrm{devss}}(1-\beta_s)

The function solve_2d_viscoelastic_cavity works with the stream function. Taking the curl of the momentum equation removes the pressure and leaves, in each iteration, a biharmonic equation βeff∇4ψ=∇×f\beta_{\mathrm{eff}}\nabla^4\psi = \nabla\times\mathbf{f} with conditions on ψ\psi and on its normal derivative at the walls. It is solved with the two-dimensional discrete sine transform; the condition on the normal derivative is imposed through a matrix of size 2(Nx+Ny)×2(Nx+Ny)2(N_x+N_y)\times 2(N_x+N_y) that relates the vorticity at the walls to the velocity there (a capacitance matrix). As βs→0\beta_s \to 0, a value of αdevss\alpha_{\mathrm{devss}} between 0.5 and 1 keeps βeff\beta_{\mathrm{eff}} of order 1.


Demonstration 3: DEVSS-G at a small solvent viscosity ratio
===========================================================
alpha_devss = 0.00 (beta_eff = 0.025) | final velocity residual = 2.584e-01 | detC_min = 1.0003
alpha_devss = 0.35 (beta_eff = 0.366) | final velocity residual = 1.283e-04 | detC_min = 1.0001
alpha_devss = 0.80 (beta_eff = 0.805) | final velocity residual = 2.465e-04 | detC_min = 1.0001
Residual reduction from DEVSS-G stabilization (alpha = 0.80 against 0.0): 1048.5x
<Figure size 1188x440 with 2 Axes>

Figure 13.3. Cavity flow at a low solvent viscosity ratio for three values of the DEVSS-G parameter α\alpha. (a) Change of the velocity per step: it grows for α=0\alpha = 0 and decays for α=0.35\alpha = 0.35 and 0.8. (b) Horizontal velocity on the vertical midline at the end of the runs.

4. Cavity flow: stream function, pressure and stretch

With DEVSS-G in the momentum equation and the log-conformation step for the polymer, the solver returns the stream function, the velocity, the pressure, Ψ\boldsymbol{\Psi} and C\mathbf{C}:

  • The velocity derived from the stream function, u=∂yψu = \partial_y\psi and v=−∂xψv = -\partial_x\psi, is divergence free in the interior, and it matches the velocity of the lid, ulid(x)=16x2(1−x)2u_{\mathrm{lid}}(x) = 16x^2(1-x)^2.

  • The pressure p(x,y)p(x,y) follows from the divergence of the momentum equation, with _dct2_poisson_neumann_2d.

  • The stretch tr⁡C(x,y)\operatorname{tr}\mathbf{C}(x,y) is largest in the sheared layer under the lid and is carried towards the downstream corner. The determinant det⁡C(x,y)=exp⁡(Ψxx+Ψyy)\det\mathbf{C}(x,y) = \exp(\Psi_{xx} + \Psi_{yy}) is positive in every cell.


Demonstration 4: cavity flow at Wi = 0.90
=========================================
Primary vortex centre (x_c, y_c)     : (0.4583, 0.8104)
Stream function min psi_min           : -0.06347
Peak conformation trace max tr(C)    : 19.002
Conformation determinant range       : [1.0000, 5.9868]
<Figure size 1056x902 with 7 Axes>

Figure 13.4. Cavity flow at Wi=0.9\mathrm{Wi} = 0.9 on a 25×2525 \times 25 grid with a regularized lid. (a) Stream function, with the vortex centre at (0.46, 0.81). (b) Trace of C\mathbf{C}, largest under the lid near the downstream corner. (c) Pressure. (d) Change of the velocity per time step.

Inside the algorithm: the 2×22\times 2 log-conformation step

The cell below prints the source of viscoelastic_fvm_2d._log_step_2d_field and compares its closed-form decomposition with the general functions tensors_kinematics.log_conformation_decompose and exp_conformation, applied cell by cell, on a grid on which the deformation varies in space.

Check against the package

A symmetric matrix Ψ=(ΨxxΨxyΨxyΨyy)\boldsymbol{\Psi} = \begin{pmatrix}\Psi_{xx} & \Psi_{xy}\\ \Psi_{xy} & \Psi_{yy}\end{pmatrix} has the eigenvalues 12(Ψxx+Ψyy)±(Ψxx−Ψyy2)2+Ψxy2\frac{1}{2}(\Psi_{xx}+\Psi_{yy}) \pm \sqrt{(\frac{\Psi_{xx}-\Psi_{yy}}{2})^2 + \Psi_{xy}^2}, and its principal axes are at the angle θ=12atan2⁡(2Ψxy,Ψxx−Ψyy)\theta = \frac{1}{2}\operatorname{atan2}(2\Psi_{xy}, \Psi_{xx}-\Psi_{yy}). The grid of the check includes the point Ψ=0\boldsymbol{\Psi} = \mathbf{0}, where the two eigenvalues are equal. The two implementations agree to rounding error (< 1e-12).


Inside the algorithm: the 2 x 2 log-conformation step against a cell-by-cell reference
======================================================================================
def _log_step_2d_field(
    Psi_xx: np.ndarray,
    Psi_yy: np.ndarray,
    Psi_xy: np.ndarray,
    u: np.ndarray,
    v: np.ndarray,
    L_xx: np.ndarray,
    L_xy: np.ndarray,
    L_yx: np.ndarray,
    L_yy: np.ndarray,
    hx: float,
    hy: float,
    dt: float,
    wi: float,
    periodic_x: bool = False,
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
    """One step of the two-dimensional log-conformation equation: upwind advection, stretching and Oldroyd-B relaxation."""
    # 1. Reconstruct C = exp(Psi) analytically for 2x2 symmetric field:
    half_tr = 0.5 * (Psi_xx + Psi_yy)
    diff = 0.5 * (Psi_xx - Psi_yy)
    r_rad = np.hypot(diff, Psi_xy)
    psi_1 = np.clip(half_tr + r_rad, -30.0, 30.0)
    psi_2 = np.clip(half_tr - r_rad, -30.0, 30.0)
    lam_1 = np.exp(psi_1)
    lam_2 = np.exp(psi_2)

    # Orthonormal eigenvectors of Psi (and C): [cos th, -sin th; sin th, cos th]
    th = 0.5 * np.arctan2(2.0 * Psi_xy, Psi_xx - Psi_yy)
    ct = np.cos(th)
    st = np.sin(th)

    C_xx = (ct**2) * lam_1 + (st**2) * lam_2
    C_yy = (st**2) * lam_1 + (ct**2) * lam_2
    C_xy = ct * st * (lam_1 - lam_2)

    # 2. Transform velocity gradient L into eigenbasis M = R^T L R:
    # R = [[ct, -st], [st, ct]] -> R^T = [[ct, st], [-st, ct]]
    t00 = ct * L_xx + st * L_yx
    t01 = ct * L_xy + st * L_yy
    t10 = -st * L_xx + ct * L_yx
    t11 = -st * L_xy + ct * L_yy

    m11 = t00 * ct + t01 * st
    m12 = -t00 * st + t01 * ct
    m21 = t10 * ct + t11 * st
    m22 = -t10 * st + t11 * ct

    # Fattal-Kupferman commutator [Omega_tilde, diag(psi)]_12 = om_12 * (psi_2 - psi_1):
    gap = np.abs(lam_2 - lam_1) / (0.5 * (lam_1 + lam_2))
    safe_dl = np.where(gap > 1e-6, lam_2 - lam_1, 1.0)
    om_12 = np.where(gap > 1e-6, (lam_2 * m12 + lam_1 * m21) / safe_dl, 0.5 * (m12 - m21))
    comm_12 = np.where(gap > 1e-6, om_12 * (psi_2 - psi_1), m12 + m21)

    # Oldroyd-B relaxation -(C - I) / wi in Psi-eigenbasis: -(1 - 1/lam_i) / wi on diagonal
    inv_wi = 1.0 / max(float(wi), 1e-6)
    d1_eig = 2.0 * m11 - (1.0 - 1.0 / lam_1) * inv_wi
    d2_eig = 2.0 * m22 - (1.0 - 1.0 / lam_2) * inv_wi
    d12_eig = comm_12

    # Rotate source back to Cartesian: R @ [[d1, d12], [d12, d2]] @ R^T:
    src_xx = (ct**2) * d1_eig + (st**2) * d2_eig - 2.0 * ct * st * d12_eig
    src_yy = (st**2) * d1_eig + (ct**2) * d2_eig + 2.0 * ct * st * d12_eig
    src_xy = ct * st * (d1_eig - d2_eig) + (ct**2 - st**2) * d12_eig

    # 3. First-order upwind advection - (u dPsi/dx + v dPsi/dy):
    def _advect(f: np.ndarray) -> np.ndarray:
        if periodic_x:
            f_xm = np.roll(f, 1, axis=0)
            f_xp = np.roll(f, -1, axis=0)
        else:
            f_xm = np.vstack([f[0:1, :], f[:-1, :]])
            f_xp = np.vstack([f[1:, :], f[-1:, :]])
        f_ym = np.hstack([f[:, 0:1], f[:, :-1]])
        f_yp = np.hstack([f[:, 1:], f[:, -1:]])
        df_dx = np.where(u >= 0.0, (f - f_xm) / hx, (f_xp - f) / hx)
        df_dy = np.where(v >= 0.0, (f - f_ym) / hy, (f_yp - f) / hy)
        return -(u * df_dx + v * df_dy)

    Psi_xx_new = np.clip(Psi_xx + dt * (_advect(Psi_xx) + src_xx), -18.0, 18.0)
    Psi_yy_new = np.clip(Psi_yy + dt * (_advect(Psi_yy) + src_yy), -18.0, 18.0)
    Psi_xy_new = np.clip(Psi_xy + dt * (_advect(Psi_xy) + src_xy), -18.0, 18.0)
    return Psi_xx_new, Psi_yy_new, Psi_xy_new, C_xx, C_yy, C_xy

Max discrepancy between vectorized 2-D kernel and cell-wise eigh reference: 5.551e-17

Exercises

Worked solutions are in 13_solutions.ipynb. The cell below the list is a short self-check to start from.

  1. Verify a result. Check that the DEVSS-G terms do not change the steady solution. Run solve_2d_viscoelastic_cavity with nx=21, ny=21, wi=0.55, beta_s=0.30, re=0.02, n_steps=200 for αdevss∈{0.25,0.55,0.95}\alpha_{\mathrm{devss}} \in \{0.25, 0.55, 0.95\}, and compare the velocity fields and the position of the vortex centre.

  2. Find how it fails. Reduce the solvent viscosity ratio, βs∈{0.50,0.12,0.025}\beta_s \in \{0.50, 0.12, 0.025\}, at Wi=0.40\mathrm{Wi} = 0.40 on a grid of 18×1818 \times 18 cells, and compare the final residual of the velocity without stabilization (alpha_devss=0.0) and with DEVSS-G (alpha_devss=0.80).

  3. Implement it yourself. Write a projection step on a staggered grid (uu on vertical faces, vv on horizontal faces, the potential ϕ\phi at cell centres) with your own Poisson solver based on the discrete cosine transform for Neumann conditions. Check that the divergence after the projection is at the level of rounding error, and compare the Poisson solver with viscoelastic_fvm_2d._dct2_poisson_neumann_2d.


Self-check for the exercises
============================
All checks passed.