[654] | 1 | %'find_field_bounds': % find the boounds and typical meshs of coordinates |
---|
| 2 | %----------------------------------------------------------------------- |
---|
| 3 | %function FieldOut=find_field_bounds(Field) |
---|
| 4 | %----------------------------------------------------------------------- |
---|
| 5 | %OUTPUT |
---|
| 6 | %FieldOut copy of the input Field with the additional items: |
---|
| 7 | % .XMin,.XMax,.YMin,.YMax,bounds for x and y |
---|
| 8 | % .CoordMesh: typical mesh needed for automatic grids |
---|
| 9 | |
---|
| 10 | %INPUT |
---|
| 11 | % Field |
---|
| 12 | |
---|
| 13 | function FieldOut=find_field_bounds(Field) |
---|
| 14 | FieldOut=Field;%default |
---|
| 15 | %% analyse input field |
---|
| 16 | [CellInfo,NbDimArray,errormsg]=find_field_cells(Field);% analyse the input field structure |
---|
| 17 | if ~isempty(errormsg) |
---|
| 18 | errormsg=['uvmat /refresh_field / find_field_cells / ' errormsg];% display error |
---|
| 19 | return |
---|
| 20 | end |
---|
| 21 | |
---|
| 22 | NbDim=max(NbDimArray);% spatial dimension of the input field |
---|
| 23 | imax=find(NbDimArray==NbDim);% indices of field cells to consider |
---|
| 24 | if isfield(Field,'NbDim') |
---|
| 25 | NbDim=double(Field.NbDim);% deal with plane fields containing z coordinates |
---|
| 26 | end |
---|
| 27 | |
---|
| 28 | %% get bounds and mesh (needed to propose default options for projection objects) |
---|
| 29 | % if NbDim>1 |
---|
| 30 | CoordMax=zeros(numel(imax),NbDim); |
---|
| 31 | CoordMin=zeros(numel(imax),NbDim); |
---|
| 32 | Mesh=zeros(1,numel(imax)); |
---|
| 33 | for ind=1:numel(imax) |
---|
| 34 | if strcmp(CellInfo{imax(ind)}.CoordType,'tps') |
---|
| 35 | CoordName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex};% X,Y coordinates in a single variable |
---|
| 36 | CoordMax(ind,NbDim)=max(max(Field.(CoordName)(1:end-3,1,:),[],1),[],3);% max of x component (2D case) |
---|
| 37 | CoordMax(ind,NbDim-1)=max(max(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% max of y component (2D case) |
---|
| 38 | CoordMin(ind,NbDim)=min(min(Field.(CoordName)(1:end-3,1,:),[],1),[],3); |
---|
| 39 | CoordMin(ind,NbDim-1)=min(min(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% min of y component (2D case) |
---|
| 40 | else |
---|
| 41 | XName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end)}; |
---|
| 42 | YName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end-1)}; |
---|
| 43 | CoordMax(ind,NbDim)=max(max(Field.(XName))); |
---|
| 44 | CoordMin(ind,NbDim)=min(min(Field.(XName))); |
---|
| 45 | CoordMax(ind,NbDim-1)=max(max(Field.(YName))); |
---|
| 46 | CoordMin(ind,NbDim-1)=min(min(Field.(YName))); |
---|
| 47 | % test_x=1;%test for unstructured coordinates |
---|
| 48 | if NbDim==3 |
---|
| 49 | ZName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(1)}; |
---|
| 50 | CoordMax(imax(ind),1)=max(max(Field.(ZName))); |
---|
| 51 | CoordMin(ind,1)=min(min(Field.(ZName))); |
---|
| 52 | end |
---|
| 53 | end |
---|
| 54 | switch CellInfo{imax(ind)}.CoordType |
---|
| 55 | |
---|
| 56 | case {'scattered','tps'} %unstructured coordinates |
---|
| 57 | NbPoints=CellInfo{imax(ind)}.CoordSize;% total nbre of points |
---|
| 58 | Mesh(ind)=(prod(CoordMax(ind,:)-CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim) |
---|
| 59 | case 'grid'%structured coordinate |
---|
| 60 | NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points in each direction |
---|
| 61 | Mesh(ind)=min((CoordMax(ind,:)-CoordMin(ind,:))./(NbPoints-1)); |
---|
| 62 | end |
---|
| 63 | end |
---|
| 64 | Mesh=min(Mesh); |
---|
| 65 | FieldOut.XMax=max(CoordMax(:,end)); |
---|
| 66 | FieldOut.XMin=min(CoordMin(:,end)); |
---|
| 67 | FieldOut.YMax=max(CoordMax(:,end-1)); |
---|
| 68 | FieldOut.YMin=min(CoordMin(:,end-1)); |
---|
| 69 | if NbDim==3 |
---|
| 70 | FieldOut.ZMax=max(CoordMax(ind,1)); |
---|
| 71 | FieldOut.ZMin=max(CoordMin(ind,1)); |
---|
| 72 | end |
---|
| 73 | % adjust the mesh to a value 1, 2 , 5 *10^n |
---|
| 74 | ord=10^(floor(log10(Mesh)));%order of magnitude |
---|
| 75 | if Mesh/ord>=5 |
---|
| 76 | FieldOut.CoordMesh=5*ord; |
---|
| 77 | elseif Mesh/ord>=2 |
---|
| 78 | FieldOut.CoordMesh=2*ord; |
---|
| 79 | else |
---|
| 80 | FieldOut.CoordMesh=ord; |
---|
| 81 | end |
---|