Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
janvonrickenbach opened this issue Aug 14, 2023 · 2 comments
Labels
enhancement New features or code improvements

Comments

@janvonrickenbach
Copy link
Contributor

📝 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 janvonrickenbach added the enhancement New features or code improvements label Aug 14, 2023
@janvonrickenbach
Copy link
Contributor Author

janvonrickenbach commented Jan 9, 2024

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features or code improvements
Projects
None yet
Development

No branches or pull requests

1 participant