CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Wiki > PFVT mesh regrade

PFVT mesh regrade

From CFD-Wiki

Revision as of 21:12, 15 March 2013 by Jonas Holdeman (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
function y=regrade(x,a,e)
%REGRADE  grade nodal points in array towards edge or center
%
% Regrades array of points
%
% Usage: regrade(x,a,e)
% x is array of nodal point coordinates in increasing order.
% a is parameter which controls grading.
% e selects side or sides for refinement.
%
% if e=0: refine both sides, 1: refine upper, 2: refine lower.
%
% if a=1 then return xarray unaltered.
% if a<1 then grade towards the edge(s)
% if a>1 then grade away from edge.

ae=abs(a);
n=length(x);
y=x;
if ae==1 || n<3 || (e~=0 && e~=1 && e~=2), return;
end;
if e==0 
  Xmx=max(x);
  Xmn=min(x);
  Xc=(Xmx+Xmn)/2;
  Xl=(Xmx-Xmn)/2;
  for k=2:(n-1)
    xk=x(k)-Xc;
    y(k)=Xc+Xl*sign(xk)*(abs(xk/Xl))^ae;
 end
elseif (e==1 && x(1)<x(n)) || (e==2 && x(1)>x(n))
   for k=2:n-1
      xk=x(k)-x(1);
      y(k)=x(1)+(x(n)-x(1))*(abs(xk/(x(n)-x(1))))^ae;
   end
else   % (e==2 & x(1)<x(n)) | (e==1 & x(1)>x(n))
   for k=2:n-1
      xk=x(k)-x(n);
      y(k)=x(n)+(x(1)-x(n))*(abs(xk/(x(1)-x(n))))^ae;
   end
end
return;
My wiki