From fd5cff165200e7e5f57b0129a4172d2c913abeec Mon Sep 17 00:00:00 2001 From: jginternational Date: Tue, 27 Jul 2021 18:08:41 +0200 Subject: [PATCH 01/15] diagonal --- kratos.gid/apps/FluidDEM/xml/Elements.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kratos.gid/apps/FluidDEM/xml/Elements.xml b/kratos.gid/apps/FluidDEM/xml/Elements.xml index 58d37e2e8..1c34adba2 100644 --- a/kratos.gid/apps/FluidDEM/xml/Elements.xml +++ b/kratos.gid/apps/FluidDEM/xml/Elements.xml @@ -14,11 +14,11 @@ - + - + @@ -34,12 +34,13 @@ + - + From cfbc895e0a6b3968a7fbc4e21d15e34542dd2eac Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Sun, 1 Aug 2021 22:55:15 +0200 Subject: [PATCH 02/15] QSVMSDEMcoupled3D uses permeability as list of 6 values --- kratos.gid/apps/FluidDEM/xml/Elements.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kratos.gid/apps/FluidDEM/xml/Elements.xml b/kratos.gid/apps/FluidDEM/xml/Elements.xml index 1c34adba2..823b60f1a 100644 --- a/kratos.gid/apps/FluidDEM/xml/Elements.xml +++ b/kratos.gid/apps/FluidDEM/xml/Elements.xml @@ -34,7 +34,12 @@ - + + + + + + From 51e201c7cfc45d0f9e0d1603a5ebd74e1abaf661 Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Sun, 1 Aug 2021 23:28:58 +0200 Subject: [PATCH 03/15] write delegated json --- kratos.gid/apps/Fluid/write/write.tcl | 5 +++++ kratos.gid/scripts/Writing/WriteMaterials.tcl | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/kratos.gid/apps/Fluid/write/write.tcl b/kratos.gid/apps/Fluid/write/write.tcl index a2cdbbce2..92a58b663 100644 --- a/kratos.gid/apps/Fluid/write/write.tcl +++ b/kratos.gid/apps/Fluid/write/write.tcl @@ -79,6 +79,11 @@ proc Fluid::write::WriteMaterialsFile { {write_const_law True} {include_modelpar if {[write::isBooleanTrue $include_modelpart_name]} {set model_part_name [GetAttribute model_part_name]} write::writePropertiesJsonFile [GetAttribute parts_un] [GetAttribute materials_file] $write_const_law $model_part_name } +proc Fluid::write::GetMaterialsFile { {write_const_law True} {include_modelpart_name True} } { + set model_part_name "" + if {[write::isBooleanTrue $include_modelpart_name]} {set model_part_name [GetAttribute model_part_name]} + return [write::getPropertiesJson [GetAttribute parts_un] $write_const_law $model_part_name] +} proc Fluid::write::Validate {} { set err "" diff --git a/kratos.gid/scripts/Writing/WriteMaterials.tcl b/kratos.gid/scripts/Writing/WriteMaterials.tcl index 3b4c48735..35706aac9 100644 --- a/kratos.gid/scripts/Writing/WriteMaterials.tcl +++ b/kratos.gid/scripts/Writing/WriteMaterials.tcl @@ -133,12 +133,18 @@ proc write::writeMaterials { {appid ""} {const_law_write_name ""}} { } } - -proc write::writePropertiesJsonFile {{parts_un ""} {fname "materials.json"} {write_claw_name "True"} {model_part_name ""}} { +proc write::getPropertiesJson {{parts_un ""} {write_claw_name "True"} {model_part_name ""}} { if {$parts_un eq ""} {set parts_un [GetConfigurationAttribute parts_un]} set mats_json [getPropertiesList $parts_un $write_claw_name $model_part_name] + return $mats_json +} + +proc write::writePropertiesJsonFile {{parts_un ""} {fname "materials.json"} {write_claw_name "True"} {model_part_name ""}} { + write::writePropertiesJsonFileDone $fname [write::getPropertiesJson $parts_un $write_claw_name $model_part_name] +} +proc write::writePropertiesJsonFileDone {fname json} { write::OpenFile $fname - write::WriteJSON $mats_json + write::WriteJSON $json write::CloseFile } From 67b0aec11c19d89c43a28f7d8eb1d2d8e2a28111 Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Sun, 1 Aug 2021 23:29:30 +0200 Subject: [PATCH 04/15] Write permeability as matrix --- kratos.gid/apps/FluidDEM/write/write.tcl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/kratos.gid/apps/FluidDEM/write/write.tcl b/kratos.gid/apps/FluidDEM/write/write.tcl index aeb1573ca..eeb4d6a8c 100644 --- a/kratos.gid/apps/FluidDEM/write/write.tcl +++ b/kratos.gid/apps/FluidDEM/write/write.tcl @@ -39,7 +39,7 @@ proc FluidDEM::write::writeCustomFilesEvent { } { } proc FluidDEM::write::WriteMaterialsFile { } { - Fluid::write::WriteMaterialsFile True + FluidDEM::write::writeFluidModifiedMaterials [Fluid::write::GetMaterialsFile True] DEM::write::writeMaterialsFile } @@ -67,4 +67,21 @@ proc Fluid::write::getFluidModelPartFilename { } { return [Kratos::GetModelName]Fluid } +proc FluidDEM::write::writeFluidModifiedMaterials {fluid_materials_json} { + set new_json [dict create] + foreach property [dict get $fluid_materials_json properties] { + if {[dict exists $property Material Variables PERMEABILITY_11]} { + set permeability_1 [list [dict get $property Material Variables PERMEABILITY_11] [dict get $property Material Variables PERMEABILITY_12] [dict get $property Material Variables PERMEABILITY_13]] + set permeability_2 [list [dict get $property Material Variables PERMEABILITY_12] [dict get $property Material Variables PERMEABILITY_22] [dict get $property Material Variables PERMEABILITY_23]] + set permeability_3 [list [dict get $property Material Variables PERMEABILITY_13] [dict get $property Material Variables PERMEABILITY_23] [dict get $property Material Variables PERMEABILITY_33]] + dict unset property Material Variables PERMEABILITY_11; dict unset property Material Variables PERMEABILITY_12; dict unset property Material Variables PERMEABILITY_13 + dict unset property Material Variables PERMEABILITY_22; dict unset property Material Variables PERMEABILITY_23 + dict unset property Material Variables PERMEABILITY_33 + dict set property Material Variables PERMEABILITY [list $permeability_1 $permeability_2 $permeability_3] + } + dict lappend new_json properties $property + } + write::writePropertiesJsonFileDone [Fluid::write::GetAttribute materials_file] $new_json +} + FluidDEM::write::Init \ No newline at end of file From df3ba13f69a3a3b117c32502a3ac318e60dac3ea Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Tue, 17 Aug 2021 15:54:54 +0200 Subject: [PATCH 05/15] Improving in matrix --- kratos.gid/apps/FluidDEM/xml/Elements.xml | 7 +------ kratos.gid/scripts/Controllers/TreeInjections.tcl | 7 +++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/kratos.gid/apps/FluidDEM/xml/Elements.xml b/kratos.gid/apps/FluidDEM/xml/Elements.xml index 823b60f1a..d8c738ffe 100644 --- a/kratos.gid/apps/FluidDEM/xml/Elements.xml +++ b/kratos.gid/apps/FluidDEM/xml/Elements.xml @@ -34,12 +34,7 @@ - - - - - - + diff --git a/kratos.gid/scripts/Controllers/TreeInjections.tcl b/kratos.gid/scripts/Controllers/TreeInjections.tcl index bbaeb66ca..28cfe2af4 100644 --- a/kratos.gid/scripts/Controllers/TreeInjections.tcl +++ b/kratos.gid/scripts/Controllers/TreeInjections.tcl @@ -374,6 +374,13 @@ proc spdAux::GetParameterValueString { param forcedParams base} { } } + "matrix" { + set rows [$param getAttribute "rows"] + set cols [$param getAttribute "cols"] + set components "" + for {set i 0} {$i < [expr max($rows,$cols)]} {incr i} {lappend components $i}; set components [join $components ","] + append node "" + } "combo" { if {[$param getAttribute "combotype"] eq "material"} { append node "" From d0eb1ef7aea05250641481cbbc47f7f9cfb3e094 Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Tue, 17 Aug 2021 21:09:28 +0200 Subject: [PATCH 06/15] matrix available in next gid version --- .../scripts/Controllers/TreeInjections.tcl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/kratos.gid/scripts/Controllers/TreeInjections.tcl b/kratos.gid/scripts/Controllers/TreeInjections.tcl index 28cfe2af4..ba2a53f18 100644 --- a/kratos.gid/scripts/Controllers/TreeInjections.tcl +++ b/kratos.gid/scripts/Controllers/TreeInjections.tcl @@ -379,7 +379,21 @@ proc spdAux::GetParameterValueString { param forcedParams base} { set cols [$param getAttribute "cols"] set components "" for {set i 0} {$i < [expr max($rows,$cols)]} {incr i} {lappend components $i}; set components [join $components ","] - append node "" + #append node "" + set value [split $v ","] + append node "" + append node " " + append node " " + for {set i 0} {$i < $rows} {incr i} { + for {set j 0} {$j < $cols} {incr j} { + set vi [lindex $value [expr ($i*$cols)+$j] ] + append node " " + } + } + append node " " + append node " " + append node "" + } "combo" { if {[$param getAttribute "combotype"] eq "material"} { From 8ed6952f63fb673b2649011c6fcec3f1fa5ad45c Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Tue, 17 Aug 2021 22:40:27 +0200 Subject: [PATCH 07/15] improve the process material function --- kratos.gid/apps/FluidDEM/xml/Elements.xml | 1 + .../scripts/Controllers/TreeInjections.tcl | 2 +- kratos.gid/scripts/Utils.tcl | 21 +++--- kratos.gid/scripts/Writing/WriteMaterials.tcl | 74 +++++++++---------- 4 files changed, 50 insertions(+), 48 deletions(-) diff --git a/kratos.gid/apps/FluidDEM/xml/Elements.xml b/kratos.gid/apps/FluidDEM/xml/Elements.xml index d8c738ffe..7106195c2 100644 --- a/kratos.gid/apps/FluidDEM/xml/Elements.xml +++ b/kratos.gid/apps/FluidDEM/xml/Elements.xml @@ -59,6 +59,7 @@ + diff --git a/kratos.gid/scripts/Controllers/TreeInjections.tcl b/kratos.gid/scripts/Controllers/TreeInjections.tcl index ba2a53f18..755709040 100644 --- a/kratos.gid/scripts/Controllers/TreeInjections.tcl +++ b/kratos.gid/scripts/Controllers/TreeInjections.tcl @@ -381,7 +381,7 @@ proc spdAux::GetParameterValueString { param forcedParams base} { for {set i 0} {$i < [expr max($rows,$cols)]} {incr i} {lappend components $i}; set components [join $components ","] #append node "" set value [split $v ","] - append node "" + append node "" append node " " append node " " for {set i 0} {$i < $rows} {incr i} { diff --git a/kratos.gid/scripts/Utils.tcl b/kratos.gid/scripts/Utils.tcl index 0e03d3d2f..beea82943 100644 --- a/kratos.gid/scripts/Utils.tcl +++ b/kratos.gid/scripts/Utils.tcl @@ -182,12 +182,12 @@ proc Kratos::LoadEnvironment { } { # W $data # Close the file close $fp - } - # Preferences are written in json format - foreach {k v} [write::json2dict $data] { - # W "$k $v" - # Foreach pair key value, restore it - set kratos_private($k) $v + # Preferences are written in json format + foreach {k v} [write::json2dict $data] { + # W "$k $v" + # Foreach pair key value, restore it + set kratos_private($k) $v + } } } @@ -291,8 +291,9 @@ proc Kratos::OpenCaseIn {program} { } } - -proc xmlprograms::OpenBrowserForDirectory { baseframe variable} { - set $variable [MessageBoxGetFilename directory write [_ "Select kratos debug compiled folder (kratos / bin / debug"]] - return variable +catch { + proc xmlprograms::OpenBrowserForDirectory { baseframe variable} { + set $variable [MessageBoxGetFilename directory write [_ "Select kratos debug compiled folder (kratos / bin / debug"]] + return variable + } } \ No newline at end of file diff --git a/kratos.gid/scripts/Writing/WriteMaterials.tcl b/kratos.gid/scripts/Writing/WriteMaterials.tcl index 35706aac9..dc4bca265 100644 --- a/kratos.gid/scripts/Writing/WriteMaterials.tcl +++ b/kratos.gid/scripts/Writing/WriteMaterials.tcl @@ -5,6 +5,7 @@ proc write::processMaterials { {alt_path ""} {last_assigned_id -1}} { set new_mats [dict create ] + # Prepare paths set parts [GetConfigurationAttribute parts_un] set materials_un [GetConfigurationAttribute materials_un] set root [customlib::GetBaseRoot] @@ -17,20 +18,29 @@ proc write::processMaterials { {alt_path ""} {last_assigned_id -1}} { } set xp2 ".//value\[@n='Material']" set material_number [expr {$last_assigned_id == -1 ? [llength [dict keys $mat_dict] ] : $last_assigned_id }] + + # Foreach group applied to parts foreach gNode [$root selectNodes $xp1] { + # Get the application. Important in Mixed apps (multiple inheritance). set nodeApp [spdAux::GetAppIdFromNode $gNode] + # Get the write group name. Used as unique id due to intervals and child tricks. set group_name [write::GetWriteGroupName [$gNode @n]] + # This group nodes are (always) child of condition (by definition), so get the condition is easy. set cond_name [[$gNode parent] @n] + # Using the condition and the group name, we can get the submodelpart id. A submodelpart is always the joint of condition + group. set submodelpart_id [write::GetSubModelPartName $cond_name $group_name] - set material_name "material $material_number" + #set material_name "material $material_number". if { ![dict exists $mat_dict $submodelpart_id] } { + # increment the material number. In multi part apps, this material number is passed as variable, in order to keep the numeration. incr material_number set mid $material_number + # Init the dictionary with initial data. dict set mat_dict $submodelpart_id MID $material_number dict set mat_dict $submodelpart_id APPID $nodeApp + # Get the elements name. Even if it's not used in this section, it's important to call it, so dependencies are applied. catch { set element_node [$gNode selectNodes ".//value\[@n = 'Element'\]"] if {$element_node ne ""} { @@ -39,40 +49,25 @@ proc write::processMaterials { {alt_path ""} {last_assigned_id -1}} { set element_name [write::getValueByNode $element_node "force"] } - set processed 0 + # We have 2 ways to get the properties (output type): + # A) Defined by all the values available below parts + # B) (By default) Defined also by the material parameters + + # Get the constitutive law output type + set output_type Materials set claw_node [$gNode selectNodes ".//value\[@n = 'ConstitutiveLaw'\]"] if {$claw_node ne ""} { set claw [write::getValueByNode $claw_node "force"] if {$claw ne "None"} { - set processed 1 set const_law [Model::getConstitutiveLaw $claw] set output_type [$const_law getOutputMode] - if {$output_type eq "Parameters"} { - set s1 [$gNode selectNodes ".//value"] - } else { - set s1 "" - set matvalueNode [$gNode selectNodes $xp2] - if {$matvalueNode ne ""} { - set real_material_name [write::getValueByNode $matvalueNode "force"] - set xp3 "[spdAux::getRoute $materials_un]/blockdata\[@n='material' and @name='$real_material_name']" - set matNode [$root selectNodes $xp3] - set s1 [join [list [$gNode selectNodes ".//value"] [$matNode selectNodes ".//value"]]] - } - } - - foreach valueNode $s1 { - write::forceUpdateNode $valueNode - set name [$valueNode getAttribute n] - set state [get_domnode_attribute $valueNode state] - if {$state ne "hidden" || $name eq "ConstitutiveLaw"} { - # All the introduced values are translated to 'm' and 'kg' with the help of this function - set value [gid_groups_conds::convert_value_to_default $valueNode] - dict set mat_dict $submodelpart_id $name $value - } - } } - } - if {!$processed} { + } + # Case A -> By parameters below parts + if {$output_type eq "Parameters"} { + set s1 [$gNode selectNodes ".//value"] + } else { + # Case B -> Include materials parameters set s1 "" set matvalueNode [$gNode selectNodes $xp2] if {$matvalueNode ne ""} { @@ -81,15 +76,20 @@ proc write::processMaterials { {alt_path ""} {last_assigned_id -1}} { set matNode [$root selectNodes $xp3] set s1 [join [list [$gNode selectNodes ".//value"] [$matNode selectNodes ".//value"]]] } - foreach valueNode $s1 { - write::forceUpdateNode $valueNode - set name [$valueNode getAttribute n] - set state [get_domnode_attribute $valueNode state] - if {$state ne "hidden" || $name eq "ConstitutiveLaw"} { - # All the introduced values are translated to 'm' and 'kg' with the help of this function - set value [gid_groups_conds::convert_value_to_default $valueNode] - dict set mat_dict $submodelpart_id $name $value - } + } + + # Once we have all the 'value' nodes, lets get it's value and add them to the list + foreach valueNode $s1 { + # Force update, useful in combo with part dependencies + write::forceUpdateNode $valueNode + # name and state, useful for filtering + set name [$valueNode getAttribute n] + set state [get_domnode_attribute $valueNode state] + # hidden values and constitutive law are not included in properties + if {$state ne "hidden" || $name eq "ConstitutiveLaw"} { + # All the introduced values are translated to 'm' and 'kg' with the help of this function + set value [gid_groups_conds::convert_value_to_default $valueNode] + dict set mat_dict $submodelpart_id $name $value } } dict set new_mats $submodelpart_id [dict get $mat_dict $submodelpart_id] From 56ba5b05600d637a698e4a3f547594459ae6e914 Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Tue, 17 Aug 2021 23:03:50 +0200 Subject: [PATCH 08/15] fix matrix display --- kratos.gid/scripts/Controllers/TreeInjections.tcl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kratos.gid/scripts/Controllers/TreeInjections.tcl b/kratos.gid/scripts/Controllers/TreeInjections.tcl index 755709040..8801156db 100644 --- a/kratos.gid/scripts/Controllers/TreeInjections.tcl +++ b/kratos.gid/scripts/Controllers/TreeInjections.tcl @@ -381,9 +381,9 @@ proc spdAux::GetParameterValueString { param forcedParams base} { for {set i 0} {$i < [expr max($rows,$cols)]} {incr i} {lappend components $i}; set components [join $components ","] #append node "" set value [split $v ","] - append node "" - append node " " - append node " " + append node "" + append node " " + append node " " for {set i 0} {$i < $rows} {incr i} { for {set j 0} {$j < $cols} {incr j} { set vi [lindex $value [expr ($i*$cols)+$j] ] From 9e217cbe877b4153fe954892ac5c8e6e9296c95b Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Tue, 17 Aug 2021 23:04:08 +0200 Subject: [PATCH 09/15] prepare output structure for matrix --- kratos.gid/scripts/Writing/WriteMaterials.tcl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kratos.gid/scripts/Writing/WriteMaterials.tcl b/kratos.gid/scripts/Writing/WriteMaterials.tcl index dc4bca265..965531304 100644 --- a/kratos.gid/scripts/Writing/WriteMaterials.tcl +++ b/kratos.gid/scripts/Writing/WriteMaterials.tcl @@ -87,8 +87,22 @@ proc write::processMaterials { {alt_path ""} {last_assigned_id -1}} { set state [get_domnode_attribute $valueNode state] # hidden values and constitutive law are not included in properties if {$state ne "hidden" || $name eq "ConstitutiveLaw"} { - # All the introduced values are translated to 'm' and 'kg' with the help of this function - set value [gid_groups_conds::convert_value_to_default $valueNode] + if {[$valueNode hasAttribute type] && [$valueNode @type] eq "matrix"} { + set value [list ] + set M [gid_groups_conds::read_matrix_function $valueNode] + for {set i 0} {$i < [$valueNode @dimension_function_rows]} {incr i} { + set row [list ] + set cols [$valueNode @dimension_function_cols] + for {set j 0} {$j < $cols} {incr j} { + lappend row [lindex $M [expr ($i*$cols)+$j]] + } + lappend value $row + } + W $value + } else { + # All the introduced values are translated to 'm' and 'kg' with the help of this function + set value [gid_groups_conds::convert_value_to_default $valueNode] + } dict set mat_dict $submodelpart_id $name $value } } From 95e3e9ef5e41204d532ae9ab680dbe6ec126ee54 Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Thu, 19 Aug 2021 17:35:46 +0200 Subject: [PATCH 10/15] Stabilized matrix write --- kratos.gid/scripts/Writing/WriteMaterials.tcl | 3 +-- kratos.gid/scripts/Writing/WriteProjectParameters.tcl | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/kratos.gid/scripts/Writing/WriteMaterials.tcl b/kratos.gid/scripts/Writing/WriteMaterials.tcl index 965531304..a59e9899b 100644 --- a/kratos.gid/scripts/Writing/WriteMaterials.tcl +++ b/kratos.gid/scripts/Writing/WriteMaterials.tcl @@ -94,11 +94,10 @@ proc write::processMaterials { {alt_path ""} {last_assigned_id -1}} { set row [list ] set cols [$valueNode @dimension_function_cols] for {set j 0} {$j < $cols} {incr j} { - lappend row [lindex $M [expr ($i*$cols)+$j]] + lappend row [expr [lindex $M [expr ($i*$cols)+$j]]] } lappend value $row } - W $value } else { # All the introduced values are translated to 'm' and 'kg' with the help of this function set value [gid_groups_conds::convert_value_to_default $valueNode] diff --git a/kratos.gid/scripts/Writing/WriteProjectParameters.tcl b/kratos.gid/scripts/Writing/WriteProjectParameters.tcl index a17aee031..508022054 100644 --- a/kratos.gid/scripts/Writing/WriteProjectParameters.tcl +++ b/kratos.gid/scripts/Writing/WriteProjectParameters.tcl @@ -17,8 +17,10 @@ proc write::json2dict {JSONtext} { proc write::tcl2json { value } { # Guess the type of the value; deep *UNSUPPORTED* magic! # display the representation of a Tcl_Obj for debugging purposes. Do not base the behavior of any command on the results of this one; it does not conform to Tcl's value semantics! - regexp {^value is a (.*?) with a refcount} [::tcl::unsupported::representation $value] -> type + # regexp {^value is a (.*?) with a refcount} [::tcl::unsupported::representation $value] -> type + set type [GidUtils::GetInternalRepresentation $value] if {$value eq ""} {return [json::write array {*}[lmap v $value {tcl2json $v}]]} + if {$type ne "dict" && [llength $value]>1} { set type list} switch $type { string { if {$value eq "false"} {return [expr "false"]} @@ -454,7 +456,7 @@ proc write::GetDefaultGiDOutput { {appid ""} } { dict set outputConfigDict python_module gid_output_process dict set outputConfigDict kratos_module KratosMultiphysics dict set outputConfigDict process_name GiDOutputProcess - dict set outputConfigDict help "This process writes postprocessing files for GiD" + # dict set outputConfigDict help "This process writes postprocessing files for GiD" dict set outputConfigDict Parameters $outputProcessParams return $outputConfigDict @@ -510,7 +512,7 @@ proc write::GetDefaultVTKOutput { {appid ""} } { dict set outputConfigDictVtk python_module vtk_output_process dict set outputConfigDictVtk kratos_module KratosMultiphysics dict set outputConfigDictVtk process_name VtkOutputProcess - dict set outputConfigDictVtk help "This process writes postprocessing files for Paraview" + #dict set outputConfigDictVtk help "This process writes postprocessing files for Paraview" dict set outputConfigDictVtk Parameters [write::GetDefaultParametersOutputVTKDict $appid] return $outputConfigDictVtk From e07e0724e7d82f4ab520de5aa70ec06ca4fe0b29 Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Tue, 8 Feb 2022 22:02:41 +0100 Subject: [PATCH 11/15] sin inventos --- .../Writing/WriteProjectParameters.tcl | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/kratos.gid/scripts/Writing/WriteProjectParameters.tcl b/kratos.gid/scripts/Writing/WriteProjectParameters.tcl index 7805fc221..ceebbfcc8 100644 --- a/kratos.gid/scripts/Writing/WriteProjectParameters.tcl +++ b/kratos.gid/scripts/Writing/WriteProjectParameters.tcl @@ -20,7 +20,7 @@ proc write::tcl2json { value } { # regexp {^value is a (.*?) with a refcount} [::tcl::unsupported::representation $value] -> type set type [GidUtils::GetInternalRepresentation $value] if {$value eq ""} {return [json::write array {*}[lmap v $value {tcl2json $v}]]} - if {$type ne "dict" && [llength $value]>1} { set type list} + # if {$type ne "dict" && [llength $value]>1} { set type list} switch $type { string { if {$value eq "false"} {return [expr "false"]} @@ -124,14 +124,14 @@ proc write::GetCutPlanesList { {cut_planes_UN CutPlanes} } { } proc write::GetCutPlanesByXPathList { xpath } { - + set root [customlib::GetBaseRoot] - + set list_of_planes [list ] - + set xp1 "$xpath/blockdata" set planes [$root selectNodes $xp1] - + foreach plane $planes { set pdict [dict create] set points [split [get_domnode_attribute [$plane firstChild] v] ","] @@ -175,7 +175,7 @@ proc write::getSolutionStrategyParametersDict { {solStratUN ""} {schemeUN ""} {S set schemeName [write::getValue $schemeUN "" force] set sol [::Model::GetSolutionStrategy $solstratName] set sch [$sol getScheme $schemeName] - + set solverSettingsDict [dict create] foreach {n in} [$sol getInputs] { dict set solverSettingsDict $n [write::getValue $StratParamsUN $n force] @@ -225,11 +225,11 @@ proc write::getSolversParametersDict { {appid ""} } { } proc write::getConditionsParametersDict {un {condition_type "Condition"}} { - + set root [customlib::GetBaseRoot] set bcCondsList [list ] set grouped_conditions [list ] - + set xp1 "[spdAux::getRoute $un]/condition/group" set groups [$root selectNodes $xp1] if {$groups eq ""} { @@ -260,44 +260,44 @@ proc write::getConditionsParametersDict {un {condition_type "Condition"}} { set process [::Model::GetProcess $processName] set processDict [dict create] set processWriteCommand [$process getAttribute write_command] - + dict set processDict process_name $processName - + if {$processWriteCommand eq ""} { set processDict [write::GetProcessHeader $group $process $condition $groupId] - + set process_parameters [$process getInputs] foreach {inputName in_obj} $process_parameters { dict set processDict Parameters $inputName [write::GetInputValue $group $in_obj] } - + } else { set processDict [$processWriteCommand $group $condition $process] } lappend bcCondsList $processDict } } - + foreach cid $grouped_conditions { if {$condition_type eq "Condition"} { set condition [::Model::getCondition $cid] } { set condition [::Model::getNodalConditionbyId $cid] } - + set processName [$condition getProcessName] set process [::Model::GetProcess $processName] set processDict [dict create] set paramDict [dict create] dict set paramDict model_part_name [write::GetModelPartNameWithParent $cid] - + set process_attributes [$process getAttributes] set process_parameters [$process getInputs] - + dict set process_attributes process_name [dict get $process_attributes n] dict unset process_attributes n dict unset process_attributes pn - + set processDict [dict merge $processDict $process_attributes] if {[$condition hasAttribute VariableName]} { set variable_name [$condition getAttribute VariableName] @@ -311,15 +311,15 @@ proc write::getConditionsParametersDict {un {condition_type "Condition"}} { } proc write::GetResultsList { un {cnd ""} } { - + if {$cnd eq ""} {set xp1 [spdAux::getRoute $un]} {set xp1 "[spdAux::getRoute $un]/container\[@n = '$cnd'\]"} return [GetResultsByXPathList $xp1] } proc write::GetResultsByXPathList { xpath } { - + set root [customlib::GetBaseRoot] - + set result [list ] set xp1 "$xpath/value" set resultxml [$root selectNodes $xp1] @@ -337,10 +337,10 @@ proc write::GetResultsByXPathList { xpath } { proc write::getAllMaterialParametersDict {matname} { set root [customlib::GetBaseRoot] set md [dict create] - + set xp3 [spdAux::getRoute [GetConfigurationAttribute materials_un]] append xp3 [format_xpath {/blockdata[@n="material" and @name=%s]/value} $matname] - + set props [$root selectNodes $xp3] foreach prop $props { dict set md [$prop @n] [get_domnode_attribute $prop v] @@ -350,7 +350,7 @@ proc write::getAllMaterialParametersDict {matname} { proc write::getIntervalsDict { { un "Intervals" } {appid "" } } { set root [customlib::GetBaseRoot] - + set intervalsDict [dict create] set xp3 "[spdAux::getRoute $un]/blockdata\[@n='Interval'\]" if {$xp3 ne ""} { @@ -397,27 +397,27 @@ proc write::GetModelPartNameWithParent { child_name {forced_parent ""}} { } proc write::GetDefaultProblemDataDict { {appid ""} } { - + # Get the results unique name. appid parameter is usefull for multiple inheritance app with more than 1 results section if {$appid eq ""} {set results_UN Results } {set results_UN [GetConfigurationAttribute results_un]} - + # Problem name set problem_data_dict [dict create] set model_name [Kratos::GetModelName] dict set problem_data_dict problem_name $model_name - + # Parallelization set paralleltype [write::getValue ParallelType] dict set problem_data_dict "parallel_type" $paralleltype - + # Write the echo level in the problem data section set echo_level [write::getValue $results_UN EchoLevel] dict set problem_data_dict echo_level $echo_level - + # Time Parameters dict set problem_data_dict start_time [write::getValue [GetConfigurationAttribute time_parameters_un] StartTime] dict set problem_data_dict end_time [write::getValue [GetConfigurationAttribute time_parameters_un] EndTime] - + return $problem_data_dict } @@ -428,24 +428,24 @@ proc write::GetDefaultOutputProcessDict { {appid ""} } { if {[write::isBooleanTrue $need_gid]} { lappend gid_output_process_list [write::GetDefaultGiDOutput $appid] } - + set vtk_output_process_list [list ] set need_vtk [write::getValue EnableVtkOutput] if {[write::isBooleanTrue $need_vtk]} { lappend vtk_output_process_list [write::GetDefaultVTKOutput $appid] } - + set outputProcessesDict [dict create] dict set outputProcessesDict gid_output $gid_output_process_list dict set outputProcessesDict vtk_output $vtk_output_process_list - + return $outputProcessesDict } proc write::GetDefaultGiDOutput { {appid ""} } { # prepare params set model_name [Kratos::GetModelName] - + # Setup GiD-Output set outputProcessParams [dict create] dict set outputProcessParams model_part_name [write::GetModelPartNameWithParent [GetConfigurationAttribute output_model_part_name]] @@ -453,21 +453,21 @@ proc write::GetDefaultGiDOutput { {appid ""} } { set folder_name [dict get $outputProcessParams postprocess_parameters folder_name] dict unset outputProcessParams postprocess_parameters folder_name dict set outputProcessParams output_name [file join $folder_name $model_name] - + set outputConfigDict [dict create] dict set outputConfigDict python_module gid_output_process dict set outputConfigDict kratos_module KratosMultiphysics dict set outputConfigDict process_name GiDOutputProcess # dict set outputConfigDict help "This process writes postprocessing files for GiD" dict set outputConfigDict Parameters $outputProcessParams - + return $outputConfigDict } proc write::GetDefaultOutputGiDDict { {appid ""} {gid_options_xpath ""} } { set outputDict [dict create] set resultDict [dict create] - + if {$appid eq ""} {set results_UN Results } {set results_UN [apps::getAppUniqueName $appid Results]} if {$gid_options_xpath eq ""} {set gid_options_xpath "[spdAux::getRoute $results_UN]/container\[@n='GiDOutput'\]/container\[@n='GiDOptions'\]"} set GiDPostDict [dict create] @@ -476,7 +476,7 @@ proc write::GetDefaultOutputGiDDict { {appid ""} {gid_options_xpath ""} } { dict set GiDPostDict WriteConditionsFlag [getValueByXPath $gid_options_xpath GiDWriteConditionsFlag] dict set GiDPostDict MultiFileFlag [getValueByXPath $gid_options_xpath GiDMultiFileFlag] dict set resultDict gidpost_flags $GiDPostDict - + dict set resultDict file_label [getValueByXPath $gid_options_xpath FileLabel] set outputCT [getValueByXPath $gid_options_xpath OutputControlType] dict set resultDict output_control_type $outputCT @@ -486,11 +486,11 @@ proc write::GetDefaultOutputGiDDict { {appid ""} {gid_options_xpath ""} } { set frequency [getValueByXPath $gid_options_xpath OutputDeltaStep] } dict set resultDict output_interval $frequency - + dict set resultDict body_output [getValueByXPath $gid_options_xpath BodyOutput] dict set resultDict node_output [getValueByXPath $gid_options_xpath NodeOutput] dict set resultDict skin_output [getValueByXPath $gid_options_xpath SkinOutput] - + set gid_cut_planes_xpath "[spdAux::getRoute $results_UN]/container\[@n='GiDOutput'\]/container\[@n='CutPlanes'\]" dict set resultDict plane_output [GetCutPlanesByXPathList $gid_cut_planes_xpath] set gid_nodes_xpath "[spdAux::getRoute $results_UN]/container\[@n='OnNodes'\]" @@ -498,19 +498,19 @@ proc write::GetDefaultOutputGiDDict { {appid ""} {gid_options_xpath ""} } { set gid_elements_xpath "[spdAux::getRoute $results_UN]/container\[@n='OnElement'\]" dict set resultDict gauss_point_results [GetResultsByXPathList $gid_elements_xpath] dict set resultDict nodal_nonhistorical_results [list ] - + dict set outputDict "result_file_configuration" $resultDict dict set outputDict "point_data_configuration" [GetEmptyList] - + dict set outputDict folder_name [getValueByXPath $gid_options_xpath FolderName] return $outputDict } proc write::GetDefaultVTKOutput { {appid ""} } { - + # prepare params set model_name [Kratos::GetModelName] - + # Setup Vtk-Output set outputConfigDictVtk [dict create] dict set outputConfigDictVtk python_module vtk_output_process @@ -518,17 +518,17 @@ proc write::GetDefaultVTKOutput { {appid ""} } { dict set outputConfigDictVtk process_name VtkOutputProcess #dict set outputConfigDictVtk help "This process writes postprocessing files for Paraview" dict set outputConfigDictVtk Parameters [write::GetDefaultParametersOutputVTKDict $appid] - + return $outputConfigDictVtk } proc write::GetDefaultParametersOutputVTKDict { {appid ""} } { set resultDict [dict create] dict set resultDict model_part_name [write::GetModelPartNameWithParent [GetConfigurationAttribute output_model_part_name]] - + if {$appid eq ""} {set results_UN Results } {set results_UN [apps::getAppUniqueName $appid Results]} set vtk_options_xpath "[spdAux::getRoute $results_UN]/container\[@n='VtkOutput'\]/container\[@n='VtkOptions'\]" - + # manually selecting step, otherwise Paraview won't group the results set outputCT [getValueByXPath $vtk_options_xpath OutputControlType] dict set resultDict output_control_type $outputCT @@ -544,12 +544,12 @@ proc write::GetDefaultParametersOutputVTKDict { {appid ""} } { dict set resultDict element_data_value_variables [list ] dict set resultDict condition_data_value_variables [list ] dict set resultDict gauss_point_variables_extrapolated_to_nodes [GetResultsList $results_UN OnElement] - + return $resultDict } proc write::GetDefaultRestartDict { } { - + set restartDict [dict create] dict set restartDict SaveRestart False dict set restartDict RestartFrequency 0 @@ -561,23 +561,23 @@ proc write::GetDefaultRestartDict { } { proc write::GetTimeStepIntervals { {time_parameters_un ""} } { if {$time_parameters_un eq ""} {set time_parameters_un [GetConfigurationAttribute time_parameters_un]} set root [customlib::GetBaseRoot] - + set xp "[spdAux::getRoute $time_parameters_un]/container\[@n = 'TimeStep'\]/blockdata" set time_step_interval_nodes [$root selectNodes $xp] - + # If the app is still working on fixed Delta time if {[llength $time_step_interval_nodes] eq 0} {return [write::getValue $time_parameters_un DeltaTime]} - + # If it works with interval delta time set time_step_intervals_list [list ] foreach time_step_interval_node $time_step_interval_nodes { set time_step_interval_start_time [write::getValueByNode [$time_step_interval_node find n StartTime]] set time_step_interval_delta_time [write::getValueByNode [$time_step_interval_node find n DeltaTime]] - + set key_value [list $time_step_interval_start_time $time_step_interval_delta_time] lappend time_step_intervals_list $key_value } - + set time_step_intervals_list [lsort -real -index 0 $time_step_intervals_list] return $time_step_intervals_list } \ No newline at end of file From e8ef87029a1658d2233b688b240c2f48c21b550b Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Tue, 8 Feb 2022 22:10:36 +0100 Subject: [PATCH 12/15] remove value in matrix --- kratos.gid/apps/FluidDEM/write/write.tcl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kratos.gid/apps/FluidDEM/write/write.tcl b/kratos.gid/apps/FluidDEM/write/write.tcl index 519d865d1..fa01fbbad 100644 --- a/kratos.gid/apps/FluidDEM/write/write.tcl +++ b/kratos.gid/apps/FluidDEM/write/write.tcl @@ -89,6 +89,8 @@ proc FluidDEM::write::writeFluidModifiedMaterials {fluid_materials_json} { dict unset property Material Variables PERMEABILITY_22; dict unset property Material Variables PERMEABILITY_23 dict unset property Material Variables PERMEABILITY_33 dict set property Material Variables PERMEABILITY [list $permeability_1 $permeability_2 $permeability_3] + + if {[dict exists $property Material Variables value]} {dict unset property Material Variables value} } dict lappend new_json properties $property } From e50a3f5947781ecdfe8294247334269a4f9d7de6 Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Wed, 9 Feb 2022 14:38:54 +0100 Subject: [PATCH 13/15] permeability print --- kratos.gid/apps/FluidDEM/write/write.tcl | 21 ++++++++++++++----- kratos.gid/kratos.tcl | 1 + kratos.gid/scripts/Utils.tcl | 2 +- .../Writing/WriteProjectParameters.tcl | 13 +++++------- kratos.gid/scripts/Writing/Writing.tcl | 21 +++++++++++++++++++ 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/kratos.gid/apps/FluidDEM/write/write.tcl b/kratos.gid/apps/FluidDEM/write/write.tcl index fa01fbbad..3056c8014 100644 --- a/kratos.gid/apps/FluidDEM/write/write.tcl +++ b/kratos.gid/apps/FluidDEM/write/write.tcl @@ -80,16 +80,27 @@ proc Fluid::write::getFluidModelPartFilename { } { proc FluidDEM::write::writeFluidModifiedMaterials {fluid_materials_json} { set new_json [dict create] + foreach property [dict get $fluid_materials_json properties] { - if {[dict exists $property Material Variables PERMEABILITY_11]} { - set permeability_1 [list [dict get $property Material Variables PERMEABILITY_11] [dict get $property Material Variables PERMEABILITY_12] [dict get $property Material Variables PERMEABILITY_13]] - set permeability_2 [list [dict get $property Material Variables PERMEABILITY_12] [dict get $property Material Variables PERMEABILITY_22] [dict get $property Material Variables PERMEABILITY_23]] - set permeability_3 [list [dict get $property Material Variables PERMEABILITY_13] [dict get $property Material Variables PERMEABILITY_23] [dict get $property Material Variables PERMEABILITY_33]] + if {[dict exists $property Material Variables PERMEABILITY]} { + set permeability [dict get $property Material Variables PERMEABILITY] + + set p11 [expr [lindex $permeability 0 0]] + set p12 [expr [lindex $permeability 0 1]] + set p13 [expr [lindex $permeability 0 2]] + set p21 [expr [lindex $permeability 1 0]] + set p22 [expr [lindex $permeability 1 1]] + set p23 [expr [lindex $permeability 1 2]] + set p31 [expr [lindex $permeability 2 0]] + set p32 [expr [lindex $permeability 2 1]] + set p33 [expr [lindex $permeability 2 2]] + set permeability_1 [list $p11 $p12 $p13] + set permeability_2 [list $p21 $p22 $p23] + set permeability_3 [list $p31 $p32 $p33] dict unset property Material Variables PERMEABILITY_11; dict unset property Material Variables PERMEABILITY_12; dict unset property Material Variables PERMEABILITY_13 dict unset property Material Variables PERMEABILITY_22; dict unset property Material Variables PERMEABILITY_23 dict unset property Material Variables PERMEABILITY_33 dict set property Material Variables PERMEABILITY [list $permeability_1 $permeability_2 $permeability_3] - if {[dict exists $property Material Variables value]} {dict unset property Material Variables value} } dict lappend new_json properties $property diff --git a/kratos.gid/kratos.tcl b/kratos.gid/kratos.tcl index 80fee738f..78a1bfdeb 100644 --- a/kratos.gid/kratos.tcl +++ b/kratos.gid/kratos.tcl @@ -523,6 +523,7 @@ proc Kratos::Event_AfterWriteCalculationFile { filename errorflag } { } proc Kratos::WriteCalculationFilesEvent { {filename ""} } { + # W "Kratos::WriteCalculationFilesEvent" # Write the calculation files (mdpa, json...) if {$filename eq ""} { # Model must be saved diff --git a/kratos.gid/scripts/Utils.tcl b/kratos.gid/scripts/Utils.tcl index 9452a5f03..6f36acb72 100644 --- a/kratos.gid/scripts/Utils.tcl +++ b/kratos.gid/scripts/Utils.tcl @@ -162,7 +162,7 @@ proc Kratos::RegisterEnvironment { } { if {[llength [dict keys $preferences]] > 0} { set fp [open [Kratos::GetPreferencesFilePath] w] - if {[catch {set data [puts $fp [write::tcl2json $preferences]]} ]} {W "Problems saving user prefecences"; W $data} + if {[catch {set data [puts $fp [write::tcl2json $preferences]]} ]} {W "Problems saving user prefecences"; W $preferences} close $fp } } diff --git a/kratos.gid/scripts/Writing/WriteProjectParameters.tcl b/kratos.gid/scripts/Writing/WriteProjectParameters.tcl index ceebbfcc8..a646385fd 100644 --- a/kratos.gid/scripts/Writing/WriteProjectParameters.tcl +++ b/kratos.gid/scripts/Writing/WriteProjectParameters.tcl @@ -20,15 +20,9 @@ proc write::tcl2json { value } { # regexp {^value is a (.*?) with a refcount} [::tcl::unsupported::representation $value] -> type set type [GidUtils::GetInternalRepresentation $value] if {$value eq ""} {return [json::write array {*}[lmap v $value {tcl2json $v}]]} - # if {$type ne "dict" && [llength $value]>1} { set type list} + #if {$type ne "dict" && [llength $value]>1 && [string index $value 0] eq "\{"} { W "$value as list"; set type list} + #if {$type eq "exprcode"} {set type list; W "$type -> $value"} switch $type { - string { - if {$value eq "false"} {return [expr "false"]} - if {$value eq "true"} {return [expr "true"]} - if {$value eq "null"} {return null} - if {$value eq "dictnull"} {return {{}}} - return [json::write string $value] - } dict { return [json::write object {*}[ dict map {k v} $value {tcl2json $v}]] @@ -57,11 +51,14 @@ proc write::tcl2json { value } { return [expr {$value}] } elseif {[string is boolean -strict $value]} { return [expr {$value ? "true" : "false"}] + } elseif {[string index $value 0] eq "\{"} { + return [json::write array {*}[lmap v $value {tcl2json $v}]] } return [json::write string $value] } } } + proc write::tcl2jsonstrings { value } { # Guess the type of the value; deep *UNSUPPORTED* magic! # display the representation of a Tcl_Obj for debugging purposes. Do not base the behavior of any command on the results of this one; it does not conform to Tcl's value semantics! diff --git a/kratos.gid/scripts/Writing/Writing.tcl b/kratos.gid/scripts/Writing/Writing.tcl index e9bb64f2b..cc7e97d3a 100644 --- a/kratos.gid/scripts/Writing/Writing.tcl +++ b/kratos.gid/scripts/Writing/Writing.tcl @@ -118,11 +118,26 @@ proc write::writeEvent { filename } { Kratos::Log "Write validation $appid" set errcode [writeValidateInApp $appid] + + set endtime [clock seconds] + set ttime [expr {$endtime-$inittime}] + if {$time_monitor} { + W "Validate time: [Kratos::Duration $ttime]" + } + #### MDPA Write #### if {$errcode eq 0} { Kratos::Log "Write MDPA $appid" set errcode [writeAppMDPA $appid] } + + + set endtime [clock seconds] + set ttime [expr {$endtime-$inittime}] + if {$time_monitor} { + W "MDPA time: [Kratos::Duration $ttime]" + } + #### Project Parameters Write #### set wevent [$activeapp getWriteParametersEvent] set filename "ProjectParameters.json" @@ -132,6 +147,12 @@ proc write::writeEvent { filename } { set errcode [write::singleFileEvent $filename $wevent "Project Parameters"] } + set endtime [clock seconds] + set ttime [expr {$endtime-$inittime}] + if {$time_monitor} { + W "Parameters time: [Kratos::Duration $ttime]" + } + #### Custom files block #### set wevent [$activeapp getWriteCustomEvent] set filename "" From 207d2423354af1ff4b7f5eeddd20ce3f0f3d8fd3 Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Wed, 9 Feb 2022 17:00:21 +0100 Subject: [PATCH 14/15] bring back the null and dictnull --- kratos.gid/scripts/Writing/WriteProjectParameters.tcl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kratos.gid/scripts/Writing/WriteProjectParameters.tcl b/kratos.gid/scripts/Writing/WriteProjectParameters.tcl index a646385fd..ef995179f 100644 --- a/kratos.gid/scripts/Writing/WriteProjectParameters.tcl +++ b/kratos.gid/scripts/Writing/WriteProjectParameters.tcl @@ -23,6 +23,11 @@ proc write::tcl2json { value } { #if {$type ne "dict" && [llength $value]>1 && [string index $value 0] eq "\{"} { W "$value as list"; set type list} #if {$type eq "exprcode"} {set type list; W "$type -> $value"} switch $type { + string { + if {$value eq "null"} {return null} + if {$value eq "dictnull"} {return {{}}} + return [json::write string $value] + } dict { return [json::write object {*}[ dict map {k v} $value {tcl2json $v}]] From 61aed48843bf0ac4de808c25bea5d699d761d26d Mon Sep 17 00:00:00 2001 From: Javi Garate Date: Wed, 9 Feb 2022 17:02:46 +0100 Subject: [PATCH 15/15] typo --- kratos.gid/scripts/Utils.tcl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kratos.gid/scripts/Utils.tcl b/kratos.gid/scripts/Utils.tcl index 6f36acb72..55f24f694 100644 --- a/kratos.gid/scripts/Utils.tcl +++ b/kratos.gid/scripts/Utils.tcl @@ -199,10 +199,7 @@ proc Kratos::LoadEnvironment { } { # W $data # Close the file close $fp -<<<<<<< HEAD -======= - ->>>>>>> master + # Preferences are written in json format foreach {k v} [write::json2dict $data] { # W "$k $v"