Hi,
for my time dependent heat convection-diffusion equation I have some material data from files: density, conductivity and specific heat. All depend on the current local temperature, i.e. local solution of the PDE. I tried the following, that works well with constant material data (as Constant()
or Expression()
):
...
# material data from file, int(temperature) == index
cpX = np.genfromtxt('analyse/cpX.ana')[:,1]
rhoX = np.genfromtxt('analyse/densityX.ana')[:,1]
lmbdaX = np.genfromtxt('analyse/conductX.ana')[:,1]
...
class userMaterial(UserExpression):
def __init__(self, temp, valArray, **kwargs):
super().__init__(kwargs)
self.temp = temp
self.valArray = valArray
def eval(self, value, x):
intT = max(1,min(int(self.temp(x)),1600))
value[0] = self.valArray[intT]
def value_shape(self):
return ()
...
U = Function(V)
U_data = np.array(U.vector())*0+100
U.vector().set_local(U_data)
lambdaU = userMaterial(temp=U,valArray=lmbdaX,degree=0)
rhoU = userMaterial(temp=U,valArray=rhoX,degree=0)
cpU = userMaterial(temp=U,valArray=cpX,degree=0)
...
E_thd = lambdaU/(rhoU*cpU) # thermal diffusivity
E_rcp = 1.0/(rhoU*cpU) # 1 / rho * cp
...
for i in bcond:
if 'Dirichlet' in bcond[i]:
bc = DirichletBC(V,bcond[i]['Dirichlet'],boundary_markers,i)
bcs.append(bc)
elif 'Neumann' in bcond[i]:
if bcond[i]['Neumann'] != 0:
g = bcond[i]['Neumann']
integrals_N.append(E_dt*E_rcp*g*v*ds(i))
elif 'Robin' in bcond[i]:
r,s = bcond[i]['Robin']
integrals_R_a.append(E_dt*E_rcp*r*u*v*ds(i))
integrals_R_L.append(E_dt*E_rcp*r*s*v*ds(i))
...
#===========================================================
# PDE
#
# rho*cp*grad(T,t)+rho*cp*w*grad(T,x)=div(lambda*grad(T,x),x)
#
#===========================================================
# weak problem formulation
F = u*v*dx + E_dt*E_thd*dot(grad(u),grad(v))*dx - u_n*v*dx \
+ E_dt*inner(E_w,grad(u))*v*dx \
+ sum(integrals_R_a) + sum(integrals_N) - sum(integrals_R_L)
a, L = lhs(F), rhs(F)
...
t = 0
while t < tFinal:
# Update current time
t += dt
print(t,"s /",tFinal,'s')
# Compute solution
solve(a == L, U, bcs)
# Save to file and plot solution
vtkfile << (U, t)
# plot(u)
# Update previous solution
u_n.assign(U)
# update material data
lambdaU.temp = U
rhoU.temp = U
cpU.temp = U
...
Unfortunately, this doesn’t work and is also extremely slow.
How can measured, temperature dependend table data be applied to the PDE?