Skip to content

Commit efbf82f

Browse files
Enable geometries import
1 parent eb85fd3 commit efbf82f

1 file changed

Lines changed: 66 additions & 7 deletions

File tree

kratos.gid/scripts/Controllers/MdpaImportMesh.tcl

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ proc Kratos::ReadPre { filename } {
7474
}
7575
}
7676
}
77+
78+
if {[string match "Begin Geometries*" $line]} {
79+
set element_type [Kratos::GuessElementTypeFromMDPA $line]
80+
while { ![eof $fp] } {
81+
gets $fp line
82+
if {$line ne "End Geometries"} {
83+
# lo del elemento
84+
set raw [regsub -all {\s+} $line $space]
85+
set id [lindex $raw 0]
86+
set nodes [lrange $raw 1 end]
87+
if {[llength $nodes] > 1} {
88+
set nodes_new [list ]
89+
foreach node $nodes {lappend nodes_new [expr $node + $offset_nodes]}
90+
GiD_Mesh create element [expr $offset_elements + $id] $element_type [llength $nodes_new] $nodes_new
91+
} else {
92+
dict set spheres_dict $nodes element_type $element_type
93+
dict set spheres_dict $nodes element $id
94+
}
95+
} else {
96+
break
97+
}
98+
}
99+
}
77100
if {[string match "Begin NodalData RADIUS*" $line]} {
78101
while { ![eof $fp] } {
79102
gets $fp line
@@ -142,6 +165,16 @@ proc Kratos::ReadPre { filename } {
142165
}
143166
}
144167
}
168+
if {[string trim $line] eq "Begin SubModelPartGeometries"} {
169+
while { ![eof $fp] } {
170+
gets $fp line
171+
if {[string trim $line] ne "End SubModelPartGeometries"} {
172+
GiD_EntitiesGroups assign $group_name elements [expr $offset_elements + [string trim $line]]
173+
} else {
174+
break
175+
}
176+
}
177+
}
145178
if {[string trim $line] eq "Begin SubModelPartConditions"} {
146179
while { ![eof $fp] } {
147180
gets $fp line
@@ -186,22 +219,35 @@ proc Kratos::ReadPre { filename } {
186219

187220
proc Kratos::GuessElementTypeFromMDPA {line} {
188221
set element_type "unknown"
189-
set element_name [lindex $line 2]
190-
set element_name [lindex [split $element_name "//"] 0]
222+
set entity [lindex $line 1]
223+
set element_name1 [lindex $line 2]
224+
set element_name [lindex [split $element_name1 "//"] 0]
191225

192-
# 0: linear, 1: quadratic, 2: biquadratic
193-
set is_quadratic [write::isquadratic]
194-
195226
if {$element_name eq "Sphere3D"} {
196227
set element_type "Sphere"
197228
} elseif {$element_name in {"SphericContinuumParticle3D" "SphericParticle3D"}} {
198229
set element_type "Sphere"
199230
} elseif {$element_name in {"CylinderContinuumParticle2D" "CylinderParticle2D"}} {
200231
set element_type "Circle"
201232
} else {
233+
if {$entity eq "Geometries"} {
234+
set dim [string index $element_name end-2]
235+
set nnodes [string index $element_name end]
236+
} else {
237+
set dim [string index $element_name end-3]
238+
set nnodes [string index $element_name end-1]
239+
}
240+
# 0: linear, 1: quadratic, 2: biquadratic
241+
set detected_mesh_quad [Kratos::GuessQuadMesh $element_name $dim $nnodes]
242+
set is_quadratic [GiD_Set Model(QuadraticType)]
243+
if { $detected_mesh_quad eq "0" } {
244+
if {$is_quadratic ne "0"} {W "We have changed the mesh mode to linear. Check preferences to change it back."}
245+
GiD_Set Model(QuadraticType) 0
246+
} elseif {$is_quadratic eq "1"} {
247+
if {is_quadratic ne "1"} {W "We have changed the mesh mode to quadratic. Check preferences to change it back."}
248+
GiD_Set Model(QuadraticType) 1
249+
}
202250

203-
set dim [string index $element_name end-3]
204-
set nnodes [string index $element_name end-1]
205251
switch $nnodes {
206252
2 {
207253
set element_type "Line"
@@ -267,5 +313,18 @@ proc Kratos::GuessElementTypeFromMDPA {line} {
267313
return $element_type
268314
}
269315

316+
proc Kratos::GuessQuadMesh {element_name dim nnodes} {
317+
set guess -1
318+
# If element name contains "Line"
319+
if {[string first "Line" $element_name] != -1} {
320+
if {$nnodes eq 2} {
321+
set guess 0
322+
} elseif {$nnodes eq 3} {
323+
set guess 1
324+
}
325+
}
326+
return $guess
327+
}
328+
270329
#register the proc to be automatically called when dropping a file
271330
GiD_RegisterExtensionProc ".mdpa" PRE Kratos::ReadPreSingleFile

0 commit comments

Comments
 (0)