This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Summation with dg

0 votes

Hi:
I am trying to solve next problem:

enter image description here

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
asked Feb 4, 2016 by jesus FEniCS Novice (300 points)

Try posing a more focussed question. You'll be more likely to get an answer.

Hi!
for the first summation I've written into the code
c * inner(hu, vu('-')) * dx
the other summations are similiar.
I think is solved my question.
Thanks

Please post you comment as an 'answer' to close off the question.

1 Answer

0 votes

Hi!
for the first summation I've written into the code

c * inner(hu, vu('-')) * dx

the other summations are similiar.
I think is solved my question.
Thanks

answered Feb 23, 2016 by jesus FEniCS Novice (300 points)
...