How to export results on all bodies with DPF in Mechanical
Mike.Thompson
Member, Employee Posts: 330
✭✭✭✭
in Structures
How can I export results data (i.e. temperature) for all bodies to their own files also with data like max and min at each time point?
Tagged:
0
Answers
-
See this example that contains a python code object. Run the solve and .csv files will be generated in the solution directory.
Code below:
import mech_dpf
import Ans.DataProcessing as dpf
from os.path import join
mech_dpf.setExtAPI(ExtAPI)def after_solve(this, analysis):# Do not edit this line
#Get some basic data
DataSource=dpf.DataSources(analysis.ResultFileName)
DpfModel = dpf.Model(analysis.ResultFileName)
#Time scoping on all the result sets of the results file.
TimeScoping = dpf.TimeFreqScopingFactory.ScopingOnAllTimeFreqs(DpfModel)
TimeScoping.Ids=list(TimeScoping.Ids)[:-1]#get all the temperature data Temp_op=dpf.operators.result.temperature() Temp_op.inputs.time_scoping.Connect(TimeScoping) Temp_op.inputs.data_sources.Connect(DataSource) Temp_FC=Temp_op.outputs.fields_container.GetData() #Get the mesh nodal scoping of all the active bodies Bodies = ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Body) ActiveBodies = filter(lambda B: B.Suppressed==False, Bodies) for B in ActiveBodies: #get the nodal mesh scoping per body SelInfo = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) SelInfo.Ids=[B.GetGeoBody().Id] BodyMeshScoping=mech_dpf.GetNodeScopingByRefId(SelInfo) #Do a subset of the total temperature data op = dpf.operators.scoping.rescope_fc() op.inputs.fields_container.Connect(Temp_FC) op.inputs.mesh_scoping.Connect(BodyMeshScoping) op.inputs.default_value.Connect(0) Body_FC = op.outputs.fields_container.GetData() #Write this info to a .csv file CSV_op=dpf.operators.serialization.field_to_csv() CSV_op.inputs.field_or_fields_container.Connect(Body_FC) CSV_op.inputs.file_path.Connect(join(analysis.WorkingDir, B.Name+"_Temperatures.csv")) CSV_op.Run() #get the min and max. result will be a min and max field with Time as Ids and a single value (min or max) MinMax_op= dpf.operators.min_max.min_max_fc() MinMax_op.inputs.fields_container.Connect(Body_FC) BodyMax_F=MinMax_op.outputs.field_max.GetData() BodyMin_F=MinMax_op.outputs.field_min.GetData() #Write this to .csv files as well. CSV_op=dpf.operators.serialization.field_to_csv() CSV_op.inputs.field_or_fields_container.Connect(BodyMax_F) CSV_op.inputs.file_path.Connect(join(analysis.WorkingDir, B.Name+"_Max.csv")) CSV_op.Run() CSV_op=dpf.operators.serialization.field_to_csv() CSV_op.inputs.field_or_fields_container.Connect(BodyMax_F) CSV_op.inputs.file_path.Connect(join(analysis.WorkingDir, B.Name+"_Min.csv")) CSV_op.Run()
0