Skip to content

Commit 4762cf4

Browse files
Reading BarResults From RFEM6 (#105)
2 parents a02e643 + bab3beb commit 4762cf4

File tree

5 files changed

+338
-8
lines changed

5 files changed

+338
-8
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2025, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
using BH.Adapter.RFEM6;
23+
using BH.Engine.Base;
24+
using BH.oM.Data.Requests;
25+
using BH.oM.Structure.MaterialFragments;
26+
using BH.Engine.Structure;
27+
using BH.oM.Structure.SectionProperties;
28+
using BH.oM.Geometry;
29+
using BH.oM.Structure.Elements;
30+
using BH.oM.Analytical.Elements;
31+
using BH.oM.Base;
32+
using BH.oM.Structure.Requests;
33+
34+
namespace RFEM_Toolkit_Test.Elements
35+
{
36+
37+
38+
public class BarResultTestClass
39+
40+
{
41+
42+
RFEM6Adapter adapter;
43+
44+
//[TearDown]
45+
//public void TearDown()
46+
//{
47+
// adapter.Wipeout();
48+
//}
49+
50+
[OneTimeSetUp]
51+
public void InitializeRFEM6Adapter()
52+
{
53+
adapter = new RFEM6Adapter(true);
54+
55+
}
56+
57+
[Test]
58+
public void ReadResult()
59+
{
60+
61+
BarResultRequest request = new BarResultRequest();
62+
63+
request.ResultType = BarResultType.BarForce;
64+
request.DivisionType = DivisionType.EvenlyDistributed;
65+
request.Divisions = 3;
66+
request.Cases = new List<Object> { 1 };
67+
request.Modes = new List<string>();
68+
request.ObjectIds = new List<object> {1};
69+
//request.ObjectIds = new List<object> {1,2,3,4};
70+
71+
var obj = adapter.Pull(request);
72+
73+
obj.First();
74+
75+
}
76+
77+
78+
79+
}
80+
}
81+
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2025, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
using System;
23+
using System.Collections.Generic;
24+
using System.Linq;
25+
using System.Text;
26+
27+
using BH.oM.Adapter;
28+
using BH.oM.Structure.Elements;
29+
using BH.oM.Structure.Constraints;
30+
31+
using rfModel = Dlubal.WS.Rfem6.Model;
32+
using BH.oM.Adapters.RFEM6;
33+
using BH.oM.Structure.Loads;
34+
using Dlubal.WS.Rfem6.Model;
35+
using System.Xml.Linq;
36+
using BH.Engine.Base;
37+
using BH.oM.Analytical.Results;
38+
using BH.oM.Structure.Requests;
39+
using BH.oM.Structure.Results;
40+
using System.Configuration;
41+
using System.Globalization;
42+
using System.ComponentModel;
43+
using System.Linq.Expressions;
44+
45+
namespace BH.Adapter.RFEM6
46+
{
47+
public partial class RFEM6Adapter
48+
{
49+
50+
public IEnumerable<IResult> ReadResults(BarResultRequest request, ActionConfig actionConfig)
51+
{
52+
53+
54+
//Warnings
55+
BH.Engine.Base.Compute.RecordWarning($"Divisions are set to {request.Divisions}. Division functionality has not been implemented yet in RFEM6_Toolkit. Currently, the number of divisions depends solely on what RFEM6 provides and can vary significantly based on the load type on the corresponding Bar/Member and the DivisionType.");
56+
57+
//RFEM Specific Stuff
58+
m_Model.use_detailed_member_results(true);
59+
60+
// Loading of Member And LoadCase Ids
61+
List<int> memberIds = request.ObjectIds.Select(s => Int32.Parse(s.ToString())).ToList();
62+
List<int> loadCaseIds = request.Cases.Select(s => Int32.Parse(s.ToString())).ToList();
63+
64+
// Definition of Object Locations for Members
65+
object_location[] objectLocatioons = memberIds.Select(n => new object_location() { type = object_types.E_OBJECT_TYPE_MEMBER, no = n, parent_no = 0 }).ToArray();
66+
67+
//ResultList
68+
List<IResult> resultList = new List<IResult>();
69+
70+
71+
foreach (int c in loadCaseIds)
72+
{
73+
74+
//Loading resulst from RFEM
75+
INotifyPropertyChanged[] barResults = new INotifyPropertyChanged[1];
76+
77+
78+
switch (request.ResultType)
79+
{
80+
81+
case BarResultType.BarForce:
82+
barResults = m_Model.get_results_for_members_internal_forces(case_object_types.E_OBJECT_TYPE_LOAD_CASE, c, objectLocatioons, axes_type.MEMBER_AXES);
83+
break;
84+
case BarResultType.BarDisplacement:
85+
barResults = m_Model.get_results_for_members_global_deformations(case_object_types.E_OBJECT_TYPE_LOAD_CASE, c, objectLocatioons);
86+
break;
87+
case BarResultType.BarDeformation:
88+
barResults = m_Model.get_results_for_members_local_deformations(case_object_types.E_OBJECT_TYPE_LOAD_CASE, c, objectLocatioons, axes_type.MEMBER_AXES);
89+
break;
90+
case BarResultType.BarStrain:
91+
barResults = m_Model.get_results_for_members_strains(case_object_types.E_OBJECT_TYPE_LOAD_CASE, c, objectLocatioons, axes_type.MEMBER_AXES);
92+
break;
93+
default:
94+
BH.Engine.Base.Compute.RecordError($"The pull result types of type {request.ResultType} has not been developed Yet");
95+
return null;
96+
97+
}
98+
99+
//Grouping of Internal Forces grouped by Member No
100+
var memberInternalForceGroup = barResults.GroupBy(r => Int32.Parse(r.PropertyValue("row.member_no").ToString()));
101+
102+
103+
//Results processing memberwise
104+
foreach (IGrouping<int, INotifyPropertyChanged> member in memberInternalForceGroup)
105+
{
106+
//Ignore Results that do now have a valied ID
107+
if (member.Key == 0) continue;
108+
109+
//Determine Member length
110+
String lengthAsString = member.ToList()[0].PropertyValue("row.specification").ToString().Split(new[] { "L : ", " m" }, StringSplitOptions.None)[1];
111+
double memberLength = double.Parse(lengthAsString, CultureInfo.InvariantCulture);// Member Length in SI unit m;
112+
113+
var memberSegmentValues = member.ToList();
114+
115+
//If we are looking for exterme Values
116+
if (request.DivisionType == DivisionType.ExtremeValues)
117+
{
118+
119+
120+
memberSegmentValues = member.SkipWhile(m => !m.PropertyValue("description").ToString().Contains("Extremes")).ToList();
121+
memberSegmentValues = memberSegmentValues.TakeWhile(m => !m.PropertyValue("description").ToString().Contains("Total")).ToList();
122+
123+
}
124+
125+
else
126+
{
127+
memberSegmentValues = memberSegmentValues.TakeWhile(m => !m.PropertyValue("description").ToString().Contains("Extremes")).ToList();
128+
129+
}
130+
131+
int corrective = (request.ResultType == BarResultType.BarDisplacement || request.ResultType == BarResultType.BarDeformation) ? 0 : 2;
132+
// important do to enable processing of Deformations due to the |u|
133+
if (memberSegmentValues?.First()?.PropertyValue("row.deformation_label")?.ToString()?.Contains("|u|") ?? false)
134+
{
135+
memberSegmentValues = memberSegmentValues.Skip(2).ToList();
136+
//corrective = 0;
137+
}
138+
139+
//Conversion for every segment of member
140+
foreach (var e in memberSegmentValues)
141+
{
142+
143+
144+
var location = Double.Parse(e.PropertyValue("row.location").ToString());
145+
var memberNumber = Int32.Parse(e.PropertyValue("row.member_no").ToString());
146+
var props = e.PropertyValue("row").GetType().GetProperties();
147+
List<int> accesList = new List<int>() { 10 - corrective, 12 - corrective, 14 - corrective, 16 - corrective, 18 - corrective, 20 - corrective };
148+
var accessedlist = accesList.Select(a => props.ToList()[a]);
149+
Dictionary<string, double> val = new[] {
150+
(10-corrective, "x"), (12-corrective, "y"), (14-corrective, "z"),
151+
(16-corrective, "rx"), (18-corrective, "ry"), (20-corrective, "rz")
152+
}.ToDictionary(p => p.Item2, p => Double.Parse(
153+
e.PropertyValue($"row.{props[p.Item1].Name}").ToString()
154+
));
155+
156+
var result = val.Values.ToList().FromRFEM(c, memberLength, location, memberNumber,request.ResultType);
157+
resultList.Add(result);
158+
}
159+
160+
}
161+
}
162+
163+
return resultList;
164+
165+
}
166+
167+
}
168+
}
169+
170+

RFEM6_Adapter/CRUD/Read/BHoMDataStructure/Result/NodeReaction.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ private IEnumerable<IResult> ExtractNodeReaction(List<int> nodeIds, List<int> lo
7878
List<IResult> resultList = new List<IResult>();
7979
object_location[] filter = null;
8080

81-
//If no node ids are provided, then we will extract the results for all nodes
82-
83-
//get all Nodal Supports
84-
//List<Node> nodeList = new List<Node>();
85-
8681
rfModel.object_with_children[] nodalSupportObjWitheChildern = m_Model.get_all_object_numbers_by_type(rfModel.object_types.E_OBJECT_TYPE_NODAL_SUPPORT);
8782
nodalSupportObjWitheChildern = nodalSupportObjWitheChildern.ToList().Where(n => n.no != 0).ToArray();
8883
IEnumerable<rfModel.nodal_support> nodalSupport = nodalSupportObjWitheChildern.Length >= 1 ? nodalSupportObjWitheChildern.ToList().Select(n => m_Model.get_nodal_support(n.no)) : new List<rfModel.nodal_support>();
@@ -128,8 +123,6 @@ private IEnumerable<IResult> ExtractNodeReaction(List<int> nodeIds, List<int> lo
128123

129124
var r = res_all.First(k => k.row.node_no.Equals(nodeIds[i]));
130125

131-
//var r = res_all[i];
132-
133126
double fxValue = r.row.support_force_p_x;
134127
double fyValue = r.row.support_force_p_y;
135128
double fzValue = r.row.support_force_p_z;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2025, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
using System;
23+
using System.Collections.Generic;
24+
using System.Linq;
25+
using System.Text;
26+
27+
using BH.oM.Adapter;
28+
using BH.oM.Structure.Elements;
29+
using BH.Engine.Adapter;
30+
using BH.oM.Adapters.RFEM6;
31+
32+
using rfModel = Dlubal.WS.Rfem6.Model;
33+
using BH.oM.Structure.Loads;
34+
using BH.oM.Geometry;
35+
using BH.Engine.Spatial;
36+
using Dlubal.WS.Rfem6.Model;
37+
using BH.oM.Adapters.RFEM6.BHoMDataStructure.SupportDatastrures;
38+
using BH.oM.Adapters.RFEM6.Fragments.Enums;
39+
using System.Linq.Expressions;
40+
using System.Diagnostics;
41+
using BH.oM.Base;
42+
using BH.oM.Analytical.Results;
43+
using BH.oM.Structure.Results;
44+
using BH.oM.Structure.Requests;
45+
46+
namespace BH.Adapter.RFEM6
47+
{
48+
public static partial class Convert
49+
{
50+
public static IResult FromRFEM(this List<double> val, int lc, double memberLength, double location, int memberNumber, BarResultType resultType)
51+
{
52+
53+
54+
IResult result;
55+
56+
switch (resultType)
57+
{
58+
case BarResultType.BarForce:
59+
result = new BarForce(memberNumber, lc, -1, -1, Math.Round((double)location / memberLength, 4), 10, val[0], val[1], val[2], val[3], val[4], val[5]);
60+
break;
61+
case BarResultType.BarDisplacement:
62+
result = new BarDisplacement(memberNumber, lc, -1, -1, Math.Round((double)location / memberLength, 4), 10, val[0], val[1], val[2], val[3], val[4], val[5]);
63+
break;
64+
65+
case BarResultType.BarDeformation:
66+
result = new BarDeformation(memberNumber, lc, -1, -1, Math.Round((double)location / memberLength, 4), 10, val[0], val[1], val[2], val[3], val[4], val[5]);
67+
break;
68+
69+
case BarResultType.BarStrain:
70+
result = new BarStrain(memberNumber, lc, -1, -1, Math.Round((double)location / memberLength, 4), 10, val[0], val[1], val[2], 0,0,0,0,0,0);
71+
BH.Engine.Base.Compute.RecordWarning($"For BarResultType {resultType}, no bending around Y or Z axis or combined axis bending has been determined.");
72+
break;
73+
74+
default:
75+
BH.Engine.Base.Compute.RecordError($"No conversion method for BarResultType {resultType} has been implemented.");
76+
return null;
77+
}
78+
79+
80+
return result;
81+
}
82+
83+
}
84+
}
85+
86+

RFEM6_Adapter/RFEM6_Adapter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
<ItemGroup>
20-
<PackageReference Include="Dlubal.RFEMWebServiceLibrary" Version="6.7.6" />
20+
<PackageReference Include="Dlubal.RFEMWebServiceLibrary" Version="6.8.2" />
2121
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
2222
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2323
<PackageReference Include="System.Private.ServiceModel" Version="4.10.0" />

0 commit comments

Comments
 (0)