Skip to content

Commit f68a983

Browse files
committed
add example code
1 parent 59f1c04 commit f68a983

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

README.rst

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ PyAnsys libraries are intended to extend and interface with existing
2626
products of Ansys services **outside** of the application itself, and
2727
in some cases permitting remote execution. As such, this requires
2828
that you have a working installation of Python, and ideally a Python
29-
distribution like the `Anaconda Distribution
30-
<https://www.anaconda.com/products/individual>`_. For existing users
29+
distribution like the `Anaconda Distribution`_. For existing users
3130
of Ansys who are not used to working with Python outside of the
3231
product, this may seem to be an unnecessary step, but what this
3332
approach provides is:
@@ -51,9 +50,9 @@ approach provides is:
5150

5251
* Customization of your entire Python environment on the OS of your
5352
choosing. For the applications that support it, you can even
54-
remotely connect with and manage the application via `gRPC
55-
<https://grpc.io/>`_. For those that don't, you can still customize
56-
the version of Python and its packages.
53+
remotely connect with and manage the application via `gRPC`_. For
54+
those that don't, you can still customize the version of Python and
55+
its packages.
5756

5857
* Create applications or pipelines that utilize Ansys products and
5958
expose features as a web-page, standalone application, or script to
@@ -64,7 +63,7 @@ approach provides is:
6463
PyAnsys Project Structure
6564
=========================
6665
The PyAnsys project hosted on GitHub at `PyAnsys
67-
<https://github.com/pyansys>`_ contains several repositories that provide:
66+
<https://github.com/pyansys>`_ contains repositories that provide:
6867

6968
* Interfaces to Ansys products or services:
7069

@@ -76,7 +75,7 @@ The PyAnsys project hosted on GitHub at `PyAnsys
7675

7776
* Documentation and Examples
7877

79-
* `about <https://github.com/pyansys/about>`_
78+
* `Project Overview <https://github.com/pyansys/about>`_
8079
* `pyansys-sphinx-theme <https://github.com/pyansys/pyansys-sphinx-theme>`_
8180
* `pyansys_landing <https://github.com/pyansys/pyansys_landing>`_
8281
* `pyansys-helloworld <https://github.com/pyansys/pyansys-helloworld>`_
@@ -88,6 +87,9 @@ The PyAnsys project hosted on GitHub at `PyAnsys
8887
* `example-coverage <https://github.com/pyansys/example-coverage>`_
8988
* `system-reporting-tool <https://github.com/pyansys/system-reporting-tool>`_
9089

90+
For details regarding each project, visit the repository and either
91+
view the README or visit the documentation linked to the repository.
92+
9193

9294
PyAnsys Library Overview
9395
========================
@@ -115,9 +117,48 @@ general pattern in the following figure:
115117
:width: 400
116118
:alt: Overview Diagram
117119

120+
In this overview, the product or service exposes an interface that is
121+
either locally acessible (in the case of .NET using `pythoncom`_,
122+
`SWIG`_, or `C extensions`_) or a service that is locally and
123+
remotably acessible (`REST`_ or `gRPC`_). This will be reffered to as
124+
the program API. While this API can be directly accessed
125+
126+
127+
+-----------------------------------------------------------------------------------------------------+-----------------------------------------+
128+
| Using gRPC Autogenerated Interface | Using PyMapdl Library |
129+
+-----------------------------------------------------------------------------------------------------+-----------------------------------------+
130+
| import grpc | from ansys.mapdl import core as pymapdl |
131+
| | |
132+
| from ansys.api.mapdl.v0 import mapdl_pb2 as pb_types | # start mapdl |
133+
| from ansys.api.mapdl.v0 import mapdl_pb2_grpc as mapdl_grpc | mapdl = pymapdl.launch_mapdl() |
134+
| from ansys.api.mapdl.v0 import kernel_pb2 as anskernel | output = mapdl.input('ds.dat') |
135+
| from grpc_interceptor_headers.header_manipulator_client_interceptor import header_adder_interceptor | |
136+
| from ansys.client.servicemanager.client import ServiceManagerClient as service_manager | |
137+
| sm = service_manager() | |
138+
| | |
139+
| # start MAPDL | |
140+
| job = sm.create_job_by_name("mapdl-212") | |
141+
| service_name = f"grpc-{job.name}" | |
142+
| mapdl_service = sm.get_service(name=service_name) | |
143+
| | |
144+
| # create a gRPC channel | |
145+
| channel_str = '%s:%d' % (mapdl_service.host, mapdl_service.port) | |
146+
| channel = grpc.insecure_channel(channel_str) | |
147+
| header_adder = header_adder_interceptor('service-name', service_name) | |
148+
| stub = mapdl_grpc.MapdlServiceStub(channel) | |
149+
| | |
150+
| # send the input file | |
151+
| request = pb_types.InputFileRequest(filename='ds.dat')) | |
152+
| metadata = (('time-step-stream', '200'), ('chunk-size', '512'),) | |
153+
| response = stub.InputFileS(request, metadata=metadata) | |
154+
| # need additional code to parse file... | |
155+
+-----------------------------------------------------------------------------------------------------+-----------------------------------------+
156+
157+
158+
118159

119160
PyAnsys Package Basic Structure
120-
-------------------------------
161+
===============================
121162

122163
ansys/<product>/<service>/my_module.py
123164
ansys/<product>/<service>/my_other_module.py
@@ -158,3 +199,11 @@ Python Modules
158199

159200
Documentation Directory `doc`
160201
- Use `pyansys-sphinx-theme <https://sphinxdocs.pyansys.com/>`_
202+
203+
204+
.. _gRPC: https://grpc.io/
205+
.. _pythoncom: http://timgolden.me.uk/pywin32-docs/pythoncom.html
206+
.. _SWIG: http://www.swig.org/
207+
.. _C extensions: https://docs.python.org/3/extending/extending.html
208+
.. _Anaconda Distribution: https://www.anaconda.com/products/individual
209+
.. _REST: https://en.wikipedia.org/wiki/Representational_state_transfer

diagram.png

-88.2 KB
Binary file not shown.

doc/source/images/diagram.png

-53.9 KB
Loading

0 commit comments

Comments
 (0)