function [ a, f ] = assemble_heat ( node_num, node_xy, node_condition, ... element_order, element_num, element_node, quad_num, ib, time ) %% ASSEMBLE_HEAT assembles the finite element system for the heat equation. % % Discussion: % % The matrix is known to be banded. A special matrix storage format % is used to reduce the space required. Details of this format are % discussed in the routine DGB_FA. % % Modified: % % 22 July 2007 % % Author: % % John Burkardt % % Parameters: % % Input, integer NODE_NUM, the number of nodes. % % Input, real NODE_XY(2,NODE_NUM), the coordinates of nodes. % % Input, integer NODE_CONDITION(NODE_NUM), reports the condition % used to set the unknown associated with the node. % 0, unknown. % 1, finite element equation. % 2, Dirichlet condition; % 3, Neumann condition. % % Input, integer ELEMENT_ORDER, the order of the elements. % % Input, integer ELEMENT_NUM, the number of elements. % % Input, integer ELEMENT_NODE(ELEMENT_ORDER,ELEMENT_NUM); % ELEMENT_NODE(I,J) is the global index of local node I in element J. % % Input, integer QUAD_NUM, the number of quadrature points used in assembly. % % Input, integer IB, the half-bandwidth of the matrix. % % Input, real TIME, the current time. % % Output, real A(3*IB+1,NODE_NUM), the NODE_NUM by NODE_NUM % coefficient matrix, stored in a compressed format. % % Output, real F(NODE_NUM), the right hand side. % % Local parameters: % % Local, real BI, DBIDX, DBIDY, the value of some basis function % and its first derivatives at a quadrature point. % % Local, real BJ, DBJDX, DBJDY, the value of another basis % function and its first derivatives at a quadrature point. % % % Initialize the arrays to zero. % f(1:node_num) = 0.0; a(1:3*ib+1,1:node_num) = 0.0; % % Get the quadrature weights and nodes. % [ quad_w, quad_xy ] = quad_rule ( quad_num ); % % Add up all quantities associated with the TRIANGLE-th triangle. % for element = 1 : element_num % % Make a copy of the triangle. % t3(1:2,1:3) = node_xy(1:2,element_node(1:3,element)); t6(1:2,1:6) = node_xy(1:2,element_node(1:6,element)); % % Map the quadrature points QUAD_XY to points PHYS_XY in the physical triangle. % phys_xy(1:2,1:quad_num) = reference_to_physical_t3 ( t3, quad_num, quad_xy ); area = abs ( triangle_area_2d ( t3 ) ); w(1:quad_num) = area * quad_w(1:quad_num); % % Consider the QUAD-th quadrature point. % for quad = 1 : quad_num k_value = k_coef ( 1, phys_xy(1:2,quad), time ); rhs_value = rhs ( 1, phys_xy(1:2,quad), time ); % % Consider the TEST-th test function. % % We generate an integral for every node associated with an unknown. % But if a node is associated with a boundary condition, we do nothing. % for test = 1 : element_order i = element_node(test,element); [ bi, dbidx, dbidy ] = basis_11_t6 ( t6, test, phys_xy(1:2,quad) ); f(i) = f(i) + w(quad) * rhs_value * bi; % % Consider the BASIS-th basis function, which is used to form the % value of the solution function. % for basis = 1 : element_order j = element_node(basis,element); [ bj, dbjdx, dbjdy ] = basis_11_t6 ( t6, basis, phys_xy(1:2,quad) ); a(i-j+2*ib+1,j) = a(i-j+2*ib+1,j) ... + w(quad) * ( dbidx * dbjdx + dbidy * dbjdy + k_value * bj * bi ); end end end end