Skip to content

Commit 8f23ec1

Browse files
committed
Remove the asynchronous decorator from TUI and datamodel command execution
1 parent e6900ed commit 8f23ec1

File tree

5 files changed

+70
-52
lines changed

5 files changed

+70
-52
lines changed

ansys/fluent/core/services/datamodel_se.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from ansys.api.fluent.v0 import datamodel_se_pb2 as DataModelProtoModule
1010
from ansys.api.fluent.v0 import datamodel_se_pb2_grpc as DataModelGrpcModule
11-
from ansys.fluent.core.utils.async_execution import asynchronous
1211
from ansys.fluent.core.services.error_handler import catch_grpc_error
1312
from ansys.fluent.core.services.interceptors import TracingInterceptor
1413

@@ -560,7 +559,6 @@ def __init__(
560559
else:
561560
self.path = path
562561

563-
@asynchronous
564562
def __call__(self, *args, **kwds) -> Any:
565563
"""Executes the command
566564

ansys/fluent/core/services/datamodel_tui.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from ansys.api.fluent.v0 import datamodel_tui_pb2 as DataModelProtoModule
99
from ansys.api.fluent.v0 import datamodel_tui_pb2_grpc as DataModelGrpcModule
10-
from ansys.fluent.core.utils.async_execution import asynchronous
1110
from ansys.fluent.core.services.error_handler import catch_grpc_error
1211
from ansys.fluent.core.services.interceptors import TracingInterceptor
1312

@@ -232,7 +231,6 @@ def set_state(self, value: Any) -> None:
232231
_convert_value_to_gvalue(value, request.state)
233232
self._service.set_state(request)
234233

235-
@asynchronous
236234
def _execute_command(
237235
self, request: DataModelProtoModule.ExecuteCommandRequest
238236
) -> Any:

ansys/fluent/core/utils/async_execution.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,29 @@
55

66

77
def asynchronous(f):
8-
"""Use for decorating functions to execute asynchronously."""
8+
"""Use for decorating functions to execute asynchronously.
9+
The decorated function returns a `future`_ object. Calling `result()`_
10+
on the future object synchronizes the function execution.
11+
12+
Examples
13+
--------
14+
>>> # asynchronous execution using @asynchronous decorator
15+
>>> @asynchronous
16+
... def asynchronous_solve(session, number_of_iterations):
17+
... session.tui.solver.solve.iterate(number_of_iterations)
18+
>>> asynchronous_solve(session1, 100)
19+
20+
>>> # using the asynchronous function directly
21+
>>> asynchronous(session2.tui.solver.solve.iterate)(100)
22+
23+
>>> # synchronous execution of above 2 calls
24+
>>> asynchronous_solve(session1, 100).result()
25+
>>> asynchronous(session2.tui.solver.solve.iterate)(100).result()
26+
27+
.. _Future: https://docs.python.org/3/library/asyncio-future.html#future-object # noqa: E501
28+
.. _result(): https://docs.python.org/3/library/asyncio-future.html#asyncio.Future.result # noqa: E501
29+
30+
"""
931
@functools.wraps(f)
1032
def func(*args, **kwargs):
1133
return ThreadPoolExecutor(max_workers=1).submit(f, *args, **kwargs)

examples/00-fluent/mixing_elbow_settings_api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,17 +400,17 @@
400400
"3",
401401
"quit",
402402
)
403-
s.tui.solver.solve.convergence_conditions("frequency", "3", "quit").result()
403+
s.tui.solver.solve.convergence_conditions("frequency", "3", "quit")
404404

405405
###############################################################################
406406

407407
# Initialize the flow field using the Hybrid Initialization
408-
s.tui.solver.solve.initialize.hyb_initialization().result()
408+
s.tui.solver.solve.initialize.hyb_initialization()
409409

410410
###############################################################################
411411

412412
# Solve for 150 Iterations.
413-
s.tui.solver.solve.iterate(150).result()
413+
s.tui.solver.solve.iterate(150)
414414

415415
###############################################################################
416416

@@ -482,7 +482,7 @@
482482
# surface outlet. Name: z=0_outlet
483483
s.tui.solver.surface.iso_surface(
484484
"z-coordinate", "z=0_outlet", "outlet", "()", "()", "0", "()"
485-
).result()
485+
)
486486

487487
# Create Contour on the iso-surface
488488
root.results.graphics.contour["contour-z_0_outlet"] = {}
@@ -494,7 +494,7 @@
494494
# root.results.graphics.contour["contour-z_0_outlet"].display()
495495

496496
###############################################################################
497-
# s.tui.solver.file.write_case_data("mixing_elbow1_set.cas.h5").result()
497+
# s.tui.solver.file.write_case_data("mixing_elbow1_set.cas.h5")
498498

499499
# Display and save an XY plot of the temperature profile across the centerline
500500
# of the outlet for the initial solution
@@ -508,8 +508,8 @@
508508
"z=0_outlet",
509509
"()",
510510
"quit",
511-
).result()
512-
# s.tui.solver.display.objects.display("xy-outlet-temp").result()
511+
)
512+
# s.tui.solver.display.objects.display("xy-outlet-temp")
513513
# s.tui.solver.plot.plot(
514514
# "yes",
515515
# "temp-1.xy",
@@ -523,11 +523,11 @@
523523
# "0",
524524
# "z=0_outlet",
525525
# "()",
526-
#).result()
526+
#)
527527

528528
###############################################################################
529529

530530
# Write final case and data.
531-
# s.tui.solver.file.write_case_data('mixing_elbow2_set.cas.h5').result()
531+
# s.tui.solver.file.write_case_data('mixing_elbow2_set.cas.h5')
532532

533533
###############################################################################

examples/00-fluent/mixing_elbow_tui_api.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
###############################################################################
167167

168168
# Check the mesh in Meshing mode
169-
s.tui.meshing.mesh.check_mesh().result()
169+
s.tui.meshing.mesh.check_mesh()
170170

171171
###############################################################################
172172

@@ -180,7 +180,7 @@
180180
# mode, you can now switch to solver mode to complete the setup of the
181181
# simulation. We have just checked the mesh, so select Yes to switch to
182182
# solution mode.
183-
s.tui.meshing.switch_to_solution_mode("yes").result()
183+
s.tui.meshing.switch_to_solution_mode("yes")
184184

185185
###############################################################################
186186

@@ -190,7 +190,7 @@
190190
# mesh features that are checked. Any errors in the mesh will be reported at
191191
# this time. Ensure that the minimum volume is not negative, since Ansys Fluent
192192
# cannot begin a calculation when this is the case.
193-
s.tui.solver.mesh.check().result()
193+
s.tui.solver.mesh.check()
194194

195195
###############################################################################
196196

@@ -200,17 +200,17 @@
200200
# to change any other units in this problem. If you want a different working
201201
# unit for length, other than inches (for example, millimeters), make the
202202
# appropriate change.
203-
s.tui.solver.define.units("length", "in").result()
203+
s.tui.solver.define.units("length", "in")
204204

205205
###############################################################################
206206

207207
# Enable heat transfer by activating the energy equation.
208-
s.tui.solver.define.models.energy("yes", ", ", ", ", ", ", ", ").result()
208+
s.tui.solver.define.models.energy("yes", ", ", ", ", ", ", ", ")
209209

210210
###############################################################################
211211

212212
# Create a new material called water-liquid.
213-
s.tui.solver.define.materials.copy("fluid", "water-liquid").result()
213+
s.tui.solver.define.materials.copy("fluid", "water-liquid")
214214

215215
###############################################################################
216216

@@ -240,7 +240,7 @@
240240
"no",
241241
"no",
242242
"no",
243-
).result()
243+
)
244244

245245
###############################################################################
246246

@@ -252,19 +252,19 @@
252252

253253
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
254254
"cold-inlet", [], "vmag", "no", 0.4, "quit"
255-
).result()
255+
)
256256
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
257257
"cold-inlet", [], "ke-spec", "no", "no", "no", "yes", "quit"
258-
).result()
258+
)
259259
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
260260
"cold-inlet", [], "turb-intensity", 5, "quit"
261-
).result()
261+
)
262262
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
263263
"cold-inlet", [], "turb-hydraulic-diam", 4, "quit"
264-
).result()
264+
)
265265
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
266266
"cold-inlet", [], "temperature", "no", 293.15, "quit"
267-
).result()
267+
)
268268

269269
###############################################################################
270270

@@ -274,19 +274,19 @@
274274

275275
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
276276
"hot-inlet", [], "vmag", "no", 1.2, "quit"
277-
).result()
277+
)
278278
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
279279
"hot-inlet", [], "ke-spec", "no", "no", "no", "yes", "quit"
280-
).result()
280+
)
281281
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
282282
"hot-inlet", [], "turb-intensity", 5, "quit"
283-
).result()
283+
)
284284
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
285285
"hot-inlet", [], "turb-hydraulic-diam", 1, "quit"
286-
).result()
286+
)
287287
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
288288
"hot-inlet", [], "temperature", "no", 313.15, "quit"
289-
).result()
289+
)
290290

291291
###############################################################################
292292

@@ -296,10 +296,10 @@
296296

297297
s.tui.solver.define.boundary_conditions.set.pressure_outlet(
298298
"outlet", [], "turb-intensity", 5, "quit"
299-
).result()
299+
)
300300
s.tui.solver.define.boundary_conditions.set.pressure_outlet(
301301
"outlet", [], "turb-viscosity-ratio", 4, "quit"
302-
).result()
302+
)
303303

304304
###############################################################################
305305

@@ -319,7 +319,7 @@
319319
"outlet",
320320
"()",
321321
"quit",
322-
).result()
322+
)
323323

324324
###############################################################################
325325

@@ -345,7 +345,7 @@
345345
# "run-index",
346346
# "0",
347347
# "quit",
348-
# ).result()
348+
# )
349349

350350
###############################################################################
351351

@@ -384,23 +384,23 @@
384384
"frequency",
385385
"3",
386386
"quit",
387-
).result()
388-
s.tui.solver.solve.convergence_conditions("frequency", "3", "quit").result()
387+
)
388+
s.tui.solver.solve.convergence_conditions("frequency", "3", "quit")
389389

390390
###############################################################################
391391

392392
# Initialize the flow field using the Hybrid Initialization
393-
s.tui.solver.solve.initialize.hyb_initialization().result()
393+
s.tui.solver.solve.initialize.hyb_initialization()
394394

395395
###############################################################################
396396

397397
# Save the case file (mixing_elbow1.cas.h5).
398-
# s.tui.solver.file.write_case('mixing_elbow1.cas.h5').result()
398+
# s.tui.solver.file.write_case('mixing_elbow1.cas.h5')
399399

400400
###############################################################################
401401

402402
# Solve for 150 Iterations.
403-
s.tui.solver.solve.iterate(150).result()
403+
s.tui.solver.solve.iterate(150)
404404

405405
###############################################################################
406406

@@ -413,7 +413,7 @@
413413
###############################################################################
414414

415415
# Save the data file (mixing_elbow1.dat.h5).
416-
# s.tui.solver.file.write_data('mixing_elbow1.dat.h5').result()
416+
# s.tui.solver.file.write_data('mixing_elbow1.dat.h5')
417417

418418
###############################################################################
419419

@@ -438,8 +438,8 @@
438438
"coloring",
439439
"banded",
440440
"quit",
441-
).result()
442-
# s.tui.solver.display.objects.display("contour-vel").result()
441+
)
442+
# s.tui.solver.display.objects.display("contour-vel")
443443

444444
###############################################################################
445445

@@ -464,7 +464,7 @@
464464
"smooth",
465465
"quit",
466466
)
467-
# s.tui.solver.display.objects.display("contour-temp").result()
467+
# s.tui.solver.display.objects.display("contour-temp")
468468

469469
###############################################################################
470470

@@ -488,19 +488,19 @@
488488
"skip",
489489
"2",
490490
"quit",
491-
).result()
492-
# s.tui.solver.display.objects.display("vector-vel").result()
491+
)
492+
# s.tui.solver.display.objects.display("vector-vel")
493493

494494
###############################################################################
495495

496496
# Create an iso-surface representing the intersection of the plane z=0 and the
497497
# surface outlet. Name: z=0_outlet
498498
s.tui.solver.surface.iso_surface(
499499
"z-coordinate", "z=0_outlet", "outlet", "()", "()", "0", "()"
500-
).result()
500+
)
501501

502502
###############################################################################
503-
# s.tui.solver.file.write_case_data("mixing_elbow1_tui.cas.h5").result()
503+
# s.tui.solver.file.write_case_data("mixing_elbow1_tui.cas.h5")
504504

505505
# Display and save an XY plot of the temperature profile across the centerline
506506
# of the outlet for the initial solution
@@ -513,8 +513,8 @@
513513
"z=0_outlet",
514514
"()",
515515
"quit",
516-
).result()
517-
# s.tui.solver.display.objects.display("xy-outlet-temp").result()
516+
)
517+
# s.tui.solver.display.objects.display("xy-outlet-temp")
518518
# s.tui.solver.plot.plot(
519519
# "yes",
520520
# "temp-1.xy",
@@ -528,11 +528,11 @@
528528
# "0",
529529
# "z=0_outlet",
530530
# "()",
531-
# ).result()
531+
# )
532532

533533
###############################################################################
534534

535535
# Write final case and data.
536-
# s.tui.solver.file.write_case_data("mixing_elbow2_tui.cas.h5").result()
536+
# s.tui.solver.file.write_case_data("mixing_elbow2_tui.cas.h5")
537537

538538
###############################################################################

0 commit comments

Comments
 (0)