Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b681a6f
Transfer to Clean branch
EmmaSander Apr 11, 2025
74522ad
Working combined method node result
EmmaSander Apr 11, 2025
797a662
Added Bar Results
EmmaSander Apr 15, 2025
9a146cb
added MeshResult and errors
EmmaSander Apr 15, 2025
d2b7193
Fixed sorting by loadCase
EmmaSander Apr 16, 2025
b7f9a56
Updated references
EmmaSander Apr 16, 2025
a09998d
Update MidasCivil_Adapter.csproj
EmmaSander Apr 16, 2025
deb8cb0
Installer error fix test
EmmaSander Apr 17, 2025
1cb3444
Start of updates
EmmaSander Apr 17, 2025
c51cb5a
Requested Updates
EmmaSander Apr 24, 2025
aa2c1fb
Minor updates
EmmaSander Apr 24, 2025
1af4564
Remove memory reference, case sorting temp. disabled
EmmaSander May 28, 2025
13aa4f2
Merge branch 'develop' into MidasCivil_Toolkit-#402-PullResultsAPI
EmmaSander May 28, 2025
72a3f1d
reinstated case filter
EmmaSander Jun 6, 2025
f0df2fc
Reference Update
EmmaSander Jun 6, 2025
a889052
Update MidasCivil_Adapter.csproj
EmmaSander Jun 6, 2025
31fd906
Update MidasCivil_Adapter/PrivateHelpers/AppendCaseTypes.cs
EmmaSander Jun 16, 2025
25291bb
Update MidasCivil_Adapter/PrivateHelpers/ReadResultAPI.cs
EmmaSander Jun 16, 2025
575f309
Update MidasCivil_Adapter/PrivateHelpers/ReadResultAPI.cs
EmmaSander Jun 16, 2025
e3ef64d
Update MidasCivil_Adapter/PrivateHelpers/AppendCaseTypes.cs
EmmaSander Jun 16, 2025
81c9539
Requested Updates
EmmaSander Jun 16, 2025
0ac3844
Add GET units for Open in Execute actions
peterjamesnugent Jun 16, 2025
9c53615
Add unit conversion for result reading
peterjamesnugent Jun 16, 2025
48aba28
Updated meshstress and removed double unit conversion
EmmaSander Jun 30, 2025
4aa1660
Fixed bugs added versioning
EmmaSander Jul 17, 2025
b5b90c9
Added LayerFiltering for Meshstresses
EmmaSander Jul 18, 2025
ac648a7
Add in sigXY
EmmaSander Jul 18, 2025
992d9f4
Formatting and correcting layer positions
EmmaSander Jul 18, 2025
414802f
Revert addition of SigmaXY as it's shear stress in MidasCivil but nor…
peterjamesnugent Jul 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MidasCivil_Adapter/CRUD/Read/Results/BarResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public IEnumerable<IResult> ReadResults(BarResultRequest request, ActionConfig a
case "9.5.0.nx":
case "9.5.5.nx":
List<string> loadCasesNX = Task.Run(() => AppendCaseTypes(request)).Result;
string divisions = GetBarDivisions(request);
string divisions = SetBarDivisions(request);

if (loadCasesNX != null)
results = Task.Run(() => ReadResult(request.ResultType.ToString(), objectIds, loadCasesNX, divisions)).Result.ToList();
Expand Down
2 changes: 1 addition & 1 deletion MidasCivil_Adapter/CRUD/Read/Results/MeshResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public IEnumerable<IResult> ReadResults(MeshResultRequest request, ActionConfig
case "9.5.5.nx":
List<string> loadCasesNX = Task.Run(() => AppendCaseTypes(request)).Result;
if (loadCasesNX != null)
results = Task.Run(() => ReadResult(request.ResultType.ToString(), objectIds, loadCasesNX)).Result.ToList();
results = Task.Run(() => ReadResult(request.ResultType.ToString(), objectIds, loadCasesNX, "", request)).Result.ToList();
break;
default:
List<string> loadCases = GetLoadcaseIDs(request);
Expand Down
18 changes: 8 additions & 10 deletions MidasCivil_Adapter/Convert/ToBHoM/Results/ToMeshStress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Collections.Generic;
using BH.oM.Geometry;
using System.Text.Json;
using BH.oM.Structure.Requests;

namespace BH.Adapter.MidasCivil
{
Expand Down Expand Up @@ -60,25 +61,22 @@ public static MeshStress ToMeshStress(this List<string> delimitted)

/***************************************************/

public static MeshStress ToMeshStressAPI(List<object> item, bool bottom)
public static MeshStress ToMeshStress(List<object> item, MeshResultRequest request)
{
double LayerPosition = 1;
MeshResultLayer meshResultLayer = MeshResultLayer.Upper;

if (bottom || item[4].ToString().Contains("Bot"))
double LayerPosition = double.NaN;
if (item[4] != null)
{
LayerPosition = 0;
meshResultLayer = MeshResultLayer.Lower;
if (bottom)
item.RemoveRange(4, 7);
LayerPosition = 1;
if (item[4].ToString().Contains("Bot"))
LayerPosition = 0;
}

//TODO: resolve below identifiers extractable through the API
int mode = -1;
double timeStep = 0;

MeshStress Meshstress = new MeshStress(System.Convert.ToInt32(item[1]), item[3].ToString(), 0,
item[2].ToString(), mode, timeStep, meshResultLayer, LayerPosition, MeshResultSmoothingType.None, null,
item[2].ToString(), mode, timeStep, request.Layer, LayerPosition, MeshResultSmoothingType.None, null,
System.Convert.ToDouble(item[5]), System.Convert.ToDouble(item[6]), 0,
0, 0,
System.Convert.ToDouble(item[8]), System.Convert.ToDouble(item[9]), 0);
Expand Down
21 changes: 9 additions & 12 deletions MidasCivil_Adapter/Convert/ToBHoM/Results/ToMeshVonMises.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Collections.Generic;
using BH.oM.Geometry;
using System.Text.Json;
using BH.oM.Structure.Requests;

namespace BH.Adapter.MidasCivil
{
Expand Down Expand Up @@ -58,26 +59,22 @@ public static MeshVonMises ToMeshVonMises(this List<string> delimitted)

/***************************************************/

public static MeshVonMises ToMeshVonMisesAPI(List<object> item, bool bottom)
public static MeshVonMises ToMeshVonMises(List<object> item, MeshResultRequest request)
{
double LayerPosition = 1;
MeshResultLayer meshResultLayer = MeshResultLayer.Upper;

if (bottom || item[4].ToString().Contains("Bot"))
double LayerPosition = double.NaN;
if (item[4] != null)
{
LayerPosition = 0;
meshResultLayer = MeshResultLayer.Lower;

if (bottom)
item.RemoveRange(4, 7);
LayerPosition = 1;
if (item[4].ToString().Contains("Bot"))
LayerPosition = 0;
}

//TODO: resolve below identifiers extractable through the API
int mode = -1;
double timeStep = 0;

MeshVonMises MeshVonMises = new MeshVonMises(System.Convert.ToInt32(item[1].ToString()), item[3].ToString(), 0,
item[2].ToString(), mode, timeStep, meshResultLayer, LayerPosition, MeshResultSmoothingType.None, null, System.Convert.ToDouble(item[10].ToString()), 0, 0
item[2].ToString(), mode, timeStep, request.Layer, LayerPosition, MeshResultSmoothingType.None, null, System.Convert.ToDouble(item[10].ToString()), 0, 0
);

return MeshVonMises;
Expand Down
5 changes: 3 additions & 2 deletions MidasCivil_Adapter/MidasCivil_Adapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,10 @@
<Compile Include="PrivateHelpers\AssignBarRelease.cs" />
<Compile Include="PrivateHelpers\CombineLoads.cs" />
<Compile Include="PrivateHelpers\CreateAssignmentString.cs" />
<Compile Include="PrivateHelpers\FilterMeshLayer.cs" />
<Compile Include="PrivateHelpers\GetAssignmentIds.cs" />
<Compile Include="PrivateHelpers\AppendCaseTypes.cs" />
<Compile Include="PrivateHelpers\GetBarDivisions.cs" />
<Compile Include="PrivateHelpers\SetBarDivisions.cs" />
<Compile Include="PrivateHelpers\GetGroupAssignments.cs" />
<Compile Include="PrivateHelpers\GetMaxID.cs" />
<Compile Include="PrivateHelpers\CreateGroups.cs" />
Expand All @@ -302,7 +303,7 @@
<Compile Include="CRUD\Delete\Delete.cs" />
<Compile Include="PrivateHelpers\GetSectionMaterialCombinations.cs" />
<Compile Include="PrivateHelpers\GetStiffnessVectorModulus.cs" />
<Compile Include="PrivateHelpers\ReadResultAPI.cs" />
<Compile Include="PrivateHelpers\ReadResult.cs" />
<Compile Include="PrivateHelpers\SetVersion.cs" />
<Compile Include="PrivateHelpers\SetUnits.cs" />
<Compile Include="Type\NextFreeId.cs" />
Expand Down
97 changes: 97 additions & 0 deletions MidasCivil_Adapter/PrivateHelpers/FilterMeshLayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2025, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.Engine.Base;
using BH.oM.Data.Requests;
using BH.oM.Structure.Elements;
using BH.oM.Structure.Requests;
using BH.oM.Structure.Results;
using System;
using System.Collections.Generic;

namespace BH.Adapter.MidasCivil
{
public partial class MidasCivilAdapter
{
private List<List<object>> FilterMeshLayer(MeshResultRequest request, List<object> resultItems)
{
List<List<object>> filteredResult = new List<List<object>>();

List<object> upperResult = resultItems.GetRange(0,11);
List<object> lowerResult = resultItems.ShallowClone();
lowerResult.RemoveRange(4, 7);

switch (request.Layer)
{
case MeshResultLayer.Upper:
filteredResult.Add(upperResult);
break;
case MeshResultLayer.Lower:
filteredResult.Add(lowerResult);
break;
case MeshResultLayer.Middle:
Compute.RecordWarning("Mesh results for the middle layer can not be pulled from Midas Civil. Results for both the top and bottom layer will be returned.");
filteredResult.Add(upperResult);
filteredResult.Add(lowerResult);
break;
case MeshResultLayer.Maximum:
List<object> maxValues = resultItems.GetRange(0, 4);
maxValues.Add(null);
for (int i = 5; i < 11; i++)
maxValues.Add(Math.Max(System.Convert.ToDouble(upperResult[i].ToString()), System.Convert.ToDouble(lowerResult[i].ToString())));
filteredResult.Add(maxValues);
break;
case MeshResultLayer.Minimum:
List<object> minValues = resultItems.GetRange(0, 4);
minValues.Add(null);
for (int i = 5; i < 11; i++)
minValues.Add(Math.Min(System.Convert.ToDouble(upperResult[i].ToString()), System.Convert.ToDouble(lowerResult[i].ToString())));
filteredResult.Add(minValues);
break;
case MeshResultLayer.AbsoluteMaximum:
List<object> absMaxValues = resultItems.GetRange(0, 4);
absMaxValues.Add(null);
for (int i = 5; i < 11; i++)
absMaxValues.Add(Math.Max(Math.Abs(System.Convert.ToDouble(upperResult[i].ToString())), Math.Abs(System.Convert.ToDouble(lowerResult[i].ToString()))));
filteredResult.Add(absMaxValues);
break;
case MeshResultLayer.Arbitrary:
switch (request.LayerPosition)
{
case 0:
filteredResult.Add(lowerResult);
break;
case 1:
filteredResult.Add(upperResult);
break;
default:
Compute.RecordWarning("Mesh results can only be pulled for the top (1) or bottom (0) layer in Midas Civil. Results for both the top and bottom layers will be returned.");
filteredResult.Add(upperResult);
filteredResult.Add(lowerResult);
break;
}
break;
}
return filteredResult;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
using BH.oM.Data.Requests;
using BH.Engine.Serialiser;
using BH.Engine.Base;
using BH.oM.Structure.Requests;


namespace BH.Adapter.MidasCivil
{
public partial class MidasCivilAdapter
{
private async Task<IEnumerable<IResult>> ReadResult(string resultType, List<int> ids, List<string> loadcaseIds, string locations="")
private async Task<IEnumerable<IResult>> ReadResult(string resultType, List<int> ids, List<string> loadcaseIds, string locations="", MeshResultRequest meshRequest=null)
{
List<IResult> results = new List<IResult>();

Expand Down Expand Up @@ -126,11 +127,15 @@ private async Task<IEnumerable<IResult>> ReadResult(string resultType, List<int>
switch (resultType)
{
case "NodeReaction":
if (m_midasCivilVersion=="9.5.0.nx")
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("Reaction(Global)")?.PropertyValue("DATA");
else
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("ReactionGlobal")?.PropertyValue("DATA");

switch (m_midasCivilVersion)
{
case "9.5.0.nx":
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("Reaction(Global)")?.PropertyValue("DATA");
break;
default:
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("ReactionGlobal")?.PropertyValue("DATA");
break;
}
resultItems = data as List<List<object>>;
if (resultItems.IsNullOrEmpty())
Engine.Base.Compute.RecordError($"No NodeReaction could be found for the selected Node/Nodes.");
Expand All @@ -139,70 +144,79 @@ private async Task<IEnumerable<IResult>> ReadResult(string resultType, List<int>
results.Add(Adapters.MidasCivil.Convert.ToNodeReaction(item));
break;
case "NodeDisplacement":
if (m_midasCivilVersion == "9.5.0.nx")
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("Displacements(Global)")?.PropertyValue("DATA");
else
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("DisplacementsGlobal")?.PropertyValue("DATA");

switch (m_midasCivilVersion)
{
case "9.5.0.nx":
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("Displacements(Global)")?.PropertyValue("DATA");
break;
default:
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("DisplacementsGlobal")?.PropertyValue("DATA");
break;
}
resultItems = data as List<List<object>>;
foreach (List<object> item in resultItems)
results.Add(Adapters.MidasCivil.Convert.ToNodeDisplacement(item));

break;
case "BarForce":
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("BeamForce")?.PropertyValue("DATA");

resultItems = data as List<List<object>>;
foreach (List<object> item in resultItems)
results.Add(Convert.ToBarForce(item));

break;
case "BarStress":
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("BeamStress")?.PropertyValue("DATA");

resultItems = data as List<List<object>>;
foreach (List<object> item in resultItems)
results.Add(Convert.ToBarStress(item));

break;
case "Forces":
if (m_midasCivilVersion == "9.5.0.nx")
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateForce(UnitLength:Local)")?.PropertyValue("DATA");
else
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateForceUnitLengthLocal")?.PropertyValue("DATA");

switch (m_midasCivilVersion)
{
case "9.5.0.nx":
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateForce(UnitLength:Local)")?.PropertyValue("DATA");
break;
default:
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateForceUnitLengthLocal")?.PropertyValue("DATA");
break;
}
resultItems = data as List<List<object>>;
foreach (List<object> item in resultItems)
results.Add(Convert.ToMeshForce(item));

break;
case "Stresses":
if (m_midasCivilVersion == "9.5.0.nx")
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateStress(Local)")?.PropertyValue("DATA");
else
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateStressLocal")?.PropertyValue("DATA");

switch (m_midasCivilVersion)
{
case "9.5.0.nx":
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateStress(Local)")?.PropertyValue("DATA");
break;
default:
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateStressLocal")?.PropertyValue("DATA");
break;
}
resultItems = data as List<List<object>>;
foreach (List<object> item in resultItems)
{
results.Add(Convert.ToMeshStressAPI(item, false));
if (item.Count > 11)
results.Add(Convert.ToMeshStressAPI(item, true));
List<List<object>> meshStresses = FilterMeshLayer(meshRequest, item);
foreach (List<object> meshStress in meshStresses)
results.Add(Convert.ToMeshStress(meshStress, meshRequest));
}

break;
case "VonMises":
if (m_midasCivilVersion == "9.5.0.nx")
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateStress(Local)")?.PropertyValue("DATA");
else
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateStressLocal")?.PropertyValue("DATA");

switch (m_midasCivilVersion)
{
case "9.5.0.nx":
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateStress(Local)")?.PropertyValue("DATA");
break;
default:
data = parsedJson.PropertyValue("CustomData")?.PropertyValue("PlateStressLocal")?.PropertyValue("DATA");
break;
}
resultItems = data as List<List<object>>;
foreach (List<object> item in resultItems)
{
results.Add(Convert.ToMeshVonMisesAPI(item, false));
if (item.Count > 11)
results.Add(Convert.ToMeshVonMisesAPI(item, true));
List<List<object>> meshVonMises = FilterMeshLayer(meshRequest, item);
foreach (List<object> meshStress in meshVonMises)
results.Add(Convert.ToMeshVonMises(meshStress, meshRequest));
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace BH.Adapter.MidasCivil
{
public partial class MidasCivilAdapter
{
private string GetBarDivisions(BarResultRequest request)
private string SetBarDivisions(BarResultRequest request)
{
string divisions = String.Empty;
if (request.DivisionType == DivisionType.ExtremeValues)
Expand Down