Ignore:
Timestamp:
11/01/19 12:01:57 (5 years ago)
Author:
Mathieu Morlighem
Message:

merged trunk-jpl and trunk for revision 24310

Location:
issm/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk

  • issm/trunk/src

  • issm/trunk/src/m/classes/qmu/continuous_state.py

    r23189 r24313  
    33from MatlabArray import *
    44
     5
    56class continuous_state(object):
    6         '''
     7    '''
    78  definition for the continuous_state class.
    89
    910  [csv] = continuous_state.continuous_state(args)
    10    csv  = continuous_state()
     11   csv = continuous_state()
    1112
    1213  where the required args are:
     
    1516  and the optional args and defaults are:
    1617    lower         (double, lower bound, -Inf)
    17     upper         (double, upper bound,  Inf)
     18    upper         (double, upper bound, Inf)
    1819
    1920  note that zero arguments constructs a default instance, one
     
    2223'''
    2324
    24         def __init__(self):
    25                 self.descriptor = ''
    26                 self.initst     =  0.
    27                 self.lower      = -np.inf
    28                 self.upper      =  np.inf
    29        
    30         @staticmethod
    31         def continuous_state(*args):
    32                 nargin = len(args)
     25    def __init__(self):
     26        self.descriptor = ''
     27        self.initst = 0.
     28        self.lower = -np.inf
     29        self.upper = np.inf
    3330
    34                 #  create a default object
    35                 if nargin == 0:
    36                         return continuous_state()
     31    @staticmethod
     32    def continuous_state(*args):
     33        nargin = len(args)
    3734
    38                 #  copy the object
    39                 if nargin == 1:
    40                         if isinstance(args[0],continuous_state):
    41                                 csv = args[0]
    42                         else:
    43                                 raise RuntimeError('Object is a '+str(type(args[0]))+' class object, not "continuous_state".')
    44                                        
    45                 #  create the object from the input
    46                 else:
    47                         shapec = np.shape(*args[0:min(nargin,4)])
    48                         csv = [continuous_state() for i in range(shapec[0]) for j in range(shapec[1])]
    49                                        
    50                         for i in range(np.size(csv)):
    51                                 if (np.size(args[0]) > 1):
    52                                         csv[i].descriptor        = args[0][i]
    53                                 else:
    54                                         csv[i].descriptor        = str(args[0])+string_dim(csv,i,'vector')
     35        #  create a default object
     36        if nargin == 0:
     37            return continuous_state()
    5538
    56                         if (nargin >= 2):
    57                                 for i in range(np.size(csv)):
    58                                         if (np.size(args[1]) > 1):
    59                                                 csv[i].initst    = args[1][i]
    60                                         else:
    61                                                 csv[i].initst    = args[1]
     39        #  copy the object
     40        if nargin == 1:
     41            if isinstance(args[0], continuous_state):
     42                csv = args[0]
     43            else:
     44                raise RuntimeError('Object is a ' + str(type(args[0])) + ' class object, not "continuous_state".')
    6245
    63                         if (nargin >= 3):
    64                                 for i in range(np.size(csv)):
    65                                         if (np.size(args[2]) > 1):
    66                                                 csv[i].lower     = args[2][i]
    67                                         else:
    68                                                 csv[i].lower     = args[2]
    69        
    70                         if (nargin >= 4):
    71                                 for i in range(np.size(csv)):
    72                                         if (np.size(args[3]) > 1):
    73                                                 csv[i].upper     = args[3][i]
    74                                         else:
    75                                                 csv[i].upper     = args[3]
     46        #  create the object from the input
     47        else:
     48            shapec = np.shape(*args[0:min(nargin, 4)])
     49            csv = [continuous_state() for i in range(shapec[0]) for j in range(shapec[1])]
    7650
    77                         if (nargin > 4):
    78                                 print 'continuous_state:extra_arg','Extra arguments for object of class '+str(type(csv))+'.'
     51            for i in range(np.size(csv)):
     52                if (np.size(args[0]) > 1):
     53                    csv[i].descriptor = args[0][i]
     54                else:
     55                    csv[i].descriptor = str(args[0]) + string_dim(csv, i, 'vector')
    7956
    80                 return csv
    81                                                                                
    82         def __repr__(self):
    83                 #  display the object
    84                 string = '\n'
    85                 string += 'class "continuous_state" object = \n'
    86                 string += '    descriptor: ' +str(self.descriptor) + '\n'
    87                 string += '        initst: ' +str(self.initst) + '\n'
    88                 string += '         lower: ' +str(self.lower) + '\n'
    89                 string += '         upper: ' +str(self.upper) + '\n'
     57            if (nargin >= 2):
     58                for i in range(np.size(csv)):
     59                    if (np.size(args[1]) > 1):
     60                        csv[i].initst = args[1][i]
     61                    else:
     62                        csv[i].initst = args[1]
    9063
    91                 return string
     64            if (nargin >= 3):
     65                for i in range(np.size(csv)):
     66                    if (np.size(args[2]) > 1):
     67                        csv[i].lower = args[2][i]
     68                    else:
     69                        csv[i].lower = args[2]
    9270
    93         @staticmethod
    94         def prop_desc(csv,dstr):
    95                 if type(csv) not in [list,np.ndarray]:
    96                         csv = [csv]
     71            if (nargin >= 4):
     72                for i in range(np.size(csv)):
     73                    if (np.size(args[3]) > 1):
     74                        csv[i].upper = args[3][i]
     75                    else:
     76                        csv[i].upper = args[3]
    9777
    98                 desc = ['' for i in range(np.size(csv))]
    99                 for i in range(np.size(csv)):
    100                         if csv[i].descriptor != '' or type(cdv[i].descriptor) != str:
    101                                 desc[i] = str(csv[i].descriptor)
    102                         elif dstr != '':
    103                                 desc[i] = str(dstr)+str(string_dim(csv,i,'vector'))
    104                         else:
    105                                 desc[i] = 'csv'+str(string_dim(csv,i,'vector'))
    106                        
    107                 desc = allempty(desc)
     78            if (nargin > 4):
     79                print('continuous_state:extra_arg', 'Extra arguments for object of class ' + str(type(csv)) + '.')
    10880
    109                 return desc
     81        return csv
    11082
    111         @staticmethod   
    112         def prop_initpt(csv):
    113                 initpt=[]
    114                 return initpt
     83    def __repr__(self):
     84        #  display the object
     85        string = '\n'
     86        string += 'class "continuous_state" object = \n'
     87        string += '    descriptor: ' + str(self.descriptor) + '\n'
     88        string += '        initst: ' + str(self.initst) + '\n'
     89        string += '         lower: ' + str(self.lower) + '\n'
     90        string += '         upper: ' + str(self.upper) + '\n'
    11591
    116         @staticmethod
    117         def prop_lower(csv):
    118                 if type(csv) not in [list,np.ndarray]:
    119                         return csv.lower
     92        return string
    12093
    121                 lower = np.zeros(np.size(csv))
    122                 for i in range(np.size(csv)):
    123                         lower[i] = csv[i].lower
    124                        
    125                 lower = allequal(lower,-np.inf)
     94    @staticmethod
     95    def prop_desc(csv, dstr):
     96        if type(csv) not in [list, np.ndarray]:
     97            csv = [csv]
    12698
    127                 return lower
     99        desc = ['' for i in range(np.size(csv))]
     100        for i in range(np.size(csv)):
     101            if csv[i].descriptor != '' or type(cdv[i].descriptor) != str:
     102                desc[i] = str(csv[i].descriptor)
     103            elif dstr != '':
     104                desc[i] = str(dstr) + str(string_dim(csv, i, 'vector'))
     105            else:
     106                desc[i] = 'csv' + str(string_dim(csv, i, 'vector'))
    128107
    129         @staticmethod   
    130         def prop_upper(csv):
    131                 if type(csv) not in [list,np.ndarray]:
    132                         return csv.upper
     108        desc = allempty(desc)
    133109
    134                 upper = np.zeros(np.size(csv))
    135                 for i in range(np.size(csv)):
    136                         upper[i] = csv[i].upper
     110        return desc
    137111
    138                 upper = allequal(upper, np.inf)
     112    @staticmethod
     113    def prop_initpt(csv):
     114        initpt = []
     115        return initpt
    139116
    140                 return upper
     117    @staticmethod
     118    def prop_lower(csv):
     119        if type(csv) not in [list, np.ndarray]:
     120            return csv.lower
    141121
    142         @staticmethod   
    143         def prop_mean(csv):
    144                 mean=[]
    145                 return mean
     122        lower = np.zeros(np.size(csv))
     123        for i in range(np.size(csv)):
     124            lower[i] = csv[i].lower
    146125
    147         @staticmethod   
    148         def prop_stddev(csv):
    149                 stddev=[]
    150                 return sttdev
     126        lower = allequal(lower, -np.inf)
    151127
    152         @staticmethod   
    153         def prop_initst(csv):
    154                 if type(csv) not in [list,np.ndarray]:
    155                         return csv.initst
     128        return lower
    156129
    157                 initst = np.zeros(np.size(csv))
    158                 for i in range(np.size(csv)):
    159                         initst[i] = csv[i].initst
     130    @staticmethod
     131    def prop_upper(csv):
     132        if type(csv) not in [list, np.ndarray]:
     133            return csv.upper
    160134
    161                 initst = allequal(initst,0.)
     135        upper = np.zeros(np.size(csv))
     136        for i in range(np.size(csv)):
     137            upper[i] = csv[i].upper
    162138
    163                 return initst
     139        upper = allequal(upper, np.inf)
    164140
    165         @staticmethod   
    166         def prop_stype(csv):
    167                 stype=''
    168                 return stype
     141        return upper
    169142
    170         @staticmethod           
    171         def prop_scale(csv):
    172                 scale=[]
    173                 return scale
     143    @staticmethod
     144    def prop_mean(csv):
     145        mean = []
     146        return mean
    174147
    175         @staticmethod
    176         def dakota_write(fidi,dvar):
    177                 #  collect only the variables of the appropriate class
    178                 csv = [struc_class(i,'continuous_state','csv') for i in dvar]
     148    @staticmethod
     149    def prop_stddev(csv):
     150        stddev = []
     151        return stddev
    179152
    180                 #  write variables
    181                 vlist_write(fidi,'continuous_state','csv',csv)
     153    @staticmethod
     154    def prop_initst(csv):
     155        if type(csv) not in [list, np.ndarray]:
     156            return csv.initst
    182157
     158        initst = np.zeros(np.size(csv))
     159        for i in range(np.size(csv)):
     160            initst[i] = csv[i].initst
     161
     162        initst = allequal(initst, 0.)
     163
     164        return initst
     165
     166    @staticmethod
     167    def prop_stype(csv):
     168        stype = ''
     169        return stype
     170
     171    @staticmethod
     172    def prop_scale(csv):
     173        scale = []
     174        return scale
     175
     176    @staticmethod
     177    def dakota_write(fidi, dvar):
     178        #  collect only the variables of the appropriate class
     179        csv = [struc_class(i, 'continuous_state', 'csv') for i in dvar]
     180
     181        #  write variables
     182        vlist_write(fidi, 'continuous_state', 'csv', csv)
Note: See TracChangeset for help on using the changeset viewer.