function [ h, indx, node, nu, xn, xquad ] = geometry ( ibc, nl, nsub, ... xl, xr ) %% GEOMETRY sets up the geometry for the interval [XL,XR]. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 09 November 2006 % % Author: % % MATLAB version by John Burkardt % % Parameters: % % Input, integer IBC. % IBC declares what the boundary conditions are. % 1, at the left endpoint, U has the value UL, % at the right endpoint, U' has the value UR. % 2, at the left endpoint, U' has the value UL, % at the right endpoint, U has the value UR. % 3, at the left endpoint, U has the value UL, % and at the right endpoint, U has the value UR. % 4, at the left endpoint, U' has the value UL, % at the right endpoint U' has the value UR. % % Input, integer NL. % The number of basis functions used in a single % subinterval. (NL-1) is the degree of the polynomials % used. For this code, NL is fixed at 2, meaning that % piecewise linear functions are used as the basis. % % Input, integer NSUB. % The number of subintervals into which the interval % [XL,XR] is broken. % % Input, real XL. % XL is the left endpoint of the interval over which the % differential equation is being solved. % % Input, real XR. % XR is the right endpoint of the interval over which the % differential equation is being solved. % % Output, real H(N), the length of the subintervals. % % Output, integer INDX(1:N+1). % For a node I, INDX(I) is the index of the unknown % associated with node I. % If INDX(I) is equal to -1, then no unknown is associated % with the node, because a boundary condition fixing the % value of U has been applied at the node instead. % Unknowns are numbered beginning with 1. % If IBC is 2 or 4, then there is an unknown value of U % at node 0, which will be unknown number 1. Otherwise, % unknown number 1 will be associated with node 1. % If IBC is 1 or 4, then there is an unknown value of U % at node N, which will be unknown N or N+1, % depending on whether there was an unknown at node 0. % % Output, integer NODE(NL,N). % For each subinterval I: % NODE(1,I) is the number of the left node, and % NODE(2,I) is the number of the right node. % % Output, integer NU. % NU is the number of unknowns in the linear system. % Depending on the value of IBC, there will be N-1, % N, or N+1 unknown values, which are the coefficients % of basis functions. % % Output, real XN(1:N+1). % XN(I) is the location of the I-th node. XN(1) is XL, % and XN(N+1) is XR. % % Output, real XQUAD(N) % XQUAD(I) is the location of the single quadrature point % in interval I. % % % Set the value of XN, the locations of the nodes. % fprintf ( 1, '\n' ); fprintf ( 1, ' Node Location\n' ); fprintf ( 1, '\n' ); for i = 0 : nsub xn(i+1) = ( ( nsub - i ) * xl ... + ( i ) * xr ) ... / ( nsub ); fprintf ( 1, ' %6d %12f\n', i, xn(i+1) ); end % % Set the lengths of each subinterval. % fprintf ( 1, '\n' ); fprintf ( 1, 'Subint Length\n' ); fprintf ( 1, '\n' ); for i = 1 : nsub h(i) = xn(i+1) - xn(i); fprintf ( 1, ' %6d %12f\n', i, h(i) ); end % % Set the quadrature points, each of which is the midpoint of its subinterval. % fprintf ( 1, '\n' ); fprintf ( 1, 'Subint Quadrature point\n' ); fprintf ( 1, '\n' ); for i = 1 : nsub xquad(i) = 0.5 * ( xn(i) + xn(i+1) ); fprintf ( 1, ' %6d %12f\n', i, xquad(i) ); end % % Set the value of NODE, which records, for each interval, % the node numbers at the left and right. % fprintf ( 1, '\n' ); fprintf ( 1, 'Subint Left Node Right Node\n' ); fprintf ( 1, '\n' ); for i = 1 : nsub node(1,i) = i - 1; node(2,i) = i; fprintf ( 1, ' %6d %6d %6d\n', i, node(1,i), node(2,i) ); end % % Starting with node 0, see if an unknown is associated with % the node. If so, give it an index. % nu = 0; % % Handle first node. % i = 0; if ( ibc == 1 | ibc == 3 ) indx(i+1) = -1; else nu = nu + 1; indx(i+1) = nu; end % % Handle nodes 1 through nsub-1 % for i = 1 : nsub-1 nu = nu + 1; indx(i+1) = nu; end % % Handle the last node. % i = nsub; if ( ibc == 2 | ibc == 3 ) indx(i+1) = -1; else nu = nu + 1; indx(i+1) = nu; end fprintf ( 1, '\n' ); fprintf ( 1, ' Node Unknown\n' ); fprintf ( 1, '\n' ); for i = 0 : nsub fprintf ( 1, ' %6d %6d\n', i, indx(i+1) ); end return end