View
216
Download
0
Category
Preview:
Citation preview
Introducción al Método de Elemento
Finito en Mathematica
José Luis Gómez Muñoz
Departamento de Física y Matemáticas
Campus Estado de México
Instituto Tecnológico y de Estudios Superiores de Monterrey
Julio 2012
Printed by Mathematica for Students
1. Ejemplo del método de Bubnov-Galerkin
Basado en el trabajo de John H. Mathews
http://math.fullerton.edu/mathews/n2003/GalerkinMod.html
Adaptado por José Luis Gómez Muñoz
http://homepage.cem.itesm.mx/lgomez/
ã Se va a calcular una solución aproximada a una ecuación diferencial ordinaria, lineal e inhomogénea,
-d
dxIpHxL d
dxyHxLM + qHxL yHxL= f HxL, con las condiciones de frontera yHaL= ya, yHbL = yb, como se
muestra a continuación :
Clear@x, y, p, q, f, a, bD;
p@x_D := x2;
q@x_D := 30;
f@x_D := −14 x;
a = 0;
b = 1;
ya = 0;
yb = 0.5;
Print@"−∂xHp@xD ∂xy@xDL+q@xD∗y@xD�f@xD"D;Print@−∂xHp@xD ∂xy@xDL + q@xD ∗ y@xD � f@xDD;Print@y@aD � yaD;Print@y@bD � ybD;
−∂xHp@xD ∂xy@xDL+q@xD∗y@xD�f@xD30 y@xD − 2 x y′@xD − x2 y′′@xD � −14 x
y@0D � 0
y@1D � 0.5
2 FEMcurso.nb
Printed by Mathematica for Students
ã La solución aproximada FHxL será una combinación lineal de ciertas funciones linealmente independientes, llamadas funciones base: FHxL= f0HxL +⁄j=1
n c j f jHxL. Cada función base f jHxL cumple
con las condiciones de frontera f jHaL= 0, f jHbL = 0, excepto f0HxL, que cumple las condiciones de
frontera del problema f0HaL= ya, f0HbL= yb.
Clear@n, φ, x, jD;
φ0@x_D := ya +yb − ya
b − aHx − aL;
n = 3;
φ1@x_D := Hx − aL ∗ Hx − bL;φ2@x_D := Hx − aL2 ∗ Hx − bL;φ3@x_D := Hx − aL2 ∗ Hx − bL2;
funciones = TableAφj@xD, 8j, 0, n<E;Plot@funciones, 8x, a, b<, PlotLabel → "Funciones base", PlotRange → AllD
0.2 0.4 0.6 0.8 1.0
-0.2
-0.1
0.1
0.2
0.3
0.4
0.5
Funciones base
ã La solución aproximada tendrá la forma FHxL = f0HxL +⁄j=1n c j f jHxL. El objetivo será encontrar los
coeficientes c j que den la mejor aproximación a la solución de la ecuación diferencial:
Clear@Φ, cD;
Φ@x_D := φ0@xD + ‚j=1
n
cj ∗ φj@xD;
Print@"Forma de la aproximación a la solución:"DPrint@"Φ@xD=", Φ@xDD
FEMcurso.nb 3
Printed by Mathematica for Students
Forma de la aproximación a la solución:
Φ@xD=0.5 x + H−1 + xL x c1 + H−1 + xL x2 c2 + H−1 + xL2 x2 c3
ã La ecuación diferencial puede escribirse de la forma:-
d
dxIpHxL d
dxyHxLM + qHxL yHxL- f HxL= 0
Si reemplazamos la solución aproximada FHxL en lugar de la solución exacta yHxL en el lado izquierdo de la ecuación anterior, el resultado ya no será exactamente cero. En su lugar obtendremos una función conocida como residuo, rHxL. En otras palabras, si el residuo rHxL, mostrado abajo, fuera cero, en ese caso la solución aproximada sería la solución exacta:-
d
dxIpHxL d
dxFHxLM + qHxLFHxL - f HxL= rHxL
Abajo se puede ver la expresión para el residuo en este ejemplo:
r@x_D := −∂xHp@xD ∂xΦ@xDL + q@xD ∗ Φ@xD − f@xD;
Print@"Residuo de la aproximación:"D;Print@"r@xD=", r@xDD
Residuo de la aproximación:
r@xD=14 x − x2 I2 c1 + 2 H−1 + xL c2 + 4 x c2 + 2 H−1 + xL2 c3 + 8 H−1 + xL x c3 + 2 x2 c3M −
2 x I0.5 + H−1 + xL c1 + x c1 + 2 H−1 + xL x c2 + x2 c2 + 2 H−1 + xL2 x c3 + 2 H−1 + xL x2 c3M +
30 I0.5 x + H−1 + xL x c1 + H−1 + xL x2 c2 + H−1 + xL2 x2 c3M
ã El método de Bubnov-Galerkin consiste en encontrar la combinación lineal FHxL = f0HxL +⁄j=1n c j f jHxL
cuyo residuo rHxL tenga componente igual a cero en el subespacio generado por las funciones base 9f j= j=1
n (sin incluir f0). Esto significa que el producto punto del residuo por cada función base debe ser
cero, Ÿa
bf jHxL rHxL‚x ä 0. Cada uno de estos productos punto igualados a cero genera una ecuación
cuyas incognitas son los coeficientes c j , como se muestra a continuación. Nótese que no se incluye el
producto punto con f0, dado que ya se tomó c0 = 1 para cumplir con las condiciones de frontera:
ecuaciones = TableB‡a
b
φj@xD ∗ r@xD x � 0, 8j, 1, n<F;
Print@"Galerkin: residuo ortogonal a funciones base"D;TableForm@ecuacionesD
Galerkin: residuo ortogonal a funciones base
−2.33333 + 1.13333 c1 + 0.6 c2 − 0.238095 c3 � 0
−1.4 + 0.6 c1 + 0.371429 c2 − 0.121429 c3 � 0
0.466667 − 0.238095 c1 − 0.121429 c2 + 0.0539683 c3 � 0
4 FEMcurso.nb
Printed by Mathematica for Students
ã A continuación se muestra el sistema de ecuaciones en forma matricial:
parametros = TableAcj, 8j, 1, n<E;
8v, m< = N@ CoefficientArrays@ecuaciones, parametrosD D;
Print@MatrixForm@mD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@−vDD
1.13333 0.6 −0.238095
0.6 0.371429 −0.121429
−0.238095 −0.121429 0.0539683
.
c1c2c3
==
2.33333
1.4
−0.466667
ã Como ya tenemos la matriz y el vector del sistema lineal, podemos obtener la solución usando el comando LinearSolve[] de Mathematica:
LinearSolve@m, −vD81.11225, 2.83562, 2.64006<
ã Sin embargo el comando NSolve proporciona la misma respuesta en un formato más útil para ser usado después en este documento:
soluciones = NSolve@ecuaciones, parametrosD88c1 → 1.11225, c2 → 2.83562, c3 → 2.64006<<
ã La solución aproximada se obtiene reemplazando los coeficientes c j en la expresión
FHxL = f0HxL +⁄j=1n c j f jHxL. Abajo se le llama gHxL a la solución aproximada que se obtiene por este
procedimiento:
g@x_D := ReplaceAll@Φ@xD, soluciones@@1DD D;
Print@"Solución aproximada por el método de Galerkin: "D;Print@"g@xD=", g@xDD
Solución aproximada por el método de Galerkin:
g@xD=0.5 x + 1.11225 H−1 + xL x + 2.83562 H−1 + xL x2 + 2.64006 H−1 + xL2 x2
FEMcurso.nb 5
Printed by Mathematica for Students
ã Ésta es la gráfica de la solución aproximada con el método de Bubnov-Galerkin:
Plot@g@xD, 8x, a, b<,PlotLabel → "Solución aproximada por el método de Galerkin"D
0.2 0.4 0.6 0.8 1.0
-0.2
-0.1
0.1
0.2
0.3
Solución aproximada por el método de Galerkin
ã A continuación se muestra la gráfica de la solución analítica exacta, obtenida con el comando DSolve:
solexacta =
DSolve@8−∂xHp@xD ∂xy@xDL + q@xD ∗ y@xD � f@xD, y@aD � ya, y@bD � yb<, y@xD, xD;
exacta@x_D := Evaluate@ReplaceAll@y@xD, solexacta@@1DD D D;
Plot@exacta@xD, 8x, a, b<, PlotLabel → "Solución analítica exacta"D
0.2 0.4 0.6 0.8 1.0
-0.2
-0.1
0.1
0.2
0.3
Solución analítica exacta
6 FEMcurso.nb
Printed by Mathematica for Students
ã A continuación se muestra la gráfica del error de la aproximación de Bubnov-Galerkin en este ejemplo:
Plot@exacta@xD − g@xD, 8x, a, b<, PlotLabel → "Error = Analítica−Bubnov−Galerkin"D
0.2 0.4 0.6 0.8 1.0
-0.002
-0.001
0.001
0.002
0.003
0.004
Error = Analítica-Bubnov-Galerkin
ã Referencias
Basado en el trabajo de John H. Mathews
http://math.fullerton.edu/mathews/n2003/GalerkinMod.html
Adaptado por José Luis Gómez Muñoz
http://homepage.cem.itesm.mx/lgomez/
FEMcurso.nb 7
Printed by Mathematica for Students
2. Ejemplo del método de Bubnov-Galerkin con funciones base del tipo usadas en Elemento Finito (funciones seccionadas de soporte local)
Basado en el trabajo de John H. Mathews
http://math.fullerton.edu/mathews/n2003/GalerkinMod.html
también en la sección 11.5 “El método de Rayleigh-Ritz” del libro de Richard L. Burden y J. Douglas Faires,
“Análisis numérico” 9a. edición, editorial Cengage, págs 696-711
y finalmente también en la sección 6.2 “Galerkin’s method with piecewise polynomials” del libro de Kenneth
Eriksson, D. Estep, P. Hansbo & C. Johnson, “Computational Differential Equations” Volumen 1, Cambridge
University Press, 1997.
Adaptado por José Luis Gómez Muñoz
http://homepage.cem.itesm.mx/lgomez/
ã Se va a calcular una solución aproximada a una ecuación diferencial ordinaria, lineal e inhomogénea,
-d
dxIpHxL d
dxyHxLM + qHxL yHxL= f HxL, con las condiciones de frontera yHaL= ya, yHbL = yb, como se
muestra a continuación :
Clear@x, y, p, q, f, a, bD;
p@x_D := x2;
q@x_D := 30;
f@x_D := −14 x;
a = 0;
b = 1;
ya = 0;
yb = 0.5;
Print@"−∂xHp@xD ∂xy@xDL+q@xD∗y@xD�f@xD → ",
−∂xHp@xD ∂xy@xDL + q@xD ∗ y@xD � f@xDD;Print@y@aD � yaD;Print@y@bD � ybD;
−∂xHp@xD ∂xy@xDL+q@xD∗y@xD�f@xD → 30 y@xD − 2 x y′@xD − x2 y′′@xD � −14 x
y@0D � 0
y@1D � 0.5
8 FEMcurso.nb
Printed by Mathematica for Students
ã La solución aproximada FHxL será una combinación lineal de ciertas funciones linealmente independientes, llamadas funciones base: FHxL=⁄j=1
n c j f jHxL. Las funciones base f jHxL usadas en el
método de Elemento Finito tienen soporte local, lo que quiere decir que cada una es distinta de cero sólo en una pequeña parte del dominio:
Clear@n, h, φ, x, jD;
n = 5;
h =b − a
n − 1;
DoB
φj@x_D := EvaluateB0 0 < x ≤ h ∗ Hj − 2Lx−h∗Hj−2L
hh ∗ Hj − 2L < x ≤ h ∗ Hj − 1L
h∗j−x
hh ∗ Hj − 1L < x ≤ h ∗ j
0 h ∗ j < x ≤ 1
F,
8j, 1, n<F;
funciones = TableAφj@xD, 8j, 1, n<E;Plot@funciones, 8x, a, b<, PlotLabel → "Funciones base", PlotRange → AllD
0.2 0.4 0.6 0.8 1.0
0.2
0.4
0.6
0.8
1.0
Funciones base
FEMcurso.nb 9
Printed by Mathematica for Students
ã La solución aproximada tendrá la forma FHxL =⁄j=1n c j f jHxL. El objetivo será encontrar los coeficientes
c j que den la mejor aproximación a la solución de la ecuación diferencial:
Clear@Φ, cD;
Φ@x_D := ‚j=1
n
cj ∗ φj@xD;
Print@"Forma de la aproximación a la solución:"DPrint@"Φ@xD=", Φ@xDD
Forma de la aproximación a la solución:
Φ@xD=4 I 1
4+ xM −
1
4< x ≤ 0
4 I 1
4− xM 0 < x ≤
1
4
0 True
c1 +
4 x 0 < x ≤1
4
4 I 1
2− xM 1
4< x ≤
1
2
0 True
c2 +
0 0 < x ≤1
4
4 I− 1
4+ xM 1
4< x ≤
1
2
4 I 3
4− xM 1
2< x ≤
3
4
0 True
c3 +
0 0 < x ≤1
2
4 I− 1
2+ xM 1
2< x ≤
3
4
4 H1 − xL 3
4< x ≤ 1
0 True
c4 +
0 0 < x ≤3
4
4 I− 3
4+ xM 3
4< x ≤ 1
4 I 5
4− xM 1 < x ≤
5
4
0 True
c5
ã La ecuación diferencial puede escribirse de la forma:-
d
dxIpHxL d
dxyHxLM + qHxL yHxL- f HxL= 0
Si reemplazamos la solución aproximada FHxL en lugar de la solución exacta yHxL en el lado izquierdo de la ecuación anterior, el resultado ya no será exactamente cero. En su lugar obtendremos una función conocida como residuo, rHxL. En otras palabras, si el residuo rHxL, mostrado abajo, fuera cero, en ese caso la solución aproximada sería la solución exacta:-
d
dxIpHxL d
dxFHxLM + qHxLFHxL - f HxL= rHxL
ã El método de Bubnov-Galerkin consiste en encontrar la combinación lineal FHxL =⁄j=1n c j f jHxL cuyo
residuo rHxL tenga componente igual a cero en el subespacio generado por las funciones base 9f j= j=2n-1
(sin incluir f1 ni fn, porqué serán usadas para cumplir las condiciones de frontera). Esto significa que el producto punto del residuo por cada función base debe ser cero:
Ÿa
bf jHxL rHxL‚x = 0 para j = 2 ... n - 1
es decir
-Ÿa
bf jHxL
d
dxIpHxL d
dxFHxLM‚x + Ÿa
bf jHxL HqHxLFHxL - f HxLL‚x = 0 para j = 2 ... n - 1
ã Sin embargo la aproximación FHxL que estamos utilizando en este ejemplo no tiene segunda derivada. Usando integración por partes se obtiene una expresión que sólo involucra primeras derivadas:
-Af jHxL pHxL dF HxLd x
Ea
b+ Ÿa
bpHxL dF HxL
d x
d f jHxLd x
‚x + Ÿa
bf jHxL HqHxLFHxL - f HxLL‚x = 0 para j = 2 ... n - 1 ,
pero recordemos que debido a su soporte local, f jHbL= f jHaL = 0 para j = 2 ... n - 1, entonces cada
producto punto igualado a cero queda:
Ÿa
bp HxL dΦ HxL
d x
d φjHxLd x
x + Ÿa
bφj HxL Hq HxL Φ HxL − f HxLL x = 0 para j = 2 ... n - 1 ,
que, junto con las condiciones de frontera c1 = ya, cn = yb, forman un sistema de n ecuaciones para los
10 FEMcurso.nb
Printed by Mathematica for Students
1 a n b
n parámetros c j , como se muestra abajo:
ecuaciones =
TableB‡a
b
p@xD ∗ Φ'@xD ∗ φj'@xD x + ‡a
b
φj@xD ∗ Hq@xD ∗ Φ@xD − f@xDL x == 0,
8j, 2, n − 1<F;
ecuaciones = Join@8c1 � ya<, ecuaciones, 8cn � yb<D;
TableForm@ecuacionesDc1 � 0
1
12H−c1 + 8 c2 − 7 c3L +
1
8H7 + 10 c1 + 40 c2 + 10 c3L � 0
1
12H−7 c2 + 26 c3 − 19 c4L +
1
4H7 + 5 c2 + 20 c3 + 5 c4L � 0
1
12H−19 c3 + 56 c4 − 37 c5L +
1
8H21 + 10 c3 + 40 c4 + 10 c5L � 0
c5 � 0.5
ã A continuación se muestra el sistema de ecuaciones en forma matricial:
parametros = TableAcj, 8j, 1, n<E;
8v, m< = N@ CoefficientArrays@ecuaciones, parametrosD D;
Print@MatrixForm@mD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@−vDD
1. 0. 0. 0. 0.
1.16667 5.66667 0.666667 0. 0.
0. 0.666667 7.16667 −0.333333 0.
0. 0. −0.333333 9.66667 −1.83333
0. 0. 0. 0. 1.
.
c1c2c3c4c5
==
0.
−0.875
−1.75
−2.625
0.5
ã Como ya tenemos la matriz y el vector del sistema lineal, podemos obtener la solución usando el comando LinearSolve[] de Mathematica:
LinearSolve@m, −vD80., −0.126051, −0.241067, −0.185037, 0.5<
FEMcurso.nb 11
Printed by Mathematica for Students
ã Sin embargo el comando NSolve proporciona la misma respuesta en un formato más útil para ser usado después en este documento:
soluciones = NSolve@ecuaciones, parametrosD88c1 → 0., c2 → −0.126051, c3 → −0.241067, c4 → −0.185037, c5 → 0.5<<
ã La solución aproximada se obtiene reemplazando los coeficientes c j en la expresión
FHxL =⁄j=1n c j f jHxL. Abajo se le llama gHxL a la solución aproximada que se obtiene por este
procedimiento:
g@x_D := ReplaceAll@Φ@xD, soluciones@@1DD D;
Print@"Solución aproximada por el método de Galerkin: "D;Print@"g@xD=", g@xDD
Solución aproximada por el método de Galerkin:
g@xD=0. − 0.126051
4 x 0 < x ≤1
4
4 I 1
2− xM 1
4< x ≤
1
2
0 True
− 0.241067
0 0 < x ≤1
4
4 I− 1
4+ xM 1
4< x ≤
1
2
4 I 3
4− xM 1
2< x ≤
3
4
0 True
−
0.185037
0 0 < x ≤1
2
4 I− 1
2+ xM 1
2< x ≤
3
4
4 H1 − xL 3
4< x ≤ 1
0 True
+ 0.5
0 0 < x ≤3
4
4 I− 3
4+ xM 3
4< x ≤ 1
4 I 5
4− xM 1 < x ≤
5
4
0 True
ã Ésta es la gráfica de la solución aproximada con el método de Bubnov-Galerkin:
Plot@g@xD, 8x, a, b<, PlotLabel → "Solución aproximada"D
0.2 0.4 0.6 0.8 1.0
-0.2
-0.1
0.1
0.2
0.3
0.4
0.5
Solución aproximada
12 FEMcurso.nb
Printed by Mathematica for Students
ã A continuación se muestra la gráfica de la solución analítica exacta, obtenida con el comando DSolve:
solexacta =
DSolve@8−∂xHp@xD ∂xy@xDL + q@xD ∗ y@xD � f@xD, y@aD � ya, y@bD � yb<, y@xD, xD;
exacta@x_D := Evaluate@ReplaceAll@y@xD, solexacta@@1DD D D;
Plot@exacta@xD, 8x, a, b<, PlotLabel → "Solución analítica exacta"D
0.2 0.4 0.6 0.8 1.0
-0.2
-0.1
0.1
0.2
0.3
Solución analítica exacta
ã Podemos graficar juntas la solución analítica y la aproximación con el método de Bubnov-Galerkin:
Plot@8exacta@xD, g@xD<, 8x, a, b<, PlotLabel → "Analítica y Bubnov−Galerkin"D
0.2 0.4 0.6 0.8 1.0
-0.2
-0.1
0.1
0.2
0.3
0.4
0.5
Analítica y Bubnov-Galerkin
ã Referencias
Basado en el trabajo de John H. Mathews
http://math.fullerton.edu/mathews/n2003/GalerkinMod.html
también en la sección 11.5 “El método de Rayleigh-Ritz” del libro de Richard L. Burden y J. Douglas Faires,
FEMcurso.nb 13
Printed by Mathematica for Students
también en la sección 11.5 “El método de Rayleigh-Ritz” del libro de Richard L. Burden y J. Douglas Faires,
“Análisis numérico” 9a. edición, editorial Cengage, págs 696-711
y finalmente también en la sección 6.2 “Galerkin’s method with piecewise polynomials” del libro de Kenneth
Eriksson, D. Estep, P. Hansbo & C. Johnson, “Computational Differential Equations” Volumen 1, Cambridge
University Press, 1997.
Adaptado por José Luis Gómez Muñoz
http://homepage.cem.itesm.mx/lgomez/
14 FEMcurso.nb
Printed by Mathematica for Students
3. Ejemplo del Método de Elemento Finito donde las ecuaciones de cada elemento se generan con el método de Bubnov-Galerkin
Basado en el trabajo de John H. Mathews
http://math.fullerton.edu/mathews/n2003/GalerkinMod.html
también en la sección 11.5 “El método de Rayleigh-Ritz” del libro de Richard L. Burden y J. Douglas Faires,
“Análisis numérico” 9a. edición, editorial Cengage, págs 696-711
y finalmente también en la sección 6.2 “Galerkin’s method with piecewise polynomials” del libro de Kenneth
Eriksson, D. Estep, P. Hansbo & C. Johnson, “Computational Differential Equations” Volumen 1, Cambridge
University Press, 1997.
Adaptado por José Luis Gómez Muñoz
http://homepage.cem.itesm.mx/lgomez/
ã Se va a calcular una solución aproximada a una ecuación diferencial ordinaria, lineal e inhomogénea,
-d
dxIpHxL d
dxyHxLM + qHxL yHxL= f HxL, con las condiciones de frontera yHaL= ya, yHbL = yb, como se
muestra a continuación :
Clear@x, y, p, q, f, a, bD;
p@x_D := x2;
q@x_D := 30;
f@x_D := −14 x;
a = 0;
b = 1;
ya = 0;
yb = 0.5;
Print@"−∂xHp@xD ∂xy@xDL+q@xD∗y@xD�f@xD → ",
−∂xHp@xD ∂xy@xDL + q@xD ∗ y@xD � f@xDD;Print@y@aD � yaD;Print@y@bD � ybD;
−∂xHp@xD ∂xy@xDL+q@xD∗y@xD�f@xD → 30 y@xD − 2 x y′@xD − x2 y′′@xD � −14 x
y@0D � 0
y@1D � 0.5
FEMcurso.nb 15
Printed by Mathematica for Students
ã La solución aproximada FHxL será una combinación lineal de ciertas funciones linealmente independientes, llamadas funciones base: FHxL=⁄j=1
n c j f jHxL. Las funciones base f jHxL usadas en el
método de Elemento Finito tienen soporte local, lo que quiere decir que cada una es distinta de cero sólo en una pequeña parte del dominio:
Clear@n, h, φ, x, jD;
n = 5;
h =b − a
n − 1;
DoB
φj@x_D := EvaluateB0 0 < x ≤ h ∗ Hj − 2Lx−h∗Hj−2L
hh ∗ Hj − 2L < x ≤ h ∗ Hj − 1L
h∗j−x
hh ∗ Hj − 1L < x ≤ h ∗ j
0 h ∗ j < x ≤ 1
F,
8j, 1, n<F;
funciones = TableAφj@xD, 8j, 1, n<E;Plot@funciones, 8x, a, b<, PlotLabel → "Funciones base", PlotRange → AllD
0.2 0.4 0.6 0.8 1.0
0.2
0.4
0.6
0.8
1.0
Funciones base
16 FEMcurso.nb
Printed by Mathematica for Students
ã La solución aproximada tendrá la forma FHxL =⁄j=1n c j f jHxL. El objetivo será encontrar los coeficientes
c j que den la mejor aproximación a la solución de la ecuación diferencial:
Clear@Φ, cD;
Φ@x_D := ‚j=1
n
cj ∗ φj@xD;
Print@"Forma de la aproximación a la solución:"D;Print@"Φ@xD=", Φ@xDD;
Forma de la aproximación a la solución:
Φ@xD=4 I 1
4+ xM −
1
4< x ≤ 0
4 I 1
4− xM 0 < x ≤
1
4
0 True
c1 +
4 x 0 < x ≤1
4
4 I 1
2− xM 1
4< x ≤
1
2
0 True
c2 +
0 0 < x ≤1
4
4 I− 1
4+ xM 1
4< x ≤
1
2
4 I 3
4− xM 1
2< x ≤
3
4
0 True
c3 +
0 0 < x ≤1
2
4 I− 1
2+ xM 1
2< x ≤
3
4
4 H1 − xL 3
4< x ≤ 1
0 True
c4 +
0 0 < x ≤3
4
4 I− 3
4+ xM 3
4< x ≤ 1
4 I 5
4− xM 1 < x ≤
5
4
0 True
c5
FEMcurso.nb 17
Printed by Mathematica for Students
ã En el Método de Elemento Finito (FEM por sus siglas en Inglés) el dominio es dividido en elementos. Cada elemento contiene partes de las funciones seccionadas que no valen cero dentro del elemento:
Table@Plot@funciones, 8x, h ∗ Helemento − 1L, h ∗ elemento<,PlotLabel → "Elemento: " <> ToString@elementoD,PlotRange → 880, 1<, Automatic<D,
8elemento, 1, n − 1<D
:
0.2 0.4 0.6 0.8 1.00.0
0.2
0.4
0.6
0.8
1.0
Elemento: 1
,
0.2 0.4 0.6 0.8 1.00.0
0.2
0.4
0.6
0.8
1.0
Elemento: 2
,
0.2 0.4 0.6 0.8 1.00.0
0.2
0.4
0.6
0.8
1.0
Elemento: 3
,
0.2 0.4 0.6 0.8 1.00.0
0.2
0.4
0.6
0.8
1.0
Elemento: 4
>
ã La ecuación diferencial puede escribirse de la forma:-
d
dxIpHxL d
dxyHxLM + qHxL yHxL- f HxL= 0
Si reemplazamos la solución aproximada FHxL en lugar de la solución exacta yHxL en el lado izquierdo de la ecuación anterior, el resultado ya no será exactamente cero. En su lugar obtendremos una función conocida como residuo, rHxL. En otras palabras, si el residuo rHxL, mostrado abajo, fuera cero, en ese caso la solución aproximada sería la solución exacta:-
d
dxIpHxL d
dxFHxLM + qHxLFHxL - f HxL= rHxL
ã El método de Bubnov-Galerkin consiste en encontrar la combinación lineal FHxL =⁄j=1n c j f jHxL cuyo
residuo rHxL tenga componente igual a cero en el subespacio generado por las funciones base. Esto significa que el producto punto del residuo por cada función base debe ser cero. En el Método de Elemento Finito este cálculo se hace elemento por elemento:Ÿelemento
f jHxL rHxL‚x = 0
es decir
-Ÿelementof jHxL
d
dxIpHxL d
dxFHxLM‚x + Ÿelemento
f jHxL HqHxLFHxL - f HxLL‚x = 0
ã Sin embargo la aproximación FHxL que estamos utilizando en este ejemplo no tiene segunda derivada. Usando integración por partes se obtiene una expresión que sólo involucra primeras derivadas:
Ÿelemento
p HxL dΦ HxLd x
d φjHxLd x
x + Ÿelemento
φj HxL Hq HxL Φ HxL − f HxLL x = 0
que forman un sistema de ecuaciones para los parámetros c j correspondientes a las funciones que no
18 FEMcurso.nb
Printed by Mathematica for Students
son cero dentro del elemento. Estas ecuaciones todavía no toman en cuenta las condiciones de frontera. Abajo se muestra este procedimiento para el primer elemento:
elemento = 1;
xini = a + h ∗ Helemento − 1L;xfin = a + h ∗ elemento;
ecuaciones =
TableB‡xini
xfin
p@xD ∗ Φ'@xD ∗ φj'@xD x + ‡xini
xfin
φj@xD ∗ Hq@xD ∗ Φ@xD − f@xDL x == 0,
8j, 1, n<F;
Print@"Ecuaciones sin condiciones de frontera"D;Print@"Elemento:", elementoD;Print@TableForm@ecuacionesDD
Ecuaciones sin condiciones de frontera
Elemento:1
1
12Hc1 − c2L +
1
48H7 + 120 c1 + 60 c2L � 0
1
12H−c1 + c2L +
1
24H7 + 30 c1 + 60 c2L � 0
True
True
True
ã A continuación se muestran las mismas ecuaciones del primer elemento en forma matricial:
ecuaciones = ReplaceAll@ecuaciones, True → 0D;
parametros = TableAcj, 8j, 1, n<E;
8v, m< = N@ CoefficientArrays@ecuaciones, parametrosD D;
Print@"Ecuaciones sin condiciones de frontera"D;Print@"Elemento:", elementoD;Print@MatrixForm@mD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@−vDD
Ecuaciones sin condiciones de frontera
Elemento:1
2.58333 1.16667 0. 0. 0.
1.16667 2.58333 0. 0. 0.
0. 0. 0. 0. 0.
0. 0. 0. 0. 0.
0. 0. 0. 0. 0.
.
c1c2c3c4c5
==
−0.145833
−0.291667
0.
0.
0.
FEMcurso.nb 19
Printed by Mathematica for Students
ã A continuación se calculan las matrices y vectores de carga para todos los elementos en este ejemplo:
matrices = 8<;cargas = 8<;
DoBxini = a + h ∗ Helemento − 1L;xfin = a + h ∗ elemento;
ecuaciones =
TableB‡xini
xfin
p@xD ∗ Φ'@xD ∗ φj'@xD x + ‡xini
xfin
φj@xD ∗ Hq@xD ∗ Φ@xD − f@xDL x == 0,
8j, 1, n<F;
ecuaciones = ReplaceAll@ecuaciones, True → 0D;
8v, m< = N@ CoefficientArrays@ecuaciones, parametrosD D;
AppendTo@matrices, mD;AppendTo@cargas, −vD;
Print@"Ecuaciones sin condiciones de frontera, elemento:", elementoD;Print@MatrixForm@mD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@−vDD,8elemento, 1, n − 1<F
20 FEMcurso.nb
Printed by Mathematica for Students
Ecuaciones sin condiciones de frontera, elemento:1
2.58333 1.16667 0. 0. 0.
1.16667 2.58333 0. 0. 0.
0. 0. 0. 0. 0.
0. 0. 0. 0. 0.
0. 0. 0. 0. 0.
.
c1c2c3c4c5
==
−0.145833
−0.291667
0.
0.
0.
Ecuaciones sin condiciones de frontera, elemento:2
0. 0. 0. 0. 0.
0. 3.08333 0.666667 0. 0.
0. 0.666667 3.08333 0. 0.
0. 0. 0. 0. 0.
0. 0. 0. 0. 0.
.
c1c2c3c4c5
==
0.
−0.583333
−0.729167
0.
0.
Ecuaciones sin condiciones de frontera, elemento:3
0. 0. 0. 0. 0.
0. 0. 0. 0. 0.
0. 0. 4.08333 −0.333333 0.
0. 0. −0.333333 4.08333 0.
0. 0. 0. 0. 0.
.
c1c2c3c4c5
==
0.
0.
−1.02083
−1.16667
0.
Ecuaciones sin condiciones de frontera, elemento:4
0. 0. 0. 0. 0.
0. 0. 0. 0. 0.
0. 0. 0. 0. 0.
0. 0. 0. 5.58333 −1.83333
0. 0. 0. −1.83333 5.58333
.
c1c2c3c4c5
==
0.
0.
0.
−1.45833
−1.60417
ã A continuación las ecuaciones de todos los elementos se suman para obtener un único sistema de ecuaciones para todos los parámetros c j . Este sistema de ecuaciones todavía no incluye las
condiciones de frontera:
matrizGlobal = Total@matricesD;
cargaGlobal = Total@cargasD;
Print@"Ecuaciones sin condiciones de frontera"D;Print@MatrixForm@matrizGlobalD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@cargaGlobalDD
Ecuaciones sin condiciones de frontera
2.58333 1.16667 0. 0. 0.
1.16667 5.66667 0.666667 0. 0.
0. 0.666667 7.16667 −0.333333 0.
0. 0. −0.333333 9.66667 −1.83333
0. 0. 0. −1.83333 5.58333
.
c1c2c3c4c5
==
−0.145833
−0.875
−1.75
−2.625
−1.60417
FEMcurso.nb 21
Printed by Mathematica for Students
ã A continuación se insertan las condiciones de frontera, reemplazando a las ecuaciones correspondientes:
matrizGlobal@@1DD = 81, 0, 0, 0, 0<;cargaGlobal@@1DD = ya;
matrizGlobal@@nDD = 80, 0, 0, 0, 1<;cargaGlobal@@nDD = yb;
Print@"Ecuaciones CON condiciones de frontera"D;Print@MatrixForm@matrizGlobalD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@cargaGlobalDD
Ecuaciones CON condiciones de frontera
1 0. 0. 0. 0.
1.16667 5.66667 0.666667 0. 0.
0. 0.666667 7.16667 −0.333333 0.
0. 0. −0.333333 9.66667 −1.83333
0. 0. 0. 0. 1
.
c1c2c3c4c5
==
0.
−0.875
−1.75
−2.625
0.5
ã Como ya tenemos la matriz y el vector del sistema lineal, podemos obtener la solución usando el comando LinearSolve[] de Mathematica:
solvector = LinearSolve@matrizGlobal, cargaGlobalD80., −0.126051, −0.241067, −0.185037, 0.5<
ã Ponemos la solución en un formato adecuado para reemplazar en la expresión de FHxL
solu = Table@parametros@@jDD → solvector@@jDD, 8j, 1, n<D8c1 → 0., c2 → −0.126051, c3 → −0.241067, c4 → −0.185037, c5 → 0.5<
ã La solución aproximada se obtiene reemplazando los coeficientes c j en la expresión
FHxL =⁄j=1n c j f jHxL. Abajo se le llama gHxL a la solución aproximada que se obtiene por este
procedimiento:
g@x_D := ReplaceAll@Φ@xD, solu D;
Print@"Solución aproximada por el método de Galerkin: "D;Print@"g@xD=", g@xDD
22 FEMcurso.nb
Printed by Mathematica for Students
Solución aproximada por el método de Galerkin:
g@xD=0. − 0.126051
4 x 0 < x ≤1
4
4 I 1
2− xM 1
4< x ≤
1
2
0 True
− 0.241067
0 0 < x ≤1
4
4 I− 1
4+ xM 1
4< x ≤
1
2
4 I 3
4− xM 1
2< x ≤
3
4
0 True
−
0.185037
0 0 < x ≤1
2
4 I− 1
2+ xM 1
2< x ≤
3
4
4 H1 − xL 3
4< x ≤ 1
0 True
+ 0.5
0 0 < x ≤3
4
4 I− 3
4+ xM 3
4< x ≤ 1
4 I 5
4− xM 1 < x ≤
5
4
0 True
ã Ésta es la gráfica de la solución aproximada con el Método de Elemento Finito:
Plot@g@xD, 8x, a, b<, PlotLabel → "Solución aproximada"D
0.2 0.4 0.6 0.8 1.0
-0.2
-0.1
0.1
0.2
0.3
0.4
0.5
Solución aproximada
FEMcurso.nb 23
Printed by Mathematica for Students
ã A continuación se muestra la gráfica de la solución analítica exacta, obtenida con el comando DSolve:
solexacta =
DSolve@8−∂xHp@xD ∂xy@xDL + q@xD ∗ y@xD � f@xD, y@aD � ya, y@bD � yb<, y@xD, xD;
exacta@x_D := Evaluate@ReplaceAll@y@xD, solexacta@@1DD D D;
Plot@exacta@xD, 8x, a, b<, PlotLabel → "Solución analítica exacta"D
0.2 0.4 0.6 0.8 1.0
-0.2
-0.1
0.1
0.2
0.3
Solución analítica exacta
ã Podemos graficar juntas la solución analítica y la aproximación con el Método de Elemento Finito:
Plot@8exacta@xD, g@xD<, 8x, a, b<, PlotLabel → "Analítica y Elemento Finito"D
0.2 0.4 0.6 0.8 1.0
-0.2
-0.1
0.1
0.2
0.3
0.4
0.5
Analítica y Elemento Finito
ã Referencias
Basado en el trabajo de John H. Mathews
http://math.fullerton.edu/mathews/n2003/GalerkinMod.html
también en la sección 11.5 “El método de Rayleigh-Ritz” del libro de Richard L. Burden y J. Douglas Faires,
24 FEMcurso.nb
Printed by Mathematica for Students
también en la sección 11.5 “El método de Rayleigh-Ritz” del libro de Richard L. Burden y J. Douglas Faires,
“Análisis numérico” 9a. edición, editorial Cengage, págs 696-711
y finalmente también en la sección 6.2 “Galerkin’s method with piecewise polynomials” del libro de Kenneth
Eriksson, D. Estep, P. Hansbo & C. Johnson, “Computational Differential Equations” Volumen 1, Cambridge
University Press, 1997.
Adaptado por José Luis Gómez Muñoz
http://homepage.cem.itesm.mx/lgomez/
FEMcurso.nb 25
Printed by Mathematica for Students
4. Ejemplo del Método de Elemento Finito
ã Para poder llevar a cabo los cálculos de esta práctica es necesario instalar el paquete gratis IMS (Imtek Mathematica Suplement). El programa de instalación de IMS se descarga en la siguiente liga:http://portal.uni-freiburg.de/imteksimulation/downloads/ims .
ã Primero hay que ejecutar los siguientes comandos Needs[], de tal manera que podamos usar los comandos de IMS del resto de esta práctica:
Needs@"Imtek`Assembler`"D;Needs@"Imtek`BoundaryConditions`"D;Needs@"Imtek`FEMOperators`"D;Needs@"Imtek`MeshElementLibrary`"D;Needs@"Imtek`StructuredMesher`"D;
Print@"Contextos de los paquetes en esta sesión:", $ContextPathDContextos de los paquetes en esta sesión:
8Imtek`StructuredMesher`, Imtek`FEMOperators`, Imtek`ShapeFunctions`,
Imtek`MeshElementLibrary`, Imtek`Graph`, Imtek`Nodes`, Imtek`BoundaryConditions`,
Imtek`Assembler`, PacletManager`, WebServices`, System`, Global`<
ã Se va a calcular una solución aproximada a una ecuación diferencial ordinaria, lineal e inhomogénea,
-d
dxIpHxL d
dxyHxLM + qHxL yHxL= f HxL, con las condiciones de frontera yHaL= ya, yHbL = yb, como se
muestra a continuación :
Clear@x, y, p, q, f, a, bD;
p@x_D := x2;
q@x_D := 30;
f@x_D := −14 x;
a = 0;
b = 1;
ya = 0;
yb = 0.5;
Print@"−∂xHp@xD ∂xy@xDL+q@xD∗y@xD�f@xD → ",
−∂xHp@xD ∂xy@xDL + q@xD ∗ y@xD � f@xDD;Print@y@aD � yaD;Print@y@bD � ybD;
−∂xHp@xD ∂xy@xDL+q@xD∗y@xD�f@xD → 30 y@xD − 2 x y′@xD − x2 y′′@xD � −14 x
y@0D � 0
y@1D � 0.5
26 FEMcurso.nb
Printed by Mathematica for Students
ã Se usa el comando imsGenerateLinearStructuredMesh[] para generar el mallado del dominio. El mallado consiste de nodos (puntos en el dominio) y elementos (en este caso unidimensional, los elementos son intervalos entre nodo y nodo):
numElem = 4;
mapeo@x_D := a +Hb − aL Hx + 1L
2;
malla =
imsGenerateLinearStructuredMesh@numElem, imsCoordinateMapping → mapeoD;
Graphics@8Orange, imsDrawElements@mallaD,Purple, imsDrawElementIdText@mallaD,Red, imsDrawNodeText@mallaD <,
Frame → True, AspectRatio → 0.5D
1 2 3 41 2 3 4 5
0.0 0.2 0.4 0.6 0.8 1.0
-1.0
-0.5
0.0
0.5
1.0
ã Estos son los nodos del mallado:
nodos = imsGetNodes@mallaD;
numNodos = Length@nodosD;
ultimoNodoId = numNodos;
Print@"Los nodos son: ", nodosD
Los nodos son: :imsNode@1, 80<, 1, 880.<<D, imsNodeB2, :14>, 0, 880.<<F,
imsNodeB3, : 12>, 0, 880.<<F, imsNodeB4, :3
4>, 0, 880.<<F, imsNode@5, 81<, 1, 880.<<D>
FEMcurso.nb 27
Printed by Mathematica for Students
ã Estos son los elementos del mallado:
elementos = imsGetElements@mallaD;
Print@"Los elementos son: ", elementosDLos elementos son: 8imsLineLinear1DOF@1, 81, 2<, 0D, imsLineLinear1DOF@2, 82, 3<, 0D,
imsLineLinear1DOF@3, 83, 4<, 0D, imsLineLinear1DOF@4, 84, 5<, 0D<
ã En este ejemplo unidimensional, a cada elemento le corresponden dos nodos:
nodosPorElemento = imsGetIncidentsIds@elementosD881, 2<, 82, 3<, 83, 4<, 84, 5<<
ã Hay una matriz local por cada elemento. Después esa matriz local será “ensamblada” en la matriz global en los renglones y columnas que corresponden a los nodos del elemento:
matrices = TableBimsMakeElementMatrixBJ 0 0
0 0N,
nodosPorElemento@@jDD, nodosPorElemento@@jDDF, 8j, 1, numElem<F
8imsElementMatrix@880, 0<, 80, 0<<, 81, 2<, 81, 2<D,imsElementMatrix@880, 0<, 80, 0<<, 82, 3<, 82, 3<D,imsElementMatrix@880, 0<, 80, 0<<, 83, 4<, 83, 4<D,imsElementMatrix@880, 0<, 80, 0<<, 84, 5<, 84, 5<D<
ã Hay un vector local de fuerzas, o cargas, por cada elemento. Después ese vector local será “ensamblado” en el vector global en los renglones que corresponden a los nodos del elemento:
cargas = TableBimsMakeElementMatrixBJ 00N,
nodosPorElemento@@jDD, nodosPorElemento@@jDDF, 8j, 1, numElem<F
8imsElementMatrix@880<, 80<<, 81, 2<, 81, 2<D,imsElementMatrix@880<, 80<<, 82, 3<, 82, 3<D,imsElementMatrix@880<, 80<<, 83, 4<, 83, 4<D,imsElementMatrix@880<, 80<<, 84, 5<, 84, 5<D<
ã El coeficiente pHxL en la ecuación diferencial es la “función de difusión”: -
d
dxIpHxL d
dxyHxLM + qHxL yHxL= f HxL
funcionDifusion@maker_, x_D := 88p@xD<<;
Print@"funcionDifusion@marker,xD=", funcionDifusion@marker, xDDfuncionDifusion@marker,xD=99x2==
28 FEMcurso.nb
Printed by Mathematica for Students
ã Aquí se calcula el efecto de la “función de difusión” (coeficiente pHxL en la ecuación diferencial ) en las matrices y cargas (en las ecuaciones) de cada elemento:
matricesycargas =
Table@imsNFEMDiffusion@ 8matrices@@jDD, cargas@@jDD<,elementos@@jDD,imsGetNodes@malla, nodosPorElemento@@jDDD, funcionDifusion D,
8j, 1, numElem<D88imsElementMatrix@880.0833333, −0.0833333<, 8−0.0833333, 0.0833333<<,
81, 2<, 81, 2<D, imsElementMatrix@880<, 80<<, 81, 2<, 81, 2<D<,8imsElementMatrix@880.583333, −0.583333<, 8−0.583333, 0.583333<<,
82, 3<, 82, 3<D, imsElementMatrix@880<, 80<<, 82, 3<, 82, 3<D<,8imsElementMatrix@881.58333, −1.58333<, 8−1.58333, 1.58333<<, 83, 4<, 83, 4<D,imsElementMatrix@880<, 80<<, 83, 4<, 83, 4<D<,
8imsElementMatrix@883.08333, −3.08333<, 8−3.08333, 3.08333<<, 84, 5<, 84, 5<D,imsElementMatrix@880<, 80<<, 84, 5<, 84, 5<D<<
ã Actualizamos la lista de matrices
matrices = matricesycargas@@All, 1DD8imsElementMatrix@880.0833333, −0.0833333<, 8−0.0833333, 0.0833333<<,
81, 2<, 81, 2<D, imsElementMatrix@880.583333, −0.583333<, 8−0.583333, 0.583333<<, 82, 3<, 82, 3<D,
imsElementMatrix@881.58333, −1.58333<, 8−1.58333, 1.58333<<, 83, 4<, 83, 4<D,imsElementMatrix@883.08333, −3.08333<, 8−3.08333, 3.08333<<, 84, 5<, 84, 5<D<
ã Actualizamos la lista de cargas
cargas = matricesycargas@@All, 2DD8imsElementMatrix@880<, 80<<, 81, 2<, 81, 2<D,imsElementMatrix@880<, 80<<, 82, 3<, 82, 3<D,imsElementMatrix@880<, 80<<, 83, 4<, 83, 4<D,imsElementMatrix@880<, 80<<, 84, 5<, 84, 5<D<
ã El coeficiente qHxL en la ecuación diferencial es la “función de reacción”, -
d
dxIpHxL d
dxyHxLM + qHxL yHxL= f HxL
funcionReaccion@marker_, x_D := q@xD;
Print@"funcionReaccion@marker,xD=", funcionReaccion@marker, xDDfuncionReaccion@marker,xD=30
FEMcurso.nb 29
Printed by Mathematica for Students
ã Aquí se calcula el efecto de la “función de reacción” (coeficiente qHxL en la ecuación diferencial ) en las matrices y cargas (en las ecuaciones) de cada elemento:
matricesycargas =
Table@imsNFEMReaction@ 8matrices@@jDD, cargas@@jDD<,elementos@@jDD,imsGetNodes@malla, nodosPorElemento@@jDDD, funcionReaccion D,
8j, 1, numElem<D88imsElementMatrix@882.58333, 1.16667<, 81.16667, 2.58333<<, 81, 2<, 81, 2<D,
imsElementMatrix@880<, 80<<, 81, 2<, 81, 2<D<,8imsElementMatrix@883.08333, 0.666667<, 80.666667, 3.08333<<, 82, 3<, 82, 3<D,imsElementMatrix@880<, 80<<, 82, 3<, 82, 3<D<,
8imsElementMatrix@884.08333, −0.333333<, 8−0.333333, 4.08333<<, 83, 4<, 83, 4<D,imsElementMatrix@880<, 80<<, 83, 4<, 83, 4<D<,
8imsElementMatrix@885.58333, −1.83333<, 8−1.83333, 5.58333<<, 84, 5<, 84, 5<D,imsElementMatrix@880<, 80<<, 84, 5<, 84, 5<D<<
ã Actualizamos la lista de matrices
matrices = matricesycargas@@All, 1DD8imsElementMatrix@882.58333, 1.16667<, 81.16667, 2.58333<<, 81, 2<, 81, 2<D,imsElementMatrix@883.08333, 0.666667<, 80.666667, 3.08333<<, 82, 3<, 82, 3<D,imsElementMatrix@884.08333, −0.333333<, 8−0.333333, 4.08333<<, 83, 4<, 83, 4<D,imsElementMatrix@885.58333, −1.83333<, 8−1.83333, 5.58333<<, 84, 5<, 84, 5<D<
ã Actualizamos la lista de cargas
cargas = matricesycargas@@All, 2DD8imsElementMatrix@880<, 80<<, 81, 2<, 81, 2<D,imsElementMatrix@880<, 80<<, 82, 3<, 82, 3<D,imsElementMatrix@880<, 80<<, 83, 4<, 83, 4<D,imsElementMatrix@880<, 80<<, 84, 5<, 84, 5<D<
ã La función f HxL en la ecuación diferencial es la “función de carga”, - d
dxIpHxL d
dxyHxLM + qHxL yHxL = f HxL
funcionCarga@maker_, x_D := f@xD;
Print@"funcionCarga@marker,xD=", funcionCarga@marker, xDDfuncionCarga@marker,xD=−14 x
30 FEMcurso.nb
Printed by Mathematica for Students
ã Aquí se calcula el efecto de la “función de carga” ( f HxL en la ecuación diferencial ) en las matrices y cargas (en las ecuaciones) de cada elemento:
matricesycargas =
Table@imsNFEMLoad@ 8matrices@@jDD, cargas@@jDD<,elementos@@jDD, imsGetNodes@malla, nodosPorElemento@@jDDD, funcionCarga D,
8j, 1, numElem<D88imsElementMatrix@882.58333, 1.16667<, 81.16667, 2.58333<<, 81, 2<, 81, 2<D,
imsElementMatrix@88−0.145833<, 8−0.291667<<, 81, 2<, 81<D<,8imsElementMatrix@883.08333, 0.666667<, 80.666667, 3.08333<<, 82, 3<, 82, 3<D,imsElementMatrix@88−0.583333<, 8−0.729167<<, 82, 3<, 81<D<,
8imsElementMatrix@884.08333, −0.333333<, 8−0.333333, 4.08333<<, 83, 4<, 83, 4<D,imsElementMatrix@88−1.02083<, 8−1.16667<<, 83, 4<, 81<D<,
8imsElementMatrix@885.58333, −1.83333<, 8−1.83333, 5.58333<<, 84, 5<, 84, 5<D,imsElementMatrix@88−1.45833<, 8−1.60417<<, 84, 5<, 81<D<<
ã Actualizamos la lista de matrices
matrices = matricesycargas@@All, 1DD8imsElementMatrix@882.58333, 1.16667<, 81.16667, 2.58333<<, 81, 2<, 81, 2<D,imsElementMatrix@883.08333, 0.666667<, 80.666667, 3.08333<<, 82, 3<, 82, 3<D,imsElementMatrix@884.08333, −0.333333<, 8−0.333333, 4.08333<<, 83, 4<, 83, 4<D,imsElementMatrix@885.58333, −1.83333<, 8−1.83333, 5.58333<<, 84, 5<, 84, 5<D<
ã Actualizamos la lista de cargas
cargas = matricesycargas@@All, 2DD8imsElementMatrix@88−0.145833<, 8−0.291667<<, 81, 2<, 81<D,imsElementMatrix@88−0.583333<, 8−0.729167<<, 82, 3<, 81<D,imsElementMatrix@88−1.02083<, 8−1.16667<<, 83, 4<, 81<D,imsElementMatrix@88−1.45833<, 8−1.60417<<, 84, 5<, 81<D<
FEMcurso.nb 31
Printed by Mathematica for Students
ã A continuación se “ensamblan” las matrices de cada elemento para formar la matriz global, y los vectores de carga de cada elemento para formar el vector de carga global:
matrizGlobal = SparseArray@8<, 8numNodos, numNodos<D;cargaGlobal = Table@0, 8numNodos<, 81<D;
Do@imsAssemble@ matrices@@jDD, matrizGlobalD;imsAssemble@ cargas@@jDD, cargaGlobalD,8j, 1, numElem<
D;
parametros = TableAcj, 8j, 1, numNodos<E;vectorCargas = Flatten@cargaGlobalD;
Print@MatrixForm@matrizGlobalD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@vectorCargasDD
2.58333 1.16667 0 0 0
1.16667 5.66667 0.666667 0 0
0 0.666667 7.16667 −0.333333 0
0 0 −0.333333 9.66667 −1.83333
0 0 0 −1.83333 5.58333
.
c1c2c3c4c5
==
−0.145833
−0.875
−1.75
−2.625
−1.60417
ã El siguiente paso es insertar las condiciones de frontera, lo cual modifica a la matriz global y al vector global de cargas. En este ejemplo unidimensional, los únicos nodos de frontera son el primero y el último:
imsDirichlet@8matrizGlobal, vectorCargas<, 1, yaD;
imsDirichlet@8matrizGlobal, vectorCargas<, ultimoNodoId, ybD;
Print@MatrixForm@matrizGlobalD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@vectorCargasDD
1. 0. 0. 0. 0.
0. 5.66667 0.666667 0. 0.
0. 0.666667 7.16667 −0.333333 0.
0. 0. −0.333333 9.66667 0.
0. 0. 0. 0. 1.
.
c1c2c3c4c5
==
0.
−0.875
−1.75
−1.70833
0.5
32 FEMcurso.nb
Printed by Mathematica for Students
ã A continuación resolvemos el sistema de ecuaciones, con lo cual obtenemos el valor de la solución aproximada en cada nodo:
solvector = LinearSolve@matrizGlobal, vectorCargasD80., −0.126051, −0.241067, −0.185037, 0.5<
ã A partir de los nodos originales construimos nuevos nodos, esta vez cada nodo nuevo incluye el valor de la solución que se acaba de obtener:
nodosNuevos =
Table@imsSetValues@ nodos@@jDD, 88 solvector@@jDD << D, 8j, 1, numNodos<D
:imsNode@1, 80<, 1, 880.<<D,
imsNodeB2, : 14>, 0, 88−0.126051<<F, imsNodeB3, : 1
2>, 0, 88−0.241067<<F,
imsNodeB4, : 34>, 0, 88−0.185037<<F, imsNode@5, 81<, 1, 880.5<<D>
ã Estos son los nuevos nodos en la frontera. Incluyen el valor de la solución:
nodosNuevosFrontera = nodosNuevos@@ imsGetIds@ imsGetBoundaryNodes@mallaD D DD8imsNode@1, 80<, 1, 880.<<D, imsNode@5, 81<, 1, 880.5<<D<
ã Estos son los nuevos nodos interiores. Incluyen el valor de la solución:
nodosNuevosInterior = nodosNuevos@@ imsGetIds@ imsGetInteriorNodes@mallaD D DD
:imsNodeB2, : 14>, 0, 88−0.126051<<F,
imsNodeB3, : 12>, 0, 88−0.241067<<F, imsNodeB4, : 3
4>, 0, 88−0.185037<<F>
FEMcurso.nb 33
Printed by Mathematica for Students
ã Esta es la nueva malla, con los valores de la solución, como se muestra en la gráifca:
mallaNueva = imsMakeNexus@nodosNuevosFrontera, nodosNuevosInterior, elementosD;
graficaFEM =
Graphics@8Brown, imsDrawElementSolution@mallaNuevaD,Green, imsDrawElements@mallaNuevaD,Blue, imsDrawElementIdText@mallaNuevaD,Red, imsDrawNodeText@mallaNuevaD
<, Frame → True, AspectRatio → 0.5D
1 2 3 41 2 3 4 5
0.0 0.2 0.4 0.6 0.8 1.0
-0.2
0.0
0.2
0.4
34 FEMcurso.nb
Printed by Mathematica for Students
ã A continuación se muestra la gráfica de la solución analítica exacta, obtenida con el comando DSolve:
solexacta =
DSolve@8−∂xHp@xD ∂xy@xDL + q@xD ∗ y@xD � f@xD, y@aD � ya, y@bD � yb<, y@xD, xD;
exacta@x_D := Evaluate@ReplaceAll@y@xD, solexacta@@1DD D D;
graficaExacta = Plot@exacta@xD, 8x, a, b<,PlotLabel → "Solución analítica exacta", PlotRange → AllD
0.2 0.4 0.6 0.8 1.0
-0.2
-0.1
0.1
0.2
0.3
0.4
0.5
Solución analítica exacta
ã Podemos graficar juntas la solución analítica y la aproximación con el método de Elemento Finito:
Show@graficaExacta, graficaFEM, PlotLabel → "Analítica y FEM"D
1 2 3 41 2 3 4 50.2 0.4 0.6 0.8 1.0
-0.2
-0.1
0.1
0.2
0.3
0.4
0.5
Analítica y FEM
ã Referencias
Para poder llevar a cabo los cálculos de esta práctica es necesario instalar el paquete gratis IMS (Imtek
Mathematica Suplement). El programa de instalación de IMS se descarga en la siguiente liga:
FEMcurso.nb 35
Printed by Mathematica for Students
Mathematica Suplement). El programa de instalación de IMS se descarga en la siguiente liga:
http://portal.uni-freiburg.de/imteksimulation/downloads/ims .
Capítulo 6, Sección 6.3 “Finite Element Method” de la Tesis de Doctorado de Oliver Rüebenkönig “Free
Surface Flow and the IMTEK Mathematica Supplement”, Institut für Mikrosystemtechnik (IMTEK), Albert-
Ludwigs-Univesität, Freiburg, Alemania.
ftp://elmo.imtek.uni-freiburg.de/pub/people/ruebenko/writing/dissertation1.1.pdf .
Daryl L. Logan, “A First Course in the Finite Element Method”, Fifth Edition, 2012, Cengage Leraning
36 FEMcurso.nb
Printed by Mathematica for Students
5. Ejemplo del Método de Elemento Finito con condiciones periódicas
ã Para poder llevar a cabo los cálculos de esta práctica es necesario instalar el paquete gratis IMS (Imtek Mathematica Suplement). El programa de instalación de IMS se descarga en la siguiente liga:http://portal.uni-freiburg.de/imteksimulation/downloads/ims .
ã Primero hay que ejecutar los siguientes comandos Needs[], de tal manera que podamos usar los comandos de IMS del resto de esta práctica:
Needs@"Imtek`Assembler`"D;Needs@"Imtek`BoundaryConditions`"D;Needs@"Imtek`FEMOperators`"D;Needs@"Imtek`MeshElementLibrary`"D;Needs@"Imtek`StructuredMesher`"D;
Print@"Contextos de los paquetes en esta sesión:", $ContextPathDContextos de los paquetes en esta sesión:
8Imtek`StructuredMesher`, Imtek`FEMOperators`, Imtek`ShapeFunctions`,
Imtek`MeshElementLibrary`, Imtek`Graph`, Imtek`Nodes`, Imtek`BoundaryConditions`,
Imtek`Assembler`, PacletManager`, WebServices`, System`, Global`<
ã Se va a calcular una solución aproximada a una ecuación diferencial ordinaria, lineal e inhomogénea,
sHxL d
dxyHxL + qHxL yHxL = f HxL, con las condiciones periódicas yHaL = yHbL, como se muestra a
continuación :
Clear@x, y, q, s, f, a, bD;
s@x_D := 1;
q@x_D := 1;
f@x_D := Cos@2 π xD − 2 π Sin@2 π xD;
a = 0;
b = 1;
Print@"s@xD∗∂xy@xD+q@xD∗y@xD�f@xD → ", s@xD ∗ ∂xy@xD + q@xD ∗ y@xD � f@xDD;Print@"Condiciones periódicas y@aD�y@bD, con a=", a, ", b=", bD
s@xD∗∂xy@xD+q@xD∗y@xD�f@xD → y@xD + y′@xD � Cos@2 π xD − 2 π Sin@2 π xDCondiciones periódicas y@aD�y@bD, con a=0, b=1
FEMcurso.nb 37
Printed by Mathematica for Students
ã Se usa el comando imsGenerateLinearStructuredMesh[] para generar el mallado del dominio. El mallado consiste de nodos (puntos en el dominio) y elementos (en este caso unidimensional, los elementos son intervalos entre nodo y nodo):
numElem = 5;
mapeo@x_D := a +Hb − aL Hx + 1L
2;
malla =
imsGenerateLinearStructuredMesh@numElem, imsCoordinateMapping → mapeoD;
Graphics@8Orange, imsDrawElements@mallaD,Purple, imsDrawElementIdText@mallaD,Red, imsDrawNodeText@mallaD <,
Frame → True, AspectRatio → 0.5D
1 2 3 4 51 2 3 4 5 6
0.0 0.2 0.4 0.6 0.8 1.0
-1.0
-0.5
0.0
0.5
1.0
ã Estos son los nodos del mallado:
nodos = imsGetNodes@mallaD;
numNodos = Length@nodosD;
ultimoNodoId = numNodos;
Print@"Los nodos son: ", nodosDLos nodos son:
:imsNode@1, 80<, 1, 880.<<D, imsNodeB2, :15>, 0, 880.<<F, imsNodeB3, :2
5>, 0, 880.<<F,
imsNodeB4, : 35>, 0, 880.<<F, imsNodeB5, :4
5>, 0, 880.<<F, imsNode@6, 81<, 1, 880.<<D>
38 FEMcurso.nb
Printed by Mathematica for Students
ã Estos son los elementos del mallado:
elementos = imsGetElements@mallaD;
Print@"Los elementos son: ", elementosDLos elementos son: 8imsLineLinear1DOF@1, 81, 2<, 0D,
imsLineLinear1DOF@2, 82, 3<, 0D, imsLineLinear1DOF@3, 83, 4<, 0D,imsLineLinear1DOF@4, 84, 5<, 0D, imsLineLinear1DOF@5, 85, 6<, 0D<
ã En este ejemplo unidimensional, a cada elemento le corresponden dos nodos:
nodosPorElemento = imsGetIncidentsIds@elementosD881, 2<, 82, 3<, 83, 4<, 84, 5<, 85, 6<<
ã Hay una matriz local por cada elemento. Después esa matriz local será “ensamblada” en la matriz global en los renglones y columnas que corresponden a los nodos del elemento:
matrices = TableBimsMakeElementMatrixBJ 0 0
0 0N,
nodosPorElemento@@jDD, nodosPorElemento@@jDDF, 8j, 1, numElem<F
8imsElementMatrix@880, 0<, 80, 0<<, 81, 2<, 81, 2<D,imsElementMatrix@880, 0<, 80, 0<<, 82, 3<, 82, 3<D,imsElementMatrix@880, 0<, 80, 0<<, 83, 4<, 83, 4<D,imsElementMatrix@880, 0<, 80, 0<<, 84, 5<, 84, 5<D,imsElementMatrix@880, 0<, 80, 0<<, 85, 6<, 85, 6<D<
ã Hay un vector local de fuerzas, o cargas, por cada elemento. Después ese vector local será “ensamblado” en el vector global en los renglones que corresponden a los nodos del elemento:
cargas = TableBimsMakeElementMatrixBJ 00N,
nodosPorElemento@@jDD, nodosPorElemento@@jDDF, 8j, 1, numElem<F
8imsElementMatrix@880<, 80<<, 81, 2<, 81, 2<D,imsElementMatrix@880<, 80<<, 82, 3<, 82, 3<D,imsElementMatrix@880<, 80<<, 83, 4<, 83, 4<D,imsElementMatrix@880<, 80<<, 84, 5<, 84, 5<D,imsElementMatrix@880<, 80<<, 85, 6<, 85, 6<D<
FEMcurso.nb 39
Printed by Mathematica for Students
ã El coeficiente sHxL en la ecuación diferencial es la “función de convección”:
sHxL d
dxyHxL + qHxL yHxL = f HxL,
funcionConveccion@maker_, x_D := 88s@xD<<;
Print@"funcionConveccion@marker,xD=", funcionConveccion@marker, xDDfuncionConveccion@marker,xD=881<<
ã Aquí se calcula el efecto de la “función de convección” (coeficiente sHxL en la ecuación diferencial ) en las matrices y cargas (en las ecuaciones) de cada elemento:
matricesycargas =
Table@imsNFEMConvection@ 8matrices@@jDD, cargas@@jDD<,elementos@@jDD,imsGetNodes@malla, nodosPorElemento@@jDDD, funcionConveccion D,
8j, 1, numElem<D88imsElementMatrix@88−0.5, 0.5<, 8−0.5, 0.5<<, 81, 2<, 81, 2<D,
imsElementMatrix@880<, 80<<, 81, 2<, 81, 2<D<,8imsElementMatrix@88−0.5, 0.5<, 8−0.5, 0.5<<, 82, 3<, 82, 3<D,imsElementMatrix@880<, 80<<, 82, 3<, 82, 3<D<,
8imsElementMatrix@88−0.5, 0.5<, 8−0.5, 0.5<<, 83, 4<, 83, 4<D,imsElementMatrix@880<, 80<<, 83, 4<, 83, 4<D<,
8imsElementMatrix@88−0.5, 0.5<, 8−0.5, 0.5<<, 84, 5<, 84, 5<D,imsElementMatrix@880<, 80<<, 84, 5<, 84, 5<D<,
8imsElementMatrix@88−0.5, 0.5<, 8−0.5, 0.5<<, 85, 6<, 85, 6<D,imsElementMatrix@880<, 80<<, 85, 6<, 85, 6<D<<
ã Actualizamos la lista de matrices
matrices = matricesycargas@@All, 1DD8imsElementMatrix@88−0.5, 0.5<, 8−0.5, 0.5<<, 81, 2<, 81, 2<D,imsElementMatrix@88−0.5, 0.5<, 8−0.5, 0.5<<, 82, 3<, 82, 3<D,imsElementMatrix@88−0.5, 0.5<, 8−0.5, 0.5<<, 83, 4<, 83, 4<D,imsElementMatrix@88−0.5, 0.5<, 8−0.5, 0.5<<, 84, 5<, 84, 5<D,imsElementMatrix@88−0.5, 0.5<, 8−0.5, 0.5<<, 85, 6<, 85, 6<D<
40 FEMcurso.nb
Printed by Mathematica for Students
ã Actualizamos la lista de cargas
cargas = matricesycargas@@All, 2DD8imsElementMatrix@880<, 80<<, 81, 2<, 81, 2<D,imsElementMatrix@880<, 80<<, 82, 3<, 82, 3<D,imsElementMatrix@880<, 80<<, 83, 4<, 83, 4<D,imsElementMatrix@880<, 80<<, 84, 5<, 84, 5<D,imsElementMatrix@880<, 80<<, 85, 6<, 85, 6<D<
ã El coeficiente qHxL en la ecuación diferencial es la “función de reacción”,
sHxL d
dxyHxL + qHxL yHxL = f HxL,
funcionReaccion@marker_, x_D := q@xD;
Print@"funcionReaccion@marker,xD=", funcionReaccion@marker, xDDfuncionReaccion@marker,xD=1
ã Aquí se calcula el efecto de la “función de reacción” (coeficiente qHxL en la ecuación diferencial ) en las matrices y cargas (en las ecuaciones) de cada elemento:
matricesycargas =
Table@imsNFEMReaction@ 8matrices@@jDD, cargas@@jDD<,elementos@@jDD,imsGetNodes@malla, nodosPorElemento@@jDDD, funcionReaccion D,
8j, 1, numElem<D88imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<,
81, 2<, 81, 2<D, imsElementMatrix@880<, 80<<, 81, 2<, 81, 2<D<,8imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<,
82, 3<, 82, 3<D, imsElementMatrix@880<, 80<<, 82, 3<, 82, 3<D<,8imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<,
83, 4<, 83, 4<D, imsElementMatrix@880<, 80<<, 83, 4<, 83, 4<D<,8imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<,
84, 5<, 84, 5<D, imsElementMatrix@880<, 80<<, 84, 5<, 84, 5<D<,8imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<,
85, 6<, 85, 6<D, imsElementMatrix@880<, 80<<, 85, 6<, 85, 6<D<<
FEMcurso.nb 41
Printed by Mathematica for Students
ã Actualizamos la lista de matrices
matrices = matricesycargas@@All, 1DD8imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<, 81, 2<,
81, 2<D, imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<,82, 3<, 82, 3<D, imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<, 83, 4<, 83, 4<D,
imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<,84, 5<, 84, 5<D, imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<, 85, 6<, 85, 6<D<
ã Actualizamos la lista de cargas
cargas = matricesycargas@@All, 2DD8imsElementMatrix@880<, 80<<, 81, 2<, 81, 2<D,imsElementMatrix@880<, 80<<, 82, 3<, 82, 3<D,imsElementMatrix@880<, 80<<, 83, 4<, 83, 4<D,imsElementMatrix@880<, 80<<, 84, 5<, 84, 5<D,imsElementMatrix@880<, 80<<, 85, 6<, 85, 6<D<
ã La función f HxL en la ecuación diferencial es la “función de carga”, - d
dxIpHxL d
dxyHxLM + qHxL yHxL = f HxL
funcionCarga@maker_, x_D := f@xD;
Print@"funcionCarga@marker,xD=", funcionCarga@marker, xDDfuncionCarga@marker,xD=Cos@2 π xD − 2 π Sin@2 π xD
42 FEMcurso.nb
Printed by Mathematica for Students
ã Aquí se calcula el efecto de la “función de carga” ( f HxL en la ecuación diferencial ) en las matrices y cargas (en las ecuaciones) de cada elemento:
matricesycargas =
Table@imsNFEMLoad@ 8matrices@@jDD, cargas@@jDD<,elementos@@jDD, imsGetNodes@malla, nodosPorElemento@@jDDD, funcionCarga D,
8j, 1, numElem<D88imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<, 81, 2<,
81, 2<D, imsElementMatrix@88−0.15567<, 8−0.383949<<, 81, 2<, 81<D<,8imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<, 82, 3<,
82, 3<D, imsElementMatrix@88−0.607863<, 8−0.56799<<, 82, 3<, 81<D<,8imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<, 83, 4<,
83, 4<D, imsElementMatrix@88−0.22001<, 80.0329116<<, 83, 4<, 81<D<,8imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<,
84, 5<, 84, 5<D, imsElementMatrix@880.47189<, 80.58833<<, 84, 5<, 81<D<,8imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<, 85, 6<,
85, 6<D, imsElementMatrix@880.511654<, 80.330696<<, 85, 6<, 81<D<<
ã Actualizamos la lista de matrices
matrices = matricesycargas@@All, 1DD8imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<, 81, 2<,
81, 2<D, imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<,82, 3<, 82, 3<D, imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<, 83, 4<, 83, 4<D,
imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<,84, 5<, 84, 5<D, imsElementMatrix@88−0.433333, 0.533333<, 8−0.466667, 0.566667<<, 85, 6<, 85, 6<D<
ã Actualizamos la lista de cargas
cargas = matricesycargas@@All, 2DD8imsElementMatrix@88−0.15567<, 8−0.383949<<, 81, 2<, 81<D,imsElementMatrix@88−0.607863<, 8−0.56799<<, 82, 3<, 81<D,imsElementMatrix@88−0.22001<, 80.0329116<<, 83, 4<, 81<D,imsElementMatrix@880.47189<, 80.58833<<, 84, 5<, 81<D,imsElementMatrix@880.511654<, 80.330696<<, 85, 6<, 81<D<
FEMcurso.nb 43
Printed by Mathematica for Students
ã A continuación se “ensamblan” las matrices de cada elemento para formar la matriz global, y se “ensamblan” los vectores de carga de cada elemento para formar el vector de carga global:
matrizGlobal = SparseArray@8<, 8numNodos, numNodos<D;cargaGlobal = Table@0, 8numNodos<, 81<D;
Do@imsAssemble@ matrices@@jDD, matrizGlobalD;imsAssemble@ cargas@@jDD, cargaGlobalD,8j, 1, numElem<
D;
parametros = TableAcj, 8j, 1, numNodos<E;vectorCargas = Flatten@cargaGlobalD;
Print@MatrixForm@matrizGlobalD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@vectorCargasDD
−0.433333 0.533333 0 0 0 0
−0.466667 0.133333 0.533333 0 0 0
0 −0.466667 0.133333 0.533333 0 0
0 0 −0.466667 0.133333 0.533333 0
0 0 0 −0.466667 0.133333 0.533333
0 0 0 0 −0.466667 0.566667
.
c1c2c3c4c5c6
==
−0.15567
−0.991812
−0.788
0.504801
1.09998
0.330696
ã El siguiente paso es insertar las condiciones periódicas, lo cual modifica a la matriz global y al vector global de cargas. En este ejemplo unidimensional, sólo es necesario insertar un multiplicador de Lagrange l1:
imsLagrangeMultipliers@8 matrizGlobal, vectorCargas <, 88 1, ultimoNodoId<<, 80<, 8 8 1, −1 < < D;
AppendTo@parametros, λ1D;
Print@MatrixForm@matrizGlobalD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@vectorCargasDD
−0.433333 0.533333 0 0 0 0 1
−0.466667 0.133333 0.533333 0 0 0 0
0 −0.466667 0.133333 0.533333 0 0 0
0 0 −0.466667 0.133333 0.533333 0 0
0 0 0 −0.466667 0.133333 0.533333 0
0 0 0 0 −0.466667 0.566667 −1
1 0 0 0 0 −1 0
.
c1c2c3c4c5c6λ1
==
−0.15567
−0.991812
−0.788
0.504801
1.09998
0.330696
0
44 FEMcurso.nb
Printed by Mathematica for Students
ã A continuación resolvemos el sistema de ecuaciones, con lo cual obtenemos el valor de la solución aproximada en cada nodo (y también los valores de los multiplicadores de Lagrange, lk):
solvector = LinearSolve@matrizGlobal, vectorCargasD81.15582, 0.354274, −0.93687, −0.933292, 0.360064, 1.15582, 0.15624<
ã A partir de los nodos originales construimos nuevos nodos, esta vez cada nodo nuevo incluye el valor de la solución que se acaba de obtener:
nodosNuevos =
Table@imsSetValues@ nodos@@jDD, 88 solvector@@jDD << D, 8j, 1, numNodos<D
:imsNode@1, 80<, 1, 881.15582<<D, imsNodeB2, : 15>, 0, 880.354274<<F,
imsNodeB3, : 25>, 0, 88−0.93687<<F, imsNodeB4, : 3
5>, 0, 88−0.933292<<F,
imsNodeB5, : 45>, 0, 880.360064<<F, imsNode@6, 81<, 1, 881.15582<<D>
ã Estos son los nuevos nodos en la frontera. Incluyen el valor de la solución:
nodosNuevosFrontera = nodosNuevos@@ imsGetIds@ imsGetBoundaryNodes@mallaD D DD8imsNode@1, 80<, 1, 881.15582<<D, imsNode@6, 81<, 1, 881.15582<<D<
ã Estos son los nuevos nodos interiores. Incluyen el valor de la solución:
nodosNuevosInterior = nodosNuevos@@ imsGetIds@ imsGetInteriorNodes@mallaD D DD
:imsNodeB2, : 15>, 0, 880.354274<<F, imsNodeB3, :2
5>, 0, 88−0.93687<<F,
imsNodeB4, : 35>, 0, 88−0.933292<<F, imsNodeB5, : 4
5>, 0, 880.360064<<F>
FEMcurso.nb 45
Printed by Mathematica for Students
ã Esta es la nueva malla, con los valores de la solución, como se muestra en la gráifca:
mallaNueva = imsMakeNexus@nodosNuevosFrontera, nodosNuevosInterior, elementosD;
graficaFEM =
Graphics@8Brown, imsDrawElementSolution@mallaNuevaD,Green, imsDrawElements@mallaNuevaD,Blue, imsDrawElementIdText@mallaNuevaD,Red, imsDrawNodeText@mallaNuevaD
<, Frame → True, AspectRatio → 0.5D
1 2 3 4 51 2 3 4 5 6
0.0 0.2 0.4 0.6 0.8 1.0-1.0
-0.5
0.0
0.5
1.0
46 FEMcurso.nb
Printed by Mathematica for Students
ã A continuación se muestra la gráfica de la solución analítica exacta, obtenida con el comando DSolve:
solexacta =
DSolve@8s@xD ∗ ∂xy@xD + q@xD ∗ y@xD � f@xD,y@aD � y@bD
<, y@xD, xD;
exacta@x_D := Evaluate@ReplaceAll@y@xD, solexacta@@1DD D D;
graficaExacta = Plot@exacta@xD, 8x, a, b<,PlotLabel → "Solución analítica exacta", PlotRange → All, AxesOrigin → 80, 0<D
0.2 0.4 0.6 0.8 1.0
-1.0
-0.5
0.5
1.0
Solución analítica exacta
ã Podemos graficar juntas la solución analítica y la aproximación con el método de Elemento Finito:
Show@graficaExacta, graficaFEM, PlotLabel → "Analítica y FEM"D
1 2 3 4 51 2 3 4 5 60.2 0.4 0.6 0.8 1.0
-1.0
-0.5
0.5
1.0
Analítica y FEM
FEMcurso.nb 47
Printed by Mathematica for Students
ã Referencias
Para poder llevar a cabo los cálculos de esta práctica es necesario instalar el paquete gratis IMS (Imtek
Mathematica Suplement). El programa de instalación de IMS se descarga en la siguiente liga:
http://portal.uni-freiburg.de/imteksimulation/downloads/ims .
Capítulo 6, Sección 6.3 “Finite Element Method” de la Tesis de Doctorado de Oliver Rüebenkönig “Free
Surface Flow and the IMTEK Mathematica Supplement”, Institut für Mikrosystemtechnik (IMTEK), Albert-
Ludwigs-Univesität, Freiburg, Alemania.
ftp://elmo.imtek.uni-freiburg.de/pub/people/ruebenko/writing/dissertation1.1.pdf .
Daryl L. Logan, “A First Course in the Finite Element Method”, Fifth Edition, 2012, Cengage Leraning
48 FEMcurso.nb
Printed by Mathematica for Students
6. Ejemplo del Método de Elemento Finito en dos dimensiones
ã Para poder llevar a cabo los cálculos de esta práctica es necesario instalar el paquete gratis IMS (Imtek Mathematica Suplement). El programa de instalación de IMS se descarga en la siguiente liga:http://portal.uni-freiburg.de/imteksimulation/downloads/ims .
ã Primero hay que ejecutar los siguientes comandos Needs[], de tal manera que podamos usar los comandos de IMS del resto de esta práctica:
Needs@"Imtek`Assembler`"D;Needs@"Imtek`BoundaryConditions`"D;Needs@"Imtek`FEMOperators`"D;Needs@"Imtek`MeshElementLibrary`"D;Needs@"Imtek`StructuredMesher`"D;
Print@"Contextos de los paquetes en esta sesión:", $ContextPathDContextos de los paquetes en esta sesión:
8Imtek`StructuredMesher`, Imtek`FEMOperators`, Imtek`ShapeFunctions`,
Imtek`MeshElementLibrary`, Imtek`Graph`, Imtek`Nodes`, Imtek`BoundaryConditions`,
Imtek`Assembler`, PacletManager`, WebServices`, System`, Global`<
ã Se va a calcular una solución aproximada la ecuación diferencial parcial que se muestra al evaluar los siguiente comandos:
Clear@x, y, z, p, q, f, xa, xb, ya, ybD;
p@x_, y_D := x2;
q@x_, y_D := 30;
f@x_, y_D := −10 ∗ x ∗3
4− y ;
xa = 0;
xb = 2;
ya = 0;
yb = 2;
zxa = 0;
zxb = 0.5;
Print@"−∂xHp@x,yD ∂xz@x,yDL+q@x,yD∗z@x,yD�f@x,yD"D;Print@−∂xHp@x, yD ∂xz@x, yDL + q@x, yD ∗ z@x, yD � f@x, yDD;Print@z@xa, yD � zxaD;Print@z@xb, yD � zxbD;
FEMcurso.nb 49
Printed by Mathematica for Students
−∂xHp@x,yD ∂xz@x,yDL+q@x,yD∗z@x,yD�f@x,yD
30 z@x, yD − 2 x zH1,0L@x, yD − x2 zH2,0L@x, yD � −10 x3
4− y
z@0, yD � 0
z@2, yD � 0.5
ã Se usa el comando imsGenerateLinearStructuredMesh[ ] para generar el mallado del dominio. El mallado consiste de nodos (puntos en el dominio) y elementos (en este ejemplo los elementos son cuadriláteros cuyos vértices son los nodos):
numElemX = 3;
numElemY = 3;
numElem = numElemX ∗ numElemY;
mapeo@8x_, y_<D := :xa +Hxb − xaL Hx + 1L
2, ya +
Hyb − yaL Hy + 1L2
>;malla = imsGenerateLinearStructuredMesh@
numElemX, numElemY, imsCoordinateMapping → mapeoD;
Graphics@8Orange, imsDrawElements@mallaD,Purple, imsDrawElementIdText@mallaD,Red, imsDrawNodeText@mallaD
<, Frame → TrueD
1 2 3
4 5 6
7 8 9
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
0.0 0.5 1.0 1.5 2.0
0.0
0.5
1.0
1.5
2.0
50 FEMcurso.nb
Printed by Mathematica for Students
ã Estos son los nodos del mallado:
nodos = imsGetNodes@mallaD;numNodos = Length@nodosD;ultimoNodoId = numNodos;
Print@"Los nodos son: ", nodosD
Los nodos son: :imsNode@1, 80, 0<, 1, 880.<<D, imsNodeB2, :23, 0>, 1, 880.<<F,
imsNodeB3, : 43, 0>, 1, 880.<<F, imsNode@4, 82, 0<, 1, 880.<<D,
imsNodeB5, :0, 2
3>, 1, 880.<<F, imsNodeB6, :2
3,2
3>, 0, 880.<<F,
imsNodeB7, : 43,2
3>, 0, 880.<<F, imsNodeB8, :2, 2
3>, 1, 880.<<F,
imsNodeB9, :0, 4
3>, 1, 880.<<F, imsNodeB10, :2
3,4
3>, 0, 880.<<F,
imsNodeB11, : 43,4
3>, 0, 880.<<F, imsNodeB12, :2, 4
3>, 1, 880.<<F,
imsNode@13, 80, 2<, 1, 880.<<D, imsNodeB14, : 23, 2>, 1, 880.<<F,
imsNodeB15, : 43, 2>, 1, 880.<<F, imsNode@16, 82, 2<, 1, 880.<<D>
ã Estos son los elementos del mallado:
elementos = imsGetElements@mallaD;
Print@"Los elementos son: ", elementosDLos elementos son: 8imsQuadLinear1DOF@1, 81, 2, 6, 5<, 0D,
imsQuadLinear1DOF@2, 82, 3, 7, 6<, 0D, imsQuadLinear1DOF@3, 83, 4, 8, 7<, 0D,imsQuadLinear1DOF@4, 85, 6, 10, 9<, 0D, imsQuadLinear1DOF@5, 86, 7, 11, 10<, 0D,imsQuadLinear1DOF@6, 87, 8, 12, 11<, 0D, imsQuadLinear1DOF@7, 89, 10, 14, 13<, 0D,imsQuadLinear1DOF@8, 810, 11, 15, 14<, 0D, imsQuadLinear1DOF@9, 811, 12, 16, 15<, 0D<
ã En este ejemplo con cuadriláteros, a cada elemento le corresponden cuatro nodos:
nodosPorElemento = imsGetIncidentsIds@elementosD881, 2, 6, 5<, 82, 3, 7, 6<, 83, 4, 8, 7<, 85, 6, 10, 9<, 86, 7, 11, 10<,87, 8, 12, 11<, 89, 10, 14, 13<, 810, 11, 15, 14<, 811, 12, 16, 15<<
FEMcurso.nb 51
Printed by Mathematica for Students
ã Hay una matriz local por cada elemento. Después cada matriz local será “ensamblada” en la matriz global, en lo renglones y columnas que corresponden a los nodos del elemento:
matrices = TableBimsMakeElementMatrixB0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
,
nodosPorElemento@@jDD, nodosPorElemento@@jDDF, 8j, 1, numElem<F
8imsElementMatrix@880, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<<, 81, 2, 6, 5<, 81, 2, 6, 5<D,
imsElementMatrix@880, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<<,82, 3, 7, 6<, 82, 3, 7, 6<D, imsElementMatrix@880, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<<, 83, 4, 8, 7<, 83, 4, 8, 7<D,
imsElementMatrix@880, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<<,85, 6, 10, 9<, 85, 6, 10, 9<D,
imsElementMatrix@880, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<<,86, 7, 11, 10<, 86, 7, 11, 10<D,
imsElementMatrix@880, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<<,87, 8, 12, 11<, 87, 8, 12, 11<D,
imsElementMatrix@880, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<<,89, 10, 14, 13<, 89, 10, 14, 13<D,
imsElementMatrix@880, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<<,810, 11, 15, 14<, 810, 11, 15, 14<D,
imsElementMatrix@880, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<, 80, 0, 0, 0<<,811, 12, 16, 15<, 811, 12, 16, 15<D<
ã Hay un vector local de fuerzas, o cargas, por cada elemento. Después ese vector local será “ensamblado” en el vector global, en los renglones que corresponden a los nodos del elemento:
cargas = TableBimsMakeElementMatrixB0
0
0
0
,
nodosPorElemento@@jDD, nodosPorElemento@@jDDF, 8j, 1, numElem<F
8imsElementMatrix@880<, 80<, 80<, 80<<, 81, 2, 6, 5<, 81, 2, 6, 5<D,imsElementMatrix@880<, 80<, 80<, 80<<, 82, 3, 7, 6<, 82, 3, 7, 6<D,imsElementMatrix@880<, 80<, 80<, 80<<, 83, 4, 8, 7<, 83, 4, 8, 7<D,imsElementMatrix@880<, 80<, 80<, 80<<, 85, 6, 10, 9<, 85, 6, 10, 9<D,imsElementMatrix@880<, 80<, 80<, 80<<, 86, 7, 11, 10<, 86, 7, 11, 10<D,imsElementMatrix@880<, 80<, 80<, 80<<, 87, 8, 12, 11<, 87, 8, 12, 11<D,imsElementMatrix@880<, 80<, 80<, 80<<, 89, 10, 14, 13<, 89, 10, 14, 13<D,imsElementMatrix@880<, 80<, 80<, 80<<, 810, 11, 15, 14<, 810, 11, 15, 14<D,imsElementMatrix@880<, 80<, 80<, 80<<, 811, 12, 16, 15<, 811, 12, 16, 15<D<
52 FEMcurso.nb
Printed by Mathematica for Students
ã El coeficiente p(x,y) en la ecuación diferencial −∂xHp@x, yD ∂xz@x, yDL + q@x, yD ∗ z@x, yD � f@x, yDes el único término diferente de cero en la función tensorial de difusión:
funcionDifusion@marker_, x_, y_D := 88p@x, yD, 0<, 80, 0<<;
Print@ "funcionDifusion@marker,x,yD=",MatrixForm@funcionDifusion@marker, x, yDD D
funcionDifusion@marker,x,yD= x2 0
0 0
FEMcurso.nb 53
Printed by Mathematica for Students
ã Aquí se calcula el efecto de la “función tensorial de difusión“ en las matrices y cargas (o sea, en las ecuaciones) de cada elemento:
matricesycargas =
Table@imsNFEMDiffusion@8matrices@@jDD, cargas@@jDD<,elementos@@jDD,imsGetNodes@malla, nodosPorElemento@@jDDD, funcionDifusionD,
8j, 1, numElem<D
54 FEMcurso.nb
Printed by Mathematica for Students
88imsElementMatrix@880.0493827, −0.0493827, −0.0246914, 0.0246914<,8−0.0493827, 0.0493827, 0.0246914, −0.0246914<,8−0.0246914, 0.0246914, 0.0493827, −0.0493827<,80.0246914, −0.0246914, −0.0493827, 0.0493827<<, 81, 2, 6, 5<, 81, 2, 6, 5<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 81, 2, 6, 5<, 81, 2, 6, 5<D<,8imsElementMatrix@880.345679, −0.345679, −0.17284, 0.17284<, 8−0.345679,
0.345679, 0.17284, −0.17284<, 8−0.17284, 0.17284, 0.345679, −0.345679<,80.17284, −0.17284, −0.345679, 0.345679<<, 82, 3, 7, 6<, 82, 3, 7, 6<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 82, 3, 7, 6<, 82, 3, 7, 6<D<,8imsElementMatrix@880.938272, −0.938272, −0.469136, 0.469136<, 8−0.938272,
0.938272, 0.469136, −0.469136<, 8−0.469136, 0.469136, 0.938272, −0.938272<,80.469136, −0.469136, −0.938272, 0.938272<<, 83, 4, 8, 7<, 83, 4, 8, 7<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 83, 4, 8, 7<, 83, 4, 8, 7<D<,8imsElementMatrix@880.0493827, −0.0493827, −0.0246914, 0.0246914<,
8−0.0493827, 0.0493827, 0.0246914, −0.0246914<,8−0.0246914, 0.0246914, 0.0493827, −0.0493827<,80.0246914, −0.0246914, −0.0493827, 0.0493827<<, 85, 6, 10, 9<, 85, 6, 10, 9<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 85, 6, 10, 9<, 85, 6, 10, 9<D<,8imsElementMatrix@880.345679, −0.345679, −0.17284, 0.17284<, 8−0.345679,
0.345679, 0.17284, −0.17284<, 8−0.17284, 0.17284, 0.345679, −0.345679<,80.17284, −0.17284, −0.345679, 0.345679<<, 86, 7, 11, 10<, 86, 7, 11, 10<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 86, 7, 11, 10<, 86, 7, 11, 10<D<,8imsElementMatrix@880.938272, −0.938272, −0.469136, 0.469136<, 8−0.938272,
0.938272, 0.469136, −0.469136<, 8−0.469136, 0.469136, 0.938272, −0.938272<,80.469136, −0.469136, −0.938272, 0.938272<<, 87, 8, 12, 11<, 87, 8, 12, 11<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 87, 8, 12, 11<, 87, 8, 12, 11<D<,8imsElementMatrix@880.0493827, −0.0493827, −0.0246914, 0.0246914<,
8−0.0493827, 0.0493827, 0.0246914, −0.0246914<,8−0.0246914, 0.0246914, 0.0493827, −0.0493827<, 80.0246914,−0.0246914, −0.0493827, 0.0493827<<, 89, 10, 14, 13<, 89, 10, 14, 13<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 89, 10, 14, 13<, 89, 10, 14, 13<D<,8imsElementMatrix@880.345679, −0.345679, −0.17284, 0.17284<, 8−0.345679,
0.345679, 0.17284, −0.17284<, 8−0.17284, 0.17284, 0.345679, −0.345679<,80.17284, −0.17284, −0.345679, 0.345679<<, 810, 11, 15, 14<, 810, 11, 15, 14<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 810, 11, 15, 14<, 810, 11, 15, 14<D<,8imsElementMatrix@880.938272, −0.938272, −0.469136, 0.469136<,
8−0.938272, 0.938272, 0.469136, −0.469136<, 8−0.469136, 0.469136,
0.938272, −0.938272<, 80.469136, −0.469136, −0.938272, 0.938272<<,811, 12, 16, 15<, 811, 12, 16, 15<D, imsElementMatrix@880<, 80<, 80<, 80<<, 811, 12, 16, 15<, 811, 12, 16, 15<D<<
FEMcurso.nb 55
Printed by Mathematica for Students
ã Actualizamos la lista de matrices
matrices = matricesycargas@@All, 1DD8imsElementMatrix@880.0493827, −0.0493827, −0.0246914, 0.0246914<,
8−0.0493827, 0.0493827, 0.0246914, −0.0246914<,8−0.0246914, 0.0246914, 0.0493827, −0.0493827<,80.0246914, −0.0246914, −0.0493827, 0.0493827<<, 81, 2, 6, 5<, 81, 2, 6, 5<D,
imsElementMatrix@880.345679, −0.345679, −0.17284, 0.17284<, 8−0.345679,0.345679, 0.17284, −0.17284<, 8−0.17284, 0.17284, 0.345679, −0.345679<,
80.17284, −0.17284, −0.345679, 0.345679<<, 82, 3, 7, 6<, 82, 3, 7, 6<D,imsElementMatrix@880.938272, −0.938272, −0.469136, 0.469136<,
8−0.938272, 0.938272, 0.469136, −0.469136<,8−0.469136, 0.469136, 0.938272, −0.938272<,80.469136, −0.469136, −0.938272, 0.938272<<, 83, 4, 8, 7<, 83, 4, 8, 7<D,
imsElementMatrix@880.0493827, −0.0493827, −0.0246914, 0.0246914<,8−0.0493827, 0.0493827, 0.0246914, −0.0246914<,8−0.0246914, 0.0246914, 0.0493827, −0.0493827<,80.0246914, −0.0246914, −0.0493827, 0.0493827<<, 85, 6, 10, 9<, 85, 6, 10, 9<D,
imsElementMatrix@880.345679, −0.345679, −0.17284, 0.17284<, 8−0.345679,0.345679, 0.17284, −0.17284<, 8−0.17284, 0.17284, 0.345679, −0.345679<,
80.17284, −0.17284, −0.345679, 0.345679<<, 86, 7, 11, 10<, 86, 7, 11, 10<D,imsElementMatrix@880.938272, −0.938272, −0.469136, 0.469136<,
8−0.938272, 0.938272, 0.469136, −0.469136<,8−0.469136, 0.469136, 0.938272, −0.938272<,80.469136, −0.469136, −0.938272, 0.938272<<, 87, 8, 12, 11<, 87, 8, 12, 11<D,
imsElementMatrix@880.0493827, −0.0493827, −0.0246914, 0.0246914<,8−0.0493827, 0.0493827, 0.0246914, −0.0246914<,8−0.0246914, 0.0246914, 0.0493827, −0.0493827<,80.0246914, −0.0246914, −0.0493827, 0.0493827<<,
89, 10, 14, 13<, 89, 10, 14, 13<D, imsElementMatrix@880.345679, −0.345679, −0.17284, 0.17284<, 8−0.345679, 0.345679,
0.17284, −0.17284<, 8−0.17284, 0.17284, 0.345679, −0.345679<,80.17284, −0.17284, −0.345679, 0.345679<<, 810, 11, 15, 14<, 810, 11, 15, 14<D,
imsElementMatrix@880.938272, −0.938272, −0.469136, 0.469136<,8−0.938272, 0.938272, 0.469136, −0.469136<,8−0.469136, 0.469136, 0.938272, −0.938272<, 80.469136, −0.469136,
−0.938272, 0.938272<<, 811, 12, 16, 15<, 811, 12, 16, 15<D<
56 FEMcurso.nb
Printed by Mathematica for Students
ã Actualizamos la lista de cargas:
cargas = matricesycargas@@All, 2DD8imsElementMatrix@880<, 80<, 80<, 80<<, 81, 2, 6, 5<, 81, 2, 6, 5<D,imsElementMatrix@880<, 80<, 80<, 80<<, 82, 3, 7, 6<, 82, 3, 7, 6<D,imsElementMatrix@880<, 80<, 80<, 80<<, 83, 4, 8, 7<, 83, 4, 8, 7<D,imsElementMatrix@880<, 80<, 80<, 80<<, 85, 6, 10, 9<, 85, 6, 10, 9<D,imsElementMatrix@880<, 80<, 80<, 80<<, 86, 7, 11, 10<, 86, 7, 11, 10<D,imsElementMatrix@880<, 80<, 80<, 80<<, 87, 8, 12, 11<, 87, 8, 12, 11<D,imsElementMatrix@880<, 80<, 80<, 80<<, 89, 10, 14, 13<, 89, 10, 14, 13<D,imsElementMatrix@880<, 80<, 80<, 80<<, 810, 11, 15, 14<, 810, 11, 15, 14<D,imsElementMatrix@880<, 80<, 80<, 80<<, 811, 12, 16, 15<, 811, 12, 16, 15<D<
ã El coeficiente q(x,y) en la ecuación −∂xHp@x, yD ∂xz@x, yDL + q@x, yD ∗ z@x, yD � f@x, yDes la “función de reacción”:
funcionReaccion@marker_, x_, y_D := q@x, yD;
Print@"funcionReaccion@marker,x,yD=", funcionReaccion@marker, x, yDDfuncionReaccion@marker,x,yD=30
FEMcurso.nb 57
Printed by Mathematica for Students
ã Aquí se calcula el efecto de la “función de reacción“ en las matrices y cargas (o sea, en las ecuaciones) de cada elemento:
matricesycargas =
Table@imsNFEMReaction@8matrices@@jDD, cargas@@jDD<,elementos@@jDD,imsGetNodes@malla, nodosPorElemento@@jDDD, funcionReaccionD,
8j, 1, numElem<D88imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358, 1.53086,
0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,80.765432, 0.345679, 0.691358, 1.53086<<, 81, 2, 6, 5<, 81, 2, 6, 5<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 81, 2, 6, 5<, 81, 2, 6, 5<D<,8imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,
1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,80.91358, 0.197531, 0.395062, 1.82716<<, 82, 3, 7, 6<, 82, 3, 7, 6<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 82, 3, 7, 6<, 82, 3, 7, 6<D<,8imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<, 8−0.197531,
2.41975, 1.20988, −0.0987654<, 8−0.0987654, 1.20988, 2.41975, −0.197531<,81.20988, −0.0987654, −0.197531, 2.41975<<, 83, 4, 8, 7<, 83, 4, 8, 7<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 83, 4, 8, 7<, 83, 4, 8, 7<D<,8imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358,
1.53086, 0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,80.765432, 0.345679, 0.691358, 1.53086<<, 85, 6, 10, 9<, 85, 6, 10, 9<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 85, 6, 10, 9<, 85, 6, 10, 9<D<,8imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,
1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,80.91358, 0.197531, 0.395062, 1.82716<<, 86, 7, 11, 10<, 86, 7, 11, 10<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 86, 7, 11, 10<, 86, 7, 11, 10<D<,8imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<, 8−0.197531,
2.41975, 1.20988, −0.0987654<, 8−0.0987654, 1.20988, 2.41975, −0.197531<,81.20988, −0.0987654, −0.197531, 2.41975<<, 87, 8, 12, 11<, 87, 8, 12, 11<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 87, 8, 12, 11<, 87, 8, 12, 11<D<,8imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358,
1.53086, 0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,80.765432, 0.345679, 0.691358, 1.53086<<, 89, 10, 14, 13<, 89, 10, 14, 13<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 89, 10, 14, 13<, 89, 10, 14, 13<D<,8imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,
1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,80.91358, 0.197531, 0.395062, 1.82716<<, 810, 11, 15, 14<, 810, 11, 15, 14<D,
imsElementMatrix@880<, 80<, 80<, 80<<, 810, 11, 15, 14<, 810, 11, 15, 14<D<,8imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<,
8−0.197531, 2.41975, 1.20988, −0.0987654<, 8−0.0987654, 1.20988,
2.41975, −0.197531<, 81.20988, −0.0987654, −0.197531, 2.41975<<,811, 12, 16, 15<, 811, 12, 16, 15<D, imsElementMatrix@880<, 80<, 80<, 80<<, 811, 12, 16, 15<, 811, 12, 16, 15<D<<
58 FEMcurso.nb
Printed by Mathematica for Students
ã Actualizamos la lista de matrices:
matrices = matricesycargas@@All, 1DD8imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358,
1.53086, 0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,80.765432, 0.345679, 0.691358, 1.53086<<, 81, 2, 6, 5<, 81, 2, 6, 5<D,
imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,
80.91358, 0.197531, 0.395062, 1.82716<<, 82, 3, 7, 6<, 82, 3, 7, 6<D,imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<,
8−0.197531, 2.41975, 1.20988, −0.0987654<,8−0.0987654, 1.20988, 2.41975, −0.197531<,81.20988, −0.0987654, −0.197531, 2.41975<<, 83, 4, 8, 7<, 83, 4, 8, 7<D,
imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358,1.53086, 0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,
80.765432, 0.345679, 0.691358, 1.53086<<, 85, 6, 10, 9<, 85, 6, 10, 9<D,imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,
1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,80.91358, 0.197531, 0.395062, 1.82716<<, 86, 7, 11, 10<, 86, 7, 11, 10<D,
imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<,8−0.197531, 2.41975, 1.20988, −0.0987654<,8−0.0987654, 1.20988, 2.41975, −0.197531<,81.20988, −0.0987654, −0.197531, 2.41975<<, 87, 8, 12, 11<, 87, 8, 12, 11<D,
imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358,1.53086, 0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,
80.765432, 0.345679, 0.691358, 1.53086<<, 89, 10, 14, 13<, 89, 10, 14, 13<D,imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,
1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,80.91358, 0.197531, 0.395062, 1.82716<<, 810, 11, 15, 14<, 810, 11, 15, 14<D,
imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<,8−0.197531, 2.41975, 1.20988, −0.0987654<,8−0.0987654, 1.20988, 2.41975, −0.197531<,81.20988, −0.0987654, −0.197531, 2.41975<<, 811, 12, 16, 15<, 811, 12, 16, 15<D<
ã Actualizamos la lista de cargas:
cargas = matricesycargas@@All, 2DD8imsElementMatrix@880<, 80<, 80<, 80<<, 81, 2, 6, 5<, 81, 2, 6, 5<D,imsElementMatrix@880<, 80<, 80<, 80<<, 82, 3, 7, 6<, 82, 3, 7, 6<D,imsElementMatrix@880<, 80<, 80<, 80<<, 83, 4, 8, 7<, 83, 4, 8, 7<D,imsElementMatrix@880<, 80<, 80<, 80<<, 85, 6, 10, 9<, 85, 6, 10, 9<D,imsElementMatrix@880<, 80<, 80<, 80<<, 86, 7, 11, 10<, 86, 7, 11, 10<D,imsElementMatrix@880<, 80<, 80<, 80<<, 87, 8, 12, 11<, 87, 8, 12, 11<D,imsElementMatrix@880<, 80<, 80<, 80<<, 89, 10, 14, 13<, 89, 10, 14, 13<D,imsElementMatrix@880<, 80<, 80<, 80<<, 810, 11, 15, 14<, 810, 11, 15, 14<D,imsElementMatrix@880<, 80<, 80<, 80<<, 811, 12, 16, 15<, 811, 12, 16, 15<D<
FEMcurso.nb 59
Printed by Mathematica for Students
ã El coeficiente f(x,y) en la ecuación −∂xHp@x, yD ∂xz@x, yDL + q@x, yD ∗ z@x, yD � f@x, yDes la “función de carga”:
funcionCarga@marker_, x_, y_D := f@x, yD;
Print@"funcionCarga@marker,x,yD=", funcionCarga@marker, x, yDD
funcionCarga@marker,x,yD=−10 x 3
4− y
ã Aquí se calcula el efecto de la “función de carga“ en las matrices y cargas (o sea, en las ecuaciones) de cada elemento:
matricesycargas =
Table@imsNFEMLoad@8matrices@@jDD, cargas@@jDD<,elementos@@jDD,imsGetNodes@malla, nodosPorElemento@@jDDD, funcionCargaD,
8j, 1, numElem<D
60 FEMcurso.nb
Printed by Mathematica for Students
88imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358, 1.53086,
0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,80.765432, 0.345679, 0.691358, 1.53086<<, 81, 2, 6, 5<, 81, 2, 6, 5<D,
imsElementMatrix@88−0.130316<, 8−0.260631<, 8−0.150892<, 8−0.0754458<<,81, 2, 6, 5<, 81<D<,
8imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,
80.91358, 0.197531, 0.395062, 1.82716<<, 82, 3, 7, 6<, 82, 3, 7, 6<D,imsElementMatrix@88−0.521262<, 8−0.651578<, 8−0.377229<, 8−0.301783<<,82, 3, 7, 6<, 81<D<,
8imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<, 8−0.197531,2.41975, 1.20988, −0.0987654<, 8−0.0987654, 1.20988, 2.41975, −0.197531<,
81.20988, −0.0987654, −0.197531, 2.41975<<, 83, 4, 8, 7<, 83, 4, 8, 7<D,imsElementMatrix@88−0.912209<, 8−1.04252<, 8−0.603567<, 8−0.528121<<,83, 4, 8, 7<, 81<D<,
8imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358,1.53086, 0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,
80.765432, 0.345679, 0.691358, 1.53086<<, 85, 6, 10, 9<, 85, 6, 10, 9<D,imsElementMatrix@880.0342936<, 80.0685871<, 80.178326<, 80.0891632<<,85, 6, 10, 9<, 81<D<,
8imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,
80.91358, 0.197531, 0.395062, 1.82716<<, 86, 7, 11, 10<, 86, 7, 11, 10<D,imsElementMatrix@880.137174<, 80.171468<, 80.445816<, 80.356653<<,86, 7, 11, 10<, 81<D<,
8imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<, 8−0.197531,2.41975, 1.20988, −0.0987654<, 8−0.0987654, 1.20988, 2.41975, −0.197531<,
81.20988, −0.0987654, −0.197531, 2.41975<<, 87, 8, 12, 11<, 87, 8, 12, 11<D,imsElementMatrix@880.240055<, 80.274348<, 80.713306<, 80.624143<<,87, 8, 12, 11<, 81<D<,
8imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358,1.53086, 0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,
80.765432, 0.345679, 0.691358, 1.53086<<, 89, 10, 14, 13<, 89, 10, 14, 13<D,imsElementMatrix@880.198903<, 80.397805<, 80.507545<, 80.253772<<,89, 10, 14, 13<, 81<D<,
8imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,
80.91358, 0.197531, 0.395062, 1.82716<<, 810, 11, 15, 14<, 810, 11, 15, 14<D,imsElementMatrix@880.79561<, 80.994513<, 81.26886<, 81.01509<<,810, 11, 15, 14<, 81<D<,
8imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<,8−0.197531, 2.41975, 1.20988, −0.0987654<, 8−0.0987654, 1.20988,
2.41975, −0.197531<, 81.20988, −0.0987654, −0.197531, 2.41975<<,811, 12, 16, 15<, 811, 12, 16, 15<D, imsElementMatrix@881.39232<, 81.59122<, 82.03018<, 81.77641<<, 811, 12, 16, 15<, 81<D<<
FEMcurso.nb 61
Printed by Mathematica for Students
ã Actualizamos la lista de matrices:
matrices = matricesycargas@@All, 1DD8imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358,
1.53086, 0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,80.765432, 0.345679, 0.691358, 1.53086<<, 81, 2, 6, 5<, 81, 2, 6, 5<D,
imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,
80.91358, 0.197531, 0.395062, 1.82716<<, 82, 3, 7, 6<, 82, 3, 7, 6<D,imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<,
8−0.197531, 2.41975, 1.20988, −0.0987654<,8−0.0987654, 1.20988, 2.41975, −0.197531<,81.20988, −0.0987654, −0.197531, 2.41975<<, 83, 4, 8, 7<, 83, 4, 8, 7<D,
imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358,1.53086, 0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,
80.765432, 0.345679, 0.691358, 1.53086<<, 85, 6, 10, 9<, 85, 6, 10, 9<D,imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,
1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,80.91358, 0.197531, 0.395062, 1.82716<<, 86, 7, 11, 10<, 86, 7, 11, 10<D,
imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<,8−0.197531, 2.41975, 1.20988, −0.0987654<,8−0.0987654, 1.20988, 2.41975, −0.197531<,81.20988, −0.0987654, −0.197531, 2.41975<<, 87, 8, 12, 11<, 87, 8, 12, 11<D,
imsElementMatrix@881.53086, 0.691358, 0.345679, 0.765432<, 80.691358,1.53086, 0.765432, 0.345679<, 80.345679, 0.765432, 1.53086, 0.691358<,
80.765432, 0.345679, 0.691358, 1.53086<<, 89, 10, 14, 13<, 89, 10, 14, 13<D,imsElementMatrix@881.82716, 0.395062, 0.197531, 0.91358<, 80.395062,
1.82716, 0.91358, 0.197531<, 80.197531, 0.91358, 1.82716, 0.395062<,80.91358, 0.197531, 0.395062, 1.82716<<, 810, 11, 15, 14<, 810, 11, 15, 14<D,
imsElementMatrix@882.41975, −0.197531, −0.0987654, 1.20988<,8−0.197531, 2.41975, 1.20988, −0.0987654<,8−0.0987654, 1.20988, 2.41975, −0.197531<,81.20988, −0.0987654, −0.197531, 2.41975<<, 811, 12, 16, 15<, 811, 12, 16, 15<D<
62 FEMcurso.nb
Printed by Mathematica for Students
ã Actualizamos la lista de cargas:
cargas = matricesycargas@@All, 2DD8imsElementMatrix@
88−0.130316<, 8−0.260631<, 8−0.150892<, 8−0.0754458<<, 81, 2, 6, 5<, 81<D,imsElementMatrix@88−0.521262<, 8−0.651578<, 8−0.377229<, 8−0.301783<<,82, 3, 7, 6<, 81<D, imsElementMatrix@88−0.912209<, 8−1.04252<, 8−0.603567<, 8−0.528121<<, 83, 4, 8, 7<, 81<D,
imsElementMatrix@880.0342936<, 80.0685871<, 80.178326<, 80.0891632<<,85, 6, 10, 9<, 81<D, imsElementMatrix@880.137174<, 80.171468<, 80.445816<, 80.356653<<, 86, 7, 11, 10<, 81<D,
imsElementMatrix@880.240055<, 80.274348<, 80.713306<, 80.624143<<,87, 8, 12, 11<, 81<D, imsElementMatrix@880.198903<, 80.397805<, 80.507545<, 80.253772<<, 89, 10, 14, 13<, 81<D,
imsElementMatrix@880.79561<, 80.994513<, 81.26886<, 81.01509<<,810, 11, 15, 14<, 81<D, imsElementMatrix@881.39232<, 81.59122<, 82.03018<, 81.77641<<, 811, 12, 16, 15<, 81<D<
FEMcurso.nb 63
Printed by Mathematica for Students
ã A continuación se “ensamblan” las matrices de cada elemento para formar la matriz global, y se “ensamblan” los vectores de carga de cada elemento para formar el vector de carga global:
matrizGlobal = SparseArray@8<, 8numNodos, numNodos<D;cargaGlobal = Table@0, 8numNodos<, 81<D;
Do@imsAssemble@matrices@@jDD, matrizGlobalD;imsAssemble@cargas@@jDD, cargaGlobalD,8j, 1, numElem<
D;
parametros = TableAcj, 8j, 1, numNodos<E;vectorCargas = Flatten@cargaGlobalD;
Print@MatrixForm@matrizGlobalD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@vectorCargasDD
1.53086 0.691358 0 0 0.765432 0.345679 0 0
0.691358 3.35802 0.395062 0 0.345679 1.67901 0.197531 0
0 0.395062 4.24691 −0.197531 0 0.197531 2.12346 −0.0987654
0 0 −0.197531 2.41975 0 0 −0.0987654 1.20988
0.765432 0.345679 0 0 3.06173 1.38272 0 0 0.765432
0.345679 1.67901 0.197531 0 1.38272 6.71605 0.790123 0 0.345679
0 0.197531 2.12346 −0.0987654 0 0.790123 8.49383 −0.395062
0 0 −0.0987654 1.20988 0 0 −0.395062 4.83951
0 0 0 0 0.765432 0.345679 0 0 3.06173
0 0 0 0 0.345679 1.67901 0.197531 0 1.38272
0 0 0 0 0 0.197531 2.12346 −0.0987654
0 0 0 0 0 0 −0.0987654 1.20988
0 0 0 0 0 0 0 0 0.765432
0 0 0 0 0 0 0 0 0.345679
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
ã El siguiente paso es insertar las condiciones de frontera, lo cual modificará a la matriz global y al vector global de cargas. Primero seleccionamos todos los nodos que están en la frontera izquierda (los que tienen coordenadas Hxa,y)):
nodosIzquierda = Select@nodos, Function@nodo, Part@imsGetCoords@nodoD, 1D � xaDD
:imsNode@1, 80, 0<, 1, 880.<<D, imsNodeB5, :0, 2
3>, 1, 880.<<F,
imsNodeB9, :0, 4
3>, 1, 880.<<F, imsNode@13, 80, 2<, 1, 880.<<D>
64 FEMcurso.nb
Printed by Mathematica for Students
ã A continuación insertamos la condición de que la solución vale zxa en cada nodo de la frontera izquierda:
Do@imsDirichlet@8matrizGlobal, vectorCargas<,imsGetIds@ nodosIzquierda@@jDD D, zxaD,
8j, 1, Length@nodosIzquierdaD<D;
Print@MatrixForm@matrizGlobalD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@vectorCargasDD
1. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 3.35802 0.395062 0. 0. 1.67901 0.197531 0. 0. 0.
0. 0.395062 4.24691 −0.197531 0. 0.197531 2.12346 −0.0987654 0. 0.
0. 0. −0.197531 2.41975 0. 0. −0.0987654 1.20988 0. 0.
0. 0. 0. 0. 1. 0. 0. 0. 0. 0.
0. 1.67901 0.197531 0. 0. 6.71605 0.790123 0. 0. 1.67901 0.197531
0. 0.197531 2.12346 −0.0987654 0. 0.790123 8.49383 −0.395062 0. 0.197531 2.12346
0. 0. −0.0987654 1.20988 0. 0. −0.395062 4.83951 0. 0. −0.0987654
0. 0. 0. 0. 0. 0. 0. 0. 1. 0.
0. 0. 0. 0. 0. 1.67901 0.197531 0. 0. 6.71605 0.790123
0. 0. 0. 0. 0. 0.197531 2.12346 −0.0987654 0. 0.790123 8.49383
0. 0. 0. 0. 0. 0. −0.0987654 1.20988 0. 0. −0.395062
0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 1.67901 0.197531
0. 0. 0. 0. 0. 0. 0. 0. 0. 0.197531 2.12346
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. −0.0987654
ã Ahora seleccionamos todos los nodos que están en la frontera derecha (los que tienen coordenadas Hxb,y)):
nodosDerecha = Select@nodos, Function@nodo, Part@imsGetCoords@nodoD, 1D � xbDD
:imsNode@4, 82, 0<, 1, 880.<<D, imsNodeB8, :2, 2
3>, 1, 880.<<F,
imsNodeB12, :2, 4
3>, 1, 880.<<F, imsNode@16, 82, 2<, 1, 880.<<D>
FEMcurso.nb 65
Printed by Mathematica for Students
ã A continuación insertamos la condición de que la solución vale zxb en cada nodo de la frontera derecha:
Do@imsDirichlet@8matrizGlobal, vectorCargas<,imsGetIds@ nodosDerecha@@jDD D, zxbD,
8j, 1, Length@nodosDerechaD<D;
Print@MatrixForm@matrizGlobalD, ".",
MatrixForm@parametrosD, "==",
MatrixForm@vectorCargasDD
1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 3.35802 0.395062 0. 0. 1.67901 0.197531 0. 0. 0. 0. 0. 0. 0.
0. 0.395062 4.24691 0. 0. 0.197531 2.12346 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 1.67901 0.197531 0. 0. 6.71605 0.790123 0. 0. 1.67901 0.197531 0. 0. 0.
0. 0.197531 2.12346 0. 0. 0.790123 8.49383 0. 0. 0.197531 2.12346 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 1.67901 0.197531 0. 0. 6.71605 0.790123 0. 0. 1.67901
0. 0. 0. 0. 0. 0.197531 2.12346 0. 0. 0.790123 8.49383 0. 0. 0.197531
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 1.67901 0.197531 0. 0. 3.35802
0. 0. 0. 0. 0. 0. 0. 0. 0. 0.197531 2.12346 0. 0. 0.395062
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
ã A continuación resolvemos el sistema de ecuaciones, con lo cual obtenemos el valor de la solución aproximada en cada nodo:
solvector = LinearSolve@matrizGlobal, vectorCargasD80., −0.184302, −0.308437, 0.5, 0., −0.0229368, −0.0133702,
0.5, 0., 0.138428, 0.281697, 0.5, 0., 0.299793, 0.576763, 0.5<
66 FEMcurso.nb
Printed by Mathematica for Students
ã A partir de los nodos originales construimos nuevos nodos, esta vez cada nodo nuevo incluye el valor de la solución:
nodosNuevos =
Table@imsSetValues@nodos@@jDD, 88 solvector@@jDD <<D, 8j, 1, numNodos<D
:imsNode@1, 80, 0<, 1, 880.<<D, imsNodeB2, : 23, 0>, 1, 88−0.184302<<F,
imsNodeB3, : 43, 0>, 1, 88−0.308437<<F, imsNode@4, 82, 0<, 1, 880.5<<D,
imsNodeB5, :0, 2
3>, 1, 880.<<F, imsNodeB6, : 2
3,2
3>, 0, 88−0.0229368<<F,
imsNodeB7, : 43,2
3>, 0, 88−0.0133702<<F, imsNodeB8, :2, 2
3>, 1, 880.5<<F,
imsNodeB9, :0, 4
3>, 1, 880.<<F, imsNodeB10, : 2
3,4
3>, 0, 880.138428<<F,
imsNodeB11, : 43,4
3>, 0, 880.281697<<F, imsNodeB12, :2, 4
3>, 1, 880.5<<F,
imsNode@13, 80, 2<, 1, 880.<<D, imsNodeB14, : 23, 2>, 1, 880.299793<<F,
imsNodeB15, : 43, 2>, 1, 880.576763<<F, imsNode@16, 82, 2<, 1, 880.5<<D>
ã Estos son los nuevos nodos en la frontera. Incluyen el valor de la solución:
nodosNuevosFrontera =
nodosNuevos@@ imsGetIds@imsGetBoundaryNodes@mallaD D DD
:imsNode@1, 80, 0<, 1, 880.<<D, imsNodeB2, : 23, 0>, 1, 88−0.184302<<F,
imsNodeB3, : 43, 0>, 1, 88−0.308437<<F, imsNode@4, 82, 0<, 1, 880.5<<D,
imsNodeB5, :0, 2
3>, 1, 880.<<F, imsNodeB8, :2, 2
3>, 1, 880.5<<F,
imsNodeB9, :0, 4
3>, 1, 880.<<F, imsNodeB12, :2, 4
3>, 1, 880.5<<F,
imsNode@13, 80, 2<, 1, 880.<<D, imsNodeB14, : 23, 2>, 1, 880.299793<<F,
imsNodeB15, : 43, 2>, 1, 880.576763<<F, imsNode@16, 82, 2<, 1, 880.5<<D>
FEMcurso.nb 67
Printed by Mathematica for Students
ã Estos son los nuevos nodos interiores. Incluyen el valor de la solución:
nodosNuevosInterior =
nodosNuevos@@ imsGetIds@imsGetInteriorNodes@mallaD D DD
:imsNodeB6, : 23,2
3>, 0, 88−0.0229368<<F, imsNodeB7, :4
3,2
3>, 0, 88−0.0133702<<F,
imsNodeB10, : 23,4
3>, 0, 880.138428<<F, imsNodeB11, :4
3,4
3>, 0, 880.281697<<F>
ã Esta es la nueva malla, con los valores de la solución, como se muestra en la gráfica:
mallaNueva = imsMakeNexus@nodosNuevosFrontera, nodosNuevosInterior, elementosD;
graficaFEM =
Graphics3D@8imsDrawElementSolution@ mallaNueva D
<, Axes → True, PlotLabel → "Solución aproximada con\n Elemento Finito"DSolución aproximada con
Elemento Finito
0.0
0.5
1.0
1.5
2.00.0
0.5
1.0
1.5
2.0
-0.2
0.0
0.2
0.4
68 FEMcurso.nb
Printed by Mathematica for Students
ã A continuación se obtiene la solución analítica exacta, para comparla con la aproximación por Elemento Finito:
solexacta = DSolve@8−∂xHp@x, yD ∂xz@x, yDL + q@x, yD ∗ z@x, yD � f@x, yD,z@xa, yD � zxa, z@xb, yD � zxb<, z@x, yD, 8x, y<D;
exacta@x_, y_D := Evaluate@ReplaceAll@z@x, yD, solexacta@@1DD D D;
graficaExacta =
Plot3D@exacta@x, yD, 8x, xa, xb<, 8y, ya, yb<, PlotLabel → "Solución exacta"D
FEMcurso.nb 69
Printed by Mathematica for Students
ã Aquí se comapara la gráfica de la solución aproximada por Elemento Finito con la gráifca de la solución analítica exacta:
Column@8graficaFEM, graficaExacta<DSolución aproximada con
Elemento Finito
0.00.5
1.01.5
2.00.0
0.5
1.0
1.5
2.0
-0.20.00.20.4
70 FEMcurso.nb
Printed by Mathematica for Students
Recommended