Skip to content

Commit 6f280c1

Browse files
committed
Merge branch 'zzqbranch'
2 parents 8dbba32 + e357903 commit 6f280c1

File tree

7 files changed

+3987
-67
lines changed

7 files changed

+3987
-67
lines changed

README.rst

Lines changed: 74 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -77,98 +77,105 @@ Usage
7777
=====
7878
Here is a basic preprocessing example:
7979

80+
Get the input file from "pydyna\\src\\ansys\\dyna\\core\\pre\\examples\\explicit\\ball_plate\\ball_plate.k"
81+
82+
The follow example can be obtained from "pydyna\examples\Explicit\ball_plate.py"
83+
8084
.. code:: python
8185
8286
import os
8387
import sys
8488
from ansys.dyna.core.pre.dynasolution import DynaSolution
85-
from ansys.dyna.core.pre.dynaicfd import (
86-
DynaICFD,
87-
ICFDAnalysis,
88-
MatICFD,
89-
ICFDPart,
90-
ICFDDOF,
91-
Curve,
92-
ICFDVolumePart,
93-
MeshedVolume,
89+
from ansys.dyna.core.pre.dynamech import (
90+
DynaMech,
91+
Velocity,
92+
PartSet,
93+
ShellPart,
94+
SolidPart,
95+
NodeSet,
96+
Contact,
97+
ContactSurface,
98+
ShellFormulation,
99+
SolidFormulation,
100+
ContactType,
101+
AnalysisType
102+
)
103+
from ansys.dyna.core.pre.dynamaterial import (
104+
MatRigid,
105+
MatPiecewiseLinearPlasticity,
94106
)
95107
from ansys.dyna.core.pre import examples
96-
# sphinx_gallery_thumbnail_path = '_static/pre/icfd/cylinderflow.png'
97108
98109
hostname = "localhost"
99110
if len(sys.argv) > 1:
100111
hostname = sys.argv[1]
112+
solution = DynaSolution(hostname)
101113
102-
icfd_solution = DynaSolution(hostname)
103-
# Import the initial mesh data(nodes and elements)
104114
fns = []
105-
path = os.getcwd()+os.sep
106-
fns.append(path+"cylinder_flow.k")
107-
icfd_solution.open_files(fns)
108-
# Set total time of simulation
109-
icfd_solution.set_termination(termination_time=100)
110-
111-
icfd = DynaICFD()
112-
icfd_solution.add(icfd)
113-
114-
icfdanalysis = ICFDAnalysis()
115-
icfdanalysis.set_timestep()
116-
icfd.add(icfdanalysis)
117-
118-
# define model
119-
mat = MatICFD(flow_density=1.0, dynamic_viscosity=0.005)
120-
121-
part_inflow = ICFDPart(1)
122-
part_inflow.set_material(mat)
123-
part_inflow.set_prescribed_velocity(dof=ICFDDOF.X, motion=Curve(x=[0, 10000], y=[1, 1]))
124-
part_inflow.set_prescribed_velocity(dof=ICFDDOF.Y, motion=Curve(x=[0, 10000], y=[0, 0]))
125-
icfd.parts.add(part_inflow)
126-
127-
part_outflow = ICFDPart(2)
128-
part_outflow.set_material(mat)
129-
part_outflow.set_prescribed_pressure(pressure=Curve(x=[0, 10000], y=[0, 0]))
130-
icfd.parts.add(part_outflow)
131-
132-
part_symmetric = ICFDPart(3)
133-
part_symmetric.set_material(mat)
134-
part_symmetric.set_free_slip()
135-
icfd.parts.add(part_symmetric)
136-
137-
part_wall = ICFDPart(4)
138-
part_wall.set_material(mat)
139-
part_wall.set_non_slip()
140-
part_wall.compute_drag_force()
141-
part_wall.set_boundary_layer(number=3)
142-
icfd.parts.add(part_wall)
143-
144-
partvol = ICFDVolumePart(surfaces=[1, 2, 3, 4])
145-
partvol.set_material(mat)
146-
icfd.parts.add(partvol)
147-
# define the volume space that will be meshed,The boundaries
148-
# of the volume are the surfaces "spids"
149-
meshvol = MeshedVolume(surfaces=[1, 2, 3, 4])
150-
icfd.add(meshvol)
151-
152-
icfd_solution.create_database_binary(dt=1)
153-
serverpath = icfd_solution.save_file()
154-
serveroutfile = '/'.join((serverpath,"cylinder_flow.k"))
115+
path = examples.ball_plate + os.sep
116+
fns.append(path+"ball_plate.k")
117+
solution.open_files(fns)
118+
119+
solution.set_termination(termination_time=10)
120+
121+
ballplate = DynaMech(AnalysisType.NONE)
122+
solution.add(ballplate)
123+
124+
matrigid = MatRigid(mass_density=7.83e-6, young_modulus=207, poisson_ratio=0.3)
125+
matplastic = MatPiecewiseLinearPlasticity(mass_density=7.83e-6, young_modulus=207, yield_stress=0.2, tangent_modulus=2)
126+
127+
plate = ShellPart(1)
128+
plate.set_element_formulation(ShellFormulation.BELYTSCHKO_TSAY)
129+
plate.set_material(matplastic)
130+
plate.set_thickness(1)
131+
plate.set_integration_points(5)
132+
ballplate.parts.add(plate)
133+
134+
ball = SolidPart(2)
135+
ball.set_material(matrigid)
136+
ball.set_element_formulation(SolidFormulation.CONSTANT_STRESS_SOLID_ELEMENT)
137+
ballplate.parts.add(ball)
138+
139+
selfcontact = Contact(type=ContactType.AUTOMATIC)
140+
surf1 = ContactSurface(PartSet([1, 2]))
141+
selfcontact.set_slave_surface(surf1)
142+
ballplate.contacts.add(selfcontact)
143+
144+
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]
145+
for i in range(1,19):
146+
spc.append(i)
147+
for i in range(272,290):
148+
spc.append(i)
149+
ballplate.boundaryconditions.create_spc(NodeSet(spc),rx=False,ry=False,rz=False)
150+
151+
for i in range(1,1652):
152+
ballplate.initialconditions.create_velocity_node(i,trans=Velocity(0, 0, -10))
153+
154+
solution.set_output_database(glstat=0.1, matsum=0.1, sleout=0.1)
155+
solution.create_database_binary(dt=1)
156+
serverpath = solution.save_file()
157+
158+
serveroutfile = '/'.join((serverpath,"ball_plate.k"))
155159
downloadpath = os.path.join(os.getcwd(), "output")
156160
if not os.path.exists(downloadpath):
157161
os.makedirs(downloadpath)
158-
downloadfile = os.path.join(downloadpath,"cylinder_flow.k")
159-
icfd_solution.download(serveroutfile,downloadfile)
162+
downloadfile = os.path.join(downloadpath,"ball_plate.k")
163+
solution.download(serveroutfile,downloadfile)
160164
161165
Here is a basic solving example:
162166

167+
The follow example can be obtained from "pydyna\\examples\\solver\\ball_plate_solver.py"
168+
163169
.. code:: python
164170
171+
import ansys.dyna.core.solver as solver
172+
165173
hostname = "localhost"
166174
port = "5000"
167-
import ansys.dyna.core.solver as solver
168175
dyna=solver.DynaSolver(hostname,port) # connect to the container
169-
dyna.push("cylinder_flow.k") # push an input file
176+
dyna.push("./output/ball_plate.k") # push an input file
170177
dyna.start(4) # start 4 ranks of mppdyna
171-
dyna.run("i=./output/cylinder_flow.k memory=10m ncycle=20000") # begin execution
178+
dyna.run("i=ball_plate.k memory=10m ncycle=20000") # begin execution
172179
173180
Here is a basic postprocessing example:
174181

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)