Skip to content

Commit

Permalink
Updating quadrature points computation AGAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyEarly committed Sep 29, 2023
1 parent e9c6775 commit eebba78
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
49 changes: 25 additions & 24 deletions Matlab/InternalModes/InternalModesSpectral.m
Original file line number Diff line number Diff line change
Expand Up @@ -576,42 +576,43 @@
% boundary, and not zero at upper)
rootMode = nPoints;
end
roots = InternalModesSpectral.FindRootsFromChebyshevVector(G_cheb(:,rootMode), self.xDomain);
rootsVar = InternalModesSpectral.FindRootsFromChebyshevVector(G_cheb(:,rootMode), self.xDomain);

% First we make sure the roots are within the bounds
roots(roots<self.xMin) = self.xMin;
roots(roots>self.xMax) = self.xMax;
rootsVar(rootsVar<self.xMin) = self.xMin;
rootsVar(rootsVar>self.xMax) = self.xMax;

% Then we eliminate any repeats (it happens)
roots = unique(roots,'stable');
rootsVar = unique(rootsVar,'stable');

if length(roots) < nPoints
error('GLOceanKit:NeedMorePoints', 'Returned %d unique roots (requested %d). Maybe need more EVP.', length(roots),nPoints);
if length(rootsVar) < nPoints
error('GLOceanKit:NeedMorePoints', 'Returned %d unique roots (requested %d). Maybe need more EVP.', length(rootsVar),nPoints);
end
warning('Two strategies here---need to consolidate.')
% F = self.Diff1_xCheb(G_cheb(:,rootMode));
% value = InternalModesSpectral.ValueOfFunctionAtPointOnGrid( roots, self.xDomain, F );
% [~,indices] = sort(abs(value),'descend');
% indices = indices(1:nPoints);
% roots = roots(indices);
% F = self.Diff1_xCheb(G_cheb(:,rootMode));
% value = InternalModesSpectral.ValueOfFunctionAtPointOnGrid( rootsVar, self.xDomain, F );
% [~,indices] = sort(abs(value),'descend');
% indices = indices(1:nPoints);
% rootsVar = rootsVar(indices);

% This strategy was useful for the vertical mode atlas
% 1/25/2023 -- this also seems to work better with the analytical mixed layer
% stratification profile
while (length(roots) > nPoints)
roots = sort(roots);
F = self.Diff1_xCheb(G_cheb(:,rootMode));
value = InternalModesSpectral.ValueOfFunctionAtPointOnGrid( roots, self.xDomain, F );
dr = diff(roots);
[~,minIndex] = min(abs(dr));
if abs(value(minIndex)) < abs(value(minIndex+1))
roots(minIndex) = [];
else
roots(minIndex+1) = [];
end
while (length(rootsVar) > nPoints)
rootsVar = sort(rootsVar);
F = InternalModesSpectral.IntegrateChebyshevVector(G_cheb(:,rootMode));
value = InternalModesSpectral.ValueOfFunctionAtPointOnGrid( rootsVar, self.xDomain, F );
dv = diff(value);
[~,minIndex] = min(abs(dv));
rootsVar(minIndex+1) = [];
% if abs(value(minIndex)) < abs(value(minIndex+1))
% rootsVar(minIndex) = [];
% else
% rootsVar(minIndex+1) = [];
% end
end

z_g = reshape(roots,[],1);
z_g = reshape(rootsVar,[],1);
z_g = InternalModesSpectral.fInverseBisection(self.x_function,z_g,min(self.zDomain),max(self.zDomain),1e-12);
else
error('GLOceanKit:NeedMorePoints', 'You need at least twice as many nEVP as points you request');
Expand Down Expand Up @@ -1371,7 +1372,7 @@
% All rights reserved.
n = length(f_cheb);

f_cheb(abs(f_cheb)<1e-15) = 1e-15;
f_cheb(abs(f_cheb)<1e-12) = 1e-15;

A=zeros(n-1); % "n-1" because Boyd's notation includes the zero-indexed
A(1,2)=1; % elements whereas Matlab's of course does not allow this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
for iK=1:length(k)


im = InternalModesWKBSpectral(rhoFunc,zIn,z,33,'nEVP',256);
im = InternalModesSpectral(rho=rhoFunc,zIn=zIn,zOut=z,latitude=33,nEVP=512);
im.normalization = normalization;
im.upperBoundary = upperBoundary;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

% Find the quadrature points for k=0
k = 0;
im = InternalModesSpectral(rhoFunc,zIn,z,33,'nEVP',256);
im = InternalModesSpectral(rho=rhoFunc,zIn=zIn,zOut=z,latitude=33,nEVP=256);
im.normalization = normalization;
im.upperBoundary = upperBoundary;
z = im.GaussQuadraturePointsForModesAtWavenumber(nPoints,k);

% Compute F,G at those points
im = InternalModesSpectral(rhoFunc,zIn,z,33,'nEVP',256);
im = InternalModesSpectral(rho=rhoFunc,zIn=zIn,zOut=z,latitude=33,nEVP=256);
im.normalization = normalization;
im.upperBoundary = upperBoundary;
[Finv,Ginv,self.h] = im.ModesAtWavenumber(k);
Expand All @@ -38,7 +38,7 @@
for iK=1:length(k)


im = InternalModesSpectral(rhoFunc,zIn,z,33,'nEVP',256);
im = InternalModesSpectral(rho=rhoFunc,zIn=zIn,zOut=z,latitude=33,nEVP=256);
im.normalization = normalization;
im.upperBoundary = upperBoundary;

Expand Down

0 comments on commit eebba78

Please sign in to comment.