|
| 1 | +namespace eval ::ShallowWater::examples::DamBreak { |
| 2 | + namespace path ::ShallowWater::examples |
| 3 | + Kratos::AddNamespace [namespace current] |
| 4 | +} |
| 5 | + |
| 6 | +proc ::ShallowWater::examples::DamBreak::Init {args} { |
| 7 | + if {![Kratos::IsModelEmpty]} { |
| 8 | + set txt "We are going to draw the example geometry.\nDo you want to lose your previous work?" |
| 9 | + set retval [tk_messageBox -default ok -icon question -message $txt -type okcancel] |
| 10 | + if { $retval == "cancel" } { return } |
| 11 | + } |
| 12 | + DrawGeometry |
| 13 | + AssignGroups |
| 14 | + TreeAssignation |
| 15 | + |
| 16 | + GiD_Process 'Redraw |
| 17 | + GidUtils::UpdateWindow GROUPS |
| 18 | + GidUtils::UpdateWindow LAYER |
| 19 | + GiD_Process 'Zoom Frame |
| 20 | +} |
| 21 | + |
| 22 | +proc ::ShallowWater::examples::DamBreak::DrawGeometry {args} { |
| 23 | + Kratos::ResetModel |
| 24 | + GiD_Layers create main_layer |
| 25 | + GiD_Layers edit to_use main_layer |
| 26 | + |
| 27 | + # Geometry creation |
| 28 | + ## Points ## |
| 29 | + set coordinates_left [list 0 0 0 5 0 0 5 1 0 0 1 0] |
| 30 | + set geom_points_left [list ] |
| 31 | + foreach {x y z} $coordinates_left { |
| 32 | + lappend geom_points_left [GiD_Geometry create point append main_layer $x $y $z] |
| 33 | + } |
| 34 | + |
| 35 | + set coordinates_right [list 5 0 0 10 0 0 10 1 0 5 1 0] |
| 36 | + set geom_points_right [list ] |
| 37 | + foreach {x y z} $coordinates_right { |
| 38 | + lappend geom_points_right [GiD_Geometry create point append main_layer $x $y $z] |
| 39 | + } |
| 40 | + |
| 41 | + ## Lines ## |
| 42 | + set geom_lines_left [list ] |
| 43 | + set initial [lindex $geom_points_left 0] |
| 44 | + foreach point [lrange $geom_points_left 1 end] { |
| 45 | + lappend geom_lines_left [GiD_Geometry create line append stline main_layer $initial $point] |
| 46 | + set initial $point |
| 47 | + } |
| 48 | + lappend geom_lines_left [GiD_Geometry create line append stline main_layer $initial [lindex $geom_points_left 0]] |
| 49 | + |
| 50 | + set geom_lines_right [list ] |
| 51 | + set initial [lindex $geom_points_right 0] |
| 52 | + foreach point [lrange $geom_points_right 1 end] { |
| 53 | + lappend geom_lines_right [GiD_Geometry create line append stline main_layer $initial $point] |
| 54 | + set initial $point |
| 55 | + } |
| 56 | + lappend geom_lines_right [GiD_Geometry create line append stline main_layer $initial [lindex $geom_points_right 0]] |
| 57 | + |
| 58 | + ## Surface ## |
| 59 | + GiD_Process Mescape Geometry Create NurbsSurface {*}$geom_lines_left escape escape |
| 60 | + GiD_Process Mescape Geometry Create NurbsSurface {*}$geom_lines_right escape escape |
| 61 | + |
| 62 | + ## Remove the duplicated line |
| 63 | + GiD_Process Mescape Utilities Collapse model Yes |
| 64 | +} |
| 65 | + |
| 66 | +proc ::ShallowWater::examples::DamBreak::AssignGroups {args} { |
| 67 | + # Create and assign the groups |
| 68 | + GiD_Groups create Body |
| 69 | + GiD_Groups edit color Body "#26d1a8ff" |
| 70 | + GiD_EntitiesGroups assign Body surfaces {1 2} |
| 71 | + |
| 72 | + GiD_Groups create Reservoir |
| 73 | + GiD_Groups edit color Reservoir "#26d1a8ff" |
| 74 | + GiD_EntitiesGroups assign Reservoir surfaces 1 |
| 75 | + |
| 76 | + GiD_Groups create Channel |
| 77 | + GiD_Groups edit color Channel "#26d1a8ff" |
| 78 | + GiD_EntitiesGroups assign Channel surfaces 2 |
| 79 | + |
| 80 | + GiD_Groups create Walls |
| 81 | + GiD_Groups edit color Walls "#3b3b3bff" |
| 82 | + GiD_EntitiesGroups assign Walls lines {1 3 5 7} |
| 83 | + |
| 84 | + GiD_Groups create Left |
| 85 | + GiD_Groups edit color Left "#3b3b3bff" |
| 86 | + GiD_EntitiesGroups assign Left lines 4 |
| 87 | + |
| 88 | + GiD_Groups create Right |
| 89 | + GiD_Groups edit color Right "#3b3b3bff" |
| 90 | + GiD_EntitiesGroups assign Right lines 6 |
| 91 | +} |
| 92 | + |
| 93 | +proc ::ShallowWater::examples::DamBreak::TreeAssignation {args} { |
| 94 | + |
| 95 | + # Parts |
| 96 | + set parts [spdAux::getRoute "SWParts"] |
| 97 | + set part_node [customlib::AddConditionGroupOnXPath $parts Body] |
| 98 | + set props [list Element GENERIC_ELEMENT Material Concrete] |
| 99 | + spdAux::SetValuesOnBaseNode $part_node $props |
| 100 | + |
| 101 | + # Topography data |
| 102 | + set topography_conditions [spdAux::getRoute "SWTopographicData"] |
| 103 | + set topography_cond "$topography_conditions/condition\[@n='Topography'\]" |
| 104 | + set topography_node [customlib::AddConditionGroupOnXPath $topography_cond Body] |
| 105 | + $topography_node setAttribute ov surface |
| 106 | + set props [list value 0.0] |
| 107 | + spdAux::SetValuesOnBaseNode $topography_node $props |
| 108 | + |
| 109 | + # Initial conditions |
| 110 | + set initial_conditions [spdAux::getRoute "SWInitialConditions"] |
| 111 | + set initial_cond "$initial_conditions/condition\[@n='InitialWaterLevel'\]" |
| 112 | + spdAux::AddIntervalGroup Reservoir "Reservoir//Initial" |
| 113 | + set initial_node [customlib::AddConditionGroupOnXPath $initial_cond "Reservoir//Initial"] |
| 114 | + $initial_node setAttribute ov surface |
| 115 | + set props [list value 1.0 Interval Initial] |
| 116 | + spdAux::SetValuesOnBaseNode $initial_node $props |
| 117 | + |
| 118 | + spdAux::AddIntervalGroup Channel "Channel//Initial" |
| 119 | + set initial_node [customlib::AddConditionGroupOnXPath $initial_cond "Channel//Initial"] |
| 120 | + $initial_node setAttribute ov surface |
| 121 | + set props [list value 0.8 Interval Initial] |
| 122 | + spdAux::SetValuesOnBaseNode $initial_node $props |
| 123 | + |
| 124 | + # Conditions |
| 125 | + set boundary_conditions [spdAux::getRoute "SWConditions"] |
| 126 | + set flow_rate_cond "$boundary_conditions/condition\[@n='ImposedFlowRate'\]" |
| 127 | + spdAux::AddIntervalGroup Walls "Walls//Total" |
| 128 | + set flow_rate_node [customlib::AddConditionGroupOnXPath $flow_rate_cond "Walls//Total"] |
| 129 | + $flow_rate_node setAttribute ov line |
| 130 | + set props [list selector_component_X Not value_component_Y 0.0 selector_component_Z Not Interval Total] |
| 131 | + spdAux::SetValuesOnBaseNode $flow_rate_node $props |
| 132 | + |
| 133 | + spdAux::AddIntervalGroup Right "Right//Total" |
| 134 | + set flow_rate_node [customlib::AddConditionGroupOnXPath $flow_rate_cond "Right//Total"] |
| 135 | + $flow_rate_node setAttribute ov line |
| 136 | + set props [list value_component_X 0.0 selector_component_Y Not selector_component_Z Not Interval Total] |
| 137 | + spdAux::SetValuesOnBaseNode $flow_rate_node $props |
| 138 | + |
| 139 | + spdAux::AddIntervalGroup Left "Left//Total" |
| 140 | + set flow_rate_node [customlib::AddConditionGroupOnXPath $flow_rate_cond "Left//Total"] |
| 141 | + $flow_rate_node setAttribute ov line |
| 142 | + set props [list value_component_X 0.0 selector_component_Y Not selector_component_Z Not Interval Total] |
| 143 | + spdAux::SetValuesOnBaseNode $flow_rate_node $props |
| 144 | + |
| 145 | + # Time parameters |
| 146 | + set parameters [list EndTime 2.0] |
| 147 | + set xpath [spdAux::getRoute "SWTimeParameters"] |
| 148 | + spdAux::SetValuesOnBasePath $xpath $parameters |
| 149 | + |
| 150 | + # Output |
| 151 | + set parameters [list OutputControlType time OutputDeltaTime 0.1] |
| 152 | + set xpath "[spdAux::getRoute Results]/container\[@n='GiDOutput'\]/container\[@n='GiDOptions'\]" |
| 153 | + spdAux::SetValuesOnBasePath $xpath $parameters |
| 154 | + |
| 155 | + # Refresh |
| 156 | + spdAux::RequestRefresh |
| 157 | +} |
0 commit comments