Plotting a field fails
janvonrickenbach opened this issue · 2 comments
janvonrickenbach commented
In order to plot a field created using DPF-Composites, I make use of dpf.operators.averaging.elemental_nodal_to_nodal, but I get the following error message:
Here the script used:
import ansys.dpf.core as dpf
import numpy as np
from ansys.dpf.composites.composite_model import CompositeModel
from ansys.dpf.composites.constants import Spot, Sym3x3TensorComponent
from ansys.dpf.composites.example_helper import get_continuous_fiber_example_files
from ansys.dpf.composites.layup_info import (
AnalysisPlyInfoProvider,
get_all_analysis_ply_names,
get_dpf_material_id_by_analyis_ply_map,
)
from ansys.dpf.composites.select_indices import (
get_selected_indices,
get_selected_indices_by_analysis_ply,
get_selected_indices_by_dpf_material_ids,
)
from ansys.dpf.composites.server_helpers import connect_to_or_start_server
server = connect_to_or_start_server()
composite_files_on_server = get_continuous_fiber_example_files(server, "shell")
composite_model = CompositeModel(composite_files_on_server, server)
stress_operator = composite_model.core_model.results.stress()
stress_operator.inputs.bool_rotate_to_global(False)
stress_field = stress_operator.get_output(pin=0, output_type=dpf.types.fields_container)[0]
analysis_ply_info_provider = AnalysisPlyInfoProvider(
mesh=composite_model.get_mesh(), name="P1L1__ud_patch ns1"
)
element_ids = analysis_ply_info_provider.property_field.scoping.ids
stress_tensor = dpf.fields_factory.create_tensor_field(num_entities = len(element_ids),
location = dpf.locations.elemental_nodal)
for element_id in element_ids:
stress_data = stress_field.get_entity_data_by_id(element_id)
element_info = composite_model.get_element_info(element_id)
assert element_info is not None
selected_indices = get_selected_indices_by_analysis_ply(
analysis_ply_info_provider, element_info
)
stress_tensor.append(stress_data[selected_indices], element_id)
op_vm = dpf.operators.invariant.von_mises_eqv(field=stress_tensor, poisson_ratio=0.27)
VM_field = op_vm.outputs.field()
print(VM_field)
op_nodal = dpf.operators.averaging.elemental_nodal_to_nodal(field=VM_field)
VM_field_nodal = op_nodal.outputs.field()
print(VM_field_nodal)
composite_model.get_mesh().plot(VM_field_nodal)
If I try to use elemental_nodal_to_nodal_fc operator, I came across with different issues. Sometimes it requests mesh, sometimes I am getting a higher number of nodes than expected. I created a bug in the system (801352).
janvonrickenbach commented
Bug 801352 in TFS
janvonrickenbach commented
The support of the created field has to be set. This can be done by adding the following line after VM_field = op_vm.outputs.field():
VM_field.meshed_region = composite_model.get_mesh()
The reason for this is that the elemental_nodal_to_nodal operator needs the mesh.