Skip to content

Commit

Permalink
Feat(CSi) : Improved analytical results (#3028)
Browse files Browse the repository at this point in the history
* attach results to element instead of in giant list with other results

* added analytical nodes

* add element2D output

* further improvements

* remove cache object

* remove unused code

* assign results as objects are converted as opposed to all at once

* more changes per PR comments

* remove unused code

* remove int extensions

* remove elses

---------

Co-authored-by: Connor Ivy <[email protected]>
  • Loading branch information
connorivy and Connor Ivy authored Nov 9, 2023
1 parent 3b78a2c commit aeca91d
Show file tree
Hide file tree
Showing 26 changed files with 1,373 additions and 911 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<Compile Include="$(MSBuildThisFileDirectory)UI\ConnectorBindingsCSI.Settings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UnusedClass.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Util\ConnectorCSIUtils.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Util\ResultUtils.cs" />
</ItemGroup>
</Project>
63 changes: 41 additions & 22 deletions ConnectorCSI/ConnectorCSIShared/UI/ConnectorBindingsCSI.Settings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DesktopUI2;
using ConnectorCSIShared.Util;
using DesktopUI2;
using DesktopUI2.Models.Settings;
using System;
using System.Collections.Generic;
Expand All @@ -9,40 +10,58 @@ namespace Speckle.ConnectorCSI.UI
public partial class ConnectorBindingsCSI : ConnectorBindings
{
// WARNING: These strings need to have the same value as the strings in ConverterCSIUtils
readonly string SendNodeResults = "sendNodeResults";
readonly string Send1DResults = "send1DResults";
readonly string Send2DResults = "send2DResults";
public const string RESULTS_NODE_SLUG = "node-results";
public const string RESULTS_1D_SLUG = "1d-results";
public const string RESULTS_2D_SLUG = "2d-results";
public const string RESULTS_LOAD_CASES_SLUG = "load-cases";

public const string BEAM_FORCES = "Beam Forces";
public const string BRACE_FORCES = "Brace Forces";
public const string COLUMN_FORCES = "Column Forces";
public const string OTHER_FORCES = "Other Forces";
public const string FORCES = "Forces";
public const string STRESSES = "Stresses";
public const string DISPLACEMENTS = "Displacements";
public const string VELOCITIES = "Velocities";
public const string ACCELERATIONS = "Accelerations";
public override List<ISetting> GetSettings()
{
return new List<ISetting>
{
new CheckBoxSetting
new MultiSelectBoxSetting
{
Slug = SendNodeResults,
Name = "Send Node Analysis Results",
Slug = RESULTS_LOAD_CASES_SLUG,
Name = "Load Case Results To Send",
Icon = "Link",
IsChecked = false,
Description =
"Include node analysis results with object data when sending to Speckle. This will make the sending process take more time."
Description = "Only the analytical results that belong to the load combinations selected here \nwill be sent to Speckle",
Values = ResultUtils.GetNamesOfAllLoadCasesAndCombos(Model)
},
new CheckBoxSetting

new MultiSelectBoxSetting
{
Slug = Send1DResults,
Name = "Send 1D Analysis Results",
Slug = RESULTS_NODE_SLUG,
Name = "Node Results To Send",
Icon = "Link",
IsChecked = false,
Description =
"Include 1D analysis results with object data when sending to Speckle. This will make the sending process take more time."
Description = "Determines which node results are sent to Speckle",
Values = new List<string>() { DISPLACEMENTS, FORCES, VELOCITIES, ACCELERATIONS }
},
new CheckBoxSetting

new MultiSelectBoxSetting
{
Slug = Send2DResults,
Name = "Send 2D Analysis Results",
Slug = RESULTS_1D_SLUG,
Name = "1D Element Results To Send",
Icon = "Link",
IsChecked = false,
Description =
"Include 2D analysis results with object data when sending to Speckle. This will make the sending process take MUCH more time."
Description = "Determines which 1D element results and sent to Speckle",
Values = new List<string>() { BEAM_FORCES, BRACE_FORCES, COLUMN_FORCES, OTHER_FORCES }
},

new MultiSelectBoxSetting
{
Slug = RESULTS_2D_SLUG,
Name = "2D Element Results To Send",
Icon = "Link",
Description = "Determines which 2D element results are computed and sent to Speckle",
Values = new List<string>() { FORCES, STRESSES }
},
};
}
Expand Down
25 changes: 25 additions & 0 deletions ConnectorCSI/ConnectorCSIShared/Util/ResultUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
using CSiAPIv1;

namespace ConnectorCSIShared.Util
{
internal static class ResultUtils
{
public static List<string> GetNamesOfAllLoadCasesAndCombos(cSapModel sapModel)
{
List<string> names = new();

int numberOfLoadCombinations = 0;
string[] loadCombinationNames = null;
sapModel.RespCombo.GetNameList(ref numberOfLoadCombinations, ref loadCombinationNames);
names.AddRange(loadCombinationNames);

sapModel.LoadCases.GetNameList(ref numberOfLoadCombinations, ref loadCombinationNames);
names.AddRange(loadCombinationNames);

return names;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using ConverterCSIShared.Extensions;
using ConverterCSIShared.Models;
using CSiAPIv1;

namespace ConverterCSIShared
{
internal static class AnalysisResultUtils
{
public delegate int ApiResultMethod(
string name,
eItemTypeElm eItemType,
ref int numItems,
ref string[] objs,
ref string[] elms,
ref string[] loadCombos,
ref string[] stepTypes,
ref double[] stepNum,
ref double[] x,
ref double[] y,
ref double[] z,
ref double[] xx,
ref double[] yy,
ref double[] zz);

public static bool TryGetAPIResult(
ApiResultMethod apiResultMethod,
string nodeName,
out int numberResults,
out string[] obj,
out string[] elm,
out string[] loadCases,
out string[] stepType,
out double[] stepNum,
out double[] F1,
out double[] F2,
out double[] F3,
out double[] M1,
out double[] M2,
out double[] M3,
bool shouldGetResults = true)
{
numberResults = 0;
obj = null;
elm = null;
loadCases = null;
stepType = null;
stepNum = null;
F1 = null;
F2 = null;
F3 = null;
M1 = null;
M2 = null;
M3 = null;

if (!shouldGetResults)
{
return false;
}

int success = apiResultMethod(
nodeName,
eItemTypeElm.Element,
ref numberResults,
ref obj,
ref elm,
ref loadCases,
ref stepType,
ref stepNum,
ref F1,
ref F2,
ref F3,
ref M1,
ref M2,
ref M3);
return ApiResultValidator.IsSuccessful(success);
}
}
}
31 changes: 31 additions & 0 deletions Objects/Converters/ConverterCSI/ConverterCSIShared/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Http;

namespace ConverterCSIShared
{
internal static class Constants
{
// these three slugs were previously used by the connector and now only serve to maintain backwards
// compatibility with the slugs that may be saved to a user's existing stream card
public const string LEGACY_SEND_NODE_RESULTS = "sendNodeResults";
public const string LEGACY_SEND_1D_RESULTS = "send1DResults";
public const string LEGACY_SEND_2D_RESULTS = "send2DResults";

public const string RESULTS_NODE_SLUG = "node-results";
public const string RESULTS_1D_SLUG = "1d-results";
public const string RESULTS_2D_SLUG = "2d-results";
public const string RESULTS_LOAD_CASES_SLUG = "load-cases";

public const string BEAM_FORCES = "Beam Forces";
public const string BRACE_FORCES = "Brace Forces";
public const string COLUMN_FORCES = "Column Forces";
public const string OTHER_FORCES = "Other Forces";
public const string FORCES = "Forces";
public const string STRESSES = "Stresses";
public const string DISPLACEMENTS = "Displacements";
public const string VELOCITIES = "Velocities";
public const string ACCELERATIONS = "Accelerations";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Objects.Structural.Materials;
using OSG = Objects.Structural.Geometry;
using Speckle.Core.Kits.ConverterInterfaces;
using ConverterCSIShared.Models;

namespace Objects.Converter.CSI
{
Expand Down Expand Up @@ -72,6 +73,7 @@ public partial class ConverterCSI : ISpeckleConverter, IFinalizable

public void SetPreviousContextObjects(List<ApplicationObject> objects) => PreviousContextObjects = objects;

private ResultsConverter? resultsConverter;
public void SetContextDocument(object doc)
{
Model = (cSapModel)doc;
Expand All @@ -91,6 +93,7 @@ public void SetContextDocument(object doc)
else if (Settings["operation"] == "send")
{
SpeckleModel = ModelToSpeckle();
resultsConverter = new ResultsConverter(Model, Settings, GetLoadCases(), GetLoadCombos());
}
else
throw new Exception("operation setting was not set to \"send\" or \"receive\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<Import_RootNamespace>ConverterCSIShared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)AnalysisResultUtils.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Constants.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ConverterCSI.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ConverterCSIUtils.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ConverterCSI.DatabaseTableUtils.cs" />
Expand All @@ -17,6 +19,11 @@
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ICurveExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\LineExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\PolycurveExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\ApiResultValidator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\Element2DAnalyticalResultConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\NodeAnalyticalResultsConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\ResultsConverter.cs" />
<Compile Include="..\ConverterCSIShared\Models\Element1DAnalyticalResultConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\DatabaseTableWrapper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\ETABSGridLineDefinitionTable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Analysis\ConvertModelSettings.cs" />
Expand All @@ -39,6 +46,7 @@
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Geometry\ConvertStories.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Geometry\ConvertTendon.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Geometry\ConvertWall.cs" />
<Compile Include="$(MSBuildThisFileDirectory)partialclasses\loading\ConvertLoadCombination.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Loading\ConvertLoadPattern.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Loading\Loading1DElements.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Loading\Loading2DElements.cs" />
Expand All @@ -54,10 +62,7 @@
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Properties\ConvertSpring.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Properties\ConvertTendonProperty.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Results\ConvertResultGlobal.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Results\ConvertResultNodes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Results\ConvertResults.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Results\ConvertResultSet1D.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialClasses\Results\ConvertResultSet2D.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\ToNativeScalingService.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using Speckle.Core.Kits;

namespace ConverterCSIShared.Models
{
public static class ApiResultValidator
{
public static bool IsSuccessful(int success)
{
return success == 0;
}
public static void ThrowIfUnsuccessful(int success, string message)
{
if (IsSuccessful(success))
{
return;
}

throw new ConversionException(message);
}
public static void ThrowIfUnsuccessful<T>(int success, string message)
where T : Exception
{
if (IsSuccessful(success))
{
return;
}

throw (T)Activator.CreateInstance(typeof(T), message);
}
}
}
Loading

0 comments on commit aeca91d

Please sign in to comment.