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/qmu/setupdesign/QmuSetupVariables.py

    r23189 r24313  
    11from MatlabFuncs import *
    2 from uniform_uncertain import*
     2from uniform_uncertain import *
    33from normal_uncertain import *
    44from copy import deepcopy
    55
    6 def QmuSetupVariables(md,dvar,variables):
    76
    8         #get descriptor
    9         descriptor=variables.descriptor
     7def QmuSetupVariables(md, dvar, variables):
    108
    11         #decide whether this is a distributed variable, which will drive whether we expand it into npart values,
    12         #or if we just carry it forward as is.
     9    #get descriptor
     10    descriptor = variables.descriptor
    1311
    14         #ok, key off according to type of descriptor:
    15         if strncmp(descriptor,'scaled_',7):
    16                 #we have a scaled variable, expand it over the partition.
     12    #decide whether this is a distributed variable, which will drive whether we expand it into npart values,
     13    #or if we just carry it forward as is.
    1714
    18                 if isinstance(variables,uniform_uncertain):
    19                         if ((type(variables.lower) in [list,np.ndarray] and len(variables.lower) > md.qmu.numberofpartitions) or (type(variables.upper) in [list,np.ndarray] and len(variables.upper) > md.qmu.numberofpartitions)):
    20                                 raise RuntimeError('QmuSetupDesign error message: upper and lower should be either a scalar or a "npart" length vector')
    21                        
    22                 elif isinstance(variables,normal_uncertain):
    23                         if type(variables.stddev) in [list,np.ndarray] and len(variables.stddev) > md.qmu.numberofpartitions:
    24                                 raise RuntimeError('QmuSetupDesign error message: stddev should be either a scalar or a "npart" length vector')
     15    #ok, key off according to type of descriptor:
     16    if strncmp(descriptor, 'scaled_', 7):
     17        #we have a scaled variable, expand it over the partition.
     18        if isinstance(variables, uniform_uncertain):
     19            if ((type(variables.lower) in [list, np.ndarray] and len(variables.lower) > md.qmu.numberofpartitions) or (type(variables.upper) in [list, np.ndarray] and len(variables.upper) > md.qmu.numberofpartitions)):
     20                raise RuntimeError('QmuSetupDesign error message: upper and lower should be either a scalar or a "npart" length vector')
    2521
    26                 #ok, dealing with semi-discrete distributed variable. Distribute according to how many
    27                 #partitions we want
     22        elif isinstance(variables, normal_uncertain):
     23            if type(variables.stddev) in [list, np.ndarray] and len(variables.stddev) > md.qmu.numberofpartitions:
     24                raise RuntimeError('QmuSetupDesign error message: stddev should be either a scalar or a "npart" length vector')
    2825
    29                 for j in range(md.qmu.numberofpartitions):
    30                         dvar.append(deepcopy(variables))
    31                         # "'" is because qmu.in files need for strings to be in actual ''
    32                         # must also account for whether we are given 1 instance or an array of instances
     26        #ok, dealing with semi - discrete distributed variable. Distribute according to how many
     27        #partitions we want
     28        for j in range(md.qmu.numberofpartitions):
     29            dvar.append(deepcopy(variables))
     30            # "'" is because qmu.in files need for strings to be in actual ''
     31            # must also account for whether we are given 1 instance or an array of instances
     32            # handle descriptors for everything
     33            if type(dvar[-1].descriptor) in [list, np.ndarray] and len(variables.descriptor) > 1 and len(variables.upper) != md.qmu.numberofpartitions:
     34                if type(variables.descriptor) == np.ndarray:
     35                    dvar[-1].descriptor = np.append(dvar[-1].descriptor, "'" + str(variables.descriptor) + '_' + str(j + 1) + "'")
     36                else:
     37                    dvar[-1].descriptor.append("'" + str(variables.descriptor) + '_' + str(j + 1) + "'")
     38            else:
     39                dvar[-1].descriptor = "'" + str(variables.descriptor) + '_' + str(j + 1) + "'"
    3340
    34                         # handle descriptors for everything
    35                         if type(dvar[-1].descriptor) in [list,np.ndarray] and len(variables.descriptor) > 1 and len(variables.upper) != md.qmu.numberofpartitions:
    36                                 if type(variables.descriptor) == np.ndarray:
    37                                         dvar[-1].descriptor = np.append(dvar[-1].descriptor,"'"+str(variables.descriptor)+'_'+str(j+1)+"'")
    38                                 else:
    39                                         dvar[-1].descriptor.append("'"+str(variables.descriptor)+'_'+str(j+1)+"'")
    40                         else:
    41                                 dvar[-1].descriptor = "'"+str(variables.descriptor)+'_'+str(j+1)+"'"
     41    # handle uniform_uncertain
     42            if isinstance(variables, uniform_uncertain):
     43                if type(variables.lower) in [list, np.ndarray] and len(variables.lower) > 1 and len(variables.upper) != md.qmu.numberofpartitions:
     44                    if type(variables.lower) == np.ndarray:
     45                        dvar[-1].lower = np.append(dvar[-1].lower, variables.lower[j])
     46                    else:
     47                        dvar[-1].lower.append(variables.lower[j])
     48                else:
     49                    dvar[-1].lower = variables.lower
    4250
    43                         # handle uniform_uncertain
    44                         if isinstance(variables,uniform_uncertain):
    45                                 if type(variables.lower) in [list,np.ndarray] and len(variables.lower) > 1 and len(variables.upper) != md.qmu.numberofpartitions:
    46                                         if type(variables.lower) == np.ndarray:
    47                                                 dvar[-1].lower = np.append(dvar[-1].lower, variables.lower[j])
    48                                         else:
    49                                                 dvar[-1].lower.append(variables.lower[j])
    50                                 else:
    51                                         dvar[-1].lower = variables.lower
     51                if type(variables.upper) in [list, np.ndarray] and len(variables.upper) > 1 and len(variables.upper) != md.qmu.numberofpartitions:
     52                    if type(variables.upper) == np.ndarray:
     53                        dvar[-1].upper = np.append(dvar[-1].upper, variables.upper[j])
     54                    else:
     55                        dvar[-1].upper.append(variables.upper[j])
     56                else:
     57                    dvar[-1].upper = variables.upper
    5258
    53                                 if type(variables.upper) in [list,np.ndarray] and len(variables.upper) > 1 and len(variables.upper) != md.qmu.numberofpartitions:
    54                                         if type(variables.upper) == np.ndarray:
    55                                                 dvar[-1].upper = np.append(dvar[-1].upper, variables.upper[j])
    56                                         else:
    57                                                 dvar[-1].upper.append(variables.upper[j])
    58                                 else:
    59                                         dvar[-1].upper = variables.upper
     59    # handle normal_uncertain
     60            elif isinstance(variables, normal_uncertain):
     61                if type(variables.stddev) in [list, np.ndarray] and len(variables.stddev) > 1 and len(variables.upper) != md.qmu.numberofpartitions:
     62                    if type(variables.stddev) == np.ndarray:
     63                        dvar[-1].stddev = np.append(dvar[-1].stddev, variables.stddev[j])
     64                    else:
     65                        dvar[-1].stddev.append(variables.stddev[j])
     66                else:
     67                    dvar[-1].stddev = variables.stddev
    6068
    61                         # handle normal_uncertain
    62                         elif isinstance(variables,normal_uncertain):
    63                                 if type(variables.stddev) in [list,np.ndarray] and len(variables.stddev) > 1 and len(variables.upper) != md.qmu.numberofpartitions:
    64                                         if type(variables.stddev) == np.ndarray:
    65                                                 dvar[-1].stddev = np.append(dvar[-1].stddev, variables.stddev[j])
    66                                         else:
    67                                                 dvar[-1].stddev.append(variables.stddev[j])
    68                                 else:
    69                                         dvar[-1].stddev = variables.stddev
     69    # running with a single instance, and therefore length 1 arrays of qmu classes
     70    else:
     71        dvar.append(variables)
     72    # text parsing in dakota requires literal "'identifier'" not just "identifier"
     73        for v in dvar:
     74            v.descriptor = "'" + str(v.descriptor) + "'"
    7075
    71         # running with a single instance, and therefore length 1 arrays of qmu classes
    72         else:
    73                 dvar.append(variables)
    74                 # text parsing in dakota requires literal "'identifier'" not just "identifier"
    75                 for v in dvar:
    76                         v.descriptor = "'"+str(v.descriptor)+"'"
    77 
    78         return dvar
    79        
     76    return dvar
Note: See TracChangeset for help on using the changeset viewer.