How to use a class to return  vectors and project them on finite element space


145
views
0
6 months ago by
CHEN  
Hello everyone.I want to use a class to return  vectors and project them on finite element space.I edit the following code:
mx=1
my=1
mz=1
mym_value=np.zeros((linenumber,3))
mym_coords=np.zeros((linenumber,3)
class MyM(Expression):
    def set_M(self,mx,my,mz):
        self.mx=mx,self.my,self.mz= mx,my,mz
    def eval(self,value,x):
        tol = 0.01
        for i in range(0,linenumber-1):
            if(sqrt(np.inner(x-mym_coords[i,0:3],x-mym_coords[i,0:3]))<=tol):
                value=mym_value[i,0:3]
                

M=MyM(degree=1)
M.set_M(1.,1.,1.)
print M(0,0,0)
m_proj=project(M,VV)
​

But what it returns is not a vector.how should I change my codes?

Community: FEniCS Project

1 Answer


2
6 months ago by
I think you also need to define the value_shape() method:

class MyM(Expression):
    def set_M(self,mx,my,mz):
        self.mx=mx,self.my,self.mz= mx,my,mz
    def eval(self,value,x):
        tol = 0.01
        for i in range(0,linenumber-1):
            if(sqrt(np.inner(x-mym_coords[i,0:3],x-mym_coords[i,0:3]))<=tol):
                value=mym_value[i,0:3]

    ################################
    def value_shape(self):
        return (3,)
    ################################​
Please login to add an answer/comment or follow this question.

Similar posts:
Search »