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

Last change on this file was 24261, checked in by bdef, 5 years ago

BUG: still some space fix

File size: 5.1 KB
Line 
1import numpy as np
2from vlist_write import *
3from MatlabArray import *
4
5
6class continuous_state(object):
7 '''
8 definition for the continuous_state class.
9
10 [csv] = continuous_state.continuous_state(args)
11 csv = continuous_state()
12
13 where the required args are:
14 descriptor (char, description, '')
15 initst (double, initial state, 0.)
16 and the optional args and defaults are:
17 lower (double, lower bound, -Inf)
18 upper (double, upper bound, Inf)
19
20 note that zero arguments constructs a default instance, one
21 argument of the class copies the instance, and two or more
22 arguments constructs a new instance from the arguments.
23'''
24
25 def __init__(self):
26 self.descriptor = ''
27 self.initst = 0.
28 self.lower = -np.inf
29 self.upper = np.inf
30
31 @staticmethod
32 def continuous_state(*args):
33 nargin = len(args)
34
35 # create a default object
36 if nargin == 0:
37 return continuous_state()
38
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".')
45
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])]
50
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')
56
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]
63
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]
70
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]
77
78 if (nargin > 4):
79 print('continuous_state:extra_arg', 'Extra arguments for object of class ' + str(type(csv)) + '.')
80
81 return csv
82
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'
91
92 return string
93
94 @staticmethod
95 def prop_desc(csv, dstr):
96 if type(csv) not in [list, np.ndarray]:
97 csv = [csv]
98
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'))
107
108 desc = allempty(desc)
109
110 return desc
111
112 @staticmethod
113 def prop_initpt(csv):
114 initpt = []
115 return initpt
116
117 @staticmethod
118 def prop_lower(csv):
119 if type(csv) not in [list, np.ndarray]:
120 return csv.lower
121
122 lower = np.zeros(np.size(csv))
123 for i in range(np.size(csv)):
124 lower[i] = csv[i].lower
125
126 lower = allequal(lower, -np.inf)
127
128 return lower
129
130 @staticmethod
131 def prop_upper(csv):
132 if type(csv) not in [list, np.ndarray]:
133 return csv.upper
134
135 upper = np.zeros(np.size(csv))
136 for i in range(np.size(csv)):
137 upper[i] = csv[i].upper
138
139 upper = allequal(upper, np.inf)
140
141 return upper
142
143 @staticmethod
144 def prop_mean(csv):
145 mean = []
146 return mean
147
148 @staticmethod
149 def prop_stddev(csv):
150 stddev = []
151 return stddev
152
153 @staticmethod
154 def prop_initst(csv):
155 if type(csv) not in [list, np.ndarray]:
156 return csv.initst
157
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 TracBrowser for help on using the repository browser.