Combine mode shapes using Mechanical DPF
Pernelle Marone-Hitz
Member, Moderator, Employee Posts: 871
✭✭✭✭
I've run an eigenvalue buckling analysis and would like to create a Python Result that will plot a combined deformation of the mode shapes, with a scale factor.
Tagged:
0
Best Answer
-
Below is an example.
The Property Provided can be defined as follows:
def reload_props(): this.PropertyProvider = None # Create the property instance provider = Provider() group = provider.AddGroup("Scaling values") scale_value_1 = group.AddProperty("Scale Value 1", Control.Double) scale_value_2 = group.AddProperty("Scale Value 2", Control.Double) this.PropertyProvider = provider
This will let the user define two values in the details' view of the Python Result to define scaling values:
The Script of the Python Result works as follows:
- deformation (u) is retrieved on all result sets
- total deformation (nrm) is computed from u
- using a loop of the result sets, the add_fc and the scale operators, we create a combined scaled field: scale_value_1 * norm_at_result_set_1 + scale_value_2 * norm_at_result_set_2 + .... (scale_value_1 is used for the first result set, and scale_value_2 for all others)
- plotting back the custom result
The code is:
def post_started(sender, analysis):# Do not edit this line define_dpf_workflow(analysis) def define_dpf_workflow(analysis): import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI) dataSource = dpf.DataSources(analysis.ResultFileName) # Retrieve scale vales scale_value_1 = this.GetCustomPropertyByPath("Scaling values/Scale Value 1").Value scale_value_2 = this.GetCustomPropertyByPath("Scaling values/Scale Value 2").Value # Get displacement u = dpf.operators.result.displacement() u.inputs.data_sources.Connect(dataSource) # Set time scoping timeScop = dpf.Scoping() number_sets = u.outputs.fields_container.GetData().GetTimeFreqSupport().NumberSets timeScop.Ids = range(1,number_sets+1) u.inputs.time_scoping.Connect(timeScop) # Use norm operator to get total deformation nrm = dpf.operators.math.norm_fc() nrm.Connect(u) nrm_field = nrm.outputs.getfields_container() # Scale total deformation and create combined scaled result add_fc = dpf.operators.math.add_fc() for i in range(nrm_field.FieldCount): my_field = nrm_field[i] scale = dpf.operators.math.scale() scale.inputs.field.Connect(my_field) if i==0: scale.inputs.ponderation.Connect(scale_value_1) else: scale.inputs.ponderation.Connect(scale_value_2) add_fc.Connect(i,scale.outputs.getfield()) data_fc = add_fc.outputs.getfields_container() data_fc.AddLabel('time') # Forward to plot output = dpf.operators.utility.forward() output.inputs.any.Connect(data_fc) dpf_workflow = dpf.Workflow() dpf_workflow.Add(output) dpf_workflow.SetOutputContour(output) dpf_workflow.Record('wf_id', False) this.WorkflowId = dpf_workflow.GetRecordedId()
And this returns:
0