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

How can I solve two problems parallelly with fenics which is relative with DG ?

0 votes

The code is like this:

    from dolfin import *
    import numpy as np
    from mpi4py import MPI

    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()

    mesh = UnitSquareMesh(mpi_comm_self(),16, 16)
    V = FunctionSpace(mesh, "DG", 1)

    # Define test and trial functions
    v = TestFunction(V)
    u = TrialFunction(V)

    # Define normal component, mesh size and right-hand side
    n = FacetNormal(mesh)
    h = CellSize(mesh)
    h_avg = (h('+') + h('-'))/2


    if(rank==0):
        g = Expression('sin(pi*x[0])*sin(pi*x[1])',pi = np.pi )
        f = Expression('2*pi*pi*sin(pi*x[0])*sin(pi*x[1])',pi = np.pi)
    if(rank==1):
        g = Expression('exp(-ll*(x[0]-0.5) )+exp(ll*(x[0]-0.5))',ll=20.0 )
        f = Expression('-ll*ll*exp(-ll*(x[0]-0.5))-ll*ll*exp(ll*(x[0]-0.5))',ll=20.0)

    alpha = 5.0
    gamma = alpha*2


    # Define variational problem
The code is as following:

    a = dot(grad(v), grad(u))*dx  \
        - dot(avg(grad(v)), jump(u, n))*dS \
        - dot(jump(v, n), avg(grad(u)))*dS \
        + alpha/h_avg*dot(jump(v, n), jump(u, n))*dS \
        - dot(grad(v), u*n)*ds \
        - dot(v*n, grad(u))*ds \
        + gamma/h*v*u*ds
    L = v*f*dx + gamma/h*v*g*ds - dot(grad(v), g*n)*ds 

    # Compute solution

    A = assemble(a)
    b = assemble(L)

but when I run : mpirun -np 2 python myprogram.py
there was wrong , I don't know why ? Thanks!

asked Nov 25, 2014 by motianlunfenics FEniCS Novice (310 points)

What exactly is wrong? Did you check that the solutions are right in serial?

1 Answer

0 votes

If you are not using the development version of dolfin, it is normal: see http://fenicsproject.org/qa/4078/dg-solve-in-parallel

answered Nov 25, 2014 by V_L FEniCS User (4,440 points)

I know the topic link you giving me ,but I think there is some differences between them! Thanks!

...