Skip to content

Commit 3b5c33a

Browse files
Merge pull request #1022 from KratosMultiphysics/point-as-geometry
Force creation of point elements
2 parents 8d5cabe + cbb886e commit 3b5c33a

File tree

5 files changed

+180
-55
lines changed

5 files changed

+180
-55
lines changed

kratos.gid/kratos.tcl

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace eval ::Kratos {
99
variable must_write_calc_data
1010
variable must_exist_calc_data
1111

12-
variable tmp_init_mesh_time
1312
variable namespaces
1413

1514
variable mesh_criteria_forced
@@ -200,7 +199,7 @@ proc Kratos::LoadCommonScripts { } {
200199
uplevel #0 [list source [file join $kratos_private(Path) scripts Writing $filename.tcl]]
201200
}
202201
# Common scripts
203-
foreach filename {Utils Launch Applications spdAuxiliar Menus Deprecated Logs} {
202+
foreach filename {Utils Launch Applications spdAuxiliar Mesh Menus Deprecated Logs} {
204203
uplevel #0 [list source [file join $kratos_private(Path) scripts $filename.tcl]]
205204
}
206205
# Common controllers
@@ -427,19 +426,10 @@ proc Kratos::Event_BeforeMeshGeneration {elementsize} {
427426
set tmp_init_mesh_time $inittime
428427
Kratos::Log "Mesh BeforeMeshGeneration start"
429428

430-
GiD_MeshData mesh_criteria to_be_meshed 1 lines [GiD_Geometry list line]
431-
GiD_MeshData mesh_criteria to_be_meshed 1 surfaces [GiD_Geometry list surface]
432-
GiD_MeshData mesh_criteria to_be_meshed 1 volumes [GiD_Geometry list volume ]
433-
434-
# We need to mesh every line and surface assigned to a group that appears in the tree
435-
foreach group [spdAux::GetAppliedGroups] {
436-
GiD_MeshData mesh_criteria to_be_meshed 2 lines [GiD_EntitiesGroups get $group lines]
437-
GiD_MeshData mesh_criteria to_be_meshed 2 surfaces [GiD_EntitiesGroups get $group surfaces]
438-
GiD_MeshData mesh_criteria to_be_meshed 2 volumes [GiD_EntitiesGroups get $group volumes]
439-
}
429+
Mesh::PrepareMeshGeneration $elementsize
440430

441431
# Change the mesh settings depending on the element requirements
442-
if {[Kratos::CheckMeshCriteria $elementsize]<0} {
432+
if {[Mesh::CheckMeshCriteria $elementsize]<0} {
443433
return "-cancel-"
444434
}
445435

@@ -459,9 +449,17 @@ proc Kratos::Event_MeshProgress { total_percent partial_percents_0 partial_perce
459449
proc Kratos::Event_AfterMeshGeneration {fail} {
460450
variable tmp_init_mesh_time
461451

452+
if {$fail} {
453+
Kratos::Log "Mesh generation failed"
454+
return
455+
}
456+
462457
# Change the mesh settings depending on the element requirements. Reset previous settings
463458
# catch {Kratos::ResetMeshCriteria $fail}
464459

460+
Mesh::AddPointElementsIfNeeded
461+
462+
465463
# Maybe the current application needs to do some extra job
466464
apps::ExecuteOnCurrentApp AfterMeshGeneration $fail
467465
set endtime [clock seconds]

kratos.gid/scripts/Mesh.tcl

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
##################################################################################
2+
3+
namespace eval ::Mesh {
4+
Kratos::AddNamespace [namespace current]
5+
6+
7+
}
8+
proc Mesh::PrepareMeshGeneration {elementsize} {
9+
10+
GiD_MeshData mesh_criteria to_be_meshed 1 lines [GiD_Geometry list line]
11+
GiD_MeshData mesh_criteria to_be_meshed 1 surfaces [GiD_Geometry list surface]
12+
GiD_MeshData mesh_criteria to_be_meshed 1 volumes [GiD_Geometry list volume ]
13+
14+
# We need to mesh every line and surface assigned to a group that appears in the tree
15+
foreach group [spdAux::GetAppliedGroups] {
16+
GiD_MeshData mesh_criteria to_be_meshed 2 lines [GiD_EntitiesGroups get $group lines]
17+
GiD_MeshData mesh_criteria to_be_meshed 2 surfaces [GiD_EntitiesGroups get $group surfaces]
18+
GiD_MeshData mesh_criteria to_be_meshed 2 volumes [GiD_EntitiesGroups get $group volumes]
19+
}
20+
}
21+
22+
23+
proc Mesh::CheckMeshCriteria { elementsize } {
24+
25+
set force_mesh_order [dict create]
26+
set elements_used [spdAux::GetUsedElements]
27+
set forced_mesh_order -1
28+
foreach element_id $elements_used {
29+
set element [Model::getElement $element_id]
30+
if {[$element hasAttribute "MeshOrder"]} {
31+
set element_forces [$element getAttribute "MeshOrder"]
32+
if {$element_forces eq "Quadratic"} {
33+
set element_forces 1
34+
} else {
35+
set element_forces 0
36+
}
37+
dict set force_mesh_order $element_id $element_forces
38+
if {$forced_mesh_order eq -1} {
39+
set forced_mesh_order $element_forces
40+
} else {
41+
if {$forced_mesh_order ne $element_forces} {
42+
# W "The element $element_id requires a different mesh order"
43+
W "Incompatible mesh orders in elements"
44+
return -1
45+
}
46+
}
47+
}
48+
}
49+
50+
if {$forced_mesh_order ne -1} {
51+
52+
set element [lindex [dict keys $force_mesh_order] 0]
53+
set previous_mesh_order [write::isquadratic]
54+
set current_mesh_type [Kratos::GetMeshOrderName $previous_mesh_order]
55+
set desired_mesh_type [Kratos::GetMeshOrderName $forced_mesh_order]
56+
if {$previous_mesh_order ne $forced_mesh_order} {
57+
W "The element $element requires a different mesh order: $desired_mesh_type"
58+
W "Currently the mesh order is $current_mesh_type. please change it in the menu Mesh > Quadratic type"
59+
return -1
60+
}
61+
}
62+
return 0
63+
}
64+
65+
proc Mesh::AddPointElementsIfNeeded {} {
66+
# Foreach groups assigned in tree
67+
set condition_groups [spdAux::GetUsedConditions]
68+
69+
# condition_groups is a dict of conditionid -> list of group nodes (tdom)
70+
foreach condid [dict keys $condition_groups] {
71+
set cond [Model::getCondition $condid]
72+
if {$cond eq ""} {
73+
continue
74+
}
75+
76+
# if group element is point and has topology for points
77+
set topology [$cond getTopologyFeature "Point" 1]
78+
if {$topology eq ""} {
79+
continue
80+
}
81+
82+
set group_nodes [dict get $condition_groups $condid]
83+
foreach node_tdom $group_nodes {
84+
set group_id [get_domnode_attribute $node_tdom n]
85+
86+
# if group ov is point or condition ov is point
87+
set ov ""
88+
if {[$node_tdom hasAttribute ov]} {
89+
set ov [get_domnode_attribute $node_tdom ov]
90+
} else {
91+
set ov [get_domnode_attribute [$node_tdom parent] ov]
92+
}
93+
if { $ov ne "Point" && $ov ne "point" } {
94+
continue
95+
}
96+
97+
# Get the goodname of the group
98+
set group_id [write::GetWriteGroupName $group_id]
99+
100+
set node_ids [GiD_EntitiesGroups get $group_id nodes]
101+
set new_nodeids [list]
102+
foreach nodeid $node_ids {
103+
set new_nodeid [GiD_Mesh create element append Point 1 [list $nodeid]]
104+
# Add to same groups as the node
105+
lappend new_nodeids $new_nodeid
106+
}
107+
GiD_EntitiesGroups assign $group_id elements $new_nodeids
108+
}
109+
}
110+
111+
}

kratos.gid/scripts/Utils.tcl

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -292,47 +292,6 @@ proc Kratos::GetMeshBasicData { } {
292292
return $result
293293
}
294294

295-
proc Kratos::CheckMeshCriteria { elementsize } {
296-
297-
set force_mesh_order [dict create]
298-
set elements_used [spdAux::GetUsedElements]
299-
set forced_mesh_order -1
300-
foreach element_id $elements_used {
301-
set element [Model::getElement $element_id]
302-
if {[$element hasAttribute "MeshOrder"]} {
303-
set element_forces [$element getAttribute "MeshOrder"]
304-
if {$element_forces eq "Quadratic"} {
305-
set element_forces 1
306-
} else {
307-
set element_forces 0
308-
}
309-
dict set force_mesh_order $element_id $element_forces
310-
if {$forced_mesh_order eq -1} {
311-
set forced_mesh_order $element_forces
312-
} else {
313-
if {$forced_mesh_order ne $element_forces} {
314-
# W "The element $element_id requires a different mesh order"
315-
W "Incompatible mesh orders in elements"
316-
return -1
317-
}
318-
}
319-
}
320-
}
321-
322-
if {$forced_mesh_order ne -1} {
323-
324-
set element [lindex [dict keys $force_mesh_order] 0]
325-
set previous_mesh_order [write::isquadratic]
326-
set current_mesh_type [Kratos::GetMeshOrderName $previous_mesh_order]
327-
set desired_mesh_type [Kratos::GetMeshOrderName $forced_mesh_order]
328-
if {$previous_mesh_order ne $forced_mesh_order} {
329-
W "The element $element requires a different mesh order: $desired_mesh_type"
330-
W "Currently the mesh order is $current_mesh_type. please change it in the menu Mesh > Quadratic type"
331-
return -1
332-
}
333-
}
334-
return 0
335-
}
336295

337296
proc Kratos::GetMeshOrderName {order} {
338297
switch $order {

kratos.gid/scripts/Writing/WriteGeometries.tcl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ proc write::printGeometryConnectivities {group etype nnodes} {
4040
# Prepare the indent
4141
set s [mdpaIndent]
4242
set nDim $::Model::SpatialDimension
43-
set geometry_name ${etype}${nDim}${nnodes}
43+
set geometry_name [GetGeometryName $etype $nDim $nnodes]
4444

4545
# Prepare the formats dict
4646
set formats [GetFormatDict $group "" $nnodes]
@@ -63,6 +63,32 @@ proc write::printGeometryConnectivities {group etype nnodes} {
6363
if {$etype == "Sphere" || $etype == "Circle"} {
6464
write::writeSphereRadiusOnGroup $group
6565
}
66+
} else {
67+
# Trick: GiD < 17.3.x return 0 if elements are of type Point
68+
set elems [GiD_EntitiesGroups get $group elements -element_type point]
69+
set num_elems [objarray length $elems]
70+
if {$num_elems > 0} {
71+
# Write header
72+
WriteString "${s}Begin Geometries $geometry_name // GUI group identifier: $group"
73+
# increase indent (allows folding in text editor)
74+
incr ::write::current_mdpa_indent_level
75+
# Write the connectivities
76+
set s1 [mdpaIndent]
77+
objarray foreach elem $elems {
78+
set node_id [GiD_Mesh get element $elem connectivities]
79+
GiD_WriteCalculationFile puts "${s1}$elem $node_id"
80+
}
81+
# decrease indent
82+
incr ::write::current_mdpa_indent_level -1
83+
# Write footer
84+
WriteString "${s}End Geometries"
85+
WriteString ""
86+
87+
# Write the radius if it is a sphere or a circle
88+
if {$etype == "Sphere" || $etype == "Circle"} {
89+
write::writeSphereRadiusOnGroup $group
90+
}
91+
}
6692
}
6793
if {[GetConfigurationAttribute time_monitor]} {set endtime [clock seconds]; set ttime [expr {$endtime-$inittime}]; W "printGeometryConnectivities $geometry_name time: [Kratos::Duration $ttime]"}
6894
}
@@ -73,4 +99,12 @@ proc write::writeSphereRadiusOnGroup { groupid } {
7399
GiD_WriteCalculationFile connectivities [dict create $groupid "%.0s %10d 0 %10g\n"]
74100
write::WriteString "End NodalData"
75101
write::WriteString ""
102+
}
103+
104+
proc write::GetGeometryName { etype nDim nnodes } {
105+
if {$etype == "Point"} {
106+
return "${etype}${nDim}"
107+
} else {
108+
return "${etype}${nDim}${nnodes}"
109+
}
76110
}

kratos.gid/scripts/spdAuxiliar.tcl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,29 @@ proc spdAux::GetUsedElements {{alt_un ""}} {
423423
return $lista
424424
}
425425

426+
# returns ["condition1" {gNode1 gNode2} "condition2" {gNode3 gNode4}]
427+
proc spdAux::GetUsedConditions {{root ""}} {
428+
set resultDict [dict create]
429+
430+
431+
set xp1 "./condition/group"
432+
if {$root eq "" } {
433+
set root [customlib::GetBaseRoot]
434+
set xp1 "//condition/group"
435+
}
436+
437+
foreach gNode [$root selectNodes $xp1] {
438+
set condition_node [$gNode parent]
439+
set condition_name [$condition_node @n]
440+
441+
set cond [Model::getCondition $condition_name]
442+
if {$cond eq ""} {continue}
443+
dict lappend resultDict $condition_name $gNode
444+
445+
}
446+
return $resultDict
447+
}
448+
426449
proc spdAux::LoadIntervalGroups { {root ""} } {
427450
customlib::UpdateDocument
428451
variable GroupsEdited

0 commit comments

Comments
 (0)