|
| 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 | + |
0 commit comments