|
13 | 13 | from ansys.dpf.core import examples |
14 | 14 | from ansys.dpf.core import operators as ops |
15 | 15 |
|
16 | | -############################################################################### |
17 | | -# Create two servers |
18 | | -# ~~~~~~~~~~~~~~~~~~ |
19 | | -# Use the ``start_local_server()`` method to start two servers on your local |
20 | | -# machine. If you have another server, you can use the ``connect_to_server()`` |
21 | | -# method to connect to any DPF server on your network. |
22 | | - |
23 | | -# The ``as_global`` attributes allows you to choose whether a server is stored |
24 | | -# by the module and used by default. This example sets the first server as the default. |
25 | | -server1 = dpf.start_local_server(as_global=True, config=dpf.AvailableServerConfigs.GrpcServer) |
26 | | -server2 = dpf.start_local_server(as_global=False, config=dpf.AvailableServerConfigs.GrpcServer) |
27 | | - |
28 | | -# Check that the two servers are listening on different ports. |
29 | | -print(server1.port if hasattr(server1, "port") else "", |
30 | | - server2.port if hasattr(server2, "port") else "") |
31 | | - |
32 | | -############################################################################### |
33 | | -# Send the result file |
34 | | -# ~~~~~~~~~~~~~~~~~~~~ |
35 | | -# The result file is sent to the temporary directory of the first server. |
36 | | -# This file upload is useless in this case because the two servers are local |
37 | | -# machines. |
38 | | -file = examples.complex_rst |
39 | | -file_path_in_tmp = dpf.upload_file_in_tmp_folder(file) |
40 | | - |
41 | | -############################################################################### |
42 | | -# Create a workflow on the first server |
43 | | -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
44 | | -# Create the model |
45 | | -model = dpf.Model(file_path_in_tmp) |
46 | | - |
47 | | -# Read displacement |
48 | | -disp = model.results.displacement() |
49 | | -disp.inputs.time_scoping(len(model.metadata.time_freq_support.time_frequencies)) |
50 | | - |
51 | | -############################################################################### |
52 | | -# Create a workflow on the second server |
53 | | -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
54 | | - |
55 | | -# Change the Cartesian coordinates to cylindrical coordinates cs |
56 | | -coordinates = ops.geo.rotate_in_cylindrical_cs_fc(server=server2) |
57 | | - |
58 | | -# Create the Cartesian coordinate cs |
59 | | -cs = dpf.fields_factory.create_scalar_field(12, server=server2) |
60 | | -cs.data = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0] |
61 | | - |
62 | | -coordinates.inputs.coordinate_system(cs) |
63 | | - |
64 | | -# Choose the radial component to plot |
65 | | -comp = dpf.operators.logic.component_selector_fc(coordinates, 0, server=server2) |
66 | | - |
67 | | -############################################################################### |
68 | | -# Pass data from one server to another |
69 | | -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
70 | | -fc_disp = disp.outputs.fields_container() |
71 | | -fc_copy = fc_disp.deep_copy(server=server2) |
72 | | - |
73 | | -mesh_copy = model.metadata.meshed_region.deep_copy(server=server2) |
74 | | -# give a mesh to the field |
75 | | -fc_copy[0].meshed_region = mesh_copy |
76 | | -fc_copy[1].meshed_region = mesh_copy |
77 | | - |
78 | | -coordinates.inputs.field(fc_copy) |
79 | | - |
80 | | -############################################################################### |
81 | | -# Plot the output |
82 | | -# ~~~~~~~~~~~~~~~ |
83 | | -out = comp.outputs.fields_container() |
84 | | - |
85 | | -# real part |
86 | | -mesh_copy.plot(out.get_field({"complex": 0})) |
87 | | - |
88 | | -# imaginary part |
89 | | -mesh_copy.plot(out.get_field({"complex": 1})) |
| 16 | +# ############################################################################### |
| 17 | +# # Create two servers |
| 18 | +# # ~~~~~~~~~~~~~~~~~~ |
| 19 | +# # Use the ``start_local_server()`` method to start two servers on your local |
| 20 | +# # machine. If you have another server, you can use the ``connect_to_server()`` |
| 21 | +# # method to connect to any DPF server on your network. |
| 22 | +# |
| 23 | +# # The ``as_global`` attributes allows you to choose whether a server is stored |
| 24 | +# # by the module and used by default. This example sets the first server as the default. |
| 25 | +# server1 = dpf.start_local_server(as_global=True, config=dpf.AvailableServerConfigs.GrpcServer) |
| 26 | +# server2 = dpf.start_local_server(as_global=False, config=dpf.AvailableServerConfigs.GrpcServer) |
| 27 | +# |
| 28 | +# # Check that the two servers are listening on different ports. |
| 29 | +# print(server1.port if hasattr(server1, "port") else "", |
| 30 | +# server2.port if hasattr(server2, "port") else "") |
| 31 | +# |
| 32 | +# ############################################################################### |
| 33 | +# # Send the result file |
| 34 | +# # ~~~~~~~~~~~~~~~~~~~~ |
| 35 | +# # The result file is sent to the temporary directory of the first server. |
| 36 | +# # This file upload is useless in this case because the two servers are local |
| 37 | +# # machines. |
| 38 | +# file = examples.complex_rst |
| 39 | +# file_path_in_tmp = dpf.upload_file_in_tmp_folder(file) |
| 40 | +# |
| 41 | +# ############################################################################### |
| 42 | +# # Create a workflow on the first server |
| 43 | +# # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 44 | +# # Create the model |
| 45 | +# model = dpf.Model(file_path_in_tmp) |
| 46 | +# |
| 47 | +# # Read displacement |
| 48 | +# disp = model.results.displacement() |
| 49 | +# disp.inputs.time_scoping(len(model.metadata.time_freq_support.time_frequencies)) |
| 50 | +# |
| 51 | +# ############################################################################### |
| 52 | +# # Create a workflow on the second server |
| 53 | +# # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 54 | +# |
| 55 | +# # Change the Cartesian coordinates to cylindrical coordinates cs |
| 56 | +# coordinates = ops.geo.rotate_in_cylindrical_cs_fc(server=server2) |
| 57 | +# |
| 58 | +# # Create the Cartesian coordinate cs |
| 59 | +# cs = dpf.fields_factory.create_scalar_field(12, server=server2) |
| 60 | +# cs.data = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0] |
| 61 | +# |
| 62 | +# coordinates.inputs.coordinate_system(cs) |
| 63 | +# |
| 64 | +# # Choose the radial component to plot |
| 65 | +# comp = dpf.operators.logic.component_selector_fc(coordinates, 0, server=server2) |
| 66 | +# |
| 67 | +# ############################################################################### |
| 68 | +# # Pass data from one server to another |
| 69 | +# # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 70 | +# fc_disp = disp.outputs.fields_container() |
| 71 | +# fc_copy = fc_disp.deep_copy(server=server2) |
| 72 | +# |
| 73 | +# mesh_copy = model.metadata.meshed_region.deep_copy(server=server2) |
| 74 | +# # give a mesh to the field |
| 75 | +# fc_copy[0].meshed_region = mesh_copy |
| 76 | +# fc_copy[1].meshed_region = mesh_copy |
| 77 | +# |
| 78 | +# coordinates.inputs.field(fc_copy) |
| 79 | +# |
| 80 | +# ############################################################################### |
| 81 | +# # Plot the output |
| 82 | +# # ~~~~~~~~~~~~~~~ |
| 83 | +# out = comp.outputs.fields_container() |
| 84 | +# |
| 85 | +# # real part |
| 86 | +# mesh_copy.plot(out.get_field({"complex": 0})) |
| 87 | +# |
| 88 | +# # imaginary part |
| 89 | +# mesh_copy.plot(out.get_field({"complex": 1})) |
0 commit comments