Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fluid write with geometries #951

Merged
merged 29 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
011bdde
Write orchestrator in parameters
jginternational Sep 15, 2023
47e771d
only import mdpa in modeler
jginternational Sep 15, 2023
641b0d7
Write geometries
jginternational Sep 15, 2023
0f6ccce
modelers inside parameters, instead of preprocess
jginternational Sep 18, 2023
aa7dbdf
Printing modeler for types
jginternational Sep 18, 2023
766f2eb
skin parts
jginternational Sep 26, 2023
a175f90
Merge branch 'master' into fluid-write-orchestrator-multistage
jginternational Sep 26, 2023
4c33649
not grouping conditions by geometry
jginternational Sep 26, 2023
7e46b38
project parameters by geometries
jginternational Sep 26, 2023
0658213
write_mdpa_mode is the keyword
jginternational Sep 26, 2023
42b2d57
materials
jginternational Sep 26, 2023
441d834
change modeler name
jginternational Oct 2, 2023
d43faf6
write materials and submodelparts not repeated
jginternational Oct 2, 2023
f846eac
fluid condition names
jginternational Oct 2, 2023
fa5c846
Revert "fluid condition names"
jginternational Oct 2, 2023
de70a5c
running scripts
jginternational Oct 2, 2023
21ef0b6
extra bin
jginternational Oct 2, 2023
f023087
Fluid dependant apps still dont write geometries
jginternational Oct 3, 2023
8d92673
Add experimental feature in preferences
jginternational Oct 6, 2023
b7c3e3c
If the user chose write by entity, dont print modelers
jginternational Oct 6, 2023
9c878b1
MPI is not compatible with geometries yet
jginternational Oct 6, 2023
2592307
Merge slip
jginternational Oct 6, 2023
85a73a7
grouped conditions in geometries
jginternational Oct 6, 2023
45ee275
package version
jginternational Oct 6, 2023
c1a4601
versioning
jginternational Oct 6, 2023
f02654e
missing parent
jginternational Oct 6, 2023
8a34560
pip versions
jginternational Oct 9, 2023
a954e98
Merge branch 'master' into fluid-write-orchestrator-multistage
jginternational Oct 9, 2023
fcc3c99
spd versioning
jginternational Oct 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ dist
*.tgz
null
__pycache__
*.whl
8 changes: 6 additions & 2 deletions dockers/dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default values. Use --build-arg on build to change
ARG pyversion=3.10.8
ARG pyversion=3.11

# Base pyton image
FROM python:$pyversion
Expand All @@ -8,10 +8,14 @@ FROM python:$pyversion
# Update pip
RUN pip install --upgrade pip

ARG krversion=9.3.2
ARG krversion=9.4.2

# WORKDIR /tmp
# COPY ./wheels/ ./wheels/

# Install Kratos and dependencies
RUN python3 -m pip install KratosMultiphysics-all==$krversion numpy
# RUN python3 -m pip install ./wheels/*.whl

# Prepare run folder
WORKDIR "/model"
Expand Down
3 changes: 2 additions & 1 deletion kratos.gid/apps/Buoyancy/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"write": {
"coordinates": "all",
"properties_location": "json",
"model_part_name": "ThermalModelPart"
"model_part_name": "ThermalModelPart",
"write_mdpa_mode": "entities"
},
"main_launch_file": "../../exec/MainKratos.py",
"examples": "examples/examples.xml"
Expand Down
2 changes: 2 additions & 0 deletions kratos.gid/apps/Buoyancy/write/write.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ proc ::Buoyancy::write::writeModelPartEvent { } {

# Start Fluid write variables
Fluid::write::Init
# Fluid has implemented the geometry mode, but we do not use it yet in inherited apps
::Fluid::write::SetAttribute write_mdpa_mode [::Buoyancy::GetWriteProperty write_mdpa_mode]
# Start Fluid write conditions map from scratch
Fluid::write::InitConditionsMap

Expand Down
3 changes: 2 additions & 1 deletion kratos.gid/apps/CompressibleFluid/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"materials_file": "FluidMaterials.json",
"properties_location": "json",
"model_part_name": "FluidModelPart",
"output_model_part_name": "fluid_computational_model_part"
"output_model_part_name": "fluid_computational_model_part",
"write_mdpa_mode": "entities"
},
"main_launch_file": "python/MainKratos.py",
"examples": "examples/examples.xml",
Expand Down
2 changes: 2 additions & 0 deletions kratos.gid/apps/CompressibleFluid/write/write.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace eval ::CompressibleFluid::write {
proc ::CompressibleFluid::write::Init { } {
# Namespace variables inicialization
::Fluid::write::Init
# Fluid has implemented the geometry mode, but we do not use it yet in inherited apps
::Fluid::write::SetAttribute write_mdpa_mode [::CompressibleFluid::GetWriteProperty write_mdpa_mode]

SetAttribute parts_un [::Fluid::GetUniqueName parts]
SetAttribute nodal_conditions_un [::CompressibleFluid::GetUniqueName nodal_conditions]
Expand Down
3 changes: 2 additions & 1 deletion kratos.gid/apps/EmbeddedFluid/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"write": {
"coordinates": "all",
"materials_file": "FluidMaterials.json",
"properties_location": "json"
"properties_location": "json",
"write_mdpa_mode": "entities"
},
"main_launch_file": "../../exec/MainKratos.py",
"examples": "examples/examples.xml"
Expand Down
2 changes: 2 additions & 0 deletions kratos.gid/apps/EmbeddedFluid/write/write.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace eval ::EmbeddedFluid::write {
proc EmbeddedFluid::write::Init { } {
# Namespace variables inicialization
variable writeAttributes
# Fluid has implemented the geometry mode, but we do not use it yet in inherited apps
::Fluid::write::SetAttribute write_mdpa_mode [::EmbeddedFluid::GetWriteProperty write_mdpa_mode]
set writeAttributes [::Fluid::write::GetAttributes]
}

Expand Down
3 changes: 2 additions & 1 deletion kratos.gid/apps/FSI/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"materials_file": "StructuralMaterials.json",
"properties_location": "json",
"model_part_name": "Structure",
"enable_dynamic_substepping": false
"enable_dynamic_substepping": false,
"write_mdpa_mode": "entities"
},
"main_launch_file": "../../exec/MainKratos.py",
"examples": "examples/examples.xml"
Expand Down
2 changes: 2 additions & 0 deletions kratos.gid/apps/FSI/write/write.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ proc ::FSI::write::writeModelPartEvent { } {
set filename [Kratos::GetModelName]

Fluid::write::Init
# Fluid has implemented the geometry mode, but we do not use it yet in inherited apps
::Fluid::write::SetAttribute write_mdpa_mode [::FSI::GetWriteProperty write_mdpa_mode]
Fluid::write::InitConditionsMap
Fluid::write::SetCoordinatesByGroups 1
write::writeAppMDPA Fluid
Expand Down
3 changes: 2 additions & 1 deletion kratos.gid/apps/Fluid/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"materials_file": "FluidMaterials.json",
"properties_location": "json",
"model_part_name": "FluidModelPart",
"output_model_part_name": "fluid_computational_model_part"
"output_model_part_name": "fluid_computational_model_part",
"write_mdpa_mode": "geometries"
},
"main_launch_file": "../../exec/MainKratos.py",
"examples": "examples/examples.xml",
Expand Down
126 changes: 92 additions & 34 deletions kratos.gid/apps/Fluid/write/write.tcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace eval ::Fluid::write {
namespace path ::Fluid
Kratos::AddNamespace [namespace current]

# Namespace variables declaration
variable writeCoordinatesByGroups
variable writeAttributes
Expand All @@ -20,15 +20,24 @@ proc ::Fluid::write::Init { } {
SetAttribute results_un [::Fluid::GetUniqueName results]
SetAttribute drag_un [::Fluid::GetUniqueName drag]
SetAttribute time_parameters_un [::Fluid::GetUniqueName time_parameters]

SetAttribute writeCoordinatesByGroups [::Fluid::GetWriteProperty coordinates]
SetAttribute validApps [list "Fluid"]
SetAttribute main_launch_file [::Fluid::GetAttribute main_launch_file]
SetAttribute materials_file [::Fluid::GetWriteProperty materials_file]
SetAttribute properties_location [::Fluid::GetWriteProperty properties_location]
SetAttribute model_part_name [::Fluid::GetWriteProperty model_part_name]
SetAttribute output_model_part_name [::Fluid::GetWriteProperty output_model_part_name]

SetAttribute write_mdpa_mode [::Fluid::GetWriteProperty write_mdpa_mode]
# Only write as geometries if the app says it AND the user allows it
# Note: Fluid will enable it but most of the apps that derive from Fluid are not ready for it
# Also user can disable it by setting the variable experimental_write_geometries to 0 in the preferences window
set write_geometries_enabled 0
if {[info exists Kratos::kratos_private(experimental_write_geometries)] && $Kratos::kratos_private(experimental_write_geometries)>0} {set write_geometries_enabled 1}
if {[GetAttribute write_mdpa_mode] eq "geometries" && $write_geometries_enabled ne 1} {
SetAttribute write_mdpa_mode "entities"
}

variable last_condition_iterator
set last_condition_iterator 0
}
Expand All @@ -38,35 +47,71 @@ proc ::Fluid::write::writeModelPartEvent { } {
# Validation
set err [Validate]
if {$err ne ""} {error $err}

InitConditionsMap

# Init data
write::initWriteConfiguration [GetAttributes]

# Headers
write::writeModelPartData
writeProperties

# Nodal coordinates (1: Print only Fluid nodes <inefficient> | 0: the whole mesh <efficient>)
if {[GetAttribute writeCoordinatesByGroups] ne "all"} {write::writeNodalCoordinatesOnParts} {write::writeNodalCoordinates}

# Element connectivities (Groups on FLParts)
write::writeElementConnectivities

# Nodal conditions and conditions
writeConditions

# Custom SubmodelParts
variable last_condition_iterator
write::writeBasicSubmodelPartsByUniqueId $Fluid::write::FluidConditionMap $last_condition_iterator

# SubmodelParts
writeMeshes
if {[GetAttribute write_mdpa_mode] eq "geometries"} {
# Write geometries
# Get the list of groups in the spd
set lista [::Fluid::xml::GetListOfSubModelParts]

# Write the geometries
set ret [::write::writeGeometryConnectivities $lista]

# Write the submodelparts
set grouped_conditions [dict create]
foreach group $lista {
# Some conditions should be grouped in the same submodelpart
# Get condition
set condition_node [$group parent]
# W "Condition node: $condition_node"
set condition_name [$condition_node @n]
# W "Condition name: $condition_name"
set condition [Model::getCondition $condition_name]
if {$condition ne "" && [$condition getGroupBy] eq "Condition"} {
dict lappend grouped_conditions $condition [$group @n]
} else {
write::writeGroupSubModelPartAsGeometry [$group @n]
}
}

# Write custom blocks at the end of the file
writeCustomBlocks
# Write the grouped conditions
foreach condition [dict keys $grouped_conditions] {
set condition_name [$condition getName]
set new_group_name "_HIDDEN_$condition_name"
set groups [dict get $grouped_conditions $condition]
set new_group [spdAux::MergeGroups $new_group_name $groups]
write::writeGroupSubModelPartAsGeometry $new_group_name
GiD_Groups delete $new_group_name
}

} else {
# Element connectivities (Groups on FLParts)
write::writeElementConnectivities

# Nodal conditions and conditions
writeConditions

# Custom SubmodelParts
variable last_condition_iterator
write::writeBasicSubmodelPartsByUniqueId $Fluid::write::FluidConditionMap $last_condition_iterator
# SubmodelParts
writeMeshes

# Write custom blocks at the end of the file
writeCustomBlocks
}

# Clean
unset ::Fluid::write::FluidConditionMap
}
Expand All @@ -79,30 +124,43 @@ proc ::Fluid::write::writeCustomFilesEvent { } {

# Custom files
proc ::Fluid::write::WriteMaterialsFile { {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]}
write::writePropertiesJsonFile [GetAttribute parts_un] [GetAttribute materials_file] $write_const_law $model_part_name
write::writePropertiesJsonFileDone [GetAttribute materials_file] [Fluid::write::GetMaterialsFile $write_const_law $include_modelpart_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]
set parts [write::getPropertiesJson [GetAttribute parts_un] $write_const_law $model_part_name]
set base [dict create model_part_name [GetAttribute model_part_name] properties_id 0 Material null]
set old_list [dict get $parts properties]
set new_list [concat [list $base] $old_list]
set result [dict create properties $new_list]
return $result
}

proc ::Fluid::write::Validate {} {
set err ""
set root [customlib::GetBaseRoot]

# Check only 1 part in Parts
set xp1 "[spdAux::getRoute [GetAttribute parts_un]]/group"
if {[llength [$root selectNodes $xp1]] ne 1} {
set err "You must set one part in Parts.\n"
}

# if the user has selected MPI, check that the write is set to entities
if {[write::getValue ParallelType] eq "MPI"} {
if {[GetAttribute write_mdpa_mode] ne "entities"} {
set err "You must set the write mode to entities when using MPI.\nCheck the Preferences window.\n"
}
}

# Check closed volume
#if {[CheckClosedVolume] ne 1} {
# append err "Check boundary conditions."
#}
# append err "Check boundary conditions."
#}
return $err
}

Expand All @@ -126,7 +184,7 @@ proc ::Fluid::write::getFluidModelPartFilename { } {
proc ::Fluid::write::writeBoundaryConditions { } {
variable FluidConditionMap
variable last_condition_iterator

# Prepare the groups to print
set BCUN [GetAttribute conditions_un]
set root [customlib::GetBaseRoot]
Expand All @@ -146,7 +204,7 @@ proc ::Fluid::write::writeBoundaryConditions { } {
set skin_group_name "_HIDDEN__SKIN_"
if {[GiD_Groups exists $skin_group_name]} {GiD_Groups delete $skin_group_name}
spdAux::MergeGroups $skin_group_name $groups

# Write the conditions
if {$::Model::SpatialDimension eq "3D"} {
set kname SurfaceCondition3D3N
Expand All @@ -156,7 +214,7 @@ proc ::Fluid::write::writeBoundaryConditions { } {
set nnodes 2
}
set last_condition_iterator [write::writeGroupConditionByUniqueId $skin_group_name $kname $nnodes 0 $::Fluid::write::FluidConditionMap]

# Clean
GiD_Groups delete $skin_group_name
}
Expand All @@ -175,7 +233,7 @@ proc ::Fluid::write::writeMeshes { } {
}

proc ::Fluid::write::writeConditionsMesh { } {

set root [customlib::GetBaseRoot]
set xp1 "[spdAux::getRoute [GetAttribute conditions_un]]/condition/group"
set grouped_conditions [list ]
Expand All @@ -199,7 +257,7 @@ proc ::Fluid::write::writeConditionsMesh { } {
}
}
}

foreach condid $grouped_conditions {
set xp "[spdAux::getRoute [GetAttribute conditions_un]]/condition\[@n='$condid'\]/group"
set groups_dict [dict create ]
Expand All @@ -213,11 +271,11 @@ proc ::Fluid::write::writeConditionsMesh { } {

# Overwrite this function to print something at the end of the mdpa
proc ::Fluid::write::writeCustomBlocks { } {

}

proc ::Fluid::write::InitConditionsMap { {map "" } } {

variable FluidConditionMap
if {$map eq ""} {
set FluidConditionMap [objarray new intarray [expr [GiD_Info Mesh MaxNumElements] +1] 0]
Expand All @@ -226,7 +284,7 @@ proc ::Fluid::write::InitConditionsMap { {map "" } } {
}
}
proc ::Fluid::write::FreeConditionsMap { } {

variable FluidConditionMap
unset FluidConditionMap
}
Expand Down
Loading