Changeset 24313 for issm/trunk/src/m/qmu/setupdesign/QmuSetupVariables.py
- Timestamp:
- 11/01/19 12:01:57 (5 years ago)
- Location:
- issm/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk
-
issm/trunk/src
- Property svn:mergeinfo changed
-
issm/trunk/src/m/qmu/setupdesign/QmuSetupVariables.py
r23189 r24313 1 1 from MatlabFuncs import * 2 from uniform_uncertain import *2 from uniform_uncertain import * 3 3 from normal_uncertain import * 4 4 from copy import deepcopy 5 5 6 def QmuSetupVariables(md,dvar,variables):7 6 8 #get descriptor 9 descriptor=variables.descriptor 7 def QmuSetupVariables(md, dvar, variables): 10 8 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 13 11 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. 17 14 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') 25 21 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') 28 25 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) + "'" 33 40 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 42 50 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 52 58 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 60 68 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) + "'" 70 75 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.