1 | from MatlabFuncs import *
|
---|
2 | from uniform_uncertain import*
|
---|
3 | from normal_uncertain import *
|
---|
4 | from copy import deepcopy
|
---|
5 |
|
---|
6 | def QmuSetupVariables(md,dvar,variables):
|
---|
7 |
|
---|
8 | #get descriptor
|
---|
9 | descriptor=variables.descriptor
|
---|
10 |
|
---|
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.
|
---|
13 |
|
---|
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.
|
---|
17 |
|
---|
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')
|
---|
25 |
|
---|
26 | #ok, dealing with semi-discrete distributed variable. Distribute according to how many
|
---|
27 | #partitions we want
|
---|
28 |
|
---|
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
|
---|
33 |
|
---|
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)+"'"
|
---|
42 |
|
---|
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
|
---|
52 |
|
---|
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
|
---|
60 |
|
---|
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
|
---|
70 |
|
---|
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 |
|
---|