exec#
- Session.exec(function: Callable, *args, remote: bool = False, **kwargs) Any #
Run a function containing EnSight API calls locally or in the EnSight interpreter.
The function is in this form:
def myfunc(ensight, *args, **kwargs): ... return value
The
exec()
method allows for the function to be executed in the PyEnSight Python interpreter or the (remote) EnSight interpreter. Thus, a function making a large number of RPC calls can run much faster than if it runs solely in the PyEnSight interpreter.These constraints exist on this capability:
The function may only use arguments passed to the
exec()
method and can only return a single value.The function cannot modify the input arguments.
The input arguments must be serializable and the PyEnSight Python interpreter version must match the version in EnSight.
- Parameters:
- remotebool,
optional
Whether to execute the function in the (remote) EnSight interpreter.
- remotebool,
Examples
>>> from ansys.pyensight.core import LocalLauncher >>> session = LocalLauncher().start() >>> options = dict() >>> options['Verbose mode'] = 'OFF' >>> options['Use ghost elements'] = 'OFF' >>> options['Long names'] = 'OFF' >>> options['Compatibility mode'] = 'ON' >>> options['Move Transient Parts'] = 'ON' >>> options['Element type'] = 'Tri 3' >>> options['Boundary ghosts'] = 'None' >>> options['Spread out parts'] = 'Legacy' >>> options['Number of spheres'] = 100 >>> options['Number of cubes'] = 100 >>> options['Number of planes'] = 0 >>> options['Number of elements start'] = 1000 >>> options['Number of elements end'] = 1000 >>> options['Number of timesteps'] = 1 >>> options['Part scaling factor'] = 1.000000e+00 >>> options['Random number seed'] = 0 >>> options['Number of scalars'] = 3 >>> options['Number of vectors'] = 3 >>> options['Number of constants'] = 3 >>> session.load_data("dummy", file_format="Synthetic", reader_options=options)
>>> def count(ensight, attr, value): >>> import time >>> start = time.time() >>> count = 0 >>> for p in ensight.objs.core.PARTS: >>> if p.getattr(attr) == value: >>> count += 1 >>> print(count(session.ensight, "VISIBLE", True)) >>> print(session.exec(count, "VISIBLE", True)) >>> print(session.exec(count, "VISIBLE", True, remote=True))