source: trunk/src/find_field_bounds.m @ 1003

Last change on this file since 1003 was 977, checked in by g7moreau, 8 years ago
  • Update Copyright 2008-2017 notice
File size: 4.9 KB
Line 
1%'find_field_bounds': % find the bounds 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: Matlab structure describing the input field
12%
13%=======================================================================
14% Copyright 2008-2017, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
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
31function FieldOut=find_field_bounds(Field)
32
33FieldOut=Field;%default
34%% analyse input field
35[CellInfo,NbDimArray,errormsg]=find_field_cells(Field);% analyse  the input field structure
36if ~isempty(errormsg)
37    errormsg=['uvmat /refresh_field / find_field_cells / ' errormsg];% display error
38    return
39end
40
41NbDim=max(NbDimArray);% spatial dimension of the input field
42imax=find(NbDimArray==NbDim);% indices of field cells to consider
43Check4D=0;
44if NbDim>3
45    NbDim=3;
46    Check4D=1;
47end
48FieldOut.NbDim=NbDim;
49if  NbDim<=1; return; end% stop here for 1D fields
50 
51%% get bounds and mesh (needed  to propose default options for projection objects)
52% if NbDim>1
53CoordMax=zeros(numel(imax),NbDim);
54CoordMin=zeros(numel(imax),NbDim);
55Mesh=zeros(1,numel(imax));
56FieldOut.ProjModeRequest='projection';%default
57for ind=1:numel(imax)
58    if strcmp(CellInfo{imax(ind)}.CoordType,'tps')
59        CoordName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex};% X,Y coordinates in a single variable
60        CoordMax(ind,NbDim)=max(max(Field.(CoordName)(1:end-3,1,:),[],1),[],3);% max of x component (2D case)
61        CoordMax(ind,NbDim-1)=max(max(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% max of y component (2D case)
62        CoordMin(ind,NbDim)=min(min(Field.(CoordName)(1:end-3,1,:),[],1),[],3);
63        CoordMin(ind,NbDim-1)=min(min(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% min of y component (2D case)
64    else
65        if Check4D
66            CellInfo{imax(ind)}.CoordIndex(4:end)=[];
67        end
68        XName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end)};
69        YName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end-1)};
70        CoordMax(ind,NbDim)=max(max(Field.(XName)));
71        CoordMin(ind,NbDim)=min(min(Field.(XName)));
72        CoordMax(ind,NbDim-1)=max(max(Field.(YName)));
73        CoordMin(ind,NbDim-1)=min(min(Field.(YName)));
74        %         test_x=1;%test for unstructured coordinates
75        if NbDim==3
76            ZName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(1)};
77            CoordMax(ind,NbDim-2)=max(max(Field.(ZName)));
78            CoordMin(ind,NbDim-2)=min(min(Field.(ZName)));
79        end
80    end
81    switch CellInfo{imax(ind)}.CoordType
82       
83        case {'scattered','tps'} %unstructured coordinates
84            NbPoints=CellInfo{imax(ind)}.CoordSize;% total nbre of points
85            Mesh(ind)=(prod(CoordMax(ind,:)-CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim)
86        case 'grid'%structured coordinate
87            NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points in each direction
88            if Check4D
89               NbPoints=NbPoints(1:3);
90            end
91            Mesh(ind)=min((CoordMax(ind,:)-CoordMin(ind,:))./(NbPoints-1));
92    end
93    if isfield(CellInfo{imax(ind)},'ProjModeRequest')
94        if strcmp(CellInfo{imax(ind)}.ProjModeRequest,'interp_tps')
95            FieldOut.ProjModeRequest='interp_tps';
96        end
97        if strcmp(CellInfo{imax(ind)}.ProjModeRequest,'interp_lin')&& ~strcmp(FieldOut.ProjModeRequest,'interp_tps')
98            FieldOut.ProjModeRequest='interp_lin';
99        end
100    end 
101end
102Mesh=min(Mesh);
103FieldOut.XMax=max(CoordMax(:,end));
104FieldOut.XMin=min(CoordMin(:,end));
105FieldOut.YMax=max(CoordMax(:,end-1));
106FieldOut.YMin=min(CoordMin(:,end-1));
107if NbDim==3
108    FieldOut.ZMax=max(CoordMax(ind,1));
109    FieldOut.ZMin=min(CoordMin(ind,1));
110end
111% adjust the mesh to a value 1, 2 , 5 *10^n
112ord=10^(floor(log10(Mesh)));%order of magnitude
113if Mesh/ord>=5
114    FieldOut.CoordMesh=5*ord;
115elseif Mesh/ord>=2
116    FieldOut.CoordMesh=2*ord;
117else
118    FieldOut.CoordMesh=ord;
119end
Note: See TracBrowser for help on using the repository browser.