Model.collisionfix_temp#

Model.collisionfix_temp(reserved, collection, smooth)#

Fixes collisions (intersections or penetrations) that have been detected with a call of Model.collisioncheck_temp() or Model.collisioncheck2_temp(), by automatically moving individual nodes. The collision result entities passed as input get updated or deleted, if the fix is successful. This has no effect if the implemented algorithm cannot find any appropriate fix.

There are some restrictions regarding the collision result entities that are used as input:

  • Only possible for either intersections or penetrations at a time. All provided collision result entities should have the same “config” (otherwise the ones with another config than the first one are ignored).

  • Only possible for one group at a time. All provided collision result entities have to have the same “parent” (otherwise the ones with another parent than the first one are ignored).

Note that Model.hm_collisionend() does not delete any collision result entities. The deletion must be handled using Model.deletemark().

Parameters:
  • reserved (int) – Reserved for future use. Must be set to 0.

  • collection (Collection) – The collection containing the collision entities to fix.

  • smooth (int) – Used to improve the results of the automatic penetration fix. Valid values are integers ≥ 0. Setting to smooth=0 will apply the built-in default, which has proven to be efficient.

Example#

Fix intersection and penetration for all components in the model , implement the recommended approach to fix penetrations only if there are no intersections#
import hm
import hm.entities as ent

model = hm.Model()

# Delete potential obsolete collision results
model.hm_collisionend()

collision_collection=hm.Collection(model,ent.Collision)

if len(collision_collection)!=0:
    model.deletemark(type=collision_collection)

comp_coll_collection=hm.Collection(model,ent.Component)

status, result = model.hm_collisiongetconfig(options=["collirad"])

model.hm_collisioninit(config=result.config)

model.hm_collisionentitycreate(
    collection=comp_coll_collection,
    dimension=0,
    thickness_type=2,
    thickness=0.0,
    edge_penetration=0,
    midside_nodes=0,
    split_quads=0,
    used_topology=0,
    grouping_identifier=0,
    offset=0
)

# Intersection check triggered by providing collection_int_elems
model.collisioncheck_temp(
    collection_int_elems=comp_coll_collection,
    self_check=0,
    reserved1=0,
    pair_angle=90.0,
    store_segments=0,
    mark_adjoining=0,
    topo_feature_angle=0.0,
    pair_results=2,
    flag=0,
    arg=0.0,
)

# Intersection fix if there are intersections
collision_collection=hm.Collection(model,ent.Collision)

if len(collision_collection)!=0:
    model.collisionfix_temp(reserved=0,collection=collision_collection,smooth=0)
else:
    # Penetration check and fix only if no intersections remain
    model.collisioncheck_temp(
        collection_pene_elems=comp_coll_collection,
        self_check=0,
        reserved1=0,
        pair_angle=90.0,
        store_segments=0,
        mark_adjoining=0,
        topo_feature_angle=0.0,
        pair_results=2,
        flag=0,
        arg=0.0,
    )

    if len(collision_collection)!=0:
        model.collisionfix_temp(reserved=0,collection=collision_collection,smooth=0)

# Delete collision results
model.hm_collisionend()

if len(collision_collection)!=0:
    model.deletemark(type=collision_collection)