# Copyright (c) 2005 Johan Hoffman (hoffman@cims.nyu.edu)
# Licensed under the GNU GPL Version 2
#
# Modified by Anders Logg 2006
#
# First added:  2005
# Last changed: 2006-03-28
#
# The continuity equation for the incompressible 
# Navier-Stokes equations using cG(1)cG(1)
#
# Compile this form with FFC: ffc FSIContinuity2D.form.
##########################################################

##########################################################

cell = "triangle"

scalar          = FiniteElement("Lagrange", cell, 1)

# Dimension of domain
d = scalar.cell_dimension()

vector          = VectorElement("Lagrange", cell, 1)
constant_scalar = FiniteElement("Discontinuous Lagrange", cell, 0)
constant_vector = VectorElement("Discontinuous Lagrange", cell, 0, d)

#P0 = VectorElement("Discontinuous Lagrange", cell, 0)
#mymean = Projection(P0)


##########################################################

q  = TestFunction(scalar)      # test basis function
P  = TrialFunction(scalar)     # trial basis function
uc = Function(vector)          # linearized velocity
um = Function(constant_vector) # cell mean value of linearized velocity
f  = Function(vector)          # force term
phi= Function(constant_scalar) # marker function

delta1 = Function(constant_scalar) # stabilization parameter

##########################################################

i0 = Index() # index for tensor notation
i1 = Index() # index for tensor notation

##########################################################

eps = 1.0e-2 - 1.0e-3
mma = eps*P*q*dx       # Allows stable homogeneous Neumann bc's 

##########################################################

a = delta1*dot(grad(q), grad(P))*dx + mma
L = delta1*dot(grad(q), f)*dx - q*uc[i0].dx(i0)*dx - delta1*q.dx(i0)*um[i1]*uc[i0].dx(i1)*dx 	 
