generalized Neumann BC: generate q,g, string allowed 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.
0001 function bc= gnbcs(pneq,varargin) 0002 % generalized Neumann BC: generate q,g, string allowed 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 % generate vector of entries of matrix q (analogue of qa=q(:) ) 0041 if pneq==1; qa{1}=q; else 0042 for ik=1:pneq;for ij=1:pneq 0043 qa{ij+pneq*(ik-1)}=q{ij}{ik}; 0044 end; end; end 0045 for j=1:length(qa) 0046 qs=qa{j}; 0047 bb(j+2,jj)=length(qs); 0048 qc = uint8(qs); % ascii codes of characters as vector 0049 bq{j} = qc; 0050 end 0051 0052 if pneq==1; ga{1}=g; else 0053 ga=g; 0054 end 0055 for j=1:length(ga) 0056 gs=ga{j}; 0057 bb(j+2+length(qa),jj)=length(gs); 0058 gc = uint8(gs); % ascii codes of characters as vector 0059 bg{j} = gc(:); 0060 end 0061 0062 % Add ascii codes of characters of entries to bb 0063 0064 bcount = 0; 0065 for j=1:length(qa), 0066 bbq = bq{j}; 0067 for k=1:length(bbq) 0068 bb(k+2+length(qa)+length(ga)+bcount,jj) = bbq(k); 0069 end 0070 bcount = bcount + length(bbq); 0071 end 0072 0073 for j=1:length(ga), 0074 bbg = bg{j}; 0075 for k=1:length(bbg) 0076 bb(k+2+length(qa)+length(ga)+bcount,jj) = bbg(k); 0077 end 0078 bcount = bcount + length(bbg); 0079 end 0080 0081 bc=bb; % return bb 0082 end