Skip to content

Commit d43faf6

Browse files
write materials and submodelparts not repeated
1 parent 441d834 commit d43faf6

2 files changed

Lines changed: 47 additions & 40 deletions

File tree

kratos.gid/apps/Fluid/write/write.tcl

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace eval ::Fluid::write {
22
namespace path ::Fluid
33
Kratos::AddNamespace [namespace current]
4-
4+
55
# Namespace variables declaration
66
variable writeCoordinatesByGroups
77
variable writeAttributes
@@ -20,7 +20,7 @@ proc ::Fluid::write::Init { } {
2020
SetAttribute results_un [::Fluid::GetUniqueName results]
2121
SetAttribute drag_un [::Fluid::GetUniqueName drag]
2222
SetAttribute time_parameters_un [::Fluid::GetUniqueName time_parameters]
23-
23+
2424
SetAttribute writeCoordinatesByGroups [::Fluid::GetWriteProperty coordinates]
2525
SetAttribute validApps [list "Fluid"]
2626
SetAttribute main_launch_file [::Fluid::GetAttribute main_launch_file]
@@ -29,7 +29,7 @@ proc ::Fluid::write::Init { } {
2929
SetAttribute model_part_name [::Fluid::GetWriteProperty model_part_name]
3030
SetAttribute output_model_part_name [::Fluid::GetWriteProperty output_model_part_name]
3131
SetAttribute write_mdpa_mode [::Fluid::GetWriteProperty write_mdpa_mode]
32-
32+
3333
variable last_condition_iterator
3434
set last_condition_iterator 0
3535
}
@@ -39,48 +39,48 @@ proc ::Fluid::write::writeModelPartEvent { } {
3939
# Validation
4040
set err [Validate]
4141
if {$err ne ""} {error $err}
42-
42+
4343
InitConditionsMap
44-
44+
4545
# Init data
4646
write::initWriteConfiguration [GetAttributes]
47-
47+
4848
# Headers
4949
write::writeModelPartData
5050
writeProperties
51-
51+
5252
# Nodal coordinates (1: Print only Fluid nodes <inefficient> | 0: the whole mesh <efficient>)
5353
if {[GetAttribute writeCoordinatesByGroups] ne "all"} {write::writeNodalCoordinatesOnParts} {write::writeNodalCoordinates}
54-
54+
5555
if {[GetAttribute write_mdpa_mode] eq "geometries"} {
5656
# Write geometries
5757
# Get the list of groups in the spd
5858
set lista [::Fluid::xml::GetListOfSubModelParts]
59-
59+
6060
# Write the geometries
6161
set ret [::write::writeGeometryConnectivities $lista]
6262

6363
# Write the submodelparts
6464
foreach group $lista {
65-
write::writeGroupSubModelPartAsGeometry [$group @n]
65+
write::writeGroupSubModelPartAsGeometry [$group @n]
6666
}
6767
} else {
6868
# Element connectivities (Groups on FLParts)
6969
write::writeElementConnectivities
70-
70+
7171
# Nodal conditions and conditions
7272
writeConditions
73-
73+
7474
# Custom SubmodelParts
7575
variable last_condition_iterator
7676
write::writeBasicSubmodelPartsByUniqueId $Fluid::write::FluidConditionMap $last_condition_iterator
7777
# SubmodelParts
7878
writeMeshes
79-
79+
8080
# Write custom blocks at the end of the file
8181
writeCustomBlocks
8282
}
83-
83+
8484
# Clean
8585
unset ::Fluid::write::FluidConditionMap
8686
}
@@ -93,30 +93,36 @@ proc ::Fluid::write::writeCustomFilesEvent { } {
9393

9494
# Custom files
9595
proc ::Fluid::write::WriteMaterialsFile { {write_const_law True} {include_modelpart_name True} } {
96+
9697
set model_part_name ""
9798
if {[write::isBooleanTrue $include_modelpart_name]} {set model_part_name [GetAttribute model_part_name]}
98-
write::writePropertiesJsonFile [GetAttribute parts_un] [GetAttribute materials_file] $write_const_law $model_part_name
99+
write::writePropertiesJsonFileDone [GetAttribute materials_file] [Fluid::write::GetMaterialsFile $write_const_law $include_modelpart_name]
99100
}
100101
proc Fluid::write::GetMaterialsFile { {write_const_law True} {include_modelpart_name True} } {
101102
set model_part_name ""
102103
if {[write::isBooleanTrue $include_modelpart_name]} {set model_part_name [GetAttribute model_part_name]}
103-
return [write::getPropertiesJson [GetAttribute parts_un] $write_const_law $model_part_name]
104+
set parts [write::getPropertiesJson [GetAttribute parts_un] $write_const_law $model_part_name]
105+
set base [dict create model_part_name [GetAttribute model_part_name] properties_id 0 Material null]
106+
set old_list [dict get $parts properties]
107+
set new_list [concat [list $base] $old_list]
108+
set result [dict create properties $new_list]
109+
return $result
104110
}
105111

106112
proc ::Fluid::write::Validate {} {
107113
set err ""
108114
set root [customlib::GetBaseRoot]
109-
115+
110116
# Check only 1 part in Parts
111117
set xp1 "[spdAux::getRoute [GetAttribute parts_un]]/group"
112118
if {[llength [$root selectNodes $xp1]] ne 1} {
113119
set err "You must set one part in Parts.\n"
114120
}
115-
121+
116122
# Check closed volume
117123
#if {[CheckClosedVolume] ne 1} {
118-
# append err "Check boundary conditions."
119-
#}
124+
# append err "Check boundary conditions."
125+
#}
120126
return $err
121127
}
122128

@@ -140,7 +146,7 @@ proc ::Fluid::write::getFluidModelPartFilename { } {
140146
proc ::Fluid::write::writeBoundaryConditions { } {
141147
variable FluidConditionMap
142148
variable last_condition_iterator
143-
149+
144150
# Prepare the groups to print
145151
set BCUN [GetAttribute conditions_un]
146152
set root [customlib::GetBaseRoot]
@@ -160,7 +166,7 @@ proc ::Fluid::write::writeBoundaryConditions { } {
160166
set skin_group_name "_HIDDEN__SKIN_"
161167
if {[GiD_Groups exists $skin_group_name]} {GiD_Groups delete $skin_group_name}
162168
spdAux::MergeGroups $skin_group_name $groups
163-
169+
164170
# Write the conditions
165171
if {$::Model::SpatialDimension eq "3D"} {
166172
set kname SurfaceCondition3D3N
@@ -170,7 +176,7 @@ proc ::Fluid::write::writeBoundaryConditions { } {
170176
set nnodes 2
171177
}
172178
set last_condition_iterator [write::writeGroupConditionByUniqueId $skin_group_name $kname $nnodes 0 $::Fluid::write::FluidConditionMap]
173-
179+
174180
# Clean
175181
GiD_Groups delete $skin_group_name
176182
}
@@ -189,7 +195,7 @@ proc ::Fluid::write::writeMeshes { } {
189195
}
190196

191197
proc ::Fluid::write::writeConditionsMesh { } {
192-
198+
193199
set root [customlib::GetBaseRoot]
194200
set xp1 "[spdAux::getRoute [GetAttribute conditions_un]]/condition/group"
195201
set grouped_conditions [list ]
@@ -213,7 +219,7 @@ proc ::Fluid::write::writeConditionsMesh { } {
213219
}
214220
}
215221
}
216-
222+
217223
foreach condid $grouped_conditions {
218224
set xp "[spdAux::getRoute [GetAttribute conditions_un]]/condition\[@n='$condid'\]/group"
219225
set groups_dict [dict create ]
@@ -227,11 +233,11 @@ proc ::Fluid::write::writeConditionsMesh { } {
227233

228234
# Overwrite this function to print something at the end of the mdpa
229235
proc ::Fluid::write::writeCustomBlocks { } {
230-
236+
231237
}
232238

233239
proc ::Fluid::write::InitConditionsMap { {map "" } } {
234-
240+
235241
variable FluidConditionMap
236242
if {$map eq ""} {
237243
set FluidConditionMap [objarray new intarray [expr [GiD_Info Mesh MaxNumElements] +1] 0]
@@ -240,7 +246,7 @@ proc ::Fluid::write::InitConditionsMap { {map "" } } {
240246
}
241247
}
242248
proc ::Fluid::write::FreeConditionsMap { } {
243-
249+
244250
variable FluidConditionMap
245251
unset FluidConditionMap
246252
}

kratos.gid/scripts/Writing/WriteSubModelPart.tcl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ proc write::writeGroupSubModelPart { cid group {what "Elements"} {iniend ""} {ta
55
variable formats_dict
66

77
set inittime [clock seconds]
8-
8+
99
set id_f [dict get $formats_dict ID]
1010
set mid ""
1111
set what [split $what "&"]
@@ -24,7 +24,7 @@ proc write::writeGroupSubModelPart { cid group {what "Elements"} {iniend ""} {ta
2424
set f [subst $f]
2525
dict set gdict $group $f
2626
incr ::write::current_mdpa_indent_level -2
27-
27+
2828
# Print header
2929
set s [mdpaIndent]
3030
WriteString "${s}Begin SubModelPart $mid // Group $group // Subtree $cid"
@@ -74,18 +74,19 @@ proc write::writeGroupSubModelPartAsGeometry { group } {
7474
variable submodelparts
7575
variable formats_dict
7676
variable geometry_cnd_name
77-
77+
7878
set cid $geometry_cnd_name
7979

8080
set inittime [clock seconds]
81-
81+
8282
set id_f [dict get $formats_dict ID]
8383
set submodelpart_id ""
8484
set group [GetWriteGroupName $group]
8585
set submodelpart_id [write::getSubModelPartId "$cid" $group]
86-
if {$submodelpart_id eq 0} {
86+
if {$submodelpart_id ni $submodelparts} {
8787
# Add the submodelpart to the catalog
8888
set submodelpart_id [write::AddSubmodelpart $cid $group]
89+
lappend submodelparts $submodelpart_id
8990
# Prepare the print formats
9091
incr ::write::current_mdpa_indent_level
9192
set s1 [mdpaIndent]
@@ -97,7 +98,7 @@ proc write::writeGroupSubModelPartAsGeometry { group } {
9798
set f [subst $f]
9899
dict set gdict $group $f
99100
incr ::write::current_mdpa_indent_level -2
100-
101+
101102
# Print header
102103
set s [mdpaIndent]
103104
WriteString "${s}Begin SubModelPart $submodelpart_id // Group $group"
@@ -175,9 +176,9 @@ proc write::_writeElementsForBasicSubmodelParts {un} {
175176
}
176177

177178
proc write::getSubModelPartNames { args } {
178-
179+
179180
set root [customlib::GetBaseRoot]
180-
181+
181182
set listOfProcessedGroups [list ]
182183
set groups [list ]
183184
foreach un $args {
@@ -197,18 +198,18 @@ proc write::getSubModelPartNames { args } {
197198
if {$gname ni $listOfProcessedGroups} {lappend listOfProcessedGroups $gname}
198199
}
199200
}
200-
201+
201202
return $listOfProcessedGroups
202203
}
203204

204205

205206
proc write::GetSubModelPartFromCondition { base_UN condition_id } {
206-
207+
207208
set root [customlib::GetBaseRoot]
208-
209+
209210
set xp1 "[spdAux::getRoute $base_UN]/condition\[@n='$condition_id'\]/group"
210211
set groups [$root selectNodes $xp1]
211-
212+
212213
set submodelpart_list [list ]
213214
foreach gNode $groups {
214215
set group [$gNode @n]

0 commit comments

Comments
 (0)