Home > p2plib > gnbc.m

gnbc

PURPOSE ^

generalized Neumann BC: generate q,g in form for pdetoolbox

SYNOPSIS ^

function bc = gnbc(pneq,varargin)

DESCRIPTION ^

 generalized Neumann BC: generate q,g in form for pdetoolbox
 even length varargin:
   varargin is vector of edgenum pairs (q,g), with one pair per edge 
   of the domain.
 odd length varargin for equal (q,g) on each edge:
   varargin = (edgenum, q, g)
    
 Returns a boundary matrix for a system with pneq components on a domain 
 with generalized Neumann bc per egde given by (q,g) of the form  
                    n*c tensor grad(u) + q*u = g,
 where q is an pneq by pneq matrix and g a vector with pneq components. 
 Both contain strings that may be formulas in terms of u, x, t etc.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function bc = gnbc(pneq,varargin)
0002 % generalized Neumann BC: generate q,g in form for pdetoolbox
0003 % even length varargin:
0004 %   varargin is vector of edgenum pairs (q,g), with one pair per edge
0005 %   of the domain.
0006 % odd length varargin for equal (q,g) on each edge:
0007 %   varargin = (edgenum, q, g)
0008 %
0009 % Returns a boundary matrix for a system with pneq components on a domain
0010 % with generalized Neumann bc per egde given by (q,g) of the form
0011 %                    n*c tensor grad(u) + q*u = g,
0012 % where q is an pneq by pneq matrix and g a vector with pneq components.
0013 % Both contain strings that may be formulas in terms of u, x, t etc.
0014 
0015 % Note: q = [[12;6789];[345;101112]] means q21=6789 in PDEtool GUI.
0016 
0017 if(mod(length(varargin),2)==0) 
0018     edgenum = length(varargin)/2;
0019 else
0020     edgenum = varargin{1};
0021     if(length(varargin)~=3) 
0022         error('argument list has wrong length')
0023     end
0024     q = varargin{2};
0025     g = varargin{3};
0026     for jj=1:edgenum
0027         varargin{2*jj-1} = q;
0028         varargin{2*jj}   = g;
0029     end
0030 end
0031 
0032 bb(1,:)= pneq*ones(edgenum,1); % # of components
0033 bb(2,:)= zeros(edgenum,1); % set # Dirichlet b.c. to zero
0034 
0035 for jj=1:edgenum,
0036     q = varargin{2*jj-1};
0037     g = varargin{2*jj};
0038     % Add lengths of entries of q and g to bb
0039 
0040     qa=q(:); % vector of entries of matrix q
0041     for j=1:length(qa),
0042         qs=mat2str(double(qa(j)));
0043         bb(j+2,jj)=length(qs);
0044         qc = uint8(qs); % ascii codes of characters as vector
0045         bq{j} = qc; 
0046     end
0047 
0048     ga=g(:); 
0049     for j=1:length(ga),
0050         gs=mat2str(double(ga(j)));
0051         bb(j+2+length(qa),jj)=length(gs);
0052         gc = uint8(gs); % ascii codes of characters as vector
0053         bg{j} = gc(:);
0054     end
0055 
0056     % Add ascii codes of characters of entries to bb
0057 
0058     bcount = 0;
0059     for j=1:length(qa),
0060         bbq = bq{j};
0061         for k=1:length(bbq)
0062             bb(k+2+length(qa)+length(ga)+bcount,jj) = bbq(k);
0063         end
0064         bcount = bcount + length(bbq);
0065     end
0066 
0067     for j=1:length(ga),
0068         bbg = bg{j};
0069         for k=1:length(bbg)
0070             bb(k+2+length(qa)+length(ga)+bcount,jj) = bbg(k);
0071         end
0072         bcount = bcount + length(bbg);
0073     end
0074 
0075     bc=bb; % return bb
0076 end

Generated on Wed 15-Aug-2012 10:09:15 by m2html © 2005