2222
2323using BH . oM . Adapters . MidasCivil ;
2424using BH . Engine . Adapter ;
25+ using BH . oM . Structure . Elements ;
2526using BH . oM . Structure . Loads ;
2627using BH . oM . Geometry ;
2728using System . IO ;
2829using System . Collections . Generic ;
2930using System . Linq ;
31+ using BH . Engine . Base ;
32+ using BH . Engine . Spatial ;
33+ using BH . Engine . Geometry ;
34+ using BH . Adapter . Adapters . MidasCivil ;
35+ using System . Data ;
3036
3137namespace BH . Adapter . MidasCivil
3238{
@@ -42,67 +48,90 @@ private bool CreateCollection(IEnumerable<BarVaryingDistributedLoad> barVaryingD
4248
4349 foreach ( BarVaryingDistributedLoad barVaryingDistributedLoad in barVaryingDistributedLoads )
4450 {
45- if ( ! barVaryingDistributedLoad . RelativePositions )
51+ BarVaryingDistributedLoad load = barVaryingDistributedLoad . ShallowClone ( ) ;
52+
53+ if ( load . StartPosition >= load . EndPosition )
4654 {
47- Engine . Base . Compute . RecordError ( "The midas adapter can only handle BarVaryingDistributedLoads with relative positions. Please update the loads to be set with this format ." ) ;
55+ Engine . Base . Compute . RecordError ( "MidasCivil only supports start positions less than end positions for BarVaryingDistributedLoads ." ) ;
4856 continue ;
4957 }
5058
51- if ( barVaryingDistributedLoad . StartPosition >= barVaryingDistributedLoad . EndPosition )
59+ List < double > startPosition = new List < double > ( ) ;
60+ List < double > endPosition = new List < double > ( ) ;
61+
62+
63+ foreach ( Bar bar in load . Objects . Elements )
5264 {
53- Engine . Base . Compute . RecordError ( "Midas civil only supports start positions less than end positions for BarVaryingDistributedLoads." ) ;
54- continue ;
65+ if ( load . RelativePositions == false )
66+ {
67+ double length = bar . Length ( ) ;
68+
69+ startPosition . Add ( barVaryingDistributedLoad . StartPosition / length ) ;
70+ endPosition . Add ( barVaryingDistributedLoad . EndPosition / length ) ;
71+
72+ if ( load . StartPosition / length > 1 || load . EndPosition / length > 1 )
73+ Engine . Base . Compute . RecordError ( "The load start or end position is outside one or more bars" ) ;
74+ }
75+ else
76+ {
77+ startPosition . Add ( barVaryingDistributedLoad . StartPosition ) ;
78+ endPosition . Add ( barVaryingDistributedLoad . EndPosition ) ;
79+ }
5580 }
5681
82+
5783 List < string > midasBarLoads = new List < string > ( ) ;
58- string barLoadPath = CreateSectionFile ( barVaryingDistributedLoad . Loadcase . Name + "\\ BEAMLOAD" ) ;
59- string midasLoadGroup = Adapters . MidasCivil . Convert . FromLoadGroup ( barVaryingDistributedLoad ) ;
84+ string barLoadPath = CreateSectionFile ( load . Loadcase . Name + "\\ BEAMLOAD" ) ;
85+ string midasLoadGroup = Adapters . MidasCivil . Convert . FromLoadGroup ( load ) ;
86+
87+ List < string > assignedBars = load . Objects . Elements . Select ( x => x . AdapterId < string > ( typeof ( MidasCivilId ) ) ) . ToList ( ) ;
6088
61- List < string > assignedBars = barVaryingDistributedLoad . Objects . Elements . Select ( x => x . AdapterId < string > ( typeof ( MidasCivilId ) ) ) . ToList ( ) ;
6289
63- List < double > startLoadVectors = new List < double > { barVaryingDistributedLoad . ForceAtStart . X ,
64- barVaryingDistributedLoad . ForceAtStart . Y ,
65- barVaryingDistributedLoad . ForceAtStart . Z ,
66- barVaryingDistributedLoad . MomentAtStart . X ,
67- barVaryingDistributedLoad . MomentAtStart . Y ,
68- barVaryingDistributedLoad . MomentAtStart . Z } ;
90+ List < double > startLoadVectors = new List < double > { load . ForceAtStart . X ,
91+ load . ForceAtStart . Y ,
92+ load . ForceAtStart . Z ,
93+ load . MomentAtStart . X ,
94+ load . MomentAtStart . Y ,
95+ load . MomentAtStart . Z } ;
6996
70- List < double > endLoadVectors = new List < double > { barVaryingDistributedLoad . ForceAtEnd . X ,
71- barVaryingDistributedLoad . ForceAtEnd . Y ,
72- barVaryingDistributedLoad . ForceAtEnd . Z ,
73- barVaryingDistributedLoad . MomentAtEnd . X ,
74- barVaryingDistributedLoad . MomentAtEnd . Y ,
75- barVaryingDistributedLoad . MomentAtEnd . Z } ;
97+ List < double > endLoadVectors = new List < double > { load . ForceAtEnd . X ,
98+ load . ForceAtEnd . Y ,
99+ load . ForceAtEnd . Z ,
100+ load . MomentAtEnd . X ,
101+ load . MomentAtEnd . Y ,
102+ load . MomentAtEnd . Z } ;
76103
77104 Vector zeroVector = new Vector { X = 0 , Y = 0 , Z = 0 } ;
78105
79106 for ( int i = 0 ; i < 6 ; i ++ )
80107 {
81- barVaryingDistributedLoad . ForceAtStart = zeroVector ;
82- barVaryingDistributedLoad . MomentAtStart = zeroVector ;
83- barVaryingDistributedLoad . ForceAtEnd = zeroVector ;
84- barVaryingDistributedLoad . MomentAtEnd = zeroVector ;
108+ load . ForceAtStart = zeroVector ;
109+ load . MomentAtStart = zeroVector ;
110+ load . ForceAtEnd = zeroVector ;
111+ load . MomentAtEnd = zeroVector ;
85112
86113 if ( ! ( startLoadVectors [ i ] == 0 && endLoadVectors [ i ] == 0 ) )
87114 {
88115 if ( i < 3 )
89116 {
90- barVaryingDistributedLoad . ForceAtStart = CreateSingleComponentVector ( i , startLoadVectors [ i ] ) ;
91- barVaryingDistributedLoad . ForceAtEnd = CreateSingleComponentVector ( i , endLoadVectors [ i ] ) ;
117+ load . ForceAtStart = CreateSingleComponentVector ( i , startLoadVectors [ i ] ) ;
118+ load . ForceAtEnd = CreateSingleComponentVector ( i , endLoadVectors [ i ] ) ;
92119
93- foreach ( string assignedBar in assignedBars )
120+ for ( int j = 0 ; j < assignedBars . Count ; j ++ )
94121 {
95- midasBarLoads . Add ( Adapters . MidasCivil . Convert . FromBarVaryingDistributedLoad ( barVaryingDistributedLoad , assignedBar , "Force" , m_forceUnit , m_lengthUnit ) ) ;
122+ midasBarLoads . Add ( Adapters . MidasCivil . Convert . FromBarVaryingDistributedLoad ( load ,
123+ assignedBars [ j ] , "Force" , m_forceUnit , m_lengthUnit , startPosition [ j ] , endPosition [ j ] ) ) ;
96124 }
97125 }
98126 else
99127 {
100- barVaryingDistributedLoad . MomentAtStart = CreateSingleComponentVector ( i - 3 , startLoadVectors [ i ] ) ;
101- barVaryingDistributedLoad . MomentAtEnd = CreateSingleComponentVector ( i - 3 , endLoadVectors [ i ] ) ;
128+ load . MomentAtStart = CreateSingleComponentVector ( i - 3 , startLoadVectors [ i ] ) ;
129+ load . MomentAtEnd = CreateSingleComponentVector ( i - 3 , endLoadVectors [ i ] ) ;
102130
103- foreach ( string assignedBar in assignedBars )
131+ for ( int j = 0 ; j < assignedBars . Count ; j ++ )
104132 {
105- midasBarLoads . Add ( Adapters . MidasCivil . Convert . FromBarVaryingDistributedLoad ( barVaryingDistributedLoad , assignedBar , "Moment" , m_forceUnit , m_lengthUnit ) ) ;
133+ midasBarLoads . Add ( Adapters . MidasCivil . Convert . FromBarVaryingDistributedLoad ( load ,
134+ assignedBars [ j ] , "Moment" , m_forceUnit , m_lengthUnit , startPosition [ j ] , endPosition [ j ] ) ) ;
106135 }
107136 }
108137
0 commit comments