### implementing different coefficients along x and y coordinates

59

views

0

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}$∂

For $\lambda_1=\lambda_2=1$λ

$\frac{\partial u}{\partial t}=\lambda_1\frac{\partial^2u}{\partial x^2}+\lambda_2\frac{\partial^2u}{\partial y^2}$∂

`u`∂`t`=λ_{1}∂^{2}`u`∂`x`^{2}+λ_{2}∂^{2}`u`∂`y`^{2}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

### 1 Answer

2

Consider the following FE discretisation of Poisson's equation, $\nabla\cdot D\nabla u=1$∇·

`D`∇`u`=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)))
a = dot(D*grad(u), grad(v))*dx
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()
```

Please login to add an answer/comment or follow this question.