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