How can I create the fibre orientation tensor file used by nCode using PyDPF-Composites?

Javier Vique
Javier Vique Member, Employee Posts: 55
5 Answers 25 Likes 10 Comments First Anniversary

When using fibre-share approach of Ansys nCode DesignLife Short-Fibre Composite, a csv file including the fibre orientation tensor per element is needed, which must be given in the same coordinate system as the stress analysis result. Can PyDPF-Composites help me on its creation?


Best Answer

  • Javier Vique
    Javier Vique Member, Employee Posts: 55
    5 Answers 25 Likes 10 Comments First Anniversary
    Answer ✓

    The available examples in PyDPF-Composites allow us to understand how to read a11 and a22 from Mechanical. Good news is that nCode reads stresses in Solution Coordinate System and values of a11 & a22 are also given in that local coordinate system, so no reconstruct of the fiber orientation tensor in the global coordinate system is needed.
    We just need to bring a11 and a22 data into a .csv file with the format requested by Ansys nCode DesignLife. Below the code:

    import ansys.dpf.core as dpf
    import numpy as np
    import os
    from ansys.dpf.composites.constants import FailureOutput
    from ansys.dpf.composites.data_sources import get_composite_files_from_workbench_result_folder
    from ansys.dpf.composites.server_helpers import connect_to_or_start_server
    server = connect_to_or_start_server()
    # Read Workbench model
    data_sources = dpf.DataSources()
    data_sources.add_file_path(r'here your path\MECH\MatML.xml', "EngineeringData")
    data_sources.add_file_path(r'here your path\MECH\ds.dat', "dat")
    data_sources.set_result_file_path(r'here your path\MECH\file.rst', "rst")
    model = dpf.Model(data_sources)
    mesh = model.metadata.meshed_region
    field_variable_provider = dpf.Operator("composite::inistate_field_variables_provider")
    field_variables = field_variable_provider.outputs.fields_container.get_data()
    a11 = field_variables[0]
    a22 = field_variables[1]
    ids = field_variables[0].scoping.ids
    a11data = a11.data_as_list
    a22data = a22.data_as_list
    a33data = np.ones(len(a11data))
    a33data = a33data - a11data - a22data
    a33data = np.around(a33data,6)
    FOT_file = os.path.join(r'here your path',"FOT.csv")
    with open(FOT_file, "w") as f:
        f.write('Orientation Tensors\n')
        f.write('Element,Layer Number,Section Point,a11,a22,a33,a12,a23,a13\n')
        [f.write(str(ids[i]) + ',1,1,' + str(a11data[i]) + ','+ str(a22data[i]) + ','+ str(a33data[i]) 
                 + ',0.,0.,0.\n') for i in range(len(ids))]