]> Creatis software - CreaPhase.git/blob - octave_packages/secs2d-0.0.8/Utilities/Ustructmesh_random.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / secs2d-0.0.8 / Utilities / Ustructmesh_random.m
1 function [p,e,t]=Ustructmesh_random(x,y,region,sides)
2
3 % [p,e,t]=Ustructmesh(x,y,region,sides)
4
5 % This file is part of 
6 %
7 %            SECS2D - A 2-D Drift--Diffusion Semiconductor Device Simulator
8 %         -------------------------------------------------------------------
9 %            Copyright (C) 2004-2006  Carlo de Falco
10 %
11 %
12 %
13 %  SECS2D is free software; you can redistribute it and/or modify
14 %  it under the terms of the GNU General Public License as published by
15 %  the Free Software Foundation; either version 2 of the License, or
16 %  (at your option) any later version.
17 %
18 %  SECS2D is distributed in the hope that it will be useful,
19 %  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 %  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 %  GNU General Public License for more details.
22 %
23 %  You should have received a copy of the GNU General Public License
24 %  along with SECS2D; If not, see <http://www.gnu.org/licenses/>.
25
26 x = sort(x);
27 y = sort(y);
28
29 nx = length(x);
30 ny = length(y);
31 [XX,YY] = meshgrid(x,y);
32 p = [XX(:),YY(:)]';
33 iiv (ny,nx)=0;
34 iiv(:)=1:nx*ny;
35 iiv(end,:)=[];
36 iiv(:,end)=[];
37 iiv=iiv(:)';
38
39 niiv = length(iiv);
40 theperm = iiv(randperm(niiv));
41 first = theperm(1:floor(niiv/2));
42 second = theperm(floor(niiv/2)+1:end);
43
44 t = [[first;first+ny;first+ny+1],[first;first+ny+1;first+1] ];
45 t = [t,[second;second+ny;second+1],[second+ny;second+ny+1;second+1] ];
46
47 t (4,:)=region;
48
49 l1 = 1+ny*([1:nx]-1);
50 l4 = 1:ny;
51 l2 = ny*(nx-1)+1:nx*ny;
52 l3 = ny + l1 -1;
53
54 e = [ l1([1:end-1]) l2([1:end-1]) l3([1:end-1]) l4([1:end-1])
55        l1([2:end]) l2([2:end]) l3([2:end]) l4([2:end])
56        [l1([1:end-1]) l2([1:end-1]) l3([1:end-1]) l4([1:end-1])]*0
57        [l1([1:end-1]) l2([1:end-1]) l3([1:end-1]) l4([1:end-1])]*0
58        l1([1:end-1])*0+sides(1) l2([1:end-1])*0+sides(2) l3([1:end-1])*0+sides(3) l4([1:end-1])*0+sides(4)
59            [l1([1:end-1]) l2([1:end-1]) l3([1:end-1]) l4([1:end-1])]*0
60            [l1([1:end-1]) l2([1:end-1]) l3([1:end-1]) l4([1:end-1])]*0+region
61            ];
62
63