-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHeatTransfer_NonLinear.m
100 lines (74 loc) · 2.41 KB
/
HeatTransfer_NonLinear.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
%% 1D Nonlinear FEM Code for Heat Equation
%
% -div(k grad U) = f
%
% where the material model is non-linear i.e.
% k = k0(1+Beta U)
%
% This example is from Reddy Nonlinear FEM book.
%
% Author: Abdullah Waseem
% Created: 04-November-2018
% Contact: engineerabdullah@ymail.com
% Initializing
clear; clc; clf; path(pathdef);
addpath FECore/
%% Creating 1D mesh
xstart = 0; % start point
xend = 1; % End point
tne = 20; % Total number of elements.
% Element type: Q1 --> LINEAR, Q2 --> QUADRATIC
elementtype = 'Q2';
% Creating 1D Mesh.
[ L, lnn, nne, el, egnn, tnn, x ] = CreateMesh( elementtype, tne, xstart, xend );
%% Material Properties
k0 = 2e-1 * ones(tne,1); % Conductivity
Beta = 2e-3 * ones(tne,1); % Nonlinearity in the model
%% Finite Element Data
% Gauss Quadrature
ngp = 3;
run('GaussianLegendre');
% Shape Functions
run('ShapeFunctions')
%% Boundary Conditions
tn = 1 : tnn; % Node iterator
p = [tn(1) tn(end)]; % Precribed nodes
f = setdiff(tn, p); % Free nodes
% Initializing solution, and solution at current Newton iteration
un = 273*ones(tnn,1);
% Drichlet BC
un(1) = 500;
un(end) = 300;
up = un; % solution at previous Newton iteration
%% Newton Raphson Algorithm
% Parameters
tol = 1e-8; % Tolerance in the solution
maxiter = 20; % Maximum number of iterations
% Initial calculation of Tangent Matrix 'T' and
% Internal Flux Vector 'FINT'
run('TangentFint')
% Neumann BC
FEXT = zeros(tnn,1);
% Initializing 'du' vector
du = zeros(tnn,1);
cnv = 1; % Initializing convergence variable
iter = 1; % Initializing iteration variable
% Newton Raphson Routine for Nonlinear Solution
while cnv > tol && iter<maxiter
% Solving
du(f,1) = T(f,f) \ ( FEXT(f,1) - FINT(f,1) );
% Incrementing the solution vector
un = un + du;
% Tangent Matrix 'T' and the Internal Flux Vector 'FINT'
run('TangentFint')
% Checking Convergence
cnv = norm(up-un);
disp([' Newton Itr.: ' num2str(iter) ' Conv.:' num2str(cnv)]);
% Assigning solution 'un', at curernt Newton iteration to the previous 'up' one
up = un;
% Incrementing iteration variable.
iter=iter+1;
% Plotting the solution
plot(x,un,'LineWidth',2)
drawnow
end