Performance Reading Mesh (API)

Performance Reading Mesh (API)

Anonymous
Not applicable
1,096 Views
3 Replies
Message 1 of 4

Performance Reading Mesh (API)

Anonymous
Not applicable

Hi all,

 

I am trying to read mesh data, nodal placements and element topology, from Robot into a post processing application written in C#.

 

Currently, I read nodal data using the RobotNodeServer

 

 

var nodes = robApp.Project.Structure.Nodes.GetAll();
for (int i = 1; i <= nodes.Count; i++)
       nodes.Get(i);

Similar, the topology is read like this (I only read quad and tri elements)

 

 

var elements = robApp.Project.Structure.FiniteElems.GetAll();
for (int i = 0; i < elements.Count; i++)
{
   var element = elements.Get(i) as IRobotFiniteElement;
   if (element.FeType == IRobotFiniteElementType.I_FET_Q4)
   {
      var n0 = element.Nodes.Get(1);
      var n1 = element.Nodes.Get(2);
      var n2 = element.Nodes.Get(3);
      var n3 = element.Nodes.Get(4);
   }
   if (element.FeType == IRobotFiniteElementType.I_FET_T3)
   {
      var n0 = element.Nodes.Get(1);
      var n1 = element.Nodes.Get(2);
      var n2 = element.Nodes.Get(3);
   }
}

 

 

While this works very well, I do get performance issues even for moderately sized models. Is there another way to read out the mesh data without the performance hit I get from the NodesServer and FiniteElementsServer?

 

 

I have experimented with exporting Table data to text files and reading them back into my application and while I can get the nodal data exported, I can't seem to get the element topology.

 

I have also looked at the Query mechanism described here but I can't figure out which parameters to set to make this work (note that no calculations have been performed when reading the data).

 

Any suggestions would be greatly appreciated.

Thanks Kasper

 

Accepted solutions (1)
1,097 Views
3 Replies
Replies (3)
Message 2 of 4

rwemay
Participant
Participant

 

Give this a try. Might need some namespace renaming and such.

 

using System.Collections.Generic;
using System.Linq;
using RobotOM;

namespace RobotToolkit
{
/// <summary>
/// Finite elements class for 2D planar shell finite element objects
/// </summary>
public class FiniteElement
{
/// <summary>
/// Gets the FE meshes from a Robot model using the fast query method
/// </summary>
/// <param name="panel_ids"></param>
/// <param name="coords"></param>
/// <param name="vertex_indices"></param>
/// <param name="str_nodes"></param>
/// <param name="filePath"></param>
/// <returns></returns>
public static bool GetFEMeshQuery(BHoM.Global.Project project, out int[] panel_ids, out double[][] coords, out Dictionary<int, int[]> vertex_indices, out Dictionary<int, BHoM.Structural.Node> str_nodes, string filePath = "LiveLink")
{
RobotApplication robot = null;
if (filePath == "LiveLink") robot = new RobotApplication();

//First call getnodesquery to get node points
double[][] nodeCoords = null;

Dictionary<int, BHoM.Structural.Node> _str_nodes = new Dictionary<int, BHoM.Structural.Node>();
RobotToolkit.Node.GetNodesQuery(project, filePath);
Dictionary<int, int> _nodeIds = new Dictionary<int, int>();
for (int i = 0; i < _str_nodes.Count; i++)
{
_nodeIds.Add(_str_nodes.ElementAt(i).Value.Number, i);
}

RobotResultQueryParams result_params = (RobotResultQueryParams)robot.Kernel.CmpntFactory.Create(IRobotComponentType.I_CT_RESULT_QUERY_PARAMS);
RobotStructure rstructure = robot.Project.Structure;
RobotSelection FE_sel = rstructure.Selections.CreateFull(IRobotObjectType.I_OT_FINITE_ELEMENT);
IRobotResultQueryReturnType query_return = IRobotResultQueryReturnType.I_RQRT_MORE_AVAILABLE;
RobotSelection cas_sel = rstructure.Selections.Create(IRobotObjectType.I_OT_CASE);
try { cas_sel.FromText(robot.Project.Structure.Cases.Get(1).Number.ToString()); } catch { }

if (cas_sel.Count > 0) result_params.Selection.Set(IRobotObjectType.I_OT_CASE, cas_sel);
result_params.Selection.Set(IRobotObjectType.I_OT_NODE, FE_sel); result_params.ResultIds.SetSize(5);
result_params.SetParam(IRobotResultParamType.I_RPT_MULTI_THREADS, true);
result_params.SetParam(IRobotResultParamType.I_RPT_THREAD_COUNT, 4);
result_params.SetParam(IRobotResultParamType.I_RPT_SMOOTHING, IRobotFeResultSmoothing.I_FRS_IN_ELEMENT_CENTER);
result_params.ResultIds.SetSize(5);
result_params.ResultIds.Set(1, 564);
result_params.ResultIds.Set(2, 565);
result_params.ResultIds.Set(3, 566);
result_params.ResultIds.Set(4, 567);
result_params.ResultIds.Set(5, 1252);

RobotResultRowSet row_set = new RobotResultRowSet();
bool ok = false;
RobotResultRow result_row = default(RobotResultRow);

List<int> _panel_ids = new List<int>();
Dictionary<int, int[]> _vertex_indices = new Dictionary<int, int[]>();
int kounta = 0;

while (!(query_return == IRobotResultQueryReturnType.I_RQRT_DONE))
{
query_return = rstructure.Results.Query(result_params, row_set);
ok = row_set.MoveFirst();
while (ok)
{
result_row = row_set.CurrentRow;
int panel_num = (int)row_set.CurrentRow.GetValue(1252);
_panel_ids.Add(panel_num);

int number_of_indices = (row_set.CurrentRow.IsAvailable(567)) ? 4 : 3;
int[] temp_indices = new int[number_of_indices];
for (int i = 0; i < number_of_indices; i++)
{
temp_indices[i] = _nodeIds[(int)row_set.CurrentRow.GetValue(564 + i)];
}

_vertex_indices.Add(kounta, temp_indices);
kounta++;
ok = row_set.MoveNext();
}
row_set.Clear();
}
result_params.Reset();

panel_ids = _panel_ids.ToArray();
vertex_indices = _vertex_indices;
coords = nodeCoords;
str_nodes = _str_nodes;
return true;
}

}
}

0 Likes
Message 3 of 4

Rafal.Gaweda
Autodesk Support
Autodesk Support
Accepted solution

FE table example:

 

Private Sub CommandButton1_Click()
 
Dim RobApp As RobotApplication
Set RobApp = New RobotApplication
Dim t As RobotTable
Dim tf As RobotTableFrame
Dim path As String
Dim Fullpath As String
Dim FName As String

path = Environ$("temp")
Dim nTables As Long

Set t = RobApp.Project.ViewMngr.CreateTable(I_TT_FINITE_ELEMENTS, I_TDT_FE)



        Set tf = RobApp.Project.ViewMngr.GetTable(1)
        FName = tf.Window.Caption
        spacepos = InStr(1, FName, " ")
        If spacepos <> 0 Then
            FName = Left(FName, spacepos - 1) + "_"
        End If
t.Select I_ST_PANEL, "all" t.Select I_ST_FINITE_ELEMENT, "all" tf.Get(2).Window.Activate Set t = tf.Get(2) tf.Current = 2 tabname = tf.GetName(2) tabname = Replace(tabname, " ", "_") DoEvents Fullpath = path + "\" + FName + tabname + ".txt" t.Printable.SaveToFile Fullpath, I_OFF_TEXT ansifilepath = Left(Fullpath, Len(Fullpath) - 4) + "_ansi.txt" X = Shell("cmd.exe /A /C TYPE " + Fullpath + " > " + ansifilepath, vbNormalFocus) DoEvents Workbooks.OpenText Filename:=ansifilepath, DataType:=xlDelimited, Semicolon:=True MsgBox "Dumping finished" Set RobApp = Nothing End Sub


Rafal Gaweda
0 Likes
Message 4 of 4

Anonymous
Not applicable
I went with the table exporting option which works great which have significantly improved the performance.
Thanks alot Rafal
0 Likes