Changeset 24830


Ignore:
Timestamp:
05/08/20 21:50:12 (5 years ago)
Author:
Eric.Larour
Message:

CHG: cleaneup classes, with semblant of partition code not activated yet. Goal long term
is to take out md.qmu.vpartition and md.qmu.epartition and to stick it into the md.qmu.variables
themselves.

Location:
issm/trunk-jpl/src/m/classes/qmu
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/classes/qmu/normal_uncertain.m

    r24823 r24830  
    2020    end
    2121    methods
    22         function self=normal_uncertain(varargin) %constructor {{{
     22                function self=normal_uncertain(varargin) %constructor {{{
    2323
    2424                        %recover options:
     
    2929                        self.mean=getfieldvalue(options,'mean');
    3030                        self.stddev=getfieldvalue(options,'stddev');
     31                        self.partition=getfieldvalue(options,'partition',[]); %default not used.
    3132
    32         end %}}}
    33         function disp(self) % {{{
    34                        
    35                         disp(sprintf('   normal uncertain variable: '));
    36                         fielddisplay(self,'descriptor','name tag');
    37                         fielddisplay(self,'mean','pdf mean');
    38                         fielddisplay(self,'mean','pdf standard deviation');
     33                end %}}}
     34        function disp(self) % {{{
    3935
    40         end
    41                 %}}}
    42         function [desc]  =prop_desc(nuv,dstr) % {{{
    43             desc=cell(1,numel(nuv));
    44             for i=1:numel(nuv)
    45                 if ~isempty(nuv(i).descriptor)
    46                     desc(i)=cellstr(nuv(i).descriptor);
    47                 elseif ~isempty(inputname(1))
    48                     desc(i)=cellstr([inputname(1) string_dim(nuv,i,'vector')]);
    49                 elseif exist('dstr','var')
    50                     desc(i)=cellstr([dstr         string_dim(nuv,i,'vector')]);
    51                 else
    52                     desc(i)=cellstr(['nuv'        string_dim(nuv,i,'vector')]);
    53                 end
    54             end
    55             desc=allempty(desc);
    56         end %}}}
    57         function [mean]  =prop_mean(nuv) % {{{
    58             mean=zeros(1,numel(nuv));
    59             for i=1:numel(nuv)
    60                 mean(i)=nuv(i).mean;
    61             end
    62         end % }}}
    63         function [stddev]=prop_stddev(nuv) % {{{
    64             stddev=zeros(1,numel(nuv));
    65             for i=1:numel(nuv)
    66                 stddev(i)=nuv(i).stddev;
    67             end
    68         end % }}}
    69                 function checkconsistency(self,md,solution,analyses) % {{{
    70                 end % }}}
     36                disp(sprintf('   normal uncertain variable: '));
     37                fielddisplay(self,'descriptor','name tag');
     38                fielddisplay(self,'mean','pdf mean');
     39                fielddisplay(self,'stddev','pdf standard deviation');
     40                self.partition
     41                if ~isempty(self.partition),
     42                        fielddisplay(self,'partition','partition vector defining where sampling will occur');
     43                end
     44        end
     45        %}}}
     46        function md=checkconsistency(self,md,solution,analyses) % {{{
     47
     48                md = checkfield(md,'field',self.mean,'fieldname','normal_uncertain.mean','NaN',1,'Inf',1,'>=',0);
     49                md = checkfield(md,'field',self.stddev,'fieldname','normal_uncertain.stddev','NaN',1,'Inf',1,'>=',0,'numel',length(self.mean));
     50                if ~isempty(self.partition),
     51                        md = checkfield(md,'field',self.partition,'fieldname','normal_uncertain.partition','NaN',1,'Inf',1,'>=',-1,'numel',[md.mesh.numberofvertices,md.mesh.numberofelements]);
     52                        if size(self.partition,1)>1,
     53                                error('normal_uncertain error message: partition should be a column vector');
     54                        end
     55                        partcheck=unique(self.partition);
     56                        partmin=min(partcheck);
     57                        partmax=max(partcheck);
     58                        if partmax<-1,
     59                                error('normal_uncertain error message: partition vector''s min value should be -1 (for no partition), or start at 0');
     60                        end
     61                        nmax=max(md.mesh.numberofelements,md.mesh.numberofvertices);
     62                        if partmax>nmax,
     63                                error('normal_uncertain error message: partition vector''s values cannot go over the number of vertices or elements');
     64                        end
     65
     66                end
     67        end % }}}
    7168        %virtual functions needed by qmu processing algorithms:
    72                 function [abscissas] =prop_abscissas(hbu) % {{{
    73             abscissas=[];
    74         end % }}}
    75         function [counts] =prop_counts(hbu) % {{{
    76             counts=[];
    77         end % }}}
    78         function [pairs_per_variable] =prop_pairs_per_variable(hbu) % {{{
    79                         pairs_per_variable=[];
    80         end % }}}
    81         function [initpt]=prop_initpt(nuv) % {{{
    82             initpt=[];
    83         end % }}}
    84         function [lower]  =prop_lower(nuv) % {{{
    85                         lower=[];
    86         end % }}}
    87         function [upper]  =prop_upper(nuv) % {{{
    88                         upper=[];
    89         end % }}}
    90         function [initst]=prop_initst(nuv) % {{{
    91             initst=[];
    92         end % }}}
    93         function [stype] =prop_stype(nuv) % {{{
    94             stype={};
    95         end % }}}
    96         function [scale] =prop_scale(nuv) % {{{
    97             scale=[];
    98         end % }}}
     69        %implemented:
     70        function [desc]  =prop_desc(nuv,dstr) % {{{
     71                desc=cell(1,numel(nuv));
     72                for i=1:numel(nuv)
     73                        if ~isempty(nuv(i).descriptor)
     74                                desc(i)=cellstr(nuv(i).descriptor);
     75                        elseif ~isempty(inputname(1))
     76                                desc(i)=cellstr([inputname(1) string_dim(nuv,i,'vector')]);
     77                        elseif exist('dstr','var')
     78                                desc(i)=cellstr([dstr         string_dim(nuv,i,'vector')]);
     79                        else
     80                                desc(i)=cellstr(['nuv'        string_dim(nuv,i,'vector')]);
     81                        end
     82                end
     83                desc=allempty(desc);
     84        end %}}}
     85        function [mean]  =prop_mean(nuv) % {{{
     86                mean=zeros(1,numel(nuv));
     87                for i=1:numel(nuv)
     88                        mean(i)=nuv(i).mean;
     89                end
     90        end % }}}
     91        function [stddev]=prop_stddev(nuv) % {{{
     92                stddev=zeros(1,numel(nuv));
     93                for i=1:numel(nuv)
     94                        stddev(i)=nuv(i).stddev;
     95                end
     96        end % }}}
     97        %default
     98        function [abscissas] =prop_abscissas(hbu) % {{{
     99                abscissas=[];
     100        end % }}}
     101        function [counts] =prop_counts(hbu) % {{{
     102                counts=[];
     103        end % }}}
     104        function [pairs_per_variable] =prop_pairs_per_variable(hbu) % {{{
     105                pairs_per_variable=[];
     106        end % }}}
     107        function [initpt]=prop_initpt(nuv) % {{{
     108                initpt=[];
     109        end % }}}
     110        function [lower]  =prop_lower(nuv) % {{{
     111                lower=[];
     112        end % }}}
     113        function [upper]  =prop_upper(nuv) % {{{
     114                upper=[];
     115        end % }}}
     116        function [initst]=prop_initst(nuv) % {{{
     117                initst=[];
     118        end % }}}
     119        function [stype] =prop_stype(nuv) % {{{
     120                stype={};
     121        end % }}}
     122        function [scale] =prop_scale(nuv) % {{{
     123                scale=[];
     124        end % }}}
    99125    end
    100126    methods (Static)
  • issm/trunk-jpl/src/m/classes/qmu/uniform_uncertain.m

    r24820 r24830  
     1%UNIFORM_UNCERTAIN Class definition
    12%
    2 %  definition for the uniform_uncertain class.
    3 %
    4 %  [uuv]=uniform_uncertain(varargin)
    5 %
    6 %  where the required varargin are:
    7 %    descriptor    (char, description, '')
    8 %    lower         (double, lower bound, -Inf)
    9 %    upper         (double, upper bound,  Inf)
    10 %
    11 %  note that zero arguments constructs a default instance; one
    12 %  argument of the class copies the instance; and three or more
    13 %  arguments constructs a new instance from the arguments.
    14 %
    15 %  "Copyright 2009, by the California Institute of Technology.
    16 %  ALL RIGHTS RESERVED. United States Government Sponsorship
    17 %  acknowledged. Any commercial use must be negotiated with
    18 %  the Office of Technology Transfer at the California Institute
    19 %  of Technology.  (J. Schiermeier, NTR 47078)
    20 %
    21 %  This software may be subject to U.S. export control laws.
    22 %  By accepting this  software, the user agrees to comply with
    23 %  all applicable U.S. export laws and regulations. User has the
    24 %  responsibility to obtain export licenses, or other export
    25 %  authority as may be required before exporting such information
    26 %  to foreign countries or providing access to foreign persons."
    27 %
     3%%   Usage:
     4%      nuv=uniform_uncertain('descriptor',descriptor,'lower',lower,'upper',upper,'partition',partition);
     5%      where nuv is the uniform_uncertain object returned by the constructor, lower and upper are the
     6%      pdf distribution bounds, and partition is the partition vector for distributed variables.
     7%      Can be a partition %      vector over elements or vertices.
     8%
     9%   Example:
     10%      md.qmu.variables.rheology=uniform_uncertain('descriptor','RheologyBBar','lower',1e8,'upper',1e9);
     11%      md.qmu.variables.rheology=uniform_uncertain('descriptor','RheologyBBar','lower',1e8,'upper',1e9,'partition',vpartition);
     12%
     13
    2814classdef uniform_uncertain
    2915    properties
     
    3117        lower     =-Inf;
    3218        upper     = Inf;
     19                partition = [];
    3320    end
     21    methods
     22                function self=uniform_uncertain(varargin) %constructor {{{
    3423
    35     methods
    36         function [uuv]=uniform_uncertain(varargin)
     24                        %recover options:
     25                        options = pairoptions(varargin{:});
    3726
    38             switch nargin
     27                        %initialize fields:
     28                        self.descriptor=getfieldvalue(options,'descriptor');
     29                        self.upper=getfieldvalue(options,'upper');
     30                        self.lower=getfieldvalue(options,'lower');
     31                        self.partition=getfieldvalue(options,'partition',[]); %default not used.
    3932
    40 %  create a default object
     33                end %}}}
     34                function disp(self) % {{{
    4135
    42                 case 0
     36                        disp(sprintf('   uniform uncertain variable: '));
     37                        fielddisplay(self,'descriptor','name tag');
     38                        fielddisplay(self,'lower','pdf lower bound');
     39                        fielddisplay(self,'upper','pdf upper bound');
     40                        if ~isempty(self.partition),
     41                                fielddisplay(self,'partition','partition vector defining where sampling will occur');
     42                        end
     43                end
     44                %}}}
     45                function md=checkconsistency(self,md,solution,analyses) % {{{
    4346
    44 %  copy the object
     47                        md = checkfield(md,'field',self.upper,'fieldname','uniform_uncertain.upper','NaN',1,'Inf',1);
     48                        md = checkfield(md,'field',self.lower,'fieldname','uniform_uncertain.lower','NaN',1,'Inf',1);
     49                        if ~isempty(self.partition),
     50                                md = checkfield(md,'field',self.partition,'fieldname','uniform_uncertain.partition','NaN',1,'Inf',1,'>=',-1,'numel',[md.mesh.numberofvertices,md.mesh.numberofelements]);
     51                                if size(self.partition,1)>1,
     52                                        error('uniform_uncertain error message: partition should be a column vector');
     53                                end
     54                                partcheck=unique(self.partition);
     55                                partmin=min(partcheck);
     56                                partmax=max(partcheck);
     57                                if partmax<-1,
     58                                        error('uniform_uncertain error message: partition vector''s min value should be -1 (for no partition), or start at 0');
     59                                end
     60                                nmax=max(md.mesh.numberofelements,md.mesh.numberofvertices);
     61                                if partmax>nmax,
     62                                        error('uniform_uncertain error message: partition vector''s values cannot go over the number of vertices or elements');
     63                                end
    4564
    46                 case 1
    47                     if isa(varargin{1},'uniform_uncertain')
    48                         uuv=varargin{1};
    49                     else
    50                         error('Object ''%s'' is a ''%s'' class object, not ''%s''.',...
    51                             inputname(1),class(varargin{1}),'uniform_uncertain');
    52                     end
    53 
    54 %  not enough arguments
    55 
    56                 case 2
    57                     error('Construction of ''%s'' class object requires at least %d inputs.',...
    58                         'uniform_uncertain',3)
    59 
    60 %  create the object from the input
    61 
    62                 otherwise
    63                     asizec=num2cell(array_size(varargin{1:min(nargin,3)}));
    64                     uuv(asizec{:})=uniform_uncertain;
    65                     clear asizec
    66 
    67                     if ischar(varargin{1})
    68                         varargin{1}=cellstr(varargin{1});
    69                     end
    70                     for i=1:numel(uuv)
    71                         if (numel(varargin{1}) > 1)
    72                             uuv(i).descriptor=varargin{1}{i};
    73                         else
    74                             uuv(i).descriptor=[char(varargin{1}) string_dim(uuv,i,'vector')];
    75                         end
    76                         if (numel(varargin{2}) > 1)
    77                             uuv(i).lower     =varargin{2}(i);
    78                         else
    79                             uuv(i).lower     =varargin{2};
    80                         end
    81                         if (numel(varargin{3}) > 1)
    82                             uuv(i).upper     =varargin{3}(i);
    83                         else
    84                             uuv(i).upper     =varargin{3};
    85                         end
    86                     end
    87             end
    88 
    89         end
    90 
    91         function []=disp(uuv)
    92 
    93 %  display the object
    94 
    95             disp(sprintf('\n'));
    96             for i=1:numel(uuv)
    97                 disp(sprintf('class ''%s'' object ''%s%s'' = \n',...
    98                     class(uuv),inputname(1),string_dim(uuv,i)));
    99                 disp(sprintf('    descriptor: ''%s'''  ,uuv(i).descriptor));
    100                 disp(sprintf('         lower: %g'      ,uuv(i).lower));
    101                 disp(sprintf('         upper: %g\n'    ,uuv(i).upper));
    102             end
    103 
    104         end
    105 
    106         function [desc]  =prop_desc(uuv,dstr)
    107             desc=cell(1,numel(uuv));
    108             for i=1:numel(uuv)
    109                 if ~isempty(uuv(i).descriptor)
    110                     desc(i)=cellstr(uuv(i).descriptor);
    111                 elseif ~isempty(inputname(1))
    112                     desc(i)=cellstr([inputname(1) string_dim(uuv,i,'vector')]);
    113                 elseif exist('dstr','var')
    114                     desc(i)=cellstr([dstr         string_dim(uuv,i,'vector')]);
    115                 else
    116                     desc(i)=cellstr(['uuv'        string_dim(uuv,i,'vector')]);
    117                 end
    118             end
    119             desc=allempty(desc);
    120         end
    121         function [initpt]=prop_initpt(uuv)
    122             initpt=[];
    123         end
    124         function [lower] =prop_lower(uuv)
    125             lower=zeros(1,numel(uuv));
    126             for i=1:numel(uuv)
    127                 lower(i)=uuv(i).lower;
    128             end
    129             lower=allequal(lower,-Inf);
    130         end
    131         function [upper] =prop_upper(uuv)
    132             upper=zeros(1,numel(uuv));
    133             for i=1:numel(uuv)
    134                 upper(i)=uuv(i).upper;
    135             end
    136             upper=allequal(upper, Inf);
    137         end
    138         function [mean]  =prop_mean(uuv)
    139             mean=[];
    140         end
    141         function [stddev]=prop_stddev(uuv)
    142             stddev=[];
    143         end
    144         function [initst]=prop_initst(uuv)
    145             initst=[];
    146         end
    147         function [stype] =prop_stype(uuv)
    148             stype={};
    149         end
    150         function [scale] =prop_scale(uuv)
    151             scale=[];
    152         end
    153                 function [abscissas] =prop_abscissas(hbu) % {{{
    154             abscissas=[];
    155         end % }}}
    156         function [counts] =prop_counts(hbu) % {{{
    157             counts=[];
    158         end % }}}
    159         function [pairs_per_variable] =prop_pairs_per_variable(hbu) % {{{
    160                         pairs_per_variable=[];
    161         end % }}}
    162                 function checkconsistency(self,md,solution,analyses) % {{{
     65                        end
    16366                end % }}}
    164 
     67        %virtual functions needed by qmu processing algorithms:
     68        %implemented:
     69                function [desc]  =prop_desc(uuv,dstr) % {{{
     70                        desc=cell(1,numel(uuv));
     71                        for i=1:numel(uuv)
     72                                if ~isempty(uuv(i).descriptor)
     73                                        desc(i)=cellstr(uuv(i).descriptor);
     74                                elseif ~isempty(inputname(1))
     75                                        desc(i)=cellstr([inputname(1) string_dim(uuv,i,'vector')]);
     76                                elseif exist('dstr','var')
     77                                        desc(i)=cellstr([dstr         string_dim(uuv,i,'vector')]);
     78                                else
     79                                        desc(i)=cellstr(['uuv'        string_dim(uuv,i,'vector')]);
     80                                end
     81                        end
     82                        desc=allempty(desc);
     83                end %}}}
     84                function [lower] =prop_lower(uuv) %{{{
     85                        lower=zeros(1,numel(uuv));
     86                        for i=1:numel(uuv)
     87                                lower(i)=uuv(i).lower;
     88                        end
     89                        lower=allequal(lower,-Inf);
     90                end %}}}
     91                function [upper] =prop_upper(uuv) %{{{
     92                        upper=zeros(1,numel(uuv));
     93                        for i=1:numel(uuv)
     94                                upper(i)=uuv(i).upper;
     95                        end
     96                        upper=allequal(upper, Inf);
     97                end % }}}
     98        %default
     99                function [stddev]=prop_stddev(uuv)  %{{{
     100                        stddev=[];
     101                        end % }}}
     102                        function [mean]  =prop_mean(nuv) % {{{
     103                        mean=[];
     104                        end % }}}
     105                        function [initpt]=prop_initpt(uuv) %{{{
     106                        initpt=[];
     107                        end %}}}
     108                        function [initst]=prop_initst(uuv) %{{{
     109                                initst=[];
     110                                end %}}}
     111                                function [stype] =prop_stype(uuv) %{{{
     112                                stype={};
     113                                end %}}}
     114                                function [scale] =prop_scale(uuv) %{{{
     115                                scale=[];
     116                                end %}}}
     117                                function [abscissas] =prop_abscissas(hbu) % {{{
     118                                abscissas=[];
     119                                end % }}}
     120                                function [counts] =prop_counts(hbu) % {{{
     121                                counts=[];
     122                                end % }}}
     123                                function [pairs_per_variable] =prop_pairs_per_variable(hbu) % {{{
     124                                pairs_per_variable=[];
     125                                end % }}}
    165126    end
    166 
    167     methods (Static)
    168         function []=dakota_write(fidi,dvar)
    169 
    170 %  collect only the variables of the appropriate class
    171 
     127        methods (Static)
     128        function []=dakota_write(fidi,dvar) % {{{
     129                        %  collect only the variables of the appropriate class
    172130            uuv=struc_class(dvar,'uniform_uncertain');
    173 
    174 %  write variables
    175 
     131                        %  write variables
    176132            vlist_write(fidi,'uniform_uncertain','uuv',uuv);
    177         end
     133        end %}}}
    178134    end
    179135end
Note: See TracChangeset for help on using the changeset viewer.