.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\04-advanced\03-exchange_data_between_servers.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_04-advanced_03-exchange_data_between_servers.py: .. _ref_exchange_data_between_servers.: Exchange data between servers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In this example, two DPF servers are started, and a workflow is created with a part on both servers. This example shows how you can read data from a given machine and transform this data on another machine without any more difficulties than working on a local computer. .. GENERATED FROM PYTHON SOURCE LINES 36-42 .. code-block:: Python from ansys.dpf import core as dpf from ansys.dpf.core import examples from ansys.dpf.core import operators as ops .. GENERATED FROM PYTHON SOURCE LINES 43-52 Create two servers ~~~~~~~~~~~~~~~~~~ Use the :func:`start_local_server() ` method to start two servers on your local machine. If you have another server, you can use the :func:`connect_to_server() ` method to connect to any DPF server on your network. The ``as_global`` attributes allows you to choose whether a server is stored by the module and used by default. This example sets the first server as the default. .. GENERATED FROM PYTHON SOURCE LINES 52-61 .. code-block:: Python server1 = dpf.start_local_server(as_global=True, config=dpf.AvailableServerConfigs.GrpcServer) server2 = dpf.start_local_server(as_global=False, config=dpf.AvailableServerConfigs.GrpcServer) # Check that the two servers are listening on different ports. print( server1.port if hasattr(server1, "port") else "", server2.port if hasattr(server2, "port") else "", ) .. rst-class:: sphx-glr-script-out .. code-block:: none 50055 50056 .. GENERATED FROM PYTHON SOURCE LINES 62-67 Send the result file ~~~~~~~~~~~~~~~~~~~~ The result file is sent to the temporary directory of the first server. This file upload is useless in this case because the two servers are local machines. .. GENERATED FROM PYTHON SOURCE LINES 67-69 .. code-block:: Python file_path_in_tmp = examples.find_complex_rst(server=server1) .. GENERATED FROM PYTHON SOURCE LINES 70-73 Create a workflow on the first server ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create the model .. GENERATED FROM PYTHON SOURCE LINES 73-79 .. code-block:: Python model = dpf.Model(file_path_in_tmp) # Read displacement disp = model.results.displacement() disp.inputs.time_scoping(len(model.metadata.time_freq_support.time_frequencies)) .. GENERATED FROM PYTHON SOURCE LINES 80-82 Create a workflow on the second server ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 82-95 .. code-block:: Python # Change the Cartesian coordinates to cylindrical coordinates cs coordinates = ops.geo.rotate_in_cylindrical_cs_fc(server=server2) # Create the Cartesian coordinate cs cs = dpf.fields_factory.create_scalar_field(12, server=server2) cs.data = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0] coordinates.inputs.coordinate_system(cs) # Choose the radial component to plot comp = dpf.operators.logic.component_selector_fc(coordinates, 0, server=server2) .. GENERATED FROM PYTHON SOURCE LINES 96-98 Pass data from one server to another ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 98-108 .. code-block:: Python fc_disp = disp.outputs.fields_container() fc_copy = fc_disp.deep_copy(server=server2) mesh_copy = model.metadata.meshed_region.deep_copy(server=server2) # give a mesh to the field fc_copy[0].meshed_region = mesh_copy fc_copy[1].meshed_region = mesh_copy coordinates.inputs.field(fc_copy) .. GENERATED FROM PYTHON SOURCE LINES 109-111 Plot the output ~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 111-118 .. code-block:: Python out = comp.outputs.fields_container() # real part mesh_copy.plot(out.get_field({"complex": 0})) # imaginary part mesh_copy.plot(out.get_field({"complex": 1})) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/04-advanced/images/sphx_glr_03-exchange_data_between_servers_001.png :alt: 03 exchange data between servers :srcset: /examples/04-advanced/images/sphx_glr_03-exchange_data_between_servers_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/04-advanced/images/sphx_glr_03-exchange_data_between_servers_002.png :alt: 03 exchange data between servers :srcset: /examples/04-advanced/images/sphx_glr_03-exchange_data_between_servers_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 11.325 seconds) .. _sphx_glr_download_examples_04-advanced_03-exchange_data_between_servers.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03-exchange_data_between_servers.ipynb <03-exchange_data_between_servers.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03-exchange_data_between_servers.py <03-exchange_data_between_servers.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 03-exchange_data_between_servers.zip <03-exchange_data_between_servers.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_