Model Geometry (Plotly)¶
A Bridge Example¶
At any point during model creation, you can run the opstool.vis.plotly.plot_model() function to visualize the current model’s geometric details.
This function operates based on post-processed data saved during the modeling process, ensuring accurate visualization.
You can use opstool.vis.plotly.plot_model() anywhere within your model script.
It reads the predefined data, such as nodes and elements, and generates a visual representation of the model.
[1]:
import opstool as opst
import opstool.vis.plotly as opsvis
[2]:
opst.load_ops_examples("ArchBridge2")
# or your model code here
Here, we use a built-in example from opstool, which is an example of a deck arch bridge model primarily composed of frame elements and shell elements.
For your own model script, simply place the opstool.vis.plotly.plot_model() function anywhere you need visualization.
QUick visualization¶
[3]:
fig = opsvis.plot_model()
fig.show()
fig.write_html("images/model_plotly0.html", full_html=False, include_plotlyjs="cdn")
Data type cannot be displayed: application/vnd.plotly.v1+json
Saving Model Data (Optional)¶
[4]:
opst.post.save_model_data(odb_tag=1)
OPSTOOL :: Model data has been saved to .opstool.output/ModelData-1.nc!
We can first save the model geometry data by assigning a unique label to the result database using the parameter
`odb_tag`.
This label is used to identify the data.
For more details, see opstool.post.save_model_data().
Visualization¶
We use the opstool.vis.plotly.set_plot_props() function to predefine some common visualization properties, which will affect all subsequent visualizations of models, eigenvalues, and responses.
[5]:
opsvis.set_plot_props(point_size=0, line_width=3)
Visualization is straightforward; simply call the opstool.vis.plotly.plot_model() function.
The `odb_tag` parameter helps you identify which dataset to use.
For details on various parameters, refer to the opstool.vis.plotly.plot_model().
[6]:
fig = opsvis.plot_model(odb_tag=1, show_outline=True)
# fig.show(renderer="jupyterlab")
# fig.show(renderer="notebook")
# fig.show(renderer="browser")
fig.show() # for auto
# fig.write_html("**.html")
OPSTOOL :: Loading model data from .opstool.output/ModelData-1.nc ...
Data type cannot be displayed: application/vnd.plotly.v1+json
The function opstool.vis.plotly.plot_model() returns a Plotly Figure object, which you can visualize using the show method.
In this example, the rendering mode is set to notebook, allowing the figure to be embedded directly within a Jupyter Notebook.
If you want it to automatically choose the rendering mode, simply call show without providing any arguments.
For more details on the available renderer, please refer to Displaying Figures in Python