How to calculate Elemental Mass using DPF?
Ayush Kumar
Member, Moderator, Employee Posts: 456
✭✭✭✭
in Structures
Comments
-
There is dedicated operator
dpf.operators.result.elemental_mass()
but in case there is an issue calculating via the operator; the following can be used:from ansys.dpf import core as dpf rst = r"\Path\to\file.rst" ds = dpf.DataSources(rst) model = dpf.Model(rst) dpf_mesh = model.metadata.meshed_region # List to store elemental densities all_mats = [] mats = dpf_mesh.property_field("mat") mat_prop = model.operator("mapdl_material_properties") mat_prop.inputs.materials.connect(mats) mat_prop.inputs.properties_name.connect("DENS") mat_field = mat_prop.outputs.properties_value.get_data()[0] for eid in dpf_mesh.elements.scoping.ids: mat_id = mats.get_entity_data_by_id(eid) density = mat_field.get_entity_data_by_id(mat_id[0]) all_mats.append(density) # Create Density Field density = dpf.fields_factory.create_scalar_field(num_entities=dpf_mesh.elements.n_elements) density.location = dpf.locations.elemental density.scoping.ids = dpf_mesh.elements.scoping.ids density.data = all_mats # Element volume el_vol = dpf.operators.geo.elements_volume(mesh=dpf_mesh) # Calculate elemental mass (density * volume) elemental_mass = dpf.operators.math.generalized_inner_product(fieldA=el_vol, fieldB=density)
0