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 | %======================================================================= |
---|
14 | % Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF 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 | |
---|
31 | function FieldOut=find_field_bounds(Field) |
---|
32 | |
---|
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 | |
---|
41 | NbDim=max(NbDimArray);% spatial dimension of the input field |
---|
42 | imax=find(NbDimArray==NbDim);% indices of field cells to consider |
---|
43 | if isfield(Field,'NbDim') |
---|
44 | NbDim=double(Field.NbDim);% deal with plane fields containing z coordinates |
---|
45 | end |
---|
46 | FieldOut.NbDim=NbDim; |
---|
47 | if NbDim<=1; return; end% stop here for 1D fields |
---|
48 | |
---|
49 | %% get bounds and mesh (needed to propose default options for projection objects) |
---|
50 | % if NbDim>1 |
---|
51 | CoordMax=zeros(numel(imax),NbDim); |
---|
52 | CoordMin=zeros(numel(imax),NbDim); |
---|
53 | Mesh=zeros(1,numel(imax)); |
---|
54 | for ind=1:numel(imax) |
---|
55 | if strcmp(CellInfo{imax(ind)}.CoordType,'tps') |
---|
56 | CoordName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex};% X,Y coordinates in a single variable |
---|
57 | CoordMax(ind,NbDim)=max(max(Field.(CoordName)(1:end-3,1,:),[],1),[],3);% max of x component (2D case) |
---|
58 | CoordMax(ind,NbDim-1)=max(max(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% max of y component (2D case) |
---|
59 | CoordMin(ind,NbDim)=min(min(Field.(CoordName)(1:end-3,1,:),[],1),[],3); |
---|
60 | CoordMin(ind,NbDim-1)=min(min(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% min of y component (2D case) |
---|
61 | else |
---|
62 | XName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end)}; |
---|
63 | YName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end-1)}; |
---|
64 | CoordMax(ind,NbDim)=max(max(Field.(XName))); |
---|
65 | CoordMin(ind,NbDim)=min(min(Field.(XName))); |
---|
66 | CoordMax(ind,NbDim-1)=max(max(Field.(YName))); |
---|
67 | CoordMin(ind,NbDim-1)=min(min(Field.(YName))); |
---|
68 | % test_x=1;%test for unstructured coordinates |
---|
69 | if NbDim==3 |
---|
70 | ZName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(1)}; |
---|
71 | CoordMax(ind,1)=max(max(Field.(ZName))); |
---|
72 | CoordMin(ind,1)=min(min(Field.(ZName))); |
---|
73 | end |
---|
74 | end |
---|
75 | switch CellInfo{imax(ind)}.CoordType |
---|
76 | |
---|
77 | case {'scattered','tps'} %unstructured coordinates |
---|
78 | NbPoints=CellInfo{imax(ind)}.CoordSize;% total nbre of points |
---|
79 | Mesh(ind)=(prod(CoordMax(ind,:)-CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim) |
---|
80 | case 'grid'%structured coordinate |
---|
81 | NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points in each direction |
---|
82 | Mesh(ind)=min((CoordMax(ind,:)-CoordMin(ind,:))./(NbPoints-1)); |
---|
83 | end |
---|
84 | end |
---|
85 | Mesh=min(Mesh); |
---|
86 | FieldOut.XMax=max(CoordMax(:,end)); |
---|
87 | FieldOut.XMin=min(CoordMin(:,end)); |
---|
88 | FieldOut.YMax=max(CoordMax(:,end-1)); |
---|
89 | FieldOut.YMin=min(CoordMin(:,end-1)); |
---|
90 | if NbDim==3 |
---|
91 | FieldOut.ZMax=max(CoordMax(ind,1)); |
---|
92 | FieldOut.ZMin=min(CoordMin(ind,1)); |
---|
93 | end |
---|
94 | % adjust the mesh to a value 1, 2 , 5 *10^n |
---|
95 | ord=10^(floor(log10(Mesh)));%order of magnitude |
---|
96 | if Mesh/ord>=5 |
---|
97 | FieldOut.CoordMesh=5*ord; |
---|
98 | elseif Mesh/ord>=2 |
---|
99 | FieldOut.CoordMesh=2*ord; |
---|
100 | else |
---|
101 | FieldOut.CoordMesh=ord; |
---|
102 | end |
---|