2020 * along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
2121 */
2222
23+ using BH . Engine . Base ;
24+ using BH . Engine . Environment ;
25+ using BH . Engine . Geometry ;
2326using BH . oM . Base . Attributes ;
27+ using BH . oM . Environment . Elements ;
28+ using BH . oM . Geometry ;
2429using BH . oM . LadybugTools ;
2530using System . Collections . Generic ;
2631using System . ComponentModel ;
2732using System . Linq ;
33+ using System . Security . Cryptography ;
2834
2935namespace BH . Engine . LadybugTools
3036{
@@ -117,6 +123,147 @@ public static Typology Typology(
117123 RadiantTemperatureAdjustment = radiantTemperatureAdjustment
118124 } ;
119125 }
120- }
121- }
122126
127+ /******************************************************/
128+
129+ [ Description ( "Create a typology from a set of inputs." ) ]
130+ [ Input ( "name" , "The identifier of the typology created." ) ]
131+ [ Input ( "hasSkyShelter" , "Whether the typology has a circular sky shelter." ) ]
132+ [ Input ( "skyShelterRadius" , "The Radius of the circular sky shelter." ) ]
133+ [ Input ( "skyShelterHeight" , "The height the sky shelter is above the ground." ) ]
134+ [ Input ( "hasNorthShelter" , "Whether the typology has a north-facing shelter wall." ) ]
135+ [ Input ( "northShelterHeight" , "The height that the northern shelter wall extends to." ) ]
136+ [ Input ( "hasEastShelter" , "Whether the typology has an east-facing shelter wall." ) ]
137+ [ Input ( "eastShelterHeight" , "The height that the eastern shelter wall extends to." ) ]
138+ [ Input ( "hasSouthShelter" , "Whether the typology has a south-facing shelter wall." ) ]
139+ [ Input ( "southShelterHeight" , "The eight that the southern shelter wall extends to." ) ]
140+ [ Input ( "hasWestShelter" , "Whether the typology has a west-facing shelter wall." ) ]
141+ [ Input ( "westShelterHeight" , "The height that the western shelter wall extends to." ) ]
142+ [ Input ( "shelterWindPorosity" , "The wind porosity of all shelters (must be between 0 and 1 inclusive)." ) ]
143+ [ Input ( "shelterRadiationPorosity" , "The radiation porosity of all shelters (must be between 0 and 1 inclusive)." ) ]
144+ [ Input ( "evaporativeCoolingEffect" , "The effective evaporative cooling that is present in this typology (must be between 0 and 1 inclusive)." ) ]
145+ [ Input ( "radiantTemperatureAdjustment" , "Any radiant temperature adjustment to apply to the resultant typology." ) ]
146+ [ Input ( "targetWindSpeed" , "List of wind speeds to be used in this typology (will replace wind speeds present in the epw when calculating UTCI)." ) ]
147+ [ Output ( "typology" , "The generated typology." ) ]
148+ public static Typology Typology (
149+ string name ,
150+ bool hasSkyShelter = false ,
151+ double skyShelterRadius = 5 ,
152+ double skyShelterHeight = 2.5 ,
153+ bool hasNorthShelter = false ,
154+ double northShelterHeight = 2.5 ,
155+ bool hasEastShelter = false ,
156+ double eastShelterHeight = 2.5 ,
157+ bool hasSouthShelter = false ,
158+ double southShelterHeight = 2.5 ,
159+ bool hasWestShelter = false ,
160+ double westShelterHeight = 2.5 ,
161+ double shelterWindPorosity = 0 ,
162+ double shelterRadiationPorosity = 0 ,
163+ double evaporativeCoolingEffect = 0 ,
164+ double radiantTemperatureAdjustment = 0 ,
165+ double ? targetWindSpeed = null
166+ )
167+ {
168+ if ( hasSkyShelter && skyShelterRadius < 0 )
169+ {
170+ BH . Engine . Base . Compute . RecordError ( "The sky shelter radius must be greater than or equal to 0." ) ;
171+ return null ;
172+ }
173+
174+ if ( hasSkyShelter && skyShelterHeight < 0 )
175+ {
176+ BH . Engine . Base . Compute . RecordError ( "The sky shelter height must be greater than or equal to 0." ) ;
177+ return null ;
178+ }
179+
180+ if ( hasNorthShelter && northShelterHeight < 0 )
181+ {
182+ BH . Engine . Base . Compute . RecordError ( "The north shelter height must be greater than or equal to 0." ) ;
183+ return null ;
184+ }
185+
186+ if ( hasEastShelter && eastShelterHeight < 0 )
187+ {
188+ BH . Engine . Base . Compute . RecordError ( "The east shelter height must be greater than or equal to 0." ) ;
189+ return null ;
190+ }
191+
192+ if ( hasSouthShelter && southShelterHeight < 0 )
193+ {
194+ BH . Engine . Base . Compute . RecordError ( "The south shelter height must be greater than or equal to 0." ) ;
195+ return null ;
196+ }
197+
198+ if ( hasWestShelter && westShelterHeight < 0 )
199+ {
200+ BH . Engine . Base . Compute . RecordError ( "The west shelter height must be greater than or equal to 0." ) ;
201+ return null ;
202+ }
203+
204+ if ( shelterWindPorosity < 0 || shelterWindPorosity > 1 )
205+ {
206+ BH . Engine . Base . Compute . RecordError ( "The shelter wind porosity must be between 0 and 1 inclusive." ) ;
207+ return null ;
208+ }
209+
210+ if ( shelterRadiationPorosity < 0 || shelterRadiationPorosity > 1 )
211+ {
212+ BH . Engine . Base . Compute . RecordError ( "The shelter radiation porosity must be between 0 and 1 inclusive." ) ;
213+ return null ;
214+ }
215+
216+ if ( evaporativeCoolingEffect < 0 || evaporativeCoolingEffect > 1 )
217+ {
218+ BH . Engine . Base . Compute . RecordError ( "The evaporative cooling effect must be between 0 and 1 inclusive." ) ;
219+ return null ;
220+ }
221+
222+ if ( targetWindSpeed != null && targetWindSpeed < 0 )
223+ {
224+ BH . Engine . Base . Compute . RecordError ( "The target wind speed must be greater than or equal to 0, or be null." ) ;
225+ return null ;
226+ }
227+
228+ Polyline perimeter = Geometry . Create . Polyline ( new List < Point > ( ) { Geometry . Create . Point ( x : 1 , y : 1 ) , Geometry . Create . Point ( x : 1 , y : - 1 ) , Geometry . Create . Point ( x : - 1 , y : - 1 ) , Geometry . Create . Point ( x : - 1 , y : 1 ) , Geometry . Create . Point ( x : 1 , y : 1 ) } ) ;
229+ List < Panel > panels = Environment . Compute . ExtrudeToVolume ( perimeter , "temp" , 2 ) . Where ( x => x . Type == PanelType . Wall ) . ToList ( ) ;
230+
231+ List < double > radiationPorosity = Enumerable . Repeat ( shelterRadiationPorosity , 8760 ) . ToList ( ) ;
232+ List < double > windPorosity = Enumerable . Repeat ( shelterWindPorosity , 8760 ) . ToList ( ) ;
233+ List < double > radiantTemperature = Enumerable . Repeat ( radiantTemperatureAdjustment , 8760 ) . ToList ( ) ;
234+ List < double > evaporativeCooling = Enumerable . Repeat ( evaporativeCoolingEffect , 8760 ) . ToList ( ) ;
235+ List < double ? > windSpeed = Enumerable . Repeat ( targetWindSpeed , 8760 ) . ToList ( ) ;
236+ List < Shelter > shelters = new List < Shelter > ( ) ;
237+
238+ if ( hasEastShelter )
239+ shelters . Add ( Convert . ToShelter ( panels [ 0 ] . ChangeHeight ( eastShelterHeight ) , radiationPorosity , windPorosity ) ) ;
240+ if ( hasSouthShelter )
241+ shelters . Add ( Convert . ToShelter ( panels [ 1 ] . ChangeHeight ( southShelterHeight ) , radiationPorosity , windPorosity ) ) ;
242+ if ( hasWestShelter )
243+ shelters . Add ( Convert . ToShelter ( panels [ 2 ] . ChangeHeight ( westShelterHeight ) , radiationPorosity , windPorosity ) ) ;
244+ if ( hasNorthShelter )
245+ shelters . Add ( Convert . ToShelter ( panels [ 3 ] . ChangeHeight ( northShelterHeight ) , radiationPorosity , windPorosity ) ) ;
246+
247+ if ( hasSkyShelter )
248+ {
249+ shelters . Add (
250+ Convert . ToShelter (
251+ new Panel ( ) { ExternalEdges = Geometry . Create . Circle ( Geometry . Create . Point ( x : 0 , y : 0 , z : skyShelterHeight ) , skyShelterRadius ) . CollapseToPolyline ( Tolerance . Angle , 36 ) . ToEdges ( ) } ,
252+ radiationPorosity ,
253+ windPorosity
254+ )
255+ ) ;
256+ }
257+
258+ return Create . Typology ( name , shelters , evaporativeCooling , windSpeed , radiantTemperature ) ;
259+ }
260+
261+ private static Panel ChangeHeight ( this Panel panel , double height )
262+ {
263+ Polyline pLine = panel . Polyline ( ) ;
264+ //Change Z values of control points that have a z value that isn't equal to 0
265+ pLine . ControlPoints = pLine . ControlPoints . Select ( x => Geometry . Create . Point ( x : x . X , y : x . Y , z : x . Z == 0 ? 0 : height ) ) . ToList ( ) ;
266+ return new Panel ( ) { ExternalEdges = pLine . ToEdges ( ) } ;
267+ }
268+ }
269+ }
0 commit comments