Incompressible Navier-Stokes with heat conduction and convection (via low level interface)

Download this notebook

Download meshes here

[ ]:
# Video generated with Paraview from the output files
from IPython.display import Video
Video("visualizations/navier_stokes_temperature.mp4", embed=True, width=800, height=400)
[9]:
import os

import jax
import jax.numpy as jnp
import meshio
from flax.core import FrozenDict

from autopdex import utility, spaces, seeder, models, dae

jax.config.update("jax_enable_x64", True)

Load the mesh that was generated with GMSH

[20]:
mesh = meshio.read("meshes/navier_stokes_mesh_v.msh")
coords_v = jnp.asarray(mesh.points[:, :2])
cells_v = jnp.asarray(mesh.cells_dict["triangle6"])

mesh = meshio.read("meshes/navier_stokes_mesh_p.msh")
coords_p = jnp.asarray(mesh.points[:, :2])
cells_p = jnp.asarray(mesh.cells_dict["triangle"])

coords_T = coords_v
cells_T = cells_v

node_coordinates = {
  '1velocity': coords_v,
  '2pressure': coords_p,
  '3temperature': coords_T,
}



Boundary conditions:

  • Parabolic inflow at x = 0,

  • No-slip on the cylinder and top/bottom walls.

  • Inflow (x = 0): T = 0 (Dirichlet)

  • Cylinder: T ramps from 0 to 20 over the first 3.5 seconds (Dirichlet)

  • Top and bottom walls: insulated (Neumann, natural condition)

  • p = 0 at lower right corner,

[21]:
def on_left(x):
  return jnp.isclose(x[:, 0], 0.0)
def on_cylinder(x):
  return jnp.isclose((x[:, 0] - 0.2)**2 + (x[:, 1] - 0.2)**2, 0.05**2)
def on_lower_right(x):
  return jnp.isclose(x, jnp.array([2.2, 0.])).all(axis=1)
def on_top_bottom_circle(x):
  return (jnp.isclose(x[:, 1], 0.0) + jnp.isclose(x[:, 1], 0.41) + jnp.isclose(
      (x[:, 0] - 0.2)**2 + (x[:, 1] - 0.2)**2, 0.05**2))

selection_v_left = utility.dof_select(on_left(coords_v), jnp.asarray([True, True]))
selection_v_remaining = utility.dof_select(on_top_bottom_circle(coords_v), jnp.asarray([True, True]))
selection_p = utility.dof_select(on_lower_right(coords_p), True)
selection_temp_left = utility.dof_select(on_left(coords_T), True)
selection_temp_cylinder = utility.dof_select(on_cylinder(coords_T), True)

dirichlet_dofs = {
  '1velocity': selection_v_left + selection_v_remaining,
  '2pressure': selection_p,
  '3temperature': selection_temp_left + selection_temp_cylinder,
}

# Set initial Dirichlet conditions
dirichlet_conditions = utility.dict_zeros_like(dirichlet_dofs, dtype=jnp.float64)

[22]:
# Time-dependent Dirichlet condition for the velocity inflow
def get_dirichlet_conditions(t):

  def condition(y_coor):
    u_max = 1.5
    u = 4 * u_max * y_coor * (0.41 - y_coor) / 0.41**2

    # 3.5 seconds sinusoidal ramp-up, then constant
    cond_list = [t <= 3.5, t > 3.5]
    func_list = [u * jnp.sin(jnp.pi / 7 * t), u]
    return jnp.asarray([jnp.piecewise(t, cond_list, func_list), 0.])

  new_values = jax.vmap(condition)(coords_v[:, 1])
  return jnp.where(selection_v_left, new_values, 0.0)

# This function is called before each time step to update the boundary conditions
def pre_step_updates(t, settings):
  settings['current time'] = t

  # Update velocity boundary conditions at time t
  new_dirichlet = get_dirichlet_conditions(t)
  settings['dirichlet conditions']['1velocity'] = new_dirichlet

  # Update temperature boundary conditions at time t
  # Cylinder temperature: ramp from 0 to 20 within the first 3.5 seconds
  cylinder_temp = jnp.where(t <= 3.5, 20 * jnp.sin(jnp.pi / 7 * t), 20.0)
  new_temp_bc = jnp.zeros_like(dirichlet_dofs['3temperature'], dtype=jnp.float64)
  new_temp_bc = new_temp_bc.at[selection_temp_cylinder].set(cylinder_temp)
  settings['dirichlet conditions']['3temperature'] = new_temp_bc

  return settings

Weak formulation: Coupled equations (Navier–Stokes and energy balance)

[23]:
def weak_form_integrand(x_int, trial_ansatz, test_ansatz, settings, static_settings, elem_number, set):
  t = settings['current time']

  # Pressure (p) and test function (q)
  p = trial_ansatz['2pressure'](x_int, t)
  q = test_ansatz['2pressure'](x_int)

  # Velocity (u) and its derivatives
  u = trial_ansatz['1velocity'](x_int, t)
  grad_u, du_dt = jax.jacfwd(trial_ansatz['1velocity'], (0, 1))(x_int, t)

  # Test function (v) and its derivatives
  v = test_ansatz['1velocity'](x_int)
  grad_v = jax.jacfwd(test_ansatz['1velocity'])(x_int)

  # Temperature (T) and test function (φ)
  T_val = trial_ansatz['3temperature'](x_int, t)
  grad_T, dT_dt = jax.jacfwd(trial_ansatz['3temperature'], (0, 1))(x_int, t)
  phi, grad_phi = jax.value_and_grad(test_ansatz['3temperature'])(x_int)

  # Divergence of u and v
  div_u = grad_u[0, 0] + grad_u[1, 1]
  div_v = grad_v[0, 0] + grad_v[1, 1]

  # Temperature-dependent viscosity:
  # Base viscosity and temperature coefficient
  nu0 = 0.001
  beta = 0.05
  nu = nu0 * (1 + beta * T_val)

  # Weak form of the momentum equation
  weak_momentum = (du_dt @ v + jnp.einsum('j,ij->i', u, grad_u) @ v + nu * jnp.einsum('ij,ij->', grad_u, grad_v) -
                   p * div_v)

  # Weak form of the continuity equation
  weak_continuity = -q * div_u

  # Thermal diffusivity parameter (α)
  alpha = 0.001

  # Weak form of the energy (temperature) equation
  weak_energy = (dT_dt * phi + (u @ grad_T) * phi + alpha * jnp.dot(grad_T, grad_phi))

  return weak_momentum + weak_continuity + weak_energy

Set-up the element and time stepping procedure

[24]:
# Ansatz functions for the fields
ansatz_fun = {
  '1velocity': spaces.fem_iso_line_tri_tet,  # quadratic (6 nodes per triangle)
  '2pressure': spaces.fem_iso_line_tri_tet,  # linear (3 nodes per triangle)
  '3temperature': spaces.fem_iso_line_tri_tet,
}

# Numerical integration
ref_int_coor, ref_int_weights = seeder.int_pts_ref_tri(order=4)

# Set-up the 'user residual' based on a weak-in-space formulation of the PDEs.
user_residual = models.mixed_reference_domain_residual_time(
    weak_form_integrand,
    ansatz_fun,
    ref_int_coor,
    ref_int_weights,
    mapping_key='1velocity',
)

# The settings are analougs to static analyses. Additionally, the 'current time' has to be initialized.
settings = {
  'connectivity': ({
    '1velocity': cells_v,
    '2pressure': cells_p,
    '3temperature': cells_T,
  },),
  'node coordinates': node_coordinates,
  'dirichlet dofs': dirichlet_dofs,
  'dirichlet conditions': dirichlet_conditions,
  'current time': 0.0,
}

# The static settings are also passed to the PDE functions.
# When used through the time stepping manager, also the 'dae' and 'time integrators' have to be specified.
static_settings = FrozenDict({
  'assembling mode': ('user residual',),
  'solution structure': ('nodal imposition',),
  'model': (user_residual,),
  'solver type': 'newton',
  'solver backend': 'pardiso',
  'solver': 'lu',
  'verbose': 1,
  'dae': 'call pde',    # Here we need the keyword 'call pde' in order to call the assembling routines for PDE specified by the 'model'.
  'time integrators': {
    '1velocity': dae.BackwardDiffFormula(2),
    '2pressure': dae.BackwardEuler(),     # The time derivative is not used, but an integrator has to be specified,
                                          #   that is compatible with the stages of the other fields
    '3temperature': dae.AdamsMoulton(1),
  },
})

# Define the postprocessing policy and pass the function for pre-step updates
manager = dae.TimeSteppingManager(static_settings,
                              save_policy=dae.SaveAllPolicy(),
                              pre_step_updates=pre_step_updates)

# Start with zero velocity and temperature
initial_conditions = {
  '1velocity': jnp.zeros((coords_v.shape[0], 2)),
  '2pressure': jnp.zeros((coords_p.shape[0], )),
  '3temperature': jnp.zeros((coords_T.shape[0], )),
}

Run the time stepping loop

[ ]:
t_final = 10
num_time_steps = 500
result = manager.run(initial_conditions, t_final / num_time_steps, t_final, num_time_steps, settings)
Iteration 0: Residual norm = 2.3690613306740624e-05
Iteration 1, Residual norm: 6.3454131650897704e-09

Iteration 0: Residual norm = 4.558955125986852e-05
Iteration 1, Residual norm: 6.476440887764573e-09

Iteration 0: Residual norm = 3.735759835019375e-05
Iteration 1, Residual norm: 6.662247547487657e-09

Iteration 0: Residual norm = 3.811627854888912e-05
Iteration 1, Residual norm: 6.852473050737693e-09

Iteration 0: Residual norm = 3.757262548943269e-05
Iteration 1, Residual norm: 7.079331285430475e-09

Iteration 0: Residual norm = 3.820441092922862e-05
Iteration 1, Residual norm: 7.326935549586557e-09

Iteration 0: Residual norm = 3.773725931291273e-05
Iteration 1, Residual norm: 7.586014317233318e-09

Iteration 0: Residual norm = 3.8283735753861407e-05
Iteration 1, Residual norm: 7.853161102695965e-09

Iteration 0: Residual norm = 3.7872214481399105e-05
Iteration 1, Residual norm: 8.127315090240174e-09

Iteration 0: Residual norm = 3.83557339666488e-05
Iteration 1, Residual norm: 8.405621850978605e-09

Iteration 0: Residual norm = 3.7988339778001236e-05
Iteration 1, Residual norm: 8.686884870243231e-09

Iteration 0: Residual norm = 3.8422992834747316e-05
Iteration 1, Residual norm: 8.96850560311337e-09

Iteration 0: Residual norm = 3.809285948060581e-05
Iteration 1, Residual norm: 9.249078954114976e-09

Iteration 0: Residual norm = 3.848908913798042e-05
Iteration 1, Residual norm: 9.526890650183709e-09

Iteration 0: Residual norm = 3.819233201318875e-05
Iteration 1, Residual norm: 9.801502779457184e-09

Iteration 0: Residual norm = 3.8558793935988796e-05
Iteration 1, Residual norm: 1.0073116573963737e-08
Progress: 3%, Time: 3.20e-01, dt: 2.00e-02, iterations: 1

Iteration 0: Residual norm = 3.829369427207513e-05
Iteration 1, Residual norm: 1.0343409264738755e-08
Iteration 2, Residual norm: 2.361989890229145e-14

Iteration 0: Residual norm = 3.8638641197555756e-05
Iteration 1, Residual norm: 1.0615591171818199e-08
Iteration 2, Residual norm: 2.434892427269048e-14

Iteration 0: Residual norm = 3.84051724766337e-05
Iteration 1, Residual norm: 1.089033327112458e-08
Iteration 2, Residual norm: 2.5253199614710256e-14

Iteration 0: Residual norm = 3.873505732909304e-05
Iteration 1, Residual norm: 1.1174355693775012e-08
Iteration 2, Residual norm: 2.6300771375937624e-14

Iteration 0: Residual norm = 3.853465383311746e-05
Iteration 1, Residual norm: 1.1471841301359611e-08
Iteration 2, Residual norm: 2.7505478431090312e-14

Iteration 0: Residual norm = 3.885735285745314e-05
Iteration 1, Residual norm: 1.1786038287905343e-08
Iteration 2, Residual norm: 2.881809319368178e-14

Iteration 0: Residual norm = 3.869276199354061e-05
Iteration 1, Residual norm: 1.2118972409008116e-08
Iteration 2, Residual norm: 3.024775988909764e-14

Iteration 0: Residual norm = 3.901591042559723e-05
Iteration 1, Residual norm: 1.2471073767965351e-08
Iteration 2, Residual norm: 3.174279485495596e-14

Iteration 0: Residual norm = 3.889112490646609e-05
Iteration 1, Residual norm: 1.2841547398197768e-08
Iteration 2, Residual norm: 3.33069146380342e-14

Iteration 0: Residual norm = 3.9222740209754315e-05
Iteration 1, Residual norm: 1.3228655246564256e-08
Iteration 2, Residual norm: 3.486200095058985e-14

Iteration 0: Residual norm = 3.914283954148882e-05
Iteration 1, Residual norm: 1.3630381775810517e-08
Iteration 2, Residual norm: 3.637425655038179e-14

Iteration 0: Residual norm = 3.9491240228315225e-05
Iteration 1, Residual norm: 1.4044574226631822e-08
Iteration 2, Residual norm: 3.7717417026782945e-14

Iteration 0: Residual norm = 3.946200737619933e-05
Iteration 1, Residual norm: 1.4469057401342807e-08
Iteration 2, Residual norm: 3.8827597230238383e-14

Iteration 0: Residual norm = 3.9835433354789825e-05
Iteration 1, Residual norm: 1.490120114827852e-08
Iteration 2, Residual norm: 3.9576156869957534e-14

Iteration 0: Residual norm = 3.9862714370599586e-05
Iteration 1, Residual norm: 1.533771500225881e-08
Iteration 2, Residual norm: 3.993905520594368e-14

Iteration 0: Residual norm = 4.0268706239532426e-05
Iteration 1, Residual norm: 1.577442451448273e-08
Iteration 2, Residual norm: 3.986726150877864e-14

Iteration 0: Residual norm = 4.0357606195329665e-05
Iteration 1, Residual norm: 1.6206601092904158e-08
Iteration 2, Residual norm: 3.9434090455724936e-14

Iteration 0: Residual norm = 4.080227081057037e-05
Iteration 1, Residual norm: 1.6629378327633318e-08
Iteration 2, Residual norm: 3.8691912990273004e-14

Iteration 0: Residual norm = 4.095631970008083e-05
Iteration 1, Residual norm: 1.7038392841200896e-08
Iteration 2, Residual norm: 3.7767346509179294e-14

Iteration 0: Residual norm = 4.1443641724586105e-05
Iteration 1, Residual norm: 1.7430183589036304e-08
Iteration 2, Residual norm: 3.673791084315584e-14

Iteration 0: Residual norm = 4.166414721036611e-05
Iteration 1, Residual norm: 1.7802417645667593e-08
Iteration 2, Residual norm: 3.5735157541280926e-14

Iteration 0: Residual norm = 4.2195644877648845e-05
Iteration 1, Residual norm: 1.8153718257129237e-08
Iteration 2, Residual norm: 3.491096789298554e-14

Iteration 0: Residual norm = 4.248160170177151e-05
Iteration 1, Residual norm: 1.848311905749759e-08
Iteration 2, Residual norm: 3.446651883405341e-14

Iteration 0: Residual norm = 4.305666453254342e-05
Iteration 1, Residual norm: 1.8789352534192704e-08
Iteration 2, Residual norm: 3.449904943316597e-14
Progress: 8%, Time: 8.00e-01, dt: 2.00e-02, iterations: 2

Iteration 0: Residual norm = 4.340536830721816e-05
Iteration 1, Residual norm: 1.9070284500886888e-08
Iteration 2, Residual norm: 3.4968126660379456e-14

Iteration 0: Residual norm = 4.402202428046516e-05
Iteration 1, Residual norm: 1.9322933289657583e-08
Iteration 2, Residual norm: 3.571555241337102e-14

Iteration 0: Residual norm = 4.4429608249281106e-05
Iteration 1, Residual norm: 1.9543677623336793e-08
Iteration 2, Residual norm: 3.6598454345823075e-14

Iteration 0: Residual norm = 4.508446796349629e-05
Iteration 1, Residual norm: 1.9728581850001582e-08
Iteration 2, Residual norm: 3.747371365182922e-14

Iteration 0: Residual norm = 4.5544945063447485e-05
Iteration 1, Residual norm: 1.987399061187591e-08
Iteration 2, Residual norm: 3.821287662157527e-14

Iteration 0: Residual norm = 4.6231354683809576e-05
Iteration 1, Residual norm: 1.9978745239192107e-08
Iteration 2, Residual norm: 3.869714166855968e-14

Iteration 0: Residual norm = 4.673430860240343e-05
Iteration 1, Residual norm: 2.004769779909379e-08
Iteration 2, Residual norm: 3.8857820753383034e-14

Iteration 0: Residual norm = 4.744050674812803e-05
Iteration 1, Residual norm: 2.009327732496281e-08
Iteration 2, Residual norm: 3.8565301020863705e-14

Iteration 0: Residual norm = 4.797078704243018e-05
Iteration 1, Residual norm: 2.0130264924937188e-08
Iteration 2, Residual norm: 3.773449142361465e-14

Iteration 0: Residual norm = 4.8681918446892714e-05
Iteration 1, Residual norm: 2.0165722366259747e-08
Iteration 2, Residual norm: 3.650459613354105e-14

Iteration 0: Residual norm = 4.922374461991446e-05
Iteration 1, Residual norm: 2.0195530860470156e-08
Iteration 2, Residual norm: 3.51891953836866e-14

Iteration 0: Residual norm = 4.992663492463021e-05
Iteration 1, Residual norm: 2.021557028641573e-08
Iteration 2, Residual norm: 3.396736837295452e-14

Iteration 0: Residual norm = 5.046720477731228e-05
Iteration 1, Residual norm: 2.023765217949297e-08
Iteration 2, Residual norm: 3.2890440049400094e-14

Iteration 0: Residual norm = 5.115163736538566e-05
Iteration 1, Residual norm: 2.029187735222725e-08
Iteration 2, Residual norm: 3.2004315100470576e-14

Iteration 0: Residual norm = 5.168072847585738e-05
Iteration 1, Residual norm: 2.041050541679136e-08
Iteration 2, Residual norm: 3.131768762369728e-14

Iteration 0: Residual norm = 5.233912247324502e-05
Iteration 1, Residual norm: 2.0605756951819143e-08
Iteration 2, Residual norm: 3.0798530927317144e-14

Iteration 0: Residual norm = 5.2850448328199296e-05
Iteration 1, Residual norm: 2.086048256042684e-08
Iteration 2, Residual norm: 3.0440758382337515e-14

Iteration 0: Residual norm = 5.3480775947471407e-05
Iteration 1, Residual norm: 2.1141453063543048e-08
Iteration 2, Residual norm: 3.011157518767568e-14

Iteration 0: Residual norm = 5.397469730273713e-05
Iteration 1, Residual norm: 2.1422829752994642e-08
Iteration 2, Residual norm: 2.958701218896368e-14

Iteration 0: Residual norm = 5.4580747819387614e-05
Iteration 1, Residual norm: 2.169647873445699e-08
Iteration 2, Residual norm: 2.8806595763554645e-14

Iteration 0: Residual norm = 5.5061268223207154e-05
Iteration 1, Residual norm: 2.1965029741618074e-08
Iteration 2, Residual norm: 2.7885275407645568e-14

Iteration 0: Residual norm = 5.564751968469552e-05
Iteration 1, Residual norm: 2.2230968357853443e-08
Iteration 2, Residual norm: 2.6914648226142085e-14

Iteration 0: Residual norm = 5.611725386730496e-05
Iteration 1, Residual norm: 2.2489543544154018e-08
Iteration 2, Residual norm: 2.5912993073596397e-14

Iteration 0: Residual norm = 5.668573954334078e-05
Iteration 1, Residual norm: 2.272694422268964e-08
Iteration 2, Residual norm: 2.4860559257632898e-14

Iteration 0: Residual norm = 5.71450700086363e-05
Iteration 1, Residual norm: 2.2925823980090752e-08
Iteration 2, Residual norm: 2.3750027541303237e-14
Progress: 13%, Time: 1.30e+00, dt: 2.00e-02, iterations: 2

Iteration 0: Residual norm = 5.769604717103553e-05
Iteration 1, Residual norm: 2.3073861835235953e-08
Iteration 2, Residual norm: 2.2588312424810123e-14

Iteration 0: Residual norm = 5.814393610679681e-05
Iteration 1, Residual norm: 2.3167849526753423e-08
Iteration 2, Residual norm: 2.1388187418526003e-14

Iteration 0: Residual norm = 5.867609451070836e-05
Iteration 1, Residual norm: 2.3212265191421073e-08
Iteration 2, Residual norm: 2.0171757308240567e-14

Iteration 0: Residual norm = 5.9109983295472524e-05
Iteration 1, Residual norm: 2.321573666698976e-08
Iteration 2, Residual norm: 1.8974537597871758e-14

Iteration 0: Residual norm = 5.962104053760891e-05
Iteration 1, Residual norm: 2.3185825293355353e-08
Iteration 2, Residual norm: 1.7812402726135572e-14

Iteration 0: Residual norm = 6.0038703111002556e-05
Iteration 1, Residual norm: 2.312404310446853e-08
Iteration 2, Residual norm: 1.6687335679266113e-14

Iteration 0: Residual norm = 6.052797326100538e-05
Iteration 1, Residual norm: 2.3027367882918355e-08
Iteration 2, Residual norm: 1.562426712824852e-14

Iteration 0: Residual norm = 6.092927662535614e-05
Iteration 1, Residual norm: 2.289639885146416e-08
Iteration 2, Residual norm: 1.4651316013894266e-14

Iteration 0: Residual norm = 6.139735696392631e-05
Iteration 1, Residual norm: 2.273910748273475e-08
Iteration 2, Residual norm: 1.376052413294636e-14

Iteration 0: Residual norm = 6.178224078739218e-05
Iteration 1, Residual norm: 2.2564851173657076e-08
Iteration 2, Residual norm: 1.293975933230415e-14

Iteration 0: Residual norm = 6.222923011393338e-05
Iteration 1, Residual norm: 2.237765586934405e-08
Iteration 2, Residual norm: 1.2182603173656403e-14

Iteration 0: Residual norm = 6.259773886090568e-05
Iteration 1, Residual norm: 2.2176876128326187e-08
Iteration 2, Residual norm: 1.1488167722655562e-14

Iteration 0: Residual norm = 6.302461496697472e-05
Iteration 1, Residual norm: 2.1961785865956622e-08
Iteration 2, Residual norm: 1.0859320480516573e-14

Iteration 0: Residual norm = 6.337771491605051e-05
Iteration 1, Residual norm: 2.1734430742640712e-08
Iteration 2, Residual norm: 1.0299933686092633e-14

Iteration 0: Residual norm = 6.37854353377363e-05
Iteration 1, Residual norm: 2.149871358483923e-08
Iteration 2, Residual norm: 9.812314536989028e-15

Iteration 0: Residual norm = 6.412307482952616e-05
Iteration 1, Residual norm: 2.125741039997185e-08
Iteration 2, Residual norm: 9.397501020605309e-15

Iteration 0: Residual norm = 6.451119776566487e-05
Iteration 1, Residual norm: 2.1010808436725185e-08
Iteration 2, Residual norm: 9.05208223679018e-15

Iteration 0: Residual norm = 6.483227199457144e-05
Iteration 1, Residual norm: 2.0758613196813664e-08
Iteration 2, Residual norm: 8.773602240722191e-15

Iteration 0: Residual norm = 6.519956703906858e-05
Iteration 1, Residual norm: 2.0502656240993617e-08
Iteration 2, Residual norm: 8.550509085976895e-15

Iteration 0: Residual norm = 6.550187681537135e-05
Iteration 1, Residual norm: 2.0247532369656772e-08
Iteration 2, Residual norm: 8.364681071134166e-15

Iteration 0: Residual norm = 6.584529495680531e-05
Iteration 1, Residual norm: 1.9998659791359334e-08
Iteration 2, Residual norm: 8.199108480149701e-15

Iteration 0: Residual norm = 6.612462972555087e-05
Iteration 1, Residual norm: 1.9759590282167696e-08
Iteration 2, Residual norm: 8.039878734003185e-15

Iteration 0: Residual norm = 6.644007681462441e-05
Iteration 1, Residual norm: 1.9530028026104205e-08
Iteration 2, Residual norm: 7.872107085753696e-15

Iteration 0: Residual norm = 6.66932218817569e-05
Iteration 1, Residual norm: 1.9305841137393502e-08
Iteration 2, Residual norm: 7.680539898452871e-15

Iteration 0: Residual norm = 6.69796728094782e-05
Iteration 1, Residual norm: 1.9081893326985235e-08
Iteration 2, Residual norm: 7.457208060297277e-15
Progress: 18%, Time: 1.80e+00, dt: 2.00e-02, iterations: 2

Iteration 0: Residual norm = 6.720745796308883e-05
Iteration 1, Residual norm: 1.8856336082346453e-08
Iteration 2, Residual norm: 7.204427498750102e-15

Iteration 0: Residual norm = 6.746725863719125e-05
Iteration 1, Residual norm: 1.8631283985268407e-08
Iteration 2, Residual norm: 6.926524232311741e-15

Iteration 0: Residual norm = 6.767227770404395e-05
Iteration 1, Residual norm: 1.840862694024262e-08
Iteration 2, Residual norm: 6.6332070515201335e-15

Iteration 0: Residual norm = 6.790807908714056e-05
Iteration 1, Residual norm: 1.8188676988640747e-08
Iteration 2, Residual norm: 6.343257217412158e-15

Iteration 0: Residual norm = 6.809258821716206e-05
Iteration 1, Residual norm: 1.7973726764424118e-08
Iteration 2, Residual norm: 6.079780853126242e-15

Iteration 0: Residual norm = 6.830666559166768e-05
Iteration 1, Residual norm: 1.7767337230081906e-08
Iteration 2, Residual norm: 5.86155192472758e-15

Iteration 0: Residual norm = 6.84729890252967e-05
Iteration 1, Residual norm: 1.7569812800235982e-08
Iteration 2, Residual norm: 5.700566260140167e-15

Iteration 0: Residual norm = 6.866839998870371e-05
Iteration 1, Residual norm: 1.737907107440389e-08
Iteration 2, Residual norm: 5.599728377908668e-15

Iteration 0: Residual norm = 6.882008571990041e-05
Iteration 1, Residual norm: 1.7194373575206924e-08
Iteration 2, Residual norm: 5.5501561554029045e-15

Iteration 0: Residual norm = 6.90005359267865e-05
Iteration 1, Residual norm: 1.7015045454739695e-08
Iteration 2, Residual norm: 5.531357386755329e-15

Iteration 0: Residual norm = 6.914036051963485e-05
Iteration 1, Residual norm: 1.6839049115160418e-08
Iteration 2, Residual norm: 5.518556332655327e-15

Iteration 0: Residual norm = 6.930719396824802e-05
Iteration 1, Residual norm: 1.6666416087519688e-08
Iteration 2, Residual norm: 5.488920998903167e-15

Iteration 0: Residual norm = 6.943436204730481e-05
Iteration 1, Residual norm: 1.65001268871099e-08
Iteration 2, Residual norm: 5.425336218174233e-15

Iteration 0: Residual norm = 6.958475386870617e-05
Iteration 1, Residual norm: 1.6342139795179453e-08
Iteration 2, Residual norm: 5.31767870354051e-15

Iteration 0: Residual norm = 6.969462452247482e-05
Iteration 1, Residual norm: 1.6192910601134408e-08
Iteration 2, Residual norm: 5.1646875795570494e-15

Iteration 0: Residual norm = 6.98230626237722e-05
Iteration 1, Residual norm: 1.605289822207207e-08
Iteration 2, Residual norm: 4.9748484746243865e-15

Iteration 0: Residual norm = 6.990993857845462e-05
Iteration 1, Residual norm: 1.591996716903233e-08
Iteration 2, Residual norm: 4.765987660371211e-15

Iteration 0: Residual norm = 7.001176896402778e-05
Iteration 1, Residual norm: 1.5788455707846566e-08
Iteration 2, Residual norm: 4.5623331991299286e-15

Iteration 0: Residual norm = 7.007280098029747e-05
Iteration 1, Residual norm: 1.5653701753375058e-08
Iteration 2, Residual norm: 4.39021775831287e-15

Iteration 0: Residual norm = 7.01475177191744e-05
Iteration 1, Residual norm: 1.551444226923221e-08
Iteration 2, Residual norm: 4.2715697166412134e-15

Iteration 0: Residual norm = 7.018398620181492e-05
Iteration 1, Residual norm: 1.5371348677009275e-08
Iteration 2, Residual norm: 4.216183163537115e-15

Iteration 0: Residual norm = 7.023411853907545e-05
Iteration 1, Residual norm: 1.5226294998865474e-08
Iteration 2, Residual norm: 4.215677180667099e-15

Iteration 0: Residual norm = 7.024901436546934e-05
Iteration 1, Residual norm: 1.5081719015283957e-08
Iteration 2, Residual norm: 4.2454651120731675e-15

Iteration 0: Residual norm = 7.027787345980598e-05
Iteration 1, Residual norm: 1.4938961163004648e-08
Iteration 2, Residual norm: 4.273572900210463e-15

Iteration 0: Residual norm = 7.02747255926725e-05
Iteration 1, Residual norm: 1.479768753242705e-08
Iteration 2, Residual norm: 4.2711995865303915e-15
Progress: 23%, Time: 2.30e+00, dt: 2.00e-02, iterations: 2

Iteration 0: Residual norm = 7.028633688140691e-05
Iteration 1, Residual norm: 1.4656612151635018e-08
Iteration 2, Residual norm: 4.220291270197736e-15

Iteration 0: Residual norm = 7.026942890175777e-05
Iteration 1, Residual norm: 1.4514613306119617e-08
Iteration 2, Residual norm: 4.1173731261942766e-15

Iteration 0: Residual norm = 7.026806875276989e-05
Iteration 1, Residual norm: 1.4371498745260415e-08
Iteration 2, Residual norm: 3.973547559119655e-15

Iteration 0: Residual norm = 7.024109514329683e-05
Iteration 1, Residual norm: 1.4228174737837441e-08
Iteration 2, Residual norm: 3.811815284745142e-15

Iteration 0: Residual norm = 7.022967874986063e-05
Iteration 1, Residual norm: 1.4086547614584659e-08
Iteration 2, Residual norm: 3.662624726466515e-15

Iteration 0: Residual norm = 7.019452895212761e-05
Iteration 1, Residual norm: 1.3949285020827683e-08
Iteration 2, Residual norm: 3.556610649884392e-15

Iteration 0: Residual norm = 7.017402074005187e-05
Iteration 1, Residual norm: 1.3819202709937486e-08
Iteration 2, Residual norm: 3.5143796908030815e-15

Iteration 0: Residual norm = 7.013072447309826e-05
Iteration 1, Residual norm: 1.3698525059192618e-08
Iteration 2, Residual norm: 3.539783144219775e-15

Iteration 0: Residual norm = 7.010044916168263e-05
Iteration 1, Residual norm: 1.3588313827276874e-08
Iteration 2, Residual norm: 3.619913994428558e-15

Iteration 0: Residual norm = 7.004764192385782e-05
Iteration 1, Residual norm: 1.3488218299474237e-08
Iteration 2, Residual norm: 3.729295569729421e-15

Iteration 0: Residual norm = 7.000570446693623e-05
Iteration 1, Residual norm: 1.3396350649259058e-08
Iteration 2, Residual norm: 3.83640462592265e-15

Iteration 0: Residual norm = 6.994089155211413e-05
Iteration 1, Residual norm: 1.3309216658138328e-08
Iteration 2, Residual norm: 3.912125101663671e-15

Iteration 0: Residual norm = 6.988425216364288e-05
Iteration 1, Residual norm: 1.322206666756694e-08
Iteration 2, Residual norm: 3.936757109625904e-15

Iteration 0: Residual norm = 6.980360789798611e-05
Iteration 1, Residual norm: 1.313002223685847e-08
Iteration 2, Residual norm: 3.9045379729877205e-15

Iteration 0: Residual norm = 6.972739858153398e-05
Iteration 1, Residual norm: 1.3029414173540969e-08
Iteration 2, Residual norm: 3.825326929481931e-15

Iteration 0: Residual norm = 6.962435269969071e-05
Iteration 1, Residual norm: 1.291854328971214e-08
Iteration 2, Residual norm: 3.723042903097287e-15

Iteration 0: Residual norm = 6.951960658618507e-05
Iteration 1, Residual norm: 1.279774537728502e-08
Iteration 2, Residual norm: 3.628884334679117e-15

Iteration 0: Residual norm = 6.938180388074179e-05
Iteration 1, Residual norm: 1.2669394829071503e-08
Iteration 2, Residual norm: 3.5709846880631195e-15

Iteration 0: Residual norm = 6.92320797226732e-05
Iteration 1, Residual norm: 1.2538136894843972e-08
Iteration 2, Residual norm: 3.565347998114606e-15

Iteration 0: Residual norm = 6.903878255603755e-05
Iteration 1, Residual norm: 1.2410504940427055e-08
Iteration 2, Residual norm: 3.611545580150237e-15

Iteration 0: Residual norm = 6.88204752219866e-05
Iteration 1, Residual norm: 1.2292555631285744e-08
Iteration 2, Residual norm: 3.692528953613214e-15

Iteration 0: Residual norm = 6.854840774368256e-05
Iteration 1, Residual norm: 1.2186091659982905e-08
Iteration 2, Residual norm: 3.782577938506541e-15

Iteration 0: Residual norm = 6.824330250622903e-05
Iteration 1, Residual norm: 1.2086771609373163e-08
Iteration 2, Residual norm: 3.859295840440123e-15

Iteration 0: Residual norm = 6.788307779338045e-05
Iteration 1, Residual norm: 1.198700006907481e-08
Iteration 2, Residual norm: 3.908717305955021e-15

Iteration 0: Residual norm = 6.749115635983317e-05
Iteration 1, Residual norm: 1.1881945276505056e-08
Iteration 2, Residual norm: 3.92878361173051e-15
Progress: 28%, Time: 2.80e+00, dt: 2.00e-02, iterations: 2

Iteration 0: Residual norm = 6.704773227000895e-05
Iteration 1, Residual norm: 1.177349939166208e-08
Iteration 2, Residual norm: 3.931048450859806e-15

Iteration 0: Residual norm = 6.657138018047554e-05
Iteration 1, Residual norm: 1.1669082918084235e-08
Iteration 2, Residual norm: 3.929645047943683e-15

Iteration 0: Residual norm = 6.603694821408848e-05
Iteration 1, Residual norm: 1.1577826930541345e-08
Iteration 2, Residual norm: 3.935875148706889e-15

Iteration 0: Residual norm = 6.545408688992745e-05
Iteration 1, Residual norm: 1.1508725316423817e-08
Iteration 2, Residual norm: 3.964095094739731e-15

Iteration 0: Residual norm = 6.479278180567211e-05
Iteration 1, Residual norm: 1.1471226027650499e-08
Iteration 2, Residual norm: 4.028962867832584e-15

Iteration 0: Residual norm = 6.405870945588877e-05
Iteration 1, Residual norm: 1.1474371105999595e-08
Iteration 2, Residual norm: 4.1387829232613474e-15

Iteration 0: Residual norm = 6.322528077533594e-05
Iteration 1, Residual norm: 1.1522886776988471e-08
Iteration 2, Residual norm: 4.287802060907093e-15

Iteration 0: Residual norm = 6.230564351472292e-05
Iteration 1, Residual norm: 1.1614189353681768e-08
Iteration 2, Residual norm: 4.4558037911653034e-15

Iteration 0: Residual norm = 6.128959582588687e-05
Iteration 1, Residual norm: 1.1740327433851802e-08
Iteration 2, Residual norm: 4.620277967266374e-15

Iteration 0: Residual norm = 6.020934625550379e-05
Iteration 1, Residual norm: 1.1893189960263453e-08
Iteration 2, Residual norm: 4.768411556200439e-15

Iteration 0: Residual norm = 5.907602745893896e-05
Iteration 1, Residual norm: 1.2068419541930132e-08
Iteration 2, Residual norm: 4.902423855054762e-15

Iteration 0: Residual norm = 5.793560866137032e-05
Iteration 1, Residual norm: 1.226619430913102e-08
Iteration 2, Residual norm: 5.037171165096119e-15

Iteration 0: Residual norm = 5.680471285027783e-05
Iteration 1, Residual norm: 1.2489997593763661e-08
Iteration 2, Residual norm: 5.203443794490019e-15

Iteration 0: Residual norm = 5.5721747784467246e-05
Iteration 1, Residual norm: 1.2744424707100369e-08
Iteration 2, Residual norm: 5.433309911300951e-15

Iteration 0: Residual norm = 5.468955381419923e-05
Iteration 1, Residual norm: 1.3032374558629778e-08
Iteration 2, Residual norm: 5.7384442701385195e-15

Iteration 0: Residual norm = 5.372803560953532e-05
Iteration 1, Residual norm: 1.3352473611265449e-08
Iteration 2, Residual norm: 6.102550023337233e-15

Iteration 0: Residual norm = 5.282579031908262e-05
Iteration 1, Residual norm: 1.3698596207977271e-08
Iteration 2, Residual norm: 6.4872357647770695e-15

Iteration 0: Residual norm = 5.1991523370486805e-05
Iteration 1, Residual norm: 1.4063385105280652e-08
Iteration 2, Residual norm: 6.857504716093108e-15

Iteration 0: Residual norm = 5.121016127798985e-05
Iteration 1, Residual norm: 1.4444811896385832e-08
Iteration 2, Residual norm: 7.193714832002346e-15

Iteration 0: Residual norm = 5.048847577886759e-05
Iteration 1, Residual norm: 1.4850156050694906e-08
Iteration 2, Residual norm: 7.512877183284109e-15

Iteration 0: Residual norm = 4.981364093036291e-05
Iteration 1, Residual norm: 1.52924808507755e-08
Iteration 2, Residual norm: 7.857397037780711e-15

Iteration 0: Residual norm = 4.919262714938868e-05
Iteration 1, Residual norm: 1.578318651917603e-08
Iteration 2, Residual norm: 8.295592155166668e-15

Iteration 0: Residual norm = 4.861459487333017e-05
Iteration 1, Residual norm: 1.6329154252356734e-08
Iteration 2, Residual norm: 8.898462265936301e-15

Iteration 0: Residual norm = 4.80854316534966e-05
Iteration 1, Residual norm: 1.6934828236121598e-08
Iteration 2, Residual norm: 9.673399747406891e-15

Iteration 0: Residual norm = 4.759531350455966e-05
Iteration 1, Residual norm: 1.7600731621620037e-08
Iteration 2, Residual norm: 1.0615736004401398e-14
Progress: 33%, Time: 3.30e+00, dt: 2.00e-02, iterations: 2

Iteration 0: Residual norm = 4.714862726091961e-05
Iteration 1, Residual norm: 1.8317943982557723e-08
Iteration 2, Residual norm: 1.1670072322423753e-14

Iteration 0: Residual norm = 4.673658236433166e-05
Iteration 1, Residual norm: 1.9070654955172844e-08
Iteration 2, Residual norm: 1.2775553997336885e-14

Iteration 0: Residual norm = 4.636216956834306e-05
Iteration 1, Residual norm: 1.9849492696348664e-08
Iteration 2, Residual norm: 1.3844250188416252e-14

Iteration 0: Residual norm = 4.601813695772888e-05
Iteration 1, Residual norm: 2.0659660338744657e-08
Iteration 2, Residual norm: 1.4811868058881695e-14

Iteration 0: Residual norm = 4.570753379476442e-05
Iteration 1, Residual norm: 2.1514387249190963e-08
Iteration 2, Residual norm: 1.576195889586029e-14

Iteration 0: Residual norm = 4.542711125823566e-05
Iteration 1, Residual norm: 2.2425767811684453e-08
Iteration 2, Residual norm: 1.6774755322816612e-14

Iteration 0: Residual norm = 4.518231230358035e-05
Iteration 1, Residual norm: 2.340539165870521e-08
Iteration 2, Residual norm: 1.8065125605424147e-14

Iteration 0: Residual norm = 4.497435996705607e-05
Iteration 1, Residual norm: 2.4468327304933075e-08
Iteration 2, Residual norm: 1.9847634434058103e-14

Iteration 0: Residual norm = 4.4809031429335396e-05
Iteration 1, Residual norm: 2.5627852023495214e-08
Iteration 2, Residual norm: 2.2170947972365172e-14

Iteration 0: Residual norm = 4.468856616051756e-05
Iteration 1, Residual norm: 2.6882328999084385e-08
Iteration 2, Residual norm: 2.49920565496448e-14

Iteration 0: Residual norm = 4.4616453017892047e-05
Iteration 1, Residual norm: 2.8224017978950974e-08
Iteration 2, Residual norm: 2.8073659371521233e-14

Iteration 0: Residual norm = 4.460026467464613e-05
Iteration 1, Residual norm: 2.9621834708640425e-08
Iteration 2, Residual norm: 3.1179043509026536e-14

Iteration 0: Residual norm = 4.464723716655334e-05
Iteration 1, Residual norm: 3.1050115017892364e-08

Postprocessing

[8]:
output_dir = "./output_navier_stokes"
os.makedirs(output_dir, exist_ok=True)

history = result.history
timesteps = history.t
velocity_history = history.q['1velocity']
pressure_history = history.q['2pressure']
temperature_history = history.q['3temperature']

# Export one VTK file for each time step
for i, t_val in enumerate(timesteps):
  # Export velocity and temperature
  point_data = {
      'velocity': jnp.pad(velocity_history[i], ((0, 0), (0, 1)), constant_values=0),
      'temperature': temperature_history[i],
  }
  meshio.Mesh(
      points=jnp.pad(coords_v, ((0, 0), (0, 1)), constant_values=0),
      cells={
          'triangle6': cells_v
      },
      point_data=point_data,
  ).write(f"{output_dir}/navier_stokes_t{i}.vtk")

  # Export pressure
  point_data = {
      'pressure': pressure_history[i],
  }
  meshio.Mesh(
      points=jnp.pad(coords_p, ((0, 0), (0, 1)), constant_values=0),
      cells={
          'triangle': cells_p
      },
      point_data=point_data,
  ).write(f"{output_dir}/navier_stokes_p_t{i}.vtk")