Skip to content

Commit 781252a

Browse files
committed
add icfd model:driven cavity
1 parent 91a6485 commit 781252a

File tree

12 files changed

+3463
-422
lines changed

12 files changed

+3463
-422
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""
2+
Driven cavity
3+
=============
4+
5+
This example shows the universally famous driven cavity case tested with the second order steady solver and for Re=1000.
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+
Curve,
18+
ICFDVolumePart,
19+
MeshedVolume,
20+
ICFDAnalysis,
21+
ICFD_AnalysisType,
22+
ICFD_MessageLevel,
23+
ICFDDOF
24+
)
25+
from ansys.dyna.core.pre import examples
26+
27+
28+
hostname = "localhost"
29+
if len(sys.argv) > 1:
30+
hostname = sys.argv[1]
31+
32+
solution = DynaSolution(hostname)
33+
# Import the initial mesh data(nodes and elements)
34+
fns = []
35+
path = examples.driven_cavity + os.sep
36+
fns.append(path + "driven_cavity.k")
37+
solution.open_files(fns)
38+
icfd = DynaICFD()
39+
solution.add(icfd)
40+
41+
icfdanalysis = ICFDAnalysis()
42+
icfdanalysis.set_type(analysis_type=ICFD_AnalysisType.STEADY_STATE_ANALYSIS)
43+
icfdanalysis.set_output(messagelevel=ICFD_MessageLevel.FULL_OUTPUT_INFORMATION,iteration_interval=250)
44+
icfdanalysis.set_steady_state(max_iteration=2500,momentum_tol_limit=1e-8,pressure_tol_limit=1e-8,velocity_relax_param=1,pressure_relax_param=1)
45+
icfd.add(icfdanalysis)
46+
47+
# define model
48+
mat = MatICFD(flow_density=1, dynamic_viscosity=0.001)
49+
50+
part1 = ICFDPart(1)
51+
part1.set_material(mat)
52+
part1.set_prescribed_velocity(dof=ICFDDOF.X, motion=Curve(x=[0, 10000], y=[1, 1]))
53+
icfd.parts.add(part1)
54+
55+
part2 = ICFDPart(2)
56+
part2.set_material(mat)
57+
part2.set_non_slip()
58+
icfd.parts.add(part2)
59+
60+
partvol = ICFDVolumePart(surfaces=[1, 2])
61+
partvol.set_material(mat)
62+
icfd.parts.add(partvol)
63+
# define the volume space that will be meshed,The boundaries
64+
# of the volume are the surfaces "spids"
65+
meshvol = MeshedVolume(surfaces=[1, 2])
66+
icfd.add(meshvol)
67+
68+
solution.create_database_binary(dt=250)
69+
solution.save_file()

src/ansys/dyna/core/pre/Server/kwprocess_pb2.py

Lines changed: 270 additions & 210 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ansys/dyna/core/pre/Server/kwprocess_pb2_grpc.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,16 @@ def __init__(self, channel):
479479
request_serializer=kwprocess__pb2.ICFDControlOutputRequest.SerializeToString,
480480
response_deserializer=kwprocess__pb2.ICFDControlOutputReply.FromString,
481481
)
482+
self.ICFDCreateControlSteady = channel.unary_unary(
483+
'/kwgrpc.kwC2S/ICFDCreateControlSteady',
484+
request_serializer=kwprocess__pb2.ICFDControlSteadyRequest.SerializeToString,
485+
response_deserializer=kwprocess__pb2.ICFDControlSteadyReply.FromString,
486+
)
487+
self.ICFDCreateControlFSI = channel.unary_unary(
488+
'/kwgrpc.kwC2S/ICFDCreateControlFSI',
489+
request_serializer=kwprocess__pb2.ICFDControlFSIRequest.SerializeToString,
490+
response_deserializer=kwprocess__pb2.ICFDControlFSIReply.FromString,
491+
)
482492
self.ICFDCreateControlTurbulence = channel.unary_unary(
483493
'/kwgrpc.kwC2S/ICFDCreateControlTurbulence',
484494
request_serializer=kwprocess__pb2.ICFDControlTurbulenceRequest.SerializeToString,
@@ -559,6 +569,11 @@ def __init__(self, channel):
559569
request_serializer=kwprocess__pb2.ICFDBdyNonSlipRequest.SerializeToString,
560570
response_deserializer=kwprocess__pb2.ICFDBdyNonSlipReply.FromString,
561571
)
572+
self.ICFDCreateBdyFSI = channel.unary_unary(
573+
'/kwgrpc.kwC2S/ICFDCreateBdyFSI',
574+
request_serializer=kwprocess__pb2.ICFDBdyFSIRequest.SerializeToString,
575+
response_deserializer=kwprocess__pb2.ICFDBdyFSIReply.FromString,
576+
)
562577
self.ICFDCreateInit = channel.unary_unary(
563578
'/kwgrpc.kwC2S/ICFDCreateInit',
564579
request_serializer=kwprocess__pb2.ICFDInitRequest.SerializeToString,
@@ -1326,6 +1341,18 @@ def ICFDCreateControlOutput(self, request, context):
13261341
context.set_details('Method not implemented!')
13271342
raise NotImplementedError('Method not implemented!')
13281343

1344+
def ICFDCreateControlSteady(self, request, context):
1345+
"""Missing associated documentation comment in .proto file."""
1346+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
1347+
context.set_details('Method not implemented!')
1348+
raise NotImplementedError('Method not implemented!')
1349+
1350+
def ICFDCreateControlFSI(self, request, context):
1351+
"""Missing associated documentation comment in .proto file."""
1352+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
1353+
context.set_details('Method not implemented!')
1354+
raise NotImplementedError('Method not implemented!')
1355+
13291356
def ICFDCreateControlTurbulence(self, request, context):
13301357
"""Missing associated documentation comment in .proto file."""
13311358
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@@ -1422,6 +1449,12 @@ def ICFDCreateBdyNonSlip(self, request, context):
14221449
context.set_details('Method not implemented!')
14231450
raise NotImplementedError('Method not implemented!')
14241451

1452+
def ICFDCreateBdyFSI(self, request, context):
1453+
"""Missing associated documentation comment in .proto file."""
1454+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
1455+
context.set_details('Method not implemented!')
1456+
raise NotImplementedError('Method not implemented!')
1457+
14251458
def ICFDCreateInit(self, request, context):
14261459
"""Missing associated documentation comment in .proto file."""
14271460
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@@ -2124,6 +2157,16 @@ def add_kwC2SServicer_to_server(servicer, server):
21242157
request_deserializer=kwprocess__pb2.ICFDControlOutputRequest.FromString,
21252158
response_serializer=kwprocess__pb2.ICFDControlOutputReply.SerializeToString,
21262159
),
2160+
'ICFDCreateControlSteady': grpc.unary_unary_rpc_method_handler(
2161+
servicer.ICFDCreateControlSteady,
2162+
request_deserializer=kwprocess__pb2.ICFDControlSteadyRequest.FromString,
2163+
response_serializer=kwprocess__pb2.ICFDControlSteadyReply.SerializeToString,
2164+
),
2165+
'ICFDCreateControlFSI': grpc.unary_unary_rpc_method_handler(
2166+
servicer.ICFDCreateControlFSI,
2167+
request_deserializer=kwprocess__pb2.ICFDControlFSIRequest.FromString,
2168+
response_serializer=kwprocess__pb2.ICFDControlFSIReply.SerializeToString,
2169+
),
21272170
'ICFDCreateControlTurbulence': grpc.unary_unary_rpc_method_handler(
21282171
servicer.ICFDCreateControlTurbulence,
21292172
request_deserializer=kwprocess__pb2.ICFDControlTurbulenceRequest.FromString,
@@ -2204,6 +2247,11 @@ def add_kwC2SServicer_to_server(servicer, server):
22042247
request_deserializer=kwprocess__pb2.ICFDBdyNonSlipRequest.FromString,
22052248
response_serializer=kwprocess__pb2.ICFDBdyNonSlipReply.SerializeToString,
22062249
),
2250+
'ICFDCreateBdyFSI': grpc.unary_unary_rpc_method_handler(
2251+
servicer.ICFDCreateBdyFSI,
2252+
request_deserializer=kwprocess__pb2.ICFDBdyFSIRequest.FromString,
2253+
response_serializer=kwprocess__pb2.ICFDBdyFSIReply.SerializeToString,
2254+
),
22072255
'ICFDCreateInit': grpc.unary_unary_rpc_method_handler(
22082256
servicer.ICFDCreateInit,
22092257
request_deserializer=kwprocess__pb2.ICFDInitRequest.FromString,
@@ -3985,6 +4033,40 @@ def ICFDCreateControlOutput(request,
39854033
options, channel_credentials,
39864034
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
39874035

4036+
@staticmethod
4037+
def ICFDCreateControlSteady(request,
4038+
target,
4039+
options=(),
4040+
channel_credentials=None,
4041+
call_credentials=None,
4042+
insecure=False,
4043+
compression=None,
4044+
wait_for_ready=None,
4045+
timeout=None,
4046+
metadata=None):
4047+
return grpc.experimental.unary_unary(request, target, '/kwgrpc.kwC2S/ICFDCreateControlSteady',
4048+
kwprocess__pb2.ICFDControlSteadyRequest.SerializeToString,
4049+
kwprocess__pb2.ICFDControlSteadyReply.FromString,
4050+
options, channel_credentials,
4051+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
4052+
4053+
@staticmethod
4054+
def ICFDCreateControlFSI(request,
4055+
target,
4056+
options=(),
4057+
channel_credentials=None,
4058+
call_credentials=None,
4059+
insecure=False,
4060+
compression=None,
4061+
wait_for_ready=None,
4062+
timeout=None,
4063+
metadata=None):
4064+
return grpc.experimental.unary_unary(request, target, '/kwgrpc.kwC2S/ICFDCreateControlFSI',
4065+
kwprocess__pb2.ICFDControlFSIRequest.SerializeToString,
4066+
kwprocess__pb2.ICFDControlFSIReply.FromString,
4067+
options, channel_credentials,
4068+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
4069+
39884070
@staticmethod
39894071
def ICFDCreateControlTurbulence(request,
39904072
target,
@@ -4257,6 +4339,23 @@ def ICFDCreateBdyNonSlip(request,
42574339
options, channel_credentials,
42584340
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
42594341

4342+
@staticmethod
4343+
def ICFDCreateBdyFSI(request,
4344+
target,
4345+
options=(),
4346+
channel_credentials=None,
4347+
call_credentials=None,
4348+
insecure=False,
4349+
compression=None,
4350+
wait_for_ready=None,
4351+
timeout=None,
4352+
metadata=None):
4353+
return grpc.experimental.unary_unary(request, target, '/kwgrpc.kwC2S/ICFDCreateBdyFSI',
4354+
kwprocess__pb2.ICFDBdyFSIRequest.SerializeToString,
4355+
kwprocess__pb2.ICFDBdyFSIReply.FromString,
4356+
options, channel_credentials,
4357+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
4358+
42604359
@staticmethod
42614360
def ICFDCreateInit(request,
42624361
target,

src/ansys/dyna/core/pre/Server/kwserver.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2009,13 +2009,37 @@ def ICFDCreateControlGeneral(self, request, context):
20092009

20102010
def ICFDCreateControlOutput(self, request, context):
20112011
msgl = request.msgl
2012-
card1 = str(msgl)
2012+
itout = request.itout
2013+
card1 = str(msgl) + ",0,0,0,," + str(itout)
20132014
newk = "*ICFD_CONTROL_OUTPUT\n" + card1
20142015
self.kwdproc.newkeyword(newk)
20152016
msg = "ICFD Control Output Created..."
20162017
print(msg)
20172018
return kwprocess_pb2.ICFDControlOutputReply(answer=0)
20182019

2020+
def ICFDCreateControlSteady(self, request, context):
2021+
its = request.its
2022+
tol1 = request.tol1
2023+
tol2 = request.tol2
2024+
tol3 = request.tol3
2025+
rel1 = request.rel1
2026+
rel2 = request.rel2
2027+
card1 = str(its) + "," + str(tol1) + "," + str(tol2) + "," + str(tol3) + "," + str(rel1) + "," + str(rel2) + ",1.0"
2028+
newk = "*ICFD_CONTROL_STEADY\n" + card1
2029+
self.kwdproc.newkeyword(newk)
2030+
msg = "ICFD Control Steady Created..."
2031+
print(msg)
2032+
return kwprocess_pb2.ICFDControlSteadyReply(answer=0)
2033+
2034+
def ICFDCreateControlFSI(self, request, context):
2035+
owc = request.owc
2036+
card1 = str(owc)
2037+
newk = "*ICFD_CONTROL_FSI\n" + card1
2038+
self.kwdproc.newkeyword(newk)
2039+
msg = "ICFD Control FSI Created..."
2040+
print(msg)
2041+
return kwprocess_pb2.ICFDControlFSIReply(answer=0)
2042+
20192043
def ICFDCreateControlTurbulence(self, request, context):
20202044
tmod = request.tmod
20212045
card1 = str(tmod)
@@ -2204,6 +2228,15 @@ def ICFDCreateBdyNonSlip(self, request, context):
22042228
print(msg)
22052229
return kwprocess_pb2.ICFDBdyNonSlipReply(answer=0)
22062230

2231+
def ICFDCreateBdyFSI(self, request, context):
2232+
pid = request.pid
2233+
card1 = str(pid)
2234+
newk = "*ICFD_BOUNDARY_FSI\n" + card1
2235+
self.kwdproc.newkeyword(newk)
2236+
msg = "ICFD boundary FSI " + str(pid) + " Created..."
2237+
print(msg)
2238+
return kwprocess_pb2.ICFDBdyFSIReply(answer=0)
2239+
22072240
def ICFDCreateInit(self, request, context):
22082241
pid = request.pid
22092242
vx = request.vx

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,88 @@ class ICFD_SurfRemeshMethod(Enum):
207207
CURVATURE_PRESERVING = 2
208208

209209

210+
class ICFD_AnalysisType(Enum):
211+
TURNOFF_ICFD_SOLVER = -1
212+
TRANSIENT_ANALYSIS = 0
213+
STEADY_STATE_ANALYSIS = 1
214+
215+
216+
class ICFD_MessageLevel(Enum):
217+
TIMESTEP_INFORMATION = 0
218+
FULL_OUTPUT_INFORMATION = 4
219+
220+
210221
class ICFDAnalysis:
211222
"""Activate ICFD analysis and define associated control parameters."""
212223

213224
def __init__(self):
214225
self.defined_timestep = False
215226
self.defined_volumemesh = False
216227
self.defined_surfmesh = False
228+
self.defined_type = False
229+
self.defined_output = False
230+
self.defined_steady_state = False
217231
self.stub = DynaBase.get_stub()
218232

233+
def set_type(self, analysis_type=ICFD_AnalysisType.TRANSIENT_ANALYSIS):
234+
"""Specify the type of CFD analysis.
235+
236+
Parameters
237+
----------
238+
analysis_type : ICFD_AnalysisType
239+
Analysis type.
240+
"""
241+
self.defined_type = True
242+
self.atype = analysis_type.value
243+
244+
def set_output(self, messagelevel=ICFD_MessageLevel.TIMESTEP_INFORMATION, iteration_interval=0):
245+
"""Modify default values for screen and file outputs related to this fluid solver only.
246+
247+
Parameters
248+
----------
249+
messagelevel : ICFD_MessageLevel
250+
Message level.
251+
iteration_interval : int
252+
Iteration interval to print the output.
253+
"""
254+
self.defined_output = True
255+
self.msgl = messagelevel.value
256+
self.itout = iteration_interval
257+
258+
def set_steady_state(
259+
self,
260+
max_iteration=1e6,
261+
momentum_tol_limit=1e-3,
262+
pressure_tol_limit=1e-3,
263+
temperature_tol_limit=1e-3,
264+
velocity_relax_param=0.3,
265+
pressure_relax_param=0.7,
266+
):
267+
"""Specify convergence options for the steady state solver.
268+
269+
Parameters
270+
----------
271+
max_iteration : int
272+
Maximum number of iterations to reach convergence.
273+
momentum_tol_limit : float
274+
Tolerance limits for the momentum equations.
275+
pressure_tol_limit : float
276+
Tolerance limits for the pressure equations.
277+
temperature_tol_limit : float
278+
Tolerance limits for the temperature equations.
279+
velocity_relax_param : float
280+
Relaxation parameters for the velocity.
281+
pressure_relax_param : float
282+
Relaxation parameters for the pressure.
283+
"""
284+
self.defined_steady_state = True
285+
self.its = max_iteration
286+
self.tol1 = momentum_tol_limit
287+
self.tol2 = pressure_tol_limit
288+
self.tol3 = temperature_tol_limit
289+
self.rel1 = velocity_relax_param
290+
self.rel2 = pressure_relax_param
291+
219292
def set_timestep(self, timestep=0):
220293
"""Set time step for the fluid problem.
221294
@@ -257,6 +330,16 @@ def create(self):
257330
self.stub.ICFDCreateControlMesh(ICFDControlMeshRequest(mgsf=self.mgsf))
258331
if self.defined_surfmesh:
259332
self.stub.ICFDCreateControlSurfMesh(ICFDControlSurfMeshRequest(rsrf=self.rsrf))
333+
if self.defined_type:
334+
self.stub.ICFDCreateControlGeneral(ICFDControlGeneralRequest(atype=self.atype, mtype=0, dvcl=0, rdvcl=0))
335+
if self.defined_output:
336+
self.stub.ICFDCreateControlOutput(ICFDControlOutputRequest(msgl=self.msgl, itout=self.itout))
337+
if self.defined_steady_state:
338+
self.stub.ICFDCreateControlSteady(
339+
ICFDControlSteadyRequest(
340+
its=self.its, tol1=self.tol1, tol2=self.tol2, tol3=self.tol3, rel1=self.rel1, rel2=self.rel2
341+
)
342+
)
260343

261344

262345
class Compressible(Enum):

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
thermal_flow = os.path.join(_module_path, "icfd", "thermal_flow")
2424
free_convection_flow = os.path.join(_module_path, "icfd", "free_convection_flow")
2525
dam_break = os.path.join(_module_path, "icfd", "dam_break")
26+
driven_cavity = os.path.join(_module_path, "icfd", "driven_cavity")
2627

2728
iga_sample = os.path.join(_module_path, "iga", "iga_sample")
2829
camry_rc = os.path.join(_module_path, "implicit", "camry_rc")

0 commit comments

Comments
 (0)