@@ -10,6 +10,7 @@ namespace eval write {
1010 variable MDPA_loop_control
1111 variable current_configuration
1212 variable current_mdpa_indent_level
13+ variable formats_dict
1314}
1415
1516proc write::Init { } {
@@ -33,6 +34,10 @@ proc write::Init { } {
3334 set MDPA_loop_control 0
3435
3536 set current_mdpa_indent_level 0
37+
38+
39+ variable formats_dict
40+ set formats_dict [dict create]
3641}
3742
3843proc write::initWriteConfiguration {configuration} {
@@ -92,6 +97,11 @@ proc write::writeEvent { filename } {
9297 return 1
9398 }
9499 if {$time_monitor } {set inittime [clock seconds]}
100+
101+ # Set write formats depending on the user's configuration
102+ InitWriteFormats
103+
104+ # Current active app
95105 set activeapp [::apps::getActiveApp]
96106 set appid [::apps::getActiveAppId]
97107
@@ -246,8 +256,12 @@ proc write::transformGroupName {groupid} {
246256
247257# Warning! Indentation must be set before calling here!
248258proc write::GetFormatDict { groupid mid num} {
259+ variable formats_dict
260+ set id_f [dict get $formats_dict ID]
261+ set mid_f [dict get $formats_dict MAT_ID]
262+
249263 set s [mdpaIndent]
250- set f " ${s} %5d [ format " %10d " $mid ] [ string repeat " %10d " $num ] \n "
264+ set f " ${s}$id_f [ format $mid_f $mid ] [ string repeat " $id_f " $num ] \n "
251265 return [dict create $groupid $f ]
252266}
253267
@@ -398,6 +412,9 @@ proc write::writePartSubModelPart { } {
398412}
399413
400414proc write::writeLinearLocalAxesGroup {group} {
415+ variable formats_dict
416+ set id_f [dict get $formats_dict ID]
417+ set coord_f [dict get $formats_dict COORDINATE]
401418 set elements [GiD_EntitiesGroups get $group elements -element_type linear]
402419 set num_elements [objarray length $elements ]
403420 if {$num_elements } {
@@ -408,7 +425,7 @@ proc write::writeLinearLocalAxesGroup {group} {
408425 set y0 [lindex $raw 1]
409426 set y1 [lindex $raw 4]
410427 set y2 [lindex $raw 7]
411- write::WriteString [format " %5d \[ 3\] (%14.10f, %14.10f, %14.10f )" $line $y0 $y1 $y2 ]
428+ write::WriteString [format " $id_f \[ 3\] ($coord_f , $coord_f , $coord_f )" $line $y0 $y1 $y2 ]
412429 }
413430 write::WriteString " End ElementalData"
414431 write::WriteString " "
@@ -577,6 +594,30 @@ proc write::mdpaIndent { {b 4} } {
577594 string repeat [string repeat " " $b ] $current_mdpa_indent_level
578595}
579596
597+ # Sets the precission for the diffetent entities written in the mdpa
598+ # To customize the formats and precissions for your mdpa.
599+ # You can edit in your write mdpa event script using write::SetWriteFormatFor
600+ proc write::InitWriteFormats { } {
601+ if {$::Kratos::kratos_private(mdpa_format) == 1} {
602+ # Readable
603+ write::SetWriteFormatFor ID " %5d"
604+ write::SetWriteFormatFor CONNECTIVITY " %10d"
605+ write::SetWriteFormatFor MAT_ID " %10d"
606+ write::SetWriteFormatFor COORDINATE " %14.10f"
607+ } else {
608+ # Optimized
609+ write::SetWriteFormatFor ID " %d"
610+ write::SetWriteFormatFor CONNECTIVITY " %d"
611+ write::SetWriteFormatFor MAT_ID " %d"
612+ write::SetWriteFormatFor COORDINATE " %.10f"
613+ }
614+ }
615+
616+ proc write::SetWriteFormatFor { what format } {
617+ variable formats_dict
618+ dict set formats_dict $what $format
619+ }
620+
580621proc write::CopyFileIntoModel { filepath } {
581622 set dir [GetConfigurationAttribute dir]
582623 set activeapp [::apps::getActiveApp]
0 commit comments