Skip to content

Commit eb615db

Browse files
Restore potential flow app
1 parent 421d55a commit eb615db

22 files changed

Lines changed: 838 additions & 1 deletion

kratos.gid/apps/FluidLauncher/start.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace eval ::FluidLauncher {
55
proc ::FluidLauncher::Init { } {
66
variable available_apps
77

8-
set available_apps [list Fluid EmbeddedFluid Buoyancy ConjugateHeatTransfer FluidDEM]
8+
set available_apps [list Fluid EmbeddedFluid PotentialFluid Buoyancy ConjugateHeatTransfer FluidDEM]
99
# Allow to open the tree
1010
set ::spdAux::TreeVisibility 0
1111

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
2+
proc ::PotentialFluid::examples::NACA0012 {args} {
3+
if {![Kratos::IsModelEmpty]} {
4+
set txt "We are going to draw the example geometry.\nDo you want to lose your previous work?"
5+
set retval [tk_messageBox -default ok -icon question -message $txt -type okcancel]
6+
if { $retval == "cancel" } { return }
7+
}
8+
DrawNACA0012Geometry$::Model::SpatialDimension
9+
AssignGroupsNACA0012$::Model::SpatialDimension
10+
AssignNACA0012MeshSizes$::Model::SpatialDimension
11+
TreeAssignationNACA0012$::Model::SpatialDimension
12+
13+
GiD_Process 'Redraw
14+
GidUtils::UpdateWindow GROUPS
15+
GidUtils::UpdateWindow LAYER
16+
GiD_Process 'Zoom Frame
17+
18+
}
19+
20+
proc PotentialFluid::examples::DrawNACA0012Geometry2D {args} {
21+
Kratos::ResetModel
22+
GiD_Layers create Fluid
23+
GiD_Layers edit to_use Fluid
24+
25+
# Geometry creation
26+
## Airfoil
27+
GiD_Process Mescape Geometry Create NurbsLine 1.000000 0.000000 0 0.998459 0.000224 0 0.993844 0.000891 0 0.986185 0.001990 0 0.975528 0.003501 0 0.961940 0.005399 0 0.945503 0.007651 0 0.926320 0.010221 0 0.904508 0.013071 0 0.880203 0.016158 0 0.853553 0.019438 0 0.824724 0.022869 0 0.793893 0.026405 0 0.761249 0.030000 0 0.726995 0.033610 0 0.691342 0.037188 0 0.654508 0.040686 0 0.616723 0.044055 0 0.578217 0.047242 0 0.539230 0.050196 0 0.500000 0.052862 0 0.460770 0.055184 0 0.421783 0.057108 0 0.383277 0.058582 0 0.345492 0.059557 0 0.308658 0.059988 0 0.273005 0.059841 0 0.238751 0.059088 0 0.206107 0.057712 0 0.175276 0.055708 0 0.146447 0.053083 0 0.119797 0.049854 0 0.095492 0.046049 0 0.073680 0.041705 0 0.054497 0.036867 0 0.038060 0.031580 0 0.024472 0.025893 0 0.013815 0.019854 0 0.006156 0.013503 0 0.001541 0.006877 0 0.000000 0.000000 0 0.001541 -0.006877 0 0.006156 -0.013503 0 0.013815 -0.019854 0 0.024472 -0.025893 0 0.038060 -0.031580 0 0.054497 -0.036867 0 0.073680 -0.041705 0 0.095492 -0.046049 0 0.119797 -0.049854 0 0.146447 -0.053083 0 0.175276 -0.055708 0 0.206107 -0.057712 0 0.238751 -0.059088 0 0.273005 -0.059841 0 0.308658 -0.059988 0 0.345492 -0.059557 0 0.383277 -0.058582 0 0.421783 -0.057108 0 0.460770 -0.055184 0 0.500000 -0.052862 0 0.539230 -0.050196 0 0.578217 -0.047242 0 0.616723 -0.044055 0 0.654508 -0.040686 0 0.691342 -0.037188 0 0.726995 -0.033610 0 0.761249 -0.030000 0 0.793893 -0.026405 0 0.824724 -0.022869 0 0.853553 -0.019438 0 0.880203 -0.016158 0 0.904508 -0.013071 0 0.926320 -0.010221 0 0.945503 -0.007651 0 0.961940 -0.005399 0 0.975528 -0.003501 0 0.986185 -0.001990 0 0.993844 -0.000891 0 0.998459 -0.000224 0 Join 1 escape escape escape escape escape escape escape escape Escape
28+
GiD_Process Mescape Geometry Edit DivideLine Multiple NumDivisions 2 1 escape escape escape
29+
30+
## Points ##
31+
set coordinates [list 50 25 0 -50 25 0 -50 -25 0 50 -25 0]
32+
set fluidPoints [list ]
33+
foreach {x y z} $coordinates {
34+
lappend fluidPoints [GiD_Geometry create point append Fluid $x $y $z]
35+
}
36+
37+
## Lines ##
38+
set fluidLines [list ]
39+
set initial [lindex $fluidPoints 0]
40+
foreach point [lrange $fluidPoints 1 end] {
41+
lappend fluidLines [GiD_Geometry create line append stline Fluid $initial $point]
42+
set initial $point
43+
}
44+
lappend fluidLines [GiD_Geometry create line append stline Fluid $initial [lindex $fluidPoints 0]]
45+
46+
## Surface
47+
# Lines 2,3 (airfoil) and 4,5,6,7 (far field)
48+
GiD_Process Mescape Geometry Create NurbsSurface 2 3 4 5 6 7 escape escape
49+
}
50+
51+
# Group assign
52+
proc PotentialFluid::examples::AssignGroupsNACA00122D {args} {
53+
# Create the groups
54+
GiD_Groups create Fluid
55+
GiD_Groups edit color Fluid "#26d1a8ff"
56+
GiD_EntitiesGroups assign Fluid surfaces 1
57+
58+
GiD_Groups create FarField
59+
GiD_Groups edit color FarField "#e0210fff"
60+
GiD_EntitiesGroups assign FarField lines 4
61+
GiD_EntitiesGroups assign FarField lines 5
62+
GiD_EntitiesGroups assign FarField lines 6
63+
GiD_EntitiesGroups assign FarField lines 7
64+
65+
# GiD_Groups create UpperSurface
66+
# GiD_Groups edit color UpperSurface "#42eb71ff"
67+
# GiD_EntitiesGroups assign UpperSurface lines 2
68+
69+
# GiD_Groups create LowerSurface
70+
# GiD_Groups edit color LowerSurface "#42eb71ff"
71+
# GiD_EntitiesGroups assign LowerSurface lines 3
72+
73+
GiD_Groups create Body
74+
GiD_Groups edit color Body "#42eb71ff"
75+
GiD_EntitiesGroups assign Body lines {2 3}
76+
}
77+
78+
proc PotentialFluid::examples::AssignNACA0012MeshSizes2D {args} {
79+
set fluid_mesh_size 2.0
80+
set airfoil_mesh_size 0.01
81+
GiD_Process Mescape Utilities Variables SizeTransitionsFactor 0.3 escape escape
82+
# GiD_Process Mescape Meshing AssignSizes Lines $airfoil_mesh_size {*}[GiD_EntitiesGroups get UpperSurface lines] escape escape
83+
# GiD_Process Mescape Meshing AssignSizes Lines $airfoil_mesh_size {*}[GiD_EntitiesGroups get LowerSurface lines] escape escape
84+
GiD_Process Mescape Meshing AssignSizes Lines $airfoil_mesh_size {*}[GiD_EntitiesGroups get Body lines] escape escape
85+
GiD_Process Mescape Meshing AssignSizes Surfaces $fluid_mesh_size [GiD_EntitiesGroups get Fluid surfaces] escape escape
86+
87+
}
88+
89+
proc PotentialFluid::examples::TreeAssignationNACA00122D {args} {
90+
set nd $::Model::SpatialDimension
91+
set root [customlib::GetBaseRoot]
92+
93+
set condtype line
94+
set elemtype surface
95+
if {$nd eq "3D"} {
96+
set condtype surface
97+
set elemtype volume
98+
}
99+
100+
# Fluid Parts
101+
set fluidParts [spdAux::getRoute "FLParts"]
102+
set fluidNode [customlib::AddConditionGroupOnXPath $fluidParts Fluid]
103+
$fluidNode setAttribute ov $elemtype
104+
set props [list Element PotentialFlowElement$nd ConstitutiveLaw Inviscid DENSITY 1.225]
105+
spdAux::SetValuesOnBaseNode $fluidNode $props
106+
107+
set fluidConditions [spdAux::getRoute "FLBC"]
108+
ErasePreviousIntervals
109+
110+
# Far field
111+
set fluidFarField "$fluidConditions/condition\[@n='PotentialWallCondition$nd'\]"
112+
set farFieldNode [customlib::AddConditionGroupOnXPath $fluidFarField FarField]
113+
$farFieldNode setAttribute ov $condtype
114+
set props [list angle_of_attack 0.0 mach_infinity 0.03 speed_of_sound 340.0]
115+
spdAux::SetValuesOnBaseNode $farFieldNode $props
116+
117+
# Fluid Conditions
118+
[customlib::AddConditionGroupOnXPath "$fluidConditions/condition\[@n='Body$nd'\]" Body] setAttribute ov $condtype
119+
120+
# Parallelism
121+
set parameters [list ParallelSolutionType OpenMP OpenMPNumberOfThreads 4]
122+
set xpath [spdAux::getRoute "Parallelization"]
123+
spdAux::SetValuesOnBasePath $xpath $parameters
124+
125+
spdAux::RequestRefresh
126+
}
127+
128+
proc PotentialFluid::examples::ErasePreviousIntervals { } {
129+
set root [customlib::GetBaseRoot]
130+
set interval_base [spdAux::getRoute "Intervals"]
131+
foreach int [$root selectNodes "$interval_base/blockdata\[@n='Interval'\]"] {
132+
if {[$int @name] ni [list Initial Total Custom1]} {$int delete}
133+
}
134+
}
135+
136+
proc PotentialFluid::examples::AddCuts { } {
137+
# Cuts
138+
set results "[spdAux::getRoute FLResults]/container\[@n='GiDOutput'\]"
139+
140+
set cp [[customlib::GetBaseRoot] selectNodes "$results/container\[@n = 'CutPlanes'\]/blockdata\[@name = 'CutPlane'\]"]
141+
[$cp selectNodes "./value\[@n = 'point'\]"] setAttribute v "0.0,0.5,0.0"
142+
}
143+
144+
# Draw Geometry
145+
proc PotentialFluid::examples::DrawNACA0012Geometry3D {args} {
146+
Kratos::ResetModel
147+
GiD_Layers create Fluid
148+
GiD_Layers edit to_use Fluid
149+
150+
# Geometry creation
151+
## Airfoil
152+
GiD_Process 'Rotate Angle 270 0
153+
GiD_Process Mescape Geometry Create NurbsLine 1.000000 0 0.000000 0.998459 0 0.000224 0.993844 0 0.000891 0.986185 0 0.001990 0.975528 0 0.003501 0.961940 0 0.005399 0.945503 0 0.007651 0.926320 0 0.010221 0.904508 0 0.013071 0.880203 0 0.016158 0.853553 0 0.019438 0.824724 0 0.022869 0.793893 0 0.026405 0.761249 0 0.030000 0.726995 0 0.033610 0.691342 0 0.037188 0.654508 0 0.040686 0.616723 0 0.044055 0.578217 0 0.047242 0.539230 0 0.050196 0.500000 0 0.052862 0.460770 0 0.055184 0.421783 0 0.057108 0.383277 0 0.058582 0.345492 0 0.059557 0.308658 0 0.059988 0.273005 0 0.059841 0.238751 0 0.059088 0.206107 0 0.057712 0.175276 0 0.055708 0.146447 0 0.053083 0.119797 0 0.049854 0.095492 0 0.046049 0.073680 0 0.041705 0.054497 0 0.036867 0.038060 0 0.031580 0.024472 0 0.025893 0.013815 0 0.019854 0.006156 0 0.013503 0.001541 0 0.006877 0.000000 0 0.000000 0.001541 0 -0.006877 0.006156 0 -0.013503 0.013815 0 -0.019854 0.024472 0 -0.025893 0.038060 0 -0.031580 0.054497 0 -0.036867 0.073680 0 -0.041705 0.095492 0 -0.046049 0.119797 0 -0.049854 0.146447 0 -0.053083 0.175276 0 -0.055708 0.206107 0 -0.057712 0.238751 0 -0.059088 0.273005 0 -0.059841 0.308658 0 -0.059988 0.345492 0 -0.059557 0.383277 0 -0.058582 0.421783 0 -0.057108 0.460770 0 -0.055184 0.500000 0 -0.052862 0.539230 0 -0.050196 0.578217 0 -0.047242 0.616723 0 -0.044055 0.654508 0 -0.040686 0.691342 0 -0.037188 0.726995 0 -0.033610 0.761249 0 -0.030000 0.793893 0 -0.026405 0.824724 0 -0.022869 0.853553 0 -0.019438 0.880203 0 -0.016158 0.904508 0 -0.013071 0.926320 0 -0.010221 0.945503 0 -0.007651 0.961940 0 -0.005399 0.975528 0 -0.003501 0.986185 0 -0.001990 0.993844 0 -0.000891 0.998459 0 -0.000224 Join 1 escape escape escape escape escape escape escape escape Escape
154+
#GiD_Process Mescape Geometry Create NurbsLine 1.000000 0 0.000000 1.5 0 0 1 0 0.1 0.5 0 0.1 Join 1 escape escape escape escape escape escape escape escape Escape
155+
GiD_Process Mescape Geometry Edit DivideLine Multiple NumDivisions 2 1 escape escape escape
156+
set AOA 5
157+
158+
GiD_Process Mescape Utilities Move AllTypes Duplicate MaintainLayers Rotation FNoJoin 0.0,0.0,0.0 FNoJoin 0.0,1.0,0.0 $AOA points 1 2 lines 2 3 surfaces volumes dimensions escape Mescape
159+
160+
## Points ##
161+
set coordinates [list 50 0 25 -50 0 25 -50 0 -25 50 0 -25]
162+
set fluidPoints [list ]
163+
foreach {x y z} $coordinates {
164+
lappend fluidPoints [GiD_Geometry create point append Fluid $x $y $z]
165+
}
166+
167+
## Lines ##
168+
set fluidLines [list ]
169+
set initial [lindex $fluidPoints 0]
170+
foreach point [lrange $fluidPoints 1 end] {
171+
lappend fluidLines [GiD_Geometry create line append stline Fluid $initial $point]
172+
set initial $point
173+
}
174+
lappend fluidLines [GiD_Geometry create line append stline Fluid $initial [lindex $fluidPoints 0]]
175+
176+
## Surface
177+
# Lines 2,3 (airfoil) and 4,5,6,7 (far field)
178+
GiD_Process Mescape Geometry Create NurbsSurface 2 3 4 5 6 7 escape escape
179+
GiD_Process Mescape Utilities Copy Surfaces Duplicate DoExtrude Volumes MaintainLayers Translation FNoJoin 0.0,0.0,0.0 FNoJoin 0.0,10.0,0.0 1 escape Mescape
180+
GiD_Process 'Zoom Frame
181+
182+
183+
}
184+
185+
# Group assign
186+
proc PotentialFluid::examples::AssignGroupsNACA00123D {args} {
187+
GiD_Groups create Fluid
188+
GiD_Groups edit color Fluid "#26d1a8ff"
189+
GiD_EntitiesGroups assign Fluid volumes 1
190+
191+
GiD_Groups create FarField
192+
GiD_Groups edit color FarField "#e0210fff"
193+
GiD_EntitiesGroups assign FarField surfaces {1 4 5 6 7 8}
194+
195+
GiD_Groups create Body
196+
GiD_Groups edit color Body "#42eb71ff"
197+
GiD_EntitiesGroups assign Body surfaces {2 3}
198+
199+
GiD_Groups create BodyLines
200+
GiD_Groups edit color BodyLines "#42eb71ff"
201+
GiD_EntitiesGroups assign BodyLines lines {2 3 8 9 14 15}
202+
203+
GiD_Groups create BodyPoints
204+
GiD_Groups edit color BodyPoints "#42eb71ff"
205+
GiD_EntitiesGroups assign BodyPoints points {1 2 7 8}
206+
207+
GiD_Groups create Wake
208+
GiD_Groups edit color Wake "#e0210fff"
209+
GiD_EntitiesGroups assign Wake lines {14}
210+
211+
GiD_Groups create WingTips
212+
GiD_Groups edit color WingTips "#e0210fff"
213+
GiD_EntitiesGroups assign WingTips points {1 7}
214+
}
215+
216+
proc PotentialFluid::examples::AssignNACA0012MeshSizes3D {args} {
217+
#set fluid_mesh_size 2.0
218+
set wing_lines_mesh_size 0.1
219+
# set wing_points_mesh_size 0.1
220+
GiD_Process Mescape Utilities Variables SizeTransitionsFactor 0.3 escape escape
221+
# GiD_Process Mescape Meshing AssignSizes Lines $airfoil_mesh_size {*}[GiD_EntitiesGroups get UpperSurface lines] escape escape
222+
# GiD_Process Mescape Meshing AssignSizes Lines $airfoil_mesh_size {*}[GiD_EntitiesGroups get LowerSurface lines] escape escape
223+
GiD_Process Mescape Meshing AssignSizes Lines $wing_lines_mesh_size {*}[GiD_EntitiesGroups get BodyLines lines] escape escape
224+
# GiD_Process Mescape Meshing AssignSizes Points $wing_points_mesh_size {*}[GiD_EntitiesGroups get Body points] escape escape
225+
# GiD_Process Mescape Meshing AssignSizes Surfaces $fluid_mesh_size [GiD_EntitiesGroups get Fluid surfaces] escape escape
226+
#Kratos::Event_BeforeMeshGeneration $fluid_mesh_size
227+
}
228+
229+
proc PotentialFluid::examples::TreeAssignationNACA00123D {args} {
230+
set nd $::Model::SpatialDimension
231+
set root [customlib::GetBaseRoot]
232+
233+
set condtype line
234+
if {$nd eq "3D"} { set condtype surface }
235+
236+
# Fluid Parts
237+
set fluidParts [spdAux::getRoute "FLParts"]
238+
set fluidNode [customlib::AddConditionGroupOnXPath $fluidParts Fluid]
239+
set props [list Element PotentialFlowElement$nd ConstitutiveLaw Inviscid DENSITY 1.225]
240+
spdAux::SetValuesOnBaseNode $fluidNode $props
241+
242+
set fluidConditions [spdAux::getRoute "FLBC"]
243+
ErasePreviousIntervals
244+
245+
# Far field
246+
set fluidFarField "$fluidConditions/condition\[@n='PotentialWallCondition$nd'\]"
247+
set farFieldNode [customlib::AddConditionGroupOnXPath $fluidFarField FarField]
248+
$farFieldNode setAttribute ov $condtype
249+
set props [list angle_of_attack 0.0 mach_infinity 0.03 speed_of_sound 340.0]
250+
spdAux::SetValuesOnBaseNode $farFieldNode $props
251+
252+
# Fluid Conditions
253+
[customlib::AddConditionGroupOnXPath "$fluidConditions/condition\[@n='Body$nd'\]" Body] setAttribute ov $condtype
254+
[customlib::AddConditionGroupOnXPath "$fluidConditions/condition\[@n='Wake$nd'\]" Wake] setAttribute ov $condtype
255+
[customlib::AddConditionGroupOnXPath "$fluidConditions/condition\[@n='Tip$nd'\]" WingTips] setAttribute ov $condtype
256+
257+
# Parallelism
258+
set time_parameters [list ParallelSolutionType OpenMP OpenMPNumberOfThreads 4]
259+
set time_params_path [spdAux::getRoute "Parallelization"]
260+
foreach {n v} $time_parameters {
261+
[$root selectNodes "$time_params_path/value\[@n = '$n'\]"] setAttribute v $v
262+
}
263+
264+
spdAux::RequestRefresh
265+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace eval PotentialFluid::examples {
2+
3+
}
4+
5+
proc PotentialFluid::examples::Init { } {
6+
uplevel #0 [list source [file join $::PotentialFluid::dir examples NACA0012.tcl]]
7+
}
8+
9+
PotentialFluid::examples::Init
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Group id="Fluid">
3+
<Example id="PotentialNACA00122D" app="PotentialFluid" logo="NACA0012.png" name="NACA 0012 2D" dim="2D" cmd="::PotentialFluid::examples::NACA0012"/>
4+
<Example id="PotentialNACA00123D" app="PotentialFluid" logo="NACA0012.png" name="NACA 0012 3D" dim="3D" cmd="::PotentialFluid::examples::NACA0012"/>
5+
</Group>
2.5 KB
Loading
683 Bytes
Loading
4.82 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#makes KratosMultiphysics backward compatible with python 2.6 and 2.7
2+
from __future__ import print_function, absolute_import, division
3+
4+
import KratosMultiphysics
5+
6+
from KratosMultiphysics.CompressiblePotentialFlowApplication.potential_flow_analysis import PotentialFlowAnalysis
7+
8+
# For user-scripting it is intended that a new class is derived from PotentialFlowAnalysis to do modifications
9+
10+
if __name__ == "__main__":
11+
12+
with open("ProjectParameters.json",'r') as parameter_file:
13+
parameters = KratosMultiphysics.Parameters(parameter_file.read())
14+
15+
model = KratosMultiphysics.Model()
16+
simulation = PotentialFlowAnalysis(model,parameters)
17+
simulation.Run()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace eval ::PotentialFluid {
2+
# Variable declaration
3+
variable dir
4+
variable prefix
5+
variable attributes
6+
variable app_id
7+
variable kratos_name
8+
}
9+
10+
proc ::PotentialFluid::Init { } {
11+
# Variable initialization
12+
variable dir
13+
variable prefix
14+
variable attributes
15+
variable kratos_name
16+
set app_id "PotentialFluid"
17+
set kratos_name "CompressiblePotentialFlowApplication"
18+
19+
apps::LoadAppById "Fluid"
20+
21+
set dir [apps::getMyDir "PotentialFluid"]
22+
set attributes [dict create]
23+
24+
set prefix PTFL
25+
set ::Model::ValidSpatialDimensions [list 2D 3D]
26+
27+
# Allow to open the tree
28+
set ::spdAux::TreeVisibility 1
29+
30+
dict set attributes UseIntervals 0
31+
32+
LoadMyFiles
33+
Kratos::AddRestoreVar "::GidPriv(DuplicateEntities)"
34+
set ::GidPriv(DuplicateEntities) 1
35+
36+
# TODO: activate this as soon as the 3D wake detection is working
37+
#::spdAux::CreateDimensionWindow
38+
}
39+
40+
proc ::PotentialFluid::LoadMyFiles { } {
41+
variable dir
42+
43+
uplevel #0 [list source [file join $dir examples examples.tcl]]
44+
uplevel #0 [list source [file join $dir xml XmlController.tcl]]
45+
uplevel #0 [list source [file join $dir write write.tcl]]
46+
uplevel #0 [list source [file join $dir write writeProjectParameters.tcl]]
47+
}
48+
49+
proc ::PotentialFluid::GetAttribute {name} {
50+
variable attributes
51+
set value ""
52+
catch {set value [dict get $attributes $name]}
53+
return $value
54+
}
55+
56+
::PotentialFluid::Init

0 commit comments

Comments
 (0)