parameters: (mu, beta, rho, mom, dim, dUdx)
return_statement: return tau_stress
docstring: Auxiliary function to calculate the viscous stress tensor for the given
      dynamic and bulk viscosity values
docstring_summary: Auxiliary function to calculate the viscous stress tensor for the given
      dynamic and bulk viscosity values
docstring_tokens: Auxiliary function to calculate the viscous stress tensor for the given dynamic and bulk viscosity values
function: def CalculateViscousStressTensor(mu, beta, rho, mom, dim, dUdx):
      """
      Auxiliary function to calculate the viscous stress tensor for the given
      dynamic and bulk viscosity values
      """
  
      # Calculate velocity divergence
      # Note that this is computed as div(mom/rho) = (dx(mom)*rho - mom*dx(rho))/rho**2
      div_vel = 0.0
      for d in range(dim):
          div_vel += (dUdx[d + 1, d] * rho - mom[d] * dUdx[0, d])
      div_vel /= rho**2
  
      # Calculate the viscous stress tensor
      # Note that the derivatives in here involve grad(mom/rho) = (dx(mom)*rho - mom*dx(rho))/rho**2
      tau_stress = defs.Matrix('tau_stress', dim, dim, real=True)
      for d1 in range(dim):
          for d2 in range(dim):
              dv1_dx2 = (dUdx[d1 + 1, d2] * rho - mom[d1] * dUdx[0, d2]) / rho**2
              dv2_dx1 = (dUdx[d2 + 1, d1] * rho - mom[d2] * dUdx[0, d1]) / rho**2
              tau_stress[d1, d2] = mu * (dv1_dx2 + dv2_dx1)
              if d1 == d2:
                  # Note that in here the second viscosity coefficient is computed
                  # as the bulk viscosity minus 2/3 of the dynamic one
                  tau_stress[d1, d2] += (beta - 2.0 * mu / 3.0) * div_vel
  
      return tau_stress
function_tokens: def CalculateViscousStressTensor ( mu , beta , rho , mom , dim , dUdx ) : # Calculate velocity divergence # Note that this is computed as div(mom/rho) = (dx(mom)*rho - mom*dx(rho))/rho**2 div_vel = 0.0 for d in range ( dim ) : div_vel += ( dUdx [ d + 1 , d ] * rho - mom [ d ] * dUdx [ 0 , d ] ) div_vel /= rho ** 2 # Calculate the viscous stress tensor # Note that the derivatives in here involve grad(mom/rho) = (dx(mom)*rho - mom*dx(rho))/rho**2 tau_stress = defs . Matrix ( 'tau_stress' , dim , dim , real = True ) for d1 in range ( dim ) : for d2 in range ( dim ) : dv1_dx2 = ( dUdx [ d1 + 1 , d2 ] * rho - mom [ d1 ] * dUdx [ 0 , d2 ] ) / rho ** 2 dv2_dx1 = ( dUdx [ d2 + 1 , d1 ] * rho - mom [ d2 ] * dUdx [ 0 , d1 ] ) / rho ** 2 tau_stress [ d1 , d2 ] = mu * ( dv1_dx2 + dv2_dx1 ) if d1 == d2 : # Note that in here the second viscosity coefficient is computed # as the bulk viscosity minus 2/3 of the dynamic one tau_stress [ d1 , d2 ] += ( beta - 2.0 * mu / 3.0 ) * div_vel return tau_stress