Skip to content

Commit f40e524

Browse files
committed
add example ball_plate
1 parent 5dec39e commit f40e524

File tree

7 files changed

+3980
-65
lines changed

7 files changed

+3980
-65
lines changed

README.rst

Lines changed: 67 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -44,90 +44,92 @@ the PyAnsys support team, email `[email protected] <pyansys.support@ansy
4444
Usage
4545
=====
4646
Here is a basic preprocessing example:
47+
Firstly, get the input file from pydyna\src\ansys\dyna\core\pre\examples\explicit\ball_plate\ball_plate.k
48+
The follow example can be obtained from pydyna\examples\Explicit\ball_plate.py
4749

4850
.. code:: python
4951
5052
import os
5153
import sys
5254
from ansys.dyna.core.pre.dynasolution import DynaSolution
53-
from ansys.dyna.core.pre.dynaicfd import (
54-
DynaICFD,
55-
ICFDAnalysis,
56-
MatICFD,
57-
ICFDPart,
58-
ICFDDOF,
59-
Curve,
60-
ICFDVolumePart,
61-
MeshedVolume,
55+
from ansys.dyna.core.pre.dynamech import (
56+
DynaMech,
57+
Velocity,
58+
PartSet,
59+
ShellPart,
60+
SolidPart,
61+
NodeSet,
62+
Contact,
63+
ContactSurface,
64+
ShellFormulation,
65+
SolidFormulation,
66+
ContactType,
67+
AnalysisType
68+
)
69+
from ansys.dyna.core.pre.dynamaterial import (
70+
MatRigid,
71+
MatPiecewiseLinearPlasticity,
6272
)
6373
from ansys.dyna.core.pre import examples
64-
# sphinx_gallery_thumbnail_path = '_static/pre/icfd/cylinderflow.png'
6574
6675
hostname = "localhost"
6776
if len(sys.argv) > 1:
6877
hostname = sys.argv[1]
78+
solution = DynaSolution(hostname)
6979
70-
icfd_solution = DynaSolution(hostname)
71-
# Import the initial mesh data(nodes and elements)
7280
fns = []
73-
path = os.getcwd()+os.sep
74-
fns.append(path+"cylinder_flow.k")
75-
icfd_solution.open_files(fns)
76-
# Set total time of simulation
77-
icfd_solution.set_termination(termination_time=100)
78-
79-
icfd = DynaICFD()
80-
icfd_solution.add(icfd)
81-
82-
icfdanalysis = ICFDAnalysis()
83-
icfdanalysis.set_timestep()
84-
icfd.add(icfdanalysis)
85-
86-
# define model
87-
mat = MatICFD(flow_density=1.0, dynamic_viscosity=0.005)
88-
89-
part_inflow = ICFDPart(1)
90-
part_inflow.set_material(mat)
91-
part_inflow.set_prescribed_velocity(dof=ICFDDOF.X, motion=Curve(x=[0, 10000], y=[1, 1]))
92-
part_inflow.set_prescribed_velocity(dof=ICFDDOF.Y, motion=Curve(x=[0, 10000], y=[0, 0]))
93-
icfd.parts.add(part_inflow)
94-
95-
part_outflow = ICFDPart(2)
96-
part_outflow.set_material(mat)
97-
part_outflow.set_prescribed_pressure(pressure=Curve(x=[0, 10000], y=[0, 0]))
98-
icfd.parts.add(part_outflow)
99-
100-
part_symmetric = ICFDPart(3)
101-
part_symmetric.set_material(mat)
102-
part_symmetric.set_free_slip()
103-
icfd.parts.add(part_symmetric)
104-
105-
part_wall = ICFDPart(4)
106-
part_wall.set_material(mat)
107-
part_wall.set_non_slip()
108-
part_wall.compute_drag_force()
109-
part_wall.set_boundary_layer(number=3)
110-
icfd.parts.add(part_wall)
111-
112-
partvol = ICFDVolumePart(surfaces=[1, 2, 3, 4])
113-
partvol.set_material(mat)
114-
icfd.parts.add(partvol)
115-
# define the volume space that will be meshed,The boundaries
116-
# of the volume are the surfaces "spids"
117-
meshvol = MeshedVolume(surfaces=[1, 2, 3, 4])
118-
icfd.add(meshvol)
119-
120-
icfd_solution.create_database_binary(dt=1)
121-
serverpath = icfd_solution.save_file()
122-
serveroutfile = '/'.join((serverpath,"cylinder_flow.k"))
81+
path = examples.ball_plate + os.sep
82+
fns.append(path+"ball_plate.k")
83+
solution.open_files(fns)
84+
85+
solution.set_termination(termination_time=10)
86+
87+
ballplate = DynaMech(AnalysisType.NONE)
88+
solution.add(ballplate)
89+
90+
matrigid = MatRigid(mass_density=7.83e-6, young_modulus=207, poisson_ratio=0.3)
91+
matplastic = MatPiecewiseLinearPlasticity(mass_density=7.83e-6, young_modulus=207, yield_stress=0.2, tangent_modulus=2)
92+
93+
plate = ShellPart(1)
94+
plate.set_element_formulation(ShellFormulation.BELYTSCHKO_TSAY)
95+
plate.set_material(matplastic)
96+
plate.set_thickness(1)
97+
plate.set_integration_points(5)
98+
ballplate.parts.add(plate)
99+
100+
ball = SolidPart(2)
101+
ball.set_material(matrigid)
102+
ball.set_element_formulation(SolidFormulation.CONSTANT_STRESS_SOLID_ELEMENT)
103+
ballplate.parts.add(ball)
104+
105+
selfcontact = Contact(type=ContactType.AUTOMATIC)
106+
surf1 = ContactSurface(PartSet([1, 2]))
107+
selfcontact.set_slave_surface(surf1)
108+
ballplate.contacts.add(selfcontact)
109+
110+
spc = [34,35,51,52,68,69,85,86,102,103,119,120,136,137,153,154,170,171,187,188,204,205,221,222,238,239,255,256]
111+
for i in range(1,19):
112+
spc.append(i)
113+
for i in range(272,290):
114+
spc.append(i)
115+
ballplate.boundaryconditions.create_spc(NodeSet(spc),rx=False,ry=False,rz=False)
116+
117+
for i in range(1,1652):
118+
ballplate.initialconditions.create_velocity_node(i,trans=Velocity(0, 0, -10))
119+
120+
solution.set_output_database(glstat=0.1, matsum=0.1, sleout=0.1)
121+
solution.create_database_binary(dt=1)
122+
serverpath = solution.save_file()
123+
124+
serveroutfile = '/'.join((serverpath,"ball_plate.k"))
123125
downloadpath = os.path.join(os.getcwd(), "output")
124126
if not os.path.exists(downloadpath):
125127
os.makedirs(downloadpath)
126-
downloadfile = os.path.join(downloadpath,"cylinder_flow.k")
127-
icfd_solution.download(serveroutfile,downloadfile)
128+
downloadfile = os.path.join(downloadpath,"ball_plate.k")
129+
solution.download(serveroutfile,downloadfile)
128130
129131
Here is a basic solving example:
130-
132+
The follow example can be obtained from pydyna\examples\solver\ball_plate_solver.py
131133
.. code:: python
132134
133135
hostname = "localhost"
66 KB
Loading

examples/Explicit/ball_plate.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
"""
2+
Ball Plate
3+
==========
4+
This example shows how to use the PyDYNA ``pre`` service to create
5+
a ball plate model. The executable file for LS-DYNA is
6+
``ls-dyna_smp_d_R13.0_365-gf8a97bda2a_winx64_ifort190.exe``.
7+
8+
"""
9+
###############################################################################
10+
# Perform required imports
11+
# ~~~~~~~~~~~~~~~~~~~~~~~~
12+
# Peform required imports.
13+
import os
14+
import sys
15+
16+
17+
from ansys.dyna.core.pre.dynasolution import DynaSolution
18+
from ansys.dyna.core.pre.dynamech import (
19+
DynaMech,
20+
Velocity,
21+
PartSet,
22+
ShellPart,
23+
SolidPart,
24+
NodeSet,
25+
Contact,
26+
ContactSurface,
27+
ShellFormulation,
28+
SolidFormulation,
29+
ContactType,
30+
AnalysisType
31+
)
32+
from ansys.dyna.core.pre.dynamaterial import (
33+
MatRigid,
34+
MatPiecewiseLinearPlasticity,
35+
)
36+
from ansys.dyna.core.pre import examples
37+
# sphinx_gallery_thumbnail_path = '_static/pre/explicit/ball_plate.png'
38+
39+
###############################################################################
40+
# Start the ``pre`` service
41+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42+
# Prerequisite: make sure the ``pre`` service docker have been started.
43+
# Refer to: https://dyna.docs.pyansys.com/version/stable/getting-started/index.html
44+
45+
# Once the ``pre`` servic is running, you can connect a client to it using
46+
# the host name and the port. This example uses the default local host and port
47+
# (``"localhost"`` and ``"50051"`` respectively).
48+
#
49+
hostname = "localhost"
50+
if len(sys.argv) > 1:
51+
hostname = sys.argv[1]
52+
solution = DynaSolution(hostname)
53+
54+
###############################################################################
55+
# Start the solution workflow
56+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~
57+
# NODES and ELEMENTS are read in from the ``ball_plate.k`` file. This file
58+
# also has the *PART* defined in it, but the section and material fields are
59+
# empty to begin with.
60+
#
61+
fns = []
62+
path = examples.ball_plate + os.sep
63+
fns.append(path+"ball_plate.k")
64+
solution.open_files(fns)
65+
66+
###############################################################################
67+
# Create database and control cards
68+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69+
# For the D3plots, set simulation termination time, simulation timestep, and
70+
# output frequency.
71+
72+
solution.set_termination(termination_time=10)
73+
74+
ballplate = DynaMech(AnalysisType.NONE)
75+
solution.add(ballplate)
76+
77+
###############################################################################
78+
# Define materials
79+
# ~~~~~~~~~~~~~~~~
80+
# The ``dynamaterials`` class
81+
# are used to define these materials: ``MAT_RIGID``, ``MAT_PIECEWISE_LINEAR_PLASTICITY``,
82+
83+
matrigid = MatRigid(mass_density=7.83e-6, young_modulus=207, poisson_ratio=0.3)
84+
matplastic = MatPiecewiseLinearPlasticity(mass_density=7.83e-6, young_modulus=207, yield_stress=0.2, tangent_modulus=2)
85+
86+
87+
###############################################################################
88+
# Define section properties and assign materials
89+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90+
# Now that you have materials with the material ID corresponding to
91+
# the Part ID, you can assign these materials to the
92+
# parts. also define the section properties, element
93+
# formulations, and constraints.
94+
#
95+
96+
plate = ShellPart(1)
97+
plate.set_element_formulation(ShellFormulation.BELYTSCHKO_TSAY)
98+
plate.set_material(matplastic)
99+
plate.set_thickness(1)
100+
plate.set_integration_points(5)
101+
ballplate.parts.add(plate)
102+
103+
ball = SolidPart(2)
104+
ball.set_material(matrigid)
105+
ball.set_element_formulation(SolidFormulation.CONSTANT_STRESS_SOLID_ELEMENT)
106+
ballplate.parts.add(ball)
107+
108+
109+
###############################################################################
110+
# Define surface-to-surface contacts
111+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112+
# Define single-surface contact between predefined part set.
113+
114+
selfcontact = Contact(type=ContactType.AUTOMATIC)
115+
surf1 = ContactSurface(PartSet([1, 2]))
116+
selfcontact.set_slave_surface(surf1)
117+
ballplate.contacts.add(selfcontact)
118+
119+
###############################################################################
120+
# Define nodal single point constraints.
121+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122+
# Constrain the nodes in the spc list
123+
124+
spc = [34,35,51,52,68,69,85,86,102,103,119,120,136,137,153,154,170,171,187,188,204,205,221,222,238,239,255,256]
125+
for i in range(1,19):
126+
spc.append(i)
127+
for i in range(272,290):
128+
spc.append(i)
129+
ballplate.boundaryconditions.create_spc(NodeSet(spc),rx=False,ry=False,rz=False)
130+
131+
###############################################################################
132+
# Define initial condition.
133+
# ~~~~~~~~~~~~~~~~~~~~~~~~~
134+
# Use the ``create_velocity_node`` method
135+
# to initialize the velocity components in the desired direction.
136+
for i in range(1,1652):
137+
ballplate.initialconditions.create_velocity_node(i,trans=Velocity(0, 0, -10))
138+
139+
###############################################################################
140+
# Define database outputs
141+
# ~~~~~~~~~~~~~~~~~~~~~~~
142+
# Define the frequency for the D3PLOT file and write out the input file.
143+
#
144+
solution.set_output_database(glstat=0.1, matsum=0.1, sleout=0.1)
145+
solution.create_database_binary(dt=1)
146+
serverpath = solution.save_file()
147+
148+
###############################################################################
149+
# Download output file
150+
# ~~~~~~~~~~~~~~~~~~~~
151+
# Download output file from service docker to local <working directory>/output/.
152+
153+
serveroutfile = '/'.join((serverpath,"ball_plate.k"))
154+
downloadpath = os.path.join(os.getcwd(), "output")
155+
if not os.path.exists(downloadpath):
156+
os.makedirs(downloadpath)
157+
downloadfile = os.path.join(downloadpath,"ball_plate.k")
158+
solution.download(serveroutfile,downloadfile)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Cylinder flow example
3+
=====================
4+
"""
5+
6+
import ansys.dyna.core.solver as solver
7+
8+
hostname = "localhost"
9+
port = "5000"
10+
dyna=solver.DynaSolver(hostname,port) # connect to the container
11+
dyna.push("./output/ball_plate.k") # push an input file
12+
dyna.start(4) # start 4 ranks of mppdyna
13+
dyna.run("i=ball_plate.k memory=10m ncycle=20000") # begin execution

src/ansys/dyna/core/pre/dynabase.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,7 @@ class InitialCondition:
23172317
def __init__(self):
23182318
self.stub = DynaBase.get_stub()
23192319
self.velocitylist = []
2320+
self.velocitynodelist = []
23202321
self.temperaturelist = []
23212322

23222323
def create_velocity(
@@ -2330,6 +2331,10 @@ def create_velocity(
23302331
"""Create initial velocities for rotating and/or translating bodies."""
23312332
self.velocitylist.append([velocityset, angular_velocity, velocity, direction, stime])
23322333

2334+
def create_velocity_node(self, nodeid, trans=Velocity(0, 0, 0), rot=RotVelocity(0, 0, 0)):
2335+
"""Define initial nodal point velocities for a node."""
2336+
self.velocitynodelist.append([nodeid, trans, rot])
2337+
23332338
def create_temperature(self, nodeset=None, temperature=0):
23342339
"""Create an initial nodal point temperature."""
23352340
self.temperaturelist.append((nodeset, temperature))
@@ -2371,6 +2376,13 @@ def create(self):
23712376
)
23722377
)
23732378
logging.info(f"Define initial velocities for {type} {id}.")
2379+
for obj in self.velocitynodelist:
2380+
nid = obj[0]
2381+
trans = obj[1]
2382+
rot = obj[2]
2383+
velocity = [trans.x, trans.y, trans.z, rot.x, rot.y, rot.z]
2384+
self.stub.CreateInitVel(InitVelRequest(nsid=nid, velocity=velocity))
2385+
logging.info(f"Define initial velocities for node {nid}.")
23742386
for obj in self.temperaturelist:
23752387
nset = obj[0]
23762388
temp = obj[1]

src/ansys/dyna/core/pre/examples/examples.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
em_rlc_define_func = os.path.join(_module_path, "em", "em_rlc_define_func")
2323

2424
belted_dummy = os.path.join(_module_path, "explicit", "belted_dummy")
25+
ball_plate = os.path.join(_module_path, "explicit", "ball_plate")
2526
# ICFD
2627
cylinder_flow = os.path.join(_module_path, "icfd", "cylinder_flow")
2728
internal_3d_flow = os.path.join(_module_path, "icfd", "internal_3d_flow")

0 commit comments

Comments
 (0)