You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use the PyDPF (using CPython, not IronPython) to extract reaction forces and moments at nodes (in a named selection) saving the outputs to arrays where the position of node in node array needs to correspond to position of reaction forces and moments in their respective arrays.
Here is what goes well in my script (see at the bottom):
extracting the nodes numbers
scoping the reaction forces and moments (force_summation()) to the nodes
creating the array of nodes (separate script)
creating the arrays of forces and moments
creating the array of node to which the forces and moments are scoped and confirming that they match to the nodes from named selection (though the order is a bit different)
extracting the coordinates (by using the model.metadata.meshed_region.nodes[node] (where the node is an element from results nodes)
Here is what goes wrong:
the out-of-plane coordinate is wrong (in the example the nodes are on a plane Z=25mm, however the output I get is Z = -65mm)
What am I doing wrong?
Should I use some other approach to read the coordinates of the nodes?
I'm a fair beginner at coding, so the code probably has a lot possibilities for improvements and optimization. However at the moment my main concern is that there seems to be a gross error in output.
Will appreciate any help in debugging this.
Here is my code:
(It should run on any *rst file as long as you change the path and the named selection name is valid and named selection is selection of nodes.)
<
from ansys.dpf import core as dpf
from ansys.dpf.core import operators as ops
import numpy as np
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to use the PyDPF (using CPython, not IronPython) to extract reaction forces and moments at nodes (in a named selection) saving the outputs to arrays where the position of node in node array needs to correspond to position of reaction forces and moments in their respective arrays.
Here is what goes well in my script (see at the bottom):
Here is what goes wrong:
What am I doing wrong?
Should I use some other approach to read the coordinates of the nodes?
I'm a fair beginner at coding, so the code probably has a lot possibilities for improvements and optimization. However at the moment my main concern is that there seems to be a gross error in output.
Will appreciate any help in debugging this.
Here is my code:
(It should run on any *rst file as long as you change the path and the named selection name is valid and named selection is selection of nodes.)
<
from ansys.dpf import core as dpf
from ansys.dpf.core import operators as ops
import numpy as np
--- Inputs ---
path = r'C:/.../BoltedBracket_files/dp0/SYS/MECH/file.rst'
ns_name = 'M24_NODETOP'
--- Getting model information ---
Import the model:
model = dpf.Model(path)
Fetching metadata from the model:
model_metadata = model.metadata
--- Manage data sources ---
data_src = model.metadata.data_sources
--- Select the nodes in named selection ---
ns_op = ops.scoping.on_named_selection()
ns_op.inputs.data_sources.connect(data_src)
ns_op.inputs.named_selection_name.connect(ns_name)
ns_op.inputs.requested_location.connect(dpf.locations.nodal)
ns_nodes = ns_op.outputs.mesh_scoping()
Finding last load step and scoping time on all load steps.
last_ls = model_metadata.time_freq_support.n_sets
time_scope = dpf.time_freq_scoping_factory.scoping_on_all_time_freqs(model)
--- Extracting Nodal Force Summation (Forces and Moments)
force_op = ops.averaging.force_summation()
force_op.inputs.time_scoping.connect(time_scope)
force_op.inputs.data_sources.connect(data_src)
force_op.inputs.nodal_scoping(ns_nodes)
force_op.inputs.force_type.connect(1)
--- Evaluating ---
Forces
force_fc = force_op.outputs.forces_on_nodes()
force_array = np.empty((0, 3))
for ls in range(0, last_ls):
force_field = force_fc[ls]
force_array = np.vstack([force_array, force_field.data])
Moments
moments_fc = force_op.outputs.moments_on_nodes()
moments_array = np.empty((0, 3))
for ls in range(0, last_ls):
moments_field = moments_fc[ls]
moments_array = np.vstack([moments_array, moments_field.data])
Coordinates of Nodes where Force Summation was read:
result_nodes_ids = np.array(force_fc[0].scoping.ids)
nodes_array = np.empty((0, 1))
for node in result_nodes_ids:
nodes_array = np.vstack([nodes_array, node])
nodes_coord = np.empty((0, 3))
for node in result_nodes_ids:
ns_field = model.metadata.meshed_region.nodes[node]
nodes_coord = np.vstack([nodes_coord, ns_field.coordinates])
Load steps for sorting:
ls_array = np.empty((0, 1))
for ls in range(0, last_ls):
for node in ns_nodes:
ls_temp = ls+1
ls_array = np.vstack([ls_array, ls_temp])
Full stack of nodes numbers through all load steps
full_nodes_array = np.empty((0, 1))
xy_coord_array = np.empty((0, 3))
for ls in range(0, last_ls):
full_nodes_array = np.vstack([full_nodes_array, nodes_array])
xy_coord_array = np.vstack([xy_coord_array, nodes_coord])
Stacked arrays for exporting to csv and results print:
results_array = np.hstack([full_nodes_array, ls_array, xy_coord_array, force_array, moments_array])
print(f"\nNodes numbers: \n{nodes_array} "
f"\nNodes coordinates: \n{nodes_coord} "
f"\nForces on nodes: \n{force_array} "
f"\nMoments on nodes: \n{moments_array} "
f"\n=== Full Results Set === \n{results_array}")
ExtractingForcesAndMomentsAllLS.py
Beta Was this translation helpful? Give feedback.
All reactions