|
|
@ -0,0 +1,191 @@ |
|
|
|
|
|
|
|
|
|
|
|
```python |
|
|
|
#1 Loading functions and modules |
|
|
|
from fenics import * |
|
|
|
import matplotlib.pyplot as plt |
|
|
|
T = 2.0 |
|
|
|
num_steps = 20 |
|
|
|
dt = T/num_steps |
|
|
|
rho = 7500 |
|
|
|
Cp = 500 |
|
|
|
k = 50 |
|
|
|
alpha = k/(rho*Cp) |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
```python |
|
|
|
#2 Create mesh and define function space |
|
|
|
nx = 0.008 |
|
|
|
ny = 0.003 |
|
|
|
mesh = RectangleMesh(Point(0,0),Point(nx,ny),30, 30,'left') |
|
|
|
V = FunctionSpace(mesh, 'Lagrange', 1) #Lagrange are triangular elements |
|
|
|
plot(mesh) |
|
|
|
plt.show() |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
![png](output_1_0.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```python |
|
|
|
# Boundary conditions |
|
|
|
u0 = Constant(100) |
|
|
|
def boundary(x, on_boundary): |
|
|
|
return on_boundary |
|
|
|
|
|
|
|
bc = DirichletBC(V,u0, boundary) |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
```python |
|
|
|
u_n = project(1, V) |
|
|
|
u = TrialFunction(V) |
|
|
|
v = TestFunction(V) |
|
|
|
f = Constant(0.0) |
|
|
|
F = u*v*dx + alpha*dt*dot(grad(u), grad(v))*dx-u_n*v*dx |
|
|
|
a, L = lhs(F), rhs(F) |
|
|
|
``` |
|
|
|
|
|
|
|
Calling FFC just-in-time (JIT) compiler, this may take some time. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```python |
|
|
|
u = Function(V) |
|
|
|
t = 0 |
|
|
|
for n in range(num_steps): |
|
|
|
t += dt |
|
|
|
#u0.t = t |
|
|
|
solve(a == L, u, bc) |
|
|
|
c = plot(u,) |
|
|
|
plt.colorbar(c) |
|
|
|
plt.show() |
|
|
|
u_n.assign(u) |
|
|
|
``` |
|
|
|
|
|
|
|
Calling FFC just-in-time (JIT) compiler, this may take some time. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_1.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_2.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_3.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_4.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_5.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_6.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_7.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_8.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_9.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_10.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_11.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_12.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_13.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_14.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_15.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_16.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_17.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_18.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_19.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![png](output_4_20.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```python |
|
|
|
1E-7 |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1e-07 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```python |
|
|
|
1e2 |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100.0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```python |
|
|
|
1E-7+1e2 |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100.0000001 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```python |
|
|
|
|
|
|
|
``` |