Hi everyone,
Is there a smart way to query the name (number) of selected nodes and their corresponding coordinates other than to first generate some data for those nodes, get the node numbers, and then refer to the automatically generated node.tcl file? This is becoming quite tedious once you start to be interested in querying tens of nodes.
Many thanks!
Query Node Name and Coordinate
Re: Query Node Name and Coordinate
You can do it in several ways depending on what you want to do:
You can use the Label tools to switch on/off the visualization of the labels and to adjust the settings for the labels:
You can use the Query Geometry tool. select a geometry vertex and obtain information about it and the associated mesh node (if the mesh has been generated)
This is what you need if you are just curious about the node ID and position. If instead, you need them for any other reason, let us know, there are many other options to automate certain processes without knowing a-priori what the ID and position of the mesh-nodes are
You can use the Label tools to switch on/off the visualization of the labels and to adjust the settings for the labels:
You can use the Query Geometry tool. select a geometry vertex and obtain information about it and the associated mesh node (if the mesh has been generated)
This is what you need if you are just curious about the node ID and position. If instead, you need them for any other reason, let us know, there are many other options to automate certain processes without knowing a-priori what the ID and position of the mesh-nodes are
Re: Query Node Name and Coordinate
Thank you for your help, that is quite informative.
I can select nodes of interest from the post-processing graphical interface, get necessary nodal results along with the node tags, copy the data and the tags into Excel, and query their coordinates from the "node.tcl" file using a simple Matlab code, which made the process a bit less manual.
But if possible, could you show me an example of extranting specific nodal results using a script?
1. Obtain results from specific nodes with known tags. E.g., get nodal results of node 78552, 865, ..., 95645.
2. Obtain results from all nodes whose coordinates fall into a specified range in the domain? E.g., all nodes that satisfy x = 0 to 100 and y = z = 0; or sqrt(x^2 + y^2) = 50 and z = -5?
I can select nodes of interest from the post-processing graphical interface, get necessary nodal results along with the node tags, copy the data and the tags into Excel, and query their coordinates from the "node.tcl" file using a simple Matlab code, which made the process a bit less manual.
But if possible, could you show me an example of extranting specific nodal results using a script?
1. Obtain results from specific nodes with known tags. E.g., get nodal results of node 78552, 865, ..., 95645.
2. Obtain results from all nodes whose coordinates fall into a specified range in the domain? E.g., all nodes that satisfy x = 0 to 100 and y = z = 0; or sqrt(x^2 + y^2) = 50 and z = -5?
Re: Query Node Name and Coordinate
Try this script for the Python API in post-processing.
If you don't know how to use it, please check the "Introduction to Python API" webinar, or ask here:
If you don't know how to use it, please check the "Introduction to Python API" webinar, or ask here:
Code: Select all
from PyMpc import *
import math
from matplotlib import pyplot as plt
# BEGIN USER-PARAMETERS ==================================
# Database ID
db_id = 1
# Stage-id for mesh evaluation
stage_for_mesh = 1
# nodal result to extract
result_name = 'Reaction Force'
result_comp = 2
# some user-define function to test for a node
def test_node_id(node):
return node.id == 100
def test_node_in_radius(node):
x = 0.0
y = 0.0
z = 0.0
radius = 10.0
dist = math.sqrt((node.x-x)**2 + (node.y-y)**2 + (node.z-z)**2)
return dist <= radius
def test_node_in_radius_2d(node):
x = 0.0
y = 0.0
z = 0.0
radius = 10.0
dist = math.sqrt((node.x-x)**2 + (node.y-y)**2)
return dist <= radius and (node.z-z)<1.0e-10
# the user-define function to test for a node
use_this_node = test_node_in_radius_2d
# END USER-PARAMETERS ==================================
# clear terminal
App.clearTerminal()
# get document
doc = App.postDocument()
# get database
db = doc.getDatabase(db_id)
if db is None:
raise Exception('Database {} is not available'.format(db_id))
# we need a mesh
# we need a random result to get the mesh
U = db.getNodalResult('Displacement', match=MpcOdb.Contains)
# create evaluation options
all_stages = db.getStageIDs()
if not stage_for_mesh in all_stages:
raise Exception('Stage {} is not available'.format(stage_for_mesh))
all_steps = db.getStepIDs(stage_for_mesh)
if len(all_steps) == 0:
raise Exception('No steps available in Stage {}'.format(stage_for_mesh))
opt = MpcOdbVirtualResultEvaluationOptions()
opt.stage = stage_for_mesh
opt.step = all_steps[0]
# evaluate the result
field = U.evaluate(opt)
mesh = field.mesh
# now we can parse nodes and get only the desired ones
the_nodes = []
for _, node in mesh.nodes.items():
if use_this_node(node):
the_nodes.append(node)
if len(the_nodes) == 0:
raise Exception('Cannot find any node which match the equation')
print('Found {} nodes'.format(len(the_nodes)))
# extract data
result = db.getNodalResult(result_name, match=MpcOdb.Contains)
plot_data = [ ([],[]) for i in range(len(the_nodes)) ]
# create the evaluation option
# evaluate all the results for each stage, for each step, and for each node.
# then we plot them in matplotlib, but you can do whatever you want with those values
opt = MpcOdbVirtualResultEvaluationOptions()
all_stages = db.getStageIDs()
for stage_id in all_stages:
all_steps = db.getStepIDs(stage_id)
opt.stage = stage_id
for step_id in all_steps:
print('process {}'.format(step_id))
App.processEvents()
opt.step = step_id
field = result.evaluate(opt)
for node, data in zip(the_nodes, plot_data):
# the row identifier for this node
row = MpcOdbResultField.node(node.id)
value = field[row, result_comp]
data[0].append(step_id)
data[1].append(value)
# plot in matplotlib
for (node, (x,y)) in zip(the_nodes, plot_data):
plt.plot(x,y,label=str(node))
plt.legend()
plt.show()