Changeset 25090


Ignore:
Timestamp:
06/21/20 21:48:26 (5 years ago)
Author:
jdquinn
Message:

CHG: Cleanup; saving progress

Location:
issm/trunk-jpl/src/m/classes
Files:
1 added
5 edited

Legend:

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

    r25087 r25090  
    123123                                end
    124124                                if strcmpi(classlist{i},'uniform_uncertain')
    125                                         if  (h~=0),
     125                                        if (h~=0),
    126126                                                error('uniform_uncertain variables should be declared before histogram_bin uncertain variables');
    127127                                        else
  • TabularUnified issm/trunk-jpl/src/m/classes/qmu.py

    r25022 r25090  
    2323        self.output   = 0
    2424        self.variables = OrderedStruct()
     25        self.correlation_matrix = []
    2526        self.responses = OrderedStruct()
    2627        self.method = OrderedDict()
     
    155156
    156157            if np.mod(md.cluster.np - 1, self.params.processors_per_evaluation):
    157                 md.checkmessage('in parallel library mode, the requirement is for md.cluster.np = md.qmu.params.processors_per_evaluation * number_of_slaves, where number_of_slaves will automatically be determined by Dakota. Modify md.cluster.np accordingly')
     158                #md.checkmessage('in parallel library mode, the requirement is for md.cluster.np = md.qmu.params.processors_per_evaluation * number_of_slaves, where number_of_slaves will automatically be determined by Dakota. Modify md.cluster.np accordingly')
    158159
    159160        # Go through variables and check for consistency
     
    163164            if hasattr(variable, 'checkconsistency'):
    164165                variable.checkconsistency(md, solution, analyses)
     166
     167        # Go through variables and check that we have normal uncertains first,
     168        # then uniform uncertains and finally histogram_bin_uncertain. Indeed,
     169        # Dakota will order them this waym, and when we send partitions for
     170        # scaled variables, they better show up in the order Dakota is feeding
     171        # them to us in InputUpdateFromDakotax!
     172        fv = fieldnames(self.variables)
     173        classlist = []
     174        for i in range(len(fv)):
     175            classlist.append(self.variables[fv[i]].__class__.__name__)
     176        n = 0
     177        u = 0
     178        h = 0
     179        for i in range(len(classlist)):
     180            if classlist[i] == 'normal_uncertain':
     181                if u != 0 or h != 0:
     182                    raise Exception('normal uncertain variables should be declared before uniform and hhistogram_bin uncertain variables')
     183                else:
     184                    n = 1
     185            if classlist[i] == 'uniform_uncertain':
     186                if h != 0:
     187                    raise Exception('uniform_uncertain variables should be declared before histogram_bin uncertain variables')
     188                else:
     189                    u = 1
     190            if classlist[i] == 'histogram_bin_uncertain':
     191                h = 1
    165192
    166193        return md
  • TabularUnified issm/trunk-jpl/src/m/classes/qmu/histogram_bin_uncertain.m

    r25078 r25090  
    1 % %  definition for the histogram_bin_uncertain class.
     1%HISTOGRAM BIN UNCERTAIN class definition
    22%
    3 %  [hbu]=histogram_bin_uncertain(varargin)
     3%       [hbu]=histogram_bin_uncertain(varargin)
    44%
    5 %  where the required varargin are:
    6 %    descriptor    (char, description, '')
    7 %    pairs_per_variable          (double vector, [])
    8 %    abscissas          (double vector, [])
    9 %    counts          (int vector, [])
     5%       where the required varargin are:
     6%               descriptor                      (char, description, '')
     7%               pairs_per_variable      (double vector, [])
     8%               abscissas                       (double vector, [])
     9%               counts                          (int vector, [])
    1010%
    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.
     11%       NOTE: A call to the constructor with zero arguments will return a default
     12%       instance; one argument of the class copies the instance; three or more
     13%       arguments constructs a new instance from the arguments.
    1414%
    1515classdef histogram_bin_uncertain
    16     properties
    17         descriptor='';
     16        properties
     17                descriptor='';
    1818                pairs_per_variable=[];
    19         abscissas = [];
    20         counts = [];
    21     end
    22 
    23     methods
    24         function [hbu]=histogram_bin_uncertain(varargin) % {{{
    25 
    26             switch nargin
    27                 case 0 %  create a default object
    28                 case 1 %  copy the object
    29                     if isa(varargin{1},'histogram_bin_uncertain')
    30                         hbu=varargin{1};
    31                     else
    32                         error('Object ''%s'' is a ''%s'' class object, not ''%s''.',...
    33                             inputname(1),class(varargin{1}),'histogram_bin_uncertain');
    34                     end
    35                 case {2,3} %  not enough arguments
    36                     error('Construction of ''%s'' class object requires at least %d inputs.',...
    37                         'histogram_bin_uncertain',4)
    38                 case 4 %
     19                abscissas = [];
     20                counts = [];
     21        end
     22        methods
     23                function [hbu]=histogram_bin_uncertain(varargin) % {{{
     24                        switch nargin
     25                                case 0 % create a default object
     26                                case 1 % copy the object
     27                                        if isa(varargin{1},'histogram_bin_uncertain')
     28                                                hbu=varargin{1};
     29                                        else
     30                                                error('Object ''%s'' is a ''%s'' class object, not ''%s''.',...
     31                                                        inputname(1),class(varargin{1}),'histogram_bin_uncertain');
     32                                        end
     33                                case {2,3} %  not enough arguments
     34                                        error('Construction of ''histogram_bin_uncertain'' class object requires at least %d inputs.',4)
     35                                case 4 %
    3936                                        %  create the object from the input
    4037                                        hbu = histogram_bin_uncertain;
     
    4441                                        hbu.counts=varargin{4};
    4542
    46                 otherwise
    47                                         error('Construction of histogram_bin_uncertain class object requires three arguments, descriptor, abscissas and counts');
    48             end
    49 
    50         end % }}}
     43                                otherwise
     44                                        error('Construction of histogram_bin_uncertain class object requires either (1) no arguments, (2) a histogram_bin_uncertain instance to copy from, or (3) a descriptor and pairs per variable, abscissas, and counts lists');
     45                        end
     46                end % }}}
    5147                function md=checkconsistency(self,md,solution,analyses) % {{{
    5248                end % }}}
    53         function []=disp(hbu) % {{{
    54 
    55 %  display the object
    56 
    57             disp(sprintf('\n'));
    58             for i=1:numel(hbu)
     49                function []=disp(hbu) % {{{
     50                        % display the object
     51                        disp(sprintf('\n'));
     52                        for i=1:numel(hbu)
    5953                disp(sprintf('class ''%s'' object ''%s%s'' = \n',...
    6054                    class(hbu),inputname(1),string_dim(hbu,i)));
     
    6458                disp(sprintf('        counts: %g'      ,hbu(i).counts));
    6559            end
    66 
    6760        end % }}}
    68         function [desc]  =prop_desc(hbu,dstr) % {{{
     61        function [desc]=prop_desc(hbu,dstr) % {{{
    6962            desc=cell(1,numel(hbu));
    7063            for i=1:numel(hbu)
     
    8477            initpt=[];
    8578        end % }}}
    86         function [lower] =prop_lower(hbu) % {{{
     79        function [lower]=prop_lower(hbu) % {{{
    8780            lower=[];
    8881        end % }}}
    89         function [upper] =prop_upper(hbu) % {{{
     82        function [upper]=prop_upper(hbu) % {{{
    9083            upper=[];
    9184        end % }}}
    92         function [mean]  =prop_mean(hbu) % {{{
     85        function [mean]=prop_mean(hbu) % {{{
    9386            mean=[];
    9487        end % }}}
     
    9992            initst=[];
    10093        end % }}}
    101         function [stype] =prop_stype(hbu) % {{{
     94        function [stype]=prop_stype(hbu) % {{{
    10295            stype={};
    10396        end % }}}
    104         function [scale] =prop_scale(hbu) % {{{
     97        function [scale]=prop_scale(hbu) % {{{
    10598            scale=[];
    10699        end % }}}
    107                 function [abscissas] =prop_abscissas(hbu) % {{{
    108                 abscissas=[];
    109                 for i=1:numel(hbu)
    110                         abscissas=[abscissas hbu(i).abscissas];
    111                 end
    112                 abscissas=allequal(abscissas,-Inf);
    113 
    114         end % }}}
     100                function [abscissas]=prop_abscissas(hbu) % {{{
     101                        abscissas=[];
     102                        for i=1:numel(hbu)
     103                                abscissas=[abscissas hbu(i).abscissas];
     104                        end
     105                        abscissas=allequal(abscissas,-Inf);
     106                end % }}}
    115107                function [pairs_per_variable] =prop_pairs_per_variable(hbu) % {{{
    116108                        pairs_per_variable=zeros(1,numel(hbu));
     
    121113        end % }}}
    122114                function [counts] =prop_counts(hbu) % {{{
    123                 counts=[];
    124                 for i=1:numel(hbu)
    125                         counts=[counts hbu(i).counts];
    126                 end
    127                 counts=allequal(counts,-Inf);
    128 
     115                        counts=[];
     116                        for i=1:numel(hbu)
     117                                counts=[counts hbu(i).counts];
     118                        end
     119                        counts=allequal(counts,-Inf);
    129120        end % }}}
    130121                function scaled=isscaled(self) % {{{
     
    138129    methods (Static)
    139130        function []=dakota_write(fidi,dvar) % {{{
     131                        % collect only the variables of the appropriate class
     132                        hbu=struc_class(dvar,'histogram_bin_uncertain');
    140133
    141 %  collect only the variables of the appropriate class
    142 
    143             hbu=struc_class(dvar,'histogram_bin_uncertain');
    144 
    145 %  write variables
    146 
     134                        % write variables
    147135            vlist_write(fidi,'histogram_bin_uncertain','hbu',hbu);
    148136        end % }}}
  • TabularUnified issm/trunk-jpl/src/m/classes/qmu/normal_uncertain.py

    r25044 r25090  
    1414
    1515    Usage:
    16         nuv = normal_uncertain('descriptor',descriptor,'mean',mean,'stddev',stddev,'partition',partition)
    17         where nuv is the normal_uncertain object returned by the constructor, mean and stddev are self
    18         explanatory.  partition is the partition vector for distributed variables. Can be a partition
    19         vector over elements or vertices.
     16        [nuv] = normal_uncertain(
     17            'descriptor', descriptor,
     18            'mean', mean,
     19            'stddev', stddev,
     20            'partition', partition
     21            )
     22
     23        where nuv is the normal_uncertain object returned by the constructor,
     24        mean and stddev are self explanatory, and partition is the partition
     25        vector for distributed variables. Can be a partition vector over
     26        elements or vertices.
    2027
    2128    Example:
     
    3239            )
    3340    '''
    34     def __init__(self):
     41    def __init__(self): #{{{
    3542        self.descriptor = ''
    3643        self.mean       = np.NaN
     
    3845        self.partition  = []
    3946        self.nsteps     = 0
     47    #}}}
    4048
    4149    @staticmethod
     
    5260                nuv = args[0]
    5361            else:
    54                 raise RuntimeError('Object ' + str(args[0]) + ' is a ' + str(type(args[0])) + ' class object, not "normal_uncertain".')
     62                raise Exception('Object ' + str(args[0]) + ' is a ' + str(type(args[0])) + ' class object, not "normal_uncertain".')
    5563
    5664        # create the object from the input
    5765        else:
    58             # lines differ here in other classes / tests; see asizec problem in notes
    5966            nuv = normal_uncertain()
    6067
     
    6774            nuv.stddev     = options.getfieldvalue('stddev')
    6875
    69             #if the variable is scaled, a partition vector should have been supplied, and
    70             #that partition vector should have as many partitions as the mean and stddev
    71             #vectors:
     76            #if the variable is scaled, a partition vector should have been
     77            #supplied, and that partition vector should have as many partitions
     78            #as the mean and stddev vectors:
    7279            if nuv.isscaled():
    7380                nuv.partition = options.getfieldvalue('partition')
     
    7582                npart = qmupart2npart(nuv.partition)
    7683                if npart != nuv.mean.shape[0]:
    77                     raise RuntimeError("normal_uncertain constructor: for the scaled variable %s the row size of the mean field should be identical to the number of partitions" % nuv.descriptor)
     84                    raise Exception("normal_uncertain constructor: for the scaled variable %s the row size of the mean field should be identical to the number of partitions" % nuv.descriptor)
    7885                if npart != nuv.stddev.shape[0]:
    79                     raise RuntimeError("normal_uncertain constructor: for the scaled variable %s the row size of the stddev field should be identical to the number of partitions" % nuv.descriptor)
     86                    raise Exception("normal_uncertain constructor: for the scaled variable %s the row size of the stddev field should be identical to the number of partitions" % nuv.descriptor)
    8087                if nuv.nsteps != nuv.mean.shape[1]:
    81                     raise RuntimeError("normal_uncertain constructor: for the scaled variable %s the col size of the mean field should be identical to the number of time steps" % nuv.descriptor)
     88                    raise Exception("normal_uncertain constructor: for the scaled variable %s the col size of the mean field should be identical to the number of time steps" % nuv.descriptor)
    8289                if nuv.nsteps != nuv.stddev.shape[1]:
    83                     raise RuntimeError("normal_uncertain constructor: for the scaled variable %s the col size of the stddev field should be identical to the number of time steps" % nuv.descriptor)
     90                    raise Exception("normal_uncertain constructor: for the scaled variable %s the col size of the stddev field should be identical to the number of time steps" % nuv.descriptor)
    8491
    8592        return [nuv] # Always return a list, so we have something akin to a MATLAB single row matrix
     
    107114    def checkconsistency(self, md, solution, analyses): #{{{
    108115        md = checkfield(md, 'field', self.mean, 'fieldname', 'normal_uncertain.mean', 'NaN', 1, 'Inf', 1, '>=', 0)
    109         md = checkfield(md, 'field', self.stddev, 'fieldname', 'normal_uncertain.stddev', 'NaN', 1, 'Inf', 1, '>=', 0, 'numel', len(self.mean))
     116        md = checkfield(md, 'field', self.stddev, 'fieldname', 'normal_uncertain.stddev', 'NaN', 1, 'Inf', 1, '>=', 0)
    110117        if self.isscaled():
    111118            if self.partition == []:
    112                 raise RuntimeError("normal_uncertain is a scaled variable, but it's missing a partition vector")
     119                raise Exception("normal_uncertain is a scaled variable, but it's missing a partition vector")
    113120            #better have a partition vector that has as many partitions as stddev's size:
    114121            if self.stddev.shape[0] != partition_npart(self.partititon):
    115                 raise RuntimeError("normal_uncertain error message: row size of stddev and partition size should be identical")
     122                raise Exception("normal_uncertain error message: row size of stddev and partition size should be identical")
    116123            if self.mean.shape[0] != partition_npart(self.partition):
    117                 raise RuntimeError("normal_uncertain error message: row size of mean and partition size should be identical")
     124                raise Exception("normal_uncertain error message: row size of mean and partition size should be identical")
    118125            #we need as many steps in stddev and mean as there are in time steps
    119126            if self.stddev.shape[1] != self.nsteps:
    120                 raise RuntimeError("normal_uncertain error message: col size of stddev and partition size should be identical")
     127                raise Exception("normal_uncertain error message: col size of stddev and partition size should be identical")
    121128            if self.mean.shape[1] != self.nsteps:
    122                 raise RuntimeError("normal_uncertain error message: col size of mean and partition size should be identical")
     129                raise Exception("normal_uncertain error message: col size of mean and partition size should be identical")
    123130            md = checkfield(md, 'field', self.partition, 'fieldname', 'normal_uncertain.partition', 'NaN', 1, 'Inf', 1, '>=', -1, 'numel', [md.mesh.numberofvertices, md.mesh.numberofvertices])
    124131            if self.partition.shape[1] > 1:
    125                 raise RuntimeError("normal_uncertain error message: partition should be a column vector")
     132                raise Exception("normal_uncertain error message: partition should be a column vector")
    126133            partcheck = np.unique(self.partition)
    127134            partmin = min(partcheck)
    128135            partmax = max(partcheck)
    129136            if partmax < -1:
    130                 raise RuntimeError("normal_uncertain error message: partition vector's min value should be -1 (for no partition), or start at 0")
     137                raise Exception("normal_uncertain error message: partition vector's min value should be -1 (for no partition), or start at 0")
    131138            nmax = max(md.mesh.numberofelements, md.mesh.numberofvertices)
    132139            if partmax > nmax:
    133                 raise RuntimeError("normal_uncertain error message: partition vector's values cannot go over the number of vertices or elements")
     140                raise Exception("normal_uncertain error message: partition vector's values cannot go over the number of vertices or elements")
    134141    #}}}
    135142
  • TabularUnified issm/trunk-jpl/src/m/classes/qmu/uniform_uncertain.py

    r25045 r25090  
    1414
    1515    Usage:
    16         uuv = uniform_uncertain(
     16        [uuv] = uniform_uncertain(
    1717            'descriptor', descriptor,
    1818            'lower', lower,
     
    3939            )
    4040    '''
    41     def __init__(self):
     41    def __init__(self): #{{{
    4242        self.descriptor = ''
    4343        self.lower      = -np.Inf
     
    4545        self.partition  = []
    4646        self.nsteps     = 0
    47 
    48     @staticmethod
    49     def uniform_uncertain(*args):
     47    #}}}
     48
     49    @staticmethod
     50    def uniform_uncertain(*args): #{{{
    5051        nargin = len(args)
    5152
     
    5960                uuv = args[0]
    6061            else:
    61                 raise RuntimeError('Object ' + str(args[0]) + ' is a ' + str(type(args[0])) + ' class object, not "uniform_uncertain".')
     62                raise Exception('Object ' + str(args[0]) + ' is a ' + str(type(args[0])) + ' class object, not "uniform_uncertain".')
    6263
    6364        # create the object from the input
     
    7475
    7576            #if the variable is scaled, a partition vector should have been
    76             #supplied, and  that partition vector should have as many partitions as
    77             #the lower and upper vectors:
     77            #supplied, and  that partition vector should have as many
     78            #partitions as the lower and upper vectors:
    7879            if uuv.isscaled():
    7980                uuv.partition = options.getfieldvalue('partition')
     
    8182                npart = qmupart2npart(uuv.partition)
    8283                if npart != uuv.upper.shape[0]:
    83                     raise RuntimeError("uniform_uncertain constructor: for the scaled variable %s the upper field is not currently a vector of values for all the partitions described in the partition vector" % uuv.descriptor)
     84                    raise Exception("uniform_uncertain constructor: for the scaled variable %s the upper field is not currently a vector of values for all the partitions described in the partition vector" % uuv.descriptor)
    8485                if npart != uuv.lower.shape[0]:
    85                     raise RuntimeError("uniform_uncertain constructor: for the scaled variable %s the lower field is not currently a vector of values for all the partitions described in the partition vector" % uuv.descriptor)
     86                    raise Exception("uniform_uncertain constructor: for the scaled variable %s the lower field is not currently a vector of values for all the partitions described in the partition vector" % uuv.descriptor)
    8687                if uuv.nsteps != uuv.upper.shape[1]:
    87                     raise RuntimeError("uniform_uncertain constructor: for the scaled variable %s the col size of the upper field should be identical to the number of time steps" % uuv.descriptor)
     88                    raise Exception("uniform_uncertain constructor: for the scaled variable %s the col size of the upper field should be identical to the number of time steps" % uuv.descriptor)
    8889                if uuv.nsteps != uuv.lower.shape[1]:
    89                     raise RuntimeError("uniform_uncertain constructor: for the scaled variable %s the col size of the lower field should be identical to the number of time steps" % uuv.descriptor)
     90                    raise Exception("uniform_uncertain constructor: for the scaled variable %s the col size of the lower field should be identical to the number of time steps" % uuv.descriptor)
    9091
    9192        return [uuv] # Always return a list, so we have something akin to a MATLAB single row matrix
     93    #}}}
    9294
    9395    def __repr__(self): #{{{
     
    115117        if self.isscaled():
    116118            if self.partition == []:
    117                 raise RuntimeError("uniform_uncertain is a scaled variable, but it's missing a partition vector")
     119                raise Exception("uniform_uncertain is a scaled variable, but it's missing a partition vector")
    118120            #better have a partition vector that has as many partitions as
    119121            #upper and lower's size:
    120122            if self.upper.shape[0] != partition_npart(self.partititon):
    121                 raise RuntimeError("uniform_uncertain error message: row size of upper and partition size should be identical")
     123                raise Exception("uniform_uncertain error message: row size of upper and partition size should be identical")
    122124            if self.lower.shape[0] != partition_npart(self.partition):
    123                 raise RuntimeError("uniform_uncertain error message: row size of lower and partition size should be identical")
     125                raise Exception("uniform_uncertain error message: row size of lower and partition size should be identical")
    124126            #we need as steps in upper and lower as there are time steps
    125127            if self.stddev.shape[1] != self.nsteps:
    126                 raise RuntimeError("uniform_uncertain error message: col size of upper and partition size should be identical")
     128                raise Exception("uniform_uncertain error message: col size of upper and partition size should be identical")
    127129            if self.mean.shape[1] != self.nsteps:
    128                 raise RuntimeError("uniform_uncertain error message: col size of lower and partition size should be identical")
     130                raise Exception("uniform_uncertain error message: col size of lower and partition size should be identical")
    129131            md = checkfield(md, 'field', self.partition, 'fieldname', 'uniform_uncertain.partition', 'NaN', 1, 'Inf', 1, '>=', -1, 'numel', [md.mesh.numberofvertices, md.mesh.numberofvertices])
    130132            if self.partition.shape[1] > 1:
    131                 raise RuntimeError("uniform_uncertain error message: partition should be a column vector")
     133                raise Exception("uniform_uncertain error message: partition should be a column vector")
    132134            partcheck = np.unique(self.partition)
    133135            partmin = min(partcheck)
    134136            partmax = max(partcheck)
    135137            if partmax < -1:
    136                 raise RuntimeError("uniform_uncertain error message: partition vector's min value should be -1 (for no partition), or start at 0")
     138                raise Exception("uniform_uncertain error message: partition vector's min value should be -1 (for no partition), or start at 0")
    137139            nmax = max(md.mesh.numberofelements, md.mesh.numberofvertices)
    138140            if partmax > nmax:
    139                 raise RuntimeError("uniform_uncertain error message: partition vector's values cannot go over the number of vertices or elements")
     141                raise Exception("uniform_uncertain error message: partition vector's values cannot go over the number of vertices or elements")
    140142    #}}}
    141143
Note: See TracChangeset for help on using the changeset viewer.