Skip to content

Commit

Permalink
Fix correct output types for gravity load and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
IsakNaslundBh authored and Fraser Greenroyd committed Jan 9, 2023
1 parent 00b997c commit f61acf7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public StructuralAdapter()
{typeof(RigidLink), new List<Type> { typeof(LinkConstraint), typeof(Node) } },
{typeof(FEMesh), new List<Type> { typeof(Node), typeof(ISurfaceProperty)} },
{ typeof(IElementLoad<Bar>), new List<Type>{ typeof(Bar)} },
{ typeof(IElementLoad<Node>), new List<Type>{ typeof(Node)} }
{ typeof(IElementLoad<Node>), new List<Type>{ typeof(Node)} },
{ typeof(GravityLoad), new List<Type>{ typeof(Bar), typeof(Panel), typeof(FEMesh)} }
};

AdapterIdFragmentType = typeof(StructuralAdapterId);
Expand Down
36 changes: 36 additions & 0 deletions .ci/code/BHoM_Adapter_Tests/PushTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,41 @@ public void DependencyOrder_CreateLoadHalfObjectsWithIds()

Assert.AreEqual(withoutIdCount, barCreationCount, "Wrong number of bars created.");
}

[Test]
public void DependencyOrder_CreateGravityLoadHalfObjectsWithIds()
{
int objectCount = 10;
List<Bar> bars = Create.RandomObjects<Bar>(objectCount);
List<Panel> panels = Create.RandomObjects<Panel>(objectCount);
int withIdCount = objectCount / 2;
int withoutIdCount = objectCount - withIdCount;
for (int i = 0; i < withIdCount; i++)
{
Engine.Adapter.Modify.SetAdapterId(bars[i], new StructuralAdapterId { Id = i + 1 });
Engine.Adapter.Modify.SetAdapterId(panels[i], new StructuralAdapterId { Id = i + 1 });
}

//Shuffle the order fo the bars.
//Doing this to test that the order of bars with and without Id does not matter
Random random = new Random(2);
bars = bars.OrderBy(x => random.Next()).ToList();
panels = panels.OrderBy(x => random.Next()).ToList();

GravityLoad load = Create.RandomObject<GravityLoad>();
load.Objects.Elements = bars.Cast<BHoMObject>().Concat(panels).ToList();

sa.Push(new List<object> { load });

Assert.IsTrue(sa.Created.Any(x => x.Item1 == typeof(Bar)), "No bars created.");
int barCreationCount = sa.Created.First(x => x.Item1 == typeof(Bar)).Item2.Count();

Assert.AreEqual(withoutIdCount, barCreationCount, "Wrong number of bars created.");

Assert.IsTrue(sa.Created.Any(x => x.Item1 == typeof(Panel)), "No Panels created.");
int panelsCreationCount = sa.Created.First(x => x.Item1 == typeof(Panel)).Item2.Count();

Assert.AreEqual(withoutIdCount, panelsCreationCount, "Wrong number of Panels created.");
}
}
}
3 changes: 2 additions & 1 deletion Structure_AdapterModules/ModuleLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public static void LoadModules(this BHoMAdapter adapter)
adapter.AdapterModules.Add(new GetLoadElementsWithoutID<Node>(adapter));
adapter.AdapterModules.Add(new GetLoadElementsWithoutID<IAreaElement>(adapter));
adapter.AdapterModules.Add(new GetGravityLoadElementsWithoutID<Bar>(adapter));
adapter.AdapterModules.Add(new GetGravityLoadElementsWithoutID<IAreaElement>(adapter));
adapter.AdapterModules.Add(new GetGravityLoadElementsWithoutID<Panel>(adapter));
adapter.AdapterModules.Add(new GetGravityLoadElementsWithoutID<FEMesh>(adapter));
}
}
}
Expand Down

0 comments on commit f61acf7

Please sign in to comment.