Skip to content

Commit f1b4d19

Browse files
committed
add icfd model:sloshing
1 parent 7e7cbc9 commit f1b4d19

File tree

9 files changed

+141127
-0
lines changed

9 files changed

+141127
-0
lines changed

examples/ICFD/icfd_sloshing.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""
2+
Sloshing
3+
========
4+
5+
This example shows how to directly impose a displacement of the entire volume mesh through the use of the keyword ICFD_CONTROL_IMPOSED_MOVE.
6+
"""
7+
8+
import os
9+
import sys
10+
11+
12+
from ansys.dyna.core.pre.dynasolution import DynaSolution
13+
from ansys.dyna.core.pre.dynaicfd import (
14+
DynaICFD,
15+
MatICFD,
16+
ICFDPart,
17+
ICFDDOF,
18+
Curve,
19+
ICFDVolumePart,
20+
MeshedVolume,
21+
ICFDAnalysis,
22+
Curve,
23+
Gravity,
24+
GravityOption,
25+
Compressible
26+
)
27+
from ansys.dyna.core.pre import examples
28+
29+
30+
hostname = "localhost"
31+
if len(sys.argv) > 1:
32+
hostname = sys.argv[1]
33+
34+
solution = DynaSolution(hostname)
35+
# Import the initial mesh data(nodes and elements)
36+
fns = []
37+
path = examples.sloshing + os.sep
38+
fns.append(path + "sloshing.k")
39+
solution.open_files(fns)
40+
solution.set_termination(termination_time=1)
41+
icfd = DynaICFD()
42+
solution.add(icfd)
43+
44+
icfdanalysis = ICFDAnalysis()
45+
icfdanalysis.set_timestep(0.02)
46+
icfd.add(icfdanalysis)
47+
48+
# define model
49+
mat1 = MatICFD(flow_density=1000, dynamic_viscosity=0.001)
50+
mat2 = MatICFD(flag=Compressible.VACUUM)
51+
52+
part_bottom = ICFDPart(1)
53+
part_bottom.set_material(mat1)
54+
part_bottom.set_non_slip()
55+
icfd.parts.add(part_bottom)
56+
57+
part_top = ICFDPart(2)
58+
part_top.set_material(mat2)
59+
part_top.set_non_slip()
60+
icfd.parts.add(part_top)
61+
62+
part_mid = ICFDPart(3)
63+
part_mid.set_material(mat1)
64+
icfd.parts.add(part_mid)
65+
66+
g = Gravity(dir=GravityOption.DIR_Z, load=Curve(x=[0, 10000], y=[1, 1]))
67+
icfd.add(g)
68+
69+
icfd.set_imposed_move(vx=Curve(x=[0, 0.5, 0.52, 0.8, 0.82, 2.0], y=[1, 1, -1, -1, 0, 0]))
70+
71+
partvol_bottom = ICFDVolumePart(surfaces=[1, 3])
72+
partvol_bottom.set_material(mat1)
73+
icfd.parts.add(partvol_bottom)
74+
75+
partvol_top = ICFDVolumePart(surfaces=[2, 3])
76+
partvol_top.set_material(mat2)
77+
icfd.parts.add(partvol_top)
78+
# define the volume space that will be meshed,The boundaries
79+
# of the volume are the surfaces "spids"
80+
meshvol = MeshedVolume(surfaces=[1, 2])
81+
meshvol.set_fluid_interfaces([3])
82+
icfd.add(meshvol)
83+
84+
solution.create_database_binary(dt=0.02)
85+
solution.save_file()

src/ansys/dyna/core/pre/dynaicfd.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,23 @@ def set_initial(self, velocity=Velocity(0, 0, 0), temperature=0, pressure=0):
186186
logging.info("ICFD_INIT Created...")
187187
return ret
188188

189+
def set_imposed_move(self, vx=None, vy=None, vz=None):
190+
"""Impose a velocity on the whole volume mesh."""
191+
lcvx, lcvy, lcvz = 0, 0, 0
192+
if vx != None:
193+
vx.create(self.stub)
194+
lcvx = vx.id
195+
if vy != None:
196+
vy.create(self.stub)
197+
lcvy = vy.id
198+
if vz != None:
199+
vz.create(self.stub)
200+
lcvz = vz.id
201+
ret = self.stub.ICFDCreateControlImposedMove(
202+
ICFDControlImposedMoveRequest(pid=0, lcvx=lcvx, lcvy=lcvy, lcvz=lcvz)
203+
)
204+
return ret
205+
189206
def save_file(self):
190207
"""Save keyword files."""
191208
self.create_section_icfd(1)

src/ansys/dyna/core/pre/examples/examples.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
mesh_adaptivity = os.path.join(_module_path, "icfd", "mesh_adaptivity")
3030
mesh_morphing = os.path.join(_module_path, "icfd", "mesh_morphing")
3131
dem_coupling = os.path.join(_module_path, "icfd", "dem_coupling")
32+
sloshing = os.path.join(_module_path, "icfd", "sloshing")
3233

3334
iga_sample = os.path.join(_module_path, "iga", "iga_sample")
3435
camry_rc = os.path.join(_module_path, "implicit", "camry_rc")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$# LS-PrePost command file created by LS-PrePost(R) V4.10 (Beta)-30Dec2022 -64bit-Window
2+
$# Created on Jan-9-2023 (09:30:19)
3+
open keyword "D:\pyDynavenv\pyDyna\src\ansys\dyna\core\pre\examples\icfd\cylinder_flow\cylinder_flow.k"
4+
open keyword "D:\!WORK\ICFD\ICFDPRE_EXAMPLE\Basics\7_User_defined_mesh\i.k"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
open keyword "D:\pyDynavenv\pyDyna\src\ansys\dyna\core\pre\examples\icfd\cylinder_flow\cylinder_flow.k"
2+
Time to read keyword file = 0.141 seconds
3+
Time to process element data = 0.109 seconds
4+
Finished reading model
5+
open keyword "D:\!WORK\ICFD\ICFDPRE_EXAMPLE\Basics\7_User_defined_mesh\i.k"
6+
LS-PrePost encounters an error when open D:\pyDynavenv\pyDyna\src\ansys\dyna\core\pre\examples\icfd\cylinder_flow\mesh.k
7+
because the path is not found
8+
Error - Include File mesh.k Not open
9+
Error occurs in file D:\!WORK\ICFD\ICFDPRE_EXAMPLE\Basics\7_User_defined_mesh\i.k line # 31
10+
Save Config. parameters to file C:\Users\dell\AppData\Roaming\LSTC\LS-PrePost4.10\lsppconf

src/ansys/dyna/core/pre/examples/icfd/sloshing/sloshing.k

Lines changed: 46961 additions & 0 deletions
Large diffs are not rendered by default.

tests/test_dynaicfd.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,4 +827,61 @@ def test_icfd_dem_coupling(resolve_icfd_path, resolve_server_path, resolve_stand
827827
solution.save_file()
828828
outputfile = os.path.join(resolve_server_path, "output", "test_dem_coupling.k")
829829
standardfile = os.path.join(resolve_standard_path, "icfd", "dem_coupling.k")
830+
assert comparefile(outputfile, standardfile)
831+
832+
def test_icfd_sloshing(resolve_icfd_path, resolve_server_path, resolve_standard_path):
833+
solution = DynaSolution("localhost")
834+
icfd_initialfile = os.path.join(resolve_icfd_path, "test_sloshing.k")
835+
fns = []
836+
fns.append(icfd_initialfile)
837+
solution.open_files(fns)
838+
solution.set_termination(termination_time=1)
839+
icfd = DynaICFD()
840+
solution.add(icfd)
841+
842+
icfdanalysis = ICFDAnalysis()
843+
icfdanalysis.set_timestep(0.02)
844+
icfd.add(icfdanalysis)
845+
846+
# define model
847+
mat1 = MatICFD(flow_density=1000, dynamic_viscosity=0.001)
848+
mat2 = MatICFD(flag=Compressible.VACUUM)
849+
850+
part_bottom = ICFDPart(1)
851+
part_bottom.set_material(mat1)
852+
part_bottom.set_non_slip()
853+
icfd.parts.add(part_bottom)
854+
855+
part_top = ICFDPart(2)
856+
part_top.set_material(mat2)
857+
part_top.set_non_slip()
858+
icfd.parts.add(part_top)
859+
860+
part_mid = ICFDPart(3)
861+
part_mid.set_material(mat1)
862+
icfd.parts.add(part_mid)
863+
864+
g = Gravity(dir=GravityOption.DIR_Z, load=Curve(x=[0, 10000], y=[1, 1]))
865+
icfd.add(g)
866+
867+
icfd.set_imposed_move(vx=Curve(x=[0, 0.5, 0.52, 0.8, 0.82, 2.0], y=[1, 1, -1, -1, 0, 0]))
868+
869+
partvol_bottom = ICFDVolumePart(surfaces=[1, 3])
870+
partvol_bottom.set_material(mat1)
871+
icfd.parts.add(partvol_bottom)
872+
873+
partvol_top = ICFDVolumePart(surfaces=[2, 3])
874+
partvol_top.set_material(mat2)
875+
icfd.parts.add(partvol_top)
876+
# define the volume space that will be meshed,The boundaries
877+
# of the volume are the surfaces "spids"
878+
meshvol = MeshedVolume(surfaces=[1, 2])
879+
meshvol.set_fluid_interfaces([3])
880+
icfd.add(meshvol)
881+
882+
solution.create_database_binary(dt=0.02)
883+
solution.save_file()
884+
885+
outputfile = os.path.join(resolve_server_path, "output", "test_sloshing.k")
886+
standardfile = os.path.join(resolve_standard_path, "icfd", "sloshing.k")
830887
assert comparefile(outputfile, standardfile)

0 commit comments

Comments
 (0)