3 ==============================================
4 :mod:`calcium` -- python interface
5 ==============================================
9 :synopsis: calcium interface (connect to YACS and exchange data between coupled components)
11 calcium python module provides all is needed to connect to YACS and exchange data between coupled components.
13 Presentation is done in the following order:
17 - functions to connect and disconnect
18 - functions to export data
19 - functions to import data
20 - functions to erase data
25 The constants defined in this module are:
29 This constant is used in cp_e* and cp_l* calls to indicate that data are associated to a time step.
31 .. data:: CP_ITERATION
33 This constant is used in cp_e* and cp_l* calls to indicate that data are associated to an iteration number.
35 .. data:: CP_SEQUENTIEL
37 This constant is used in cp_l* calls to indicate that the call requests the next data that has been produced.
41 This constant can be used in cp_fin to indicate that variables produced by the component are defined
42 beyond the last time or iteration number and their value is equal to the last value produced.
46 This constant can be used in cp_fin to indicate that variables produced by the component are not defined
47 beyond the last time or iteration number.
49 and all the error codes as listed in :ref:`errcodes`.
53 numpy arrays can be used to export or import data but if the numpy module is not installed
54 calcium provides simple array types to replace them.
56 .. class:: calcium.intArray(nelem)
58 The constructor takes a single argument which is the number of elements of the array
60 .. class:: calcium.longArray(nelem)
62 The constructor takes a single argument which is the number of elements of the array
64 .. class:: calcium.floatArray(nelem)
66 The constructor takes a single argument which is the number of elements of the array
68 .. class:: calcium.doubleArray(nelem)
70 The constructor takes a single argument which is the number of elements of the array
72 .. class:: calcium.stringArray(nelem, eltsize)
74 The constructor takes two arguments: the number of elements of the array and the size
75 of the elements (strings)
77 Functions to connect and disconnect
78 ===============================================
80 .. function:: calcium.cp_cd(compo) -> info, name
82 Initialize the connection with YACS.
84 :param compo: component reference
85 :type compo: SALOME component object
87 :param info: error code
89 :param name: instance name given by YACS
92 .. function:: calcium.cp_fin(compo, directive) -> info
94 Close the connection with YACS.
96 :param compo: component reference
97 :type compo: SALOME component object
98 :param directive: indicate how variables will be handled after disconnection. If directive = CP_CONT,
99 variables produced by this component are defined constant beyond the last time or iteration number. If
100 directive = CP_ARRET, variables are not defined beyond the last step.
103 :param info: error code
106 Functions to export data
107 ============================
108 .. function:: calcium.cp_ere(compo, dep, t, i, nm_var, n,var_real) -> info
109 .. function:: calcium.cp_edb(compo, dep, t, i, nm_var, n,var_double) -> info
110 .. function:: calcium.cp_ecp(compo, dep, t, i, nm_var, n,var_complex) -> info
111 .. function:: calcium.cp_een(compo, dep, t, i, nm_var, n,var_integer) -> info
112 .. function:: calcium.cp_elg(compo, dep, t, i, nm_var, n,var_long) -> info
113 .. function:: calcium.cp_eln(compo, dep, t, i, nm_var, n,var_long) -> info
114 .. function:: calcium.cp_elo(compo, dep, t, i, nm_var, n,var_boolean) -> info
115 .. function:: calcium.cp_ech(compo, dep, t, i, nm_var, n,var_string) -> info
117 :param compo: component reference
118 :type compo: SALOME component object
119 :param dep: dependency mode (calcium.CP_TEMPS, calcium.CP_ITERATION)
121 :param t: export time if mode=calcium.CP_TEMPS
123 :param i: export iteration number if mode=calcium.CP_ITERATION
125 :param nm_var: port name
127 :param n: number of values to export
129 :param var_real: array containing float values to export
130 :type var_real: float numpy array or :class:`calcium.floatArray`
131 :param var_double: array containing double values to export
132 :type var_double: double numpy array or :class:`calcium.doubleArray`
133 :param var_complex: array containing complex values to export
134 :type var_complex: complex numpy array or :class:`calcium.floatArray` (double size)
135 :param var_integer: array containing integer values to export
136 :type var_integer: integer numpy array or :class:`calcium.intArray`
137 :param var_long: array containing long values to export
138 :type var_long: long numpy array or :class:`calcium.longArray`
139 :param var_boolean: array containing boolean values to export
140 :type var_boolean: integer numpy array or :class:`calcium.intArray`
141 :param var_string: array containing string values to export
142 :type var_string: string numpy array or :class:`calcium.stringArray`
144 :param info: error code
147 With numpy, the data types to use when creating the array, are the following:
149 ============ ====================
150 Request numpy data type
151 ============ ====================
160 ============ ====================
164 For cp_lch xx is the size of the element string
167 Functions to import data
168 ===========================
169 .. function:: calcium.cp_lre(compo, dep, ti, tf, i, nm_var, len, var_real) -> info, t, ii, n
170 .. function:: calcium.cp_ldb(compo, dep, ti, tf, i, nm_var, len, var_double) -> info, t, ii, n
171 .. function:: calcium.cp_lcp(compo, dep, ti, tf, i, nm_var, len, var_complex) -> info, t, ii, n
172 .. function:: calcium.cp_len(compo, dep, ti, tf, i, nm_var, len, var_integer) -> info, t, ii, n
173 .. function:: calcium.cp_llg(compo, dep, ti, tf, i, nm_var, len, var_long) -> info, t, ii, n
174 .. function:: calcium.cp_lln(compo, dep, ti, tf, i, nm_var, len, var_long) -> info, t, ii, n
175 .. function:: calcium.cp_llo(compo, dep, ti, tf, i, nm_var, len, var_boolean) -> info, t, ii, n
176 .. function:: calcium.cp_lch(compo, dep, ti, tf, i, nm_var, len, var_string) -> info, t, ii, n
178 :param compo: component reference
179 :type compo: SALOME component object
180 :param dep: dependency mode (calcium.CP_TEMPS, calcium.CP_ITERATION or calcium.CP_SEQUENTIEL)
182 :param ti: interval start time
184 :param tf: interval end time
186 :param i: iteration number
188 :param nm_var: port name
190 :param len: number of values to import
192 :param var_real: array to store imported float values (must be large enough to contain imported values)
193 :type var_real: float numpy array or :class:`calcium.floatArray`
194 :param var_double: array to store imported double values
195 :type var_double: double numpy array or :class:`calcium.doubleArray`
196 :param var_complex: array to store imported complex values
197 :type var_complex: complex numpy array or :class:`calcium.floatArray` (double size)
198 :param var_integer: array to store imported integer values
199 :type var_integer: integer numpy array or :class:`calcium.intArray`
200 :param var_long: array to store imported long values
201 :type var_long: long numpy array or :class:`calcium.longArray`
202 :param var_boolean: array to store imported boolean values
203 :type var_boolean: integer numpy array or :class:`calcium.intArray`
204 :param var_string: array to store imported string values
205 :type var_string: string numpy array or :class:`calcium.stringArray`
207 :param info: error code
209 :param t: effective time if mode=calcium.CP_TEMPS or associated time if mode=calcium.CP_SEQUENTIEL
211 :param ii: associated iteration number if mode=calcium.CP_SEQUENTIEL
213 :param n: effective number of imported values (<= len)
216 Functions to erase data
217 ==========================
218 The functions cp_fini and cp_fint are used to request that all values of the specified
219 variable defined for iteration number or time before a given one be erased.
221 The functions cp_effi and cp_efft are used to request that all values of the specified
222 variable defined for iteration number or time after a given one be erased.
224 .. function:: calcium.cp_fini(compo, nm_var, i) -> info
226 Erase all values of port nm_var before iteration i
228 :param compo: component reference
229 :type compo: SALOME component object
230 :param nm_var: port name
232 :param i: iteration number
234 :param info: error code
235 :type info: int, return
237 .. function:: calcium.cp_fint(compo, nm_var, t) -> info
239 Erase all values of port nm_var before time t
241 :param compo: component reference
242 :type compo: SALOME component object
243 :param nm_var: port name
247 :param info: error code
248 :type info: int, return
250 .. function:: calcium.cp_effi(compo, nm_var, i) -> info
252 Erase all values of port nm_var after iteration i
254 :param compo: component reference
255 :type compo: SALOME component object
256 :param nm_var: port name
258 :param i: iteration number
260 :param info: error code
261 :type info: int, return
263 .. function:: calcium.cp_efft(compo, nm_var, t) -> info
265 Erase all values of port nm_var after time t
267 :param compo: component reference
268 :type compo: SALOME component object
269 :param nm_var: port name
273 :param info: error code
274 :type info: int, return
278 If you want to export a double precision real array and import an integer array in time mode,
279 you could write a function as follows. Connection and disconnection must be done only once.
281 .. code-block:: numpy
288 info, name = calcium.cp_cd(compo)
289 # export 10 double values at time 0. on port outa
290 af=numpy.zeros(10,'d')
292 info = calcium.cp_edb(compo,calcium.CP_TEMPS,0.,0,"outa",10,af);
294 # import 10 integer values at interval time (0.,1.) on port ina
295 # (by default it is imported at the start time 0.)
296 ai=numpy.zeros(10,'i')
297 info,t,i,n = calcium.cp_len(compo,calcium.CP_TEMPS,0., 1.,0,"ina",10,ai);
299 info = calcium.cp_fin(compo,calcium.CP_CONT);