Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MidasCivil 2023 v1.1 and bug fixes #352

Merged
2 changes: 1 addition & 1 deletion MidasCivil_Adapter/CRUD/Create/Elements/RigidLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private bool CreateCollection(IEnumerable<RigidLink> links)
{
string midasBoundaryGroup = Adapters.MidasCivil.Convert.FromTag(link.Name);
CompareGroup(midasBoundaryGroup, boundaryGroupPath);
midasRigidLinks.Add(Adapters.MidasCivil.Convert.FromRigidLink(link));
midasRigidLinks.Add(Adapters.MidasCivil.Convert.FromRigidLink(link, m_midasCivilVersion));
}

File.AppendAllLines(path, midasRigidLinks);
Expand Down
2 changes: 1 addition & 1 deletion MidasCivil_Adapter/CRUD/Read/Elements/RigidLinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private List<RigidLink> ReadRigidLinks(List<string> ids = null)

foreach (string link in linkText)
{
RigidLink bhomRigidLink = Adapters.MidasCivil.Convert.ToRigidLink(link, nodeDictionary, count);
RigidLink bhomRigidLink = Adapters.MidasCivil.Convert.ToRigidLink(link, nodeDictionary, count, m_midasCivilVersion);
bhomRigidLinks.Add(bhomRigidLink);

if (string.IsNullOrWhiteSpace(link.Split(',')[3].Trim()))
Expand Down
54 changes: 39 additions & 15 deletions MidasCivil_Adapter/Convert/ToBHoM/Elements/ToRigidLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace BH.Adapter.Adapters.MidasCivil
{
public static partial class Convert
{
public static RigidLink ToRigidLink(string rigidLink, Dictionary<string, Node> nodes, int count)
public static RigidLink ToRigidLink(string rigidLink, Dictionary<string, Node> nodes, int count, string version)
{
/***************************************************/
/**** Public Methods ****/
Expand All @@ -41,9 +41,44 @@ public static RigidLink ToRigidLink(string rigidLink, Dictionary<string, Node> n
string[] delimitted = rigidLink.Split(',');
List<Node> secondaryNodes = new List<Node>();

string primaryId = delimitted[1].Trim();
string fixity = delimitted[2].Replace(" ", "");
List<string> secondaryIds = delimitted[3].Split(' ').Where(m => !string.IsNullOrWhiteSpace(m)).ToList();
string primaryId = "";
string fixity = "";
List<string> secondaryIds = new List<string>();

string name = "";

switch (version)
{
case "9.0.5":
case "9.1.0":
case "9.4.0":
primaryId = delimitted[0].Trim();
fixity = delimitted[1].Replace(" ", "");
secondaryIds = delimitted[2].Split(' ').Where(m => !string.IsNullOrWhiteSpace(m)).ToList();
if (string.IsNullOrWhiteSpace(delimitted[3]))
{
name = "RL" + count;
}
else
{
name = delimitted[3].Trim();
}
break;
default:
primaryId = delimitted[1].Trim();
fixity = delimitted[2].Replace(" ", "");
secondaryIds = delimitted[3].Split(' ').Where(m => !string.IsNullOrWhiteSpace(m)).ToList();
if (string.IsNullOrWhiteSpace(delimitted[4]))
{
name = "RL" + count;
}
else
{
name = delimitted[4].Trim();
}
break;
}

List<int> assignments = MidasCivilAdapter.GetAssignmentIds(secondaryIds);

bool x = FromFixity(fixity.Substring(0, 1));
Expand All @@ -65,17 +100,6 @@ public static RigidLink ToRigidLink(string rigidLink, Dictionary<string, Node> n
secondaryNodes.Add(secondaryNode);
}

string name = "";

if (string.IsNullOrWhiteSpace(delimitted[4]))
{
name = "RL" + count;
}
else
{
name = delimitted[4].Trim();
}

RigidLink bhomRigidLink = new RigidLink { PrimaryNode = primaryNode, SecondaryNodes = secondaryNodes, Constraint = constraint };
bhomRigidLink.Name = name;
bhomRigidLink.SetAdapterId(typeof(MidasCivilId), name);
Expand Down
4 changes: 2 additions & 2 deletions MidasCivil_Adapter/Convert/ToBHoM/Properties/ToBarRelease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static BarRelease ToBarRelease(string release, int count)

for (int i = 0; i < 6; i++)
{
bhomStartFixity.Add(FromFixity(startFixity.Substring(i, 1)));
bhomEndFixity.Add(FromFixity(endFixity.Substring(i, 1)));
bhomStartFixity.Add(FromFixity(startFixity.Substring(i, 1),true));
bhomEndFixity.Add(FromFixity(endFixity.Substring(i, 1), true));
}

Constraint6DOF startConstraint = Engine.Structure.Create.Constraint6DOF(bhomStartFixity[0], bhomStartFixity[1], bhomStartFixity[2],
Expand Down
48 changes: 20 additions & 28 deletions MidasCivil_Adapter/Convert/ToBHoM/Properties/ToConstraint6DOF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,29 @@ public static Constraint6DOF ToConstraint6DOF(this string support, string versio
{
switch (version)
{
case "9.1.0":
case "9.0.5":
case "9.0.0":
case "8.9.5":
case "8.9.0":
case "8.8.5":
case "8.6.5":
case "8.7.0":
case "8.7.5":
case "8.8.1":
for (int i = 2; i < 8; i++)
{
if (delimitted[i].Trim() == "YES")
if (delimitted[i] == "")
{
fixity.Add(true);
fixity.Add(false);
stiffness.Add(0);
}
else if (delimitted[i].Trim() == "NO")
else
{
double spring;
if (i < 5)
{
spring = double.Parse(delimitted[i + 6]).ForcePerLengthToSI(forceUnit, lengthUnit);
spring = double.Parse(delimitted[i]).ForcePerLengthToSI(forceUnit, lengthUnit);
}
else
{
spring = double.Parse(delimitted[i + 6]).MomentToSI(forceUnit, lengthUnit);
spring = double.Parse(delimitted[i]).MomentToSI(forceUnit, lengthUnit);
}
if (spring > 1E+017.ForcePerLengthToSI(forceUnit, lengthUnit) || spring > 1E+19.MomentToSI(forceUnit, lengthUnit))
if (spring > 1E+017.ForcePerLengthFromSI(forceUnit, lengthUnit) || spring > 1E+19.MomentFromSI(forceUnit, lengthUnit))
{
fixity.Add(true);
stiffness.Add(0);
Expand All @@ -109,35 +107,32 @@ public static Constraint6DOF ToConstraint6DOF(this string support, string versio
}
}
}
supportName = delimitted[21].Trim();
supportName = delimitted[15].Trim();
if (supportName == "")
{
supportName = "Fx=" + delimitted[8] + "Fy=" + delimitted[9] + "Fz=" + delimitted[10] + "Rx=" + delimitted[11] + "Ry=" + delimitted[12] + "Rz=" + delimitted[13];
supportName = "Fx=" + delimitted[2] + "Fy=" + delimitted[3] + "Fz=" + delimitted[4] + "Rx=" + delimitted[5] + "Ry=" + delimitted[6] + "Rz=" + delimitted[7];
}


break;

default:
for (int i = 2; i < 8; i++)
{
if (delimitted[i] == "")
if (delimitted[i].Trim() == "YES")
{
fixity.Add(false);
fixity.Add(true);
stiffness.Add(0);
}
else
else if (delimitted[i].Trim() == "NO")
{
double spring;
if (i < 5)
{
spring = double.Parse(delimitted[i]).ForcePerLengthToSI(forceUnit, lengthUnit);
spring = double.Parse(delimitted[i + 6]).ForcePerLengthToSI(forceUnit, lengthUnit);
}
else
{
spring = double.Parse(delimitted[i]).MomentToSI(forceUnit, lengthUnit);
spring = double.Parse(delimitted[i + 6]).MomentToSI(forceUnit, lengthUnit);
}
if (spring > 1E+017.ForcePerLengthFromSI(forceUnit, lengthUnit) || spring > 1E+19.MomentFromSI(forceUnit, lengthUnit))
if (spring > 1E+017.ForcePerLengthToSI(forceUnit, lengthUnit) || spring > 1E+19.MomentToSI(forceUnit, lengthUnit))
{
fixity.Add(true);
stiffness.Add(0);
Expand All @@ -149,16 +144,13 @@ public static Constraint6DOF ToConstraint6DOF(this string support, string versio
}
}
}
supportName = delimitted[15].Trim();
supportName = delimitted[21].Trim();
if (supportName == "")
{
supportName = "Fx=" + delimitted[2] + "Fy=" + delimitted[3] + "Fz=" + delimitted[4] + "Rx=" + delimitted[5] + "Ry=" + delimitted[6] + "Rz=" + delimitted[7];
supportName = "Fx=" + delimitted[8] + "Fy=" + delimitted[9] + "Fz=" + delimitted[10] + "Rx=" + delimitted[11] + "Ry=" + delimitted[12] + "Rz=" + delimitted[13];
}
break;
}



}
}

Expand Down
23 changes: 11 additions & 12 deletions MidasCivil_Adapter/Convert/ToBHoM/Properties/ToSurfaceProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,28 @@ public static ISurfaceProperty ToSurfaceProperty(this string surfaceProperty, st

switch (version)
{
case "9.1.0":
case "9.0.5":
case "9.0.0":
case "8.9.5":
case "8.9.0":
case "8.8.5":
constantThickness = new ConstantThickness
{
Thickness = System.Convert.ToDouble(split[4].Trim()).LengthToSI(lengthUnit),
Name = "t = " + split[4].Trim()
Name = split[1]
};
break;
case "8.8.5":
constantThickness =new ConstantThickness
case "8.8.1":
case "8.7.5":
case "8.7.0":
case "8.6.5":
constantThickness = new ConstantThickness
{
Thickness = System.Convert.ToDouble(split[4].Trim()).LengthToSI(lengthUnit),
Name = split[1]
Thickness = System.Convert.ToDouble(split[3].Trim()).LengthToSI(lengthUnit),
Name = "t = " + split[3].Trim()
};
break;
default:
constantThickness = new ConstantThickness
{
Thickness = System.Convert.ToDouble(split[3].Trim()).LengthToSI(lengthUnit),
Name = "t = " + split[3].Trim()
Thickness = System.Convert.ToDouble(split[4].Trim()).LengthToSI(lengthUnit),
Name = "t = " + split[4].Trim()
};
break;
}
Expand Down
14 changes: 12 additions & 2 deletions MidasCivil_Adapter/Convert/ToMidasCivil/Elements/FromRigidLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static partial class Convert
/**** Public Methods ****/
/***************************************************/

public static string FromRigidLink(this RigidLink link)
public static string FromRigidLink(this RigidLink link, string version)
{
string midasLink = "";

Expand All @@ -51,7 +51,17 @@ public static string FromRigidLink(this RigidLink link)
BoolToFixity(link.Constraint.YYtoYY) +
BoolToFixity(link.Constraint.ZZtoZZ);

midasLink = "1, " + primaryId + "," + fixity + "," + secondaryId + "," + link.Name;
switch (version)
{
case "9.0.5":
case "9.1.0":
case "9.4.0":
midasLink = primaryId + "," + fixity + "," + secondaryId + "," + link.Name;
break;
default:
midasLink = "1, " + primaryId + "," + fixity + "," + secondaryId + "," + link.Name;
break;
}

return midasLink;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static partial class Convert
public static string FromAreaDifferentialTemperatureLoad(this AreaDifferentialTemperatureLoad temperatureProfile, string assignedFEMesh, string temperatureUnit)
{
string midasFEMeshLoad = null;
double temperatureDifference = temperatureProfile.TemperatureProfile[0].DeltaTemperatureToSI(temperatureUnit) - temperatureProfile.TemperatureProfile[1].DeltaTemperatureToSI(temperatureUnit);
double temperatureDifference = temperatureProfile.TemperatureProfile[0].DeltaTemperatureFromSI(temperatureUnit) - temperatureProfile.TemperatureProfile[1].DeltaTemperatureFromSI(temperatureUnit);
midasFEMeshLoad = assignedFEMesh + ",2," + temperatureDifference + "," + "YES,0," + temperatureProfile.Name;
return midasFEMeshLoad;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static string FromAreaUniformlyDistributedLoad(this AreaUniformlyDistribu

switch (version)
{
case "9.4.0":
case "9.1.0":
midasFEMeshLoad = assignedFEMesh + ", PRES, PLATE, FACE, " + FromLoadAxis(femeshLoad.Axis) + direction +
", 0, 0, 0, " + FromLoadProjection(femeshLoad.Projected) + ", " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,13 @@ public static List<string> FromLoadCombination(this LoadCombination loadCombinat

switch (version)
{
case "9.1.0":
case "9.0.5":
case "9.0.0":
case "8.9.5":
case "8.9.0":
case "8.8.5":
line1 = "NAME=" + loadCombination.Name + ", GEN, ACTIVE, 0, 0, , 0, 0, 0";
case "8.8.1":
case "8.7.5":
case "8.6.5":
line1 = "NAME=" + loadCombination.Name + ", GEN, ACTIVE, 0, 0, , 0, 0";
break;
default:
line1 = "NAME=" + loadCombination.Name + ", GEN, ACTIVE, 0, 0, , 0, 0";
line1 = "NAME=" + loadCombination.Name + ", GEN, ACTIVE, 0, 0, , 0, 0, 0";
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public static string FromPointLoad(this PointLoad pointLoad, string assignedNode
{
string midasPointLoad = "";

switch(version)
switch (version)
{
case "9.4.0":
case "9.1.0":
midasPointLoad = assignedNode + "," + pointLoad.Force.X.ForceFromSI(forceUnit).ToString() +
"," + pointLoad.Force.Y.ForceFromSI(forceUnit).ToString() +
Expand Down
19 changes: 15 additions & 4 deletions MidasCivil_Adapter/Convert/ToMidasCivil/Properties/FromFixity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,26 @@ public static partial class Convert
/**** Public Methods ****/
/***************************************************/

internal static bool FromFixity(string number)
internal static bool FromFixity(string number, bool release = false)
{
bool fixity = true;

if (int.Parse(number) == 1)
if(release)
{
fixity = false;
// For bar releases
if (int.Parse(number.Trim()) == 1)
{
fixity = false;
}
}
else
{
// For constraints, rigid links etc.
if (int.Parse(number.Trim()) == 0)
{
fixity = false;
}
}

return fixity;
}

Expand Down
Loading