@@ -31,7 +31,8 @@ proc DEM::write::WriteMDPAParts { } {
3131
3232 # SubmodelParts
3333 write::writePartSubModelPart
34- writeVelocityMeshes
34+ if {$::Model::SpatialDimension eq " 2D" } { writeVelocityMeshes2D
35+ } else {writeVelocityMeshes}
3536
3637 # CustomSubmodelParts
3738 # WriteWallCustomDEMSmp not required for dem.
@@ -292,18 +293,135 @@ proc DEM::write::writeVelocityMeshes { } {
292293}
293294
294295
296+ proc DEM::write::writeVelocityMeshes2D { } {
297+ set i 0
298+ foreach {cond group_list} [GetSpheresGroupsListInConditions] {
299+ if {$cond eq " DEM-VelocityBC2D" } {
300+ set cnd [Model::getCondition $cond ]
301+ foreach group $group_list {
302+ incr i
303+ write::WriteString " Begin SubModelPart $i // GUI DEM-VelocityBC - $cond - group identifier: $group "
304+ write::WriteString " Begin SubModelPartData // DEM-VelocityBC. Group name: $group "
305+ set xp1 " [ spdAux::getRoute [GetAttribute conditions_un] ]/condition\[ @n = '$cond '\] /group\[ @n = '$group '\] "
306+ set group_node [[customlib::GetBaseRoot] selectNodes $xp1 ]
307+
308+ set prescribeMotion_flag [write::getValueByNode [$group_node selectNodes " ./value\[ @n='PrescribeMotion_flag'\] " ]]
309+ if {[write::isBooleanTrue $prescribeMotion_flag ]} {
310+
311+ # Linear velocity
312+ set velocity [write::getValueByNode [$group_node selectNodes " ./value\[ @n='VelocityModulus'\] " ]]
313+ lassign [write::getValueByNode [$group_node selectNodes " ./value\[ @n='DirectionVector'\] " ]] velocity_X velocity_Y
314+ lassign [MathUtils::VectorNormalized [list $velocity_X $velocity_Y ]] velocity_X velocity_Y
315+ lassign [MathUtils::ScalarByVectorProd $velocity [list $velocity_X $velocity_Y ] ] vx vy
316+ write::WriteString " LINEAR_VELOCITY \[ 3\] ($vx , $vy , 0.0)"
317+
318+ # Period
319+ set periodic [write::getValueByNode [$group_node selectNodes " ./value\[ @n='LinearPeriodic'\] " ]]
320+ if {[write::isBooleanTrue $periodic ]} {
321+ set period [write::getValueByNode [$group_node selectNodes " ./value\[ @n='LinearPeriod'\] " ]]
322+ } else {
323+ set period 0.0
324+ }
325+ write::WriteString " VELOCITY_PERIOD $period "
326+
327+ # Angular velocity
328+ set avelocity [write::getValueByNode [$group_node selectNodes " ./value\[ @n='AngularVelocityModulus'\] " ]]
329+ write::WriteString " ANGULAR_VELOCITY \[ 3\] (0.0,0.0,$avelocity )"
330+
331+ # Angular center of rotation
332+ lassign [write::getValueByNode [$group_node selectNodes " ./value\[ @n='CenterOfRotation'\] " ]] oX oY
333+ write::WriteString " ROTATION_CENTER \[ 3\] ($oX ,$oY ,0.0)"
334+
335+ # Angular Period
336+ set angular_periodic [write::getValueByNode [$group_node selectNodes " ./value\[ @n='AngularPeriodic'\] " ]]
337+ if {[write::isBooleanTrue $angular_periodic ]} {
338+ set angular_period [write::getValueByNode [$group_node selectNodes " ./value\[ @n='AngularPeriod'\] " ]]
339+ } else {
340+ set angular_period 0.0
341+ }
342+ write::WriteString " ANGULAR_VELOCITY_PERIOD $angular_period "
343+
344+ # set intervals
345+ set LinearStartTime [write::getValueByNode [$group_node selectNodes " ./value\[ @n='LinearStartTime'\] " ]]
346+ set LinearEndTime [write::getValueByNode [$group_node selectNodes " ./value\[ @n='LinearEndTime'\] " ]]
347+ set AngularStartTime [write::getValueByNode [$group_node selectNodes " ./value\[ @n='AngularStartTime'\] " ]]
348+ set AngularEndTime [write::getValueByNode [$group_node selectNodes " ./value\[ @n='AngularEndTime'\] " ]]
349+ write::WriteString " VELOCITY_START_TIME $LinearStartTime "
350+ write::WriteString " VELOCITY_STOP_TIME $LinearEndTime "
351+ write::WriteString " ANGULAR_VELOCITY_START_TIME $AngularStartTime "
352+ write::WriteString " ANGULAR_VELOCITY_STOP_TIME $AngularEndTime "
353+
354+ # Interval. # TODO, able to assign intervals as start and end time. Both linear and angular could be different
355+ # set interval [write::getValueByNode [$group_node selectNodes "./value\[@n='Interval'\]"]]
356+ # lassign [write::getInterval $interval] ini end
357+ # if {![string is double $ini]} {
358+ # set ini [write::getValue DEMTimeParameters StartTime]
359+ # }
360+ # write::WriteString " ${cond}_START_TIME $ini"
361+ # if {![string is double $end]} {
362+ # set end [write::getValue DEMTimeParameters EndTime]
363+ # }
364+ # write::WriteString " ${cond}_STOP_TIME $end"
365+ }
366+
367+ write::WriteString " End SubModelPartData"
368+ write::WriteString " Begin SubModelPartNodes"
369+ GiD_WriteCalculationFile nodes -sorted [dict create [write::GetWriteGroupName $group ] [subst " %10i\n " ]]
370+ write::WriteString " End SubModelPartNodes"
371+ write::WriteString " End SubModelPart"
372+ write::WriteString " "
373+ }
374+ } elseif {$cond eq " DEM-VelocityIC2D" } {
375+ set cnd [Model::getCondition $cond ]
376+ foreach group $group_list {
377+ incr i
378+ write::WriteString " Begin SubModelPart $i // GUI DEM-VelocityIC - $cond - group identifier: $group "
379+ write::WriteString " Begin SubModelPartData // DEM-VelocityIC. Group name: $group "
380+ set xp1 " [ spdAux::getRoute [GetAttribute conditions_un] ]/condition\[ @n = '$cond '\] /group\[ @n = '$group '\] "
381+ set group_node [[customlib::GetBaseRoot] selectNodes $xp1 ]
382+
383+ set prescribeMotion_flag [write::getValueByNode [$group_node selectNodes " ./value\[ @n='PrescribeMotion_flag'\] " ]]
384+ if {[write::isBooleanTrue $prescribeMotion_flag ]} {
385+
386+ # Linear velocity
387+ set velocity [write::getValueByNode [$group_node selectNodes " ./value\[ @n='InitialVelocityModulus'\] " ]]
388+ lassign [write::getValueByNode [$group_node selectNodes " ./value\[ @n='iDirectionVector'\] " ]] velocity_X velocity_Y
389+ lassign [MathUtils::VectorNormalized [list $velocity_X $velocity_Y ]] velocity_X velocity_Y
390+ lassign [MathUtils::ScalarByVectorProd $velocity [list $velocity_X $velocity_Y ] ] vx vy
391+ write::WriteString " INITIAL_VELOCITY_X_VALUE $vx "
392+ write::WriteString " INITIAL_VELOCITY_Y_VALUE $vy "
393+ write::WriteString " INITIAL_VELOCITY_Z_VALUE 0.0"
394+
395+ # Angular velocity
396+ set avelocity [write::getValueByNode [$group_node selectNodes " ./value\[ @n='InitialAngularVelocityModulus'\] " ]]
397+ write::WriteString " INITIAL_ANGULAR_VELOCITY_X_VALUE 0.0"
398+ write::WriteString " INITIAL_ANGULAR_VELOCITY_Y_VALUE 0.0"
399+ write::WriteString " INITIAL_ANGULAR_VELOCITY_Z_VALUE $avelocity "
400+ }
401+
402+ write::WriteString " End SubModelPartData"
403+ write::WriteString " Begin SubModelPartNodes"
404+ GiD_WriteCalculationFile nodes -sorted [dict create [write::GetWriteGroupName $group ] [subst " %10i\n " ]]
405+ write::WriteString " End SubModelPartNodes"
406+ write::WriteString " End SubModelPart"
407+ write::WriteString " "
408+ }
409+ }
410+ }
411+ }
412+
413+
295414proc DEM::write::GetSpheresGroupsListInConditions { } {
296415 set conds_groups_dict [dict create ]
297416 set groups [list ]
298-
299417 # Get all the groups with spheres
300418 foreach group [GetSpheresGroups] {
301- foreach surface [GiD_EntitiesGroups get $group elements] {
302- foreach involved_group [GiD_EntitiesGroups entity_groups elements $surface ] {
303- set involved_group_id [write::GetWriteGroupName $involved_group ]
304- if {$involved_group_id ni $groups } {lappend groups $involved_group_id }
305- }
306- }
419+ foreach surface [GiD_EntitiesGroups get $group elements] {
420+ foreach involved_group [GiD_EntitiesGroups entity_groups elements $surface ] {
421+ set involved_group_id [write::GetWriteGroupName $involved_group ]
422+ if {$involved_group_id ni $groups } {lappend groups $involved_group_id }
423+ }
424+ }
307425 }
308426
309427 # Find the relations condition -> group
@@ -321,12 +439,14 @@ proc DEM::write::GetSpheresGroupsListInConditions { } {
321439
322440proc DEM::write::GetSpheresGroups { } {
323441 set groups [list ]
324- set xp1 " [ spdAux::getRoute [GetAttribute conditions_un] ]/condition\[ @n = 'DEM-VelocityBC'\] /group"
442+ if {$::Model::SpatialDimension eq " 2D" } { set xp1 " [ spdAux::getRoute [GetAttribute conditions_un] ]/condition\[ @n = 'DEM-VelocityBC2D'\] /group"
443+ } else {set xp1 " [ spdAux::getRoute [GetAttribute conditions_un] ]/condition\[ @n = 'DEM-VelocityBC'\] /group" }
325444 foreach group [[customlib::GetBaseRoot] selectNodes $xp1 ] {
326445 set groupid [$group @n]
327446 lappend groups [write::GetWriteGroupName $groupid ]
328447 }
329- set xp2 " [ spdAux::getRoute [GetAttribute conditions_un] ]/condition\[ @n = 'DEM-VelocityIC'\] /group"
448+ if {$::Model::SpatialDimension eq " 2D" } { set xp2 " [ spdAux::getRoute [GetAttribute conditions_un] ]/condition\[ @n = 'DEM-VelocityIC2D'\] /group"
449+ } else {set xp2 " [ spdAux::getRoute [GetAttribute conditions_un] ]/condition\[ @n = 'DEM-VelocityIC'\] /group" }
330450 foreach group [[customlib::GetBaseRoot] selectNodes $xp2 ] {
331451 set groupid [$group @n]
332452 lappend groups [write::GetWriteGroupName $groupid ]
@@ -339,13 +459,33 @@ proc DEM::write::writeMaterialsParts { } {
339459 variable partsProperties
340460 set xp1 " [ spdAux::getRoute [GetAttribute conditions_un] ]/condition\[ @n = 'PartsCont'\] /group"
341461 set partsProperties $::write::mat_dict
342- set printable [list PARTICLE_DENSITY YOUNG_MODULUS POISSON_RATIO FRICTION COEFFICIENT_OF_RESTITUTION PARTICLE_MATERIAL ROLLING_FRICTION ROLLING_FRICTION_WITH_WALLS CONTACT_SIGMA_MIN CONTACT_TAU_ZERO CONTACT_INTERNAL_FRICC ConstitutiveLaw]
343- foreach group [dict keys $partsProperties ] {
462+ set printable [list PARTICLE_DENSITY \
463+ YOUNG_MODULUS \
464+ POISSON_RATIO \
465+ FRICTION \
466+ COEFFICIENT_OF_RESTITUTION \
467+ PARTICLE_MATERIAL \
468+ ROLLING_FRICTION \
469+ ROLLING_FRICTION_WITH_WALLS \
470+ CONTACT_SIGMA_MIN \
471+ CONTACT_TAU_ZERO \
472+ CONTACT_INTERNAL_FRICC \
473+ ConstitutiveLaw \
474+ SHEAR_ENERGY_COEF \
475+ LOOSE_MATERIAL_YOUNG_MODULUS \
476+ FRACTURE_ENERGY \
477+ INTERNAL_FRICTION_ANGLE]
478+
479+ foreach group [dict keys $partsProperties ] {
344480 write::WriteString " Begin Properties [ dict get $partsProperties $group MID] "
345481 foreach {prop val} [dict get $partsProperties $group ] {
346482 if {$prop in $printable } {
347483 if {$prop eq " ConstitutiveLaw" } {
348484 write::WriteString " DEM_CONTINUUM_CONSTITUTIVE_LAW_NAME $val "
485+ } elseif {$prop eq " FRICTION" } {
486+ set pi $MathUtils::PI
487+ set propvalue [expr {tan($val *$pi /180.0)}]
488+ write::WriteString " FRICTION $propvalue "
349489 } else {
350490 write::WriteString " $prop $val "
351491 }
0 commit comments