We would like to get the surface area where the electric field is above a certain value max Electric_field_x * 0.9. How can that be done using say dpf in mechanical?
Many thanks - below is the script with some changes (nodal scoping and electric field result), that seems to work ok (use at own risk):
#User inputs: file_path=Model.Analyses[0].ResultFileName node_ids = ExtAPI.DataModel.GetObjectsByName("MyFaceNodes")[0].Ids threshold = 1.5 #------------------------ routine ---------------------------------------- import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI) ds = dpf.DataSources(file_path) #Get the results from the result file result_op = dpf.operators.result.electric_field() result_op.inputs.data_sources.Connect(ds) result_op.inputs.requested_location.Connect('Nodal') #Convert to scalar elef_field_scalar_op = dpf.operators.math.norm_fc() elef_field_scalar_op.inputs.fields_container.Connect(result_op) #get the mesh from results file mesh_op=dpf.operators.mesh.mesh_provider() mesh_op.inputs.data_sources.Connect(ds) dpf_mesh = mesh_op.outputs.mesh.GetData() #make a skin mesh on a specific scoping of nodes mesh_scoping = dpf.MeshScopingFactory.NodalScoping(node_ids) skin_op = dpf.operators.mesh.skin() skin_op.inputs.mesh.Connect(dpf_mesh) skin_op.inputs.mesh_scoping.Connect(mesh_scoping) skin_mesh = skin_op.outputs.mesh.GetData() #Area of skin mesh op = dpf.operators.geo.elements_facets_surfaces_over_time() # operator instantiation op.inputs.mesh.Connect(skin_mesh)# optional area_fc = op.outputs.fields_container.GetData() area_f=area_fc[0] #Average from nodal to elemental to get values on the new skin elements ave_op = dpf.operators.averaging.nodal_to_elemental_fc() ave_op.inputs.fields_container.Connect(elef_field_scalar_op) ave_op.inputs.mesh.Connect(skin_mesh) #note the skin mesh is the input here, not the full mesh ave_op.inputs.scoping.Connect(dpf.MeshScopingFactory.ElementalScoping(skin_mesh.ElementIds)) ave_res=ave_op.outputs.fields_container.GetData() #Drop any skin elements below threshold of user choosing filter_op=dpf.operators.filter.field_high_pass_fc() filter_op.inputs.fields_container.Connect(ave_op) filter_op.inputs.threshold.Connect(threshold) fc = filter_op.outputs.fields_container.GetData() #sum up the element areas from the filtered field my_field = fc[0] areas=[area_f.GetEntityDataById(ElId)[0] for ElId in my_field.ScopingIds] total_area = sum(areas) print total_area
This is an example of how to do something similar with a displacement result (I don't have an electric field result off hand)
#User inputs: file_path=Model.Analyses[0].ResultFileName node_ids = ExtAPI.DataModel.GetObjectsByName("MyFaceNodes")[0].Ids threshold = 2.5E-11 #------------------------ routine ---------------------------------------- import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI) ds = dpf.DataSources(file_path) #Get the results from the result file result_op = dpf.operators.result.displacement() result_op.inputs.data_sources.Connect(ds) #Convert to scalar elef_field_scalar_op = dpf.operators.math.norm_fc() elef_field_scalar_op.inputs.fields_container.Connect(result_op) #get the mesh from results file mesh_op=dpf.operators.mesh.mesh_provider() mesh_op.inputs.data_sources.Connect(ds) dpf_mesh = mesh_op.outputs.mesh.GetData() #make a skin mesh on a specific scoping of nodes mesh_scoping = dpf.MeshScopingFactory.NodalScoping(node_ids) skin_op = dpf.operators.mesh.skin() skin_op.inputs.mesh.Connect(dpf_mesh) skin_op.inputs.mesh_scoping.Connect(mesh_scoping) skin_mesh = skin_op.outputs.mesh.GetData() #Area of skin mesh op = dpf.operators.geo.elements_facets_surfaces_over_time() # operator instantiation op.inputs.mesh.Connect(skin_mesh)# optional area_fc = op.outputs.fields_container.GetData() area_f=area_fc[0] #Average from nodal to elemental to get values on the new skin elements ave_op = dpf.operators.averaging.nodal_to_elemental_fc() ave_op.inputs.fields_container.Connect(elef_field_scalar_op) ave_op.inputs.mesh.Connect(skin_mesh) #note the skin mesh is the input here, not the full mesh ave_op.inputs.scoping.Connect(dpf.MeshScopingFactory.ElementalScoping(skin_mesh.ElementIds)) #Drop any skin elements below threshold of user choosing filter_op=dpf.operators.filter.field_high_pass_fc() filter_op.inputs.fields_container.Connect(ave_op) filter_op.inputs.threshold.Connect(threshold) fc = filter_op.outputs.fields_container.GetData() #sum up the element areas from the filtered field my_field = fc[0] areas=[area_f.GetEntityDataById(ElId)[0] for ElId in my_field.ScopingIds] total_area = sum(areas) print total_area