Skip to content

Commit

Permalink
Merge pull request #957 from KratosMultiphysics/mdpa-import-quadratic…
Browse files Browse the repository at this point in the history
…-mesh

MDPA Import quadratic mesh
  • Loading branch information
jginternational authored Oct 11, 2023
2 parents 2ba04d1 + cd93f66 commit 5a4b29c
Showing 1 changed file with 85 additions and 9 deletions.
94 changes: 85 additions & 9 deletions kratos.gid/scripts/Controllers/MdpaImportMesh.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,29 @@ proc Kratos::ReadPre { filename } {
}
}
}

if {[string match "Begin Geometries*" $line]} {
set element_type [Kratos::GuessElementTypeFromMDPA $line]
while { ![eof $fp] } {
gets $fp line
if {$line ne "End Geometries"} {
# lo del elemento
set raw [regsub -all {\s+} $line $space]
set id [lindex $raw 0]
set nodes [lrange $raw 1 end]
if {[llength $nodes] > 1} {
set nodes_new [list ]
foreach node $nodes {lappend nodes_new [expr $node + $offset_nodes]}
GiD_Mesh create element [expr $offset_elements + $id] $element_type [llength $nodes_new] $nodes_new
} else {
dict set spheres_dict $nodes element_type $element_type
dict set spheres_dict $nodes element $id
}
} else {
break
}
}
}
if {[string match "Begin NodalData RADIUS*" $line]} {
while { ![eof $fp] } {
gets $fp line
Expand Down Expand Up @@ -142,6 +165,16 @@ proc Kratos::ReadPre { filename } {
}
}
}
if {[string trim $line] eq "Begin SubModelPartGeometries"} {
while { ![eof $fp] } {
gets $fp line
if {[string trim $line] ne "End SubModelPartGeometries"} {
GiD_EntitiesGroups assign $group_name elements [expr $offset_elements + [string trim $line]]
} else {
break
}
}
}
if {[string trim $line] eq "Begin SubModelPartConditions"} {
while { ![eof $fp] } {
gets $fp line
Expand Down Expand Up @@ -186,24 +219,46 @@ proc Kratos::ReadPre { filename } {

proc Kratos::GuessElementTypeFromMDPA {line} {
set element_type "unknown"
set element_name [lindex $line 2]
set element_name [lindex [split $element_name "//"] 0]

set entity [lindex $line 1]
set element_name1 [lindex $line 2]
set element_name [lindex [split $element_name1 "//"] 0]

if {$element_name eq "Sphere3D"} {
set element_type "Sphere"
} elseif {$element_name in {"SphericContinuumParticle3D" "SphericParticle3D"}} {
set element_type "Sphere"
} elseif {$element_name in {"CylinderContinuumParticle2D" "CylinderParticle2D"}} {
set element_type "Circle"
} else {
set dim [string index $element_name end-3]
set nnodes [string index $element_name end-1]
if {$entity eq "Geometries"} {
set dim [string index $element_name end-2]
set nnodes [string index $element_name end]
} else {
set dim [string index $element_name end-3]
set nnodes [string index $element_name end-1]
}
# 0: linear, 1: quadratic, 2: biquadratic
set detected_mesh_quad [Kratos::GuessQuadMesh $element_name $dim $nnodes]
set is_quadratic [GiD_Set Model(QuadraticType)]
if { $detected_mesh_quad eq "0" } {
if {$is_quadratic ne "0"} {W "We have changed the mesh mode to linear. Check Mesh menu to change it back."}
GiD_Set Model(QuadraticType) 0
}
if {$detected_mesh_quad eq "1"} {
if {$is_quadratic ne "1"} {W "We have changed the mesh mode to quadratic. Check Mesh menu to change it back."}
GiD_Set Model(QuadraticType) 1
}

switch $nnodes {
2 {
set element_type "Line"
}
3 {
set element_type "Triangle"
if {$is_quadratic eq "0"} {
set element_type "Triangle"
} else {
set element_type "Line"
}
}
4 {
if {$dim eq 2} {
Expand All @@ -216,10 +271,14 @@ proc Kratos::GuessElementTypeFromMDPA {line} {
set element_type "Pyramid"
}
6 {
if {$dim eq 2} {
set element_type "Triangle"
if {$is_quadratic eq "0"} {
if {$dim eq 2} {
set element_type "Triangle"
}
} else {
set element_type "Prism"
if {$dim eq 2} {
set element_type "Triangle"
}
}
}
8 {
Expand Down Expand Up @@ -255,5 +314,22 @@ proc Kratos::GuessElementTypeFromMDPA {line} {
return $element_type
}

proc Kratos::GuessQuadMesh {element_name dim nnodes} {
if {$nnodes eq 6 && $dim eq 2} {return 1}
if {$nnodes eq 4 && $dim eq 2} {return 0}
if {$nnodes eq 4 && $dim eq 3} {return 0}
if {$nnodes eq 8 && $dim eq 2} {return 1}
if {$nnodes eq 8 && $dim eq 3} {return 0}
if {$nnodes eq 2 } {return 0}
if {$nnodes eq 9 } {return 2}
if {$nnodes eq 20 } {return 1}
if {$nnodes eq 27 } {return 2}
if {$nnodes eq 15 } {return 1}
if {$nnodes eq 18 } {return 2}
if {$nnodes eq 5 } {return 0}
if {$nnodes eq 13 } {return 1}
return -1
}

#register the proc to be automatically called when dropping a file
GiD_RegisterExtensionProc ".mdpa" PRE Kratos::ReadPreSingleFile

0 comments on commit 5a4b29c

Please sign in to comment.