Skip to content

Update basic_dpf_example.py #2008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 7, 2023
Merged
3 changes: 2 additions & 1 deletion doc/source/user_guide/convert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ function:
Or, you can convert code in form of strings for later processing using the
:func:`convert_apdl_block() <ansys.mapdl.core.convert_apdl_block>` function:

.. code:: pycon

.. code:: python

from ansys.mapdl.core.convert import convert_apdl_block

Expand Down
23 changes: 8 additions & 15 deletions examples/00-mapdl-examples/basic_dpf_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

# If you are working locally, you don't need to perform the following steps
temp_directory = tempfile.gettempdir()

# Downloading RST file to the current folder
rst_path = mapdl.download_result(temp_directory)

Expand All @@ -57,28 +58,20 @@
# - Available results
# - Size of the mesh
# - Number of results
#
# Also, note that the first time you create a DPF object, Python
# automatically attempts to start the server in the background. If you
# want to connect to an existing server (either local or remote), use
# :func:`dpf.connect_to_server <ansys.dpf.core.server.connect_to_server>`.
# In this case, DPF will attempt to connect to a local server at the port 50052
# unless another port is specified.

dpf.connect_to_server()


###############################################################################
# If you are working with a remote server, you might need to upload the ``RST``
# file before working with it.
server_file_path = dpf.upload_file_in_tmp_folder(rst_path)
# Then you can create the :class:`DPF Model <ansys.dpf.core.model.Model>`.

dpf.core.make_tmp_dir_server(dpf.SERVER)

###############################################################################
# Then you can create the :class:`DPF Model <ansys.dpf.core.model.Model>`.
#
if dpf.SERVER.local_server:
model = dpf.Model(rst_path)
else:
server_file_path = dpf.upload_file_in_tmp_folder(rst_path)
model = dpf.Model(server_file_path)

model = dpf.Model(server_file_path)
print(model)

###############################################################################
Expand Down
19 changes: 7 additions & 12 deletions examples/00-mapdl-examples/composite_dcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import tempfile

from ansys.dpf import core as dpf
from ansys.dpf.core import Model
import matplotlib.pyplot as plt
import numpy as np
import pyvista as pv
Expand Down Expand Up @@ -313,18 +312,13 @@
temp_directory = tempfile.gettempdir()
rst_path = mapdl.download_result(temp_directory)

try:
# ONLY IF DPF SERVER DEPLOYED WITH gRPC COMMUNICATION
# Upload file to DPF server
dpf.connect_to_server()
server_file_path = dpf.upload_file_in_tmp_folder(rst_path)
data_src = dpf.DataSources(server_file_path)
except:
# Using DPF locally
data_src = dpf.DataSources(rst_path)
dpf.core.make_tmp_dir_server(dpf.SERVER)

# Generate the DPF model
model = Model(data_src)
if dpf.SERVER.local_server:
model = dpf.Model(rst_path)
else:
server_file_path = dpf.upload_file_in_tmp_folder(rst_path)
model = dpf.Model(server_file_path)

# Get the mesh of the whole model
meshed_region = model.metadata.meshed_region
Expand All @@ -348,6 +342,7 @@
nmisc_index = 70

# Generate the damage result operator
data_src = dpf.DataSources(server_file_path)
dam_op = dpf.operators.result.nmisc(data_sources=data_src, item_index=70)

# Generate the displacement operator
Expand Down