Skip to content

Commit 5a7b97f

Browse files
committed
Successul repackaging.
1 parent 063eb73 commit 5a7b97f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+1123
-706
lines changed
File renamed without changes.

+sctool/findz0.m

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
function [z0,w0] = scimapz0(prefix,wp,mapfun,w,beta,z,c,qdat,aux)
2+
%SCIMAPZ0 (not intended for calling directly by the user)
3+
% SCIMAPZ0 returns starting points for computing inverses of
4+
% Schwarz-Christoffel maps.
5+
%
6+
% Each wp(j) (in the polygon plane) requires z0(j) (in the fundamental
7+
% domain) whose image w0(j) is such that the line segment from w0(j)
8+
% to wp(j) lies in the target (interior or exterior) region. The
9+
% algorithm here is to choose z0(j) as a (weighted) average of
10+
% successive pairs of adjacent prevertices. The resulting w0(j) is on
11+
% a polygon side. Each choice is tested by looking for intersections
12+
% of the segment with (other) sides of the polygon.
13+
%
14+
% After randomly trying 10 weights with such prevertex pairs, the
15+
% routine gives up. Failures are pretty rare. Slits are the most
16+
% likely cause of trouble, since the intersection method doesn't know
17+
% "which side" of the slit it's on. In such a case you will have to
18+
% supply starting points manually, perhaps by a continuation method.
19+
%
20+
% See also HPINVMAP, DINVMAP, DEINVMAP, RINVMAP, STINVMAP.
21+
22+
% Copyright 1997 by Toby Driscoll. Last updated 05/07/97.
23+
24+
% P.S. This file illustrates why the different domains in the SC
25+
% Toolbox have mostly independent M-files. The contingencies for the
26+
% various geometries become rather cumbersome.
27+
28+
n = length(w);
29+
shape = wp;
30+
wp = wp(:);
31+
z0 = wp;
32+
w0 = wp;
33+
from_disk = strcmp(prefix(1),'d');
34+
from_hp = strcmp(prefix,'hp');
35+
from_strip = strcmp(prefix,'st');
36+
from_rect = strcmp(prefix,'r');
37+
38+
% Calculate arguments of the directed polygon edges.
39+
if from_strip
40+
% Renumber to put left end of strip first
41+
atinf = find(isinf(z));
42+
renum = [atinf(1):n 1:atinf(1)-1];
43+
w = w(renum);
44+
z = z(renum);
45+
beta = beta(renum);
46+
qdat(:,1:n) = qdat(:,renum);
47+
qdat(:,n+1+(1:n)) = qdat(:,n+1+renum);
48+
kinf = max(find(isinf(z)));
49+
argw = cumsum([angle(w(3)-w(2));-pi*beta([3:n,1])]);
50+
argw = argw([n,1:n-1]);
51+
else
52+
argw = cumsum([angle(w(2)-w(1));-pi*beta(2:n)]);
53+
end
54+
55+
% Express each side in a form to allow detection of intersections.
56+
infty = isinf(w);
57+
fwd = [2:n 1];
58+
anchor = zeros(1,n);
59+
anchor(~infty) = w(~infty);
60+
anchor(infty) = w( fwd(infty) ); % use the finite endpoint
61+
direcn = exp(i*argw);
62+
direcn(infty) = -direcn(infty); % reverse
63+
len = abs( w(fwd) - w );
64+
65+
if from_disk
66+
argz = angle(z);
67+
argz(argz<=0) = argz(argz<=0) + 2*pi;
68+
end
69+
70+
if from_rect
71+
% Extra argument given
72+
L = qdat;
73+
qdat = aux;
74+
end
75+
76+
factor = 0.5; % images of midpoints of preverts
77+
done = zeros(1,length(wp));
78+
m = length(wp);
79+
iter = 0;
80+
if length(qdat) > 1
81+
tol = 1000*10^(-size(qdat,1));
82+
else
83+
tol = qdat;
84+
end
85+
86+
zbase = NaN*ones(n,1);
87+
wbase = NaN*ones(n,1);
88+
idx = [];
89+
while m > 0 % while some not done
90+
% Choose a "basis point" on each side of the polygon.
91+
for j = 1:n
92+
if from_disk
93+
if j<n
94+
zbase(j) = exp(i*(factor*argz(j) + (1-factor)*argz(j+1)));
95+
else
96+
zbase(j) = exp(i*(factor*argz(n) + (1-factor)*(2*pi+argz(1))));
97+
end
98+
elseif from_hp
99+
if j < n-1 % between two finite points
100+
zbase(j) = z(j) + factor*(z(j+1)-z(j));
101+
elseif j==n-1 % between x(n-1) & Inf
102+
zbase(j) = max(10,z(n-1))/factor;
103+
else % between -Inf and x(1)
104+
zbase(j) = min(-10,z(1))/factor;
105+
end
106+
elseif from_strip
107+
if j==1
108+
zbase(j) = min(-1,real(z(2)))/factor;
109+
elseif j==kinf-1
110+
zbase(j) = max(1,real(z(kinf-1)))/factor;
111+
elseif j==kinf
112+
zbase(j) = i+max(1,real(z(kinf+1)))/factor;
113+
elseif j==n
114+
zbase(j) = i+min(-1,real(z(n)))/factor;
115+
else
116+
zbase(j) = z(j) + factor*(z(j+1)-z(j));
117+
end
118+
elseif from_rect
119+
zbase(j) = z(j) + factor*(z(rem(j,n)+1)-z(j));
120+
% Can't use 0 or iK' as basis points.
121+
if abs(zbase(j)) < 1e-4
122+
zbase(j) = zbase(j) + .2i;
123+
elseif abs(zbase(j)-i*max(imag(z))) < 1e-4
124+
zbase(j) = zbase(j) - .2i;
125+
end
126+
end
127+
128+
% Find images of all the z-plane basis points.
129+
wbase(j) = feval(mapfun,zbase(j));
130+
131+
% Project each base point exactly to the nearest polygon side. This
132+
% is needed to make intersection detection go smoothly in borderline
133+
% cases.
134+
proj = real( (wbase(j)-anchor(j)) * conj(direcn(j)) );
135+
wbase(j) = anchor(j) + proj*direcn(j);
136+
137+
end
138+
139+
if isempty(idx)
140+
% First time through, assign nearest basis point to each image point
141+
[dist,idx] = min(abs( wp(~done,ones(n,1)).' - wbase(:,ones(m,1)) ));
142+
else
143+
% Other times, just change those that failed.
144+
idx(~done) = rem(idx(~done),n) + 1;
145+
end
146+
z0(~done) = zbase(idx(~done));
147+
w0(~done) = wbase(idx(~done));
148+
149+
% Now, cycle thru basis points
150+
for j = 1:n
151+
% Those points who come from basis j and need checking
152+
active = (idx==j) & (~done);
153+
if any(active)
154+
% Assume for now that it's good
155+
done(active) = ones(1,sum(active));
156+
% Test line segment for intersections with other sides.
157+
% We'll parameterize line segment and polygon side, compute parameters
158+
% at intersection, and check parameters at intersection.
159+
for k=[1:j-1,j+1:n]
160+
A(:,1) = [ real(direcn(k)); imag(direcn(k)) ];
161+
for p = find(active)
162+
dif = (w0(p)-wp(p));
163+
A(:,2) = [real(dif);imag(dif)];
164+
% Get line segment and side parameters at intersection.
165+
if rcond(A) < eps
166+
% All 4 involved points are collinear.
167+
wpx = real( (wp(p)-anchor(k)) / direcn(k) );
168+
w0x = real( (w0(p)-anchor(k)) / direcn(k) );
169+
if (wpx*w0x < 0) | ((wpx-len(k))*(w0x-len(k)) < 0)
170+
% Intersection interior to segment: it's no good
171+
done(p) = 0;
172+
end
173+
else
174+
dif = (w0(p)-anchor(k));
175+
s = A\[real(dif);imag(dif)];
176+
% Intersection occurs interior to side? and segment?
177+
if s(1)>=0 & s(1)<=len(k)
178+
if abs(s(2)-1) < tol
179+
% Special case: wp(p) is on polygon side k
180+
z0(p) = zbase(k);
181+
w0(p) = wbase(k);
182+
elseif abs(s(2)) < tol
183+
% Happens when two sides are partially coincident (slit)
184+
% Check against normal to that side
185+
if real( conj(wp(p)-w0(p))*1i*direcn(k) ) > 0
186+
% Line segment came from "outside"
187+
done(p) = 0;
188+
end
189+
elseif s(2) > 0 & s(2) < 1
190+
% Intersection interior to segment: it's no good
191+
done(p) = 0;
192+
end
193+
end
194+
end
195+
end
196+
end
197+
198+
% Short circuit if everything is finished
199+
m = sum(~done);
200+
if ~m, break, end
201+
end
202+
end
203+
if iter > 2*n
204+
error('Can''t seem to choose starting points. Supply them manually.')
205+
else
206+
iter = iter + 1;
207+
end
208+
factor = rand(1); % abandon midpoints
209+
end
210+
211+
shape(:) = z0;
212+
z0 = shape;
213+
shape(:) = w0;
214+
w0 = shape;

private/gaussj.m +sctool/gaussj.m

File renamed without changes.

isinpoly.m +sctool/isinpoly.m

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
% $Id: isinpoly.m 298 2009-09-15 14:36:37Z driscoll $
1818

1919
% Uses the argument principle, with some gymnastics for boundary points.
20+
import sctool.*
2021

2122
if nargin < 4
2223
tol = eps;
File renamed without changes.
File renamed without changes.
File renamed without changes.

private/neconest.m +sctool/neconest.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
%
6767
% Algorithm step 8.
6868
%
69-
x = nersolv(M,M2,x);
69+
x = sctool.nersolv(M,M2,x);
7070

7171
%
7272
% Algorithm steps 9 & 10.
File renamed without changes.

private/nefn.m +sctool/nefn.m

File renamed without changes.

private/nehook.m +sctool/nehook.m

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
%
3434
% Initialization.
3535
%
36+
import sctool.*
3637
n = length(xc);
3738
umflag = (length(details) == 17); % This is how we tell NE from UM.
3839
xpprev = zeros(n,1); % allocation

private/neinck.m +sctool/neinck.m

File renamed without changes.

private/nelnsrch.m +sctool/nelnsrch.m

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
%
2525
% Initialization.
2626
%
27+
import sctool.*
2728
n = length(xc);
2829
xp = zeros(n,1);
2930
fp = 0;

private/nemodel.m +sctool/nemodel.m

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
%
1717
% Algorithm step 1.
1818
%
19+
import sctool.*
1920
n = length(J);
2021
m = diag(sf)*J;
2122

2223
%
2324
% Algorithm step 2.
2425
%
25-
[m,m1,m2,sing]=neqrdcmp(m);
26+
[m,m1,m2,sing]=sctool.neqrdcmp(m);
2627

2728
%
2829
% Algorithm step 3.
@@ -32,7 +33,7 @@
3233
m(1:(j-1),j)=m(1:(j-1),j)/sx(j);
3334
end
3435
m2 = m2./sx;
35-
est = neconest(m,m2);
36+
est = sctool.neconest(m,m2);
3637
else
3738
est=0.;
3839
end
@@ -54,7 +55,7 @@
5455
end
5556
h = h + sqrt(n*eps) * hnorm * (diag(sx)^2);
5657
% caculate sn=inv(H)*g, and keep m (the cholesky factor) for later use.
57-
[m,maxadd] = nechdcmp(h,0);
58+
[m,maxadd] = sctool.nechdcmp(h,0);
5859
sn = -m'\(m\g);
5960
else
6061
% Calculate normal Newton step
@@ -63,7 +64,7 @@
6364
end
6465
m2 = m2.*sx;
6566
sn = -sf.*fc;
66-
sn = neqrsolv(m,m1,m2,sn);
67+
sn = sctool.neqrsolv(m,m1,m2,sn);
6768
if (globmeth ==2) | (globmeth ==3)
6869
% the cholesky factor (for later use) is the same as R' from QR.
6970
m = triu(m) + triu(m)';
File renamed without changes.

private/neqrsolv.m +sctool/neqrsolv.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
%
2626
% Algorithm step 2.
2727
%
28-
b = nersolv(M,M2,b);
28+
b = sctool.nersolv(M,M2,b);
2929

File renamed without changes.

private/nesolve.m +sctool/nesolve.m

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757

5858
% Initialization.
5959
%
60+
import sctool.*
61+
6062
if (nargin < 3)
6163
details = zeros(16,1);
6264
end

private/nesolvei.m +sctool/nesolvei.m

+12-12
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@
6262
%
6363
if (details(16) > 0) % Might need F(x0) for scaling.
6464
if details(15)
65-
[fc,FVplus,nofun] = nefn(x0,ones(length(x0),1),fvec,nofun,fparam);
65+
[fc,FVplus,nofun] = sctool.nefn(x0,ones(length(x0),1),fvec,nofun,fparam);
6666
else
67-
[fc,FVplus,nofun] = nefn(x0,ones(length(x0),1),fvec,nofun);
67+
[fc,FVplus,nofun] = sctool.nefn(x0,ones(length(x0),1),fvec,nofun);
6868
end
6969
else
7070
FVplus = zeros(length(x0),1);
7171
end
72-
[details,Sx,SF,termcode] = neinck(x0,FVplus,details,scale);
72+
[details,Sx,SF,termcode] = sctool.neinck(x0,FVplus,details,scale);
7373

7474
%
7575
% Algorithm step 3.
@@ -89,9 +89,9 @@
8989
% Algorithm step 5.
9090
%
9191
if details(15)
92-
[fc,FVplus,nofun] = nefn(x0,SF,fvec,nofun,fparam);
92+
[fc,FVplus,nofun] = sctool.nefn(x0,SF,fvec,nofun,fparam);
9393
else
94-
[fc,FVplus,nofun] = nefn(x0,SF,fvec,nofun);
94+
[fc,FVplus,nofun] = sctool.nefn(x0,SF,fvec,nofun);
9595
end
9696

9797
%
@@ -157,17 +157,17 @@
157157
end
158158
itncount = itncount + 1;
159159
if (details(4) | details(3) | (1-details(5)))
160-
[M,Hc,sN] = nemodel(FVc,Jc,gc,SF,Sx,details(2));
160+
[M,Hc,sN] = sctool.nemodel(FVc,Jc,gc,SF,Sx,details(2));
161161
else
162162
error('Factored model not implemented.')
163163
% [] = nemodfac();
164164
end
165165
if (details(2) == 1)
166166
[retcode,xplus,fplus,FVplus,maxtaken,nofun,btrack] = ...
167-
nelnsrch(xc,fc,fvec,gc,sN,Sx,SF,details,nofun,btrack,fparam);
167+
sctool.nelnsrch(xc,fc,fvec,gc,sN,Sx,SF,details,nofun,btrack,fparam);
168168
elseif (details(2) == 2)
169169
[retcode,xplus,fplus,FVplus,maxtaken,details,trustvars,nofun] = ...
170-
nehook(xc,fc,fvec,gc,tril(M),Hc,sN,Sx,SF,details,itncount,trustvars,...
170+
sctool.nehook(xc,fc,fvec,gc,tril(M),Hc,sN,Sx,SF,details,itncount,trustvars,...
171171
nofun,fparam);
172172
else
173173
error('Dogleg not implemented.')
@@ -182,25 +182,25 @@
182182
end
183183
nofun = nofun + addfun;
184184
elseif (details(3))
185-
[Jc,nofun] = nefdjac(fvec,FVplus,xplus,Sx,details,nofun,fparam);
185+
[Jc,nofun] = sctool.nefdjac(fvec,FVplus,xplus,Sx,details,nofun,fparam);
186186
elseif (details(5))
187187
error('Factored secant method not implemented.')
188188
% [] = nebroyf();
189189
else
190-
Jc = nebroyuf(Jc,xc,xplus,FVc,FVplus,Sx,details(13)); % Broyden update
190+
Jc = sctool.nebroyuf(Jc,xc,xplus,FVc,FVplus,Sx,details(13)); % Broyden update
191191
end
192192
if (details(5))
193193
error('Gradient calculation for factored method not implemented.')
194194
% Calculate gc using QR factorization (see book).
195195
else
196196
gc = Jc' * (FVplus .* (SF.^2));
197197
end
198-
[consecmax,termcode] = nestop(xc,xplus,FVplus,fplus,gc,Sx,SF,retcode,...
198+
[consecmax,termcode] = sctool.nestop(xc,xplus,FVplus,fplus,gc,Sx,SF,retcode,...
199199
details,itncount,maxtaken,consecmax);
200200
end
201201
if (((retcode == 1) | (termcode == 2)) & (1-restart) & ...
202202
(1-details(4)) & (1-details(3)))
203-
[Jc,nofun] = nefdjac(fvec,FVc,xc,Sx,details,nofun,fparam);
203+
[Jc,nofun] = sctool.nefdjac(fvec,FVc,xc,Sx,details,nofun,fparam);
204204
gc = Jc' * (FVc .* (SF.^2));
205205
if ((details(2) == 2) | (details(2) == 3))
206206
details(7) = -1;

private/nestop.m +sctool/nestop.m

File renamed without changes.

private/netrust.m +sctool/netrust.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
nofun = nofun + 1;
4949
else
5050
if details(15)
51-
[fp,Fp,nofun] = nefn(xp,sf,fn,nofun,fparam);
51+
[fp,Fp,nofun] = sctool.nefn(xp,sf,fn,nofun,fparam);
5252
else
53-
[fp,Fp,nofun] = nefn(xp,sf,fn,nofun);
53+
[fp,Fp,nofun] = sctool.nefn(xp,sf,fn,nofun);
5454
end
5555
end
5656

File renamed without changes.

scaddvtx.m +sctool/scaddvtx.m

File renamed without changes.

scangle.m +sctool/scangle.m

File renamed without changes.

sccheck.m +sctool/sccheck.m

File renamed without changes.

scfix.m +sctool/scfix.m

File renamed without changes.

scgexprt.m +sctool/scgexprt.m

File renamed without changes.

scgimprt.m +sctool/scgimprt.m

File renamed without changes.

scgui.m +sctool/scgui.m

File renamed without changes.

0 commit comments

Comments
 (0)