def test_plotter_on_fields_container_nodal(allkindofcomplexity): model = Model(allkindofcomplexity) stress = model.results.stress() stress.inputs.requested_location.connect("Elemental") avg_op = Operator("to_nodal_fc") avg_op.inputs.fields_container.connect(stress.outputs.fields_container) fc = avg_op.outputs.fields_container() pl = DpfPlotter(model.metadata.meshed_region) cpos = pl.plot_contour(fc)
def test_chart_plotter(plate_msup): model = Model(plate_msup) mesh = model.metadata.meshed_region tfq = model.metadata.time_freq_support timeids = list(range(1, tfq.n_sets + 1)) disp = model.results.displacement() disp.inputs.time_scoping.connect(timeids) new_fields_container = disp.get_output(0, dpf.core.types.fields_container) pl = DpfPlotter(model.metadata.meshed_region) ret = pl.plot_chart(new_fields_container) assert ret
def test_plotter_add_mesh(multishells): model = core.Model(multishells) mesh = model.metadata.meshed_region split_mesh_op = core.Operator("split_mesh") split_mesh_op.connect(7, mesh) split_mesh_op.connect(13, "mat") meshes_cont = split_mesh_op.get_output(0, core.types.meshes_container) from ansys.dpf.core.plotter import DpfPlotter pl = DpfPlotter() for i in range(len(meshes_cont) - 10): pl.add_mesh(meshes_cont[i]) pl.show_figure()
def test_plotter_on_field(allkindofcomplexity): model = Model(allkindofcomplexity) stress = model.results.stress() stress.inputs.requested_location.connect("Elemental") avg_op = Operator("to_elemental_fc") avg_op.inputs.fields_container.connect(stress.outputs.fields_container) fc = avg_op.outputs.fields_container() field = fc[1] pl = DpfPlotter(model.metadata.meshed_region) fields_container = dpf.core.FieldsContainer() fields_container.add_label("time") fields_container.add_field({"time": 1}, field) cpos = pl.plot_contour(fields_container)
def plot(self, fields_container=None, **kwargs): """Plot the meshes container with a specific result if fields_container is specified. Parameters ---------- fields_container : FieldsContainer, optional Data to plot. The default is ``None``. Examples -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples >>> model = dpf.Model(examples.multishells_rst) >>> mesh = model.metadata.meshed_region >>> split_mesh_op = dpf.operators.mesh.split_mesh(mesh=mesh, property="mat") >>> meshes_cont = split_mesh_op.eval() >>> disp_op = dpf.operators.result.displacement( ... data_sources = dpf.DataSources(examples.multishells_rst), ... mesh = meshes_cont ... ) >>> disp_fc = disp_op.outputs.fields_container() >>> meshes_cont.plot(disp_fc) """ kwargs.setdefault("show_edges", True) notebook = kwargs.pop("notebook", None) pl = DpfPlotter(notebook=notebook) if fields_container is not None: for i in range(len(fields_container)): label_space = fields_container.get_label_space(i) mesh_to_send = self.get_mesh(label_space) if mesh_to_send is None: raise dpf_errors.DpfValueError( "Meshes container and result fields " "container do not have the same scope. " "Plotting can not proceed. ") field = fields_container[i] pl.add_field(field, mesh_to_send, **kwargs) else: from random import random random_color = "color" not in kwargs for mesh in self: if random_color: kwargs["color"] = [random(), random(), random()] pl.add_mesh(mesh, **kwargs) pl.show_figure()
def test_plot_min_max_labels(multishells): field, field_m, mesh, mesh_m = create_mesh_and_field_mapped_2(multishells) # create plotter, add fields and plot from ansys.dpf.core.plotter import DpfPlotter pl = DpfPlotter() pl.add_field(field_m, mesh_m) pl.add_field(field, mesh, style="wireframe", show_edges=True, color="w", opacity=0.3, show_max=True, show_min=True) pl.show_figure()
def test_plot_path_3(multishells): field, field_m, mesh, mesh_m = create_mesh_and_field_mapped_2(multishells) # create plotter, add fields and plot from ansys.dpf.core.plotter import DpfPlotter pl = DpfPlotter() # to use outside of the window: # pl = DpfPlotter(notebook=False) pl.add_field(field_m, mesh_m) pl.add_field(field, mesh, style="wireframe", show_edges=True, color="w", opacity=0.3) pl.show_figure()
def test_plot_node_labels(multishells): field, field_m, mesh, mesh_m = create_mesh_and_field_mapped_2(multishells) # create plotter, add fields and plot from ansys.dpf.core.plotter import DpfPlotter pl = DpfPlotter() pl.add_field(field_m, mesh_m) my_nodes_1 = [mesh_m.nodes[0], mesh_m.nodes[10]] my_labels_1 = ["MyNode1", "MyNode2"] pl.add_node_labels(my_nodes_1, mesh_m, my_labels_1, italic=True, bold=True, font_size=26, text_color="white", font_family="courier", shadow=True, point_color="grey", point_size=20) pl.show_figure()
# results over the same mesh and make a comparison. # Here we create a Model and request its mesh model = dpf.Model(examples.msup_transient) mesh_set2 = model.metadata.meshed_region # Then we need to request the displacement for two different time steps displacement_operator = model.results.displacement() displacement_operator.inputs.time_scoping.connect([2, 15]) displacement_set2 = displacement_operator.outputs.fields_container()[0] displacement_set15 = displacement_operator.outputs.fields_container()[1] ############################################################################### # Now we create an :class:`ansys.dpf.core.plotter.DpfPlotter` and add the # first mesh and the first result pl = DpfPlotter() pl.add_field(displacement_set2, mesh_set2) # Then it is needed to create a new mesh and translate it along x axis mesh_set15 = mesh_set2.deep_copy() overall_field = dpf.fields_factory.create_3d_vector_field( 1, dpf.locations.overall) overall_field.append([0.2, 0.0, 0.0], 1) coordinates_to_update = mesh_set15.nodes.coordinates_field add_operator = dpf.operators.math.add(coordinates_to_update, overall_field) coordinates_updated = add_operator.outputs.field() coordinates_to_update.data = coordinates_updated.data # Finally we feed the DpfPlotter with the second mesh and the second result # and we plot the result pl.add_field(displacement_set15, mesh_set15)
fieldB=stress_tensor_lc2_sc) ############################################################################### # Principal Stresses are the Eigenvalues of the stress tensor. # Use ``principal_invariants`` to get S1, S2 and S3 # p_inv = dpf.operators.invariant.principal_invariants() p_inv.inputs.field.connect(stress_tensor_combi) ############################################################################### # Print S1 - Maximum Principal stress # print(p_inv.outputs.field_eig_1().data) ############################################################################### # Get the meshed region # mesh_set = model.metadata.meshed_region ############################################################################### # Plot the results on the mesh. # ``label_text_size`` and ``label_point_size`` control font size of the label. # plot = DpfPlotter() plot.add_field(p_inv.outputs.field_eig_1(), meshed_region=mesh_set) # You can set the camera positions using the `cpos` argument # The three tuples in the list `cpos` represent camera position- # focal point, and view up respectively. plot.show_figure(show_axes=True)
# stress_tensor = model.results.stress() time_scope = dpf.Scoping() time_scope.ids = [1, 2] stress_tensor.inputs.time_scoping.connect(time_scope) stress_tensor.inputs.requested_location.connect("Nodal") ############################################################################### # Get the meshed region # mesh_set = model.metadata.meshed_region ############################################################################### # Plot the results on the mesh, show the minimum and maximum. # plot = DpfPlotter() plot.add_field( stress_tensor.outputs.fields_container.get_data()[1], meshed_region=mesh_set, show_max=True, show_min=True, label_text_size=15, label_point_size=5, ) # Add custom labels to specific nodes with specific label properties. # If label for a node is missing, by default nodal value is shown. my_nodes_1 = [mesh_set.nodes[0], mesh_set.nodes[10]] my_labels_1 = ["MyNode1", "MyNode2"] plot.add_node_labels(
coord_copy[1] = coord_copy[0] + i * 0.001 coordinates.append(coord_copy) field_coord = dpf.fields_factory.create_3d_vector_field(len(coordinates)) field_coord.data = coordinates field_coord.scoping.ids = list(range(1, len(coordinates) + 1)) ############################################################################### # Let's now compute the mapped data using the mapping operator mapping_operator = ops.mapping.on_coordinates( fields_container=stress_fc, coordinates=field_coord, create_support=True, mesh=mesh) fields_mapped = mapping_operator.outputs.fields_container() ############################################################################### # Here, we request the mapped field data and its mesh field_m = fields_mapped[0] mesh_m = field_m.meshed_region ############################################################################### # Now we create the plotter and add fields and meshes pl = DpfPlotter() pl.add_field(field_m, mesh_m) pl.add_mesh(mesh, style="surface", show_edges=True, color="w", opacity=0.3) # Finally we plot the result pl.show_figure(show_axes=True)
def test_plotter_on_mesh(allkindofcomplexity): model = Model(allkindofcomplexity) pl = DpfPlotter(model.metadata.meshed_region) cpos = pl.plot_mesh()
def test_plot_contour_using_vtk_file(complex_model): model = core.Model(complex_model) stress = model.results.displacement() fc = stress.outputs.fields_container() pl = DpfPlotter(model.metadata.meshed_region) pl._plot_contour_using_vtk_file(fc)