Skip to content

Commit 8cc7a05

Browse files
committed
add icfd model:mesh adaptivity
1 parent edb811a commit 8cc7a05

File tree

12 files changed

+2130
-470
lines changed

12 files changed

+2130
-470
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""
2+
Mesh Adaptivity
3+
===============
4+
5+
This example shows a simple ICFD problem with adaptivity.
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+
)
23+
from ansys.dyna.core.pre import examples
24+
25+
26+
hostname = "localhost"
27+
if len(sys.argv) > 1:
28+
hostname = sys.argv[1]
29+
30+
solution = DynaSolution(hostname)
31+
# Import the initial mesh data(nodes and elements)
32+
fns = []
33+
path = examples.mesh_adaptivity + os.sep
34+
fns.append(path + "mesh_adaptivity.k")
35+
solution.open_files(fns)
36+
solution.set_termination(termination_time=40)
37+
icfd = DynaICFD()
38+
solution.add(icfd)
39+
40+
icfdanalysis = ICFDAnalysis()
41+
icfdanalysis.set_timestep()
42+
icfdanalysis.set_mesh_adaptivity(min_mesh_size=0.02,max_mesh_size=0.2,max_perceptual_error=2,num_iteration=10)
43+
icfd.add(icfdanalysis)
44+
45+
# define model
46+
mat = MatICFD(flow_density=1.0, dynamic_viscosity=0.005)
47+
48+
part_inflow = ICFDPart(1)
49+
part_inflow.set_material(mat)
50+
part_inflow.set_prescribed_velocity(dof=ICFDDOF.X, motion=Curve(x=[0, 10000], y=[1, 1]))
51+
part_inflow.set_prescribed_velocity(dof=ICFDDOF.Y, motion=Curve(x=[0, 10000], y=[0, 0]))
52+
icfd.parts.add(part_inflow)
53+
54+
part_outflow = ICFDPart(2)
55+
part_outflow.set_material(mat)
56+
part_outflow.set_prescribed_pressure(pressure=Curve(x=[0, 10000], y=[0, 0]))
57+
icfd.parts.add(part_outflow)
58+
59+
part_symmetric = ICFDPart(3)
60+
part_symmetric.set_material(mat)
61+
part_symmetric.set_free_slip()
62+
icfd.parts.add(part_symmetric)
63+
64+
part_wall = ICFDPart(4)
65+
part_wall.set_material(mat)
66+
part_wall.set_non_slip()
67+
part_wall.compute_drag_force()
68+
part_wall.set_boundary_layer(number=2)
69+
icfd.parts.add(part_wall)
70+
71+
part_meshsize = ICFDPart(5)
72+
part_meshsize.set_material(mat)
73+
icfd.parts.add(part_meshsize)
74+
75+
partvol = ICFDVolumePart(surfaces=[1, 2, 3, 4])
76+
partvol.set_material(mat)
77+
icfd.parts.add(partvol)
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, 3, 4])
81+
icfd.add(meshvol)
82+
83+
solution.create_database_binary(dt=0.5)
84+
solution.save_file()

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

Lines changed: 255 additions & 235 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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@ def __init__(self, channel):
514514
request_serializer=kwprocess__pb2.ICFDControlMeshRequest.SerializeToString,
515515
response_deserializer=kwprocess__pb2.ICFDControlMeshReply.FromString,
516516
)
517+
self.ICFDCreateControlAdapt = channel.unary_unary(
518+
'/kwgrpc.kwC2S/ICFDCreateControlAdapt',
519+
request_serializer=kwprocess__pb2.ICFDControlAdaptRequest.SerializeToString,
520+
response_deserializer=kwprocess__pb2.ICFDControlAdaptReply.FromString,
521+
)
517522
self.ICFDCreateControlSurfMesh = channel.unary_unary(
518523
'/kwgrpc.kwC2S/ICFDCreateControlSurfMesh',
519524
request_serializer=kwprocess__pb2.ICFDControlSurfMeshRequest.SerializeToString,
@@ -1398,6 +1403,12 @@ def ICFDCreateControlMesh(self, request, context):
13981403
context.set_details('Method not implemented!')
13991404
raise NotImplementedError('Method not implemented!')
14001405

1406+
def ICFDCreateControlAdapt(self, request, context):
1407+
"""Missing associated documentation comment in .proto file."""
1408+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
1409+
context.set_details('Method not implemented!')
1410+
raise NotImplementedError('Method not implemented!')
1411+
14011412
def ICFDCreateControlSurfMesh(self, request, context):
14021413
"""Missing associated documentation comment in .proto file."""
14031414
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@@ -2225,6 +2236,11 @@ def add_kwC2SServicer_to_server(servicer, server):
22252236
request_deserializer=kwprocess__pb2.ICFDControlMeshRequest.FromString,
22262237
response_serializer=kwprocess__pb2.ICFDControlMeshReply.SerializeToString,
22272238
),
2239+
'ICFDCreateControlAdapt': grpc.unary_unary_rpc_method_handler(
2240+
servicer.ICFDCreateControlAdapt,
2241+
request_deserializer=kwprocess__pb2.ICFDControlAdaptRequest.FromString,
2242+
response_serializer=kwprocess__pb2.ICFDControlAdaptReply.SerializeToString,
2243+
),
22282244
'ICFDCreateControlSurfMesh': grpc.unary_unary_rpc_method_handler(
22292245
servicer.ICFDCreateControlSurfMesh,
22302246
request_deserializer=kwprocess__pb2.ICFDControlSurfMeshRequest.FromString,
@@ -4200,6 +4216,23 @@ def ICFDCreateControlMesh(request,
42004216
options, channel_credentials,
42014217
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
42024218

4219+
@staticmethod
4220+
def ICFDCreateControlAdapt(request,
4221+
target,
4222+
options=(),
4223+
channel_credentials=None,
4224+
call_credentials=None,
4225+
insecure=False,
4226+
compression=None,
4227+
wait_for_ready=None,
4228+
timeout=None,
4229+
metadata=None):
4230+
return grpc.experimental.unary_unary(request, target, '/kwgrpc.kwC2S/ICFDCreateControlAdapt',
4231+
kwprocess__pb2.ICFDControlAdaptRequest.SerializeToString,
4232+
kwprocess__pb2.ICFDControlAdaptReply.FromString,
4233+
options, channel_credentials,
4234+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
4235+
42034236
@staticmethod
42044237
def ICFDCreateControlSurfMesh(request,
42054238
target,

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,18 @@ def ICFDCreateControlMesh(self, request, context):
20962096
print(msg)
20972097
return kwprocess_pb2.ICFDControlMeshReply(answer=0)
20982098

2099+
def ICFDCreateControlAdapt(self, request, context):
2100+
minh = request.minh
2101+
maxh = request.maxh
2102+
err = request.err
2103+
nit = request.nit
2104+
card1 = str(minh) + "," + str(maxh) + "," + str(err) + ",0," + str(nit)
2105+
newk = "*ICFD_CONTROL_ADAPT\n" + card1
2106+
self.kwdproc.newkeyword(newk)
2107+
msg = "ICFD_CONTROL_ADAPT Created..."
2108+
print(msg)
2109+
return kwprocess_pb2.ICFDControlAdaptReply(answer=0)
2110+
20992111
def ICFDCreateControlSurfMesh(self, request, context):
21002112
rsrf = request.rsrf
21012113
card1 = str(rsrf)

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def __init__(self):
224224
self.defined_output = False
225225
self.defined_steady_state = False
226226
self.defined_coupling_dem = False
227+
self.defined_mesh_adapt = False
227228
self.stub = DynaBase.get_stub()
228229

229230
def set_type(self, analysis_type=ICFD_AnalysisType.TRANSIENT_ANALYSIS):
@@ -307,6 +308,26 @@ def set_volume_mesh(self, mesh_growth_scale_factor=1.41):
307308
self.defined_volumemesh = True
308309
self.mgsf = mesh_growth_scale_factor
309310

311+
def set_mesh_adaptivity(self, min_mesh_size=0, max_mesh_size=0, max_perceptual_error=0, num_iteration=0):
312+
"""Activate the adaptive mesh refinement feature..
313+
314+
Parameters
315+
----------
316+
min_mesh_size : float
317+
Minimum mesh size allowed to the mesh generator.
318+
max_mesh_size : float
319+
Maximum mesh size.
320+
max_perceptual_error : float
321+
Maximum perceptual error allowed in the whole domain.
322+
num_iteration : int
323+
Number of iterations before a forced remeshing.
324+
"""
325+
self.defined_mesh_adapt = True
326+
self.minh = min_mesh_size
327+
self.maxh = max_mesh_size
328+
self.err = max_perceptual_error
329+
self.nit = num_iteration
330+
310331
def set_surface_mesh(self, remesh_method=ICFD_SurfRemeshMethod.LAPLACIAN_SMOOTHING):
311332
"""Enable automatic surface re-meshing.
312333
@@ -370,6 +391,10 @@ def create(self):
370391
self.stub.ICFDCreateControlDEMCoupling(
371392
ICFDControlDEMCouplingRequest(ctype=self.ctype, bt=self.bt, dt=self.dt, sf=self.sf, form=self.form)
372393
)
394+
if self.defined_mesh_adapt:
395+
self.stub.ICFDCreateControlAdapt(
396+
ICFDControlAdaptRequest(minh=self.minh, maxh=self.maxh, err=self.err, nit=self.nit)
397+
)
373398

374399

375400
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
@@ -26,6 +26,7 @@
2626
weak_fsi = os.path.join(_module_path, "icfd", "weak_fsi")
2727
strong_fsi = os.path.join(_module_path, "icfd", "strong_fsi")
2828
imposed_move = os.path.join(_module_path, "icfd", "imposed_move")
29+
mesh_adaptivity = os.path.join(_module_path, "icfd", "mesh_adaptivity")
2930
dem_coupling = os.path.join(_module_path, "icfd", "dem_coupling")
3031

3132
iga_sample = os.path.join(_module_path, "iga", "iga_sample")

0 commit comments

Comments
 (0)