Skip to content

Commit

Permalink
fix: node resp vis when model_update is True
Browse files Browse the repository at this point in the history
  • Loading branch information
yexiang1992 committed Dec 8, 2024
1 parent 4ddb2b1 commit fda2a88
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 42 deletions.
80 changes: 44 additions & 36 deletions opstool/post/_get_response/_get_nodal_resp.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,37 @@ def _get_nodal_resp(node_tags):
node_pressure = [] # 1 data each row, P
for i, tag in enumerate(node_tags):
tag = int(tag)
coord = ops.nodeCoord(tag)
disp = ops.nodeDisp(tag)
vel = ops.nodeVel(tag)
accel = ops.nodeAccel(tag)
if len(coord) == 1:
coord.extend([0, 0])
disp.extend([0, 0, 0, 0, 0])
vel.extend([0, 0, 0, 0, 0])
accel.extend([0, 0, 0, 0, 0])
elif len(coord) == 2:
coord.extend([0])
if len(disp) == 2: # 2 ndim 2 dof
disp.extend([0, 0, 0, 0])
vel.extend([0, 0, 0, 0])
accel.extend([0, 0, 0, 0])
elif len(disp) == 3: # 2 ndim 3 dof
disp = [disp[0], disp[1], 0.0, 0.0, 0.0, disp[-1]]
vel = [vel[0], vel[1], 0.0, 0.0, 0.0, vel[-1]]
accel = [accel[0], accel[1], 0.0, 0.0, 0.0, accel[-1]]
if tag in ops.getNodeTags():
coord = ops.nodeCoord(tag)
disp = ops.nodeDisp(tag)
vel = ops.nodeVel(tag)
accel = ops.nodeAccel(tag)
if len(coord) == 1:
coord.extend([0, 0])
disp.extend([0, 0, 0, 0, 0])
vel.extend([0, 0, 0, 0, 0])
accel.extend([0, 0, 0, 0, 0])
elif len(coord) == 2:
coord.extend([0])
if len(disp) == 2: # 2 ndim 2 dof
disp.extend([0, 0, 0, 0])
vel.extend([0, 0, 0, 0])
accel.extend([0, 0, 0, 0])
elif len(disp) == 3: # 2 ndim 3 dof
disp = [disp[0], disp[1], 0.0, 0.0, 0.0, disp[-1]]
vel = [vel[0], vel[1], 0.0, 0.0, 0.0, vel[-1]]
accel = [accel[0], accel[1], 0.0, 0.0, 0.0, accel[-1]]
else:
if len(disp) == 3: # 3 ndim 3 dof
disp.extend([0, 0, 0])
vel.extend([0, 0, 0])
accel.extend([0, 0, 0])
elif len(disp) == 6: # 3 ndim 6 dof
pass
else:
if len(disp) == 3: # 3 ndim 3 dof
disp.extend([0, 0, 0])
vel.extend([0, 0, 0])
accel.extend([0, 0, 0])
elif len(disp) == 6: # 3 ndim 6 dof
pass
disp = [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]
vel = [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]
accel = [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]
node_disp.append(disp)
node_vel.append(vel)
node_accel.append(accel)
Expand All @@ -145,18 +150,21 @@ def get_react(tags):
forces = [] # 6 data each row, Ux, Uy, Uz, Rx, Ry, Rz
for tag in tags:
tag = int(tag)
coord = ops.nodeCoord(tag)
fo = ops.nodeReaction(tag)
if len(coord) == 1:
fo.extend([0.0, 0.0, 0.0, 0.0, 0.0])
elif len(coord) == 2:
if len(fo) == 2:
fo.extend([0.0, 0.0, 0.0, 0.0])
elif len(fo) == 3:
fo = [fo[0], fo[1], 0.0, 0.0, 0.0, fo[-1]]
if tag in ops.getNodeTags():
coord = ops.nodeCoord(tag)
fo = ops.nodeReaction(tag)
if len(coord) == 1:
fo.extend([0.0, 0.0, 0.0, 0.0, 0.0])
elif len(coord) == 2:
if len(fo) == 2:
fo.extend([0.0, 0.0, 0.0, 0.0])
elif len(fo) == 3:
fo = [fo[0], fo[1], 0.0, 0.0, 0.0, fo[-1]]
else:
if len(fo) == 3:
fo.extend([0.0, 0.0, 0.0])
else:
if len(fo) == 3:
fo.extend([0.0, 0.0, 0.0])
fo = [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]
forces.append(fo)
return forces

Expand Down
21 changes: 18 additions & 3 deletions opstool/vis/plotly/vis_nodal_resp.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,35 @@ def _create_mesh(
show_mp_constraint: bool = True,
):
step = int(round(value))
node_nodeform_coords = self._get_node_data(step).to_numpy()
node_nodeform_coords = self._get_node_data(step)
# bounds = self._get_node_data(step).attrs["bounds"]
# model_dims = self._get_node_data(step).attrs["ndims"]
line_cells, _ = _get_line_cells(self._get_line_data(step))
_, unstru_cell_types, unstru_cells = _get_unstru_cells(
self._get_unstru_data(step)
)
# t_ = self.time[step]
node_disp = self._get_deformation_data(step)
node_resp = self._get_resp_data(step, self.resp_type, self.component)
is_coord_equal = np.array_equal(
node_nodeform_coords.coords["tags"].values,
node_disp.coords["nodeTags"].values
)
if not is_coord_equal:
common_coords = np.intersect1d(
node_nodeform_coords.coords["tags"].values,
node_disp.coords["nodeTags"].values
)
node_nodeform_coords = node_nodeform_coords.sel({"tags": common_coords})
node_disp = node_disp.sel({"nodeTags": common_coords})
node_resp = node_resp.sel({"nodeTags": common_coords})
node_nodeform_coords = node_nodeform_coords.to_numpy()
node_disp = node_disp.to_numpy()
node_resp = node_resp.to_numpy()
if alpha > 0.0:
node_disp = self._get_deformation_data(step).to_numpy()
node_deform_coords = alpha * node_disp + node_nodeform_coords
else:
node_deform_coords = node_nodeform_coords
node_resp = self._get_resp_data(step, self.resp_type, self.component)
if node_resp.ndim == 1:
scalars = node_resp
else:
Expand Down
21 changes: 18 additions & 3 deletions opstool/vis/pyvista/vis_nodal_resp.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,35 @@ def _create_mesh(
show_mp_constraint: bool = True,
):
step = int(round(value))
node_nodeform_coords = self._get_node_data(step).to_numpy()
node_nodeform_coords = self._get_node_data(step)
bounds = self._get_node_data(step).attrs["bounds"]
model_dims = self._get_node_data(step).attrs["ndims"]
line_cells, _ = _get_line_cells(self._get_line_data(step))
_, unstru_cell_types, unstru_cells = _get_unstru_cells(
self._get_unstru_data(step)
)
t_ = self.time[step]
node_disp = self._get_deformation_data(step)
node_resp = self._get_resp_data(step, self.resp_type, self.component)
is_coord_equal = np.array_equal(
node_nodeform_coords.coords["tags"].values,
node_disp.coords["nodeTags"].values
)
if not is_coord_equal:
common_coords = np.intersect1d(
node_nodeform_coords.coords["tags"].values,
node_disp.coords["nodeTags"].values
)
node_nodeform_coords = node_nodeform_coords.sel({"tags": common_coords})
node_disp = node_disp.sel({"nodeTags": common_coords})
node_resp = node_resp.sel({"nodeTags": common_coords})
node_nodeform_coords = node_nodeform_coords.to_numpy()
node_disp = node_disp.to_numpy()
node_resp = node_resp.to_numpy()
if alpha > 0.0:
node_disp = self._get_deformation_data(step).to_numpy()
node_deform_coords = alpha * node_disp + node_nodeform_coords
else:
node_deform_coords = node_nodeform_coords
node_resp = self._get_resp_data(step, self.resp_type, self.component)
if node_resp.ndim == 1:
scalars = node_resp
else:
Expand Down

0 comments on commit fda2a88

Please sign in to comment.