|
| 1 | +The next few sections show how to preprocessing, solve, and postprocessing a ball plate example. |
| 2 | + |
| 3 | +Preprocessing |
| 4 | +~~~~~~~~~~~~~ |
| 5 | +The following code processes a ball plate example. In the repository, you can get the |
| 6 | +input file from ``src/ansys/dyna/core/pre/examples/explicit/ball_plate/ball_plate.k`` and |
| 7 | +the Python file from ``examples/Explicit/ball_plate.py``. |
| 8 | + |
| 9 | +.. code:: python |
| 10 | +
|
| 11 | + import os |
| 12 | + import sys |
| 13 | + from ansys.dyna.core.pre.dynasolution import DynaSolution |
| 14 | + from ansys.dyna.core.pre.dynamech import ( |
| 15 | + DynaMech, |
| 16 | + Velocity, |
| 17 | + PartSet, |
| 18 | + ShellPart, |
| 19 | + SolidPart, |
| 20 | + NodeSet, |
| 21 | + Contact, |
| 22 | + ContactSurface, |
| 23 | + ShellFormulation, |
| 24 | + SolidFormulation, |
| 25 | + ContactType, |
| 26 | + AnalysisType |
| 27 | + ) |
| 28 | + from ansys.dyna.core.pre.dynamaterial import ( |
| 29 | + MatRigid, |
| 30 | + MatPiecewiseLinearPlasticity, |
| 31 | + ) |
| 32 | + from ansys.dyna.core.pre import examples |
| 33 | +
|
| 34 | + hostname = "localhost" |
| 35 | + if len(sys.argv) > 1: |
| 36 | + hostname = sys.argv[1] |
| 37 | + solution = DynaSolution(hostname) |
| 38 | +
|
| 39 | + fns = [] |
| 40 | + path = examples.ball_plate + os.sep |
| 41 | + fns.append(path+"ball_plate.k") |
| 42 | + solution.open_files(fns) |
| 43 | +
|
| 44 | + solution.set_termination(termination_time=10) |
| 45 | +
|
| 46 | + ballplate = DynaMech(AnalysisType.NONE) |
| 47 | + solution.add(ballplate) |
| 48 | +
|
| 49 | + matrigid = MatRigid(mass_density=7.83e-6, young_modulus=207, poisson_ratio=0.3) |
| 50 | + matplastic = MatPiecewiseLinearPlasticity(mass_density=7.83e-6, young_modulus=207, yield_stress=0.2, tangent_modulus=2) |
| 51 | +
|
| 52 | + plate = ShellPart(1) |
| 53 | + plate.set_element_formulation(ShellFormulation.BELYTSCHKO_TSAY) |
| 54 | + plate.set_material(matplastic) |
| 55 | + plate.set_thickness(1) |
| 56 | + plate.set_integration_points(5) |
| 57 | + ballplate.parts.add(plate) |
| 58 | +
|
| 59 | + ball = SolidPart(2) |
| 60 | + ball.set_material(matrigid) |
| 61 | + ball.set_element_formulation(SolidFormulation.CONSTANT_STRESS_SOLID_ELEMENT) |
| 62 | + ballplate.parts.add(ball) |
| 63 | +
|
| 64 | + selfcontact = Contact(type=ContactType.AUTOMATIC) |
| 65 | + surf1 = ContactSurface(PartSet([1, 2])) |
| 66 | + selfcontact.set_slave_surface(surf1) |
| 67 | + ballplate.contacts.add(selfcontact) |
| 68 | +
|
| 69 | + 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] |
| 70 | + for i in range(1,19): |
| 71 | + spc.append(i) |
| 72 | + for i in range(272,290): |
| 73 | + spc.append(i) |
| 74 | + ballplate.boundaryconditions.create_spc(NodeSet(spc),rx=False,ry=False,rz=False) |
| 75 | +
|
| 76 | + for i in range(1,1652): |
| 77 | + ballplate.initialconditions.create_velocity_node(i,trans=Velocity(0, 0, -10)) |
| 78 | +
|
| 79 | + solution.set_output_database(glstat=0.1, matsum=0.1, sleout=0.1) |
| 80 | + solution.create_database_binary(dt=1) |
| 81 | + serverpath = solution.save_file() |
| 82 | +
|
| 83 | + serveroutfile = '/'.join((serverpath,"ball_plate.k")) |
| 84 | + downloadpath = os.path.join(os.getcwd(), "output") |
| 85 | + if not os.path.exists(downloadpath): |
| 86 | + os.makedirs(downloadpath) |
| 87 | + downloadfile = os.path.join(downloadpath,"ball_plate.k") |
| 88 | + solution.download(serveroutfile,downloadfile) |
| 89 | + |
| 90 | +Solve |
| 91 | +~~~~~ |
| 92 | +The following code solves this basic ball plate example. In the repository, |
| 93 | +you can get the Python file from ``examples/solver/ball_plate_solver.py``. |
| 94 | + |
| 95 | +.. code:: python |
| 96 | +
|
| 97 | + import ansys.dyna.core.solver as solver |
| 98 | +
|
| 99 | + hostname = "localhost" |
| 100 | + port = "5000" |
| 101 | + dyna=solver.DynaSolver(hostname,port) # connect to the container |
| 102 | + dyna.push("./output/ball_plate.k") # push an input file |
| 103 | + dyna.start(4) # start 4 ranks of mppdyna |
| 104 | + dyna.run("i=ball_plate.k memory=10m ncycle=20000") # begin execution |
| 105 | +
|
| 106 | +
|
| 107 | +Post processing |
| 108 | +~~~~~~~~~~~~~~~ |
| 109 | +The following code processes results from the solve of this basic ball plate example: |
| 110 | + |
| 111 | +.. code:: python |
| 112 | +
|
| 113 | + from ansys.dpf import core as dpf |
| 114 | + import os |
| 115 | +
|
| 116 | + ds = dpf.DataSources() |
| 117 | + data_path = os.path.join(os.getcwd(), 'd3plot') |
| 118 | + ds.set_result_file_path(data_path, 'd3plot') |
| 119 | +
|
| 120 | + model = dpf.Model(ds) |
| 121 | + # Extract displacements for all time steps from d3plot |
| 122 | + D = model.results.displacement.on_all_time_freqs().eval() |
| 123 | + D.animate() |
| 124 | +
|
| 125 | + stress = dpf.operators.result.stress() |
| 126 | + stress.inputs.data_sources(ds) |
| 127 | + stress.inputs.time_scoping([12]) |
| 128 | + stress.connect(25, [1]) |
| 129 | + stress.inputs.requested_location.connect("Nodal") |
| 130 | + fields = stress.outputs.fields_container() |
| 131 | +
|
| 132 | + shell_layer_extract = dpf.operators.utility.change_shell_layers() |
| 133 | + shell_layer_extract.inputs.fields_container.connect(fields) |
| 134 | + print(shell_layer_extract.inputs.e_shell_layer) |
| 135 | + shell_layer_extract.inputs.e_shell_layer.connect(0) |
| 136 | + fields_top = shell_layer_extract.outputs.fields_container_as_fields_container() |
| 137 | + print(fields_top) |
| 138 | + fields_top.animate() |
| 139 | +
|
| 140 | +For more examples, see `Examples <https://dyna.docs.pyansys.com/version/stable/examples/index.html>`_ |
| 141 | +in the PyDYNA documentation. |
0 commit comments