Material property depending on solution

Thanks ! it works perfectly ! here’s the MWE

from fenics import *

class CoeffClass(UserExpression):

    def __init__(self, temp, **kwargs):

        super().__init__(kwargs)

        self.temp = temp

    def eval(self, value, x):

        if x[0] > 0.5:

            value[0] = 2*self.temp(x)

        else:

            value[0] = 3*self.temp(x)

    def value_shape(self):

        return ()

nx = ny = 100

mesh = UnitSquareMesh(nx, ny)

n = FacetNormal(mesh)

V = FunctionSpace(mesh, 'P', 1)

D0 = FunctionSpace(mesh, 'DG', 0)

# Temperature

temp = Expression("2*x[0]*x[0] + t", degree=2, t=1)

D = CoeffClass(temp=temp, degree=1)

# Solution

u = interpolate(temp, V)

# Time stepping loop

for t in [1, 2, 3]:

    temp.t = t

    # Update coefficient D

    D.temp = temp

    # Compute flux

    print(assemble(D*dot(grad(u), n)*ds))
1 Like