Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/ansys/dpf/core/fields_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,12 @@
if label_space is None:
label_space = {}
fields = self.get_fields(label_space=label_space)
for f in fields:
plt.add_field(field=f, **kwargs)
# Fields with same support will override each other so we first merge them
merge_op = dpf.core.operators.utility.merge_fields()
for i, f in enumerate(fields):
merge_op.connect(i, f)
merged_field = merge_op.eval()
plt.add_field(field=merged_field, **kwargs)

Check warning on line 555 in src/ansys/dpf/core/fields_container.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/fields_container.py#L551-L555

Added lines #L551 - L555 were not covered by tests
return plt.show_figure(**kwargs)

def animate(
Expand Down
33 changes: 33 additions & 0 deletions tests/test_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,39 @@ def test_fields_container_plot(allkindofcomplexity):
disp_fc.plot()


@pytest.mark.skipif(not HAS_PYVISTA, reason="Please install pyvista")
def test_fields_container_plot_same_mesh(multishells):
import numpy as np

fc = core.FieldsContainer()
f1 = core.fields_factory.create_scalar_field(num_entities=1, location=core.locations.elemental)
f1.append(data=[2.0], scopingid=1)
f2 = core.fields_factory.create_scalar_field(num_entities=1, location=core.locations.elemental)
f2.append(data=[4.0], scopingid=2)
fc.add_label(label="id", default_value=0)
fc.add_field({"id": 1}, f1)
fc.add_field({"id": 2}, f2)

mesh = core.meshed_region.MeshedRegion(num_nodes=6, num_elements=2)
arr = np.array(
[
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.0, 1.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 2.0, 0.0],
[1.0, 2.0, 0.0],
]
)
coord = core.field_from_array(arr)
mesh.set_coordinates_field(coordinates_field=coord)
mesh.elements.add_shell_element(id=1, connectivity=[0, 1, 2, 3])
mesh.elements.add_shell_element(id=2, connectivity=[2, 3, 4, 5])
f1.meshed_region = mesh
f2.meshed_region = mesh
fc.plot()


@pytest.mark.skipif(not HAS_PYVISTA, reason="Please install pyvista")
def test_field_elemental_plot(allkindofcomplexity):
model = Model(allkindofcomplexity)
Expand Down
Loading