Hi:
I am trying to solve next problem:
in fact I add the equations in unique equation. I don't get the 4 summations following the idea come from previous question Using non-integral in variational formulation
I introduce c * inner(I, V) * dx where c = Constant(1.0 / assemble(1.0 * dx(mesh))).
How do I write the summations into the code?
Adjoint the code. I'm sorry the length one.
Thanks.
Jesus
# DG 1D using Cockburn
from dolfin import *
import sys, numpy
mesh = UnitIntervalMesh(4) # Define function spaces
V0 = FunctionSpace(mesh, "DG", 2)
W = MixedFunctionSpace([V0, V0])
tol = DOLFIN_EPS # Define boundary conditions
def left_boundary(x, on_boundary):
return on_boundary and abs(x[0]) < tol
def right_boundary(x, on_boundary):
return on_boundary and abs(x[0]-1.0) < tol
Gamma_0 = DirichletBC(W.sub(0), Constant(2.0), left_boundary)
Gamma_1 = DirichletBC(W.sub(0), Constant(1.0), right_boundary)
bcs = [Gamma_0, Gamma_1]
(u,q) = TrialFunctions(W)
(vu,vq) = TestFunctions(W)
w = Function(W)
u, q = (w[0],w[1])
alfa = 0.00001 # Define parameters
beta = alfa
auxv = as_vector((1.0, 1.0))
h = Expression('2.0 -x[0] ')
h2 = Expression('(2.0 -x[0])*(2.0 -x[0]) ')
h3 = Expression('(2.0 -x[0])*(2.0 -x[0])*(2.0 -x[0])')
hdx = Expression('-1.0 ')
auxu = alfa + beta*u
aux1 = sqrt(h*(alfa + beta*u))
aux2 = sqrt(h*alfa)
hu = u*(1.0-alfa) - beta*u*u - q*aux1
hq = (-2.0/(3*sqrt(beta*h)))*(aux1*aux1*aux1 - aux2*aux2*aux2)
c = Constant(1.0 / assemble(1.0 * dx(mesh)))
f = Constant(0.0)
L = f*vq*dx
a = -inner(hu,vu.dx(0))*dx
b = inner(q,vq)*dx - inner(hq,vq.dx(0))*dx
F = a + b - L
J = derivative(F,w)
problem = NonlinearVariationalProblem(F,w,bcs=bcs,J=J)
solver = NonlinearVariationalSolver(problem)
solver.solve()
(u,q) = w.leaf_node().split() # extract solutions