Skip to content

Commit

Permalink
Merge pull request #823 from KratosMultiphysics/swimming-dem-add-elem…
Browse files Browse the repository at this point in the history
…ent-parameters

SwimmingDEM add permeability
  • Loading branch information
jginternational authored Feb 9, 2022
2 parents 77ed742 + 61aed48 commit d8606ea
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 103 deletions.
5 changes: 5 additions & 0 deletions kratos.gid/apps/Fluid/write/write.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ proc ::Fluid::write::WriteMaterialsFile { {write_const_law True} {include_modelp
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 ""
Expand Down
37 changes: 34 additions & 3 deletions kratos.gid/apps/FluidDEM/write/write.tcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace eval ::FluidDEM::write {
namespace path ::FluidDEM
Kratos::AddNamespace [namespace current]

variable fluid_project_parameters
variable dem_project_parameters
}
Expand All @@ -19,7 +19,7 @@ proc ::FluidDEM::write::Init { } {
proc FluidDEM::write::writeModelPartEvent { } {
Validate
set filename [Kratos::GetModelName]

Fluid::write::Init
Fluid::write::InitConditionsMap
Fluid::write::SetCoordinatesByGroups 1
Expand Down Expand Up @@ -50,7 +50,7 @@ proc DEM::write::GetInletElementType {} {
}

proc FluidDEM::write::WriteMaterialsFile { } {
Fluid::write::WriteMaterialsFile True
FluidDEM::write::writeFluidModifiedMaterials [Fluid::write::GetMaterialsFile True]
DEM::write::writeMaterialsFile
}

Expand Down Expand Up @@ -78,3 +78,34 @@ 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]} {
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
}
write::writePropertiesJsonFileDone [Fluid::write::GetAttribute materials_file] $new_json
}

FluidDEM::write::Init
8 changes: 5 additions & 3 deletions kratos.gid/apps/FluidDEM/xml/Elements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
<NodalConditions></NodalConditions>
<inputs>
<parameter n="Material" pn="Material" v="" type="combo" combotype="material" help="Material"/>
</inputs>
</inputs>
<outputs></outputs>
</ElementItem>

<ElementItem n="QSVMSDEMcoupled3D" pn="QSVMS DEM coupled 3D" WriteName="qsvmsDEM" ImplementedInFile="qsvms_dem_coupled.cpp" ImplementedInApplication="SwimmingDEMApplication" MinimumKratosVersion="9000" ProductionReady="ProductionReady" WorkingSpaceDimension="3D" LocalSpaceDimension="3" RequiresLocalAxes="False" LargeDeformation="False" MainDofsVariables="VELOCITY" ElementType="Fluid" help="This element implements a fluid element using the QSVMS formulation to couple with solid particles" FormulationElementType="qsvms">
<ElementItem n="QSVMSDEMcoupled3D" pn="QSVMS DEM coupled 3D" WriteName="qsvmsDEM" ImplementedInFile="qsvms_dem_coupled.cpp" ImplementedInApplication="SwimmingDEMApplication" MinimumKratosVersion="9000" ProductionReady="ProductionReady" WorkingSpaceDimension="3D" LocalSpaceDimension="3" RequiresLocalAxes="False" LargeDeformation="False" MainDofsVariables="VELOCITY" ElementType="Fluid" help="This element implements a fluid element using the QSVMS formulation to couple with solid particles" FormulationElementType="qsvms">

<!--here we could add a list of all of the possible geometries-->
<TopologyFeatures>
Expand All @@ -34,12 +34,13 @@
<NodalCondition n="PRESSURE"/>
</NodalConditions>
<inputs>
<parameter n="PERMEABILITY" pn="Permeability" v="1e+89,0.0,0.0,0.0,1e+89,0.0,0.0,0.0,1e+89" type="matrix" rows="3" cols="3" />
</inputs>
<outputs>
<parameter n="VORTICITY" pn="Vorticity" />
</outputs>
</ElementItem>
<ElementItem n="QSVMSDEMcoupled2D" pn="QSVMS DEM coupled 2D" WriteName="qsvmsDEM2D" ImplementedInFile="qsvms_dem_coupled.cpp" ImplementedInApplication="SwimmingDEMApplication" MinimumKratosVersion="9000" ProductionReady="ProductionReady" WorkingSpaceDimension="2D" LocalSpaceDimension="2" RequiresLocalAxes="False" LargeDeformation="False" MainDofsVariables="VELOCITY" ElementType="Fluid" help="This element implements a fluid element using the QSVMS formulation to coupled with solid particles" FormulationElementType="qsvms">
<ElementItem n="QSVMSDEMcoupled2D" pn="QSVMS DEM coupled 2D" WriteName="qsvmsDEM2D" ImplementedInFile="qsvms_dem_coupled.cpp" ImplementedInApplication="SwimmingDEMApplication" MinimumKratosVersion="9000" ProductionReady="ProductionReady" WorkingSpaceDimension="2D" LocalSpaceDimension="2" RequiresLocalAxes="False" LargeDeformation="False" MainDofsVariables="VELOCITY" ElementType="Fluid" help="This element implements a fluid element using the QSVMS formulation to coupled with solid particles" FormulationElementType="qsvms">

<!--here we could add a list of all of the possible geometries-->
<TopologyFeatures>
Expand All @@ -58,6 +59,7 @@
<NodalCondition n="PRESSURE"/>
</NodalConditions>
<inputs>
<parameter n="PERMEABILITY" pn="Permeability" v="1e+89,0.0,0.0,1e+89" type="matrix" rows="2" cols="2" />
</inputs>
<outputs>
<parameter n="VORTICITY" pn="Vorticity" />
Expand Down
1 change: 1 addition & 0 deletions kratos.gid/kratos.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions kratos.gid/scripts/Controllers/TreeInjections.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,27 @@ 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 "<value n='$inName' pn='$pn' v='$v' function='matrix_func,no_function' dimension_function_rows='$rows' dimension_function_cols='$cols' components_function='$components' help='$help' state='$state' show_in_window='$show_in_window' />"
set value [split $v ","]
append node "<value n='$inName' pn='$pn' function='matrix_func,no_function' symmetric_function='0' has_diag='1' dimension_function_rows='$rows' dimension_function_cols='$cols' v='f(Matrix value for $pn)...' components_function='$components' help='$help' tree_state='closed' type='matrix'>"
append node " <function>"
append node " <functionVariable n='matrix_func' pn='Matrix value for $pn'>"
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 " <value n='value' pn='V$i,$j' v='$vi'/>"
}
}
append node " </functionVariable>"
append node " </function>"
append node "</value>"

}
"combo" {
if {[$param getAttribute "combotype"] eq "material"} {
Expand Down
5 changes: 3 additions & 2 deletions kratos.gid/scripts/Utils.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -199,7 +199,7 @@ 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"
Expand Down Expand Up @@ -321,3 +321,4 @@ proc Kratos::IsDeveloperMode {} {
if {[info exists ::Kratos::kratos_private(DevMode)] && $::Kratos::kratos_private(DevMode) eq "dev"} {set is_dev 1}
return $is_dev
}

95 changes: 57 additions & 38 deletions kratos.gid/scripts/Writing/WriteMaterials.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 ""} {
Expand All @@ -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 ""} {
Expand All @@ -83,15 +78,33 @@ proc write::processMaterials { {alt_path ""} {last_assigned_id -1}} {
} else {
set s1 [$gNode 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"} {
}

# 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"} {
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 [expr [lindex $M [expr ($i*$cols)+$j]]]
}
lappend value $row
}
} 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
}
}
dict set mat_dict $submodelpart_id $name $value
}
}
dict set new_mats $submodelpart_id [dict get $mat_dict $submodelpart_id]
Expand Down Expand Up @@ -135,12 +148,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
}

Expand Down
Loading

0 comments on commit d8606ea

Please sign in to comment.