### implementing different coefficients along x and y coordinates

59
views
0
8 weeks ago by
Sorry for the question if it is a simple one, i am new. How do we implement the following heat equation in fenics?
$\frac{\partial u}{\partial t}=\lambda_1\frac{\partial^2u}{\partial x^2}+\lambda_2\frac{\partial^2u}{\partial y^2}$ut =λ12ux2 +λ22uy2
For  $\lambda_1=\lambda_2=1$λ1=λ2=1  there is good explanation in fenics manual. But if the coefficients are different and not equal to one how do we implement this. I could not find related information on google and fenics manual.
Community: FEniCS Project

2
8 weeks ago by
Consider the following FE discretisation of Poisson's equation, $\nabla\cdot D\nabla u=1$·Du=1 , where the diffusion tensor  $D=\left(\left(\lambda_1,0\right),\left(0,\lambda_2\right)\right)$D=((λ1,0),(0,λ2))

Constant could also be an Expression or something custom made using as_matrix

from dolfin import *

mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, "CG", 1)
u, v = TrialFunction(V), TestFunction(V)

lmbda1 = 1.0
lmbda2 = 100.0
D = Constant(((lmbda1, 0.0),
(0.0, lmbda2)))

L = Constant(1.0)*v*dx

bcs = [DirichletBC(V, Constant(0.0), "on_boundary")]

soln = Function(V)
solve(a == L, soln, bcs)

import matplotlib.pyplot as plt
plot(soln)
plt.show()​