function [ a, f ] = dirichlet_apply_sparse ( node_num, node_xy, node_p_variable, ... node_u_variable, node_v_variable, node_p_condition, ... node_u_condition, node_v_condition, variable_num, a, f ) %% DIRICHLET_APPLY_SPARSE accounts for Dirichlet boundary conditions. % % Discussion: % % The finite element stiffness matrix has been set up as a MATLAB % sparse matrix. % % Modified: % % 15 September 2006 % % 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_P_VARIABLE(NODE_NUM), % is the index of the pressure variable associated with the node, % or -1 if there is no associated pressure variable. % % Input, integer NODE_U_VARIABLE(NODE_NUM), % is the index of the horizontal velocity variable associated with the node. % % Input, integer NODE_V_VARIABLE(NODE_NUM), % is the index of the vertical velocity variable associated with the node. % % Input, integer NODE_P_CONDITION(NODE_NUM), % indicates the condition used to determine pressure at a node. % 0, there is no condition at this node. % 1, a finite element equation is used; % 2, a Dirichlet condition is used. % 3, a Neumann condition is used. % % Input, integer NODE_U_CONDITION(NODE_NUM), % indicates the condition used to determine horizontal velocity at a node. % 0, there is no condition at this node. % 1, a finite element equation is used; % 2, a Dirichlet condition is used. % 3, a Neumann condition is used. % % Input, integer NODE_V_CONDITION(NODE_NUM), % indicates the condition used to determine vertical velocity at a node. % 0, there is no condition at this node. % 1, a finite element equation is used; % 2, a Dirichlet condition is used. % 3, a Neumann condition is used. % % Input, integer VARIABLE_NUM, the number of variables. % % Input, real sparse A, the coefficient matrix, stored in MATLAB % sparse format. % % Input, real F(VARIABLE_NUM), the right hand side. % % Output, real sparse A, the matrix has been adjusted for Dirichlet boundary % conditions. % % Output, real F(VARIABLE_NUM), the right hand side has been adjusted % for Dirichlet boundary conditions. % DIRICHLET = 2; for node = 1 : node_num [ u_bc, v_bc, p_bc ] = dirichlet_condition ( 1, node_xy(1:2,node) ); iu = node_u_variable(node); iv = node_v_variable(node); ip = node_p_variable(node); if ( node_u_condition(node) == DIRICHLET ) a(iu,:) = 0.0; a(iu,iu) = 1.0; f(iu) = u_bc; end if ( node_v_condition(node) == DIRICHLET ) a(iv,:) = 0.0; a(iv,iv) = 1.0; f(iv) = v_bc; end if ( 0 < ip ) if ( node_p_condition(node) == DIRICHLET ) a(ip,:) = 0.0; a(ip,ip) = 1.0; f(ip) = p_bc; end end end