# Copyright (C) 2007 Murtazo Nazarov.
# Licensed under the GNU GPL Version 2.
#

name = "CNSResMomentum2D"
scalar = FiniteElement("Lagrange", "triangle", 1)
vector = VectorElement("Lagrange", "triangle", 1)
constant_scalar = FiniteElement("Discontinuous Lagrange", "triangle", 0)
constant_vector = VectorElement("Discontinuous Lagrange", "triangle", 0)


v    =  TestFunction(constant_vector)   # constant scalar test basis function
P    =  Function(scalar)                # pressure
u    =  Function(vector)                # velocity
m    =  Function(vector)                # momentum
m0   =  Function(vector)                # momentum from previous timestep


vol_inv = Function(constant_scalar)     # the inverse of volume of the element

k = Constant("triangle")

# the linear form of the momentum residual:
L = mult( 1/k * dot( m-m0, v) +                                                                                             
          0.5 * ((u[0] *  m[0]).dx(0) * v[0] + (u[1] *  m[0]).dx(1) * v[0]) +         
	  0.5 * ((u[0] *  m[1]).dx(0) * v[1] + (u[1] *  m[1]).dx(1) * v[1]) +                                               
          0.5 * ((u[0] * m0[0]).dx(0) * v[0] + (u[1] * m0[0]).dx(1) * v[0]) +                                               
          0.5 * ((u[0] * m0[1]).dx(0) * v[1] + (u[1] * m0[1]).dx(1) * v[1]) +                                               
          dot(grad(P), v), vol_inv) * dx     


#L = mult( 1/k * dot( m-m0, v) +
#          0.5 * (u[0] * m[0]).dx(0) * v[0] + (u[1] * m[0]).dx(1) * v[0] +
#          0.5 * (u[0] * m[1]).dx(0) * v[1] + (u[1] * m[1]).dx(1) * v[1] +
#          0.5 * (u[0] * m0[0]).dx(0) * v[0] + (u[1] * m0[0]).dx(1) * v[0] +
#          0.5 * (u[0] * m0[1]).dx(0) * v[1] + (u[1] * m0[1]).dx(1) * v[1] +
#          dot(grad(P), v), vol_inv) * dx

