Replies: 2 comments
-
If you discretize the heat equation in space using FEM, you will get the system of ODEs: Then you can apply finite difference method in time using time step You can rearrange the equation to get a linear system for Then in code you implement matrices |
Beta Was this translation helpful? Give feedback.
-
Here are examples of solving the heat equation using Crank–Nicolson: These use a generalization of the Crank–Nicolson method called the θ-method which reduces to Crank–Nicolson for θ = ½. It's derived pretty much as by @kinnala (above) for the special case θ = 1; It also gives the explicit Euler method for θ = 0. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to simulate the temperature evolution in a cable due to the Joule effect. I already have a code that allows me to simulate conduction in a cable but not temporally. I've heard that one possible method is the Crank-Nicolson method. I've tried to look into it but I can't seem to understand how to apply this method to my code. Maybe there's an expert in this kind of simulation who will come across this message. Thanks in advance for the help!
from pathlib import Path
from typing import Optional
import numpy as np
from skfem import *
from skfem.helpers import dot, grad
from skfem.models.poisson import mass, unit_load
from skfem.io.json import from_file
joule_heating = 5.
heat_transfer_coefficient = 7.
thermal_conductivity = {'core': 101., 'annulus': 11.}
mesh = from_file(Path(file).parent / 'meshes' / 'disk.json')
radii = sorted([np.linalg.norm(mesh.p[:, mesh.t[:, s]], axis=0).max() for s in mesh.subdomains.values()])
@BilinearForm
def conduction(u, v, w):
return dot(w['conductivity'] * grad(u), grad(v))
convection = mass
element = ElementQuad1()
basis = Basis(mesh, element)
basis0 = basis.with_element(ElementQuad0())
conductivity = basis0.zeros()
for s in mesh.subdomains:
conductivity[basis0.get_dofs(elements=s)] = thermal_conductivity[s]
L = asm(conduction, basis, conductivity=basis0.interpolate(conductivity))
facet_basis = FacetBasis(mesh, element, facets=mesh.boundaries['perimeter'])
H = heat_transfer_coefficient * asm(convection, facet_basis)
core_basis = Basis(mesh, basis.elem, elements=mesh.subdomains['core'])
f = joule_heating * asm(unit_load, core_basis)
temperature = solve(L + H, f)
T0 = {
"skfem": (basis.probes(np.zeros((2, 1))) @ temperature)[0],
"exact": (
joule_heating
* radii[0] ** 2
/ 4
/ thermal_conductivity["core"]
* (
2 * thermal_conductivity["core"] / radii[1] / heat_transfer_coefficient
+ (
2
* thermal_conductivity["core"]
/ thermal_conductivity["annulus"]
* np.log(radii[1] / radii[0])
)
+ 1
)
)
}
if name == 'main':
I hope someone can explain to me how to make this simulation temporal. If anyone has an example, please don't hesitate to share.
Beta Was this translation helpful? Give feedback.
All reactions