.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\07-distributed-post\01-distributed_workflows_on_remote.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_07-distributed-post_01-distributed_workflows_on_remote.py: .. _ref_distributed_workflows_on_remote: Create a custom workflow on distributed processes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example shows how to read and postprocess distributed files on distributed processes. After remote postprocessing, results are merged on the local process. This example creates different operator sequences directly on different servers. These operators are then connected together so that you don't have to care that they are on remote processes. .. graphviz:: digraph foo { graph [pad="0", nodesep="0.3", ranksep="0.3"] node [shape=box, style=filled, fillcolor="#ffcc00", margin="0"]; rankdir=LR; splines=line; subgraph cluster_1 { ds01 [label="data_src", shape=box, style=filled, fillcolor=cadetblue2]; ds01 -> stress1 [style=dashed]; label="Server 1"; style=filled; fillcolor=lightgrey; } subgraph cluster_2 { ds02 [label="data_src", shape=box, style=filled, fillcolor=cadetblue2]; ds02 -> stress2 [style=dashed]; stress2 -> mul; label="Server 2"; style=filled; fillcolor=lightgrey; } stress1 -> "merge"; mul -> "merge"; } .. GENERATED FROM PYTHON SOURCE LINES 49-50 Import the ``dpf-core`` module and its examples files. .. GENERATED FROM PYTHON SOURCE LINES 50-56 .. code-block:: Python import os 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 57-60 Configure the servers. To make it easier, this example starts local servers. However, you can connect to any existing servers on your network. .. GENERATED FROM PYTHON SOURCE LINES 60-72 .. code-block:: Python config = dpf.AvailableServerConfigs.InProcessServer if "DPF_DOCKER" in os.environ.keys(): # If running DPF on Docker, you cannot start an InProcessServer config = dpf.AvailableServerConfigs.GrpcServer global_server = dpf.start_local_server(as_global=True, config=config) remote_servers = [ dpf.start_local_server(as_global=False, config=dpf.AvailableServerConfigs.GrpcServer), dpf.start_local_server(as_global=False, config=dpf.AvailableServerConfigs.GrpcServer), ] .. GENERATED FROM PYTHON SOURCE LINES 73-74 Send files to the temporary directory if they are not in shared memory. .. GENERATED FROM PYTHON SOURCE LINES 74-81 .. code-block:: Python files = examples.download_distributed_files(return_local_path=True) server_file_paths = [ dpf.upload_file_in_tmp_folder(files[0], server=remote_servers[0]), dpf.upload_file_in_tmp_folder(files[1], server=remote_servers[1]), ] .. GENERATED FROM PYTHON SOURCE LINES 82-83 Create the first operator chain. .. GENERATED FROM PYTHON SOURCE LINES 83-91 .. code-block:: Python remote_operators = [] stress1 = ops.result.stress(server=remote_servers[0]) remote_operators.append(stress1) ds = dpf.DataSources(server_file_paths[0], server=remote_servers[0]) stress1.inputs.data_sources(ds) .. GENERATED FROM PYTHON SOURCE LINES 92-93 Create the second operator chain. .. GENERATED FROM PYTHON SOURCE LINES 93-100 .. code-block:: Python stress2 = ops.result.stress(server=remote_servers[1]) mul = stress2 * 2.0 remote_operators.append(mul) ds = dpf.DataSources(server_file_paths[1], server=remote_servers[1]) stress2.inputs.data_sources(ds) .. GENERATED FROM PYTHON SOURCE LINES 101-102 Create the local merge operator. .. GENERATED FROM PYTHON SOURCE LINES 102-105 .. code-block:: Python merge = ops.utility.merge_fields_containers() .. GENERATED FROM PYTHON SOURCE LINES 106-107 Connect the operator chains together and get the output. .. GENERATED FROM PYTHON SOURCE LINES 107-116 .. code-block:: Python nodal = ops.averaging.to_nodal_fc(merge) merge.connect(0, remote_operators[0], 0) merge.connect(1, remote_operators[1], 0) fc = nodal.get_output(0, dpf.types.fields_container) print(fc[0]) fc[0].meshed_region.plot(fc[0]) .. image-sg:: /examples/07-distributed-post/images/sphx_glr_01-distributed_workflows_on_remote_001.png :alt: 01 distributed workflows on remote :srcset: /examples/07-distributed-post/images/sphx_glr_01-distributed_workflows_on_remote_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none DPF stress_7491.964387Hz Field Location: Nodal Unit: Pa 432 entities Data: 6 components and 432 elementary data Nodal IDs data(Pa) ------------ ---------- 24 -1.931259e+11 4.889198e+11 9.893517e+10 -1.873750e+12 8.823901e+11 2.278725e+10 124 -4.577267e+11 -4.345968e+10 1.408608e+11 -4.123077e+10 1.609307e+10 6.080418e+10 89 -1.935788e+11 -3.031243e+11 1.267524e+11 5.413418e+10 3.645896e+10 -1.808178e+10 ... .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.034 seconds) .. _sphx_glr_download_examples_07-distributed-post_01-distributed_workflows_on_remote.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01-distributed_workflows_on_remote.ipynb <01-distributed_workflows_on_remote.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01-distributed_workflows_on_remote.py <01-distributed_workflows_on_remote.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_