function [ a, f ] = assemble_poisson ( node_num, node_xy, ... element_num, element_node, quad_num, ib ) %% ASSEMBLE_POISSON assembles the system for the Poisson 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. % % Licensing: % % This code is distributed under the GNU LGPL license. % % 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 ELEMENT_NUM, the number of elements. % % Input, integer ELEMENT_NODE(3,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. % % 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 element-th element. % for element = 1 : element_num % % Make a copy of the element. % t3(1:2,1:3) = node_xy(1:2,element_node(1:3,element)); % % Map the quadrature points QUAD_XY to points PHYS_XY in the physical element. % 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) = quad_w(1:quad_num) * area; phys_rhs = rhs ( quad_num, phys_xy ); phys_k = k_coef ( quad_num, phys_xy ); % % Consider the QUAD-th quadrature point.. % for quad = 1 : quad_num % % 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 : 3 i = element_node(test,element); [ bi, dbidx, dbidy ] = basis_11_t3 ( t3, test, phys_xy(1:2,quad) ); f(i) = f(i) + w(quad) * phys_rhs(quad) * bi; % % Consider the BASIS-th basis function, which is used to form the % value of the solution function. % for basis = 1 : 3 j = element_node(basis,element); [ bj, dbjdx, dbjdy ] = basis_11_t3 ( t3, 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 + phys_k(quad) * bj * bi ); end end end end return end