source: issm/trunk-jpl/src/m/classes/qmu/continuous_state.py@ 23716

Last change on this file since 23716 was 23716, checked in by bdef, 6 years ago

CHG: shifting to py3 version of python interface (py2 compatible)

File size: 4.2 KB
Line 
1import numpy as np
2from vlist_write import *
3from MatlabArray import *
4
5class continuous_state(object):
6 '''
7 definition for the continuous_state class.
8
9 [csv] = continuous_state.continuous_state(args)
10 csv = continuous_state()
11
12 where the required args are:
13 descriptor (char, description, '')
14 initst (double, initial state, 0.)
15 and the optional args and defaults are:
16 lower (double, lower bound, -Inf)
17 upper (double, upper bound, Inf)
18
19 note that zero arguments constructs a default instance, one
20 argument of the class copies the instance, and two or more
21 arguments constructs a new instance from the arguments.
22'''
23
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)
33
34 # create a default object
35 if nargin == 0:
36 return continuous_state()
37
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')
55
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]
62
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]
76
77 if (nargin > 4):
78 print('continuous_state:extra_arg','Extra arguments for object of class '+str(type(csv))+'.')
79
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'
90
91 return string
92
93 @staticmethod
94 def prop_desc(csv,dstr):
95 if type(csv) not in [list,np.ndarray]:
96 csv = [csv]
97
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)
108
109 return desc
110
111 @staticmethod
112 def prop_initpt(csv):
113 initpt=[]
114 return initpt
115
116 @staticmethod
117 def prop_lower(csv):
118 if type(csv) not in [list,np.ndarray]:
119 return csv.lower
120
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)
126
127 return lower
128
129 @staticmethod
130 def prop_upper(csv):
131 if type(csv) not in [list,np.ndarray]:
132 return csv.upper
133
134 upper = np.zeros(np.size(csv))
135 for i in range(np.size(csv)):
136 upper[i] = csv[i].upper
137
138 upper = allequal(upper, np.inf)
139
140 return upper
141
142 @staticmethod
143 def prop_mean(csv):
144 mean=[]
145 return mean
146
147 @staticmethod
148 def prop_stddev(csv):
149 stddev=[]
150 return sttdev
151
152 @staticmethod
153 def prop_initst(csv):
154 if type(csv) not in [list,np.ndarray]:
155 return csv.initst
156
157 initst = np.zeros(np.size(csv))
158 for i in range(np.size(csv)):
159 initst[i] = csv[i].initst
160
161 initst = allequal(initst,0.)
162
163 return initst
164
165 @staticmethod
166 def prop_stype(csv):
167 stype=''
168 return stype
169
170 @staticmethod
171 def prop_scale(csv):
172 scale=[]
173 return scale
174
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]
179
180 # write variables
181 vlist_write(fidi,'continuous_state','csv',csv)
182
Note: See TracBrowser for help on using the repository browser.