[871] | 1 | %'find_field_bounds': % find the bounds and typical meshs of coordinates |
---|
[654] | 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 |
---|
[809] | 9 | % |
---|
[654] | 10 | %INPUT |
---|
[871] | 11 | % Field: Matlab structure describing the input field |
---|
| 12 | % |
---|
[809] | 13 | %======================================================================= |
---|
[1107] | 14 | % Copyright 2008-2022, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[809] | 15 | % http://www.legi.grenoble-inp.fr |
---|
| 16 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 17 | % |
---|
| 18 | % This file is part of the toolbox UVMAT. |
---|
| 19 | % |
---|
| 20 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 21 | % it under the terms of the GNU General Public License as published |
---|
| 22 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 23 | % or (at your option) any later version. |
---|
| 24 | % |
---|
| 25 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 26 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 27 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 28 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 29 | %======================================================================= |
---|
| 30 | |
---|
[654] | 31 | function FieldOut=find_field_bounds(Field) |
---|
[667] | 32 | |
---|
[654] | 33 | FieldOut=Field;%default |
---|
| 34 | %% analyse input field |
---|
| 35 | [CellInfo,NbDimArray,errormsg]=find_field_cells(Field);% analyse the input field structure |
---|
| 36 | if ~isempty(errormsg) |
---|
| 37 | errormsg=['uvmat /refresh_field / find_field_cells / ' errormsg];% display error |
---|
| 38 | return |
---|
| 39 | end |
---|
| 40 | NbDim=max(NbDimArray);% spatial dimension of the input field |
---|
| 41 | imax=find(NbDimArray==NbDim);% indices of field cells to consider |
---|
[893] | 42 | Check4D=0; |
---|
| 43 | if NbDim>3 |
---|
| 44 | NbDim=3; |
---|
| 45 | Check4D=1; |
---|
| 46 | end |
---|
[667] | 47 | FieldOut.NbDim=NbDim; |
---|
[1028] | 48 | %if NbDim<=1; return; end% stop here for 1D fields |
---|
[893] | 49 | |
---|
[654] | 50 | %% get bounds and mesh (needed to propose default options for projection objects) |
---|
| 51 | % if NbDim>1 |
---|
| 52 | CoordMax=zeros(numel(imax),NbDim); |
---|
| 53 | CoordMin=zeros(numel(imax),NbDim); |
---|
| 54 | Mesh=zeros(1,numel(imax)); |
---|
[954] | 55 | FieldOut.ProjModeRequest='projection';%default |
---|
[654] | 56 | for ind=1:numel(imax) |
---|
| 57 | if strcmp(CellInfo{imax(ind)}.CoordType,'tps') |
---|
| 58 | CoordName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex};% X,Y coordinates in a single variable |
---|
| 59 | CoordMax(ind,NbDim)=max(max(Field.(CoordName)(1:end-3,1,:),[],1),[],3);% max of x component (2D case) |
---|
| 60 | CoordMax(ind,NbDim-1)=max(max(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% max of y component (2D case) |
---|
| 61 | CoordMin(ind,NbDim)=min(min(Field.(CoordName)(1:end-3,1,:),[],1),[],3); |
---|
| 62 | CoordMin(ind,NbDim-1)=min(min(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% min of y component (2D case) |
---|
| 63 | else |
---|
[893] | 64 | if Check4D |
---|
| 65 | CellInfo{imax(ind)}.CoordIndex(4:end)=[]; |
---|
| 66 | end |
---|
[1028] | 67 | if isempty(CellInfo{imax(ind)}.CoordIndex) |
---|
| 68 | FieldName=CellInfo{imax(ind)}.FieldName; |
---|
| 69 | DimList=Field.VarDimName{imax(ind)}; |
---|
| 70 | siz=size(DimList); |
---|
| 71 | |
---|
| 72 | FieldOut.(DimList{end})=1:siz(end); |
---|
| 73 | FieldOut.ListVarName=[FieldOut.ListVarName DimList(end)]; |
---|
| 74 | FieldOut.VarDimName=[FieldOut.VarDimName DimList(end)]; |
---|
| 75 | CoordMax(ind,numel(siz))=siz(end); |
---|
| 76 | if numel(siz)>=2 |
---|
| 77 | FieldOut.(DimList{end-1})=1:siz(end-1); |
---|
| 78 | CoordMax(ind,numel(siz)-1)=siz(end-1); |
---|
| 79 | FieldOut.ListVarName=[FieldOut.ListVarName DimList(end-1)]; |
---|
| 80 | FieldOut.VarDimName=[FieldOut.VarDimName DimList(end-1)]; |
---|
| 81 | end |
---|
| 82 | if numel(siz)>=3 |
---|
| 83 | FieldOut.(DimList{1})=1:siz(1); |
---|
| 84 | CoordMax(ind,1)=siz(1); |
---|
| 85 | FieldOut.ListVarName=[FieldOut.ListVarName DimList(1)]; |
---|
| 86 | FieldOut.VarDimName=[FieldOut.VarDimName DimList(1)]; |
---|
| 87 | end |
---|
| 88 | CoordMin(ind,1:numel(siz))=1; |
---|
| 89 | CellInfo{imax(ind)}.CoordSize=CoordMax(ind,:); |
---|
| 90 | else |
---|
| 91 | XName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end)}; |
---|
| 92 | YName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end-1)}; |
---|
| 93 | CoordMax(ind,NbDim)=max(max(Field.(XName))); |
---|
| 94 | CoordMin(ind,NbDim)=min(min(Field.(XName))); |
---|
| 95 | CoordMax(ind,NbDim-1)=max(max(Field.(YName))); |
---|
| 96 | CoordMin(ind,NbDim-1)=min(min(Field.(YName))); |
---|
| 97 | % test_x=1;%test for unstructured coordinates |
---|
| 98 | if NbDim==3 |
---|
| 99 | ZName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(1)}; |
---|
| 100 | CoordMax(ind,NbDim-2)=max(max(Field.(ZName))); |
---|
| 101 | CoordMin(ind,NbDim-2)=min(min(Field.(ZName))); |
---|
| 102 | end |
---|
[654] | 103 | end |
---|
| 104 | end |
---|
| 105 | switch CellInfo{imax(ind)}.CoordType |
---|
| 106 | |
---|
| 107 | case {'scattered','tps'} %unstructured coordinates |
---|
| 108 | NbPoints=CellInfo{imax(ind)}.CoordSize;% total nbre of points |
---|
| 109 | Mesh(ind)=(prod(CoordMax(ind,:)-CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim) |
---|
| 110 | case 'grid'%structured coordinate |
---|
| 111 | NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points in each direction |
---|
[893] | 112 | if Check4D |
---|
[1028] | 113 | NbPoints=NbPoints(1:3); |
---|
[893] | 114 | end |
---|
[654] | 115 | Mesh(ind)=min((CoordMax(ind,:)-CoordMin(ind,:))./(NbPoints-1)); |
---|
| 116 | end |
---|
[954] | 117 | if isfield(CellInfo{imax(ind)},'ProjModeRequest') |
---|
| 118 | if strcmp(CellInfo{imax(ind)}.ProjModeRequest,'interp_tps') |
---|
| 119 | FieldOut.ProjModeRequest='interp_tps'; |
---|
| 120 | end |
---|
[1095] | 121 | % if strcmp(CellInfo{imax(ind)}.ProjModeRequest,'interp_lin')&& ~strcmp(FieldOut.ProjModeRequest,'interp_tps') |
---|
| 122 | % FieldOut.ProjModeRequest='interp_lin'; |
---|
| 123 | % end |
---|
[1028] | 124 | end |
---|
[654] | 125 | end |
---|
| 126 | Mesh=min(Mesh); |
---|
| 127 | FieldOut.XMax=max(CoordMax(:,end)); |
---|
| 128 | FieldOut.XMin=min(CoordMin(:,end)); |
---|
| 129 | FieldOut.YMax=max(CoordMax(:,end-1)); |
---|
| 130 | FieldOut.YMin=min(CoordMin(:,end-1)); |
---|
| 131 | if NbDim==3 |
---|
| 132 | FieldOut.ZMax=max(CoordMax(ind,1)); |
---|
[747] | 133 | FieldOut.ZMin=min(CoordMin(ind,1)); |
---|
[654] | 134 | end |
---|
| 135 | % adjust the mesh to a value 1, 2 , 5 *10^n |
---|
[1078] | 136 | FieldOut.CoordMesh = round_uvmat(Mesh); |
---|
| 137 | |
---|
| 138 | |
---|