Skip to content

Commit 5e62c6f

Browse files
Make it generic for 2D and 3D. Use of objarray
1 parent 8700c86 commit 5e62c6f

1 file changed

Lines changed: 34 additions & 36 deletions

File tree

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,50 @@
11

22
proc ::CDEM::examples::BulkGroup {args} {
3+
4+
35
if {![Kratos::IsModelEmpty]} {
4-
set txt "Bulk grouping of all the current volumes is about to be executed"
6+
set entity surfaces
7+
if {$::Model::SpatialDimension eq "3D"} {
8+
set entity volumes
9+
}
10+
set txt "Bulk grouping of all the current $entity is about to be executed"
511
set retval [tk_messageBox -default ok -icon question -message $txt -type okcancel]
612
if { $retval == "cancel" } { return }
713
}
814

9-
10-
if {$::Model::SpatialDimension eq "2D"} {
11-
CreateAndAssign2DBondedGroups
12-
} else {
13-
CreateAndAssign3DBondedGroups
14-
}
15-
15+
CreateAndAssignBondedGroups
16+
1617
GiD_Process 'Redraw
1718
GidUtils::UpdateWindow GROUPS
1819
GidUtils::UpdateWindow LAYER
1920
GiD_Process 'Zoom Frame
2021
}
2122

22-
proc ::CDEM::examples::CreateAndAssign3DBondedGroups { } {
23-
24-
set volume_list [GiD_Geometry -v2 list volume]
25-
26-
for {set i 0} {$i < [llength $volume_list]} {incr i} {
27-
28-
set volume_id [lindex $volume_list $i]
29-
GiD_Groups create Bonded_domain_groups//SG$volume_id
30-
GiD_EntitiesGroups assign Bonded_domain_groups//SG$volume_id volumes $volume_id
31-
32-
set DEMConditions [spdAux::getRoute "DEMConditions"]
33-
set cohesive_cond "$DEMConditions/condition\[@n='DEM-Cohesive'\]"
34-
set cohesive_group [customlib::AddConditionGroupOnXPath $cohesive_cond Bonded_domain_groups//SG$volume_id]
23+
proc ::CDEM::examples::CreateAndAssignBondedGroups { } {
24+
# Prepare the variables
25+
set entity surface
26+
set condition_id "DEM-Cohesive2D"
27+
if {$::Model::SpatialDimension eq "3D"} {
28+
set entity volume
29+
set condition_id "DEM-Cohesive"
3530
}
36-
}
37-
38-
proc ::CDEM::examples::CreateAndAssign2DBondedGroups { } {
39-
40-
set surface_list [GiD_Geometry -v2 list surface]
41-
42-
for {set i 0} {$i < [llength $surface_list]} {incr i} {
43-
44-
set surface_id [lindex $surface_list $i]
45-
GiD_Groups create Bonded_domain_groups//SG$surface_id
46-
GiD_EntitiesGroups assign Bonded_domain_groups//SG$surface_id surfaces $surface_id
47-
48-
set DEMConditions [spdAux::getRoute "DEMConditions"]
49-
set cohesive_cond "$DEMConditions/condition\[@n='DEM-Cohesive2D'\]"
50-
set cohesive_group [customlib::AddConditionGroupOnXPath $cohesive_cond Bonded_domain_groups//SG$surface_id]
31+
# Locate the condition
32+
set DEMConditions [spdAux::getRoute "DEMConditions"]
33+
set cohesive_cond "$DEMConditions/condition\[@n='$condition_id'\]"
34+
35+
# Get the list of entities (surfaces/volumes)
36+
set entity_list [GiD_Geometry -v2 list $entity]
37+
# Foreach entity, create subgroup and assign it to the condition
38+
set entity_list_length [objarray length $entity_list]
39+
for {set i 0} {$i < $entity_list_length} {incr i} {
40+
# Get the entity id
41+
set entity_id [objarray get $entity_list $i]
42+
# Create the subgroup
43+
set group_id "Bonded_domain_groups//SG$entity_id"
44+
GiD_Groups create $group_id
45+
# Assign entity to subgroup
46+
GiD_EntitiesGroups assign $group_id volumes $entity_id
47+
# Assign the subgroup to the tree condition
48+
set cohesive_group [customlib::AddConditionGroupOnXPath $cohesive_cond $group_id]
5149
}
5250
}

0 commit comments

Comments
 (0)