@@ -222,6 +222,30 @@ def add_block(self, block, node=None, attr_dict=None, **kwattr):
222222 self ._blocks [block .guid ] = node
223223 return node
224224
225+ def add_block_from_mesh (self , mesh , node = None , attr_dict = None , ** kwattr ):
226+ """Add a block to the assembly from a normal mesh.
227+
228+ Parameters
229+ ----------
230+ mesh : :class:`compas.datastructures.Mesh`
231+ The mesh to add.
232+ node : hashable, optional
233+ The identifier of the corresponding node in the connectivity graph.
234+ If no value is provided, the identifier will be generated automatically by the graph.
235+ attr_dict : dict, optional
236+ A dictionary of block attributes.
237+ **kwatr : dict, optional
238+ Additional attributes in the form of named function parameters.
239+
240+ Returns
241+ -------
242+ hashable
243+ The identifier of the node in the graph corresponding to the block.
244+
245+ """
246+ block = mesh .copy (cls = Block )
247+ return self .add_block (block , node = node , attr_dict = attr_dict , ** kwattr )
248+
225249 def add_block_block_interfaces (self , a , b , interfaces ):
226250 """Add an interface between two blocks.
227251
@@ -297,6 +321,16 @@ def has_interface(self, interface):
297321 # accessors
298322 # ==========================================================================
299323
324+ def number_of_nodes (self ):
325+ """Return the number of nodes in the assembly graph.
326+
327+ Returns
328+ -------
329+ int
330+
331+ """
332+ return len (list (self .graph .nodes ()))
333+
300334 def nodes (self ):
301335 """Iterate over the nodes of the graph of the assembly.
302336
@@ -307,6 +341,16 @@ def nodes(self):
307341 """
308342 return self .graph .nodes ()
309343
344+ def number_of_edges (self ):
345+ """Return the number of edges in the assembly graph.
346+
347+ Returns
348+ -------
349+ int
350+
351+ """
352+ return len (list (self .graph .edges ()))
353+
310354 def edges (self ):
311355 """Iterate over the edges of the graph of the assembly.
312356
@@ -317,6 +361,16 @@ def edges(self):
317361 """
318362 return self .graph .edges ()
319363
364+ def number_of_blocks (self ):
365+ """Return the number of blocks in the assembly.
366+
367+ Returns
368+ -------
369+ int
370+
371+ """
372+ return self .number_of_nodes ()
373+
320374 def blocks (self ):
321375 """Iterate over the blocks of the assembly.
322376
@@ -328,6 +382,16 @@ def blocks(self):
328382 for node in self .graph .nodes ():
329383 yield self .node_block (node )
330384
385+ def number_of_interfaces (self ):
386+ """Return the number of interfaces in the assembly.
387+
388+ Returns
389+ -------
390+ int
391+
392+ """
393+ return self .number_of_edges ()
394+
331395 def interfaces (self ):
332396 """Yield the interfaces of the assembly.
333397
@@ -411,7 +475,7 @@ def node_point(self, node):
411475 Parameters
412476 ----------
413477 node : hashable
414- the identifier of the node.
478+ The identifier of the node.
415479
416480 Returns
417481 -------
@@ -439,6 +503,52 @@ def edge_line(self, edge):
439503 b = self .node_point (v )
440504 return Line (a , b )
441505
506+ # ==========================================================================
507+ # boundary conditions
508+ # ==========================================================================
509+
510+ def unset_boundary_conditions (self ):
511+ """Unset all boundary conditions.
512+
513+ Returns
514+ -------
515+ None
516+
517+ """
518+ for node in self .graph .nodes ():
519+ self .graph .unset_node_attribute (node , "is_support" )
520+
521+ def set_boundary_condition (self , node ):
522+ """Set the boundary condition for a single node.
523+
524+ Parameters
525+ ----------
526+ node : hashable
527+ The identifier of the node.
528+
529+ Returns
530+ -------
531+ None
532+
533+ """
534+ self .graph .node_attribute (node , "is_support" , True )
535+
536+ def set_boundary_conditions (self , nodes ):
537+ """Set the boundary condition for multiple nodes.
538+
539+ Parameters
540+ ----------
541+ nodes : list[hashable]
542+ The identifiers of the node.
543+
544+ Returns
545+ -------
546+ None
547+
548+ """
549+ for node in nodes :
550+ self .graph .node_attribute (node , "is_support" , True )
551+
442552 # ==========================================================================
443553 # methods
444554 # ==========================================================================
0 commit comments