source: trunk/src/find_field_bounds.m @ 1148

Last change on this file since 1148 was 1127, checked in by g7moreau, 12 months ago

Update Joel email

File size: 6.0 KB
RevLine 
[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%=======================================================================
[1126]14% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[809]15%   http://www.legi.grenoble-inp.fr
[1127]16%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
[809]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]31function FieldOut=find_field_bounds(Field)
[667]32
[654]33FieldOut=Field;%default
34%% analyse input field
35[CellInfo,NbDimArray,errormsg]=find_field_cells(Field);% analyse  the input field structure
[1123]36if isempty(CellInfo)
37    errormsg='bad input field'
38    return
39end
[654]40if ~isempty(errormsg)
[1123]41    errormsg=['uvmat /refresh_field / find_field_cells / ' errormsg]% display error
[654]42    return
43end
44NbDim=max(NbDimArray);% spatial dimension of the input field
45imax=find(NbDimArray==NbDim);% indices of field cells to consider
[893]46Check4D=0;
47if NbDim>3
48    NbDim=3;
49    Check4D=1;
50end
[667]51FieldOut.NbDim=NbDim;
[1028]52%if  NbDim<=1; return; end% stop here for 1D fields
[893]53 
[654]54%% get bounds and mesh (needed  to propose default options for projection objects)
55% if NbDim>1
56CoordMax=zeros(numel(imax),NbDim);
57CoordMin=zeros(numel(imax),NbDim);
58Mesh=zeros(1,numel(imax));
[954]59FieldOut.ProjModeRequest='projection';%default
[654]60for ind=1:numel(imax)
61    if strcmp(CellInfo{imax(ind)}.CoordType,'tps')
62        CoordName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex};% X,Y coordinates in a single variable
63        CoordMax(ind,NbDim)=max(max(Field.(CoordName)(1:end-3,1,:),[],1),[],3);% max of x component (2D case)
64        CoordMax(ind,NbDim-1)=max(max(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% max of y component (2D case)
65        CoordMin(ind,NbDim)=min(min(Field.(CoordName)(1:end-3,1,:),[],1),[],3);
66        CoordMin(ind,NbDim-1)=min(min(Field.(CoordName)(1:end-3,2,:),[],1),[],3);% min of y component (2D case)
67    else
[893]68        if Check4D
69            CellInfo{imax(ind)}.CoordIndex(4:end)=[];
70        end
[1028]71        if isempty(CellInfo{imax(ind)}.CoordIndex)
72            FieldName=CellInfo{imax(ind)}.FieldName;
73            DimList=Field.VarDimName{imax(ind)};
74            siz=size(DimList);
75
76            FieldOut.(DimList{end})=1:siz(end);
77            FieldOut.ListVarName=[FieldOut.ListVarName DimList(end)];
78            FieldOut.VarDimName=[FieldOut.VarDimName DimList(end)];
79            CoordMax(ind,numel(siz))=siz(end);
80            if numel(siz)>=2
81                FieldOut.(DimList{end-1})=1:siz(end-1);
82                CoordMax(ind,numel(siz)-1)=siz(end-1);
83                FieldOut.ListVarName=[FieldOut.ListVarName DimList(end-1)];
84                FieldOut.VarDimName=[FieldOut.VarDimName DimList(end-1)];
85            end
86            if numel(siz)>=3
87                FieldOut.(DimList{1})=1:siz(1);
88                CoordMax(ind,1)=siz(1);
89                FieldOut.ListVarName=[FieldOut.ListVarName DimList(1)];
90                FieldOut.VarDimName=[FieldOut.VarDimName DimList(1)];
91            end
92            CoordMin(ind,1:numel(siz))=1;
93            CellInfo{imax(ind)}.CoordSize=CoordMax(ind,:);
94        else
95            XName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end)};
96            YName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end-1)};
97            CoordMax(ind,NbDim)=max(max(Field.(XName)));
98            CoordMin(ind,NbDim)=min(min(Field.(XName)));
99            CoordMax(ind,NbDim-1)=max(max(Field.(YName)));
100            CoordMin(ind,NbDim-1)=min(min(Field.(YName)));
101            %         test_x=1;%test for unstructured coordinates
102            if NbDim==3
103                ZName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(1)};
104                CoordMax(ind,NbDim-2)=max(max(Field.(ZName)));
105                CoordMin(ind,NbDim-2)=min(min(Field.(ZName)));
106            end
[654]107        end
108    end
109    switch CellInfo{imax(ind)}.CoordType
110       
111        case {'scattered','tps'} %unstructured coordinates
112            NbPoints=CellInfo{imax(ind)}.CoordSize;% total nbre of points
113            Mesh(ind)=(prod(CoordMax(ind,:)-CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim)
114        case 'grid'%structured coordinate
115            NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points in each direction
[893]116            if Check4D
[1028]117                NbPoints=NbPoints(1:3);
[893]118            end
[654]119            Mesh(ind)=min((CoordMax(ind,:)-CoordMin(ind,:))./(NbPoints-1));
120    end
[954]121    if isfield(CellInfo{imax(ind)},'ProjModeRequest')
122        if strcmp(CellInfo{imax(ind)}.ProjModeRequest,'interp_tps')
123            FieldOut.ProjModeRequest='interp_tps';
124        end
[1095]125%         if strcmp(CellInfo{imax(ind)}.ProjModeRequest,'interp_lin')&& ~strcmp(FieldOut.ProjModeRequest,'interp_tps')
126%             FieldOut.ProjModeRequest='interp_lin';
127%         end
[1028]128    end
[654]129end
130Mesh=min(Mesh);
131FieldOut.XMax=max(CoordMax(:,end));
132FieldOut.XMin=min(CoordMin(:,end));
133FieldOut.YMax=max(CoordMax(:,end-1));
134FieldOut.YMin=min(CoordMin(:,end-1));
135if NbDim==3
136    FieldOut.ZMax=max(CoordMax(ind,1));
[747]137    FieldOut.ZMin=min(CoordMin(ind,1));
[654]138end
139% adjust the mesh to a value 1, 2 , 5 *10^n
[1078]140FieldOut.CoordMesh = round_uvmat(Mesh);
141
142
Note: See TracBrowser for help on using the repository browser.