compas_model.models
¤
Classes¤
ElementNode
¤
Class representing nodes containing elements in an element tree.
Parameters:
-
element(Element) –The element contained in the node.
Attributes:
-
element(Element) –The element contained in the node.
Notes
This object will raise an Exception, when it is (de)serialised independently, outside the context of a Model.
ElementTree
¤
ElementTree(name: str | None = None)
Class representing the hierarchy of elements in a model through a tree.
Parameters:
-
model(:class:`compas_model.model.Model`) –The parent model of the element tree.
-
name(str, default:None) –The name of the tree.
Attributes:
-
model(:class:`compas_model.model.Model`) –The parent model of the tree.
-
groups(list[:class:`GroupNode`], read-only) –The groups contained in the tree.
-
elements((list[Element], read - only)) –The elements contained in the tree
InteractionGraph
¤
Class representing the interactions between elements in a model.
Parameters:
-
default_node_attributes(dict) –The default attributes for nodes.
-
default_edge_attributes(dict) –The default attributes for edges.
Notes
The main purpose of this class customisation is to modify the data serialisation behaviour of the graph in the context of element interaction modelling in a model.
Model
¤
Class representing a general model of hierarchically organised elements, with interactions.
Attributes:
-
tree((ElementTree, read - only)) –A tree representing the spatial hierarchy of the elements in the model.
-
graph((InteractionGraph, read - only)) –A graph containing the interactions between the elements of the model on its edges.
-
bvh((ElementBVH, read - only)) –To recompute the BVH, use
compute_bvh. The BVH is used to speed up collision detection: for example, during calculation of element contacts. -
kdtree((KDTree, read - only)) –To recompute the tree, use
compute_kdtree. The KD tree is used for nearest neighbour searches: for example, during calculation of element contacts. -
transformation(Transformation) –The transformation from local to world coordinates.
Notes
A model has an element tree to store the hierarchical relationships between elements, and an interaction graph to store the interactions between pairs of elements. Model elements are contained in the tree hierarchy in tree nodes, and in the interaction graph in graph nodes.
Every model element can appear only once in the tree, and only once in the graph. This means that every element can have only one hierarchical parent. At the same time, independently of the hierarchy, every element can have many interactions with other elements.
Functions¤
add_element
¤
add_element(
element: Element | ElementType,
parent: Element | None = None,
material: Material | None = None,
) -> Element | ElementType
Add an element to the model.
Parameters:
-
element(Element) –The element to add.
-
parent(Element, default:None) –The parent element of the element. If
None, the element will be added directly under the root element. -
material(Material, default:None) –A material to assign to the element. Note that the material should have already been added to the model before it can be assigned.
Returns:
-
Element–The element added to the model.
Raises:
-
ValueError–If the parent node is not a GroupNode.
-
ValueError–If a material is provided that is not part of the model.
add_elements
¤
add_elements(
elements: list[Element | ElementType],
parent: Element | None = None,
material: Material | None = None,
) -> list[Element | ElementType]
Add a list of elements to the model.
Parameters:
-
elements(list[Element]) –The elements to add.
-
parent(Element, default:None) –The parent element of the elements. If
None, the elements will be added directly under the root element. -
material(Material, default:None) –A material to assign to the elements. Note that the material should have already been added to the model before it can be assigned.
Returns:
-
list[Element]–The list of elements added to the model.
Raises:
-
ValueError–If the parent node is not a GroupNode.
-
ValueError–If a material is provided that is not part of the model.
add_group
¤
add_group(name: str | None = None) -> Group
Add a group to the model.
Parameters:
-
name(str, default:None) –The name of the group.
Returns:
-
class:`Group`–The group added to the model.
add_interaction
¤
Add an interaction between two elements of the model.
Parameters:
-
a(Element) –The first element.
-
b(Element) –The second element.
Returns:
-
tuple[int, int]–The edge of the interaction graph representing the interaction between the two elements.
Raises:
-
Exception–If one or both of the elements are not in the graph.
Notes
In future implementations, adding an interaction should implicitly take care of adding modifiers onto the interaction edges, based on the registered modifiers of the source nodes.
In the current implementation, modifiers have to be added explicitly using :meth:add_modifiers.
This method will add an interaction edge from the source of the modifier to its target if needed
and store the modifier object on it.
add_modifier
¤
Add a modifier between two elements, with one the source of the modifier and the other the target.
Parameters:
-
source(Element) –The source element.
-
target(Element) –The target element.
-
modifiertype(Type[Modifier]) –The type of modifier.
Returns:
Notes
This element should implement the protocol specified by the modifier. The methods of the source element defined by the protocol are used to compute the tools involved in the modification. The tools are used by the modifier to apply the modification to the model geometry of the target element.
The modifier defines the protocol for the modification. The protocol should be implemented by the source element. The protocol methods of the source element are used to compute the modification tool. The modifier applies the modification to the target using this tool.
add_or_get_material
¤
assign_material
¤
assign_material(
material: Material,
element: Element | None = None,
elements: list[Element] | None = None,
) -> None
Assign a material to an element or a list of elements.
Parameters:
-
material(Material) –The material.
-
element(Element, default:None) –The element to assign the material to.
-
elements(list[Element, optional], default:None) –The list of elements to assign the material to.
Returns:
-
None–
Raises:
-
ValueError–If neither
elementorelementsis provided. -
ValueError–If both
elementandelementsare provided. -
ValueError–If the material is not part of the model.
-
ValueError–If the provided element or one of the elements in the provided element list is not part of the model.
compute_bvh
¤
compute_bvh(
nodetype=ElementAABBNode, max_depth: int | None = None, leafsize: int = 1
) -> ElementBVH
Compute the Bounding Volume Hierarchy (BVH) of the elements for fast collision checks.
Parameters:
-
nodetype(ElementOBBNode, default:ElementAABBNode) –The type of bounding volume node used in the tree.
-
max_depth(int, default:None) –The maximum depth used for constructing the BVH.
-
leafsize(int, default:1) –The number of elements contained in a BVH leaf node.
Returns:
-
ElementBVH–
compute_contacts
¤
compute_contacts(
tolerance=1e-06, minimum_area=0.01, contacttype: Type[Contact] = Contact
) -> None
Compute the contacts between the block elements of this model.
Computing contacts is done independently of the edges of the interaction graph. If contacts are found between two elements with an existing edge, the contacts attribute of the edge will be replaced. If there is no pre-existing edge, one will be added. No element pairs are excluded in the search based on the existence of an edge between their nodes in the interaction graph.
The search is conducted entirely based on the BVH of the elements contained in the model. It is a spatial search that creates topological connections between elements based on their geometrical interaction.
Parameters:
-
tolerance(float, default:1e-06) –The distance tolerance.
-
minimum_area(float, default:0.01) –The minimum contact size.
Returns:
-
None–
compute_kdtree
¤
compute_kdtree() -> KDTree
Compute the KD tree of the elements for fast nearest neighbour queries.
The KD tree is built using the reference points of the elements of the model.
Returns:
-
class:`KDTree`–
element_nnbrs
¤
Find the nearest neighbours to a root element.
Parameters:
-
element(Element) –The root element.
-
k(int, default:1) –The number of nearest neighbours that should be returned.
Returns:
find_all_elements_of_type
¤
find_element_with_name
¤
find_element_with_name(name: str) -> Element | None
Returns True if the model contains an element with the given name.
Parameters:
-
name(str) –The name to check.
Returns:
-
Element or None–
has_element
¤
has_element(element: Element) -> bool
Returns True if the model contains the given element.
Parameters:
-
element(Element) –The element to check.
Returns:
-
bool–
has_element_with_name
¤
has_interaction
¤
has_interaction(a: Element, b: Element) -> bool
Returns True if two elements have an interaction set between them.
Parameters:
-
a(Element) –The first element.
-
b(Element) –The second element.
Returns:
-
bool–
has_material
¤
materials
¤
point_nnbrs
¤
Find the nearest neighbours to a point.
Parameters:
-
point(Point) –The root point.
-
k(int, default:1) –The number of nearest neighbours that should be returned.
Returns:
remove_element
¤
Remove an element from the model.
Parameters:
-
element(Element) –The element to remove.
Returns:
-
None–
remove_elements_of_type
¤
remove_interaction
¤
Remove the interaction between two elements.
Parameters:
-
a(Element) – -
b(Element) –
Returns:
-
None–
transform
¤
transform(transformation: Transformation) -> None
Transform the model and all that it contains.
Parameters:
-
Transformation–The transformation to apply.
Returns:
-
None–The model is modified in-place.