How to make a plot of S11 stresses (fibre-direction) vs z coordinate for named selections?
Javier Vique
Member, Employee Posts: 84
✭✭✭✭
The scenario is a composite model made by solids where user wants to grab S11 stresses of a specific ply, selected by named selections. These elemental named selections are previously created by Worksheet in Mechanical.
Tagged:
1
Answers
-
With mech-dpf, we can easily grab this data. Data can be output in a csv file, or with the beta functionality of C-python included in Mechanical can be also directly plot in Mechanical.
Let's assume that we've got the list of named selections in a list called 'ns' and we apply an offset of 135.55mm to the z coordinate of the elements, so z=0 is at the bottom of our model.
It is also recommended to have a look at this post from our forum.import os import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI) analysis = Model.Analyses[0] WorkDir = analysis.WorkingDir model = dpf.Model(analysis.ResultFileName) dataSource = dpf.DataSources(analysis.ResultFileName) mesh = model.Mesh ns = ['PLYA_NS', 'PLYB_NS', 'PLYC_NS', 'PLYD_NS', 'PLYE_NS'] # Get elements centroids op_cent = dpf.operators.result.element_centroids() op_cent.inputs.data_sources.Connect(dataSource) op_cent.inputs.bool_rotate_to_global.Connect(True) cent_field = op_cent.outputs.fields_container.GetData()[0] # Apply offset to z coordinate op_add = dpf.operators.math.add_constant() op_add.inputs.field.Connect(cent_field) op_add.inputs.ponderation.Connect(135.55) cent_field_d = op_add.outputs.field.GetData() # Get results for each ply for ply in ns: ply_mesh_region = model.GetNamedSelection(ply) op_rscope = dpf.operators.scoping.rescope() op_rscope.inputs.fields.Connect(cent_field_d) op_rscope.inputs.mesh_scoping.Connect(ply_mesh_region) cent_ply = op_rscope.outputs.fields.GetDataT2() op_z = dpf.operators.logic.component_selector() op_z.inputs.field.Connect(cent_ply) op_z.inputs.component_number.Connect(2) centZ_ply = op_z.outputs.field.GetData() op_s11 = dpf.operators.result.stress_X() op_s11.inputs.mesh_scoping.Connect(ply_mesh_region) op_s11.inputs.requested_location.Connect(dpf.locations.elemental_nodal) op_s11.inputs.data_sources.Connect(dataSource) op_s11.inputs.bool_rotate_to_global.Connect(False) s11 = op_s11.outputs.fields_container.GetData()[0] z = [] s11_max = [] for Elem in s11.ScopingIds: z.append(centZ_ply.GetEntityDataById(Elem)[0]) s11_max.append(max(s11.GetEntityDataById(Elem),key=abs)) data_sorted_byZ = sorted(zip(z,s11_max), key=lambda x: x[0]) file = ply[:-3] + '.csv' file_path = os.path.join(WorkDir,file) with open(file_path,'w') as f: [f.write('%.3f,%.3f\n' % (zi,s11i)) for zi,s11i in data_sorted_byZ] model.ReleaseStreams()
1