project abs(function) get weird result


219
views
1
5 months ago by
Hi:

I am getting a weird result by project abs(form) to function space, take below examples for example:
from dolfin import *

mesh=UnitSquareMesh(5,5)

V=FunctionSpace(mesh, "Lagrange",2)

a_=Function(V)

a_.vector()[:]=1
a_.vector()[25]=-1

b=abs(a_)

b_=project(b,V)

a_.vector().array()
array([ 1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
        1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1., -1.,
        1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
        1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
        1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
        1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
        1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
        1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
        1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
        1.,  1.,  1.,  1.])
b_.vector().array()​
array([ 1.00003235,  0.99998718,  1.0000411 ,  1.0002116 ,  1.00003093,
        1.00000102,  0.99988153,  1.00039026,  1.00026108,  1.0005321 ,
        1.00020869,  0.99988144,  1.0000015 ,  0.99999015,  1.00301379,
        0.99883067,  1.00568495,  1.00705697,  1.00114053,  0.99883045,
        1.00038962,  1.00002745,  1.00002479,  0.99999212,  1.00001519,
       -0.87478348,  1.0070579 ,  1.0070586 ,  1.00705765,  1.00002632,
        1.00301083,  0.99999615,  1.000533  ,  1.00037788,  1.00568149,
        0.9988333 ,  1.00000961,  1.00000438,  1.0000133 ,  0.99999845,
        1.00301099,  1.00568216,  0.99883188,  1.00053096,  1.00010755,
        0.9999761 ,  0.99990562,  1.00013051,  1.00300798,  0.99883301,
        0.99883352,  1.00053459,  1.00111251,  1.00037708,  0.99990574,
        0.99999719,  1.00000973,  1.00000658,  1.00038587,  1.00003222,
        0.99999616,  1.00002952,  0.99999703,  0.99997599,  1.00001273,
        1.00111868,  1.00037582,  0.99990147,  0.99991235,  1.00010475,
        1.00002319,  1.00000486,  0.99999651,  0.99999511,  0.99999542,
        1.00001765,  1.00000682,  0.9999991 ,  1.00000071,  1.00020489,
        1.00013493,  0.99995206,  1.00000513,  1.00000076,  1.00000761,
        0.99999949,  1.00010857,  0.9999957 ,  0.99998809,  1.000004  ,
        1.00001404,  1.00000791,  0.99999719,  1.00000102,  1.00000026,
        1.00000043,  1.00005611,  1.00000984,  0.99999483,  1.00000355,
        1.00000792,  0.99999977,  0.99999951,  1.00000069,  1.00000247,
        1.00000002,  1.00000081,  1.00000012,  1.00000016,  1.00000648,
        0.99999977,  1.00000002,  1.0000013 ,  1.00000052,  0.99999989,
        1.0000004 ,  1.00000049,  0.99999996,  1.00000004,  1.00000006,
        1.00000012])

It seems the function b, which is the supposed to be abs(a), but donot, I am using dolfin 2016.1

Yuxiang

Community: FEniCS Project

1 Answer


0
5 months ago by
Your vector a_ will oscillate between -1 and 1 and its abs is not uniformly 1. It will be 1 only at the nodes of your lagrange polynomials. You should plot a_ and see for yourself.

So you cannot expect that projection of abs(a_) will be unity everywhere.

If you interpolate, you will probably get unity everywhere, since only the nodal values will be used to get b.
But if a_ is set to -1 and -10 somewhere, project(abs(a_),V) will get 1 and 10 by a_.vector().array()

by saying interpolate, you mean to interpolate(abs(a_), V)? The interpolate function do not accept ufl form as input, however

Actually the final question I am asking will (a+abs(a))/2 get the 0 if some part <0 and original value if <=0 if a is a form, though project((a_+abs(a_))/2, V) does not show
written 5 months ago by Yuxiang Lin  
It seems I would need to project to DG space to get the result I want
written 5 months ago by Yuxiang Lin  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »