Exemplo n.º 1
0
The novelty here is that the temperature is defined as a finite element function
throughout the mesh (:math:`r < b`) but only solved on a subdomain.

"""
from skfem import *
from skfem.models.poisson import laplace, unit_load

import numpy as np

from docs.examples.ex17 import mesh, basis, radii,\
    joule_heating, thermal_conductivity

annulus = np.unique(basis.element_dofs[:, mesh.subdomains['annulus']])
temperature = np.zeros(basis.N)
core = basis.complement_dofs(annulus)
core_basis = InteriorBasis(mesh, basis.elem, elements=mesh.subdomains['core'])
L = asm(laplace, core_basis)
f = asm(unit_load, core_basis)
temperature = solve(
    *condense(thermal_conductivity['core'] * L, joule_heating * f, D=annulus))

if __name__ == '__main__':
    from os.path import splitext
    from sys import argv
    from skfem.visuals.matplotlib import draw, plot

    T0 = {
        'skfem': basis.interpolator(temperature)(np.zeros((2, 1)))[0],
        'exact': joule_heating * radii[0]**2 / 4 / thermal_conductivity['core']
    }
Exemplo n.º 2
0
from skfem import *
from skfem.models.poisson import laplace, unit_load

import numpy as np

from docs.examples.ex17 import mesh, basis, radii,\
    joule_heating, thermal_conductivity

insulation = np.unique(basis.element_dofs[:, mesh.subdomains['insulation']])
temperature = np.zeros(basis.N)
wire = basis.complement_dofs(insulation)
wire_basis = InteriorBasis(mesh, basis.elem, elements=mesh.subdomains['wire'])
L = asm(laplace, wire_basis)
f = asm(unit_load, wire_basis)
temperature = solve(*condense(
    thermal_conductivity['wire'] * L, joule_heating * f, D=insulation))

if __name__ == '__main__':

    from os.path import splitext
    from sys import argv

    T0 = {
        'skfem': basis.interpolator(temperature)(np.zeros((2, 1)))[0],
        'exact': joule_heating * radii[0]**2 / 4 / thermal_conductivity['wire']
    }
    print('Central temperature:', T0)

    mesh.plot(temperature[basis.nodal_dofs.flatten()], colorbar=True)
    mesh.savefig(splitext(argv[0])[0] + '_solution.png')