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

Translate SubDomains to Expressions

0 votes

Hi
I'd like to use something containing subdomain number as a variable coefficient. First I've tried to return the number itself in an Expression:

subdomains = MeshFunction("size_t", mesh, "mesh_physical_region.xml")
class subExpression(Expression):  
    def __init__(self, subdomains):
        Expression.__init__(self)
        self.subdomains = subdomains
    def eval(self, values, cell):
        values [0] = self.subdomains.array()[cell.global_index()]

and get following error: 'numpy.ndarray' object has no attribute 'global_index'.
I don't know how to find cell index properly (what's the structure of the 'cell' object).

closed with the note: answer found
asked Jan 26, 2016 by bp FEniCS Novice (520 points)
closed Jan 26, 2016 by bp

After printing 'cell' I found that it returns an array of coordinates (perhaps the middle?). So I need to evaluate Mesh function at a certain point. I want to avoid premature projection to DG, because subdomains arrangement is rather complicated (hard to map to dofs).

Solution is trivial: use ufl_cell instead of cell in the constructor.

I also encountered this problem,and wantto use something containing subdomain number as a variable coefficient. how can i do?
subdomains = MeshFunction("size_t", mesh, "subdomain.xml"),and how to set value[0];

...