Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 26, 2024
1 parent f5fe6d0 commit 12c1963
Showing 1 changed file with 69 additions and 72 deletions.
141 changes: 69 additions & 72 deletions examples/Metalforming/metalforming.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,37 @@
``ls-dyna_smp_d_R13.0_365-gf8a97bda2a_winx64_ifort190.exe``.
"""

###############################################################################
# Perform required imports
# ~~~~~~~~~~~~~~~~~~~~~~~~
# Peform the required imports.
import os
import sys


from ansys.dyna.core.pre import launch_dyna
from ansys.dyna.core.pre import examples, launch_dyna
from ansys.dyna.core.pre.dynamaterial import MatRigid, MatTransverselyAnisotropicElasticPlastic
from ansys.dyna.core.pre.dynamech import (
DynaMech,
PartSet,
Curve,
ShellPart,
NodeSet,
DOF,
AnalysisType,
BulkViscosity,
Contact,
Motion,
ContactCategory,
ContactSurface,
ShellFormulation,
ContactType,
ContactCategory,
AnalysisType,
MetalFormingAnalysis,
DOF,
BulkViscosity,
Curve,
DynaMech,
EnergyFlag,
HourglassControl,
MetalFormingAnalysis,
Motion,
NodeSet,
PartSet,
ShellFormulation,
ShellPart,
)
from ansys.dyna.core.pre.dynamaterial import (
MatRigid,
MatTransverselyAnisotropicElasticPlastic,
)
from ansys.dyna.core.pre import examples
from ansys.dyna.core.pre.misc import check_valid_ip

# sphinx_gallery_thumbnail_path = '_static/pre/explicit/ball_plate.png'

###############################################################################
Expand All @@ -48,9 +45,9 @@
# Before starting the ``pre`` service, you must ensure that the Docker container
# for this service has been started. For more information, see "Start the Docker
# container for the ``pre`` service" in https://dyna.docs.pyansys.com/version/stable/index.html.
#
# The ``pre`` service can also be started locally, please download the latest version of
# ansys-pydyna-pre-server.zip package from https://github.com/ansys/pydyna/releases and start it
#
# The ``pre`` service can also be started locally, please download the latest version of
# ansys-pydyna-pre-server.zip package from https://github.com/ansys/pydyna/releases and start it
# refering to the README.rst file in this server package.
#
# Once the ``pre`` service is running, you can connect a client to it using
Expand All @@ -60,7 +57,7 @@
hostname = "localhost"
if len(sys.argv) > 1 and check_valid_ip(sys.argv[1]):
hostname = sys.argv[1]
solution = launch_dyna(ip = hostname)
solution = launch_dyna(ip=hostname)

###############################################################################
# Start the solution workflow
Expand All @@ -71,49 +68,49 @@
#
fns = []
path = examples.mf_simple_roll + os.sep
fns.append(path+"model.k")
fns.append(path + "model.k")
solution.open_files(fns)

###############################################################################
# Create database and control cards
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# For the D3plots, set simulation termination time, simulation timestep, and
# output frequency.
# output frequency.

solution.set_termination(termination_time=0.05)

mf = DynaMech(AnalysisType.NONE)
solution.add(mf)

mfanalysis = MetalFormingAnalysis()
mfanalysis.set_springback(PartSet([1]),100)
mfanalysis.set_springback(PartSet([1]), 100)
mfanalysis.set_rigid_body_nodes_fast_update(fast_update=1)
mf.add(mfanalysis)

mf.set_timestep(timestep_size_for_mass_scaled=-7e-7)
mf.set_accuracy()
mf.set_bulk_viscosity(bulk_viscosity_type=BulkViscosity.STANDARD_BULK_VISCOSITY_SHELL)
mf.set_energy(hourglass_energy=EnergyFlag.COMPUTED,
rigidwall_energy=EnergyFlag.NOT_COMPUTED,
sliding_interface_energy=EnergyFlag.COMPUTED
)
mf.set_energy(
hourglass_energy=EnergyFlag.COMPUTED,
rigidwall_energy=EnergyFlag.NOT_COMPUTED,
sliding_interface_energy=EnergyFlag.COMPUTED,
)
mf.set_hourglass(HourglassControl.FLANAGAN_BELYTSCHKO_EXACT_VOLUME_INTEGRATION_SOLID)
mf.set_output(print_suppression_d3hsp=True)
mf.create_control_shell(esort=1,istupd=1)
mf.create_control_contact(initial_penetration_check = 2,
shlthk = 1,
penalty_stiffness_option = 4,
orien = 4,
penetration_check_multiplier = 1.0)
mf.set_adaptive(time_interval_refinement=2.5e-4,
adaptive_error_tolerance=5.0,
adaptive_type = 2,
generate_adaptive_mesh_at_exit = 1,
min_shell_size = 1.83,
h_adaptivity_pass_flag = 1,
shell_h_adapt = 5.0,
fission_control_flag = -1,
)
mf.create_control_shell(esort=1, istupd=1)
mf.create_control_contact(
initial_penetration_check=2, shlthk=1, penalty_stiffness_option=4, orien=4, penetration_check_multiplier=1.0
)
mf.set_adaptive(
time_interval_refinement=2.5e-4,
adaptive_error_tolerance=5.0,
adaptive_type=2,
generate_adaptive_mesh_at_exit=1,
min_shell_size=1.83,
h_adaptivity_pass_flag=1,
shell_h_adapt=5.0,
fission_control_flag=-1,
)

###############################################################################
# Define materials
Expand Down Expand Up @@ -145,14 +142,15 @@
translational_constraint=7,
rotational_constraint=7,
)
crv = Curve(x=[0, 1],y=[0, 13])
crv = Curve(x=[0, 1], y=[0, 13])
matblank = MatTransverselyAnisotropicElasticPlastic(
mass_density=7.9e-09,
young_modulus=2.07e5,
yield_stress=201.3,
mass_density=7.9e-09,
young_modulus=2.07e5,
yield_stress=201.3,
anisotropic_hardening_parameter=-1.5930001,
curve_stress = crv)

curve_stress=crv,
)


###############################################################################
# Define section properties and assign materials
Expand Down Expand Up @@ -202,36 +200,36 @@

mfcontact = Contact(type=ContactType.FORMING, category=ContactCategory.ONE_WAY_SURFACE_TO_SURFACE)
mfcontact.set_friction_coefficient(static=0.125, dynamic=0)
mfcontact.set_extra_coefficient(viscous_damping = 20)
surf1 = ContactSurface(PartSet([1]),save_interface_force = 1)
surf2 = ContactSurface(PartSet([2]),save_interface_force = 1)
mfcontact.set_extra_coefficient(viscous_damping=20)
surf1 = ContactSurface(PartSet([1]), save_interface_force=1)
surf2 = ContactSurface(PartSet([2]), save_interface_force=1)
mfcontact.set_slave_surface(surf1)
mfcontact.set_master_surface(surf2)
mf.contacts.add(mfcontact)

mfcontact = Contact(type=ContactType.FORMING, category=ContactCategory.ONE_WAY_SURFACE_TO_SURFACE)
mfcontact.set_friction_coefficient(static=0.125, dynamic=0)
mfcontact.set_extra_coefficient(viscous_damping = 20)
surf1 = ContactSurface(PartSet([1]),save_interface_force = 1)
surf2 = ContactSurface(PartSet([3]),save_interface_force = 1)
mfcontact.set_extra_coefficient(viscous_damping=20)
surf1 = ContactSurface(PartSet([1]), save_interface_force=1)
surf2 = ContactSurface(PartSet([3]), save_interface_force=1)
mfcontact.set_slave_surface(surf1)
mfcontact.set_master_surface(surf2)
mf.contacts.add(mfcontact)

mfcontact = Contact(type=ContactType.FORMING, category=ContactCategory.ONE_WAY_SURFACE_TO_SURFACE)
mfcontact.set_friction_coefficient(static=0.125, dynamic=0)
mfcontact.set_extra_coefficient(viscous_damping = 20)
surf1 = ContactSurface(PartSet([1]),save_interface_force = 1)
surf2 = ContactSurface(PartSet([4]),save_interface_force = 1)
mfcontact.set_extra_coefficient(viscous_damping=20)
surf1 = ContactSurface(PartSet([1]), save_interface_force=1)
surf2 = ContactSurface(PartSet([4]), save_interface_force=1)
mfcontact.set_slave_surface(surf1)
mfcontact.set_master_surface(surf2)
mf.contacts.add(mfcontact)

mfcontact = Contact(type=ContactType.FORMING, category=ContactCategory.ONE_WAY_SURFACE_TO_SURFACE)
mfcontact.set_friction_coefficient(static=0.125, dynamic=0)
mfcontact.set_extra_coefficient(viscous_damping = 20)
surf1 = ContactSurface(PartSet([1]),save_interface_force = 1)
surf2 = ContactSurface(PartSet([5]),save_interface_force = 1)
mfcontact.set_extra_coefficient(viscous_damping=20)
surf1 = ContactSurface(PartSet([1]), save_interface_force=1)
surf2 = ContactSurface(PartSet([5]), save_interface_force=1)
mfcontact.set_slave_surface(surf1)
mfcontact.set_master_surface(surf2)
mf.contacts.add(mfcontact)
Expand All @@ -241,19 +239,19 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Constrain the nodes in a list of single point constraints (spc).

spc = [600,593]
mf.boundaryconditions.create_spc(NodeSet(spc),tx = False, tz = False,ry=False)
spc = [600, 593]
mf.boundaryconditions.create_spc(NodeSet(spc), tx=False, tz=False, ry=False)

mf.boundaryconditions.create_imposed_motion(
PartSet([2]),
Curve(x=[0,100], y=[600,600]),
Curve(x=[0, 100], y=[600, 600]),
dof=DOF.Y_ROTATIONAL,
motion=Motion.VELOCITY,
scalefactor=-1,
)
mf.boundaryconditions.create_imposed_motion(
PartSet([3]),
Curve(x=[0,100], y=[600,600]),
Curve(x=[0, 100], y=[600, 600]),
dof=DOF.Y_ROTATIONAL,
motion=Motion.VELOCITY,
scalefactor=1,
Expand All @@ -263,8 +261,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~

mf.loads.create_nodal_force(
NodeSet([695,696,697,698,694,693,692]),
load_curve = Curve(x=[0,0.015,0.016,100],y=[100,100,0,0])
NodeSet([695, 696, 697, 698, 694, 693, 692]), load_curve=Curve(x=[0, 0.015, 0.016, 100], y=[100, 100, 0, 0])
)

###############################################################################
Expand All @@ -282,9 +279,9 @@
# Download output file from Docker image for the server to
# your local ``<working directory>/output/`` location.

serveroutfile = '/'.join((serverpath,"model.k"))
serveroutfile = "/".join((serverpath, "model.k"))
downloadpath = os.path.join(os.getcwd(), "output")
if not os.path.exists(downloadpath):
os.makedirs(downloadpath)
downloadfile = os.path.join(downloadpath,"model.k")
solution.download(serveroutfile,downloadfile)
downloadfile = os.path.join(downloadpath, "model.k")
solution.download(serveroutfile, downloadfile)

0 comments on commit 12c1963

Please sign in to comment.