ansys / pydpf-composites

A Python wrapper for Ansys DPF for the post-processing of composite structures.
https://composites.dpf.docs.pyansys.com
MIT License
8 stars 1 forks source link

Investigate how pydpf-composites can be loaded into a mechanical python results #329

Open janvonrickenbach opened 1 year ago

janvonrickenbach commented 1 year ago

📝 Description of the feature

It is now possible to use CPython for the python results in Mechanical. Test if it is possible to load pydpf-composites in Mechanical.

💡 Steps for implementing the feature

No response

🔗 Useful links and references

No response

janvonrickenbach commented 9 months ago

The following code snipped can be used to run a dpf evaluation with a CPython Python result. One neededs to install ansys-dpf-core for the ansys python first and then ansys-dpf-composites with --no-dependencies. The --no-dependencies is important because to keep the numpy version that comes with the ansys python. Just did a quick test with the snippet below. Clear generated data causes problems because the rst file is still in use by the dpf operator and cannot be moved. The results match with the composite failure tool

def post_started(sender, analysis):# Do not edit this line
    define_dpf_workflow(analysis)

def define_dpf_workflow(analysis):
    from ansys.dpf import core as dpf
    analysis = Model.Analyses[0]

    from ansys.dpf.composites.server_helpers._load_plugin import load_composites_plugin
    from ansys.dpf.composites.composite_model import CompositeModel, CompositeScope
    from ansys.dpf.composites.constants import FailureOutput
    from ansys.dpf.composites.example_helper import get_continuous_fiber_example_files
    from ansys.dpf.composites.failure_criteria import (
        MaxStressCriterion,
        CombinedFailureCriterion,
    )

    from ansys.dpf.composites.server_helpers import connect_to_or_start_server
    from ansys.dpf.composites.data_sources import get_composite_files_from_workbench_result_folder

    composite_files_on_server = get_composite_files_from_workbench_result_folder(Model.Analyses[0].Solution.ResultFileDirectory)

    combined_fc = CombinedFailureCriterion(
        name="failure of all materials",
        failure_criteria=[
            MaxStressCriterion(),
        ],
    )

    load_composites_plugin(dpf._global_server(), ansys_path=dpf._global_server().ansys_path)

    composite_model = CompositeModel(composite_files_on_server, server=dpf._global_server())

    output_all_elements = composite_model.evaluate_failure_criteria(
        combined_criterion=combined_fc,
    )
    irf_field = output_all_elements.get_field({"failure_label": FailureOutput.FAILURE_VALUE})

    forward = dpf.Operator("forward")
    forward.connect(0, irf_field)
    forward_type = dpf.Operator("forward")
    forward_type.connect(0, "fe_elemental_scoping")

    dpf_workflow = dpf.Workflow()
    dpf_workflow.add_operator(forward)
    dpf_workflow.add_operator(forward_type)

    dpf_workflow.set_output_name("contour", forward, 0)
    dpf_workflow.set_output_name("contour_gfx_type", forward_type, 0)
    workflow_id = dpf_workflow.record('wf_id', False)
    this = Tree.FirstActiveObject
    this.WorkflowId = workflow_id
janvonrickenbach commented 9 months ago

@greschd @roosre A basic evaluation with the python result works when using --no-dependencies.