← Back to team overview

dolfin team mailing list archive

[Question #104855]: piecewise defined function

 

New question #104855 on DOLFIN:
https://answers.launchpad.net/dolfin/+question/104855

Hi! 
My piecewise defined function alpha (see below) just returns zero. 
What is wrong? How to define it instead?

Best, Achim

# set parameters
alpha1 = 0.2; alpha2 = 0.8

# create mesh and finite element
mesh = UnitSquare(20, 20)
V = FunctionSpace(mesh, "CG", 1)

# define trial & testfunctions
u_trial = TrialFunction(V); phi = TestFunction(V)

# define diffusion parameter
class alpha(Function):
    def __init__(self, V):
        Function.__init__(self, V)
    def eval(self, v, x):
        v[0] = alpha1
        if x[0] > 0.5: v[0] = alpha2
d = alpha(V)
print " |d| = %g" %(d.vector().norm("l2"))


-- 
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.