Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,8 @@ jobs:

tests:
name: Testing
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
needs: [smoke-tests]
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest]

steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -152,35 +147,39 @@ jobs:
cache: 'pip'
cache-dependency-path: 'pyproject.toml'

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: LS-DYNA Keyword server activation
run: |
docker pull ghcr.io/ansys/ls-pre:latest
docker run -d --name kw_server -p 50051:50051 ghcr.io/ansys/ls-pre:latest && echo "Keyword server active on port 50051."

- name: Install ansys-dyna-core (with test requirements)
run: |
pip install -e .[tests]

- name: Run tests (Windows)
if: runner.os == 'Windows'
- name: Run tests
run: |
Start-Job -ScriptBlock {cd ${{ github.workspace }}\src\ansys\dyna\core\pre\Server\;python kwserver.py >> server_output.txt}
Start-Sleep -Seconds 10
pytest

- name: Run tests (Linux)
if: runner.os == 'Linux'
- name: Extract the server logs
if: always()
run: |
cd src/ansys/dyna/core/pre/Server
python kwserver.py > server_output.txt &
sleep 10
cd -
pytest
docker logs kw_server > server_output.txt

- name: Upload the server logs
if: always()
uses: actions/upload-artifact@v3
with:
name: server-logs-${{ runner.os }}
path: src/ansys/dyna/core/pre/Server/server_output.txt
name: server_output.txt
path: server_output.txt

- name: Upload coverage results
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
with:
name: coverage-html
Expand Down
143 changes: 105 additions & 38 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build up ansys-dyna input deck, submit to solver and finally post processing the

Project Overview
----------------
There are 3 related packages here, pre and solver are all under the ansys/dyna/ directory,
There are 3 related packages here, pre and solver are all under the ansys/pydyna/ directory,
while pyDPF is used for post-processing.

pre contains highly abstracted APIs for setting up a LS-DYNA input deck, so far,
Expand Down Expand Up @@ -35,8 +35,33 @@ leaving a Python environment.
Visit the `DPF-Post Documentation <https://postdocs.pyansys.com>`_ for a
detailed description of the package.

Installation
------------
Install PyDyna-Pre Docker
-------------------------

Launching the PyDyna-Pre service locally, the only requirement is that:

* Docker is installed on your machine.

.. caution::

The PyDyna-Pre service is currently available only as a Linux Docker image.
make sure that your Docker engine is configured to run Linux Docker images.

Please refer to ``docker/README.rst`` to install PyDyna-Pre service docker container

Install PyDyna-Solver Docker
----------------------------

Once pydyna is installed, the docker-compose.yml file to build and launch the dyna solver docker can be located
under ``docker``. The yml file can be copied locally. To run the docker the following command can be used

.. code:: bash

docker-compose up


Install the package
-------------------

PyDyna has three installation modes: user, developer, and offline.

Expand Down Expand Up @@ -98,31 +123,21 @@ archive from the `Releases Page <https://github.com/pyansys/pydyna/releases>`_ f
corresponding machine architecture.

Each wheelhouse archive contains all the Python wheels necessary to install PyDyna from scratch on Windows
and Linux, from Python 3.7 to 3.10. You can install this on an isolated system with a fresh Python
and Linux, from Python 3.6,3.8 and 3.9. You can install this on an isolated system with a fresh Python
installation or on a virtual environment.

For example, on Linux with Python 3.7, unzip the wheelhouse archive and install it with:
For example, on Linux with Python 3.8, unzip the wheelhouse archive and install it with:

.. code:: bash

unzip ansys-dyna-core-v0.3.dev0-wheelhouse-Linux-3.7.zip wheelhouse
unzip ansys-dyna-core-v0.3.dev0-wheelhouse-Linux-3.8.zip wheelhouse
pip install ansys-dyna-core -f wheelhouse --no-index --upgrade --ignore-installed

If you are on Windows with Python 3.9, unzip the corresponding wheelhouse to a wheelhouse directory
and install using the preceding command.

Consider installing using a `virtual environment <https://docs.python.org/3/library/venv.html>`_.

Install Solver Docker
^^^^^^^^^^^^^^^^^^^^^

Once pydyna is installed, the docker-compose.yml file to build and launch the dyna solver docker can be located
under /src/ansys/dyna/core/solver/. The yml file can be copied locally. To run the docker the following command can be used

.. code:: bash

docker-compose up

Documentation
-------------
For comprehesive information on PyDyna, see the latest release
Expand All @@ -138,28 +153,80 @@ Here is a basic pre-processing example:

.. code:: python

from ansys.dyna.core.pre.dynasolution import *
from ansys.dyna.core.pre.dynaiga import *
from ansys.dyna.core.pre.dynamaterial import *
hostname = "localhost"
iga_solution = DynaSolution(hostname)
fns = []
path = os.getcwd() + os.sep + "input" + os.sep + "iga_sample" + os.sep
fns.append(path + "maino.k")
fns.append(path + "rkrwelds.key")
fns.append(path + "27parts.key")
iga_solution.open_files(fns)
iga_solution.set_termination(20)
iga_solution.create_database_binary(dt=0.1)
iga = DynaIGA()
iga_solution.add(iga)
iga.set_timestep(timestep_size_for_mass_scaled=-0.0004)
...
selfcontact = Contact(type=ContactType.AUTOMATIC)
selfcontact.set_friction_coefficient(static=0.2)
surf1=ContactSurface(PartSet(igaparts))
selfcontact.set_slave_surface(surf1)
iga_solution.save_file()
import os
import sys
from ansys.dyna.core.pre.dynasolution import DynaSolution
from ansys.dyna.core.pre.dynaicfd import (
DynaICFD,
ICFDAnalysis,
MatICFD,
ICFDPart,
ICFDDOF,
Curve,
ICFDVolumePart,
MeshedVolume,
)
from ansys.dyna.core.pre import examples
# sphinx_gallery_thumbnail_path = '_static/pre/icfd/cylinderflow.png'

hostname = "localhost"
if len(sys.argv) > 1:
hostname = sys.argv[1]

icfd_solution = DynaSolution(hostname)
# Import the initial mesh data(nodes and elements)
fns = []
path = examples.cylinder_flow + os.sep
fns.append(path + "cylinder_flow.k")
icfd_solution.open_files(fns)
# Set total time of simulation
icfd_solution.set_termination(termination_time=100)

icfd = DynaICFD()
icfd_solution.add(icfd)

icfdanalysis = ICFDAnalysis()
icfdanalysis.set_timestep()
icfd.add(icfdanalysis)

# define model
mat = MatICFD(flow_density=1.0, dynamic_viscosity=0.005)

part_inflow = ICFDPart(1)
part_inflow.set_material(mat)
part_inflow.set_prescribed_velocity(dof=ICFDDOF.X, motion=Curve(x=[0, 10000], y=[1, 1]))
part_inflow.set_prescribed_velocity(dof=ICFDDOF.Y, motion=Curve(x=[0, 10000], y=[0, 0]))
icfd.parts.add(part_inflow)

part_outflow = ICFDPart(2)
part_outflow.set_material(mat)
part_outflow.set_prescribed_pressure(pressure=Curve(x=[0, 10000], y=[0, 0]))
icfd.parts.add(part_outflow)

part_symmetric = ICFDPart(3)
part_symmetric.set_material(mat)
part_symmetric.set_free_slip()
icfd.parts.add(part_symmetric)

part_wall = ICFDPart(4)
part_wall.set_material(mat)
part_wall.set_non_slip()
part_wall.compute_drag_force()
part_wall.set_boundary_layer(number=3)
icfd.parts.add(part_wall)

partvol = ICFDVolumePart(surfaces=[1, 2, 3, 4])
partvol.set_material(mat)
icfd.parts.add(partvol)
# define the volume space that will be meshed,The boundaries
# of the volume are the surfaces "spids"
meshvol = MeshedVolume(surfaces=[1, 2, 3, 4])
icfd.add(meshvol)

icfd_solution.create_database_binary(dt=1)
icfd_solution.save_file()

For more examples, visit https://dyna.docs.pyansys.com/version/stable/examples/index.html

Here is a basic solving example:

Expand Down
2 changes: 2 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ RUN pip3 install grpcio grpcio-tools protobuf

RUN python -m grpc_tools.protoc --python_out=./linux-binaries --grpc_python_out=./linux-binaries -I./linux-binaries ./linux-binaries/kwprocess.proto

EXPOSE 50051

CMD ["python3", "./linux-binaries/kwserver.py"]
31 changes: 27 additions & 4 deletions docker/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Create your own pydyna-pre service docker container
=================================================
===================================================

The pydyna-pre service Docker containers can be easily built by following
these steps.
Expand All @@ -19,7 +19,7 @@ Prerequisites
* Download the latest release artifacts for the Linux
Docker container. You can do this as follows:

* Latest Linux artifacts: `linux-binaries.zip <https://github.com/ansys/pydyna/releases/latest/download/linux-binaries.zip>`_
* Latest Linux artifacts: `linux-binaries.zip <https://github.com/ansys/pydyna/releases/download/v0.2.1/linux-binaries.zip>`_

* Move these ``.zip`` files to the current location (i.e. ``<repository-root-folder>/docker``).

Expand All @@ -33,7 +33,12 @@ In order to build your images, follow the next instructions:

.. code:: bash

docker build -t ls-pre .
docker build -t ghcr.io/ansys/ls-pre:<DOCKER_IMAGE_TAG> -f <DOCKERFILE_NAME> .

Bear in mind that you will need to substitute the following entries in the previous command:

* ``<DOCKERFILE_NAME>``: this will be ``Dockerfile``
* ``<DOCKER_IMAGE_TAG>``: this will be ``latest``

* Check that the image has been created successfully. You should see an output similar
to this one when running the following command:
Expand All @@ -43,5 +48,23 @@ In order to build your images, follow the next instructions:
docker images

>>> REPOSITORY TAG IMAGE ID CREATED SIZE
>>> ls-pre *******-latest ............ X seconds ago 187MB
>>> ghcr.io/ansys/ls-pre *******-latest ............ X seconds ago 188MB
>>> ...... ...... ............ .............. ......

Run the image as a container
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* Run the following Docker command:

.. code:: bash

docker run -d -p 50051:50051 ghcr.io/ansys/ls-pre .

* Check that the image has been created successfully.


.. code:: bash


>>> CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
>>> c77ffd67f9fa ghcr.io/ansys/ls-pre "python3 ./linux-bin…" 7 seconds ago Up 7 seconds 0.0.0.0:50051->50051/tcp, :::50051->50051/tcp hardcore_margulis
22 changes: 22 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3.8"
services:
dyna:
image: ghcr.io/pyansys/dynasolver:0.3
networks:
- dyna_internal
deploy:
replicas: 1
volumes:
- /rundir
cap_add:
- SYS_PTRACE
ports:
- target: 5000
published: 5000
mode: ingress
user: mpirun
entrypoint: ["/ansys_inc/server.py","dyna"]
environment:
- LSTC_LICENSE_SERVER=lvrpanda.ansys.com
networks:
dyna_internal:
1 change: 1 addition & 0 deletions src/ansys/dyna/core/pre/Server/kwprocess.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ message SaveFileRequest {

message SaveFileReply {
int64 length = 1;
string outpath = 2;
}

message LoadFileRequest {
Expand Down
560 changes: 280 additions & 280 deletions src/ansys/dyna/core/pre/Server/kwprocess_pb2.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ansys/dyna/core/pre/Server/kwserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def SaveFile(self, request, context):
self.kwdproc.write(subsystems)
self.fns.clear()
print("Saved Successfully!")
return kwprocess_pb2.SaveFileReply(length=1)
return kwprocess_pb2.SaveFileReply(length=1,outpath=fn)

def CreateTimestep(self, request, context):
tssfac = request.tssfac
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/dyna/core/pre/dynasolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def upload(self, stub_, filename):
chunks_generator = self.get_file_chunks(filename)
response = stub_.Upload(chunks_generator)

def download(self, stub_, remote_name, local_name):
def download(self, remote_name, local_name):
"""Download files from server."""
response = stub_.Download(DownloadRequest(url=remote_name))
response = self.stub.Download(DownloadRequest(url=remote_name))
with open(local_name, "wb") as f:
for chunk in response:
f.write(chunk.buffer)
Expand Down Expand Up @@ -294,4 +294,4 @@ def save_file(self):
ret = self.stub.SaveFile(SaveFileRequest(name=self.mainname))
msg = self.mainname + " is outputed..."
logging.info(msg)
return ret
return ret.outpath
560 changes: 280 additions & 280 deletions src/ansys/dyna/core/pre/kwprocess_pb2.py

Large diffs are not rendered by default.

Loading